From 4d4d9ccb4e21033e869f73c494e6e1cb2a18b0ad Mon Sep 17 00:00:00 2001 From: Martin Georgiev Date: Tue, 25 Feb 2014 13:59:59 +0200 Subject: [PATCH] Call resize() only if the media-query has changed Currently the interchangeable content is reloaded every 50ms during window resize, if one has facebook, twitter or GMaps widgets as interchangeable content, things get nasty :) With this change content is reloaded only when the media-query changes. --- js/foundation/foundation.interchange.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/js/foundation/foundation.interchange.js b/js/foundation/foundation.interchange.js index ca8697ccc..a732e15a3 100644 --- a/js/foundation/foundation.interchange.js +++ b/js/foundation/foundation.interchange.js @@ -78,13 +78,25 @@ this.load('nodes'); }, + getMediaHash : function() { + var mediaHash=''; + for (var queryName in this.settings.named_queries ) { + mediaHash += matchMedia(this.settings.named_queries[queryName]).matches.toString(); + } + return mediaHash; + }, + events : function () { - var self = this; + var self = this, prevMediaHash; $(window) .off('.interchange') .on('resize.fndtn.interchange', self.throttle(function () { - self.resize(); + var currMediaHash = self.getMediaHash(); + if (currMediaHash !== prevMediaHash) { + self.resize(); + } + prevMediaHash = currMediaHash; }, 50)); return this; -- 2.47.2