forked from headjs/headjs
/
head.min.js
7 lines (6 loc) · 4.7 KB
/
head.min.js
1
2
3
4
5
6
7
/**
Head JS: The only script in your <HEAD>
copyright: "tipiirai" / Tero Piirainen
license: MIT
*/
(function(a){var b=a.documentElement,c={screens:[320,480,640,768,1024,1280,1440,1680,1920],section:"-section",page:"-page",head:"head"},d=[];if(typeof window.head_conf=="object")for(var e in head_conf)head_conf[e]&&(c[e]=head_conf[e]);window.head_conf=c;function f(a){d.push(a)}function g(a){var c=new RegExp("\\b"+a+"\\b");b.className=b.className.replace(c,"")}function h(a,b){for(var c=0;c<a.length;c++)b.call(a,a[c],c)}var i=window[c.head]=function(){i.ready.apply(null,arguments)};i.feature=function(a,c,e){if(a)e||(g("no-"+a),g(a));else{b.className+=" "+d.join(" ");return d=[]}f((c?"":"no-")+a),i[a]=c;return i};var j=navigator.userAgent.toLowerCase();j=/(webkit)[ \/]([\w.]+)/.exec(j)||/(opera)(?:.*version)?[ \/]([\w.]+)/.exec(j)||/(msie) ([\w.]+)/.exec(j)||!/compatible/.test(j)&&/(mozilla)(?:.*? rv:([\w.]+))?/.exec(j)||[],j[1]=="msie"&&(j[1]="ie"),f(j[1]),i.browser={version:j[2]},i.browser[j[1]]=!0;if(i.browser.ie)for(var k=3;k<11;k++)parseFloat(j[2])<k&&f("lt-ie"+k);h("abbr|article|aside|audio|canvas|details|figcaption|figure|footer|header|hgroup|mark|meter|nav|output|progress|section|summary|time|video".split("|"),function(b){a.createElement(b)});var l=location.pathname,m=l.split("/"),n=m.slice(0,m.length-1).join("-")||"root",o=m.slice(-1)[0]||"index",p=o.indexOf(".");p>=0&&(o=o.substring(0,p)),i.section=n,i.pageId=o,f(n+c.section),b.id=o+c.page;function q(){var a=window.outerWidth||b.clientWidth;b.className=b.className.replace(/ (w|lt)-\d+/g,""),f("w-"+Math.round(a/100)*100),h(c.screens,function(b){a<=b&&f("lt-"+b)}),i.feature()}q(),window.onresize=q,i.feature("script",!0).feature()})(document),function(a){var b=document.createElement("i"),c=b.style,d=" -o- -moz- -ms- -webkit- -khtml- ".split(" ");function e(a){c.cssText=d.join(a+";");var b=c.cssText?c.cssText.length:0;return b>0&&!c.cssText.split(";")[1]}var f={gradient:function(){var a="background-image:",b="gradient(linear,left top,right bottom,from(#9f9),to(#fff));",e="linear-gradient(left top,#eee,#fff);";c.cssText=(a+d.join(b+a)+d.join(e+a)).slice(0,-a.length);return c.backgroundImage},rgba:function(){c.cssText="background-color:rgba(0,0,0,0.5)";return c.backgroundColor},boxshadow:function(){return e("box-shadow: 0 0 0 red")},textshadow:function(){return c.textShadow===""},multiplebgs:function(){c.cssText="background:url(//:),url(//:),red url(//:)";return(new RegExp("(url\\s*\\(.*?){3}")).test(c.background)},borderimage:function(){return e("border-image: url(m.png) 1 1 stretch")},borderradius:function(){return e("border-radius:0")},opacity:function(){return b.style.opacity===""},reflections:function(){return e("box-reflect:right 0")},transforms:function(){return e("transform:rotate(1deg)")},transitions:function(){return e("transition:all .1s linear")}};for(var g in f)f[g]&&a.feature(g,f[g].call(),!0);a.feature()}(window[head_conf.head]),function(a){var b=a.documentElement,c=!1,d=[],e=[],f={},g={},h=window.head_conf&&head_conf.head||"head",i=window[h]=window[h]||{};i.js=function(){var a=arguments,b=[].slice.call(a,1),e=b[0];if(!c){d.push(function(){i.js.apply(null,a)});return i}e?(l(e)||m.apply(null,b),p(j(a[0]),l(e)?e:function(){i.js.apply(null,b)})):p(j(a[0]));return i},i.ready=function(a,b){if(l(a))return e.push(a);var c=f[a];c?c.push(b):c=f[a]=[b];return i};function j(a){var b=g[a.url||a];if(b)return b;if(typeof a=="object")for(var c in a)a[c]&&(b={name:c,url:a[c]});else b={name:a.substring(a.indexOf("/",10)+1,a.indexOf("?")),url:a};g[b.url]=b;return b}function k(a,b){if(a){typeof a=="object"&&(a=[].slice.call(a));for(var c=0;c<a.length;c++)b.call(a,a[c],c)}}function l(a){return Object.prototype.toString.call(a)=="[object Function]"}function m(){k(arguments,function(a){l(a)||o(j(a))})}function n(a){a.state="preloaded",k(a.onpreload,function(a){a.call()})}function o(c,d){if(!c.state){c.state="preloading",c.onpreload=[];if(/Firefox/.test(navigator.userAgent)){var e=a.createElement("object");e.data=c.url,e.width=0,e.height=0,e.onload=function(){n(c),setTimeout(function(){b.removeChild(e)},1)},b.appendChild(e)}else q({src:c.url,type:"cache"},function(){n(c)})}}function p(a,b){if(a.state=="loaded")return b();if(a.state=="preloading")return a.onpreload.push(function(){p(a,b)});a.state="loading",q(a.url,function(){a.state="loaded",b&&b.call(),k(f[a.name],function(a){a.call()});var c=!0;for(var d in g)g[d].state!="loaded"&&(c=!1);c&&k(e,function(a){a.done||a.call(),a.done=!0})})}function q(c,d){var e=a.createElement("script");e.type="text/"+(c.type||"javascript"),e.src=c.src||c,e.onreadystatechange=e.onload=function(){d.done||(d.call(),d.done=!0),document.all||b.removeChild(e)},b.appendChild(e)}setTimeout(function(){c=!0,k(d,function(a){a.call()})},200)}(document)