Skip to content

Commit

Permalink
Added data attributes for buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
HTMLGuyLLC committed Sep 10, 2019
1 parent 03479ad commit 20b9e11
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 6 deletions.
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -216,19 +216,27 @@ $('.social-share').jConfirm({
{
text:'Facebook',
event:'facebook-share',
data: {
some_data_attr: 1
},
class:'facebook-btn jc-button-highlight'
},
{
text:'Twitter',
event:'twitter-share',
data: {
some_data_attr: 2
},
class:'twitter-btn jc-button-highlight'
}
]
}).on('facebook-share', function(e){
}).on('facebook-share', function(e, data){
var btn = $(this);
var data_attr = btn.data('some_data_attr'); //1
console.log('Sharing to facebook: '+btn.data('url-to-share'));
}).on('twitter-share', function(e){
}).on('twitter-share', function(e, data){
var btn = $(this);
var data_attr = btn.data('some_data_attr'); //2
console.log('Sharing to twitter: '+btn.data('url-to-share'));
});
```
8 changes: 8 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -335,23 +335,31 @@ <h4>Social Media Sharing:</h4>
{
text:'&lt;i class="fa fa-facebook">&lt;/i> Facebook',
event:'facebook-share',
data: {
some_data_attr: 1
},
class:'facebook-btn'
},
{
text:'&lt;i class="fa fa-twitter">&lt;/i> Twitter',
event:'twitter-share',
data: {
some_data_attr: 2
},
class:'twitter-btn'
}
]
}).on('facebook-share', function(e){
var btn = $(this);
var data_attr = btn.data('some_data_attr'); //1
var url = 'http://www.facebook.com/sharer.php?u='+btn.data('url-to-share');
window.open(
url,
'_blank'
);
}).on('twitter-share', function(e){
var btn = $(this);
var data_attr = btn.data('some_data_attr'); //2
var url = 'http://twitter.com/share?text=This%20is%20the%20best!&url='+btn.data('url-to-share');
window.open(
url,
Expand Down
11 changes: 10 additions & 1 deletion jConfirm.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,16 @@
//loop through buttons and add to html
$.each(helper.btns, function(key,btn){
html += `<div class='jc-button-wrap'>
<a href='#' data-event='${btn.event}' class='jc-button ${btn.class}'>${btn.text}</a>
<a href='#' data-event='${btn.event}' class='jc-button ${btn.class}'`;
if( typeof btn.data === 'object' ){
const data_attrs = btn.data;
for ( let prop in data_attrs ) {
if (Object.prototype.hasOwnProperty.call(data_attrs, prop)) {
html += ` data-${prop}="${data_attrs[prop]}"`;
}
}
}
html += `>${btn.text}</a>
</div>`;
});

Expand Down
4 changes: 2 additions & 2 deletions jConfirm.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jconfirm",
"version": "4.4.5",
"version": "4.5.0",
"description": "jQuery confirmation tooltip plugin",
"author": {
"name" : "HTMLGuy, LLC",
Expand Down

0 comments on commit 20b9e11

Please sign in to comment.