Skip to content

Commit

Permalink
Add componentHanderConfig to config auto upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderOtavka committed Sep 23, 2016
1 parent 7f57f99 commit 07bd6fd
Showing 1 changed file with 31 additions and 2 deletions.
33 changes: 31 additions & 2 deletions src/mdlComponentHandler.js
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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,
Expand All @@ -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.
Expand Down Expand Up @@ -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;
Expand All @@ -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.
Expand Down

0 comments on commit 07bd6fd

Please sign in to comment.