Merge pull request #1779 from google/garbee/downgrade-radio

Downgrade radio components.
master
Sérgio Gomes 2015-11-02 11:54:58 +00:00
commit ce3c5fad8e
2 changed files with 36 additions and 5 deletions

View File

@ -225,6 +225,11 @@
this.btnElement_ = this.element_.querySelector('.' +
this.CssClasses_.RADIO_BTN);
this.boundChangeHandler_ = this.onChange_.bind(this);
this.boundFocusHandler_ = this.onChange_.bind(this);
this.boundBlurHandler_ = this.onBlur_.bind(this);
this.boundMouseUpHandler_ = this.onMouseup_.bind(this);
var outerCircle = document.createElement('span');
outerCircle.classList.add(this.CssClasses_.RADIO_OUTER_CIRCLE);
@ -244,7 +249,7 @@
this.CssClasses_.RIPPLE_CONTAINER);
rippleContainer.classList.add(this.CssClasses_.RIPPLE_EFFECT);
rippleContainer.classList.add(this.CssClasses_.RIPPLE_CENTER);
rippleContainer.addEventListener('mouseup', this.onMouseup_.bind(this));
rippleContainer.addEventListener('mouseup', this.boundMouseUpHandler_);
var ripple = document.createElement('span');
ripple.classList.add(this.CssClasses_.RIPPLE);
@ -253,16 +258,34 @@
this.element_.appendChild(rippleContainer);
}
this.btnElement_.addEventListener('change', this.onChange_.bind(this));
this.btnElement_.addEventListener('focus', this.onFocus_.bind(this));
this.btnElement_.addEventListener('blur', this.onBlur_.bind(this));
this.element_.addEventListener('mouseup', this.onMouseup_.bind(this));
this.btnElement_.addEventListener('change', this.boundChangeHandler_);
this.btnElement_.addEventListener('focus', this.boundFocusHandler_);
this.btnElement_.addEventListener('blur', this.boundBlurHandler_);
this.element_.addEventListener('mouseup', this.boundMouseUpHandler_);
this.updateClasses_();
this.element_.classList.add(this.CssClasses_.IS_UPGRADED);
}
};
/**
* Downgrade the element.
*
* @private
*/
MaterialRadio.prototype.mdlDowngrade_ = function() {
var rippleContainer = this.element_.querySelector('.' +
this.CssClasses_.RIPPLE_CONTAINER);
this.btnElement_.removeEventListener('change', this.boundChangeHandler_);
this.btnElement_.removeEventListener('focus', this.boundFocusHandler_);
this.btnElement_.removeEventListener('blur', this.boundBlurHandler_);
this.element_.removeEventListener('mouseup', this.boundMouseUpHandler_);
if (rippleContainer) {
rippleContainer.removeEventListener('mouseup', this.boundMouseUpHandler_);
this.element_.removeChild(rippleContainer);
}
};
// The component registers itself. It can assume componentHandler is available
// in the global scope.
componentHandler.register({

View File

@ -131,4 +131,12 @@ describe('MaterialRadio', function () {
});
it('should downgrade successfully', function() {
var radio = createRadio();
componentHandler.upgradeElement(radio);
expect(radio.dataset.upgraded).to.equal(',MaterialRadio');
componentHandler.downgradeElements(radio);
expect(radio.dataset.upgraded).to.equal('');
});
});