r3422 committed - Slider: Added paging - page up/down jumps by 1/5 the size of the range...

r3422 committed - Slider: Added paging - page up/down jumps by 1/5 the size of the range...


Revision: 3422
Author: scott.gonzalez
Date: Sun Nov 8 19:10:57 2009
Log: Slider: Added paging - page up/down jumps by 1/5 the size of the range.
Fixes #3096 - Add a paging option for slider
http://code.google.com/p/jquery-ui/source/detail?r=3422
Modified:
/trunk/tests/unit/slider/slider_core.js
/trunk/ui/jquery.ui.slider.js
=======================================
--- /trunk/tests/unit/slider/slider_core.js    Sun Feb 1 23:13:25 2009
+++ /trunk/tests/unit/slider/slider_core.js    Sun Nov 8 19:10:57 2009
@@ -83,6 +83,52 @@
    el.slider('destroy');
});
+test("keydown PAGE_UP on handle increases value by 1/5 range, not greater
than max", function() {
+    $.each(['horizontal', 'vertical'], function(i, orientation) {
+        el = $('<div></div>');
+        options = {
+            max: 100,
+            min: 0,
+            orientation: orientation,
+            step: 1
+        };
+        el.slider(options);
+
+        el.slider("value", 70);
+
+        handle().simulate("keydown", { keyCode: $.ui.keyCode.PAGE_UP });
+        equals(el.slider("value"), 90);
+
+        handle().simulate("keydown", { keyCode: $.ui.keyCode.PAGE_UP });
+        equals(el.slider("value"), 100);
+
+        el.slider("destroy");
+    });
+});
+
+test("keydown PAGE_DOWN on handle decreases value by 1/5 range, not less
than min", function() {
+    $.each(['horizontal', 'vertical'], function(i, orientation) {
+        el = $('<div></div>');
+        options = {
+            max: 100,
+            min: 0,
+            orientation: orientation,
+            step: 1
+        };
+        el.slider(options);
+
+        el.slider("value", 30);
+
+        handle().simulate("keydown", { keyCode: $.ui.keyCode.PAGE_DOWN });
+        equals(el.slider("value"), 10);
+
+        handle().simulate("keydown", { keyCode: $.ui.keyCode.PAGE_DOWN });
+        equals(el.slider("value"), 0);
+
+        el.slider("destroy");
+    });
+});
+
test("keydown UP on handle increases value by step, not greater than max",
function() {
    el = $('<div></div>');
    options = {
=======================================
--- /trunk/ui/jquery.ui.slider.js    Mon Oct 12 07:32:31 2009
+++ /trunk/ui/jquery.ui.slider.js    Sun Nov 8 19:10:57 2009
@@ -13,6 +13,10 @@
(function($) {
+// number of pages in a slider
+// (how many times can you page up/down to go through the whole range)
+var numPages = 5;
+
$.widget("ui.slider", $.extend({}, $.ui.mouse, {
    _init: function() {
@@ -119,6 +123,8 @@
            switch (event.keyCode) {
                case $.ui.keyCode.HOME:
                case $.ui.keyCode.END:
+                case $.ui.keyCode.PAGE_UP:
+                case $.ui.keyCode.PAGE_DOWN:
                case $.ui.keyCode.UP:
                case $.ui.keyCode.RIGHT:
                case $.ui.keyCode.DOWN:
@@ -146,6 +152,12 @@
                case $.ui.keyCode.END:
                    newVal = self._valueMax();
                    break;
+                case $.ui.keyCode.PAGE_UP:
+                    newVal = curVal + ((self._valueMax() - self._valueMin()) / numPages);
+                    break;
+                case $.ui.keyCode.PAGE_DOWN:
+                    newVal = curVal - ((self._valueMax() - self._valueMin()) / numPages);
+                    break;
                case $.ui.keyCode.UP:
                case $.ui.keyCode.RIGHT:
                    if(curVal == self._valueMax()) return;