';return html;}function story_to_thumbnail_item(story, options){var html = '';var photo_url = '';if(story.photo_cdn > ''){photo_url = story.photo_cdn + '/width=850,height=400,fit=cover';}else {photo_url = '/image/w850-h400-c850:400-p1/files/' + story.photo;}html += '
';html += '
';html += '';html += '';html += '';if(typeof story.read_time != 'undefined' && story.read_time > 0){html += '';html += '' + story.read_time + '';html += '';html += 'minute';if(story.read_time > 1){html += 's';}html += '';html += '';}html += '
';if(window.innerWidth > 500){html += '
';}else {html += '
';}if(window.innerWidth > 500){html += '
';if(story.author > ''){html += '';html += story.author;html += ' • ';html += ' ';}html += '';html += story.publish_friendly;html += '';html += '
';}html += '
';if(story.categories.length){html += '
';for (var category in story.categories) {html += '';html += story.categories[category].name;html += ' ';}html += '
';}html += '
';html += '';html += story.title;html += '';if(window.innerWidth <= 500){if(story.author > ''){html += '';html += story.author;html += ' • ';html += ' ';}html += '';html += story.publish_friendly;html += '';}html += '';html += story.subtitle;html += '';html += '
';html += '
';return html;}function show_list(news_feed, data){if(news_feed.length){var html = '';var options = {};var ad_class = '';var max_width = 728;if(window.innerWidth<=500){ad_class = 'dfp-square';max_width = 300;}else {//var random = Math.floor(Math.random() * 3);//if(random == 1){//ad_class = 'dfp-square';//max_width = 300;//}//else {ad_class = 'dfp-leaderboard';max_width = 728;//}}if(data.options.show_ads == 'before'){html += '
';html += '
';html += '
';data.ad_counter++;}for (var i = 0; i < news_feed.length; i++) {if(window.innerWidth > 500){html += '
';}else {html += '
';}if(i == 0){html += story_to_thumbnail_item(news_feed[i], options);}else {html += story_to_list_item(news_feed[i], options);}html += '
';if(window.innerWidth > 500){html += '
';}}if(data.options.show_ads == 'after'){//leaderboardif(ad_class == 'dfp-leaderboard'){html += '
';}else {html += '
';}html += '
';html += '
';data.ad_counter++;}if(data.should_append_feed){document.getElementById("news_feed").insertAdjacentHTML('beforeend',html);//show_ad(data);}else {document.getElementById("news_feed").innerHTML = html;data.should_append_feed = true;}data.story_positions = calculate_story_positions();data.ad_positions = calculate_ad_positions();}}function feed_request_callback(xhr, data) {return function() { if(this.readyState == 4 && this.status == 200) { var now = Math.floor(Date.now() / 1000); var json = JSON.parse(this.responseText);data.saved_list.push(json.news_feed);//console.log(data.saved_list);//console.log('show feed');show_list(json.news_feed, data);try {sessionStorage.setItem('feed_' + data.options_string, JSON.stringify(data.saved_list));sessionStorage.setItem('feed_date_' + data.options_string, now);;}catch (e) {if (e == QUOTA_EXCEEDED_ERR) {sessionStorage.clear();sessionStorage.setItem('feed_' + data.options_string, JSON.stringify(data.saved_list));sessionStorage.setItem('feed_saved_' + data.options_string, now);;}}data.loading.style.display = 'none';data.loading_stories = false;}};}function calculate_story_positions(){var stories = document.querySelectorAll(".feed_story");var scroll_y = window.scrollY || document.documentElement.scrollTop;var story_positions = [];if(stories.length){var top;for (var i = 0; i < stories.length; i++){top = stories[i].getBoundingClientRect().top + scroll_y;story_positions.push({id:stories[i].getAttribute('data-id'),position:{top:top}});}}return story_positions;}function calculate_ad_positions(){var ads = document.querySelectorAll(".dfp-feed-ad");var scroll_y = window.scrollY || document.documentElement.scrollTop;var ad_positions = [];if(ads.length){var top;for (var i = 0; i < ads.length; i++){if(ads[i].getAttribute('data-shown') == 0){top = ads[i].getBoundingClientRect().top + scroll_y;ad_positions.push({id:ads[i].getAttribute('data-id'),position:{top:top}});}}}return ad_positions;}function update_ad_positions(data){data.ad_positions = calculate_ad_positions();//console.log(data.ad_positions);}function load_stories(data){if(data.loading_stories == false){var url = '/optimized/feed/?';var post = {offset: data.options.offset,limit: data.options.limit};if(typeof data.options.category != 'undefined' && data.options.category != null){post.category = data.options.category;}if(typeof data.options.exclude_stories != 'undefined' && data.options.exclude_stories != null){post.exclude_story = data.options.exclude_stories;}for (var key in post) {url += key + '=' + post[key] + '&';}url = url.slice(0, -1);data.loading_stories = true;var xhr = new XMLHttpRequest();xhr.onreadystatechange = feed_request_callback(xhr, data)xhr.open("GET", url, true);data.options.offset += data.options.limit;xhr.send();// gtag("event", "page_view", {// pageTitle: data.url + "| page: " + (data.options.offset/data.options.limit)// // });// ga('send', 'pageview', {'page': data.url + ':' + (data.options.offset/data.options.limit)});}}function handleScroll(position,data){var furthest_scrolled_story = {id: '',position:{top: 0}};//use bottom of screenvar compare_to = position+window.innerHeight;var position_in_list = 0;if(data.story_positions.length){data.story_positions.sort(function(a,b) {return a.position.top < b.position.top ? -1 : a.position.top > b.position.top ? 1 : 0;});for (i = 0; i < data.story_positions.length; i++){if(compare_to>data.story_positions[i].position.top && data.story_positions[i].position.top>furthest_scrolled_story.position.top){furthest_scrolled_story = data.story_positions[i];position_in_list = i;}}}if(furthest_scrolled_story.id > '' && window.location.hash != '#fs_' + furthest_scrolled_story.id){if(history.replaceState){history.replaceState(undefined, undefined, '#fs_' + furthest_scrolled_story.id);}}if(data.story_positions.length - position_in_list <7){load_stories(data);}if(data.ad_positions.length){var ad_compare_to = compare_to + 100;for (i = 0; i < data.ad_positions.length; i++){if(data.ad_positions[i] != null && ad_compare_to>data.ad_positions[i].position.top){show_ad(data.ad_positions[i].id);data.ad_positions[i] = null;}}}}//may switch this to a timeout of 50 for better performancefunction scroll_callback(data){return function(){data.last_known_scroll_position = window.scrollY || document.documentElement.scrollTop;if(!data.ticking){window.requestAnimationFrame(function() {handleScroll(data.last_known_scroll_position,data);data.ticking = false;});data.ticking = true;}};}function refresh_callback(data){return function(event){event.preventDefault();data.loading_status.innerHTML = 'Updating Stories';data.loading_svg.style.display = 'block';data.options.offset = 0;data.should_append_feed = false;load_stories(data);};}function show_ad(ad_id){var ad = document.getElementById(ad_id);ad.setAttribute('data-shown',1);//console.log('yay ad! ' + ad_id);if((' ' + ad.className + ' ').indexOf(' dfp-square ') > -1){feed_ajax_ad(ad, '/15020739/nowmedia_sidebar', [300, 250], dfp_targeting);}else {if(window.innerWidth<=500){feed_ajax_ad(ad, '/15020739/nowmedia_sidebar', [300, 250], dfp_targeting);}else {feed_ajax_ad(ad, '/15020739/nowmedia_news_feed', [728, 90], dfp_targeting);}/*if(typeof site_url != 'undefined' && site_url != 'www.kelownanow.com' && site_url != 'www.kamloopsbcnow.com'){//var rand = Math.floor(Math.random() * Math.floor(11));//if(rand < 8){//console.log('feed adsense');//feed_ajax_ad(ad, '/15020739/nowmedia_leaderboard/nowmedia_leaderboard_adsense', [728, 90], dfp_targeting);//}//else {feed_ajax_ad(ad, '/15020739/nowmedia_news_feed', [728, 90], dfp_targeting);//}}else {feed_ajax_ad(ad, '/15020739/nowmedia_news_feed', [728, 90], dfp_targeting);}*/}}//googletag.openConsole();function feed_ajax_ad(e, slotCode, size, targeting) {if (typeof targeting === 'undefined') { targeting = {}; } else if ( Object.prototype.toString.call( targeting ) !== '[object Object]' ) { targeting = {}; }var elId = e.getAttribute('id'); googletag.cmd.push(function() { //console.log(elId); var slot = googletag.defineSlot(slotCode, size, elId); //console.log(slot); for (var t in targeting) { slot.setTargeting(t, targeting[t]); } slot.addService(googletag.pubads()); googletag.display(elId); //googletag.pubads().refresh([slot]); });}function init_feed(element_id){var e = document.getElementById(element_id);var now = Math.floor(Date.now() / 1000);if(typeof e != 'undefined'){var options = {};if(typeof e.getAttribute('data-options') > ''){options = JSON.parse(e.getAttribute('data-options'));}options.offset = 0;if(typeof options.limit == 'undefined'){options.limit = 7;}if(typeof options.show_ads == 'undefined'){options.show_ads = 'after';}var options_string = JSON.stringify(options);var data = {options_string: options_string, options:options, ticking: false,saved_list: [],loading: document.getElementById('news_feed_loading'),loading_status: document.getElementById('news_feed_loading_status'),loading_svg: document.getElementById('news_feed_svg'),ad_counter: 0,last_known_scroll_position: 0,loading_stories: false,story_positions: [],ad_positions: [],should_append_feed: true,url: window.location.pathname};var saved_list = sessionStorage.getItem('feed_' + options_string);var saved_date = sessionStorage.getItem('feed_date_' + options_string);//if there are saved stories, and there's a hash in the url, indicating scrolling down the pageif(window.location.hash && saved_list != null && saved_date != null){//console.log('load new stories');saved_list = JSON.parse(saved_list);data.loading.style.display = 'block';for (i = 0; i < saved_list.length; i++){show_list(saved_list[i],data);data.options.offset += data.options.limit;}data.saved_list = saved_list;}//if its been more than 5 minutes, load new storiesif(!window.location.hash || saved_date == null || (now - parseInt(saved_date)) > (60*5)){data.should_append_feed = false;data.options.offset = 0;data.saved_list = [];load_stories(data);}else {//console.log('show_saved_stories');data.loading.style.display = 'none';setTimeout(function(){data.loading_status.innerHTML = 'Click to Check for New Stories';data.loading_svg.style.display = 'none';data.loading.style.display = 'block';}, 240000);}//load_stories(data);//may want to also do this for storieswindow.addEventListener('load', update_ad_positions(data));setTimeout(function(){update_ad_positions(data);}, 3000);window.addEventListener('scroll', scroll_callback(data));data.loading.addEventListener('click', refresh_callback(data));return true;}return false;}//only show ads if should_append_feed is trueinit_feed('news_feed');//}
19°
Thu
27℃
Fri
28℃
Sat
28℃
Sun
26℃
Mon
23℃
Tue
26℃
Recent Livestream
Top Stories
Kelowna's Born to Shake looks to expand
Lots of food still perfectly edible after its 'best before date'
‘Well-placed kick’: Arrest made after bystander knocks BC man fleeing police off bike
Body of second missing cousin found in Dawson Creek, BC
BC environmental regulator orders LNG company to deploy 'floatel' near Squamish
Over $114K in contraband seized from BC prison
VIDEO: Grieving mother disappointed in crane safety recommendations
Follow Us
Privacy Policy