").appendTo(this.$menu);for(var e in this.options){var f=this.options[e];if(f=="-"){d=c("
").appendTo(this.$menu)}else{var h=c("").appendTo(d),g=c(""+f.label+"").appendTo(h);if(typeof f.onClick=="function"){(function(i,j){setTimeout(c.proxy(function(){i.mousedown(c.proxy(function(k){this.hideMenu();j.call(this.currentTarget,c.extend(k,{currentTarget:this.currentTarget}))},this))},this),1)}).call(this,g,f.onClick)}}}},showMenu:function(d){if(d.type=="mousedown"&&d.which!=Garnish.SECONDARY_CLICK){return}if(d.type=="contextmenu"){d.preventDefault()}if(this.showing&&d.currentTarget==this.currentTarget){return}this.currentTarget=d.currentTarget;if(!this.$menu){this.buildMenu()}this.$menu.appendTo(document.body);this.$menu.show();this.$menu.css({left:d.pageX+1,top:d.pageY-4});this.showing=true;setTimeout(c.proxy(function(){this.addListener(Garnish.$doc,"mousedown","hideMenu")},this),0)},hideMenu:function(){this.removeListener(Garnish.$doc,"mousedown");this.$menu.hide();this.showing=false},enable:function(){this.addListener(this.$target,"contextmenu,mousedown","showMenu")},disable:function(){this.removeListener(this.$target,"contextmenu,mousedown")}},{defaults:{menuClass:"menu"},counter:0});Garnish.Drag=Garnish.BaseDrag.extend({$draggee:null,otherItems:null,totalOtherItems:null,helpers:null,helperTargets:null,helperPositions:null,helperLagIncrement:null,updateHelperPosInterval:null,init:function(d,e){if(!e&&Garnish.isObject(d)){e=d;d=null}e=c.extend({},Garnish.Drag.defaults,e);this.base(d,e)},onDragStart:function(){this.helpers=[];this.helperTargets=[];this.helperPositions=[];this.getDraggee();this.draggeeIndex=c.inArray(this.$draggee[0],this.$items);this.draggeeDisplay=this.$draggee.css("display");this.createHelpers();if(this.settings.removeDraggee){this.$draggee.hide()}else{this.$draggee.css("visibility","hidden")}this.lastMouseX=this.lastMouseY=null;this.otherItems=[];for(var d=0;d').appendTo(Garnish.$bod);this.$tip=c('').appendTo(this.$hud);this.$body=c('').appendTo(this.$hud).append(f);this.show();this.addListener(this.$hud,"click",function(g){g.stopPropagation()})},show:function(f){if(this.showing){return}if(Garnish.HUD.active){Garnish.HUD.active.hide()}this.$hud.show();this.windowWidth=Garnish.$win.width();this.windowHeight=Garnish.$win.height();this.windowScrollLeft=Garnish.$win.scrollLeft();this.windowScrollTop=Garnish.$win.scrollTop();this.triggerWidth=this.$trigger.outerWidth();this.triggerHeight=this.$trigger.outerHeight();this.triggerOffset=this.$trigger.offset();this.triggerOffsetRight=this.triggerOffset.left+this.triggerWidth;this.triggerOffsetBottom=this.triggerOffset.top+this.triggerHeight;this.triggerOffsetLeft=this.triggerOffset.left;this.triggerOffsetTop=this.triggerOffset.top;this.width=this.$hud.outerWidth();this.height=this.$hud.outerHeight();this.minHorizontalClearance=this.width+this.settings.triggerSpacing+this.settings.windowSpacing;this.minVerticalClearance=this.height+this.settings.triggerSpacing+this.settings.windowSpacing;this.rightClearance=this.windowWidth+this.windowScrollLeft-this.triggerOffsetRight;this.bottomClearance=this.windowHeight+this.windowScrollTop-this.triggerOffsetBottom;this.leftClearance=this.triggerOffsetLeft-this.windowScrollLeft;this.topClearance=this.triggerOffsetTop-this.windowScrollTop;if(this.bottomClearance>=this.minVerticalClearance){var i=this.triggerOffsetBottom+this.settings.triggerSpacing;this.$hud.css("top",i);this._setLeftPos();this._setTipClass("top")}else{if(this.topClearance>=this.minVerticalClearance){var i=this.triggerOffsetTop-(this.height+this.settings.triggerSpacing);this.$hud.css("top",i);this._setLeftPos();this._setTipClass("bottom")}else{if(this.rightClearance>=this.minHorizontalClearance){var h=this.triggerOffsetRight+this.settings.triggerSpacing;this.$hud.css("left",h);this._setTopPos();this._setTipClass("left")}else{if(this.leftClearance>=this.minHorizontalClearance){var h=this.triggerOffsetLeft-(this.width+this.settings.triggerSpacing);this.$hud.css("left",h);this._setTopPos();this._setTipClass("right")}else{var e=this.minHorizontalClearance-this.rightClearance,g=this.minVerticalClearance-this.bottomClearance;if(e>=g){var h=this.windowWidth-(this.width+this.settings.windowSpacing),d=this.triggerOffsetLeft+this.settings.triggerSpacing;if(hg){f=g}if(ff){h=f}if(h0){d=0}}this.$innerContainer.css("marginLeft",d)},_onDragStop:function(){var d=this._getMargin();if(d>-16){this.turnOn()}else{this.turnOff()}},destroy:function(){this.base();this.dragger.destroy()}},{offMargin:-50,defaults:{onChange:c.noop}});Garnish.Menu=Garnish.Base.extend({settings:null,$container:null,$options:null,$btn:null,init:function(d,e){this.setSettings(e,Garnish.Menu.defaults);this.$container=c(d).appendTo(Garnish.$bod);this.$options=this.$container.find("a");this.$options.data("menu",this);if(this.settings.attachToButton){this.$btn=c(this.settings.attachToButton)}this.addListener(this.$container,"mousedown",function(f){f.stopPropagation()});this.addListener(this.$options,"click","selectOption")},setPositionRelativeToButton:function(){var h={minWidth:(n-32)};var d=Garnish.$win.height(),i=Garnish.$win.scrollTop(),m=this.$btn.offset(),n=this.$btn.outerWidth(),g=this.$btn.outerHeight(),e=m.top+g,k=m.top,f=this.$container.outerHeight(),l=d+i-e,j=k-i;if(l>=g||l>=j){h.top=e}else{h.top=k-f}switch(this.$container.data("align")){case"right":h.right=1+Garnish.$win.width()-(m.left+n);break;case"center":h.left=Math.round((m.left+n/2)-(this.$container.outerWidth()/2));break;default:h.left=1+m.left}this.$container.css(h)},show:function(){if(this.$btn){this.setPositionRelativeToButton()}this.$container.fadeIn(50)},hide:function(){this.$container.fadeOut("fast")},selectOption:function(d){this.settings.onOptionSelect(d.currentTarget);this.hide()}},{defaults:{attachToButton:null,onOptionSelect:c.noop}});Garnish.MenuBtn=Garnish.Base.extend({$btn:null,menu:null,showingMenu:false,init:function(d,f){this.$btn=c(d);if(this.$btn.data("menubtn")){Garnish.log("Double-instantiating a menu button on an element");this.$btn.data("menubtn").destroy()}this.$btn.data("menubtn",this);this.setSettings(f,Garnish.MenuBtn.defaults);var e=this.$btn.next(".menu");this.menu=new Garnish.Menu(e,{attachToButton:this.$btn,onOptionSelect:c.proxy(this,"onOptionSelect")});this.addListener(this.$btn,"mousedown","onMouseDown")},onMouseDown:function(d){if(d.which!=Garnish.PRIMARY_CLICK||d.metaKey){return}d.preventDefault();if(this.showingMenu){this.hideMenu()}else{this.showMenu()}},showMenu:function(){this.menu.show();this.$btn.addClass("active");this.showingMenu=true;setTimeout(c.proxy(function(){this.addListener(Garnish.$doc,"mousedown","onMouseDown")},this),1);if(!Garnish.isMobileBrowser()){this.addListener(Garnish.$win,"resize","hideMenu")}},hideMenu:function(){this.menu.hide();this.$btn.removeClass("active");this.showingMenu=false;this.removeListener(Garnish.$doc,"mousedown");if(!Garnish.isMobileBrowser()){this.removeListener(Garnish.$doc,"resize")}},onOptionSelect:function(d){this.settings.onOptionSelect(d)}},{defaults:{onOptionSelect:c.noop}});Garnish.MixedInput=Garnish.Base.extend({$container:null,elements:null,focussedElement:null,blurTimeout:null,init:function(d,e){this.$container=c(d);this.setSettings(e,Garnish.MixedInput.defaults);this.elements=[];this.$container.attr("tabindex",0);this.addListener(this.$container,"focus","onFocus")},getElementIndex:function(d){return c.inArray(d,this.elements)},isText:function(d){return(d.prop("nodeName")=="INPUT")},onFocus:function(e){if(this.elements.length){var d=this.elements[0];this.setFocus(d);this.setCarotPos(d,0)}else{this.addTextElement()}},addTextElement:function(d){var e=new b(this);this.addElement(e.$input,d);return e},addElement:function(d,h){if(typeof h=="undefined"){if(this.focussedElement){var k=this.focussedElement,i=this.getElementIndex(k);if(this.isText(k)){var l=k.prop("selectionStart"),m=k.prop("selectionEnd"),e=k.val(),f=e.substring(0,l),j=e.substr(m);if(f&&j){k.val(f).trigger("change");var g=new b(this);g.$input.val(j).trigger("change");this.addElement(g.$input,i+1);h=i+1}else{if(!f){h=i}else{h=i+1}}}else{h=i+1}}else{h=this.elements.length}}if(typeof this.elements[h]!="undefined"){d.insertBefore(this.elements[h]);this.elements.splice(h,0,d)}else{h=this.elements.length;this.$container.append(d);this.elements.push(d)}if(!this.isText(d)){if(h==0||!this.isText(this.elements[h-1])){this.addTextElement(h);h++}if(h==this.elements.length-1||!this.isText(this.elements[h+1])){this.addTextElement(h+1)}}this.addListener(d,"click",function(){this.setFocus(d)});setTimeout(c.proxy(function(){this.setFocus(d)},this),1)},removeElement:function(d){var f=this.getElementIndex(d);if(f!=-1){this.elements.splice(f,1);if(!this.isText(d)){var i=this.elements[f-1],g=this.elements[f];if(this.isText(i)&&this.isText(g)){var h=i.val(),e=h+g.val();i.val(e).trigger("change");this.removeElement(g);this.setFocus(i);this.setCarotPos(i,h.length)}}d.remove()}},setFocus:function(d){this.$container.addClass("focus");if(!this.focussedElement){this.$container.attr("tabindex","-1")}else{this.blurFocussedElement()}d.attr("tabindex","0");d.focus();this.focussedElement=d;this.addListener(d,"blur",function(){this.blurTimeout=setTimeout(c.proxy(function(){if(this.focussedElement==d){this.blurFocussedElement();this.focussedElement=null;this.$container.removeClass("focus");this.$container.attr("tabindex","0")}},this),1)})},blurFocussedElement:function(){this.removeListener(this.focussedElement,"blur");this.focussedElement.attr("tabindex","-1")},focusPreviousElement:function(g){var e=this.getElementIndex(g);if(e>0){var d=this.elements[e-1];this.setFocus(d);if(this.isText(d)){var f=d.val().length;this.setCarotPos(d,f)}}},focusNextElement:function(f){var e=this.getElementIndex(f);if(e').appendTo(this.parentInput.$container);this.$input.css("margin-right",(2-b.padding)+"px");this.setWidth();this.addListener(this.$input,"focus","onFocus");this.addListener(this.$input,"blur","onBlur");this.addListener(this.$input,"keydown","onKeyDown");this.addListener(this.$input,"change","checkInput")},getIndex:function(){return this.parentInput.getElementIndex(this.$input)},buildStage:function(){this.$stage=c("").appendTo(Garnish.$bod);this.$stage.css({position:"absolute",top:-9999,left:-9999,wordWrap:"nowrap"});Garnish.copyTextStyles(this.$input,this.$stage)},getTextWidth:function(d){if(!this.$stage){this.buildStage()}if(d){d=d.replace(/&/g,"&");d=d.replace(//g,">");d=d.replace(/ /g," ")}this.$stage.html(d);this.stageWidth=this.$stage.width();return this.stageWidth},onFocus:function(){this.focussed=true;this.interval=setInterval(c.proxy(this,"checkInput"),Garnish.NiceText.interval);this.checkInput()},onBlur:function(){this.focussed=false;clearInterval(this.interval);this.checkInput()},onKeyDown:function(d){setTimeout(c.proxy(this,"checkInput"),1);switch(d.keyCode){case Garnish.LEFT_KEY:if(this.$input.prop("selectionStart")==0&&this.$input.prop("selectionEnd")==0){this.parentInput.focusPreviousElement(this.$input)}break;case Garnish.RIGHT_KEY:if(this.$input.prop("selectionStart")==this.val.length&&this.$input.prop("selectionEnd")==this.val.length){this.parentInput.focusNextElement(this.$input)}break;case Garnish.DELETE_KEY:if(this.$input.prop("selectionStart")==0&&this.$input.prop("selectionEnd")==0){this.parentInput.focusPreviousElement(this.$input);d.preventDefault()}}},getVal:function(){this.val=this.$input.val();return this.val},setVal:function(d){this.$input.val(d);this.checkInput()},checkInput:function(){var d=(this.val!==this.getVal());if(d){this.setWidth();this.onChange()}return d},setWidth:function(){if(this.stageWidth!==this.getTextWidth(this.val)){var d=this.stageWidth+b.padding;this.$input.width(d)}},onChange:c.noop},{padding:20});Garnish.Modal=Garnish.Base.extend({$container:null,$header:null,$body:null,$scrollpane:null,$footer:null,$footerBtns:null,$submitBtn:null,$shade:null,_headerHeight:null,_footerHeight:null,visible:false,dragger:null,init:function(d,e){if(!e&&Garnish.isObject(d)){e=d;d=null}this.setSettings(e,Garnish.Modal.defaults);if(d){this.$shade=c('').insertBefore(d)}else{this.$shade=c('').appendTo(Garnish.$bod)}if(d){this.setContainer(d);this.show()}Garnish.Modal.instances.push(this)},setContainer:function(d){this.$container=c(d);if(this.$container.data("modal")){Garnish.log("Double-instantiating a modal on an element");this.$container.data("modal").destroy()}this.$container.data("modal",this);this.$header=this.$container.find(".pane-head:first");this.$body=this.$container.find(".pane-body:first");this.$scrollpane=this.$body.children(".scrollpane:first");this.$footer=this.$container.find(".pane-foot:first");this.$footerBtns=this.$footer.find(".btn");this.$submitBtn=this.$footerBtns.filter(".submit:first");this.$closeBtn=this.$footerBtns.filter(".close:first");if(this.settings.draggable){var e=this.$header.add(this.$footer);if(e.length){this.dragger=new Garnish.DragMove(this.$container,{handle:this.$container})}}this.addListener(this.$container,"click",function(f){f.stopPropagation()});this.addListener(this.$container,"keydown","onKeyDown");this.addListener(this.$closeBtn,"click","hide")},show:function(){if(Garnish.Modal.visibleModal&&this.settings.closeOtherModals){Garnish.Modal.visibleModal.hide()}if(this.$container){this.$container.show();var d=this.getHeight();this.$container.css("margin-top",-Math.round(d/2));var e=Garnish.$win.width();if(this.$container.width()>e){this.$container.css({width:e,marginLeft:-Math.round(e/2)})}this.$container.delay(50).fadeIn(c.proxy(this,"onFadeIn"))}this.visible=true;Garnish.Modal.visibleModal=this;this.$shade.fadeIn(50);this.addListener(this.$shade,"click","hide");this.addListener(Garnish.$bod,"keyup",function(f){if(f.keyCode==Garnish.ESC_KEY){this.hide()}});this.settings.onShow()},hide:function(d){if(d){d.stopPropagation()}if(this.$container){this.$container.fadeOut("fast");this.removeListener(Garnish.$win,"resize")}this.visible=false;Garnish.Modal.visibleModal=null;this.$shade.fadeOut("fast",c.proxy(this,"onFadeOut"));this.removeListener(this.$shade,"click");this.removeListener(Garnish.$bod,"keyup");this.settings.onHide()},onFadeIn:function(){this.settings.onFadeIn()},onFadeOut:function(){this.settings.onFadeOut()},getHeight:function(){if(!this.$container){throw"Attempted to get the height of a modal whose container has not been set."}if(!this.visible){this.$container.show()}var d=this.$container.outerHeight();if(!this.visible){this.$container.hide()}return d},getWidth:function(){if(!this.$container){throw"Attempted to get the width of a modal whose container has not been set."}if(!this.visible){this.$container.show()}var d=this.$container.outerWidth();if(!this.visible){this.$container.hide()}return d},positionRelativeTo:function(h){if(!this.$container){throw"Attempted to position a modal whose container has not been set."}var e=c(h),j=e.offset(),g=Garnish.$bod.scrollTop(),f=j.top-g,d=this.getHeight();if(d').insertBefore(this.$input);this.$hint=c('
").appendTo(this.$menu);for(var e in this.options){var f=this.options[e];if(f=="-"){d=c("
").appendTo(this.$menu)}else{var h=c("").appendTo(d),g=c(""+f.label+"").appendTo(h);if(typeof f.onClick=="function"){(function(i,j){setTimeout(c.proxy(function(){i.mousedown(c.proxy(function(k){this.hideMenu();j.call(this.currentTarget,c.extend(k,{currentTarget:this.currentTarget}))},this))},this),1)}).call(this,g,f.onClick)}}}},showMenu:function(d){if(d.type=="mousedown"&&d.which!=Garnish.SECONDARY_CLICK){return}if(d.type=="contextmenu"){d.preventDefault()}if(this.showing&&d.currentTarget==this.currentTarget){return}this.currentTarget=d.currentTarget;if(!this.$menu){this.buildMenu()}this.$menu.appendTo(document.body);this.$menu.show();this.$menu.css({left:d.pageX+1,top:d.pageY-4});this.showing=true;setTimeout(c.proxy(function(){this.addListener(Garnish.$doc,"mousedown","hideMenu")},this),0)},hideMenu:function(){this.removeListener(Garnish.$doc,"mousedown");this.$menu.hide();this.showing=false},enable:function(){this.addListener(this.$target,"contextmenu,mousedown","showMenu")},disable:function(){this.removeListener(this.$target,"contextmenu,mousedown")}},{defaults:{menuClass:"menu"},counter:0});Garnish.Drag=Garnish.BaseDrag.extend({$draggee:null,otherItems:null,totalOtherItems:null,helpers:null,helperTargets:null,helperPositions:null,helperLagIncrement:null,updateHelperPosInterval:null,init:function(d,e){if(!e&&Garnish.isObject(d)){e=d;d=null}e=c.extend({},Garnish.Drag.defaults,e);this.base(d,e)},onDragStart:function(){this.helpers=[];this.helperTargets=[];this.helperPositions=[];this.getDraggee();this.draggeeIndex=c.inArray(this.$draggee[0],this.$items);this.draggeeDisplay=this.$draggee.css("display");this.createHelpers();if(this.settings.removeDraggee){this.$draggee.hide()}else{this.$draggee.css("visibility","hidden")}this.lastMouseX=this.lastMouseY=null;this.otherItems=[];for(var d=0;d').appendTo(Garnish.$bod);this.$tip=c('').appendTo(this.$hud);this.$body=c('').appendTo(this.$hud).append(f);this.show();this.addListener(this.$hud,"click",function(g){g.stopPropagation()})},show:function(f){if(this.showing){return}if(Garnish.HUD.active){Garnish.HUD.active.hide()}this.$hud.show();this.windowWidth=Garnish.$win.width();this.windowHeight=Garnish.$win.height();this.windowScrollLeft=Garnish.$win.scrollLeft();this.windowScrollTop=Garnish.$win.scrollTop();this.triggerWidth=this.$trigger.outerWidth();this.triggerHeight=this.$trigger.outerHeight();this.triggerOffset=this.$trigger.offset();this.triggerOffsetRight=this.triggerOffset.left+this.triggerWidth;this.triggerOffsetBottom=this.triggerOffset.top+this.triggerHeight;this.triggerOffsetLeft=this.triggerOffset.left;this.triggerOffsetTop=this.triggerOffset.top;this.width=this.$hud.outerWidth();this.height=this.$hud.outerHeight();this.minHorizontalClearance=this.width+this.settings.triggerSpacing+this.settings.windowSpacing;this.minVerticalClearance=this.height+this.settings.triggerSpacing+this.settings.windowSpacing;this.rightClearance=this.windowWidth+this.windowScrollLeft-this.triggerOffsetRight;this.bottomClearance=this.windowHeight+this.windowScrollTop-this.triggerOffsetBottom;this.leftClearance=this.triggerOffsetLeft-this.windowScrollLeft;this.topClearance=this.triggerOffsetTop-this.windowScrollTop;if(this.bottomClearance>=this.minVerticalClearance){var i=this.triggerOffsetBottom+this.settings.triggerSpacing;this.$hud.css("top",i);this._setLeftPos();this._setTipClass("top")}else{if(this.topClearance>=this.minVerticalClearance){var i=this.triggerOffsetTop-(this.height+this.settings.triggerSpacing);this.$hud.css("top",i);this._setLeftPos();this._setTipClass("bottom")}else{if(this.rightClearance>=this.minHorizontalClearance){var h=this.triggerOffsetRight+this.settings.triggerSpacing;this.$hud.css("left",h);this._setTopPos();this._setTipClass("left")}else{if(this.leftClearance>=this.minHorizontalClearance){var h=this.triggerOffsetLeft-(this.width+this.settings.triggerSpacing);this.$hud.css("left",h);this._setTopPos();this._setTipClass("right")}else{var e=this.minHorizontalClearance-this.rightClearance,g=this.minVerticalClearance-this.bottomClearance;if(e>=g){var h=this.windowWidth-(this.width+this.settings.windowSpacing),d=this.triggerOffsetLeft+this.settings.triggerSpacing;if(hg){f=g}if(ff){h=f}if(h0){d=0}}this.$innerContainer.css("marginLeft",d)},_onDragStop:function(){var d=this._getMargin();if(d>-16){this.turnOn()}else{this.turnOff()}},destroy:function(){this.base();this.dragger.destroy()}},{offMargin:-50,defaults:{onChange:c.noop}});Garnish.Menu=Garnish.Base.extend({settings:null,$container:null,$options:null,$trigger:null,init:function(d,e){this.setSettings(e,Garnish.Menu.defaults);this.$container=c(d).appendTo(Garnish.$bod);this.$options=this.$container.find("a");this.$options.data("menu",this);if(this.settings.attachToElement){this.$trigger=c(this.settings.attachToElement)}this.addListener(this.$container,"mousedown",function(f){f.stopPropagation()});this.addListener(this.$options,"click","selectOption")},setPositionRelativeToButton:function(){var h={minWidth:(n-32)};var d=Garnish.$win.height(),i=Garnish.$win.scrollTop(),m=this.$trigger.offset(),n=this.$trigger.outerWidth(),g=this.$trigger.outerHeight(),e=m.top+g,k=m.top,f=this.$container.outerHeight(),l=d+i-e,j=k-i;if(l>=g||l>=j){h.top=e}else{h.top=k-f}switch(this.$container.data("align")){case"right":h.right=1+Garnish.$win.width()-(m.left+n);break;case"center":h.left=Math.round((m.left+n/2)-(this.$container.outerWidth()/2));break;default:h.left=1+m.left}this.$container.css(h)},show:function(){if(this.$trigger){this.setPositionRelativeToButton()}this.$container.fadeIn(50)},hide:function(){this.$container.fadeOut("fast")},selectOption:function(d){this.settings.onOptionSelect(d.currentTarget);this.hide()}},{defaults:{attachToElement:null,onOptionSelect:c.noop}});Garnish.MenuBtn=Garnish.Base.extend({$btn:null,menu:null,showingMenu:false,init:function(d,f){this.$btn=c(d);if(this.$btn.data("menubtn")){Garnish.log("Double-instantiating a menu button on an element");this.$btn.data("menubtn").destroy()}this.$btn.data("menubtn",this);this.setSettings(f,Garnish.MenuBtn.defaults);var e=this.$btn.next(".menu");this.menu=new Garnish.Menu(e,{attachToElement:this.$btn,onOptionSelect:c.proxy(this,"onOptionSelect")});this.addListener(this.$btn,"mousedown","onMouseDown")},onMouseDown:function(d){if(d.which!=Garnish.PRIMARY_CLICK||d.metaKey){return}d.preventDefault();if(this.showingMenu){this.hideMenu()}else{this.showMenu()}},showMenu:function(){this.menu.show();this.$btn.addClass("active");this.showingMenu=true;setTimeout(c.proxy(function(){this.addListener(Garnish.$doc,"mousedown","onMouseDown")},this),1);if(!Garnish.isMobileBrowser()){this.addListener(Garnish.$win,"resize","hideMenu")}},hideMenu:function(){this.menu.hide();this.$btn.removeClass("active");this.showingMenu=false;this.removeListener(Garnish.$doc,"mousedown");if(!Garnish.isMobileBrowser()){this.removeListener(Garnish.$doc,"resize")}},onOptionSelect:function(d){this.settings.onOptionSelect(d)}},{defaults:{onOptionSelect:c.noop}});Garnish.MixedInput=Garnish.Base.extend({$container:null,elements:null,focussedElement:null,blurTimeout:null,init:function(d,e){this.$container=c(d);this.setSettings(e,Garnish.MixedInput.defaults);this.elements=[];this.$container.attr("tabindex",0);this.addListener(this.$container,"focus","onFocus")},getElementIndex:function(d){return c.inArray(d,this.elements)},isText:function(d){return(d.prop("nodeName")=="INPUT")},onFocus:function(e){if(this.elements.length){var d=this.elements[0];this.setFocus(d);this.setCarotPos(d,0)}else{this.addTextElement()}},addTextElement:function(d){var e=new b(this);this.addElement(e.$input,d);return e},addElement:function(d,h){if(typeof h=="undefined"){if(this.focussedElement){var k=this.focussedElement,i=this.getElementIndex(k);if(this.isText(k)){var l=k.prop("selectionStart"),m=k.prop("selectionEnd"),e=k.val(),f=e.substring(0,l),j=e.substr(m);if(f&&j){k.val(f).trigger("change");var g=new b(this);g.$input.val(j).trigger("change");this.addElement(g.$input,i+1);h=i+1}else{if(!f){h=i}else{h=i+1}}}else{h=i+1}}else{h=this.elements.length}}if(typeof this.elements[h]!="undefined"){d.insertBefore(this.elements[h]);this.elements.splice(h,0,d)}else{h=this.elements.length;this.$container.append(d);this.elements.push(d)}if(!this.isText(d)){if(h==0||!this.isText(this.elements[h-1])){this.addTextElement(h);h++}if(h==this.elements.length-1||!this.isText(this.elements[h+1])){this.addTextElement(h+1)}}this.addListener(d,"click",function(){this.setFocus(d)});setTimeout(c.proxy(function(){this.setFocus(d)},this),1)},removeElement:function(d){var f=this.getElementIndex(d);if(f!=-1){this.elements.splice(f,1);if(!this.isText(d)){var i=this.elements[f-1],g=this.elements[f];if(this.isText(i)&&this.isText(g)){var h=i.val(),e=h+g.val();i.val(e).trigger("change");this.removeElement(g);this.setFocus(i);this.setCarotPos(i,h.length)}}d.remove()}},setFocus:function(d){this.$container.addClass("focus");if(!this.focussedElement){this.$container.attr("tabindex","-1")}else{this.blurFocussedElement()}d.attr("tabindex","0");d.focus();this.focussedElement=d;this.addListener(d,"blur",function(){this.blurTimeout=setTimeout(c.proxy(function(){if(this.focussedElement==d){this.blurFocussedElement();this.focussedElement=null;this.$container.removeClass("focus");this.$container.attr("tabindex","0")}},this),1)})},blurFocussedElement:function(){this.removeListener(this.focussedElement,"blur");this.focussedElement.attr("tabindex","-1")},focusPreviousElement:function(g){var e=this.getElementIndex(g);if(e>0){var d=this.elements[e-1];this.setFocus(d);if(this.isText(d)){var f=d.val().length;this.setCarotPos(d,f)}}},focusNextElement:function(f){var e=this.getElementIndex(f);if(e').appendTo(this.parentInput.$container);this.$input.css("margin-right",(2-b.padding)+"px");this.setWidth();this.addListener(this.$input,"focus","onFocus");this.addListener(this.$input,"blur","onBlur");this.addListener(this.$input,"keydown","onKeyDown");this.addListener(this.$input,"change","checkInput")},getIndex:function(){return this.parentInput.getElementIndex(this.$input)},buildStage:function(){this.$stage=c("").appendTo(Garnish.$bod);this.$stage.css({position:"absolute",top:-9999,left:-9999,wordWrap:"nowrap"});Garnish.copyTextStyles(this.$input,this.$stage)},getTextWidth:function(d){if(!this.$stage){this.buildStage()}if(d){d=d.replace(/&/g,"&");d=d.replace(//g,">");d=d.replace(/ /g," ")}this.$stage.html(d);this.stageWidth=this.$stage.width();return this.stageWidth},onFocus:function(){this.focussed=true;this.interval=setInterval(c.proxy(this,"checkInput"),Garnish.NiceText.interval);this.checkInput()},onBlur:function(){this.focussed=false;clearInterval(this.interval);this.checkInput()},onKeyDown:function(d){setTimeout(c.proxy(this,"checkInput"),1);switch(d.keyCode){case Garnish.LEFT_KEY:if(this.$input.prop("selectionStart")==0&&this.$input.prop("selectionEnd")==0){this.parentInput.focusPreviousElement(this.$input)}break;case Garnish.RIGHT_KEY:if(this.$input.prop("selectionStart")==this.val.length&&this.$input.prop("selectionEnd")==this.val.length){this.parentInput.focusNextElement(this.$input)}break;case Garnish.DELETE_KEY:if(this.$input.prop("selectionStart")==0&&this.$input.prop("selectionEnd")==0){this.parentInput.focusPreviousElement(this.$input);d.preventDefault()}}},getVal:function(){this.val=this.$input.val();return this.val},setVal:function(d){this.$input.val(d);this.checkInput()},checkInput:function(){var d=(this.val!==this.getVal());if(d){this.setWidth();this.onChange()}return d},setWidth:function(){if(this.stageWidth!==this.getTextWidth(this.val)){var d=this.stageWidth+b.padding;this.$input.width(d)}},onChange:c.noop},{padding:20});Garnish.Modal=Garnish.Base.extend({$container:null,$header:null,$body:null,$scrollpane:null,$footer:null,$footerBtns:null,$submitBtn:null,$shade:null,_headerHeight:null,_footerHeight:null,visible:false,dragger:null,init:function(d,e){if(!e&&Garnish.isObject(d)){e=d;d=null}this.setSettings(e,Garnish.Modal.defaults);if(d){this.$shade=c('').insertBefore(d)}else{this.$shade=c('').appendTo(Garnish.$bod)}if(d){this.setContainer(d);this.show()}Garnish.Modal.instances.push(this)},setContainer:function(d){this.$container=c(d);if(this.$container.data("modal")){Garnish.log("Double-instantiating a modal on an element");this.$container.data("modal").destroy()}this.$container.data("modal",this);this.$header=this.$container.find(".pane-head:first");this.$body=this.$container.find(".pane-body:first");this.$scrollpane=this.$body.children(".scrollpane:first");this.$footer=this.$container.find(".pane-foot:first");this.$footerBtns=this.$footer.find(".btn");this.$submitBtn=this.$footerBtns.filter(".submit:first");this.$closeBtn=this.$footerBtns.filter(".close:first");if(this.settings.draggable){var e=this.$header.add(this.$footer);if(e.length){this.dragger=new Garnish.DragMove(this.$container,{handle:this.$container})}}this.addListener(this.$container,"click",function(f){f.stopPropagation()});this.addListener(this.$container,"keydown","onKeyDown");this.addListener(this.$closeBtn,"click","hide")},show:function(){if(Garnish.Modal.visibleModal&&this.settings.closeOtherModals){Garnish.Modal.visibleModal.hide()}if(this.$container){this.$container.show();var d=this.getHeight();this.$container.css("margin-top",-Math.round(d/2));var e=Garnish.$win.width();if(this.$container.width()>e){this.$container.css({width:e,marginLeft:-Math.round(e/2)})}this.$container.delay(50).fadeIn(c.proxy(this,"onFadeIn"))}this.visible=true;Garnish.Modal.visibleModal=this;this.$shade.fadeIn(50);this.addListener(this.$shade,"click","hide");this.addListener(Garnish.$bod,"keyup",function(f){if(f.keyCode==Garnish.ESC_KEY){this.hide()}});this.settings.onShow()},hide:function(d){if(d){d.stopPropagation()}if(this.$container){this.$container.fadeOut("fast");this.removeListener(Garnish.$win,"resize")}this.visible=false;Garnish.Modal.visibleModal=null;this.$shade.fadeOut("fast",c.proxy(this,"onFadeOut"));this.removeListener(this.$shade,"click");this.removeListener(Garnish.$bod,"keyup");this.settings.onHide()},onFadeIn:function(){this.settings.onFadeIn()},onFadeOut:function(){this.settings.onFadeOut()},getHeight:function(){if(!this.$container){throw"Attempted to get the height of a modal whose container has not been set."}if(!this.visible){this.$container.show()}var d=this.$container.outerHeight();if(!this.visible){this.$container.hide()}return d},getWidth:function(){if(!this.$container){throw"Attempted to get the width of a modal whose container has not been set."}if(!this.visible){this.$container.show()}var d=this.$container.outerWidth();if(!this.visible){this.$container.hide()}return d},positionRelativeTo:function(h){if(!this.$container){throw"Attempted to position a modal whose container has not been set."}var e=c(h),j=e.offset(),g=Garnish.$bod.scrollTop(),f=j.top-g,d=this.getHeight();if(d').insertBefore(this.$input);this.$hint=c('
'+this.settings.hint+"
").appendTo(this.$hintContainer);this.$hint.css({top:(parseInt(this.$input.css("borderTopWidth"))+parseInt(this.$input.css("paddingTop"))),left:(parseInt(this.$input.css("borderLeftWidth"))+parseInt(this.$input.css("paddingLeft"))+1)});Garnish.copyTextStyles(this.$input,this.$hint);if(this.val){this.$hint.hide()}else{this.showingHint=true}this.addListener(this.$hint,"mousedown",function(f){f.preventDefault();this.$input.focus()})}this.addListener(this.$input,"focus","onFocus");this.addListener(this.$input,"blur","onBlur");this.addListener(this.$input,"keydown","onKeyDown");this.initialized=true},getVal:function(){this.val=this.$input.val();return this.val},showHint:function(){this.$hint.fadeIn(Garnish.NiceText.hintFadeDuration);this.showingHint=true},hideHint:function(){this.$hint.fadeOut(Garnish.NiceText.hintFadeDuration);this.showingHint=false},checkInput:function(){var d=(this.val!==this.getVal());if(d){if(this.$hint){if(this.showingHint&&this.val){this.hideHint()}else{if(!this.showingHint&&!this.val){this.showHint()}}}if(this.autoHeight){this.updateHeight()}}return d},buildStage:function(){this.$stage=c("").appendTo(Garnish.$bod);this.$stage.css({position:"absolute",top:-9999,left:-9999,wordWrap:"break-word"});this.inputBoxSizing=this.$input.css("box-sizing");if(this.inputBoxSizing=="border-box"){this.$stage.css({"border-top-width":this.$input.css("border-top-width"),"border-right-width":this.$input.css("border-right-width"),"border-bottom-width":this.$input.css("border-bottom-width"),"border-left-width":this.$input.css("border-left-width"),"padding-top":this.$input.css("padding-top"),"padding-right":this.$input.css("padding-right"),"padding-bottom":this.$input.css("padding-bottom"),"padding-left":this.$input.css("padding-left"),"-webkit-box-sizing":this.inputBoxSizing,"-moz-box-sizing":this.inputBoxSizing,"box-sizing":this.inputBoxSizing})}Garnish.copyTextStyles(this.$input,this.$stage)},getHeightForValue:function(e){if(!this.$stage){this.buildStage()}if(this.inputBoxSizing=="border-box"){this.$stage.css("width",this.$input.outerWidth())}else{this.$stage.css("width",this.$input.width())}if(!e){e=" ";for(var d=1;d "}}else{e=e.replace(/&/g,"&");e=e.replace(//g,">");e=e.replace(/ /g," ");e=e.replace(/[\n\r]$/g," ");e=e.replace(/[\n\r]/g," ")}this.$stage.html(e);if(this.inputBoxSizing=="border-box"){this.getHeightForValue._height=this.$stage.outerHeight()}else{this.getHeightForValue._height=this.$stage.height()}if(this.minHeight&&this.getHeightForValue._height").hide();this.$showPasswordToggle.addClass("password-toggle");this.$showPasswordToggle.insertAfter(this.$passwordInput);this.addListener(this.$showPasswordToggle,"mousedown","onToggleMouseDown");this.hidePassword()},setCurrentInput:function(d){if(this.$currentInput){d.addClass("focus");this.$currentInput.replaceWith(d);d.focus();d.removeClass("focus");d.val(this.$currentInput.val())}this.$currentInput=d;this.addListener(this.$currentInput,"keypress,keyup,change,blur","onInputChange")},updateToggleLabel:function(d){this.$showPasswordToggle.text(d)},showPassword:function(){if(this.showingPassword){return}if(!this.$textInput){this.$textInput=this.$passwordInput.clone(true);this.$textInput.attr("type","text")}this.setCurrentInput(this.$textInput);this.updateToggleLabel(Garnish.PasswordInput.lang.Hide);this.showingPassword=true},hidePassword:function(){if(this.showingPassword===false){return}this.setCurrentInput(this.$passwordInput);this.updateToggleLabel(Garnish.PasswordInput.lang.Show);this.showingPassword=false;this.addListener(this.$passwordInput,"keydown","onKeyDown")},togglePassword:function(){if(this.showingPassword){this.hidePassword()}else{this.showPassword()}},onKeyDown:function(d){if(d.keyCode==Garnish.ALT_KEY&&this.$currentInput.val()){this.showPassword();this.$showPasswordToggle.hide();this.addListener(this.$textInput,"keyup","onKeyUp")}},onKeyUp:function(d){d.preventDefault();if(d.keyCode==Garnish.ALT_KEY){this.hidePassword();this.$showPasswordToggle.show()}},onInputChange:function(){if(this.$currentInput.val()){this.$showPasswordToggle.show()}else{this.$showPasswordToggle.hide()}},onToggleMouseDown:function(d){d.preventDefault();if(this.$currentInput[0].setSelectionRange){var e=this.$currentInput[0].selectionStart,f=this.$currentInput[0].selectionEnd}this.togglePassword();if(this.$currentInput[0].setSelectionRange){this.$currentInput[0].setSelectionRange(e,f)}}},{lang:{Show:"Show",Hide:"Hide"}});Garnish.Pill=Garnish.Base.extend({$outerContainer:null,$innerContainer:null,$btns:null,$selectedBtn:null,$input:null,init:function(d){this.$outerContainer=c(d);if(this.$outerContainer.data("pill")){Garnish.log("Double-instantiating a pill on an element");this.$outerContainer.data("pill").destroy()}this.$outerContainer.data("pill",this);this.$innerContainer=this.$outerContainer.find(".btngroup:first");this.$btns=this.$innerContainer.find(".btn");this.$selectedBtn=this.$btns.filter(".active:first");this.$input=this.$outerContainer.find("input:first");Garnish.preventOutlineOnMouseFocus(this.$innerContainer);this.addListener(this.$btns,"mousedown","onMouseDown");this.addListener(this.$innerContainer,"keydown","onKeyDown")},select:function(d){this.$selectedBtn.removeClass("active");var e=c(d);e.addClass("active");this.$input.val(e.attr("data-value"));this.$selectedBtn=e},onMouseDown:function(d){this.select(d.currentTarget)},_getSelectedBtnIndex:function(){if(typeof this.$selectedBtn[0]!="undefined"){return c.inArray(this.$selectedBtn[0],this.$btns)}else{return -1}},onKeyDown:function(f){switch(f.keyCode){case Garnish.RIGHT_KEY:if(!this.$selectedBtn.length){this.select(this.$btns[this.$btns.length-1])}else{var d=this._getSelectedBtnIndex()+1;if(typeof this.$btns[d]!="undefined"){this.select(this.$btns[d])}}f.preventDefault();break;case Garnish.LEFT_KEY:if(!this.$selectedBtn.length){this.select(this.$btns[0])}else{var e=this._getSelectedBtnIndex()-1;if(typeof this.$btns[e]!="undefined"){this.select(this.$btns[e])}}f.preventDefault();break}}});Garnish.Select=Garnish.Base.extend({$container:null,$items:null,totalSelected:null,mousedownX:null,mousedownY:null,mouseUpTimeout:null,mouseUpTimeoutDuration:null,callbackTimeout:null,$focusable:null,$first:null,first:null,$last:null,last:null,init:function(d,e,f){this.$container=c(d);if(!f&&Garnish.isObject(e)){f=e;e=null}if(this.$container.data("select")){Garnish.log("Double-instantiating a select on an element");this.$container.data("select").destroy()}this.$container.data("select",this);this.setSettings(f,Garnish.Select.defaults);this.mouseUpTimeoutDuration=(this.settings.waitForDblClick?300:0);this.$items=c();this.addItems(e);this.addListener(this.$container,"click",function(g){if(this.ignoreClick){this.ignoreClick=false}else{this.deselectAll(true)}})},getItemIndex:function(d){return this.$items.index(d[0])},isSelected:function(d){return d.hasClass(this.settings.selectedClass)},selectItem:function(d){if(!this.settings.multi){this.deselectAll()}d.addClass(this.settings.selectedClass);this.$first=this.$last=d;this.first=this.last=this.getItemIndex(d);this.setFocusableItem(d);d.focus();this.totalSelected++;this.setCallbackTimeout()},selectAll:function(){if(!this.settings.multi||!this.$items.length){return}this.first=0;this.last=this.$items.length-1;this.$first=c(this.$items[this.first]);this.$last=c(this.$items[this.last]);this.$items.addClass(this.settings.selectedClass);this.totalSelected=this.$items.length;this.setCallbackTimeout()},selectRange:function(e){if(!this.settings.multi){return this.selectItem(e)}this.deselectAll();this.$last=e;this.last=this.getItemIndex(e);this.setFocusableItem(e);e.focus();if(this.first0)},isNextItem:function(d){return(d")}}}},getItemAbove:function(d){if(this.isPreviousItem(d)){if(this.settings.vertical){return this.getPreviousItem(d)}else{if(!this.settings.horizontal){return this.getClosestItem(d,Garnish.Y_AXIS,"<")}}}},getItemBelow:function(d){if(this.isNextItem(d)){if(this.settings.vertical){return this.getNextItem(d)}else{if(!this.settings.horizontal){return this.getClosestItem(d,Garnish.Y_AXIS,">")}}}},getClosestItem:function(k,e,f){var d=Garnish.Select.closestItemAxisProps[e],j=Garnish.Select.closestItemDirectionProps[f];var p=c(this.$items[k]),o=p.offset(),q=o[d.midpointOffset]+Math.round(p[d.midpointSizeFunc]()/2),l=null,m=null,t=null;for(var g=k+j.step;(typeof this.$items[g]!="undefined");g+=j.step){var n=c(this.$items[g]),s=n.offset();if(j.isNextRow(s[d.rowOffset],o[d.rowOffset])){if(l===null){l=s[d.rowOffset]}else{if(s[d.rowOffset]!=l){break}}var r=s[d.midpointOffset]+Math.round(n[d.midpointSizeFunc]()/2),h=Math.abs(q-r);if(m===null||hd)}},">":{step:1,isNextRow:function(e,d){return(e>d)},isWrongDirection:function(e,d){return(edb->createCommand()->delete('tagsets', array('id' => $tagSetId));
return (bool) $affectedRows;
}
+
+ // Tags
+
+ /**
+ * Saves a tag.
+ *
+ * @param TagModel $tag
+ * @throws Exception
+ * @return bool
+ */
+ public function saveTag(TagModel $tag)
+ {
+ $isNewTag = !$tag->id;
+
+ // Tag data
+ if (!$isNewTag)
+ {
+ $tagRecord = TagRecord::model()->with('element')->findById($tag->id);
+
+ if (!$tagRecord)
+ {
+ throw new Exception(Craft::t('No tag exists with the ID “{id}”', array('id' => $tag->id)));
+ }
+
+ $elementRecord = $tagRecord->element;
+
+ // If tag->setId is null and there is an tagRecord setId, we assume this is a front-end edit.
+ if ($tag->setId === null && $tagRecord->setId)
+ {
+ $tag->setId = $tagRecord->setId;
+ }
+ }
+ else
+ {
+ $tagRecord = new TagRecord();
+
+ $elementRecord = new ElementRecord();
+ $elementRecord->type = ElementType::Tag;
+ }
+
+ $tagRecord->setId = $tag->setId;
+ $tagRecord->name = $tag->name;
+
+ $tagRecord->validate();
+ $tag->addErrors($tagRecord->getErrors());
+
+ $elementRecord->validate();
+ $tag->addErrors($elementRecord->getErrors());
+
+ if (!$tag->hasErrors())
+ {
+ // Save the element record first
+ $elementRecord->save(false);
+
+ // Now that we have an element ID, save it on the other stuff
+ if (!$tag->id)
+ {
+ $tag->id = $elementRecord->id;
+ $tagRecord->id = $tag->id;
+ }
+
+ $tagRecord->save(false);
+
+ // Update the search index
+ craft()->search->indexElementAttributes($tag, $tag->locale);
+
+ // Fire an 'onSaveTag' event
+ $this->onSaveTag(new Event($this, array(
+ 'tag' => $tag,
+ 'isNewTag' => $isNewTag
+ )));
+
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+ }
+
+ /**
+ * Fires an 'onSaveTag' event.
+ *
+ * @param Event $event
+ */
+ public function onSaveTag(Event $event)
+ {
+ $this->raiseEvent('onSaveTag', $event);
+ }
+
}
diff --git a/src/templates/_components/fieldtypes/Tags/input.html b/src/templates/_components/fieldtypes/Tags/input.html
new file mode 100644
index 00000000000..b81545a5bcf
--- /dev/null
+++ b/src/templates/_components/fieldtypes/Tags/input.html
@@ -0,0 +1,31 @@
+{% set elements = (elements is defined ? elements : []) -%}
+{% set criteria = (criteria is defined and criteria ? criteria : null) -%}
+{% from "_includes/forms" import text %}
+
+
+
+ {% for element in elements %}
+ {% include "_elements/element" with { mode: 'field' } %}
+ {% endfor %}
+