From 69ccd536536ce0bf81627c4bce5534110f397da6 Mon Sep 17 00:00:00 2001 From: Andrew Bauer Date: Sat, 9 May 2015 17:23:01 -0500 Subject: [PATCH] rollback mootools-core to 1.4.5-compat --- web/tools/mootools/Makefile.am | 6 +- ...1.5.1.js => mootools-core-1.4.5-compat.js} | 3157 +++++++++-------- 2 files changed, 1771 insertions(+), 1392 deletions(-) rename web/tools/mootools/{mootools-core-1.5.1.js => mootools-core-1.4.5-compat.js} (87%) diff --git a/web/tools/mootools/Makefile.am b/web/tools/mootools/Makefile.am index 8b31023a8..89b17ab8d 100644 --- a/web/tools/mootools/Makefile.am +++ b/web/tools/mootools/Makefile.am @@ -3,14 +3,14 @@ AUTOMAKE_OPTIONS = gnu webdir = @WEB_PREFIX@/tools/mootools dist_web_DATA = \ - mootools-core-1.5.1.js \ + mootools-core-1.4.5-compat.js \ mootools-more-1.5.1.js # Yes, you are correct. This is a HACK! install-data-hook: ( cd $(DESTDIR)$(webdir); rm -f mootools-core.js mootools-more.js ) - ( cd $(DESTDIR)$(webdir); ln -s mootools-core-1.5.1.js mootools-core.js ) - ( cd $(DESTDIR)$(webdir); ln -s mootools-more-1.5.1.js mootools-more.js ) + ( cd $(DESTDIR)$(webdir); ln -sf mootools-core-1.4.5-compat.js mootools-core.js ) + ( cd $(DESTDIR)$(webdir); ln -sf mootools-more-1.5.1.js mootools-more.js ) uninstall-hook: @-( cd $(DESTDIR)$(webdir); rm -f mootools-* ) diff --git a/web/tools/mootools/mootools-core-1.5.1.js b/web/tools/mootools/mootools-core-1.4.5-compat.js similarity index 87% rename from web/tools/mootools/mootools-core-1.5.1.js rename to web/tools/mootools/mootools-core-1.4.5-compat.js index e0bea6df6..574c9411a 100644 --- a/web/tools/mootools/mootools-core-1.5.1.js +++ b/web/tools/mootools/mootools-core-1.4.5-compat.js @@ -1,7 +1,16 @@ -/* MooTools: the javascript framework. license: MIT-style license. copyright: Copyright (c) 2006-2015 [Valerio Proietti](http://mad4milk.net/).*/ /* -Web Build: http://mootools.net/core/builder/e426a9ae7167c5807b173d5deff673fc +--- +MooTools: the javascript framework + +web build: + - 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.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 + +... */ + /* --- @@ -11,7 +20,7 @@ description: The heart of MooTools. license: MIT-style license. -copyright: Copyright (c) 2006-2014 [Valerio Proietti](http://mad4milk.net/). +copyright: Copyright (c) 2006-2012 [Valerio Proietti](http://mad4milk.net/). authors: The MooTools production team (http://mootools.net/developers/) @@ -23,12 +32,12 @@ provides: [Core, MooTools, Type, typeOf, instanceOf, Native] ... */ -/*! MooTools: the javascript framework. license: MIT-style license. copyright: Copyright (c) 2006-2014 [Valerio Proietti](http://mad4milk.net/).*/ + (function(){ this.MooTools = { - version: '1.5.1', - build: '0542c135fdeb7feed7d9917e01447a408f22c876' + version: '1.4.5', + build: 'ab8ea8824dc3b24b6666867a2c4ed58ebb762cf0' }; // typeOf, instanceOf @@ -41,7 +50,7 @@ var typeOf = this.typeOf = function(item){ if (item.nodeType == 1) return 'element'; if (item.nodeType == 3) return (/\S/).test(item.nodeValue) ? 'textnode' : 'whitespace'; } else if (typeof item.length == 'number'){ - if ('callee' in item) return 'arguments'; + if (item.callee) return 'arguments'; if ('item' in item) return 'collection'; } @@ -165,7 +174,9 @@ var Type = this.Type = function(name, object){ object.prototype.$family = (function(){ return lower; }).hide(); - + //<1.2compat> + object.type = typeCheck; + // } } @@ -258,7 +269,7 @@ var force = function(name, object, methods){ if (!methodsEnumerable) for (var i = 0, l = methods.length; i < l; i++){ fn.call(prototype, prototype[methods[i]], methods[i]); } - for (var key in prototype) fn.call(prototype, prototype[key], key); + for (var key in prototype) fn.call(prototype, prototype[key], key) }; } @@ -266,7 +277,7 @@ var force = function(name, object, methods){ }; force('String', String, [ - 'charAt', 'charCodeAt', 'concat', 'contains', 'indexOf', 'lastIndexOf', 'match', 'quote', 'replace', 'search', + 'charAt', 'charCodeAt', 'concat', 'indexOf', 'lastIndexOf', 'match', 'quote', 'replace', 'search', 'slice', 'split', 'substr', 'substring', 'trim', 'toLowerCase', 'toUpperCase' ])('Array', Array, [ 'pop', 'push', 'reverse', 'shift', 'sort', 'splice', 'unshift', 'concat', 'join', 'slice', @@ -316,13 +327,11 @@ Object.each = Object.forEach; Array.implement({ - /**/ forEach: function(fn, bind){ for (var i = 0, l = this.length; i < l; i++){ if (i in this) fn.call(bind, this[i], i, this); } }, - /**/ each: function(fn, bind){ Array.forEach(this, fn, bind); @@ -400,10 +409,129 @@ String.extend('uniqueID', function(){ return (UID++).toString(36); }); +//<1.2compat> +var Hash = this.Hash = new Type('Hash', function(object){ + if (typeOf(object) == 'hash') object = Object.clone(object.getClean()); + for (var key in object) this[key] = object[key]; + return this; +}); + +Hash.implement({ + + forEach: function(fn, bind){ + Object.forEach(this, fn, bind); + }, + + getClean: function(){ + var clean = {}; + for (var key in this){ + if (this.hasOwnProperty(key)) clean[key] = this[key]; + } + return clean; + }, + + getLength: function(){ + var length = 0; + for (var key in this){ + if (this.hasOwnProperty(key)) length++; + } + return length; + } + +}); + +Hash.alias('each', 'forEach'); + +Object.type = Type.isObject; + +var Native = this.Native = function(properties){ + return new Type(properties.name, properties.initialize); +}; + +Native.type = Type.type; + +Native.implement = function(objects, methods){ + for (var i = 0; i < objects.length; i++) objects[i].implement(methods); + return Native; +}; + +var arrayType = Array.type; +Array.type = function(item){ + return instanceOf(item, Array) || arrayType(item); +}; + +this.$A = function(item){ + return Array.from(item).slice(); +}; + +this.$arguments = function(i){ + return function(){ + return arguments[i]; + }; +}; + +this.$chk = function(obj){ + return !!(obj || obj === 0); +}; + +this.$clear = function(timer){ + clearTimeout(timer); + clearInterval(timer); + return null; +}; + +this.$defined = function(obj){ + return (obj != null); +}; + +this.$each = function(iterable, fn, bind){ + var type = typeOf(iterable); + ((type == 'arguments' || type == 'collection' || type == 'array' || type == 'elements') ? Array : Object).each(iterable, fn, bind); +}; + +this.$empty = function(){}; + +this.$extend = function(original, extended){ + return Object.append(original, extended); +}; + +this.$H = function(object){ + return new Hash(object); +}; + +this.$merge = function(){ + var args = Array.slice(arguments); + args.unshift({}); + return Object.merge.apply(null, args); +}; + +this.$lambda = Function.from; +this.$mixin = Object.merge; +this.$random = Number.random; +this.$splat = Array.from; +this.$time = Date.now; + +this.$type = function(object){ + var type = typeOf(object); + if (type == 'elements') return 'array'; + return (type == 'null') ? false : type; +}; + +this.$unlink = function(object){ + switch (typeOf(object)){ + case 'object': return Object.clone(object); + case 'array': return Array.clone(object); + case 'hash': return new Hash(object); + default: return object; + } +}; + +// })(); + /* --- @@ -413,7 +541,7 @@ description: Contains Array Prototypes like each, contains, and erase. license: MIT-style license. -requires: [Type] +requires: Type provides: Array @@ -556,7 +684,7 @@ Array.implement({ if (this.length != 3) return null; var rgb = this.map(function(value){ if (value.length == 1) value += value; - return parseInt(value, 16); + return value.toInt(16); }); return (array) ? rgb : 'rgb(' + rgb + ')'; }, @@ -574,6 +702,153 @@ Array.implement({ }); +//<1.2compat> + +Array.alias('extend', 'append'); + +var $pick = function(){ + return Array.from(arguments).pick(); +}; + +// + + +/* +--- + +name: String + +description: Contains String Prototypes like camelCase, capitalize, test, and toInt. + +license: MIT-style license. + +requires: Type + +provides: String + +... +*/ + +String.implement({ + + test: function(regex, params){ + return ((typeOf(regex) == 'regexp') ? regex : new RegExp('' + regex, params)).test(this); + }, + + contains: function(string, separator){ + return (separator) ? (separator + this + separator).indexOf(separator + string + separator) > -1 : String(this).indexOf(string) > -1; + }, + + trim: function(){ + return String(this).replace(/^\s+|\s+$/g, ''); + }, + + clean: function(){ + return String(this).replace(/\s+/g, ' ').trim(); + }, + + camelCase: function(){ + return String(this).replace(/-\D/g, function(match){ + return match.charAt(1).toUpperCase(); + }); + }, + + hyphenate: function(){ + return String(this).replace(/[A-Z]/g, function(match){ + return ('-' + match.charAt(0).toLowerCase()); + }); + }, + + capitalize: function(){ + return String(this).replace(/\b[a-z]/g, function(match){ + return match.toUpperCase(); + }); + }, + + escapeRegExp: function(){ + return String(this).replace(/([-.*+?^${}()|[\]\/\\])/g, '\\$1'); + }, + + toInt: function(base){ + return parseInt(this, base || 10); + }, + + toFloat: function(){ + return parseFloat(this); + }, + + hexToRgb: function(array){ + 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 = String(this).match(/\d{1,3}/g); + return (rgb) ? rgb.rgbToHex(array) : null; + }, + + substitute: function(object, regexp){ + return String(this).replace(regexp || (/\\?\{([^{}]+)\}/g), function(match, name){ + if (match.charAt(0) == '\\') return match.slice(1); + return (object[name] != null) ? object[name] : ''; + }); + } + +}); + + +/* +--- + +name: Number + +description: Contains Number Prototypes like limit, round, times, and ceil. + +license: MIT-style license. + +requires: Type + +provides: Number + +... +*/ + +Number.implement({ + + limit: function(min, max){ + return Math.min(max, Math.max(min, this)); + }, + + round: function(precision){ + precision = Math.pow(10, precision || 0).toFixed(precision < 0 ? -precision : 0); + return Math.round(this * precision) / precision; + }, + + times: function(fn, bind){ + for (var i = 0; i < this; i++) fn.call(bind, i, this); + }, + + toFloat: function(){ + return parseFloat(this); + }, + + toInt: function(base){ + return parseInt(this, base || 10); + } + +}); + +Number.alias('each', 'times'); + +(function(math){ + var methods = {}; + math.each(function(name){ + if (!Number[name]) methods[name] = function(){ + return Math[name].apply(null, [this].concat(Array.from(arguments))); + }; + }); + Number.implement(methods); +})(['abs', 'acos', 'asin', 'atan', 'atan2', 'ceil', 'cos', 'exp', 'floor', 'log', 'max', 'min', 'pow', 'sin', 'sqrt', 'tan']); /* @@ -654,577 +929,57 @@ Function.implement({ }); +//<1.2compat> +delete Function.prototype.bind; -/* ---- +Function.implement({ -name: Number - -description: Contains Number Prototypes like limit, round, times, and ceil. - -license: MIT-style license. - -requires: Type - -provides: Number - -... -*/ - -Number.implement({ - - limit: function(min, max){ - return Math.min(max, Math.max(min, this)); - }, - - round: function(precision){ - precision = Math.pow(10, precision || 0).toFixed(precision < 0 ? -precision : 0); - return Math.round(this * precision) / precision; - }, - - times: function(fn, bind){ - for (var i = 0; i < this; i++) fn.call(bind, i, this); - }, - - toFloat: function(){ - return parseFloat(this); - }, - - toInt: function(base){ - return parseInt(this, base || 10); - } - -}); - -Number.alias('each', 'times'); - -(function(math){ - var methods = {}; - math.each(function(name){ - if (!Number[name]) methods[name] = function(){ - return Math[name].apply(null, [this].concat(Array.from(arguments))); + create: function(options){ + var self = this; + options = options || {}; + return function(event){ + var args = options.arguments; + args = (args != null) ? Array.from(args) : Array.slice(arguments, (options.event) ? 1 : 0); + if (options.event) args = [event || window.event].extend(args); + var returns = function(){ + return self.apply(options.bind || null, args); + }; + if (options.delay) return setTimeout(returns, options.delay); + if (options.periodical) return setInterval(returns, options.periodical); + if (options.attempt) return Function.attempt(returns); + return returns(); }; - }); - Number.implement(methods); -})(['abs', 'acos', 'asin', 'atan', 'atan2', 'ceil', 'cos', 'exp', 'floor', 'log', 'max', 'min', 'pow', 'sin', 'sqrt', 'tan']); - -/* ---- - -name: String - -description: Contains String Prototypes like camelCase, capitalize, test, and toInt. - -license: MIT-style license. - -requires: [Type, Array] - -provides: String - -... -*/ - -String.implement({ - - // - contains: function(string, index){ - return (index ? String(this).slice(index) : String(this)).indexOf(string) > -1; - }, - // - - test: function(regex, params){ - return ((typeOf(regex) == 'regexp') ? regex : new RegExp('' + regex, params)).test(this); }, - trim: function(){ - return String(this).replace(/^\s+|\s+$/g, ''); - }, - - clean: function(){ - return String(this).replace(/\s+/g, ' ').trim(); - }, - - camelCase: function(){ - return String(this).replace(/-\D/g, function(match){ - return match.charAt(1).toUpperCase(); - }); - }, - - hyphenate: function(){ - return String(this).replace(/[A-Z]/g, function(match){ - return ('-' + match.charAt(0).toLowerCase()); - }); - }, - - capitalize: function(){ - return String(this).replace(/\b[a-z]/g, function(match){ - return match.toUpperCase(); - }); - }, - - escapeRegExp: function(){ - return String(this).replace(/([-.*+?^${}()|[\]\/\\])/g, '\\$1'); - }, - - toInt: function(base){ - return parseInt(this, base || 10); - }, - - toFloat: function(){ - return parseFloat(this); - }, - - hexToRgb: function(array){ - 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 = String(this).match(/\d{1,3}/g); - return (rgb) ? rgb.rgbToHex(array) : null; - }, - - substitute: function(object, regexp){ - return String(this).replace(regexp || (/\\?\{([^{}]+)\}/g), function(match, name){ - if (match.charAt(0) == '\\') return match.slice(1); - return (object[name] != null) ? object[name] : ''; - }); - } - -}); - - - -/* ---- - -name: Browser - -description: The Browser Object. Contains Browser initialization, Window and Document, and the Browser Hash. - -license: MIT-style license. - -requires: [Array, Function, Number, String] - -provides: [Browser, Window, Document] - -... -*/ - -(function(){ - -var document = this.document; -var window = document.window = this; - -var parse = function(ua, platform){ - ua = ua.toLowerCase(); - platform = (platform ? platform.toLowerCase() : ''); - - var UA = ua.match(/(opera|ie|firefox|chrome|trident|crios|version)[\s\/:]([\w\d\.]+)?.*?(safari|(?:rv[\s\/:]|version[\s\/:])([\w\d\.]+)|$)/) || [null, 'unknown', 0]; - - if (UA[1] == 'trident'){ - UA[1] = 'ie'; - if (UA[4]) UA[2] = UA[4]; - } else if (UA[1] == 'crios'){ - UA[1] = 'chrome'; - } - - platform = ua.match(/ip(?:ad|od|hone)/) ? 'ios' : (ua.match(/(?:webos|android)/) || platform.match(/mac|win|linux/) || ['other'])[0]; - if (platform == 'win') platform = 'windows'; - - return { - extend: Function.prototype.extend, - name: (UA[1] == 'version') ? UA[3] : UA[1], - version: parseFloat((UA[1] == 'opera' && UA[4]) ? UA[4] : UA[2]), - platform: platform - }; -}; - -var Browser = this.Browser = parse(navigator.userAgent, navigator.platform); - -if (Browser.name == 'ie'){ - Browser.version = document.documentMode; -} - -Browser.extend({ - Features: { - xpath: !!(document.evaluate), - air: !!(window.runtime), - query: !!(document.querySelector), - json: !!(window.JSON) - }, - parseUA: parse -}); - - - -// Request - -Browser.Request = (function(){ - - var XMLHTTP = function(){ - return new XMLHttpRequest(); - }; - - var MSXML2 = function(){ - return new ActiveXObject('MSXML2.XMLHTTP'); - }; - - var MSXML = function(){ - return new ActiveXObject('Microsoft.XMLHTTP'); - }; - - return Function.attempt(function(){ - XMLHTTP(); - return XMLHTTP; - }, function(){ - MSXML2(); - return MSXML2; - }, function(){ - MSXML(); - return MSXML; - }); - -})(); - -Browser.Features.xhr = !!(Browser.Request); - - - -// String scripts - -Browser.exec = function(text){ - if (!text) return text; - if (window.execScript){ - window.execScript(text); - } else { - var script = document.createElement('script'); - script.setAttribute('type', 'text/javascript'); - script.text = text; - document.head.appendChild(script); - document.head.removeChild(script); - } - return text; -}; - -String.implement('stripScripts', function(exec){ - var scripts = ''; - var text = this.replace(/]*>([\s\S]*?)<\/script>/gi, function(all, code){ - scripts += code + '\n'; - return ''; - }); - if (exec === true) Browser.exec(scripts); - else if (typeOf(exec) == 'function') exec(scripts, text); - return text; -}); - -// Window, Document - -Browser.extend({ - Document: this.Document, - Window: this.Window, - Element: this.Element, - Event: this.Event -}); - -this.Window = this.$constructor = new Type('Window', function(){}); - -this.$family = Function.from('window').hide(); - -Window.mirror(function(name, method){ - window[name] = method; -}); - -this.Document = document.$constructor = new Type('Document', function(){}); - -document.$family = Function.from('document').hide(); - -Document.mirror(function(name, method){ - document[name] = method; -}); - -document.html = document.documentElement; -if (!document.head) document.head = document.getElementsByTagName('head')[0]; - -if (document.execCommand) try { - document.execCommand("BackgroundImageCache", false, true); -} catch (e){} - -/**/ -if (this.attachEvent && !this.addEventListener){ - var unloadEvent = function(){ - this.detachEvent('onunload', unloadEvent); - document.head = document.html = document.window = null; - window = this.Window = document = null; - }; - this.attachEvent('onunload', unloadEvent); -} - -// IE fails on collections and ) -var arrayFrom = Array.from; -try { - arrayFrom(document.html.childNodes); -} catch(e){ - Array.from = function(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; - } - return arrayFrom(item); - }; - - var prototype = Array.prototype, - slice = prototype.slice; - ['pop', 'push', 'reverse', 'shift', 'sort', 'splice', 'unshift', 'concat', 'join', 'slice'].each(function(name){ - var method = prototype[name]; - Array[name] = function(item){ - return method.apply(Array.from(item), slice.call(arguments, 1)); + bind: function(bind, args){ + var self = this; + if (args != null) args = Array.from(args); + return function(){ + return self.apply(bind, args || arguments); }; - }); -} -/**/ - - - -})(); - -/* ---- - -name: Class - -description: Contains the Class Function for easily creating, extending, and implementing reusable Classes. - -license: MIT-style license. - -requires: [Array, String, Function, Number] - -provides: Class - -... -*/ - -(function(){ - -var Class = this.Class = new Type('Class', function(params){ - if (instanceOf(params, Function)) params = {initialize: params}; - - var newClass = function(){ - reset(this); - if (newClass.$prototyping) return this; - this.$caller = null; - var value = (this.initialize) ? this.initialize.apply(this, arguments) : this; - this.$caller = this.caller = null; - return value; - }.extend(this).implement(params); - - newClass.$constructor = Class; - newClass.prototype.$constructor = newClass; - newClass.prototype.parent = parent; - - return newClass; -}); - -var parent = function(){ - if (!this.$caller) throw new Error('The method "parent" cannot be called.'); - var name = this.$caller.$name, - parent = this.$caller.$owner.parent, - previous = (parent) ? parent.prototype[name] : null; - if (!previous) throw new Error('The method "' + name + '" has no parent.'); - return previous.apply(this, arguments); -}; - -var reset = function(object){ - for (var key in object){ - var value = object[key]; - switch (typeOf(value)){ - case 'object': - var F = function(){}; - F.prototype = value; - object[key] = reset(new F); - break; - case 'array': object[key] = value.clone(); break; - } - } - return object; -}; - -var wrap = function(self, key, method){ - if (method.$origin) method = method.$origin; - var wrapper = function(){ - 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 = wrapper; - var result = method.apply(this, arguments); - this.$caller = current; this.caller = caller; - return result; - }.extend({$owner: self, $origin: method, $name: key}); - return wrapper; -}; - -var implement = function(key, value, retain){ - if (Class.Mutators.hasOwnProperty(key)){ - value = Class.Mutators[key].call(this, value); - if (value == null) return this; - } - - if (typeOf(value) == 'function'){ - if (value.$hidden) return this; - this.prototype[key] = (retain) ? value : wrap(this, key, value); - } else { - Object.merge(this.prototype, key, value); - } - - return this; -}; - -var getInstance = function(klass){ - klass.$prototyping = true; - var proto = new klass; - delete klass.$prototyping; - return proto; -}; - -Class.implement('implement', implement.overloadSetter()); - -Class.Mutators = { - - Extends: function(parent){ - this.parent = parent; - this.prototype = getInstance(parent); }, - Implements: function(items){ - Array.from(items).each(function(item){ - var instance = new item; - for (var key in instance) implement.call(this, key, instance[key], true); - }, this); - } -}; - -})(); - -/* ---- - -name: Class.Extras - -description: Contains Utility Classes that can be implemented into your own Classes to ease the execution of many common tasks. - -license: MIT-style license. - -requires: Class - -provides: [Class.Extras, Chain, Events, Options] - -... -*/ - -(function(){ - -this.Chain = new Class({ - - $chain: [], - - chain: function(){ - this.$chain.append(Array.flatten(arguments)); - return this; + bindWithEvent: function(bind, args){ + var self = this; + if (args != null) args = Array.from(args); + return function(event){ + return self.apply(bind, (args == null) ? arguments : [event].concat(args)); + }; }, - callChain: function(){ - return (this.$chain.length) ? this.$chain.shift().apply(this, arguments) : false; - }, - - clearChain: function(){ - this.$chain.empty(); - return this; + run: function(args, bind){ + return this.apply(bind, Array.from(args)); } }); -var removeOn = function(string){ - return string.replace(/^on([A-Z])/, function(full, first){ - return first.toLowerCase(); - }); -}; +if (Object.create == Function.prototype.create) Object.create = null; -this.Events = new Class({ +var $try = Function.attempt; - $events: {}, +// - addEvent: function(type, fn, internal){ - type = removeOn(type); - - - - this.$events[type] = (this.$events[type] || []).include(fn); - if (internal) fn.internal = true; - return this; - }, - - addEvents: function(events){ - for (var type in events) this.addEvent(type, events[type]); - return this; - }, - - fireEvent: function(type, args, delay){ - type = removeOn(type); - var events = this.$events[type]; - if (!events) return this; - args = Array.from(args); - events.each(function(fn){ - if (delay) fn.delay(delay, this, args); - else fn.apply(this, args); - }, this); - return this; - }, - - removeEvent: function(type, fn){ - type = removeOn(type); - var events = this.$events[type]; - if (events && !fn.internal){ - var index = events.indexOf(fn); - if (index != -1) delete events[index]; - } - return this; - }, - - removeEvents: function(events){ - var type; - if (typeOf(events) == 'object'){ - for (type in events) this.removeEvent(type, events[type]); - return this; - } - if (events) events = removeOn(events); - for (type in this.$events){ - if (events && events != type) continue; - var fns = this.$events[type]; - for (var i = fns.length; i--;) if (i in fns){ - this.removeEvent(type, fns[i]); - } - } - return this; - } - -}); - -this.Options = new Class({ - - setOptions: function(){ - var options = this.options = Object.merge.apply(null, [{}, this.options].append(arguments)); - if (this.addEvent) for (var option in options){ - if (typeOf(options[option]) != 'function' || !(/^on[A-Z]/).test(option)) continue; - this.addEvent(option, options[option]); - delete options[option]; - } - return this; - } - -}); - -})(); /* --- @@ -1346,6 +1101,717 @@ Object.extend({ })(); +//<1.2compat> + +Hash.implement({ + + has: Object.prototype.hasOwnProperty, + + keyOf: function(value){ + return Object.keyOf(this, value); + }, + + hasValue: function(value){ + return Object.contains(this, value); + }, + + extend: function(properties){ + Hash.each(properties || {}, function(value, key){ + Hash.set(this, key, value); + }, this); + return this; + }, + + combine: function(properties){ + Hash.each(properties || {}, function(value, key){ + Hash.include(this, key, value); + }, this); + return this; + }, + + erase: function(key){ + if (this.hasOwnProperty(key)) delete this[key]; + return this; + }, + + get: function(key){ + return (this.hasOwnProperty(key)) ? this[key] : null; + }, + + set: function(key, value){ + if (!this[key] || this.hasOwnProperty(key)) this[key] = value; + return this; + }, + + empty: function(){ + Hash.each(this, function(value, key){ + delete this[key]; + }, this); + return this; + }, + + include: function(key, value){ + if (this[key] == null) this[key] = value; + return this; + }, + + map: function(fn, bind){ + return new Hash(Object.map(this, fn, bind)); + }, + + filter: function(fn, bind){ + return new Hash(Object.filter(this, fn, bind)); + }, + + every: function(fn, bind){ + return Object.every(this, fn, bind); + }, + + some: function(fn, bind){ + return Object.some(this, fn, bind); + }, + + getKeys: function(){ + return Object.keys(this); + }, + + getValues: function(){ + return Object.values(this); + }, + + toQueryString: function(base){ + return Object.toQueryString(this, base); + } + +}); + +Hash.extend = Object.append; + +Hash.alias({indexOf: 'keyOf', contains: 'hasValue'}); + +// + + +/* +--- + +name: Browser + +description: The Browser Object. Contains Browser initialization, Window and Document, and the Browser Hash. + +license: MIT-style license. + +requires: [Array, Function, Number, String] + +provides: [Browser, Window, Document] + +... +*/ + +(function(){ + +var document = this.document; +var window = document.window = this; + +var ua = navigator.userAgent.toLowerCase(), + platform = navigator.platform.toLowerCase(), + UA = ua.match(/(opera|ie|firefox|chrome|version)[\s\/:]([\w\d\.]+)?.*?(safari|version[\s\/:]([\w\d\.]+)|$)/) || [null, 'unknown', 0], + mode = UA[1] == 'ie' && document.documentMode; + +var Browser = this.Browser = { + + extend: Function.prototype.extend, + + name: (UA[1] == 'version') ? UA[3] : UA[1], + + version: mode || parseFloat((UA[1] == 'opera' && UA[4]) ? UA[4] : UA[2]), + + Platform: { + name: ua.match(/ip(?:ad|od|hone)/) ? 'ios' : (ua.match(/(?:webos|android)/) || platform.match(/mac|win|linux/) || ['other'])[0] + }, + + Features: { + xpath: !!(document.evaluate), + air: !!(window.runtime), + query: !!(document.querySelector), + json: !!(window.JSON) + }, + + Plugins: {} + +}; + +Browser[Browser.name] = true; +Browser[Browser.name + parseInt(Browser.version, 10)] = true; +Browser.Platform[Browser.Platform.name] = true; + +// Request + +Browser.Request = (function(){ + + var XMLHTTP = function(){ + return new XMLHttpRequest(); + }; + + var MSXML2 = function(){ + return new ActiveXObject('MSXML2.XMLHTTP'); + }; + + var MSXML = function(){ + return new ActiveXObject('Microsoft.XMLHTTP'); + }; + + return Function.attempt(function(){ + XMLHTTP(); + return XMLHTTP; + }, function(){ + MSXML2(); + return MSXML2; + }, function(){ + MSXML(); + return MSXML; + }); + +})(); + +Browser.Features.xhr = !!(Browser.Request); + +// Flash detection + +var version = (Function.attempt(function(){ + return navigator.plugins['Shockwave Flash'].description; +}, function(){ + return new ActiveXObject('ShockwaveFlash.ShockwaveFlash').GetVariable('$version'); +}) || '0 r0').match(/\d+/g); + +Browser.Plugins.Flash = { + version: Number(version[0] || '0.' + version[1]) || 0, + build: Number(version[2]) || 0 +}; + +// String scripts + +Browser.exec = function(text){ + if (!text) return text; + if (window.execScript){ + window.execScript(text); + } else { + var script = document.createElement('script'); + script.setAttribute('type', 'text/javascript'); + script.text = text; + document.head.appendChild(script); + document.head.removeChild(script); + } + return text; +}; + +String.implement('stripScripts', function(exec){ + var scripts = ''; + var text = this.replace(/]*>([\s\S]*?)<\/script>/gi, function(all, code){ + scripts += code + '\n'; + return ''; + }); + if (exec === true) Browser.exec(scripts); + else if (typeOf(exec) == 'function') exec(scripts, text); + return text; +}); + +// Window, Document + +Browser.extend({ + Document: this.Document, + Window: this.Window, + Element: this.Element, + Event: this.Event +}); + +this.Window = this.$constructor = new Type('Window', function(){}); + +this.$family = Function.from('window').hide(); + +Window.mirror(function(name, method){ + window[name] = method; +}); + +this.Document = document.$constructor = new Type('Document', function(){}); + +document.$family = Function.from('document').hide(); + +Document.mirror(function(name, method){ + document[name] = method; +}); + +document.html = document.documentElement; +if (!document.head) document.head = document.getElementsByTagName('head')[0]; + +if (document.execCommand) try { + document.execCommand("BackgroundImageCache", false, true); +} catch (e){} + +/**/ +if (this.attachEvent && !this.addEventListener){ + var unloadEvent = function(){ + this.detachEvent('onunload', unloadEvent); + document.head = document.html = document.window = null; + }; + this.attachEvent('onunload', unloadEvent); +} + +// IE fails on collections and ) +var arrayFrom = Array.from; +try { + arrayFrom(document.html.childNodes); +} catch(e){ + Array.from = function(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; + } + return arrayFrom(item); + }; + + var prototype = Array.prototype, + slice = prototype.slice; + ['pop', 'push', 'reverse', 'shift', 'sort', 'splice', 'unshift', 'concat', 'join', 'slice'].each(function(name){ + var method = prototype[name]; + Array[name] = function(item){ + return method.apply(Array.from(item), slice.call(arguments, 1)); + }; + }); +} +/**/ + +//<1.2compat> + +if (Browser.Platform.ios) Browser.Platform.ipod = true; + +Browser.Engine = {}; + +var setEngine = function(name, version){ + Browser.Engine.name = name; + Browser.Engine[name + version] = true; + Browser.Engine.version = version; +}; + +if (Browser.ie){ + Browser.Engine.trident = true; + + switch (Browser.version){ + case 6: setEngine('trident', 4); break; + case 7: setEngine('trident', 5); break; + case 8: setEngine('trident', 6); + } +} + +if (Browser.firefox){ + Browser.Engine.gecko = true; + + if (Browser.version >= 3) setEngine('gecko', 19); + else setEngine('gecko', 18); +} + +if (Browser.safari || Browser.chrome){ + Browser.Engine.webkit = true; + + switch (Browser.version){ + case 2: setEngine('webkit', 419); break; + case 3: setEngine('webkit', 420); break; + case 4: setEngine('webkit', 525); + } +} + +if (Browser.opera){ + Browser.Engine.presto = true; + + if (Browser.version >= 9.6) setEngine('presto', 960); + else if (Browser.version >= 9.5) setEngine('presto', 950); + else setEngine('presto', 925); +} + +if (Browser.name == 'unknown'){ + switch ((ua.match(/(?:webkit|khtml|gecko)/) || [])[0]){ + case 'webkit': + case 'khtml': + Browser.Engine.webkit = true; + break; + case 'gecko': + Browser.Engine.gecko = true; + } +} + +this.$exec = Browser.exec; + +// + +})(); + + +/* +--- + +name: Event + +description: Contains the Event Type, to make the event object cross-browser. + +license: MIT-style license. + +requires: [Window, Document, Array, Function, String, Object] + +provides: Event + +... +*/ + +(function() { + +var _keys = {}; + +var DOMEvent = this.DOMEvent = new Type('DOMEvent', function(event, win){ + if (!win) win = window; + event = event || win.event; + if (event.$extended) return event; + this.event = event; + this.$extended = true; + 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') == 0){ + var code = this.code = (event.which || event.keyCode); + this.key = _keys[code]/*<1.3compat>*/ || Object.keyOf(Event.Keys, code)/**/; + if (type == 'keydown'){ + if (code > 111 && code < 124) this.key = 'f' + (code - 111); + else if (code > 95 && code < 106) this.key = code - 96; + } + 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; + this.page = { + x: (event.pageX != null) ? event.pageX : event.clientX + doc.scrollLeft, + y: (event.pageY != null) ? event.pageY : event.clientY + doc.scrollTop + }; + this.client = { + x: (event.pageX != null) ? event.pageX - win.pageXOffset : event.clientX, + y: (event.pageY != null) ? event.pageY - win.pageYOffset : event.clientY + }; + 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 (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]; + this.page = {x: touch.pageX, y: touch.pageY}; + this.client = {x: touch.clientX, y: touch.clientY}; + } + } + + if (!this.client) this.client = {}; + if (!this.page) this.page = {}; +}); + +DOMEvent.implement({ + + stop: function(){ + return this.preventDefault().stopPropagation(); + }, + + stopPropagation: function(){ + if (this.event.stopPropagation) this.event.stopPropagation(); + else this.event.cancelBubble = true; + return this; + }, + + preventDefault: function(){ + if (this.event.preventDefault) this.event.preventDefault(); + else this.event.returnValue = false; + return this; + } + +}); + +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' +}); + +})(); + +/*<1.3compat>*/ +var Event = DOMEvent; +Event.Keys = {}; +/**/ + +/*<1.2compat>*/ + +Event.Keys = new Hash(Event.Keys); + +/**/ + + +/* +--- + +name: Class + +description: Contains the Class Function for easily creating, extending, and implementing reusable Classes. + +license: MIT-style license. + +requires: [Array, String, Function, Number] + +provides: Class + +... +*/ + +(function(){ + +var Class = this.Class = new Type('Class', function(params){ + if (instanceOf(params, Function)) params = {initialize: params}; + + var newClass = function(){ + reset(this); + if (newClass.$prototyping) return this; + this.$caller = null; + var value = (this.initialize) ? this.initialize.apply(this, arguments) : this; + this.$caller = this.caller = null; + return value; + }.extend(this).implement(params); + + newClass.$constructor = Class; + newClass.prototype.$constructor = newClass; + newClass.prototype.parent = parent; + + return newClass; +}); + +var parent = function(){ + if (!this.$caller) throw new Error('The method "parent" cannot be called.'); + var name = this.$caller.$name, + parent = this.$caller.$owner.parent, + previous = (parent) ? parent.prototype[name] : null; + if (!previous) throw new Error('The method "' + name + '" has no parent.'); + return previous.apply(this, arguments); +}; + +var reset = function(object){ + for (var key in object){ + var value = object[key]; + switch (typeOf(value)){ + case 'object': + var F = function(){}; + F.prototype = value; + object[key] = reset(new F); + break; + case 'array': object[key] = value.clone(); break; + } + } + return object; +}; + +var wrap = function(self, key, method){ + if (method.$origin) method = method.$origin; + var wrapper = function(){ + 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 = wrapper; + var result = method.apply(this, arguments); + this.$caller = current; this.caller = caller; + return result; + }.extend({$owner: self, $origin: method, $name: key}); + return wrapper; +}; + +var implement = function(key, value, retain){ + if (Class.Mutators.hasOwnProperty(key)){ + value = Class.Mutators[key].call(this, value); + if (value == null) return this; + } + + if (typeOf(value) == 'function'){ + if (value.$hidden) return this; + this.prototype[key] = (retain) ? value : wrap(this, key, value); + } else { + Object.merge(this.prototype, key, value); + } + + return this; +}; + +var getInstance = function(klass){ + klass.$prototyping = true; + var proto = new klass; + delete klass.$prototyping; + return proto; +}; + +Class.implement('implement', implement.overloadSetter()); + +Class.Mutators = { + + Extends: function(parent){ + this.parent = parent; + this.prototype = getInstance(parent); + }, + + Implements: function(items){ + Array.from(items).each(function(item){ + var instance = new item; + for (var key in instance) implement.call(this, key, instance[key], true); + }, this); + } +}; + +})(); + + +/* +--- + +name: Class.Extras + +description: Contains Utility Classes that can be implemented into your own Classes to ease the execution of many common tasks. + +license: MIT-style license. + +requires: Class + +provides: [Class.Extras, Chain, Events, Options] + +... +*/ + +(function(){ + +this.Chain = new Class({ + + $chain: [], + + chain: function(){ + this.$chain.append(Array.flatten(arguments)); + return this; + }, + + callChain: function(){ + return (this.$chain.length) ? this.$chain.shift().apply(this, arguments) : false; + }, + + clearChain: function(){ + this.$chain.empty(); + return this; + } + +}); + +var removeOn = function(string){ + return string.replace(/^on([A-Z])/, function(full, first){ + return first.toLowerCase(); + }); +}; + +this.Events = new Class({ + + $events: {}, + + addEvent: function(type, fn, internal){ + type = removeOn(type); + + /*<1.2compat>*/ + if (fn == $empty) return this; + /**/ + + this.$events[type] = (this.$events[type] || []).include(fn); + if (internal) fn.internal = true; + return this; + }, + + addEvents: function(events){ + for (var type in events) this.addEvent(type, events[type]); + return this; + }, + + fireEvent: function(type, args, delay){ + type = removeOn(type); + var events = this.$events[type]; + if (!events) return this; + args = Array.from(args); + events.each(function(fn){ + if (delay) fn.delay(delay, this, args); + else fn.apply(this, args); + }, this); + return this; + }, + + removeEvent: function(type, fn){ + type = removeOn(type); + var events = this.$events[type]; + if (events && !fn.internal){ + var index = events.indexOf(fn); + if (index != -1) delete events[index]; + } + return this; + }, + + removeEvents: function(events){ + var type; + if (typeOf(events) == 'object'){ + for (type in events) this.removeEvent(type, events[type]); + return this; + } + if (events) events = removeOn(events); + for (type in this.$events){ + if (events && events != type) continue; + var fns = this.$events[type]; + for (var i = fns.length; i--;) if (i in fns){ + this.removeEvent(type, fns[i]); + } + } + return this; + } + +}); + +this.Options = new Class({ + + setOptions: function(){ + var options = this.options = Object.merge.apply(null, [{}, this.options].append(arguments)); + if (this.addEvent) for (var option in options){ + if (typeOf(options[option]) != 'function' || !(/^on[A-Z]/).test(option)) continue; + this.addEvent(option, options[option]); + delete options[option]; + } + return this; + } + +}); + +})(); /* @@ -1579,6 +2045,7 @@ if (!this.Slick) this.Slick = Slick; }).apply(/**/(typeof exports != 'undefined') ? exports : /**/this); + /* --- name: Slick.Finder @@ -1743,7 +2210,7 @@ local.setDocument = function(document){ // native matchesSelector function - features.nativeMatchesSelector = root.matches || /*root.msMatchesSelector ||*/ root.mozMatchesSelector || root.webkitMatchesSelector; + features.nativeMatchesSelector = root.matchesSelector || /*root.msMatchesSelector ||*/ root.mozMatchesSelector || root.webkitMatchesSelector; if (features.nativeMatchesSelector) try { // if matchesSelector trows errors on incorrect sintaxes we can use it features.nativeMatchesSelector.call(root, ':slick'); @@ -1756,7 +2223,7 @@ local.setDocument = function(document){ root.slick_expando = 1; delete root.slick_expando; features.getUID = this.getUIDHTML; - } catch(e){ + } catch(e) { features.getUID = this.getUIDXML; } @@ -1777,9 +2244,9 @@ local.setDocument = function(document){ // hasAttribute - features.hasAttribute = (root && this.isNativeCode(root.hasAttribute)) ? function(node, attribute){ + features.hasAttribute = (root && this.isNativeCode(root.hasAttribute)) ? function(node, attribute) { return node.hasAttribute(attribute); - } : function(node, attribute){ + } : function(node, attribute) { node = node.getAttributeNode(attribute); return !!(node && (node.specified || node.nodeValue)); }; @@ -1861,7 +2328,7 @@ local.search = function(context, expression, append, first){ /**/ var simpleSelector = expression.match(reSimpleSelector); - simpleSelectors: if (simpleSelector){ + simpleSelectors: if (simpleSelector) { var symbol = simpleSelector[1], name = simpleSelector[2], @@ -1914,7 +2381,7 @@ local.search = function(context, expression, append, first){ /**/ /**/ - querySelector: if (context.querySelectorAll){ + querySelector: if (context.querySelectorAll) { if (!this.isHTMLDocument || qsaFailExpCache[expression] @@ -1943,7 +2410,7 @@ local.search = function(context, expression, append, first){ try { if (first) return context.querySelector(_expression) || null; else nodes = context.querySelectorAll(_expression); - } catch(e){ + } catch(e) { qsaFailExpCache[expression] = 1; break querySelector; } finally { @@ -2142,14 +2609,14 @@ local.matchNode = function(node, selector){ if (this.isHTMLDocument && this.nativeMatchesSelector){ try { return this.nativeMatchesSelector.call(node, selector.replace(/\[([^=]+)=\s*([^'"\]]+?)\s*\]/g, '[$1="$2"]')); - } catch(matchError){} + } catch(matchError) {} } var parsed = this.Slick.parse(selector); if (!parsed) return true; // simple (single) selectors - var expressions = parsed.expressions, simpleExpCounter = 0, i, currentExpression; + var expressions = parsed.expressions, simpleExpCounter = 0, i; for (i = 0; (currentExpression = expressions[i]); i++){ if (currentExpression.length == 1){ var exp = currentExpression[0]; @@ -2565,6 +3032,7 @@ if (!this.Slick) this.Slick = Slick; }).apply(/**/(typeof exports != 'undefined') ? exports : /**/this); + /* --- @@ -2576,12 +3044,12 @@ license: MIT-style license. requires: [Window, Document, Array, String, Function, Object, Number, Slick.Parser, Slick.Finder] -provides: [Element, Elements, $, $$, IFrame, Selectors] +provides: [Element, Elements, $, $$, Iframe, Selectors] ... */ -var Element = this.Element = function(tag, props){ +var Element = function(tag, props){ var konstructor = Element.Constructors[tag]; if (konstructor) return konstructor(props); if (typeof tag != 'string') return document.id(tag).set(props); @@ -2650,7 +3118,11 @@ if (!Browser.Element){ Element.Constructors = {}; +//<1.2compat> +Element.Constructors = new Hash; + +// var IFrame = new Type('IFrame', function(){ var params = Array.link(arguments, { @@ -2741,7 +3213,11 @@ new Type('Elements', Elements).implement({ }); +//<1.2compat> +Elements.alias('extend', 'append'); + +// (function(){ @@ -2765,7 +3241,7 @@ Array.mirror(Elements); /**/ var createElementAcceptsHTML; try { - createElementAcceptsHTML = (document.createElement('').name == 'x'); + createElementAcceptsHTML = (document.createElement('').name == 'x'); } catch (e){} var escapeQuotes = function(html){ @@ -2773,44 +3249,20 @@ var escapeQuotes = function(html){ }; /**/ -/**/ -// #2479 - IE8 Cannot set HTML of style element -var canChangeStyleHTML = (function(){ - var div = document.createElement('style'), - flag = false; - try { - div.innerHTML = '#justTesing{margin: 0px;}'; - flag = !!div.innerHTML; - } catch(e){} - return flag; -})(); -/**/ - Document.implement({ newElement: function(tag, props){ - if (props){ - if (props.checked != null) props.defaultChecked = props.checked; - if ((props.type == 'checkbox' || props.type == 'radio') && props.value == null) props.value = 'on'; - /**/ // IE needs the type to be set before changing content of style element - if (!canChangeStyleHTML && tag == 'style'){ - var styleElement = document.createElement('style'); - styleElement.setAttribute('type', 'text/css'); - if (props.type) delete props.type; - return this.id(styleElement).set(props); - } - /**/ - /**/// Fix for readonly name and type properties in IE < 8 - if (createElementAcceptsHTML){ - tag = '<' + tag; - if (props.name) tag += ' name="' + escapeQuotes(props.name) + '"'; - if (props.type) tag += ' type="' + escapeQuotes(props.type) + '"'; - tag += '>'; - delete props.name; - delete props.type; - } - /**/ + if (props && props.checked != null) props.defaultChecked = props.checked; + /**/// Fix for readonly name and type properties in IE < 8 + if (createElementAcceptsHTML && props){ + tag = '<' + tag; + if (props.name) tag += ' name="' + escapeQuotes(props.name) + '"'; + if (props.type) tag += ' type="' + escapeQuotes(props.type) + '"'; + tag += '>'; + delete props.name; + delete props.type; } + /**/ return this.id(this.createElement(tag)).set(props); } @@ -2915,7 +3367,42 @@ var contains = {contains: function(element){ if (!document.contains) Document.implement(contains); if (!document.createElement('div').contains) Element.implement(contains); +//<1.2compat> +Element.implement('hasChild', function(element){ + return this !== element && this.contains(element); +}); + +(function(search, find, match){ + + this.Selectors = {}; + var pseudos = this.Selectors.Pseudo = new Hash(); + + var addSlickPseudos = function(){ + for (var name in pseudos) if (pseudos.hasOwnProperty(name)){ + Slick.definePseudo(name, pseudos[name]); + delete pseudos[name]; + } + }; + + Slick.search = function(context, expression, append){ + addSlickPseudos(); + return search.call(this, context, expression, append); + }; + + Slick.find = function(context, expression){ + addSlickPseudos(); + return find.call(this, context, expression); + }; + + Slick.match = function(node, selector){ + addSlickPseudos(); + return match.call(this, node, selector); + }; + +})(Slick.search, Slick.find, Slick.match); + +// // tree walking @@ -2981,7 +3468,23 @@ Element.implement({ }); +//<1.2compat> +if (window.$$ == null) Window.implement('$$', function(selector){ + var elements = new Elements; + if (arguments.length == 1 && typeof selector == 'string') return Slick.search(this.document, selector, elements); + var args = Array.flatten(arguments); + for (var i = 0, l = args.length; i < l; i++){ + var item = args[i]; + switch (typeOf(item)){ + case 'element': elements.push(item); break; + case 'string': Slick.search(this.document, item, elements); + } + } + return elements; +}); + +// if (window.$$ == null) Window.implement('$$', function(selector){ if (arguments.length == 1){ @@ -3017,7 +3520,29 @@ var inserters = { inserters.inside = inserters.bottom; +//<1.2compat> +Object.each(inserters, function(inserter, where){ + + where = where.capitalize(); + + var methods = {}; + + methods['inject' + where] = function(el){ + inserter(this, document.id(el, true)); + return this; + }; + + methods['grab' + where] = function(el){ + inserter(document.id(el, true), this); + return this; + }; + + Element.implement(methods); + +}); + +// // getProperty / setProperty @@ -3045,21 +3570,6 @@ Object.forEach(properties, function(real, key){ }; }); -/**/ -propertySetters.text = (function(setter){ - return function(node, value){ - if (node.get('tag') == 'style') node.set('html', value); - else node[properties.text] = value; - }; -})(propertySetters.text); - -propertyGetters.text = (function(getter){ - return function(node){ - return (node.get('tag') == 'style') ? node.innerHTML : getter(node); - }; -})(propertyGetters.text); -/**/ - // Booleans var bools = [ @@ -3118,42 +3628,15 @@ el = null; /* */ /**/ - -/**/ -// #2479 - IE8 Cannot set HTML of style element -var canChangeStyleHTML = (function(){ - var div = document.createElement('style'), - flag = false; - try { - div.innerHTML = '#justTesing{margin: 0px;}'; - flag = !!div.innerHTML; - } catch(e){} - return flag; -})(); -/**/ - -var input = document.createElement('input'), volatileInputValue, html5InputSupport; - -// #2178 +var input = document.createElement('input'); input.value = 't'; input.type = 'submit'; -volatileInputValue = input.value != 't'; - -// #2443 - IE throws "Invalid Argument" when trying to use html5 input types -try { - input.type = 'email'; - html5InputSupport = input.type == 'email'; -} catch(e){} - -input = null; - -if (volatileInputValue || !html5InputSupport) propertySetters.type = function(node, type){ - try { - var value = node.value; - node.type = type; - node.value = value; - } catch (e){} +if (input.value != 't') propertySetters.type = function(node, type){ + var value = node.value; + node.type = type; + node.value = value; }; +input = null; /**/ /* getProperty, setProperty */ @@ -3164,28 +3647,7 @@ var pollutesGetAttribute = (function(div){ return (div.getAttribute('random') == 'attribute'); })(document.createElement('div')); -var hasCloneBug = (function(test){ - test.innerHTML = ''; - return test.cloneNode(true).firstChild.childNodes.length != 1; -})(document.createElement('div')); -/* */ - -var hasClassList = !!document.createElement('div').classList; - -var classes = function(className){ - var classNames = (className || '').clean().split(" "), uniques = {}; - return classNames.filter(function(className){ - if (className !== "" && !uniques[className]) return uniques[className] = className; - }); -}; - -var addToClassList = function(name){ - this.classList.add(name); -}; - -var removeFromClassList = function(name){ - this.classList.remove(name); -}; +/* */ Element.implement({ @@ -3195,8 +3657,7 @@ Element.implement({ setter(this, value); } else { /* */ - var attributeWhiteList; - if (pollutesGetAttribute) attributeWhiteList = this.retrieve('$attributeWhiteList', {}); + if (pollutesGetAttribute) var attributeWhiteList = this.retrieve('$attributeWhiteList', {}); /* */ if (value == null){ @@ -3268,27 +3729,17 @@ Element.implement({ return this; }, - hasClass: hasClassList ? function(className){ - return this.classList.contains(className); - } : function(className){ - return classes(this.className).contains(className); + hasClass: function(className){ + return this.className.clean().contains(className, ' '); }, - addClass: hasClassList ? function(className){ - classes(className).forEach(addToClassList, this); - return this; - } : function(className){ - this.className = classes(className + ' ' + this.className).join(' '); + addClass: function(className){ + if (!this.hasClass(className)) this.className = (this.className + ' ' + className).clean(); return this; }, - removeClass: hasClassList ? function(className){ - classes(className).forEach(removeFromClassList, this); - return this; - } : function(className){ - var classNames = classes(this.className); - classes(className).forEach(classNames.erase, classNames); - this.className = classNames.join(' '); + removeClass: function(className){ + this.className = this.className.replace(new RegExp('(^|\\s)' + className + '(?:\\s|$)'), '$1'); return this; }, @@ -3363,37 +3814,6 @@ Element.implement({ }); - -// appendHTML - -var appendInserters = { - before: 'beforeBegin', - after: 'afterEnd', - bottom: 'beforeEnd', - top: 'afterBegin', - inside: 'beforeEnd' -}; - -Element.implement('appendHTML', ('insertAdjacentHTML' in document.createElement('div')) ? function(html, where){ - this.insertAdjacentHTML(appendInserters[where || 'bottom'], html); - return this; -} : function(html, where){ - var temp = new Element('div', {html: html}), - children = temp.childNodes, - fragment = temp.firstChild; - - if (!fragment) return this; - if (children.length > 1){ - fragment = document.createDocumentFragment(); - for (var i = 0, l = children.length; i < l; i++){ - fragment.appendChild(children[i]); - } - } - - inserters[where || 'bottom'](fragment, this); - return this; -}); - var collected = {}, storage = {}; var get = function(uid){ @@ -3459,7 +3879,7 @@ Element.implement({ } /**/ - if (hasCloneBug){ + if (Browser.ie){ var co = clone.getElementsByTagName('object'), to = this.getElementsByTagName('object'); for (i = co.length; i--;) co[i].outerHTML = to[i].outerHTML; } @@ -3472,7 +3892,13 @@ Element.implement({ [Element, Window, Document].invoke('implement', { addListener: function(type, fn){ - if (window.attachEvent && !window.addEventListener){ + if (type == 'unload'){ + var old = fn, self = this; + fn = function(){ + self.removeListener('unload', fn); + old(); + }; + } else { collected[Slick.uidOf(this)] = this; } if (this.addEventListener) this.addEventListener(type, fn, !!arguments[2]); @@ -3507,19 +3933,19 @@ Element.implement({ }); /**/ -if (window.attachEvent && !window.addEventListener){ - var gc = function(){ - Object.each(collected, clean); - if (window.CollectGarbage) CollectGarbage(); - window.removeListener('unload', gc); - } - window.addListener('unload', gc); -} +if (window.attachEvent && !window.addEventListener) window.addListener('unload', function(){ + Object.each(collected, clean); + if (window.CollectGarbage) CollectGarbage(); +}); /**/ Element.Properties = {}; +//<1.2compat> +Element.Properties = new Hash; + +// Element.Properties.style = { @@ -3550,24 +3976,20 @@ Element.Properties.html = { set: function(html){ if (html == null) html = ''; else if (typeOf(html) == 'array') html = html.join(''); - - /**/ - if (this.styleSheet && !canChangeStyleHTML) this.styleSheet.cssText = html; - else /**/this.innerHTML = html; + this.innerHTML = html; }, + erase: function(){ - this.set('html', ''); + this.innerHTML = ''; } }; -var supportsHTML5Elements = true, supportsTableInnerHTML = true, supportsTRInnerHTML = true; - /**/ // technique by jdbarlett - http://jdbartlett.com/innershiv/ var div = document.createElement('div'); div.innerHTML = ''; -supportsHTML5Elements = (div.childNodes.length == 1); +var supportsHTML5Elements = (div.childNodes.length == 1); if (!supportsHTML5Elements){ 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; @@ -3577,7 +3999,7 @@ div = null; /**/ /**/ -supportsTableInnerHTML = Function.attempt(function(){ +var supportsTableInnerHTML = Function.attempt(function(){ var table = document.createElement('table'); table.innerHTML = ''; return true; @@ -3586,7 +4008,7 @@ supportsTableInnerHTML = Function.attempt(function(){ /**/ var tr = document.createElement('tr'), html = ''; tr.innerHTML = html; -supportsTRInnerHTML = (tr.innerHTML == html); +var supportsTRInnerHTML = (tr.innerHTML == html); tr = null; /**/ @@ -3604,10 +4026,6 @@ if (!supportsTableInnerHTML || !supportsTRInnerHTML || !supportsHTML5Elements){ translations.thead = translations.tfoot = translations.tbody; return function(html){ - - /**/ - if (this.styleSheet) return set.call(this, html); - /**/ var wrap = translations[this.get('tag')]; if (!wrap && !supportsHTML5Elements) wrap = [0, '', '']; if (!wrap) return set.call(this, html); @@ -3635,12 +4053,11 @@ if (testForm.firstChild.value != 's') Element.Properties.value = { var tag = this.get('tag'); if (tag != 'select') return this.setProperty('value', value); var options = this.getElements('option'); - value = String(value); 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; + if (optionValue == value) return option.selected = true; } }, @@ -3675,133 +4092,226 @@ if (document.createElement('div').getAttributeNode('id')) Element.Properties.id })(); + /* --- -name: Event +name: Element.Style -description: Contains the Event Type, to make the event object cross-browser. +description: Contains methods for interacting with the styles of Elements in a fashionable way. license: MIT-style license. -requires: [Window, Document, Array, Function, String, Object] +requires: Element -provides: Event +provides: Element.Style ... */ (function(){ -var _keys = {}; -var normalizeWheelSpeed = function(event){ - var normalized; - if (event.wheelDelta){ - normalized = event.wheelDelta % 120 == 0 ? event.wheelDelta / 120 : event.wheelDelta / 12; - } else { - var rawAmount = event.deltaY || event.detail || 0; - normalized = -(rawAmount % 3 == 0 ? rawAmount / 3 : rawAmount * 10); - } - return normalized; -} +var html = document.html; -var DOMEvent = this.DOMEvent = new Type('DOMEvent', function(event, win){ - if (!win) win = window; - event = event || win.event; - if (event.$extended) return event; - this.event = event; - this.$extended = true; - 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); +// +// Check for oldIE, which does not remove styles when they're set to null +var el = document.createElement('div'); +el.style.color = 'red'; +el.style.color = null; +var doesNotRemoveStyles = el.style.color == 'red'; +el = null; +// - if (type.indexOf('key') == 0){ - var code = this.code = (event.which || event.keyCode); - this.key = _keys[code]; - if (type == 'keydown' || type == 'keyup'){ - if (code > 111 && code < 124) this.key = 'f' + (code - 111); - else if (code > 95 && code < 106) this.key = code - 96; - } - if (this.key == null) this.key = String.fromCharCode(code).toLowerCase(); - } else if (type == 'click' || type == 'dblclick' || type == 'contextmenu' || type == 'wheel' || type == 'DOMMouseScroll' || type.indexOf('mouse') == 0){ - var doc = win.document; - doc = (!doc.compatMode || doc.compatMode == 'CSS1Compat') ? doc.html : doc.body; - this.page = { - x: (event.pageX != null) ? event.pageX : event.clientX + doc.scrollLeft, - y: (event.pageY != null) ? event.pageY : event.clientY + doc.scrollTop - }; - this.client = { - x: (event.pageX != null) ? event.pageX - win.pageXOffset : event.clientX, - y: (event.pageY != null) ? event.pageY - win.pageYOffset : event.clientY - }; - if (type == 'DOMMouseScroll' || type == 'wheel' || type == 'mousewheel') this.wheel = normalizeWheelSpeed(event); - 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 (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]; - this.page = {x: touch.pageX, y: touch.pageY}; - this.client = {x: touch.clientX, y: touch.clientY}; - } - } +Element.Properties.styles = {set: function(styles){ + this.setStyles(styles); +}}; - if (!this.client) this.client = {}; - if (!this.page) this.page = {}; -}); +var hasOpacity = (html.style.opacity != null), + hasFilter = (html.style.filter != null), + reAlpha = /alpha\(opacity=([\d.]+)\)/i; -DOMEvent.implement({ - - stop: function(){ - return this.preventDefault().stopPropagation(); - }, - - stopPropagation: function(){ - if (this.event.stopPropagation) this.event.stopPropagation(); - else this.event.cancelBubble = true; - return this; - }, - - preventDefault: function(){ - if (this.event.preventDefault) this.event.preventDefault(); - else this.event.returnValue = false; - return this; - } - -}); - -DOMEvent.defineKey = function(code, key){ - _keys[code] = key; - return this; +var setVisibility = function(element, opacity){ + element.store('$opacity', opacity); + element.style.visibility = opacity > 0 || opacity == null ? 'visible' : 'hidden'; }; -DOMEvent.defineKeys = DOMEvent.defineKey.overloadSetter(true); +var setOpacity = (hasOpacity ? function(element, opacity){ + element.style.opacity = opacity; +} : (hasFilter ? function(element, opacity){ + var style = element.style; + if (!element.currentStyle || !element.currentStyle.hasLayout) style.zoom = 1; + if (opacity == null || opacity == 1) opacity = ''; + else opacity = 'alpha(opacity=' + (opacity * 100).limit(0, 100).round() + ')'; + var filter = style.filter || element.getComputedStyle('filter') || ''; + style.filter = reAlpha.test(filter) ? filter.replace(reAlpha, opacity) : filter + opacity; + if (!style.filter) style.removeAttribute('filter'); +} : setVisibility)); -DOMEvent.defineKeys({ - '38': 'up', '40': 'down', '37': 'left', '39': 'right', - '27': 'esc', '32': 'space', '8': 'backspace', '9': 'tab', - '46': 'delete', '13': 'enter' +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'; + +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; + }, + + setStyle: function(property, value){ + if (property == 'opacity'){ + if (value != null) value = parseFloat(value); + setOpacity(this, value); + return this; + } + property = (property == 'float' ? floatName : property).camelCase(); + if (typeOf(value) != 'string'){ + var map = (Element.Styles[property] || '@').split(' '); + value = Array.from(value).map(function(val, i){ + if (!map[i]) return ''; + return (typeOf(val) == 'number') ? map[i].replace('@', Math.round(val)) : val; + }).join(' '); + } else if (value == String(Number(value))){ + value = Math.round(value); + } + this.style[property] = value; + // + if ((value == '' || value == null) && doesNotRemoveStyles && this.style.removeAttribute){ + this.style.removeAttribute(property); + } + // + return this; + }, + + getStyle: function(property){ + if (property == 'opacity') return getOpacity(this); + property = (property == 'float' ? floatName : property).camelCase(); + var result = this.style[property]; + if (!result || property == 'zIndex'){ + result = []; + for (var style in Element.ShortStyles){ + if (property != style) continue; + for (var s in Element.ShortStyles[style]) result.push(this.getStyle(s)); + return result.join(' '); + } + result = this.getComputedStyle(property); + } + if (result){ + result = String(result); + var color = result.match(/rgba?\([\d\s,]+\)/); + if (color) result = result.replace(color[0], color[0].rgbToHex()); + } + if (Browser.opera || Browser.ie){ + if ((/^(height|width)$/).test(property) && !(/px$/.test(result))){ + var values = (property == 'width') ? ['left', 'right'] : ['top', 'bottom'], size = 0; + values.each(function(value){ + size += this.getStyle('border-' + value + '-width').toInt() + this.getStyle('padding-' + value).toInt(); + }, this); + return this['offset' + property.capitalize()] - size + 'px'; + } + if (Browser.ie && (/^border(.+)Width|margin|padding/).test(property) && isNaN(parseFloat(result))){ + return '0px'; + } + } + return result; + }, + + setStyles: function(styles){ + for (var style in styles) this.setStyle(style, styles[style]); + return this; + }, + + getStyles: function(){ + var result = {}; + Array.flatten(arguments).each(function(key){ + result[key] = this.getStyle(key); + }, this); + return result; + } + +}); + +Element.Styles = { + left: '@px', top: '@px', bottom: '@px', right: '@px', + width: '@px', height: '@px', maxWidth: '@px', maxHeight: '@px', minWidth: '@px', minHeight: '@px', + backgroundColor: 'rgb(@, @, @)', backgroundPosition: '@px @px', color: 'rgb(@, @, @)', + fontSize: '@px', letterSpacing: '@px', lineHeight: '@px', clip: 'rect(@px @px @px @px)', + margin: '@px @px @px @px', padding: '@px @px @px @px', border: '@px @ rgb(@, @, @) @px @ rgb(@, @, @) @px @ rgb(@, @, @)', + borderWidth: '@px @px @px @px', borderStyle: '@ @ @ @', borderColor: 'rgb(@, @, @) rgb(@, @, @) rgb(@, @, @) rgb(@, @, @)', + zIndex: '@', 'zoom': '@', fontWeight: '@', textIndent: '@px', opacity: '@' +}; + +//<1.3compat> + +Element.implement({ + + setOpacity: function(value){ + setOpacity(this, value); + return this; + }, + + getOpacity: function(){ + return getOpacity(this); + } + +}); + +Element.Properties.opacity = { + + set: function(opacity){ + setOpacity(this, opacity); + setVisibility(this, opacity); + }, + + get: function(){ + return getOpacity(this); + } + +}; + +// + +//<1.2compat> + +Element.Styles = new Hash(Element.Styles); + +// + +Element.ShortStyles = {margin: {}, padding: {}, border: {}, borderWidth: {}, borderStyle: {}, borderColor: {}}; + +['Top', 'Right', 'Bottom', 'Left'].each(function(direction){ + var Short = Element.ShortStyles; + var All = Element.Styles; + ['margin', 'padding'].each(function(style){ + var sd = style + direction; + Short[style][sd] = All[sd] = '@px'; + }); + var bd = 'border' + direction; + Short.border[bd] = All[bd] = '@px @ rgb(@, @, @)'; + var bdw = bd + 'Width', bds = bd + 'Style', bdc = bd + 'Color'; + Short[bd] = {}; + Short.borderWidth[bdw] = Short[bd][bdw] = All[bdw] = '@px'; + Short.borderStyle[bds] = Short[bd][bds] = All[bds] = '@'; + Short.borderColor[bdc] = Short[bd][bdc] = All[bdc] = 'rgb(@, @, @)'; }); })(); - - - /* --- @@ -3934,7 +4444,7 @@ Element.Properties.events = {set: function(events){ Element.NativeEvents = { click: 2, dblclick: 2, mouseup: 2, mousedown: 2, contextmenu: 2, //mouse buttons - wheel: 2, mousewheel: 2, DOMMouseScroll: 2, //mouse wheel + mousewheel: 2, DOMMouseScroll: 2, //mouse wheel mouseover: 2, mouseout: 2, mousemove: 2, selectstart: 2, selectend: 2, //mouse movement keydown: 2, keypress: 2, keyup: 2, //keyboard orientationchange: 2, // mobile @@ -3942,27 +4452,23 @@ Element.NativeEvents = { gesturestart: 2, gesturechange: 2, gestureend: 2, // gesture 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 - hashchange: 1, popstate: 2, // history - error: 1, abort: 1, scroll: 1, message: 2 //misc + error: 1, abort: 1, scroll: 1 //misc }; -Element.Events = { - mousewheel: { - base: 'onwheel' in document ? 'wheel' : 'onmousewheel' in document ? 'mousewheel' : 'DOMMouseScroll' - } -}; - -var check = function(event){ - var related = event.relatedTarget; - if (related == null) return true; - if (!related) return false; - return (related != this && related.prefix != 'xul' && typeOf(this) != 'document' && !this.contains(related)); -}; +Element.Events = {mousewheel: { + base: (Browser.firefox) ? 'DOMMouseScroll' : 'mousewheel' +}}; if ('onmouseenter' in document.documentElement){ Element.NativeEvents.mouseenter = Element.NativeEvents.mouseleave = 2; - Element.MouseenterCheck = check; } else { + var check = function(event){ + var related = event.relatedTarget; + if (related == null) return true; + if (!related) return false; + return (related != this && related.prefix != 'xul' && typeOf(this) != 'document' && !this.contains(related)); + }; + Element.Events.mouseenter = { base: 'mouseover', condition: check @@ -3980,19 +4486,24 @@ if (!window.addEventListener){ Element.Events.change = { base: function(){ var type = this.type; - return (this.get('tag') == 'input' && (type == 'radio' || type == 'checkbox')) ? 'propertychange' : 'change'; + return (this.get('tag') == 'input' && (type == 'radio' || type == 'checkbox')) ? 'propertychange' : 'change' }, condition: function(event){ - return event.type != 'propertychange' || event.event.propertyName == 'checked'; + return this.type != 'radio' || (event.event.propertyName == 'checked' && this.checked); } - }; + } } /**/ +//<1.2compat> +Element.Events = new Hash(Element.Events); + +// })(); + /* --- @@ -4024,12 +4535,10 @@ var bubbleUp = function(self, match, fn, event, target){ var map = { mouseenter: { - base: 'mouseover', - condition: Element.MouseenterCheck + base: 'mouseover' }, mouseleave: { - base: 'mouseout', - condition: Element.MouseenterCheck + base: 'mouseout' }, focus: { base: 'focus' + (eventListenerSupport ? '' : 'in'), @@ -4052,10 +4561,7 @@ var formObserver = function(type){ remove: function(self, uid){ var list = self.retrieve(_key + type + 'listeners', {})[uid]; if (list && list.forms) for (var i = list.forms.length; i--;){ - // the form may have been destroyed, so it won't have the - // removeEvent method anymore. In that case the event was - // removed as well. - if (list.forms[i].removeEvent) list.forms[i].removeEvent(type, list.fns[i]); + list.forms[i].removeEvent(type, list.fns[i]); } }, @@ -4139,8 +4645,8 @@ var delegation = { }; var elementEvent = Element.Events[_type]; - if (_map.condition || elementEvent && elementEvent.condition){ - var __match = match, condition = _map.condition || elementEvent.condition; + if (elementEvent && elementEvent.condition){ + var __match = match, condition = elementEvent.condition; match = function(target, event){ return __match(target, event) && condition.call(target, event, type); }; @@ -4175,7 +4681,7 @@ var delegation = { if (_map.remove) _map.remove(this, _uid); delete stored[_uid]; storage[_type] = stored; - return removeEvent.call(this, type, delegator, _map.capture); + return removeEvent.call(this, type, delegator); } var __uid, s; @@ -4198,237 +4704,6 @@ var delegation = { })(); -/* ---- - -name: Element.Style - -description: Contains methods for interacting with the styles of Elements in a fashionable way. - -license: MIT-style license. - -requires: Element - -provides: Element.Style - -... -*/ - -(function(){ - -var html = document.html, el; - -// -// Check for oldIE, which does not remove styles when they're set to null -el = document.createElement('div'); -el.style.color = 'red'; -el.style.color = null; -var doesNotRemoveStyles = el.style.color == 'red'; - -// check for oldIE, which returns border* shorthand styles in the wrong order (color-width-style instead of width-style-color) -var border = '1px solid #123abc'; -el.style.border = border; -var returnsBordersInWrongOrder = el.style.border != border; -el = null; -// - -var hasGetComputedStyle = !!window.getComputedStyle, - supportBorderRadius = document.createElement('div').style.borderRadius != null; - -Element.Properties.styles = {set: function(styles){ - this.setStyles(styles); -}}; - -var hasOpacity = (html.style.opacity != null), - hasFilter = (html.style.filter != null), - reAlpha = /alpha\(opacity=([\d.]+)\)/i; - -var setVisibility = function(element, opacity){ - element.store('$opacity', opacity); - element.style.visibility = opacity > 0 || opacity == null ? 'visible' : 'hidden'; -}; - -// -var setFilter = function(element, regexp, value){ - var style = element.style, - filter = style.filter || element.getComputedStyle('filter') || ''; - style.filter = (regexp.test(filter) ? filter.replace(regexp, value) : filter + ' ' + value).trim(); - if (!style.filter) style.removeAttribute('filter'); -}; -// - -var setOpacity = (hasOpacity ? function(element, opacity){ - element.style.opacity = opacity; -} : (hasFilter ? function(element, opacity){ - if (!element.currentStyle || !element.currentStyle.hasLayout) element.style.zoom = 1; - if (opacity == null || opacity == 1){ - setFilter(element, reAlpha, ''); - if (opacity == 1 && getOpacity(element) != 1) setFilter(element, reAlpha, 'alpha(opacity=100)'); - } else { - setFilter(element, reAlpha, 'alpha(opacity=' + (opacity * 100).limit(0, 100).round() + ')'); - } -} : 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', - namedPositions = {left: '0%', top: '0%', center: '50%', right: '100%', bottom: '100%'}, - hasBackgroundPositionXY = (html.style.backgroundPositionX != null); - -// -var removeStyle = function(style, property){ - if (property == 'backgroundPosition'){ - style.removeAttribute(property + 'X'); - property += 'Y'; - } - style.removeAttribute(property); -}; -// - -Element.implement({ - - getComputedStyle: function(property){ - if (!hasGetComputedStyle && 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()) : ''; - }, - - setStyle: function(property, value){ - if (property == 'opacity'){ - if (value != null) value = parseFloat(value); - setOpacity(this, value); - return this; - } - property = (property == 'float' ? floatName : property).camelCase(); - if (typeOf(value) != 'string'){ - var map = (Element.Styles[property] || '@').split(' '); - value = Array.from(value).map(function(val, i){ - if (!map[i]) return ''; - return (typeOf(val) == 'number') ? map[i].replace('@', Math.round(val)) : val; - }).join(' '); - } else if (value == String(Number(value))){ - value = Math.round(value); - } - this.style[property] = value; - // - if ((value == '' || value == null) && doesNotRemoveStyles && this.style.removeAttribute){ - removeStyle(this.style, property); - } - // - return this; - }, - - getStyle: function(property){ - if (property == 'opacity') return getOpacity(this); - property = (property == 'float' ? floatName : property).camelCase(); - if (supportBorderRadius && property.indexOf('borderRadius') != -1){ - return ['borderTopLeftRadius', 'borderTopRightRadius', 'borderBottomRightRadius', 'borderBottomLeftRadius'].map(function(corner){ - return this.style[corner] || '0px'; - }, this).join(' '); - } - var result = this.style[property]; - if (!result || property == 'zIndex'){ - if (Element.ShortStyles.hasOwnProperty(property)){ - result = []; - for (var s in Element.ShortStyles[property]) result.push(this.getStyle(s)); - return result.join(' '); - } - result = this.getComputedStyle(property); - } - if (hasBackgroundPositionXY && /^backgroundPosition[XY]?$/.test(property)){ - return result.replace(/(top|right|bottom|left)/g, function(position){ - return namedPositions[position]; - }) || '0px'; - } - if (!result && property == 'backgroundPosition') return '0px 0px'; - if (result){ - result = String(result); - var color = result.match(/rgba?\([\d\s,]+\)/); - if (color) result = result.replace(color[0], color[0].rgbToHex()); - } - if (!hasGetComputedStyle && !this.style[property]){ - if ((/^(height|width)$/).test(property) && !(/px$/.test(result))){ - var values = (property == 'width') ? ['left', 'right'] : ['top', 'bottom'], size = 0; - values.each(function(value){ - size += this.getStyle('border-' + value + '-width').toInt() + this.getStyle('padding-' + value).toInt(); - }, this); - return this['offset' + property.capitalize()] - size + 'px'; - } - if ((/^border(.+)Width|margin|padding/).test(property) && isNaN(parseFloat(result))){ - return '0px'; - } - } - // - if (returnsBordersInWrongOrder && /^border(Top|Right|Bottom|Left)?$/.test(property) && /^#/.test(result)){ - return result.replace(/^(.+)\s(.+)\s(.+)$/, '$2 $3 $1'); - } - // - - return result; - }, - - setStyles: function(styles){ - for (var style in styles) this.setStyle(style, styles[style]); - return this; - }, - - getStyles: function(){ - var result = {}; - Array.flatten(arguments).each(function(key){ - result[key] = this.getStyle(key); - }, this); - return result; - } - -}); - -Element.Styles = { - left: '@px', top: '@px', bottom: '@px', right: '@px', - width: '@px', height: '@px', maxWidth: '@px', maxHeight: '@px', minWidth: '@px', minHeight: '@px', - backgroundColor: 'rgb(@, @, @)', backgroundSize: '@px', backgroundPosition: '@px @px', color: 'rgb(@, @, @)', - fontSize: '@px', letterSpacing: '@px', lineHeight: '@px', clip: 'rect(@px @px @px @px)', - margin: '@px @px @px @px', padding: '@px @px @px @px', border: '@px @ rgb(@, @, @) @px @ rgb(@, @, @) @px @ rgb(@, @, @)', - borderWidth: '@px @px @px @px', borderStyle: '@ @ @ @', borderColor: 'rgb(@, @, @) rgb(@, @, @) rgb(@, @, @) rgb(@, @, @)', - zIndex: '@', 'zoom': '@', fontWeight: '@', textIndent: '@px', opacity: '@', borderRadius: '@px @px @px @px' -}; - - - - - -Element.ShortStyles = {margin: {}, padding: {}, border: {}, borderWidth: {}, borderStyle: {}, borderColor: {}}; - -['Top', 'Right', 'Bottom', 'Left'].each(function(direction){ - var Short = Element.ShortStyles; - var All = Element.Styles; - ['margin', 'padding'].each(function(style){ - var sd = style + direction; - Short[style][sd] = All[sd] = '@px'; - }); - var bd = 'border' + direction; - Short.border[bd] = All[bd] = '@px @ rgb(@, @, @)'; - var bdw = bd + 'Width', bds = bd + 'Style', bdc = bd + 'Color'; - Short[bd] = {}; - Short.borderWidth[bdw] = Short[bd][bdw] = All[bdw] = '@px'; - Short.borderStyle[bds] = Short[bd][bds] = All[bds] = '@'; - Short.borderColor[bdc] = Short[bd][bdc] = All[bdc] = 'rgb(@, @, @)'; -}); - -if (hasBackgroundPositionXY) Element.ShortStyles.backgroundPosition = {backgroundPositionX: '@', backgroundPositionY: '@'}; -})(); /* --- @@ -4459,23 +4734,6 @@ element.appendChild(child); var brokenOffsetParent = (child.offsetParent === element); element = child = null; -var heightComponents = ['height', 'paddingTop', 'paddingBottom', 'borderTopWidth', 'borderBottomWidth'], - widthComponents = ['width', 'paddingLeft', 'paddingRight', 'borderLeftWidth', 'borderRightWidth']; - -var svgCalculateSize = function(el){ - - var gCS = window.getComputedStyle(el), - bounds = {x: 0, y: 0}; - - heightComponents.each(function(css){ - bounds.y += parseFloat(gCS[css]); - }); - widthComponents.each(function(css){ - bounds.x += parseFloat(gCS[css]); - }); - return bounds; -}; - var isOffset = function(el){ return styleString(el, 'position') != 'static' || isBody(el); }; @@ -4498,18 +4756,7 @@ Element.implement({ getSize: function(){ if (isBody(this)) return this.getWindow().getSize(); - - // - // This if clause is because IE8- cannot calculate getBoundingClientRect of elements with visibility hidden. - if (!window.getComputedStyle) return {x: this.offsetWidth, y: this.offsetHeight}; - // - - // This svg section under, calling `svgCalculateSize()`, can be removed when FF fixed the svg size bug. - // Bug info: https://bugzilla.mozilla.org/show_bug.cgi?id=530985 - if (this.get('tag') == 'svg') return svgCalculateSize(this); - - var bounds = this.getBoundingClientRect(); - return {x: bounds.width, y: bounds.height}; + return {x: this.offsetWidth, y: this.offsetHeight}; }, getScrollSize: function(){ @@ -4547,14 +4794,12 @@ Element.implement({ try { return element.offsetParent; - } catch(e){} + } catch(e) {} return null; }, getOffsets: function(){ - var hasGetBoundingClientRect = this.getBoundingClientRect; - - if (hasGetBoundingClientRect){ + if (this.getBoundingClientRect && !Browser.Platform.ios){ var bound = this.getBoundingClientRect(), html = document.id(this.getDocument().documentElement), htmlScroll = html.getScroll(), @@ -4563,7 +4808,7 @@ Element.implement({ return { x: bound.left.toInt() + elemScrolls.x + ((isFixed) ? 0 : htmlScroll.x) - html.clientLeft, - y: bound.top.toInt() + elemScrolls.y + ((isFixed) ? 0 : htmlScroll.y) - html.clientTop + y: bound.top.toInt() + elemScrolls.y + ((isFixed) ? 0 : htmlScroll.y) - html.clientTop }; } @@ -4574,9 +4819,27 @@ Element.implement({ position.x += element.offsetLeft; position.y += element.offsetTop; + if (Browser.firefox){ + if (!borderBox(element)){ + position.x += leftBorder(element); + position.y += topBorder(element); + } + var parent = element.parentNode; + if (parent && styleString(parent, 'overflow') != 'visible'){ + position.x += leftBorder(parent); + position.y += topBorder(parent); + } + } else if (element != this && Browser.safari){ + position.x += leftBorder(element); + position.y += topBorder(element); + } + element = element.offsetParent; } - + if (Browser.firefox && !borderBox(this)){ + position.x -= leftBorder(this); + position.y -= topBorder(this); + } return position; }, @@ -4725,6 +4988,7 @@ Element.alias({position: 'setPosition'}); //compatability }); + /* --- @@ -4857,17 +5121,13 @@ var Fx = this.Fx = new Class({ }, resume: function(){ - if (this.isPaused()) pushInstance.call(this, this.options.fps); + if ((this.frame < this.frames) && !this.isRunning()) pushInstance.call(this, this.options.fps); return this; }, isRunning: function(){ var list = instances[this.options.fps]; return list && list.contains(this); - }, - - isPaused: function(){ - return (this.frame < this.frames) && !this.isRunning(); } }); @@ -4909,6 +5169,7 @@ var pullInstance = function(fps){ })(); + /* --- @@ -4939,7 +5200,7 @@ Fx.CSS = new Class({ from = element.getStyle(property); var unit = this.options.unit; // adapted from: https://github.com/ryanmorr/fx/blob/master/fx.js#L299 - if (unit && from && typeof from == 'string' && from.slice(-unit.length) != unit && parseFloat(from) != 0){ + if (unit && from.slice(-unit.length) != unit && parseFloat(from) != 0){ element.setStyle(property, to + unit); var value = element.getComputedStyle(property); // IE and Opera support pixelLeft or pixelWidth @@ -5011,13 +5272,11 @@ Fx.CSS = new Class({ search: function(selector){ if (Fx.CSS.Cache[selector]) return Fx.CSS.Cache[selector]; var to = {}, selectorTest = new RegExp('^' + selector.escapeRegExp() + '$'); - - var searchStyles = function(rules){ + Array.each(document.styleSheets, function(sheet, j){ + var href = sheet.href; + if (href && href.contains('://') && !href.contains(document.domain)) return; + var rules = sheet.rules || sheet.cssRules; Array.each(rules, function(rule, i){ - if (rule.media){ - searchStyles(rule.rules || rule.cssRules); - return; - } if (!rule.style) return; var selectorText = (rule.selectorText) ? rule.selectorText.replace(/^\w+/, function(m){ return m.toLowerCase(); @@ -5029,13 +5288,6 @@ Fx.CSS = new Class({ to[style] = ((/^rgb/).test(value)) ? value.rgbToHex() : value; }); }); - }; - - Array.each(document.styleSheets, function(sheet, j){ - var href = sheet.href; - if (href && href.indexOf('://') > -1 && href.indexOf(document.domain) == -1) return; - var rules = sheet.rules || sheet.cssRules; - searchStyles(rules); }); return Fx.CSS.Cache[selector] = to; } @@ -5081,195 +5333,12 @@ Fx.CSS.Parsers = { }; +//<1.2compat> +Fx.CSS.Parsers = new Hash(Fx.CSS.Parsers); -/* ---- +// -name: Fx.Morph - -description: Formerly Fx.Styles, effect to transition any number of CSS properties for an element using an object of rules, or CSS based selector rules. - -license: MIT-style license. - -requires: Fx.CSS - -provides: Fx.Morph - -... -*/ - -Fx.Morph = new Class({ - - Extends: Fx.CSS, - - initialize: function(element, options){ - this.element = this.subject = document.id(element); - this.parent(options); - }, - - set: function(now){ - if (typeof now == 'string') now = this.search(now); - for (var p in now) this.render(this.element, p, now[p], this.options.unit); - return this; - }, - - compute: function(from, to, delta){ - var now = {}; - for (var p in from) now[p] = this.parent(from[p], to[p], delta); - return now; - }, - - start: function(properties){ - if (!this.check(properties)) return this; - if (typeof properties == 'string') properties = this.search(properties); - var from = {}, to = {}; - for (var p in properties){ - var parsed = this.prepare(this.element, p, properties[p]); - from[p] = parsed.from; - to[p] = parsed.to; - } - return this.parent(from, to); - } - -}); - -Element.Properties.morph = { - - set: function(options){ - this.get('morph').cancel().setOptions(options); - return this; - }, - - get: function(){ - var morph = this.retrieve('morph'); - if (!morph){ - morph = new Fx.Morph(this, {link: 'cancel'}); - this.store('morph', morph); - } - return morph; - } - -}; - -Element.implement({ - - morph: function(props){ - this.get('morph').start(props); - return this; - } - -}); - -/* ---- - -name: Fx.Transitions - -description: Contains a set of advanced transitions to be used with any of the Fx Classes. - -license: MIT-style license. - -credits: - - Easing Equations by Robert Penner, , modified and optimized to be used with MooTools. - -requires: Fx - -provides: Fx.Transitions - -... -*/ - -Fx.implement({ - - getTransition: function(){ - var trans = this.options.transition || Fx.Transitions.Sine.easeInOut; - if (typeof trans == 'string'){ - var data = trans.split(':'); - trans = Fx.Transitions; - trans = trans[data[0]] || trans[data[0].capitalize()]; - if (data[1]) trans = trans['ease' + data[1].capitalize() + (data[2] ? data[2].capitalize() : '')]; - } - return trans; - } - -}); - -Fx.Transition = function(transition, params){ - params = Array.from(params); - var easeIn = function(pos){ - return transition(pos, params); - }; - return Object.append(easeIn, { - easeIn: easeIn, - easeOut: function(pos){ - return 1 - transition(1 - pos, params); - }, - easeInOut: function(pos){ - return (pos <= 0.5 ? transition(2 * pos, params) : (2 - transition(2 * (1 - pos), params))) / 2; - } - }); -}; - -Fx.Transitions = { - - linear: function(zero){ - return zero; - } - -}; - - - -Fx.Transitions.extend = function(transitions){ - for (var transition in transitions) Fx.Transitions[transition] = new Fx.Transition(transitions[transition]); -}; - -Fx.Transitions.extend({ - - Pow: function(p, x){ - return Math.pow(p, x && x[0] || 6); - }, - - Expo: function(p){ - return Math.pow(2, 8 * (p - 1)); - }, - - Circ: function(p){ - return 1 - Math.sin(Math.acos(p)); - }, - - Sine: function(p){ - return 1 - Math.cos(p * Math.PI / 2); - }, - - Back: function(p, x){ - x = x && x[0] || 1.618; - return Math.pow(p, 2) * ((x + 1) * p - x); - }, - - Bounce: function(p){ - var value; - for (var a = 0, b = 1; 1; a += b, b /= 2){ - if (p >= (7 - 4 * a) / 11){ - value = b * b - Math.pow((11 - 6 * a - 11 * p) / 4, 2); - break; - } - } - return value; - }, - - Elastic: function(p, x){ - return Math.pow(2, 10 * --p) * Math.cos(20 * p * Math.PI * (x && x[0] || 1) / 3); - } - -}); - -['Quad', 'Cubic', 'Quart', 'Quint'].each(function(transition, i){ - Fx.Transitions[transition] = new Fx.Transition(function(p){ - return Math.pow(p, i + 2); - }); -}); /* --- @@ -5383,6 +5452,201 @@ Element.implement({ }); + +/* +--- + +name: Fx.Morph + +description: Formerly Fx.Styles, effect to transition any number of CSS properties for an element using an object of rules, or CSS based selector rules. + +license: MIT-style license. + +requires: Fx.CSS + +provides: Fx.Morph + +... +*/ + +Fx.Morph = new Class({ + + Extends: Fx.CSS, + + initialize: function(element, options){ + this.element = this.subject = document.id(element); + this.parent(options); + }, + + set: function(now){ + if (typeof now == 'string') now = this.search(now); + for (var p in now) this.render(this.element, p, now[p], this.options.unit); + return this; + }, + + compute: function(from, to, delta){ + var now = {}; + for (var p in from) now[p] = this.parent(from[p], to[p], delta); + return now; + }, + + start: function(properties){ + if (!this.check(properties)) return this; + if (typeof properties == 'string') properties = this.search(properties); + var from = {}, to = {}; + for (var p in properties){ + var parsed = this.prepare(this.element, p, properties[p]); + from[p] = parsed.from; + to[p] = parsed.to; + } + return this.parent(from, to); + } + +}); + +Element.Properties.morph = { + + set: function(options){ + this.get('morph').cancel().setOptions(options); + return this; + }, + + get: function(){ + var morph = this.retrieve('morph'); + if (!morph){ + morph = new Fx.Morph(this, {link: 'cancel'}); + this.store('morph', morph); + } + return morph; + } + +}; + +Element.implement({ + + morph: function(props){ + this.get('morph').start(props); + return this; + } + +}); + + +/* +--- + +name: Fx.Transitions + +description: Contains a set of advanced transitions to be used with any of the Fx Classes. + +license: MIT-style license. + +credits: + - Easing Equations by Robert Penner, , modified and optimized to be used with MooTools. + +requires: Fx + +provides: Fx.Transitions + +... +*/ + +Fx.implement({ + + getTransition: function(){ + var trans = this.options.transition || Fx.Transitions.Sine.easeInOut; + if (typeof trans == 'string'){ + var data = trans.split(':'); + trans = Fx.Transitions; + trans = trans[data[0]] || trans[data[0].capitalize()]; + if (data[1]) trans = trans['ease' + data[1].capitalize() + (data[2] ? data[2].capitalize() : '')]; + } + return trans; + } + +}); + +Fx.Transition = function(transition, params){ + params = Array.from(params); + var easeIn = function(pos){ + return transition(pos, params); + }; + return Object.append(easeIn, { + easeIn: easeIn, + easeOut: function(pos){ + return 1 - transition(1 - pos, params); + }, + easeInOut: function(pos){ + return (pos <= 0.5 ? transition(2 * pos, params) : (2 - transition(2 * (1 - pos), params))) / 2; + } + }); +}; + +Fx.Transitions = { + + linear: function(zero){ + return zero; + } + +}; + +//<1.2compat> + +Fx.Transitions = new Hash(Fx.Transitions); + +// + +Fx.Transitions.extend = function(transitions){ + for (var transition in transitions) Fx.Transitions[transition] = new Fx.Transition(transitions[transition]); +}; + +Fx.Transitions.extend({ + + Pow: function(p, x){ + return Math.pow(p, x && x[0] || 6); + }, + + Expo: function(p){ + return Math.pow(2, 8 * (p - 1)); + }, + + Circ: function(p){ + return 1 - Math.sin(Math.acos(p)); + }, + + Sine: function(p){ + return 1 - Math.cos(p * Math.PI / 2); + }, + + Back: function(p, x){ + x = x && x[0] || 1.618; + return Math.pow(p, 2) * ((x + 1) * p - x); + }, + + Bounce: function(p){ + var value; + for (var a = 0, b = 1; 1; a += b, b /= 2){ + if (p >= (7 - 4 * a) / 11){ + value = b * b - Math.pow((11 - 6 * a - 11 * p) / 4, 2); + break; + } + } + return value; + }, + + Elastic: function(p, x){ + return Math.pow(2, 10 * --p) * Math.cos(20 * p * Math.PI * (x && x[0] || 1) / 3); + } + +}); + +['Quad', 'Cubic', 'Quart', 'Quint'].each(function(transition, i){ + Fx.Transitions[transition] = new Fx.Transition(function(p){ + return Math.pow(p, i + 2); + }); +}); + + /* --- @@ -5419,8 +5683,7 @@ var Request = this.Request = new Class({ onException: function(headerName, value){}, onTimeout: function(){}, user: '', - password: '', - withCredentials: false,*/ + password: '',*/ url: '', data: '', headers: { @@ -5458,10 +5721,7 @@ var Request = this.Request = new Class({ }.bind(this)); xhr.onreadystatechange = empty; if (progressSupport) xhr.onprogress = xhr.onloadstart = empty; - if (this.timer){ - clearTimeout(this.timer); - delete this.timer; - } + clearTimeout(this.timer); this.response = {text: this.xhr.responseText || '', xml: this.xhr.responseXML}; if (this.options.isSuccess.call(this, this.status)) @@ -5572,10 +5832,10 @@ var Request = this.Request = new Class({ if (trimPosition > -1 && (trimPosition = url.indexOf('#')) > -1) url = url.substr(0, trimPosition); if (this.options.noCache) - url += (url.indexOf('?') > -1 ? '&' : '?') + String.uniqueID(); + url += (url.contains('?') ? '&' : '?') + String.uniqueID(); - if (data && (method == 'get' || method == 'delete')){ - url += (url.indexOf('?') > -1 ? '&' : '?') + data; + if (data && method == 'get'){ + url += (url.contains('?') ? '&' : '?') + data; data = null; } @@ -5586,7 +5846,7 @@ var Request = this.Request = new Class({ } xhr.open(method.toUpperCase(), url, this.options.async, this.options.user, this.options.password); - if ((this.options.withCredentials) && 'withCredentials' in xhr) xhr.withCredentials = true; + if (this.options.user && 'withCredentials' in xhr) xhr.withCredentials = true; xhr.onreadystatechange = this.onStateChange.bind(this); @@ -5610,10 +5870,7 @@ var Request = this.Request = new Class({ this.running = false; var xhr = this.xhr; xhr.abort(); - if (this.timer){ - clearTimeout(this.timer); - delete this.timer; - } + clearTimeout(this.timer); xhr.onreadystatechange = empty; if (progressSupport) xhr.onprogress = xhr.onloadstart = empty; this.xhr = new Browser.Request(); @@ -5624,7 +5881,7 @@ var Request = this.Request = new Class({ }); var methods = {}; -['get', 'post', 'put', 'delete', 'patch', 'head', 'GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'HEAD'].each(function(method){ +['get', 'post', 'put', 'delete', 'GET', 'POST', 'PUT', 'DELETE'].each(function(method){ methods[method] = function(data){ var object = { method: method @@ -5669,6 +5926,7 @@ Element.implement({ })(); + /* --- @@ -5758,6 +6016,7 @@ Element.implement({ }); + /* --- @@ -5778,7 +6037,14 @@ provides: JSON if (typeof JSON == 'undefined') this.JSON = {}; +//<1.2compat> +JSON = new Hash({ + stringify: JSON.stringify, + parse: JSON.parse +}); + +// (function(){ @@ -5820,14 +6086,10 @@ JSON.encode = JSON.stringify ? function(obj){ return null; }; -JSON.secure = true; - - JSON.decode = function(string, secure){ if (!string || typeOf(string) != 'string') return null; - - if (secure == null) secure = JSON.secure; - if (secure){ + + if (secure || JSON.secure){ if (JSON.parse) return JSON.parse(string); if (!JSON.validate(string)) throw new Error('JSON could not decode the input; security is enabled and the value is not secure.'); } @@ -5837,6 +6099,7 @@ JSON.decode = function(string, secure){ })(); + /* --- @@ -5884,6 +6147,7 @@ Request.JSON = new Class({ }); + /* --- @@ -5959,6 +6223,7 @@ Cookie.dispose = function(key, options){ return new Cookie(key, options).dispose(); }; + /* --- @@ -5986,14 +6251,12 @@ var ready, var domready = function(){ clearTimeout(timer); - if (!ready) { - Browser.loaded = ready = true; - document.removeListener('DOMContentLoaded', domready).removeListener('readystatechange', check); - document.fireEvent('domready'); - window.fireEvent('domready'); - } - // cleanup scope vars - document = window = testElement = null; + if (ready) return; + Browser.loaded = ready = true; + document.removeListener('DOMContentLoaded', domready).removeListener('readystatechange', check); + + document.fireEvent('domready'); + window.fireEvent('domready'); }; var check = function(){ @@ -6066,3 +6329,119 @@ window.addEvent('load', function(){ }); })(window, document); + + +/* +--- + +name: Swiff + +description: Wrapper for embedding SWF movies. Supports External Interface Communication. + +license: MIT-style license. + +credits: + - Flash detection & Internet Explorer + Flash Player 9 fix inspired by SWFObject. + +requires: [Options, Object, Element] + +provides: Swiff + +... +*/ + +(function(){ + +var Swiff = this.Swiff = new Class({ + + Implements: Options, + + options: { + id: null, + height: 1, + width: 1, + container: null, + properties: {}, + params: { + quality: 'high', + allowScriptAccess: 'always', + wMode: 'window', + swLiveConnect: true + }, + callBacks: {}, + vars: {} + }, + + toElement: function(){ + return this.object; + }, + + initialize: function(path, options){ + this.instance = 'Swiff_' + String.uniqueID(); + + this.setOptions(options); + options = this.options; + var id = this.id = options.id || this.instance; + var container = document.id(options.container); + + Swiff.CallBacks[this.instance] = {}; + + var params = options.params, vars = options.vars, callBacks = options.callBacks; + var properties = Object.append({height: options.height, width: options.width}, options.properties); + + var self = this; + + for (var callBack in callBacks){ + Swiff.CallBacks[this.instance][callBack] = (function(option){ + return function(){ + return option.apply(self.object, arguments); + }; + })(callBacks[callBack]); + vars[callBack] = 'Swiff.CallBacks.' + this.instance + '.' + callBack; + } + + params.flashVars = Object.toQueryString(vars); + if (Browser.ie){ + properties.classid = 'clsid:D27CDB6E-AE6D-11cf-96B8-444553540000'; + params.movie = path; + } else { + properties.type = 'application/x-shockwave-flash'; + } + properties.data = path; + + var build = ''; + } + build += ''; + this.object = ((container) ? container.empty() : new Element('div')).set('html', build).firstChild; + }, + + replaces: function(element){ + element = document.id(element, true); + element.parentNode.replaceChild(this.toElement(), element); + return this; + }, + + inject: function(element){ + document.id(element, true).appendChild(this.toElement()); + return this; + }, + + remote: function(){ + return Swiff.remote.apply(Swiff, [this.toElement()].append(arguments)); + } + +}); + +Swiff.CallBacks = {}; + +Swiff.remote = function(obj, fn){ + var rs = obj.CallFunction('' + __flash__argumentsToXML(arguments, 2) + ''); + return eval(rs); +}; + +})(); +