Skip to content

Instantly share code, notes, and snippets.

@HichemBenChaaben
Created September 17, 2013 19:10
Show Gist options
  • Save HichemBenChaaben/6599222 to your computer and use it in GitHub Desktop.
Save HichemBenChaaben/6599222 to your computer and use it in GitHub Desktop.
Init file
(function (window, document, $, undefined) {
"use strict";
/*
Strict mode helps in a couple ways:
- It catches some common coding bloopers by throwing exceptions.
- It prevents or throws errors when relatively "unsafe" actions are taken
(such as gaining access to the global object).
- It disables features that are confusing or poorly thought out.
Further reading: http://ejohn.org/blog/ecmascript-5-strict-mode-json-and-more/
*/
var Init = {
whatViewPort: function () {
if (Modernizr.mq("only all and (min-width: 200px) and (max-width: 759px)")) {
return "mobile";
}
if (Modernizr.mq("only all and (min-width: 760px) and (max-width: 1019px)")) {
return "tablet";
}
if (Modernizr.mq("only all and (min-width: 1020px)")) {
return "desktop";
}
},
checkWindowSize: function () {
if (Modernizr.mq("only all and (min-width: 200px) and (max-width: 759px)")) {
$("html").addClass("wmobile");
} else {
$("html").removeClass("wmobile");
}
if (Modernizr.mq("only all and (min-width: 760px) and (max-width: 1019px)")) {
$("html").addClass("w780");
} else {
$("html").removeClass("w780");
}
if (Modernizr.mq("only all and (min-width: 1020px)")) {
$("html").addClass("w1020");
} else {
$("html").removeClass("w1020");
}
},
// toggle grid should not be shipped to production,
// we should create a file for that
toggleGrid: function () {
$(document.documentElement).keyup(function (event) {
if ($(event.target).is(":not(input, textarea)")) {
if (event.keyCode === 71) {
$(".container").addClass("add-grid");
}
if (event.keyCode === 72) {
$(".container").removeClass("add-grid");
}
}
});
},
init: function () {
var self = this;
// init site here
// modernizer checks
// conditional lib loading
// etc
self.checkWindowSize();
if (DEBUG_STATUS === "True") {
self.toggleGrid();
}
if ($("html").hasClass("lt-ie9") === false) {
$(window).resize(function () {
self.checkWindowSize();
});
}
}
};
$(function () {
// document ready
Init.init();
window.Init = Init;
});
})(window, document, jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment