// Copyright Our-Hometown, Inc. // Points Mentioned // usage var newsbayoushort = function() { var self = this; var iplocation = {"continent_code":"NA","country_code":"US","country_code3":"USA","country_name":"United States","region":"VA","city":"Ashburn","postal_code":"20147","latitude":39.018001556396,"longitude":-77.539001464844,"dma_code":511,"area_code":703}; var pt_short = null; var pt_domain = 'pointsmentioned.com'; var stories = 3; var address = "San Francisco, CA"; var latitude = 37.7749295; var longitude = -122.4194155; var pt_height = 0; var gotoNewsBayou = function() { document.location.href = 'https://newsbayou.our-hometown.com/#!/' + encodeURIComponent(address) + '/0.5'; }; var scaleWidget = function() { pt_short.className = 'small'; if(pt_height > 0) { pt_short.style.maxHeight = pt_height + 'px'; pt_short.style.overflow = 'auto'; } else { return; } }; var header = function() { var short_header = null; if(document.getElementById('short-header') != null) { short_header = document.getElementById('short-header'); } else { short_header = document.createElement('div'); short_header.id = 'short-header'; pt_short.appendChild(short_header); } short_header.innerHTML = '

A personalized look at news in your area

for ' + address + '

'; }; var footer = function() { var short_footer = null; if(document.getElementById('ptshort-footer') != null) { short_footer = document.getElementById('ptshort-footer'); } else { short_footer = document.createElement('p'); short_footer.className = 'check-out'; short_footer.id = 'ptshort-footer'; pt_short.appendChild(short_footer); } short_footer.innerHTML = 'Check Us Out Today'; }; self.geolocate = function() { navigator.geolocation.getCurrentPosition(function(position) { latitude = position.coords.latitude; longitude = position.coords.longitude; var latlng = new google.maps.LatLng(latitude, longitude); var geocoder = new google.maps.Geocoder(); geocoder.geocode({'latLng' : latlng}, function(results, status) { address = 'Unknown Location'; if (status == google.maps.GeocoderStatus.OK) { address = 'Unknown Location'; if(results[0]) { address = results[0].formatted_address; } } else { address = 'Unknown Location'; } ptshort_loadstories(); }); }, function(error) { return; }, {enableHighAccuracy: true, timeout: 30000}); }; var ptshort_loadstories = function() { header(); var short_stories = null; if(document.getElementById('short-stories') != null) { short_stories = document.getElementById('short-stories'); } else { short_stories = document.createElement('ul'); short_stories.id = 'short-stories'; pt_short.appendChild(short_stories); footer(); } document.getElementById('short-stories').innerHTML = 'loading'; ptshort_loadScript('//' + pt_domain + '/js/bayoushort/stories/' + latitude + '/' + longitude + '/' + stories, ptshort_renderstories); } var ptshort_renderstories = function() { var short_stories = null; if(document.getElementById('short-stories') != null) { short_stories = document.getElementById('short-stories'); } else { short_stories = document.createElement('ul'); short_stories.id = 'short-stories'; pt_short.appendChild(short_stories); footer(); } document.getElementById('short-stories').innerHTML = ''; // fix teaser for(var t = 0; t < ptshort_locations.length; t++) { ptshort_locations[t].teaser = (ptshort_locations[t].teaser.indexOf('')>0?'...':'') + ptshort_locations[t].teaser.match(/.{0,50}.*<\/span>.{0,100}/g) + '...'; } for(var i = 0; i < ptshort_locations.length; i++) { var short_story = document.createElement('li'); short_story.innerHTML = '
' + timeSince(ptshort_locations[i].hoursago*3600) + '
' + ptshort_locations[i].miles + ' miles

' + ptshort_locations[i].title + '

' + ptshort_locations[i].teaser + ''; short_stories.appendChild(short_story); } }; function addCSS(cssname) { var th = document.getElementsByTagName('head')[0]; var cssref=document.createElement("link"); cssref.setAttribute("rel", "stylesheet"); cssref.setAttribute("type", "text/css"); cssref.setAttribute("href", cssname); th.appendChild(cssref); } // http://stackoverflow.com/questions/3177836/how-to-format-time-since-xxx-e-g-4-minutes-ago-similar-to-stack-exchange-site function timeSince(seconds) { var interval = Math.floor(seconds / 31536000); if (interval > 1) { return interval + " Years"; } interval = Math.floor(seconds / 2592000); if (interval > 1) { return interval + " Mnths"; } interval = Math.floor(seconds / 86400); if (interval > 1) { return interval + " Days"; } interval = Math.floor(seconds / 3600); if (interval > 1) { return interval + " Hrs"; } interval = Math.floor(seconds / 60); if (interval > 1) { return interval + " Min"; } return "Now"; } var ptshort_loadScript = function(scriptUrl, afterCallback) { var firstScriptElement = document.getElementsByTagName('script')[0]; var scriptElement = document.createElement('script'); scriptElement.type = 'text/javascript'; scriptElement.async = false; scriptElement.src = scriptUrl; var ieLoadBugFix = function (scriptElement, callback) { if ( scriptElement.readyState == 'loaded' || scriptElement.readyState == 'complete' ) { callback(); } else { setTimeout(function() { ieLoadBugFix(scriptElement, callback); }, 100); } }; if ( typeof afterCallback === "function" ) { if ( typeof scriptElement.addEventListener !== "undefined" ) { scriptElement.addEventListener("load", afterCallback, false); } else { scriptElement.onreadystatechange = function(){ scriptElement.onreadystatechange = null; ieLoadBugFix(scriptElement, afterCallback); }; } } firstScriptElement.parentNode.insertBefore(scriptElement, firstScriptElement); }; return{ init: function(){ if(iplocation != false) { latitude = iplocation.latitude; longitude = iplocation.longitude; address = iplocation.city + ", " + iplocation.region + ", " + iplocation.country_code; } addCSS("//fonts.googleapis.com/css?family=Open+Sans:400,700"); addCSS("//" + pt_domain + '/bundles/pointsmentionedmain/css/pt_short.css?654'); var pt_anchor = document.getElementById('newsbayou-short'); pt_short = document.createElement('div'); pt_short.id = 'pt-short'; pt_short.onclick = gotoNewsBayou; scaleWidget(); pt_anchor.parentElement.insertBefore(pt_short,pt_anchor); ptshort_loadstories(); ptshort_loadScript('//maps.googleapis.com/maps/api/js?sensor=true&callback=newsbayoushort.geocallback', function(){}); }, geocallback: function() { geolocate(); } } }(); newsbayoushort.init();