|
From: <ma...@us...> - 2011-07-06 19:46:06
|
Revision: 383
http://openautomation.svn.sourceforge.net/openautomation/?rev=383&view=rev
Author: makki1
Date: 2011-07-06 19:45:58 +0000 (Wed, 06 Jul 2011)
Log Message:
-----------
Plugins RSS and Yahoo-weather - both still need some work on CSS to look fine, so no entry in visu_config_demo yet
Added Paths:
-----------
CometVisu/trunk/visu/plugins/rss/
CometVisu/trunk/visu/plugins/rss/structure_plugin.js
CometVisu/trunk/visu/plugins/rss/zrssfeed/
CometVisu/trunk/visu/plugins/rss/zrssfeed/jquery.vticker.js
CometVisu/trunk/visu/plugins/rss/zrssfeed/jquery.zrssfeed.css
CometVisu/trunk/visu/plugins/rss/zrssfeed/jquery.zrssfeed.js
CometVisu/trunk/visu/plugins/rss/zrssfeed/jquery.zrssfeed.min.js
CometVisu/trunk/visu/plugins/zweather/
CometVisu/trunk/visu/plugins/zweather/structure_plugin.js
CometVisu/trunk/visu/plugins/zweather/zweatherfeed/
CometVisu/trunk/visu/plugins/zweather/zweatherfeed/jquery.zweatherfeed.css
CometVisu/trunk/visu/plugins/zweather/zweatherfeed/jquery.zweatherfeed.js
CometVisu/trunk/visu/plugins/zweather/zweatherfeed/jquery.zweatherfeed.min.js
Added: CometVisu/trunk/visu/plugins/rss/structure_plugin.js
===================================================================
--- CometVisu/trunk/visu/plugins/rss/structure_plugin.js (rev 0)
+++ CometVisu/trunk/visu/plugins/rss/structure_plugin.js 2011-07-06 19:45:58 UTC (rev 383)
@@ -0,0 +1,115 @@
+/* structure_plugin.js (c) 2011 by Michael Markstaller [de...@wi...]
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation; either version 3 of the License, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+*/
+
+/**
+ * This plugins integrates jFeed to display RSS-Feeds into CometVisu.
+ */
+
+$("body").append("<script type=\"text/javascript\" src=\"plugins/rss/zrssfeed/jquery.zrssfeed.min.js\"></script>");
+
+VisuDesign_Custom.prototype.addCreator("rss", {
+ create: function( page, path ) {
+ var $p = $(page);
+
+ function uniqid() {
+ var newDate = new Date;
+ return newDate.getTime();
+ }
+
+ var id = "rss_" + uniqid();
+
+ var ret_val = $('<div class="widget" />');
+ ret_val.addClass( 'rss' );
+ var label = '<div class="label">' + page.textContent + '</div>';
+ var actor = $("<div class=\"actor\"><div class=\"rss_inline\" id=\"" + id + "\">loading...</div></div>");
+ var rss = $("#" + id, actor);
+
+ if ($p.attr("width")) {
+ rss.css("width", $p.attr("width"));
+ }
+ if ($p.attr("height")) {
+ rss.css("height", $p.attr("height"));
+ }
+
+ ret_val.append(label).append(actor);
+
+ rss.data("id", id);
+ rss.data("src", $p.attr("src"));
+ rss.data("label", page.textContent);
+ rss.data("refresh", $p.attr("refresh"));
+ rss.data("limit", $p.attr("limit")) || 10;
+ rss.data("header", $p.attr("header")) || true;
+ rss.data("date", $p.attr("date")) || true;
+ rss.data("content", $p.attr("content")) || true;
+ rss.data("snippet", $p.attr("snippet")) || true;
+ rss.data("showerror", $p.attr("showerror")) || true;
+ rss.data("ssl", $p.attr("ssl")) || false;
+ rss.data("linktarget", $p.attr("linktarget")) || "_new";
+
+ refreshRSS(rss, {});
+
+ return ret_val;
+ },
+ attributes: {
+ src: {type: "string", required: true},
+ width: {type: "string", required: false},
+ height: {type: "string", required: false},
+ refresh: {type: "numeric", required: false},
+ limit: {type: "numeric", required: false},
+ header: {type: "list", required: false, list: {'true': "yes", 'false': "no"}},
+ date: {type: "list", required: false, list: {'true': "yes", 'false': "no"}},
+ content: {type: "list", required: false, list: {'true': "yes", 'false': "no"}},
+ snippet: {type: "list", required: false, list: {'true': "yes", 'false': "no"}},
+ showerror: {type: "list", required: false, list: {'true': "yes", 'false': "no"}},
+ ssl: {type: "list", required: false, list: {'true': "yes", 'false': "no"}},
+ linktarget: {type: "list", required: false, list: {"_new": "_new", "_self": "_self"}}
+ },
+ content: {type: "string", required: true}
+});
+
+function refreshRSS(rss, data) {
+ var rss = $(rss);
+
+ var src = rss.data("src");
+ var label = rss.data("label");
+ var refresh = rss.data("refresh");
+ var limit = rss.data("limit");
+ //console.log("refresh rss:" + src); //DEBUG
+ //eval needed to convert string true/false to bool?
+ jQuery(function() {
+ $(rss).rssfeed(src, {
+ limit: rss.data("limit"),
+ header: eval(rss.data("header")),
+ date: eval(rss.data("date")),
+ date: eval(rss.data("date")),
+ content: rss.data("content"),
+ snippet: eval(rss.data("snippet")),
+ showerror: eval(rss.data("showerror")),
+ ssl: eval(rss.data("ssl")),
+ linktarget: rss.data("linktarget")
+ });
+
+ });
+ if (typeof (refresh) != "undefined" && refresh) {
+ // reload regularly
+ window.setTimeout(function(rss, data) {
+ refreshRSS(rss, data)
+ }, refresh * 1000, rss, data);
+ }
+
+ return false;
+}
Added: CometVisu/trunk/visu/plugins/rss/zrssfeed/jquery.vticker.js
===================================================================
--- CometVisu/trunk/visu/plugins/rss/zrssfeed/jquery.vticker.js (rev 0)
+++ CometVisu/trunk/visu/plugins/rss/zrssfeed/jquery.vticker.js 2011-07-06 19:45:58 UTC (rev 383)
@@ -0,0 +1,77 @@
+/*
+* Tadas Juozapaitis ( kas...@gm... )
+*
+* Modifed by Zazar:
+* 24.06.2011 - Corrected pausing issue with multiple instances
+*
+*/
+
+(function($){
+
+$.fn.vTicker = function(options) {
+ var defaults = {
+ speed: 700,
+ pause: 4000,
+ showItems: 3,
+ animation: '',
+ mousePause: true,
+ isPaused: false
+ };
+
+ var options = $.extend(defaults, options);
+
+ moveUp = function(obj2, height, paused){
+ if(paused) return;
+
+ var obj = obj2.children('ul');
+
+ first = obj.children('li:first').clone(true);
+
+ obj.animate({top: '-=' + height + 'px'}, options.speed, function() {
+ $(this).children('li:first').remove();
+ $(this).css('top', '0px');
+ });
+
+ if(options.animation == 'fade') {
+ obj.children('li:first').fadeOut(options.speed);
+ obj.children('li:last').hide().fadeIn(options.speed);
+ }
+
+ first.appendTo(obj);
+ };
+
+ return this.each(function() {
+ var obj = $(this);
+ var maxHeight = 0;
+ var itempause = options.isPaused;
+
+ obj.css({overflow: 'hidden', position: 'relative'})
+ .children('ul').css({position: 'absolute', margin: 0, padding: 0})
+ .children('li').css({margin: 0, padding: 0});
+
+ obj.children('ul').children('li').each(function(){
+
+ if($(this).height() > maxHeight) {
+ maxHeight = $(this).height();
+ }
+ });
+
+ obj.children('ul').children('li').each(function() {
+ $(this).height(maxHeight);
+ });
+
+ obj.height(maxHeight * options.showItems);
+
+ var interval = setInterval(function(){ moveUp(obj, maxHeight, itempause); }, options.pause);
+
+ if (options.mousePause)
+ {
+ obj.bind("mouseenter",function() {
+ itempause = true;
+ }).bind("mouseleave",function() {
+ itempause = false;
+ });
+ }
+ });
+};
+})(jQuery);
\ No newline at end of file
Added: CometVisu/trunk/visu/plugins/rss/zrssfeed/jquery.zrssfeed.css
===================================================================
--- CometVisu/trunk/visu/plugins/rss/zrssfeed/jquery.zrssfeed.css (rev 0)
+++ CometVisu/trunk/visu/plugins/rss/zrssfeed/jquery.zrssfeed.css 2011-07-06 19:45:58 UTC (rev 383)
@@ -0,0 +1,52 @@
+@charset "UTF-8";
+/*
+ * Example of zRSSFeed Styling
+ *
+ * Version: 1.1.2
+ * (c) Copyright 2010-2011, Zazar Ltd
+ *
+ */
+
+body {
+ margin: 1em 3em;
+ font-family: Tahoma, Genevam, sans-serif;
+}
+
+.rssFeed {
+ font-family: Arial, Helvetica, sans-serif;
+ font-size: 90%;
+ margin: 2em 3em;
+}
+.rssFeed a {
+ color: #444;
+ text-decoration: none;
+}
+.rssFeed a:hover {
+ color: #000;
+ text-decoration: underline;
+}
+
+.rssHeader { padding: 0.2em 0; }
+
+.rssBody { border: 1px solid #999; }
+.rssBody ul { list-style: none; }
+.rssBody ul, .rssRow, .rssRow h4, .rssRow p {
+ margin: 0;
+ padding: 0;
+}
+
+.rssRow { padding: 0.8em; }
+.rssRow h4 { font-size: 1.1em; }
+.rssRow div {
+ font-size: 90%;
+ color: #666;
+ margin: 0.2em 0 0.4em 0;
+}
+
+.odd { background-color: #e8e8fc; }
+.even { background-color: #d4d4e8; }
+
+.rssRow .rssMedia {
+ padding: 0.5em;
+ font-size: 1em;
+}
Added: CometVisu/trunk/visu/plugins/rss/zrssfeed/jquery.zrssfeed.js
===================================================================
--- CometVisu/trunk/visu/plugins/rss/zrssfeed/jquery.zrssfeed.js (rev 0)
+++ CometVisu/trunk/visu/plugins/rss/zrssfeed/jquery.zrssfeed.js 2011-07-06 19:45:58 UTC (rev 383)
@@ -0,0 +1,187 @@
+/**
+ * Plugin: jquery.zRSSFeed
+ *
+ * Version: 1.1.2
+ * (c) Copyright 2010-2011, Zazar Ltd
+ *
+ * Description: jQuery plugin for display of RSS feeds via Google Feed API
+ * (Based on original plugin jGFeed by jQuery HowTo. Filesize function by Cary Dunn.)
+ *
+ * History:
+ * 1.1.2 - Added user callback function due to issue with ajaxStop after jQuery 1.4.2
+ * 1.1.1 - Correction to null xml entries and support for media with jQuery < 1.5
+ * 1.1.0 - Added support for media in enclosure tags
+ * 1.0.3 - Added feed link target
+ * 1.0.2 - Fixed issue with GET parameters (Seb Dangerfield) and SSL option
+ * 1.0.1 - Corrected issue with multiple instances
+ *
+ **/
+
+(function($){
+
+ $.fn.rssfeed = function(url, options, fn) {
+
+ // Set pluign defaults
+ var defaults = {
+ limit: 10,
+ header: true,
+ titletag: 'h4',
+ date: true,
+ content: true,
+ snippet: true,
+ showerror: true,
+ errormsg: '',
+ key: null,
+ ssl: false,
+ linktarget: '_self'
+ };
+ var options = $.extend(defaults, options);
+
+ // Functions
+ return this.each(function(i, e) {
+ var $e = $(e);
+ var s = '';
+
+ // Check for SSL protocol
+ if (options.ssl) s = 's';
+
+ // Add feed class to user div
+ if (!$e.hasClass('rssFeed')) $e.addClass('rssFeed');
+
+ // Check for valid url
+ if(url == null) return false;
+
+ // Create Google Feed API address
+ var api = "http"+ s +"://ajax.googleapis.com/ajax/services/feed/load?v=1.0&callback=?&q=" + encodeURIComponent(url);
+ if (options.limit != null) api += "&num=" + options.limit;
+ if (options.key != null) api += "&key=" + options.key;
+ api += "&output=json_xml"
+
+ // Send request
+ $.getJSON(api, function(data){
+
+ // Check for error
+ if (data.responseStatus == 200) {
+
+ // Process the feeds
+ _process(e, data.responseData, options);
+
+ // Optional user callback function
+ if ($.isFunction(fn)) fn.call(this,$e);
+
+ } else {
+
+ // Handle error if required
+ if (options.showerror)
+ if (options.errormsg != '') {
+ var msg = options.errormsg;
+ } else {
+ var msg = data.responseDetails;
+ };
+ $(e).html('<div class="rssError"><p>'+ msg +'</p></div>');
+ };
+ });
+ });
+ };
+
+ // Function to create HTML result
+ var _process = function(e, data, options) {
+
+ // Get JSON feed data
+ var feeds = data.feed;
+ if (!feeds) {
+ return false;
+ }
+ var html = '';
+ var row = 'odd';
+
+ // Get XML data for media (parseXML not used as requires 1.5+)
+ var xml = getXMLDocument(data.xmlString);
+ var xmlEntries = xml.getElementsByTagName('item');
+
+ // Add header if required
+ if (options.header)
+ html += '<div class="rssHeader">' +
+ '<a href="'+feeds.link+'" title="'+ feeds.description +'">'+ feeds.title +'</a>' +
+ '</div>';
+
+ // Add body
+ html += '<div class="rssBody">' +
+ '<ul>';
+
+ // Add feeds
+ for (var i=0; i<feeds.entries.length; i++) {
+
+ // Get individual feed
+ var entry = feeds.entries[i];
+
+ // Format published date
+ var entryDate = new Date(entry.publishedDate);
+ var pubDate = entryDate.toLocaleDateString() + ' ' + entryDate.toLocaleTimeString();
+
+ // Add feed row
+ html += '<li class="rssRow '+row+'">' +
+ '<'+ options.titletag +'><a href="'+ entry.link +'" title="View this feed at '+ feeds.title +'" target="'+ options.linktarget +'">'+ entry.title +'</a></'+ options.titletag +'>'
+ if (options.date) html += '<div>'+ pubDate +'</div>'
+ if (options.content) {
+
+ // Use feed snippet if available and optioned
+ if (options.snippet && entry.contentSnippet != '') {
+ var content = entry.contentSnippet;
+ } else {
+ var content = entry.content;
+ }
+
+ html += '<p>'+ content +'</p>'
+ }
+
+ // Add any media
+ if(xmlEntries.length > 0) {
+ var xmlMedia = xmlEntries[i].getElementsByTagName('enclosure');
+ if (xmlMedia.length > 0) {
+ html += '<div class="rssMedia"><div>Media files</div><ul>'
+ for (var m=0; m<xmlMedia.length; m++) {
+ var xmlUrl = xmlMedia[m].getAttribute("url");
+ var xmlType = xmlMedia[m].getAttribute("type");
+ var xmlSize = xmlMedia[m].getAttribute("length");
+ html += '<li><a href="'+ xmlUrl +'" title="Download this media">'+ xmlUrl.split('/').pop() +'</a> ('+ xmlType +', '+ formatFilesize(xmlSize) +')</li>';
+ }
+ html += '</ul></div>'
+ }
+ html += '</li>';
+ }
+
+ // Alternate row classes
+ if (row == 'odd') {
+ row = 'even';
+ } else {
+ row = 'odd';
+ }
+ }
+
+ html += '</ul>' +
+ '</div>'
+
+ $(e).html(html);
+ };
+
+ function formatFilesize(bytes) {
+ var s = ['bytes', 'kb', 'MB', 'GB', 'TB', 'PB'];
+ var e = Math.floor(Math.log(bytes)/Math.log(1024));
+ return (bytes/Math.pow(1024, Math.floor(e))).toFixed(2)+" "+s[e];
+ }
+
+ function getXMLDocument(string) {
+ var browser = navigator.appName;
+ var xml;
+ if (browser == 'Microsoft Internet Explorer') {
+ xml = new ActiveXObject('Microsoft.XMLDOM');
+ xml.async = 'false'
+ xml.loadXML(string);
+ } else {
+ xml = (new DOMParser()).parseFromString(string, 'text/xml');
+ }
+ return xml;
+ }
+
+})(jQuery);
Added: CometVisu/trunk/visu/plugins/rss/zrssfeed/jquery.zrssfeed.min.js
===================================================================
--- CometVisu/trunk/visu/plugins/rss/zrssfeed/jquery.zrssfeed.min.js (rev 0)
+++ CometVisu/trunk/visu/plugins/rss/zrssfeed/jquery.zrssfeed.min.js 2011-07-06 19:45:58 UTC (rev 383)
@@ -0,0 +1,19 @@
+
+(function($){$.fn.rssfeed=function(url,options,fn){var defaults={limit:10,header:true,titletag:'h4',date:true,content:true,snippet:true,showerror:true,errormsg:'',key:null,ssl:false,linktarget:'_self'};var options=$.extend(defaults,options);return this.each(function(i,e){var $e=$(e);var s='';if(options.ssl)s='s';if(!$e.hasClass('rssFeed'))$e.addClass('rssFeed');if(url==null)return false;var api="http"+s+"://ajax.googleapis.com/ajax/services/feed/load?v=1.0&callback=?&q="+encodeURIComponent(url);if(options.limit!=null)api+="&num="+options.limit;if(options.key!=null)api+="&key="+options.key;api+="&output=json_xml"
+$.getJSON(api,function(data){if(data.responseStatus==200){_process(e,data.responseData,options);if($.isFunction(fn))fn.call(this,$e);}else{if(options.showerror)
+if(options.errormsg!=''){var msg=options.errormsg;}else{var msg=data.responseDetails;};$(e).html('<div class="rssError"><p>'+msg+'</p></div>');};});});};var _process=function(e,data,options){var feeds=data.feed;if(!feeds){return false;}
+var html='';var row='odd';var xml=getXMLDocument(data.xmlString);var xmlEntries=xml.getElementsByTagName('item');if(options.header)
+html+='<div class="rssHeader">'+'<a href="'+feeds.link+'" title="'+feeds.description+'">'+feeds.title+'</a>'+'</div>';html+='<div class="rssBody">'+'<ul>';for(var i=0;i<feeds.entries.length;i++){var entry=feeds.entries[i];var entryDate=new Date(entry.publishedDate);var pubDate=entryDate.toLocaleDateString()+' '+entryDate.toLocaleTimeString();html+='<li class="rssRow '+row+'">'+'<'+options.titletag+'><a href="'+entry.link+'" title="View this feed at '+feeds.title+'" target="'+options.linktarget+'">'+entry.title+'</a></'+options.titletag+'>'
+if(options.date)html+='<div>'+pubDate+'</div>'
+if(options.content){if(options.snippet&&entry.contentSnippet!=''){var content=entry.contentSnippet;}else{var content=entry.content;}
+html+='<p>'+content+'</p>'}
+if(xmlEntries.length>0){var xmlMedia=xmlEntries[i].getElementsByTagName('enclosure');if(xmlMedia.length>0){html+='<div class="rssMedia"><div>Media files</div><ul>'
+for(var m=0;m<xmlMedia.length;m++){var xmlUrl=xmlMedia[m].getAttribute("url");var xmlType=xmlMedia[m].getAttribute("type");var xmlSize=xmlMedia[m].getAttribute("length");html+='<li><a href="'+xmlUrl+'" title="Download this media">'+xmlUrl.split('/').pop()+'</a> ('+xmlType+', '+formatFilesize(xmlSize)+')</li>';}
+html+='</ul></div>'}
+html+='</li>';}
+if(row=='odd'){row='even';}else{row='odd';}}
+html+='</ul>'+'</div>'
+$(e).html(html);};function formatFilesize(bytes){var s=['bytes','kb','MB','GB','TB','PB'];var e=Math.floor(Math.log(bytes)/Math.log(1024));return(bytes/Math.pow(1024,Math.floor(e))).toFixed(2)+" "+s[e];}
+function getXMLDocument(string){var browser=navigator.appName;var xml;if(browser=='Microsoft Internet Explorer'){xml=new ActiveXObject('Microsoft.XMLDOM');xml.async='false'
+xml.loadXML(string);}else{xml=(new DOMParser()).parseFromString(string,'text/xml');}
+return xml;}})(jQuery);
\ No newline at end of file
Added: CometVisu/trunk/visu/plugins/zweather/structure_plugin.js
===================================================================
--- CometVisu/trunk/visu/plugins/zweather/structure_plugin.js (rev 0)
+++ CometVisu/trunk/visu/plugins/zweather/structure_plugin.js 2011-07-06 19:45:58 UTC (rev 383)
@@ -0,0 +1,89 @@
+/* structure_plugin.js (c) 2011 by Michael Markstaller [de...@wi...]
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation; either version 3 of the License, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+*/
+
+/**
+ * This plugins integrates jFeed to display RSS-Feeds into CometVisu.
+ */
+
+// $( 'head' ).append( '<link rel="stylesheet" href="plugins/zweather/zweatherfeed/jquery.zweatherfeed.css" type="text/css" />' );
+$( 'head' ).append("<script type=\"text/javascript\" src=\"plugins/zweather/zweatherfeed/jquery.zweatherfeed.min.js\"></script>");
+
+VisuDesign_Custom.prototype.addCreator("zweather", {
+ create: function( page, path ) {
+ var $p = $(page);
+
+ function uniqid() {
+ var newDate = new Date;
+ return newDate.getTime();
+ }
+
+ var id = "zweather_" + uniqid();
+
+ var ret_val = $('<div class="widget" />');
+ ret_val.addClass( 'zweather' );
+ var label = '<div class="label">' + page.textContent + '</div>';
+ var actor = $("<div class=\"actor\"><div class=\"zweather_inline\" id=\"" + id + "\"></div></div>");
+ var zweather = $("#" + id, actor);
+
+ if ($p.attr("width")) {
+ zweather.css("width", $p.attr("width"));
+ }
+ if ($p.attr("height")) {
+ zweather.css("height", $p.attr("height"));
+ }
+
+ ret_val.append(label).append(actor);
+ console.log("loaded plugin zweather");
+
+ zweather.data("id", id);
+ zweather.data("label", page.textContent);
+ zweather.data("refresh", $p.attr("refresh"));
+ zweather.data("location", $p.attr("location"));
+ console.log(zweather.data("location"));
+ refreshZWeather(zweather, {});
+
+ return ret_val;
+ },
+ attributes: {
+ width: {type: "string", required: false},
+ height: {type: "string", required: false},
+ refresh: {type: "numeric", required: false},
+ location: {type: "string", required: true}
+ },
+ content: {type: "string", required: true}
+});
+
+function refreshZWeather(zweather, data) {
+ var zweather = $(zweather);
+
+ var label = zweather.data("label");
+ var refresh = zweather.data("refresh");
+ var location = zweather.data("location");
+ console.log("refresh zweather:" + location); //DEBUG
+ //eval needed to convert string true/false to bool?
+ jQuery(function() {
+ $(zweather).weatherfeed([location]);
+ });
+ if (typeof (refresh) != "undefined" && refresh) {
+ // reload regularly
+ window.setTimeout(function(zweather, data) {
+ refreshZWeather(zweather, data)
+ }, refresh * 1000, zweather, data);
+ }
+
+ return false;
+}
Added: CometVisu/trunk/visu/plugins/zweather/zweatherfeed/jquery.zweatherfeed.css
===================================================================
--- CometVisu/trunk/visu/plugins/zweather/zweatherfeed/jquery.zweatherfeed.css (rev 0)
+++ CometVisu/trunk/visu/plugins/zweather/zweatherfeed/jquery.zweatherfeed.css 2011-07-06 19:45:58 UTC (rev 383)
@@ -0,0 +1,44 @@
+@charset "UTF-8";
+/*
+ * Example of zWeatherFeed Styling
+ *
+ * Version: 1.0.2
+ * (c) Copyright 2010, Zazar Ltd
+ *
+ */
+
+.weatherFeed
+{
+ font-family: Arial, Helvetica, sans-serif;
+ font-size: 90%;
+ margin: 2em 3em;
+ width: 280px;
+}
+.weatherFeed a { color: #888; }
+.weatherFeed a:hover
+{
+ color: #000;
+ text-decoration: none;
+}
+.weatherItem
+{
+ padding: 0.8em;
+ text-align: right;
+}
+.weatherCity { text-transform: uppercase; }
+.weatherTemp
+{
+ font-size: 2.8em;
+ font-weight: bold;
+}
+.weatherDesc, .weatherCity { font-weight: bold; }
+.weatherDesc { margin-bottom: 0.4em; }
+.weatherRange, .weatherWind { font-size: 0.8em; }
+.weatherLink
+{
+ text-align: left;
+ font-size: 0.8em;
+}
+
+.odd { background-color: #e8e8fc; }
+.even { background-color: #d4d4e8; }
\ No newline at end of file
Added: CometVisu/trunk/visu/plugins/zweather/zweatherfeed/jquery.zweatherfeed.js
===================================================================
--- CometVisu/trunk/visu/plugins/zweather/zweatherfeed/jquery.zweatherfeed.js (rev 0)
+++ CometVisu/trunk/visu/plugins/zweather/zweatherfeed/jquery.zweatherfeed.js 2011-07-06 19:45:58 UTC (rev 383)
@@ -0,0 +1,141 @@
+/**
+ * Plugin: jquery.zWeatherFeed
+ *
+ * Version: 1.0.2
+ * (c) Copyright 2010, Zazar Ltd
+ *
+ * Description: jQuery plugin for display of Yahoo! Weather feeds
+ *
+ * History:
+ * 1.0.2 - Correction to options / link
+ * 1.0.1 - Added hourly caching to YQL to avoid rate limits
+ * Uses Weather Channel location ID and not Yahoo WOEID
+ * Displays day or night background images
+ *
+ **/
+
+(function($){
+
+ var row = 'odd';
+
+ $.fn.weatherfeed = function(locations, options) {
+
+ // Set pluign defaults
+ var defaults = {
+ unit: 'c',
+ image: true,
+ highlow: true,
+ wind: true,
+ link: true,
+ showerror: true
+ };
+ var options = $.extend(defaults, options);
+
+ // Functions
+ return this.each(function(i, e) {
+ var $e = $(e);
+
+ // Add feed class to user div
+ if (!$e.hasClass('weatherFeed')) $e.addClass('weatherFeed');
+
+ // Check and append locations
+ if (!$.isArray(locations)) return false;
+ var count = locations.length;
+ if (count > 10) count = 10;
+ var locationid = '';
+ for (var i=0; i<count; i++) {
+ if (locationid != '') locationid += ',';
+ locationid += "'"+ locations[i] + "'";
+ }
+
+ // Cache results for an hour to prevent overuse
+ now = new Date()
+
+ // Create Yahoo Weather feed API address
+ var query = "select * from weather.forecast where location in ("+ locationid +") and u='"+ options.unit +"'";
+ var api = 'http://query.yahooapis.com/v1/public/yql?q='+ encodeURIComponent(query) +'&rnd='+ now.getFullYear() + now.getMonth() + now.getDay() + now.getHours() +'&format=json&callback=?';
+
+ // Send request
+ //$.getJSON(api, function(data) {
+ $.ajax({
+ type: 'GET',
+ url: api,
+ dataType: 'json',
+ success: function(data) {
+
+ if (data.query) {
+
+ if (data.query.results.channel.length > 0 ) {
+
+ // Multiple locations
+ var result = data.query.results.channel.length;
+ for (var i=0; i<result; i++) {
+
+ // Create weather feed item
+ _callback(e, data.query.results.channel[i], options);
+ }
+ } else {
+
+ // Single location only
+ _callback(e, data.query.results.channel, options);
+ }
+ } else {
+ if (options.showerror) $e.html('<p>Weather information unavailable</p>');
+ }
+ },
+ error: function(data) {
+ if (options.showerror) $e.html('<p>Weather request failed</p>');
+ }
+ });
+
+ });
+ };
+
+ // Function to each feed item
+ var _callback = function(e, feed, options) {
+ var $e = $(e);
+
+ // Format feed items
+ var wd = feed.wind.direction;
+ if (wd>=348.75&&wd<=360){wd="N"};if(wd>=0&&wd<11.25){wd="N"};if(wd>=11.25&&wd<33.75){wd="NNE"};if(wd>=33.75&&wd<56.25){wd="NE"};if(wd>=56.25&&wd<78.75){wd="ENE"};if(wd>=78.75&&wd<101.25){wd="E"};if(wd>=101.25&&wd<123.75){wd="ESE"};if(wd>=123.75&&wd<146.25){wd="SE"};if(wd>=146.25&&wd<168.75){wd="SSE"};if(wd>=168.75&&wd<191.25){wd="S"};if(wd>=191.25 && wd<213.75){wd="SSW"};if(wd>=213.75&&wd<236.25){wd="SW"};if(wd>=236.25&&wd<258.75){wd="WSW"};if(wd>=258.75 && wd<281.25){wd="W"};if(wd>=281.25&&wd<303.75){wd="WNW"};if(wd>=303.75&&wd<326.25){wd="NW"};if(wd>=326.25&&wd<348.75){wd="NNW"};
+ var wf = feed.item.forecast[0];
+
+ // Determine day or night image
+ wpd = feed.item.pubDate;
+ n = wpd.indexOf(":");
+ tpb = _getTimeAsDate(wpd.substr(n-2,8));
+ tsr = _getTimeAsDate(feed.astronomy.sunrise);
+ tss = _getTimeAsDate(feed.astronomy.sunset);
+
+ if (tpb>tsr && tpb<tss) { daynight = 'd'; } else { daynight = 'n'; }
+
+ // Add item container
+ var html = '<div class="weatherItem '+ row +'"';
+ if (options.image) html += ' style="background-image: url(http://l.yimg.com/a/i/us/nws/weather/gr/'+ feed.item.condition.code + daynight +'.png); background-repeat: no-repeat;"';
+ html += '>';
+
+ // Add item data
+ html += '<div class="weatherCity">'+ feed.location.city +'</div>';
+ html += '<div class="weatherTemp">'+ feed.item.condition.temp +'°</div>';
+ html += '<div class="weatherDesc">'+ feed.item.condition.text +'</div>';
+ if (options.highlow) html += '<div class="weatherRange">High: '+ wf.high +'° Low: '+ wf.low +'°</div>';
+ if (options.wind) html += '<div class="weatherWind">Wind: '+ wd +' '+ feed.wind.speed + feed.units.speed +'</div>';
+ if (options.link) html += '<div class="weatherLink"><a href="'+ feed.item.link +'">Read full forecast</a></div>';
+
+ html += '</div>';
+
+ // Alternate row classes
+ if (row == 'odd') { row = 'even'; } else { row = 'odd'; }
+
+ $e.append(html);
+ };
+
+ // Get time string as date
+ var _getTimeAsDate = function(t) {
+
+ d = new Date();
+ r = new Date(d.toDateString() +' '+ t);
+
+ return r;
+ };
+})(jQuery);
Added: CometVisu/trunk/visu/plugins/zweather/zweatherfeed/jquery.zweatherfeed.min.js
===================================================================
--- CometVisu/trunk/visu/plugins/zweather/zweatherfeed/jquery.zweatherfeed.min.js (rev 0)
+++ CometVisu/trunk/visu/plugins/zweather/zweatherfeed/jquery.zweatherfeed.min.js 2011-07-06 19:45:58 UTC (rev 383)
@@ -0,0 +1,6 @@
+
+(function($){var row='odd';$.fn.weatherfeed=function(locations,options){var defaults={unit:'c',image:true,highlow:true,wind:true,link:true,showerror:true};var options=$.extend(defaults,options);return this.each(function(i,e){var $e=$(e);if(!$e.hasClass('weatherFeed'))$e.addClass('weatherFeed');if(!$.isArray(locations))return false;var count=locations.length;if(count>10)count=10;var locationid='';for(var i=0;i<count;i++){if(locationid!='')locationid+=',';locationid+="'"+locations[i]+"'";}
+now=new Date()
+var query="select * from weather.forecast where location in ("+locationid+") and u='"+options.unit+"'";var api='http://query.yahooapis.com/v1/public/yql?q='+encodeURIComponent(query)+'&rnd='+now.getFullYear()+now.getMonth()+now.getDay()+now.getHours()+'&format=json&callback=?';$.ajax({type:'GET',url:api,dataType:'json',success:function(data){if(data.query){if(data.query.results.channel.length>0){var result=data.query.results.channel.length;for(var i=0;i<result;i++){_callback(e,data.query.results.channel[i],options);}}else{_callback(e,data.query.results.channel,options);}}else{if(options.showerror)$e.html('<p>Weather information unavailable</p>');}},error:function(data){if(options.showerror)$e.html('<p>Weather request failed</p>');}});});};var _callback=function(e,feed,options){var $e=$(e);var wd=feed.wind.direction;if(wd>=348.75&&wd<=360){wd="N"};if(wd>=0&&wd<11.25){wd="N"};if(wd>=11.25&&wd<33.75){wd="NNE"};if(wd>=33.75&&wd<56.25){wd="NE"};if(wd>=56.25&&wd<78.75){wd="ENE"};if(wd>=78.75&&wd<101.25){wd="E"};if(wd>=101.25&&wd<123.75){wd="ESE"};if(wd>=123.75&&wd<146.25){wd="SE"};if(wd>=146.25&&wd<168.75){wd="SSE"};if(wd>=168.75&&wd<191.25){wd="S"};if(wd>=191.25&&wd<213.75){wd="SSW"};if(wd>=213.75&&wd<236.25){wd="SW"};if(wd>=236.25&&wd<258.75){wd="WSW"};if(wd>=258.75&&wd<281.25){wd="W"};if(wd>=281.25&&wd<303.75){wd="WNW"};if(wd>=303.75&&wd<326.25){wd="NW"};if(wd>=326.25&&wd<348.75){wd="NNW"};var wf=feed.item.forecast[0];wpd=feed.item.pubDate;n=wpd.indexOf(":");tpb=_getTimeAsDate(wpd.substr(n-2,8));tsr=_getTimeAsDate(feed.astronomy.sunrise);tss=_getTimeAsDate(feed.astronomy.sunset);if(tpb>tsr&&tpb<tss){daynight='d';}else{daynight='n';}
+var html='<div class="weatherItem '+row+'"';if(options.image)html+=' style="background-image: url(http://l.yimg.com/a/i/us/nws/weather/gr/'+feed.item.condition.code+daynight+'.png); background-repeat: no-repeat;"';html+='>';html+='<div class="weatherCity">'+feed.location.city+'</div>';html+='<div class="weatherTemp">'+feed.item.condition.temp+'°</div>';html+='<div class="weatherDesc">'+feed.item.condition.text+'</div>';if(options.highlow)html+='<div class="weatherRange">High: '+wf.high+'° Low: '+wf.low+'°</div>';if(options.wind)html+='<div class="weatherWind">Wind: '+wd+' '+feed.wind.speed+feed.units.speed+'</div>';if(options.link)html+='<div class="weatherLink"><a href="'+feed.item.link+'">Read full forecast</a></div>';html+='</div>';if(row=='odd'){row='even';}else{row='odd';}
+$e.append(html);};var _getTimeAsDate=function(t){d=new Date();r=new Date(d.toDateString()+' '+t);return r;};})(jQuery);
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|