diff -u b/core/misc/matchmedia.js b/core/misc/matchmedia.js --- b/core/misc/matchmedia.js +++ b/core/misc/matchmedia.js @@ -12,20 +12,21 @@ * This polyfill triggers tests on window resize and orientationchange. */ -window.matchMedia = window.matchMedia || (function (doc) { +window.matchMedia = window.matchMedia || (function (doc, window) { "use strict"; var docElem = doc.documentElement; var refNode = docElem.firstElementChild || docElem.firstChild; - // fakeBody required for - var fakeBody = doc.createElement( "body" ); - var div = doc.createElement( "div" ); + // fakeBody required for . + var fakeBody = doc.createElement("body"); + var div = doc.createElement("div"); div.id = "mq-test-1"; div.style.cssText = "position:absolute;top:-100em"; fakeBody.style.background = "none"; fakeBody.appendChild(div); + /** * A replacement for the native MediaQueryList object. * @@ -37,33 +38,36 @@ this.matches = false; this.check.call(this); } + /** * Polyfill the addListener and removeListener methods. */ MediaQueryList.prototype = { listeners: [], + /** * Perform the media query application check. */ check: function () { var isApplied; - div.innerHTML = "­"; - docElem.insertBefore( fakeBody, refNode ); + div.innerHTML = "­"; + docElem.insertBefore(fakeBody, refNode); isApplied = div.offsetWidth === 42; - docElem.removeChild( fakeBody ); + docElem.removeChild(fakeBody); this.matches = isApplied; }, + /** * Polyfill the addListener method of the MediaQueryList object. * * @param {Function} callback - * The callback to be invoked on screen resize or orientationchange. + * The callback to be invoked when the media query is applicable. * * @return {Object MediaQueryList} * A MediaQueryList object that indicates whether the registered media - * query applies to the current screen dimenions and orientation. The - * matches property is true when the media query applies and false when - * not. The original media query is referenced in the media property. + * query applies. The matches property is true when the media query + * applies and false when not. The original media query is referenced in + * the media property. */ addListener: function (callback) { var handler = (function (mql, debounced) { @@ -78,6 +82,7 @@ 'callback': callback, 'handler': handler }); + // Associate the handler to the resize and orientationchange events. if ('addEventListener' in window) { window.addEventListener('resize', handler); @@ -88,6 +93,7 @@ window.attachEvent('onorientationchange', handler); } }, + /** * Polyfill the removeListener method of the MediaQueryList object. * @@ -111,6 +117,7 @@ } } }; + /** * Limits the invocations of a function in a given time frame. * @@ -136,6 +143,7 @@ return result; }; } + /** * Return a MediaQueryList. * @@ -150 +158 @@ -}(document)); +}(document, window)); diff -u b/core/modules/system/system.module b/core/modules/system/system.module --- b/core/modules/system/system.module +++ b/core/modules/system/system.module @@ -1380,12 +1380,13 @@ ), ); - $libraries['matchMedia'] = array( + // matchMedia polyfill. + $libraries['matchmedia'] = array( 'title' => 'window.matchMedia polyfill', 'website' => 'http://drupal.org/node/1815602', - 'version' => '1.0', + 'version' => VERSION, 'js' => array( - 'core/misc/matchMedia.js' => array(), + 'core/misc/matchmedia.js' => array(), ), );