reservation plugin - unbound request (unclean
[unfold.git] / portal / static / unbound_reservation_static / src / drag.js
1 /*
2  * this is experimental and probably will not be used.  solutions exist for most libraries.  but of course if
3  * i want to support multiple scopes at some stage then i will have to do dragging inside jsPlumb.
4  */ 
5 ;(function() {
6     
7     window.jsPlumbDrag = function(_jsPlumb) {
8       
9         var ta = new TouchAdapter();
10         
11         this.draggable = function(selector) {
12             var el, elId, da = [], elo, d = false,
13                 isInSelector = function(el) {
14                     if (typeof selector == "string")
15                         return selector === _jsPlumb.getId(el);
16                     
17                     for (var i = 0; i < selector.length; i++) {
18                         var _sel = jsPlumb.CurrentLibrary.getDOMElement(selector[i]);
19                         if (_sel == el) return true;
20                     }
21                     return false;
22                 };
23                                 
24                         ta.bind(document, "mousedown", function(e) {
25                 var target = e.target || e.srcElement;
26                 if (isInSelector(target)) {
27                     el = jsPlumb.CurrentLibrary.getElementObject(target);
28                     elId = _jsPlumb.getId(el);
29                     elo = jsPlumb.CurrentLibrary.getOffset(el);
30                     da = [e.pageX, e.pageY];
31                     d = true;
32                 }
33                         });
34                         
35                         ta.bind(document, "mousemove", function(e) {
36                                 if (d) {
37                                         var dx = e.pageX - da[0],
38                                                 dy = e.pageY - da[1];
39                                                 
40                                         jsPlumb.CurrentLibrary.setOffset(el, {
41                                                 left:elo.left + dx,
42                                                 top:elo.top + dy
43                                         });
44                                         _jsPlumb.repaint(elId);
45                                         e.preventDefault();
46                                         e.stopPropagation();
47                                 }
48                         });
49                         ta.bind(document, "mouseup", function(e) {
50                                 el = null;
51                                 d = false;                              
52                         });    
53         };
54         
55         var isIOS = ((/iphone|ipad/gi).test(navigator.appVersion));
56         if (isIOS)
57             _jsPlumb.draggable = this.draggable;
58         
59     };
60     
61 })();