origin33/app/html/js/akamai-async-loader.unmin.js

86 lines
2.3 KiB
JavaScript
Raw Normal View History

2024-03-19 12:48:13 +00:00
/*! Copyright 2019, Akamai Technologies, Inc. All Rights Reserved. akamai-viewer-0.7.2 */(function(exports){
/**
* Akamai AsyncViewer omni-component for async viewer loading and init
* @class
* @alias Akamai.AsyncViewer
* @param {HTMLElement} element - the DOM element representing the component markup
* @param {Object} options - configuration options
*
* @example <caption>Instantiation</caption>
* var element = document.querySelector( "[data-akamai-viewer]" );
* var viewer = Akamai.AsyncViewer( element, options );
* @returns AsyncViewer instance
*/
var AsyncViewer = function( elem, options ){
this._element = elem;
this._options = options;
this._bindings = [];
AsyncViewer.queue.push( this );
AsyncViewer.runQueue();
};
AsyncViewer.queue = [];
AsyncViewer.deps = 0;
AsyncViewer.depsNeeded = 2;
AsyncViewer.ready = function(){
AsyncViewer.deps++;
AsyncViewer.runQueue();
};
AsyncViewer.runQueue = function(){
var domLib = window.shoestring;
if( AsyncViewer.deps < AsyncViewer.depsNeeded ){
return;
}
AsyncViewer.queue.map(function(viewer){
return viewer.instantiate();
});
};
/**
* onInitialize callback - access the viewer instance
*
*
* @callback
* @example <caption>Callback function usage</caption>
* var asyncViewer = new Akamai.AsyncViewer( element, options );
* asyncViewer.onInitialize(function(viewer){
* console.log(viewer.getCarousels());
* });
*/
AsyncViewer.prototype.onInitialize = function(binding){
if(this._instantiated){
binding(this._viewer);
return;
}
this._bindings.push(binding);
};
AsyncViewer.prototype.instantiate = function(){
this._instantiated = true;
var domLib = window.shoestring;
var $element = domLib(this._element);
$element.bind( "akamai-carousel-first-media-load", function(){
domLib( $element.attr("data-akamai-viewer-placeholder") ).remove();
});
$element.bind("akamai-viewer-init", function(){
this._bindings.forEach(function(binding){
binding(this._viewer);
}.bind(this));
}.bind(this));
this._viewer = new Akamai.Viewer(this._element, this._options);
this._instantiated = true;
return this._viewer;
};
exports.Akamai = exports.Akamai || {};
exports.Akamai.AsyncViewer = AsyncViewer;
})(typeof exports === 'undefined'? window : exports);