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

Essential update: return the element on events and fix arrow position and added center alingment #143

Open
wants to merge 3 commits into
base: gh-pages
Choose a base branch
from
Open
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: 18 additions & 12 deletions src/clockpicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -352,12 +352,12 @@
this.canvas = canvas;
}

raiseCallback(this.options.init);
raiseCallback(this.element, this.options.init);
}

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

Expand All @@ -367,7 +367,7 @@
fromnow: 0, // set default time to * milliseconds from now (using with default = 'now')
placement: 'bottom', // clock popover placement
align: 'left', // popover arrow align
donetext: '完成', // done button text
donetext: 'Done', // done button text
autoclose: false, // auto close when minute is selected
twelvehour: false, // change to 12 hour AM/PM clock from 24 hour
vibrate: true // vibrate the device when dragging clock hand
Expand All @@ -382,6 +382,7 @@
ClockPicker.prototype.locate = function(){
var element = this.element,
popover = this.popover,
arrow = this.popover.find('.arrow'),
offset = element.offset(),
width = element.outerWidth(),
height = element.outerHeight(),
Expand Down Expand Up @@ -410,11 +411,16 @@

// Align the popover arrow
switch (align) {
case 'center':
styles.left = offset.left - ((popover.outerWidth() - element.outerWidth())/2);
break;
case 'left':
styles.left = offset.left;
arrow.style.left = '10%';
break;
case 'right':
styles.left = offset.left + width - popover.outerWidth();
arrow.style.left = '90%';
break;
case 'top':
styles.top = offset.top;
Expand All @@ -434,7 +440,7 @@
return;
}

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

var self = this;

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

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

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

this.isShown = false;

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

this.popover.hide();

raiseCallback(this.options.afterHide);
raiseCallback(this.element, 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);
raiseCallback(this.element, this.options.beforeHourSelect);
raiseAfterHourSelect = true;
}
var isHours = view === 'hours',
Expand All @@ -540,7 +546,7 @@
}, duration);

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

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

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

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

// Remove clockpicker from input
Expand Down