Add componentHanderConfig to config auto upgrade

This commit is contained in:
Zander Otavka 2016-09-22 21:35:47 -05:00
parent 7f57f99436
commit 07bd6fdd94

View File

@ -27,6 +27,12 @@
// Pre-defining the componentHandler interface, for closure documentation and
// static verification.
var componentHandler = {
/**
* Configuration for component handler, such as preventing initial upgrade.
*
* @type {componentHandler.ComponentHanderConfig}
*/
config: {},
/**
* Searches existing DOM for elements of our component type and upgrades them
* if they have not already been upgraded.
@ -93,6 +99,15 @@ componentHandler = (function() {
var componentConfigProperty_ = 'mdlComponentConfigInternal_';
var configInternal = {
preventAutoUpgrade: false
};
var globalConfig_ = window.componentHandlerConfig || {};
if ('preventAutoUpgrade' in globalConfig_) {
configInternal.preventAutoUpgrade = globalConfig_.preventAutoUpgrade;
}
/**
* Searches registered components for a class we are interested in using.
* Optionally replaces a match with passed object if specified.
@ -397,9 +412,10 @@ componentHandler = (function() {
}
}
// Now return the functions that should be made public with their publicly
// Now return the functions and members that should be made public with their publicly
// facing names...
return {
config: configInternal,
upgradeDom: upgradeDomInternal,
upgradeElement: upgradeElementInternal,
upgradeElements: upgradeElementsInternal,
@ -410,6 +426,16 @@ componentHandler = (function() {
};
})();
/**
* Describes the type of the config object for componentHandler.
* Provided for benefit of the Closure compiler.
*
* @typedef {{
* preventAutoUpgrade: boolean
* }}
*/
componentHandler.ComponentHandlerConfig; // jshint ignore: line
/**
* Describes the type of a registered component type managed by
* componentHandler. Provided for benefit of the Closure compiler.
@ -453,6 +479,7 @@ componentHandler.Component; // jshint ignore:line
// Export all symbols, for the benefit of Closure compiler.
// No effect on uncompiled code.
componentHandler['config'] = componentHandler.config;
componentHandler['upgradeDom'] = componentHandler.upgradeDom;
componentHandler['upgradeElement'] = componentHandler.upgradeElement;
componentHandler['upgradeElements'] = componentHandler.upgradeElements;
@ -477,7 +504,9 @@ window.addEventListener('load', function() {
'querySelector' in document &&
'addEventListener' in window && Array.prototype.forEach) {
document.documentElement.classList.add('mdl-js');
componentHandler.upgradeAllRegistered();
if (!componentHandler.config.preventAutoUpgrade) {
componentHandler.upgradeAllRegistered();
}
} else {
/**
* Dummy function to avoid JS errors.