Browse files

Update to MooTools 1.4.1

  • Loading branch information...
1 parent 9ea99da commit d72c8bfccbac5301d9097baca25cf0d4f3f381a7 @arian arian committed Oct 30, 2011
View
1,064 Source/mootools-core-1.3-full.js → Source/mootools-core-1.4-full.js
@@ -3,10 +3,10 @@
MooTools: the javascript framework
web build:
- - http://mootools.net/core/7c56cfef9dddcf170a5d68e3fb61cfd7
+ - http://mootools.net/core/76bf47062d6c1983d66ce47ad66aa0e0
packager build:
- - packager build Core/Core Core/Array Core/String Core/Number Core/Function Core/Object Core/Event Core/Browser Core/Class Core/Class.Extras Core/Slick.Parser Core/Slick.Finder Core/Element Core/Element.Style Core/Element.Event Core/Element.Dimensions Core/Fx Core/Fx.CSS Core/Fx.Tween Core/Fx.Morph Core/Fx.Transitions Core/Request Core/Request.HTML Core/Request.JSON Core/Cookie Core/JSON Core/DOMReady Core/Swiff
+ - packager build Core/Core Core/Array Core/String Core/Number Core/Function Core/Object Core/Event Core/Browser Core/Class Core/Class.Extras Core/Slick.Parser Core/Slick.Finder Core/Element Core/Element.Style Core/Element.Event Core/Element.Delegation Core/Element.Dimensions Core/Fx Core/Fx.CSS Core/Fx.Tween Core/Fx.Morph Core/Fx.Transitions Core/Request Core/Request.HTML Core/Request.JSON Core/Cookie Core/JSON Core/DOMReady Core/Swiff
/*
---
@@ -33,8 +33,8 @@ provides: [Core, MooTools, Type, typeOf, instanceOf, Native]
(function(){
this.MooTools = {
- version: '1.3.2',
- build: 'c9f1ff10e9e7facb65e9481049ed1b450959d587'
+ version: '1.4.1',
+ build: 'd1fb25710e3c5482a219ab9dc675a4e0ad2176b6'
};
// typeOf, instanceOf
@@ -265,7 +265,7 @@ var force = function(name, object, methods){
force('String', String, [
'charAt', 'charCodeAt', 'concat', 'indexOf', 'lastIndexOf', 'match', 'quote', 'replace', 'search',
- 'slice', 'split', 'substr', 'substring', 'toLowerCase', 'toUpperCase'
+ 'slice', 'split', 'substr', 'substring', 'trim', 'toLowerCase', 'toUpperCase'
])('Array', Array, [
'pop', 'push', 'reverse', 'shift', 'sort', 'splice', 'unshift', 'concat', 'join', 'slice',
'indexOf', 'lastIndexOf', 'filter', 'forEach', 'every', 'map', 'some', 'reduce', 'reduceRight'
@@ -421,38 +421,38 @@ Array.implement({
/*<!ES5>*/
every: function(fn, bind){
- for (var i = 0, l = this.length; i < l; i++){
+ for (var i = 0, l = this.length >>> 0; i < l; i++){
if ((i in this) && !fn.call(bind, this[i], i, this)) return false;
}
return true;
},
filter: function(fn, bind){
var results = [];
- for (var i = 0, l = this.length; i < l; i++){
+ for (var i = 0, l = this.length >>> 0; i < l; i++){
if ((i in this) && fn.call(bind, this[i], i, this)) results.push(this[i]);
}
return results;
},
indexOf: function(item, from){
- var len = this.length;
- for (var i = (from < 0) ? Math.max(0, len + from) : from || 0; i < len; i++){
+ var length = this.length >>> 0;
+ for (var i = (from < 0) ? Math.max(0, length + from) : from || 0; i < length; i++){
if (this[i] === item) return i;
}
return -1;
},
map: function(fn, bind){
- var results = [];
- for (var i = 0, l = this.length; i < l; i++){
+ var length = this.length >>> 0, results = Array(length);
+ for (var i = 0; i < length; i++){
if (i in this) results[i] = fn.call(bind, this[i], i, this);
}
return results;
},
some: function(fn, bind){
- for (var i = 0, l = this.length; i < l; i++){
+ for (var i = 0, l = this.length >>> 0; i < l; i++){
if ((i in this) && fn.call(bind, this[i], i, this)) return true;
}
return false;
@@ -596,37 +596,37 @@ String.implement({
},
contains: function(string, separator){
- return (separator) ? (separator + this + separator).indexOf(separator + string + separator) > -1 : this.indexOf(string) > -1;
+ return (separator) ? (separator + this + separator).indexOf(separator + string + separator) > -1 : String(this).indexOf(string) > -1;
},
trim: function(){
- return this.replace(/^\s+|\s+$/g, '');
+ return String(this).replace(/^\s+|\s+$/g, '');
},
clean: function(){
- return this.replace(/\s+/g, ' ').trim();
+ return String(this).replace(/\s+/g, ' ').trim();
},
camelCase: function(){
- return this.replace(/-\D/g, function(match){
+ return String(this).replace(/-\D/g, function(match){
return match.charAt(1).toUpperCase();
});
},
hyphenate: function(){
- return this.replace(/[A-Z]/g, function(match){
+ return String(this).replace(/[A-Z]/g, function(match){
return ('-' + match.charAt(0).toLowerCase());
});
},
capitalize: function(){
- return this.replace(/\b[a-z]/g, function(match){
+ return String(this).replace(/\b[a-z]/g, function(match){
return match.toUpperCase();
});
},
escapeRegExp: function(){
- return this.replace(/([-.*+?^${}()|[\]\/\\])/g, '\\$1');
+ return String(this).replace(/([-.*+?^${}()|[\]\/\\])/g, '\\$1');
},
toInt: function(base){
@@ -638,17 +638,17 @@ String.implement({
},
hexToRgb: function(array){
- var hex = this.match(/^#?(\w{1,2})(\w{1,2})(\w{1,2})$/);
+ var hex = String(this).match(/^#?(\w{1,2})(\w{1,2})(\w{1,2})$/);
return (hex) ? hex.slice(1).hexToRgb(array) : null;
},
rgbToHex: function(array){
- var rgb = this.match(/\d{1,3}/g);
+ var rgb = String(this).match(/\d{1,3}/g);
return (rgb) ? rgb.rgbToHex(array) : null;
},
substitute: function(object, regexp){
- return this.replace(regexp || (/\\?\{([^{}]+)\}/g), function(match, name){
+ return String(this).replace(regexp || (/\\?\{([^{}]+)\}/g), function(match, name){
if (match.charAt(0) == '\\') return match.slice(1);
return (object[name] != null) ? object[name] : '';
});
@@ -750,18 +750,26 @@ Function.implement({
return null;
},
- /*<!ES5>*/
- bind: function(bind){
+ /*<!ES5-bind>*/
+ bind: function(that){
var self = this,
- args = (arguments.length > 1) ? Array.slice(arguments, 1) : null;
-
- return function(){
- if (!args && !arguments.length) return self.call(bind);
- if (args && arguments.length) return self.apply(bind, args.concat(Array.from(arguments)));
- return self.apply(bind, args || arguments);
+ args = arguments.length > 1 ? Array.slice(arguments, 1) : null,
+ F = function(){};
+
+ var bound = function(){
+ var context = that, length = arguments.length;
+ if (this instanceof bound){
+ F.prototype = self.prototype;
+ context = new F;
+ }
+ var result = (!args && !length)
+ ? self.call(context)
+ : self.apply(context, args && length ? args.concat(Array.slice(arguments)) : args || arguments);
+ return context == that ? result : context;
};
+ return bound;
},
- /*</!ES5>*/
+ /*</!ES5-bind>*/
pass: function(args, bind){
var self = this;
@@ -1118,7 +1126,7 @@ try {
name: Event
-description: Contains the Event Class, to make the event object cross-browser.
+description: Contains the Event Type, to make the event object cross-browser.
license: MIT-style license.
@@ -1129,106 +1137,74 @@ provides: Event
...
*/
-var Event = new Type('Event', function(event, win){
+(function() {
+
+var _keys = {};
+
+var DOMEvent = this.DOMEvent = new Type('DOMEvent', function(event, win){
if (!win) win = window;
- var doc = win.document;
event = event || win.event;
if (event.$extended) return event;
+ this.event = event;
this.$extended = true;
- var type = event.type,
- target = event.target || event.srcElement,
- page = {},
- client = {},
- related = null,
- rightClick, wheel, code, key;
+ this.shift = event.shiftKey;
+ this.control = event.ctrlKey;
+ this.alt = event.altKey;
+ this.meta = event.metaKey;
+ var type = this.type = event.type;
+ var target = event.target || event.srcElement;
while (target && target.nodeType == 3) target = target.parentNode;
+ this.target = document.id(target);
- if (type.indexOf('key') != -1){
- code = event.which || event.keyCode;
- key = Object.keyOf(Event.Keys, code);
+ if (type.indexOf('key') == 0){
+ var code = this.code = (event.which || event.keyCode);
+ this.key = _keys[code];
if (type == 'keydown'){
- var fKey = code - 111;
- if (fKey > 0 && fKey < 13) key = 'f' + fKey;
+ if (code > 111 && code < 124) this.key = 'f' + (code - 111);
+ else if (code > 95 && code < 106) this.key = code - 96;
}
- if (!key) key = String.fromCharCode(code).toLowerCase();
- } else if ((/click|mouse|menu/i).test(type)){
+ if (this.key == null) this.key = String.fromCharCode(code).toLowerCase();
+ } else if (type == 'click' || type == 'dblclick' || type == 'contextmenu' || type == 'DOMMouseScroll' || type.indexOf('mouse') == 0){
+ var doc = win.document;
doc = (!doc.compatMode || doc.compatMode == 'CSS1Compat') ? doc.html : doc.body;
- page = {
+ this.page = {
x: (event.pageX != null) ? event.pageX : event.clientX + doc.scrollLeft,
y: (event.pageY != null) ? event.pageY : event.clientY + doc.scrollTop
};
- client = {
+ this.client = {
x: (event.pageX != null) ? event.pageX - win.pageXOffset : event.clientX,
y: (event.pageY != null) ? event.pageY - win.pageYOffset : event.clientY
};
- if ((/DOMMouseScroll|mousewheel/).test(type)){
- wheel = (event.wheelDelta) ? event.wheelDelta / 120 : -(event.detail || 0) / 3;
- }
- rightClick = (event.which == 3) || (event.button == 2);
- if ((/over|out/).test(type)){
- related = event.relatedTarget || event[(type == 'mouseover' ? 'from' : 'to') + 'Element'];
- var testRelated = function(){
- while (related && related.nodeType == 3) related = related.parentNode;
- return true;
- };
- var hasRelated = (Browser.firefox2) ? testRelated.attempt() : testRelated();
- related = (hasRelated) ? related : null;
+ if (type == 'DOMMouseScroll' || type == 'mousewheel')
+ this.wheel = (event.wheelDelta) ? event.wheelDelta / 120 : -(event.detail || 0) / 3;
+
+ this.rightClick = (event.which == 3 || event.button == 2);
+ if (type == 'mouseover' || type == 'mouseout'){
+ var related = event.relatedTarget || event[(type == 'mouseover' ? 'from' : 'to') + 'Element'];
+ while (related && related.nodeType == 3) related = related.parentNode;
+ this.relatedTarget = document.id(related);
}
- } else if ((/gesture|touch/i).test(type)){
+ } else if (type.indexOf('touch') == 0 || type.indexOf('gesture') == 0){
this.rotation = event.rotation;
this.scale = event.scale;
this.targetTouches = event.targetTouches;
this.changedTouches = event.changedTouches;
var touches = this.touches = event.touches;
if (touches && touches[0]){
var touch = touches[0];
- page = {x: touch.pageX, y: touch.pageY};
- client = {x: touch.clientX, y: touch.clientY};
+ this.page = {x: touch.pageX, y: touch.pageY};
+ this.client = {x: touch.clientX, y: touch.clientY};
}
}
- return Object.append(this, {
- event: event,
- type: type,
-
- page: page,
- client: client,
- rightClick: rightClick,
-
- wheel: wheel,
-
- relatedTarget: document.id(related),
- target: document.id(target),
-
- code: code,
- key: key,
-
- shift: event.shiftKey,
- control: event.ctrlKey,
- alt: event.altKey,
- meta: event.metaKey
- });
+ if (!this.client) this.client = {};
+ if (!this.page) this.page = {};
});
-Event.Keys = {
- 'enter': 13,
- 'up': 38,
- 'down': 40,
- 'left': 37,
- 'right': 39,
- 'esc': 27,
- 'space': 32,
- 'backspace': 8,
- 'tab': 9,
- 'delete': 46
-};
-
-
-
-Event.implement({
+DOMEvent.implement({
stop: function(){
- return this.stopPropagation().preventDefault();
+ return this.preventDefault().stopPropagation();
},
stopPropagation: function(){
@@ -1245,6 +1221,25 @@ Event.implement({
});
+DOMEvent.defineKey = function(code, key){
+ _keys[code] = key;
+ return this;
+};
+
+DOMEvent.defineKeys = DOMEvent.defineKey.overloadSetter(true);
+
+DOMEvent.defineKeys({
+ '38': 'up', '40': 'down', '37': 'left', '39': 'right',
+ '27': 'esc', '32': 'space', '8': 'backspace', '9': 'tab',
+ '46': 'delete', '13': 'enter'
+});
+
+})();
+
+
+
+
+
/*
---
@@ -2280,7 +2275,7 @@ local.matchNode = function(node, selector){
if (!parsed) return true;
// simple (single) selectors
- var expressions = parsed.expressions, reversedExpressions, simpleExpCounter = 0, i;
+ var expressions = parsed.expressions, simpleExpCounter = 0, i;
for (i = 0; (currentExpression = expressions[i]); i++){
if (currentExpression.length == 1){
var exp = currentExpression[0];
@@ -2575,7 +2570,7 @@ for (var p in pseudos) local['pseudo:' + p] = pseudos[p];
// attributes methods
-local.attributeGetters = {
+var attributeGetters = local.attributeGetters = {
'class': function(){
return this.getAttribute('class') || this.className;
@@ -2600,15 +2595,22 @@ local.attributeGetters = {
'type': function(){
return this.getAttribute('type');
+ },
+
+ 'maxlength': function(){
+ var attributeNode = this.getAttributeNode('maxLength');
+ return (attributeNode && attributeNode.specified) ? attributeNode.nodeValue : null;
}
};
+attributeGetters.MAXLENGTH = attributeGetters.maxLength = attributeGetters.maxlength;
+
// Slick
var Slick = local.Slick = (this.Slick || {});
-Slick.version = '1.1.5';
+Slick.version = '1.1.6';
// Slick finder
@@ -2630,9 +2632,15 @@ Slick.contains = function(container, node){
// Slick attribute getter
Slick.getAttribute = function(node, name){
+ local.setDocument(node);
return local.getAttribute(node, name);
};
+Slick.hasAttribute = function(node, name){
+ local.setDocument(node);
+ return local.hasAttribute(node, name);
+};
+
// Slick matcher
Slick.match = function(node, selector){
@@ -2697,7 +2705,7 @@ description: One of the most important items in MooTools. Contains the dollar fu
license: MIT-style license.
-requires: [Window, Document, Array, String, Function, Number, Slick.Parser, Slick.Finder]
+requires: [Window, Document, Array, String, Function, Object, Number, Slick.Parser, Slick.Finder]
provides: [Element, Elements, $, $$, Iframe, Selectors]
@@ -2717,8 +2725,8 @@ var Element = function(tag, props){
if (parsed.id && props.id == null) props.id = parsed.id;
var attributes = parsed.attributes;
- if (attributes) for (var i = 0, l = attributes.length; i < l; i++){
- var attr = attributes[i];
+ if (attributes) for (var attr, i = 0, l = attributes.length; i < l; i++){
+ attr = attributes[i];
if (props[attr.key] != null) continue;
if (attr.value != null && attr.operator == '=') props[attr.key] = attr.value;
@@ -2862,9 +2870,9 @@ var splice = Array.prototype.splice, object = {'0': 0, '1': 1, length: 2};
splice.call(object, 1, 1);
if (object[1] == 1) Elements.implement('splice', function(){
var length = this.length;
- splice.apply(this, arguments);
+ var result = splice.apply(this, arguments);
while (length >= this.length) delete this[length--];
- return this;
+ return result;
}.protect());
Elements.implement(Array.prototype);
@@ -2984,6 +2992,79 @@ Window.implement({
});
+var contains = {contains: function(element){
+ return Slick.contains(this, element);
+}};
+
+if (!document.contains) Document.implement(contains);
+if (!document.createElement('div').contains) Element.implement(contains);
+
+
+
+// tree walking
+
+var injectCombinator = function(expression, combinator){
+ if (!expression) return combinator;
+
+ expression = Object.clone(Slick.parse(expression));
+
+ var expressions = expression.expressions;
+ for (var i = expressions.length; i--;)
+ expressions[i][0].combinator = combinator;
+
+ return expression;
+};
+
+Object.forEach({
+ getNext: '~',
+ getPrevious: '!~',
+ getParent: '!'
+}, function(combinator, method){
+ Element.implement(method, function(expression){
+ return this.getElement(injectCombinator(expression, combinator));
+ });
+});
+
+Object.forEach({
+ getAllNext: '~',
+ getAllPrevious: '!~',
+ getSiblings: '~~',
+ getChildren: '>',
+ getParents: '!'
+}, function(combinator, method){
+ Element.implement(method, function(expression){
+ return this.getElements(injectCombinator(expression, combinator));
+ });
+});
+
+Element.implement({
+
+ getFirst: function(expression){
+ return document.id(Slick.search(this, injectCombinator(expression, '>'))[0]);
+ },
+
+ getLast: function(expression){
+ return document.id(Slick.search(this, injectCombinator(expression, '>')).getLast());
+ },
+
+ getWindow: function(){
+ return this.ownerDocument.window;
+ },
+
+ getDocument: function(){
+ return this.ownerDocument;
+ },
+
+ getElementById: function(id){
+ return document.id(Slick.find(this, '#' + ('' + id).replace(/(\W)/g, '\\$1')));
+ },
+
+ match: function(expression){
+ return !expression || Slick.match(this, expression);
+ }
+
+});
+
if (window.$$ == null) Window.implement('$$', function(selector){
@@ -2996,48 +3077,7 @@ if (window.$$ == null) Window.implement('$$', function(selector){
(function(){
-var collected = {}, storage = {};
-var formProps = {input: 'checked', option: 'selected', textarea: 'value'};
-
-var get = function(uid){
- return (storage[uid] || (storage[uid] = {}));
-};
-
-var clean = function(item){
- var uid = item.uid;
- if (item.removeEvents) item.removeEvents();
- if (item.clearAttributes) item.clearAttributes();
- if (uid != null){
- delete collected[uid];
- delete storage[uid];
- }
- return item;
-};
-
-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', 'defaultChecked'
-];
- var attributes = {
- 'html': 'innerHTML',
- 'class': 'className',
- 'for': 'htmlFor',
- 'text': (function(){
- var temp = document.createElement('div');
- return (temp.textContent == null) ? 'innerText' : 'textContent';
- })()
-};
-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, expandos.associate(expandos));
+// Inserters
var inserters = {
@@ -3065,42 +3105,92 @@ inserters.inside = inserters.bottom;
-var injectCombinator = function(expression, combinator){
- if (!expression) return combinator;
+// getProperty / setProperty
- expression = Object.clone(Slick.parse(expression));
+var propertyGetters = {}, propertySetters = {};
- var expressions = expression.expressions;
- for (var i = expressions.length; i--;)
- expressions[i][0].combinator = combinator;
+// properties
- return expression;
-};
+var properties = {};
+Array.forEach([
+ 'type', 'value', 'defaultValue', 'accessKey', 'cellPadding', 'cellSpacing', 'colSpan',
+ 'frameBorder', 'readOnly', 'rowSpan', 'tabIndex', 'useMap'
+], function(property){
+ properties[property.toLowerCase()] = property;
+});
-Element.implement({
+Object.append(properties, {
+ 'html': 'innerHTML',
+ 'text': (function(){
+ var temp = document.createElement('div');
+ return (temp.textContent == null) ? 'innerText': 'textContent';
+ })()
+});
- set: function(prop, value){
- var property = Element.Properties[prop];
- (property && property.set) ? property.set.call(this, value) : this.setProperty(prop, value);
- }.overloadSetter(),
+Object.forEach(properties, function(real, key){
+ propertySetters[key] = function(node, value){
+ node[real] = value;
+ };
+ propertyGetters[key] = function(node){
+ return node[real];
+ };
+});
- get: function(prop){
- var property = Element.Properties[prop];
- return (property && property.get) ? property.get.apply(this) : this.getProperty(prop);
- }.overloadGetter(),
+// Booleans
- erase: function(prop){
- var property = Element.Properties[prop];
- (property && property.erase) ? property.erase.apply(this) : this.removeProperty(prop);
- return this;
+var bools = [
+ 'compact', 'nowrap', 'ismap', 'declare', 'noshade', 'checked',
+ 'disabled', 'readOnly', 'multiple', 'selected', 'noresize',
+ 'defer', 'defaultChecked', 'autofocus', 'controls', 'autoplay',
+ 'loop'
+];
+
+var booleans = {};
+Array.forEach(bools, function(bool){
+ var lower = bool.toLowerCase();
+ booleans[lower] = bool;
+ propertySetters[lower] = function(node, value){
+ node[bool] = !!value;
+ };
+ propertyGetters[lower] = function(node){
+ return !!node[bool];
+ };
+});
+
+// Special cases
+
+Object.append(propertySetters, {
+
+ 'class': function(node, value){
+ ('className' in node) ? node.className = value : node.setAttribute('class', value);
+ },
+
+ 'for': function(node, value){
+ ('htmlFor' in node) ? node.htmlFor = value : node.setAttribute('for', value);
},
- setProperty: function(attribute, value){
- attribute = camels[attribute] || attribute;
- if (value == null) return this.removeProperty(attribute);
- var key = attributes[attribute];
- (key) ? this[key] = value :
- (bools[attribute]) ? this[attribute] = !!value : this.setAttribute(attribute, '' + value);
+ 'style': function(node, value){
+ (node.style) ? node.style.cssText = value : node.setAttribute('style', value);
+ }
+
+});
+
+/* getProperty, setProperty */
+
+Element.implement({
+
+ setProperty: function(name, value){
+ var lower = name.toLowerCase();
+ if (value == null){
+ if (!booleans[lower]){
+ this.removeAttribute(name);
+ return this;
+ }
+ value = false;
+ }
+ var setter = propertySetters[lower];
+ if (setter) setter(this, value);
+ else this.setAttribute(name, value);
return this;
},
@@ -3109,33 +3199,43 @@ Element.implement({
return this;
},
- getProperty: function(attribute){
- 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;
+ getProperty: function(name){
+ var getter = propertyGetters[name.toLowerCase()];
+ if (getter) return getter(this);
+ var result = Slick.getAttribute(this, name);
+ return (!result && !Slick.hasAttribute(this, name)) ? null : result;
},
getProperties: function(){
var args = Array.from(arguments);
return args.map(this.getProperty, this).associate(args);
},
- removeProperty: function(attribute){
- attribute = camels[attribute] || attribute;
- var key = attributes[attribute];
- (key) ? this[key] = '' :
- (bools[attribute]) ? this[attribute] = false : this.removeAttribute(attribute);
- return this;
+ removeProperty: function(name){
+ return this.setProperty(name, null);
},
removeProperties: function(){
Array.each(arguments, this.removeProperty, this);
return this;
},
+ set: function(prop, value){
+ var property = Element.Properties[prop];
+ (property && property.set) ? property.set.call(this, value) : this.setProperty(prop, value);
+ }.overloadSetter(),
+
+ get: function(prop){
+ var property = Element.Properties[prop];
+ return (property && property.get) ? property.get.apply(this) : this.getProperty(prop);
+ }.overloadGetter(),
+
+ erase: function(prop){
+ var property = Element.Properties[prop];
+ (property && property.erase) ? property.erase.apply(this) : this.removeProperty(prop);
+ return this;
+ },
+
hasClass: function(className){
return this.className.clean().contains(className, ' ');
},
@@ -3194,58 +3294,6 @@ Element.implement({
return this.replaces(el).grab(el, where);
},
- getPrevious: function(expression){
- return document.id(Slick.find(this, injectCombinator(expression, '!~')));
- },
-
- getAllPrevious: function(expression){
- return Slick.search(this, injectCombinator(expression, '!~'), new Elements);
- },
-
- getNext: function(expression){
- return document.id(Slick.find(this, injectCombinator(expression, '~')));
- },
-
- getAllNext: function(expression){
- return Slick.search(this, injectCombinator(expression, '~'), new Elements);
- },
-
- getFirst: function(expression){
- return document.id(Slick.search(this, injectCombinator(expression, '>'))[0]);
- },
-
- getLast: function(expression){
- return document.id(Slick.search(this, injectCombinator(expression, '>')).getLast());
- },
-
- getParent: function(expression){
- return document.id(Slick.find(this, injectCombinator(expression, '!')));
- },
-
- getParents: function(expression){
- return Slick.search(this, injectCombinator(expression, '!'), new Elements);
- },
-
- getSiblings: function(expression){
- return Slick.search(this, injectCombinator(expression, '~~'), new Elements);
- },
-
- getChildren: function(expression){
- return Slick.search(this, injectCombinator(expression, '>'), new Elements);
- },
-
- getWindow: function(){
- return this.ownerDocument.window;
- },
-
- getDocument: function(){
- return this.ownerDocument;
- },
-
- getElementById: function(id){
- return document.id(Slick.find(this, '#' + ('' + id).replace(/(\W)/g, '\\$1')));
- },
-
getSelected: function(){
this.selectedIndex; // Safari 3.2.1
return new Elements(Array.from(this.options).filter(function(option){
@@ -3269,7 +3317,30 @@ Element.implement({
});
});
return queryString.join('&');
- },
+ }
+
+});
+
+var collected = {}, storage = {};
+
+var get = function(uid){
+ return (storage[uid] || (storage[uid] = {}));
+};
+
+var clean = function(item){
+ var uid = item.uid;
+ if (item.removeEvents) item.removeEvents();
+ if (item.clearAttributes) item.clearAttributes();
+ if (uid != null){
+ delete collected[uid];
+ delete storage[uid];
+ }
+ return item;
+};
+
+var formProps = {input: 'checked', option: 'selected', textarea: 'value'};
+
+Element.implement({
destroy: function(){
var children = clean(this).getElementsByTagName('*');
@@ -3287,55 +3358,44 @@ Element.implement({
return (this.parentNode) ? this.parentNode.removeChild(this) : this;
},
- match: function(expression){
- return !expression || Slick.match(this, expression);
- }
-
-});
+ clone: function(contents, keepid){
+ contents = contents !== false;
+ var clone = this.cloneNode(contents), ce = [clone], te = [this], i;
-var cleanClone = function(node, element, keepid){
- if (!keepid) node.setAttributeNode(document.createAttribute('id'));
- if (node.clearAttributes){
- node.clearAttributes();
- node.mergeAttributes(element);
- node.removeAttribute('uid');
- if (node.options){
- var no = node.options, eo = element.options;
- for (var i = no.length; i--;) no[i].selected = eo[i].selected;
+ if (contents){
+ ce.append(Array.from(clone.getElementsByTagName('*')));
+ te.append(Array.from(this.getElementsByTagName('*')));
}
- }
-
- var prop = formProps[element.tagName.toLowerCase()];
- if (prop && element[prop]) node[prop] = element[prop];
-};
-Element.implement('clone', function(contents, keepid){
- contents = contents !== false;
- var clone = this.cloneNode(contents), i;
+ for (i = ce.length; i--;){
+ var node = ce[i], element = te[i];
+ if (!keepid) node.removeAttribute('id');
+ /*<ltIE9>*/
+ if (node.clearAttributes){
+ node.clearAttributes();
+ node.mergeAttributes(element);
+ node.removeAttribute('uid');
+ if (node.options){
+ var no = node.options, eo = element.options;
+ for (var j = no.length; j--;) no[j].selected = eo[j].selected;
+ }
+ }
+ /*</ltIE9>*/
+ var prop = formProps[element.tagName.toLowerCase()];
+ if (prop && element[prop]) node[prop] = element[prop];
+ }
- if (contents){
- var ce = clone.getElementsByTagName('*'), te = this.getElementsByTagName('*');
- for (i = ce.length; i--;) cleanClone(ce[i], te[i], keepid);
+ /*<ltIE9>*/
+ if (Browser.ie){
+ var co = clone.getElementsByTagName('object'), to = this.getElementsByTagName('object');
+ for (i = co.length; i--;) co[i].outerHTML = to[i].outerHTML;
+ }
+ /*</ltIE9>*/
+ return document.id(clone);
}
- cleanClone(clone, this, keepid);
-
- if (Browser.ie){
- var co = clone.getElementsByTagName('object'), to = this.getElementsByTagName('object');
- for (i = co.length; i--;) co[i].outerHTML = to[i].outerHTML;
- }
- return document.id(clone);
});
-var contains = {contains: function(element){
- return Slick.contains(this, element);
-}};
-
-if (!document.contains) Document.implement(contains);
-if (!document.createElement('div').contains) Element.implement(contains);
-
-
-
[Element, Window, Document].invoke('implement', {
addListener: function(type, fn){
@@ -3386,8 +3446,6 @@ if (window.attachEvent && !window.addEventListener) window.addListener('unload',
});
/*</ltIE9>*/
-})();
-
Element.Properties = {};
@@ -3416,17 +3474,6 @@ Element.Properties.tag = {
};
-/*<ltIE9>*/
-(function(maxLength){
- if (maxLength != null) Element.Properties.maxlength = Element.Properties.maxLength = {
- get: function(){
- var maxlength = this.getAttribute('maxLength');
- return maxlength == maxLength ? null : maxlength;
- }
- };
-})(document.createElement('input').getAttribute('maxLength'));
-/*</ltIE9>*/
-
/*<!webkit>*/
Element.Properties.html = (function(){
@@ -3445,10 +3492,26 @@ Element.Properties.html = (function(){
};
translations.thead = translations.tfoot = translations.tbody;
+ /*<ltIE9>*/
+ // technique by jdbarlett - http://jdbartlett.com/innershiv/
+ wrapper.innerHTML = '<nav></nav>';
+ var HTML5Test = wrapper.childNodes.length == 1;
+ if (!HTML5Test){
+ var tags = 'abbr article aside audio canvas datalist details figcaption figure footer header hgroup mark meter nav output progress section summary time video'.split(' '),
+ fragment = document.createDocumentFragment(), l = tags.length;
+ while (l--) fragment.createElement(tags[l]);
+ fragment.appendChild(wrapper);
+ }
+ /*</ltIE9>*/
+
var html = {
- set: function(){
- var html = Array.flatten(arguments).join('');
+ set: function(html){
+ if (typeOf(html) == 'array') html = html.join('');
+
var wrap = (!tableTest && translations[this.get('tag')]);
+ /*<ltIE9>*/
+ if (!wrap && !HTML5Test) wrap = [0, '', ''];
+ /*</ltIE9>*/
if (wrap){
var first = wrapper;
first.innerHTML = wrap[1] + html + wrap[2];
@@ -3466,6 +3529,40 @@ Element.Properties.html = (function(){
})();
/*</!webkit>*/
+/*<ltIE9>*/
+var testForm = document.createElement('form');
+testForm.innerHTML = '<select><option>s</option></select>';
+
+if (testForm.firstChild.value != 's') Element.Properties.value = {
+
+ set: function(value){
+ var tag = this.get('tag');
+ if (tag != 'select') return this.setProperty('value', value);
+ var options = this.getElements('option');
+ for (var i = 0; i < options.length; i++){
+ var option = options[i],
+ attr = option.getAttributeNode('value'),
+ optionValue = (attr && attr.specified) ? option.value : option.get('text');
+ if (optionValue == value) return option.selected = true;
+ }
+ },
+
+ get: function(){
+ var option = this, tag = option.get('tag');
+
+ if (tag != 'select' && tag != 'option') return this.getProperty('value');
+
+ if (tag == 'select' && !(option = option.getSelected()[0])) return '';
+
+ var attr = option.getAttributeNode('value');
+ return (attr && attr.specified) ? option.value : option.get('text');
+ }
+
+};
+/*</ltIE9>*/
+
+})();
+
/*
---
@@ -3491,41 +3588,38 @@ Element.Properties.styles = {set: function(styles){
this.setStyles(styles);
}};
-var hasOpacity = (html.style.opacity != null);
-var reAlpha = /alpha\(opacity=([\d.]+)\)/i;
+var hasOpacity = (html.style.opacity != null),
+ hasFilter = (html.style.filter != null),
+ reAlpha = /alpha\(opacity=([\d.]+)\)/i;
-var setOpacity = function(element, opacity){
- if (!element.currentStyle || !element.currentStyle.hasLayout) element.style.zoom = 1;
- if (hasOpacity){
- element.style.opacity = opacity;
- } else {
- opacity = (opacity * 100).limit(0, 100).round();
- opacity = (opacity == 100) ? '' : 'alpha(opacity=' + opacity + ')';
- var filter = element.style.filter || element.getComputedStyle('filter') || '';
- element.style.filter = reAlpha.test(filter) ? filter.replace(reAlpha, opacity) : filter + opacity;
- }
+var setVisibility = function(element, opacity){
+ element.store('$opacity', opacity);
+ element.style.visibility = opacity > 0 ? 'visible' : 'hidden';
};
-Element.Properties.opacity = {
-
- set: function(opacity){
- var visibility = this.style.visibility;
- if (opacity == 0 && visibility != 'hidden') this.style.visibility = 'hidden';
- else if (opacity != 0 && visibility != 'visible') this.style.visibility = 'visible';
-
- setOpacity(this, opacity);
- },
-
- get: (hasOpacity) ? function(){
- var opacity = this.style.opacity || this.getComputedStyle('opacity');
- return (opacity == '') ? 1 : opacity;
- } : function(){
- var opacity, filter = (this.style.filter || this.getComputedStyle('filter'));
- if (filter) opacity = filter.match(reAlpha);
- return (opacity == null || filter == null) ? 1 : (opacity[1] / 100);
- }
-
-};
+var setOpacity = (hasOpacity ? function(element, opacity){
+ element.style.opacity = opacity;
+} : (hasFilter ? function(element, opacity){
+ if (!element.currentStyle || !element.currentStyle.hasLayout) element.style.zoom = 1;
+ opacity = (opacity * 100).limit(0, 100).round();
+ opacity = (opacity == 100) ? '' : 'alpha(opacity=' + opacity + ')';
+ var filter = element.style.filter || element.getComputedStyle('filter') || '';
+ element.style.filter = reAlpha.test(filter) ? filter.replace(reAlpha, opacity) : filter + opacity;
+} : setVisibility));
+
+var getOpacity = (hasOpacity ? function(element){
+ var opacity = element.style.opacity || element.getComputedStyle('opacity');
+ return (opacity == '') ? 1 : opacity.toFloat();
+} : (hasFilter ? function(element){
+ var filter = (element.style.filter || element.getComputedStyle('filter')),
+ opacity;
+ if (filter) opacity = filter.match(reAlpha);
+ return (opacity == null || filter == null) ? 1 : (opacity[1] / 100);
+} : function(element){
+ var opacity = element.retrieve('$opacity');
+ if (opacity == null) opacity = (element.style.visibility == 'hidden' ? 0 : 1);
+ return opacity;
+}));
var floatName = (html.style.cssFloat == null) ? 'styleFloat' : 'cssFloat';
@@ -3538,21 +3632,12 @@ Element.implement({
return (computed) ? computed.getPropertyValue((property == floatName) ? 'float' : property.hyphenate()) : null;
},
- setOpacity: function(value){
- setOpacity(this, value);
- return this;
- },
-
- getOpacity: function(){
- return this.get('opacity');
- },
-
setStyle: function(property, value){
- switch (property){
- case 'opacity': return this.set('opacity', parseFloat(value));
- case 'float': property = floatName;
+ if (property == 'opacity'){
+ setOpacity(this, parseFloat(value));
+ return this;
}
- property = property.camelCase();
+ property = (property == 'float' ? floatName : property).camelCase();
if (typeOf(value) != 'string'){
var map = (Element.Styles[property] || '@').split(' ');
value = Array.from(value).map(function(val, i){
@@ -3567,11 +3652,8 @@ Element.implement({
},
getStyle: function(property){
- switch (property){
- case 'opacity': return this.get('opacity');
- case 'float': property = floatName;
- }
- property = property.camelCase();
+ if (property == 'opacity') return getOpacity(this);
+ property = (property == 'float' ? floatName : property).camelCase();
var result = this.style[property];
if (!result || property == 'zIndex'){
result = [];
@@ -3628,6 +3710,8 @@ Element.Styles = {
+
+
Element.ShortStyles = {margin: {}, padding: {}, border: {}, borderWidth: {}, borderStyle: {}, borderColor: {}};
['Top', 'Right', 'Bottom', 'Left'].each(function(direction){
@@ -3683,14 +3767,14 @@ Element.Properties.events = {set: function(events){
condition = fn,
self = this;
if (custom){
- if (custom.onAdd) custom.onAdd.call(this, fn);
+ if (custom.onAdd) custom.onAdd.call(this, fn, type);
if (custom.condition){
condition = function(event){
- if (custom.condition.call(this, event)) return fn.call(this, event);
+ if (custom.condition.call(this, event, type)) return fn.call(this, event);
return true;
};
}
- realType = custom.base || realType;
+ if (custom.base) realType = Function.from(custom.base).call(this, type);
}
var defn = function(){
return fn.call(self);
@@ -3699,7 +3783,7 @@ Element.Properties.events = {set: function(events){
if (nativeEvent){
if (nativeEvent == 2){
defn = function(event){
- event = new Event(event, self.getWindow());
+ event = new DOMEvent(event, self.getWindow());
if (condition.call(self, event) === false) event.stop();
};
}
@@ -3720,8 +3804,8 @@ Element.Properties.events = {set: function(events){
delete list.values[index];
var custom = Element.Events[type];
if (custom){
- if (custom.onRemove) custom.onRemove.call(this, fn);
- type = custom.base || type;
+ if (custom.onRemove) custom.onRemove.call(this, fn, type);
+ if (custom.base) type = Function.from(custom.base).call(this, type);
}
return (Element.NativeEvents[type]) ? this.removeListener(type, value, arguments[2]) : this;
},
@@ -3787,7 +3871,7 @@ Element.NativeEvents = {
orientationchange: 2, // mobile
touchstart: 2, touchmove: 2, touchend: 2, touchcancel: 2, // touch
gesturestart: 2, gesturechange: 2, gestureend: 2, // gesture
- focus: 2, blur: 2, change: 2, reset: 2, select: 2, submit: 2, //form elements
+ focus: 2, blur: 2, change: 2, reset: 2, select: 2, submit: 2, paste: 2, input: 2, //form elements
load: 2, unload: 1, beforeunload: 2, resize: 1, move: 1, DOMContentLoaded: 1, readystatechange: 1, //window
error: 1, abort: 1, scroll: 1 //misc
};
@@ -3817,6 +3901,21 @@ Element.Events = {
};
+/*<ltIE9>*/
+if (!window.addEventListener){
+ Element.NativeEvents.propertychange = 2;
+ Element.Events.change = {
+ base: function(){
+ var type = this.type;
+ return (this.get('tag') == 'input' && (type == 'radio' || type == 'checkbox')) ? 'propertychange' : 'change'
+ },
+ condition: function(event){
+ return !!(this.type != 'radio' || this.checked);
+ }
+ }
+}
+/*</ltIE9>*/
+
})();
@@ -3825,6 +3924,207 @@ Element.Events = {
/*
---
+name: Element.Delegation
+
+description: Extends the Element native object to include the delegate method for more efficient event management.
+
+license: MIT-style license.
+
+requires: [Element.Event]
+
+provides: [Element.Delegation]
+
+...
+*/
+
+(function(){
+
+var eventListenerSupport = !!window.addEventListener;
+
+Element.NativeEvents.focusin = Element.NativeEvents.focusout = 2;
+
+var bubbleUp = function(self, match, fn, event, target){
+ while (target && target != self){
+ if (match(target, event)) return fn.call(target, event, target);
+ target = document.id(target.parentNode);
+ }
+};
+
+var map = {
+ mouseenter: {
+ base: 'mouseover'
+ },
+ mouseleave: {
+ base: 'mouseout'
+ },
+ focus: {
+ base: 'focus' + (eventListenerSupport ? '' : 'in'),
+ capture: true
+ },
+ blur: {
+ base: eventListenerSupport ? 'blur' : 'focusout',
+ capture: true
+ }
+};
+
+/*<ltIE9>*/
+var _key = '$delegation:';
+var formObserver = function(type){
+
+ return {
+
+ base: 'focusin',
+
+ remove: function(self, uid){
+ var list = self.retrieve(_key + type + 'listeners', {})[uid];
+ if (list && list.forms) for (var i = list.forms.length; i--;){
+ list.forms[i].removeEvent(type, list.fns[i]);
+ }
+ },
+
+ listen: function(self, match, fn, event, target, uid){
+ var form = (target.get('tag') == 'form') ? target : event.target.getParent('form');
+ if (!form) return;
+
+ var listeners = self.retrieve(_key + type + 'listeners', {}),
+ listener = listeners[uid] || {forms: [], fns: []},
+ forms = listener.forms, fns = listener.fns;
+
+ if (forms.indexOf(form) != -1) return;
+ forms.push(form);
+
+ var _fn = function(event){
+ bubbleUp(self, match, fn, event, target);
+ };
+ form.addEvent(type, _fn);
+ fns.push(_fn);
+
+ listeners[uid] = listener;
+ self.store(_key + type + 'listeners', listeners);
+ }
+ };
+};
+
+var inputObserver = function(type){
+ return {
+ base: 'focusin',
+ listen: function(self, match, fn, event, target){
+ var events = {blur: function(){
+ this.removeEvents(events);
+ }};
+ events[type] = function(event){
+ bubbleUp(self, match, fn, event, target);
+ };
+ event.target.addEvents(events);
+ }
+ };
+};
+
+if (!eventListenerSupport) Object.append(map, {
+ submit: formObserver('submit'),
+ reset: formObserver('reset'),
+ change: inputObserver('change'),
+ select: inputObserver('select')
+});
+/*</ltIE9>*/
+
+var proto = Element.prototype,
+ addEvent = proto.addEvent,
+ removeEvent = proto.removeEvent;
+
+var relay = function(old, method){
+ return function(type, fn, useCapture){
+ if (type.indexOf(':relay') == -1) return old.call(this, type, fn, useCapture);
+ var parsed = Slick.parse(type).expressions[0][0];
+ if (parsed.pseudos[0].key != 'relay') return old.call(this, type, fn, useCapture);
+ var newType = parsed.tag;
+ parsed.pseudos.slice(1).each(function(pseudo){
+ newType += ':' + pseudo.key + (pseudo.value ? '(' + pseudo.value + ')' : '');
+ });
+ old.call(this, type, fn);
+ return method.call(this, newType, parsed.pseudos[0].value, fn);
+ };
+};
+
+var delegation = {
+
+ addEvent: function(type, match, fn){
+ var storage = this.retrieve('$delegates', {}), stored = storage[type];
+ if (stored) for (var _uid in stored){
+ if (stored[_uid].fn == fn && stored[_uid].match == match) return this;
+ }
+
+ var _type = type, _match = match, _fn = fn, _map = map[type] || {};
+ type = _map.base || _type;
+
+ match = function(target){
+ return Slick.match(target, _match);
+ };
+
+ var elementEvent = Element.Events[_type];
+ if (elementEvent && elementEvent.condition){
+ var __match = match, condition = elementEvent.condition;
+ match = function(target, event){
+ return __match(target, event) && condition.call(target, event, type);
+ };
+ }
+
+ var self = this, uid = String.uniqueID();
+ var delegator = _map.listen ? function(event, target){
+ if (!target && event && event.target) target = event.target;
+ if (target) _map.listen(self, match, fn, event, target, uid);
+ } : function(event, target){
+ if (!target && event && event.target) target = event.target;
+ if (target) bubbleUp(self, match, fn, event, target);
+ };
+
+ if (!stored) stored = {};
+ stored[uid] = {
+ match: _match,
+ fn: _fn,
+ delegator: delegator
+ };
+ storage[_type] = stored;
+ return addEvent.call(this, type, delegator, _map.capture);
+ },
+
+ removeEvent: function(type, match, fn, _uid){
+ var storage = this.retrieve('$delegates', {}), stored = storage[type];
+ if (!stored) return this;
+
+ if (_uid){
+ var _type = type, delegator = stored[_uid].delegator, _map = map[type] || {};
+ type = _map.base || _type;
+ if (_map.remove) _map.remove(this, _uid);
+ delete stored[_uid];
+ storage[_type] = stored;
+ return removeEvent.call(this, type, delegator);
+ }
+
+ var __uid, s;
+ if (fn) for (__uid in stored){
+ s = stored[__uid];
+ if (s.match == match && s.fn == fn) return delegation.removeEvent.call(this, type, match, fn, __uid);
+ } else for (__uid in stored){
+ s = stored[__uid];
+ if (s.match == match) delegation.removeEvent.call(this, type, match, s.fn, __uid);
+ }
+ return this;
+ }
+
+};
+
+[Element, Window, Document].invoke('implement', {
+ addEvent: relay(addEvent, delegation.addEvent),
+ removeEvent: relay(removeEvent, delegation.removeEvent)
+});
+
+})();
+
+
+/*
+---
+
name: Element.Dimensions
description: Contains methods to work with size, scroll, or positioning of Elements and the window object.
@@ -3961,7 +4261,6 @@ Element.implement({
},
getPosition: function(relative){
- if (isBody(this)) return {x: 0, y: 0};
var offset = this.getOffsets(),
scroll = this.getScrolls();
var position = {
@@ -4500,27 +4799,33 @@ Element.Properties.tween = {
Element.implement({
tween: function(property, from, to){
- this.get('tween').start(arguments);
+ this.get('tween').start(property, from, to);
return this;
},
fade: function(how){
- var fade = this.get('tween'), o = 'opacity', toggle;
- how = [how, 'toggle'].pick();
+ var fade = this.get('tween'), method, to, toggle;
+ if (how == null) how = 'toggle';
switch (how){
- case 'in': fade.start(o, 1); break;
- case 'out': fade.start(o, 0); break;
- case 'show': fade.set(o, 1); break;
- case 'hide': fade.set(o, 0); break;
+ case 'in': method = 'start'; to = 1; break;
+ case 'out': method = 'start'; to = 0; break;
+ case 'show': method = 'set'; to = 1; break;
+ case 'hide': method = 'set'; to = 0; break;
case 'toggle':
- var flag = this.retrieve('fade:flag', this.get('opacity') == 1);
- fade.start(o, (flag) ? 0 : 1);
+ var flag = this.retrieve('fade:flag', this.getStyle('opacity') == 1);
+ method = 'start';
+ to = flag ? 0 : 1;
this.store('fade:flag', !flag);
toggle = true;
break;
- default: fade.start(o, arguments);
+ default: method = 'start'; to = how;
}
if (!toggle) this.eliminate('fade:flag');
+ fade[method]('opacity', to);
+ if (method == 'set' || to != 0) this.setStyle('visibility', to == 0 ? 'hidden' : 'visible');
+ else fade.chain(function(){
+ this.element.setStyle('visibility', 'hidden');
+ });
return this;
},
@@ -5051,11 +5356,18 @@ Request.HTML = new Class({
var temp = new Element('div').set('html', response.html);
response.tree = temp.childNodes;
- response.elements = temp.getElements('*');
-
- if (options.filter) response.tree = response.elements.filter(options.filter);
- if (options.update) document.id(options.update).empty().set('html', response.html);
- else if (options.append) document.id(options.append).adopt(temp.getChildren());
+ response.elements = temp.getElements(options.filter || '*');
+
+ if (options.filter) response.tree = response.elements;
+ if (options.update){
+ var update = document.id(options.update).empty();
+ if (options.filter) update.adopt(response.elements);
+ else update.set('html', response.html);
+ } else if (options.append){
+ var append = document.id(options.append);
+ if (options.filter) response.elements.reverse().inject(append);
+ else append.adopt(temp.getChildren());
+ }
if (options.evalScripts) Browser.exec(response.javascript);
this.onSuccess(response.tree, response.elements, response.html, response.javascript);
@@ -5101,7 +5413,7 @@ description: JSON encoder and decoder.
license: MIT-style license.
-See Also: <http://www.json.org/>
+SeeAlso: <http://www.json.org/>
requires: [Array, String, Number, Function]
@@ -5351,7 +5663,7 @@ var doScrollWorks = function(){
return true;
} catch (e){}
return false;
-}
+};
// If doScroll works already, it can't be used to determine domready
// e.g. in an iframe
if (testElement.doScroll && !doScrollWorks()){
View
622 Source/mootools-more-1.3-full.js → Source/mootools-more-1.4-full.js
@@ -1,6 +1,6 @@
// MooTools: the javascript framework.
-// Load this file's selection again by visiting: http://mootools.net/more/dd5b84594dc4c16de16f47ec6cbdbe12
-// Or build this file again with packager using: packager build More/More More/Events.Pseudos More/Class.Refactor More/Class.Binds More/Class.Occlude More/Chain.Wait More/Array.Extras More/Date More/Date.Extras More/Number.Format More/Object.Extras More/String.Extras More/String.QueryString More/URI More/URI.Relative More/Hash More/Hash.Extras More/Element.Forms More/Elements.From More/Element.Event.Pseudos More/Element.Event.Pseudos.Keys More/Element.Delegation More/Element.Measure More/Element.Pin More/Element.Position More/Element.Shortcuts More/Form.Request More/Form.Request.Append More/Form.Validator More/Form.Validator.Inline More/Form.Validator.Extras More/OverText More/Fx.Elements More/Fx.Accordion More/Fx.Move More/Fx.Reveal More/Fx.Scroll More/Fx.Slide More/Fx.SmoothScroll More/Fx.Sort More/Drag More/Drag.Move More/Slider More/Sortables More/Request.JSONP More/Request.Queue More/Request.Periodical More/Assets More/Color More/Group More/Hash.Cookie More/IframeShim More/Table More/HtmlTable More/HtmlTable.Zebra More/HtmlTable.Sort More/HtmlTable.Select More/Keyboard More/Keyboard.Extras More/Mask More/Scroller More/Tips More/Spinner More/Locale More/Locale.Set.From More/Locale.en-US.Date More/Locale.en-US.Form.Validator More/Locale.en-US.Number
+// Load this file's selection again by visiting: http://mootools.net/more/0f0c6cb64c0317f3f6766c79a4da6762
+// Or build this file again with packager using: packager build More/More More/Events.Pseudos More/Class.Refactor More/Class.Binds More/Class.Occlude More/Chain.Wait More/Array.Extras More/Date More/Date.Extras More/Number.Format More/Object.Extras More/String.Extras More/String.QueryString More/URI More/URI.Relative More/Hash More/Hash.Extras More/Element.Forms More/Elements.From More/Element.Event.Pseudos More/Element.Event.Pseudos.Keys More/Element.Measure More/Element.Pin More/Element.Position More/Element.Shortcuts More/Form.Request More/Form.Request.Append More/Form.Validator More/Form.Validator.Inline More/Form.Validator.Extras More/OverText More/Fx.Elements More/Fx.Accordion More/Fx.Move More/Fx.Reveal More/Fx.Scroll More/Fx.Slide More/Fx.SmoothScroll More/Fx.Sort More/Drag More/Drag.Move More/Slider More/Sortables More/Request.JSONP More/Request.Queue More/Request.Periodical More/Assets More/Color More/Group More/Hash.Cookie More/IframeShim More/Table More/HtmlTable More/HtmlTable.Zebra More/HtmlTable.Sort More/HtmlTable.Select More/Keyboard More/Keyboard.Extras More/Mask More/Scroller More/Tips More/Spinner More/Locale More/Locale.Set.From More/Locale.en-US.Date More/Locale.en-US.Form.Validator More/Locale.en-US.Number
/*
---
@@ -31,8 +31,8 @@ provides: [MooTools.More]
*/
MooTools.More = {
- 'version': '1.3.2.1',
- 'build': 'e586bcd2496e9b22acfde32e12f84d49ce09e59d'
+ 'version': '1.4.0.1',
+ 'build': 'a4244edf2aa97ac8a196fc96082dd35af1abab87'
};
@@ -55,22 +55,24 @@ provides: [Events.Pseudos]
...
*/
+(function(){
+
Events.Pseudos = function(pseudos, addEvent, removeEvent){
- var storeKey = 'monitorEvents:';
+ var storeKey = '_monitorEvents:';
var storageOf = function(object){
return {
store: object.store ? function(key, value){
object.store(storeKey + key, value);
} : function(key, value){
- (object.$monitorEvents || (object.$monitorEvents = {}))[key] = value;
+ (object._monitorEvents || (object._monitorEvents = {}))[key] = value;
},
retrieve: object.retrieve ? function(key, dflt){
return object.retrieve(storeKey + key, dflt);
} : function(key, dflt){
- if (!object.$monitorEvents) return dflt;
- return object.$monitorEvents[key] || dflt;
+ if (!object._monitorEvents) return dflt;
+ return object._monitorEvents[key] || dflt;
}
};
};
@@ -83,24 +85,20 @@ Events.Pseudos = function(pseudos, addEvent, removeEvent){
l = parsedPseudos.length,
splits = [];
- while (l--) if (pseudos[parsedPseudos[l].key]){
- splits.push({
+ while (l--){
+ var pseudo = parsedPseudos[l].key,
+ listener = pseudos[pseudo];
+ if (listener != null) splits.push({
event: parsed.tag,
value: parsedPseudos[l].value,
- pseudo: parsedPseudos[l].key,
- original: type
+ pseudo: pseudo,
+ original: type,
+ listener: listener
});
}
-
return splits.length ? splits : null;
};
- var mergePseudoOptions = function(split){
- return Object.merge.apply(this, split.map(function(item){
- return pseudos[item.pseudo].options || {};
- }));
- };
-
return {
addEvent: function(type, fn, internal){
@@ -110,30 +108,24 @@ Events.Pseudos = function(pseudos, addEvent, removeEvent){
var storage = storageOf(this),
events = storage.retrieve(type, []),
eventType = split[0].event,
- options = mergePseudoOptions(split),
- stack = fn,
- eventOptions = options[eventType] || {},
args = Array.slice(arguments, 2),
- self = this,
- monitor;
-
- if (eventOptions.args) args.append(Array.from(eventOptions.args));
- if (eventOptions.base) eventType = eventOptions.base;
- if (eventOptions.onAdd) eventOptions.onAdd(this);
+ stack = fn,
+ self = this;
split.each(function(item){
- var stackFn = stack;
- stack = function(){
- (eventOptions.listener || pseudos[item.pseudo].listener).call(self, item, stackFn, arguments, monitor, options);
+ var listener = item.listener,
+ stackFn = stack;
+ if (listener == false) eventType += ':' + item.pseudo + '(' + item.value + ')';
+ else stack = function(){
+ listener.call(self, item, stackFn, arguments, stack);
};
});
- monitor = stack.bind(this);
- events.include({event: fn, monitor: monitor});
+ events.include({type: eventType, event: fn, monitor: stack});
storage.store(type, events);
- addEvent.apply(this, [type, fn].concat(args));
- return addEvent.apply(this, [eventType, monitor].concat(args));
+ if (type != eventType) addEvent.apply(this, [type, fn].concat(args));
+ return addEvent.apply(this, [eventType, stack].concat(args));
},
removeEvent: function(type, fn){
@@ -144,18 +136,11 @@ Events.Pseudos = function(pseudos, addEvent, removeEvent){
events = storage.retrieve(type);
if (!events) return this;
- var eventType = split[0].event,
- options = mergePseudoOptions(split),
- eventOptions = options[eventType] || {},
- args = Array.slice(arguments, 2);
-
- if (eventOptions.args) args.append(Array.from(eventOptions.args));
- if (eventOptions.base) eventType = eventOptions.base;
- if (eventOptions.onRemove) eventOptions.onRemove(this);
+ var args = Array.slice(arguments, 2);
removeEvent.apply(this, [type, fn].concat(args));
events.each(function(monitor, i){
- if (!fn || monitor.event == fn) removeEvent.apply(this, [eventType, monitor.monitor].concat(args));
+ if (!fn || monitor.event == fn) removeEvent.apply(this, [monitor.type, monitor.monitor].concat(args));
delete events[i];
}, this);
@@ -167,40 +152,32 @@ Events.Pseudos = function(pseudos, addEvent, removeEvent){
};
-(function(){
-
var pseudos = {
- once: {
- listener: function(split, fn, args, monitor){
- fn.apply(this, args);
- this.removeEvent(split.event, monitor)
- .removeEvent(split.original, fn);
- }
+ once: function(split, fn, args, monitor){
+ fn.apply(this, args);
+ this.removeEvent(split.event, monitor)
+ .removeEvent(split.original, fn);
},
- throttle: {
- listener: function(split, fn, args){
- if (!fn._throttled){
- fn.apply(this, args);
- fn._throttled = setTimeout(function(){
- fn._throttled = false;
- }, split.value || 250);
- }
+ throttle: function(split, fn, args){
+ if (!fn._throttled){
+ fn.apply(this, args);
+ fn._throttled = setTimeout(function(){
+ fn._throttled = false;
+ }, split.value || 250);
}
},
- pause: {
- listener: function(split, fn, args){
- clearTimeout(fn._pause);
- fn._pause = fn.delay(split.value || 250, this, args);
- }
+ pause: function(split, fn, args){
+ clearTimeout(fn._pause);
+ fn._pause = fn.delay(split.value || 250, this, args);
}
};
Events.definePseudo = function(key, listener){
- pseudos[key] = Type.isFunction(listener) ? {listener: listener} : listener;
+ pseudos[key] = listener;
return this;
};
@@ -1001,19 +978,19 @@ Date.implement({
},
isValid: function(date){
- return !isNaN((date || this).valueOf());
+ if (!date) date = this;
+ return typeOf(date) == 'date' && !isNaN(date.valueOf());
},
- format: function(f){
+ format: function(format){
if (!this.isValid()) return 'invalid date';
- if (!f) f = '%x %X';
- var formatLower = f.toLowerCase();
- if (formatters[formatLower]) return formatters[formatLower](this); // it's a formatter!
- f = formats[formatLower] || f; // replace short-hand with actual format
+ if (!format) format = '%x %X';
+ if (typeof format == 'string') format = formats[format.toLowerCase()] || format;
+ if (typeof format == 'function') return format(this);
var d = this;
- return f.replace(/%([a-z%])/gi,
+ return format.replace(/%([a-z%])/gi,
function($0, $1){
switch ($1){
case 'a': return Date.getMsg('days_abbr')[d.get('day')];
@@ -1060,18 +1037,15 @@ Date.implement({
strftime: 'format'
});
-var formats = {
- db: '%Y-%m-%d %H:%M:%S',
- compact: '%Y%m%dT%H%M%S',
- 'short': '%d %b %H:%M',
- 'long': '%B %d, %Y %H:%M'
-};
-
// The day and month abbreviations are standardized, so we cannot use simply %a and %b because they will get localized
var rfcDayAbbr = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
rfcMonthAbbr = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
-var formatters = {
+var formats = {
+ db: '%Y-%m-%d %H:%M:%S',
+ compact: '%Y%m%dT%H%M%S',
+ 'short': '%d %b %H:%M',
+ 'long': '%B %d, %Y %H:%M',
rfc822: function(date){
return rfcDayAbbr[date.get('day')] + date.format(', %d ') + rfcMonthAbbr[date.get('month')] + date.format(' %Y %H:%M:%S %Z');
},
@@ -1091,7 +1065,6 @@ var formatters = {
}
};
-
var parsePatterns = [],
nativeParse = Date.parse;
@@ -1203,11 +1176,6 @@ Date.extend({
return this;
},
- defineFormats: function(formats){
- for (var name in formats) Date.defineFormat(name, formats[name]);
- return this;
- },
-
defineParser: function(pattern){
@@ -1226,6 +1194,8 @@ Date.extend({
return this;
}
+}).extend({
+ defineFormats: Date.defineFormat.overloadSetter()
});
var regexOf = function(type){
@@ -1621,18 +1591,20 @@ Number.implement({
return value;
},
- formatCurrency: function(){
+ formatCurrency: function(decimals){
var locale = Locale.get('Number.currency') || {};
if (locale.scientific == null) locale.scientific = false;
- if (locale.decimals == null) locale.decimals = 2;
+ locale.decimals = decimals != null ? decimals
+ : (locale.decimals == null ? 2 : locale.decimals);
return this.format(locale);
},
- formatPercentage: function(){
+ formatPercentage: function(decimals){
var locale = Locale.get('Number.percentage') || {};
if (locale.suffix == null) locale.suffix = '%';
- if (locale.decimals == null) locale.decimals = 2;
+ locale.decimals = decimals != null ? decimals
+ : (locale.decimals == null ? 2 : locale.decimals);
return this.format(locale);
}
@@ -2473,23 +2445,23 @@ license: MIT-style license
authors:
- Arian Stolwijk
-requires: [Core/Element.Event, Events.Pseudos]
+requires: [Core/Element.Event, Core/Element.Delegation, Events.Pseudos]
-provides: [Element.Event.Pseudos]
+provides: [Element.Event.Pseudos, Element.Delegation]
...
*/
(function(){
-var pseudos = {},
+var pseudos = {relay: false},
copyFromEvents = ['once', 'throttle', 'pause'],
count = copyFromEvents.length;
while (count--) pseudos[copyFromEvents[count]] = Events.lookupPseudo(copyFromEvents[count]);
-Event.definePseudo = function(key, listener){
- pseudos[key] = Type.isFunction(listener) ? {listener: listener} : listener;
+DOMEvent.definePseudo = function(key, listener){
+ pseudos[key] = listener;
return this;
};
@@ -2524,7 +2496,7 @@ var keysStoreKey = '$moo:keys-pressed',
keysKeyupStoreKey = '$moo:keys-keyup';
-Event.definePseudo('keys', function(split, fn, args){
+DOMEvent.definePseudo('keys', function(split, fn, args){
var event = args[0],
keys = [],
@@ -2555,172 +2527,29 @@ Event.definePseudo('keys', function(split, fn, args){
});
-Object.append(Event.Keys, {
- 'shift': 16,
- 'control': 17,
- 'alt': 18,
- 'capslock': 20,
- 'pageup': 33,
- 'pagedown': 34,
- 'end': 35,
- 'home': 36,
- 'numlock': 144,
- 'scrolllock': 145,
- ';': 186,
- '=': 187,
- ',': 188,
- '-': Browser.firefox ? 109 : 189,
- '.': 190,
- '/': 191,
- '`': 192,
- '[': 219,
- '\\': 220,
- ']': 221,
- "'": 222,
- '+': 107
-});
-
-})();
-
-
-/*
----
-
-script: Element.Delegation.js
-
-name: Element.Delegation
-
-description: Extends the Element native object to include the delegate method for more efficient event management.
-
-credits:
- - "Event checking based on the work of Daniel Steigerwald. License: MIT-style license. Copyright: Copyright (c) 2008 Daniel Steigerwald, daniel.steigerwald.cz"
-
-license: MIT-style license
-
-authors:
- - Aaron Newton
- - Daniel Steigerwald
-
-requires: [/MooTools.More, Element.Event.Pseudos]
-
-provides: [Element.Delegation]
-
-...
-*/
-
-(function(){
-
-var eventListenerSupport = !(window.attachEvent && !window.addEventListener),
- nativeEvents = Element.NativeEvents;
-
-nativeEvents.focusin = 2;
-nativeEvents.focusout = 2;
-
-var check = function(split, target, event){
- var elementEvent = Element.Events[split.event], condition;
- if (elementEvent) condition = elementEvent.condition;
- return Slick.match(target, split.value) && (!condition || condition.call(target, event));
-};
-
-var bubbleUp = function(split, event, fn){
- for (var target = event.target; target && target != this; target = document.id(target.parentNode)){
- if (target && check(split, target, event)) return fn.call(target, event, target);
- }
-};
-
-var formObserver = function(eventName){
-
- var $delegationKey = '$delegation:';
-
- return {
- base: 'focusin',
-
- onRemove: function(element){
- element.retrieve($delegationKey + 'forms', []).each(function(el){
- el.retrieve($delegationKey + 'listeners', []).each(function(listener){
- el.removeEvent(eventName, listener);
- });
- el.eliminate($delegationKey + eventName + 'listeners')
- .eliminate($delegationKey + eventName + 'originalFn');
- });
- },
-
- listener: function(split, fn, args, monitor, options){
- var event = args[0],
- forms = this.retrieve($delegationKey + 'forms', []),
- target = event.target,
- form = (target.get('tag') == 'form') ? target : event.target.getParent('form');
-
- if (!form) return;
-
- var formEvents = form.retrieve($delegationKey + 'originalFn', []),
- formListeners = form.retrieve($delegationKey + 'listeners', []),
- self = this;
-
- forms.include(form);
- this.store($delegationKey + 'forms', forms);
-
- if (!formEvents.contains(fn)){
- var formListener = function(event){
- bubbleUp.call(self, split, event, fn);
- };
- form.addEvent(eventName, formListener);
-
- formEvents.push(fn);
- formListeners.push(formListener);
-
- form.store($delegationKey + eventName + 'originalFn', formEvents)
- .store($delegationKey + eventName + 'listeners', formListeners);
- }
- }
- };
-};