Skip to content

Commit

Permalink
Added option for having multiple instance
Browse files Browse the repository at this point in the history
Added option for having multiple instance and removed some useless code
  • Loading branch information
ymlsudhanshu committed Oct 19, 2013
1 parent dd103cf commit 8fe624d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 20 deletions.
28 changes: 12 additions & 16 deletions contextMenu.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
*contextMenu.js v 1.0.3
*contextMenu.js v 1.0.32
*Author: Sudhanshu Yadav
*s-yadav.github.com
*Copyright (c) 2013 Sudhanshu Yadav.
Expand Down Expand Up @@ -47,6 +47,7 @@
horAdjust: 0,
top: 'auto',
left: 'auto',
closeOther:true, //to close other already opened context menu
containment: window,
winEventClose: true,
sizeStyle: 'auto', //allowed values are auto and content (popup size will be according content size)
Expand Down Expand Up @@ -120,10 +121,13 @@
newElm = this.filter(function () {
return $(this).data('iw-menuData') == null;
})
//to change basetrigger on refresh
menuData.option.baseTrigger =this;
iMethods.contextMenuBind.call(newElm, menuData.menuSelector, menuData.option);
},
//to get value of a key
value: function (key) {
var menuData = $(this).data('iw-menuData');
var menuData = this.data('iw-menuData');
if (menuData[key]) {
return menuData[key];
} else if (menuData.option) {
Expand Down Expand Up @@ -175,11 +179,6 @@
//get base trigger
var baseTrigger = option.baseTrigger;

//to add current menu.
if (baseTrigger.index(trigger) != -1) {
menu.addClass('iw-curMenu');
}


if (!menuData) {
var menuId;
Expand Down Expand Up @@ -248,7 +247,7 @@
});
},
eventHandler: function (e) {
e.preventDefault();
e.preventDefault();
var trigger = $(this),
trgrData = trigger.data('iw-menuData'),
menu = trgrData.menu,
Expand All @@ -264,7 +263,7 @@
btChck = option.baseTrigger.index(trigger) == -1;

//to close previous open menu.
if (!btChck) {
if (!btChck && option.closeOther) {
$('.iw-contextMenu').css('display', 'none');
}

Expand Down Expand Up @@ -460,17 +459,14 @@
}



$(document.documentElement).unbind('keyup', iMethods.keyEvent);
$(document).unbind('click', iMethods.clickEvent);
var dataParm = {
trigger: trigger,
menu: menu,
option: option,
method: trgrData.method
}
$(document).click(dataParm, iMethods.clickEvent);
$(document.documentElement).keyup(dataParm, iMethods.keyEvent);
$('html').unbind('click', iMethods.clickEvent).click(dataParm, iMethods.clickEvent);
$(document.documentElement).unbind('keyup', iMethods.keyEvent).keyup(dataParm, iMethods.keyEvent);
if (option.winEventClose) {
$(window).bind('scroll resize', dataParm, iMethods.scrollEvent);
}
Expand Down Expand Up @@ -566,7 +562,7 @@

//unbind all events from top DOM
$(document.documentElement).unbind('keyup', iMethods.keyEvent);
$(document).unbind('click', iMethods.clickEvent);
$('html').unbind('click', iMethods.clickEvent);
$(window).unbind('scroll resize', iMethods.scrollEvent);
$('.iw-contextMenu').hide();
$(document).focus();
Expand Down Expand Up @@ -721,4 +717,4 @@
return option;
},
}
})(jQuery, window, document);
})(jQuery, window, document);
4 changes: 2 additions & 2 deletions contextMenu.js.jquery.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "contextMenu.js",
"version": "1.0.31",
"version": "1.0.32",
"title": "A light weight multi functional context menu plugin",
"author": {
"name": "Sudhanshu Yadav",
Expand All @@ -19,7 +19,7 @@
"dependencies": {
"jquery": ">=1.6"
},
"keywords":["context","submenu","window","jquery","popup","menu","tooltip"],
"keywords":["context-menu","contextmenu","right-click-menu","context","submenu","jquery","popup","menu","tooltip"],
"demo": "http://s-yadav.github.io/contextMenu.html#demo",
"docs": "http://s-yadav.github.io/contextMenu.html#documentation",
"homepage": "http://s-yadav.github.io/contextMenu.html",
Expand Down
Loading

0 comments on commit 8fe624d

Please sign in to comment.