new Item( template [, options ] )

The base class for an item.

Parameters
Name Type Attributes Description
template FooGallery.Template

The template this item belongs to.

options FooGallery.Item~Options <optional>

The options to initialize the item with.

Members


<readonly> isAttached :boolean

Whether or not the items' elements are appended to the template.

Details
boolean

<readonly> isCreated :boolean

Whether or not the items' elements are created and can be used.

Details
boolean

<readonly> isLoading :boolean

Whether or not the items' image is currently loading.

Details
boolean

<readonly> isLoaded :boolean

Whether or not the items' image has been loaded.

Details
boolean

<readonly> isError :boolean

Whether or not the items' image threw an error while loading.

Details
boolean

<nullable> $el :jQuery

Details
jQuery

<nullable> $inner :jQuery

Details
jQuery

<nullable> $anchor :jQuery

Details
jQuery

<nullable> $image :jQuery

Details
jQuery

<nullable> $caption :jQuery

Details
jQuery

id :string

Details
string

href :string

Details
string

src :string

Details
string

srcset :string

Details
string

width :number

Details
number

height :number

Details
number

title :string

Details
string

description :string

Details
string

attrItem :FooGallery.Item~Attributes


tags :Array.<string>

Details
Array.<string>

<nullable> maxWidth :FooGallery.Item~maxWidthCallback


tmpl :FooGallery.Template

The template that created this component.

Methods


destroy()

Destroy the item preparing it for garbage collection.


parse( element ) → {boolean}

Parse the supplied element updating the current items' properties.

Parameters
Name Type Description
element jQuery | HTMLElement | string

The element to parse.

Returns
Fires
Raised when an item needs to parse properties from an element.
Raised after an item has been parsed from an element.

create() → {boolean}

Create the items' DOM elements and populate the corresponding properties.

Returns
Fires
Raised when an item needs to create its' elements.
Raised after an items' elements have been created.

append() → {boolean}

Append the item to the current template.

Returns
Fires
Raised when an item needs to append its elements to the template.
Raised after an item has appended its' elements to the template.

detach() → {boolean}

Detach the item from the current template preserving its' data and events.

Returns

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

Load the items' $image.

Returns

fix() → {FooGallery.Item}

Attempts to set a inline width and height on the $image to prevent layout jumps.


unfix() → {FooGallery.Item}

Removes any inline width and height values set on the $image.


getThumbUrl( [ refresh ] ) → {string}

Inspect the src and srcset properties to determine which url to load for the thumb.

Parameters
Name Type Attributes Default Description
refresh boolean <optional>
false

Whether or not to force refreshing of the cached value.

Returns

scrollTo()

Scroll the item into the center of the viewport.


bounds() → {FooGallery.utils.Bounds}

Get the bounds for the item.


intersects( bounds ) → {boolean}

Checks if the item bounds intersects the supplied bounds.

Parameters
Name Type Description
bounds FooGallery.utils.Bounds

The bounds to check.

Returns

<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

Type Definitions


maxWidthCallback( item ) → {number}

Called when setting an items' image size to prevent layout jumps.

Parameters
Name Type Description
item FooGallery.Item

The item to determine the maxWidth for.

Returns

Returns the maximum width allowed for the $image element.

Examples

An example of the default behavior this callback replaces would look like the below.


{
	"maxWidth": function(item){
		return item.$image.outerWidth();
	}
}
Details
function

Options

A simple object containing an items' default values.

Properties
Name Type Attributes Default Description
id string <optional>
<nullable>

The data-id attribute for the outer element.

href string <optional>
<nullable>

The href attribute for the anchor element.

src string <optional>
<nullable>

The src attribute for the image element.

srcset string <optional>
<nullable>

The srcset attribute for the image element.

width number <optional>
0

The width of the image.

height number <optional>
0

The height of the image.

title string <optional>
<nullable>

The title for the image.

description string <optional>
<nullable>

The description for the image.

tags Array.<string> <optional>
[]

The data-tags attribute for the outer element.

maxWidth FooGallery.Item~maxWidthCallback <optional>
<nullable>

Called when setting an items' image size. If not supplied the images outer width is used.

attr FooGallery.Item~Attributes <optional>

Additional attributes to apply to the items' elements.

Details
object

CSSClasses

A simple object containing the CSS classes used by an item.

Properties
Name Type Attributes Default Description
elem string <optional>
"fg-item"

The CSS class for the outer containing div element of an item.

inner string <optional>
"fg-item-inner"

The CSS class for the inner containing div element of an item.

anchor string <optional>
"fg-thumb"

The CSS class for the a element of an item.

image string <optional>
"fg-image"

The CSS class for the img element of an item.

loading string <optional>
"fg-idle"

The CSS class applied to an item that is waiting to be loaded.

loading string <optional>
"fg-loading"

The CSS class applied to an item while it is loading.

loaded string <optional>
"fg-loaded"

The CSS class applied to an item once it is loaded.

error string <optional>
"fg-error"

The CSS class applied to an item if it throws an error while loading.

caption object <optional>

A simple object containing the CSS classes used by an items' caption.

Name Type Attributes Default Description
elem string <optional>
"fg-caption"

The CSS class for the outer containing div element of a caption.

inner string <optional>
"fg-caption-inner"

The CSS class for the inner containing div element of a caption.

title string <optional>
"fg-caption-title"

The CSS class for the title div element of a caption.

description string <optional>
"fg-caption-desc"

The CSS class for the description div element of a caption.

Details
object

Attributes

A simple object used to store any additional attributes to apply to an items' elements.

Properties
Name Type Attributes Default Description
elem object <optional>
{}

The attributes to apply to the items' outer <div/> element.

inner object <optional>
{}

The attributes to apply to the items' inner element.

anchor object <optional>
{}

The attributes to apply to the items' anchor element.

image object <optional>
{}

The attributes to apply to the items' image element.

caption object <optional>

A simple object used to store any additional attributes to apply to an items' caption elements.

Name Type Attributes Default Description
elem object <optional>
{}

The attributes to apply to the captions' outer <div/> element.

inner object <optional>
{}

The attributes to apply to the captions' inner element.

title object <optional>
{}

The attributes to apply to the captions' title element.

description object <optional>
{}

The attributes to apply to the captions' description element.

Details
object