// jQuery Context Menu Plugin
//
// Version 1.01
//
// Cory S.N. LaViska
// A Beautiful Site (http://abeautifulsite.net/)
//
// More info: http://abeautifulsite.net/2008/09/jquery-context-menu-plugin/
//
// Terms of Use
//
// This plugin is dual-licensed under the GNU General Public License
//   and the MIT License and is copyright A Beautiful Site, LLC.
//
// Modified by Philip Weir:
//   Added highlighting of selected row and submenu support
//   Added sub menu functions
//   Added bind to contextmenu event
//   Adjust menu position for screen boundaries
//   Shrunk with Google Closure Compiler (Simple Optimizations)
jQuery&&function(){$.extend($.fn,{contextMenu:function(a,e){if(void 0==a.menu)return!1;void 0==a.inSpeed&&(a.inSpeed=150);void 0==a.outSpeed&&(a.outSpeed=75);0==a.inSpeed&&(a.inSpeed=-1);0==a.outSpeed&&(a.outSpeed=-1);$(this).each(function(){var b=$(this),l=$(b).offset();$("#"+a.menu).addClass("contextMenu");$(this).mousedown(function(m){$(this).mouseup(function(g){var d=$(this);$(this).unbind("mouseup");if(2==m.button){$(".contextRow").removeClass("contextRow");$(".contextMenu").hide();d.addClass("contextRow"); rcm_update_options(d);var f=$("#"+a.menu);$(this).submenu_render(f);if($(b).hasClass("disabled"))return!1;var c={},h,j;self.innerHeight?(c.pageYOffset=self.pageYOffset,c.pageXOffset=self.pageXOffset,c.innerHeight=self.innerHeight,c.innerWidth=self.innerWidth):document.documentElement&&document.documentElement.clientHeight?(c.pageYOffset=document.documentElement.scrollTop,c.pageXOffset=document.documentElement.scrollLeft,c.innerHeight=document.documentElement.clientHeight,c.innerWidth=document.documentElement.clientWidth): document.body&&(c.pageYOffset=document.body.scrollTop,c.pageXOffset=document.body.scrollLeft,c.innerHeight=document.body.clientHeight,c.innerWidth=document.body.clientWidth);g.pageX?h=g.pageX:h=g.clientX+c.scrollLeft;g.pageY?j=g.pageY:j=g.clientY+c.scrollTop;h+$(f).width()+10>$(document).width()&&0<$(document).width()-$(f).width()-10&&(h=$(document).width()-$(f).width()-10);j+$(f).height()+10>$(document).height()&&0<$(document).height()-$(f).height()-10&&(j=$(document).height()-$(f).height()-10); $(document).unbind("click",$(this).document_click);$("#"+a.menu+" li ul").hide();$("#"+a.menu+" li div").hide();$(f).css({top:j,left:h}).fadeIn(a.inSpeed);$(document).bind("keypress",{menu:f},$(this).menu_keypress);$("#"+a.menu).find("a").unbind("click");$("#"+a.menu).find("li a:not(.disabled)").click(function(){$(document).unbind("click",$(this).document_click).unbind("keypress",$(this).menu_keypress);$(".contextMenu").hide();d.removeClass("contextRow");e&&e($(this).attr("href").substr(1),$(d),{x:h- l.left,y:j-l.top,docX:h,docY:j});return!1});setTimeout(function(){$(document).bind("click",{menu:f,o:a},$(this).document_click);$("iframe").load(function(){(this.contentDocument?this.contentDocument:this.contentWindow?this.contentWindow.document:null).onclick=function(){$(document).click()}});$("iframe").contents().mouseup(function(){$(document).click()})},0)}rcmail.drag_active||(g.cancelBubble=!0,g.stopPropagation&&g.stopPropagation())})});var d,k;$("#"+a.menu).children("li").mouseenter(function(){if($(this).hasClass("submenu")){if($(this).hasClass("submenu")&& !d&&!$(this).children("*:not(a, span)").is(":visible")){window.clearTimeout(k);k=null;var b=this;d=window.setTimeout(function(){$("#"+a.menu).children("li.submenu").children("div.popupmenu").children("ul.scrollable").scrollTop(0);$("#"+a.menu).children("li.submenu").children("div.popupmenu").children("div.scroll_up_act").addClass("scroll_up_pas").removeClass("scroll_up_act");$("#"+a.menu).children("li.submenu").children("div.popupmenu").children("div.scroll_down_pas").addClass("scroll_down_act").removeClass("scroll_down_pas"); $("#"+a.menu).children("li.submenu").children("*:not(a, span)").hide();doc_height=$(document).height();$(b).children("*:not(a, span)").css({left:$("#"+a.menu).width()-2,top:0});$(b).children("*:not(a, span)").show();$(b).children("*:not(a, span)").offset().left+$(b).children("*:not(a, span)").width()+10>$(document).width()&&0<$(document).width()-$(b).children("*:not(a, span)").width()-$("#"+a.menu).width()&&$(b).children("*:not(a, span)").css({left:-1*$(b).children("*:not(a, span)").width()});y=-1* ($(b).children("*:not(a, span)").offset().top+$(b).children("*:not(a, span)").height()+10-doc_height);0>y&&0<$(b).children("*:not(a, span)").offset().top+y&&$(b).children("*:not(a, span)").css({top:y});$(b).children("div.popupmenu").length&&$(b).children("div.popupmenu").children().show();d=null},a.submenu_delay)}}else k=window.setTimeout(function(){$("#"+a.menu).children("li.submenu").children("*:not(a, span)").hide();k=null},a.submenu_delay)});$("#"+a.menu).children("li.submenu").mouseleave(function(){window.clearTimeout(d); d=null});$(this).mouseleave(function(){window.clearTimeout(d);d=null});$("#"+a.menu).each(function(){$(this).attr("unselectable","on");$(this).css("user-select","none");$(this).on("selectstart",!1)});$(b).add($("ul.contextMenu")).bind("contextmenu",function(){return!1})});return $(this)},disableContextMenuItems:function(a){if(void 0==a)return $(this).find("a").addClass("disabled"),$(this);$(this).each(function(){if(void 0!=a)for(var e=a.split(","),b=0;b<e.length;b++)$(this).find('a[href="'+e[b]+'"]').addClass("disabled")}); return $(this)},enableContextMenuItems:function(a){if(void 0==a)return $(this).find("a.disabled").removeClass("disabled"),$(this);$(this).each(function(){if(void 0!=a)for(var e=a.split(","),b=0;b<e.length;b++)$(this).find('a[href="'+e[b]+'"]').removeClass("disabled")});return $(this)},disableContextMenu:function(){$(this).each(function(){$(this).addClass("disabled")});return $(this)},enableContextMenu:function(){$(this).each(function(){$(this).removeClass("disabled")});return $(this)},destroyContextMenu:function(){$(this).each(function(){$(this).unbind("mousedown").unbind("mouseup")}); return $(this)},submenu_render:function(a){$(a).show();$(a).children("li.submenu").children().show();$(a).children("li.submenu").children("div.popupmenu").each(function(){ul_overflow=$(this).children("ul").css("overflow");$(this).children("ul").css({overflow:"visible"});$(this).children("div").css({width:$(this).children("ul").width()+"px"});$(this).css({width:$(this).children("ul").width()+"px"});$(this).children("ul").css({overflow:ul_overflow});$(this).children("div").click(function(a){var b=$(this).parent().children("ul"); $(this).hasClass("scroll_up_act")?($(b).scrollTop($(b).scrollTop()-18),$(this).parent().children("div.scroll_down_pas").addClass("scroll_down_act"),$(this).parent().children("div.scroll_down_pas").removeClass("scroll_down_pas"),0==$(b).scrollTop()&&($(this).removeClass("scroll_up_act"),$(this).addClass("scroll_up_pas"))):$(this).hasClass("scroll_down_act")&&($(b).scrollTop($(b).scrollTop()+18),$(this).parent().children("div.scroll_up_pas").addClass("scroll_up_act"),$(this).parent().children("div.scroll_up_pas").removeClass("scroll_up_pas"), $(b).prop("scrollHeight")-$(b).scrollTop()==$(b).outerHeight()&&($(this).removeClass("scroll_down_act"),$(this).addClass("scroll_down_pas")));a.cancelBubble=!0;a.stopPropagation&&a.stopPropagation()});$(this).children("ul").mousewheel($(this).submenu_mousewheel)});$(a).children("li.submenu").children("*:not(a, span)").hide();$(a).hide()},submenu_mousewheel:function(a,e){0<e?$(this).parent().children("div.scroll_up_act").click():0>e&&$(this).parent().children("div.scroll_down_act").click()},menu_keypress:function(a){switch(a.keyCode){case 13:$(a.data.menu).find("li a.hover").trigger("click"); break;case 27:$(document).trigger("click")}},document_click:function(a){$(document).unbind("click",$(this).document_click).unbind("keypress",$(this).menu_keypress);$(".contextRow").removeClass("contextRow");$(a.data.menu).fadeOut(a.data.o.outSpeed);return!1}})}(jQuery);