Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

updating to ref latest jQuery

  • Loading branch information...
commit ba8a7316516709e4a62c907539b88c8ebbbb28f5 1 parent 8b49ed1
@addyosmani authored
Showing with 3 additions and 2 deletions.
  1. +2 −2 docs.html
  2. +1 −0  jquery.contextMenu.min.js
View
4 docs.html
@@ -6,7 +6,7 @@
<title>jQuery contextMenu Plugin</title>
<meta name="description" content="simple contextMenu generator for interactive web applications based on jQuery" />
- <script src="jquery-1.6.1.min.js" type="text/javascript"></script>
+ <script src="jquery-1.6.2.min.js" type="text/javascript"></script>
<script src="jquery.contextMenu.js" type="text/javascript"></script>
<link href="jquery.contextMenu.css" rel="stylesheet" type="text/css" />
<link href="screen.css" rel="stylesheet" type="text/css" />
@@ -15,7 +15,7 @@
<body>
<a id="github-forkme" href="http://github.com/medialize/jQuery-contextMenu"><img src="http://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png" alt="Fork me on GitHub" /></a>
<div id="container">
- <h1><a href="http://github.com/medialize/jQuery-contextMenu">jQuery contextMenu</a></h1>
+ <h1><a href="http://github.com/addyosmani/jQuery-contextMenu">jQuery contextMenu</a></h1>
<ul class="menu">
<li><a href="index.html">About</a></li>
View
1  jquery.contextMenu.min.js
@@ -0,0 +1 @@
+(function(a,b){function o(c,d,e){e||(e=0),d.each(function(){var d=a(this),f=this,g=this.nodeName.toLowerCase(),h,i;g=="label"&&d.find("input, textarea, select").length&&(h=d.text(),d=d.children().first(),f=d.get(0),g=f.nodeName.toLowerCase());switch(g){case"menu":i={name:d.attr("label"),items:{}},o(i.items,d.children(),e);break;case"a":i={name:d.text(),callback:function(){return function(){d.click()}}()};break;case"command":switch(f.type){case b:case"command":i={name:d.attr("label"),disabled:f.disabled,callback:function(){return function(){f.click()}}()};break;case"checkbox":i={type:"text",disabled:f.disabled,name:d.attr("label"),selected:f.checked};break;case"radio":i={type:"text",disabled:f.disabled,name:d.attr("label"),radio:f.radiogroup,value:f.id,selected:f.checked};break;default:i=b}break;case"menuitem":switch(f.type){case b:case"menuitem":i={name:d.attr("label"),disabled:f.disabled,callback:function(){return function(){f.click()}}()};break;case"checkbox":i={type:"text",disabled:f.disabled,name:d.attr("label"),selected:f.checked};break;case"radio":i={type:"text",disabled:f.disabled,name:d.attr("label"),radio:f.radiogroup,value:f.id,selected:f.checked};break;default:i=b}break;case"hr":i="-------";break;case"input":switch(d.attr("type")){case"text":i={type:"text",name:h||n(f),value:d.val()};break;case"checkbox":i={type:"text",name:h||n(f),selected:f.checked};break;case"radio":i={type:"text",name:h||n(f),radio:f.name,value:d.val(),selected:f.checked};break;default:i=b}break;case"select":i={type:"select",name:h||n(f),selected:d.val(),options:{}},d.children().each(function(){i.options[this.value]=a(this).text()});break;case"textarea":i={type:"textarea",name:h||n(f),value:d.val()};break;case"label":break;default:i={type:"html",html:d.clone(!0)}}i&&(e++,c["key"+e]=i)})}function n(b){return b.id&&a('label[for="'+b.id+'"]').val()||b.name}var c=null,d=!1,e=!1,f=0,g={},h={},i={selector:null,appendTo:null,trigger:"right",autoHide:!1,ignoreRightClick:!1,delay:200,determinePosition:function(b){if(a.ui&&a.ui.position)b.css("display","block").position({my:"center top",at:"center bottom",of:this,offset:"0 5",collision:"fit"}).css("display","none");else{var c=this.offset();c.top+=this.outerHeight(),c.left+=this.outerWidth()/2-b.outerWidth()/2,b.css(c)}},position:function(b,c,d){var e=this,f;if(!c&&!d)b.determinePosition.call(this,b.$menu);else{c==="maintain"&&d==="maintain"?f=b.$menu.position():f={top:d,left:c};var g=a(window),h=g.scrollTop()+g.height(),i=g.scrollLeft()+g.width(),j=b.$menu.height(),k=b.$menu.width();f.top+j>h&&(f.top-=j),f.left+k>i&&(f.left-=k),b.$menu.css(f)}},positionSubmenu:function(b){if(a.ui&&a.ui.position)b.css("display","block").position({my:"left top",at:"right top",of:this,collision:"fit"}).css("display","");else{var c=this.offset();c.top+=0,c.left+=this.outerWidth(),b.css(c)}},zIndex:1,animation:{duration:50,show:"slideDown",hide:"slideUp"},events:{show:a.noop,hide:a.noop},callback:null,items:{}},j={timer:null,pageX:null,pageY:null},k=function(a){var b=0,c=a;for(;;){b=Math.max(b,parseInt(c.css("z-index"),10)||0),c=c.parent();if(!c||!c.length||c.prop("nodeName").toLowerCase()=="body")break}return b},l={abortevent:function(a){a.preventDefault(),a.stopImmediatePropagation()},contextmenu:function(b){var d=a(this);b.preventDefault(),b.stopImmediatePropagation();e?e=!1:d.hasClass("context-menu-disabled")||(c=d,m.show.call(d,b.data,b.pageX,b.pageY))},click:function(b){b.preventDefault(),b.stopImmediatePropagation(),a(this).trigger(jQuery.Event("contextmenu",{data:b.data,pageX:b.pageX,pageY:b.pageY}))},mousedown:function(d){var e=a(this);c&&c.length&&!c.is(e)&&(m.hide.call(c,b),c=null),d.button==2&&(c=e.data("contextMenuActive",!0))},mouseup:function(b){var d=a(this);d.data("contextMenuActive")&&c&&c.length&&c.is(d)&&!d.hasClass("context-menu-disabled")&&(b.preventDefault(),b.stopImmediatePropagation(),c=d,d.trigger(jQuery.Event("contextmenu",{data:b.data,pageX:b.pageX,pageY:b.pageY}))),d.removeData("contextMenuActive")},mouseenter:function(b){var d=a(this),e=a(b.relatedTarget),f=a(document);if(!e.is(".context-menu-list")&&!e.closest(".context-menu-list").length){if(c&&c.length)return;j.pageX=b.pageX,j.pageY=b.pageY,j.data=b.data,f.bind("mousemove.contextMenuShow",l.mousemove),j.timer=setTimeout(function(){j.timer=null,f.unbind("mousemove.contextMenuShow"),c=d,d.trigger(jQuery.Event("contextmenu",{data:j.data,pageX:j.pageX,pageY:j.pageY}))},b.data.delay)}},mousemove:function(a){j.pageX=a.pageX,j.pageY=a.pageY},mouseleave:function(b){var c=a(b.relatedTarget);if(!c.is(".context-menu-list")&&!c.closest(".context-menu-list").length){try{clearTimeout(j.timer)}catch(b){}j.timer=null}},ignoreRightClick:function(a){a.button==2&&(e=!0)},layerClick:function(b){var c=a(this),d=c.data("contextMenuRoot");b.preventDefault(),b.stopImmediatePropagation(),c.remove(),m.hide.call(d.$trigger,d)},key:function(a){var b=c.data("contextMenu")||{},d=b.$menu.children(),e;b.isInput||a.preventDefault(),a.stopPropagation();switch(a.keyCode){case 9:case 38:if(b.isInput){if(a.keyCode==9&&a.shiftKey){a.preventDefault(),b.$selected&&b.$selected.find("input, textarea, select").blur(),b.$menu.trigger("prevcommand");break}if(a.keyCode==38&&b.$selected.find("input, textarea, select").prop("type")=="checkbox"){a.preventDefault();break}}else if(a.keyCode!=9||a.shiftKey){b.$menu.trigger("prevcommand");break};case 9:case 40:b.isInput?a.keyCode==9?(a.preventDefault(),b.$selected&&b.$selected.find("input, textarea, select").blur(),b.$menu.trigger("nextcommand")):a.keyCode==40&&b.$selected.find("input, textarea, select").prop("type")=="checkbox"&&a.preventDefault():b.$menu.trigger("nextcommand");break;case 37:if(b.isInput||!b.$selected||!b.$selected.length)break;if(!b.$selected.parent().hasClass("context-menu-root")){var f=b.$selected.parent().parent();b.$selected.removeClass("hover"),b.$selected=f}break;case 39:if(b.isInput||!b.$selected||!b.$selected.length)break;var g=b.$selected.data("contextMenu")||{};g.$menu&&(b.$selected=null,g.$selected=null,g.$menu.trigger("nextcommand"));break;case 13:if(b.isInput){b.$selected&&!b.$selected.is(":textarea, :select")&&a.preventDefault();break}b.$selected&&b.$selected.trigger("mouseup");break;case 27:m.hide.call(c,b),c=null}},prevItem:function(b){b.stopPropagation();var c=a(this).data("contextMenu")||{};if(c.$selected){var d=c.$selected;c=c.$selected.parent().data("contextMenu")||{},c.$selected=d}var e=c.$menu.children(),f=!c.$selected||!c.$selected.prev().length?e.last():c.$selected.prev(),g=f;while(f.hasClass("disabled")||f.hasClass("not-selectable")){f.prev().length?f=f.prev():f=e.last();if(f.is(g))return}c.$selected&&l.itemMouseleave.call(c.$selected.get(0),b),l.itemMouseenter.call(f.get(0),b);var h=f.find("input, textarea, select");h.length&&h.focus()},nextItem:function(b){b.stopPropagation();var c=a(this).data("contextMenu")||{};if(c.$selected){var d=c.$selected;c=c.$selected.parent().data("contextMenu")||{},c.$selected=d}var e=c.$menu.children(),f=!c.$selected||!c.$selected.next().length?e.first():c.$selected.next(),g=f;while(f.hasClass("disabled")||f.hasClass("not-selectable")){f.next().length?f=f.next():f=e.first();if(f.is(g))return}c.$selected&&l.itemMouseleave.call(c.$selected.get(0),b),l.itemMouseenter.call(f.get(0),b);var h=f.find("input, textarea, select");h.length&&h.focus()},focusInput:function(b){var c=a(this).closest(".context-menu-item"),d=c.data(),e=d.contextMenu,f=d.contextMenuRoot;f.$selected=e.$selected=c,f.isInput=e.isInput=!0},blurInput:function(b){var c=a(this).closest(".context-menu-item"),d=c.data(),e=d.contextMenu,f=d.contextMenuRoot;f.isInput=e.isInput=!1},menuMouseenter:function(b){var c=a(this).data().contextMenuRoot;c.hovering=!0},menuMouseleave:function(b){var c=a(this).data().contextMenuRoot;c.$layer&&c.$layer.is(b.relatedTarget)&&(c.hovering=!1)},itemMouseenter:function(b){var c=a(this),d=c.data(),e=d.contextMenu,f=d.contextMenuRoot;f.hovering=!0,f.$layer&&f.$layer.is(b.relatedTarget)&&(b.preventDefault(),b.stopImmediatePropagation()),(d.contextMenu.$menu?d.contextMenu:d.contextMenuRoot).$menu.children().removeClass("hover");c.hasClass("disabled")||c.hasClass("not-selectable")?e.$selected=null:(e.$selected=f.$selected=c,c.addClass("hover"),e.$node&&f.positionSubmenu.call(e.$node,e.$menu))},itemMouseleave:function(b){var c=a(this),d=c.data(),e=d.contextMenu,f=d.contextMenuRoot;f!==e&&f.$layer&&f.$layer.is(b.relatedTarget)?(f.$selected.removeClass("hover"),b.preventDefault(),b.stopImmediatePropagation(),f.$selected=e.$selected=e.$node):(e.$selected=null,c.removeClass("hover"))},itemClick:function(b){var d=a(this),e=d.data(),f=e.contextMenu,g=e.contextMenuRoot,h=e.contextMenuKey,i;if(!!f.items[h]&&!d.hasClass("disabled")){b.preventDefault(),b.stopImmediatePropagation();if(a.isFunction(g.callbacks[h]))i=g.callbacks[h];else if(a.isFunction(g.callback))i=g.callback;else return;i.call(g.$trigger,h,g)!==!1?(m.hide.call(g.$trigger,g),c=null):m.update.call(g.$trigger,g)}},inputClick:function(a){a.stopImmediatePropagation()}},m={show:function(b,d,e){var f=a(this),g,h={};a("#context-menu-layer").trigger("mousedown");if(b.events.show.call(f,b)===!1)c=null;else{m.update.call(f,b),b.position.call(f,b,d,e),b.zIndex&&(h.zIndex=k(f)+b.zIndex),m.layer.call(b.$menu,b,h.zIndex),b.$trigger=f,b.$menu.css(h)[b.animation.show](b.animation.duration),f.data("contextMenu",b),a(document).unbind("keydown.contextMenu").bind("keydown.contextMenu",l.key);if(b.autoHide){var i=f.position();i.right=i.left+f.outerWidth(),i.bottom=i.top+this.outerHeight(),a(document).bind("mousemove.contextMenuAutoHide",function(a){b.$layer&&!b.hovering&&(!(a.pageX>=i.left&&a.pageX<=i.right)||!(a.pageY>=i.top&&a.pageY<=i.bottom))&&b.$layer.trigger("mousedown")})}}},hide:function(b){var d=a(this);b||(b=d.data("contextMenu")||{});if(!b.events||b.events.hide.call(d,b)!==!1){if(b.$layer)try{b.$layer.remove(),delete b.$layer}catch(e){b.$layer=null}c=null,b.$menu.find(".hover").removeClass("hover"),b.$selected=null,a(document).unbind("keydown.contextMenu").unbind(".contextMenuAutoHide"),b.$menu&&b.$menu[b.animation.hide](b.animation.duration)}},create:function(c,d){d===b&&(d=c),c.$menu=a('<ul class="context-menu-list '+(this.className||"")+'"></ul>').data({contextMenu:c,contextMenuRoot:d}),a.each(["callbacks","commands","inputs"],function(a,b){c[b]={},d[b]||(d[b]={})}),a.each(c.items,function(b,e){var f=a('<li class="context-menu-item '+(e.className||"")+'"></li>'),g=null,h=null;e.$node=f.data({contextMenu:c,contextMenuRoot:d,contextMenuKey:b});if(typeof e=="string")f.addClass("context-menu-separator not-selectable");else{e.type=="html"?f.addClass("context-menu-html not-selectable"):e.type?(g=a("<label></label>").appendTo(f),a("<span></span>").appendTo(g).text(e.name),f.addClass("context-menu-input"),c.hasTypes=!0,a.each([c,d],function(a,c){c.commands[b]=e,c.inputs[b]=e})):e.items&&(e.type="sub");switch(e.type){case"text":h=a('<input type="text" value="1" name="context-menu-input-'+b+'" value="">').val(e.value||"").appendTo(g);break;case"textarea":h=a('<textarea name="context-menu-input-'+b+'"></textarea>').val(e.value||"").appendTo(g),e.height&&h.height(e.height);break;case"checkbox":h=a('<input type="checkbox" value="1" name="context-menu-input-'+b+'" value="">').val(e.value||"").prop("checked",!!e.selected).prependTo(g);break;case"radio":h=a('<input type="radio" value="1" name="context-menu-input-'+e.radio+'" value="">').val(e.value||"").prop("checked",!!e.selected).prependTo(g);break;case"select":h=a('<select name="context-menu-input-'+b+'">').appendTo(g),e.options&&(a.each(e.options,function(b,c){a("<option></option>").val(b).text(c).appendTo(h)}),h.val(e.selected));break;case"sub":a("<span></span>").text(e.name).appendTo(f),e.appendTo=e.$node,m.create(e,d),f.data("contextMenu",e),e.callback=null;break;case"html":a(e.html).appendTo(f);break;default:a.each([c,d],function(c,d){d.commands[b]=e,a.isFunction(e.callback)&&(d.callbacks[b]=e.callback)}),a("<span></span>").text(e.name||"").appendTo(f)}e.type&&e.type!="sub"&&e.type!="html"&&(h.bind("focus",l.focusInput).bind("blur",l.blurInput),e.events&&h.bind(e.events)),e.icon&&f.addClass("icon icon-"+e.icon)}e.$input=h,e.$label=g,f.appendTo(c.$menu),c.hasTypes||(a.browser.msie?f.bind("selectstart.disableTextSelect",l.abortevent):a.browser.mozilla||f.bind("mousedown.disableTextSelect",l.abortevent))}),c.$node||c.$menu.css("display","none").addClass("context-menu-root"),c.$menu.appendTo(c.appendTo||document.body)},update:function(b){var c=this;b.$menu.children().each(function(){var d=a(this),e=d.data("contextMenuKey"),f=b.items[e],g=a.isFunction(f.disabled)&&f.disabled.call(c,e,b)||f.disabled===!0;d[g?"addClass":"removeClass"]("disabled");if(f.type){d.find("input, select, textarea").prop("disabled",g);switch(f.type){case"text":case"textarea":f.$input.val(f.value||"");break;case"checkbox":case"radio":f.$input.val(f.value||"").prop("checked",!!f.selected);break;case"select":f.$input.val(f.selected||"")}}})},layer:function(b,c){var d=a(window);return b.$layer=a('<div id="context-menu-layer" style="position:fixed; z-index:'+c+'; top:0; left:0; opacity: 0;"></div>').css({height:d.height(),width:d.width(),display:"block"}).data("contextMenuRoot",b).insertBefore(this).bind("mousedown",l.layerClick)}};a.fn.contextMenu=function(a){a===b?this.first().trigger("contextmenu"):a.x&&a.y?this.first().trigger(jQuery.Event("contextmenu",{pageX:a.x,pageY:a.y})):a?this.removeClass("context-menu-disabled"):a||this.addClass("context-menu-disabled");return this},a.contextMenu=function(c,e){typeof c!="string"&&(e=c,c="create"),typeof e=="string"?e={selector:e}:e===b&&(e={});var j=a.extend(!0,{},i,e||{}),k=k=a(document);switch(c){case"create":if(!j.selector)throw new Error("No selector specified");if(j.selector.match(/.context-menu-(list|item|input)($|\s)/))throw new Error('Cannot bind to selector "'+j.selector+'" as it contains a reserved className');if(!j.items||a.isEmptyObject(j.items))throw new Error("No Items sepcified");f++,j.ns=".contextMenu"+f,g[j.selector]=j.ns,h[j.ns]=j,d||(k.delegate(".context-menu-list","prevcommand.contextMenu",l.prevItem).delegate(".context-menu-list","nextcommand.contextMenu",l.nextItem).delegate(".context-menu-list","contextmenu.contextMenu",l.abortevent).delegate(".context-menu-list","mouseenter.contextMenu",l.menuMouseenter).delegate(".context-menu-list","mouseleave.contextMenu",l.menuMouseleave).delegate(".context-menu-input","mouseup.contextMenu",l.inputClick).delegate(".context-menu-item","mouseup.contextMenu",l.itemClick).delegate(".context-menu-item","contextmenu.contextMenu",l.abortevent).delegate(".context-menu-item","mouseenter.contextMenu",l.itemMouseenter).delegate(".context-menu-item","mouseleave.contextMenu",l.itemMouseleave),d=!0),k.delegate(j.selector,"contextmenu"+j.ns,j,l.contextmenu);switch(j.trigger){case"hover":k.delegate(j.selector,"mouseenter"+j.ns,j,l.mouseenter).delegate(j.selector,"mouseleave"+j.ns,j,l.mouseleave);break;case"left":k.delegate(j.selector,"click"+j.ns,j,l.click)}j.trigger!="hover"&&j.ignoreRightClick&&k.delegate(j.selector,"mousedown"+j.ns,l.ignoreRightClick),m.create(j);break;case"destroy":if(!j.selector)k.undelegate(".contextMenu").unbind(".contextMenu"),a.each(g,function(a,b){k.undelegate(b)}),g={},h={},f=0,a(".context-menu-list").remove();else if(g[j.selector]){try{h[g[j.selector]].$menu&&h[g[j.selector]].$menu.remove(),delete h[g[j.selector]]}catch(n){h[g[j.selector]]=null}k.undelegate(g[j.selector])}break;case"html5":(!("HTMLMenuItemElement"in window)||!("HTMLCommandElement"in window))&&a('menu[type="context"]').each(function(){this.id&&a.contextMenu({selector:"[contextmenu="+this.id+"]",items:a.contextMenu.fromMenu(this)})}).css("display","none");break;default:throw new Error('Unknown operation "'+c+'"')}return this},a.contextMenu.setInputValues=function(c,d){d===b&&(d={}),a.each(c.inputs,function(a,b){switch(b.type){case"text":case"textarea":b.value=d[a]||"";break;case"checkbox":b.selected=d[a]?!0:!1;break;case"radio":b.selected=(d[b.radio]||"")==b.value?!0:!1;break;case"select":b.selected=d[a]||""}})},a.contextMenu.getInputValues=function(c,d){d===b&&(d={}),a.each(c.inputs,function(a,b){switch(b.type){case"text":case"textarea":case"select":d[a]=b.$input.val();break;case"checkbox":d[a]=b.$input.prop("checked");break;case"radio":b.$input.prop("checked")&&(d[b.radio]=b.value)}});return d},a.contextMenu.fromMenu=function(b){var c=a(b),d={};o(d,c.children());return d},a.contextMenu.defaults=i})(jQuery)
Please sign in to comment.
Something went wrong with that request. Please try again.