1 2WS.Namespace.Create('NovAxis.RadioButton', (function () 3{ 4 /** 5 @class RadioButton 6 @namespace NovAxis 7 @constructor 8 @param {JQuery dom} Element Dom element that will be replaced by the control. <br /> 9 Must be in the specific form : <input type="radio" value="myvalue"><label>Mon texte</label><br /> 10 Property checked intag is supported : <input type="radio" value="myvalue" <span style="background-color:yellow;">checked</span>><label>Mon texte</label> 11 @param {String} [Value] the value for selected item. 12 @param {Integer} [Orientation] The orientation of the control. (0=horizontal, 1=vertical) Default : 0 13 @param {Array<String>} [Classes] Array of class names to apply to the control. 14 @param {Boolean} [Nullable] Whether or not the control can have no value. 15 **/ 16 var Class = function (Element, Value, Orientation, Classes, Nullable) 17 { 18 // Validation 19 if (!Element || Element.length == 0) throw "Element control cannot be null."; 20 21 /** 22 Fired when the value is changed. 23 24 @event change 25 @param {Number} The new value. 26 **/ 27 WS.EventObject.call(this, ['change']); 28 29 // InitData 30 this._Value = null; 31 this.originalElement = Element; 32 33 // Element 34 this._Element = $(CreateControl.call(this, Element)); 35 this._Nullable = Nullable || false; 36 37 // Orientation 38 if (Orientation != null && Orientation == 1) this._Element.find(".naRadioButtonOption:not(:first-child)").css({ "display": "block", "margin": "5px 0px 0px 0px" }); 39 40 Element.after(this._Element); 41 Element.remove(); 42 if (Classes && Classes.length > 0) this._Element.addClass(Classes.join(" ")); 43 44 // Events, Bindings 45 AddEvents.apply(this); 46 if (Value != null || Nullable) this.SetValue(Value); 47 }; 48 49 WS.Exts.Inherits(Class, WS.EventObject); 50 51 // Private Method(s) 52 var CreateControl = function (Element) 53 { 54 var Me = this; 55 56 var Html = []; 57 Html.push("<div class=\"naRadioButton\">"); 58 var ElementChecked = false; 59 Element.find("input[type=radio]").each(function () 60 { 61 var MyElement = $(this); 62 var Checked = ""; 63 if (MyElement.is("[checked]") && !ElementChecked) 64 { 65 Checked = " wsChecked"; 66 ElementChecked = true; 67 Me._Value = MyElement.val(); 68 } 69 Html.push("<div class=\"naRadioButtonOption\">"); 70 Html.push("<div class=\"naRadioButtonItem" + Checked + "\" data=\"" + MyElement.val() + "\"></div>"); 71 Html.push("<label>" + MyElement.next("label").text() + "</label>"); 72 Html.push("</div>"); 73 }); 74 Html.push("</div>") 75 76 return Html.join(""); 77 }; 78 79 var AddEvents = function () 80 { 81 var Me = this; 82 83 var Elements = this._Element.find(".naRadioButtonOption > div"); 84 var Labels = this._Element.find(".naRadioButtonOption > label"); 85 86 Elements.off("click"); 87 Elements.on("click", function () 88 { 89 var Value = $(this).attr("data"); 90 if (Me.GetValue() != Value) 91 { 92 Me.SetValue(Value); 93 Me.RaiseEvent("change", Value); 94 } 95 }); 96 97 Labels.off("click"); 98 Labels.on("click", function () 99 { 100 $(this).prev("div").click(); 101 }) 102 }; 103 104 // Public Method(s) 105 (function (Methods) 106 { 107 /** 108 Get the selected value. 109 110 @method GetValue 111 @return {String} Value 112 **/ 113 Methods.GetValue = function () 114 { 115 return this._Value; 116 }; 117 118 /** 119 Set the selected value. 120 121 @method SetValue 122 @param {String} Value 123 **/ 124 Methods.SetValue = function (Value) 125 { 126 // Validation 127 if (Value == null && !this._Nullable) throw "Value cannot be null."; 128 129 this._Value = Value;
130 var Elements = this._Element.find(".naRadioButtonOption > div"); 131 var Element = null; 132 if (Value != null) 133 { 134 Element = this._Element.find(".naRadioButtonOption > div[data=" + Value + "]"); 135 if (Element.length == 0) throw "Invalid value."; 136 } 137 138 Elements.removeClass("wsChecked"); 139 if (Element) Element.addClass("wsChecked"); 140 }; 141 142 /** 143 Destroy the control. 144 145 @method Destroy 146 **/ 147 Methods.Destroy = function () 148 { 149 this._Element.after(this.originalElement); 150 this._Element.remove(); 151 this._Element = null; 152 }; 153 154 })(Class.prototype); 155 156 return Class; 157})());
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.