Skip to content

Commit

Permalink
Merge branch '1.3wip' of github.com:mootools/mootools-core
Browse files Browse the repository at this point in the history
  • Loading branch information
kamicane committed Apr 27, 2010
2 parents f4bb6ae + 7140fd3 commit 52c103d
Show file tree
Hide file tree
Showing 14 changed files with 104 additions and 90 deletions.
6 changes: 3 additions & 3 deletions Source/Browser/Browser.js
Expand Up @@ -160,8 +160,8 @@ if (document.execCommand) try {
document.execCommand("BackgroundImageCache", false, true);
} catch (e){}

if (this.attachEvent) this.attachEvent('onunload', function(){
this.detachEvent('onunload', arguments.callee);
if (this.attachEvent) this.attachEvent('onunload', function event(){
this.detachEvent('onunload', event);
document.head = document.html = document.window = null;
});

Expand All @@ -171,7 +171,7 @@ try {
arrayFrom(document.html.childNodes);
} catch(e){
Array.from = function(item){
if (item != null && typeOf(item) != 'array' && Type.isEnumerable(item)){
if (typeof item != 'string' && Type.isEnumerable(item) && typeOf(item) != 'array'){
var i = item.length, array = new Array(i);
while (i--) array[i] = item[i];
return array;
Expand Down
6 changes: 3 additions & 3 deletions Source/Class/Class.js
Expand Up @@ -66,10 +66,10 @@ var reset = function(object){
var wrap = function(self, key, method){
if (method.$origin) method = method.$origin;

return function(){
return function wrapper(){
if (method.$protected && this.$caller == null) throw new Error('The method "' + key + '" cannot be called.');
var caller = this.caller, current = this.$caller;
this.caller = current; this.$caller = arguments.callee;
this.caller = current; this.$caller = wrapper;
var result = method.apply(this, arguments);
this.$caller = current; this.caller = caller;
return result;
Expand Down Expand Up @@ -103,7 +103,7 @@ var getInstance = function(klass){
};

var enumerables = true;
for (var i in {toString: 1}) enumerables = false;
for (var i in {toString: 1}) enumerables = null;
if (enumerables) enumerables = ['hasOwnProperty', 'valueOf', 'isPrototypeOf', 'propertyIsEnumerable', 'toLocaleString', 'toString', 'constructor'];

Class.implement({implement: function(object){
Expand Down
6 changes: 3 additions & 3 deletions Source/Core/Core.js
Expand Up @@ -80,7 +80,7 @@ Function.from = function(item){

Array.from = function(item){
if (item == null) return [];
return (Type.isEnumerable(item)) ? (typeOf(item) == 'array') ? item : Array.prototype.slice.call(item) : [item];
return (Type.isEnumerable(item) && typeof item != 'string') ? (typeOf(item) == 'array') ? item : Array.prototype.slice.call(item) : [item];
};

Number.from = function(item){
Expand Down Expand Up @@ -138,10 +138,10 @@ var Type = this.Type = function(name, object){
return object;
};

var objectToString = Object.prototype.toString;
var toString = Object.prototype.toString;

Type.isEnumerable = function(item){
return (objectToString.call(item) != '[object Function]' && typeof item != 'string' && typeof item.length == 'number');
return (item != null && typeof item.length == 'number' && toString.call(item) != '[object Function]' );
};

var hooks = {};
Expand Down
2 changes: 1 addition & 1 deletion Source/Element/Element.Dimensions.js
Expand Up @@ -11,7 +11,7 @@ credits:
- Element positioning based on the [qooxdoo](http://qooxdoo.org/) code and smart browser fixes, [LGPL License](http://www.gnu.org/licenses/lgpl.html).
- Viewport dimensions based on [YUI](http://developer.yahoo.com/yui/) code, [BSD License](http://developer.yahoo.com/yui/license.html).
requires: Element
requires: [Element, Element.Style]
provides: [Element.Dimensions]
Expand Down
27 changes: 22 additions & 5 deletions Source/Element/Element.Style.js
Expand Up @@ -14,10 +14,16 @@ provides: Element.Style
...
*/

(function(){

var html = document.html;

Element.Properties.styles = {set: function(styles){
this.setStyles(styles);
}};

var hasFilter = (html.style.filter != null);

Element.Properties.opacity = {

set: function(opacity, novisibility){
Expand All @@ -29,7 +35,7 @@ Element.Properties.opacity = {
}
}
if (!this.currentStyle || !this.currentStyle.hasLayout) this.style.zoom = 1;
if (Browser.ie) this.style.filter = (opacity == 1) ? '' : 'alpha(opacity=' + opacity * 100 + ')';
if (hasFilter) this.style.filter = (opacity == 1) ? '' : 'alpha(opacity=' + opacity * 100 + ')';
this.style.opacity = opacity;
this.store('opacity', opacity);
},
Expand All @@ -40,8 +46,17 @@ Element.Properties.opacity = {

};

var floatName = (html.style.cssFloat == null) ? 'styleFloat' : 'cssFloat';

Element.implement({

getComputedStyle: function(property){
if (this.currentStyle) return this.currentStyle[property.camelCase()];
var defaultView = Element.getDocument(this).defaultView,
computed = defaultView ? defaultView.getComputedStyle(this, null) : null;
return (computed) ? computed.getPropertyValue((property == floatName) ? 'float' : property.hyphenate()) : null;
},

setOpacity: function(value){
return this.set('opacity', value, true);
},
Expand All @@ -53,7 +68,7 @@ Element.implement({
setStyle: function(property, value){
switch (property){
case 'opacity': return this.set('opacity', parseFloat(value));
case 'float': property = (Browser.ie) ? 'styleFloat' : 'cssFloat';
case 'float': property = floatName;
}
property = property.camelCase();
if (typeOf(value) != 'string'){
Expand All @@ -72,11 +87,11 @@ Element.implement({
getStyle: function(property){
switch (property){
case 'opacity': return this.get('opacity');
case 'float': property = (Browser.ie) ? 'styleFloat' : 'cssFloat';
case 'float': property = floatName;
}
property = property.camelCase();
var result = this.style[property];
if (!$chk(result)){
if (!$chk(result) || property == 'zIndex'){
result = [];
for (var style in Element.ShortStyles){
if (property != style) continue;
Expand All @@ -98,7 +113,7 @@ Element.implement({
}, this);
return this['offset' + property.capitalize()] - size + 'px';
}
if ((Browser.opera) && String(result).test('px')) return result;
if (Browser.opera && String(result).test('px')) return result;
if (property.test(/(border(.+)Width|margin|padding)/)) return '0px';
}
return result;
Expand Down Expand Up @@ -146,3 +161,5 @@ Element.ShortStyles = {margin: {}, padding: {}, border: {}, borderWidth: {}, bor
Short.borderStyle[bds] = Short[bd][bds] = All[bds] = '@';
Short.borderColor[bdc] = Short[bd][bdc] = All[bdc] = 'rgb(@, @, @)';
});

})();
103 changes: 53 additions & 50 deletions Source/Element/Element.js
Expand Up @@ -21,7 +21,7 @@ var Element = function(tag, props){

if (!props) props = {};

if (!tag.test(/^\w+$/)){
if (!tag.test(/^[\w-]+$/)){
var parsed = Slick.parse(tag).expressions[0][0];
tag = (parsed.tag == '*') ? 'div' : parsed.tag;
if (parsed.id && props.id == null) props.id = parsed.id;
Expand Down Expand Up @@ -230,13 +230,13 @@ if (window.$$ == null) Window.implement({$$: function(selector){
/*</block>*/

if (window.$$ == null) Window.implement({$$: function(selector){
return Slick.search(this.document, selector);
return Slick.search(this.document, selector, new Elements);
}});

(function(){

var collected = {}, storage = {};
var props = {input: 'checked', option: 'selected', textarea: (Browser.safari && Browser.version == 2) ? 'innerHTML' : 'value'};
var props = {input: 'checked', option: 'selected', textarea: 'value'};

var get = function(uid){
return (storage[uid] || (storage[uid] = {}));
Expand Down Expand Up @@ -272,23 +272,30 @@ var purge = function(){
collected = storage = null;
};

var attributes = {
var camels = ['defaultValue', 'accessKey', 'cellPadding', 'cellSpacing', 'colSpan', 'frameBorder', 'maxLength', 'readOnly',
'rowSpan', 'tabIndex', 'useMap'
];
var bools = ['compact', 'nowrap', 'ismap', 'declare', 'noshade', 'checked', 'disabled', 'readOnly', 'multiple', 'selected',
'noresize', 'defer'
];
var attributes = {
'html': 'innerHTML',
'class': 'className',
'for': 'htmlFor',
'defaultValue': 'defaultValue',
'text': (Browser.ie || (Browser.safari && Browser.version <= 2)) ? 'innerText' : 'textContent'
'text': (function(){
var temp = document.createElement('div');
return (temp.innerText == null) ? 'textContent' : 'innerText';
})()
};
var bools = ['compact', 'nowrap', 'ismap', 'declare', 'noshade', 'checked', 'disabled', 'readonly', 'multiple', 'selected', 'noresize', 'defer'];
var camels = [
'value', 'type', 'defaultValue', 'accessKey', 'cellPadding', 'cellSpacing', 'colSpan', 'frameBorder', 'maxLength', 'readOnly',
'rowSpan', 'tabIndex', 'useMap'
];
var readOnly = ['type'];
var expandos = ['value', 'defaultValue'];
var uriAttrs = /^href|src|usemap$/i;

bools = bools.associate(bools);
camels = camels.associate(camels.map(String.toLowerCase));
readOnly = readOnly.associate(readOnly);

Object.append(attributes, bools);
Object.append(attributes, camels.associate(camels.map(String.toLowerCase)));
Object.append(attributes, expandos.associate(expandos));

var inserters = {

Expand Down Expand Up @@ -361,10 +368,11 @@ Element.implement({
},

setProperty: function(attribute, value){
var key = attributes[attribute];
attribute = camels[attribute] || attribute;
if (value == undefined) return this.removeProperty(attribute);
if (key && bools[attribute]) value = !!value;
(key) ? this[key] = value : this.setAttribute(attribute, '' + value);
var key = attributes[attribute];
(key) ? this[key] = value :
(bools[attribute]) ? this[attribute] = !!value : this.setAttribute(attribute, '' + value);
return this;
},

Expand All @@ -374,9 +382,12 @@ Element.implement({
},

getProperty: function(attribute){
var key = attributes[attribute];
var value = (key) ? this[key] : this.getAttribute(attribute, 2);
return (bools[attribute]) ? !!value : (key) ? value : value || null;
attribute = camels[attribute] || attribute;
var key = attributes[attribute] || readOnly[attribute];
return (key) ? this[key] :
(bools[attribute]) ? !!this[attribute] :
(uriAttrs.test(attribute) ? this.getAttribute(attribute, 2) :
(key = this.getAttributeNode(attribute)) ? key.nodeValue : null) || null;
},

getProperties: function(){
Expand All @@ -385,8 +396,10 @@ Element.implement({
},

removeProperty: function(attribute){
attribute = camels[attribute] || attribute;
var key = attributes[attribute];
(key) ? this[key] = (key && bools[attribute]) ? false : '' : this.removeAttribute(attribute);
(key) ? this[key] = '' :
(bools[attribute]) ? this[attribute] = false : this.removeAttribute(attribute);
return this;
},

Expand Down Expand Up @@ -452,43 +465,43 @@ Element.implement({
return this.replaces(el).grab(el, where);
},

getPrevious: function(match, nocash){
getPrevious: function(match){
return document.id(Slick.find(this, '!+ ' + (match || '')));
},

getAllPrevious: function(match, nocash){
getAllPrevious: function(match){
return Slick.search(this, '!~ ' + (match || ''), new Elements);
},

getNext: function(match, nocash){
getNext: function(match){
return document.id(Slick.find(this, '~ ' + (match || '')));
},

getAllNext: function(match, nocash){
getAllNext: function(match){
return Slick.search(this, '~ ' + (match || ''), new Elements);
},

getFirst: function(match, nocash){
getFirst: function(match){
return document.id(Slick.find(this, '> ' + (match || '')));
},

getLast: function(match, nocash){
getLast: function(match){
return document.id(Slick.find(this, '!^ ' + (match || '')));
},

getParent: function(match, nocash){
getParent: function(match){
return document.id(Slick.find(this, '! ' + (match || '')));
},

getParents: function(match, nocash){
getParents: function(match){
return Slick.search(this, '! ' + (match || ''), new Elements);
},

getSiblings: function(match, nocash){
getSiblings: function(match){
return Slick.search(this, '~~ ' + (match || ''), new Elements);
},

getChildren: function(match, nocash){
getChildren: function(match){
return Slick.search(this, '> ' + (match || ''), new Elements);
},

Expand All @@ -500,28 +513,22 @@ Element.implement({
return this.ownerDocument;
},

getElementById: function(id, nocash){
getElementById: function(id){
return document.id(Slick.find(this, '#' + id));
},

getSelected: function(){
this.selectedIndex; // Safari 3.2.1
return new Elements(Array.from(this.options).filter(function(option){
return option.selected;
}));
},

getComputedStyle: function(property){
if (this.currentStyle) return this.currentStyle[property.camelCase()];
var defaultView = this.getDocument().defaultView;
var computed = defaultView && defaultView.getComputedStyle(this, null);
return (computed) ? computed.getPropertyValue([property.hyphenate()]) : null;
},

toQueryString: function(){
var queryString = [];
this.getElements('input, select, textarea').each(function(el){
var type = el.type;
if (!el.name || el.disabled || type == 'submit' || type == 'reset' || type == 'file') return;
if (!el.name || el.disabled || type == 'submit' || type == 'reset' || type == 'file' || type == 'image') return;

var value = (el.get('tag') == 'select') ? el.getSelected().map(function(opt){
// IE
Expand Down Expand Up @@ -679,6 +686,12 @@ Element.Properties.tag = {
};

Element.Properties.html = (function(){

var tableTest = Function.stab(function(){
var table = document.createElement('table');
table.innerHTML = '<tr><td></td></tr>';
});

var wrapper = document.createElement('div');

var translations = {
Expand All @@ -692,7 +705,7 @@ Element.Properties.html = (function(){
var html = {
set: function(){
var html = Array.flatten(arguments).join('');
var wrap = Browser.ie && translations[this.get('tag')];
var wrap = (!tableTest && translations[this.get('tag')]);
if (wrap){
var first = wrapper;
first.innerHTML = wrap[1] + html + wrap[2];
Expand All @@ -708,13 +721,3 @@ Element.Properties.html = (function(){

return html;
})();

if (Browser.safari && Browser.version <= 2) Element.Properties.text = {
get: function(){
if (this.innerText) return this.innerText;
var temp = this.ownerDocument.newElement('div', {html: this.innerHTML}).inject(this.ownerDocument.body);
var text = temp.innerText;
temp.destroy();
return text;
}
};
6 changes: 3 additions & 3 deletions Source/Fx/Fx.js
Expand Up @@ -20,9 +20,9 @@ var Fx = new Class({

options: {
/*
onStart: $empty,
onCancel: $empty,
onComplete: $empty,
onStart: nil,
onCancel: nil,
onComplete: nil,
*/
fps: 50,
unit: false,
Expand Down

0 comments on commit 52c103d

Please sign in to comment.