| | |
| | | var isTouch = svgedit.browser.isTouch(); |
| | | var completed = true //for mousewheel |
| | | var $cursor = (area && this.dragCfg.cursor) |
| | | ? $("<div class='draginput_cursor' />").appendTo($label) |
| | | ? $("<div class='draginput_cursor' />").appendTo($label) |
| | | : false |
| | | $input.attr("readonly", "readonly") |
| | | if ($cursor && !isNaN(this.dragCfg.start)) $cursor.css("top", (this.dragCfg.start*-1)/scale+cursorHeight) |
| | | |
| | | //this is where all the magic happens |
| | | |
| | | //this is where all the magic happens |
| | | this.adjustValue = function(i, completed){ |
| | | var v; |
| | | i = parseFloat(i); |
| | |
| | | $label.attr("data-value", v) |
| | | if ($.isFunction(this.dragCfg.callback)) this.dragCfg.callback(this, completed) |
| | | }; |
| | | |
| | | |
| | | $label.toggleClass("draginput", $label.is("label")) |
| | | |
| | | |
| | | // when the mouse is down and moving |
| | | this.move = function(e, oy, val) { |
| | | if (isTouch) { |
| | |
| | | var fixed = (step < 1) ? 1 : 0 |
| | | this.adjustValue(val.toFixed(fixed)) //no undo true |
| | | }; |
| | | |
| | | |
| | | //when the mouse is released |
| | | this.stop = function() { |
| | | var selectedElems = canvas.getSelectedElems(); |
| | |
| | | } |
| | | this.adjustValue(0, completed) |
| | | } |
| | | |
| | | |
| | | this.updateCursor = function(){ |
| | | var value = parseFloat(this.value); |
| | | var pos = (value*-1)/scale+cursorHeight; |
| | | $cursor.css("top", pos); |
| | | } |
| | | |
| | | |
| | | this.launch = function(e) { |
| | | var selectedElems = canvas.getSelectedElems(); |
| | | if (isTouch) e = e.originalEvent.touches[0]; |
| | |
| | | $(window).bind("mousemove.draginput touchmove.draginput", function(e){el.move(e, oy, parseFloat(val))}) |
| | | $(window).bind("mouseup.draginput touchend.draginput", function(e){el.stop()}) |
| | | } |
| | | |
| | | |
| | | $(this) |
| | | .attr("readonly", "readonly") |
| | | .attr("data-scale", scale) |
| | | .attr("data-domain", cursorHeight) |
| | | .attr("data-cursor", ($cursor != false)) |
| | | |
| | | |
| | | .bind("mousedown touchstart", function(e){ |
| | | this.blur(); |
| | | this.launch(e); |
| | | }) |
| | | |
| | | |
| | | .bind("dblclick taphold", function(e) { |
| | | this.removeAttribute("readonly", "readonly"); |
| | | this.focus(); |
| | | this.select(); |
| | | }) |
| | | |
| | | |
| | | .keydown(function(e){ |
| | | // Respond to up/down arrow keys. |
| | | switch(e.keyCode){ |
| | | case 13: this.adjustValue(0); this.blur(); break; // Enter |
| | | } |
| | | }) |
| | | |
| | | |
| | | .focus(function(e){ |
| | | if (this.getAttribute("readonly") === "readonly") this.blur() |
| | | }) |
| | | |
| | | |
| | | .blur(function(e){ |
| | | this.setAttribute("readonly", "readonly") |
| | | }) |
| | | |
| | | |
| | | .bind("mousewheel", function(e, delta, deltaX, deltaY){ |
| | | var selectedElems = canvas.getSelectedElems(); |
| | | if (completed) canvas.undoMgr.beginUndoableChange(attr, selectedElems) |
| | |
| | | window.undoTimeout = setTimeout(function(){ |
| | | wheel_input.stop() |
| | | },200) |
| | | |
| | | |
| | | var wheel_input = this; |
| | | if (deltaY > 0) |
| | | this.adjustValue(this.dragCfg.step); |
| | | else if (deltaY < 0) |
| | | this.adjustValue(-this.dragCfg.step); |
| | | e.preventDefault(); |
| | | |
| | | |
| | | }) |
| | | |
| | | }); |
| | | |
| | | |
| | | }; |
| | | |
| | | // public function |