2016-04-04 21:31:15 -04:00
( function e ( t , n , r ) { function s ( o , u ) { if ( ! n [ o ] ) { if ( ! t [ o ] ) { var a = typeof require == "function" && require ; if ( ! u && a ) return a ( o , ! 0 ) ; if ( i ) return i ( o , ! 0 ) ; var f = new Error ( "Cannot find module '" + o + "'" ) ; throw f . code = "MODULE_NOT_FOUND" , f } var l = n [ o ] = { exports : { } } ; t [ o ] [ 0 ] . call ( l . exports , function ( e ) { var n = t [ o ] [ 1 ] [ e ] ; return s ( n ? n : e ) } , l , l . exports , e , t , n , r ) } return n [ o ] . exports } var i = typeof require == "function" && require ; for ( var o = 0 ; o < r . length ; o ++ ) s ( r [ o ] ) ; return s } ) ( { 1 : [ function ( require , module , exports ) {
'use strict' ;
2016-07-19 10:21:09 -04:00
var _environment = require ( './utils/environment' ) ;
var _html = require ( './utils/html' ) ;
2016-05-18 23:12:36 -04:00
var _globals = require ( './utils/globals' ) ;
var _globals2 = _interopRequireDefault ( _globals ) ;
2016-04-04 21:31:15 -04:00
var _modules = require ( './modules' ) ;
var modules = _interopRequireWildcard ( _modules ) ;
function _interopRequireWildcard ( obj ) { if ( obj && obj . _ _esModule ) { return obj ; } else { var newObj = { } ; if ( obj != null ) { for ( var key in obj ) { if ( Object . prototype . hasOwnProperty . call ( obj , key ) ) newObj [ key ] = obj [ key ] ; } } newObj . default = obj ; return newObj ; } }
2016-05-18 23:12:36 -04:00
function _interopRequireDefault ( obj ) { return obj && obj . _ _esModule ? obj : { default : obj } ; }
2016-07-14 14:41:30 -04:00
function _classCallCheck ( instance , Constructor ) { if ( ! ( instance instanceof Constructor ) ) { throw new TypeError ( "Cannot call a class as a function" ) ; } } /* jshint esnext: true */
2016-04-04 21:31:15 -04:00
2016-07-19 10:21:09 -04:00
// Global functions and tools
2016-04-04 21:31:15 -04:00
2016-07-19 10:21:09 -04:00
// Basic modules
2016-04-04 21:31:15 -04:00
2016-07-19 10:21:09 -04:00
var App = function ( ) {
function App ( ) {
var _this = this ;
2016-04-04 21:31:15 -04:00
2016-07-19 10:21:09 -04:00
_classCallCheck ( this , App ) ;
2016-04-04 21:31:15 -04:00
2016-07-19 10:21:09 -04:00
this . modules = modules ;
this . currentModules = [ ] ;
2016-04-04 21:31:15 -04:00
2016-07-19 10:21:09 -04:00
_environment . $document . on ( 'initModules.App' , function ( event ) {
_this . initGlobals ( event . firstBlood ) . deleteModules ( ) . initModules ( ) ;
} ) ;
}
2016-04-04 21:31:15 -04:00
2016-07-19 10:21:09 -04:00
/ * *
* Destroy all existing modules
* @ return { Object } this Allows chaining
* /
2016-04-04 21:31:15 -04:00
2016-07-19 10:21:09 -04:00
App . prototype . deleteModules = function deleteModules ( ) {
// Loop modules
var i = this . currentModules . length ;
2016-04-04 21:31:15 -04:00
2016-07-19 10:21:09 -04:00
// Destroy all modules
while ( i -- ) {
this . currentModules [ i ] . destroy ( ) ;
this . currentModules . splice ( i ) ;
}
2016-04-04 21:31:15 -04:00
2016-07-19 10:21:09 -04:00
return this ;
} ;
2016-04-04 21:31:15 -04:00
2016-07-19 10:21:09 -04:00
/ * *
* Execute global functions and settings
* Allows you to initialize global modules only once if you need
* ( ex . : when using Barba . js or SmoothState . js )
* @ return { Object } this Allows chaining
* /
2016-04-04 21:31:15 -04:00
2016-07-19 10:21:09 -04:00
App . prototype . initGlobals = function initGlobals ( firstBlood ) {
( 0 , _globals2 . default ) ( firstBlood ) ;
return this ;
} ;
2016-04-04 21:31:15 -04:00
2016-07-19 10:21:09 -04:00
/ * *
* Find modules and initialize them
* @ return { Object } this Allows chaining
* /
2016-07-14 14:41:30 -04:00
2016-04-04 21:31:15 -04:00
2016-07-19 10:21:09 -04:00
App . prototype . initModules = function initModules ( ) {
// Elements with module
var moduleEls = document . querySelectorAll ( '[data-module]' ) ;
2016-04-04 21:31:15 -04:00
2016-07-19 10:21:09 -04:00
// Loop through elements
var i = 0 ;
var elsLen = moduleEls . length ;
2016-04-04 21:31:15 -04:00
2016-07-19 10:21:09 -04:00
for ( ; i < elsLen ; i ++ ) {
2016-04-04 21:31:15 -04:00
2016-07-19 10:21:09 -04:00
// Current element
var el = moduleEls [ i ] ;
2016-04-04 21:31:15 -04:00
2016-07-19 10:21:09 -04:00
// All data- attributes considered as options
var options = ( 0 , _html . getNodeData ) ( el ) ;
2016-04-04 21:31:15 -04:00
2016-07-19 10:21:09 -04:00
// Add current DOM element and jQuery element
options . el = el ;
options . $el = $ ( el ) ;
2016-04-04 21:31:15 -04:00
2016-07-19 10:21:09 -04:00
// Module does exist at this point
var attr = options . module ;
2016-04-04 21:31:15 -04:00
2016-07-19 10:21:09 -04:00
// Splitting modules found in the data-attribute
var moduleIdents = attr . replace ( /\s/g , '' ) . split ( ',' ) ;
2016-07-14 14:41:30 -04:00
2016-07-19 10:21:09 -04:00
// Loop modules
var j = 0 ;
var modulesLen = moduleIdents . length ;
2016-07-14 14:41:30 -04:00
2016-07-19 10:21:09 -04:00
for ( ; j < modulesLen ; j ++ ) {
var moduleAttr = moduleIdents [ j ] ;
2016-04-04 21:31:15 -04:00
2016-07-19 10:21:09 -04:00
if ( typeof this . modules [ moduleAttr ] === 'function' ) {
var module = new this . modules [ moduleAttr ] ( options ) ;
this . currentModules . push ( module ) ;
}
}
}
2016-04-04 21:31:15 -04:00
2016-07-19 10:21:09 -04:00
return this ;
} ;
2016-04-04 21:31:15 -04:00
2016-07-19 10:21:09 -04:00
return App ;
} ( ) ;
2016-07-14 14:41:30 -04:00
2016-07-19 10:21:09 -04:00
// IIFE for loading the application
// ==========================================================================
2016-07-14 14:41:30 -04:00
2016-04-04 21:31:15 -04:00
2016-07-19 10:21:09 -04:00
( function ( ) {
window . App = new App ( ) ;
_environment . $document . trigger ( {
type : 'initModules.App' ,
firstBlood : true
} ) ;
} ) ( ) ;
2016-04-04 21:31:15 -04:00
2016-07-19 10:21:09 -04:00
} , { "./modules" : 3 , "./utils/environment" : 8 , "./utils/globals" : 9 , "./utils/html" : 10 } ] , 2 : [ function ( require , module , exports ) {
'use strict' ;
2016-04-04 21:31:15 -04:00
Object . defineProperty ( exports , "__esModule" , {
2016-07-19 10:21:09 -04:00
value : true
2016-04-04 21:31:15 -04:00
} ) ;
2016-07-19 10:21:09 -04:00
exports . scrollTo = scrollTo ;
/* jshint esnext: true */
var isAnimating = false ;
var defaults = {
easing : 'swing' ,
headerOffset : 60 ,
speed : 300
2016-05-18 23:12:36 -04:00
} ;
2016-04-04 21:31:15 -04:00
2016-07-19 10:21:09 -04:00
/ * *
* scrollTo is a function that scrolls a container to an element ' s position within that controller
* Uses jQuery ' s $ . Deferred to allow using a callback on animation completion
* @ param { object } $element A jQuery node
* @ param { object } options
* /
function scrollTo ( $element , options ) {
var deferred = $ . Deferred ( ) ;
// Drop everything if this ain't a jQuery object
if ( $element instanceof jQuery && $element . length > 0 ) {
// Merging options
options = $ . extend ( { } , defaults , typeof options !== 'undefined' ? options : { } ) ;
// Prevents accumulation of animations
if ( isAnimating === false ) {
isAnimating = true ;
// Default container that we'll be scrolling
var $container = $ ( 'html, body' ) ;
var elementOffset = 0 ;
// Testing container in options for jQuery-ness
// If we're not using a custom container, we take the top document offset
// If we are, we use the elements position relative to the container
if ( typeof options . $container !== 'undefined' && options . $container instanceof jQuery && options . $container . length > 0 ) {
$container = options . $container ;
elementOffset = $element . position ( ) . top ;
} else {
elementOffset = $element . offset ( ) . top ;
}
$container . animate ( {
scrollTop : elementOffset - options . headerOffset
} , options . speed , options . easing , function ( ) {
isAnimating = false ;
deferred . resolve ( ) ;
} ) ;
}
}
return deferred . promise ( ) ;
}
2016-05-18 23:12:36 -04:00
} , { } ] , 3 : [ function ( require , module , exports ) {
'use strict' ;
Object . defineProperty ( exports , "__esModule" , {
value : true
2016-04-04 21:31:15 -04:00
} ) ;
var _Button = require ( './modules/Button' ) ;
Object . defineProperty ( exports , 'Button' , {
enumerable : true ,
get : function get ( ) {
return _interopRequireDefault ( _Button ) . default ;
}
} ) ;
var _Title = require ( './modules/Title' ) ;
Object . defineProperty ( exports , 'Title' , {
enumerable : true ,
get : function get ( ) {
return _interopRequireDefault ( _Title ) . default ;
}
} ) ;
function _interopRequireDefault ( obj ) { return obj && obj . _ _esModule ? obj : { default : obj } ; }
2016-05-18 23:12:36 -04:00
} , { "./modules/Button" : 5 , "./modules/Title" : 6 } ] , 4 : [ function ( require , module , exports ) {
2016-04-04 21:31:15 -04:00
'use strict' ;
Object . defineProperty ( exports , "__esModule" , {
value : true
} ) ;
2016-05-18 23:12:36 -04:00
var _environment = require ( '../utils/environment' ) ;
2016-04-04 21:31:15 -04:00
2016-05-18 23:58:08 -04:00
function _classCallCheck ( instance , Constructor ) { if ( ! ( instance instanceof Constructor ) ) { throw new TypeError ( "Cannot call a class as a function" ) ; } } /* jshint esnext: true */
2016-04-04 21:31:15 -04:00
2016-05-18 23:12:36 -04:00
/ * *
* Abstract module
* Gives access to generic jQuery nodes
* /
2016-04-04 21:31:15 -04:00
2016-05-18 23:58:08 -04:00
var _class = function _class ( options ) {
_classCallCheck ( this , _class ) ;
2016-04-04 21:31:15 -04:00
2016-05-18 23:12:36 -04:00
this . $document = _environment . $document ;
this . $window = _environment . $window ;
this . $html = _environment . $html ;
this . $body = _environment . $body ;
this . $el = options . $el ;
2016-07-19 10:21:09 -04:00
this . el = options . el ;
2016-04-04 21:31:15 -04:00
} ;
2016-05-18 23:58:08 -04:00
exports . default = _class ;
2016-04-04 21:31:15 -04:00
2016-05-19 13:37:19 -04:00
} , { "../utils/environment" : 8 } ] , 5 : [ function ( require , module , exports ) {
2016-04-04 21:31:15 -04:00
'use strict' ;
Object . defineProperty ( exports , "__esModule" , {
value : true
} ) ;
2016-05-18 23:12:36 -04:00
var _AbstractModule2 = require ( './AbstractModule' ) ;
var _AbstractModule3 = _interopRequireDefault ( _AbstractModule2 ) ;
2016-04-04 21:31:15 -04:00
function _interopRequireDefault ( obj ) { return obj && obj . _ _esModule ? obj : { default : obj } ; }
function _classCallCheck ( instance , Constructor ) { if ( ! ( instance instanceof Constructor ) ) { throw new TypeError ( "Cannot call a class as a function" ) ; } }
function _possibleConstructorReturn ( self , call ) { if ( ! self ) { throw new ReferenceError ( "this hasn't been initialised - super() hasn't been called" ) ; } return call && ( typeof call === "object" || typeof call === "function" ) ? call : self ; }
2016-05-18 23:12:36 -04:00
function _inherits ( subClass , superClass ) { if ( typeof superClass !== "function" && superClass !== null ) { throw new TypeError ( "Super expression must either be null or a function, not " + typeof superClass ) ; } subClass . prototype = Object . create ( superClass && superClass . prototype , { constructor : { value : subClass , enumerable : false , writable : true , configurable : true } } ) ; if ( superClass ) Object . setPrototypeOf ? Object . setPrototypeOf ( subClass , superClass ) : subClass . _ _proto _ _ = superClass ; } /* jshint esnext: true */
2016-04-04 21:31:15 -04:00
2016-05-18 23:12:36 -04:00
var _class = function ( _AbstractModule ) {
_inherits ( _class , _AbstractModule ) ;
2016-04-04 21:31:15 -04:00
2016-05-18 23:12:36 -04:00
function _class ( options ) {
_classCallCheck ( this , _class ) ;
2016-04-04 21:31:15 -04:00
2016-07-14 14:41:30 -04:00
var _this = _possibleConstructorReturn ( this , _AbstractModule . call ( this , options ) ) ;
2016-04-04 21:31:15 -04:00
2016-05-19 13:37:19 -04:00
_this . $el . on ( 'click.Button' , function ( event ) {
_this . $document . trigger ( 'Title.changeLabel' , [ $ ( event . currentTarget ) . val ( ) ] ) ;
2016-05-18 23:12:36 -04:00
} ) ;
2016-04-04 21:31:15 -04:00
return _this ;
}
2016-07-14 14:41:30 -04:00
_class . prototype . destroy = function destroy ( ) {
this . $el . off ( '.Button' ) ;
} ;
2016-05-18 23:12:36 -04:00
return _class ;
} ( _AbstractModule3 . default ) ;
2016-04-04 21:31:15 -04:00
2016-05-18 23:12:36 -04:00
exports . default = _class ;
2016-04-04 21:31:15 -04:00
2016-05-18 23:12:36 -04:00
} , { "./AbstractModule" : 4 } ] , 6 : [ function ( require , module , exports ) {
2016-04-04 21:31:15 -04:00
'use strict' ;
Object . defineProperty ( exports , "__esModule" , {
value : true
} ) ;
2016-05-18 23:58:08 -04:00
var _visibility = require ( '../utils/visibility' ) ;
2016-05-18 23:12:36 -04:00
var _AbstractModule2 = require ( './AbstractModule' ) ;
2016-04-04 21:31:15 -04:00
2016-05-18 23:12:36 -04:00
var _AbstractModule3 = _interopRequireDefault ( _AbstractModule2 ) ;
2016-04-04 21:31:15 -04:00
function _interopRequireDefault ( obj ) { return obj && obj . _ _esModule ? obj : { default : obj } ; }
function _classCallCheck ( instance , Constructor ) { if ( ! ( instance instanceof Constructor ) ) { throw new TypeError ( "Cannot call a class as a function" ) ; } }
function _possibleConstructorReturn ( self , call ) { if ( ! self ) { throw new ReferenceError ( "this hasn't been initialised - super() hasn't been called" ) ; } return call && ( typeof call === "object" || typeof call === "function" ) ? call : self ; }
function _inherits ( subClass , superClass ) { if ( typeof superClass !== "function" && superClass !== null ) { throw new TypeError ( "Super expression must either be null or a function, not " + typeof superClass ) ; } subClass . prototype = Object . create ( superClass && superClass . prototype , { constructor : { value : subClass , enumerable : false , writable : true , configurable : true } } ) ; if ( superClass ) Object . setPrototypeOf ? Object . setPrototypeOf ( subClass , superClass ) : subClass . _ _proto _ _ = superClass ; } /* jshint esnext: true */
2016-05-18 23:12:36 -04:00
var _class = function ( _AbstractModule ) {
_inherits ( _class , _AbstractModule ) ;
2016-04-04 21:31:15 -04:00
2016-05-18 23:12:36 -04:00
function _class ( options ) {
_classCallCheck ( this , _class ) ;
2016-04-04 21:31:15 -04:00
2016-07-14 14:41:30 -04:00
var _this = _possibleConstructorReturn ( this , _AbstractModule . call ( this , options ) ) ;
2016-04-04 21:31:15 -04:00
_this . $label = _this . $el . find ( '.js-label' ) ;
2016-05-19 13:37:19 -04:00
_this . $document . on ( 'Title.changeLabel' , function ( event , value ) {
2016-04-04 21:31:15 -04:00
_this . changeLabel ( value ) ;
2016-05-19 13:37:19 -04:00
_this . destroy ( ) ;
2016-04-04 21:31:15 -04:00
} ) ;
2016-05-18 23:58:08 -04:00
2016-05-19 13:37:19 -04:00
_this . hiddenCallbackIdent = ( 0 , _visibility . visibilityApi ) ( {
action : 'addCallback' ,
state : 'hidden' ,
callback : _this . logHidden
} ) ;
_this . visibleCallbackIdent = ( 0 , _visibility . visibilityApi ) ( {
action : 'addCallback' ,
state : 'visible' ,
callback : _this . logVisible
} ) ;
2016-04-04 21:31:15 -04:00
return _this ;
}
2016-07-14 14:41:30 -04:00
_class . prototype . logHidden = function logHidden ( ) {
console . log ( 'Title is hidden' ) ;
} ;
_class . prototype . logVisible = function logVisible ( ) {
console . log ( 'Title is visible' ) ;
} ;
_class . prototype . changeLabel = function changeLabel ( value ) {
this . $label . text ( value ) ;
} ;
_class . prototype . destroy = function destroy ( ) {
this . $document . off ( 'Title.changeLabel' ) ;
( 0 , _visibility . visibilityApi ) ( {
action : 'removeCallback' ,
state : 'hidden' ,
ident : this . hiddenCallbackIdent
} ) ;
( 0 , _visibility . visibilityApi ) ( {
action : 'removeCallback' ,
state : 'visible' ,
ident : this . visibleCallbackIdent
} ) ;
this . $el . off ( '.Title' ) ;
} ;
2016-04-04 21:31:15 -04:00
2016-05-18 23:12:36 -04:00
return _class ;
} ( _AbstractModule3 . default ) ;
exports . default = _class ;
2016-07-19 10:21:09 -04:00
} , { "../utils/visibility" : 12 , "./AbstractModule" : 4 } ] , 7 : [ function ( require , module , exports ) {
2016-05-19 13:37:19 -04:00
'use strict' ;
Object . defineProperty ( exports , "__esModule" , {
value : true
} ) ;
exports . addToArray = addToArray ;
exports . arrayContains = arrayContains ;
exports . arrayContentsMatch = arrayContentsMatch ;
exports . ensureArray = ensureArray ;
exports . lastItem = lastItem ;
exports . removeFromArray = removeFromArray ;
exports . toArray = toArray ;
exports . findByKeyValue = findByKeyValue ;
var _is = require ( './is' ) ;
function addToArray ( array , value ) {
var index = array . indexOf ( value ) ;
if ( index === - 1 ) {
array . push ( value ) ;
}
}
function arrayContains ( array , value ) {
for ( var i = 0 , c = array . length ; i < c ; i ++ ) {
if ( array [ i ] == value ) {
return true ;
}
}
return false ;
}
function arrayContentsMatch ( a , b ) {
var i ;
if ( ! ( 0 , _is . isArray ) ( a ) || ! ( 0 , _is . isArray ) ( b ) ) {
return false ;
}
if ( a . length !== b . length ) {
return false ;
}
i = a . length ;
while ( i -- ) {
if ( a [ i ] !== b [ i ] ) {
return false ;
}
}
return true ;
}
function ensureArray ( x ) {
if ( typeof x === 'string' ) {
return [ x ] ;
}
if ( x === undefined ) {
return [ ] ;
}
return x ;
}
function lastItem ( array ) {
return array [ array . length - 1 ] ;
}
function removeFromArray ( array , member ) {
if ( ! array ) {
return ;
}
var index = array . indexOf ( member ) ;
if ( index !== - 1 ) {
array . splice ( index , 1 ) ;
}
}
function toArray ( arrayLike ) {
var array = [ ] ,
i = arrayLike . length ;
while ( i -- ) {
array [ i ] = arrayLike [ i ] ;
}
return array ;
}
function findByKeyValue ( array , key , value ) {
return array . filter ( function ( obj ) {
return obj [ key ] === value ;
} ) ;
}
2016-07-19 10:21:09 -04:00
} , { "./is" : 11 } ] , 8 : [ function ( require , module , exports ) {
2016-05-18 23:12:36 -04:00
"use strict" ;
Object . defineProperty ( exports , "__esModule" , {
value : true
} ) ;
var $document = $ ( document ) ;
var $window = $ ( window ) ;
var $html = $ ( document . documentElement ) ;
var $body = $ ( document . body ) ;
2016-04-04 21:31:15 -04:00
2016-05-18 23:12:36 -04:00
exports . $document = $document ;
exports . $window = $window ;
exports . $html = $html ;
exports . $body = $body ;
2016-05-19 13:37:19 -04:00
} , { } ] , 9 : [ function ( require , module , exports ) {
2016-07-19 10:21:09 -04:00
"use strict" ;
2016-05-18 23:12:36 -04:00
Object . defineProperty ( exports , "__esModule" , {
value : true
} ) ;
exports . default = function ( ) {
2016-07-19 10:21:09 -04:00
svg4everybody ( ) ;
2016-05-18 23:12:36 -04:00
} ;
2016-07-19 10:21:09 -04:00
} , { } ] , 10 : [ function ( require , module , exports ) {
'use strict' ;
2016-05-18 23:12:36 -04:00
2016-07-19 10:21:09 -04:00
Object . defineProperty ( exports , "__esModule" , {
value : true
} ) ;
exports . escapeHtml = escapeHtml ;
exports . unescapeHtml = unescapeHtml ;
exports . getNodeData = getNodeData ;
/ * *
* @ see https : //github.com/ractivejs/ractive/blob/dev/src/utils/html.js
* /
function escapeHtml ( str ) {
return str . replace ( /&/g , '&' ) . replace ( /</g , '<' ) . replace ( />/g , '>' ) ;
}
2016-05-18 23:12:36 -04:00
2016-07-19 10:21:09 -04:00
/ * *
* Prepare HTML content that contains mustache characters for use with Ractive
* @ param { string } str
* @ return { string }
* /
function unescapeHtml ( str ) {
return str . replace ( /</g , '<' ) . replace ( />/g , '>' ) . replace ( /&/g , '&' ) ;
}
2016-04-04 21:31:15 -04:00
2016-07-19 10:21:09 -04:00
/ * *
* Get element data attributes
* @ param { DOMElement } node
* @ return { Array } data
* /
function getNodeData ( node ) {
// All attributes
var attributes = node . attributes ;
// Regex Pattern
var pattern = /^data\-(.+)$/ ;
// Output
var data = { } ;
for ( var i in attributes ) {
if ( ! attributes [ i ] ) {
continue ;
}
// Attributes name (ex: data-module)
var name = attributes [ i ] . name ;
// This happens.
if ( ! name ) {
continue ;
}
var match = name . match ( pattern ) ;
if ( ! match ) {
continue ;
}
// If this throws an error, you have some
// serious problems in your HTML.
data [ match [ 1 ] ] = node . getAttribute ( name ) ;
}
return data ;
}
} , { } ] , 11 : [ function ( require , module , exports ) {
2016-05-18 23:58:08 -04:00
'use strict' ;
Object . defineProperty ( exports , "__esModule" , {
value : true
} ) ;
2016-05-19 13:37:19 -04:00
var _typeof = typeof Symbol === "function" && typeof Symbol . iterator === "symbol" ? function ( obj ) { return typeof obj ; } : function ( obj ) { return obj && typeof Symbol === "function" && obj . constructor === Symbol ? "symbol" : typeof obj ; } ;
exports . isArray = isArray ;
exports . isArrayLike = isArrayLike ;
exports . isEqual = isEqual ;
exports . isNumeric = isNumeric ;
exports . isObject = isObject ;
exports . isFunction = isFunction ;
var toString = Object . prototype . toString ,
arrayLikePattern = /^\[object (?:Array|FileList)\]$/ ;
// thanks, http://perfectionkills.com/instanceof-considered-harmful-or-how-to-write-a-robust-isarray/
function isArray ( thing ) {
return toString . call ( thing ) === '[object Array]' ;
}
function isArrayLike ( obj ) {
return arrayLikePattern . test ( toString . call ( obj ) ) ;
}
function isEqual ( a , b ) {
if ( a === null && b === null ) {
return true ;
}
if ( ( typeof a === 'undefined' ? 'undefined' : _typeof ( a ) ) === 'object' || ( typeof b === 'undefined' ? 'undefined' : _typeof ( b ) ) === 'object' ) {
return false ;
}
return a === b ;
}
// http://stackoverflow.com/questions/18082/validate-numbers-in-javascript-isnumeric
function isNumeric ( thing ) {
return ! isNaN ( parseFloat ( thing ) ) && isFinite ( thing ) ;
}
function isObject ( thing ) {
return thing && toString . call ( thing ) === '[object Object]' ;
}
function isFunction ( thing ) {
var getType = { } ;
return thing && getType . toString . call ( thing ) === '[object Function]' ;
}
2016-07-19 10:21:09 -04:00
} , { } ] , 12 : [ function ( require , module , exports ) {
2016-05-19 13:37:19 -04:00
'use strict' ;
Object . defineProperty ( exports , "__esModule" , {
value : true
} ) ;
exports . visibilityApi = undefined ;
var _is = require ( './is' ) ;
var _array = require ( './array' ) ;
var _environment = require ( './environment' ) ;
2016-05-18 23:58:08 -04:00
var CALLBACKS = {
hidden : [ ] ,
visible : [ ]
2016-05-19 13:37:19 -04:00
} ; /* jshint esnext: true */
var ACTIONS = [ 'addCallback' , 'removeCallback' ] ;
var STATES = [ 'visible' , 'hidden' ] ;
var PREFIX = 'v-' ;
var UUID = 0 ;
2016-05-18 23:58:08 -04:00
// Main event
_environment . $document . on ( 'visibilitychange' , function ( event ) {
if ( document . hidden ) {
onDocumentChange ( 'hidden' ) ;
} else {
onDocumentChange ( 'visible' ) ;
}
} ) ;
2016-05-19 13:37:19 -04:00
/ * *
* Add a callback
* @ param { string } state
* @ param { function } callback
* @ return { string } ident
* /
function addCallback ( state , options ) {
var callback = options . callback || '' ;
if ( ! ( 0 , _is . isFunction ) ( callback ) ) {
console . warn ( 'Callback is not a function' ) ;
return false ;
}
var ident = PREFIX + UUID ++ ;
CALLBACKS [ state ] . push ( {
ident : ident ,
callback : callback
} ) ;
return ident ;
2016-05-18 23:58:08 -04:00
}
2016-05-19 13:37:19 -04:00
/ * *
* Remove a callback
* @ param { string } state Visible or hidden
* @ param { string } ident Unique identifier
* @ return { boolean } If operation was a success
* /
function removeCallback ( state , options ) {
var ident = options . ident || '' ;
if ( typeof ident === 'undefined' || ident === '' ) {
console . warn ( 'Need ident to remove callback' ) ;
return false ;
}
var index = ( 0 , _array . findByKeyValue ) ( CALLBACKS [ state ] , 'ident' , ident ) [ 0 ] ;
// console.log(ident)
// console.log(CALLBACKS[state])
if ( typeof index !== 'undefined' ) {
( 0 , _array . removeFromArray ) ( CALLBACKS [ state ] , index ) ;
return true ;
} else {
console . warn ( 'Callback could not be found' ) ;
return false ;
}
2016-05-18 23:58:08 -04:00
}
2016-05-19 13:37:19 -04:00
/ * *
* When document state changes , trigger callbacks
* @ param { string } state Visible or hidden
* /
2016-05-18 23:58:08 -04:00
function onDocumentChange ( state ) {
2016-05-19 13:37:19 -04:00
var callbackArray = CALLBACKS [ state ] ;
2016-05-18 23:58:08 -04:00
var i = 0 ;
2016-05-19 13:37:19 -04:00
var len = callbackArray . length ;
2016-05-18 23:58:08 -04:00
for ( ; i < len ; i ++ ) {
2016-05-19 13:37:19 -04:00
callbackArray [ i ] . callback ( ) ;
2016-05-18 23:58:08 -04:00
}
}
2016-05-19 13:37:19 -04:00
/ * *
* Public facing API for adding and removing callbacks
* @ param { object } options Options
* @ return { boolean | integer } Unique identifier for the callback or boolean indicating success or failure
* /
function visibilityApi ( options ) {
var action = options . action || '' ;
var state = options . state || '' ;
var ret = void 0 ;
// Type and value checking
if ( ! ( 0 , _array . arrayContains ) ( ACTIONS , action ) ) {
console . warn ( 'Action does not exist' ) ;
return false ;
}
if ( ! ( 0 , _array . arrayContains ) ( STATES , state ) ) {
console . warn ( 'State does not exist' ) ;
return false ;
}
// @todo Magic call function pls
if ( action === 'addCallback' ) {
ret = addCallback ( state , options ) ;
} else if ( action === 'removeCallback' ) {
ret = removeCallback ( state , options ) ;
}
return ret ;
}
exports . visibilityApi = visibilityApi ;
2016-05-18 23:58:08 -04:00
2016-07-19 10:21:09 -04:00
} , { "./array" : 7 , "./environment" : 8 , "./is" : 11 } ] } , { } , [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 ] )
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIm5vZGVfbW9kdWxlcy9icm93c2VyLXBhY2svX3ByZWx1ZGUuanMiLCJhc3NldHMvc2NyaXB0cy9BcHAuanMiLCJhc3NldHMvc2NyaXB0cy9nbG9iYWwvc2NvbGxUby5qcyIsImFzc2V0cy9zY3JpcHRzL21vZHVsZXMuanMiLCJhc3NldHMvc2NyaXB0cy9tb2R1bGVzL0Fic3RyYWN0TW9kdWxlLmpzIiwiYXNzZXRzL3NjcmlwdHMvbW9kdWxlcy9CdXR0b24uanMiLCJhc3NldHMvc2NyaXB0cy9tb2R1bGVzL1RpdGxlLmpzIiwiYXNzZXRzL3NjcmlwdHMvdXRpbHMvYXJyYXkuanMiLCJhc3NldHMvc2NyaXB0cy91dGlscy9lbnZpcm9ubWVudC5qcyIsImFzc2V0cy9zY3JpcHRzL3V0aWxzL2dsb2JhbHMuanMiLCJhc3NldHMvc2NyaXB0cy91dGlscy9odG1sLmpzIiwiYXNzZXRzL3NjcmlwdHMvdXRpbHMvaXMuanMiLCJhc3NldHMvc2NyaXB0cy91dGlscy92aXNpYmlsaXR5LmpzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBOzs7QUNDQTs7QUFDQTs7QUFHQTs7OztBQUdBOztJQUFZLE87Ozs7Ozt5SkFSWjs7O0FBSUE7OztBQUdBOzs7SUFHTSxHO0FBQ0wsbUJBQWM7QUFBQTs7QUFBQTs7QUFDYixhQUFLLE9BQUwsR0FBZSxPQUFmO0FBQ0EsYUFBSyxjQUFMLEdBQXNCLEVBQXRCOztBQUVBLCtCQU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