Members
-
<readonly> apiEnabled :boolean
Whether or not the history API is enabled in the current browser.
-
Details
-
opt :FooGallery.State~Options
The state specific options for the template.
-
Details
-
enabled :boolean
Whether or not the component is enabled.
-
Details
-
pushOrReplace :string
Which method of the history API to use by default when updating the state.
-
Details
-
<readonly> regex :Object
An object containing regular expressions used to test and parse a hash value into a state object.
-
tmpl :FooGallery.Template
The template that created this component.
-
Details
Methods
-
destroy()
Destroy the component clearing any current state from the url and preparing it for garbage collection.
-
Details
-
isPushOrReplace( value ) → {boolean}
Check if the supplied value is
"push"
or"replace"
. -
Parameters
Name Type Description value
* The value to check.
Returns
Details
-
exists() → {boolean}
Check if the current url contains state for this template.
-
Returns
Details
-
parse() → {object}
Parse the current url returning an object containing all values for the template.
-
Description
This method always returns an object, if successful the object contains properties otherwise it is just a plain empty object. For this method to be successful the current template id must match the one from the url.
Returns
Details
-
hashify( state ) → {string}
Converts the supplied state object into a string value to use as a hash.
-
Parameters
Name Type Description state
object The object to hashify.
Returns
Details
-
replace( state )
Replace the current state with the one supplied.
-
Parameters
Name Type Description state
object The state to replace the current with.
Details
-
push( state )
Push the supplied
state
into the browser history. -
Parameters
Name Type Description state
object The state to push.
Details
-
update( state [, pushOrReplace ] )
Update the browser history using the supplied
state
. -
Parameters
Name Type Attributes Description state
object The state to update.
pushOrReplace
string <optional> The method to use to update the state. If not supplied this falls back to the value of the pushOrReplace property.
Details
-
clear()
Clear the template state from the current browser history if it exists.
-
Details
-
initial() → {FooGallery~State}
Get the initial start up state of the template.
-
Description
This method returns an initial start up state from the template options.
Returns
Details
-
get( [ item ] ) → {FooGallery~State}
Get the current state of the template.
-
Description
This method does not parse the history or url it returns the current state of the template itself. To parse the current url use the parse method instead.
Parameters
Name Type Attributes Description item
FooGallery.Item <optional> If supplied the items' id is included in the resulting state object.
Returns
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 definition
Object <optional> An object containing any methods to implement/override.
Returns
Examples
// 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
Details
-
<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
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
Details
-
set( state )
Set the current state of the template.
-
Description
This method does not set the history or url it sets the current state of the template itself. To update the url use the update method instead.
Parameters
Name Type Description state
FooGallery~State The state to set the template to.
Details
Type Definitions
-
Options
An object containing the state options for the template.
-
Properties
Name Type Attributes Default Description enabled
boolean <optional> false Whether or not state is enabled for the template.
pushOrReplace
string <optional> "replace" Which method of the history API to use by default when updating the state.
values
string <optional> "/" The delimiter used between key value pairs in the hash.
pair
string <optional> ":" The delimiter used between a key and a value in the hash.
array
string <optional> "+" The delimiter used for array values in the hash.
Details