EasyImages2.0/public/static/zui/lib/contextmenu/zui.contextmenu.min.js

7 lines
3.5 KiB
JavaScript

/*!
* ZUI: 右键菜单 - v1.9.2 - 2020-07-09
* http://openzui.com
* GitHub: https://github.com/easysoft/zui.git
* Copyright (c) 2020 cnezsoft.com; Licensed MIT
*/
!function(t,e){"use strict";var n="zui.contextmenu",i={duration:200},o=!1,a={},r="zui-contextmenu-"+t.zui.uuid(),u=0,s=0,d=function(){return t(document).off("mousemove."+n).on("mousemove."+n,function(t){u=t.clientX,s=t.clientY}),a},l=function(e,n){if("string"==typeof e&&(e="seperator"===e||"divider"===e||"-"===e||"|"===e?{type:"seperator"}:{label:e,id:n}),"seperator"===e.type||"divider"===e.type)return t('<li class="divider"></li>');var i=t("<a/>").attr({href:e.url||"###","class":e.className,style:e.style}).data("item",e);return e.html?e.html===!0?i.html(e.label||e.text):i=t(e.html):i.text(e.label||e.text),e.onClick&&i.on("click",e.onClick),t("<li />").toggleClass("disabled",e.disabled===!0).append(i)},c=null,m=function(e,n){"function"==typeof e&&(n=e,e=null),c&&(clearTimeout(c),c=null);var i=t("#"+r);if(i.length){var o=i.data("options");if(!e||o.id===e){var u=function(){i.hide(),o.onHidden&&o.onHidden(),n&&n()};o.onHide&&o.onHide();var s=o.animation;i.removeClass("in"),s?c=setTimeout(u,o.duration):u()}}return a},f=function(d,f,h){t.isPlainObject(d)&&(h=f,f=d,d=f.items),o=!0,f=t.extend({},i,f);var p=f.x,v=f.y;p===e&&(p=(f.event||f).clientX),p===e&&(p=u),v===e&&(v=(f.event||f).clientY),v===e&&(v=s);var x=t("#"+r);x.length||(x=t('<div style="display: none; position: fixed; z-index: 2000;" class="contextmenu" id="'+r+'"><ul class="dropdown-menu contextmenu-menu"></ul></div>').appendTo("body"));var y=x.find(".contextmenu-menu").off("click."+n).on("click."+n,"a",function(e){var n=t(this),i=f.onClickItem&&f.onClickItem(n.data("item"),n,e);i!==!1&&m()}).empty();y.attr("class","dropdown-menu contextmenu-menu"+(f.className?" "+f.className:"")),x.hide().attr("class","contextmenu");var w=f.itemCreator||l,g=typeof d;"string"===g?d=d.split(","):"function"===g&&(d=d(f)),t.each(d,function(t,e){y.append(w(e,t,f))});var C=f.animation,b=f.duration;C===!0&&(f.animation=C="fade"),c&&(clearTimeout(c),c=null);var H=function(){x.addClass("in"),f.onShown&&f.onShown(),h&&h()};f.onShow&&f.onShow(),x.data("options",{animation:C,onHide:f.onHide,onHidden:f.onHidden,id:f.id,duration:b});var k=t(window);return p=Math.max(0,Math.min(p,k.width()-y.outerWidth())),v=Math.max(0,Math.min(v,k.height()-y.outerHeight())),x.css({left:p,top:v}),C?(x.addClass("open").addClass(C).show(),c=setTimeout(function(){H(),o=!1},f.duration)):(x.addClass("open").show(),H(),c=setTimeout(function(){o=!1},200)),a};t(document).on("click",function(e){o||t(e.target).closest(".contextmenu").length||m()}),t.extend(a,{NAME:n,DEFAULTS:i,show:f,hide:m,listenMouse:d}),t.zui({ContextMenu:a});var h=function(e,i){var o=this;o.name=n,o.$=t(e),i=o.options=t.extend({trigger:"contextmenu"},a.DEFAULTS,this.$.data(),i);var r=i.trigger;o.id=t.zui.uuid();var u=function(t){if("mousedown"!==t.type||2===t.button){var e={x:t.clientX,y:t.clientY,event:t};return i.itemsCreator&&(e.items=i.itemsCreator.call(this,t)),o.show(e),t.preventDefault(),t.returnValue=!1,!1}},s=r+"."+n;i.selector?o.$.on(s,i.selector,u):o.$.on(s,u)};h.prototype.destory=function(){that.$.off("."+n)},h.prototype.hide=function(t){a.hide(this.id,t)},h.prototype.show=function(e,n){e=t.extend({},this.options,e),a.show(e,n)},t.fn.contextmenu=function(e){return this.each(function(){var i=t(this),o=i.data(n),a="object"==typeof e&&e;o||i.data(n,o=new h(this,a)),"string"==typeof e&&o[e]()})},t.fn.contextmenu.Constructor=h}(jQuery,void 0);