Members
-
<nullable> masonry :Masonry
The current Masonry instance for the template.
-
Description
This value is
nulluntil after thepre-init.foogalleryevent has been raised.Details
-
cls :FooGallery.MasonryTemplate~CSSClasses
The CSS classes for the Masonry template.
-
Details
-
sel :FooGallery.MasonryTemplate~CSSSelectors
The CSS selectors for the Masonry template.
-
Details
-
$el :jQuery
The jQuery object for the template container.
-
Details
-
opt :FooGallery~Options
The options for the template.
-
Details
-
template :object
Any custom options for the template.
-
Details
-
id :string
The ID for the template.
-
Details
-
createdSelf :boolean
Whether or not the template created its' own container element.
-
Details
-
il8n :FooGallery~il8n
The il8n strings for the template.
-
Details
-
items :FooGallery.Items
The item manager for the template.
-
Details
-
<nullable> pages :FooGallery.Paging
The page manager for the template.
-
Details
-
state :FooGallery.State
The state manager for the template.
-
Details
Methods
-
<protected> create() → {jQuery}
Create a new container element for the template returning the jQuery object.
-
Returns
Examples
The following displays the raw HTML output by this method.
<div id="{current template id}" class="foogallery fg-masonry {additional classes}"> <div class="fg-column-width"></div> <div class="fg-gutter-width"></div> </div>Details
-
<protected> onPreInit( event, self )
Listens for the
pre-init.foogalleryevent. -
Description
Performs all pre-initialization work required by the Masonry template, specifically handling the
layoutoption and building up the required Masonry options.Parameters
Name Type Description eventjQuery.Event The jQuery.Event object for the event.
selfFooGallery.MasonryTemplate The current instance of the template.
Details
-
<protected> onParsedItems( event, self, items )
Listens for the
parsed-items.foogalleryevent. -
Description
Instructs Masonry to perform a layout operation whenever items are parsed.
Parameters
Name Type Description eventjQuery.Event The jQuery.Event object for the event.
selfFooGallery.MasonryTemplate The current instance of the template.
itemsArray.<FooGallery.Item> The array of items that were parsed.
Details
-
<protected> onAppendedItems( event, self, items )
Listens for the
appended-items.foogalleryevent. -
Description
Instructs Masonry to perform a layout operation whenever items are appended.
Parameters
Name Type Description eventjQuery.Event The jQuery.Event object for the event.
selfFooGallery.MasonryTemplate The current instance of the template.
itemsArray.<FooGallery.Item> The array of items that were parsed.
Details
-
<protected> onDetachItem( event, self, item )
Listens for the
detach-item.foogalleryevent. -
Description
If not already overridden this method will override the default logic to detach an item and replace it with Masonry specific logic.
Parameters
Name Type Description eventjQuery.Event The jQuery.Event object for the event.
selfFooGallery.MasonryTemplate The current instance of the template.
itemFooGallery.Item The item to detach.
Details
-
<protected> onDetachedItems( event, self, items )
Listens for the
detached-items.foogalleryevent. -
Description
Instructs Masonry to perform a layout operation whenever items are detached.
Parameters
Name Type Description eventjQuery.Event The jQuery.Event object for the event.
selfFooGallery.MasonryTemplate The current instance of the template.
itemsArray.<FooGallery.Item> The array of items that were detached.
Details
-
initialize( [ parent ] ) → {Promise.<FooGallery.Template>}
Initialize the template.
-
Description
Once resolved all options, objects and elements required by the template have been parsed or created and the initial load is complete.
Parameters
Name Type Attributes Description parentjQuery | HTMLElement | string <optional> If no element was supplied to the constructor you must supply a parent element for the template to append itself to. This can be a jQuery object, HTMLElement or a CSS selector.
Returns
Fires
Details
-
destroy()
Destroy the template.
-
Description
Once this method is called it can not be stopped and the template will be destroyed.
Fires
Details
-
loadAvailable() → {Promise.<Array.<FooGallery.Item>>}
Check if any available items need to be loaded and loads them.
-
Returns
Details
-
raise( eventName [, args ] ) → {jQuery.Event}
Raises the supplied
eventNameon the template element. -
Description
This method also executes any listeners set on the template object itself. These listeners are not bound to the element but are executed after the event is raised but before any default logic is executed. The names of these listeners use the following convention; prefix the
eventNamewith"on-"and then camel-case the result. e.g."pre-init"becomesonPreInit.Parameters
Name Type Attributes Description eventNamestring The name of the event to raise.
argsArray <optional> An additional arguments to supply to the listeners for the event.
Returns
Examples
The following displays a listener for the
"pre-init.foogallery"event in a sub-classed template.FooGallery.MyTemplate = FooGallery.Template.extend({ onPreInit: function(event, template){ // do something } });Details
-
<static> extend( [ definition ] ) → {function}
Creates a new class that inherits from this one which in turn allows itself to be extended.
-
Description
Parameters
Name Type Attributes Description definitionObject <optional> An object containing any methods to implement/override.
Returns
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 ); // => trueDetails
-
<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 namestring The name of the function to override.
fnfunction The new function to override with, the
_supermethod will be made available within this function.Examples
The below example wraps the
Person.prototype.dancemethod 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() ); // => falseDetails
Type Definitions
-
Options
An object containing the default options for the Masonry template.
-
Description
Apart from the
layoutoption the template object is identical to the standard Masonry options.
Note that the template overrides and sets its' own values for the following options based primarily on thelayoutvalue;itemSelector,columnWidth,gutter,isFitWidth,percentPositionandtransitionDuration.
Thelayoutvalue can be classed into two categories, fixed width and column type layouts. You can see in the examples below the options the template sets for each of these types of layouts.Properties
Name Type Attributes Description templateobject <optional> An object containing the custom options for the Masonry template.
Name Type Attributes Default Description layoutstring <optional> "col4" The layout to use for the template; "fixed", "col2", "col3", "col4" or "col5".
clsFooGallery.MasonryTemplate~CSSClasses <optional> An object containing all CSS classes for the Masonry template.
Examples
For both fixed and column layouts the template sets the below option values.
{ "itemSelector": ".fg-item", // this selector is generated from the classes.item.elem value. "columnWidth": ".fg-column-width", // this selector is generated from the classes.masonry.columnWidth value. "gutter": ".fg-gutter-width", // this selector is generated from the classes.masonry.gutterWidth value. "transitionDuration": 0 // disables masonry's inline transitions to prevent them overriding our CSS class transitions }For fixed layouts (
"fixed") the template sets the below options. If a number was supplied for thecolumnWidthorgutteroptions it is applied to the relevant elements before they are replaced by the selector seen above.{ "isFitWidth": true, "percentPosition": false }For column layouts (
"col2","col3","col4","col5") the template sets the below options.{ "isFitWidth": false, "percentPosition": true }Details
-
CSSClasses
An object containing the default CSS classes for the Masonry template.
-
Properties
Name Type Attributes Default Description containerstring <optional> "foogallery fg-masonry" The base CSS class names to apply to the container element.
columnWidthstring <optional> "fg-column-width" The CSS class name to apply to the Masonry column sizer element.
gutterWidthstring <optional> "fg-gutter-width" The CSS class name to apply to the Masonry gutter sizer element.
layoutobject <optional> An object containing all layout classes.
Name Type Attributes Default Description fixedstring <optional> "fg-masonry-fixed" The CSS class name for a fixed width layout.
col2string <optional> "fg-masonry-2col" The CSS class name for a two column layout.
col3string <optional> "fg-masonry-3col" The CSS class name for a three column layout.
col4string <optional> "fg-masonry-4col" The CSS class name for a four column layout.
col5string <optional> "fg-masonry-5col" The CSS class name for a five column layout.
layoutsstring <optional> "fg-masonry-fixed fg-masonry-2col fg-masonry-3col fg-masonry-4col fg-masonry-5col" A space delimited string of all CSS class names from the
layoutobject.Details
-
CSSSelectors
An object containing all CSS selectors for the Masonry template.
-
Description
This object is automatically generated from a classes object and its properties mirror those except the class name values are converted into CSS selectors.
Properties
Name Type Attributes Default Description containerstring <optional> ".foogallery.fg-masonry" The CSS selector for the container element.
columnWidthstring <optional> ".fg-column-width" The CSS selector for the Masonry column sizer element.
gutterWidthstring <optional> ".fg-gutter-width" The CSS selector for the Masonry gutter sizer element.
layoutobject <optional> An object containing all layout CSS selectors.
Name Type Attributes Default Description fixedstring <optional> ".fg-masonry-fixed" The CSS selector for a fixed width layout.
col2string <optional> ".fg-masonry-2col" The CSS selector for a two column layout.
col3string <optional> ".fg-masonry-3col" The CSS selector for a three column layout.
col4string <optional> ".fg-masonry-4col" The CSS selector for a four column layout.
col5string <optional> ".fg-masonry-5col" The CSS selector for a five column layout.
Details