GithubHelp home page GithubHelp logo

imclab / open-weather Goto Github PK

View Code? Open in Web Editor NEW

This project forked from michael-lynch/open-weather

0.0 2.0 0.0 340 KB

A simple, lightweight jQuery plugin used to display the current weather of any city using the free OpenWeatherMap API.

License: MIT License

CSS 3.65% JavaScript 96.35%

open-weather's Introduction

#Open Weather

A simple, lightweight jQuery plugin used to display the current weather of any city using the free OpenWeatherMap API.

This plugin allows you to display the location, the current temperature, the current low temperature, the current high temperature, a description of the current weather, a weather icon, the humidity level, the wind speed, the time the sun will rise, and the time the sun will set.

An API key is not required but it is reccomended. Register here to obtain an OpenWeatherMap API key for your application.

See demo

##Instructions

Include jQuery and the plugin in the head or footer of your page.

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
    
<script src="/js/plugins/openWeather.js"></script>

The only default output is the current temperature.

To display the current temperature, create an element on your page where the current temperature will be displayed.

<div class="weather-temperature"></div>

Initialize the plugin targeting the class, ID or element that you've created with either the 'city' option or 'lat' and 'lng' options set.

$('.weather-temperature').openWeather({
	city: 'Toronto,ON'
});

OR

$('.weather-temperature').openWeather({
	lat: 30,
	lng: 25
});

##Custom Icons

The OpenWeatherMap API returns their own set of icons, however, if you don't want to use them, the plugin also allows you to use 6 custom icons for both day and night, so 12 in total. Custom icons must be named as follows:

    <p>clear.png</p>
    
    <p>clouds.png</p>
    
    <p>rain.png</p>
    
    <p>snow.png</p>
    
    <p>storm.png</p>
    
    <p>mist.png</p>
    

To use custom icons create a directory where the icons will live and inside of that directory create two more directories, "day" and "night."

/img/icons/weather/day/
/img/icons/weather/night/

Place your custom icons inside the "day" and "night" directories and initialize the plugin using the customIcons option.

$('.weather-temperature').openWeather({
	city: 'Toronto,ON',
	customIcons: '/img/icons/weather/'
});

* Note that if you are using custom icons you must include all 12 images.

####Options

key: integer
A string that defines the OpenWeatherMap API key for your application (default: null).

lang: string
A string that defines the language (default: 'en').
(English - en, Russian - ru, Italian - it, Spanish - sp, Ukrainian - ua, German - de, Portuguese - pt, Romanian - ro, Polish - pl, Finnish - fi, Dutch - nl, French - fr, Bulgarian - bg, Swedish - se, Chinese Traditional - zh_tw, Chinese Simplified - zh_cn, Turkish - tr)

city: "city name, country / province/ state"
A string that defines the city (default: null).

lat: integer
An integer that defines the latitude (default: null).

lng: integer
An integer that defines the longitude (default: null).

placeTarget: "id / class / element"
A string that defines the ID, class or element that will contain the location name (default: null).

units: "c / f"
A string that defines the type of units (default: 'c').

descriptionTarget: "id / class / element"
A string that defines the ID, class or element that will contain the weather description (default: null).

minTemperatureTarget: "id / class / element"
A string that defines the ID, class or element that will contain the minimum temperature (default: null).

maxTemperatureTarget: "id / class / element"
A string that defines the ID, class or element that will contain the maximum temperature (default: null).

windSpeedTarget: "id / class / element"
A string that defines the ID, class or element that will contain the wind speed (default: null).

humidityTarget: "id / class / element"
A string that defines the ID, class or element that will contain the humidity (default: null).

sunriseTarget: "id / class / element"
A string that defines the ID, class or element that will contain the time of sunrise (default: null).

sunsetTarget: "id / class / element"
A string that defines the ID, class or element that will contain the time of sunset (default: null).

iconTarget: "id / class / element"
A string that defines the ID, class or element that will contain the icon image (default: null).

customIcons: "path"
A string that defines the path to the custom icons (default: null).

success: function() {}
A function that runs after the plugin has successfully retrieved weather data. (default: function()).

error: function() {}
A function that runs if there was an error retrieving weather data. (default: function(message)).

#####Example:

$(function() {

	$('.weather-temperature').openWeather({
		lang: 'ru',
		city: 'Toronto, ON',
		placeTarget: '.weather-place',
		units: 'f',
		descriptionTarget: '.weather-description',
		minTemperatureTarget: '.weather-min-temperature',
		maxTemperatureTarget: '.weather-max-temperature',
		windSpeedTarget: '.weather-wind-speed',
		humidityTarget: '.weather-humidity',
		sunriseTarget: '.weather-sunrise',
		sunsetTarget: '.weather-sunset',
		iconTarget: '.weather-icon',
		customIcons: '/img/icons/weather/',
		success: function() {
			$('.weather-temperature').show();
		},
		error: function(message) {
			console.log(message);
		}
	});
	
});

open-weather's People

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.