]> granicus.if.org Git - transmission/commitdiff
(trunk web) use jQuery to limit the preference dialog's numberic entry fields to...
authorJordan Lee <jordan@transmissionbt.com>
Sun, 21 Aug 2011 05:54:02 +0000 (05:54 +0000)
committerJordan Lee <jordan@transmissionbt.com>
Sun, 21 Aug 2011 05:54:02 +0000 (05:54 +0000)
web/index.html
web/javascript/common.js
web/javascript/transmission.js

index 58ab94ad9bfd58beae5af6e4902ced56fd27a252..520a2a5e1ee7ee86ec96223d6a6d3cfc472996a6 100755 (executable)
                                                                <label class="category">Web Client:</label>
                                                                <div class="formdiv">
                                                                        <label for="refresh_rate" class="item">Refresh Rate:</label>
-                                                                       <input type="text" name="refresh_rate" id="refresh_rate"/>
+                                                                       <input type="text" name="refresh_rate" id="refresh_rate" class="numberinput"/>
                                                                        <label class="suffix">seconds</label>
                                                                </div>
                                                        </div>
                                                                <div class="formdiv checkbox">
                                                                        <input type="checkbox" name="limit_download" id="limit_download"/>
                                                                        <label for="limit_download" class="item">Download Rate:</label>
-                                                                       <input type="text" name="download_rate" id="download_rate"/>
+                                                                       <input type="text" name="download_rate" id="download_rate" class="numberinput"/>
                                                                        <label class="suffix">kB/s</label>
                                                                </div>
                                                                <div class="formdiv checkbox">
                                                                        <input type="checkbox" name="limit_upload" id="limit_upload"/>
                                                                        <label for="limit_upload" class="item">Upload Rate:</label>
-                                                                       <input type="text" name="upload_rate" id="upload_rate"/>
+                                                                       <input type="text" name="upload_rate" id="upload_rate" class="numberinput"/>
                                                                        <label class="suffix">kB/s</label>
                                                                </div>
                                                        </div>
                                                                <label>Override normal speed limits manually or at scheduled times</label>
                                                                <div class="formdiv">
                                                                        <label for="turtle_download_rate" class="item">Download Rate:</label>
-                                                                       <input type="text" name="turtle_download_rate" id="turtle_download_rate"/>
+                                                                       <input type="text" name="turtle_download_rate" id="turtle_download_rate" class="numberinput"/>
                                                                        <label class="suffix">kB/s</label>
                                                                </div>
                                                                <div class="formdiv">
                                                                        <label for="turtle_upload_rate" class="item">Upload Rate:</label>
-                                                                       <input type="text" name="turtle_upload_rate" id="turtle_upload_rate"/>
+                                                                       <input type="text" name="turtle_upload_rate" id="turtle_upload_rate" class="numberinput"/>
                                                                        <label class="suffix">kB/s</label>
                                                                </div>
                                                                <div class="formdiv checkbox">
                                                                <label class="category">Connections:</label>
                                                                <div class="formdiv">
                                                                        <label for="conn_global" class="item">Global maximum connections:</label>
-                                                                       <input type="text" name="conn_global" id="conn_global"/>
+                                                                       <input type="text" name="conn_global" id="conn_global" class="numberinput"/>
                                                                        <label class="suffix">peers</label>
                                                                </div>
                                                                <div class="formdiv">
                                                                        <label for="conn_torrent" class="item">Maximum connections for new transfers:</label>
-                                                                       <input type="text" name="conn_torrent" id="conn_torrent"/>
+                                                                       <input type="text" name="conn_torrent" id="conn_torrent" class="numberinput"/>
                                                                        <label class="suffix">peers</label>
                                                                </div>
                                                                <div class="formdiv checkbox">
                                                                <label class="category">Peer listening port:</label>
                                                                <div class="formdiv">
                                                                        <label for="port" class="item">Incoming TCP Port:</label>
-                                                                       <input type="text" id="port" name="port"/>
+                                                                       <input type="text" id="port" name="port" class="numberinput"/>
                                                                        <label class="suffix" id="port_test"></label>
                                                                </div>
                                                                <div class="formdiv checkbox">
