Ripples shouldn't be widgets.

This introduces a `widget` config option to the component handler, to
define whether a component should behave as a widget. It also uses this
option on ripples, setting it to `false`, so that they don't override
the widget definition for components.

This fixes several element APIs, which can now be accessed with
<element>.widget to do e.g. <element>.widget.disable();
master
Sérgio Gomes 2015-05-27 17:18:37 +01:00
parent b6c677a414
commit da206505c1
2 changed files with 11 additions and 7 deletions

View File

@ -104,8 +104,10 @@ var componentHandler = (function() {
callback(element);
});
// Assign per element instance for control over API
element.widget = instance;
if (registeredClass.widget) {
// Assign per element instance for control over API
element.widget = instance;
}
} else {
// If component creator forgot to register, try and see if
// it is in global scope.
@ -129,6 +131,7 @@ var componentHandler = (function() {
'classConstructor': config.constructor,
'className': config.classAsString,
'cssClass': config.cssClass,
'widget': config.widget === undefined ? true : config.widget,
'callbacks': []
};
@ -166,7 +169,6 @@ var componentHandler = (function() {
}
}
// Now return the functions that should be made public with their publicly
// facing names...
return {
@ -178,7 +180,6 @@ var componentHandler = (function() {
};
})();
window.addEventListener('load', function() {
'use strict';
@ -187,11 +188,13 @@ window.addEventListener('load', function() {
* tested, adds a mdl-js class to the <html> element. It then upgrades all MDL
* components requiring JavaScript.
*/
if ('classList' in document.createElement('div') && 'querySelector' in document &&
if ('classList' in document.createElement('div') &&
'querySelector' in document &&
'addEventListener' in window && Array.prototype.forEach) {
document.documentElement.classList.add('mdl-js');
componentHandler.upgradeAllRegistered();
} else {
componentHandler.upgradeElement = componentHandler.register = function () { };
componentHandler.upgradeElement =
componentHandler.register = function () { };
}
});

View File

@ -217,5 +217,6 @@ MaterialRipple.prototype.init = function() {
componentHandler.register({
constructor: MaterialRipple,
classAsString: 'MaterialRipple',
cssClass: 'mdl-js-ripple-effect'
cssClass: 'mdl-js-ripple-effect',
widget: false
});