Skip to content

Commit

Permalink
Merge pull request #18 from jannicz/feature/mouse-event
Browse files Browse the repository at this point in the history
Add alternative mouseclick event support, resolves #17
  • Loading branch information
jannicz authored Jun 12, 2018
2 parents eec8b73 + 16bf6ad commit fb02cf9
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 6 deletions.
2 changes: 1 addition & 1 deletion css/appointment-picker.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* appointment-picker.css 1.0.6 | MIT License | github.com/jannicz/appointment-picker
* appointment-picker.css 1.0.7 | MIT License | github.com/jannicz/appointment-picker
*/
/* Default variation */
.appo-picker {
Expand Down
2 changes: 1 addition & 1 deletion css/appointment-picker.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* appointment-picker.css 1.0.6 | MIT License | github.com/jannicz/appointment-picker
* appointment-picker.css 1.0.7 | MIT License | github.com/jannicz/appointment-picker
*/

/* Default variation */
Expand Down
15 changes: 13 additions & 2 deletions js/appointment-picker.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Appointment-Picker - a lightweight, accessible and customizable timepicker
*
* @module Appointment-Picker
* @version 1.0.6
* @version 1.0.7
*
* @author Jan Suwart
*/
Expand Down Expand Up @@ -56,6 +56,7 @@
this.displayTime = ''; // '6:30pm'
this.selectionEventFn = _onselect.bind(this);
this.changeEventFn = _onchange.bind(this);
this.clickEventFn = _onInputClick.bind(this);
this.closeEventFn = this.close.bind(this);
this.openEventFn = this.open.bind(this);
this.keyEventFn = _onKeyPress.bind(this);
Expand Down Expand Up @@ -105,6 +106,7 @@
_this.picker.classList.add('is-position-static');
_this.picker.addEventListener('click', _this.selectionEventFn);
_this.isOpen = true;

_this.render();
}
};
Expand Down Expand Up @@ -152,10 +154,12 @@
this.render();
this.picker.addEventListener('click', this.selectionEventFn);
this.picker.addEventListener('keyup', this.keyEventFn);
this.el.removeEventListener('click', this.clickEventFn);

// Delay document click listener to prevent picker flashing
setTimeout(function() {
document.body.addEventListener('click', _this.closeEventFn);
document.body.addEventListener('focus', _this.bodyFocusEventFn, true);
document.body.addEventListener('focus', _this.bodyFocusEventFn, true);
}, 100);
};

Expand Down Expand Up @@ -190,6 +194,8 @@
this.picker.removeEventListener('keyup', this.keyEventFn);
document.body.removeEventListener('click', this.closeEventFn);
document.body.removeEventListener('focus', this.bodyFocusEventFn, true);
// Add an event listener to open on click regardless of mouse focus
this.el.addEventListener('click', this.clickEventFn);
};

/**
Expand Down Expand Up @@ -252,6 +258,11 @@
this.close(e);
};

// If the input has focus, a mouseclick can still open the picker
function _onInputClick(e) {
this.open();
}

// Remove the picker's node from the dom and unregister all events
AppointmentPicker.prototype.destroy = function() {
this.close(null);
Expand Down
2 changes: 1 addition & 1 deletion js/appointment-picker.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "appointment-picker",
"version": "1.0.6",
"version": "1.0.7",
"description": "customizable timepicker to be used with or without jQuery",
"main": "js/appointment-picker.js",
"scripts": {
Expand Down

0 comments on commit fb02cf9

Please sign in to comment.