Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'master' into gh-pages

  • Loading branch information...
commit 263fdfd18b0f68a6185cc4f2b8172e650efd5042 2 parents ff2160c + 8869cf8
@jdewit authored
View
33 Gruntfile.js
@@ -6,25 +6,20 @@ module.exports = function(grunt) {
grunt.loadNpmTasks('grunt-contrib-less');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-watch');
- grunt.loadNpmTasks('grunt-gh-pages');
+ grunt.loadNpmTasks('grunt-bump');
grunt.initConfig({
- pkg: grunt.file.readJSON('package.json'),
- meta: {
- project: 'bootstrap-timepicker',
- version: '0.2.3'
+ 'pkg': grunt.file.readJSON('package.json'),
+ 'meta': {
+ project: '<%= pkg.name %>',
+ version: '<%= pkg.version %>'
},
- 'gh-pages': {
+ 'bump': {
options: {
- add: true,
- push: false
- },
- src: [
- 'css/bootstrap-timepicker.min.css',
- 'js/bootstrap-timepicker.min.js'
- ]
+ files: ['package.json', 'component.json', 'composer.json']
+ }
},
- jasmine: {
+ 'jasmine': {
build: {
src : ['spec/js/libs/jquery/jquery.min.js', 'spec/js/libs/bootstrap/js/bootstrap.min.js', 'spec/js/libs/autotype/index.js', 'js/bootstrap-timepicker.js'],
options: {
@@ -34,7 +29,7 @@ module.exports = function(grunt) {
}
}
},
- jshint: {
+ 'jshint': {
options: {
browser: true,
camelcase: true,
@@ -68,7 +63,7 @@ module.exports = function(grunt) {
},
files: ['js/bootstrap-timepicker.js', 'Gruntfile.js', 'package.json', 'spec/js/*Spec.js']
},
- less: {
+ 'less': {
dev: {
options: {
paths: ['css']
@@ -87,9 +82,9 @@ module.exports = function(grunt) {
}
}
},
- uglify: {
+ 'uglify': {
options: {
- banner: '/*! <%= meta.project %> v<%= meta.version %> \n' +
+ banner: '/*! <%= pkg.name %> v<%= pkg.version %> \n' +
'* http://jdewit.github.com/bootstrap-timepicker \n' +
'* Copyright (c) <%= grunt.template.today("yyyy") %> Joris de Wit \n' +
'* MIT License \n' +
@@ -100,7 +95,7 @@ module.exports = function(grunt) {
dest: 'js/<%= pkg.name %>.min.js'
}
},
- watch: {
+ 'watch': {
js: {
files: ['js/bootstrap-timepicker.js', 'spec/js/*Spec.js'],
tasks: ['jshint', 'jasmine'],
View
2  README.md
@@ -42,6 +42,8 @@ $ bower install
$ grunt test // run jshint and jasmine tests
$ grunt watch // run jsHint and Jasmine tests whenever a file is changed
$ grunt compile // minify the js and css files
+$ grunt gh-pages // push updates to gh-pages
+$ grunt bump:[patch/minor/major] // bump the version
```
- Please make it easy on me by covering any new features or issues
View
2  _layouts/default.html
@@ -106,7 +106,7 @@
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/2.2.2/bootstrap.min.js"></script>
<script type="text/javascript" src="assets/prettify/prettify.js"></script>
- <script type="text/javascript" src="js/bootstrap-timepicker.min.js?v0.2.4"></script>
+ <script type="text/javascript" src="js/bootstrap-timepicker.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$('#timepicker1').timepicker();
View
2  component.json
@@ -1,6 +1,6 @@
{
"name": "bootstrap-timepicker",
- "version": "0.2.3",
+ "version": "0.2.4",
"description": "A timepicker component for Twitter Bootstrap 2.x",
"repository": {
"type": "git",
View
2  composer.json
@@ -1,7 +1,7 @@
{
"name" : "jdewit/bootstrap-timepicker",
"description" : "A simple timepicker component for Twitter Bootstrap.",
- "version" : "0.2.3",
+ "version" : "0.2.4",
"license" : "MIT",
"authors": [
{
View
1  css/bootstrap-timepicker.css
@@ -96,6 +96,7 @@
}
.bootstrap-timepicker-widget table td a i {
margin-top: 2px;
+ font-size: 18px;
}
.bootstrap-timepicker-widget table td input {
width: 25px;
View
4 js/bootstrap-timepicker.js
@@ -549,8 +549,8 @@
if (defaultTime === 'current') {
var dTime = new Date(),
hours = dTime.getHours(),
- minutes = Math.floor(dTime.getMinutes() / this.minuteStep) * this.minuteStep,
- seconds = Math.floor(dTime.getSeconds() / this.secondStep) * this.secondStep,
+ minutes = Math.ceil(dTime.getMinutes() / this.minuteStep) * this.minuteStep,
+ seconds = Math.ceil(dTime.getSeconds() / this.secondStep) * this.secondStep,
meridian = 'AM';
if (this.showMeridian) {
View
4 js/bootstrap-timepicker.min.js
@@ -1,5 +1,5 @@
-/*! bootstrap-timepicker v0.2.3
+/*! bootstrap-timepicker v0.2.4
* http://jdewit.github.com/bootstrap-timepicker
* Copyright (c) 2013 Joris de Wit
* MIT License
-*/!function(a,b,c,d){"use strict";var e=function(b,c){this.widget="",this.$element=a(b),this.defaultTime=c.defaultTime,this.disableFocus=c.disableFocus,this.isOpen=c.isOpen,this.minuteStep=c.minuteStep,this.modalBackdrop=c.modalBackdrop,this.secondStep=c.secondStep,this.showInputs=c.showInputs,this.showMeridian=c.showMeridian,this.showSeconds=c.showSeconds,this.template=c.template,this.appendWidgetTo=c.appendWidgetTo,this._init()};e.prototype={constructor:e,_init:function(){var b=this;this.$element.parent().hasClass("input-append")||this.$element.parent().hasClass("input-prepend")?(this.$element.parent(".input-append, .input-prepend").find(".add-on").on({"click.timepicker":a.proxy(this.showWidget,this)}),this.$element.on({"focus.timepicker":a.proxy(this.highlightUnit,this),"click.timepicker":a.proxy(this.highlightUnit,this),"keydown.timepicker":a.proxy(this.elementKeydown,this),"blur.timepicker":a.proxy(this.blurElement,this)})):this.template?this.$element.on({"focus.timepicker":a.proxy(this.showWidget,this),"click.timepicker":a.proxy(this.showWidget,this),"blur.timepicker":a.proxy(this.blurElement,this)}):this.$element.on({"focus.timepicker":a.proxy(this.highlightUnit,this),"click.timepicker":a.proxy(this.highlightUnit,this),"keydown.timepicker":a.proxy(this.elementKeydown,this),"blur.timepicker":a.proxy(this.blurElement,this)}),this.$widget=this.template!==!1?a(this.getTemplate()).prependTo(this.$element.parents(this.appendWidgetTo)).on("click",a.proxy(this.widgetClick,this)):!1,this.showInputs&&this.$widget!==!1&&this.$widget.find("input").each(function(){a(this).on({"click.timepicker":function(){a(this).select()},"keydown.timepicker":a.proxy(b.widgetKeydown,b)})}),this.setDefaultTime(this.defaultTime)},blurElement:function(){this.highlightedUnit=d,this.updateFromElementVal()},decrementHour:function(){if(this.showMeridian)if(1===this.hour)this.hour=12;else{if(12===this.hour)return this.hour--,this.toggleMeridian();if(0===this.hour)return this.hour=11,this.toggleMeridian();this.hour--}else 0===this.hour?this.hour=23:this.hour--;this.update()},decrementMinute:function(a){var b;b=a?this.minute-a:this.minute-this.minuteStep,0>b?(this.decrementHour(),this.minute=b+60):this.minute=b,this.update()},decrementSecond:function(){var a=this.second-this.secondStep;0>a?(this.decrementMinute(!0),this.second=a+60):this.second=a,this.update()},elementKeydown:function(a){switch(a.keyCode){case 9:switch(this.updateFromElementVal(),this.highlightedUnit){case"hour":a.preventDefault(),this.highlightNextUnit();break;case"minute":(this.showMeridian||this.showSeconds)&&(a.preventDefault(),this.highlightNextUnit());break;case"second":this.showMeridian&&(a.preventDefault(),this.highlightNextUnit())}break;case 27:this.updateFromElementVal();break;case 37:a.preventDefault(),this.highlightPrevUnit(),this.updateFromElementVal();break;case 38:switch(a.preventDefault(),this.highlightedUnit){case"hour":this.incrementHour(),this.highlightHour();break;case"minute":this.incrementMinute(),this.highlightMinute();break;case"second":this.incrementSecond(),this.highlightSecond();break;case"meridian":this.toggleMeridian(),this.highlightMeridian()}break;case 39:a.preventDefault(),this.updateFromElementVal(),this.highlightNextUnit();break;case 40:switch(a.preventDefault(),this.highlightedUnit){case"hour":this.decrementHour(),this.highlightHour();break;case"minute":this.decrementMinute(),this.highlightMinute();break;case"second":this.decrementSecond(),this.highlightSecond();break;case"meridian":this.toggleMeridian(),this.highlightMeridian()}}},formatTime:function(a,b,c,d){return a=10>a?"0"+a:a,b=10>b?"0"+b:b,c=10>c?"0"+c:c,a+":"+b+(this.showSeconds?":"+c:"")+(this.showMeridian?" "+d:"")},getCursorPosition:function(){var a=this.$element.get(0);if("selectionStart"in a)return a.selectionStart;if(c.selection){a.focus();var b=c.selection.createRange(),d=c.selection.createRange().text.length;return b.moveStart("character",-a.value.length),b.text.length-d}},getTemplate:function(){var a,b,c,d,e,f;switch(this.showInputs?(b='<input type="text" name="hour" class="bootstrap-timepicker-hour" maxlength="2"/>',c='<input type="text" name="minute" class="bootstrap-timepicker-minute" maxlength="2"/>',d='<input type="text" name="second" class="bootstrap-timepicker-second" maxlength="2"/>',e='<input type="text" name="meridian" class="bootstrap-timepicker-meridian" maxlength="2"/>'):(b='<span class="bootstrap-timepicker-hour"></span>',c='<span class="bootstrap-timepicker-minute"></span>',d='<span class="bootstrap-timepicker-second"></span>',e='<span class="bootstrap-timepicker-meridian"></span>'),f='<table><tr><td><a href="#" data-action="incrementHour"><i class="icon-chevron-up"></i></a></td><td class="separator">&nbsp;</td><td><a href="#" data-action="incrementMinute"><i class="icon-chevron-up"></i></a></td>'+(this.showSeconds?'<td class="separator">&nbsp;</td><td><a href="#" data-action="incrementSecond"><i class="icon-chevron-up"></i></a></td>':"")+(this.showMeridian?'<td class="separator">&nbsp;</td><td class="meridian-column"><a href="#" data-action="toggleMeridian"><i class="icon-chevron-up"></i></a></td>':"")+"</tr>"+"<tr>"+"<td>"+b+"</td> "+'<td class="separator">:</td>'+"<td>"+c+"</td> "+(this.showSeconds?'<td class="separator">:</td><td>'+d+"</td>":"")+(this.showMeridian?'<td class="separator">&nbsp;</td><td>'+e+"</td>":"")+"</tr>"+"<tr>"+'<td><a href="#" data-action="decrementHour"><i class="icon-chevron-down"></i></a></td>'+'<td class="separator"></td>'+'<td><a href="#" data-action="decrementMinute"><i class="icon-chevron-down"></i></a></td>'+(this.showSeconds?'<td class="separator">&nbsp;</td><td><a href="#" data-action="decrementSecond"><i class="icon-chevron-down"></i></a></td>':"")+(this.showMeridian?'<td class="separator">&nbsp;</td><td><a href="#" data-action="toggleMeridian"><i class="icon-chevron-down"></i></a></td>':"")+"</tr>"+"</table>",this.template){case"modal":a='<div class="bootstrap-timepicker-widget modal hide fade in" data-backdrop="'+(this.modalBackdrop?"true":"false")+'">'+'<div class="modal-header">'+'<a href="#" class="close" data-dismiss="modal">×</a>'+"<h3>Pick a Time</h3>"+"</div>"+'<div class="modal-content">'+f+"</div>"+'<div class="modal-footer">'+'<a href="#" class="btn btn-primary" data-dismiss="modal">OK</a>'+"</div>"+"</div>";break;case"dropdown":a='<div class="bootstrap-timepicker-widget dropdown-menu">'+f+"</div>"}return a},getTime:function(){return this.formatTime(this.hour,this.minute,this.second,this.meridian)},hideWidget:function(){this.isOpen!==!1&&(this.showInputs&&this.updateFromWidgetInputs(),this.$element.trigger({type:"hide.timepicker",time:{value:this.getTime(),hours:this.hour,minutes:this.minute,seconds:this.second,meridian:this.meridian}}),"modal"===this.template&&this.$widget.modal?this.$widget.modal("hide"):this.$widget.removeClass("open"),a(c).off("mousedown.timepicker"),this.isOpen=!1)},highlightUnit:function(){this.position=this.getCursorPosition(),this.position>=0&&this.position<=2?this.highlightHour():this.position>=3&&this.position<=5?this.highlightMinute():this.position>=6&&this.position<=8?this.showSeconds?this.highlightSecond():this.highlightMeridian():this.position>=9&&this.position<=11&&this.highlightMeridian()},highlightNextUnit:function(){switch(this.highlightedUnit){case"hour":this.highlightMinute();break;case"minute":this.showSeconds?this.highlightSecond():this.showMeridian?this.highlightMeridian():this.highlightHour();break;case"second":this.showMeridian?this.highlightMeridian():this.highlightHour();break;case"meridian":this.highlightHour()}},highlightPrevUnit:function(){switch(this.highlightedUnit){case"hour":this.highlightMeridian();break;case"minute":this.highlightHour();break;case"second":this.highlightMinute();break;case"meridian":this.showSeconds?this.highlightSecond():this.highlightMinute()}},highlightHour:function(){var a=this.$element.get(0);this.highlightedUnit="hour",a.setSelectionRange&&setTimeout(function(){a.setSelectionRange(0,2)},0)},highlightMinute:function(){var a=this.$element.get(0);this.highlightedUnit="minute",a.setSelectionRange&&setTimeout(function(){a.setSelectionRange(3,5)},0)},highlightSecond:function(){var a=this.$element.get(0);this.highlightedUnit="second",a.setSelectionRange&&setTimeout(function(){a.setSelectionRange(6,8)},0)},highlightMeridian:function(){var a=this.$element.get(0);this.highlightedUnit="meridian",a.setSelectionRange&&(this.showSeconds?setTimeout(function(){a.setSelectionRange(9,11)},0):setTimeout(function(){a.setSelectionRange(6,8)},0))},incrementHour:function(){if(this.showMeridian){if(11===this.hour)return this.hour++,this.toggleMeridian();12===this.hour&&(this.hour=0)}return 23===this.hour?(this.hour=0,void 0):(this.hour++,this.update(),void 0)},incrementMinute:function(a){var b;b=a?this.minute+a:this.minute+this.minuteStep-this.minute%this.minuteStep,b>59?(this.incrementHour(),this.minute=b-60):(this.minute=b,this.update())},incrementSecond:function(){var a=this.second+this.secondStep-this.second%this.secondStep;a>59?(this.incrementMinute(!0),this.second=a-60):this.second=a,this.update()},remove:function(){a("document").off(".timepicker"),this.$widget&&this.$widget.remove(),delete this.$element.data().timepicker},setDefaultTime:function(a){if(this.$element.val())this.updateFromElementVal();else if("current"===a){var b=new Date,c=b.getHours(),d=Math.floor(b.getMinutes()/this.minuteStep)*this.minuteStep,e=Math.floor(b.getSeconds()/this.secondStep)*this.secondStep,f="AM";this.showMeridian&&(0===c?c=12:c>=12?(c>12&&(c-=12),f="PM"):f="AM"),this.hour=c,this.minute=d,this.second=e,this.meridian=f,this.update()}else a===!1?(this.hour=0,this.minute=0,this.second=0,this.meridian="AM"):this.setTime(a)},setTime:function(a){var b,c;this.showMeridian?(b=a.split(" "),c=b[0].split(":"),this.meridian=b[1]):c=a.split(":"),this.hour=parseInt(c[0],10),this.minute=parseInt(c[1],10),this.second=parseInt(c[2],10),isNaN(this.hour)&&(this.hour=0),isNaN(this.minute)&&(this.minute=0),this.showMeridian?(this.hour>12?this.hour=12:this.hour<1&&(this.hour=12),"am"===this.meridian||"a"===this.meridian?this.meridian="AM":("pm"===this.meridian||"p"===this.meridian)&&(this.meridian="PM"),"AM"!==this.meridian&&"PM"!==this.meridian&&(this.meridian="AM")):this.hour>=24?this.hour=23:this.hour<0&&(this.hour=0),this.minute<0?this.minute=0:this.minute>=60&&(this.minute=59),this.showSeconds&&(isNaN(this.second)?this.second=0:this.second<0?this.second=0:this.second>=60&&(this.second=59)),this.update()},showWidget:function(){if(!this.isOpen&&!this.$element.is(":disabled")){var b=this;a(c).on("mousedown.timepicker",function(c){0===a(c.target).closest(".bootstrap-timepicker-widget").length&&b.hideWidget()}),this.$element.trigger({type:"show.timepicker",time:{value:this.getTime(),hours:this.hour,minutes:this.minute,seconds:this.second,meridian:this.meridian}}),this.disableFocus&&this.$element.blur(),this.updateFromElementVal(),"modal"===this.template&&this.$widget.modal?this.$widget.modal("show").on("hidden",a.proxy(this.hideWidget,this)):this.isOpen===!1&&this.$widget.addClass("open"),this.isOpen=!0}},toggleMeridian:function(){this.meridian="AM"===this.meridian?"PM":"AM",this.update()},update:function(){this.$element.trigger({type:"changeTime.timepicker",time:{value:this.getTime(),hours:this.hour,minutes:this.minute,seconds:this.second,meridian:this.meridian}}),this.updateElement(),this.updateWidget()},updateElement:function(){this.$element.val(this.getTime()).change()},updateFromElementVal:function(){var a=this.$element.val();a&&this.setTime(a)},updateWidget:function(){if(this.$widget!==!1){var a=this.hour<10?"0"+this.hour:this.hour,b=this.minute<10?"0"+this.minute:this.minute,c=this.second<10?"0"+this.second:this.second;this.showInputs?(this.$widget.find("input.bootstrap-timepicker-hour").val(a),this.$widget.find("input.bootstrap-timepicker-minute").val(b),this.showSeconds&&this.$widget.find("input.bootstrap-timepicker-second").val(c),this.showMeridian&&this.$widget.find("input.bootstrap-timepicker-meridian").val(this.meridian)):(this.$widget.find("span.bootstrap-timepicker-hour").text(a),this.$widget.find("span.bootstrap-timepicker-minute").text(b),this.showSeconds&&this.$widget.find("span.bootstrap-timepicker-second").text(c),this.showMeridian&&this.$widget.find("span.bootstrap-timepicker-meridian").text(this.meridian))}},updateFromWidgetInputs:function(){if(this.$widget!==!1){var b=a("input.bootstrap-timepicker-hour",this.$widget).val()+":"+a("input.bootstrap-timepicker-minute",this.$widget).val()+(this.showSeconds?":"+a("input.bootstrap-timepicker-second",this.$widget).val():"")+(this.showMeridian?" "+a("input.bootstrap-timepicker-meridian",this.$widget).val():"");this.setTime(b)}},widgetClick:function(b){b.stopPropagation(),b.preventDefault();var c=a(b.target).closest("a").data("action");c&&this[c]()},widgetKeydown:function(b){var c=a(b.target).closest("input"),d=c.attr("name");switch(b.keyCode){case 9:if(this.showMeridian){if("meridian"===d)return this.hideWidget()}else if(this.showSeconds){if("second"===d)return this.hideWidget()}else if("minute"===d)return this.hideWidget();this.updateFromWidgetInputs();break;case 27:this.hideWidget();break;case 38:switch(b.preventDefault(),d){case"hour":this.incrementHour();break;case"minute":this.incrementMinute();break;case"second":this.incrementSecond();break;case"meridian":this.toggleMeridian()}break;case 40:switch(b.preventDefault(),d){case"hour":this.decrementHour();break;case"minute":this.decrementMinute();break;case"second":this.decrementSecond();break;case"meridian":this.toggleMeridian()}}}},a.fn.timepicker=function(b){var c=Array.apply(null,arguments);return c.shift(),this.each(function(){var d=a(this),f=d.data("timepicker"),g="object"==typeof b&&b;f||d.data("timepicker",f=new e(this,a.extend({},a.fn.timepicker.defaults,g,a(this).data()))),"string"==typeof b&&f[b].apply(f,c)})},a.fn.timepicker.defaults={defaultTime:"current",disableFocus:!1,isOpen:!1,minuteStep:15,modalBackdrop:!1,secondStep:15,showSeconds:!1,showInputs:!0,showMeridian:!0,template:"dropdown",appendWidgetTo:".bootstrap-timepicker"},a.fn.timepicker.Constructor=e}(jQuery,window,document);
+*/!function(a,b,c,d){"use strict";var e=function(b,c){this.widget="",this.$element=a(b),this.defaultTime=c.defaultTime,this.disableFocus=c.disableFocus,this.isOpen=c.isOpen,this.minuteStep=c.minuteStep,this.modalBackdrop=c.modalBackdrop,this.secondStep=c.secondStep,this.showInputs=c.showInputs,this.showMeridian=c.showMeridian,this.showSeconds=c.showSeconds,this.template=c.template,this.appendWidgetTo=c.appendWidgetTo,this._init()};e.prototype={constructor:e,_init:function(){var b=this;this.$element.parent().hasClass("input-append")||this.$element.parent().hasClass("input-prepend")?(this.$element.parent(".input-append, .input-prepend").find(".add-on").on({"click.timepicker":a.proxy(this.showWidget,this)}),this.$element.on({"focus.timepicker":a.proxy(this.highlightUnit,this),"click.timepicker":a.proxy(this.highlightUnit,this),"keydown.timepicker":a.proxy(this.elementKeydown,this),"blur.timepicker":a.proxy(this.blurElement,this)})):this.template?this.$element.on({"focus.timepicker":a.proxy(this.showWidget,this),"click.timepicker":a.proxy(this.showWidget,this),"blur.timepicker":a.proxy(this.blurElement,this)}):this.$element.on({"focus.timepicker":a.proxy(this.highlightUnit,this),"click.timepicker":a.proxy(this.highlightUnit,this),"keydown.timepicker":a.proxy(this.elementKeydown,this),"blur.timepicker":a.proxy(this.blurElement,this)}),this.$widget=this.template!==!1?a(this.getTemplate()).prependTo(this.$element.parents(this.appendWidgetTo)).on("click",a.proxy(this.widgetClick,this)):!1,this.showInputs&&this.$widget!==!1&&this.$widget.find("input").each(function(){a(this).on({"click.timepicker":function(){a(this).select()},"keydown.timepicker":a.proxy(b.widgetKeydown,b)})}),this.setDefaultTime(this.defaultTime)},blurElement:function(){this.highlightedUnit=d,this.updateFromElementVal()},decrementHour:function(){if(this.showMeridian)if(1===this.hour)this.hour=12;else{if(12===this.hour)return this.hour--,this.toggleMeridian();if(0===this.hour)return this.hour=11,this.toggleMeridian();this.hour--}else 0===this.hour?this.hour=23:this.hour--;this.update()},decrementMinute:function(a){var b;b=a?this.minute-a:this.minute-this.minuteStep,0>b?(this.decrementHour(),this.minute=b+60):this.minute=b,this.update()},decrementSecond:function(){var a=this.second-this.secondStep;0>a?(this.decrementMinute(!0),this.second=a+60):this.second=a,this.update()},elementKeydown:function(a){switch(a.keyCode){case 9:switch(this.updateFromElementVal(),this.highlightedUnit){case"hour":a.preventDefault(),this.highlightNextUnit();break;case"minute":(this.showMeridian||this.showSeconds)&&(a.preventDefault(),this.highlightNextUnit());break;case"second":this.showMeridian&&(a.preventDefault(),this.highlightNextUnit())}break;case 27:this.updateFromElementVal();break;case 37:a.preventDefault(),this.highlightPrevUnit(),this.updateFromElementVal();break;case 38:switch(a.preventDefault(),this.highlightedUnit){case"hour":this.incrementHour(),this.highlightHour();break;case"minute":this.incrementMinute(),this.highlightMinute();break;case"second":this.incrementSecond(),this.highlightSecond();break;case"meridian":this.toggleMeridian(),this.highlightMeridian()}break;case 39:a.preventDefault(),this.updateFromElementVal(),this.highlightNextUnit();break;case 40:switch(a.preventDefault(),this.highlightedUnit){case"hour":this.decrementHour(),this.highlightHour();break;case"minute":this.decrementMinute(),this.highlightMinute();break;case"second":this.decrementSecond(),this.highlightSecond();break;case"meridian":this.toggleMeridian(),this.highlightMeridian()}}},formatTime:function(a,b,c,d){return a=10>a?"0"+a:a,b=10>b?"0"+b:b,c=10>c?"0"+c:c,a+":"+b+(this.showSeconds?":"+c:"")+(this.showMeridian?" "+d:"")},getCursorPosition:function(){var a=this.$element.get(0);if("selectionStart"in a)return a.selectionStart;if(c.selection){a.focus();var b=c.selection.createRange(),d=c.selection.createRange().text.length;return b.moveStart("character",-a.value.length),b.text.length-d}},getTemplate:function(){var a,b,c,d,e,f;switch(this.showInputs?(b='<input type="text" name="hour" class="bootstrap-timepicker-hour" maxlength="2"/>',c='<input type="text" name="minute" class="bootstrap-timepicker-minute" maxlength="2"/>',d='<input type="text" name="second" class="bootstrap-timepicker-second" maxlength="2"/>',e='<input type="text" name="meridian" class="bootstrap-timepicker-meridian" maxlength="2"/>'):(b='<span class="bootstrap-timepicker-hour"></span>',c='<span class="bootstrap-timepicker-minute"></span>',d='<span class="bootstrap-timepicker-second"></span>',e='<span class="bootstrap-timepicker-meridian"></span>'),f='<table><tr><td><a href="#" data-action="incrementHour"><i class="icon-chevron-up"></i></a></td><td class="separator">&nbsp;</td><td><a href="#" data-action="incrementMinute"><i class="icon-chevron-up"></i></a></td>'+(this.showSeconds?'<td class="separator">&nbsp;</td><td><a href="#" data-action="incrementSecond"><i class="icon-chevron-up"></i></a></td>':"")+(this.showMeridian?'<td class="separator">&nbsp;</td><td class="meridian-column"><a href="#" data-action="toggleMeridian"><i class="icon-chevron-up"></i></a></td>':"")+"</tr>"+"<tr>"+"<td>"+b+"</td> "+'<td class="separator">:</td>'+"<td>"+c+"</td> "+(this.showSeconds?'<td class="separator">:</td><td>'+d+"</td>":"")+(this.showMeridian?'<td class="separator">&nbsp;</td><td>'+e+"</td>":"")+"</tr>"+"<tr>"+'<td><a href="#" data-action="decrementHour"><i class="icon-chevron-down"></i></a></td>'+'<td class="separator"></td>'+'<td><a href="#" data-action="decrementMinute"><i class="icon-chevron-down"></i></a></td>'+(this.showSeconds?'<td class="separator">&nbsp;</td><td><a href="#" data-action="decrementSecond"><i class="icon-chevron-down"></i></a></td>':"")+(this.showMeridian?'<td class="separator">&nbsp;</td><td><a href="#" data-action="toggleMeridian"><i class="icon-chevron-down"></i></a></td>':"")+"</tr>"+"</table>",this.template){case"modal":a='<div class="bootstrap-timepicker-widget modal hide fade in" data-backdrop="'+(this.modalBackdrop?"true":"false")+'">'+'<div class="modal-header">'+'<a href="#" class="close" data-dismiss="modal">×</a>'+"<h3>Pick a Time</h3>"+"</div>"+'<div class="modal-content">'+f+"</div>"+'<div class="modal-footer">'+'<a href="#" class="btn btn-primary" data-dismiss="modal">OK</a>'+"</div>"+"</div>";break;case"dropdown":a='<div class="bootstrap-timepicker-widget dropdown-menu">'+f+"</div>"}return a},getTime:function(){return this.formatTime(this.hour,this.minute,this.second,this.meridian)},hideWidget:function(){this.isOpen!==!1&&(this.showInputs&&this.updateFromWidgetInputs(),this.$element.trigger({type:"hide.timepicker",time:{value:this.getTime(),hours:this.hour,minutes:this.minute,seconds:this.second,meridian:this.meridian}}),"modal"===this.template&&this.$widget.modal?this.$widget.modal("hide"):this.$widget.removeClass("open"),a(c).off("mousedown.timepicker"),this.isOpen=!1)},highlightUnit:function(){this.position=this.getCursorPosition(),this.position>=0&&this.position<=2?this.highlightHour():this.position>=3&&this.position<=5?this.highlightMinute():this.position>=6&&this.position<=8?this.showSeconds?this.highlightSecond():this.highlightMeridian():this.position>=9&&this.position<=11&&this.highlightMeridian()},highlightNextUnit:function(){switch(this.highlightedUnit){case"hour":this.highlightMinute();break;case"minute":this.showSeconds?this.highlightSecond():this.showMeridian?this.highlightMeridian():this.highlightHour();break;case"second":this.showMeridian?this.highlightMeridian():this.highlightHour();break;case"meridian":this.highlightHour()}},highlightPrevUnit:function(){switch(this.highlightedUnit){case"hour":this.highlightMeridian();break;case"minute":this.highlightHour();break;case"second":this.highlightMinute();break;case"meridian":this.showSeconds?this.highlightSecond():this.highlightMinute()}},highlightHour:function(){var a=this.$element.get(0);this.highlightedUnit="hour",a.setSelectionRange&&setTimeout(function(){a.setSelectionRange(0,2)},0)},highlightMinute:function(){var a=this.$element.get(0);this.highlightedUnit="minute",a.setSelectionRange&&setTimeout(function(){a.setSelectionRange(3,5)},0)},highlightSecond:function(){var a=this.$element.get(0);this.highlightedUnit="second",a.setSelectionRange&&setTimeout(function(){a.setSelectionRange(6,8)},0)},highlightMeridian:function(){var a=this.$element.get(0);this.highlightedUnit="meridian",a.setSelectionRange&&(this.showSeconds?setTimeout(function(){a.setSelectionRange(9,11)},0):setTimeout(function(){a.setSelectionRange(6,8)},0))},incrementHour:function(){if(this.showMeridian){if(11===this.hour)return this.hour++,this.toggleMeridian();12===this.hour&&(this.hour=0)}return 23===this.hour?(this.hour=0,void 0):(this.hour++,this.update(),void 0)},incrementMinute:function(a){var b;b=a?this.minute+a:this.minute+this.minuteStep-this.minute%this.minuteStep,b>59?(this.incrementHour(),this.minute=b-60):(this.minute=b,this.update())},incrementSecond:function(){var a=this.second+this.secondStep-this.second%this.secondStep;a>59?(this.incrementMinute(!0),this.second=a-60):this.second=a,this.update()},remove:function(){a("document").off(".timepicker"),this.$widget&&this.$widget.remove(),delete this.$element.data().timepicker},setDefaultTime:function(a){if(this.$element.val())this.updateFromElementVal();else if("current"===a){var b=new Date,c=b.getHours(),d=Math.ceil(b.getMinutes()/this.minuteStep)*this.minuteStep,e=Math.ceil(b.getSeconds()/this.secondStep)*this.secondStep,f="AM";this.showMeridian&&(0===c?c=12:c>=12?(c>12&&(c-=12),f="PM"):f="AM"),this.hour=c,this.minute=d,this.second=e,this.meridian=f,this.update()}else a===!1?(this.hour=0,this.minute=0,this.second=0,this.meridian="AM"):this.setTime(a)},setTime:function(a){var b,c;this.showMeridian?(b=a.split(" "),c=b[0].split(":"),this.meridian=b[1]):c=a.split(":"),this.hour=parseInt(c[0],10),this.minute=parseInt(c[1],10),this.second=parseInt(c[2],10),isNaN(this.hour)&&(this.hour=0),isNaN(this.minute)&&(this.minute=0),this.showMeridian?(this.hour>12?this.hour=12:this.hour<1&&(this.hour=12),"am"===this.meridian||"a"===this.meridian?this.meridian="AM":("pm"===this.meridian||"p"===this.meridian)&&(this.meridian="PM"),"AM"!==this.meridian&&"PM"!==this.meridian&&(this.meridian="AM")):this.hour>=24?this.hour=23:this.hour<0&&(this.hour=0),this.minute<0?this.minute=0:this.minute>=60&&(this.minute=59),this.showSeconds&&(isNaN(this.second)?this.second=0:this.second<0?this.second=0:this.second>=60&&(this.second=59)),this.update()},showWidget:function(){if(!this.isOpen&&!this.$element.is(":disabled")){var b=this;a(c).on("mousedown.timepicker",function(c){0===a(c.target).closest(".bootstrap-timepicker-widget").length&&b.hideWidget()}),this.$element.trigger({type:"show.timepicker",time:{value:this.getTime(),hours:this.hour,minutes:this.minute,seconds:this.second,meridian:this.meridian}}),this.disableFocus&&this.$element.blur(),this.updateFromElementVal(),"modal"===this.template&&this.$widget.modal?this.$widget.modal("show").on("hidden",a.proxy(this.hideWidget,this)):this.isOpen===!1&&this.$widget.addClass("open"),this.isOpen=!0}},toggleMeridian:function(){this.meridian="AM"===this.meridian?"PM":"AM",this.update()},update:function(){this.$element.trigger({type:"changeTime.timepicker",time:{value:this.getTime(),hours:this.hour,minutes:this.minute,seconds:this.second,meridian:this.meridian}}),this.updateElement(),this.updateWidget()},updateElement:function(){this.$element.val(this.getTime()).change()},updateFromElementVal:function(){var a=this.$element.val();a&&this.setTime(a)},updateWidget:function(){if(this.$widget!==!1){var a=this.hour<10?"0"+this.hour:this.hour,b=this.minute<10?"0"+this.minute:this.minute,c=this.second<10?"0"+this.second:this.second;this.showInputs?(this.$widget.find("input.bootstrap-timepicker-hour").val(a),this.$widget.find("input.bootstrap-timepicker-minute").val(b),this.showSeconds&&this.$widget.find("input.bootstrap-timepicker-second").val(c),this.showMeridian&&this.$widget.find("input.bootstrap-timepicker-meridian").val(this.meridian)):(this.$widget.find("span.bootstrap-timepicker-hour").text(a),this.$widget.find("span.bootstrap-timepicker-minute").text(b),this.showSeconds&&this.$widget.find("span.bootstrap-timepicker-second").text(c),this.showMeridian&&this.$widget.find("span.bootstrap-timepicker-meridian").text(this.meridian))}},updateFromWidgetInputs:function(){if(this.$widget!==!1){var b=a("input.bootstrap-timepicker-hour",this.$widget).val()+":"+a("input.bootstrap-timepicker-minute",this.$widget).val()+(this.showSeconds?":"+a("input.bootstrap-timepicker-second",this.$widget).val():"")+(this.showMeridian?" "+a("input.bootstrap-timepicker-meridian",this.$widget).val():"");this.setTime(b)}},widgetClick:function(b){b.stopPropagation(),b.preventDefault();var c=a(b.target).closest("a").data("action");c&&this[c]()},widgetKeydown:function(b){var c=a(b.target).closest("input"),d=c.attr("name");switch(b.keyCode){case 9:if(this.showMeridian){if("meridian"===d)return this.hideWidget()}else if(this.showSeconds){if("second"===d)return this.hideWidget()}else if("minute"===d)return this.hideWidget();this.updateFromWidgetInputs();break;case 27:this.hideWidget();break;case 38:switch(b.preventDefault(),d){case"hour":this.incrementHour();break;case"minute":this.incrementMinute();break;case"second":this.incrementSecond();break;case"meridian":this.toggleMeridian()}break;case 40:switch(b.preventDefault(),d){case"hour":this.decrementHour();break;case"minute":this.decrementMinute();break;case"second":this.decrementSecond();break;case"meridian":this.toggleMeridian()}}}},a.fn.timepicker=function(b){var c=Array.apply(null,arguments);return c.shift(),this.each(function(){var d=a(this),f=d.data("timepicker"),g="object"==typeof b&&b;f||d.data("timepicker",f=new e(this,a.extend({},a.fn.timepicker.defaults,g,a(this).data()))),"string"==typeof b&&f[b].apply(f,c)})},a.fn.timepicker.defaults={defaultTime:"current",disableFocus:!1,isOpen:!1,minuteStep:15,modalBackdrop:!1,secondStep:15,showSeconds:!1,showInputs:!0,showMeridian:!0,template:"dropdown",appendWidgetTo:".bootstrap-timepicker"},a.fn.timepicker.Constructor=e}(jQuery,window,document);
View
5 package.json
@@ -1,7 +1,7 @@
{
"name": "bootstrap-timepicker",
"description": "Timepicker widget for Twitter Bootstrap 2.*",
- "version": "0.2.3",
+ "version": "0.2.4",
"homepage": "http://jdewit.github.com/bootstrap-timepicker",
"author": {
"name": "Joris de Wit",
@@ -27,6 +27,7 @@
"grunt-contrib-uglify": "~0.2.0",
"grunt-contrib-jasmine": "~0.4.2",
"grunt-contrib-watch": "~0.4.3",
- "grunt-gh-pages": "~0.7.6"
+ "grunt-shell": "~0.2.2",
+ "grunt-bump": "0.0.11"
}
}
View
5 spec/js/TimepickerSpec.js
@@ -97,11 +97,14 @@ describe('Timepicker feature', function() {
it('should have current time by default', function() {
var dTime = new Date(),
hour = dTime.getHours(),
- minute = Math.floor(dTime.getMinutes() / tp1.minuteStep) * tp1.minuteStep;
+ minute = Math.ceil(dTime.getMinutes() / tp1.minuteStep) * tp1.minuteStep;
if (hour > 12) {
hour = hour - 12;
}
+ if (hour === 0) {
+ hour = 12;
+ }
expect(tp1.hour).toBe(hour);
expect(tp1.minute).toBe(minute);
Please sign in to comment.
Something went wrong with that request. Please try again.