UNPKG

videojs-contextmenu-pt

Version:

A cross-device context menu UI for video.js players.

3 lines (2 loc) 4.3 kB
/*! @name videojs-contextmenu-pt @version 5.4.1 @license Apache-2.0 */ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("video.js"),require("global/document"),require("global/window")):"function"==typeof define&&define.amd?define(["video.js","global/document","global/window"],t):e.videojsContextmenuPt=t(e.videojs,e.document,e.window)}(this,function(s,l,p){"use strict";function o(e,t){e.prototype=Object.create(t.prototype),(e.prototype.constructor=e).__proto__=t}s=s&&s.hasOwnProperty("default")?s.default:s,l=l&&l.hasOwnProperty("default")?l.default:l,p=p&&p.hasOwnProperty("default")?p.default:p;var i=function(n){function e(){return n.apply(this,arguments)||this}return o(e,n),e.prototype.handleClick=function(e){var t=this;n.prototype.handleClick.call(this),this.options_.listener(),p.setTimeout(function(){t.player().contextmenuUI.menu.dispose()},1)},e}(s.getComponent("MenuItem")),e=s.getComponent("Menu"),n=s.dom||s,c=function(t){function e(n,e){var o;return(o=t.call(this,n,e)||this).dispose=s.bind(function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(o),o.dispose),e.content.forEach(function(e){var t=function(){};"function"==typeof e.listener?t=e.listener:"string"==typeof e.href&&(t=function(){return p.open(e.href)}),o.addItem(new i(n,{label:e.label,listener:s.bind(n,t)}))}),o}return o(e,t),e.prototype.createEl=function(){var e=t.prototype.createEl.call(this);return n.addClass(e,"vjs-contextmenu-ui-menu"),e.style.left=this.options_.position.left+"px",e.style.top=this.options_.position.top+"px",e},e}(e);function a(e,t){var n={},o=function(e){var t;if(e.getBoundingClientRect&&e.parentNode&&(t=e.getBoundingClientRect()),!t)return{left:0,top:0};var n=l.documentElement,o=l.body,i=n.clientLeft||o.clientLeft||0,r=p.pageXOffset||o.scrollLeft,u=t.left+r-i,s=n.clientTop||o.clientTop||0,c=p.pageYOffset||o.scrollTop,a=t.top+c-s;return{left:Math.round(u),top:Math.round(a)}}(e),i=e.offsetWidth,r=e.offsetHeight,u=o.top,s=o.left,c=t.pageY,a=t.pageX;return t.changedTouches&&(a=t.changedTouches[0].pageX,c=t.changedTouches[0].pageY),n.y=Math.max(0,Math.min(1,(u-c+r)/r)),n.x=Math.max(0,Math.min(1,(a-s)/i)),n}var r="5.4.1";function d(e){return e.hasOwnProperty("contextmenuUI")&&e.contextmenuUI.hasOwnProperty("menu")&&e.contextmenuUI.menu.el()}function u(e){var t=e.tagName.toLowerCase();return"input"===t||"textarea"===t}function h(e){var t=this;if(d(this))this.contextmenuUI.menu.dispose();else if(!this.contextmenuUI.options_.excludeElements(e.target)){var n=function(e,t){return{left:Math.round(t.width*e.x),top:Math.round(t.height-t.height*e.y)}}(a(this.el(),e),this.el().getBoundingClientRect()),o=s.browser.IS_FIREFOX?l.documentElement:l;e.preventDefault();var i=this.contextmenuUI.menu=new c(this,{content:function(e){return e&&"[object Function]"==={}.toString.call(e)}(this.contextmenuUI.content)&&this.contextmenuUI.content()||this.contextmenuUI.content,position:n});this.contextmenuUI.closeMenu=function(){s.log.warn("player.contextmenuUI.closeMenu() is deprecated, please use player.contextmenuUI.menu.dispose() instead!"),i.dispose()},i.on("dispose",function(){s.off(o,["click","tap"],i.dispose),t.removeChild(i),delete t.contextmenuUI.menu}),this.addChild(i);var r=i.el_.getBoundingClientRect(),u=l.body.getBoundingClientRect();(this.contextmenuUI.keepInside||r.right>u.width||r.bottom>u.height)&&(i.el_.style.left=Math.floor(Math.min(n.left,this.player_.currentWidth()-i.currentWidth()))+"px",i.el_.style.top=Math.floor(Math.min(n.top,this.player_.currentHeight()-i.currentHeight()))+"px"),s.on(o,["click","tap"],i.dispose)}}function f(e){var t=this,n={keepInside:!0,excludeElements:u};if(e=s.mergeOptions(n,e),!Array.isArray(e.content)&&!Array.isArray(e.content()))throw new Error('"content" required');d(this)&&(this.contextmenuUI.menu.dispose(),this.off("contextmenu",this.contextmenuUI.onContextMenu),delete this.contextmenuUI);var o=this.contextmenuUI=function(){f.apply(this,arguments)};o.onContextMenu=s.bind(this,h),o.content=e.content,o.keepInside=e.keepInside,o.options_=e,o.VERSION=r,this.on("contextmenu",o.onContextMenu),this.ready(function(){return t.addClass("vjs-contextmenu-ui")})}return s.registerPlugin("contextmenuUI",f),f.VERSION=r,f});