/// Type.registerNamespace("Bleroy.Sample"); Bleroy.Sample.EditInPlace = function(element) { /// Transforms a text input into an edit in place control. /// The input to extend. var tagName = element.tagName.toUpperCase(); if (tagName !== "INPUT" && tagName !== "TEXTAREA") { throw Error.argument("element", "Element must be an input or a textarea."); } Bleroy.Sample.EditInPlace.initializeBase(this, [element]); this._oldBorderColor = this._class = this._blur = this._focus = null; } Bleroy.Sample.EditInPlace.prototype = { get_cssClass: function() { /// The class to apply to the label. return this._class; }, set_cssClass: function(value) { var elt = this.get_element(); if (this._class) { Sys.UI.DomElement.removeCssClass(elt, this._class); } if (this.get_isEditing()) { Sys.UI.DomElement.addCssClass(elt, value); } this._class = value; }, get_isEditing: function() { /// True if in edit mode. return this.get_element().style.visibility !== "hidden"; }, beginEdit: function() { /// Puts the behavior in edit mode var elt = this.get_element(); if (this._class) Sys.UI.DomElement.addCssClass(elt, this._class); elt.style.borderColor = this._oldBorderColor; this.raisePropertyChanged("isEditing"); }, endEdit: function() { /// Puts the behavior out of edit mode var elt = this.get_element(); this._oldBorderColor = elt.style.borderColor; if (this._class) Sys.UI.DomElement.removeCssClass(elt, this._class); elt.style.borderColor = "transparent"; this.raisePropertyChanged("isEditing"); }, initialize: function() { Bleroy.Sample.EditInPlace.callBaseMethod(this, "initialize"); var elt = this.get_element(); this._oldBorderColor = elt.style.borderColor; this._focus = Function.createDelegate(this, this.beginEdit); Sys.UI.DomEvent.addHandler(elt, "focus", this._focus); this._blur = Function.createDelegate(this, this.endEdit); Sys.UI.DomEvent.addHandler(elt, "blur", this._blur); this.endEdit(); }, dispose: function() { if (this._blur) { var elt = this.get_element(); Sys.UI.DomEvent.removeHandler(elt, "blur", this._blur); Sys.UI.DomEvent.removeHandler(elt, "focus", this._focus); elt.style.borderColor = this._oldBorderColor; this._blur = this._focus = null; } Bleroy.Sample.EditInPlace.callBaseMethod(this, "dispose"); } } Bleroy.Sample.EditInPlace.registerClass("Bleroy.Sample.EditInPlace", Sys.UI.Behavior);