From 2589abc882770878b229a428bb6192f5306d5b0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E5=BD=B1?= Date: Sun, 15 Oct 2017 14:24:51 +0800 Subject: [PATCH] 1.1.2 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修复 jQuery 插件执行方法时无返回值 --- dist/jquery.social-sharer.min.js | 4 ++-- dist/social-sharer.min.js | 2 +- package.json | 2 +- src/jquery.plugin.wrapper.js | 15 +++++++-------- 4 files changed, 11 insertions(+), 12 deletions(-) diff --git a/dist/jquery.social-sharer.min.js b/dist/jquery.social-sharer.min.js index 15116cf..423a1eb 100644 --- a/dist/jquery.social-sharer.min.js +++ b/dist/jquery.social-sharer.min.js @@ -1,6 +1,6 @@ /*! - * jquery.social-sharer.js v1.1.1 + * jquery.social-sharer.js v1.1.2 * http://cople.github.io/SocialSharer * Licensed under MIT */ -!function(e){"function"==typeof define&&define.amd?define(["jquery"],e):e("object"==typeof exports?require("jquery"):jQuery)}(function(e){function t(t,i){return this.each(function(){var r=e(this);"string"==typeof t?r.data("SocialSharer")[t](i):r.data("SocialSharer")||r.data("SocialSharer",new n(this,t))})}function i(e){var t=document.querySelector("meta[property='"+e+"']");return t?t.content:t}var r=Object.assign||function(e,t){if(void 0===e||null===e)return e;for(var i in t)t.hasOwnProperty(i)&&(e[i]=t[i]);return e},n=function(){this.init.apply(this,arguments)},o=n.defaults={url:i("og:url")||function(){var e=document.querySelector("link[rel='canonical']");return e?e.href:e}()||location.href,title:i("og:title")||document.title,summary:i("og:description")||function(e){var t=document.querySelector("meta[name='"+e+"']");return t?t.content:t}("description")||"",pic:i("og:image")||(document.images.length?document.images[0].src:""),source:i("og:site_name")||"",weiboKey:"",twitterVia:"",twitterHashTags:"",wechatTitle:"分享到微信",wechatTip:"用微信「扫一扫」上方二维码即可。",qrcodeSize:260,services:["weibo","wechat","qzone","qq","douban","yingxiang"],classNamePrefix:"icon icon-",onRender:null,onClick:null},c=n.templates={weibo:"http://service.weibo.com/share/share.php?url={url}&title={title}&pic={pic}&appkey={weiboKey}",qq:"http://connect.qq.com/widget/shareqq/index.html?url={url}&title={title}&summary={summary}&pics={pic}&site={source}",qzone:"http://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?url={url}&title={title}&summary={summary}&pics={pic}&site={source}",douban:"https://www.douban.com/share/service?url={url}&title={title}&text={summary}&image={pic}",facebook:"https://www.facebook.com/sharer/sharer.php?u={url}",twitter:"https://twitter.com/intent/tweet?url={url}&text={title}&via={twitterVia}&hashtags={twitterHashTags}",gplus:"https://plus.google.com/share?url={url}",linkedin:"http://www.linkedin.com/shareArticle?mini=true&url={url}&title={title}&summary={summary}&source={source}",evernote:"http://www.evernote.com/clip.action?url={url}&title={title}",yingxiang:"http://app.yinxiang.com/clip.action?url={url}&title={title}",qrcode:"//pan.baidu.com/share/qrcode?w={qrcodeSize}&h={qrcodeSize}&url={url}",email:"mailto:?subject={title}&body={url}",webshare:"javascript:;"};n.addService=function(e,t){c[e]=t,t.replace(/\{(.*?)\}/g,function(e,t){o[t]=""})},n.prototype={constructor:n,init:function(e,t){this.container="string"==typeof e?document.querySelector(e):e,this.container._SocialSharer||(this.container._SocialSharer=this,this.options=r(o,this.mergeOptions(t||{})),this.options.qrcodeSize*=Math.min(2,window.devicePixelRatio||1),this.createIcons())},mergeOptions:function(e){var t,i;for(t in o)"onRender"!==t&&"onClick"!==t&&(i=this.container.getAttribute("data-"+t.replace(/[A-Z]/g,"-$&").toLowerCase()))&&(e[t]="services"===t?i.split(","):i);return e},setIcon:function(e,t){var i=this;e.className+=" "+this.options.classNamePrefix+t,"wechat"===t?(this.createQRCode(e),e.href="javascript:;"):(e.href=this.getURL(t),"email"!==t&&(e.target="_blank")),this.options.onClick&&(e.onclick=function(e){return i.options.onClick.call(i,e,t)}),"webshare"===t&&(e.origOnClick=e.onclick,e.onclick=function(t){navigator.share({title:i.options.title,text:i.options.text,url:i.options.url}),e.origOnClick&&e.origOnClick(t)}),this.options.onRender&&this.options.onRender.call(this,e,t)},createIcons:function(){var e,t,i,r,n=this.container.querySelectorAll("[data-service]");if(n.length)for(e=0,t=n.length;e"+this.options.wechatTitle+"

"+this.options.wechatTip+"

",e.appendChild(t)},getURL:function(e){var t=c["wechat"===e?"qrcode":e],i=this.options;return t?t.replace(/\{(.*?)\}/g,function(e,t){return encodeURIComponent(i[t])}):t}},e.fn.socialSharer=t}); \ No newline at end of file +!function(e){"function"==typeof define&&define.amd?define(["jquery"],e):e("object"==typeof exports?require("jquery"):jQuery)}(function(e){function t(t,i){return"string"==typeof t?e.data(this[0],"SocialSharer")[t](i):this.each(function(){e.data(this,"SocialSharer")||e.data(this,"SocialSharer",new n(this,t))})}function i(e){var t=document.querySelector("meta[property='"+e+"']");return t?t.content:t}var r=Object.assign||function(e,t){if(void 0===e||null===e)return e;for(var i in t)t.hasOwnProperty(i)&&(e[i]=t[i]);return e},n=function(){this.init.apply(this,arguments)},o=n.defaults={url:i("og:url")||function(){var e=document.querySelector("link[rel='canonical']");return e?e.href:e}()||location.href,title:i("og:title")||document.title,summary:i("og:description")||function(e){var t=document.querySelector("meta[name='"+e+"']");return t?t.content:t}("description")||"",pic:i("og:image")||(document.images.length?document.images[0].src:""),source:i("og:site_name")||"",weiboKey:"",twitterVia:"",twitterHashTags:"",wechatTitle:"分享到微信",wechatTip:"用微信「扫一扫」上方二维码即可。",qrcodeSize:260,services:["weibo","wechat","qzone","qq","douban","yingxiang"],classNamePrefix:"icon icon-",onRender:null,onClick:null},c=n.templates={weibo:"http://service.weibo.com/share/share.php?url={url}&title={title}&pic={pic}&appkey={weiboKey}",qq:"http://connect.qq.com/widget/shareqq/index.html?url={url}&title={title}&summary={summary}&pics={pic}&site={source}",qzone:"http://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?url={url}&title={title}&summary={summary}&pics={pic}&site={source}",douban:"https://www.douban.com/share/service?url={url}&title={title}&text={summary}&image={pic}",facebook:"https://www.facebook.com/sharer/sharer.php?u={url}",twitter:"https://twitter.com/intent/tweet?url={url}&text={title}&via={twitterVia}&hashtags={twitterHashTags}",gplus:"https://plus.google.com/share?url={url}",linkedin:"http://www.linkedin.com/shareArticle?mini=true&url={url}&title={title}&summary={summary}&source={source}",evernote:"http://www.evernote.com/clip.action?url={url}&title={title}",yingxiang:"http://app.yinxiang.com/clip.action?url={url}&title={title}",qrcode:"//pan.baidu.com/share/qrcode?w={qrcodeSize}&h={qrcodeSize}&url={url}",email:"mailto:?subject={title}&body={url}",webshare:"javascript:;"};n.addService=function(e,t){c[e]=t,t.replace(/\{(.*?)\}/g,function(e,t){o[t]=""})},n.prototype={constructor:n,init:function(e,t){this.container="string"==typeof e?document.querySelector(e):e,this.container._SocialSharer||(this.container._SocialSharer=this,this.options=r(o,this.mergeOptions(t||{})),this.options.qrcodeSize*=Math.min(2,window.devicePixelRatio||1),this.createIcons())},mergeOptions:function(e){var t,i;for(t in o)"onRender"!==t&&"onClick"!==t&&(i=this.container.getAttribute("data-"+t.replace(/[A-Z]/g,"-$&").toLowerCase()))&&(e[t]="services"===t?i.split(","):i);return e},setIcon:function(e,t){var i=this;e.className+=" "+this.options.classNamePrefix+t,"wechat"===t?(this.createQRCode(e),e.href="javascript:;"):(e.href=this.getURL(t),"email"!==t&&(e.target="_blank")),this.options.onClick&&(e.onclick=function(e){return i.options.onClick.call(i,e,t)}),"webshare"===t&&(e.origOnClick=e.onclick,e.onclick=function(t){navigator.share({title:i.options.title,text:i.options.text,url:i.options.url}),e.origOnClick&&e.origOnClick(t)}),this.options.onRender&&this.options.onRender.call(this,e,t)},createIcons:function(){var e,t,i,r,n=this.container.querySelectorAll("[data-service]");if(n.length)for(e=0,t=n.length;e"+this.options.wechatTitle+"

"+this.options.wechatTip+"

",e.appendChild(t)},getURL:function(e){var t=c["wechat"===e?"qrcode":e],i=this.options;return t?t.replace(/\{(.*?)\}/g,function(e,t){return encodeURIComponent(i[t])}):t}},e.fn.socialSharer=t}); \ No newline at end of file diff --git a/dist/social-sharer.min.js b/dist/social-sharer.min.js index d2b5fb4..cb75177 100644 --- a/dist/social-sharer.min.js +++ b/dist/social-sharer.min.js @@ -1,5 +1,5 @@ /*! - * social-sharer.js v1.1.1 + * social-sharer.js v1.1.2 * http://cople.github.io/SocialSharer * Licensed under MIT */ diff --git a/package.json b/package.json index d4622d6..42dbc44 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "social-sharer", - "version": "1.1.1", + "version": "1.1.2", "description": "最 Pure 的社会化分享按钮", "main": "dist/social-sharer.min.js", "keywords": [ diff --git a/src/jquery.plugin.wrapper.js b/src/jquery.plugin.wrapper.js index 3ad5912..cb680ad 100644 --- a/src/jquery.plugin.wrapper.js +++ b/src/jquery.plugin.wrapper.js @@ -1,10 +1,9 @@ function plugin(method, param) { - return this.each(function() { - var $el = $(this); - if (typeof method === "string") { - $el.data("SocialSharer")[method](param); - } else { - if (!$el.data("SocialSharer")) $el.data("SocialSharer", new SocialSharer(this, method)); - } - }); + if (typeof method === "string") { + return $.data(this[0], "SocialSharer")[method](param); + } else { + return this.each(function() { + if (!$.data(this, "SocialSharer")) $.data(this, "SocialSharer", new SocialSharer(this, method)); + }); + } }