From 2abd2964cfbff66ee58574fb8eedbacf229ad1d4 Mon Sep 17 00:00:00 2001 From: Matthew Sigley Date: Thu, 2 Jul 2015 10:45:16 -0400 Subject: [PATCH 1/9] Fixed callback to be run after the css is loaded. --- assets/js/adapt.js | 56 ++++++++++++++++++++++++---------------------- 1 file changed, 29 insertions(+), 27 deletions(-) diff --git a/assets/js/adapt.js b/assets/js/adapt.js index f4f8372..c6c72bd 100644 --- a/assets/js/adapt.js +++ b/assets/js/adapt.js @@ -17,30 +17,30 @@ if (!config) { return; } - + + // Cache element reference + // Use faster document.head if possible. + var docHead = (d.head || d.getElementsByTagName('head')[0]); + // Empty vars to use later. - var url, url_old, timer; + var url, url_old, timer, css; // Alias config values. - var callback = config.callback || function(){}; - var path = config.path ? config.path : ''; - var range = config.range; - var range_len = range.length; - - // Create empty link tag: - // - var css = d.createElement('link'); - css.rel = 'stylesheet'; - css.media = 'screen'; + var callback = config.callback || function(){}, + path = config.path ? config.path : '', + range = config.range, + range_len = range.length; // Called from within adapt(). function change(i, width) { // Set the URL. css.href = url; url_old = url; - - // Fire callback. - callback(i, width); + + css.onload = function() { + // Fire callback. + callback(i, width); + }; } // Adapt to width. @@ -94,19 +94,21 @@ break; } } - - // Was it created yet? - if (!url_old) { - // Apply changes. - change(i, width); - - // If URL has been defined, add the CSS. - // Use faster document.head if possible. - url && (d.head || d.getElementsByTagName('head')[0]).appendChild(css); - } - else if (url_old !== url) { + + if (url && (!url_old || url_old !== url)) { + if(css) { + docHead.removeChild(css); + css = null; + } + // Create empty link tag: + // + css = d.createElement('link'); + css.rel = 'stylesheet'; + css.media = 'screen'; + // Apply changes. change(i, width); + docHead.appendChild(css); } } @@ -149,4 +151,4 @@ } // Pass in window, document, config, undefined. -})(this, this.document, ADAPT_CONFIG); \ No newline at end of file +})(this, this.document, ADAPT_CONFIG); From d545fdd296fbe618db1b051c2c1fc77fb3c86c8d Mon Sep 17 00:00:00 2001 From: Matthew Sigley Date: Thu, 2 Jul 2015 10:49:56 -0400 Subject: [PATCH 2/9] Re-minified with closure compiler. --- assets/js/adapt.min.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/assets/js/adapt.min.js b/assets/js/adapt.min.js index 5e1eb82..0d552e7 100644 --- a/assets/js/adapt.min.js +++ b/assets/js/adapt.min.js @@ -1 +1,2 @@ -!function(a,b,c,d){function m(a,b){l.href=e,f=e,h(a,b)}function n(){clearTimeout(g);var c,h,n,o,p,q,a=b.documentElement?b.documentElement.clientWidth:0,r=k,s=k-1;for(e=d;r--;)if(c=j[r].split("="),h=c[0],q=c[1]?c[1].replace(/\s/g,""):d,p=h.match("to"),n=p?parseInt(h.split("to")[0],10):parseInt(h,10),o=p?parseInt(h.split("to")[1],10):d,!o&&r===s&&a>n||a>n&&o>=a){q&&(e=i+q);break}f?f!==e&&m(r,a):(m(r,a),e&&(b.head||b.getElementsByTagName("head")[0]).appendChild(l))}function o(){clearTimeout(g),g=setTimeout(n,16)}if(c){var e,f,g,h=c.callback||function(){},i=c.path?c.path:"",j=c.range,k=j.length,l=b.createElement("link");l.rel="stylesheet",l.media="screen",n(),c.dynamic&&(a.addEventListener?a.addEventListener("resize",o,!1):a.attachEvent?a.attachEvent("onresize",o):a.onresize=o)}}(this,this.document,ADAPT_CONFIG); \ No newline at end of file +(function(d,g,a,m){function u(a,b){n=c.href=h;c.onload=function(){v(a,b)}}function k(){clearTimeout(p);var a=g.documentElement?g.documentElement.clientWidth:0,b,e,d,f,l=q,k=q-1;for(h=m;l--;)if(b=r[l].split("="),e=b[0],f=b[1]?b[1].replace(/\s/g,""):m,b=(d=e.match("to"))?parseInt(e.split("to")[0],10):parseInt(e,10),e=d?parseInt(e.split("to")[1],10):m,!e&&l===k&&a>b||a>b&&a<=e){f&&(h=w+f);break}!h||n&&n===h||(c&&(t.removeChild(c),c=null),c=g.createElement("link"),c.rel="stylesheet",c.media="screen", +u(l,a),t.appendChild(c))}function f(){clearTimeout(p);p=setTimeout(k,16)}if(a){var t=g.head||g.getElementsByTagName("head")[0],h,n,p,c,v=a.callback||function(){},w=a.path?a.path:"",r=a.range,q=r.length;k();a.dynamic&&(d.addEventListener?d.addEventListener("resize",f,!1):d.attachEvent?d.attachEvent("onresize",f):d.onresize=f)}})(this,this.document,ADAPT_CONFIG); From 9040ee317202ba5627ccbf806d0ddb344e30d361 Mon Sep 17 00:00:00 2001 From: Matthew Sigley Date: Tue, 25 Apr 2017 12:00:23 -0400 Subject: [PATCH 3/9] Fixed various CSS load order and responsive issues Fixes zoom bug after resizing. Prevents loading the css file if its already loaded. --- assets/js/adapt.js | 345 +++++++++++++++++++++++++++------------------ 1 file changed, 206 insertions(+), 139 deletions(-) diff --git a/assets/js/adapt.js b/assets/js/adapt.js index c6c72bd..7a3495d 100644 --- a/assets/js/adapt.js +++ b/assets/js/adapt.js @@ -12,143 +12,210 @@ */ // Closure. -(function(w, d, config, undefined) { - // If no config, exit. - if (!config) { - return; - } - - // Cache element reference - // Use faster document.head if possible. - var docHead = (d.head || d.getElementsByTagName('head')[0]); - - // Empty vars to use later. - var url, url_old, timer, css; - - // Alias config values. - var callback = config.callback || function(){}, - path = config.path ? config.path : '', - range = config.range, - range_len = range.length; - - // Called from within adapt(). - function change(i, width) { - // Set the URL. - css.href = url; - url_old = url; - - css.onload = function() { - // Fire callback. - callback(i, width); - }; - } - - // Adapt to width. - function adapt() { - // This clearTimeout is for IE. - // Really it belongs in react(), - // but doesn't do any harm here. - clearTimeout(timer); - - // Parse viewport width. - var width = d.documentElement ? d.documentElement.clientWidth : 0; - - // While loop vars. - var arr, arr_0, val_1, val_2, is_range, file; - - // How many ranges? - var i = range_len; - var last = range_len - 1; - - // Start with blank URL. - url = undefined; - - while (i--) { - // Turn string into array. - arr = range[i].split('='); - - // Width is to the left of "=". - arr_0 = arr[0]; - - // File name is to the right of "=". - // Presuppoes a file with no spaces. - // If no file specified, make empty. - file = arr[1] ? arr[1].replace(/\s/g, '') : undefined; - - // Assume max if "to" isn't present. - is_range = arr_0.match('to'); - - // If it's a range, split left/right sides of "to", - // and then convert each one into numerical values. - // If it's not a range, turn maximum into a number. - val_1 = is_range ? parseInt(arr_0.split('to')[0], 10) : parseInt(arr_0, 10); - val_2 = is_range ? parseInt(arr_0.split('to')[1], 10) : undefined; - - // Check for maxiumum or range. - if ((!val_2 && i === last && width > val_1) || (width > val_1 && width <= val_2)) { - // Build full URL to CSS file. - file && (url = path + file); - - // Exit the while loop. No need to continue - // if we've already found a matching range. - break; - } - } - - if (url && (!url_old || url_old !== url)) { - if(css) { - docHead.removeChild(css); - css = null; - } - // Create empty link tag: - // - css = d.createElement('link'); - css.rel = 'stylesheet'; - css.media = 'screen'; - - // Apply changes. - change(i, width); - docHead.appendChild(css); - } - } - - // Fire off once. - adapt(); - - // Slight delay. - function react() { - // Clear the timer as window resize fires, - // so that it only calls adapt() when the - // user has finished resizing the window. - clearTimeout(timer); - - // Start the timer countdown. - timer = setTimeout(adapt, 16); - // -----------------------^^ - // Note: 15.6 milliseconds is lowest "safe" - // duration for setTimeout and setInterval. - // - // http://www.nczonline.net/blog/2011/12/14/timer-resolution-in-browsers - } - - // Do we want to watch for - // resize and device tilt? - if (config.dynamic) { - // Event listener for window resize, - // also triggered by phone rotation. - if (w.addEventListener) { - // Good browsers. - w.addEventListener('resize', react, false); - } - else if (w.attachEvent) { - // Legacy IE support. - w.attachEvent('onresize', react); - } - else { - // Old-school fallback. - w.onresize = react; - } - } - -// Pass in window, document, config, undefined. +(function (w, d, config, undefined) { + // If no config, exit. + if (!config) { + return; + } + + // Empty vars to use later. + var docHead, docBody, bodyClass, url, url_old, timer, css, css_old; + + // Alias config values. + var callback = config.callback || function () { }, + path = config.path ? config.path : '', + range = config.range, + range_len = range.length; + + function setupAdapt() { + d.removeEventListener( "DOMContentLoaded", setupAdapt ); + + // Cache and element reference + // Use faster document.head and document.body if possible. + docHead = (d.head || d.getElementsByTagName('head')[0]); + docBody = (d.body || d.getElementsByTagName('body')[0]); + bodyClass = ''; + + // Get existing link tag if cssId was provided + if (config.cssId) + css = d.getElementById(config.cssId); + + // Fire off once. + adapt(); + + // Do we want to watch for + // resize and device tilt? + if (config.dynamic) { + // Event listener for window resize, + // also triggered by phone rotation. + if (w.addEventListener) { + // Good browsers. + w.addEventListener('resize', react, false); + } + else if (w.attachEvent) { + // Legacy IE support. + w.attachEvent('onresize', react); + } + else { + // Old-school fallback. + w.onresize = react; + } + } + } + + // Called from within adapt(). + function change(i, width, linkElement) { + // Set the URL. + linkElement.href = url; + url_old = url; + + linkElement.onload = function () { + // Remove old css + if(css_old) { + docHead.removeChild(css_old); + css_old = undefined; + } + // Fire callback. + callback(i, width); + }; + } + + // Adapt to width. + function adapt() { + // This clearTimeout is for IE. + // Really it belongs in react(), + // but doesn't do any harm here. + clearTimeout(timer); + + // Remove old css + if(css_old) { + docHead.removeChild(css_old); + css_old = undefined; + } + + // Parse viewport width. + var width = d.documentElement ? d.documentElement.clientWidth : 0; + + // While loop vars. + var arr, arr_0, val_1, val_2, is_range, file; + + // How many ranges? + var i = range_len; + var last = range_len - 1; + + // Start with blank URL. + url = undefined; + + while (i--) { + + // Find first occurance of "=". + equalPos = range[i].indexOf('='); + + // Width is to the left of "=". + arr_0 = range[i].substr(0, equalPos); + + // File name is to the right of "=". + // Presuppoes a file with no spaces. + // If no file specified, make empty. + file = range[i].substr(equalPos+1); + file = file ? file.replace(/\s/g, '') : undefined; + + // Assume max if "to" isn't present. + is_range = arr_0.match('to'); + + // If it's a range, split left/right sides of "to", + // and then convert each one into numerical values. + // If it's not a range, turn maximum into a number. + val_1 = is_range ? parseInt(arr_0.split('to')[0], 10) : parseInt(arr_0, 10); + val_2 = is_range ? parseInt(arr_0.split('to')[1], 10) : undefined; + + // Check for maxiumum or range. + if ((!val_2 && i === last && width > val_1) || (width > val_1 && width <= val_2)) { + // Build full URL to CSS file. + file && (url = path + file); + + // Exit the while loop. No need to continue + // if we've already found a matching range. + break; + } + } + + // Update css link tag, only if css url has changed + if (url && (!url_old || url_old !== url)) { + if (css) { + if(css.href !== url) { + // Create empty link tag: + // + var newCss = d.createElement('link'); + newCss.rel = 'stylesheet'; + newCss.media = css.media; + newCss.id = css.id; + // Apply changes. + change(i, width, newCss); + + // Prevent overflowing flash of content + css_old = css; + css_old.id += '_old'; //Prevent duplicate IDs + + // Preserve css load order with graceful content stepping + if(css.nextSibling) + docHead.insertBefore(newCss, css.nextSibling); + else + docHead.appendChild(newCss); + css = newCss; + } else { + // Fire callback even if css link element wasn't changed. + url_old = url; + callback(i, width); + } + } else { + // Create empty link tag: + // + css = d.createElement('link'); + css.rel = 'stylesheet'; + css.media = 'screen'; + // Apply changes. + change(i, width, css); + + // Append css to end of head + docHead.appendChild(css); + } + } + + // Update css body class + // Remove bodyClass + if (bodyClass.length && docBody.classList.contains(bodyClass)) + docBody.classList.remove(bodyClass); + + bodyClass = '_' + css.href.split('/').pop().split('.')[0]; + + // Add bodyClass + docBody.classList.add(bodyClass); + } + + // Slight delay. + function react() { + // Clear the timer as window resize fires, + // so that it only calls adapt() when the + // user has finished resizing the window. + clearTimeout(timer); + + // Start the timer countdown. + timer = setTimeout(adapt, 16); + // -----------------------^^ + // Note: 15.6 milliseconds is lowest "safe" + // duration for setTimeout and setInterval. + // + // http://www.nczonline.net/blog/2011/12/14/timer-resolution-in-browsers + } + + // Setup adapt after DOM is loaded + if ( d.readyState === "complete" || + ( d.readyState !== "loading" && !d.documentElement.doScroll ) ) { + setupAdapt(); + } else { + d.addEventListener( "DOMContentLoaded", setupAdapt ); + } + + // Pass in window, document, config, undefined. })(this, this.document, ADAPT_CONFIG); From 24ac237797e7def07f795375db9cecd72898a2df Mon Sep 17 00:00:00 2001 From: Matthew Sigley Date: Tue, 25 Apr 2017 12:06:12 -0400 Subject: [PATCH 4/9] Updated version to 2.0.0 --- assets/js/adapt.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/assets/js/adapt.js b/assets/js/adapt.js index 7a3495d..cc64f0d 100644 --- a/assets/js/adapt.js +++ b/assets/js/adapt.js @@ -6,9 +6,9 @@ */ /* - Adapt.js licensed under GPL and MIT. - - Read more here: http://adapt.960.gs +Adapt.js licensed under GPL and MIT. +Read more here: http://adapt.960.gs +Version 2.0.0 */ // Closure. From 09b8d8d33928aa3f4ad39d217fcebd21767ae3c0 Mon Sep 17 00:00:00 2001 From: Matthew Sigley Date: Tue, 25 Apr 2017 12:06:47 -0400 Subject: [PATCH 5/9] Re-minified for version 2.0.0 --- assets/js/adapt.min.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/assets/js/adapt.min.js b/assets/js/adapt.min.js index 0d552e7..471383b 100644 --- a/assets/js/adapt.min.js +++ b/assets/js/adapt.min.js @@ -1,2 +1,8 @@ -(function(d,g,a,m){function u(a,b){n=c.href=h;c.onload=function(){v(a,b)}}function k(){clearTimeout(p);var a=g.documentElement?g.documentElement.clientWidth:0,b,e,d,f,l=q,k=q-1;for(h=m;l--;)if(b=r[l].split("="),e=b[0],f=b[1]?b[1].replace(/\s/g,""):m,b=(d=e.match("to"))?parseInt(e.split("to")[0],10):parseInt(e,10),e=d?parseInt(e.split("to")[1],10):m,!e&&l===k&&a>b||a>b&&a<=e){f&&(h=w+f);break}!h||n&&n===h||(c&&(t.removeChild(c),c=null),c=g.createElement("link"),c.rel="stylesheet",c.media="screen", -u(l,a),t.appendChild(c))}function f(){clearTimeout(p);p=setTimeout(k,16)}if(a){var t=g.head||g.getElementsByTagName("head")[0],h,n,p,c,v=a.callback||function(){},w=a.path?a.path:"",r=a.range,q=r.length;k();a.dynamic&&(d.addEventListener?d.addEventListener("resize",f,!1):d.attachEvent?d.attachEvent("onresize",f):d.onresize=f)}})(this,this.document,ADAPT_CONFIG); +/* + Adapt.js licensed under GPL and MIT. + Read more here: http://adapt.960.gs + Version 2.0.0 +*/ +(function(f,b,c,n){function p(){b.removeEventListener("DOMContentLoaded",p);l=b.head||b.getElementsByTagName("head")[0];r=b.body||b.getElementsByTagName("body")[0];m="";c.cssId&&(a=b.getElementById(c.cssId));x();c.dynamic&&(f.addEventListener?f.addEventListener("resize",v,!1):f.attachEvent?f.attachEvent("onresize",v):f.onresize=v)}function y(a,b,d){t=d.href=k;d.onload=function(){e&&(l.removeChild(e),e=n);z(a,b)}}function x(){clearTimeout(w);e&&(l.removeChild(e),e=n);var c=b.documentElement?b.documentElement.clientWidth: +0,g,d,f,q,h=A,p=A-1;for(k=n;h--;)if(equalPos=u[h].indexOf("="),g=u[h].substr(0,equalPos),q=(q=u[h].substr(equalPos+1))?q.replace(/\s/g,""):n,d=(f=g.match("to"))?parseInt(g.split("to")[0],10):parseInt(g,10),g=f?parseInt(g.split("to")[1],10):n,!g&&h===p&&c>d||c>d&&c<=g){q&&(k=B+q);break}!k||t&&t===k||(a?a.href!==k?(d=b.createElement("link"),d.rel="stylesheet",d.media=a.media,d.id=a.id,y(h,c,d),e=a,e.id+="_old",a.nextSibling?l.insertBefore(d,a.nextSibling):l.appendChild(d),a=d):(t=k,z(h,c)):(a=b.createElement("link"), +a.rel="stylesheet",a.media="screen",y(h,c,a),l.appendChild(a)));m.length&&r.classList.contains(m)&&r.classList.remove(m);m="_"+a.href.split("/").pop().split(".")[0];r.classList.add(m)}function v(){clearTimeout(w);w=setTimeout(x,16)}if(c){var l,r,m,k,t,w,a,e,z=c.callback||function(){},B=c.path?c.path:"",u=c.range,A=u.length;"complete"===b.readyState||"loading"!==b.readyState&&!b.documentElement.doScroll?p():b.addEventListener("DOMContentLoaded",p)}})(this,this.document,ADAPT_CONFIG); From 2f8d72f5c2b8adc6045abc90f0ef4bf6d1d4ebdf Mon Sep 17 00:00:00 2001 From: Matthew Sigley Date: Thu, 22 Mar 2018 13:36:34 -0400 Subject: [PATCH 6/9] Prevent css body class from constantly being updated in resize event --- assets/js/adapt.js | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/assets/js/adapt.js b/assets/js/adapt.js index cc64f0d..8d76cd6 100644 --- a/assets/js/adapt.js +++ b/assets/js/adapt.js @@ -6,9 +6,9 @@ */ /* -Adapt.js licensed under GPL and MIT. -Read more here: http://adapt.960.gs -Version 2.0.0 + Adapt.js licensed under GPL and MIT. + + Read more here: http://adapt.960.gs */ // Closure. @@ -180,17 +180,17 @@ Version 2.0.0 // Append css to end of head docHead.appendChild(css); } - } - // Update css body class - // Remove bodyClass - if (bodyClass.length && docBody.classList.contains(bodyClass)) - docBody.classList.remove(bodyClass); + // Update css body class + // Remove bodyClass + if (bodyClass.length && docBody.classList.contains(bodyClass)) + docBody.classList.remove(bodyClass); - bodyClass = '_' + css.href.split('/').pop().split('.')[0]; - - // Add bodyClass - docBody.classList.add(bodyClass); + bodyClass = '_' + css.href.split('/').pop().split('.')[0]; + + // Add bodyClass + docBody.classList.add(bodyClass); + } } // Slight delay. @@ -201,12 +201,10 @@ Version 2.0.0 clearTimeout(timer); // Start the timer countdown. - timer = setTimeout(adapt, 16); + timer = setTimeout(adapt, 20); // -----------------------^^ - // Note: 15.6 milliseconds is lowest "safe" + // Note: 20 milliseconds is lowest "safe" // duration for setTimeout and setInterval. - // - // http://www.nczonline.net/blog/2011/12/14/timer-resolution-in-browsers } // Setup adapt after DOM is loaded From c8d72a38f6c4aa51d5f8c74e7eee9f42b2757259 Mon Sep 17 00:00:00 2001 From: Matthew Sigley Date: Thu, 22 Mar 2018 13:39:19 -0400 Subject: [PATCH 7/9] Reminified for 2.0.1 --- assets/js/adapt.min.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/assets/js/adapt.min.js b/assets/js/adapt.min.js index 471383b..24b9ad7 100644 --- a/assets/js/adapt.min.js +++ b/assets/js/adapt.min.js @@ -1,8 +1,8 @@ /* Adapt.js licensed under GPL and MIT. Read more here: http://adapt.960.gs - Version 2.0.0 + Version 2.0.1 */ -(function(f,b,c,n){function p(){b.removeEventListener("DOMContentLoaded",p);l=b.head||b.getElementsByTagName("head")[0];r=b.body||b.getElementsByTagName("body")[0];m="";c.cssId&&(a=b.getElementById(c.cssId));x();c.dynamic&&(f.addEventListener?f.addEventListener("resize",v,!1):f.attachEvent?f.attachEvent("onresize",v):f.onresize=v)}function y(a,b,d){t=d.href=k;d.onload=function(){e&&(l.removeChild(e),e=n);z(a,b)}}function x(){clearTimeout(w);e&&(l.removeChild(e),e=n);var c=b.documentElement?b.documentElement.clientWidth: -0,g,d,f,q,h=A,p=A-1;for(k=n;h--;)if(equalPos=u[h].indexOf("="),g=u[h].substr(0,equalPos),q=(q=u[h].substr(equalPos+1))?q.replace(/\s/g,""):n,d=(f=g.match("to"))?parseInt(g.split("to")[0],10):parseInt(g,10),g=f?parseInt(g.split("to")[1],10):n,!g&&h===p&&c>d||c>d&&c<=g){q&&(k=B+q);break}!k||t&&t===k||(a?a.href!==k?(d=b.createElement("link"),d.rel="stylesheet",d.media=a.media,d.id=a.id,y(h,c,d),e=a,e.id+="_old",a.nextSibling?l.insertBefore(d,a.nextSibling):l.appendChild(d),a=d):(t=k,z(h,c)):(a=b.createElement("link"), -a.rel="stylesheet",a.media="screen",y(h,c,a),l.appendChild(a)));m.length&&r.classList.contains(m)&&r.classList.remove(m);m="_"+a.href.split("/").pop().split(".")[0];r.classList.add(m)}function v(){clearTimeout(w);w=setTimeout(x,16)}if(c){var l,r,m,k,t,w,a,e,z=c.callback||function(){},B=c.path?c.path:"",u=c.range,A=u.length;"complete"===b.readyState||"loading"!==b.readyState&&!b.documentElement.doScroll?p():b.addEventListener("DOMContentLoaded",p)}})(this,this.document,ADAPT_CONFIG); +(function(g,b,c,n){function p(){b.removeEventListener("DOMContentLoaded",p);l=b.head||b.getElementsByTagName("head")[0];q=b.body||b.getElementsByTagName("body")[0];m="";c.cssId&&(a=b.getElementById(c.cssId));x();c.dynamic&&(g.addEventListener?g.addEventListener("resize",v,!1):g.attachEvent?g.attachEvent("onresize",v):g.onresize=v)}function y(a,b,d){r=d.href=h;d.onload=function(){f&&(l.removeChild(f),f=n);z(a,b)}}function x(){clearTimeout(w);f&&(l.removeChild(f),f=n);var c=b.documentElement?b.documentElement.clientWidth: +0,g,d=A,p=A-1;for(h=n;d--;){equalPos=t[d].indexOf("=");var k=t[d].substr(0,equalPos);var u=(u=t[d].substr(equalPos+1))?u.replace(/\s/g,""):n;var e=(g=k.match("to"))?parseInt(k.split("to")[0],10):parseInt(k,10);k=g?parseInt(k.split("to")[1],10):n;if(!k&&d===p&&c>e||c>e&&c<=k){u&&(h=B+u);break}}!h||r&&r===h||(a?a.href!==h?(e=b.createElement("link"),e.rel="stylesheet",e.media=a.media,e.id=a.id,y(d,c,e),f=a,f.id+="_old",a.nextSibling?l.insertBefore(e,a.nextSibling):l.appendChild(e),a=e):(r=h,z(d,c)): +(a=b.createElement("link"),a.rel="stylesheet",a.media="screen",y(d,c,a),l.appendChild(a)),m.length&&q.classList.contains(m)&&q.classList.remove(m),m="_"+a.href.split("/").pop().split(".")[0],q.classList.add(m))}function v(){clearTimeout(w);w=setTimeout(x,20)}if(c){var l,q,m,h,r,w,a,f,z=c.callback||function(){},B=c.path?c.path:"",t=c.range,A=t.length;"complete"===b.readyState||"loading"!==b.readyState&&!b.documentElement.doScroll?p():b.addEventListener("DOMContentLoaded",p)}})(this,this.document,ADAPT_CONFIG); From 8acb76873e493e22b7b99e2401769cb7c4e72f8e Mon Sep 17 00:00:00 2001 From: Matthew Sigley Date: Fri, 30 Nov 2018 18:30:03 -0500 Subject: [PATCH 8/9] Fixed body classes. --- assets/js/adapt.js | 101 +++++++++++++++++++++++++-------------------- 1 file changed, 57 insertions(+), 44 deletions(-) diff --git a/assets/js/adapt.js b/assets/js/adapt.js index 8d76cd6..06c117d 100644 --- a/assets/js/adapt.js +++ b/assets/js/adapt.js @@ -43,6 +43,16 @@ // Fire off once. adapt(); + // Clean up any preexisting body classes + var classesToRemove = []; + for (var i = 0; i < docBody.classList.length; i++) { + if( docBody.classList[i].charAt(0) == '_' && docBody.classList[i] != bodyClass ) + classesToRemove[classesToRemove.length] = docBody.classList[i]; + } + for (var i = 0; i < classesToRemove.length; i++) { + docBody.classList.remove(classesToRemove[i]); + } + // Do we want to watch for // resize and device tilt? if (config.dynamic) { @@ -140,56 +150,59 @@ } } - // Update css link tag, only if css url has changed - if (url && (!url_old || url_old !== url)) { - if (css) { - if(css.href !== url) { + if (url) { + // Update css link tag, only if css url has changed + if(!url_old || url_old !== url) { + if (css) { + if(css.href !== url) { + // Create empty link tag: + // + var newCss = d.createElement('link'); + newCss.rel = 'stylesheet'; + newCss.media = css.media; + newCss.id = css.id; + // Apply changes. + change(i, width, newCss); + + // Prevent overflowing flash of content + css_old = css; + css_old.id += '_old'; //Prevent duplicate IDs + + // Preserve css load order with graceful content stepping + if(css.nextSibling) + docHead.insertBefore(newCss, css.nextSibling); + else + docHead.appendChild(newCss); + css = newCss; + } else { + // Fire callback even if css link element wasn't changed. + url_old = url; + callback(i, width); + } + } else { // Create empty link tag: // - var newCss = d.createElement('link'); - newCss.rel = 'stylesheet'; - newCss.media = css.media; - newCss.id = css.id; + css = d.createElement('link'); + css.rel = 'stylesheet'; + css.media = 'screen'; // Apply changes. - change(i, width, newCss); - - // Prevent overflowing flash of content - css_old = css; - css_old.id += '_old'; //Prevent duplicate IDs - - // Preserve css load order with graceful content stepping - if(css.nextSibling) - docHead.insertBefore(newCss, css.nextSibling); - else - docHead.appendChild(newCss); - css = newCss; - } else { - // Fire callback even if css link element wasn't changed. - url_old = url; - callback(i, width); + change(i, width, css); + + // Append css to end of head + docHead.appendChild(css); } - } else { - // Create empty link tag: - // - css = d.createElement('link'); - css.rel = 'stylesheet'; - css.media = 'screen'; - // Apply changes. - change(i, width, css); - - // Append css to end of head - docHead.appendChild(css); } - // Update css body class - // Remove bodyClass - if (bodyClass.length && docBody.classList.contains(bodyClass)) - docBody.classList.remove(bodyClass); - - bodyClass = '_' + css.href.split('/').pop().split('.')[0]; - - // Add bodyClass - docBody.classList.add(bodyClass); + // Update css body class if it has changed + var newBodyClass = '_' + url.split('/').pop().split('.')[0]; + if( newBodyClass != bodyClass ) { + // Remove bodyClass + if (bodyClass.length && docBody.classList.contains(bodyClass)) + docBody.classList.remove(bodyClass); + bodyClass = newBodyClass; + // Add bodyClass + docBody.classList.add(bodyClass); + } } } From 8e7a17465768f53214e39cadbba0bf5e8dc36543 Mon Sep 17 00:00:00 2001 From: Matthew Sigley Date: Fri, 30 Nov 2018 18:30:52 -0500 Subject: [PATCH 9/9] Update adapt.min.js --- assets/js/adapt.min.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/assets/js/adapt.min.js b/assets/js/adapt.min.js index 24b9ad7..88add8a 100644 --- a/assets/js/adapt.min.js +++ b/assets/js/adapt.min.js @@ -1,8 +1,9 @@ /* Adapt.js licensed under GPL and MIT. Read more here: http://adapt.960.gs - Version 2.0.1 + Version 2.0.2 */ -(function(g,b,c,n){function p(){b.removeEventListener("DOMContentLoaded",p);l=b.head||b.getElementsByTagName("head")[0];q=b.body||b.getElementsByTagName("body")[0];m="";c.cssId&&(a=b.getElementById(c.cssId));x();c.dynamic&&(g.addEventListener?g.addEventListener("resize",v,!1):g.attachEvent?g.attachEvent("onresize",v):g.onresize=v)}function y(a,b,d){r=d.href=h;d.onload=function(){f&&(l.removeChild(f),f=n);z(a,b)}}function x(){clearTimeout(w);f&&(l.removeChild(f),f=n);var c=b.documentElement?b.documentElement.clientWidth: -0,g,d=A,p=A-1;for(h=n;d--;){equalPos=t[d].indexOf("=");var k=t[d].substr(0,equalPos);var u=(u=t[d].substr(equalPos+1))?u.replace(/\s/g,""):n;var e=(g=k.match("to"))?parseInt(k.split("to")[0],10):parseInt(k,10);k=g?parseInt(k.split("to")[1],10):n;if(!k&&d===p&&c>e||c>e&&c<=k){u&&(h=B+u);break}}!h||r&&r===h||(a?a.href!==h?(e=b.createElement("link"),e.rel="stylesheet",e.media=a.media,e.id=a.id,y(d,c,e),f=a,f.id+="_old",a.nextSibling?l.insertBefore(e,a.nextSibling):l.appendChild(e),a=e):(r=h,z(d,c)): -(a=b.createElement("link"),a.rel="stylesheet",a.media="screen",y(d,c,a),l.appendChild(a)),m.length&&q.classList.contains(m)&&q.classList.remove(m),m="_"+a.href.split("/").pop().split(".")[0],q.classList.add(m))}function v(){clearTimeout(w);w=setTimeout(x,20)}if(c){var l,q,m,h,r,w,a,f,z=c.callback||function(){},B=c.path?c.path:"",t=c.range,A=t.length;"complete"===b.readyState||"loading"!==b.readyState&&!b.documentElement.doScroll?p():b.addEventListener("DOMContentLoaded",p)}})(this,this.document,ADAPT_CONFIG); +(function(m,c,a,q){function v(){c.removeEventListener("DOMContentLoaded",v);p=c.head||c.getElementsByTagName("head")[0];g=c.body||c.getElementsByTagName("body")[0];k="";a.cssId&&(b=c.getElementById(a.cssId));y();for(var d=[],e=0;ef||d>f&&d<=n){u&&(l=C+u);break}}l&&(r&&r===l||(b? +b.href!==l?(f=c.createElement("link"),f.rel="stylesheet",f.media=b.media,f.id=b.id,z(a,d,f),h=b,h.id+="_old",b.nextSibling?p.insertBefore(f,b.nextSibling):p.appendChild(f),b=f):(r=l,A(a,d)):(b=c.createElement("link"),b.rel="stylesheet",b.media="screen",z(a,d,b),p.appendChild(b))),d="_"+l.split("/").pop().split(".")[0],d!=k&&(k.length&&g.classList.contains(k)&&g.classList.remove(k),k=d,g.classList.add(k)))}function w(){clearTimeout(x);x=setTimeout(y,20)}if(a){var p,g,k,l,r,x,b,h,A=a.callback||function(){}, +C=a.path?a.path:"",t=a.range,B=t.length;"complete"===c.readyState||"loading"!==c.readyState&&!c.documentElement.doScroll?v():c.addEventListener("DOMContentLoaded",v)}})(this,this.document,ADAPT_CONFIG);