Skip to content
This repository has been archived by the owner on Apr 18, 2020. It is now read-only.

Commit

Permalink
Added the ability to pass strings to add().
Browse files Browse the repository at this point in the history
  • Loading branch information
J. T. L committed Nov 25, 2013
1 parent 8a9ce87 commit 26225ec
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 12 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.DS_Store
25 changes: 13 additions & 12 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ <h1>Skycons</h1>
<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();

Expand All @@ -135,18 +138,16 @@ <h1>Skycons</h1>
<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>
Expand Down
9 changes: 9 additions & 0 deletions skycons.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down

0 comments on commit 26225ec

Please sign in to comment.