diff --git a/README.md b/README.md index 95fa790d..327c316d 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,9 @@ Timepicker Plugin for jQuery ======================== -[timepicker screenshot](http://jonthornton.github.com/jquery-timepicker) +[timepicker screenshot](https://www.jonthornton.com/jquery-timepicker) -[See a demo and examples here](http://jonthornton.github.com/jquery-timepicker) +[See a demo and examples here](https://www.jonthornton.com/jquery-timepicker) jquery.timepicker is a lightweight timepicker plugin for jQuery inspired by Google Calendar. It supports both mouse and keyboard navigation, and weighs in at 5.5kb minified and gzipped. @@ -288,11 +288,16 @@ Submit a [GitHub Issues request](https://github.com/jonthornton/jquery-timepicke Development guidelines ---------------------- -1. Install dependencies (jquery + grunt) `npm install` -2. For sanity checks and minification run `grunt`, or just `grunt lint` to have the code linted +After cloning, install dev dependencies with `npm install`. + +* `npm run build`: compile timepicker and place updated output in `dist/` +* `npm run watch`: rebuild every time one of the source files changes +* `npm run format`: apply code formatting rules +* `npm run test`: run the jest test suite + jquery-timepicker follows [semantic versioning](http://semver.org/). - - - -This software is made available under the open source MIT License. © 2014 [Jon Thornton](http://www.jonthornton.com) and [contributors](https://github.com/jonthornton/jquery-timepicker/graphs/contributors) +This software is made available under the open source MIT License. © 2020 [Jon Thornton](https://www.jonthornton.com) and [contributors](https://github.com/jonthornton/jquery-timepicker/graphs/contributors) diff --git a/bower.json b/bower.json index 6659df09..32330fef 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "jt.timepicker", - "version": "1.13.4", + "version": "1.13.5", "description": "A jQuery timepicker plugin inspired by Google Calendar.", "homepage": "http://jonthornton.github.com/jquery-timepicker", "main": ["./jquery.timepicker.js", "./jquery.timepicker.css"], diff --git a/dist/jquery.timepicker.js b/dist/jquery.timepicker.js index ee726334..ee2ca099 100644 --- a/dist/jquery.timepicker.js +++ b/dist/jquery.timepicker.js @@ -1,3 +1,8 @@ +/*! + * jquery-timepicker v1.13.5 - A jQuery timepicker plugin inspired by Google Calendar. It supports both mouse and keyboard navigation. + * Copyright (c) 2020 Jon Thornton - https://www.jonthornton.com/jquery-timepicker/ + * License: MIT + */ (function () { 'use strict'; @@ -266,12 +271,6 @@ } } - /*! - * jquery-timepicker v1.13.4 - A jQuery timepicker plugin inspired by Google Calendar. It supports both mouse and keyboard navigation. - * Copyright (c) 2015 Jon Thornton - http://jonthornton.github.com/jquery-timepicker/ - * License: MIT - */ - (function(factory) { if ( typeof exports === "object" && diff --git a/dist/jquery.timepicker.min.js b/dist/jquery.timepicker.min.js index 6f2f82bc..1801dea5 100644 --- a/dist/jquery.timepicker.min.js +++ b/dist/jquery.timepicker.min.js @@ -1,6 +1 @@ -!function(){"use strict";const e=(e,t)=>{if(null===e)return null;if("number"!=typeof t.step)return e;var i=e%(60*t.step);return(i-=(t.minTime||0)%(60*t.step))>=30*t.step?e+=60*t.step-i:e-=i,function(e,t){if(86400==e&&t.show2400)return e;return e%86400}(e,t)};const t={appendTo:"body",className:null,closeOnWindowScroll:!1,disableTextInput:!1,disableTimeRanges:[],disableTouchKeyboard:!1,durationTime:null,forceRoundTime:!1,lang:{},maxTime:null,minTime:null,noneOption:!1,orientation:"l",roundingFunction:e,scrollDefault:null,selectOnBlur:!1,show2400:!1,showDuration:!1,showOn:["click","focus"],showOnFocus:!0,step:30,stopScrollPropagation:!1,timeFormat:"g:ia",typeaheadHighlight:!0,useSelect:!1,wrapHours:!0},i={am:"am",pm:"pm",AM:"AM",PM:"PM",decimal:".",mins:"mins",hr:"hr",hrs:"hrs"};class n{constructor(e,i={}){const s=n.extractAttrOptions(e,Object.keys(t));this.settings=this.parseSettings({...t,...i,...s})}static extractAttrOptions(e,t){const i={};for(const n of t)n in e.dataset&&(i[n]=e.dataset[n]);return i}time2int(e){if(""===e||null==e)return null;if(e instanceof Date)return 3600*e.getHours()+60*e.getMinutes()+e.getSeconds();if(e instanceof String)return e;"a"!=(e=e.toLowerCase().replace(/[\s\.]/g,"")).slice(-1)&&"p"!=e.slice(-1)||(e+="m");var t=e.match(/^(([^0-9]*))?([0-9]?[0-9])(\W?([0-5][0-9]))?(\W+([0-5][0-9]))?(([^0-9]*))$/);if(!t)return null;var i=parseInt(1*t[3],10),n=t[2]||t[9],s=i,r=1*t[5]||0,a=1*t[7]||0;if(i<=12&&n){var o=(n=n.trim())==this.settings.lang.pm||n==this.settings.lang.PM;s=12==i?o?12:0:i+(o?12:0)}else{if(3600*i+60*r+a>=86400+(this.settings.show2400?1:0)){if(!1===this.settings.wrapHours)return null;s=i%24}}var l=3600*s+60*r+a;if(i<12&&!n&&this.settings._twelveHourTime&&this.settings.scrollDefault){var c=l-this.settings.scrollDefault();c<0&&c>=-43200&&(l=(l+43200)%86400)}return l}parseSettings(e){if(e.lang={...i,...e.lang},this.settings=e,e.minTime&&(e.minTime=this.time2int(e.minTime)),e.maxTime&&(e.maxTime=this.time2int(e.maxTime)),e.durationTime&&"function"!=typeof e.durationTime&&(e.durationTime=this.time2int(e.durationTime)),"now"==e.scrollDefault)e.scrollDefault=()=>e.roundingFunction(this.time2int(new Date),e);else if(e.scrollDefault&&"function"!=typeof e.scrollDefault){var t=e.scrollDefault;e.scrollDefault=()=>e.roundingFunction(this.time2int(t),e)}else e.minTime&&(e.scrollDefault=function(){return e.roundingFunction(e.minTime,e)});if("string"==typeof e.timeFormat&&e.timeFormat.match(/[gh]/)&&(e._twelveHourTime=!0),!1===e.showOnFocus&&-1!=e.showOn.indexOf("focus")&&e.showOn.splice(e.showOn.indexOf("focus"),1),e.disableTimeRanges.length>0){for(var n in e.disableTimeRanges)e.disableTimeRanges[n]=[this.time2int(e.disableTimeRanges[n][0]),this.time2int(e.disableTimeRanges[n][1])];e.disableTimeRanges=e.disableTimeRanges.sort((function(e,t){return e[0]-t[0]}));for(n=e.disableTimeRanges.length-1;n>0;n--)e.disableTimeRanges[n][0]<=e.disableTimeRanges[n-1][1]&&(e.disableTimeRanges[n-1]=[Math.min(e.disableTimeRanges[n][0],e.disableTimeRanges[n-1][0]),Math.max(e.disableTimeRanges[n][1],e.disableTimeRanges[n-1][1])],e.disableTimeRanges.splice(n,1))}return e}} -/*! - * jquery-timepicker v1.13.4 - A jQuery timepicker plugin inspired by Google Calendar. It supports both mouse and keyboard navigation. - * Copyright (c) 2015 Jon Thornton - http://jonthornton.github.com/jquery-timepicker/ - * License: MIT - */var s;s=function(t){var i={},s={init:function(e){return this.each((function(){var r=t(this);const o=new n(this,e),l=o.settings;if(i=l.lang,r.data("timepicker-settings",l),r.data("timepicker-obj",o),r.addClass("ui-timepicker-input"),l.useSelect)a(r);else{if(r.prop("autocomplete","off"),l.showOn)for(var c in l.showOn)r.on(l.showOn[c]+".timepicker",s.show);r.on("change.timepicker",d),r.on("keydown.timepicker",k),r.on("keyup.timepicker",v),l.disableTextInput&&r.on("keydown.timepicker",g),r.on("cut.timepicker",v),r.on("paste.timepicker",v),d.call(r.get(0),null,"initial")}}))},show:function(e){var i=t(this),n=i.data("timepicker-settings"),o=i.data("timepicker-obj");if(e&&e.preventDefault(),n.useSelect)i.data("timepicker-list").focus();else{u(i)&&i.blur();var l=i.data("timepicker-list");if(!i.prop("readonly")&&(l&&0!==l.length&&"function"!=typeof n.durationTime||(a(i),l=i.data("timepicker-list")),!r(l))){i.data("ui-timepicker-value",i.val()),m(i,l),s.hide(),"number"==typeof n.listWidth&&(console.log(n.listWidth),l.width(i.outerWidth()*n.listWidth)),l.show();var d={};n.orientation.match(/r/)?d.left=i.offset().left+i.outerWidth()-l.outerWidth()+parseInt(l.css("marginLeft").replace("px",""),10):n.orientation.match(/l/)?d.left=i.offset().left+parseInt(l.css("marginLeft").replace("px",""),10):n.orientation.match(/c/)&&(d.left=i.offset().left+(i.outerWidth()-l.outerWidth())/2+parseInt(l.css("marginLeft").replace("px",""),10)),"t"==(n.orientation.match(/t/)?"t":n.orientation.match(/b/)?"b":i.offset().top+i.outerHeight(!0)+l.outerHeight()>t(window).height()+t(window).scrollTop()?"t":"b")?(l.addClass("ui-timepicker-positioned-top"),d.top=i.offset().top-l.outerHeight()+parseInt(l.css("marginTop").replace("px",""),10)):(l.removeClass("ui-timepicker-positioned-top"),d.top=i.offset().top+i.outerHeight()+parseInt(l.css("marginTop").replace("px",""),10)),l.offset(d);var h=l.find(".ui-timepicker-selected");if(!h.length){var g=o.time2int(f(i));null!==g?h=p(i,l,g):n.scrollDefault&&(h=p(i,l,n.scrollDefault()))}if(h.length&&!h.hasClass("ui-timepicker-disabled")||(h=l.find("li:not(.ui-timepicker-disabled):first")),h&&h.length){var k=l.scrollTop()+h.position().top-h.outerHeight();l.scrollTop(k)}else l.scrollTop(0);return n.stopScrollPropagation&&t(document).on("wheel.ui-timepicker",".ui-timepicker-wrapper",(function(e){e.preventDefault();var i=t(this).scrollTop();t(this).scrollTop(i+e.originalEvent.deltaY)})),t(document).on("touchstart.ui-timepicker mousedown.ui-timepicker",c),t(window).on("resize.ui-timepicker",c),n.closeOnWindowScroll&&t(document).on("scroll.ui-timepicker",c),i.trigger("showTimepicker"),this}}},hide:function(e){var i=t(this),n=i.data("timepicker-settings");return n&&n.useSelect&&i.blur(),t(".ui-timepicker-wrapper").each((function(){var e=t(this);if(r(e)){var i=e.data("timepicker-input"),n=i.data("timepicker-settings");n&&n.selectOnBlur&&T(i),e.hide(),i.trigger("hideTimepicker")}})),this},option:function(e,i){return"string"==typeof e&&void 0===i?t(this).data("timepicker-settings")[e]:this.each((function(){var n=t(this),s=n.data("timepicker-settings"),r=n.data("timepicker-obj"),o=n.data("timepicker-list");"object"==typeof e?s=t.extend(s,e):"string"==typeof e&&(s[e]=i),s=r.parseSettings(s),n.data("timepicker-settings",s),d.call(n.get(0),{type:"change"},"initial"),o&&(o.remove(),n.data("timepicker-list",!1)),s.useSelect&&a(n)}))},getSecondsFromMidnight:function(){return t(this).data("timepicker-obj").time2int(f(this))},getTime:function(e){var i=t(this),n=i.data("timepicker-obj"),s=f(i);if(!s)return null;var r=n.time2int(s);if(null===r)return null;e||(e=new Date);var a=new Date(e);return a.setHours(r/3600),a.setMinutes(r%3600/60),a.setSeconds(r%60),a.setMilliseconds(0),a},isVisible:function(){var e=this.data("timepicker-list");return!(!e||!r(e))},setTime:function(e){var t=this.data("timepicker-settings"),i=this.data("timepicker-obj");if(t.forceRoundTime)var n=l(i.time2int(e),t);else n=w(i.time2int(e),t);return e&&null===n&&t.noneOption&&(n=e),h(this,n,"initial"),d.call(this.get(0),{type:"change"},"initial"),this.data("timepicker-list")&&m(this,this.data("timepicker-list")),this},remove:function(){if(this.hasClass("ui-timepicker-input")){var e=this.data("timepicker-settings");return this.removeAttr("autocomplete","off"),this.removeClass("ui-timepicker-input"),this.removeData("timepicker-settings"),this.off(".timepicker"),this.data("timepicker-list")&&this.data("timepicker-list").remove(),e.useSelect&&this.show(),this.removeData("timepicker-list"),this}}};function r(e){var t=e[0];return t.offsetWidth>0&&t.offsetHeight>0}function a(i){var n=i.data("timepicker-settings"),r=i.data("timepicker-list"),a=i.data("timepicker-obj");if(r&&r.length&&(r.remove(),i.data("timepicker-list",!1)),n.useSelect){r=t("",{class:"ui-timepicker-select"}),i.attr("name")&&r.attr("name","ui-timepicker-"+i.attr("name"));var c=r}else r=t("