Changeset 184 for ether_megapoli/trunk/web/resources/js
- Timestamp:
- 09/07/11 19:09:04 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
ether_megapoli/trunk/web/resources/js/DomHelper.js
r129 r184 164 164 165 165 166 var Select = Class.create({167 initialize: function( id, className, name, disabled )168 {169 this.id = id;170 this.name = name;171 this.valueKey = 'value';172 this.textKey = 'text';173 if( disabled )174 this.select = new Element('select', {id:id, disabled:disabled});175 else176 this.select = new Element('select', {id:id});177 this.select.addClassName(className);178 },179 180 setValueKey: function( key )181 {182 this.valueKey = key;183 },184 185 setTextKey: function( key )186 {187 this.textKey = key;188 },189 190 addOptions: function( options, selectedOption, onClickAction )191 {192 options.each(function( option )193 {194 this.addOption(option, selectedOption, onClickAction);195 }.bind(this));196 },197 198 addOption: function( option, selectedOption, onClickAction )199 {200 var value = this.valueKey ? option[this.valueKey] : option;201 var text = this.textKey ? option[this.textKey] : option;202 if( null != selectedOption && value == selectedOption )203 var option = new Element('option', {value:value, selected:"selected"}).update(text);204 else205 var option = new Element('option', {value:value}).update(text);206 207 if( null != onClickAction )208 Event.observe(option, 'click', onClickAction.bind(this));209 this.select.insert(option);210 },211 212 addToElement: function( elementId )213 {214 $(elementId).insert(this.select);215 }216 });166 //var Select = Class.create({ 167 // initialize: function( id, className, name, disabled ) 168 // { 169 // this.id = id; 170 // this.name = name; 171 // this.valueKey = 'value'; 172 // this.textKey = 'text'; 173 // if( disabled ) 174 // this.select = new Element('select', {id:id, disabled:disabled}); 175 // else 176 // this.select = new Element('select', {id:id}); 177 // this.select.addClassName(className); 178 // }, 179 // 180 // setValueKey: function( key ) 181 // { 182 // this.valueKey = key; 183 // }, 184 // 185 // setTextKey: function( key ) 186 // { 187 // this.textKey = key; 188 // }, 189 // 190 // addOptions: function( options, selectedOption, onClickAction ) 191 // { 192 // options.each(function( option ) 193 // { 194 // this.addOption(option, selectedOption, onClickAction); 195 // }.bind(this)); 196 // }, 197 // 198 // addOption: function( option, selectedOption, onClickAction ) 199 // { 200 // var value = this.valueKey ? option[this.valueKey] : option; 201 // var text = this.textKey ? option[this.textKey] : option; 202 // if( null != selectedOption && value == selectedOption ) 203 // var option = new Element('option', {value:value, selected:"selected"}).update(text); 204 // else 205 // var option = new Element('option', {value:value}).update(text); 206 // 207 // if( null != onClickAction ) 208 // Event.observe(option, 'click', onClickAction.bind(this)); 209 // this.select.insert(option); 210 // }, 211 // 212 // addToElement: function( elementId ) 213 // { 214 // $(elementId).insert(this.select); 215 // } 216 //}); 217 217 218 218
Note: See TracChangeset
for help on using the changeset viewer.