/*****************************************************************/ /* 5grid 0.4 by n33.co | MIT+GPLv2 license licensed */ /* init.js: Init script */ /*****************************************************************/ /*********************/ /* Settings */ /*********************/ var _5grid_settings = { breakpoint_1000px: 1200, breakpoint_mobile: 480, prefix: 'style', use: 'mobile,desktop', viewport_is1000px: 1040, viewport_is1200px: 1280, //////////////////////////////////////////////////////// mobileUI: 0, mobileUI_hideAddressBar: 0, mobileUI_openerText: '=', mobileUI_openerWidth: 60, mobileUI_slideSpeed: 200, mobileUI_theme: 'modern', mobileUI_themeNavColor: '#1f1f1f', mobileUI_themeTitleBarColor: '#444444', mobileUI_titleBarFixed: 1, mobileUI_titleBarHeight: 44, mobileUI_titleBarOverlaid: 0, //////////////////////////////////////////////////////// mobileUI_navInnerPad: 0, mobileUI_force: 0, mobileUI_tapDelay: 200, debug_noExtLoad: 0 }; /*********************/ /* Helper plugins */ /*********************/ /* jQuery resize event - v1.1 - 3/14/2010 http://benalman.com/projects/jquery-resize-plugin/ | Copyright (c) 2010 "Cowboy" Ben Alman | Dual licensed under the MIT and GPL licenses. | http://benalman.com/about/license/ */ (function(jQuery,h,c){var a=jQuery([]),e=jQuery.resize=jQuery.extend(jQuery.resize,{}),i,k="setTimeout",j="resize",d=j+"-special-event",b="delay",f="throttleWindow";e[b]=250;e[f]=true;jQuery.event.special[j]={setup:function(){if(!e[f]&&this[k]){return false}var l=jQuery(this);a=a.add(l);jQuery.data(this,d,{w:l.width(),h:l.height()});if(a.length===1){g()}},teardown:function(){if(!e[f]&&this[k]){return false}var l=jQuery(this);a=a.not(l);l.removeData(d);if(!a.length){clearTimeout(i)}},add:function(l){if(!e[f]&&this[k]){return false}var n;function m(s,o,p){var q=jQuery(this),r=jQuery.data(this,d);r.w=o!==c?o:q.width();r.h=p!==c?p:q.height();n.apply(this,arguments)}if(jQuery.isFunction(l)){n=l;return m}else{n=l.handler;l.handler=m}}};function g(){i=h[k](function(){a.each(function(){var n=jQuery(this),m=n.width(),l=n.height(),o=jQuery.data(this,d);if(m!==o.w||l!==o.h){n.trigger(j,[o.w=m,o.h=l])}});g()},e[b])}})(jQuery,this); /*********************/ /* Object Setup */ /*********************/ var _5gridC = function() { this.events = new Array(); this.readyWait = false; this.isReady = false; this.isMobile = false; this.isDesktop = false; this.isFluid = false; this.is1000px = false; this.is1200px = false; } _5gridC.prototype.bind = function(name, f) { if (!this.events[name]) this.events[name] = new Array(); this.events[name].push(f); } _5gridC.prototype.trigger = function(name) { if (!this.isReady || !this.events[name] || this.events[name].length < 1) return; for (i in this.events[name]) (this.events[name][i])(); } _5gridC.prototype.ready = function(f, wait) { if (wait) this.readyWait = true; this.bind('ready', f); } // Custom events _5gridC.prototype.orientationChange = function(f) { this.bind('orientationChange', f); } _5gridC.prototype.mobileUINavOpen = function(f) { this.bind('mobileUINavOpen', f); } _5gridC.prototype.mobileUINavClose = function(f) { this.bind('mobileUINavClose', f); } _5gridC.prototype.readyCheck = function() { var x = this; window.setTimeout(function() { if (x.isReady) x.trigger('ready'); else x.readyCheck(); }, 50); } var _5grid = new _5gridC; (function() { /*********************/ /* Initialize */ /*********************/ // Vars var _settings = _5grid_settings, _window = jQuery(window), _head = jQuery('head'), _document = jQuery(document); var baseURL, doFluid, do1000px, do1200px, doMobile, doDesktop, doMobileOnly, isLocked = false, isTapLocked = false, tapId, isTouch = !!('ontouchstart' in window), headQueue = new Array(); var v, w, wk, wv, x, y; // Tap handling jQuery.fn.tap_5grid = function(f, suffix, noMove) { var target = jQuery(this); if (isTouch) { target .bind('touchstart' + (suffix ? '.' + suffix : ''), function() { if (!isTapLocked) { isTapLocked = true; if (_settings.mobileUI_tapDelay > -1) tapId = window.setTimeout(function() { window.clearTimeout(tapId); isTapLocked = false; }, _settings.mobileUI_tapDelay); } }) .bind('touchend' + (suffix ? '.' + suffix : ''), function(e) { if (isTapLocked) { isTapLocked = false; window.clearTimeout(tapId); (f)(e); } }); if (noMove) target .bind('touchmove' + (suffix ? '.' + suffix : ''), function(e) { isTapLocked = false; window.clearTimeout(tapId); }); } else target.bind('click' + (suffix ? '.' + suffix : ''), f); return target; }; jQuery.fn.untap_5grid = function(suffix) { var target = jQuery(this); if (isTouch) { target .unbind('touchstart' + (suffix ? '.' + suffix : '')) .unbind('touchend' + (suffix ? '.' + suffix : '')) .unbind('touchmove' + (suffix ? '.' + suffix : '')); } else target.unbind('click' + (suffix ? '.' + suffix : '')); return target; }; // Shortcut methods headQueue.pushI_5grid = function(s) { headQueue.push({ type: 'i', value: s }); }; headQueue.pushE_5grid = function(s) { headQueue.push({ type: 'e', value: s }); }; headQueue.process_5grid = function() { var doE; if (document.createStyleSheet) doE = function(s) { document.createStyleSheet(s); }; else doE = function(s) { _head.append(''); }; for (x in headQueue) { if (headQueue[x].type == 'i') _head.append(''); else if (headQueue[x].type == 'e') (doE)(headQueue[x].value); } }; jQuery.fn.disableSelection_5grid = function() { return jQuery(this).css('user-select', 'none').css('-khtml-user-select', 'none').css('-moz-user-select', 'none').css('-o-user-select', 'none').css('-webkit-user-select', 'none'); } jQuery.fn.enableSelection_5grid = function() { return jQuery(this).css('user-select', 'auto').css('-khtml-user-select', 'auto').css('-moz-user-select', 'auto').css('-o-user-select', 'auto').css('-webkit-user-select', 'auto'); } jQuery.fn.accelerate_5grid = function() { return jQuery(this).css('-webkit-transform', 'translateZ(0)').css('-webkit-backface-visibility', 'hidden').css('-webkit-perspective', '500'); } // Determine base URL, settings x = jQuery('script').filter(function() { return this.src.match(/5grid\/init\.js/); }).first(); y = x.attr('src').split('?'); baseURL = y[0].replace(/5grid\/init\.js/, ''); // Override settings if (y.length > 1) { x = y[1].split('&'); for (v in x) { w = x[v].split('='); wk = w[0].replace(/\./, '_'); wv = w[1]; // Thanks, @cmsalvado! :) if (!isNaN(parseFloat(wv)) && isFinite(wv)) wv = parseInt(wv); _settings[wk] = wv; } } // Debug settings if (_settings.debug_noExtLoad == 1) headQueue.pushE_5grid = function(s) { }; // Determine viewing modes doDesktop = doMobile = doFluid = do1000px = do1200px = doMobileOnly = false; v = _settings.use.split(','); if (jQuery.inArray('fluid', v) > -1) doFluid = true; if (jQuery.inArray('desktop', v) > -1) doDesktop = true; if (jQuery.inArray('1000px', v) > -1) do1000px = true; if (jQuery.inArray('1200px', v) > -1) do1200px = true; if (jQuery.inArray('mobile', v) > -1) doMobile = true; if (doMobile && !doFluid && !do1000px && !do1200px && !doDesktop) doMobileOnly = true; // Apply workarounds for broken/old browsers // Android, Webkit <= 534 if (navigator.userAgent.match(/Android.+AppleWebKit\/534/)) _settings.mobileUI_titleBarFixed = 0; // IE <= 8 if (jQuery.browser.msie) { // HTML5 Shiv if (jQuery.browser.version < 9) _head.append('