new Items( template )

This class controls everything related to items and serves as the base class for the various paging types.

Parameters
Name Type Description
template FooGallery.Template

The template for this component.

Members


tmpl :FooGallery.Template

The template that created this component.

Methods


loadable( items ) → {Array.<FooGallery.Item>}

Filter the supplied items and return only those that can be loaded.

Parameters
Name Type Description
items Array.<FooGallery.Item>

The items to filter.

Returns

creatable( items ) → {Array.<FooGallery.Item>}

Filter the supplied items and return only those that can be created.

Parameters
Name Type Description
items Array.<FooGallery.Item>

The items to filter.

Returns

appendable( items ) → {Array.<FooGallery.Item>}

Filter the supplied items and return only those that can be appended.

Parameters
Name Type Description
items Array.<FooGallery.Item>

The items to filter.

Returns

detachable( items ) → {Array.<FooGallery.Item>}

Filter the supplied items and return only those that can be detached.

Parameters
Name Type Description
items Array.<FooGallery.Item>

The items to filter.

Returns

jquerify( items ) → {jQuery}

Get a single jQuery object containing all the supplied items' elements.

Parameters
Name Type Description
items Array.<FooGallery.Item>

The items to get a jQuery object for.

Returns

make( items ) → {Array.<FooGallery.Item>}

Makes a jQuery object, NodeList or an array of elements or item options, into an array of item objects.

Parameters
Name Type Description
items jQuery | NodeList | Array.<Node> | Array.<FooGallery.Item~Options>

The value to convert into an array of items.

Returns

The array of items successfully made.

Fires
Raised before the template makes an array of elements or item options into an array of item objects.
Raised after the template has made an array of item objects.
Raised after the template has parsed any elements into an array of item objects.

create( items [, append ] ) → {Array.<FooGallery.Item>}

Create each of the supplied items elements.

Description

This will only create and/or append items that are not already created and/or appended so it is safe to call without worrying about the items' pre-existing state.

Parameters
Name Type Attributes Default Description
items Array.<FooGallery.Item>

The array of items to create.

append boolean <optional>
false

Whether or not to automatically append the item after it is created.

Returns

The array of items that were created or if append is true the array of items that were appended.

Fires
Raised before the template creates the `items` elements.
Raised after the template has created the `items` elements.
Raised before the template appends any items to itself.
Raised after the template has appended items to itself.

append( items ) → {Array.<FooGallery.Item>}

Append each of the supplied items to the template.

Parameters
Name Type Description
items Array.<FooGallery.Item>

The array of items to append.

Returns

The array of items that were appended.

Fires
Raised before the template appends any items to itself.
Raised after the template has appended items to itself.

detach( items ) → {Array.<FooGallery.Item>}

Detach each of the supplied items from the template.

Parameters
Name Type Description
items Array.<FooGallery.Item>

The array of items to detach.

Returns

The array of items that were detached.

Fires
Raised before the template detaches any items from itself.
Raised after the template has detached items from itself.

load( items ) → {Promise.<Array.<FooGallery.Item>>}

Load each of the supplied items images.

Parameters
Name Type Description
items Array.<FooGallery.Item>

The array of items to load.

Returns

Resolved with an array of items as the first argument. If no items are loaded this array is empty.

Fires
Raised before the template loads any items.
Raised after the template has loaded items.

destroy()

Destroy the component making it ready for garbage collection.


<static> extend( [ definition ] ) → {function}

Creates a new class that inherits from this one which in turn allows itself to be extended.

Description

Every class created using this method has both the extend and override static methods added to it to allow it to be extended.

Parameters
Name Type Attributes Description
definition Object <optional>

An object containing any methods to implement/override.

Returns

A new class that inherits from the base class.

Examples

The below shows an example of how to implement inheritance using this method.


// create a base Person class
var Person = FooGallery.utils.Class.extend({
	construct: function(isDancing){
		this.dancing = isDancing;
	},
	dance: function(){
		return this.dancing;
	}
});

var Ninja = Person.extend({
	construct: function(){
		// Call the inherited version of construct()
		this._super( false );
	},
	dance: function(){
		// Call the inherited version of dance()
		return this._super();
	},
	swingSword: function(){
		return true;
	}
});

var p = new Person(true);
console.log( p.dance() ); // => true

var n = new Ninja();
console.log( n.dance() ); // => false
console.log( n.swingSword() ); // => true
console.log(
	p instanceof Person && p.constructor === Person && p instanceof FooGallery.utils.Class
	&& n instanceof Ninja && n.constructor === Ninja && n instanceof Person && n instanceof FooGallery.utils.Class
); // => true


<static> override( name, fn )

Overrides a single method on this class.

Description

This is a helper method for overriding a single function of a FooGallery.utils.Class or one of its child classes. This uses the FooGallery.utils.fn.addOrOverride method internally and simply provides the correct prototype.

Parameters
Name Type Description
name string

The name of the function to override.

fn function

The new function to override with, the _super method will be made available within this function.

Examples

The below example wraps the Person.prototype.dance method with a new one that inverts the result. Note the override applies even to instances of the class that are already created.


var Person = FooGallery.utils.Class.extend({
  construct: function(isDancing){
    this.dancing = isDancing;
  },
  dance: function(){
    return this.dancing;
  }
});

var p = new Person(true);
console.log( p.dance() ); // => true

Person.override("dance", function(){
	// Call the original version of dance()
	return !this._super();
});

console.log( p.dance() ); // => false