Skip to content

Commit

Permalink
Add reinitialize: true param to override existing dom events
Browse files Browse the repository at this point in the history
  • Loading branch information
darklow committed Sep 7, 2017
1 parent 789319d commit dbe420d
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 4 deletions.
2 changes: 1 addition & 1 deletion dist/css/social-share-kit.css

Large diffs are not rendered by default.

Binary file modified dist/fonts/social-share-kit.eot
Binary file not shown.
1 change: 1 addition & 0 deletions dist/fonts/social-share-kit.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified dist/fonts/social-share-kit.ttf
Binary file not shown.
Binary file modified dist/fonts/social-share-kit.woff
Binary file not shown.
13 changes: 12 additions & 1 deletion dist/js/social-share-kit.js
Expand Up @@ -35,10 +35,14 @@ var SocialShareKit = (function () {
}

if (el.getAttribute('data-ssk-ready'))
return;
if (options.reinitialize && el._skkListener) {
removeEventListener(el, 'click', el._skkListener);
} else
return;

el.setAttribute('data-ssk-ready', true);
addEventListener(el, 'click', onClick);
el._skkListener = onClick

// Gather icons with share counts
if (el.parentNode.className.indexOf('ssk-count') !== -1) {
Expand Down Expand Up @@ -165,6 +169,13 @@ var SocialShareKit = (function () {
}
}

function removeEventListener(el, eventName, handler) {
if (el.removeEventListener)
el.removeEventListener(eventName, handler);
else
el.detachEvent('on' + eventName, handler);
}

function elSupportsShare(el) {
return el.className.match(supportsShare);
}
Expand Down
2 changes: 1 addition & 1 deletion dist/js/social-share-kit.min.js

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

24 changes: 23 additions & 1 deletion docs/index.html
Expand Up @@ -415,6 +415,7 @@ <h3 class="page-header">Extra icons</h3>
<a href="" class="ssk ssk-icon ssk-reddit2" title="Reddit2"></a>
<a href="" class="ssk ssk-buffer" title="Buffer"></a>
<a href="" class="ssk ssk-icon ssk-buffer" title="Buffer"></a>
<a href="" class="ssk ssk-icon ssk-slack" title="Slack"></a>
</div>
<div>
<h3 class="page-header">Floating/sticky bar</h3>
Expand Down Expand Up @@ -693,7 +694,11 @@ <h3 class="page-header">Setup JavaScript</h3>
SocialShareKit.init({ forceInit: true });
&lt;/script&gt;</pre>

Social Share Kit is keeping track of already initialised items, so in case if your DOM changes, you can call <code>SocialShareKit.init()</code> multiple times.
Social Share Kit is keeping track of already initialised items, so in case if your DOM changes, you can call <code>SocialShareKit.init()</code> multiple times. If you would like reinitialize SSK once again to the same DOM elements using other parameters use <code>reinitialize: true</code>:

<pre class="prettyprint">&lt;script type="text/javascript"&gt;
SocialShareKit.init({ reinitialize: true });
&lt;/script&gt;</pre>

<h3 about="page-header">Sharer popup options</h3>

Expand Down Expand Up @@ -1055,6 +1060,23 @@ <h2 id="support" class="page-header">Support</h2>
console.log(arguments);
}
});
SocialShareKit.init({
reinitialize: true,
url: 'http://socialsharekit.com',
twitter: {
title: 'Social Share Kit 222222',
via: 'socialsharekit'
},
onBeforeOpen: function(targetElement, network, paramsObj){
console.log(arguments);
},
onOpen: function(targetElement, network, url, popupWindow){
console.log(arguments);
},
onClose: function(targetElement, network, url, popupWindow){
console.log(arguments);
}
});

$(function () {

Expand Down
3 changes: 3 additions & 0 deletions less/fonts.less
Expand Up @@ -101,3 +101,6 @@
content: "\79";
transform: scale(.85);
}
.ssk-slack:before {
content: "\7a";
}

0 comments on commit dbe420d

Please sign in to comment.