Ben Boeckel avatar Ben Boeckel committed e08b487

Fix up code after initial stab

Comments (0)

Files changed (1)

src/js/draggable.js

 */
 
 ko.bindingHandlers.draggable = (function() {
+'use strict';
+
 // Global flag indicating whether anything is dragging at the moment.
 var dragActive = false;
 
     };
 
     // Options
-    var min = bindings.min();
-    var max = bindings.max();
-    var step = bindings.step();
-    var tooltip = bindings.tooltip() || 'drag';
+    var min = 0;
+    var max = 100;
+    var step = 1;
+    var tooltip = 'drag';
+
+    var attr = bindings.attr;
+
+    if (typeof attr === 'object') {
+        if (attr.min !== undefined) {
+            min = attr.min;
+        }
+        if (attr.max !== undefined) {
+            max = attr.max;
+        }
+        if (attr.step !== undefined) {
+            step = attr.step;
+        }
+        if (attr.tooltip !== undefined) {
+            tooltip = attr.tooltip;
+        }
+    }
 
     // Flags
     var isHovering = false;
     // Make the element hoverable
     var $hoverable = $element.Hoverable();
 
+    var dragValue;
+
     // Bind the functions
-    hoverable.
+    $hoverable.
       bind('newHoverIn', function(evt, touch) {
         isHovering = true;
 
           isDragging = true;
           dragActive = true;
 
-          that.dragValue = valueAccessor();
+          dragValue = value();
 
           updateEffects();
       }).
       bind('touchablemove', function (ev, touch) {
-          var value = that.dragValue + touch.currentStartDelta.x / 5 * step;
-          value = ((value / step).round() * step).limit(min, max);
-          valueAccessor(value);
+          var _step = ko.utils.unwrapObservable(step);
+          var _min = ko.utils.unwrapObservable(min);
+          var _max = ko.utils.unwrapObservable(max);
+          var val = dragValue + touch.currentStartDelta.x / 5 * _step;
+
+          val = Math.round(val / _step) * _step;
+
+          if (val < _min) {
+              val = _min;
+          } else if (val > _max) {
+              val = _max;
+          }
+
+          value(val);
           updateHelp();
       }).
       bind('touchableend', function (ev, touch) {
       });
    },
    update: function(element, valueAccessor, allBindingsAccessor, viewModel) {
-  };
+   }
+};
 }());
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.