lib/har/viewer/scripts/domplate/popupMenu.js in har-0.1.0 vs lib/har/viewer/scripts/domplate/popupMenu.js in har-0.1.1
- old
+ new
@@ -1,2 +1,4 @@
-require.def("domplate/popupMenu",["domplate/domplate","core/lib","core/trace"],function(Domplate,Lib,Trace){with(Domplate){var Controller={controllers:[],controllerContext:{label:"controller context"},initialize:function(a){this.controllers=[],this.controllerContext=a||this.controllerContext},shutdown:function(){this.removeControllers()},addController:function(){for(var a=0,b;b=arguments[a];a++){typeof b[0]=="string"&&(b[0]=$$(b[0],this.controllerContext));var c=b[2];b[2]=Lib.bind(c,this),b[3]=c,this.controllers.push(b),Lib.addEventListener.apply(this,b)}},removeController:function(){for(var a=0,b;b=arguments[a];a++)for(var c=0,d;d=this.controllers[c];c++)b[0]==d[0]&&b[1]==d[1]&&b[2]==d[3]&&Lib.removeEventListener.apply(this,d)},removeControllers:function(){for(var a=0,b;b=this.controllers[a];a++)Lib.removeEventListener.apply(this,b)}},menuItemProps={"class":"$item.className",type:"$item.type",value:"$item.value",_command:"$item.command"};Lib.isIE6&&(menuItemProps.href="javascript:void(0)");var MenuPlate=domplate({tag:DIV({"class":"popupMenu popupMenuShadow"},DIV({"class":"popupMenuContent popupMenuShadowContent"},FOR("item","$object.items|memberIterator",TAG("$item.tag",{item:"$item"})))),itemTag:A(menuItemProps,"$item.label"),checkBoxTag:A(Lib.extend(menuItemProps,{checked:"$item.checked"}),"$item.label"),radioButtonTag:A(Lib.extend(menuItemProps,{selected:"$item.selected"}),"$item.label"),groupTag:A(Lib.extend(menuItemProps,{child:"$item.child"}),"$item.label"),shortcutTag:A(menuItemProps,"$item.label",SPAN({"class":"popupMenuShortcutKey"},"$item.key")),separatorTag:SPAN({"class":"popupMenuSeparator"}),memberIterator:function(a){var b=[];for(var c=0,d=a.length;c<d;c++){var e=a[c];if(typeof e=="string"&&e.indexOf("-")==0){b.push({tag:this.separatorTag});continue}e=Lib.extend(e,{}),e.type=e.type||"",e.value=e.value||"";var f=e.type;e.tag=this.itemTag;var g=e.className||"";g+="popupMenuOption ",f=="checkbox"?(g+="popupMenuCheckBox ",e.tag=this.checkBoxTag):f=="radio"?(g+="popupMenuRadioButton ",e.tag=this.radioButtonTag):f=="group"?(g+="popupMenuGroup ",e.tag=this.groupTag):f=="shortcut"&&(g+="popupMenuShortcut ",e.tag=this.shortcutTag),e.checked?g+="popupMenuChecked ":e.selected&&(g+="popupMenuRadioSelected "),e.disabled&&(g+="popupMenuDisabled "),e.className=g,e.label=e.label,b.push(e)}return b}});function Menu(a){if(!a.element){a.getItems&&(a.items=a.getItems()),a.items[0]=="-"&&a.items.shift(),a.items[a.items.length-1]=="-"&&a.items.pop();var b=Lib.getBody(document);a.element=MenuPlate.tag.append({object:a},b,MenuPlate)}Lib.append(this,a),typeof this.element=="string"?(this.id=this.element,this.element=$(this.id)):this.id&&(this.element.id=this.id),this.elementStyle=this.element.style,this.isVisible=!1,this.handleMouseDown=Lib.bind(this.handleMouseDown,this),this.handleMouseOver=Lib.bind(this.handleMouseOver,this),this.handleMouseOut=Lib.bind(this.handleMouseOut,this),this.handleWindowMouseDown=Lib.bind(this.handleWindowMouseDown,this)}var menuMap={};Menu.prototype=Lib.extend(Controller,{initialize:function(){Controller.initialize.call(this),this.addController([this.element,"mousedown",this.handleMouseDown],[this.element,"mouseover",this.handleMouseOver])},destroy:function(){this.hide(),this.parentMenu&&(this.parentMenu.childMenu=null),this.element.parentNode.removeChild(this.element),this.element=null,this.elementStyle=null,this.parentMenu=null,this.parentTarget=null},shutdown:function(){Controller.shutdown.call(this)},showPopup:function(a){var b=Lib.isIE6?1:-4,c=Lib.getElementBox(a),d={top:0,left:0};this.show(c.left+b-d.left,c.top+c.height-5-d.top)},show:function(a,b){this.initialize();if(!this.isVisible){a=a||0,b=b||0;if(this.parentMenu){var c=this.parentMenu.childMenu;c&&c!=this&&c.destroy(),this.parentMenu.childMenu=this}else Lib.addEventListener(document,"mousedown",this.handleWindowMouseDown);this.elementStyle.display="block",this.elementStyle.visibility="hidden";var d=Lib.getWindowSize();a=Math.min(a,d.width-this.element.clientWidth-10),a=Math.max(a,0),b=Math.min(b,d.height-this.element.clientHeight-10),b=Math.max(b,0),this.elementStyle.left=a+"px",this.elementStyle.top=b+"px",this.elementStyle.visibility="visible",this.isVisible=!0,Lib.isFunction(this.onShow)&&this.onShow.apply(this,arguments)}},hide:function(){this.clearHideTimeout(),this.clearShowChildTimeout();this.isVisible&&(this.elementStyle.display="none",this.childMenu&&(this.childMenu.destroy(),this.childMenu=null),this.parentTarget&&Lib.removeClass(this.parentTarget,"popupMenuGroupSelected"),this.isVisible=!1,this.shutdown(),Lib.isFunction(this.onHide)&&this.onHide.apply(this,arguments))},showChildMenu:function(a){var b=a.getAttribute("child"),c=this,a=a;this.showChildTimeout=window.setTimeout(function(){var d=Lib.getElementBox(a),e=menuMap.hasOwnProperty(b)?menuMap[b]:{element:$(b)},f=new Menu(Lib.extend(e,{parentMenu:c,parentTarget:a})),g=Lib.isIE6?-1:-6;f.show(d.left+d.width+g,d.top-6),Lib.setClass(a,"popupMenuGroupSelected")},350)},clearHideTimeout:function(){this.hideTimeout&&(window.clearTimeout(this.hideTimeout),delete this.hideTimeout)},clearShowChildTimeout:function(){this.showChildTimeout&&(window.clearTimeout(this.showChildTimeout),this.showChildTimeout=null)},handleMouseDown:function(a){Lib.cancelEvent(a,!0);var b=this;while(b.parentMenu)b=b.parentMenu;var c=a.target||a.srcElement;c=Lib.getAncestorByClass(c,"popupMenuOption");if(!c||Lib.hasClass(c,"popupMenuGroup"))return!1;if(c&&!Lib.hasClass(c,"popupMenuDisabled")){var d=c.getAttribute("type");if(d=="checkbox"){var e=c.getAttribute("checked"),f=c.getAttribute("value"),g=Lib.hasClass(c,"popupMenuChecked");g?(Lib.removeClass(c,"popupMenuChecked"),c.setAttribute("checked","")):(Lib.setClass(c,"popupMenuChecked"),c.setAttribute("checked","true")),Lib.isFunction(this.onCheck)&&this.onCheck.call(this,c,f,!g)}if(d=="radiobutton"){var h=Lib.getElementsByClass(c.parentNode,"popupMenuRadioSelected"),i=c.getAttribute("group");for(var j=0,k=h.length;j<k;j++)radio=h[j],radio.getAttribute("group")==i&&(Lib.removeClass(radio,"popupMenuRadioSelected"),radio.setAttribute("selected",""));Lib.setClass(c,"popupMenuRadioSelected"),c.setAttribute("selected","true")}var l=null,m=c.command;Lib.isFunction(m)?l=m:typeof m=="string"&&(l=this[m]);var n=!0;l&&(n=l.call(this,c)!==!1),n&&b.hide()}return!1},handleWindowMouseDown:function(a){var b=a.target||a.srcElement;b=Lib.getAncestorByClass(b,"popupMenu"),b||(Lib.removeEventListener(document,"mousedown",this.handleWindowMouseDown),this.destroy())},handleMouseOver:function(a){this.clearHideTimeout(),this.clearShowChildTimeout();var b=a.target||a.srcElement;b=Lib.getAncestorByClass(b,"popupMenuOption");if(b){var c=this.childMenu;c&&(Lib.removeClass(c.parentTarget,"popupMenuGroupSelected"),c.parentTarget!=b&&c.isVisible&&(c.clearHideTimeout(),c.hideTimeout=window.setTimeout(function(){c.destroy()},300))),Lib.hasClass(b,"popupMenuGroup")&&this.showChildMenu(b)}}}),Lib.append(Menu,{register:function(a){menuMap[a.id]=a},check:function(a){Lib.setClass(a,"popupMenuChecked"),a.setAttribute("checked","true")},uncheck:function(a){Lib.removeClass(a,"popupMenuChecked"),a.setAttribute("checked","")},disable:function(a){Lib.setClass(a,"popupMenuDisabled")},enable:function(a){Lib.removeClass(a,"popupMenuDisabled")}});return Menu}})
+/* See license.txt for terms of usage */
+
+define("domplate/popupMenu",["domplate/domplate","core/lib","core/trace"],function(Domplate,Lib,Trace){with(Domplate){var Controller={controllers:[],controllerContext:{label:"controller context"},initialize:function(e){this.controllers=[],this.controllerContext=e||this.controllerContext},shutdown:function(){this.removeControllers()},addController:function(){for(var e=0,t;t=arguments[e];e++){typeof t[0]=="string"&&(t[0]=$$(t[0],this.controllerContext));var n=t[2];t[2]=Lib.bind(n,this),t[3]=n,this.controllers.push(t),Lib.addEventListener.apply(this,t)}},removeController:function(){for(var e=0,t;t=arguments[e];e++)for(var n=0,r;r=this.controllers[n];n++)t[0]==r[0]&&t[1]==r[1]&&t[2]==r[3]&&Lib.removeEventListener.apply(this,r)},removeControllers:function(){for(var e=0,t;t=this.controllers[e];e++)Lib.removeEventListener.apply(this,t)}},menuItemProps={"class":"$item.className",type:"$item.type",value:"$item.value",_command:"$item.command"};Lib.isIE6&&(menuItemProps.href="javascript:void(0)");var MenuPlate=domplate({tag:DIV({"class":"popupMenu popupMenuShadow"},DIV({"class":"popupMenuContent popupMenuShadowContent"},FOR("item","$object.items|memberIterator",TAG("$item.tag",{item:"$item"})))),itemTag:A(menuItemProps,"$item.label"),checkBoxTag:A(Lib.extend(menuItemProps,{checked:"$item.checked"}),"$item.label"),radioButtonTag:A(Lib.extend(menuItemProps,{selected:"$item.selected"}),"$item.label"),groupTag:A(Lib.extend(menuItemProps,{child:"$item.child"}),"$item.label"),shortcutTag:A(menuItemProps,"$item.label",SPAN({"class":"popupMenuShortcutKey"},"$item.key")),separatorTag:SPAN({"class":"popupMenuSeparator"}),memberIterator:function(e){var t=[];for(var n=0,r=e.length;n<r;n++){var i=e[n];if(typeof i=="string"&&i.indexOf("-")==0){t.push({tag:this.separatorTag});continue}i=Lib.extend(i,{}),i.type=i.type||"",i.value=i.value||"";var s=i.type;i.tag=this.itemTag;var o=i.className||"";o+="popupMenuOption ",s=="checkbox"?(o+="popupMenuCheckBox ",i.tag=this.checkBoxTag):s=="radio"?(o+="popupMenuRadioButton ",i.tag=this.radioButtonTag):s=="group"?(o+="popupMenuGroup ",i.tag=this.groupTag):s=="shortcut"&&(o+="popupMenuShortcut ",i.tag=this.shortcutTag),i.checked?o+="popupMenuChecked ":i.selected&&(o+="popupMenuRadioSelected "),i.disabled&&(o+="popupMenuDisabled "),i.className=o,i.label=i.label,t.push(i)}return t}});function Menu(e){if(!e.element){e.getItems&&(e.items=e.getItems()),e.items[0]=="-"&&e.items.shift(),e.items[e.items.length-1]=="-"&&e.items.pop();var t=Lib.getBody(document);e.element=MenuPlate.tag.append({object:e},t,MenuPlate)}Lib.append(this,e),typeof this.element=="string"?(this.id=this.element,this.element=$(this.id)):this.id&&(this.element.id=this.id),this.elementStyle=this.element.style,this.isVisible=!1,this.handleMouseDown=Lib.bind(this.handleMouseDown,this),this.handleMouseOver=Lib.bind(this.handleMouseOver,this),this.handleMouseOut=Lib.bind(this.handleMouseOut,this),this.handleWindowMouseDown=Lib.bind(this.handleWindowMouseDown,this)}var menuMap={};return Menu.prototype=Lib.extend(Controller,{initialize:function(){Controller.initialize.call(this),this.addController([this.element,"mousedown",this.handleMouseDown],[this.element,"mouseover",this.handleMouseOver])},destroy:function(){this.hide(),this.parentMenu&&(this.parentMenu.childMenu=null),this.element.parentNode.removeChild(this.element),this.element=null,this.elementStyle=null,this.parentMenu=null,this.parentTarget=null},shutdown:function(){Controller.shutdown.call(this)},showPopup:function(e){var t=Lib.isIE6?1:-4,n=Lib.getElementBox(e),r={top:0,left:0};this.show(n.left+t-r.left,n.top+n.height-5-r.top)},show:function(e,t){this.initialize();if(this.isVisible)return;e=e||0,t=t||0;if(this.parentMenu){var n=this.parentMenu.childMenu;n&&n!=this&&n.destroy(),this.parentMenu.childMenu=this}else Lib.addEventListener(document,"mousedown",this.handleWindowMouseDown);this.elementStyle.display="block",this.elementStyle.visibility="hidden";var r=Lib.getWindowSize();e=Math.min(e,r.width-this.element.clientWidth-10),e=Math.max(e,0),t=Math.min(t,r.height-this.element.clientHeight-10),t=Math.max(t,0),this.elementStyle.left=e+"px",this.elementStyle.top=t+"px",this.elementStyle.visibility="visible",this.isVisible=!0,Lib.isFunction(this.onShow)&&this.onShow.apply(this,arguments)},hide:function(){this.clearHideTimeout(),this.clearShowChildTimeout();if(!this.isVisible)return;this.elementStyle.display="none",this.childMenu&&(this.childMenu.destroy(),this.childMenu=null),this.parentTarget&&Lib.removeClass(this.parentTarget,"popupMenuGroupSelected"),this.isVisible=!1,this.shutdown(),Lib.isFunction(this.onHide)&&this.onHide.apply(this,arguments)},showChildMenu:function(e){var t=e.getAttribute("child"),n=this,e=e;this.showChildTimeout=window.setTimeout(function(){var r=Lib.getElementBox(e),i=menuMap.hasOwnProperty(t)?menuMap[t]:{element:$(t)},s=new Menu(Lib.extend(i,{parentMenu:n,parentTarget:e})),o=Lib.isIE6?-1:-6;s.show(r.left+r.width+o,r.top-6),Lib.setClass(e,"popupMenuGroupSelected")},350)},clearHideTimeout:function(){this.hideTimeout&&(window.clearTimeout(this.hideTimeout),delete this.hideTimeout)},clearShowChildTimeout:function(){this.showChildTimeout&&(window.clearTimeout(this.showChildTimeout),this.showChildTimeout=null)},handleMouseDown:function(e){Lib.cancelEvent(e,!0);var t=this;while(t.parentMenu)t=t.parentMenu;var n=e.target||e.srcElement;n=Lib.getAncestorByClass(n,"popupMenuOption");if(!n||Lib.hasClass(n,"popupMenuGroup"))return!1;if(n&&!Lib.hasClass(n,"popupMenuDisabled")){var r=n.getAttribute("type");if(r=="checkbox"){var i=n.getAttribute("checked"),s=n.getAttribute("value"),o=Lib.hasClass(n,"popupMenuChecked");o?(Lib.removeClass(n,"popupMenuChecked"),n.setAttribute("checked","")):(Lib.setClass(n,"popupMenuChecked"),n.setAttribute("checked","true")),Lib.isFunction(this.onCheck)&&this.onCheck.call(this,n,s,!o)}if(r=="radiobutton"){var u=Lib.getElementsByClass(n.parentNode,"popupMenuRadioSelected"),a=n.getAttribute("group");for(var f=0,l=u.length;f<l;f++)radio=u[f],radio.getAttribute("group")==a&&(Lib.removeClass(radio,"popupMenuRadioSelected"),radio.setAttribute("selected",""));Lib.setClass(n,"popupMenuRadioSelected"),n.setAttribute("selected","true")}var c=null,h=n.command;Lib.isFunction(h)?c=h:typeof h=="string"&&(c=this[h]);var p=!0;c&&(p=c.call(this,n)!==!1),p&&t.hide()}return!1},handleWindowMouseDown:function(e){var t=e.target||e.srcElement;t=Lib.getAncestorByClass(t,"popupMenu"),t||(Lib.removeEventListener(document,"mousedown",this.handleWindowMouseDown),this.destroy())},handleMouseOver:function(e){this.clearHideTimeout(),this.clearShowChildTimeout();var t=e.target||e.srcElement;t=Lib.getAncestorByClass(t,"popupMenuOption");if(!t)return;var n=this.childMenu;n&&(Lib.removeClass(n.parentTarget,"popupMenuGroupSelected"),n.parentTarget!=t&&n.isVisible&&(n.clearHideTimeout(),n.hideTimeout=window.setTimeout(function(){n.destroy()},300))),Lib.hasClass(t,"popupMenuGroup")&&this.showChildMenu(t)}}),Lib.append(Menu,{register:function(e){menuMap[e.id]=e},check:function(e){Lib.setClass(e,"popupMenuChecked"),e.setAttribute("checked","true")},uncheck:function(e){Lib.removeClass(e,"popupMenuChecked"),e.setAttribute("checked","")},disable:function(e){Lib.setClass(e,"popupMenuDisabled")},enable:function(e){Lib.removeClass(e,"popupMenuDisabled")}}),Menu}});
\ No newline at end of file