- Arguments:
- source - the path of the image file
- properties - some additional attributes you might want to add to the img element
-
- Example:
- > new Asset.image('/images/myImage.png', {id: 'myImage', title: 'myImage', onload: myFunction});
-
- Returns:
- the img element. you can inject it anywhere you want with <Element.injectInside>/<Element.injectAfter>/<Element.injectBefore>
- */
-
- image: function(source, properties){
- properties = $merge({
- 'onload': Class.empty,
- 'onabort': Class.empty,
- 'onerror': Class.empty
- }, properties);
- var image = new Image();
- image.src = source;
- var element = new Element('img', {'src': source});
- ['load', 'abort', 'error'].each(function(type){
- var event = properties['on' + type];
- delete properties['on' + type];
- element.addEvent(type, function(){
- this.removeEvent(type, arguments.callee);
- event.call(this);
- });
- });
- if (image.width && image.height) element.fireEvent('load', element, 1);
- return element.setProperties(properties);
- },
-
- /*
- Property: images
- Preloads an array of images (as strings) and returns an array of img elements. does not inject them to the page.
-
- Arguments:
- sources - array, the paths of the image files
- options - object, see below
-
- Options:
- onComplete - a function to execute when all image files are loaded in the browser's cache
- onProgress - a function to execute when one image file is loaded in the browser's cache
-
- Example:
- (start code)
- new Asset.images(['/images/myImage.png', '/images/myImage2.gif'], {
- onComplete: function(){
- alert('all images loaded!');
- }
- });
- (end)
-
- Returns:
- the img elements as $$. you can inject them anywhere you want with <Element.injectInside>/<Element.injectAfter>/<Element.injectBefore>
- */
-
- images: function(sources, options){
- options = $merge({
- onComplete: Class.empty,
- onProgress: Class.empty
- }, options);
- if (!sources.push) sources = [sources];
- var images = [];
- var counter = 0;
- sources.each(function(source){
- var img = new Asset.image(source, {
- 'onload': function(){
- options.onProgress.call(this, counter);
- counter++;
- if (counter == sources.length) options.onComplete();
- }
- });
- images.push(img);
- });
- return new Elements(images);
- }
-
-});
-
-/*\r
-Script: Hash.js\r
- Contains the class Hash.\r
-\r
-License:\r
- MIT-style license.\r
-*/\r
-\r
-/*\r
-Class: Hash\r
- It wraps an object that it uses internally as a map. The user must use set(), get(), and remove() to add/change, retrieve and remove values, it must not access the internal object directly. null/undefined values are allowed.\r
-\r
-Note:\r
- Each hash instance has the length property.\r
-\r
-Arguments:\r
- obj - an object to convert into a Hash instance.\r
-\r
-Example:\r
- (start code)\r
- var hash = new Hash({a: 'hi', b: 'world', c: 'howdy'});\r
- hash.remove('b'); // b is removed.\r
- hash.set('c', 'hello');\r
- hash.get('c'); // returns 'hello'\r
- hash.length // returns 2 (a and c)\r
- (end)\r
-*/\r
-\r
-var Hash = new Class({\r
-\r
- length: 0,\r
-\r
- initialize: function(object){\r
- this.obj = object || {};\r
- this.setLength();\r
- },\r
-\r
- /*\r
- Property: get\r
- Retrieves a value from the hash.\r
-\r
- Arguments:\r
- key - The key\r
-\r
- Returns:\r
- The value\r
- */\r
-\r
- get: function(key){\r
- return (this.hasKey(key)) ? this.obj[key] : null;\r
- },\r
-\r
- /*\r
- Property: hasKey\r
- Check the presence of a specified key-value pair in the hash.\r
-\r
- Arguments:\r
- key - The key\r
-\r
- Returns:\r
- True if the Hash contains a value for the specified key, otherwise false\r
- */\r
-\r
- hasKey: function(key){\r
- return (key in this.obj);\r
- },\r
-\r
- /*\r
- Property: set\r
- Adds a key-value pair to the hash or replaces a previous value associated with the key.\r
-\r
- Arguments:\r
- key - The key\r
- value - The value\r
- */\r
-\r
- set: function(key, value){\r
- if (!this.hasKey(key)) this.length++;\r
- this.obj[key] = value;\r
- return this;\r
- },\r
-\r
- setLength: function(){\r
- this.length = 0;\r
- for (var p in this.obj) this.length++;\r
- return this;\r
- },\r
-\r
- /*\r
- Property: remove\r
- Removes a key-value pair from the hash.\r
-\r
- Arguments:\r
- key - The key\r
- */\r
-\r
- remove: function(key){\r
- if (this.hasKey(key)){\r
- delete this.obj[key];\r
- this.length--;\r
- }\r
- return this;\r
- },\r
-\r
- /*\r
- Property: each\r
- Calls a function for each key-value pair. The first argument passed to the function will be the value, the second one will be the key, like $each.\r
-\r
- Arguments:\r
- fn - The function to call for each key-value pair\r
- bind - Optional, the object that will be referred to as "this" in the function\r
- */\r
-\r
- each: function(fn, bind){\r
- $each(this.obj, fn, bind);\r
- },\r
-\r
- /*\r
- Property: extend\r
- Extends the current hash with an object containing key-value pairs. Values for duplicate keys will be replaced by the new ones.\r
-\r
- Arguments:\r
- obj - An object containing key-value pairs\r
- */\r
-\r
- extend: function(obj){\r
- $extend(this.obj, obj);\r
- return this.setLength();\r
- },\r
-\r
- /*\r
- Property: merge\r
- Merges the current hash with multiple objects.\r
- */\r
-\r
- merge: function(){\r
- this.obj = $merge.apply(null, [this.obj].extend(arguments));\r
- return this.setLength();\r
- },\r
-\r
- /*\r
- Property: empty\r
- Empties all hash values properties and values.\r
- */\r
-\r
- empty: function(){\r
- this.obj = {};\r
- this.length = 0;\r
- return this;\r
- },\r
-\r
- /*\r
- Property: keys\r
- Returns an array containing all the keys, in the same order as the values returned by <Hash.values>.\r
-\r
- Returns:\r
- An array containing all the keys of the hash\r
- */\r
-\r
- keys: function(){\r
- var keys = [];\r
- for (var property in this.obj) keys.push(property);\r
- return keys;\r
- },\r
-\r
- /*\r
- Property: values\r
- Returns an array containing all the values, in the same order as the keys returned by <Hash.keys>.\r
-\r
- Returns:\r
- An array containing all the values of the hash\r
- */\r
-\r
- values: function(){\r
- var values = [];\r
- for (var property in this.obj) values.push(this.obj[property]);\r
- return values;\r
- }\r
-\r
-});\r
-\r
-/* Section: Utility Functions */\r
-\r
-/*\r
-Function: $H\r
- Shortcut to create a Hash from an Object.\r
-*/\r
-\r
-function $H(obj){\r
- return new Hash(obj);\r
-};
-
-/*\r
-Script: Hash.Cookie.js\r
- Stores and loads an Hash as a cookie using Json format.\r
-*/\r
-\r
-/*\r
-Class: Hash.Cookie\r
- Inherits all the methods from <Hash>, additional methods are save and load.\r
- Hash json string has a limit of 4kb (4096byte), so be careful with your Hash size.\r
- Creating a new instance automatically loads the data from the Cookie into the Hash.\r
- If the Hash is emptied, the cookie is also removed.\r
-\r
-Arguments:\r
- name - the key (name) for the cookie\r
- options - options are identical to <Cookie> and are simply passed along to it.\r
- In addition, it has the autoSave option, to save the cookie at every operation. defaults to true.\r
-\r
-Example:\r
- (start code)\r
- var fruits = new Hash.Cookie('myCookieName', {duration: 3600});\r
- fruits.extend({\r
- 'lemon': 'yellow',\r
- 'apple': 'red'\r
- });\r
- fruits.set('melon', 'green');\r
- fruits.get('lemon'); // yellow\r
-\r
- // ... on another page ... values load automatically\r
-\r
- var fruits = new Hash.Cookie('myCookieName', {duration: 365});\r
- fruits.get('melon'); // green\r
-\r
- fruits.erase(); // delete cookie\r
- (end)\r
-*/\r
-\r
-Hash.Cookie = Hash.extend({\r
-\r
- initialize: function(name, options){\r
- this.name = name;\r
- this.options = $extend({'autoSave': true}, options || {});\r
- this.load();\r
- },\r
-\r
- /*\r
- Property: save\r
- Saves the Hash to the cookie. If the hash is empty, removes the cookie.\r
-\r
- Returns:\r
- Returns false when the JSON string cookie is too long (4kb), otherwise true.\r
-\r
- Example:\r
- (start code)\r
- var login = new Hash.Cookie('userstatus', {autoSave: false});\r
-\r
- login.extend({\r
- 'username': 'John',\r
- 'credentials': [4, 7, 9]\r
- });\r
- login.set('last_message', 'User logged in!');\r
-\r
- login.save(); // finally save the Hash\r
- (end)\r
- */\r
-\r
- save: function(){\r
- if (this.length == 0){\r
- Cookie.remove(this.name, this.options);\r
- return true;\r
- }\r
- var str = Json.toString(this.obj);\r
- if (str.length > 4096) return false; //cookie would be truncated!\r
- Cookie.set(this.name, str, this.options);\r
- return true;\r
- },\r
- \r
- /*\r
- Property: load\r
- Loads the cookie and assigns it to the Hash.\r
- */\r
-\r
- load: function(){\r
- this.obj = Json.evaluate(Cookie.get(this.name), true) || {};\r
- this.setLength();\r
- }\r
-\r
-});\r
-\r
-Hash.Cookie.Methods = {};\r
-['extend', 'set', 'merge', 'empty', 'remove'].each(function(method){\r
- Hash.Cookie.Methods[method] = function(){\r
- Hash.prototype[method].apply(this, arguments);\r
- if (this.options.autoSave) this.save();\r
- return this;\r
- };\r
-});\r
-Hash.Cookie.implement(Hash.Cookie.Methods);
-
-/*
-Script: Color.js
- Contains the Color class.
-
-License:
- MIT-style license.
-*/
-
-/*
-Class: Color
- Creates a new Color Object, which is an array with some color specific methods.
-Arguments:
- color - the hex, the RGB array or the HSB array of the color to create. For HSB colors, you need to specify the second argument.
- type - a string representing the type of the color to create. needs to be specified if you intend to create the color with HSB values, or an array of HEX values. Can be 'rgb', 'hsb' or 'hex'.
-
-Example:
- (start code)
- var black = new Color('#000');
- var purple = new Color([255,0,255]);
- // mix black with white and purple, each time at 10% of the new color
- var darkpurple = black.mix('#fff', purple, 10);
- $('myDiv').setStyle('background-color', darkpurple);
- (end)
-*/
-
-var Color = new Class({