Skip to content

Option to change the default div #36

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

Merged
merged 3 commits into from
Oct 30, 2018
Merged
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules
*.swp
.idea
21 changes: 21 additions & 0 deletions examples/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,24 @@ <h3>Examples</h3>
<div class="timer-pause" data-minutes-left="1.5"></div>
</p>
</li>

<li>
<p><strong>timer structured elements span</strong></p>
<p><pre><code>
// HTML
&lt;span class="timer-span" data-minutes-left="5"&gt;&lt;/span&gt;

// JavaScript
$('.timer-span').startTimer({
elementContainer: "span"
});
</code></pre>
<span class="timer-span" data-seconds-left="5"></span>
</li>
</ul>
<br/>
<br/>
<br/>
<style>
.jst-hours {
float: left;
Expand All @@ -103,6 +120,10 @@ <h3>Examples</h3>

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

$('.timer-span').startTimer({
elementContainer: "span"
});

$('.timer').startTimer({
onComplete: function(){
console.log('Complete');
Expand Down
20 changes: 12 additions & 8 deletions jquery.simple.timer.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@
// pass this object as argument multiple times.
function mergeOptions(timer, opts) {
opts = opts || {};

// Element that will be created for hours, minutes, and seconds.
timer._options.elementContainer = opts.elementContainer || 'div';

var classNames = opts.classNames || {};

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

var that = this;

var createSubDivs = function(timerBoxElement){
var seconds = document.createElement('div');
var createSubElements = function(timerBoxElement){
var seconds = document.createElement(that._options.elementContainer);
seconds.className = that._options.classNameSeconds;

var minutes = document.createElement('div');
var minutes = document.createElement(that._options.elementContainer);
minutes.className = that._options.classNameMinutes;

var hours = document.createElement('div');
var hours = document.createElement(that._options.elementContainer);
hours.className = that._options.classNameHours;

var clearDiv = document.createElement('div');
clearDiv.className = that._options.classNameClearDiv;
var clearElement = document.createElement(that._options.elementContainer);
clearElement.className = that._options.classNameClearDiv;

return timerBoxElement.
append(hours).
append(minutes).
append(seconds).
append(clearDiv);
append(clearElement);
};

this.targetElement.each(function(_index, timerBox) {
Expand Down Expand Up @@ -119,7 +123,7 @@
that.startCountdown(timerBoxElement, { secondsLeft: timerBoxElement.data('timeLeft') });
});

createSubDivs(timerBoxElement);
createSubElements(timerBoxElement);
return this.startCountdown(timerBoxElement, options);
}.bind(this));
};
Expand Down