Skip to content

Commit

Permalink
Updating to 0.97a
Browse files Browse the repository at this point in the history
  • Loading branch information
robert-hoffmann committed Oct 19, 2012
1 parent 921318b commit 48d4823
Show file tree
Hide file tree
Showing 22 changed files with 4,376 additions and 2,404 deletions.
11 changes: 9 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
github.com
www
github.com
www
.idea*/
_Resharper*/
Web.config
WebWorkbench.mswwsettings
headjs.sln
headjs.v11.suo
dist/dist.chirp.config
48 changes: 43 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,61 @@
_**Hello everyone,**_
![Head JS](http://headjs.com/media/img/headjs.gif)

This project was never announced. `git push` and it was all viral.

The website: [http://headjs.com](http://headjs.com)

v0.97a / 2012-10-20

[Report a Bug](https://github.com/headjs/headjs/issues).

This project may have been sitting idle for the last year or so, but i [Robert](https://github.com/itechnology) have just gotten the green light from [Tipiirai](https://github.com/tipiirai) to try and keep the project alive together with [Paul](https://github.com/paulirish).

0.97a

- Updated QUnit & got unit tests running again
- Swictched to "use strict"
- Fixed up some variable usage
- Added browser detections other than just for ie-lt
- updated browser regexes (firefox, safari, opera, ios, android, webkit)
- detect if browser is: desktop, mobile, touch enabled
- detect portrait/landscape mode
- html5 shim now only triggers on ie-lt9
- added a throttle to onResize, since some browsers fire tons of events/sec
- added corrected height/width measurements, but only exposed via new object: head.screen
- contains height/width, innerHeight/innerWidth, outerHeight/outerWidth
- force all css router names to lowercase just in case ppl try typing in names with wierd casings

There will be a few questions to work out, but i think that [Head.JS](http://headjs.com) still solves some basic problems that many users are experiencing. Especially in the Enterprise, where we must support obsolete browsers while at the same time moving forward with our time.

Future

- In the immediate future i would like to patch up things that have been sitting on hold, and that people already using **HeadJS** can continue to use without any breaking changes.
- After that however things will likely change a bit
- Have a peek here [HeadJS@I-Technology](https://github.com/itechnology/headjs)
- For example :
- Programatically it's very had to use the current syntax of prefixig things with **no-**. Instead they should be suffixed with **-true/-false**. Like this it is very easy to generate variable on the fly and have them match your HeadJS rules.
- Currently screen detection is based on the **outerWidth** of the navigator window, so once you add tabs, scrollbars, sidebars, & toolbars ..you are probably in for a big surprise with your design! Therefore generated classes should instead reflect the actual screen estate availiable: **innerWidth/innerHeight**
- Right now you only get classes based on **lt**, but what about **lte, gt, and gte** ? Not to mention **height** ! :)


_**Rebooting HeadJS,**_

This project was sitting idle for the last year or so, but me [Robert Hoffmann](https://github.com/itechnology) and [Paul Irish](https://github.com/paulirish) have just gotten the green light from [Tipiirai](https://github.com/tipiirai) to try and keep the project alive a bit more :)


There will be a few questions to work out, but i think that **HeadJS** still solves the basic problems that many users are experiencing. Especially in the Enterprise, where we must support obsolete browsers while moving forward with our time.

1. Feature detection
* This area seems well covered by [Modernizr](http://modernizr.com)
2. Script loading
* This area also seems well covered by libraries like [YepNope.JS](http://yepnopejs.com) or [Require.JS](http://requirejs.org)
* [YepNope.JS](http://yepnopejs.com) can by the way be bundled into [Modernizr](http://modernizr.com)
3. Responsive design
* [Head.JS](http://headjs.com) handles this very well through css classes
* **HeadJS** handles this very well through css classes
* But there are other solutions like [Respond.JS](https://github.com/scottjehl/Respond) that work well too.
4. Browser detection
5. Plug browser quirks


Since points 1 & 2 seem pretty well covered, going forward we will need to decide if those functionalities should be removed or not from [Head.JS](http://headjs.com), to be able to concentrate on the points that [Head.JS](http://headjs.com) handles well: 3-5
Since points 1 & 2 seem pretty well covered, going forward we will need to decide if these functionalities should be removed or not from **HeadJS**, to we can concentrate on the points that **HeadJS** handles well: 3-5

If you're like me, and need to support browsers like IE6+, FF2+, and think head.js does a great job emulating responsive design, while letting you plug the odd bugs and quirks of your least favorite browsers...

Expand Down
17 changes: 17 additions & 0 deletions dist/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#Prepackaged Files

###head.js / head.min.js

- Complete package containing: core.js, css3.js, and load.js

###head.css3.js / head.css3.min.js

- Package containing: core.js and css3.js

###head.core.js / head.core.min.js

- Package containing only core.js

###head.load.js / head.load.min.js

- Package containing only load.js
276 changes: 276 additions & 0 deletions dist/head.core.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,276 @@
/**!
Head JS The only script in your <HEAD>
Copyright Tero Piirainen (tipiirai)
License MIT / http://bit.ly/mit-license
Version 0.97a
http://headjs.com
*/
; (function (win, undefined) {
"use strict";

var doc = win.document,
nav = win.navigator,
loc = win.location,
html = doc.documentElement,
klass = [],
conf = {
screens: [320, 480, 640, 768, 1024, 1280, 1440, 1680, 1920],
section: "-section",
page : "-page",
head : "head"
};

if (win.head_conf) {
for (var item in win.head_conf) {
if (win.head_conf[item] !== undefined) {
conf[item] = win.head_conf[item];
}
}
}

function pushClass(name) {
klass[klass.length] = name;
}

function removeClass(name) {
var re = new RegExp("\\b" + name + "\\b");
html.className = html.className.replace(re, '');
}

function each(arr, fn) {
for (var i = 0, l = arr.length; i < l; i++) {
fn.call(arr, arr[i], i);
}
}


// API
var api = win[conf.head] = function () {
api.ready.apply(null, arguments);
};

api.feature = function (key, enabled, queue) {

// internal: apply all classes
if (!key) {
html.className += ' ' + klass.join(' ');
klass = [];
return api;
}

if (Object.prototype.toString.call(enabled) === '[object Function]') {
enabled = enabled.call();
}

pushClass((enabled ? '' : 'no-') + key);
api[key] = !!enabled;

// apply class to HTML element
if (!queue) {
removeClass('no-' + key);
removeClass(key);
api.feature();
}

return api;
};

// no queue here, so we can remove any eventual pre-existing no-js class
api.feature("js", true);

// browser type & version
var ua = nav.userAgent.toLowerCase(),
mobile = /mobile|midp/.test(ua);

// useful for enabling/disabling feature (we can consider a desktop navigator to have more cpu/gpu power)
api.feature("mobile" , mobile , true);
api.feature("desktop", !mobile, true);
api.feature("touch" , 'ontouchstart' in win, true);

// http://www.zytrax.com/tech/web/browser_ids.htm
// http://www.zytrax.com/tech/web/mobile_ids.html
ua = /(chrome|firefox)[ \/]([\w.]+)/.exec(ua) || // Chrome & Firefox
/(iphone|ipad|ipod)(?:.*version)?[ \/]([\w.]+)/.exec(ua) || // Mobile IOS
/(android)(?:.*version)?[ \/]([\w.]+)/.exec(ua) || // Mobile Webkit
/(webkit|opera)(?:.*version)?[ \/]([\w.]+)/.exec(ua) || // Safari & Opera
/(msie) ([\w.]+)/.exec(ua) || [];


var browser = ua[1],
version = parseFloat(ua[2]),
start = 0,
stop = 0;

switch (browser) {
case 'msie':
browser = 'ie';
version = doc.documentMode || version;

start = 6;
stop = 10;
break;

// Add/remove extra tests here
case 'chrome':
start = 8;
stop = 22;
break;

case 'firefox':
browser = 'ff';

start = 3;
stop = 17;
break;

case 'ipod':
case 'ipad':
case 'iphone':
browser = 'ios';

start = 3;
stop = 6;
break;

case 'android':
start = 2;
stop = 4;
break;

case 'webkit':
browser = 'safari';

start = 9;
stop = 12;
break;

case 'opera':
start = 9;
stop = 12;
break;
}


// name can be used further on for various tasks, like font-face detection in css3.js
api.browser = {
name : browser,
version: version
};
api.browser[browser] = true;


// add supported, not supported classes
var supported = ['ie'];
//var supported = ['ie', 'chrome', 'ff', 'ios', 'android', 'safari', 'opera'];
each(supported, function (name) {
if (name === browser) {
pushClass(name);
}
else {
pushClass("no-" + name);
}
});


for (var v = start; v <= stop; v++) {
if (version < v) {
pushClass("lt-" + browser + v);
}
}


// IE lt9 specific
if (browser === "ie" && version < 9) {
// HTML5 support : you still need to add html5 css initialization styles to your site
// See: assets/html5.css
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);
});
}


// CSS "router"
each(loc.pathname.split("/"), function (el, i) {
if (this.length > 2 && this[i + 1] !== undefined) {
if (i) {
pushClass(this.slice(1, i + 1).join("-").toLowerCase() + conf.section);
}
} else {
// pageId
var id = el || "index", index = id.indexOf(".");
if (index > 0) {
id = id.substring(0, index);
}

html.id = id.toLowerCase() + conf.page;

// on root?
if (!i) {
pushClass("root" + conf.section);
}
}
});

// basic screen info
api.screen = {
height: win.screen.height,
width : win.screen.width
};

// screen resolution: w-100, lt-480, lt-1024 ...
function screenSize() {
// Viewport width
var iw = win.innerWidth || html.clientWidth,
ow = win.outerWidth || win.screen.width;

api.screen['innerWidth'] = iw;
api.screen['outerWidth'] = ow;


// START old code
var w = win.outerWidth || html.clientWidth;

// remove earlier widths
html.className = html.className.replace(/ (w|lt|portrait|no-portrait|landscape|no-landscape)-\d+/g, "");

// add new ones
pushClass("w-" + Math.round(w / 100) * 100);

each(conf.screens, function (width) {
if (w <= width) {
pushClass("lt-" + width);
}
});
// END old code

// Viewport height
var ih = win.innerHeight || html.clientHeight,
oh = win.outerHeight || win.screen.height;

api.screen['innerHeight'] = ih;
api.screen['outerHeight'] = oh;

// no need for onChange event to detect this
api.feature("portrait" , (ih > iw));
api.feature("landscape", (ih < iw));
}

screenSize();

// Throttle navigators from triggering too many resize events
var resizeId = 0;
function onResize() {
win.clearTimeout(resizeId);
resizeId = win.setTimeout(screenSize, 100);
}

// Manually attach, as to not overwrite existing handler
if (win.addEventListener) {
win.addEventListener("resize", onResize, false);

} else {
win.attachEvent("onresize", onResize);
}
})(window);

1 change: 1 addition & 0 deletions dist/head.core.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 48d4823

Please sign in to comment.