]> source.dussan.org Git - jquery-ui.git/commitdiff
added: improved index and value methods, if you used value method in your scripts...
authorFelix Nagel <info@felixnagel.com>
Mon, 29 Nov 2010 02:22:07 +0000 (03:22 +0100)
committerFelix Nagel <info@felixnagel.com>
Mon, 29 Nov 2010 02:22:07 +0000 (03:22 +0100)
fixed: forgotten console debug

demos/selectmenu/default.html
demos/selectmenu/methods.html
ui/jquery.ui.selectmenu.js

index fed7f2f0f1e705423f16f8186e073e0f949cadaa..28ec1c3bdddeab041924be348520e9fcb4946bb4 100644 (file)
                        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 />
index 5504950a6f242d7f6449b7a2c20f7f7472e3419b..8d82af78d40096c100fc7ce9d562800ce3b5a039 100644 (file)
        </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>
index 73292c7f4379d45aa2ab0d9ab010fcdff0dbd975..ad05d04239aa00fb43528c6b8269f4adc38e12d7 100644 (file)
@@ -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" : "";