Skip to content

Commit

Permalink
- Added back getOffsetParent to Element.Dimensions.js as it's needed…
Browse files Browse the repository at this point in the history
… for positioning an element over the top of another element (as in the case of sortables) this should fix all the IE sortables bugs

 - Modified the test3 functional test for sortables
 - Added a format option to the request class that's been around for a long time.  Use it in rails applications to override the format of the response
 - Added 'put' and 'delete' methods to Request for completeness.  Useful when calling methods with brackets like '''request[flag ? "put" : "delete"]();'''

git-svn-id: http://svn.mootools.net/trunk@1548 4db308c1-fb21-0410-9919-de62e267375e
  • Loading branch information
tomocchino authored and subtleGradient committed Jun 9, 2008
1 parent 2b5aa62 commit edb8e19
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 66 deletions.
110 changes: 47 additions & 63 deletions Source/Class/Class.js
Expand Up @@ -11,26 +11,20 @@ var Class = new Native({
name: 'Class',

initialize: function(properties){

properties = properties || {};

var klass = function(empty){

for (var key in this) this[key] = $unlink(this[key]);

for (var mutator in Class.Mutators){
if (!this[mutator]) continue;
Class.Mutators[mutator](this, this[mutator]);
delete this[mutator];
}

this.constructor = klass;

if (empty === $empty) return this;

var self = (this.initialize) ? this.initialize.apply(this, arguments) : this;
if (this.options && this.options.initialize) this.options.initialize.call(this);

return self;
};

Expand All @@ -51,61 +45,51 @@ Class.implement({

});

Class.Mutators = {};

Class.Mutators.Implements = function(self, klasses){
$splat(klasses).each(function(klass){
$extend(self, ($type(klass) == 'class') ? new klass($empty) : klass);
});
Class.Mutators = {

Implements: function(self, klasses){
$splat(klasses).each(function(klass){
$extend(self, ($type(klass) == 'class') ? new klass($empty) : klass);
});
},

Extends: function(self, klass){
var instance = new klass($empty);
delete instance.parent;
delete instance.parentOf;

for (var key in instance){
var current = self[key], previous = instance[key];
if (current == undefined){
self[key] = previous;
continue;
}

var ctype = $type(current), ptype = $type(previous);
if (ctype != ptype) continue;

switch (ctype){
case 'function':
// this code will be only executed if the current browser does not support function.caller (currently only opera).
// we replace the function code with brute force. Not pretty, but it will only be executed if function.caller is not supported.
if (!arguments.callee.caller) self[key] = eval('(' + String(current).replace(/\bthis\.parent\(\s*(\))?/g, function(full, close){
return 'arguments.callee._parent_.call(this' + (close || ', ');
}).replace(/(\d+)\.([A-Za-z_])/g, '($1).$2') + ')');
// end "opera" code
self[key]._parent_ = previous;
break;
case 'object': self[key] = $merge(previous, current);
}

}

self.parent = function(){
return arguments.callee.caller._parent_.apply(this, arguments);
};

self.parentOf = function(descendant){
return descendant._parent_.apply(this, Array.slice(arguments, 1));
};
}

};

Class.Mutators.Extends = function(self, klass){

var instance = new klass($empty);

delete instance.parent;
delete instance.parentOf;

for (var key in instance){

var current = self[key], previous = instance[key];

if (current == undefined){
self[key] = previous;
continue;
}

var ctype = $type(current), ptype = $type(previous);

if (ctype != ptype) continue;

switch (ctype){
case 'function':

// opera does not support function.caller, so we replace the function code with brute force. Not pretty, but its just for opera.
// if future opera versions will support function.caller, this code wont be executed anymore.
// this code will be only executed if the current browser does not support function.caller (only opera).
// there is also a fix for an opera bug where in the function string, parentheses around numbers are ignored, and an error is thrown.

if (!arguments.callee.caller) self[key] = eval('(' + String(current).replace(/\bthis\.parent\(\s*(\))?/g, function(full, close){
return 'arguments.callee._parent_.call(this' + (close || ', ');
}).replace(/(\d+)\.([A-Za-z_])/g, '($1).$2') + ')');

// end "opera" code

self[key]._parent_ = previous;
break;
case 'object': self[key] = $merge(previous, current);
}

}

self.parent = function(){
return arguments.callee.caller._parent_.apply(this, arguments);
};

self.parentOf = function(descendant){
return descendant._parent_.apply(this, Array.slice(arguments, 1));
};

};
10 changes: 10 additions & 0 deletions Source/Element/Element.Dimensions.js
Expand Up @@ -48,6 +48,16 @@ Element.implement({
}
return position;
},

getOffsetParent: function(){
var element = this;
if (isBody(element)) return null;
if (!Browser.Engine.trident) return element.offsetParent;
while ((element = element.parentNode) && !isBody(element)){
if (styleString(element, 'position') != 'static') return element;
}
return null;
},

getOffsets: function(){
var element = this, position = {x: 0, y: 0};
Expand Down
2 changes: 1 addition & 1 deletion Source/Plugins/Sortables.js
Expand Up @@ -89,7 +89,7 @@ var Sortables = new Class({
'position': 'absolute',
'visibility': 'hidden',
'width': element.getStyle('width')
}).inject(this.list).position(element.getPosition(element.offsetParent));
}).inject(this.list).position(element.getPosition(element.getOffsetParent()));
},

getDroppables: function(){
Expand Down
8 changes: 7 additions & 1 deletion Source/Request/Request.js
Expand Up @@ -22,6 +22,7 @@ var Request = new Class({
'Accept': 'text/javascript, text/html, application/xml, text/xml, */*'
},
async: true,
format: false,
method: 'post',
link: 'ignore',
isSuccess: null,
Expand Down Expand Up @@ -117,6 +118,11 @@ var Request = new Class({
case 'object': case 'hash': data = Hash.toQueryString(data);
}

if (this.options.format){
var format = 'format=' + this.options.format;
data = (data) ? format + '&' + data : format;
}

if (this.options.emulation && ['put', 'delete'].contains(method)){
var _method = '_method=' + method;
data = (data) ? _method + '&' + data : _method;
Expand Down Expand Up @@ -165,7 +171,7 @@ var Request = new Class({
(function(){

var methods = {};
['get', 'post', 'GET', 'POST', 'PUT', 'DELETE'].each(function(method){
['get', 'post', 'put', 'delete', 'GET', 'POST', 'PUT', 'DELETE'].each(function(method){
methods[method] = function(){
var params = Array.link(arguments, {url: String.type, data: $defined});
return this.send($extend(params, {method: method.toLowerCase()}));
Expand Down
5 changes: 4 additions & 1 deletion Tests/Plugins/Sortables/test3.html
Expand Up @@ -23,7 +23,7 @@
#lists ul li span { cursor:move; display:block; border:solid 1px; }
#list-1 { width:820px; }
#list-1 li { float:left; width:39px; height:75px; }
#list-2 { width:250px; }
#list-2 { width:268px; height:360px; overflow:auto; }
#list-2 li { float:left; width:238px; }
#list-3 { width:524px; }
#list-3 li { float:left; width:75px; height:78px; }
Expand Down Expand Up @@ -89,6 +89,9 @@
<li id="item-2-8" class="blue">item 2-8</li>
<li id="item-2-9" class="blue">item 2-9</li>
<li id="item-2-10" class="blue">item 2-10</li>
<li id="item-2-11" class="blue">item 2-11</li>
<li id="item-2-12" class="blue">item 2-12</li>
<li id="item-2-13" class="blue">item 2-13</li>
</ul>
</div>
</body>
Expand Down

0 comments on commit edb8e19

Please sign in to comment.