diff --git a/assets/lib/share-link/share-link.js b/assets/lib/share-link/share-link.js index 95e991b160bc..7cf0e9880253 100644 --- a/assets/lib/share-link/share-link.js +++ b/assets/lib/share-link/share-link.js @@ -3,19 +3,17 @@ */ ( function() { window.ShareLink = function( eElement, userSettings ) { - var element, - setting = {}; + let element = {}; + let setting = {}; - var getNetworkNameFromClass = function( className ) { - var classNamePrefix = className.substr( 0, settings.classPrefixLength ); + const getNetworkNameFromClass = function( className ) { + const classNamePrefix = className.substr( 0, settings.classPrefixLength ); return classNamePrefix === settings.classPrefix ? className.substr( settings.classPrefixLength ) : null; }; - var bindShareClick = function( networkName ) { - element.addEventListener( 'click', function() { - openShareLink( networkName ); - } ); + const bindShareClick = function( networkName ) { + element.addEventListener( 'click', () => openShareLink( networkName ) ); // Add "Enter" and "Space" event only if the element has role=button attribute. if ( 'button' === element.getAttribute( 'role' ) ) { @@ -29,26 +27,26 @@ } }; - var openShareLink = function( networkName ) { - var shareWindowParams = ''; + const openShareLink = function( networkName ) { + let shareWindowParams = ''; if ( settings.width && settings.height ) { - var shareWindowLeft = ( screen.width / 2 ) - ( settings.width / 2 ), - shareWindowTop = ( screen.height / 2 ) - ( settings.height / 2 ); + const shareWindowLeft = ( screen.width / 2 ) - ( settings.width / 2 ); + const shareWindowTop = ( screen.height / 2 ) - ( settings.height / 2 ); shareWindowParams = 'toolbar=0,status=0,width=' + settings.width + ',height=' + settings.height + ',top=' + shareWindowTop + ',left=' + shareWindowLeft; } - var link = ShareLink.getNetworkLink( networkName, settings ), + const link = ShareLink.getNetworkLink( networkName, settings ), isPlainLink = /^https?:\/\//.test( link ), windowName = isPlainLink ? '' : '_self'; open( link, windowName, shareWindowParams ); }; - var run = function() { - element.classList.forEach( function() { - var networkName = getNetworkNameFromClass( this ); + const run = function() { + element.classList.forEach( () => { + const networkName = getNetworkNameFromClass( this ); if ( networkName ) { bindShareClick( networkName ); @@ -58,17 +56,15 @@ } ); }; - var initSettings = function() { + const initSettings = function() { settings = { ...ShareLink.defaultSettings, ...userSettings }; - [ 'title', 'text' ].forEach( function( propertyName ) { - settings[ propertyName ] = settings[ propertyName ].replace( '#', '' ); - } ); + [ 'title', 'text' ].forEach( ( propertyName ) => settings[ propertyName ] = settings[ propertyName ].replace( '#', '' ) ); settings.classPrefixLength = settings.classPrefix.length; }; - var init = function() { + const init = function() { initSettings(); run(); @@ -111,21 +107,19 @@ }; window.ShareLink.getNetworkLink = function( networkName, settings ) { - var link = ShareLink.networkTemplates[ networkName ].replace( /{([^}]+)}/g, function( fullMatch, pureMatch ) { + let link = ShareLink.networkTemplates[ networkName ].replace( /{([^}]+)}/g, ( fullMatch, pureMatch ) => { return settings[ pureMatch ] || ''; } ); if ( 'email' === networkName ) { if ( -1 < settings['title'].indexOf( '&' ) || -1 < settings['text'].indexOf( '&' ) ) { - var emailSafeSettings = { + const emailSafeSettings = { text: settings['text'].replace( new RegExp('&', 'g'), '%26' ), title: settings['title'].replace( new RegExp('&', 'g'), '%26' ), url: settings['url'], }; - link = ShareLink.networkTemplates[ networkName ].replace( /{([^}]+)}/g, function( fullMatch, pureMatch ) { - return emailSafeSettings[ pureMatch ]; - } ); + link = ShareLink.networkTemplates[ networkName ].replace( /{([^}]+)}/g, ( fullMatch, pureMatch ) => emailSafeSettings[ pureMatch ] ); } if ( link.indexOf( '?subject=&body') ) { @@ -138,15 +132,15 @@ return link; }; - Element.prototype.shareLink = function( settings ) { + Element.prototype.shareLink = function ( settings ) { new ShareLink( this, settings ); return this; }; - NodeList.prototype.shareLink = function( settings ) { - this.forEach(function( element) { + NodeList.prototype.shareLink = function ( settings ) { + this.forEach( ( element ) => { new ShareLink( element, settings ); - }); + } ); return this; }; } )(); diff --git a/assets/lib/share-link/share-link.min.js b/assets/lib/share-link/share-link.min.js index 70eacf398605..d9bc66bbdf6c 100644 --- a/assets/lib/share-link/share-link.min.js +++ b/assets/lib/share-link/share-link.min.js @@ -1 +1 @@ -window.t=function(t,e){var i,n=function(t){return t.substr(0,settings.i)===settings.u?t.substr(settings.i):null},r=function(e){i.addEventListener("click",function(){s(e)}),"button"===i.getAttribute("role")&&i.addEventListener("keyup",t=>{13!==t.keyCode&&32!==t.keyCode||(t.preventDefault(),s(e))})},s=function(t){var e="",i=(settings.width&&settings.height&&(i=screen.width/2-settings.width/2,e="toolbar=0,status=0,width="+settings.width+",height="+settings.height+",top="+(screen.height/2-settings.height/2)+",left="+i),ShareLink.l(t,settings)),t=/^https?:\/\//.test(i);open(i,t?"":"_self",e)};settings={...ShareLink.o,...e},["title","text"].forEach(function(t){settings[t]=settings[t].replace("#","")}),settings.i=settings.u.length,i.classList.forEach(function(){var t=n(this);if(t)return r(t),!1})},window.t.h={p:"https://twitter.com/intent/tweet?text={text} {url}",g:"https://x.com/intent/tweet?text={text} {url}",m:"https://www.pinterest.com/pin/create/button/?url={url}&media={image}",k:"https://www.facebook.com/sharer.php?u={url}",v:"https://threads.net/intent/post?text={text} {url}",L:"https://vkontakte.ru/share.php?url={url}&title={title}&description={text}&image={image}",S:"https://www.linkedin.com/shareArticle?mini=true&url={url}&title={title}&summary={text}&source={url}",j:"https://connect.ok.ru/offer?url={url}&title={title}&imageUrl={image}",A:"https://tumblr.com/share/link?url={url}",R:"https://plus.google.com/share?url={url}",_:"https://digg.com/submit?url={url}",N:"https://reddit.com/submit?url={url}&title={title}",P:"https://www.stumbleupon.com/submit?url={url}",U:"https://getpocket.com/edit?url={url}",q:"https://api.whatsapp.com/send?text=*{title}*%0A{text}%0A{url}",B:"https://www.xing.com/spi/shares/new?url={url}",print:"javascript:print()",email:"mailto:?subject={title}&body={text}%0A{url}",C:"https://telegram.me/share/url?url={url}&text={text}",D:"https://web.skype.com/share?url={url}"},window.t.o={title:"",text:"",F:"",url:location.href,u:"s_",width:640,height:480},window.t.l=function(t,i){var n,e=ShareLink.h[t].replace(/{([^}]+)}/g,function(t,e){return i[e]||""});return"email"===t&&((-1n(e)),"button"===i.getAttribute("role")&&i.addEventListener("keyup",t=>{13!==t.keyCode&&32!==t.keyCode||(t.preventDefault(),n(e))})},n=function(t){let e="";settings.width&&settings.height&&(i=screen.width/2-settings.width/2,e="toolbar=0,status=0,width="+settings.width+",height="+settings.height+",top="+(screen.height/2-settings.height/2)+",left="+i);var i=ShareLink.u(t,settings),t=/^https?:\/\//.test(i);open(i,t?"":"_self",e)};settings={...ShareLink.o,...e},["title","text"].forEach(t=>settings[t]=settings[t].replace("#","")),settings.i=settings.l.length,function(){i.classList.forEach(()=>{var t=s(this);if(t)return r(t),!1})}()},window.t.h={p:"https://twitter.com/intent/tweet?text={text} {url}",g:"https://x.com/intent/tweet?text={text} {url}",m:"https://www.pinterest.com/pin/create/button/?url={url}&media={image}",k:"https://www.facebook.com/sharer.php?u={url}",L:"https://threads.net/intent/post?text={text} {url}",S:"https://vkontakte.ru/share.php?url={url}&title={title}&description={text}&image={image}",v:"https://www.linkedin.com/shareArticle?mini=true&url={url}&title={title}&summary={text}&source={url}",j:"https://connect.ok.ru/offer?url={url}&title={title}&imageUrl={image}",A:"https://tumblr.com/share/link?url={url}",R:"https://plus.google.com/share?url={url}",_:"https://digg.com/submit?url={url}",N:"https://reddit.com/submit?url={url}&title={title}",P:"https://www.stumbleupon.com/submit?url={url}",U:"https://getpocket.com/edit?url={url}",q:"https://api.whatsapp.com/send?text=*{title}*%0A{text}%0A{url}",B:"https://www.xing.com/spi/shares/new?url={url}",print:"javascript:print()",email:"mailto:?subject={title}&body={text}%0A{url}",C:"https://telegram.me/share/url?url={url}&text={text}",D:"https://web.skype.com/share?url={url}"},window.t.o={title:"",text:"",F:"",url:location.href,l:"s_",width:640,height:480},window.t.u=function(t,s){let e=ShareLink.h[t].replace(/{([^}]+)}/g,(t,e)=>s[e]||"");if("email"!==t)return e;if(-1i[e])}return e=e.indexOf("?subject=&body")?e.replace("subject=&",""):e},Element.prototype.G=function(t){return new ShareLink(this,t),this},NodeList.prototype.G=function(e){return this.forEach(t=>{new ShareLink(t,e)}),this}; \ No newline at end of file