2 * Copyright (c) 2009 Matt Brown
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
5 * file except in compliance with the License. You may obtain a copy of the License at
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software distributed under the
10 * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
11 * either express or implied. See the License for the specific language governing permissions
12 * and limitations under the License.
15 if (typeof jQuery=='undefined') throw('This version of Rico requires the jQuery library');
19 Rico.LibVersion=jQuery().jquery;
20 Rico.extend=jQuery.extend;
21 Rico.trim=jQuery.trim;
22 Rico.tryFunctions = function() {
23 for (var i=0; i<arguments.length; i++) {
25 return arguments[i]();
32 Rico._j=function(element) {
33 if (typeof element=='string')
34 element = document.getElementById(element);
35 return jQuery(element);
38 Rico.select=function(selector, element) {
39 return element ? this._j(element).find(selector) : jQuery(selector);
42 Rico.eventBind=function(element, eventName, handler) {
43 this._j(element).bind(eventName, handler);
46 Rico.eventUnbind=function(element, eventName, handler) {
47 this._j(element).unbind(eventName, handler);
50 Rico.eventHandle=function(object, method) {
52 return object[method].call(object,e);
56 Rico.eventElement=function(ev) {
60 Rico.eventClient=function(ev) {
61 return {x:ev.clientX, y:ev.clientY};
64 Rico.eventStop=function(ev) {
69 Rico.addClass=function(element, className) {
70 return this._j(element).addClass(className);
73 Rico.removeClass=function(element, className) {
74 return this._j(element).removeClass(className);
77 Rico.hasClass=function(element, className) {
78 return this._j(element).hasClass(className);
81 Rico.getStyle=function(element, property) {
82 return this._j(element).css(property);
84 Rico.setStyle=function(element, properties) {
85 return this._j(element).css(properties);
89 * @returns available height, excluding scrollbar & margin
91 Rico.windowHeight=function() {
92 return jQuery(window).height();
96 * @returns available width, excluding scrollbar & margin
98 Rico.windowWidth=function() {
99 return jQuery(window).width();
102 Rico.positionedOffset=function(element) {
103 return this._j(element).position();
106 Rico.cumulativeOffset=function(element) {
107 return this._j(element).offset();
110 Rico.docScrollLeft=function() {
111 return jQuery('html').scrollLeft();
114 Rico.docScrollTop=function() {
115 return jQuery('html').scrollTop();
118 Rico.getDirectChildrenByTag=function(element, tagName) {
119 return this._j(element).children(tagName);
122 Rico.ajaxRequest=function(url,options) {
123 this.jSend(url,options);
126 Rico.ajaxRequest.prototype = {
127 jSend: function(url,options) {
128 this.onSuccess=options.onSuccess;
130 complete : options.onComplete,
131 error: options.onFailure,
132 success: Rico.bind(this,'jSuccess'),
133 type : options.method.toUpperCase(),
135 data : options.parameters
137 this.xhr=jQuery.ajax(jOptions);
140 jSuccess: function() {
141 if (this.onSuccess) this.onSuccess(this.xhr);
145 Rico.getJSON=function(xhr) { return jQuery.httpData(xhr,'json'); };
147 Rico.ajaxSubmit=function(form,url,options) {
148 options.parameters=this._j(form).serialize();
149 if (!options.method) options.method='post';
150 url=url || form.action;
151 new Rico.ajaxRequest(url,options);
153 Rico.toQueryString=jQuery.param;
157 Rico.fadeIn=function(element,duration,onEnd) {
158 this._j(element).fadeIn(duration,onEnd);
161 Rico.fadeOut=function(element,duration,onEnd) {
162 this._j(element).fadeOut(duration,onEnd);
165 Rico.animate=function(element,options,properties) {
166 options.complete=options.onEnd;
167 this._j(element).animate(properties,options);