2010-05-25 17:04:59 -07:00
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
2010-06-16 17:19:11 -07:00
|
|
|
* The Original Code is iq.js.
|
2010-05-25 17:04:59 -07:00
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Ian Gilman <ian@iangilman.com>.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2010
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
2010-05-27 19:17:01 -07:00
|
|
|
* Aza Raskin <aza@mozilla.com>
|
2010-06-16 17:19:11 -07:00
|
|
|
* Michael Yoshitaka Erlewine <mitcho@mitcho.com>
|
2010-05-25 17:04:59 -07:00
|
|
|
*
|
|
|
|
* Some portions copied from:
|
|
|
|
* jQuery JavaScript Library v1.4.2
|
|
|
|
* http://jquery.com/
|
|
|
|
* Copyright 2010, John Resig
|
|
|
|
* Dual licensed under the MIT or GPL Version 2 licenses.
|
|
|
|
* http://jquery.org/license
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
2010-06-16 17:19:11 -07:00
|
|
|
// **********
|
2010-05-25 17:04:59 -07:00
|
|
|
// Title: iq.js
|
2010-06-09 14:45:48 -07:00
|
|
|
// jQuery, hacked down to just the bits we need, with a bunch of other stuff added.
|
2010-06-16 17:19:11 -07:00
|
|
|
|
2010-05-25 17:04:59 -07:00
|
|
|
(function( window, undefined ) {
|
|
|
|
|
|
|
|
var iQ = function(selector, context) {
|
2010-07-11 16:48:05 -07:00
|
|
|
// The iQ object is actually just the init constructor 'enhanced'
|
|
|
|
return new iQ.fn.init( selector, context );
|
|
|
|
},
|
2010-05-25 17:04:59 -07:00
|
|
|
|
2010-07-11 16:48:05 -07:00
|
|
|
// Map over iQ in case of overwrite
|
|
|
|
_iQ = window.iQ,
|
2010-05-25 17:04:59 -07:00
|
|
|
|
2010-07-11 16:48:05 -07:00
|
|
|
// Use the correct document accordingly with window argument (sandbox)
|
|
|
|
document = window.document,
|
2010-05-25 17:04:59 -07:00
|
|
|
|
2010-07-11 16:48:05 -07:00
|
|
|
// A central reference to the root iQ(document)
|
|
|
|
rootiQ,
|
2010-05-25 17:04:59 -07:00
|
|
|
|
2010-07-11 16:48:05 -07:00
|
|
|
// A simple way to check for HTML strings or ID strings
|
|
|
|
// (both of which we optimize for)
|
|
|
|
quickExpr = /^[^<]*(<[\w\W]+>)[^>]*$|^#([\w-]+)$/,
|
2010-05-25 17:04:59 -07:00
|
|
|
|
2010-07-11 16:48:05 -07:00
|
|
|
// Match a standalone tag
|
|
|
|
rsingleTag = /^<(\w+)\s*\/?>(?:<\/\1>)?$/,
|
2010-05-25 17:04:59 -07:00
|
|
|
|
2010-07-11 16:48:05 -07:00
|
|
|
// Save a reference to some core methods
|
|
|
|
toString = Object.prototype.toString,
|
|
|
|
hasOwnProperty = Object.prototype.hasOwnProperty,
|
2010-07-13 19:02:11 -07:00
|
|
|
|
|
|
|
rclass = /[\n\t]/g,
|
|
|
|
rspace = /\s+/;
|
2010-05-26 17:04:56 -07:00
|
|
|
|
2010-05-25 17:04:59 -07:00
|
|
|
// ##########
|
|
|
|
// Class: iQ.fn
|
|
|
|
// An individual element or group of elements.
|
|
|
|
iQ.fn = iQ.prototype = {
|
|
|
|
// ----------
|
|
|
|
// Function: init
|
2010-05-26 17:04:56 -07:00
|
|
|
// You don't call this directly; this is what's called by iQ().
|
|
|
|
// It works pretty much like jQuery(), with a few exceptions,
|
|
|
|
// most notably that you can't use strings with complex html,
|
|
|
|
// just simple tags like '<div>'.
|
2010-07-11 16:48:05 -07:00
|
|
|
init: function( selector, context ) {
|
|
|
|
var match, elem, ret, doc;
|
|
|
|
|
|
|
|
// Handle $(""), $(null), or $(undefined)
|
|
|
|
if ( !selector ) {
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Handle $(DOMElement)
|
|
|
|
if ( selector.nodeType ) {
|
|
|
|
this.context = this[0] = selector;
|
|
|
|
this.length = 1;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
// The body element only exists once, optimize finding it
|
|
|
|
if ( selector === "body" && !context ) {
|
|
|
|
this.context = document;
|
|
|
|
this[0] = document.body;
|
|
|
|
this.selector = "body";
|
|
|
|
this.length = 1;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Handle HTML strings
|
|
|
|
if ( typeof selector === "string" ) {
|
|
|
|
// Are we dealing with HTML string or an ID?
|
|
|
|
match = quickExpr.exec( selector );
|
|
|
|
|
|
|
|
// Verify a match, and that no context was specified for #id
|
|
|
|
if ( match && (match[1] || !context) ) {
|
|
|
|
|
|
|
|
// HANDLE $(html) -> $(array)
|
|
|
|
if ( match[1] ) {
|
|
|
|
doc = (context ? context.ownerDocument || context : document);
|
|
|
|
|
|
|
|
// If a single string is passed in and it's a single tag
|
|
|
|
// just do a createElement and skip the rest
|
|
|
|
ret = rsingleTag.exec( selector );
|
|
|
|
|
|
|
|
if ( ret ) {
|
|
|
|
if ( iQ.isPlainObject( context ) ) {
|
|
|
|
Utils.assert('does not support HTML creation with context', false);
|
|
|
|
} else {
|
|
|
|
selector = [ doc.createElement( ret[1] ) ];
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
Utils.assert('does not support complex HTML creation', false);
|
|
|
|
}
|
|
|
|
|
|
|
|
return iQ.merge( this, selector );
|
|
|
|
|
|
|
|
// HANDLE $("#id")
|
|
|
|
} else {
|
|
|
|
elem = document.getElementById( match[2] );
|
|
|
|
|
|
|
|
if ( elem ) {
|
|
|
|
this.length = 1;
|
|
|
|
this[0] = elem;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.context = document;
|
|
|
|
this.selector = selector;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
// HANDLE $("TAG")
|
|
|
|
} else if ( !context && /^\w+$/.test( selector ) ) {
|
|
|
|
this.selector = selector;
|
|
|
|
this.context = document;
|
|
|
|
selector = document.getElementsByTagName( selector );
|
|
|
|
return iQ.merge( this, selector );
|
|
|
|
|
|
|
|
// HANDLE $(expr, $(...))
|
|
|
|
} else if ( !context || context.iq ) {
|
|
|
|
return (context || rootiQ).find( selector );
|
|
|
|
|
|
|
|
// HANDLE $(expr, context)
|
|
|
|
// (which is just equivalent to: $(context).find(expr)
|
|
|
|
} else {
|
|
|
|
return iQ( context ).find( selector );
|
|
|
|
}
|
|
|
|
|
|
|
|
// HANDLE $(function)
|
|
|
|
// Shortcut for document ready
|
|
|
|
} else if ( iQ.isFunction( selector ) ) {
|
|
|
|
Utils.log('iQ does not support ready functions');
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (selector.selector !== undefined) {
|
|
|
|
this.selector = selector.selector;
|
|
|
|
this.context = selector.context;
|
|
|
|
}
|
|
|
|
|
2010-07-13 14:39:46 -07:00
|
|
|
// this used to be makeArray:
|
|
|
|
var ret = this || [];
|
|
|
|
if ( selector != null ) {
|
|
|
|
// The window, strings (and functions) also have 'length'
|
|
|
|
// The extra typeof function check is to prevent crashes
|
|
|
|
// in Safari 2 (See: #3039)
|
|
|
|
if ( selector.length == null || typeof selector === "string" || iQ.isFunction(selector) || (typeof selector !== "function" && selector.setInterval) ) {
|
2010-07-13 19:02:11 -07:00
|
|
|
Array.prototype.push.call( ret, selector );
|
2010-07-13 14:39:46 -07:00
|
|
|
} else {
|
|
|
|
iQ.merge( ret, selector );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
|
2010-07-11 16:48:05 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
// Start with an empty selector
|
|
|
|
selector: "",
|
|
|
|
|
|
|
|
// The current version of iQ being used
|
|
|
|
iq: "1.4.2",
|
|
|
|
|
|
|
|
// The default length of a iQ object is 0
|
|
|
|
length: 0,
|
|
|
|
|
2010-05-26 17:04:56 -07:00
|
|
|
// ----------
|
|
|
|
// Function: get
|
2010-07-11 16:48:05 -07:00
|
|
|
// Get the Nth element in the matched element set OR
|
|
|
|
// Get the whole matched element set as a clean array
|
|
|
|
get: function( num ) {
|
|
|
|
return num == null ?
|
2010-05-26 17:04:56 -07:00
|
|
|
|
2010-07-11 16:48:05 -07:00
|
|
|
// Return a 'clean' array
|
2010-07-13 19:02:11 -07:00
|
|
|
// was toArray
|
|
|
|
Array.prototype.slice.call( this, 0 ) :
|
2010-05-26 17:04:56 -07:00
|
|
|
|
2010-07-11 16:48:05 -07:00
|
|
|
// Return just the object
|
2010-07-13 19:02:11 -07:00
|
|
|
( num < 0 ? this[ num + this.length ] : this[ num ] );
|
2010-07-11 16:48:05 -07:00
|
|
|
},
|
2010-05-26 17:04:56 -07:00
|
|
|
|
|
|
|
// ----------
|
|
|
|
// Function: each
|
2010-07-11 16:48:05 -07:00
|
|
|
// Execute a callback for every element in the matched set.
|
2010-07-13 21:03:47 -07:00
|
|
|
each: function( callback ) {
|
|
|
|
for ( var i = 0, elem; (elem = this[i]) != null; i++ ) {
|
|
|
|
callback(elem);
|
|
|
|
}
|
2010-07-11 16:48:05 -07:00
|
|
|
},
|
2010-05-26 17:04:56 -07:00
|
|
|
|
|
|
|
// ----------
|
|
|
|
// Function: addClass
|
2010-07-11 16:48:05 -07:00
|
|
|
addClass: function( value ) {
|
|
|
|
if ( iQ.isFunction(value) ) {
|
|
|
|
Utils.assert('does not support function argument', false);
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( value && typeof value === "string" ) {
|
|
|
|
for ( var i = 0, l = this.length; i < l; i++ ) {
|
|
|
|
var elem = this[i];
|
|
|
|
if ( elem.nodeType === 1 ) {
|
2010-07-13 19:17:35 -07:00
|
|
|
(value || "").split( rspace ).forEach(function(className) {
|
|
|
|
elem.classList.add(className);
|
|
|
|
});
|
2010-07-11 16:48:05 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return this;
|
|
|
|
},
|
2010-05-26 17:04:56 -07:00
|
|
|
|
|
|
|
// ----------
|
|
|
|
// Function: removeClass
|
2010-07-11 16:48:05 -07:00
|
|
|
removeClass: function( value ) {
|
|
|
|
if ( iQ.isFunction(value) ) {
|
|
|
|
Utils.assert('does not support function argument', false);
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( (value && typeof value === "string") || value === undefined ) {
|
|
|
|
for ( var i = 0, l = this.length; i < l; i++ ) {
|
|
|
|
var elem = this[i];
|
|
|
|
if ( elem.nodeType === 1 && elem.className ) {
|
|
|
|
if ( value ) {
|
2010-07-13 19:17:35 -07:00
|
|
|
(value || "").split(rspace).forEach(function(className) {
|
|
|
|
elem.classList.remove(className);
|
|
|
|
});
|
2010-07-11 16:48:05 -07:00
|
|
|
} else {
|
|
|
|
elem.className = "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return this;
|
|
|
|
},
|
2010-05-26 17:04:56 -07:00
|
|
|
|
2010-05-27 17:25:14 -07:00
|
|
|
// ----------
|
|
|
|
// Function: hasClass
|
2010-07-11 16:48:05 -07:00
|
|
|
hasClass: function( selector ) {
|
|
|
|
for ( var i = 0, l = this.length; i < l; i++ ) {
|
2010-07-13 19:17:35 -07:00
|
|
|
if ( this[i].classList.contains( selector ) ) {
|
2010-07-11 16:48:05 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
},
|
2010-05-27 17:25:14 -07:00
|
|
|
|
2010-05-26 17:04:56 -07:00
|
|
|
// ----------
|
|
|
|
// Function: find
|
2010-07-11 16:48:05 -07:00
|
|
|
find: function( selector ) {
|
|
|
|
var ret = [], length = 0;
|
2010-05-26 17:04:56 -07:00
|
|
|
|
2010-07-11 16:48:05 -07:00
|
|
|
for ( var i = 0, l = this.length; i < l; i++ ) {
|
|
|
|
length = ret.length;
|
2010-05-26 17:04:56 -07:00
|
|
|
try {
|
|
|
|
iQ.merge(ret, this[i].querySelectorAll( selector ) );
|
|
|
|
} catch(e) {
|
|
|
|
Utils.log('iQ.find error (bad selector)', e);
|
|
|
|
}
|
|
|
|
|
2010-07-11 16:48:05 -07:00
|
|
|
if ( i > 0 ) {
|
|
|
|
// Make sure that the results are unique
|
|
|
|
for ( var n = length; n < ret.length; n++ ) {
|
|
|
|
for ( var r = 0; r < length; r++ ) {
|
|
|
|
if ( ret[r] === ret[n] ) {
|
|
|
|
ret.splice(n--, 1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return iQ(ret);
|
|
|
|
},
|
2010-05-26 17:04:56 -07:00
|
|
|
|
|
|
|
// ----------
|
|
|
|
// Function: remove
|
2010-07-11 16:48:05 -07:00
|
|
|
remove: function(unused) {
|
|
|
|
Utils.assert('does not accept a selector', unused === undefined);
|
|
|
|
for ( var i = 0, elem; (elem = this[i]) != null; i++ ) {
|
|
|
|
if ( elem.parentNode ) {
|
|
|
|
elem.parentNode.removeChild( elem );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return this;
|
|
|
|
},
|
2010-05-26 17:04:56 -07:00
|
|
|
|
|
|
|
// ----------
|
|
|
|
// Function: empty
|
2010-07-11 16:48:05 -07:00
|
|
|
empty: function() {
|
|
|
|
for ( var i = 0, elem; (elem = this[i]) != null; i++ ) {
|
|
|
|
while ( elem.firstChild ) {
|
|
|
|
elem.removeChild( elem.firstChild );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return this;
|
|
|
|
},
|
2010-05-26 17:04:56 -07:00
|
|
|
|
|
|
|
// ----------
|
|
|
|
// Function: width
|
2010-07-11 16:48:05 -07:00
|
|
|
width: function(unused) {
|
2010-05-26 17:04:56 -07:00
|
|
|
Utils.assert('does not yet support setting', unused === undefined);
|
2010-06-10 12:04:39 -07:00
|
|
|
return parseInt(this.css('width'));
|
2010-05-26 17:04:56 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
// ----------
|
|
|
|
// Function: height
|
2010-07-11 16:48:05 -07:00
|
|
|
height: function(unused) {
|
2010-05-26 17:04:56 -07:00
|
|
|
Utils.assert('does not yet support setting', unused === undefined);
|
2010-06-10 12:04:39 -07:00
|
|
|
return parseInt(this.css('height'));
|
2010-05-26 17:04:56 -07:00
|
|
|
},
|
|
|
|
|
2010-05-28 15:56:00 -07:00
|
|
|
// ----------
|
|
|
|
// Function: position
|
|
|
|
position: function(unused) {
|
|
|
|
Utils.assert('does not yet support setting', unused === undefined);
|
|
|
|
return {
|
2010-06-09 17:30:02 -07:00
|
|
|
left: parseInt(this.css('left')),
|
|
|
|
top: parseInt(this.css('top'))
|
2010-05-28 15:56:00 -07:00
|
|
|
};
|
|
|
|
},
|
|
|
|
|
2010-05-26 17:04:56 -07:00
|
|
|
// ----------
|
|
|
|
// Function: bounds
|
|
|
|
bounds: function(unused) {
|
|
|
|
Utils.assert('does not yet support setting', unused === undefined);
|
2010-06-15 15:55:47 -07:00
|
|
|
var p = this.position();
|
|
|
|
return new Rect(p.left, p.top, this.width(), this.height());
|
2010-05-26 17:04:56 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
// ----------
|
|
|
|
// Function: data
|
|
|
|
data: function(key, value) {
|
2010-06-25 16:00:51 -07:00
|
|
|
var data = null;
|
2010-07-11 17:54:42 -07:00
|
|
|
if (value === undefined) {
|
2010-06-04 15:08:24 -07:00
|
|
|
Utils.assert('does not yet support multi-objects (or null objects)', this.length == 1);
|
2010-06-25 16:00:51 -07:00
|
|
|
data = this[0].iQData;
|
2010-05-26 17:04:56 -07:00
|
|
|
return (data ? data[key] : null);
|
2010-06-04 15:08:24 -07:00
|
|
|
}
|
|
|
|
|
2010-07-11 16:48:05 -07:00
|
|
|
for ( var i = 0, elem; (elem = this[i]) != null; i++ ) {
|
2010-06-25 16:00:51 -07:00
|
|
|
data = elem.iQData;
|
2010-06-04 15:08:24 -07:00
|
|
|
|
2010-07-11 17:54:42 -07:00
|
|
|
if (!data)
|
2010-06-04 15:08:24 -07:00
|
|
|
data = elem.iQData = {};
|
|
|
|
|
|
|
|
data[key] = value;
|
|
|
|
}
|
2010-05-26 17:04:56 -07:00
|
|
|
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
|
|
|
// ----------
|
|
|
|
// Function: html
|
|
|
|
// TODO: security
|
|
|
|
html: function(value) {
|
|
|
|
Utils.assert('does not yet support multi-objects (or null objects)', this.length == 1);
|
2010-07-11 17:54:42 -07:00
|
|
|
if (value === undefined)
|
2010-05-26 17:04:56 -07:00
|
|
|
return this[0].innerHTML;
|
|
|
|
|
|
|
|
this[0].innerHTML = value;
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
|
|
|
// ----------
|
|
|
|
// Function: text
|
|
|
|
text: function(value) {
|
|
|
|
Utils.assert('does not yet support multi-objects (or null objects)', this.length == 1);
|
2010-07-11 17:54:42 -07:00
|
|
|
if (value === undefined) {
|
2010-05-26 17:04:56 -07:00
|
|
|
return this[0].textContent;
|
|
|
|
}
|
|
|
|
|
2010-07-11 16:48:05 -07:00
|
|
|
return this.empty().append( (this[0] && this[0].ownerDocument || document).createTextNode(value));
|
2010-05-26 17:04:56 -07:00
|
|
|
},
|
|
|
|
|
2010-06-03 15:31:18 -07:00
|
|
|
// ----------
|
|
|
|
// Function: val
|
|
|
|
val: function(value) {
|
|
|
|
Utils.assert('does not yet support multi-objects (or null objects)', this.length == 1);
|
2010-07-11 17:54:42 -07:00
|
|
|
if (value === undefined) {
|
2010-06-03 15:31:18 -07:00
|
|
|
return this[0].value;
|
|
|
|
}
|
|
|
|
|
|
|
|
this[0].value = value;
|
2010-07-11 16:48:05 -07:00
|
|
|
return this;
|
2010-06-03 15:31:18 -07:00
|
|
|
},
|
|
|
|
|
2010-05-26 17:04:56 -07:00
|
|
|
// ----------
|
|
|
|
// Function: appendTo
|
|
|
|
appendTo: function(selector) {
|
|
|
|
Utils.assert('does not yet support multi-objects (or null objects)', this.length == 1);
|
|
|
|
iQ(selector).append(this);
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
|
|
|
// ----------
|
|
|
|
// Function: append
|
|
|
|
append: function(selector) {
|
|
|
|
Utils.assert('does not yet support multi-objects (or null objects)', this.length == 1);
|
|
|
|
var object = iQ(selector);
|
|
|
|
Utils.assert('does not yet support multi-objects (or null objects)', object.length == 1);
|
|
|
|
this[0].appendChild(object[0]);
|
|
|
|
return this;
|
2010-05-27 17:25:14 -07:00
|
|
|
},
|
|
|
|
|
2010-06-21 17:27:12 -07:00
|
|
|
// ----------
|
|
|
|
// Function: attr
|
|
|
|
// Sets or gets an attribute on the element(s).
|
|
|
|
attr: function(key, value) {
|
|
|
|
try {
|
|
|
|
Utils.assert('string key', typeof key === 'string');
|
2010-07-11 17:54:42 -07:00
|
|
|
if (value === undefined) {
|
2010-06-21 17:27:12 -07:00
|
|
|
Utils.assert('retrieval does not support multi-objects (or null objects)', this.length == 1);
|
|
|
|
return this[0].getAttribute(key);
|
2010-07-11 16:48:05 -07:00
|
|
|
}
|
|
|
|
for ( var i = 0, elem; (elem = this[i]) != null; i++ ) {
|
|
|
|
elem.setAttribute(key, value);
|
2010-06-21 17:27:12 -07:00
|
|
|
}
|
|
|
|
} catch(e) {
|
|
|
|
Utils.log(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2010-05-27 17:25:14 -07:00
|
|
|
// ----------
|
|
|
|
// Function: css
|
|
|
|
css: function(a, b) {
|
|
|
|
var properties = null;
|
2010-05-28 15:56:00 -07:00
|
|
|
|
2010-07-11 17:54:42 -07:00
|
|
|
if (typeof a === 'string') {
|
2010-06-09 17:30:02 -07:00
|
|
|
var key = a;
|
2010-07-11 17:54:42 -07:00
|
|
|
if (b === undefined) {
|
2010-05-27 17:25:14 -07:00
|
|
|
Utils.assert('retrieval does not support multi-objects (or null objects)', this.length == 1);
|
2010-06-09 17:30:02 -07:00
|
|
|
|
|
|
|
var substitutions = {
|
|
|
|
'MozTransform': '-moz-transform',
|
|
|
|
'zIndex': 'z-index'
|
|
|
|
};
|
|
|
|
|
|
|
|
return window.getComputedStyle(this[0], null).getPropertyValue(substitutions[key] || key);
|
2010-05-27 17:25:14 -07:00
|
|
|
}
|
2010-07-11 16:48:05 -07:00
|
|
|
properties = {};
|
|
|
|
properties[key] = b;
|
|
|
|
} else {
|
2010-05-27 17:25:14 -07:00
|
|
|
properties = a;
|
2010-07-11 16:48:05 -07:00
|
|
|
}
|
2010-05-27 17:25:14 -07:00
|
|
|
|
2010-07-11 16:48:05 -07:00
|
|
|
var pixels = {
|
|
|
|
'left': true,
|
|
|
|
'top': true,
|
|
|
|
'right': true,
|
|
|
|
'bottom': true,
|
|
|
|
'width': true,
|
|
|
|
'height': true
|
|
|
|
};
|
|
|
|
|
|
|
|
for ( var i = 0, elem; (elem = this[i]) != null; i++ ) {
|
2010-07-13 21:03:47 -07:00
|
|
|
for (var key in properties) {
|
|
|
|
var value = properties[key];
|
2010-07-11 17:54:42 -07:00
|
|
|
if (pixels[key] && typeof(value) != 'string')
|
2010-06-03 15:31:18 -07:00
|
|
|
value += 'px';
|
2010-05-27 19:17:01 -07:00
|
|
|
|
2010-07-11 17:54:42 -07:00
|
|
|
if (key.indexOf('-') != -1)
|
2010-06-03 15:31:18 -07:00
|
|
|
elem.style.setProperty(key, value, '');
|
|
|
|
else
|
|
|
|
elem.style[key] = value;
|
2010-07-13 21:03:47 -07:00
|
|
|
}
|
2010-05-28 15:56:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return this;
|
2010-05-27 17:25:14 -07:00
|
|
|
},
|
2010-05-28 15:56:00 -07:00
|
|
|
|
|
|
|
// ----------
|
|
|
|
// Function: animate
|
2010-06-07 16:16:55 -07:00
|
|
|
// Uses CSS transitions to animate the element.
|
|
|
|
//
|
|
|
|
// Parameters:
|
|
|
|
// css - an object map of the CSS properties to change
|
|
|
|
// options - an object with various properites (see below)
|
|
|
|
//
|
|
|
|
// Possible "options" properties:
|
|
|
|
// duration - how long to animate, in milliseconds
|
|
|
|
// easing - easing function to use. Possibilities include 'tabcandyBounce', 'easeInQuad'.
|
|
|
|
// Default is 'ease'.
|
|
|
|
// complete - function to call once the animation is done, takes nothing in, but "this"
|
|
|
|
// is set to the element that was animated.
|
|
|
|
animate: function(css, options) {
|
2010-05-28 15:56:00 -07:00
|
|
|
try {
|
2010-06-07 16:16:55 -07:00
|
|
|
Utils.assert('does not yet support multi-objects (or null objects)', this.length == 1);
|
|
|
|
|
2010-07-11 17:54:42 -07:00
|
|
|
if (!options)
|
2010-06-07 16:16:55 -07:00
|
|
|
options = {};
|
|
|
|
|
|
|
|
var easings = {
|
2010-06-08 13:42:27 -07:00
|
|
|
tabcandyBounce: 'cubic-bezier(0.0, 0.63, .6, 1.29)',
|
2010-06-11 17:57:02 -07:00
|
|
|
easeInQuad: 'ease-in', // TODO: make it a real easeInQuad, or decide we don't care
|
|
|
|
fast: 'cubic-bezier(0.7,0,1,1)'
|
2010-06-07 16:16:55 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
var duration = (options.duration || 400);
|
|
|
|
var easing = (easings[options.easing] || 'ease');
|
|
|
|
|
2010-06-10 14:35:15 -07:00
|
|
|
// The latest versions of Firefox do not animate from a non-explicitly set
|
|
|
|
// css properties. So for each element to be animated, go through and
|
|
|
|
// explicitly define 'em.
|
2010-06-25 16:00:51 -07:00
|
|
|
var rupper = /([A-Z])/g;
|
2010-07-13 21:03:47 -07:00
|
|
|
this.each(function(elem){
|
|
|
|
var cStyle = window.getComputedStyle(elem, null);
|
2010-07-11 17:54:42 -07:00
|
|
|
for (var prop in css){
|
2010-06-10 14:35:15 -07:00
|
|
|
prop = prop.replace( rupper, "-$1" ).toLowerCase();
|
2010-07-13 21:03:47 -07:00
|
|
|
iQ(elem).css(prop, cStyle.getPropertyValue(prop));
|
2010-06-10 14:35:15 -07:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2010-06-04 16:39:33 -07:00
|
|
|
this.css({
|
2010-06-07 16:16:55 -07:00
|
|
|
'-moz-transition-property': 'all', // TODO: just animate the properties we're changing
|
|
|
|
'-moz-transition-duration': (duration / 1000) + 's',
|
|
|
|
'-moz-transition-timing-function': easing
|
2010-06-04 16:39:33 -07:00
|
|
|
});
|
|
|
|
|
2010-06-07 16:16:55 -07:00
|
|
|
this.css(css);
|
2010-05-28 15:56:00 -07:00
|
|
|
|
|
|
|
var self = this;
|
2010-06-10 12:04:39 -07:00
|
|
|
iQ.timeout(function() {
|
|
|
|
self.css({
|
|
|
|
'-moz-transition-property': 'none',
|
|
|
|
'-moz-transition-duration': '',
|
|
|
|
'-moz-transition-timing-function': ''
|
|
|
|
});
|
|
|
|
|
2010-07-11 17:54:42 -07:00
|
|
|
if (iQ.isFunction(options.complete))
|
2010-06-10 12:04:39 -07:00
|
|
|
options.complete.apply(self);
|
2010-06-07 16:16:55 -07:00
|
|
|
}, duration);
|
2010-05-28 15:56:00 -07:00
|
|
|
} catch(e) {
|
2010-06-07 16:16:55 -07:00
|
|
|
Utils.log(e);
|
2010-05-28 15:56:00 -07:00
|
|
|
}
|
|
|
|
|
2010-06-03 17:11:13 -07:00
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
|
|
|
// ----------
|
|
|
|
// Function: fadeOut
|
2010-06-04 15:08:24 -07:00
|
|
|
fadeOut: function(callback) {
|
2010-06-03 17:11:13 -07:00
|
|
|
try {
|
2010-06-04 15:08:24 -07:00
|
|
|
Utils.assert('does not yet support duration', iQ.isFunction(callback) || callback === undefined);
|
2010-06-08 17:13:19 -07:00
|
|
|
this.animate({
|
|
|
|
opacity: 0
|
|
|
|
}, {
|
|
|
|
duration: 400,
|
|
|
|
complete: function() {
|
|
|
|
iQ(this).css({display: 'none'});
|
2010-07-11 17:54:42 -07:00
|
|
|
if (iQ.isFunction(callback))
|
2010-06-08 17:13:19 -07:00
|
|
|
callback.apply(this);
|
|
|
|
}
|
2010-06-03 17:11:13 -07:00
|
|
|
});
|
|
|
|
} catch(e) {
|
|
|
|
Utils.log(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
|
|
|
// ----------
|
|
|
|
// Function: fadeIn
|
|
|
|
fadeIn: function() {
|
|
|
|
try {
|
|
|
|
this.css({display: ''});
|
2010-06-08 17:13:19 -07:00
|
|
|
this.animate({
|
|
|
|
opacity: 1
|
|
|
|
}, {
|
|
|
|
duration: 400
|
|
|
|
});
|
2010-06-03 17:11:13 -07:00
|
|
|
} catch(e) {
|
|
|
|
Utils.log(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
return this;
|
2010-05-28 15:56:00 -07:00
|
|
|
},
|
|
|
|
|
2010-06-04 12:34:03 -07:00
|
|
|
// ----------
|
|
|
|
// Function: hide
|
|
|
|
hide: function() {
|
|
|
|
try {
|
|
|
|
this.css({display: 'none', opacity: 0});
|
|
|
|
} catch(e) {
|
|
|
|
Utils.log(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
|
|
|
// ----------
|
|
|
|
// Function: show
|
|
|
|
show: function() {
|
|
|
|
try {
|
|
|
|
this.css({display: '', opacity: 1});
|
|
|
|
} catch(e) {
|
|
|
|
Utils.log(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2010-05-27 17:25:14 -07:00
|
|
|
// ----------
|
|
|
|
// Function: bind
|
2010-06-07 17:24:55 -07:00
|
|
|
// Binds the given function to the given event type. Also wraps the function
|
|
|
|
// in a try/catch block that does a Utils.log on any errors.
|
2010-05-27 17:25:14 -07:00
|
|
|
bind: function(type, func) {
|
|
|
|
Utils.assert('does not support eventData argument', iQ.isFunction(func));
|
2010-05-28 15:56:00 -07:00
|
|
|
|
2010-06-25 16:00:51 -07:00
|
|
|
var handler = function(event) {
|
2010-05-28 15:56:00 -07:00
|
|
|
try {
|
2010-06-25 16:00:51 -07:00
|
|
|
return func.apply(this, [event]);
|
2010-05-28 15:56:00 -07:00
|
|
|
} catch(e) {
|
|
|
|
Utils.log(e);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2010-07-11 16:48:05 -07:00
|
|
|
for ( var i = 0, elem; (elem = this[i]) != null; i++ ) {
|
2010-07-11 17:54:42 -07:00
|
|
|
if (!elem.iQEventData)
|
2010-06-07 17:20:15 -07:00
|
|
|
elem.iQEventData = {};
|
|
|
|
|
2010-07-11 17:54:42 -07:00
|
|
|
if (!elem.iQEventData[type])
|
2010-06-07 17:20:15 -07:00
|
|
|
elem.iQEventData[type] = [];
|
|
|
|
|
|
|
|
elem.iQEventData[type].push({
|
|
|
|
original: func,
|
|
|
|
modified: handler
|
|
|
|
});
|
|
|
|
|
|
|
|
elem.addEventListener(type, handler, false);
|
2010-05-27 17:25:14 -07:00
|
|
|
}
|
2010-05-28 15:56:00 -07:00
|
|
|
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
|
|
|
// ----------
|
|
|
|
// Function: one
|
|
|
|
one: function(type, func) {
|
|
|
|
Utils.assert('does not support eventData argument', iQ.isFunction(func));
|
|
|
|
|
|
|
|
var handler = function(e) {
|
|
|
|
iQ(this).unbind(type, handler);
|
2010-06-04 16:39:33 -07:00
|
|
|
return func.apply(this, [e]);
|
2010-05-28 15:56:00 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
return this.bind(type, handler);
|
2010-05-27 17:25:14 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
// ----------
|
|
|
|
// Function: unbind
|
|
|
|
unbind: function(type, func) {
|
2010-05-28 15:56:00 -07:00
|
|
|
Utils.assert('Must provide a function', iQ.isFunction(func));
|
|
|
|
|
2010-07-11 16:48:05 -07:00
|
|
|
for ( var i = 0, elem; (elem = this[i]) != null; i++ ) {
|
2010-06-07 17:20:15 -07:00
|
|
|
var handler = func;
|
2010-07-11 17:54:42 -07:00
|
|
|
if (elem.iQEventData && elem.iQEventData[type]) {
|
|
|
|
for (var a = 0, count = elem.iQEventData[type].length; a < count; a++) {
|
2010-06-07 17:20:15 -07:00
|
|
|
var pair = elem.iQEventData[type][a];
|
2010-07-11 17:54:42 -07:00
|
|
|
if (pair.original == func) {
|
2010-06-07 17:20:15 -07:00
|
|
|
handler = pair.modified;
|
|
|
|
elem.iQEventData[type].splice(a, 1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
elem.removeEventListener(type, handler, false);
|
2010-05-27 17:25:14 -07:00
|
|
|
}
|
2010-05-28 15:56:00 -07:00
|
|
|
|
|
|
|
return this;
|
2010-05-26 17:04:56 -07:00
|
|
|
}
|
2010-05-25 17:04:59 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
// ----------
|
|
|
|
// Give the init function the iQ prototype for later instantiation
|
|
|
|
iQ.fn.init.prototype = iQ.fn;
|
|
|
|
|
|
|
|
// ----------
|
|
|
|
// Function: extend
|
|
|
|
iQ.extend = iQ.fn.extend = function() {
|
2010-07-11 16:48:05 -07:00
|
|
|
// copy reference to target object
|
|
|
|
var target = arguments[0] || {}, i = 1, length = arguments.length, deep = false, options, name, src, copy;
|
|
|
|
|
|
|
|
// Handle a deep copy situation
|
|
|
|
if ( typeof target === "boolean" ) {
|
|
|
|
deep = target;
|
|
|
|
target = arguments[1] || {};
|
|
|
|
// skip the boolean and the target
|
|
|
|
i = 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Handle case when target is a string or something (possible in deep copy)
|
|
|
|
if ( typeof target !== "object" && !iQ.isFunction(target) ) {
|
|
|
|
target = {};
|
|
|
|
}
|
|
|
|
|
|
|
|
// extend iQ itself if only one argument is passed
|
|
|
|
if ( length === i ) {
|
|
|
|
target = this;
|
|
|
|
--i;
|
|
|
|
}
|
|
|
|
|
|
|
|
for ( ; i < length; i++ ) {
|
|
|
|
// Only deal with non-null/undefined values
|
|
|
|
if ( (options = arguments[ i ]) != null ) {
|
|
|
|
// Extend the base object
|
|
|
|
for ( name in options ) {
|
|
|
|
src = target[ name ];
|
|
|
|
copy = options[ name ];
|
|
|
|
|
|
|
|
// Prevent never-ending loop
|
|
|
|
if ( target === copy ) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Recurse if we're merging object literal values or arrays
|
|
|
|
if ( deep && copy && ( iQ.isPlainObject(copy) || iQ.isArray(copy) ) ) {
|
|
|
|
var clone = src && ( iQ.isPlainObject(src) || iQ.isArray(src) ) ? src
|
|
|
|
: iQ.isArray(copy) ? [] : {};
|
|
|
|
|
|
|
|
// Never move original objects, clone them
|
|
|
|
target[ name ] = iQ.extend( deep, clone, copy );
|
|
|
|
|
|
|
|
// Don't bring in undefined values
|
|
|
|
} else if ( copy !== undefined ) {
|
|
|
|
target[ name ] = copy;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return the modified object
|
|
|
|
return target;
|
2010-05-25 17:04:59 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
// ##########
|
|
|
|
// Class: iQ
|
|
|
|
// Singleton
|
|
|
|
iQ.extend({
|
2010-06-03 15:31:18 -07:00
|
|
|
// ----------
|
|
|
|
// Variable: animationCount
|
|
|
|
// For internal use only
|
|
|
|
animationCount: 0,
|
|
|
|
|
|
|
|
// ----------
|
|
|
|
// Function: isAnimating
|
|
|
|
isAnimating: function() {
|
|
|
|
return (this.animationCount != 0);
|
|
|
|
},
|
|
|
|
|
2010-07-11 16:48:05 -07:00
|
|
|
// -----------
|
|
|
|
// Function: isFunction
|
|
|
|
isFunction: function( obj ) {
|
|
|
|
return toString.call(obj) === "[object Function]";
|
|
|
|
},
|
2010-05-25 17:04:59 -07:00
|
|
|
|
|
|
|
// ----------
|
|
|
|
// Function: isArray
|
2010-07-11 16:48:05 -07:00
|
|
|
isArray: function( obj ) {
|
|
|
|
return toString.call(obj) === "[object Array]";
|
|
|
|
},
|
2010-05-25 17:04:59 -07:00
|
|
|
|
|
|
|
// ----------
|
|
|
|
// Function: isPlainObject
|
2010-07-11 16:48:05 -07:00
|
|
|
isPlainObject: function( obj ) {
|
|
|
|
// Must be an Object.
|
|
|
|
// Because of IE, we also have to check the presence of the constructor property.
|
|
|
|
// Make sure that DOM nodes and window objects don't pass through, as well
|
|
|
|
if ( !obj || toString.call(obj) !== "[object Object]" || obj.nodeType || obj.setInterval ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Not own constructor property must be Object
|
|
|
|
if ( obj.constructor
|
|
|
|
&& !hasOwnProperty.call(obj, "constructor")
|
|
|
|
&& !hasOwnProperty.call(obj.constructor.prototype, "isPrototypeOf") ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Own properties are enumerated firstly, so to speed up,
|
|
|
|
// if last one is own, then all properties are own.
|
|
|
|
|
|
|
|
var key;
|
|
|
|
for ( key in obj ) {}
|
|
|
|
|
|
|
|
return key === undefined || hasOwnProperty.call( obj, key );
|
|
|
|
},
|
2010-05-25 17:04:59 -07:00
|
|
|
|
|
|
|
// ----------
|
|
|
|
// Function: isEmptyObject
|
2010-07-11 16:48:05 -07:00
|
|
|
isEmptyObject: function( obj ) {
|
|
|
|
for ( var name in obj ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
|
2010-05-26 17:04:56 -07:00
|
|
|
// ----------
|
|
|
|
// Function: merge
|
2010-07-11 16:48:05 -07:00
|
|
|
merge: function( first, second ) {
|
|
|
|
var i = first.length, j = 0;
|
2010-05-26 17:04:56 -07:00
|
|
|
|
2010-07-11 16:48:05 -07:00
|
|
|
if ( typeof second.length === "number" ) {
|
|
|
|
for ( var l = second.length; j < l; j++ ) {
|
|
|
|
first[ i++ ] = second[ j ];
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
while ( second[j] !== undefined ) {
|
|
|
|
first[ i++ ] = second[ j++ ];
|
|
|
|
}
|
|
|
|
}
|
2010-05-26 17:04:56 -07:00
|
|
|
|
2010-07-11 16:48:05 -07:00
|
|
|
first.length = i;
|
2010-05-26 17:04:56 -07:00
|
|
|
|
2010-07-11 16:48:05 -07:00
|
|
|
return first;
|
|
|
|
},
|
2010-05-26 17:04:56 -07:00
|
|
|
|
2010-06-10 12:04:39 -07:00
|
|
|
// ----------
|
|
|
|
// Function: timeout
|
|
|
|
// wraps setTimeout with try/catch
|
|
|
|
timeout: function(func, delay) {
|
|
|
|
setTimeout(function() {
|
|
|
|
try {
|
|
|
|
func();
|
|
|
|
} catch(e) {
|
|
|
|
Utils.log(e);
|
|
|
|
}
|
|
|
|
}, delay);
|
|
|
|
}
|
2010-05-25 17:04:59 -07:00
|
|
|
});
|
|
|
|
|
2010-05-28 15:56:00 -07:00
|
|
|
// ----------
|
|
|
|
// Create various event aliases
|
|
|
|
(function() {
|
|
|
|
var events = [
|
|
|
|
'keyup',
|
|
|
|
'keydown',
|
|
|
|
'mouseup',
|
|
|
|
'mousedown',
|
2010-06-07 17:20:15 -07:00
|
|
|
'mouseover',
|
2010-06-19 18:46:39 -07:00
|
|
|
'mouseout',
|
2010-05-28 15:56:00 -07:00
|
|
|
'mousemove',
|
2010-06-03 15:31:18 -07:00
|
|
|
'click',
|
|
|
|
'resize',
|
2010-06-04 15:08:24 -07:00
|
|
|
'change',
|
|
|
|
'blur',
|
|
|
|
'focus'
|
2010-05-28 15:56:00 -07:00
|
|
|
];
|
|
|
|
|
2010-07-13 16:38:51 -07:00
|
|
|
events.forEach(function(event) {
|
2010-05-28 15:56:00 -07:00
|
|
|
iQ.fn[event] = function(func) {
|
|
|
|
return this.bind(event, func);
|
|
|
|
};
|
|
|
|
});
|
|
|
|
})();
|
|
|
|
|
2010-05-25 17:04:59 -07:00
|
|
|
// ----------
|
|
|
|
// All iQ objects should point back to these
|
|
|
|
rootiQ = iQ(document);
|
|
|
|
|
|
|
|
// ----------
|
|
|
|
// Expose iQ to the global object
|
|
|
|
window.iQ = iQ;
|
|
|
|
|
|
|
|
})(window);
|