changeset 1043:e7733df2e2c4

fix buggy behaviour with step
author hertzhaft
date Fri, 23 Mar 2012 11:54:42 +0100
parents 2c5a48a624c5
children 2d04f160ce09
files webapp/src/main/webapp/jquery/jquery.digilib.sliders.js webapp/src/main/webapp/jquery/jquery.range.js
diffstat 2 files changed, 17 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/webapp/src/main/webapp/jquery/jquery.digilib.sliders.js	Thu Mar 22 19:22:38 2012 +0100
+++ b/webapp/src/main/webapp/jquery/jquery.digilib.sliders.js	Fri Mar 23 11:54:42 2012 +0100
@@ -34,6 +34,7 @@
             icon : "rotate.png",
             'min' : 0,
             'max' : 360,
+            'step' : 0.1,
             'start' : 90
             },
         brgt : {
@@ -42,6 +43,7 @@
             icon : "brightness.png",
             'min' : -255,
             'max' : 255,
+            'step' : 10,
             'start' : 0
             },
         cont : {
@@ -50,6 +52,7 @@
             icon : "contrast.png",
             'min' : -4,
             'max' : 4,
+            'step' : 0.01,
             'start' : 0
         },
         red : {
@@ -426,7 +429,7 @@
             <div class="'+cssClass+'" style="width:300px; background-color:white; padding:10px;" title="'+opts.tooltip+'">\
                 <form class="'+cssClass+'">\
                     <span>'+opts.label+'</span>\
-                    <input type="range" class="'+cssClass+'range" name="'+paramname+'" min="'+opts.min+'" max="'+opts.max+'" value="'+param+'"/>\
+                    <input type="range" class="'+cssClass+'range" name="'+paramname+'" step="'+opts.step+'" min="'+opts.min+'" max="'+opts.max+'" value="'+param+'"/>\
                     <input type="text" class="'+cssClass+'text" name="'+paramname+'" size="3" value="'+param+'"/>\
                     <br/>\
                     <input class="'+cssClass+'cancel" type="button" value="Cancel"/><input type="submit" name="sub" value="Ok"/>\
--- a/webapp/src/main/webapp/jquery/jquery.range.js	Thu Mar 22 19:22:38 2012 +0100
+++ b/webapp/src/main/webapp/jquery/jquery.range.js	Fri Mar 23 11:54:42 2012 +0100
@@ -70,10 +70,11 @@
         p = boundL;
       }
       
-      if(options.snap && p !== boundR){
-        var snapPx = valueToPx(options.snap);
-        p = Math.round(p/snapPx) * snapPx;
-      }
+// leads to erratic behaviour with "step" attribute
+//      if(options.snap && p !== boundR){
+//         var snapPx = valueToPx(options.snap);
+//         p = Math.round(p/snapPx) * snapPx;
+//      }
       
       $h.css({'left': p, 'position': 'absolute'});
       if(options.range) updateSelection();
@@ -126,15 +127,15 @@
       if(options.range){
       
         prev = options.values.slice(); // clone
-        options.values[0] = pxToValue($handle);
-        options.values[1] = pxToValue($handle2);
+        options.values[0] = pxToValue($handle.position().left);
+        options.values[1] = pxToValue($handle2.position().left);
         
         // set value on original element
         $original.val(options.values[0] +','+options.values[1]);
       } else {
       
         prev = options.values;
-        options.values = pxToValue($handle);
+        options.values = pxToValue($handle.position().left);
         
         // set value on original element
         $original.val(options.values);
@@ -164,13 +165,14 @@
       updateValues();
     };
     
-    var pxToValue = function($h){
+    var pxToValue = function(p){
       var w = $input.width()-size;
-      var p = $h.position().left;
       var v = (p/(w/(options.max-options.min)))+options.min;
 
-      if(options.snap) return Math.floor(v/options.snap) * options.snap;
-
+      if(options.snap) {
+        v = Math.floor(v/options.snap) * options.snap;
+        return v;
+        }
       return Math.round(v);
     };