/**
- * Copyright (c) 2009, 2010 Matt Brown
+ * Copyright (c) 2009-2011 Matt Brown
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
* file except in compliance with the License. You may obtain a copy of the License at
if (typeof MooTools=='undefined') throw('This version of Rico requires the MooTools library');
+var Rico = {
+ Lib: 'MooTools',
+ LibVersion: MooTools.version,
+ extend: typeof($extend) != 'undefined' ? $extend : Object.append,
+ tryFunctions: typeof($try) != 'undefined' ? $try : Function.attempt,
+ trim: function(s) { return s.trim(); },
-Rico.Lib='MooTools';
-Rico.LibVersion=MooTools.version;
-Rico.extend=typeof($extend) != 'undefined' ? $extend : Object.append;
-Rico.tryFunctions = typeof($try) != 'undefined' ? $try : Function.attempt;
-Rico.trim=function(s) { return s.trim(); };
+ select: function(selector, element) {
+ return $(element || document).getElements(selector);
+ },
-Rico.select=function(selector, element) {
- return $(element || document).getElements(selector);
-};
-
-Rico.eventBind=function(element, eventName, handler) {
- $(element).addEvent(eventName, handler);
-};
+ eventBind: function(element, eventName, handler) {
+ $(element).addEvent(eventName, handler);
+ },
-Rico.eventUnbind=function(element, eventName, handler) {
- $(element).removeEvent(eventName, handler);
-};
+ eventUnbind: function(element, eventName, handler) {
+ $(element).removeEvent(eventName, handler);
+ },
-Rico.eventHandle=function(object, method) {
- return function(e) { object[method].call(object,e); };
-};
+ eventHandle: function(object, method) {
+ return function(e) { object[method].call(object,e); };
+ },
-Rico.eventElement=function(ev) {
- return ev.target;
-};
+ eventElement: function(ev) {
+ return ev.target;
+ },
-Rico.eventClient=function(ev) {
- return ev.client;
-};
+ eventClient: function(ev) {
+ return ev.client;
+ },
-Rico.eventKey=function(ev) {
- return ev.code;
-};
+ eventKey: function(ev) {
+ return ev.code;
+ },
-Rico.eventStop=function(ev) {
- ev.stop();
-};
+ eventStop: function(ev) {
+ ev.stop();
+ },
-Rico.eventLeftClick=function(ev) {
- return !ev.rightClick;
-};
-
-Rico.addClass=function(element, className) {
- return $(element).addClass(className);
-};
+ eventLeftClick: function(ev) {
+ return !ev.rightClick;
+ },
-Rico.removeClass=function(element, className) {
- return $(element).removeClass(className);
-};
+ addClass: function(element, className) {
+ return $(element).addClass(className);
+ },
-Rico.hasClass=function(element, className) {
- return $(element).hasClass(className);
-};
-
-Rico.getStyle=function(element, property) {
- return $(element).getStyle(property);
-};
+ removeClass: function(element, className) {
+ return $(element).removeClass(className);
+ },
-Rico.setStyle=function(element, properties) {
- return $(element).setStyles(properties);
-};
+ hasClass: function(element, className) {
+ return $(element).hasClass(className);
+ },
-/**
- * @returns available height, excluding scrollbar & margin
- */
-Rico.windowHeight=function() {
- return Window.getSize().y;
-};
+ getStyle: function(element, property) {
+ return $(element).getStyle(property);
+ },
-/**
- * @returns available width, excluding scrollbar & margin
- */
-Rico.windowWidth=function() {
- return Window.getSize().x;
-};
+ setStyle: function(element, properties) {
+ return $(element).setStyles(properties);
+ },
-Rico._fixOffsets=function(o) {
- return {top: o.y, left: o.x};
-}
-
-Rico.positionedOffset=function(element) {
- var p, valueT = 0, valueL = 0;
- do {
- valueT += element.offsetTop || 0;
- valueL += element.offsetLeft || 0;
- element = element.offsetParent;
- if (element) {
- p = $(element).getStyle('position');
- if (p == 'relative' || p == 'absolute') break;
- }
- } while (element);
- return {left: valueL, top: valueT};
-};
+ /**
+ * @returns available height, excluding scrollbar & margin
+ */
+ windowHeight: function() {
+ return Window.getSize().y;
+ },
-Rico.cumulativeOffset=function(element) {
- return this._fixOffsets($(element).getPosition());
-};
+ /**
+ * @returns available width, excluding scrollbar & margin
+ */
+ windowWidth: function() {
+ return Window.getSize().x;
+ },
-Rico.docScrollLeft=function() {
- return Window.getScroll().x;
-};
+ _fixOffsets: function(o) {
+ return {top: o.y, left: o.x};
+ },
-Rico.docScrollTop=function() {
- return Window.getScroll().y;
-};
+ positionedOffset: function(element) {
+ var p, valueT = 0, valueL = 0;
+ do {
+ valueT += element.offsetTop || 0;
+ valueL += element.offsetLeft || 0;
+ element = element.offsetParent;
+ if (element) {
+ p = $(element).getStyle('position');
+ if (p == 'relative' || p == 'absolute') break;
+ }
+ } while (element);
+ return {left: valueL, top: valueT};
+ },
-Rico.getDirectChildrenByTag=function(element, tagName) {
- return $(element).getChildren(tagName);
-};
+ cumulativeOffset: function(element) {
+ return this._fixOffsets($(element).getPosition());
+ },
+
+ docScrollLeft: function() {
+ return Window.getScroll().x;
+ },
+
+ docScrollTop: function() {
+ return Window.getScroll().y;
+ },
+
+ getDirectChildrenByTag: function(element, tagName) {
+ return $(element).getChildren(tagName);
+ },
+
+ // Animation
+
+ fadeIn: function(element,duration,onEnd) {
+ var a = new Fx.Tween(element, {duration:duration, onComplete:onEnd});
+ a.start('opacity', 1);
+ },
+
+ fadeOut: function(element,duration,onEnd) {
+ var a = new Fx.Tween(element, {duration:duration, onComplete:onEnd});
+ a.start('opacity', 0);
+ },
-Rico.ajaxRequest=function(url,options) {
- this.mooSend(url,options);
-}
+ animate: function(element,options,properties) {
+ options.onComplete=options.onEnd;
+ var effect=new Fx.Morph(element,options);
+ effect.start(properties);
+ return effect;
+ },
+
+ // AJAX
+
+ getJSON: function(xhr) { return JSON.decode(xhr.responseText,true); },
+
+ toQueryString: typeof(Hash) != 'undefined' ? Hash.toQueryString : Object.toQueryString,
+
+ ajaxRequest: function(url,options) {
+ this.mooSend(url,options);
+ }
+};
Rico.ajaxRequest.prototype = {
mooSend : function(url,options) {
this.mooRequest = new Request(mooOptions);
this.mooRequest.send();
},
-
+
mooSuccess : function() {
if (this.onSuccess) this.onSuccess(this.mooRequest.xhr);
},
-
+
mooComplete : function() {
if (this.onComplete) this.onComplete(this.mooRequest.xhr);
}
-}
-
-Rico.getJSON=function(xhr) { return JSON.decode(xhr.responseText,true); };
+};
Rico.ajaxSubmit=function(form,url,options) {
options.parameters=$(form).toQueryString();
if (!options.method) options.method='post';
url=url || form.action;
new Rico.ajaxRequest(url,options);
-}
-Rico.toQueryString=typeof(Hash) != 'undefined' ? Hash.toQueryString : Object.toQueryString;
-
-// Animation
-
-Rico.fadeIn=function(element,duration,onEnd) {
- var a = new Fx.Tween(element, {duration:duration, onComplete:onEnd});
- a.start('opacity', 1);
};
-
-Rico.fadeOut=function(element,duration,onEnd) {
- var a = new Fx.Tween(element, {duration:duration, onComplete:onEnd});
- a.start('opacity', 0);
-};
-
-Rico.animate=function(element,options,properties) {
- options.onComplete=options.onEnd;
- var effect=new Fx.Morph(element,options);
- effect.start(properties);
- return effect;
-};
-
-Rico._bindLoadEvent();