var _OHNCB = { config: { debug: false, dbg_url: 'http://ws-1.app.outdoorhub.com/ncb', //cdn_url: 'http://ws-1.app.outdoorhub.com/ncb', cdn_url: 'http://banners.outdoorhub.com', iframe_width: 0, iframe_height: 0, in_frame: (top != self), data_url: '', sponsor_url: 'http://www.outdoorhub.com', ref_domain: 'outdoorhub.com', first_module: '', url_params: { r: 'outdoorhub.com' }, solo_mode: false, auto_cycle_ms: 7000, anim_speed_ms: 'normal', module_timer: null, browser: { name: '', version: '', os: '', css_id: '' } }, modules: { news: { enabled: true, title: 'Outdoor News', loaded: false, rendered: false, num_items: 0, dividers: false }, videos: { enabled: true, title: 'Outdoor Videos', loaded: false, rendered: false, num_items: 0 }, articles: { enabled: true, title: 'Outdoor Articles', loaded: false, rendered: false, num_items: 0, dividers: false }, discuss: { enabled: true, title: 'Discuss', loaded: false, rendered: false, num_items: 0 }, jobs: { enabled: true, title: 'Outdoor Jobs', loaded: false, rendered: false, num_items: 0 }, weather: { enabled: false, title: 'Local Weather', loaded: false, rendered: false, data_url: '' } }, stats: { postal_code: geoip_postal_code(), tracker_url: 'http://st.ohub.us', click_url: 'http://ct.ohub.us', application_id: 17, publisher_id: 283, component_ids: { news: 55, videos: 28, articles: 17, weather: 59, jobs: 61, discuss: 63 }, action_ids: { impression: 9, click: 1, mouseover: 3, mouseout: 4 } }, data: { news: {}, videos: {}, articles: {}, weather: {}, jobs: {} }, flags: { auto_cycle_ok: true, loaded: false, dropped_cookie: false, loaded_module: false }, /** * Initialize the object * @return void */ init: function() { _OHNCB.debug('init()'); _OHNCB.introspect(); $('a').live('mousedown', function(e) { e.target.blur(); try { e.target.hideFocus = true; e.target.style.outline = 'none'; } catch(e) {} }).live('mouseout', function(e) { e.target.blur(); try { e.target.hideFocus = false; e.target.style.outline = null; } catch(e) {} }); _OHNCB.get_publisher_id(function() { _OHNCB.load_data(function() { _OHNCB.init_style(function() { _OHNCB.init_ui(function() { $('body').dequeue(); }); }); }); }); }, /** * Imports the URL parameters to config variables * @return void */ import_url_parameters: function() { _OHNCB.debug('import_url_parameters()'); if (document.location.search !== '') { _OHNCB.config.url_params = _OHNCB.parse_querystring(document.location.search); } var import_params = ['solo_mode', 'first_module']; for (var param in _OHNCB.config.url_params) { var valid = import_params.join(',') + ','; if (valid.indexOf(param + ',') !== -1) { if (isNaN(_OHNCB.config.url_params[param])) { //import as string _OHNCB.config[param] = _OHNCB.config.url_params[param]; } else { if (parseInt(_OHNCB.config.url_params[param], 10) === 0 || parseInt(_OHNCB.config.url_params[param], 10) === 1) { //import as bool _OHNCB.config[param] = (parseInt(_OHNCB.config.url_params[param], 10) > 0); } else { //import as int _OHNCB.config[param] = parseInt(_OHNCB.config.url_params[param], 10); } } } } }, /** * Introspect on the environment * @return void */ introspect: function() { _OHNCB.debug('introspect()'); _OHNCB.import_url_parameters(); if (typeof(_OHNCB.config.url_params.first_module) == 'undefined') { _OHNCB.config.first_module = _OHNCB.get_first_module(); } else { _OHNCB.config.first_module = _OHNCB.config.url_params.first_module; _OHNCB.modules[_OHNCB.config.first_module].enabled = true; } _OHNCB.config.ref_domain = _OHNCB.config.url_params.r; _OHNCB.config.data_url = _OHNCB.base_url() + '/data/' + _OHNCB.config.ref_domain; _OHNCB.config.browser.name = $.browser.name; _OHNCB.config.browser.version = $.browser.versionX; _OHNCB.config.browser.os = $.os.name; _OHNCB.config.browser.className = $.browser.className; if (_OHNCB.modules.weather.enabled) { if (_OHNCB.stats.postal_code !== '') { _OHNCB.modules.weather.data_url = 'http://query.yahooapis.com/v1/public/yql?q=' + encodeURIComponent('select * from weather.forecast where location=' + _OHNCB.stats.postal_code) + '&format=json&callback=?'; } else { _OHNCB.modules.weather.enabled = false; } } /* if (_OHNCB.config.in_frame) { _OHNCB.config.iframe_width = $(window).width(); _OHNCB.config.iframe_height = $(window).height(); } else { */ var dimensions = _OHNCB.topmost_current_directory().split('x'); _OHNCB.config.iframe_width = parseInt(dimensions[0], 10); _OHNCB.config.iframe_height = parseInt(dimensions[1], 10); //} switch(_OHNCB.config.iframe_width) { case 160: _OHNCB.modules.news.num_items = 3; _OHNCB.modules.videos.num_items = 4; _OHNCB.modules.articles.num_items = 3; _OHNCB.modules.jobs.num_items = 4; _OHNCB.modules.discuss.num_items = 3; _OHNCB.stats.application_id = 17; break; case 300: _OHNCB.modules.news.num_items = 2; _OHNCB.modules.videos.num_items = 2; _OHNCB.modules.videos.view_all = true; _OHNCB.modules.articles.num_items = 2; _OHNCB.modules.jobs.num_items = 2; _OHNCB.modules.discuss.num_items = 1; _OHNCB.modules.jobs.view_all = true; _OHNCB.modules.news.remove_brs = true; _OHNCB.modules.articles.remove_brs = true; _OHNCB.modules.jobs.remove_brs = true; _OHNCB.stats.application_id = 19; _OHNCB.modules.weather.dividers = true; break; case 728: _OHNCB.modules.news.num_items = 2; _OHNCB.modules.videos.num_items = 4; _OHNCB.modules.articles.num_items = 2; _OHNCB.modules.jobs.num_items = 3; _OHNCB.modules.discuss.num_items = 2; _OHNCB.modules.news.dividers = true; _OHNCB.modules.articles.dividers = true; _OHNCB.modules.jobs.dividers = true; _OHNCB.modules.weather.dividers = true; _OHNCB.modules.discuss.dividers = true; _OHNCB.modules.news.remove_brs = true; _OHNCB.modules.articles.remove_brs = true; //_OHNCB.modules.jobs.remove_brs = true; _OHNCB.modules.discuss.remove_brs = true; _OHNCB.stats.application_id = 18; $('#all').prepend('
'); break; } switch (_OHNCB.config.browser.os) { case 'win': _OHNCB.config.browser.os = 'win'; break; case 'mac': _OHNCB.config.browser.os = 'mac'; break; case 'iphone': case 'unknown': _OHNCB.config.browser.os = 'ios'; break; } switch (_OHNCB.config.browser.name) { case 'firefox': _OHNCB.config.browser.css_id = 'firefox'; break; case 'msie': _OHNCB.config.browser.css_id = 'ie' + _OHNCB.config.browser.version; break; case 'opera': _OHNCB.config.browser.css_id = 'opera'; break; case 'safari': switch(_OHNCB.config.browser.os) { case 'mac': case 'win': _OHNCB.config.browser.css_id = 'safari-' + _OHNCB.config.browser.os; break; case 'ios': _OHNCB.config.browser.css_id = _OHNCB.config.browser.os; break; } break; case 'chrome': _OHNCB.config.browser.css_id = 'chrome'; break; } }, /** * Initializes the UI * @return void * @param function cb callback */ init_ui: function(cb) { _OHNCB.debug('init_ui(cb=' + cb + ')'); $('#modules > div').hide(); $('#all').bind('click', function() { $('#all').data('clicked', true); }); $('#sponsor').bind('click', function() { _OHNCB.open_url(_OHNCB.config.sponsor_url); }); if (_OHNCB.config.solo_mode && !_OHNCB.modules[_OHNCB.config.first_module].rendered) { $('body').queue(function() { _OHNCB.render_module(_OHNCB.config.first_module, function() { $('body').dequeue(); }); }); } else { $.each(_OHNCB.modules, function(module_name, module_config) { if (_OHNCB.modules[module_name].enabled) { $('body').queue(function() { _OHNCB.render_module(module_name, function() { $('body').dequeue(); }); }); } }); $('body').queue(function() { _OHNCB.render_pager(function() { $('body').dequeue(); }); }); } $('body').queue(function() { if ((_OHNCB.config.solo_mode && _OHNCB.flags.loaded_module) || !_OHNCB.flags.loaded) { _OHNCB.goto_module(_OHNCB.config.first_module, false, function() { _OHNCB.flags.loaded = true; if (typeof(cb) == 'function') { cb(); } }); } else { _OHNCB.goto_module(_OHNCB.config.first_module, true, function() { _OHNCB.flags.loaded = true; if (typeof(cb) == 'function') { cb(); } }); } $('body').dequeue(); }); }, /** * Auto-cycles the modules on a timer * @return void */ module_auto_cycle: function() { _OHNCB.debug('module_auto_cycle()'); if (_OHNCB.config.solo_mode) { return; } if (_OHNCB.config.module_timer != null) { clearInterval(_OHNCB.config.module_timer); _OHNCB.config.module_timer = null; } _OHNCB.config.module_timer = setInterval(function() { if (_OHNCB.flags.auto_cycle_ok && !$('#all').data('clicked')) { _OHNCB.goto_next_page(); } }, _OHNCB.config.auto_cycle_ms); $('#all').hover( function() { _OHNCB.flags.auto_cycle_ok = false; }, function() { _OHNCB.flags.auto_cycle_ok = true; } ); }, /** * Renders the pager * @return void * @param function cb callback */ render_pager: function(cb) { _OHNCB.debug('render_pager(cb=' + cb + ')'); var html = ''; $('#sponsor').after(html); $('#page_buttons a').bind('click', function() { if (!$('#modules:animated').length) { _OHNCB.goto_module($(this).attr('module')); } }); $('#back').bind('click', function() { if (!$('#modules:animated').length) { _OHNCB.goto_previous_page(); } }); $('#next').bind('click', function() { if (!$('#modules:animated').length) { _OHNCB.goto_next_page(); } }); if (typeof(cb) == 'function') { cb(); } }, /** * Selects a page in the pager * @return void */ select_page: function(module, cb) { _OHNCB.debug('select_page(module=' + module + ', cb=' + cb + ')'); if (!_OHNCB.module_exists(module)) { return; } $('#page_buttons a').removeClass('current'); $('#page_buttons a[module="' + module + '"]').addClass('current'); }, /** * Returns the selected page * @return string */ get_selected_page: function() { _OHNCB.debug('get_selected_page()'); return $('#page_buttons a.current').attr('module'); }, /** * Goes to the next page * @return void */ goto_next_page: function() { _OHNCB.debug('goto_next_page()'); var next_available = $('#page_buttons a.current').next(); if (next_available.length) { var next_module = $(next_available).attr('module'); } else { var next_module = $('#page_buttons a:eq(0)').attr('module'); } _OHNCB.goto_module(next_module); }, /** * Goes to the previous page * @return void */ goto_previous_page: function() { _OHNCB.debug('goto_previous_page()'); var prev_available = $('#page_buttons a.current').prev(); if (prev_available.length) { var prev_module = $(prev_available).attr('module'); } else { var prev_module = $('#page_buttons a:last-child').attr('module'); } _OHNCB.goto_module(prev_module); }, /** * Go to a module (animate as needed) * @param string module to go to * @param boolean anim animate the transition? (for load) * @param function cb callback when finished going to */ goto_module: function(module, anim, cb) { _OHNCB.debug('goto_module(module=' + module + ', anim=' + anim + ', cb=' + cb + ')'); anim = (typeof(anim) == 'undefined') ? true : anim; if (!_OHNCB.module_exists(module)) { return; } if (!_OHNCB.config.solo_mode) { var old_selected_page = _OHNCB.get_selected_page(); _OHNCB.select_page(module); var new_selected_page = _OHNCB.get_selected_page(); var new_index = $('#page_buttons a.current').index(); if (old_selected_page == new_selected_page) { return; } switch(_OHNCB.config.iframe_width) { case 160: case 300: var left = new_index * _OHNCB.config.iframe_width - new_index; var new_left = ((String(left).substr(0, 1) == '-') ? '' : '-') + left + 'px'; var new_top = 0; var fade_caption = false; _OHNCB.module_auto_cycle(); break; case 728: var top = new_index * _OHNCB.config.iframe_height - new_index; var new_top = ((String(top).substr(0, 1) == '-') ? '' : '-') + top + 'px'; var new_left = 180; var fade_caption = true; _OHNCB.module_auto_cycle(); break; } } else { switch(_OHNCB.config.iframe_width) { case 160: case 300: var new_left = '0px'; var new_top = '0px'; break; case 728: var new_left = '180px'; var new_top = '0px'; break; } } if (anim) { if (fade_caption && old_selected_page != new_selected_page) { $('body').queue(function() { $('#modules h1').fadeOut(_OHNCB.config.anim_speed_ms, function() { $('body').dequeue(); }); }); } $('body').queue(function() { $('#modules').animate( { left: new_left, top: new_top }, _OHNCB.config.anim_speed_ms, 'swing', function() { if ($('#modules #' + module + ':visible').length === 0) { $('#modules #' + module).fadeIn(_OHNCB.config.anim_speed_ms, function() { if (typeof(cb) == 'function') { _OHNCB.send_module_impressions(module, cb); } else { _OHNCB.send_module_impressions(module); } $('body').dequeue(); }); } else { $('body').queue(function() { if (fade_caption && old_selected_page != new_selected_page) { $('#modules h1').fadeIn(_OHNCB.config.anim_speed_ms, function() { $('body').dequeue(); }); } else { $('body').dequeue(); } }); if (typeof(cb) == 'function') { _OHNCB.send_module_impressions(module, cb); } else { _OHNCB.send_module_impressions(module); } $('body').dequeue(); } } ); }); } else { $('#modules').css({ left: new_left, top: new_top }); if (typeof(cb) == 'function') { _OHNCB.send_module_impressions(module, cb); } else { _OHNCB.send_module_impressions(module); } } }, /** * Sends statistics for a module * @param string module to send stats for * @param function cb callback */ send_module_impressions: function(module, cb) { _OHNCB.debug('send_module_impressions(module=' + module + ', cb=' + cb + ')'); var batch = []; switch (module) { case 'news': case 'articles': case 'jobs': $('#modules #' + module + ' .item').each(function(i, el) { batch.push({ t: 'article', r: $(this).attr('feed_item_id'), f: $(this).attr('feed_id'), a: _OHNCB.stats.application_id, x: _OHNCB.stats.action_ids.impression, p: _OHNCB.stats.publisher_id, c: _OHNCB.stats.component_ids[module] }); }); break; case 'videos': $('#modules #' + module + ' .item').each(function(i, el) { batch.push({ t: 'video', v: $(this).attr('video_id'), a: _OHNCB.stats.application_id, x: _OHNCB.stats.action_ids.impression, p: _OHNCB.stats.publisher_id, c: _OHNCB.stats.component_ids[module] }); }); break; } batch.push({ t: 'app', a: _OHNCB.stats.application_id, x: _OHNCB.stats.action_ids.impression, p: _OHNCB.stats.publisher_id, c: _OHNCB.stats.component_ids[module] }); _OHNCB.stat(batch); }, /** * Render a module * @param string module to render * @param function cb callback */ render_module: function(module, cb) { _OHNCB.debug('render_module(module=' + module + ', cb=' + cb + ')'); var html = ''; var html = 'We are unable to determine your zip code using geoIP
' + 'Local weather is disabled
'; } } catch(e) { html += 'We are unable to determine your zip code using geoIP
' + 'Local weather is disabled
'; } $(html).prependTo('#modules #weather > div'); if (_OHNCB.modules[module].dividers) { switch(_OHNCB.config.iframe_width) { case 728: $('#modules #weather > div .divider').eq(0).css({ position: 'absolute', left: '165px' }); $('#modules #weather > div .divider').eq(1).css({ position: 'absolute', left: '305px' }); break; case 300: $('#modules #weather > div .divider').eq(0).hide(); $('#modules #weather > div .divider').eq(1).css({ position: 'absolute', left: '124px', top: '46px' }); break; } } } break; case 'jobs': if (_OHNCB.modules.jobs.enabled || _OHNCB.config.first_module == module) { var item_template = ''; $.each(_OHNCB.data.jobs, function(i, data) { url = _OHNCB.stats.click_url + '?u=' + encodeURIComponent(data.link) + ';'; url += '&t=article'; url += '&r=' + data.feed_item_id; url += '&f=' + data.feed_id; url += '&a=' + _OHNCB.stats.application_id; url += '&x=' + _OHNCB.stats.action_ids.click; url += '&p=' + _OHNCB.stats.publisher_id; url += '&c=' + _OHNCB.stats.component_ids.jobs; html += $.simple_template( item_template, { feed_item_id: data.feed_item_id, feed_id: data.feed_id, title: data.title, description: data.description, link: url, url: url } ); }); $(html).prependTo('#modules #jobs > div'); if (_OHNCB.modules[module].dividers) { $('#modules #jobs > div .item').not(':last-child').after(''); } if (_OHNCB.modules[module].remove_brs) { $('#modules #jobs br').remove(); } if (_OHNCB.modules.jobs.view_all) { $('View all').prependTo('#modules #jobs > div'); } } break; case 'discuss': if (_OHNCB.modules.discuss.enabled) { var item_template = ''; $.each(_OHNCB.data.discuss, function(i, data) { url = _OHNCB.stats.click_url + '?u=' + encodeURIComponent(data.link) + ';'; url += '&t=article'; url += '&r=' + data.feed_item_id; url += '&f=' + data.feed_id; url += '&a=' + _OHNCB.stats.application_id; url += '&x=' + _OHNCB.stats.action_ids.click; url += '&p=' + _OHNCB.stats.publisher_id; url += '&c=' + _OHNCB.stats.component_ids.discuss; html += $.simple_template( item_template, { feed_item_id: data.feed_item_id, feed_id: data.feed_id, title: data.title, description: data.description, link: url, url: url } ); }); $(html).prependTo('#modules #discuss > div'); if (_OHNCB.modules[module].dividers) { $('#modules #discuss > div .item').not(':last-child').after(''); } if (_OHNCB.modules[module].remove_brs) { $('#modules #discuss br').remove(); } } break; } _OHNCB.modules[module].rendered = true; if (typeof(cb) == 'function') { cb(); } }, /** * Initializes the CSS style * @param function cb callback * @return void */ init_style: function(cb) { _OHNCB.debug('init_style(cb=' + cb +')'); var css_url = _OHNCB.asset_url() + '/css/style-' + _OHNCB.config.browser.css_id + '.css'; $.getCSS(css_url, function() { $('#all').fadeIn('normal', function() { if (typeof(cb) == 'function') { cb(); } }); }); }, /** * Return which direction to animate based on user input * @param string new_module module animating to * @return string 'left'|'right' */ get_animation_direction: function(new_module) { _OHNCB.debug('get_animation_direction(module=' + new_module + ')'); var current_index = $('#page_buttons a.current').index(); var new_index = $('#page_buttons a[module="' + new_module + '"]').index(); return (current_index > new_index) ? 'left' : 'right'; }, /** * Opens a new window with a URL * @param string url to open * @return window handle of window opened */ open_url: function(url) { _OHNCB.debug('open_url(url=' + url + ')'); if (url != 'undefined') { return setTimeout(function() { return window.open(url, '_top'); }, 1000); } }, /** * Returns the name of the first module. * * If cookie OHNCB_LAST_MODULE exists, and first_module is not passed in * via URL parameter and thus overridden, first_module is the next available * module AFTER the module stored in OHNCB_LAST_MODULE cookie. * * If a cookie is not set, and first_module is not passed in via URL param, * first_module is the first_module in the _OHNCB.modules object. * * If the first_module URL parameter is passed, it overrides the cookie. * * @return string first module */ get_first_module: function() { _OHNCB.debug('get_first_module()'); if (_OHNCB.config.solo_mode) { $.cookie('OHNCB_LAST_MODULE', null); } var cookie_module = $.cookie('OHNCB_LAST_MODULE'); try { if (!_OHNCB.modules[cookie_module].enabled) { cookie_module = 'news'; } } catch(e) { cookie_module = 'news'; } var default_module = ''; var first_module = ''; var next_module = ''; var found = false; for (var module in _OHNCB.modules) { if (default_module === '') { default_module = module; } if (cookie_module == module) { found = true; } else if (found && next_module === '') { next_module = module; } } if (found && next_module === '') { next_module = default_module; } if (cookie_module != null && _OHNCB.config.first_module === '') { first_module = next_module; } else if (_OHNCB.config.first_module !== '') { if (_OHNCB.module_exists(_OHNCB.config.first_module)) { first_module = _OHNCB.config.first_module; } else { first_module = default_module; } } else { first_module = default_module; } if (!_OHNCB.config.solo_mode) { $.cookie('OHNCB_LAST_MODULE', first_module); } try { if (!_OHNCB.modules[first_module].enabled) { first_module = 'news'; } } catch(e) { first_module = 'news'; } return first_module; }, /** * Determines if a module exists * @param string module to check * @return boolean TRUE if module exists | FALSE otherwise */ module_exists: function(module) { _OHNCB.debug('module_exists(module=' + module + ') = ' + (typeof(_OHNCB.modules[module]) == 'object')); return typeof(_OHNCB.modules[module]) == 'object'; }, /** * Returns the base URL (which is different depending on debug mode) * @return string URL for base URL */ base_url: function() { _OHNCB.debug('base_url()'); return (_OHNCB.config.debug) ? _OHNCB.config.dbg_url : _OHNCB.config.cdn_url; }, /** * Returns the topmost current directory in a URL path * @return string */ topmost_current_directory: function() { return document.location.href.split('/')[document.location.href.split('/').length-2]; }, /** * Returns the asset URL (which is where the index.html, css, and css/images dirs are) * @return string URL for assets */ asset_url: function() { _OHNCB.debug('asset_url()'); return _OHNCB.base_url() + '/' + _OHNCB.config.iframe_width + 'x' + _OHNCB.config.iframe_height; }, /** * Gets the publisher ID * @param function callback * @return int publisher_id of the publisher */ get_publisher_id: function(callback) { _OHNCB.debug('get_publisher_id()'); $.jsonp({ url: _OHNCB.config.data_url + '/publisher.json', cache: false, callback: 'cb', callbackParameter: 'cb', success: function(json, textStatus) { if (json.publisher_id) { _OHNCB.stats.publisher_id = parseInt(json.publisher_id, 10); if (typeof(callback) == 'function') { callback(); } } }, error: function(xOptions, textStatus) { _OHNCB.stats.publisher_id = -1; _OHNCB.config.ref_domain = 'outdoorhub.com'; if (typeof(callback) == 'function') { callback(); } } }); }, /** * Load all data into each of the modules * @param function cb callback */ load_data: function(cb) { _OHNCB.debug('load_data(cb=' + cb + ')'); if (_OHNCB.config.solo_mode && _OHNCB.config.first_module !== '' && !_OHNCB.modules[_OHNCB.config.first_module].loaded) { $('body').queue(function() { _OHNCB.load_module_data(_OHNCB.config.first_module, function() { $('body').dequeue(); }); }); $('body').queue(function() { _OHNCB.flags.loaded_module = true; $('body').dequeue(); }); } else { $.each(_OHNCB.modules, function(module_name, module_config) { $('body').queue(function() { _OHNCB.load_module_data(module_name, function() { $('body').dequeue(); }); }); }); } if (typeof(cb) == 'function') { $('body').queue(function() { cb(); $('body').dequeue(); }); } }, /** * Load data for a given module * @param string module to load * @param function cb callback */ load_module_data: function(module, cb) { _OHNCB.debug('load_module_data(module=' + module + ', cb=' + cb + ')'); if (!_OHNCB.modules[module].enabled) { if (typeof(cb) == 'function') { _OHNCB.modules[module].loaded = true; cb(); } return; } if (module == 'weather') { var url = _OHNCB.modules[module].data_url; } else if (module == 'jobs' || module == 'discuss') { var url = _OHNCB.config.cdn_url + '/data/' + module + '.json'; } else { var url = _OHNCB.config.cdn_url + '/data/' + _OHNCB.config.ref_domain + '/' + module + '.json'; } $.jsonp({ url: url, cache: false, callback: 'cb', callbackParameter: 'cb', success: function(json, textStatus) { if (module == 'weather') { _OHNCB.data[module] = json.query.results.channel; } else { _OHNCB.data[module] = json.items.slice(0, _OHNCB.modules[module].num_items); } if (typeof(cb) == 'function') { _OHNCB.modules[module].loaded = true; cb(); } } }); }, /** * Stat tracker * @param object data * @param function cb callback * @return void */ stat: function(data, cb) { //_OHNCB.debug('stat: ' + typeof(data)); if (typeof(data) != 'object') { return; } else { //array (batch mode) if (data.length != 'undefined') { var batch = []; for (var i=0; i < data.length; i++) { batch.push(prepare(data[i])); } $.getJSON(_OHNCB.stats.tracker_url + '?cb=?', { sb: batch }, function() { if (typeof(cb) == 'function') { cb(); } }); } else { //single object mode args = prepare(data); $.getJSON(_OHNCB.stats.tracker_url + '?cb=?', args, function() { if (typeof(cb) == 'function') { cb(); } }); } } function prepare(data) { var args = {}; args.a = _OHNCB.stats.application_id; args.o = 'json'; for (var prop in data) { args[prop] = data[prop]; } return args; } }, /** * Parses the query string and returns object of key=value pairs * @param string url to parse * @returns object of parsed key=value pairs */ parse_querystring: function(url) { var parsed = {}; var e, a = /\+/g; var r = /([^&=]+)=?([^&]*)/g; var d = function (s) { return decodeURIComponent(s.replace(a, ' ')); }; if (url.indexOf('?') == -1) { return; } var q = url.substr(url.indexOf('?')+1); while (e = r.exec(q)) { parsed[d(e[1])] = d(e[2]); } return parsed; }, /** * Debug message handler * @param mixed out string, func, or object * @return void */ debug: function(out) { if (!_OHNCB.config.debug) { return; } try { if (typeof(console) == 'object') { switch(typeof(out)) { case 'string': case 'function': console.log('_OHNCB.' + out); break; case 'object': console.dir(out); break; } } } catch(e) { } } }; $(document).ready(function() { _OHNCB.init(); $.ajaxSetup({ cache: false }); });