Permalink
Browse files

Added the ability to pass strings to add().

  • Loading branch information...
1 parent 8a9ce87 commit 26225ec9e37f2968136fd282ada80bcf13cd05d7 @ironwallaby ironwallaby committed Nov 25, 2013
Showing with 23 additions and 12 deletions.
  1. +1 −0 .gitignore
  2. +13 −12 index.html
  3. +9 −0 skycons.js
View
@@ -0,0 +1 @@
+.DS_Store
View
@@ -110,6 +110,9 @@
<span class="comment">// ...or by the canvas DOM element itself.</span>
skycons.add(document.getElementById(<span class="constant">"icon2"</span>), Skycons.RAIN);
+ <span class="comment">// if you're using the Forecast API, you can also supply
+ strings: "partly-cloudy-day" or "rain".</span>
+
<span class="comment">// start animation!</span>
skycons.play();
@@ -135,18 +138,16 @@
<script src="skycons.js"></script>
<script>
- var icons = new Skycons();
-
- icons.set("clear-day", Skycons.CLEAR_DAY);
- icons.set("clear-night", Skycons.CLEAR_NIGHT);
- icons.set("partly-cloudy-day", Skycons.PARTLY_CLOUDY_DAY);
- icons.set("partly-cloudy-night", Skycons.PARTLY_CLOUDY_NIGHT);
- icons.set("cloudy", Skycons.CLOUDY);
- icons.set("rain", Skycons.RAIN);
- icons.set("sleet", Skycons.SLEET);
- icons.set("snow", Skycons.SNOW);
- icons.set("wind", Skycons.WIND);
- icons.set("fog", Skycons.FOG);
+ var icons = new Skycons(),
+ list = [
+ "clear-day", "clear-night", "partly-cloudy-day",
+ "partly-cloudy-night", "cloudy", "rain", "sleet", "snow", "wind",
+ "fog"
+ ],
+ i;
+
+ for(i = list.length; i--; )
+ icons.set(list[i], list[i]);
icons.play();
</script>
View
@@ -645,6 +645,15 @@
if(el === null)
return;
+ if(typeof draw === "string") {
+ draw = draw.toUpperCase().replace(/-/g, "_");
+ draw = Skycons.hasOwnProperty(draw) ? Skycons[draw] : null;
+ }
+
+ // Does nothing if the draw function isn't actually a function
+ if(typeof draw !== "function")
+ return;
+
obj = {
element: el,
context: el.getContext("2d"),

0 comments on commit 26225ec

Please sign in to comment.