diff --git a/dist/ax5menu.js b/dist/ax5menu.js index d09170e..0bd1c01 100644 --- a/dist/ax5menu.js +++ b/dist/ax5menu.js @@ -8,7 +8,7 @@ UI.addClass({ className: "menu", - version: "1.3.69" + version: "${VERSION}" }, function () { /** * @class ax5.ui.menu @@ -135,7 +135,7 @@ */ var ax5menu = function ax5menu() { var self = this, - cfg; + cfg = void 0; this.instanceId = ax5.getGuid(); this.config = { @@ -202,8 +202,8 @@ }, popup = function popup(opt, items, depth, path) { var data = opt, - activeMenu, - removed; + activeMenu = void 0, + removed = void 0; data.theme = opt.theme || cfg.theme; data.cfg = { @@ -252,12 +252,12 @@ var depth = this.getAttribute("data-menu-item-depth"), index = this.getAttribute("data-menu-item-index"), path = this.getAttribute("data-menu-item-path"), - $this, - offset, - scrollTop, - childOpt, - _items, - _activeMenu; + $this = void 0, + offset = void 0, + scrollTop = void 0, + childOpt = void 0, + _items = void 0, + _activeMenu = void 0; if (depth != null && typeof depth != "undefined") { _items = self.queue[depth].data[cfg.columnKeys.items][index][cfg.columnKeys.items]; @@ -310,7 +310,7 @@ var depth = this.getAttribute("data-menu-item-depth"), index = this.getAttribute("data-menu-item-index"), path = this.getAttribute("data-menu-item-path"), - _items; + _items = void 0; _items = self.queue[depth].data[cfg.columnKeys.items][index][cfg.columnKeys.items]; if (_items && _items.length > 0) {} else { @@ -362,7 +362,7 @@ if (target) { item = function (path) { if (!path) return false; - var item; + var item = void 0; try { item = Function("", "return this.config.items[" + path.substring(5).replace(/\./g, '].' + cfg.columnKeys.items + '[') + "];").call(self); } catch (e) { @@ -423,7 +423,6 @@ return this; }, align = function align(activeMenu, data) { - //console.log(data['@parent']); var $window = jQuery(window), $document = jQuery(document), wh = cfg.position == "fixed" ? $window.height() : $document.height(), @@ -503,6 +502,9 @@ theme: cfg.theme }; + e.left -= 5; + e.top -= 5; + if (cfg.offset) { if (cfg.offset.left) e.left += cfg.offset.left; if (cfg.offset.top) e.top += cfg.offset.top; @@ -538,8 +540,8 @@ //opt = null; } } - }; - var updateTheme = function updateTheme(theme) { + }, + updateTheme = function updateTheme(theme) { if (theme) cfg.theme = theme; }; @@ -549,13 +551,15 @@ opt = getOption[typeof e.clientX == "undefined" ? "object" : "event"].call(this, e, opt); updateTheme(opt.theme); - var items = [].concat(cfg.items); + var items = [].concat(cfg.items), + _filteringItem = void 0; + if (opt.filter) { - var filteringItem = function filteringItem(_items) { + _filteringItem = function filteringItem(_items) { var arr = []; _items.forEach(function (n) { if (n.items && n.items.length > 0) { - n.items = filteringItem(n.items); + n.items = _filteringItem(n.items); } if (opt.filter.call(n)) { arr.push(n); @@ -563,16 +567,19 @@ }); return arr; }; - items = filteringItem(items); + items = _filteringItem(items); } if (items.length) { popup.call(this, opt, items, 0); // 0 is seq of queue - appEventAttach.call(this, true); // 이벤트 연결 + + if (this.popupEventAttachTimer) clearTimeout(this.popupEventAttachTimer); + this.popupEventAttachTimer = setTimeout(function () { + appEventAttach.call(this, true); // 이벤트 연결 + }.bind(this), 500); } e = null; - //opt = null; return this; }; }(); diff --git a/dist/ax5menu.min.js b/dist/ax5menu.min.js index cfd524d..ad8fcaf 100644 --- a/dist/ax5menu.min.js +++ b/dist/ax5menu.min.js @@ -1 +1,2 @@ -"use strict";!function(){var e,t=ax5.ui,n=ax5.util;t.addClass({className:"menu",version:"1.3.69"},function(){var i=function(){var i,u=this;this.instanceId=ax5.getGuid(),this.config={theme:"default",iconWidth:22,acceleratorWidth:100,menuBodyPadding:5,offset:{left:0,top:0},position:"fixed",animateTime:250,items:[],itemClickAndClose:!0,columnKeys:{label:"label",items:"items"}},this.openTimer=null,this.closeTimer=null,this.queue=[],this.menuBar={},this.state=void 0,i=this.config;var l=function(e){e?(jQuery(document).unbind("click.ax5menu-"+this.menuId).bind("click.ax5menu-"+this.menuId,o.bind(this)),jQuery(window).unbind("keydown.ax5menu-"+this.menuId).bind("keydown.ax5menu-"+this.menuId,function(e){e.which==ax5.info.eventKeys.ESC&&u.close()}),jQuery(window).unbind("resize.ax5menu-"+this.menuId).bind("resize.ax5menu-"+this.menuId,function(e){u.close()})):(jQuery(document).unbind("click.ax5menu-"+this.menuId),jQuery(window).unbind("keydown.ax5menu-"+this.menuId),jQuery(window).unbind("resize.ax5menu-"+this.menuId))},a=function(e,t){return e&&e.onStateChanged?e.onStateChanged.call(t,t):this.onStateChanged&&this.onStateChanged.call(t,t),u.state=t.state,e=null,t=null,!0},c=function(e){return this.onLoad&&this.onLoad.call(e,e),e=null,!0},s=function d(t,n,l,s){var o,r,h=t;return h.theme=t.theme||i.theme,h.cfg={icons:jQuery.extend({},i.icons),iconWidth:t.iconWidth||i.iconWidth,acceleratorWidth:t.acceleratorWidth||i.acceleratorWidth},n.forEach(function(e){e.html||e.divide?(e["@isMenu"]=!1,e.html&&(e["@html"]=e.html.call({item:e,config:i,opt:t}))):e["@isMenu"]=!0}),h[i.columnKeys.items]=n,h["@depth"]=l,h["@path"]=s||"root",h["@hasChild"]=function(){return this[i.columnKeys.items]&&this[i.columnKeys.items].length>0},o=jQuery(e.tmpl.get.call(this,"tmpl",h,i.columnKeys)),jQuery(document.body).append(o),r=this.queue.splice(l),r.forEach(function(e){e.$target.remove()}),this.queue.push({$target:o,data:jQuery.extend({},h)}),o.find("[data-menu-item-index]").bind("mouseover",function(){var e,n,l,a,c,s,o=this.getAttribute("data-menu-item-depth"),m=this.getAttribute("data-menu-item-index"),r=this.getAttribute("data-menu-item-path");null!=o&&"undefined"!=typeof o&&(c=u.queue[o].data[i.columnKeys.items][m][i.columnKeys.items],s=u.queue[o].$target,s.find("[data-menu-item-index]").removeClass("hover"),jQuery(this).addClass("hover"),s.attr("data-selected-menu-item-index")!=m&&(s.attr("data-selected-menu-item-index",m),c&&c.length>0?(e=jQuery(this),n=e.offset(),l="fixed"==i.position?jQuery(document).scrollTop():0,a={"@parent":{left:n.left,top:n.top,width:e.outerWidth(),height:e.outerHeight()},left:n.left+e.outerWidth()-i.menuBodyPadding,top:n.top-i.menuBodyPadding-1-l},a=jQuery.extend(!0,t,a),d.call(u,a,c,Number(o)+1,r)):u.queue.splice(Number(o)+1).forEach(function(e){e.$target.remove()}))),o=null,m=null,r=null,e=null,n=null,l=null,a=null,c=null,s=null}),o.find("[data-menu-item-index]").bind("mouseout",function(){var e,t=this.getAttribute("data-menu-item-depth"),n=this.getAttribute("data-menu-item-index");this.getAttribute("data-menu-item-path");e=u.queue[t].data[i.columnKeys.items][n][i.columnKeys.items],e&&e.length>0||jQuery(this).removeClass("hover")}),0==l&&(h.direction&&o.addClass("direction-"+h.direction),a.call(this,null,{self:this,items:n,parent:function(e){if(!e)return!1;var t=null;try{t=Function("","return this.config.items["+e.substring(5).replace(/\./g,"].items[")+"];").call(u)}catch(n){}return t}(h["@path"]),state:"popup"})),m.call(this,o,h),c.call(this,{self:this,items:n,element:o.get(0)}),h=null,o=null,r=null,t=null,n=null,l=null,s=null,this},o=function(e,t,l){if(t=n.findParentNode(e.target,function(e){if(e.getAttribute("data-menu-item-index"))return!0})){if(l=function(e){if(!e)return!1;var t;try{t=Function("","return this.config.items["+e.substring(5).replace(/\./g,"]."+i.columnKeys.items+"[")+"];").call(u)}catch(n){console.log(ax5.info.getError("ax5menu","501","menuItemClick"))}try{return t}finally{t=null}}(t.getAttribute("data-menu-item-path")),!l)return this;l.check&&(function(e){var t={checkbox:function(e){this.checked=!e},radio:function(t){var n=this.name;e.forEach(function(e){e.check&&"radio"===e.check.type&&e.check.name==n&&(e.check.checked=!1)}),this.checked=!t}};t[this.type]&&t[this.type].call(this,this.checked),t=null}.call(l.check,i.items),i.itemClickAndClose||u.queue.forEach(function(e){e.$target.find("[data-menu-item-index]").each(function(){var t=e.data[i.columnKeys.items][this.getAttribute("data-menu-item-index")];t.check&&jQuery(this).find(".item-checkbox-wrap").attr("data-item-checked",t.check.checked)})})),u.onClick&&u.onClick.call(l,l),l[i.columnKeys.items]&&0!=l[i.columnKeys.items].length||!i.itemClickAndClose||u.close()}else u.close();return t=null,l=null,this},m=function(e,t){var n=jQuery(window),u=jQuery(document),l="fixed"==i.position?n.height():u.height(),a=n.width(),c=e.outerHeight(),s=e.outerWidth(),o=t.left,m=t.top,d=i.position||"fixed";return o+s>a&&(o=t["@parent"]?t["@parent"].left-s+i.menuBodyPadding:a-s),m+c>l&&(m=l-c),e.css({left:o,top:m,position:d}),e=null,t=null,n=null,u=null,l=null,a=null,c=null,s=null,o=null,m=null,d=null,this};this.init=function(){u.menuId=ax5.getGuid(),this.onStateChanged=i.onStateChanged,this.onClick=i.onClick,this.onLoad=i.onLoad,a.call(this,null,{self:this,state:"init"})},this.popup=function(){var e={event:function(e,t){e={left:e.clientX,top:"fixed"==i.position?e.clientY:e.pageY,width:i.width,theme:i.theme},i.offset&&(i.offset.left&&(e.left+=i.offset.left),i.offset.top&&(e.top+=i.offset.top)),t=jQuery.extend(!0,e,t);try{return t}finally{e=null}},object:function(e,t){e={left:e.left,top:e.top,width:e.width||i.width,theme:e.theme||i.theme},i.offset&&(i.offset.left&&(e.left+=i.offset.left),i.offset.top&&(e.top+=i.offset.top)),t=jQuery.extend(!0,e,t);try{return t}finally{e=null}}},t=function(e){e&&(i.theme=e)};return function(n,u){if(!n)return this;u=e["undefined"==typeof n.clientX?"object":"event"].call(this,n,u),t(u.theme);var a=[].concat(i.items);if(u.filter){var c=function o(e){var t=[];return e.forEach(function(e){e.items&&e.items.length>0&&(e.items=o(e.items)),u.filter.call(e)&&t.push(e)}),t};a=c(a)}return a.length&&(s.call(this,u,a,0),l.call(this,!0)),n=null,this}}(),this.attach=function(){var t={object:function(e,t){e={left:e.left,top:e.top,width:e.width||i.width,theme:e.theme||i.theme,direction:e.direction||i.direction},t=jQuery.extend(!0,t,e);try{return t}finally{e=null,t=null}}},a=function(e,n,a){var c=jQuery(e),o=c.offset(),m=c.outerHeight(),d=Number(e.getAttribute("data-menu-item-index")),r="fixed"==i.position?jQuery(document).scrollTop():0;if(i.items&&i.items[d][i.columnKeys.items]&&i.items[d][i.columnKeys.items].length){if(u.menuBar.openedIndex==d)return"click"==a&&u.close(),!1;u.menuBar.target.find("[data-menu-item-index]").removeClass("hover"),u.menuBar.opened=!0,u.menuBar.openedIndex=d,c.attr("data-menu-item-opened","true"),c.addClass("hover"),i.offset&&(i.offset.left&&(o.left+=i.offset.left),i.offset.top&&(o.top+=i.offset.top)),n=t.object.call(this,{left:o.left,top:o.top+m-r},n),s.call(u,n,i.items[d][i.columnKeys.items],0,"root."+e.getAttribute("data-menu-item-index")),l.call(u,!0)}e=null,n=null,c=null,o=null,m=null,d=null,r=null},c=function(e,t,n){var l=jQuery(e),a=(l.offset(),l.outerHeight(),Number(e.getAttribute("data-menu-item-index")));"fixed"==i.position?jQuery(document).scrollTop():0;!i.items||i.items[a][i.columnKeys.items]&&0!=i.items[a][i.columnKeys.items].length||u.onClick&&u.onClick.call(i.items[a],i.items[a])};return function(t,l){var s,o={},m=i.items;return"undefined"==typeof l&&(l={}),o.theme=l.theme||i.theme,o.cfg={icons:jQuery.extend({},i.icons),iconWidth:l.iconWidth||i.iconWidth,acceleratorWidth:l.acceleratorWidth||i.acceleratorWidth},m.forEach(function(e){e.html||e.divide?(e["@isMenu"]=!1,e.html&&(e["@html"]=e.html.call({item:e,config:i,opt:l}))):e["@isMenu"]=!0}),o[i.columnKeys.items]=m,s=jQuery(e.tmpl.get.call(this,"tmplMenubar",o,i.columnKeys)),u.menuBar={target:jQuery(t),opened:!1},u.menuBar.target.html(s),u.menuBar.target.bind("click",function(e){if(!e)return this;var t=n.findParentNode(e.target,function(e){if(e.getAttribute("data-menu-item-index"))return!0});t&&(c(t,l,"click"),a(t,l,"click")),t=null}),u.menuBar.target.bind("mouseover",function(e){if(!u.menuBar.opened)return!1;var t=n.findParentNode(e.target,function(e){if(e.getAttribute("data-menu-item-index"))return!0});t&&a(t,l,"mouseover"),t=null}),t=null,l=null,o=null,m=null,s=null,this}}(),this.close=function(){return u.menuBar&&u.menuBar.target&&(u.menuBar.target.find("[data-menu-item-index]").removeClass("hover"),u.menuBar.opened=!1,u.menuBar.openedIndex=null),l.call(this,!1),this.queue.forEach(function(e){e.$target.remove()}),this.queue=[],a.call(this,null,{self:this,state:"close"}),this},this.getCheckValue=function(){var e={},t=function(i){for(var u=i.length;u--;)i[u].check&&i[u].check.checked&&(e[i[u].check.name]?(n.isString(e[i[u].check.name])&&(e[i[u].check.name]=[e[i[u].check.name]]),e[i[u].check.name].push(i[u].check.value)):e[i[u].check.name]=i[u].check.value),i[u].items&&i[u].items.length>0&&t(i[u].items)};t(i.items);try{return e}finally{e=null,t=null}},this.main=function(){t.menu_instance=t.menu_instance||[],t.menu_instance.push(this),arguments&&n.isObject(arguments[0])&&this.setConfig(arguments[0])}.apply(this,arguments)};return i}()),e=ax5.ui.menu}(),function(){var e=ax5.ui.menu,t=function(e){return'\n
\n '},n=function(e){return'\n \n "};e.tmpl={tmpl:t,tmplMenubar:n,get:function(t,n,i){return ax5.mustache.render(e.tmpl[t].call(this,i),n)}}}(); \ No newline at end of file +"use strict";!function(){var e,t=ax5.ui,n=ax5.util;t.addClass({className:"menu",version:"${VERSION}"},function(){var i=function(){var i=this,u=void 0;this.instanceId=ax5.getGuid(),this.config={theme:"default",iconWidth:22,acceleratorWidth:100,menuBodyPadding:5,offset:{left:0,top:0},position:"fixed",animateTime:250,items:[],itemClickAndClose:!0,columnKeys:{label:"label",items:"items"}},this.openTimer=null,this.closeTimer=null,this.queue=[],this.menuBar={},this.state=void 0,u=this.config;var l=function(e){e?(jQuery(document).unbind("click.ax5menu-"+this.menuId).bind("click.ax5menu-"+this.menuId,o.bind(this)),jQuery(window).unbind("keydown.ax5menu-"+this.menuId).bind("keydown.ax5menu-"+this.menuId,function(e){e.which==ax5.info.eventKeys.ESC&&i.close()}),jQuery(window).unbind("resize.ax5menu-"+this.menuId).bind("resize.ax5menu-"+this.menuId,function(e){i.close()})):(jQuery(document).unbind("click.ax5menu-"+this.menuId),jQuery(window).unbind("keydown.ax5menu-"+this.menuId),jQuery(window).unbind("resize.ax5menu-"+this.menuId))},a=function(e,t){return e&&e.onStateChanged?e.onStateChanged.call(t,t):this.onStateChanged&&this.onStateChanged.call(t,t),i.state=t.state,e=null,t=null,!0},c=function(e){return this.onLoad&&this.onLoad.call(e,e),e=null,!0},s=function d(t,n,l,s){var o=t,r=void 0,h=void 0;return o.theme=t.theme||u.theme,o.cfg={icons:jQuery.extend({},u.icons),iconWidth:t.iconWidth||u.iconWidth,acceleratorWidth:t.acceleratorWidth||u.acceleratorWidth},n.forEach(function(e){e.html||e.divide?(e["@isMenu"]=!1,e.html&&(e["@html"]=e.html.call({item:e,config:u,opt:t}))):e["@isMenu"]=!0}),o[u.columnKeys.items]=n,o["@depth"]=l,o["@path"]=s||"root",o["@hasChild"]=function(){return this[u.columnKeys.items]&&this[u.columnKeys.items].length>0},r=jQuery(e.tmpl.get.call(this,"tmpl",o,u.columnKeys)),jQuery(document.body).append(r),h=this.queue.splice(l),h.forEach(function(e){e.$target.remove()}),this.queue.push({$target:r,data:jQuery.extend({},o)}),r.find("[data-menu-item-index]").bind("mouseover",function(){var e=this.getAttribute("data-menu-item-depth"),n=this.getAttribute("data-menu-item-index"),l=this.getAttribute("data-menu-item-path"),a=void 0,c=void 0,s=void 0,o=void 0,m=void 0,r=void 0;null!=e&&"undefined"!=typeof e&&(m=i.queue[e].data[u.columnKeys.items][n][u.columnKeys.items],r=i.queue[e].$target,r.find("[data-menu-item-index]").removeClass("hover"),jQuery(this).addClass("hover"),r.attr("data-selected-menu-item-index")!=n&&(r.attr("data-selected-menu-item-index",n),m&&m.length>0?(a=jQuery(this),c=a.offset(),s="fixed"==u.position?jQuery(document).scrollTop():0,o={"@parent":{left:c.left,top:c.top,width:a.outerWidth(),height:a.outerHeight()},left:c.left+a.outerWidth()-u.menuBodyPadding,top:c.top-u.menuBodyPadding-1-s},o=jQuery.extend(!0,t,o),d.call(i,o,m,Number(e)+1,l)):i.queue.splice(Number(e)+1).forEach(function(e){e.$target.remove()}))),e=null,n=null,l=null,a=null,c=null,s=null,o=null,m=null,r=null}),r.find("[data-menu-item-index]").bind("mouseout",function(){var e=this.getAttribute("data-menu-item-depth"),t=this.getAttribute("data-menu-item-index"),n=(this.getAttribute("data-menu-item-path"),void 0);n=i.queue[e].data[u.columnKeys.items][t][u.columnKeys.items],n&&n.length>0||jQuery(this).removeClass("hover")}),0==l&&(o.direction&&r.addClass("direction-"+o.direction),a.call(this,null,{self:this,items:n,parent:function(e){if(!e)return!1;var t=null;try{t=Function("","return this.config.items["+e.substring(5).replace(/\./g,"].items[")+"];").call(i)}catch(n){}return t}(o["@path"]),state:"popup"})),m.call(this,r,o),c.call(this,{self:this,items:n,element:r.get(0)}),o=null,r=null,h=null,t=null,n=null,l=null,s=null,this},o=function(e,t,l){if(t=n.findParentNode(e.target,function(e){if(e.getAttribute("data-menu-item-index"))return!0})){if(l=function(e){if(!e)return!1;var t=void 0;try{t=Function("","return this.config.items["+e.substring(5).replace(/\./g,"]."+u.columnKeys.items+"[")+"];").call(i)}catch(n){console.log(ax5.info.getError("ax5menu","501","menuItemClick"))}try{return t}finally{t=null}}(t.getAttribute("data-menu-item-path")),!l)return this;l.check&&(function(e){var t={checkbox:function(e){this.checked=!e},radio:function(t){var n=this.name;e.forEach(function(e){e.check&&"radio"===e.check.type&&e.check.name==n&&(e.check.checked=!1)}),this.checked=!t}};t[this.type]&&t[this.type].call(this,this.checked),t=null}.call(l.check,u.items),u.itemClickAndClose||i.queue.forEach(function(e){e.$target.find("[data-menu-item-index]").each(function(){var t=e.data[u.columnKeys.items][this.getAttribute("data-menu-item-index")];t.check&&jQuery(this).find(".item-checkbox-wrap").attr("data-item-checked",t.check.checked)})})),i.onClick&&i.onClick.call(l,l),l[u.columnKeys.items]&&0!=l[u.columnKeys.items].length||!u.itemClickAndClose||i.close()}else i.close();return t=null,l=null,this},m=function(e,t){var n=jQuery(window),i=jQuery(document),l="fixed"==u.position?n.height():i.height(),a=n.width(),c=e.outerHeight(),s=e.outerWidth(),o=t.left,m=t.top,d=u.position||"fixed";return o+s>a&&(o=t["@parent"]?t["@parent"].left-s+u.menuBodyPadding:a-s),m+c>l&&(m=l-c),e.css({left:o,top:m,position:d}),e=null,t=null,n=null,i=null,l=null,a=null,c=null,s=null,o=null,m=null,d=null,this};this.init=function(){i.menuId=ax5.getGuid(),this.onStateChanged=u.onStateChanged,this.onClick=u.onClick,this.onLoad=u.onLoad,a.call(this,null,{self:this,state:"init"})},this.popup=function(){var e={event:function(e,t){e={left:e.clientX,top:"fixed"==u.position?e.clientY:e.pageY,width:u.width,theme:u.theme},e.left-=5,e.top-=5,u.offset&&(u.offset.left&&(e.left+=u.offset.left),u.offset.top&&(e.top+=u.offset.top)),t=jQuery.extend(!0,e,t);try{return t}finally{e=null}},object:function(e,t){e={left:e.left,top:e.top,width:e.width||u.width,theme:e.theme||u.theme},u.offset&&(u.offset.left&&(e.left+=u.offset.left),u.offset.top&&(e.top+=u.offset.top)),t=jQuery.extend(!0,e,t);try{return t}finally{e=null}}},t=function(e){e&&(u.theme=e)};return function(n,i){if(!n)return this;i=e["undefined"==typeof n.clientX?"object":"event"].call(this,n,i),t(i.theme);var a=[].concat(u.items),c=void 0;return i.filter&&(c=function(e){var t=[];return e.forEach(function(e){e.items&&e.items.length>0&&(e.items=c(e.items)),i.filter.call(e)&&t.push(e)}),t},a=c(a)),a.length&&(s.call(this,i,a,0),this.popupEventAttachTimer&&clearTimeout(this.popupEventAttachTimer),this.popupEventAttachTimer=setTimeout(function(){l.call(this,!0)}.bind(this),500)),n=null,this}}(),this.attach=function(){var t={object:function(e,t){e={left:e.left,top:e.top,width:e.width||u.width,theme:e.theme||u.theme,direction:e.direction||u.direction},t=jQuery.extend(!0,t,e);try{return t}finally{e=null,t=null}}},a=function(e,n,a){var c=jQuery(e),o=c.offset(),m=c.outerHeight(),d=Number(e.getAttribute("data-menu-item-index")),r="fixed"==u.position?jQuery(document).scrollTop():0;if(u.items&&u.items[d][u.columnKeys.items]&&u.items[d][u.columnKeys.items].length){if(i.menuBar.openedIndex==d)return"click"==a&&i.close(),!1;i.menuBar.target.find("[data-menu-item-index]").removeClass("hover"),i.menuBar.opened=!0,i.menuBar.openedIndex=d,c.attr("data-menu-item-opened","true"),c.addClass("hover"),u.offset&&(u.offset.left&&(o.left+=u.offset.left),u.offset.top&&(o.top+=u.offset.top)),n=t.object.call(this,{left:o.left,top:o.top+m-r},n),s.call(i,n,u.items[d][u.columnKeys.items],0,"root."+e.getAttribute("data-menu-item-index")),l.call(i,!0)}e=null,n=null,c=null,o=null,m=null,d=null,r=null},c=function(e,t,n){var l=jQuery(e),a=(l.offset(),l.outerHeight(),Number(e.getAttribute("data-menu-item-index")));"fixed"==u.position?jQuery(document).scrollTop():0;!u.items||u.items[a][u.columnKeys.items]&&0!=u.items[a][u.columnKeys.items].length||i.onClick&&i.onClick.call(u.items[a],u.items[a])};return function(t,l){var s,o={},m=u.items;return"undefined"==typeof l&&(l={}),o.theme=l.theme||u.theme,o.cfg={icons:jQuery.extend({},u.icons),iconWidth:l.iconWidth||u.iconWidth,acceleratorWidth:l.acceleratorWidth||u.acceleratorWidth},m.forEach(function(e){e.html||e.divide?(e["@isMenu"]=!1,e.html&&(e["@html"]=e.html.call({item:e,config:u,opt:l}))):e["@isMenu"]=!0}),o[u.columnKeys.items]=m,s=jQuery(e.tmpl.get.call(this,"tmplMenubar",o,u.columnKeys)),i.menuBar={target:jQuery(t),opened:!1},i.menuBar.target.html(s),i.menuBar.target.bind("click",function(e){if(!e)return this;var t=n.findParentNode(e.target,function(e){if(e.getAttribute("data-menu-item-index"))return!0});t&&(c(t,l,"click"),a(t,l,"click")),t=null}),i.menuBar.target.bind("mouseover",function(e){if(!i.menuBar.opened)return!1;var t=n.findParentNode(e.target,function(e){if(e.getAttribute("data-menu-item-index"))return!0});t&&a(t,l,"mouseover"),t=null}),t=null,l=null,o=null,m=null,s=null,this}}(),this.close=function(){return i.menuBar&&i.menuBar.target&&(i.menuBar.target.find("[data-menu-item-index]").removeClass("hover"),i.menuBar.opened=!1,i.menuBar.openedIndex=null),l.call(this,!1),this.queue.forEach(function(e){e.$target.remove()}),this.queue=[],a.call(this,null,{self:this,state:"close"}),this},this.getCheckValue=function(){var e={},t=function(i){for(var u=i.length;u--;)i[u].check&&i[u].check.checked&&(e[i[u].check.name]?(n.isString(e[i[u].check.name])&&(e[i[u].check.name]=[e[i[u].check.name]]),e[i[u].check.name].push(i[u].check.value)):e[i[u].check.name]=i[u].check.value),i[u].items&&i[u].items.length>0&&t(i[u].items)};t(u.items);try{return e}finally{e=null,t=null}},this.main=function(){t.menu_instance=t.menu_instance||[],t.menu_instance.push(this),arguments&&n.isObject(arguments[0])&&this.setConfig(arguments[0])}.apply(this,arguments)};return i}()),e=ax5.ui.menu}(),function(){var e=ax5.ui.menu,t=function(e){return'\n \n '},n=function(e){return'\n \n "};e.tmpl={tmpl:t,tmplMenubar:n,get:function(t,n,i){return ax5.mustache.render(e.tmpl[t].call(this,i),n)}}}(); +//# sourceMappingURL=ax5menu.min.js.map diff --git a/src/ax5menu.js b/src/ax5menu.js index e812528..b7ee8a5 100644 --- a/src/ax5menu.js +++ b/src/ax5menu.js @@ -132,8 +132,7 @@ * ``` */ var ax5menu = function () { - var - self = this, + let self = this, cfg; this.instanceId = ax5.getGuid(); @@ -162,8 +161,7 @@ cfg = this.config; - var - appEventAttach = function (active) { + let appEventAttach = function (active) { if (active) { jQuery(document).unbind("click.ax5menu-" + this.menuId).bind("click.ax5menu-" + this.menuId, clickItem.bind(this)); jQuery(window).unbind("keydown.ax5menu-" + this.menuId).bind("keydown.ax5menu-" + this.menuId, function (e) { @@ -203,8 +201,7 @@ return true; }, popup = function (opt, items, depth, path) { - var - data = opt, + let data = opt, activeMenu, removed ; @@ -254,8 +251,7 @@ }); activeMenu.find('[data-menu-item-index]').bind("mouseover", function () { - var - depth = this.getAttribute("data-menu-item-depth"), + let depth = this.getAttribute("data-menu-item-depth"), index = this.getAttribute("data-menu-item-index"), path = this.getAttribute("data-menu-item-path"), $this, @@ -314,7 +310,7 @@ // mouse out activeMenu.find('[data-menu-item-index]').bind("mouseout", function () { - var depth = this.getAttribute("data-menu-item-depth"), + let depth = this.getAttribute("data-menu-item-depth"), index = this.getAttribute("data-menu-item-index"), path = this.getAttribute("data-menu-item-path"), _items; @@ -322,7 +318,7 @@ _items = self.queue[depth].data[cfg.columnKeys.items][index][cfg.columnKeys.items]; if (_items && _items.length > 0) { - }else{ + } else { jQuery(this).removeClass("hover"); } }); @@ -373,7 +369,7 @@ if (target) { item = (function (path) { if (!path) return false; - var item; + let item; try { item = (Function("", "return this.config.items[" + path.substring(5).replace(/\./g, '].' + cfg.columnKeys.items + '[') + "];")).call(self); } catch (e) { @@ -436,9 +432,7 @@ return this; }, align = function (activeMenu, data) { - //console.log(data['@parent']); - var - $window = jQuery(window), + let $window = jQuery(window), $document = jQuery(document), wh = (cfg.position == "fixed") ? $window.height() : $document.height(), ww = $window.width(), @@ -505,60 +499,63 @@ */ this.popup = (function () { - var getOption = { - 'event': function (e, opt) { - //var xOffset = Math.max(document.documentElement.scrollLeft, document.body.scrollLeft); - //var yOffset = Math.max(document.documentElement.scrollTop, document.body.scrollTop); - //console.log(e.pageY); + let getOption = { + 'event': function (e, opt) { + //var xOffset = Math.max(document.documentElement.scrollLeft, document.body.scrollLeft); + //var yOffset = Math.max(document.documentElement.scrollTop, document.body.scrollTop); + //console.log(e.pageY); + + e = { + left: e.clientX, + top: (cfg.position == "fixed") ? e.clientY : e.pageY, + width: cfg.width, + theme: cfg.theme + }; + + e.left -= 5; + e.top -= 5; + + if (cfg.offset) { + if (cfg.offset.left) e.left += cfg.offset.left; + if (cfg.offset.top) e.top += cfg.offset.top; + } + opt = jQuery.extend(true, e, opt); - e = { - left: e.clientX, - top: (cfg.position == "fixed") ? e.clientY : e.pageY, - width: cfg.width, - theme: cfg.theme - }; + try { + return opt; + } + finally { + e = null; + //opt = null; + } + }, + 'object': function (e, opt) { + e = { + left: e.left, + top: e.top, + width: e.width || cfg.width, + theme: e.theme || cfg.theme + }; + + if (cfg.offset) { + if (cfg.offset.left) e.left += cfg.offset.left; + if (cfg.offset.top) e.top += cfg.offset.top; + } - if (cfg.offset) { - if (cfg.offset.left) e.left += cfg.offset.left; - if (cfg.offset.top) e.top += cfg.offset.top; - } - opt = jQuery.extend(true, e, opt); + opt = jQuery.extend(true, e, opt); - try { - return opt; - } - finally { - e = null; - //opt = null; + try { + return opt; + } + finally { + e = null; + //opt = null; + } } }, - 'object': function (e, opt) { - e = { - left: e.left, - top: e.top, - width: e.width || cfg.width, - theme: e.theme || cfg.theme - }; - - if (cfg.offset) { - if (cfg.offset.left) e.left += cfg.offset.left; - if (cfg.offset.top) e.top += cfg.offset.top; - } - - opt = jQuery.extend(true, e, opt); - - try { - return opt; - } - finally { - e = null; - //opt = null; - } - } - }; - var updateTheme = function (theme) { - if (theme) cfg.theme = theme; - }; + updateTheme = function (theme) { + if (theme) cfg.theme = theme; + }; return function (e, opt) { @@ -566,10 +563,12 @@ opt = getOption[((typeof e.clientX == "undefined") ? "object" : "event")].call(this, e, opt); updateTheme(opt.theme); - var items = [].concat(cfg.items); + let items = [].concat(cfg.items), + filteringItem; + if (opt.filter) { - var filteringItem = function (_items) { - var arr = []; + filteringItem = function (_items) { + let arr = []; _items.forEach(function (n) { if (n.items && n.items.length > 0) { n.items = filteringItem(n.items); @@ -585,11 +584,14 @@ if (items.length) { popup.call(this, opt, items, 0); // 0 is seq of queue - appEventAttach.call(this, true); // 이벤트 연결 + + if(this.popupEventAttachTimer) clearTimeout(this.popupEventAttachTimer); + this.popupEventAttachTimer = setTimeout((function () { + appEventAttach.call(this, true); // 이벤트 연결 + }).bind(this), 500); } e = null; - //opt = null; return this; } })(); diff --git a/test/index.html b/test/index.html index 1219c67..0f3b28e 100644 --- a/test/index.html +++ b/test/index.html @@ -224,7 +224,7 @@ attached(); - $(document).bind("contextmenu", function (e) { + $(document.body).on("contextmenu", function (e) { /* menu.popup(e, {theme:"danger", filter: function(){ return true; @@ -235,7 +235,7 @@ return this.type != 1; }}); - ax5.util.stopEvent(e); + ax5.util.stopEvent(e.originalEvent); // e || {left: 'Number', top: 'Number', direction: '', width: 'Number'} }); });