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

Added a simple in-session bell #2

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
4 changes: 2 additions & 2 deletions css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ a:hover {
animation: click 0.5s ease-in-out 2 alternate;
-webkit-animation: click 0.5s ease-in-out 2 alternate;
}
#time-options {
#time-options, #transition-options {
display: -webkit-flex;
display: flex;
-webkit-flex-direction: row;
Expand All @@ -77,7 +77,7 @@ a:hover {
align-content: stretch;
padding-bottom: 20px;
}
.time-selector-btn {
.time-selector-btn, .transitions-selector-btn {
cursor: pointer;
width: 40px;
color: #2A6496;
Expand Down
21 changes: 20 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,12 @@
<script id="meditationDialog" type="text/html">
<div id="meditation-dialog" style="display: none;">
<div class="meditation-timer">
<p id="meditation-text">{{duration}} minute meditation</p>
<p id="meditation-text">
</p>
<div id="time-options">
</div>
<div id="transition-options">
</div>
<div id="start-button" class="full-btn">Begin</div>
</div>
<div id="about-link">
Expand All @@ -44,6 +47,22 @@
<div id="time-button-{{value}}" class="time-selector-btn">{{value}}</div>
{{/timeIntervals}}
</script>
<script id="transitionOptionButtons" type="text/html">
{{#nbOfTransitions}}
<div id="nb-of-transitions-button-{{value}}" class="transitions-selector-btn">{{value}}</div>
{{/nbOfTransitions}}
</script>
<script id="meditationText" type="text/html">
<span id="meditation-text-duration"></span>
<br>
<span id="meditation-text-transitions"></span>
</script>
<script id="meditationTextDuration" type="text/html">
{{duration}} minute meditation
</script>
<script id="meditationTextTransitions" type="text/html">
{{nbOfTransitions}} transition{{plural}}
</script>
<script src="js/jquery-2.1.1.min.js"></script>
<script src="js/ICanHaz.min.js"></script>
<script src="js/index.js"></script>
Expand Down
38 changes: 34 additions & 4 deletions js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,25 @@ $(function() {
if ($.inArray(selectedTimeInterval, timeIntervals) < 0) {
selectedTimeInterval = 20;
}
var nbOfTransitions = [0, 1, 2, 3, 4, 5];
var selectedNbOfTransitions = parseInt(window.localStorage.defaultNbOfTransitions);
if ($.inArray(selectedNbOfTransitions, nbOfTransitions) < 0) {
selectedNbOfTransitions = 0;
}
var meditationProgressTimer = null;
var lock = null;

$("#content").html(ich.meditationDialog({ 'duration': selectedTimeInterval }));
$("#content").html(ich.meditationDialog());
$("#meditation-dialog").fadeIn('fast');
$("#meditation-text").html(ich.meditationText());

$("#time-options").append(ich.timeOptionButtons({'timeIntervals': timeIntervals.map(function v(val) { return { "value": val } }) }));
$("#transition-options").append(ich.transitionOptionButtons({'nbOfTransitions': nbOfTransitions.map(function v(val) { return { "value": val } }) }));

function intervalSelected(timeInterval) {
selectedTimeInterval = timeInterval;
window.localStorage.defaultTimeInterval = selectedTimeInterval;
$("#meditation-text").html(timeInterval + " minute meditation");
$("#meditation-text-duration").html(ich.meditationTextDuration({'duration': timeInterval}, true));
$(".time-selector-btn").removeClass('btn-link-selected');
$("#time-button-" + timeInterval).addClass('btn-link-selected');
};
Expand All @@ -31,6 +38,20 @@ $(function() {
});
intervalSelected(selectedTimeInterval);

function nbOfTransitionsSelected(nbOfTransitions) {
selectedNbOfTransitions = nbOfTransitions;
window.localStorage.defaultNbOfTransitions = nbOfTransitions;
$("#meditation-text-transitions").html(ich.meditationTextTransitions({'nbOfTransitions': nbOfTransitions, 'plural': (nbOfTransitions>1?'s':'')}, true));
$(".transitions-selector-btn").removeClass('btn-link-selected');
$("#nb-of-transitions-button-" + selectedNbOfTransitions).addClass('btn-link-selected');
};
nbOfTransitions.forEach(function(nbOfTransitions) {
$("#nb-of-transitions-button-" + nbOfTransitions).click(function() {
nbOfTransitionsSelected(nbOfTransitions);
});
});
nbOfTransitionsSelected(selectedNbOfTransitions);

function reset() {
$("#bell").off();

Expand All @@ -43,6 +64,7 @@ $(function() {
intervalSelected(selectedTimeInterval);
$("#about-link").show();
$("#start-button").html("Begin");
setupTimer();
}

$("#start-button").click(function() {
Expand All @@ -61,6 +83,7 @@ $(function() {
$("#meditation-text").html("Prepare for meditation " +
"<span class='blink'>...</span>");
var startTime = null;
var currentInterval = 1;
meditationProgressTimer = window.setTimeout(function() {
if (!startTime) {
startTime = Date.now();
Expand All @@ -77,10 +100,17 @@ $(function() {
}
return num;
}
$("#meditation-text").html(doubleDigits(minutesRemaining) + ":" +
doubleDigits(secondsRemaining));
if (timeRemaining > 0) {
if ( elapsed > (selectedTimeInterval*60*currentInterval/selectedNbOfTransitions) ) {
currentInterval++;
$("#bell").get(0).currentTime = 0;
$("#bell").get(0).play();
}
meditationProgressTimer = window.setTimeout(timerFired, 1000);
$("#meditation-text").html("Time remaining: " +
doubleDigits(minutesRemaining) + ":" +
doubleDigits(secondsRemaining) + "<br>" +
"Current interval: " + currentInterval);
} else {
// we're done
$("#meditation-text").html("<span class='blink'>00:00</span>");
Expand Down