Skip to content

Commit cbc88a9

Browse files
authored
Merge pull request #36 from alexsilva/master
Add option to set specific HTML element to be created for hours, minutes and seconds.
2 parents 1bc8682 + 7714cb7 commit cbc88a9

File tree

3 files changed

+34
-8
lines changed

3 files changed

+34
-8
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
node_modules
22
*.swp
3+
.idea

examples/index.html

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,24 @@ <h3>Examples</h3>
7878
<div class="timer-pause" data-minutes-left="1.5"></div>
7979
</p>
8080
</li>
81+
82+
<li>
83+
<p><strong>timer structured elements span</strong></p>
84+
<p><pre><code>
85+
// HTML
86+
&lt;span class="timer-span" data-minutes-left="5"&gt;&lt;/span&gt;
87+
88+
// JavaScript
89+
$('.timer-span').startTimer({
90+
elementContainer: "span"
91+
});
92+
</code></pre>
93+
<span class="timer-span" data-seconds-left="5"></span>
94+
</li>
8195
</ul>
96+
<br/>
97+
<br/>
98+
<br/>
8299
<style>
83100
.jst-hours {
84101
float: left;
@@ -103,6 +120,10 @@ <h3>Examples</h3>
103120

104121
$('.timer-quick').startTimer();
105122

123+
$('.timer-span').startTimer({
124+
elementContainer: "span"
125+
});
126+
106127
$('.timer').startTimer({
107128
onComplete: function(){
108129
console.log('Complete');

jquery.simple.timer.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@
5353
// pass this object as argument multiple times.
5454
function mergeOptions(timer, opts) {
5555
opts = opts || {};
56+
57+
// Element that will be created for hours, minutes, and seconds.
58+
timer._options.elementContainer = opts.elementContainer || 'div';
59+
5660
var classNames = opts.classNames || {};
5761

5862
timer._options.classNameSeconds = classNames.seconds || 'jst-seconds'
@@ -66,24 +70,24 @@
6670

6771
var that = this;
6872

69-
var createSubDivs = function(timerBoxElement){
70-
var seconds = document.createElement('div');
73+
var createSubElements = function(timerBoxElement){
74+
var seconds = document.createElement(that._options.elementContainer);
7175
seconds.className = that._options.classNameSeconds;
7276

73-
var minutes = document.createElement('div');
77+
var minutes = document.createElement(that._options.elementContainer);
7478
minutes.className = that._options.classNameMinutes;
7579

76-
var hours = document.createElement('div');
80+
var hours = document.createElement(that._options.elementContainer);
7781
hours.className = that._options.classNameHours;
7882

79-
var clearDiv = document.createElement('div');
80-
clearDiv.className = that._options.classNameClearDiv;
83+
var clearElement = document.createElement(that._options.elementContainer);
84+
clearElement.className = that._options.classNameClearDiv;
8185

8286
return timerBoxElement.
8387
append(hours).
8488
append(minutes).
8589
append(seconds).
86-
append(clearDiv);
90+
append(clearElement);
8791
};
8892

8993
this.targetElement.each(function(_index, timerBox) {
@@ -119,7 +123,7 @@
119123
that.startCountdown(timerBoxElement, { secondsLeft: timerBoxElement.data('timeLeft') });
120124
});
121125

122-
createSubDivs(timerBoxElement);
126+
createSubElements(timerBoxElement);
123127
return this.startCountdown(timerBoxElement, options);
124128
}.bind(this));
125129
};

0 commit comments

Comments
 (0)