Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Day and Night skinning #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions coolclock.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ CoolClock.prototype = {
// Parse and store the options
this.canvasId = options.canvasId;
this.skinId = options.skinId || CoolClock.config.defaultSkin;
// If there is a corresponding nightskin, use that, otherwise just use the reagular skin.
if(CoolClock.config.skins[this.skinId+'Night'] != null) this.skinIdNight = this.skinId+'Night';
else this.skinId_night = this.skinId;
// Variable to keep track of the dayskin when the skin switches to Nightskin
this.skinIdDay = this.skinId;
this.displayRadius = options.displayRadius || CoolClock.config.defaultRadius;
this.showSecondHand = typeof options.showSecondHand == "boolean" ? options.showSecondHand : true;
this.gmtOffset = (options.gmtOffset != null && options.gmtOffset != '') ? parseFloat(options.gmtOffset) : null;
Expand Down Expand Up @@ -216,6 +221,12 @@ CoolClock.prototype = {
},

render: function(hour,min,sec) {
//Detect day/night and set appropriate skin.
if(hour >= 18 || hour < 6) {
this.skinId = this.skinIdNight;
} else {
this.skinId = this.skinIdDay;
}
// Get the skin
var skin = CoolClock.config.skins[this.skinId];
if (!skin) skin = CoolClock.config.skins[CoolClock.config.defaultSkin];
Expand Down
Binary file added demos/clock_bg.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 35 additions & 0 deletions demos/demo3.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<html>
<head>
<title>Day/Night Coolclock</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js" type="text/javascript"></script>
<!--[if IE]><script type="text/javascript" src="excanvas.js"></script><![endif]-->
<script src="../coolclock.js" type="text/javascript"></script>
<script src="../moreskins.js" type="text/javascript"></script>
</head>
<body>
<table border="0" align="center">
<tr>
<td align="center" style="background: transparent url('clock_bg.png') no-repeat; padding: 4px;"><canvas id="NewYorkTime" class="CoolClock:Knight:20::-5"></canvas></td>
<td>&nbsp;&nbsp;&nbsp;</td>
<td align="center" style="background: transparent url('clock_bg.png') no-repeat; padding: 4px;"><canvas id="LondonTime" class="CoolClock:Knight:20::0"></canvas></td>
<td>&nbsp;&nbsp;&nbsp;</td>
<td align="center" style="background: transparent url('clock_bg.png') no-repeat; padding: 4px;"><canvas id="NewDelhiTime" class="CoolClock:Knight:20::+5.5"></canvas></td>
<td>&nbsp;&nbsp;&nbsp;</td>
<td align="center" style="background: transparent url('clock_bg.png') no-repeat; padding: 4px;"><canvas id="TokyoTime" class="CoolClock:Knight:20::+9"></canvas></td>
</tr>
<tr style="font-size: 10px">
<td align="center">New York</td>
<td>&nbsp;&nbsp;&nbsp;</td>
<td align="center">London</td>
<td>&nbsp;&nbsp;&nbsp;</td>
<td align="center">New Delhi</td>
<td>&nbsp;&nbsp;&nbsp;</td>
<td align="center">Tokyo</td>
</tr>
</table>
<hr style="border: 0px; border-bottom: 1px dotted rgb(201, 201, 201);" />
<script type="text/javascript">
CoolClock.findAndCreateClocks();
</script>
</body>
</html>
20 changes: 20 additions & 0 deletions moreskins.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,5 +208,25 @@ CoolClock.config.skins = {
minuteHand: { lineWidth: 2, startAt: -20, endAt: 80, color: "#7c8c03", alpha: .9 },
secondHand: { lineWidth: 2, startAt: 70, endAt: 94, color: "#d93d04", alpha: .85 },
secondDecoration: { lineWidth: 1, startAt: 70, radius: 3, fillColor: "red", color: "black", alpha: .7 }
},

Knight: {
outerBorder: { lineWidth: 99, radius: 50, color: "white", alpha: 0.4 },
smallIndicator: { lineWidth: 2, startAt: 88, endAt: 92, color: "black", alpha: 0 },
largeIndicator: { lineWidth: 8, startAt: 80, endAt: 92, color: "black", alpha: 1 },
hourHand: { lineWidth: 12, startAt: -15, endAt: 50, color: "black", alpha: 1 },
minuteHand: { lineWidth: 10, startAt: -15, endAt: 75, color: "black", alpha: 1 },
secondHand: { lineWidth: 4, startAt: -20, endAt: 85, color: "red", alpha: 1 },
secondDecoration: { lineWidth: 2, startAt: 70, radius: 4, fillColor: "red", color: "red", alpha: 0 }
},

KnightNight: {
outerBorder: { lineWidth: 99, radius: 50, color: "black", alpha: 0.6 },
smallIndicator: { lineWidth: 2, startAt: 88, endAt: 92, color: "white", alpha: 0 },
largeIndicator: { lineWidth: 8, startAt: 80, endAt: 92, color: "white", alpha: 1 },
hourHand: { lineWidth: 12, startAt: -15, endAt: 50, color: "white", alpha: 1 },
minuteHand: { lineWidth: 10, startAt: -15, endAt: 75, color: "white", alpha: 1 },
secondHand: { lineWidth: 4, startAt: -20, endAt: 85, color: "red", alpha: 1 },
secondDecoration: { lineWidth: 2, startAt: 70, radius: 4, fillColor: "red", color: "red", alpha: 0 }
}
};