/** * videojs-share * @version 1.1.0 * @copyright 2018 Mikhail Khazov * @license MIT */ !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.videojsShare=e()}(this,function(){"use strict";function t(t,e){return e={exports:{}},t(e,e.exports),e.exports}function e(t){var e;if("SELECT"===t.nodeName)t.focus(),e=t.value;else if("INPUT"===t.nodeName||"TEXTAREA"===t.nodeName){var n=t.hasAttribute("readonly");n||t.setAttribute("readonly",""),t.select(),t.setSelectionRange(0,t.value.length),n||t.removeAttribute("readonly"),e=t.value}else{t.hasAttribute("contenteditable")&&t.focus();var i=window.getSelection(),r=document.createRange();r.selectNodeContents(t),i.removeAllRanges(),i.addRange(r),e=i.toString()}return e}function n(){}function i(t,e){for(;t&&t.nodeType!==D;){if("function"==typeof t.matches&&t.matches(e))return t;t=t.parentNode}}function r(t,e,n,i,r){var a=o.apply(this,arguments);return t.addEventListener(n,a,r),{destroy:function(){t.removeEventListener(n,a,r)}}}function o(t,e,n,i){return function(n){n.delegateTarget=W(n.target,e),n.delegateTarget&&i.call(t,n)}}function a(t,e,n){if(!t&&!e&&!n)throw new Error("Missing required arguments");if(!q.string(e))throw new TypeError("Second argument must be a String");if(!q.fn(n))throw new TypeError("Third argument must be a Function");if(q.node(t))return s(t,e,n);if(q.nodeList(t))return l(t,e,n);if(q.string(t))return c(t,e,n);throw new TypeError("First argument must be a String, HTMLElement, HTMLCollection, or NodeList")}function s(t,e,n){return t.addEventListener(e,n),{destroy:function(){t.removeEventListener(e,n)}}}function l(t,e,n){return Array.prototype.forEach.call(t,function(t){t.addEventListener(e,n)}),{destroy:function(){Array.prototype.forEach.call(t,function(t){t.removeEventListener(e,n)})}}}function c(t,e,n){return X(document.body,t,e,n)}function u(t){return Object.keys(t).filter(function(e){return void 0!==t[e]&&""!==t[e]}).map(function(e){return encodeURIComponent(e)+"="+encodeURIComponent(t[e])}).join("&")}function h(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e=t.fbAppId,n=t.url,i=t.redirectUri;if(!e)throw new Error("fbAppId is not defined");var r=u({app_id:e,display:"popup",redirect_uri:i,link:n});return window.open("https://www.facebook.com/dialog/feed?"+r,"_blank",K)}function d(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e=t.fbAppId,n=t.url,i=t.hashtag,r=t.redirectUri;if(!e)throw new Error("fbAppId is not defined");var o=u({app_id:e,display:"popup",redirect_uri:r,href:n,hashtag:i});return window.open("https://www.facebook.com/dialog/share?"+o,"_blank",K)}function f(){var t=(arguments.length>0&&void 0!==arguments[0]?arguments[0]:{}).url;if(!t)throw new Error("url is not defined");var e=u({kid_directed_site:"0",sdk:"joey",u:t,display:"popup",ref:"plugin",src:"share_button"});return window.open("https://www.facebook.com/sharer/sharer.php?"+e,"_blank",K)}function p(){var t=u({url:(arguments.length>0&&void 0!==arguments[0]?arguments[0]:{}).url});return window.open("https://plus.google.com/share?"+t,"_blank",K)}function v(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e=u({share_url:t.url,title:t.title,description:t.description,imageurl:t.image});return window.open("http://connect.mail.ru/share?"+e,"_blank",K)}function g(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e=u({"st.cmd":"addShare","st._surl":t.url,title:t.title});return window.open("https://ok.ru/dk?"+e,"_blank",K)}function w(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e=u({url:t.url,text:t.title});return window.open("https://t.me/share/url?"+e,"_blank",K)}function m(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e=u({text:t.title,url:t.url});return window.open("https://twitter.com/intent/tweet?"+e,"_blank",K)}function y(){var t=u({url:(arguments.length>0&&void 0!==arguments[0]?arguments[0]:{}).url});return window.open("https://www.reddit.com/submit?"+t,"_blank",K)}function b(){return!!window.navigator.userAgent.match(/Version\/[\d.]+.*Safari/)}function k(t){return b()?window.open(t):window.location.assign(t)}function _(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e=t.url,n=t.title;if(!e&&!n)throw new Error("url and title not specified");return k("viber://forward?"+u({text:[n,e].filter(function(t){return t}).join(" ")}))}function C(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e=t.url,n=t.image,i=t.isVkParse,r=t.description,o=t.title;r&&r.length>Q&&(r=r.substr(0,Q)+"..."),o&&o.length>Q&&(o=o.substr(0,Q)+"...");return"https://vk.com/share.php?"+u(i?{url:e}:{url:e,title:o,description:r,image:n,noparse:!0})}function x(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return window.open(C(t),"_blank",K)}function E(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e=t.phone,n=u({text:[t.title,t.url].filter(function(t){return t}).join(" "),phone:e});return window.open("https://api.whatsapp.com/send?"+n,"_blank",K)}function j(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e=t.title,n=t.url,i=u({title:e,summary:t.description,url:n});return window.open("https://www.linkedin.com/shareArticle?mini=true&"+i,"_blank",K)}function S(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e=t.fbAppId,n=t.url;if(!e)throw new Error("fbAppId is not defined");var i=u({app_id:e,link:n});return window.location.assign("fb-messenger://share?"+i)}function F(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e=t.title,n=t.url;if(!n)throw new Error("url is not defined");var i=encodeURIComponent(""+n);return e&&(i=""+encodeURIComponent(e+" ")+i),window.open("https://line.me/R/msg/text/?"+i,"_blank",K)}function T(){return"ontouchstart"in window||navigator.MaxTouchPoints>0||navigator.msMaxTouchPoints>0}function A(){return/Android/.test(window.navigator.userAgent)||/iP(hone|ad|od)/i.test(window.navigator.userAgent)}function z(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];return A()?t:t.filter(function(t){return!["whatsapp","viber","messenger"].includes(t)})}var M=function(){return window.location.href}(),O={title:"Video",url:M,socials:["fbFeed","tw","reddit","gp","messenger","linkedin","vk","ok","mail","telegram","whatsapp","viber"],embedCode:function(){return""}(),redirectUri:function(){return M+"#close_window"}()},L=function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")},H=function(){function t(t,e){for(var n=0;n0&&void 0!==arguments[0]?arguments[0]:{};this.action=t.action,this.container=t.container,this.emitter=t.emitter,this.target=t.target,this.text=t.text,this.trigger=t.trigger,this.selectedText=""}},{key:"initSelection",value:function(){this.text?this.selectFake():this.target&&this.selectTarget()}},{key:"selectFake",value:function(){var t=this,e="rtl"==document.documentElement.getAttribute("dir");this.removeFake(),this.fakeHandlerCallback=function(){return t.removeFake()},this.fakeHandler=this.container.addEventListener("click",this.fakeHandlerCallback)||!0,this.fakeElem=document.createElement("textarea"),this.fakeElem.style.fontSize="12pt",this.fakeElem.style.border="0",this.fakeElem.style.padding="0",this.fakeElem.style.margin="0",this.fakeElem.style.position="absolute",this.fakeElem.style[e?"right":"left"]="-9999px";var n=window.pageYOffset||document.documentElement.scrollTop;this.fakeElem.style.top=n+"px",this.fakeElem.setAttribute("readonly",""),this.fakeElem.value=this.text,this.container.appendChild(this.fakeElem),this.selectedText=(0,i.default)(this.fakeElem),this.copyText()}},{key:"removeFake",value:function(){this.fakeHandler&&(this.container.removeEventListener("click",this.fakeHandlerCallback),this.fakeHandler=null,this.fakeHandlerCallback=null),this.fakeElem&&(this.container.removeChild(this.fakeElem),this.fakeElem=null)}},{key:"selectTarget",value:function(){this.selectedText=(0,i.default)(this.target),this.copyText()}},{key:"copyText",value:function(){var t=void 0;try{t=document.execCommand(this.action)}catch(e){t=!1}this.handleResult(t)}},{key:"handleResult",value:function(t){this.emitter.emit(t?"success":"error",{action:this.action,text:this.selectedText,trigger:this.trigger,clearSelection:this.clearSelection.bind(this)})}},{key:"clearSelection",value:function(){this.trigger&&this.trigger.focus(),window.getSelection().removeAllRanges()}},{key:"destroy",value:function(){this.removeFake()}},{key:"action",set:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"copy";if(this._action=t,"copy"!==this._action&&"cut"!==this._action)throw new Error('Invalid "action" value, use either "copy" or "cut"')},get:function(){return this._action}},{key:"target",set:function(t){if(void 0!==t){if(!t||"object"!==(void 0===t?"undefined":r(t))||1!==t.nodeType)throw new Error('Invalid "target" value, use a valid Element');if("copy"===this.action&&t.hasAttribute("disabled"))throw new Error('Invalid "target" attribute. Please use "readonly" instead of "disabled" attribute');if("cut"===this.action&&(t.hasAttribute("readonly")||t.hasAttribute("disabled")))throw new Error('Invalid "target" attribute. You can\'t cut text from elements with "readonly" or "disabled" attributes');this._target=t}},get:function(){return this._target}}]),t}();t.exports=a})});n.prototype={on:function(t,e,n){var i=this.e||(this.e={});return(i[t]||(i[t]=[])).push({fn:e,ctx:n}),this},once:function(t,e,n){function i(){r.off(t,i),e.apply(n,arguments)}var r=this;return i._=e,this.on(t,i,n)},emit:function(t){var e=[].slice.call(arguments,1),n=((this.e||(this.e={}))[t]||[]).slice(),i=0,r=n.length;for(i;i0&&void 0!==arguments[0]?arguments[0]:{};this.action="function"==typeof t.action?t.action:this.defaultAction,this.target="function"==typeof t.target?t.target:this.defaultTarget,this.text="function"==typeof t.text?t.text:this.defaultText,this.container="object"===d(t.container)?t.container:document.body}},{key:"listenClick",value:function(t){var e=this;this.listener=(0,h.default)(t,"click",function(t){return e.onClick(t)})}},{key:"onClick",value:function(t){var e=t.delegateTarget||t.currentTarget;this.clipboardAction&&(this.clipboardAction=null),this.clipboardAction=new c.default({action:this.action(e),target:this.target(e),text:this.text(e),container:this.container,trigger:e,emitter:this})}},{key:"defaultAction",value:function(t){return l("action",t)}},{key:"defaultTarget",value:function(t){var e=l("target",t);if(e)return document.querySelector(e)}},{key:"defaultText",value:function(t){return l("text",t)}},{key:"destroy",value:function(){this.listener.destroy(),this.clipboardAction&&(this.clipboardAction.destroy(),this.clipboardAction=null)}}],[{key:"isSupported",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:["copy","cut"],e="string"==typeof t?[t]:t,n=!!document.queryCommandSupported;return e.forEach(function(t){n=n&&!!document.queryCommandSupported(t)}),n}}]),e}(u.default);t.exports=p})})),K="scrollbars=0, resizable=1, menubar=0, left=100, top=100, width=550, height=440, toolbar=0, status=0",Q=80,Z=(Object.freeze||Object)({fbFeed:h,fbShare:d,fbButton:f,gp:p,mail:v,ok:g,telegram:w,tw:m,reddit:y,viber:_,getVkUrl:C,vk:x,whatsapp:E,linkedin:j,messenger:S,line:F}),$={fbFeed:'\n \n\n',tw:'\n \n\n',reddit:'\n \n\n',gp:'\n \n\n',messenger:'\n \n \n\n',linkedin:'\n \n\n',vk:'\n \n\n',ok:'\n \n\n',mail:'\n \n\n',telegram:'\n \n\n',whatsapp:'\n \n\n',viber:'\n \n\n'},tt=function(){function t(e,n){L(this,t),this.player=e,this.options=n,this.socials=z(n.socials),this.copyBtnTextClass="vjs-share__btn-text",this.socialBtnClass="vjs-share__social",this._createContent(),this._initToggle(),this._initClipboard(),this._initSharing()}return t.prototype.getContent=function(){return this.content},t.prototype._createContent=function(){var t='\n \n \n \n '+this.player.localize("Copy")+"\n ",e=document.createElement("div");e.innerHTML='
\n \n\n
\n \n \n\n \n \n
\n\n
\n
\n '+this._getSocialItems().join("")+"\n
\n
\n
",this.content=e.firstChild},t.prototype._initClipboard=function(){var t=this;new J(".vjs-share__btn",{target:function(t){return t.previousElementSibling}}).on("success",function(e){var n=e.trigger.querySelector("."+t.copyBtnTextClass),i=function(){n.innerText=t.player.localize("Copy"),e.clearSelection()};n.innerText=t.player.localize("Copied"),T()?setTimeout(i,1e3):n.parentElement.addEventListener("mouseleave",function(){setTimeout(i,300)})})},t.prototype._initSharing=function(){var t=this,e=this.content.querySelectorAll("."+this.socialBtnClass);Array.from(e).forEach(function(e){e.addEventListener("click",function(e){var n=e.currentTarget.getAttribute("data-social");"function"==typeof Z[n]&&Z[n](t.socialOptions)})})},t.prototype._initToggle=function(){var t=this.content.querySelector(".vjs-share__socials");this.socials.length>10||window.innerWidth<=180&&this.socials.length>6?t.style.height="calc((2em + 5px) * 2)":t.classList.add("horizontal")},t.prototype._getSocialItems=function(){var t=[];return this.socials.forEach(function(e){$[e]&&t.push('\n \n ")}),t},H(t,[{key:"socialOptions",get:function(){var t=this.options;return{url:t.url,title:t.title,description:t.description,image:t.image,fbAppId:t.fbAppId,isVkParse:t.isVkParse,redirectUri:t.redirectUri}}}]),t}(),et=function(t){function e(n,i){L(this,e);var r=V(this,t.call(this,n,i));return r.player=n,r.options=i,r}return I(e,t),e.prototype._createModal=function(){var t=new tt(this.player,this.options).getContent();this.modal=new R(this.player,{content:t,temporary:!0}),this.el=this.modal.contentEl(),this.player.addChild(this.modal)},e.prototype.open=function(){this._createModal(),this.modal.open()},e}(videojs.getComponent("Component")),nt=videojs.registerPlugin||videojs.plugin,it=function(t,e){t.addClass("vjs-videojs-share"),t.getChild("controlBar").addChild("ShareButton",e),t.addChild("ShareOverlay",e)},rt=function(t){it(this,videojs.mergeOptions(O,t))};return videojs.registerComponent("ShareButton",P),videojs.registerComponent("ShareOverlay",et),nt("share",rt),rt.VERSION="1.1.0",rt});