Skip to content

Instantly share code, notes, and snippets.

@neufeldtech
Last active January 25, 2016 04:01
Show Gist options
  • Save neufeldtech/b3ae8e7619bd0ad02f01 to your computer and use it in GitHub Desktop.
Save neufeldtech/b3ae8e7619bd0ad02f01 to your computer and use it in GitHub Desktop.
<script>
jQuery( document ).ready(function() {
(function(jQuery){
jQuery.extend({
jGFeed : function(url, fnk, num, key){
// Make sure url to get is defined
if(url == null) return false;
// Build Google Feed API URL
var gurl = "https://ajax.googleapis.com/ajax/services/feed/load?v=1.0&callback=?&q="+url;
if(num != null) gurl += "&num="+num;
if(key != null) gurl += "&key="+key;
// AJAX request the API
jQuery.getJSON(gurl, function(data){
if(typeof fnk == 'function')
fnk.call(this, data.responseData.feed);
else
return false;
});
}
});
})(jQuery);
//Put in desired feed below:
// Whitehorse
var feed = "https://weather.gc.ca/rss/battleboard/yt10_e.xml";
//Carberry
// var feed = "http://meteo.gc.ca/rss/warning/mb-35_e.xml"
var alertBarHtml = '<div class=\"alert alert-danger weather-alert\" style=\"margin:0px;padding:3px;display:none;text-align:center;cursor: pointer\"><i class=\"fa fa-exclamation-triangle\"></i>&nbsp;<strong><span class=\"contentTitle\"></span></strong></div>';
jQuery('#main-nav').prepend(alertBarHtml);
jQuery.jGFeed(feed,
function(feeds){
// Check for errors
if(!feeds){
// there was an error
return false;
}
// Loop through the entries
for(var i=0; i<feeds.entries.length; i++){
var entry = feeds.entries[i];
// Set Entry title (Main warning)
jQuery('span.contentTitle').text(entry.title);
// Set URL
var weatherUrl = entry.link;
// Build the onClick event for the URL
var onClick = "window.open('" + entry.link + "', '_blank')";
// Attach onclick event to the Alert Div
jQuery('div.weather-alert').attr("onclick",onClick );
var noWarningsString = "no watches or warnings in effect"
if (entry.title.toLowerCase().indexOf(noWarningsString) >= 0) {
//Do not display the banner
} else {
jQuery('div.weather-alert').css('display','block');
}
}
}, 10);
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment