Browse files

Fixed a couple of IE bugs and made new combined & minified versions. …

…Should be on alpha 0.1.0 level now.
  • Loading branch information...
1 parent 59a77c4 commit 65bfc750476cf08bbd806c3fd47b25fbd8a89cd7 @tipiirai tipiirai committed Dec 1, 2010
Showing with 43 additions and 56 deletions.
  1. +29 −45 head.js
  2. +1 −1 head.min.js
  3. +3 −3 src/head.core.js
  4. +2 −2 src/head.detect.js
  5. +2 −2 test/ie.js
  6. +6 −3 test/index.html
View
74 head.js
@@ -47,28 +47,7 @@
addClass((enabled ? '' : 'no-') + key);
api[key] = !!enabled;
return api;
- };
-
- api.cookie = function(name, val, expires) {
-
- if (val === undefined) {
- var cook = document.cookie;
-
- if (cook) {
- var i = cook.indexOf(name + "=");
- if (i > -1) {
- var end = cook.indexOf(";", i);
- return cook.substring(i + name.length + 1, end > -1 ? end : cook.length);
- }
- }
- } else {
- document.cookie = name +"="+ escape(val) + (
- expires ? ";expires=" +(new Date((new Date()).getTime() + 100000000)).toUTCString() : ""
- );
- }
- return api;
- };
-
+ };
// browser type & version
var ua = navigator.userAgent.toLowerCase();
@@ -78,40 +57,39 @@
/(msie) ([\w.]+)/.exec( ua ) ||
!/compatible/.test( ua ) && /(mozilla)(?:.*? rv:([\w.]+))?/.exec( ua ) || [];
- if (ua[1] == 'msie') ua[1] == 'ie';
+ if (ua[1] == 'msie') ua[1] = 'ie';
addClass(ua[1]);
- addClass(ua[1] + ua[2].replace(".", "").substring(0, 2));
+ // addClass(ua[1] + ua[2].replace(/\./g, "").substring(0, 3));
- head.browser = { version: parseFloat(ua[2]) };
- head.browser[ua[1]] = true;
+ api.browser = { version: ua[2] };
+ api.browser[ua[1]] = true;
// IE specific
- if (head.browser.ie) {
+ if (api.browser.ie) {
// IE versions
for (var ver = 3; ver < 11; ver++) {
- if (ua[2] <= ver) { addClass("lt-ie" + ver); }
+ if (parseFloat(ua[2]) < ver) { addClass("lt-ie" + ver); }
}
}
// HTML5 support
- each("article|aside|footer|header|nav|section".split("|"), function(el) {
+ each("abbr|article|aside|audio|canvas|details|figcaption|figure|footer|header|hgroup|mark|meter|nav|output|progress|section|summary|time|video".split("|"), function(el) {
doc.createElement(el);
});
// page class && id
- var root = location.host,
- path = location.href.substring(location.href.indexOf(root) + root.length + 1),
+ var path = location.pathname,
els = path.split("/"),
- section = els.slice(0, els.length -1).join("-") || "root";
+ section = els.slice(0, els.length -1).join("-") || "root",
pageId = els.slice(-1)[0] || "index",
index = pageId.indexOf(".");
if (index >= 0) { pageId = pageId.substring(0, index); }
- head.section = section;
- head.pageId = pageId;
+ api.section = section;
+ api.pageId = pageId;
addClass(section + conf.section);
html.id = pageId + conf.page;
@@ -154,7 +132,7 @@
function testAll(definition) {
style.cssText = prefs.join(definition + ";");
var len = style.cssText ? style.cssText.length : 0;
- return len > 0 && len < 150;
+ return len > 0 && !style.cssText.split(";")[1];
}
var tests = {
@@ -207,7 +185,7 @@
},
transitions: function() {
- return testAll("transition:all .5s linear");
+ return testAll("transition:all .1s linear");
}
};
@@ -229,9 +207,9 @@
/*** public API ***/
- var head_var = window.head_conf ? head_conf.head : "head",
- api = window[head_var] = (window[head_var] || {});
-
+ var head_var = window.head_conf && head_conf.head || "head",
+ api = window[head_var] = (window[head_var] || {});
+
api.js = function() {
var args = arguments,
@@ -273,7 +251,7 @@
else arr.push[fn];
return api.js;
};
-
+
/*
api.dump = function() {
console.info(scripts);
@@ -287,7 +265,7 @@
if (script) return script;
if (typeof url == 'object') {
- for (key in url) {
+ for (var key in url) {
script = { name: key, url: url[key] };
}
} else {
@@ -310,14 +288,14 @@
}
function isFunc(el) {
- return typeof el == 'function';
+ return Object.prototype.toString.call(el) == '[object Function]';
}
function preloadAll() {
each(arguments, function(el) {
if (!isFunc(el)) {
preload(getScript(el));
- }
+ }
});
}
@@ -339,7 +317,11 @@
});
}
- if (head.browser.mozilla) {
+ /*
+ Browser detection required. Firefox does not support script.type = text/cache
+ http://www.phpied.com/preload-cssjavascript-without-execution/
+ */
+ if (/Firefox/.test(navigator.userAgent)) {
var obj = doc.createElement('object');
obj.data = script.url;
obj.width = 0;
@@ -421,7 +403,9 @@
callback.call();
callback.done = true;
}
- if (!api.browser.ie) {
+
+ // cleanup. IE runs into trouble
+ if (!document.all) {
head.removeChild(elem);
}
};
View
2 head.min.js
@@ -4,4 +4,4 @@
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"};if(typeof window.head_conf=="object")for(var d in head_conf)c[d]=head_conf[d];window.head_conf=c;function e(a){b.className+=" "+a}function f(a){var c=new RegExp("\\b"+a+"\\b");b.className=b.className.replace(c,"")}function g(a,b){for(var c=0;c<a.length;c++)b.call(a,a[c],c)}var h=window[c.head]=function(){h.ready.apply(null,arguments)};h.feature=function(a,b){f("no-"+a),f(a),e((b?"":"no-")+a),h[a]=b;return h},h.cookie=function(a,b,c){if(b===undefined){var d=document.cookie;if(d){var e=d.indexOf(a+"=");if(e>-1){var f=d.indexOf(";",e);return d.substring(e+a.length+1,f>-1?f:d.length)}}}else document.cookie=a+"="+escape(b)+(c?";expires="+(new Date((new Date).getTime()+1e8)).toUTCString():"");return h};var i=navigator.userAgent.toLowerCase();i=/(webkit)[ \/]([\w.]+)/.exec(i)||/(opera)(?:.*version)?[ \/]([\w.]+)/.exec(i)||/(msie) ([\w.]+)/.exec(i)||!/compatible/.test(i)&&/(mozilla)(?:.*? rv:([\w.]+))?/.exec(i)||[],i[1]=="msie"&&i[1]=="ie",e(i[1]),e(i[1]+i[2].replace(".","").substring(0,2)),head.browser={version:parseFloat(i[2])},head.browser[i[1]]=!0;if(head.browser.ie)for(var j=3;j<11;j++)i[2]<=j&&e("lt-ie"+j);g("article|aside|footer|header|nav|section".split("|"),function(b){a.createElement(b)});var k=location.host,l=location.href.substring(location.href.indexOf(k)+k.length+1),m=l.split("/"),n=m.slice(0,m.length-1).join("-")||"root";pageId=m.slice(-1)[0]||"index",index=pageId.indexOf("."),index>=0&&(pageId=pageId.substring(0,index)),head.section=n,head.pageId=pageId,e(n+c.section),b.id=pageId+c.page;function o(){var a=document.width||window.outerWidth||document.documentElement.clientWidth;b.className=b.className.replace(/ (w|lt)-\d+/g,""),e("w-"+Math.round(a/100)*100),g(c.screens,function(b){a<=b&&e("lt-"+b)})}o(),window.onresize=o,head.feature("script",!0)})(document),function(a){var b=a.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&&b<150}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 e("opacity:.1")},reflections:function(){return e("box-reflect:right 0")},transforms:function(){return e("transform:rotate(1deg)")},transitions:function(){return e("transition:all .5s linear")}},g=window[head_conf.head];for(var h in f)g.feature(h,f[h].call())}(document),function(a){var b=!1,c=[],d=[],e={},f={},g=window.head_conf?head_conf.head:"head",h=window[g]=window[g]||{};h.js=function(){var a=arguments,d=[].slice.call(a,1),e=d[0];if(!b)return c.push(function(){h.js.apply(null,a)});e?(k(e)||l.apply(null,d),n(i(a[0]),k(e)?e:function(){h.js.apply(null,d)})):n(i(a[0]));return h.js},h.ready=function(a,b){if(k(a))return d.push(a);var c=e[a];c?c.push[b]:c=e[a]=[b];return h.js};function i(a){var b=f[a.url||a];if(b)return b;if(typeof a=="object")for(key in a)b={name:key,url:a[key]};else b={name:a.substring(a.indexOf("/",10)+1,a.indexOf("?")),url:a};f[b.url]=b;return b}function j(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 k(a){return typeof a=="function"}function l(){j(arguments,function(a){k(a)||m(i(a))})}function m(b,c){if(!b.state){b.state="preloading",b.onpreload=[];function d(){b.state="preloaded",j(b.onpreload,function(a){a.call()})}if(head.browser.mozilla){var e=a.createElement("object");e.data=b.url,e.width=0,e.height=0,e.onload=function(){d(),setTimeout(function(){a.body.removeChild(e)},1)},a.body.appendChild(e)}else o({src:b.url,type:"cache"},d)}}function n(a,b){if(a.state=="loaded")return b();if(a.state=="preloading")return a.onpreload.push(function(){n(a,b)});a.state="loading",o(a.url,function(){a.state="loaded",b&&b.call(),j(e[a.name],function(a){a.call()});var c=!0;for(var g in f)f[g].state!="loaded"&&(c=!1);c&&j(d,function(a){a.done||a.call(),a.done=!0})})}function o(b,c){var d=a.getElementsByTagName("head")[0],e=a.createElement("script");e.type="text/"+(b.type||"javascript"),e.src=b.src||b,e.onreadystatechange=e.onload=function(){c.done||(c.call(),c.done=!0),h.browser.ie||d.removeChild(e)},d.appendChild(e)}setTimeout(function(){b=!0,j(c,function(a){a.call()})},50)}(document)
+(function(a){var b=a.documentElement,c={screens:[320,480,640,768,1024,1280,1440,1680,1920],section:"-section",page:"-page",head:"head"};if(typeof window.head_conf=="object")for(var d in head_conf)c[d]=head_conf[d];window.head_conf=c;function e(a){b.className+=" "+a}function f(a){var c=new RegExp("\\b"+a+"\\b");b.className=b.className.replace(c,"")}function g(a,b){for(var c=0;c<a.length;c++)b.call(a,a[c],c)}var h=window[c.head]=function(){h.ready.apply(null,arguments)};h.feature=function(a,b){f("no-"+a),f(a),e((b?"":"no-")+a),h[a]=b;return h};var i=navigator.userAgent.toLowerCase();i=/(webkit)[ \/]([\w.]+)/.exec(i)||/(opera)(?:.*version)?[ \/]([\w.]+)/.exec(i)||/(msie) ([\w.]+)/.exec(i)||!/compatible/.test(i)&&/(mozilla)(?:.*? rv:([\w.]+))?/.exec(i)||[],i[1]=="msie"&&(i[1]="ie"),e(i[1]),h.browser={version:i[2]},h.browser[i[1]]=!0;if(h.browser.ie)for(var j=3;j<11;j++)parseFloat(i[2])<j&&e("lt-ie"+j);g("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 k=location.pathname,l=k.split("/"),m=l.slice(0,l.length-1).join("-")||"root",n=l.slice(-1)[0]||"index",o=n.indexOf(".");o>=0&&(n=n.substring(0,o)),h.section=m,h.pageId=n,e(m+c.section),b.id=n+c.page;function p(){var a=document.width||window.outerWidth||document.documentElement.clientWidth;b.className=b.className.replace(/ (w|lt)-\d+/g,""),e("w-"+Math.round(a/100)*100),g(c.screens,function(b){a<=b&&e("lt-"+b)})}p(),window.onresize=p,head.feature("script",!0)})(document),function(a){var b=a.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 e("opacity:.1")},reflections:function(){return e("box-reflect:right 0")},transforms:function(){return e("transform:rotate(1deg)")},transitions:function(){return e("transition:all .1s linear")}},g=window[head_conf.head];for(var h in f)g.feature(h,f[h].call())}(document),function(a){var b=!1,c=[],d=[],e={},f={},g=window.head_conf&&head_conf.head||"head",h=window[g]=window[g]||{};h.js=function(){var a=arguments,d=[].slice.call(a,1),e=d[0];if(!b)return c.push(function(){h.js.apply(null,a)});e?(k(e)||l.apply(null,d),n(i(a[0]),k(e)?e:function(){h.js.apply(null,d)})):n(i(a[0]));return h.js},h.ready=function(a,b){if(k(a))return d.push(a);var c=e[a];c?c.push[b]:c=e[a]=[b];return h.js};function i(a){var b=f[a.url||a];if(b)return b;if(typeof a=="object")for(var c in a)b={name:c,url:a[c]};else b={name:a.substring(a.indexOf("/",10)+1,a.indexOf("?")),url:a};f[b.url]=b;return b}function j(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 k(a){return Object.prototype.toString.call(a)=="[object Function]"}function l(){j(arguments,function(a){k(a)||m(i(a))})}function m(b,c){if(!b.state){b.state="preloading",b.onpreload=[];function d(){b.state="preloaded",j(b.onpreload,function(a){a.call()})}if(/Firefox/.test(navigator.userAgent)){var e=a.createElement("object");e.data=b.url,e.width=0,e.height=0,e.onload=function(){d(),setTimeout(function(){a.body.removeChild(e)},1)},a.body.appendChild(e)}else o({src:b.url,type:"cache"},d)}}function n(a,b){if(a.state=="loaded")return b();if(a.state=="preloading")return a.onpreload.push(function(){n(a,b)});a.state="loading",o(a.url,function(){a.state="loaded",b&&b.call(),j(e[a.name],function(a){a.call()});var c=!0;for(var g in f)f[g].state!="loaded"&&(c=!1);c&&j(d,function(a){a.done||a.call(),a.done=!0})})}function o(b,c){var d=a.getElementsByTagName("head")[0],e=a.createElement("script");e.type="text/"+(b.type||"javascript"),e.src=b.src||b,e.onreadystatechange=e.onload=function(){c.done||(c.call(),c.done=!0),document.all||d.removeChild(e)},d.appendChild(e)}setTimeout(function(){b=!0,j(c,function(a){a.call()})},50)}(document)
View
6 src/head.core.js
@@ -57,19 +57,19 @@
/(msie) ([\w.]+)/.exec( ua ) ||
!/compatible/.test( ua ) && /(mozilla)(?:.*? rv:([\w.]+))?/.exec( ua ) || [];
- if (ua[1] == 'msie') ua[1] == 'ie';
+ if (ua[1] == 'msie') ua[1] = 'ie';
addClass(ua[1]);
// addClass(ua[1] + ua[2].replace(/\./g, "").substring(0, 3));
api.browser = { version: ua[2] };
api.browser[ua[1]] = true;
// IE specific
- if (head.browser.ie) {
+ if (api.browser.ie) {
// IE versions
for (var ver = 3; ver < 11; ver++) {
- if (parseFloat(ua[2]) <= ver) { addClass("lt-ie" + ver); }
+ if (parseFloat(ua[2]) < ver) { addClass("lt-ie" + ver); }
}
}
View
4 src/head.detect.js
@@ -32,7 +32,7 @@
function testAll(definition) {
style.cssText = prefs.join(definition + ";");
var len = style.cssText ? style.cssText.length : 0;
- return len > 0 && len < 150;
+ return len > 0 && !style.cssText.split(";")[1];
}
var tests = {
@@ -85,7 +85,7 @@
},
transitions: function() {
- return testAll("transition:all .5s linear");
+ return testAll("transition:all .1s linear");
}
};
View
4 test/ie.js
@@ -1,6 +1,7 @@
var console = {
info: function(a, b, c) {
+ var info = document.getElementById("info");
info.innerHTML += "<p>" + [].join.call(arguments) + "</p>";
},
@@ -10,5 +11,4 @@ var console = {
};
-var info = document.createElement("info");
-document.body.appendChild(info);
+
View
9 test/index.html
@@ -2,13 +2,14 @@
<head class="no-script">
<title>Test page</title>
- <!--[if IE 7 ]><script src=".ie.js"></script><![endif]-->
+ <!--[if IE]><script src="ie.js"></script><![endif]-->
<script>var head_conf = {screens: [100, 200, 2000], section: '-area', page: 'page'};</script>
+ <script src="../head.min.js"></script>
- <script src="../src/head.core.js"></script>
+ <!-- <script src="../src/head.core.js"></script>
<script src="../src/head.detect.js"></script>
- <script src="../src/head.loader.js"></script>
+ <script src="../src/head.loader.js"></script> -->
<link rel="stylesheet" type="text/css" href="http://192.168.0.102:2000/style.css?time=1"/>
</head>
@@ -17,6 +18,8 @@
<h2>headjs</h2>
+ <div id="info"></div>
+
<script>
(function() {

0 comments on commit 65bfc75

Please sign in to comment.