Changeset 5704
- Timestamp:
- 05/28/08 09:36:28 (8 months ago)
- Location:
- trunk/plugins/treeview
- Files:
-
- 2 modified
-
demo/sortable.html (modified) (2 diffs)
-
jquery.treeview.sortable.js (modified) (13 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/plugins/treeview/demo/sortable.html
r5497 r5704 22 22 <script src="../jquery.treeview.js" type="text/javascript"></script> 23 23 <script src="../jquery.treeview.edit.js" type="text/javascript"></script> 24 24 25 <script src="../../../ui/ui.core.js" type="text/javascript" charset="utf-8"></script> 25 26 <script src="../../../ui/ui.droppable.js" type="text/javascript" charset="utf-8"></script> … … 79 80 this.each(function() { 80 81 81 $(this).treeview().sortable ({82 $(this).treeview().sortableTree({ 82 83 connectWith: o.connectWith, 83 84 items: 'li', -
trunk/plugins/treeview/jquery.treeview.sortable.js
r5497 r5704 21 21 } 22 22 23 $.fn.extend({ 24 sortable: function(options) { 25 26 var args = Array.prototype.slice.call(arguments, 1); 27 28 if (options == "serialize" || options == "toArray") 29 return $.data(this[0], "sortable")[options](arguments[1]); 30 31 return this.each(function() { 32 if (typeof options == "string") { 33 var sort = $.data(this, "sortable"); 34 if (sort) sort[options].apply(sort, args); 35 36 } else if(!$.data(this, "sortable")) 37 new $.ui.sortable(this, options); 38 }); 39 } 40 }); 23 24 $.widget("ui.sortableTree", $.extend($.ui.mouse, { 25 init: function() { 26 27 //Initialize needed constants 28 var self = this, o = this.options; 29 this.containerCache = {}; 30 this.element.addClass("ui-sortableTree"); 31 32 //Get the items 33 this.refresh(); 34 35 //Let's determine the parent's offset 36 if(!(/(relative|absolute|fixed)/).test(this.element.css('position'))) this.element.css('position', 'relative'); 37 this.offset = this.element.offset(); 41 38 42 $.ui.sortable = function(element, options) { 43 //Initialize needed constants 44 var self = this; 45 46 this.element = $(element); 47 this.containerCache = {}; 48 49 $.data(element, "sortable", this); 50 this.element.addClass("ui-sortable"); 51 52 //Prepare the passed options 53 this.options = $.extend({}, options); 54 var o = this.options; 55 $.extend(o, { 56 items: this.options.items || '> *', 57 zIndex: this.options.zIndex || 1000, 58 startCondition: function() { 59 return !self.options.disabled; 60 } 61 }); 62 63 $(element).bind("setData.sortable", function(event, key, value){ 64 self.options[key] = value; 65 }).bind("getData.sortable", function(event, key){ 66 return self.options[key]; 67 }); 68 69 //Get the items 70 this.refresh(); 71 72 //Let's determine the parent's offset 73 if(!(/(relative|absolute|fixed)/).test(this.element.css('position'))) this.element.css('position', 'relative'); 74 this.offset = this.element.offset(); 75 76 //Initialize mouse events for interaction 77 this.element.mouse({ 78 executor: this, 79 delay: o.delay, 80 distance: o.distance || 1, 81 dragPrevention: o.prevention ? o.prevention.toLowerCase().split(',') : ['input','textarea','button','select','option'], 82 start: this.start, 83 stop: this.stop, 84 drag: this.drag, 85 condition: function(e) { 86 87 if(this.options.disabled || this.options.type == 'static') return false; 88 89 //Find out if the clicked node (or one of its parents) is a actual item in this.items 90 var currentItem = null, nodes = $(e.target).parents().each(function() { 91 if($.data(this, 'sortable-item')) { 92 currentItem = $(this); 93 return false; 94 } 95 }); 96 if($.data(e.target, 'sortable-item')) currentItem = $(e.target); 97 98 if(!currentItem) return false; 99 if(this.options.handle) { 100 var validHandle = false; 101 $(this.options.handle, currentItem).each(function() { if(this == e.target) validHandle = true; }); 102 if(!validHandle) return false; 103 } 104 105 this.currentItem = currentItem; 106 return true; 107 108 } 109 }); 110 111 //Prepare cursorAt 112 if(o.cursorAt && o.cursorAt.constructor == Array) 113 o.cursorAt = { left: o.cursorAt[0], top: o.cursorAt[1] }; 114 }; 115 116 $.extend($.ui.sortable.prototype, { 39 //Initialize mouse events for interaction 40 this.mouseInit(); 41 42 //Prepare cursorAt 43 if(o.cursorAt && o.cursorAt.constructor == Array) 44 o.cursorAt = { left: o.cursorAt[0], top: o.cursorAt[1] }; 45 46 }, 117 47 plugins: {}, 118 48 ui: function(inst) { … … 134 64 serialize: function(o) { 135 65 136 var items = $(this.options.items, this.element).not('.ui-sortable -helper'); //Only the items of the sortable itself66 var items = $(this.options.items, this.element).not('.ui-sortableTree-helper'); //Only the items of the sortable itself 137 67 var str = []; o = o || {}; 138 68 … … 146 76 }, 147 77 toArray: function(attr) { 148 var items = $(this.options.items, this.element).not('.ui-sortable -helper'); //Only the items of the sortable itself78 var items = $(this.options.items, this.element).not('.ui-sortableTree-helper'); //Only the items of the sortable itself 149 79 var ret = []; 150 80 … … 153 83 }, 154 84 enable: function() { 155 this.element.removeClass("ui-sortable -disabled");85 this.element.removeClass("ui-sortableTree-disabled"); 156 86 this.options.disabled = false; 157 87 }, 158 88 disable: function() { 159 this.element.addClass("ui-sortable -disabled");89 this.element.addClass("ui-sortableTree-disabled"); 160 90 this.options.disabled = true; 161 91 }, … … 178 108 var t = item.top, b = t + item.height; 179 109 180 if(!this.intersectsWith(item.item.parents(".ui-sortable ").data("sortable").containerCache)) return false;110 if(!this.intersectsWith(item.item.parents(".ui-sortableTree").data("sortableTree").containerCache)) return false; 181 111 182 112 if (!( t < y1 + (this.helperProportions.height / 2) // Bottom Half … … 204 134 var cur = $(this.options.connectWith[i]); 205 135 for (var j = cur.length - 1; j >= 0; j--){ 206 var inst = $.data(cur[j], 'sortable ');136 var inst = $.data(cur[j], 'sortableTree'); 207 137 if(inst && !inst.options.disabled) { 208 138 queries.push($(inst.options.items, inst.element)); … … 215 145 for (var i = queries.length - 1; i >= 0; i--){ 216 146 queries[i].each(function() { 217 $.data(this, 'sortable -item', true); // Data for target checking (mouse manager)147 $.data(this, 'sortableTree-item', true); // Data for target checking (mouse manager) 218 148 items.push({ 219 149 item: $(this), … … 239 169 }, 240 170 destroy: function() { 171 241 172 this.element 242 .removeClass("ui-sortable ui-sortable-disabled")243 .removeData("sortable ")244 .unbind(".sortable ")245 .removeMouseInteraction();173 .removeClass("ui-sortableTree ui-sortableTree-disabled") 174 .removeData("sortableTree") 175 .unbind(".sortableTree"); 176 this.mouseDestroy(); 246 177 247 178 for ( var i = this.items.length - 1; i >= 0; i-- ) 248 this.items[i].item.removeData("sortable-item"); 179 this.items[i].item.removeData("sortableTree-item"); 180 249 181 }, 250 182 contactContainers: function(e) { … … 285 217 }; 286 218 }, 287 start: function(e,el) { 219 mouseStart: function(e,el) { 220 221 if(this.options.disabled || this.options.type == 'static') return false; 222 223 //Find out if the clicked node (or one of its parents) is a actual item in this.items 224 var currentItem = null, nodes = $(e.target).parents().each(function() { 225 if($.data(this, 'sortableTree-item')) { 226 currentItem = $(this); 227 return false; 228 } 229 }); 230 if($.data(e.target, 'sortableTree-item')) currentItem = $(e.target); 231 232 if(!currentItem) return false; 233 if(this.options.handle) { 234 var validHandle = false; 235 $(this.options.handle, currentItem).each(function() { if(this == e.target) validHandle = true; }); 236 if(!validHandle) return false; 237 } 238 239 this.currentItem = currentItem; 288 240 289 241 var o = this.options; … … 294 246 this.helper = typeof o.helper == 'function' ? $(o.helper.apply(this.element[0], [e, this.currentItem])) : this.currentItem.clone(); 295 247 if(!this.helper.parents('body').length) this.helper.appendTo("body"); //Add the helper to the DOM if that didn't happen already 296 this.helper.css({ position: 'absolute', clear: 'both' }).addClass('ui-sortable -helper'); //Position it absolutely and add a helper class248 this.helper.css({ position: 'absolute', clear: 'both' }).addClass('ui-sortableTree-helper'); //Position it absolutely and add a helper class 297 249 298 250 //Prepare variables for position generation … … 324 276 325 277 this.dragging = true; 326 return false;327 328 }, 329 stop: function(e) {278 return true; 279 280 }, 281 mouseStop: function(e) { 330 282 331 283 if(this.newPositionAt) this.options.sortIndication.remove.call(this.currentItem, this.newPositionAt); //remove sort indicator … … 363 315 364 316 }, 365 drag: function(e) {317 mouseDrag: function(e) { 366 318 367 319 //Compute the helpers position … … 411 363 } 412 364 } 365 })); 366 367 $.extend($.ui.sortableTree, { 368 defaults: { 369 items: '> *', 370 zIndex: 1000, 371 distance: 1 372 }, 373 getter: "serialize toArray" 413 374 }); 414 375
