Skip to content
This repository has been archived by the owner on Jun 21, 2022. It is now read-only.

Pass the main object (this) to the callbacks #76

Open
wants to merge 1 commit into
base: gh-pages
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
30 changes: 15 additions & 15 deletions dist/bootstrap-clockpicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -352,13 +352,7 @@
this.canvas = canvas;
}

raiseCallback(this.options.init);
}

function raiseCallback(callbackFunction) {
if (callbackFunction && typeof callbackFunction === "function") {
callbackFunction();
}
this.raiseCallback(this.options.init);
}

// Default options
Expand All @@ -373,6 +367,12 @@
vibrate: true // vibrate the device when dragging clock hand
};

ClockPicker.prototype.raiseCallback = function (callbackFunction) {
if (callbackFunction && typeof callbackFunction === "function") {
callbackFunction(this);
}
};

// Show or hide popover
ClockPicker.prototype.toggle = function(){
this[this.isShown ? 'hide' : 'show']();
Expand Down Expand Up @@ -434,7 +434,7 @@
return;
}

raiseCallback(this.options.beforeShow);
this.raiseCallback(this.options.beforeShow);

var self = this;

Expand Down Expand Up @@ -492,12 +492,12 @@
}
});

raiseCallback(this.options.afterShow);
this.raiseCallback(this.options.afterShow);
};

// Hide popover
ClockPicker.prototype.hide = function(){
raiseCallback(this.options.beforeHide);
this.raiseCallback(this.options.beforeHide);

this.isShown = false;

Expand All @@ -507,14 +507,14 @@

this.popover.hide();

raiseCallback(this.options.afterHide);
this.raiseCallback(this.options.afterHide);
};

// Toggle to hours or minutes view
ClockPicker.prototype.toggleView = function(view, delay){
var raiseAfterHourSelect = false;
if (view === 'minutes' && $(this.hoursView).css("visibility") === "visible") {
raiseCallback(this.options.beforeHourSelect);
this.raiseCallback(this.options.beforeHourSelect);
raiseAfterHourSelect = true;
}
var isHours = view === 'hours',
Expand All @@ -540,7 +540,7 @@
}, duration);

if (raiseAfterHourSelect) {
raiseCallback(this.options.afterHourSelect);
this.raiseCallback(this.options.afterHourSelect);
}
};

Expand Down Expand Up @@ -672,7 +672,7 @@

// Hours and minutes are selected
ClockPicker.prototype.done = function() {
raiseCallback(this.options.beforeDone);
this.raiseCallback(this.options.beforeDone);
this.hide();
var last = this.input.prop('value'),
value = leadingZero(this.hours) + ':' + leadingZero(this.minutes);
Expand All @@ -692,7 +692,7 @@
this.input.trigger('blur');
}

raiseCallback(this.options.afterDone);
this.raiseCallback(this.options.afterDone);
};

// Remove clockpicker from input
Expand Down
10 changes: 4 additions & 6 deletions dist/bootstrap-clockpicker.min.js

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions dist/bootstrap-clockpicker.min.js.map

Large diffs are not rendered by default.

36 changes: 21 additions & 15 deletions dist/jquery-clockpicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -352,13 +352,7 @@
this.canvas = canvas;
}

raiseCallback(this.options.init);
}

function raiseCallback(callbackFunction) {
if (callbackFunction && typeof callbackFunction === "function") {
callbackFunction();
}
this.raiseCallback(this.options.init);
}

// Default options
Expand Down Expand Up @@ -434,7 +428,7 @@
return;
}

raiseCallback(this.options.beforeShow);
this.raiseCallback(this.options.beforeShow);

var self = this;

Expand Down Expand Up @@ -492,12 +486,12 @@
}
});

raiseCallback(this.options.afterShow);
this.raiseCallback(this.options.afterShow);
};

// Hide popover
ClockPicker.prototype.hide = function(){
raiseCallback(this.options.beforeHide);
this.raiseCallback(this.options.beforeHide);

this.isShown = false;

Expand All @@ -507,14 +501,14 @@

this.popover.hide();

raiseCallback(this.options.afterHide);
this.raiseCallback(this.options.afterHide);
};

// Toggle to hours or minutes view
ClockPicker.prototype.toggleView = function(view, delay){
var raiseAfterHourSelect = false;
if (view === 'minutes' && $(this.hoursView).css("visibility") === "visible") {
raiseCallback(this.options.beforeHourSelect);
this.raiseCallback(this.options.beforeHourSelect);
raiseAfterHourSelect = true;
}
var isHours = view === 'hours',
Expand All @@ -540,7 +534,7 @@
}, duration);

if (raiseAfterHourSelect) {
raiseCallback(this.options.afterHourSelect);
this.raiseCallback(this.options.afterHourSelect);
}
};

Expand Down Expand Up @@ -672,7 +666,7 @@

// Hours and minutes are selected
ClockPicker.prototype.done = function() {
raiseCallback(this.options.beforeDone);
this.raiseCallback(this.options.beforeDone);
this.hide();
var last = this.input.prop('value'),
value = leadingZero(this.hours) + ':' + leadingZero(this.minutes);
Expand All @@ -692,7 +686,7 @@
this.input.trigger('blur');
}

raiseCallback(this.options.afterDone);
this.raiseCallback(this.options.afterDone);
};

// Remove clockpicker from input
Expand All @@ -709,6 +703,18 @@
}
};

ClockPicker.prototype.raiseCallback = function (callbackFunction) {
if (callbackFunction && typeof callbackFunction === "function") {
callbackFunction(this);
}
}

//function raiseCallback(callbackFunction) {
// if (callbackFunction && typeof callbackFunction === "function") {
// callbackFunction();
// }
//}

// Extends $.fn.clockpicker
$.fn.clockpicker = function(option){
var args = Array.prototype.slice.call(arguments, 1);
Expand Down
10 changes: 4 additions & 6 deletions dist/jquery-clockpicker.min.js

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions dist/jquery-clockpicker.min.js.map

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ <h3>License</h3>

<script type="text/javascript" src="assets/js/jquery.min.js"></script>
<script type="text/javascript" src="assets/js/bootstrap.min.js"></script>
<script type="text/javascript" src="dist/bootstrap-clockpicker.min.js"></script>
<script type="text/javascript" src="dist/bootstrap-clockpicker.js"></script>
<script type="text/javascript">
$('.clockpicker').clockpicker()
.find('input').change(function(){
Expand All @@ -412,8 +412,8 @@ <h3>License</h3>

$('.clockpicker-with-callbacks').clockpicker({
donetext: 'Done',
init: function() {
console.log("colorpicker initiated");
init: function (element) {
console.log(element, "colorpicker initiated");
},
beforeShow: function() {
console.log("before show");
Expand All @@ -436,8 +436,8 @@ <h3>License</h3>
beforeDone: function() {
console.log("before done");
},
afterDone: function() {
console.log("after done");
afterDone: function(element) {
console.log(element, "after done");
}
})
.find('input').change(function(){
Expand Down