From: Carey Evans Date: Wed, 6 May 2015 02:38:46 +0000 (+1200) Subject: Make media_queries work when Foundation JS is loaded asynchronously, X-Git-Tag: v5.5.3~40^2~8^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=refs%2Fpull%2F6664%2Fhead;p=thirdparty%2Ffoundation%2Ffoundation-sites.git Make media_queries work when Foundation JS is loaded asynchronously, rather than synchronously at the end of the HTML. --- diff --git a/js/foundation/foundation.js b/js/foundation/foundation.js index 46a8a826e..81a85d08a 100644 --- a/js/foundation/foundation.js +++ b/js/foundation/foundation.js @@ -10,14 +10,12 @@ 'use strict'; var header_helpers = function (class_array) { - var i = class_array.length; var head = $('head'); - - while (i--) { - if (head.has('.' + class_array[i]).length === 0) { - head.append(''); + head.prepend($.map(class_array, function (class_name) { + if (head.has('.' + class_name).length === 0) { + return ''; } - } + })); }; header_helpers([ @@ -290,21 +288,30 @@ return string; } + function MediaQuery(selector) { + this.selector = selector; + this.query = ''; + } + + MediaQuery.prototype.toString = function () { + return this.query || (this.query = S(this.selector).css('font-family').replace(/^[\/\\'"]+|(;\s?})+|[\/\\'"]+$/g, '')); + }; + window.Foundation = { name : 'Foundation', version : '{{VERSION}}', media_queries : { - 'small' : S('.foundation-mq-small').css('font-family').replace(/^[\/\\'"]+|(;\s?})+|[\/\\'"]+$/g, ''), - 'small-only' : S('.foundation-mq-small-only').css('font-family').replace(/^[\/\\'"]+|(;\s?})+|[\/\\'"]+$/g, ''), - 'medium' : S('.foundation-mq-medium').css('font-family').replace(/^[\/\\'"]+|(;\s?})+|[\/\\'"]+$/g, ''), - 'medium-only' : S('.foundation-mq-medium-only').css('font-family').replace(/^[\/\\'"]+|(;\s?})+|[\/\\'"]+$/g, ''), - 'large' : S('.foundation-mq-large').css('font-family').replace(/^[\/\\'"]+|(;\s?})+|[\/\\'"]+$/g, ''), - 'large-only' : S('.foundation-mq-large-only').css('font-family').replace(/^[\/\\'"]+|(;\s?})+|[\/\\'"]+$/g, ''), - 'xlarge' : S('.foundation-mq-xlarge').css('font-family').replace(/^[\/\\'"]+|(;\s?})+|[\/\\'"]+$/g, ''), - 'xlarge-only' : S('.foundation-mq-xlarge-only').css('font-family').replace(/^[\/\\'"]+|(;\s?})+|[\/\\'"]+$/g, ''), - 'xxlarge' : S('.foundation-mq-xxlarge').css('font-family').replace(/^[\/\\'"]+|(;\s?})+|[\/\\'"]+$/g, '') + 'small' : new MediaQuery('.foundation-mq-small'), + 'small-only' : new MediaQuery('.foundation-mq-small-only'), + 'medium' : new MediaQuery('.foundation-mq-medium'), + 'medium-only' : new MediaQuery('.foundation-mq-medium-only'), + 'large' : new MediaQuery('.foundation-mq-large'), + 'large-only' : new MediaQuery('.foundation-mq-large-only'), + 'xlarge' : new MediaQuery('.foundation-mq-xlarge'), + 'xlarge-only' : new MediaQuery('.foundation-mq-xlarge-only'), + 'xxlarge' : new MediaQuery('.foundation-mq-xxlarge') }, stylesheet : $('').appendTo('head')[0].sheet,