@@ -2968,10 +2968,11 @@ FooGallery.utils, FooGallery.utils.is, FooGallery.utils.str);
29682968 * @memberof FooGallery.utils.
29692969 * @class Timer
29702970 * @param {number } [interval=1000] - The internal tick interval of the timer.
2971+ * @augments FooGallery.utils.EventClass
29712972 */
29722973
29732974 _ . Timer = _ . EventClass . extend (
2974- /** @lends FooGallery.utils.Timer */
2975+ /** @lends FooGallery.utils.Timer.prototype */
29752976 {
29762977 /**
29772978 * @ignore
@@ -3258,6 +3259,7 @@ FooGallery.utils, FooGallery.utils.is, FooGallery.utils.str);
32583259 if ( self . isRunning ) {
32593260 self . isRunning = false ;
32603261 self . isPaused = true ;
3262+ self . canResume = self . __remaining > 0 ;
32613263 self . trigger ( "pause" , self . __eventArgs ( ) ) ;
32623264 }
32633265
@@ -4745,8 +4747,8 @@ FooGallery.utils.$, FooGallery.utils, FooGallery.utils.is, FooGallery.utils.fn);
47454747 reg . push ( this . registered [ name ] ) ;
47464748 }
47474749 reg . sort ( function ( a , b ) { return b . priority - a . priority ; } ) ;
4748- $ . each ( reg , function ( i , r ) {
4749- names . push ( r . name ) ;
4750+ reg . forEach ( function ( registered ) {
4751+ names . push ( registered . name ) ;
47504752 } ) ;
47514753 } else {
47524754 for ( name in this . registered ) {
@@ -4792,15 +4794,17 @@ FooGallery.utils.$, FooGallery.utils, FooGallery.utils.is, FooGallery.utils.fn);
47924794 } ;
47934795 return true ;
47944796 } ,
4795- load : function ( ) {
4796- var self = this , result = [ ] , reg = [ ] , name ;
4797+ load : function ( arg1 , argN ) {
4798+ var self = this , args = _fn . arg2arr ( arguments ) , result = [ ] , reg = [ ] , name ;
47974799 for ( name in self . registered ) {
47984800 if ( ! self . registered . hasOwnProperty ( name ) ) continue ;
47994801 reg . push ( self . registered [ name ] ) ;
48004802 }
48014803 reg . sort ( function ( a , b ) { return b . priority - a . priority ; } ) ;
4802- $ . each ( reg , function ( i , r ) {
4803- result . push ( self . make ( r . name ) ) ;
4804+ reg . forEach ( function ( registered ) {
4805+ var makeArgs = args . slice ( ) ;
4806+ makeArgs . unshift ( registered . name ) ;
4807+ result . push ( self . make . apply ( self , makeArgs ) ) ;
48044808 } ) ;
48054809 return result ;
48064810 } ,
@@ -5772,7 +5776,7 @@ FooGallery.utils.$, FooGallery.utils, FooGallery.utils.is, FooGallery.utils.fn);
57725776) ;
57735777( function ( $ , _ , _utils , _is , _str , _obj ) {
57745778
5775- _ . State = _ . Component . extend ( /** @lends FooGallery.State */ {
5779+ _ . State = _ . Component . extend ( /** @lends FooGallery.State.prototype */ {
57765780 /**
57775781 * @summary This class manages all the getting and setting of its' parent templates' state.
57785782 * @memberof FooGallery
@@ -5795,7 +5799,6 @@ FooGallery.utils.$, FooGallery.utils, FooGallery.utils.is, FooGallery.utils.fn);
57955799 * @memberof FooGallery.State#
57965800 * @name apiEnabled
57975801 * @type {boolean }
5798- * @readonly
57995802 */
58005803 self . apiEnabled = ! ! window . history && ! ! history . replaceState ;
58015804 /**
@@ -5851,6 +5854,20 @@ FooGallery.utils.$, FooGallery.utils, FooGallery.utils.is, FooGallery.utils.fn);
58515854 masked : new RegExp ( "^#" + masked + "\\" + values + ".+?" ) ,
58525855 values : new RegExp ( "(\\w+)" + pair + "([^" + values + "]+)" , "g" )
58535856 } ;
5857+ /**
5858+ * @summary Whether or not the component listens to the popstate event.
5859+ * @memberof FooGallery.State#
5860+ * @name usePopState
5861+ * @type {boolean }
5862+ */
5863+ self . usePopState = self . opt . usePopState ;
5864+ // force context
5865+ self . onPopState = self . onPopState . bind ( self ) ;
5866+ } ,
5867+ init : function ( ) {
5868+ var self = this ;
5869+ self . set ( self . initial ( ) ) ;
5870+ if ( self . enabled && self . apiEnabled && self . usePopState ) window . addEventListener ( 'popstate' , self . onPopState ) ;
58545871 } ,
58555872 /**
58565873 * @summary Destroy the component clearing any current state from the url and preparing it for garbage collection.
@@ -5860,13 +5877,11 @@ FooGallery.utils.$, FooGallery.utils, FooGallery.utils.is, FooGallery.utils.fn);
58605877 */
58615878 destroy : function ( preserve ) {
58625879 var self = this ;
5880+ if ( self . enabled && self . apiEnabled && self . usePopState ) window . removeEventListener ( 'popstate' , self . onPopState ) ;
58635881 if ( ! preserve ) self . clear ( ) ;
58645882 self . opt = self . regex = { } ;
58655883 self . _super ( ) ;
58665884 } ,
5867- init : function ( ) {
5868- this . set ( this . initial ( ) ) ;
5869- } ,
58705885 getIdNumber : function ( ) {
58715886 return this . tmpl . id . match ( / \d + / g) [ 0 ] ;
58725887 } ,
@@ -6096,6 +6111,12 @@ FooGallery.utils.$, FooGallery.utils, FooGallery.utils.is, FooGallery.utils.fn);
60966111 }
60976112 }
60986113 } ,
6114+ onPopState : function ( e ) {
6115+ var self = this , parsed = self . parse ( ) ;
6116+ if ( Object . keys ( parsed ) . length ) {
6117+ self . set ( parsed ) ;
6118+ }
6119+ }
60996120 } ) ;
61006121
61016122 _ . template . configure ( "core" , {
@@ -6104,6 +6125,7 @@ FooGallery.utils.$, FooGallery.utils, FooGallery.utils.is, FooGallery.utils.fn);
61046125 scrollTo : true ,
61056126 pushOrReplace : "replace" ,
61066127 mask : "foogallery-gallery-{id}" ,
6128+ usePopState : true ,
61076129 values : "/" ,
61086130 pair : ":" ,
61096131 array : "+" ,
@@ -6120,11 +6142,15 @@ FooGallery.utils.$, FooGallery.utils, FooGallery.utils.is, FooGallery.utils.fn);
61206142 /**
61216143 * @summary An object containing the state options for the template.
61226144 * @typedef {object } FooGallery.State~Options
6123- * @property {boolean } [enabled=false] - Whether or not state is enabled for the template.
6145+ * @property {boolean } [enabled=false] - Whether state is enabled for the template.
6146+ * @property {boolean } [scrollTo=true] - Whether the page is scrolled to the current state item.
61246147 * @property {string } [pushOrReplace="replace"] - Which method of the history API to use by default when updating the state.
6148+ * @property {string } [mask="foogallery-gallery-{id}"] - The mask used to generate the full ID from just the ID number.
6149+ * @property {boolean } [usePopState=true] - Whether state listens to the 'popstate' event and updates the gallery.
61256150 * @property {string } [values="/"] - The delimiter used between key value pairs in the hash.
61266151 * @property {string } [pair=":"] - The delimiter used between a key and a value in the hash.
61276152 * @property {string } [array="+"] - The delimiter used for array values in the hash.
6153+ * @property {string } [arraySeparator=","] - The delimiter used to separate multiple array values in the hash.
61286154 */
61296155
61306156 /**
@@ -6808,7 +6834,7 @@ FooGallery.utils.$, FooGallery.utils, FooGallery.utils.is, FooGallery.utils.fn);
68086834) ;
68096835( function ( $ , _ , _utils , _is , _fn , _obj , _str ) {
68106836
6811- _ . Item = _ . Component . extend ( /** @lends FooGallery.Item */ {
6837+ _ . Item = _ . Component . extend ( /** @lends FooGallery.Item.prototype */ {
68126838 /**
68136839 * @summary The base class for an item.
68146840 * @memberof FooGallery
@@ -7535,7 +7561,17 @@ FooGallery.utils.$, FooGallery.utils, FooGallery.utils.is, FooGallery.utils.fn);
75357561 _setAttributes : function ( element , attributes ) {
75367562 Object . keys ( attributes ) . forEach ( function ( key ) {
75377563 if ( ! _is . empty ( attributes [ key ] ) ) {
7538- element . setAttribute ( key , _is . string ( attributes [ key ] ) ? attributes [ key ] : JSON . stringify ( attributes [ key ] ) ) ;
7564+ if ( key === 'class' ) {
7565+ var classes = _is . array ( attributes [ key ] )
7566+ ? attributes [ key ]
7567+ : ( _is . string ( attributes [ key ] ) ? attributes [ key ] . split ( ' ' ) : [ ] ) ;
7568+
7569+ classes . forEach ( function ( className ) {
7570+ element . classList . add ( className ) ;
7571+ } ) ;
7572+ } else {
7573+ element . setAttribute ( key , _is . string ( attributes [ key ] ) ? attributes [ key ] : JSON . stringify ( attributes [ key ] ) ) ;
7574+ }
75397575 }
75407576 } ) ;
75417577 } ,
@@ -7575,12 +7611,15 @@ FooGallery.utils.$, FooGallery.utils, FooGallery.utils.is, FooGallery.utils.fn);
75757611
75767612 var elem = document . createElement ( "div" ) ;
75777613 self . _setAttributes ( elem , attr . elem ) ;
7578-
7579- elem . className = [ cls . elem , self . getTypeClass ( ) , exif , self . isLoaded ? cls . loaded : cls . idle ] . join ( " " ) ;
7614+ self . _setAttributes ( elem , {
7615+ "class" : [ cls . elem , self . getTypeClass ( ) , exif , self . isLoaded ? cls . loaded : cls . idle ]
7616+ } ) ;
75807617
75817618 var inner = document . createElement ( "figure" ) ;
75827619 self . _setAttributes ( inner , attr . inner ) ;
7583- inner . className = cls . inner ;
7620+ self . _setAttributes ( inner , {
7621+ "class" : cls . inner
7622+ } ) ;
75847623
75857624 var anchorClasses = [ cls . anchor ] ;
75867625 if ( self . noLightbox ) {
@@ -7670,11 +7709,15 @@ FooGallery.utils.$, FooGallery.utils, FooGallery.utils.is, FooGallery.utils.fn);
76707709
76717710 var caption = document . createElement ( "figcaption" ) ;
76727711 self . _setAttributes ( caption , attr . caption . elem ) ;
7673- caption . className = cls . caption . elem ;
7712+ self . _setAttributes ( caption , {
7713+ "class" : cls . caption . elem
7714+ } ) ;
76747715
76757716 var captionInner = document . createElement ( "div" ) ;
76767717 self . _setAttributes ( captionInner , attr . caption . inner ) ;
7677- captionInner . className = cls . caption . inner ;
7718+ self . _setAttributes ( captionInner , {
7719+ "class" : cls . caption . inner
7720+ } ) ;
76787721
76797722 var captionTitle = null , hasTitle = self . showCaptionTitle && _is . string ( self . caption ) && self . caption . length > 0 ;
76807723 if ( hasTitle ) {
0 commit comments