From 6809442bf67b30f7e5f62a1f4968a6bdf94bacbc Mon Sep 17 00:00:00 2001 From: Artemiy Date: Tue, 22 Oct 2019 17:24:17 +0800 Subject: [PATCH 1/2] Make umd; export with update method --- dist/share-buttons.js | 2 +- example/dynamic.html | 64 +++++++++++++++++++++++++++++++++++++++++++ package.json | 3 +- src/share-buttons.js | 21 +++++++++++--- 4 files changed, 84 insertions(+), 6 deletions(-) create mode 100644 example/dynamic.html diff --git a/dist/share-buttons.js b/dist/share-buttons.js index fa4a986..155c302 100644 --- a/dist/share-buttons.js +++ b/dist/share-buttons.js @@ -1 +1 @@ -!function(b,m){"use strict";(new function(){var s=function(e,n){return e.replace(/\{(\d+)\}/g,function(e,t){return n[t]||e})},u=function(e){return e.join(" - ")};this.i=function(){var e,t=m.querySelectorAll(".share-btn");for(e=t.length;e--;)n(t[e])};var n=function(e){var t,n=e.querySelectorAll("a");for(t=n.length;t--;)r(n[t],{id:"",url:c(e),title:i(e),desc:a(e)})},r=function(e,t){t.id=l(e,"data-id"),t.id&&o(e,"click",t)},c=function(e){return l(e,"data-url")||location.href||" "},i=function(e){return l(e,"data-title")||m.title||" "},a=function(e){var t=m.querySelector("meta[name=description]");return l(e,"data-desc")||t&&l(t,"content")||" "},o=function(e,t,n){var r=function(){p(n.id,n.url,n.title,n.desc)};e.addEventListener?e.addEventListener(t,r):e.attachEvent("on"+t,function(){r.call(e)})},l=function(e,t){return e.getAttribute(t)},h=function(e){return encodeURIComponent(e)},p=function(e,t,n,r){var c=h(t),i=h(r),a=h(n),o=a||i||"";switch(e){case"fb":d(s("https://www.facebook.com/sharer/sharer.php?u={0}",[c]),n);break;case"vk":d(s("https://vk.com/share.php?url={0}&title={1}",[c,u([a,i])]),n);break;case"tw":d(s("https://twitter.com/intent/tweet?url={0}&text={1}",[c,u([a,i])]),n);break;case"tg":d(s("https://t.me/share/url?url={0}&text={1}",[c,u([a,i])]),n);break;case"pk":d(s("https://getpocket.com/edit?url={0}&title={1}",[c,u([a,i])]),n);break;case"re":d(s("https://reddit.com/submit/?url={0}",[c]),n);break;case"ev":d(s("https://www.evernote.com/clip.action?url={0}&t={1}",[c,a]),n);break;case"in":d(s("https://www.linkedin.com/shareArticle?mini=true&url={0}&title={1}&summary={2}&source={0}",[c,a,u([a,i])]),n);break;case"pi":d(s("https://pinterest.com/pin/create/button/?url={0}&media={0}&description={1}",[c,u([a,i])]),n);break;case"sk":d(s("https://web.skype.com/share?url={0}&source=button&text={1}",[c,u([a,i])]),n);break;case"wa":d(s("whatsapp://send?text={0}%20{1}",[u([a,i]),c]),n);break;case"ok":d(s("https://connect.ok.ru/dk?st.cmd=WidgetSharePreview&service=odnoklassniki&st.shareUrl={0}",[c]),n);break;case"tu":d(s("https://www.tumblr.com/widgets/share/tool?posttype=link&title={0}&caption={0}&content={1}&canonicalUrl={1}&shareSource=tumblr_share_button",[u([a,i]),c]),n);break;case"hn":d(s("https://news.ycombinator.com/submitlink?t={0}&u={1}",[u([a,i]),c]),n);break;case"xi":d(s("https://www.xing.com/app/user?op=share;url={0};title={1}",[c,u([a,i])]),n);break;case"mail":0 + + + + + Test page for sharing + + + + + + + +

Share this page with:

+ + + + + + + + + + \ No newline at end of file diff --git a/package.json b/package.json index 4c1c6f5..c06507a 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,8 @@ "example": "example" }, "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" + "test": "echo \"Error: no test specified\" && exit 1", + "build": "gulp build" }, "repository": { "type": "git", diff --git a/src/share-buttons.js b/src/share-buttons.js index f6b6c6d..b5e108a 100644 --- a/src/share-buttons.js +++ b/src/share-buttons.js @@ -1,5 +1,11 @@ -(function (w, d) { - 'use strict'; +(function (global, factory) { + typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : + typeof define === 'function' && define.amd ? define(factory) : + (global = global || self, global.ShareButtons = factory()); +}(this, function () { 'use strict'; + + var w = window; + var d = w.document; /** * Class to display the buttons of social networks. @@ -350,6 +356,13 @@ } // start - new ShareButtons().i(); + var shareButtons = new ShareButtons(); + shareButtons.i(); -}(window, document)); + return { + update: function () { + shareButtons.i(); + } + }; + +})); From 39ec2b74ce13b373c7ccacb3f507afe7adb5a45b Mon Sep 17 00:00:00 2001 From: Artemiy Date: Tue, 22 Oct 2019 17:26:48 +0800 Subject: [PATCH 2/2] Build --- dist/share-buttons.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dist/share-buttons.js b/dist/share-buttons.js index 155c302..9df83cc 100644 --- a/dist/share-buttons.js +++ b/dist/share-buttons.js @@ -1 +1 @@ -!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e=e||self).myBundle=t()}(w,function(){"use strict";var f=w.document;var e=new function(){function s(e,n){return e.replace(/\{(\d+)\}/g,function(e,t){return n[t]||e})}function u(e){return e.join(" - ")}function l(e){return encodeURIComponent(e)}this.i=function(){var e,t=f.querySelectorAll(".share-btn");for(e=t.length;e--;)n(t[e])};var n=function(e){var t,n=e.querySelectorAll("a");for(t=n.length;t--;)r(n[t],{id:"",url:i(e),title:c(e),desc:o(e)})},r=function(e,t){t.id=d(e,"data-id"),t.id&&a(e,"click",t)},i=function(e){return d(e,"data-url")||location.href||" "},c=function(e){return d(e,"data-title")||f.title||" "},o=function(e){var t=f.querySelector("meta[name=description]");return d(e,"data-desc")||t&&d(t,"content")||" "},a=function(e,t,n){function r(){h(n.id,n.url,n.title,n.desc)}e.addEventListener?e.addEventListener(t,r):e.attachEvent("on"+t,function(){r.call(e)})},d=function(e,t){return e.getAttribute(t)},h=function(e,t,n,r){var i=l(t),c=l(r),o=l(n),a=o||c||"";switch(e){case"fb":p(s("https://www.facebook.com/sharer/sharer.php?u={0}",[i]),n);break;case"vk":p(s("https://vk.com/share.php?url={0}&title={1}",[i,u([o,c])]),n);break;case"tw":p(s("https://twitter.com/intent/tweet?url={0}&text={1}",[i,u([o,c])]),n);break;case"tg":p(s("https://t.me/share/url?url={0}&text={1}",[i,u([o,c])]),n);break;case"pk":p(s("https://getpocket.com/edit?url={0}&title={1}",[i,u([o,c])]),n);break;case"re":p(s("https://reddit.com/submit/?url={0}",[i]),n);break;case"ev":p(s("https://www.evernote.com/clip.action?url={0}&t={1}",[i,o]),n);break;case"in":p(s("https://www.linkedin.com/shareArticle?mini=true&url={0}&title={1}&summary={2}&source={0}",[i,o,u([o,c])]),n);break;case"pi":p(s("https://pinterest.com/pin/create/button/?url={0}&media={0}&description={1}",[i,u([o,c])]),n);break;case"sk":p(s("https://web.skype.com/share?url={0}&source=button&text={1}",[i,u([o,c])]),n);break;case"wa":p(s("whatsapp://send?text={0}%20{1}",[u([o,c]),i]),n);break;case"ok":p(s("https://connect.ok.ru/dk?st.cmd=WidgetSharePreview&service=odnoklassniki&st.shareUrl={0}",[i]),n);break;case"tu":p(s("https://www.tumblr.com/widgets/share/tool?posttype=link&title={0}&caption={0}&content={1}&canonicalUrl={1}&shareSource=tumblr_share_button",[u([o,c]),i]),n);break;case"hn":p(s("https://news.ycombinator.com/submitlink?t={0}&u={1}",[u([o,c]),i]),n);break;case"xi":p(s("https://www.xing.com/app/user?op=share;url={0};title={1}",[i,u([o,c])]),n);break;case"mail":0