diff --git a/browser/base/content/tabcandy/core/iq.js b/browser/base/content/tabcandy/core/iq.js index b57332c855d..8c773d63772 100644 --- a/browser/base/content/tabcandy/core/iq.js +++ b/browser/base/content/tabcandy/core/iq.js @@ -45,7 +45,7 @@ // ********** // Title: iq.js -// jQuery, hacked down to just the bits we need, with a bunch of other stuff added. +// Various helper functions, in the vein of jQuery. (function( window, undefined ) { @@ -239,6 +239,7 @@ iQ.fn = iQ.prototype = { // ---------- // Function: addClass + // Adds the given class(es) to the receiver. addClass: function( value ) { if ( iQ.isFunction(value) ) { Utils.assert('does not support function argument', false); @@ -261,6 +262,7 @@ iQ.fn = iQ.prototype = { // ---------- // Function: removeClass + // Removes the given class(es) from the receiver. removeClass: function( value ) { if ( iQ.isFunction(value) ) { Utils.assert('does not support function argument', false); @@ -287,6 +289,7 @@ iQ.fn = iQ.prototype = { // ---------- // Function: hasClass + // Returns true is the receiver has the given css class. hasClass: function( selector ) { for ( var i = 0, l = this.length; i < l; i++ ) { if ( this[i].classList.contains( selector ) ) { @@ -298,6 +301,8 @@ iQ.fn = iQ.prototype = { // ---------- // Function: find + // Searches the receiver and its children, returning a new iQ object with + // elements that match the given selector. find: function( selector ) { var ret = [], length = 0; @@ -327,6 +332,7 @@ iQ.fn = iQ.prototype = { // ---------- // Function: remove + // Removes the receiver from the DOM. remove: function(unused) { Utils.assert('does not accept a selector', unused === undefined); for ( var i = 0, elem; (elem = this[i]) != null; i++ ) { @@ -340,6 +346,7 @@ iQ.fn = iQ.prototype = { // ---------- // Function: empty + // Removes all of the reciever's children and HTML content from the DOM. empty: function() { for ( var i = 0, elem; (elem = this[i]) != null; i++ ) { while ( elem.firstChild ) { @@ -352,6 +359,7 @@ iQ.fn = iQ.prototype = { // ---------- // Function: width + // Returns the width of the receiver. width: function(unused) { Utils.assert('does not yet support setting', unused === undefined); return parseInt(this.css('width')); @@ -359,6 +367,7 @@ iQ.fn = iQ.prototype = { // ---------- // Function: height + // Returns the height of the receiver. height: function(unused) { Utils.assert('does not yet support setting', unused === undefined); return parseInt(this.css('height')); @@ -366,6 +375,7 @@ iQ.fn = iQ.prototype = { // ---------- // Function: position + // Returns an object with the receiver's position in left and top properties. position: function(unused) { Utils.assert('does not yet support setting', unused === undefined); return { @@ -376,6 +386,7 @@ iQ.fn = iQ.prototype = { // ---------- // Function: bounds + // Returns a with the receiver's bounds. bounds: function(unused) { Utils.assert('does not yet support setting', unused === undefined); var p = this.position(); @@ -384,6 +395,8 @@ iQ.fn = iQ.prototype = { // ---------- // Function: data + // Pass in both key and value to attach some data to the receiver; + // pass in just key to retrieve it. data: function(key, value) { var data = null; if (value === undefined) { @@ -406,6 +419,7 @@ iQ.fn = iQ.prototype = { // ---------- // Function: html + // Given a value, sets the receiver's innerHTML to it; otherwise returns what's already there. // TODO: security html: function(value) { Utils.assert('does not yet support multi-objects (or null objects)', this.length == 1); @@ -418,6 +432,7 @@ iQ.fn = iQ.prototype = { // ---------- // Function: text + // Given a value, sets the receiver's textContent to it; otherwise returns what's already there. text: function(value) { Utils.assert('does not yet support multi-objects (or null objects)', this.length == 1); if (value === undefined) { @@ -429,6 +444,7 @@ iQ.fn = iQ.prototype = { // ---------- // Function: val + // Given a value, sets the receiver's value to it; otherwise returns what's already there. val: function(value) { Utils.assert('does not yet support multi-objects (or null objects)', this.length == 1); if (value === undefined) { @@ -441,6 +457,7 @@ iQ.fn = iQ.prototype = { // ---------- // Function: appendTo + // Appends the receiver to the result of iQ(selector). appendTo: function(selector) { Utils.assert('does not yet support multi-objects (or null objects)', this.length == 1); iQ(selector).append(this); @@ -449,6 +466,7 @@ iQ.fn = iQ.prototype = { // ---------- // Function: append + // Appends the result of iQ(selector) to the receiver. append: function(selector) { Utils.assert('does not yet support multi-objects (or null objects)', this.length == 1); var object = iQ(selector); @@ -479,6 +497,13 @@ iQ.fn = iQ.prototype = { // ---------- // Function: css + // Sets or gets CSS properties on the receiver. When setting certain numerical properties, + // will automatically add "px". + // + // Possible call patterns: + // a: object, b: undefined - sets with properties from a + // a: string, b: undefined - gets property specified by a + // a: string, b: string/number - sets property specified by a to b css: function(a, b) { var properties = null; @@ -596,6 +621,7 @@ iQ.fn = iQ.prototype = { // ---------- // Function: fadeOut + // Animates the receiver to full transparency. Calls callback on completion. fadeOut: function(callback) { try { Utils.assert('does not yet support duration', iQ.isFunction(callback) || callback === undefined); @@ -618,6 +644,7 @@ iQ.fn = iQ.prototype = { // ---------- // Function: fadeIn + // Animates the receiver to full opacity. fadeIn: function() { try { this.css({display: ''}); @@ -635,6 +662,7 @@ iQ.fn = iQ.prototype = { // ---------- // Function: hide + // Hides the receiver. hide: function() { try { this.css({display: 'none', opacity: 0}); @@ -647,6 +675,7 @@ iQ.fn = iQ.prototype = { // ---------- // Function: show + // Shows the receiver. show: function() { try { this.css({display: '', opacity: 1}); @@ -692,6 +721,8 @@ iQ.fn = iQ.prototype = { // ---------- // Function: one + // Binds the given function to the given event type, but only for one call; + // automatically unbinds after the event fires once. one: function(type, func) { Utils.assert('does not support eventData argument', iQ.isFunction(func)); @@ -705,6 +736,7 @@ iQ.fn = iQ.prototype = { // ---------- // Function: unbind + // Unbinds the given function from the given event type. unbind: function(type, func) { Utils.assert('Must provide a function', iQ.isFunction(func)); @@ -732,8 +764,13 @@ iQ.fn = iQ.prototype = { // Give the init function the iQ prototype for later instantiation iQ.fn.init.prototype = iQ.fn; +// ########## +// Class: iQ +// Additional utility functions. + // ---------- // Function: extend +// Pass several objects in and it will combine them all into the first object and return it. iQ.extend = iQ.fn.extend = function() { // copy reference to target object var target = arguments[0] || {}, i = 1, length = arguments.length, deep = false, options, name, src, copy; @@ -790,35 +827,24 @@ iQ.extend = iQ.fn.extend = function() { return target; }; -// ########## -// Class: iQ -// Singleton iQ.extend({ - // ---------- - // Variable: animationCount - // For internal use only - animationCount: 0, - - // ---------- - // Function: isAnimating - isAnimating: function() { - return (this.animationCount != 0); - }, - // ----------- // Function: isFunction + // Returns true if the given object is a function. isFunction: function( obj ) { return toString.call(obj) === "[object Function]"; }, // ---------- // Function: isArray + // Returns true if the given object is an array. isArray: function( obj ) { return toString.call(obj) === "[object Array]"; }, // ---------- // Function: isPlainObject + // Check to see if an object is a plain object (created using "{}" or "new Object"). isPlainObject: function( obj ) { // Must be an Object. // Because of IE, we also have to check the presence of the constructor property. @@ -845,6 +871,7 @@ iQ.extend({ // ---------- // Function: isEmptyObject + // Returns true if the given object has no members. isEmptyObject: function( obj ) { for ( var name in obj ) { return false; @@ -854,6 +881,7 @@ iQ.extend({ // ---------- // Function: merge + // Merge two arrays and return the result. merge: function( first, second ) { var i = first.length, j = 0; diff --git a/browser/base/content/tabcandy/core/tabs.js b/browser/base/content/tabcandy/core/tabs.js index 6fc20f2a34b..f6b3a85038c 100644 --- a/browser/base/content/tabcandy/core/tabs.js +++ b/browser/base/content/tabcandy/core/tabs.js @@ -159,8 +159,7 @@ function ImmutableArray(baseArray) { // Class: Extension // Singleton var Extension = { - // === {{{Extension.addUnloadMethod()}}} === - // + // Function: addUnloadMethod // This attaches a given method called 'unload' to the given object. // The method is also tied to the Extension page's lifetime, so if // the unload method isn't called before the page is unloaded, it is @@ -168,7 +167,6 @@ var Extension = { // don't propagate past Extension page reloads, and it can also help // developers find objects that aren't being properly cleaned up // before the page is unloaded. - addUnloadMethod: function addUnloadMethod(obj, unloader) { function unloadWrapper() { window.removeEventListener("unload", unloadWrapper, true); @@ -186,6 +184,8 @@ var Extension = { function EventListenerMixIns(mixInto) { var mixIns = {}; + // ---------- + // Function: add this.add = function add(options) { if (mixIns) { if (options.name in mixIns) @@ -195,6 +195,8 @@ function EventListenerMixIns(mixInto) { } }; + // ---------- + // Function: bubble this.bubble = function bubble(name, target, event) { if (mixIns) mixIns[name].trigger(target, event); @@ -256,6 +258,8 @@ function EventListenerMixIn(options) { } }; + // ---------- + // Function: trigger this.trigger = function trigger(target, event) { onEvent(event, target); };