7z' [;a $ 6|P
/*!
* jSignage.Weather
* http://www.spinetix.com/
* Copyright 2015, SpinetiX S.A.
* Released under the GPL Version 2 or later license.
* $Date: 2015-10-01 22:47:26 +0200 (Thu, 01 Oct 2015) $
* $Revision: 26919 $
*/
( function () {
var version = new String( "1.0.0" );
version.major = 1;
version.minor = 0;
version.revision = 0;
function getOptionsSrcFromUriArray( base, uri, data ) {
var results = [];
for ( var i=0; i v2[i] ){
return 1;
}
}
return 0;
}
function getConfig( args, src ) {
var config;
if ( args.target === 'today' ){
config = $.extend(true, {}, src.daily );
args.cnt = 2;
config.parser.push( {
startDate: "this day",
endDate: "this day",
src: "date",
test: "range",
type: "filterDate"
});
} else if ( args.target === 'tomorrow' ){
config = $.extend(true, {}, src.daily );
args.cnt = 3;
config.parser.push( {
startDate: "+1 day",
endDate: "+1 day",
src: "date",
test: "range",
type: "filterDate"
});
} else {
config = $.extend(true, {},src[args.target] );
}
return config;
}
jSignage.Weather = {
version: version,
iconsNames: [
"sunny", "cloudy_rain1", "cloudy_rain2", "cloudy_rain3", "rain1", "rain2", "rain3", "mist", "cloudy1", "cloudy2", "cloudy3", "snow", "storm", "thunderstorm", "tornado", "windy"
],
options : {
iconSrc: "http://download.spinetix.com/content/widgets/icons/weather/"
},
extendOptionsFromUri: function ( options ){
var uri = document.documentURI || window.location && window.location.href || document.location && document.location.href;
return $.extend( options, jSignage.decodeURIQueryString( uri ) );
},
getAndParseFeedArray: function( feeds, callback, useGetURL ) {
var cnt;
var results = [];
var addResult = function( idx, data, rt ){
if ( jSignage.isArray( data ) && data.length === 1){
results[idx] = data[0];
} else {
results[idx] = data;
}
cnt--;
if ( cnt === 0 ){
callback( results, rt );
cnt = results.length;
}
};
var process = function( idx, feed ){
jSignage.getAndParseFeed( feed, function( data, rt ) {
addResult( idx, data, rt );
}, useGetURL );
};
if ( jSignage.isArray( feeds ) ){
cnt = feeds.length;
for ( var i=0; i= 0) {
addParser( config, {
inline: "alert(text + ' => ' + rowData.rain); if ( text == '10d' && rowData.rain < 1 ) { if ( rowData.clouds > 0 ) return '02d'; else return '01d'; } else { return text; };",
src: "icon",
type: "custom"
} );
}
*/
var argsProps = ['refresh', 'syncVariable'];
var configProps = ['fallbacks', 'parser'];
var dataSource = {};
jSignage.copyProps( args, dataSource, argsProps );
jSignage.copyProps( config, dataSource, configProps );
dataSource.type = 'uri';
var src = config.baseSrc;
if ( args.units && ( args.units === "imperial" || args.units === "F" || args.units === "f" || args.units === "Fahrenheit" ) ) {
src += "units=imperial";
} else {
src += "units=metric";
}
if ( args.cnt ) {
src += "&cnt=" + args.cnt;
}
if ( args.locale ) {
src += "&lang=" + args.locale.trim();
}
if ( args.apiid ) {
src += "&APPID=" + args.apiid;
}
var item;
if ( args.locations ){
src += "&q=[[i]]";
item = args.locations;
} else if ( args.id ){
src += "&id=[[i]]";
item = args.id;
} else if ( args.lat && args.lon ){
src += "&lat=" + args.lat + "&lon=" + args.lon;
dataSource.src = src + item.trim();
return dataSource;
} else if ( args.zip ){
src += "&zip=[[i]]";
item = args.zip;
} else {
throw Error('Must specify a location, using either "locations", "id", "lat, lon" or "zip"');
}
if ( !jSignage.isArray( item ) && item.search(";") !== -1 ){
item = item.split(";");
}
if ( jSignage.isArray( item ) ){
return getOptionsSrcFromUriArray( dataSource, src, item );
} else {
dataSource.src = src.replace( "[[i]]", encodeURIComponent(item.trim())) ;
return dataSource;
}
},
current : {
fallbacks: {
clouds: 0,
rain: 0,
snow: 0
},
parser: [
{
columns: [
{ name: "id", property: "weather.0.id" },
{ name: "main", property: "weather.0.main" },
{ name: "description", property: "weather.0.description" },
{ name: "temp", property: "main.temp" },
{ name: "pressure", property: "main.pressure" },
{ name: "humidity", property: "main.humidity" },
{ name: "temp_min", property: "main.temp_min" },
{ name: "temp_max", property: "main.temp_max" },
{ name: "wind_speed", property: "wind.speed" },
{ name: "wind_deg", property: "wind.deg" },
{ name: "clouds", property: "clouds.all" },
{ name: "rain", property: "rain.3h" },
{ name: "snow", property: "snow.3h" },
{ name: "date", property: "dt" },
{ name: "country", property: "sys.country" },
{ name: "sunrise", property: "sys.sunrise" },
{ name: "sunset", property: "sys.sunset" },
{ name: "name", property: "name" }
],
rows: "",
type: "json"
},
{ format: "unix", src: "date", type: "date" },
{ format: "unix", src: "sunrise", type: "date" },
{ format: "unix", src: "sunset", type: "date" }
],
baseSrc: "http://api.openweathermap.org/data/2.5/weather?"
},
daily : {
fallbacks: {
clouds: 0,
rain: 0,
snow: 0
},
parser: [
{
columns: [
{ name: "country", property: "city.country" },
{ name: "name", property: "city.name" },
{ name: "id", property: "list" }
],
rows: "",
type: "json"
},
{
columns: [
{ name: "date", property: "dt" },
{ name: "temp", property: "temp.day" },
{ name: "temp_min", property: "temp.min" },
{ name: "temp_max", property: "temp.max" },
{ name: "temp_night", property: "temp.night" },
{ name: "temp_day", property: "temp.day" },
{ name: "pressure", property: "pressure" },
{ name: "humidity", property: "humidity" },
{ name: "id", property: "weather.0.id" },
{ name: "main", property: "weather.0.main" },
{ name: "description", property: "weather.0.description" },
{ name: "wind_deg", property: "deg" },
{ name: "wind_speed", property: "speed" },
{ name: "clouds", property: "clouds" },
{ name: "rain", property: "rain" },
{ name: "snow", property: "snow" }
],
src: "id",
rows: "",
type: "json"
},
{ format: "unix", src: "date", type: "date" }
],
baseSrc: "http://api.openweathermap.org/data/2.5/forecast/daily?"
},
hourly : {
fallbacks: {
clouds: 0,
rain: 0,
snow: 0
},
parser: [
{
columns: [
{ name: "country", property: "city.country" },
{ name: "name", property: "city.name" },
{ name: "id", property: "list" }
],
rows: "",
type: "json"
},
{
columns: [
{ name: "date", property: "dt" },
{ name: "temp", property: "main.temp" },
{ name: "temp_max", property: "main.temp_max" },
{ name: "temp_min", property: "main.temp_min" },
{ name: "pressure", property: "main.pressure" },
{ name: "humidity", property: "main.humidity" },
{ name: "id", property: "weather.0.id" },
{ name: "main", property: "weather.0.main" },
{ name: "description", property: "weather.0.description" },
{ name: "clouds", property: "clouds.all" },
{ name: "wind_speed", property: ".wind.speed" },
{ name: "wind_deg", property: "wind.deg" },
{ name: "rain", property: "rain.3h" },
{ name: "snow", property: "snow.3h" }
],
src: "id",
rows: "",
type: "json"
},
{ format: "unix", src: "date", type: "date" }
],
baseSrc: "http://api.openweathermap.org/data/2.5/forecast?"
}
};
jSignage.Weather.yahooweather = {
getOptions: function ( args ) {
var config = getConfig( args, jSignage.Weather.yahooweather );
// fix for trhe case of rain icon with no rain
addParser( config, {
inline: function( id, rowData ) {
if ( id < 3 ) return {icon: "tornado"};
if ( id < 5 ) return {icon: "thunderstorm"};
if ( id == 11 || id == 12 || id == 40 ) return {icon: "cloudy_rain3"};
if ( id < 19 || id == 41 || id == 42 || id == 43 || id == 46 ) return {icon: "snow"};
if ( id < 26 ) return {icon: "mist"};
if ( id == 26 ) return {icon: "cloudy3"};
if ( id == 27 || id == 28 ) return {icon: "cloudy2"};
if ( id == 29 || id == 30 || id == 44 ) return {icon: "cloudy1"};
if ( id == 31 || id == 32 || id == 36 ) return {icon: "sunny"};
if ( id == 33 || id == 34 ) return {icon: "cloudy_rain1"};
if ( id == 35 ) return {icon: "rain3"};
if ( id < 40 || id == 45 || id == 47) return {icon: "thunderstorm"};
if ( id == 44 ) return {icon: "cloudy1"};
return {icon: "cloudy_rain2"};
},
src: "id",
type: "custom"
} );
var argsProps = ['refresh', 'syncVariable'];
var configProps = ['fallbacks', 'parser'];
var dataSource = {};
jSignage.copyProps( args, dataSource, argsProps );
jSignage.copyProps( config, dataSource, configProps );
dataSource.type = 'uri';
var base = "https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20weather.forecast%20where";
var cityfind = "select%20woeid%20from%20geo.places%281%29%20where%28[[i]]%29";
var city = "text%3D%22[[i]]%22";
var woeid = "%20woeid%20in%20%28[[i]]%29";
var unit = "%20and%20u%3D%22[[i]]%22";
var option ="&format=json";
if ( args.units && ( args.units === "imperial" || args.units === "F" || args.units === "f" || args.units === "Fahrenheit" ) ) {
unit = unit.replace("[[i]]", "f");
} else {
unit = unit.replace("[[i]]", "c");
}
var item;
if ( args.locations ){
item = args.locations;
if ( args.target !== 'daily' ){
if ( !jSignage.isArray( item ) && item.search(";") !== -1 ){
item = item.split(";");
}
if ( jSignage.isArray( item ) ){
var str = "";
for ( var i=0; i