vendor/assets/javascripts/material.js in material_design_lite-rails-1.1.3 vs vendor/assets/javascripts/material.js in material_design_lite-rails-1.2.0
- old
+ new
@@ -230,12 +230,12 @@
'Unable to find a registered component for the given class.');
}
var ev;
if ('CustomEvent' in window && typeof window.CustomEvent === 'function') {
- ev = new Event('mdl-componentupgraded', {
- 'bubbles': true, 'cancelable': false
+ ev = new CustomEvent('mdl-componentupgraded', {
+ bubbles: true, cancelable: false
});
} else {
ev = document.createEvent('Events');
ev.initEvent('mdl-componentupgraded', true, true);
}
@@ -249,14 +249,14 @@
* @param {!Element|!Array<!Element>|!NodeList|!HTMLCollection} elements
* The elements we wish to upgrade.
*/
function upgradeElementsInternal(elements) {
if (!Array.isArray(elements)) {
- if (typeof elements.item === 'function') {
- elements = Array.prototype.slice.call(/** @type {Array} */ (elements));
- } else {
+ if (elements instanceof Element) {
elements = [elements];
+ } else {
+ elements = Array.prototype.slice.call(elements);
}
}
for (var i = 0, n = elements.length, element; i < n; i++) {
element = elements[i];
if (element instanceof HTMLElement) {
@@ -361,17 +361,18 @@
upgrades.splice(componentPlace, 1);
component.element_.setAttribute('data-upgraded', upgrades.join(','));
var ev;
if ('CustomEvent' in window && typeof window.CustomEvent === 'function') {
- ev = new Event('mdl-componentdowngraded', {
- 'bubbles': true, 'cancelable': false
+ ev = new CustomEvent('mdl-componentdowngraded', {
+ bubbles: true, cancelable: false
});
} else {
ev = document.createEvent('Events');
ev.initEvent('mdl-componentdowngraded', true, true);
}
+ component.element_.dispatchEvent(ev);
}
}
/**
* Downgrade either a given node, an array of nodes, or a NodeList.
@@ -1791,21 +1792,21 @@
*
* @public
*/
MaterialRadio.prototype.check = function () {
this.btnElement_.checked = true;
- this.updateClasses_();
+ this.onChange_(null);
};
MaterialRadio.prototype['check'] = MaterialRadio.prototype.check;
/**
* Uncheck radio.
*
* @public
*/
MaterialRadio.prototype.uncheck = function () {
this.btnElement_.checked = false;
- this.updateClasses_();
+ this.onChange_(null);
};
MaterialRadio.prototype['uncheck'] = MaterialRadio.prototype.uncheck;
/**
* Initialize element.
*/
@@ -3047,20 +3048,20 @@
var marginLeft = -1 * (this.element_.offsetWidth / 2);
var marginTop = -1 * (this.element_.offsetHeight / 2);
if (this.element_.classList.contains(this.CssClasses_.LEFT) || this.element_.classList.contains(this.CssClasses_.RIGHT)) {
left = props.width / 2;
if (top + marginTop < 0) {
- this.element_.style.top = 0;
- this.element_.style.marginTop = 0;
+ this.element_.style.top = '0';
+ this.element_.style.marginTop = '0';
} else {
this.element_.style.top = top + 'px';
this.element_.style.marginTop = marginTop + 'px';
}
} else {
if (left + marginLeft < 0) {
- this.element_.style.left = 0;
- this.element_.style.marginLeft = 0;
+ this.element_.style.left = '0';
+ this.element_.style.marginLeft = '0';
} else {
this.element_.style.left = left + 'px';
this.element_.style.marginLeft = marginLeft + 'px';
}
}
@@ -3074,36 +3075,37 @@
this.element_.style.top = props.top + props.height + 10 + 'px';
}
this.element_.classList.add(this.CssClasses_.IS_ACTIVE);
};
/**
- * Handle mouseleave for tooltip.
+ * Hide tooltip on mouseleave or scroll
*
* @private
*/
-MaterialTooltip.prototype.handleMouseLeave_ = function () {
+MaterialTooltip.prototype.hideTooltip_ = function () {
this.element_.classList.remove(this.CssClasses_.IS_ACTIVE);
};
/**
* Initialize element.
*/
MaterialTooltip.prototype.init = function () {
if (this.element_) {
- var forElId = this.element_.getAttribute('for');
+ var forElId = this.element_.getAttribute('for') || this.element_.getAttribute('data-mdl-for');
if (forElId) {
this.forElement_ = document.getElementById(forElId);
}
if (this.forElement_) {
// It's left here because it prevents accidental text selection on Android
if (!this.forElement_.hasAttribute('tabindex')) {
this.forElement_.setAttribute('tabindex', '0');
}
this.boundMouseEnterHandler = this.handleMouseEnter_.bind(this);
- this.boundMouseLeaveHandler = this.handleMouseLeave_.bind(this);
+ this.boundMouseLeaveAndScrollHandler = this.hideTooltip_.bind(this);
this.forElement_.addEventListener('mouseenter', this.boundMouseEnterHandler, false);
this.forElement_.addEventListener('touchend', this.boundMouseEnterHandler, false);
- this.forElement_.addEventListener('mouseleave', this.boundMouseLeaveHandler, false);
- window.addEventListener('touchstart', this.boundMouseLeaveHandler);
+ this.forElement_.addEventListener('mouseleave', this.boundMouseLeaveAndScrollHandler, false);
+ window.addEventListener('scroll', this.boundMouseLeaveAndScrollHandler, true);
+ window.addEventListener('touchstart', this.boundMouseLeaveAndScrollHandler);
}
}
};
// The component registers itself. It can assume componentHandler is available
// in the global scope.