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