Skip to content

Commit 21d6df1

Browse files
committed
Merge pull request #13 from molecularbear/smart-countdown
Add countdownSmart option
2 parents e665618 + 5c8b321 commit 21d6df1

File tree

3 files changed

+26
-5
lines changed

3 files changed

+26
-5
lines changed

README.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,13 +136,22 @@ Default: `false`
136136

137137
If `true`, this will launch the Bootstrap warning dialog / redirect (or callback functions) in a set amounts of time regardless of user activity. This in turn makes the plugin act much like the [jquery-sessionTimeout-bootstrap by maxfierke](https://github.com/maxfierke/jquery-sessionTimeout-bootstrap) plugin.
138138

139+
**countdownSmart**
140+
141+
Type: `Boolean`
142+
143+
Default: `false`
144+
145+
If `true`, displays minutes as well as seconds in the countdown timer (e.g. "3m 14s").
146+
Displays only seconds when timer is under one minute (e.g. "42s").
147+
139148
**countdownMessage**
140149

141150
Type: `String` or `Boolean`
142151

143152
Default: `false`
144153

145-
If you want a custom sentence to appear in the warning dialog with a timer showing the seconds remaining, use this option. Example: `countdownMessage: 'Redirecting in {timer} seconds.'` Place the `{timer}` string where you want the numeric countdown (seconds) to appear. Another example: `countdownMessage: '{timer} seconds remaining.'`. Can be combined with countdownBar option or used independently.
154+
If you want a custom sentence to appear in the warning dialog with a timer showing the seconds remaining, use this option. Example: `countdownMessage: 'Redirecting in {timer}.'` Place the `{timer}` string where you want the numeric countdown to appear. Another example: `countdownMessage: '{timer} remaining.'`. Can be combined with countdownBar option or used independently.
146155

147156
**countdownBar**
148157

dist/bootstrap-session-timeout.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
onWarn: false,
3030
onRedir: false,
3131
countdownMessage: false,
32-
countdownBar: false
32+
countdownBar: false,
33+
countdownSmart: false
3334
};
3435

3536
var opt = defaults,
@@ -55,7 +56,7 @@
5556
var coundownBarHtml = opt.countdownBar ?
5657
'<div class="progress"> \
5758
<div class="progress-bar progress-bar-striped countdown-bar active" role="progressbar" style="min-width: 15px; width: 100%;"> \
58-
<span class="countdown-holder"></span><span>s</span> \
59+
<span class="countdown-holder"></span> \
5960
</div> \
6061
</div>' : '';
6162

@@ -196,7 +197,18 @@
196197
countdown.percentLeft = Math.floor(countdown.timeLeft / (opt.redirAfter / 1000) * 100);
197198
}
198199
// Set countdown message time value
199-
$('.countdown-holder').text(countdown.timeLeft);
200+
var countdownEl = $('.countdown-holder');
201+
var secondsLeft = countdown.timeLeft >= 0 ? countdown.timeLeft : 0;
202+
if (opt.countdownSmart) {
203+
var minLeft = Math.floor(secondsLeft / 60);
204+
var secRemain = secondsLeft % 60;
205+
var countTxt = minLeft > 0 ? minLeft + 'm' : '';
206+
if (countTxt.length > 0) { countTxt += ' '; }
207+
countTxt += secRemain + 's';
208+
countdownEl.text(countTxt);
209+
} else {
210+
countdownEl.text(secondsLeft + "s");
211+
}
200212

201213
// Set countdown message time value
202214
if (opt.countdownBar) {

dist/bootstrap-session-timeout.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)