/*! jQuery UI context menu plugin - v1.3.0-1 - 2013-12-27 |  https://github.com/mar10/jquery-ui-contextmenu |  Copyright (c) 2013 Martin Wendt; Licensed MIT */
!function(a,b,c,d){"use strict";function e(a){return a&&a.match(/^#/)?a.substring(1):a||""}var f="onselectstart"in c.createElement("div");a.widget("moogle.contextmenu",{version:"1.3.0-1",options:{delegate:null,hide:{effect:"fadeOut",duration:"fast"},ignoreParentSelect:!0,menu:null,position:null,preventSelect:!1,show:{effect:"slideDown",duration:"fast"},taphold:!1,beforeOpen:a.noop,blur:a.noop,close:a.noop,create:a.noop,createMenu:a.noop,focus:a.noop,open:a.noop,select:a.noop},_create:function(){var b,d,e,g=this.options;if(this.$headStyle=null,this.$menu=null,this.menuIsTemp=!1,this.currentTarget=null,g.preventSelect){e=(a(this.element).is(c)?a("body"):this.element).uniqueId().attr("id"),b="#"+e+" "+g.delegate+" { -webkit-user-select: none; -khtml-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none; }",this.$headStyle=a("<style class='moogle-contextmenu-style' />").prop("type","text/css").appendTo("head");try{this.$headStyle.html(b)}catch(h){this.$headStyle[0].styleSheet.cssText=b}f&&this.element.delegate(g.delegate,"selectstart"+this.eventNamespace,function(a){a.preventDefault()})}this._createUiMenu(g.menu),d="contextmenu"+this.eventNamespace,g.taphold&&(d+=" taphold"+this.eventNamespace),this.element.delegate(g.delegate,d,a.proxy(this._openMenu,this))},_destroy:function(){this.element.undelegate(this.eventNamespace),this._createUiMenu(null),this.$headStyle&&(this.$headStyle.remove(),this.$headStyle=null)},_createUiMenu:function(b){this.isOpen()&&this._closeMenu(!0),this.menuIsTemp?this.$menu.remove():this.$menu&&this.$menu.menu("destroy").hide(),this.$menu=null,this.menuIsTemp=!1,b&&(a.isArray(b)?(this.$menu=a.moogle.contextmenu.createMenuMarkup(b),this.menuIsTemp=!0):this.$menu="string"==typeof b?a(b):b,this.$menu.hide().menu({blur:a.proxy(this.options.blur,this),create:a.proxy(this.options.createMenu,this),focus:a.proxy(this.options.focus,this),select:a.proxy(function(b,c){var d,f=c.item.has(">a[aria-haspopup='true']").length>0,g=c.item.find(">a"),h=g.data("actionHandler");c.cmd=e(g.attr("href")),c.target=a(this.currentTarget),f&&this.options.ignoreParentSelect||(d=this._trigger.call(this,"select",b,c),h&&(d=h.call(this,b,c)),d!==!1&&this._closeMenu.call(this),b.preventDefault())},this)}))},_openMenu:function(b){var e=this.options,f=e.position,g=this,h={menu:this.$menu,target:a(b.target),extraData:b.extraData};return this.currentTarget=b.target,b.preventDefault(),this._trigger("beforeOpen",b,h)===!1?(this.currentTarget=null,!1):(h.menu=this.$menu,a(c).bind("keydown"+this.eventNamespace,function(b){b.which===a.ui.keyCode.ESCAPE&&g._closeMenu()}).bind("mousedown"+this.eventNamespace+" touchstart"+this.eventNamespace,function(b){a(b.target).closest(".ui-menu-item").length||g._closeMenu()}),a.isFunction(f)&&(f=f(b,h)),f=a.extend({my:"left top",at:"left bottom",of:b.pageX===d?b.target:b,collision:"fit"},f),this.$menu.show().css({position:"absolute",left:0,top:0}).position(f).hide(),this._show(this.$menu,this.options.show,function(){g._trigger.call(g,"open",b,h)}),void 0)},_closeMenu:function(b){var d=this,e=b?!1:this.options.hide;a(c).unbind("mousedown"+this.eventNamespace).unbind("touchstart"+this.eventNamespace).unbind("keydown"+this.eventNamespace),d.currentTarget=null,this._hide(this.$menu,e,function(){d._trigger("close")})},_setOption:function(b,c){switch(b){case"menu":this.replaceMenu(c)}a.Widget.prototype._setOption.apply(this,arguments)},_getMenuEntry:function(a,b){var c=this.$menu.find("li a[href=#"+e(a)+"]");return b?c.closest("li"):c},close:function(){this.isOpen()&&this._closeMenu()},enableEntry:function(a,b){this._getMenuEntry(a,!0).toggleClass("ui-state-disabled",b===!1)},getMenu:function(){return this.$menu},isOpen:function(){return!!this.$menu&&!!this.currentTarget},open:function(a,b){b=b||{};var c=jQuery.Event("contextmenu",{target:a.get(0),extraData:b});return this.element.trigger(c)},replaceMenu:function(a){this._createUiMenu(a)},setEntry:function(b,c){var d,e=this._getMenuEntry(b,!1);"string"==typeof c?e.children("span").length?e.contents().filter(function(){return 3===this.nodeType}).first().replaceWith(c):e.text(c):(d=e.closest("li").empty(),c.cmd=c.cmd||b,a.moogle.contextmenu.createEntryMarkup(c,d))},showEntry:function(a,b){this._getMenuEntry(a,!0).toggle(b!==!1)}}),a.extend(a.moogle.contextmenu,{createEntryMarkup:function(b,c){var d=null;return/[^\-\u2014\u2013\s]/.test(b.title)?(d=a("<a/>",{text:""+b.title,href:"#"+e(b.cmd)}).appendTo(c),a.isFunction(b.action)&&d.data("actionHandler",b.action),b.uiIcon&&d.append(a("<span class='ui-icon' />").addClass(b.uiIcon)),b.disabled&&c.addClass("ui-state-disabled"),a.isPlainObject(b.data)&&d.data(b.data)):c.text(b.title),d},createMenuMarkup:function(b,c){var d,e,f,g;for(null==c&&(c=a("<ul class='ui-helper-hidden' />").appendTo("body")),d=0;d<b.length;d++)e=b[d],g=a("<li/>").appendTo(c),a.moogle.contextmenu.createEntryMarkup(e,g),a.isArray(e.children)&&(f=a("<ul/>").appendTo(g),a.moogle.contextmenu.createMenuMarkup(e.children,f));return c}})}(jQuery,window,document);