diff --git a/contextMenu.css b/contextMenu.css index 8184256..65cc595 100644 --- a/contextMenu.css +++ b/contextMenu.css @@ -64,6 +64,6 @@ height: 20px; left: 0px; top: 3px; - + position: absolute; } /*context menu css end */ \ No newline at end of file diff --git a/contextMenu.js b/contextMenu.js index 39d5d94..2123675 100644 --- a/contextMenu.js +++ b/contextMenu.js @@ -103,7 +103,7 @@ var name = selector[i].name, disable = selector[i].disable, fun = selector[i].fun, - ico = selector[i].ico, + icon = selector[i].icon, img = selector[i].img, title = selector[i].title, className = selector[i].className, @@ -126,42 +126,21 @@ //update class name className != undefined && elm.attr('class', className); - //update image + var imgIcon = elm.find('.iw-mIcon'); + if(imgIcon.length) imgIcon[0].remove(); + + //update image or icon if (img) { - var imgIcon = elm.find('.iw-mIcon'); - if (imgIcon.length) { - imgIcon[0].src = img; - } else { - elm.prepend(''); - } + elm.prepend(''); + } else if (icon) { + elm.prepend(''); } - - //update ico - if (ico) { - var imgIcon = elm.find('.iw-mIcon'); - if (imgIcon.length) { - if(imgIcon[0].tagName.toLowerCase() === "span"){ - var classList = ["iw-mIcon"]; - if(typeof ico == "string") - classList.push(ico); - else - classList.push.apply(classList, ico); - imgIcon[0].classList = classList - } else { - imgIcon[0].remove() - elm.prepend(''); - } - } else { - elm.prepend(''); - } - } - + //to change submenus if (subMenu) { elm.contextMenu('update', subMenu); } } - } iMethods.onOff(menu); @@ -702,7 +681,7 @@ fun = selObj.fun || function() {}, subMenu = selObj.subMenu, img = selObj.img || '', - ico = selObj.ico || '', + icon = selObj.icon || '', title = selObj.title || "", className = selObj.className || "", disable = selObj.disable, @@ -710,9 +689,9 @@ if (img) { list.prepend(''); - } else if (ico) { - list.prepend(''); - } + } else if (icon) { + list.prepend(''); + } //to add disable if (disable) { list.addClass('iw-mDisable'); diff --git a/contextMenu.less b/contextMenu.less index d083e78..60ff1b3 100644 --- a/contextMenu.less +++ b/contextMenu.less @@ -16,63 +16,63 @@ @color6: #e6e6e6; // Appears 1 time .iw-contextMenu { - -moz-box-shadow: 1px 1px 2px rgba(0, 0, 0, 0.2); - -webkit-box-shadow: 1px 1px 2px rgba(0, 0, 0, 0.2); - border: 1px solid @color6; - box-shadow: 1px 1px 2px rgba(0, 0, 0, 0.2); - display: none; - z-index: 1000; - li.iw-mDisable { - opacity: .3; - } + -moz-box-shadow: 1px 1px 2px rgba(0, 0, 0, 0.2); + -webkit-box-shadow: 1px 1px 2px rgba(0, 0, 0, 0.2); + border: 1px solid @color6; + box-shadow: 1px 1px 2px rgba(0, 0, 0, 0.2); + display: none; + z-index: 1000; + li.iw-mDisable { + opacity: .3; + } } .iw-cm-menu { - background: @color5; - color: @color0; - margin: 0px; - padding: 0px; - li { - border-bottom: 1px solid @color4; - cursor: pointer; - list-style: none; - padding-left: 30px; - padding-right: 20px; - padding-top: 5px; - padding-bottom: 5px; - position: relative; - } + background: @color5; + color: @color0; + margin: 0px; + padding: 0px; + li { + border-bottom: 1px solid @color4; + cursor: pointer; + list-style: none; + padding-left: 30px; + padding-right: 20px; + padding-top: 5px; + padding-bottom: 5px; + position: relative; + } } .iw-mOverlay { - background: @color1; - height: 100%; - left: 0px; - opacity: .5; - position: absolute; - top: 0px; - width: 100%; + background: @color1; + height: 100%; + left: 0px; + opacity: .5; + position: absolute; + top: 0px; + width: 100%; } .iw-mSelected { - background-color: @color2; - color: @color3; + background-color: @color2; + color: @color3; } .iw-cm-arrow-right { - border-bottom: 5px solid transparent; - border-left: 5px solid @color0; - border-top: 5px solid transparent; - height: 0; - margin-top: -3px; - position: absolute; - right: 3px; - top: 50%; - width: 0; + border-bottom: 5px solid transparent; + border-left: 5px solid @color0; + border-top: 5px solid transparent; + height: 0; + margin-top: -3px; + position: absolute; + right: 3px; + top: 50%; + width: 0; } .iw-mSelected>.iw-cm-arrow-right { - border-left: 5px solid @color1; + border-left: 5px solid @color1; } .iw-mIcon { - height: 20px; - left: 0px; - top: 3px; - width: 20px; - position: absolute; + height: 20px; + left: 0px; + top: 3px; + width: 20px; + position: absolute; } \ No newline at end of file diff --git a/contextMenu.min.css b/contextMenu.min.css index c12d569..7ca335a 100644 --- a/contextMenu.min.css +++ b/contextMenu.min.css @@ -6,4 +6,4 @@ *Dual licensed under the MIT and GPL licenses */ /*Context menu css */ -.iw-contextMenu{-webkit-box-shadow:1px 1px 2px rgba(0,0,0,.2);-moz-box-shadow:1px 1px 2px rgba(0,0,0,.2);box-shadow:1px 1px 2px rgba(0,0,0,.2);border:1px solid #E6E6E6;display:none;z-index:1000}.iw-cm-menu{background:#F4F4F4;color:#333;margin:0;padding:0}.iw-cm-menu li{list-style:none;padding:3px 20px 3px 30px;border-bottom:1px solid #CCC;cursor:pointer;position:relative}.iw-mOverlay{position:absolute;width:100%;height:100%;top:0;left:0;background:#FFF;opacity:.5}.iw-contextMenu li.iw-mDisable{opacity:.3}.iw-mSelected{background-color:#036;color:#F2F2F2}.iw-cm-arrow-right{width:0;height:0;border-top:5px solid transparent;border-bottom:5px solid transparent;border-left:5px solid #333;position:absolute;right:3px;top:50%;margin-top:-3px}.iw-mSelected>.iw-cm-arrow-right{border-left:5px solid #FFF}.iw-mIcon{width:20px;height:20px;left:0;top:3px} \ No newline at end of file +.iw-mIcon,.iw-mOverlay{left:0;position:absolute}.iw-contextMenu{-webkit-box-shadow:1px 1px 2px rgba(0,0,0,.2);-moz-box-shadow:1px 1px 2px rgba(0,0,0,.2);box-shadow:1px 1px 2px rgba(0,0,0,.2);border:1px solid #E6E6E6;display:none;z-index:1000}.iw-cm-menu{background:#F4F4F4;color:#333;margin:0;padding:0}.iw-cm-menu li{list-style:none;padding:3px 20px 3px 30px;border-bottom:1px solid #CCC;cursor:pointer;position:relative}.iw-mOverlay{width:100%;height:100%;top:0;background:#FFF;opacity:.5}.iw-contextMenu li.iw-mDisable{opacity:.3}.iw-mSelected{background-color:#036;color:#F2F2F2}.iw-cm-arrow-right{width:0;height:0;border-top:5px solid transparent;border-bottom:5px solid transparent;border-left:5px solid #333;position:absolute;right:3px;top:50%;margin-top:-3px}.iw-mSelected>.iw-cm-arrow-right{border-left:5px solid #FFF}.iw-mIcon{width:20px;height:20px;top:3px} \ No newline at end of file diff --git a/contextMenu.min.js b/contextMenu.min.js index dff1579..2e1b907 100644 --- a/contextMenu.min.js +++ b/contextMenu.min.js @@ -5,4 +5,4 @@ *Copyright (c) 2013-2015 Sudhanshu Yadav. *Dual licensed under the MIT and GPL licenses */ -!function(a,b,c,d){"use strict";a.single=function(){var b=a({});return function(a){return b[0]=a,b}}(),a.fn.contextMenu=function(b,c,d){e[b]?c&&(c instanceof Array||"string"==typeof c||c.nodeType||c.jquery||(d=c,c=null)):(d=c,c=b,b="popup"),c instanceof Array&&"update"!=b&&(b="menu");var g=d;return a.inArray(b,["menu","popup","close","destroy"])>-1?(d=f.optionOtimizer(b,d),this.each(function(){var f=a(this);g=a.extend({},a.fn.contextMenu.defaults,d),g.baseTrigger||(g.baseTrigger=f),e[b].call(f,c,g)})):e[b].call(this,c,g),this},a.fn.contextMenu.defaults={triggerOn:"click",subMenuTriggerOn:"hover click",displayAround:"cursor",mouseClick:"left",verAdjust:0,horAdjust:0,top:"auto",left:"auto",closeOther:!0,containment:b,winEventClose:!0,position:"auto",closeOnClick:!0,onOpen:function(a,b){},afterOpen:function(a,b){},onClose:function(a,b){}};var e={menu:function(a,b){a=f.createMenuList(this,a,b),f.contextMenuBind.call(this,a,b,"menu")},popup:function(b,c){a(b).addClass("iw-contextMenu"),f.contextMenuBind.call(this,b,c,"popup")},update:function(b,c){var e=this;c=c||{},this.each(function(){var g=a(this),h=g.data("iw-menuData");h||(e.contextMenu("refresh"),h=g.data("iw-menuData"));var i=h.menu;if("object"==typeof b)for(var j=0;j')}if(n){var t=r.find(".iw-mIcon");if(t.length)if("span"===t[0].tagName.toLowerCase()){var u=["iw-mIcon"];"string"==typeof n?u.push(n):u.push.apply(u,n),t[0].classList=u}else t[0].remove(),r.prepend('');else r.prepend('')}s&&r.contextMenu("update",s)}f.onOff(i);var v=c.triggerOn;if(v){g.unbind(".contextMenu"),v=v.split(" ");for(var w=[],j=0,x=v.length;jp&&(y-t<0?z-pq&&(x-u<0?A-qp&&(y-t<0?z-pq&&(x-u<0?A-q');if(a.each(d,function(b,c){var d=c.name,h=c.fun||function(){},j=c.subMenu,k=c.img||"",l=c.ico||"",m=c.title||"",n=c.className||"",o=c.disable,p=a('
  • '+d+"
  • ");k?p.prepend(''):l&&p.prepend(''),o&&p.addClass("iw-mDisable"),j||p.bind("click.contextMenu",function(a){h.call(this,{trigger:g,menu:i},a)}),i.append(p),j&&(p.addClass("iw-has-submenu").append('
    '),f.subMenu(p,j,g,e))}),g.index(c[0])==-1)c.append(i);else{var j=e.containment==b?"body":e.containment;a(j).append(i)}return f.onOff(a("#iw-contextMenu"+h)),"#iw-contextMenu"+h}if(0!=a(d).length){var k=a(d);return k.removeClass("iw-contextMenuCurrent").addClass("iw-contextMenu iw-cm-menu iw-contextMenu"+h).attr("menuId","iw-contextMenu"+h).css("display","none"),k.find("ul").each(function(b,c){var d=a(this),h=d.parent("li");h.append('
    '),d.addClass("iw-contextMenuCurrent"),f.subMenu(h,".iw-contextMenuCurrent",g,e)}),f.onOff(a(".iw-contextMenu"+h)),".iw-contextMenu"+h}},subMenu:function(a,b,c,d){a.contextMenu("menu",b,{triggerOn:d.subMenuTriggerOn,displayAround:"trigger",position:"auto",mouseClick:"left",baseTrigger:c,containment:d.containment})},onOff:function(b){b.find(".iw-mOverlay").remove(),b.find(".iw-mDisable").each(function(){var b=a(this);b.append('
    '),b.find(".iw-mOverlay").bind("click mouseenter",function(a){a.stopPropagation()})})},optionOtimizer:function(b,c){if(c)return"menu"==b&&(c.mouseClick||(c.mouseClick="right")),"right"==c.mouseClick&&"click"==c.triggerOn&&(c.triggerOn="contextmenu"),a.inArray(c.triggerOn,["hover","mouseenter","mouseover","mouseleave","mouseout","focusin","focusout"])!=-1&&(c.displayAround="trigger"),c}}}(jQuery,window,document); \ No newline at end of file +!function(a,b,c,d){"use strict";a.single=function(){var b=a({});return function(a){return b[0]=a,b}}(),a.fn.contextMenu=function(b,c,d){e[b]?c&&(c instanceof Array||"string"==typeof c||c.nodeType||c.jquery||(d=c,c=null)):(d=c,c=b,b="popup"),c instanceof Array&&"update"!=b&&(b="menu");var g=d;return a.inArray(b,["menu","popup","close","destroy"])>-1?(d=f.optionOtimizer(b,d),this.each(function(){var f=a(this);g=a.extend({},a.fn.contextMenu.defaults,d),g.baseTrigger||(g.baseTrigger=f),e[b].call(f,c,g)})):e[b].call(this,c,g),this},a.fn.contextMenu.defaults={triggerOn:"click",subMenuTriggerOn:"hover click",displayAround:"cursor",mouseClick:"left",verAdjust:0,horAdjust:0,top:"auto",left:"auto",closeOther:!0,containment:b,winEventClose:!0,position:"auto",closeOnClick:!0,onOpen:function(a,b){},afterOpen:function(a,b){},onClose:function(a,b){}};var e={menu:function(a,b){a=f.createMenuList(this,a,b),f.contextMenuBind.call(this,a,b,"menu")},popup:function(b,c){a(b).addClass("iw-contextMenu"),f.contextMenuBind.call(this,b,c,"popup")},update:function(b,c){var e=this;c=c||{},this.each(function(){var g=a(this),h=g.data("iw-menuData");h||(e.contextMenu("refresh"),h=g.data("iw-menuData"));var i=h.menu;if("object"==typeof b)for(var j=0;j'):n&&r.prepend(''),s&&r.contextMenu("update",s)}f.onOff(i);var u=c.triggerOn;if(u){g.unbind(".contextMenu"),u=u.split(" ");for(var v=[],j=0,w=u.length;jp&&(y-t<0?z-pq&&(x-u<0?A-qp&&(y-t<0?z-pq&&(x-u<0?A-q');if(a.each(d,function(b,c){var d=c.name,h=c.fun||function(){},j=c.subMenu,k=c.img||"",l=c.icon||"",m=c.title||"",n=c.className||"",o=c.disable,p=a('
  • '+d+"
  • ");k?p.prepend(''):l&&p.prepend(''),o&&p.addClass("iw-mDisable"),j||p.bind("click.contextMenu",function(a){h.call(this,{trigger:g,menu:i},a)}),i.append(p),j&&(p.addClass("iw-has-submenu").append('
    '),f.subMenu(p,j,g,e))}),g.index(c[0])==-1)c.append(i);else{var j=e.containment==b?"body":e.containment;a(j).append(i)}return f.onOff(a("#iw-contextMenu"+h)),"#iw-contextMenu"+h}if(0!=a(d).length){var k=a(d);return k.removeClass("iw-contextMenuCurrent").addClass("iw-contextMenu iw-cm-menu iw-contextMenu"+h).attr("menuId","iw-contextMenu"+h).css("display","none"),k.find("ul").each(function(b,c){var d=a(this),h=d.parent("li");h.append('
    '),d.addClass("iw-contextMenuCurrent"),f.subMenu(h,".iw-contextMenuCurrent",g,e)}),f.onOff(a(".iw-contextMenu"+h)),".iw-contextMenu"+h}},subMenu:function(a,b,c,d){a.contextMenu("menu",b,{triggerOn:d.subMenuTriggerOn,displayAround:"trigger",position:"auto",mouseClick:"left",baseTrigger:c,containment:d.containment})},onOff:function(b){b.find(".iw-mOverlay").remove(),b.find(".iw-mDisable").each(function(){var b=a(this);b.append('
    '),b.find(".iw-mOverlay").bind("click mouseenter",function(a){a.stopPropagation()})})},optionOtimizer:function(b,c){if(c)return"menu"==b&&(c.mouseClick||(c.mouseClick="right")),"right"==c.mouseClick&&"click"==c.triggerOn&&(c.triggerOn="contextmenu"),a.inArray(c.triggerOn,["hover","mouseenter","mouseover","mouseleave","mouseout","focusin","focusout"])!=-1&&(c.displayAround="trigger"),c}}}(jQuery,window,document); \ No newline at end of file