1/*! jquery.draggable.js (CUSTOM MODIFIED) */ 2(function($) { 3 $.fn.drags = function(opt) { 4 opt = $.extend({ 5 handle: "", 6 draggableClass: "draggable", 7 activeHandleClass: "active-handle", 8 cancelTypes: "a,input,textarea,button,select,option", 9 cancelClasses: "", 10 cancelClassesDefault: ".ace_editor", 11 minX: -9999999, 12 maxX: +9999999, 13 minY: -9999999, 14 maxY: +9999999, 15 snap: [], 16 snapParent: null, 17 dragStart: function() {}, 18 dragDone: function() {}, 19 dragSuccess: function() {} 20 }, 21 opt); 22 23 var $selected = null; 24 var $elements = (opt.handle === "") ? this : this.find(opt.handle); 25 26 //cursor 27 $elements.css("cursor", "move"); 28 29 $(opt.cancelClassesDefault).each(function() { 30 if ($(this).css("cursor") == "move") 31 $(this).css("cursor", "default"); 32 }); 33 34 if (opt.cancelClasses.length > 0) { 35 $(opt.cancelClasses).each(function() { 36 if ($(this).css("cursor") == "move") 37 $(this).css("cursor", "default"); 38 }); 39 } 40 41 //elements: mousedown 42 $elements.on("mousedown", 43 function(e) { 44 if (e.which != 1) 45 return; 46 47 var elIsCancel = e.target.nodeName ? $(e.target).closest(opt.cancelTypes).length : false; 48 if (!elIsCancel && (opt.cancelClasses.length > 0)) 49 elIsCancel = (($(e.target).is(opt.cancelClasses)) || ($(e.target).parents(opt.cancelClasses).length > 0)); 50 if (!elIsCancel) 51 elIsCancel = (($(e.target).is(opt.cancelClassesDefault)) || ($(e.target).parents(opt.cancelClassesDefault).length > 0)); 52 53 if (opt.handle === "") { 54 $selected = $(this); 55 $selected.addClass(opt.draggableClass); 56 } else { 57 $selected = $(this).parent(); 58 $selected.addClass(opt.draggableClass).find(opt.handle).addClass(opt.activeHandleClass); 59 } 60 61 if (elIsCancel) { 62 $selected = null; 63 return true; 64 } 65 66 opt.dragStart($selected, 1); 67 68 var snapDistance = 8; 69 var drg_h = $selected.outerHeight(); 70 var drg_w = $selected.outerWidth(); 71 var pos_y = $selected.offset().top + drg_h - e.pageY; 72 var pos_x = $selected.offset().left + drg_w - e.pageX; 73 74 //document: mousemove 75 $(document).on("mousemove", 76 function(e) { 77 $selected.offset({ 78 left: e.pageX + pos_x - drg_w, 79 top: e.pageY + pos_y - drg_h 80 }); 81 82 var tempX = $selected.position().left; 83 var tempY = $selected.position().top; 84 var snappedH = false; 85 var snappedV = false; 86 87 //Lock Left 88 if (tempX < opt.minX) { 89 //console.log('LockedLeft: ' + opt.minX); 90 $selected.css("left", opt.minX + "px"); 91 tempX = $selected.position().left; 92 snappedH = true; 93 } 94 95 //Lock Right 96 if (tempX + drg_w > opt.maxX) { 97 //console.log('LockedRight: ' + opt.maxX); 98 $selected.css("left", (opt.maxX - drg_w) + "px"); 99 tempX = $selected.position().left; 100 snappedH = true; 101 } 102 103 //Lock Top 104 if (tempY < opt.minY) { 105 //console.log('LockedTop: ' + opt.minY); 106 $selected.css("top", opt.minY + "px"); 107 tempY = $selected.position().top; 108 snappedV = true; 109 } 110 111 //Lock Bottom 112 if (tempY + drg_h > opt.maxY) { 113 //console.log('LockedBottom: ' + opt.maxY); 114 $selected.css("top", (opt.maxY - drg_h) + "px"); 115 tempY = $selected.position().top; 116 snappedV = true; 117 } 118 119 //Snapping (only if no Shift key) 120 if (!e.shiftKey) { 121 if (opt.snapParent) { 122 opt.snap = [{ x: -1, y: -1, width: $(opt.snapParent).outerWidth(), height: $(opt.snapParent).outerHeight() }]; 123 $(".DragSnapBox", opt.snapParent).each(function(index, element) { 124 if ($(element).attr("id") !== $selected.attr("id")) 125 opt.snap.push({ x: $(element).position().left, y: $(element).position().top, width: $(element).outerWidth(), height: $(element).outerHeight() }); 126 });
127 } 128 129 for (var a = 0; a < opt.snap.length; a++) { 130 //console.log(opt.snap); 131 132 //Horizontal Snapping 133 if ((tempY <= (opt.snap[a].y + opt.snap[a].height)) && 134 ((tempY + drg_h) >= opt.snap[a].y)) { 135 //My Left -> Left 136 if ((!snappedH) && (Math.abs(tempX - opt.snap[a].x) <= snapDistance)) { 137 //console.log('SnapLeft->Left'); 138 $selected.css("left", opt.snap[a].x + "px"); 139 tempX = $selected.position().left; 140 snappedH = true; 141 } 142 143 //My Left -> Right 144 if ((!snappedH) && (Math.abs(tempX - (opt.snap[a].x + opt.snap[a].width)) <= snapDistance)) { 145 //console.log('SnapLeft->Right'); 146 $selected.css("left", (opt.snap[a].x + opt.snap[a].width) + "px"); 147 tempX = $selected.position().left; 148 snappedH = true; 149 } 150 151 //My Right -> Left 152 if ((!snappedH) && (Math.abs((tempX + drg_w) - opt.snap[a].x) < snapDistance)) { 153 //console.log('SnapRight->Left'); 154 $selected.css("left", (opt.snap[a].x - drg_w) + "px"); 155 tempX = $selected.position().left; 156 snappedH = true; 157 } 158 159 //My Right -> Right 160 if ((!snappedH) && (Math.abs((tempX + drg_w) - (opt.snap[a].x + opt.snap[a].width)) < snapDistance)) { 161 //console.log('SnapRight->Left'); 162 $selected.css("left", (opt.snap[a].x + opt.snap[a].width - drg_w) + "px"); 163 tempX = $selected.position().left; 164 snappedH = true; 165 } 166 } 167 168 //Vertical Snapping 169 if ((tempX <= (opt.snap[a].x + opt.snap[a].width)) && 170 ((tempX + drg_w) >= opt.snap[a].x)) { 171 //My Top -> Top 172 if ((!snappedV) && (Math.abs(tempY - opt.snap[a].y) < snapDistance)) { 173 //console.log('SnapTop->Top'); 174 $selected.css("top", opt.snap[a].y + "px"); 175 tempY = $selected.position().top; 176 snappedV = true; 177 } 178 179 //My Top -> Bottom 180 if ((!snappedV) && (Math.abs(tempY - (opt.snap[a].y + opt.snap[a].height)) < snapDistance)) { 181 //console.log('SnapTop->Bottom'); 182 $selected.css("top", (opt.snap[a].y + opt.snap[a].height) + "px"); 183 tempY = $selected.position().top; 184 snappedV = true; 185 } 186 187 //My Bottom -> Top 188 if ((!snappedV) && (Math.abs((tempY + drg_h) - opt.snap[a].y) < snapDistance)) { 189 //console.log('SnapBottom->Top'); 190 $selected.css("top", (opt.snap[a].y - drg_h) + "px"); 191 tempY = $selected.position().top; 192 snappedV = true; 193 } 194 195 //My Bottom -> Bottom 196 if ((!snappedV) && (Math.abs((tempY + drg_h) - (opt.snap[a].y + opt.snap[a].height)) < snapDistance)) { 197 //console.log('SnapBottom->Bottom'); 198 $selected.css("top", (opt.snap[a].y + opt.snap[a].height - drg_h) + "px"); 199 tempY = $selected.position().top; 200 snappedV = true; 201 } 202 } 203 } 204 } 205 }); 206 207 //document: mouseup 208 $(document).on("mouseup", 209 function() { 210 opt.dragDone($selected, 1); 211 212 $(this).off("mousemove"); 213 if ($selected !== null) { 214 $selected.removeClass(opt.draggableClass); 215 $selected = null; 216 } 217 }); 218 e.preventDefault(); // disable selection 219 }); 220 221 //elements: mouseup 222 $elements.on("mouseup", 223 function() { 224 if ($selected != null) { 225 opt.dragDone($selected, 1); 226 opt.dragSuccess($selected, 1); 227 228 if (opt.handle === "") { 229 $selected.removeClass(opt.draggableClass); 230 } else { 231 $selected.removeClass(opt.draggableClass) 232 .find(opt.handle).removeClass(opt.activeHandleClass); 233 } 234 235 $selected = null; 236 } 237 }); 238 239 return this; 240 }; 241})(jQuery);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.