diff options
author | Thomas Fuchs <thomas@fesch.at> | 2006-10-09 22:09:08 +0000 |
---|---|---|
committer | Thomas Fuchs <thomas@fesch.at> | 2006-10-09 22:09:08 +0000 |
commit | b0e78c62783b27a98a324557bf9f3f6385bce315 (patch) | |
tree | 2222dc6efab3db6fd3b20144db61ddd71ec4d721 /actionpack/lib/action_view/helpers/javascripts/dragdrop.js | |
parent | f65ab3b233e112679fc7a183b488c5356a01c96c (diff) | |
download | rails-b0e78c62783b27a98a324557bf9f3f6385bce315.tar.gz rails-b0e78c62783b27a98a324557bf9f3f6385bce315.tar.bz2 rails-b0e78c62783b27a98a324557bf9f3f6385bce315.zip |
Update to latest Prototype and script.aculo.us trunk versions
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5276 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack/lib/action_view/helpers/javascripts/dragdrop.js')
-rw-r--r-- | actionpack/lib/action_view/helpers/javascripts/dragdrop.js | 74 |
1 files changed, 24 insertions, 50 deletions
diff --git a/actionpack/lib/action_view/helpers/javascripts/dragdrop.js b/actionpack/lib/action_view/helpers/javascripts/dragdrop.js index 91088b53db..a2f852afa4 100644 --- a/actionpack/lib/action_view/helpers/javascripts/dragdrop.js +++ b/actionpack/lib/action_view/helpers/javascripts/dragdrop.js @@ -1,9 +1,8 @@ // Copyright (c) 2005 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us) // (c) 2005 Sammi Williams (http://www.oriontransfer.co.nz, sammi@oriontransfer.co.nz) // -// See scriptaculous.js for full license. - -/*--------------------------------------------------------------------------*/ +// script.aculo.us is freely distributable under the terms of an MIT-style license. +// For details, see the script.aculo.us web site: http://script.aculo.us/ if(typeof Effect == 'undefined') throw("dragdrop.js requires including script.aculo.us' effects.js library"); @@ -251,7 +250,7 @@ Draggable.prototype = { delay: 0 }; - if(arguments[1] && typeof arguments[1].endeffect == 'undefined') + if(!arguments[1] || typeof arguments[1].endeffect == 'undefined') Object.extend(defaults, { starteffect: function(element) { element._opacity = Element.getOpacity(element); @@ -264,10 +263,9 @@ Draggable.prototype = { this.element = $(element); - if(options.handle && (typeof options.handle == 'string')) { - var h = Element.childrenWithClassName(this.element, options.handle, true); - if(h.length>0) this.handle = h[0]; - } + if(options.handle && (typeof options.handle == 'string')) + this.handle = this.element.down('.'+options.handle, 0); + if(!this.handle) this.handle = $(options.handle); if(!this.handle) this.handle = this.element; @@ -368,12 +366,8 @@ Draggable.prototype = { with(this._getWindowScroll(this.options.scroll)) { p = [ left, top, left+width, top+height ]; } } else { p = Position.page(this.options.scroll); - p[0] += this.options.scroll.scrollLeft; - p[1] += this.options.scroll.scrollTop; - - p[0] += (window.pageXOffset || document.documentElement.scrollLeft || document.body.scrollLeft || 0); - p[1] += (window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0); - + p[0] += this.options.scroll.scrollLeft + Position.deltaX; + p[1] += this.options.scroll.scrollTop + Position.deltaY; p.push(p[0]+this.options.scroll.offsetWidth); p.push(p[1]+this.options.scroll.offsetHeight); } @@ -441,7 +435,6 @@ Draggable.prototype = { var pos = Position.cumulativeOffset(this.element); if(this.options.ghosting) { var r = Position.realOffset(this.element); - window.status = r.inspect(); pos[0] += r[0] - Position.deltaX; pos[1] += r[1] - Position.deltaY; } @@ -665,7 +658,6 @@ var Sortable = { tree: options.tree, hoverclass: options.hoverclass, onHover: Sortable.onHover - //greedy: !options.dropOnEmpty } var options_for_tree = { @@ -690,7 +682,7 @@ var Sortable = { (this.findElements(element, options) || []).each( function(e) { // handles are per-draggable var handle = options.handle ? - Element.childrenWithClassName(e, options.handle)[0] : e; + $(e).down('.'+options.handle,0) : e; options.draggables.push( new Draggable(e, Object.extend(options_for_draggable, { handle: handle }))); Droppables.add(e, options_for_droppable); @@ -788,7 +780,7 @@ var Sortable = { }, unmark: function() { - if(Sortable._marker) Element.hide(Sortable._marker); + if(Sortable._marker) Sortable._marker.hide(); }, mark: function(dropon, position) { @@ -797,23 +789,21 @@ var Sortable = { if(sortable && !sortable.ghosting) return; if(!Sortable._marker) { - Sortable._marker = $('dropmarker') || document.createElement('DIV'); - Element.hide(Sortable._marker); - Element.addClassName(Sortable._marker, 'dropmarker'); - Sortable._marker.style.position = 'absolute'; + Sortable._marker = + ($('dropmarker') || Element.extend(document.createElement('DIV'))). + hide().addClassName('dropmarker').setStyle({position:'absolute'}); document.getElementsByTagName("body").item(0).appendChild(Sortable._marker); } var offsets = Position.cumulativeOffset(dropon); - Sortable._marker.style.left = offsets[0] + 'px'; - Sortable._marker.style.top = offsets[1] + 'px'; + Sortable._marker.setStyle({left: offsets[0]+'px', top: offsets[1] + 'px'}); if(position=='after') if(sortable.overlap == 'horizontal') - Sortable._marker.style.left = (offsets[0]+dropon.clientWidth) + 'px'; + Sortable._marker.setStyle({left: (offsets[0]+dropon.clientWidth) + 'px'}); else - Sortable._marker.style.top = (offsets[1]+dropon.clientHeight) + 'px'; + Sortable._marker.setStyle({top: (offsets[1]+dropon.clientHeight) + 'px'}); - Element.show(Sortable._marker); + Sortable._marker.show(); }, _tree: function(element, options, parent) { @@ -828,9 +818,9 @@ var Sortable = { id: encodeURIComponent(match ? match[1] : null), element: element, parent: parent, - children: new Array, + children: [], position: parent.children.length, - container: Sortable._findChildrenElement(children[i], options.treeTag.toUpperCase()) + container: $(children[i]).down(options.treeTag) } /* Get the element containing the children and recurse over it */ @@ -843,17 +833,6 @@ var Sortable = { return parent; }, - /* Finds the first element of the given tag type within a parent element. - Used for finding the first LI[ST] within a L[IST]I[TEM].*/ - _findChildrenElement: function (element, containerTag) { - if (element && element.hasChildNodes) - for (var i = 0; i < element.childNodes.length; ++i) - if (element.childNodes[i].tagName == containerTag) - return element.childNodes[i]; - - return null; - }, - tree: function(element) { element = $(element); var sortableOptions = this.options(element); @@ -868,12 +847,12 @@ var Sortable = { var root = { id: null, parent: null, - children: new Array, + children: [], container: element, position: 0 } - return Sortable._tree (element, options, root); + return Sortable._tree(element, options, root); }, /* Construct a [i] index for a particular node */ @@ -933,12 +912,10 @@ var Sortable = { } } -/* Returns true if child is contained within element */ +// Returns true if child is contained within element Element.isParent = function(child, element) { if (!child.parentNode || child == element) return false; - if (child.parentNode == element) return true; - return Element.isParent(child.parentNode, element); } @@ -961,8 +938,5 @@ Element.findChildren = function(element, only, recursive, tagName) { } Element.offsetSize = function (element, type) { - if (type == 'vertical' || type == 'height') - return element.offsetHeight; - else - return element.offsetWidth; -}
\ No newline at end of file + return element['offset' + ((type=='vertical' || type=='height') ? 'Height' : 'Width')]; +} |