X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=portal%2Fstatic%2Funbound_reservation_static%2Fsrc%2Fdrag.js;fp=portal%2Fstatic%2Funbound_reservation_static%2Fsrc%2Fdrag.js;h=d71db029e5150de4c45a33cd39248b7844e78902;hb=729a9dbb380b51a217194ba2a4e5978186fe50b0;hp=0000000000000000000000000000000000000000;hpb=c4bd5da6e2630eddf1262aa8d808dbb48b097d53;p=myslice.git diff --git a/portal/static/unbound_reservation_static/src/drag.js b/portal/static/unbound_reservation_static/src/drag.js new file mode 100644 index 00000000..d71db029 --- /dev/null +++ b/portal/static/unbound_reservation_static/src/drag.js @@ -0,0 +1,61 @@ +/* + * this is experimental and probably will not be used. solutions exist for most libraries. but of course if + * i want to support multiple scopes at some stage then i will have to do dragging inside jsPlumb. + */ +;(function() { + + window.jsPlumbDrag = function(_jsPlumb) { + + var ta = new TouchAdapter(); + + this.draggable = function(selector) { + var el, elId, da = [], elo, d = false, + isInSelector = function(el) { + if (typeof selector == "string") + return selector === _jsPlumb.getId(el); + + for (var i = 0; i < selector.length; i++) { + var _sel = jsPlumb.CurrentLibrary.getDOMElement(selector[i]); + if (_sel == el) return true; + } + return false; + }; + + ta.bind(document, "mousedown", function(e) { + var target = e.target || e.srcElement; + if (isInSelector(target)) { + el = jsPlumb.CurrentLibrary.getElementObject(target); + elId = _jsPlumb.getId(el); + elo = jsPlumb.CurrentLibrary.getOffset(el); + da = [e.pageX, e.pageY]; + d = true; + } + }); + + ta.bind(document, "mousemove", function(e) { + if (d) { + var dx = e.pageX - da[0], + dy = e.pageY - da[1]; + + jsPlumb.CurrentLibrary.setOffset(el, { + left:elo.left + dx, + top:elo.top + dy + }); + _jsPlumb.repaint(elId); + e.preventDefault(); + e.stopPropagation(); + } + }); + ta.bind(document, "mouseup", function(e) { + el = null; + d = false; + }); + }; + + var isIOS = ((/iphone|ipad/gi).test(navigator.appVersion)); + if (isIOS) + _jsPlumb.draggable = this.draggable; + + }; + +})(); \ No newline at end of file