// ******************************************************* // * SimpleButton // ******************************************************* var SimpleButton = Class.create({ initialize: function(elControl) { this.elControl = $(elControl); this.ID_ = this.elControl.readAttribute('id'); this.elControl.JSControl=this; this.visibility=this.elControl.readAttribute('visibility'); if (!(this.visibility=='yes' || this.visibility=='vo' || this.visibility=='ro' || this.visibility=='no')) this.visibility='yes'; // 'disabled' support left for backward compatibility. TODO: remove in Effi-1.8.x version var dis=this.elControl.readAttribute('disabled'); if (dis=='yes' || dis=='disabled') this.visibility='vo'; this.setVisibility(this.visibility); this.elControl.observe('focus', this.OnFocus.bind(this, true)); this.elControl.observe('blur', this.OnFocus.bind(this, false)); this.elControl.observe('click', this.DoClick.bind(this)); this.elControl.observe('keydown', this.OnKeyDown.bind(this)); GDocumentEventManager.AddTransparentControl(this.ClassName()); }, Shortcut: function() { if (this.Disabled()) return; this.OnClick(); }, ClassName: function() { return "SimpleButton"; }, Disabled: function() { return (this.visibility!='yes'); }, OnFocus: function(focus, evt) { if (focus) this.elControl.addClassName('FocusedButton'); else this.elControl.removeClassName('FocusedButton'); }, OnKeyDown: function(evt) { var event = Event.extend(evt || window.event); if (this.Disabled()) return; if (evt.altKey || evt.ctrlKey) return; var key = event.keyCode; if (key == 13 || key == 32) this.OnClick(); else return; StopEvent(event); return false; }, DoClick: function(evt) { if (this.Disabled()) return; this.elControl.focus(); this.OnClick(evt); }, OnClick: function() { new AEvent("CLICK", {}, this); }, Busy: function(isBusy) { if(isBusy && this.visibility=="yes") this.setVisibility('vo'); if(!isBusy) this.setVisibility(this.visibility); }, // SetValue: function() { }, Attribute: function(sName) { return this.elControl.readAttribute(sName); }, setVisibility: function(sValue) { var c=this.elControl; if (!(sValue=='yes' || sValue=='vo' || sValue=='ro' || sValue=='no')) sValue='yes'; if (sValue!='yes') { c.addClassName('DisabledButton'); c.removeClassName('EnabledButton'); c.tabIndex=-1; // Chrome bug workaround if (sValue=='no') c.addClassName('HiddenButton'); else c.removeClassName('HiddenButton'); // 'disabled' support left for backward compatibility. TODO: remove in Effi-1.8.x version c.writeAttribute('disabled', 'disabled'); } else { c.removeClassName('DisabledButton'); c.removeClassName('HiddenButton'); c.addClassName('EnabledButton'); if(this.tabIndex) c.tabIndex=this.tabIndex; // Chrome bug workaround // 'disabled' support left for backward compatibility. TODO: remove in Effi-1.8.x version c.writeAttribute('disabled', false); } c.writeAttribute('visibility', sValue); }, SetAttribute: function(sName, sValue) { var c=this.elControl; if (sName=='visibility') { this.visibility=sValue; this.setVisibility(this.visibility); } // 'disabled' support left for backward compatibility. TODO: remove in Effi-1.8.x version else if (sName=='disabled') { var vis=(sValue=='yes' || sValue=='disabled') ? 'vo' : 'yes'; this.visibility=vis; this.setVisibility(this.visibility); } else c.writeAttribute(sName, sValue); }, SetTabOrder: function(nTabBase) { this.tabIndex=nTabBase; if(!this.Disabled()) this.elControl.tabIndex=this.tabIndex; else this.elControl.tabIndex=-1; return ++nTabBase; }, ID: function() { return this.ID_; } }); // ******************************************************* // * AButton // * This is a SimpleButton that has no default action // ******************************************************* var AButton = Class.create(SimpleButton, { }); // ******************************************************* // * DropContainer // * Container to display dropping panels filled in with other controls // ******************************************************* var DropContainer = Class.create({ initialize: function (opts) { this.id = opts.id; this.element = $(opts.element); this.mouseDownCallback = this.onMouseDown.bind(this); this.documentMouseDownCallback = this.onDocumentMouseDown.bind(this); this.element.observe('mousedown', this.mouseDownCallback); }, show: function(x, y) { var bSetPos=false; var positionedParent=null; if(typeof(x)!='undefined' && typeof(y)!='undefined' && x!==null && y!==null) { positionedParent=this.element.getOffsetParent(); var pvo=positionedParent.viewportOffset(); y-=pvo.top; x-=pvo.left; this.element.setStyle({position: 'absolute', visibility: 'hidden', left: '-1000px', top: '-1000px'}); bSetPos=true; } this.element.setStyle({display: '', visibility: '', position: 'absolute', display: 'block'}); if (bSetPos) { var dx=positionedParent.offsetWidth-(x+this.element.offsetWidth); if (dx<0) x+=dx; // horizontal correction this.element.setStyle({left: x+'px', top: y+'px'}); } this.element.tabIndex=1; this.element.focus(); Event.observe(document, "mousedown", this.documentMouseDownCallback); }, hide: function() { this.element.setStyle({display: 'none'}); Event.stopObserving(document, "mousedown", this.documentMouseDownCallback); }, toggle: function(x, y) { if (this.element.getStyle('display') == 'none') this.show(x, y); else this.hide(); }, onMouseDown: function(event) { event.stop(); }, onDocumentMouseDown: function(event) { if (!event.ctrlKey && !event.isRightClick()) this.hide(); } }); // ******************************************************* // * DropButton // * Button which is a drop-down with a list of actions // ******************************************************* var DropButton = Class.create(SimpleButton, { initialize: function(element) { this.elControl = $(element); this.ID_ = this.elControl.readAttribute('id'); this.elControl.JSControl=this; var vis=this.elControl.readAttribute('visibility'); this.setVisibility(vis); this.elControl.observe('focus', this.OnFocus.bind(this, true)); this.elControl.observe('blur', this.OnFocus.bind(this, false)); this.elControl.observe('click', this.DoClick.bind(this)); this.elControl.observe('keyup', this.OnKeyUp.bind(this)); this.element = $(element); this.optionUL = $(element+"_UL"); this.element.JSControl = this; this.ID_ = this.element.readAttribute('id'); this.buttonMouseDownCallback = this.OnButtonMouseDown.bind(this); this.menuObj = new DropContainer({ id: this.ID(), element: this.optionUL }); this.element.observe('mousedown', this.buttonMouseDownCallback); }, OnButtonMouseDown: function(event) { if(event.ctrlKey || event.isRightClick() || this.Disabled()) return; var element = Event.element(event); var y = getAbsoluteOffset(this.element, "offsetTop")+this.element.offsetHeight; var x = getAbsoluteOffset(this.element, "offsetLeft"); this.menuObj.toggle(x, y); event.stop(); }, OnChange: function(evt) { new AEvent("CHANGE", {}, this); new AEvent("CLICK", {}, this); } }); // ******************************************************* // * SimpleLink // ******************************************************* var SimpleLink = Class.create({ initialize: function(elLink) { this.elControl = $(elControl); this.ID_ = this.elControl.readAttribute('id'); this.elControl.JSControl=this; this.elControl.observe('click', this.OnClick.bind(this)); }, OnClick: function() { new AEvent("CLICK", {}, this); }, SetValue: function() { }, Value: function() { return null; }, SetAttribute: function(sName, sValue) { // that was very BAD line: //this.elControl.writeAttribute(sName, sValue); }, SetTabOrder: function(nTabBase) { this.elControl.tabIndex=nTabBase; return ++nTabBase; }, ID: function() { return this.ID_; } });