index 80747367715353323b1d6912646c1f87da3a7ad2..8273ff4779c35796b52c90da95955c3b52960a07 100644 (file)
@@ -309,3 +309,28 @@ Prefs.getClutchPrefs = function( o )
                o[key] = Prefs.getValue( key, Prefs._Defaults[key] );
        return o;
 };
+
+
+// forceNumeric() plug-in implementation
+jQuery.fn.forceNumeric = function () {
+       return this.each(function () {
+               $(this).keydown(function (e) {
+                       var key = e.which || e.keyCode;
+                       return !e.shiftKey && !e.altKey && !e.ctrlKey &&
+                               // numbers   
+                               key >= 48 && key <= 57 ||
+                               // Numeric keypad
+                               key >= 96 && key <= 105 ||
+                               // comma, period and minus, . on keypad
+                               key == 190 || key == 188 || key == 109 || key == 110 ||
+                               // Backspace and Tab and Enter
+                               key == 8 || key == 9 || key == 13 ||
+                               // Home and End
+                               key == 35 || key == 36 ||
+                               // left and right arrows
+                               key == 37 || key == 39 ||
+                               // Del and Ins
+                               key == 46 || key == 45;
+               });
+       });
+}
index 0819763e6474205b08268c8e2742e55677add320..45004c283aa7ca249c6f9550e3326d10ac6e19e4 100644 (file)
@@ -35,6 +35,7 @@ Transmission.prototype =
 
                // Set up user events
                var tr = this;
+               $(".numberinput").forceNumeric();
                $('#pause_all_link').bind('click', function(e){ tr.stopAllClicked(e); });
                $('#resume_all_link').bind('click', function(e){ tr.startAllClicked(e); });
                $('#pause_selected_link').bind('click', function(e){ tr.stopSelectedClicked(e); } );
@@ -129,9 +130,6 @@ Transmission.prototype =
                this._inspector._info_tab.upload_speed = $(ti+'upload_speed')[0];
                this._inspector._info_tab.upload_to = $(ti+'upload_to')[0];
 
-               // Setup the preference box
-               this.setupPrefConstraints();
-
                // Setup the prefs gui
                this.initializeSettings( );
 
@@ -205,23 +203,6 @@ Transmission.prototype =
                        jQuery("<img>").attr("src", row);
        },
 
-       /*
-        * Set up the preference validation
-        */
-       setupPrefConstraints: function() {
-               // only allow integers for speed limit & port options
-               $('div.preference input[@type=text]:not(#download_location,#block_url)').blur( function() {
-                       this.value = this.value.replace(/[^0-9]/gi, '');
-                       if (this.value == '') {
-                               if ($(this).is('#refresh_rate')) {
-                                       this.value = 5;
-                               } else {
-                                       this.value = 0;
-                               }
-                       }
-               });
-       },
-
        setCompactMode: function( is_compact )
        {
                this.torrentRenderer = is_compact ? new TorrentRendererCompact( )
@@ -1257,7 +1238,7 @@ Transmission.prototype =
                                        $element.deselectMenuSiblings().selectMenuItem();
                                        args[RPC._DownSpeedLimited] = false;
                                } else {
-                                       var rate_str = ($element[0].innerHTML).replace(/[^0-9]/ig, '');
+                                       var rate_str = $element[0].innerHTML
                                        var rate_val = parseInt( rate_str );
                                        setInnerHTML( $('#limited_download_rate')[0], [ 'Limit (', Transmission.fmt.speed(rate_val), ')' ].join('') );
                                        $('#limited_download_rate').deselectMenuSiblings().selectMenuItem();
@@ -1276,7 +1257,7 @@ Transmission.prototype =
                                        $element.deselectMenuSiblings().selectMenuItem();
                                        args[RPC._UpSpeedLimited] = false;
                                } else {
-                                       var rate_str = ($element[0].innerHTML).replace(/[^0-9]/ig, '');
+                                       var rate_str = $element[0].innerHTML
                                        var rate_val = parseInt( rate_str );
                                        setInnerHTML( $('#limited_upload_rate')[0], [ 'Limit (', Transmission.fmt.speed(rate_val), ')' ].join('')  );
                                        $('#limited_upload_rate').deselectMenuSiblings().selectMenuItem();