diff options
-rw-r--r-- | demos/selectmenu/default.html | 2 | ||||
-rw-r--r-- | demos/selectmenu/methods.html | 36 | ||||
-rw-r--r-- | ui/jquery.ui.selectmenu.js | 26 |
3 files changed, 47 insertions, 17 deletions
diff --git a/demos/selectmenu/default.html b/demos/selectmenu/default.html index fed7f2f0f..28ec1c3bd 100644 --- a/demos/selectmenu/default.html +++ b/demos/selectmenu/default.html @@ -70,8 +70,10 @@ return newText; } </script> + <!-- <script type="text/javascript" src="http://ui.jquery.com/applications/themeroller/themeswitchertool/"></script> <script type="text/javascript"> $(function(){ $('<div style="position: absolute; top: 20px; right: 10px;" />').appendTo('body').themeswitcher(); }); </script> + --> </head> <body> <br /> diff --git a/demos/selectmenu/methods.html b/demos/selectmenu/methods.html index 5504950a6..8d82af78d 100644 --- a/demos/selectmenu/methods.html +++ b/demos/selectmenu/methods.html @@ -22,28 +22,43 @@ </style> <script type="text/javascript"> $(function(){ - var speedA = $('select#speedA').selectmenu( - ); + var speedA = $('select#speedA').selectmenu(); - $("#getValue").click(function(event){ + $("#index").click(function(event){ + console.log($('select#speedA').selectmenu("index")); + }); + $("#indexNumber").click(function(event){ + console.log($('select#speedA').selectmenu("index", 4)); + }); + $("#value").click(function(event){ console.log($('select#speedA').selectmenu("value")); }); - $("#setValue").click(function(event){ + $("#valueString").click(function(event){ + console.log($('select#speedA').selectmenu("value", "Medium")); + }); + $("#valueNumber").click(function(event){ console.log($('select#speedA').selectmenu("value", 4)); }); + $("#valueNumberAsString").click(function(event){ + console.log($('select#speedA').selectmenu("value", "11")); + }); + $("#valueNonExisting").click(function(event){ + console.log($('select#speedA').selectmenu("value", "test123")); + }); }); </script> - <!-- - <script type="text/javascript" src="http://ui.jquery.com/applications/themeroller/themeswitchertool/"></script> - <script type="text/javascript"> $(function(){ $('<div style="position: absolute; top: 20px; right: 10px;" />').appendTo('body').themeswitcher(); }); </script> - --> </head> <body> <br /> <br /> <form action="#"> - <a href="#nogo" id="getValue">getValue</a> - <a href="#nogo" id="setValue">setValue to 4</a> + <a href="#nogo" id="index">method index without paramaters (get index)</a><br /> + <a href="#nogo" id="indexNumber">method index with paramater '4' (set index by number)</a><br /> + <a href="#nogo" id="value">method value without paramaters (get value)</a><br /> + <a href="#nogo" id="valueString">method value with paramater 'Medium' (set value by string)</a><br /> + <a href="#nogo" id="valueNumber">method value with paramater '4' (passed as number)</a><br /> + <a href="#nogo" id="valueNumberAsString">method value with paramater '11' (passed as string)</a><br /> + <a href="#nogo" id="valueNonExisting">method value with paramater 'test123' (not existing value)</a> <br /> <h2>"default popup" Style</h2> <fieldset> @@ -54,6 +69,7 @@ <option value="Medium">Medium</option> <option value="Fast">Fast</option> <option value="Faster">Faster</option> + <option value="11">Up to eleven</option> </select> </fieldset> </form> diff --git a/ui/jquery.ui.selectmenu.js b/ui/jquery.ui.selectmenu.js index 73292c7f4..ad05d0423 100644 --- a/ui/jquery.ui.selectmenu.js +++ b/ui/jquery.ui.selectmenu.js @@ -161,7 +161,7 @@ $.widget("ui.selectmenu", { .mouseup(function(event){ if(self._safemouseup){ var changed = $(this).data('index') != self._selectedIndex(); - self.value($(this).data('index')); + self.index($(this).data('index')); self.select(event); if(changed){ self.change(event); } self.close(event,true); @@ -327,7 +327,7 @@ $.widget("ui.selectmenu", { if(this.element.attr('disabled') == true){ this.disable(); } //update value - this.value(this._selectedIndex()); + this.index(this._selectedIndex()); // needed when selectmenu is placed at the very bottom / top of the page window.setTimeout(function() { @@ -382,7 +382,7 @@ $.widget("ui.selectmenu", { this._prevChar[0] = C; }, _uiHash: function(){ - var index = this.value(); + var index = this.index(); return { index: index, option: $("option", this.element).get(index), @@ -416,8 +416,6 @@ $.widget("ui.selectmenu", { .attr('aria-hidden', true) .removeClass(this.widgetBaseClass+'-open'); if(this.options.style == "dropdown"){ this.newelement.removeClass('ui-corner-top').addClass('ui-corner-all'); } - console.log(this.newelement); - console.log(this.retainFocus); if(retainFocus){this.newelement.focus();} this._trigger("close", event, this._uiHash()); } @@ -491,12 +489,26 @@ $.widget("ui.selectmenu", { .attr("aria-disabled", value); } }, - value: function(newValue) { + index: function(newValue) { if (arguments.length) { this.element[0].selectedIndex = newValue; this._refreshValue(); + } else { + return this._selectedIndex(); + } + }, + value: function(newValue) { + if (arguments.length) { + // FIXME test for number is a kind of legacy support, could be removed at any time (Dez. 2010) + if (typeof newValue == "number") { + this.index(newValue); + } else if (typeof newValue == "string") { + this.element[0].value = newValue; + this._refreshValue(); + } + } else { + return this.element[0].value; } - return this.element[0].selectedIndex; }, _refreshValue: function() { var activeClass = (this.options.style == "popup") ? " ui-state-active" : ""; |