From d5f574359001b83bfbd8e93dad8fad391b4eac5f Mon Sep 17 00:00:00 2001 From: Nicklas Ansman Giertz Date: Mon, 9 Apr 2012 14:03:07 +0300 Subject: [PATCH 01/13] Allow the date input to have the class `date` --- js/bootstrap-datepicker.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/js/bootstrap-datepicker.js b/js/bootstrap-datepicker.js index 07ffc6c..9f897b9 100644 --- a/js/bootstrap-datepicker.js +++ b/js/bootstrap-datepicker.js @@ -34,6 +34,8 @@ }); this.isInput = this.element.is('input'); this.component = this.element.is('.date') ? this.element.find('.add-on') : false; + if(this.component && this.component.length === 0) + this.component = false; if (this.isInput) { this.element.on({ From 4f9a3e5551ef007d736bff0f92c9eba2f113dbbd Mon Sep 17 00:00:00 2001 From: Enrico Rubboli Date: Tue, 10 Apr 2012 01:11:46 +0200 Subject: [PATCH 02/13] add italian language --- js/locales/bootstrap-datepicker.it.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 js/locales/bootstrap-datepicker.it.js diff --git a/js/locales/bootstrap-datepicker.it.js b/js/locales/bootstrap-datepicker.it.js new file mode 100644 index 0000000..e0abc60 --- /dev/null +++ b/js/locales/bootstrap-datepicker.it.js @@ -0,0 +1,13 @@ +/** + * Spanish translation for bootstrap-datepicker + * Bruno Bonamin + */ +;(function($){ + $.fn.datepicker.dates['it'] = { + days: ["Domenica", "Lunedi", "Martedi", "Mercoledi", "Giovedi", "Venerdi", "Sabato", "Domenica"], + daysShort: ["Dom", "Lun", "Mar", "Mer", "Gio", "Ven", "Sab", "Dom"], + daysMin: ["Do", "Lu", "Ma", "Me", "Gi", "Ve", "Sa", "Do"], + months: ["Gennaio", "Febbraio", "Marzo", "Aprile", "Maggio", "Giugno", "Luglio", "Agosto", "Settembre", "Ottobre", "Novembre", "Dicembre"], + monthsShort: ["Gen", "Feb", "Mar", "Apr", "Mag", "Giu", "Lug", "Ago", "Set", "Ott", "Nov", "Dic"] + }; +}(jQuery)); From 198d6d34b2c9cb33b7d8cf6f7b9ffff033d50b33 Mon Sep 17 00:00:00 2001 From: Victor Taranenko Date: Tue, 10 Apr 2012 15:20:28 +0700 Subject: [PATCH 03/13] add russian translation --- js/locales/bootstrap-datepicker.ru.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 js/locales/bootstrap-datepicker.ru.js diff --git a/js/locales/bootstrap-datepicker.ru.js b/js/locales/bootstrap-datepicker.ru.js new file mode 100644 index 0000000..1b5565e --- /dev/null +++ b/js/locales/bootstrap-datepicker.ru.js @@ -0,0 +1,13 @@ +/** + * Russian translation for bootstrap-datepicker + * Victor Taranenko + */ +;(function($){ + $.fn.datepicker.dates['ru'] = { + days: ["Воскресенье", "Понедельник", "Вторник", "Среда", "Четверг", "Пятница", "Суббота", "Воскресенье"], + daysShort: ["Вск", "Пнд", "Втр", "Срд", "Чтв", "Птн", "Суб", "Вск"], + daysMin: ["Вс", "Пн", "Вт", "Ср", "Чт", "Пт", "Сб", "Вс"], + months: ["Январь", "Февраль", "Март", "Апрель", "Май", "Июнь", "Июль", "Август", "Сентябрь", "Октябрь", "Ноябрь", "Декабрь"], + monthsShort: ["Янв", "Фев", "Мар", "Апр", "Май", "Июн", "Июл", "Авг", "Сен", "Окт", "Ноя", "Дек"] + }; +}(jQuery)); \ No newline at end of file From e42149a810516f615885ee11a2b5859dfc2b8bd8 Mon Sep 17 00:00:00 2001 From: Christian Pedersen Date: Tue, 10 Apr 2012 13:35:26 +0200 Subject: [PATCH 04/13] Added danish translation --- js/locales/bootstrap-datepicker.da.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 js/locales/bootstrap-datepicker.da.js diff --git a/js/locales/bootstrap-datepicker.da.js b/js/locales/bootstrap-datepicker.da.js new file mode 100644 index 0000000..33aaf61 --- /dev/null +++ b/js/locales/bootstrap-datepicker.da.js @@ -0,0 +1,13 @@ +/** + * Danish translation for bootstrap-datepicker + * Christian Pedersen + */ +;(function($){ + $.fn.datepicker.dates['da'] = { + days: ["Søndag", "Mandag", "Tirsdag", "Onsdag", "Torsdag", "Fredag", "Lørdag", "Søndag"], + daysShort: ["Søn", "Man", "Tir", "Ons", "Tor", "Fre", "Lør", "Søn"], + daysMin: ["Sø", "Ma", "Ti", "On", "To", "Fr", "Lø", "Sø"], + months: ["Januar", "Februar", "Marts", "April", "Maj", "Juni", "Juli", "August", "September", "Oktober", "November", "December"], + monthsShort: ["Jan", "Feb", "Mar", "Apr", "Maj", "Jun", "Jul", "Aug", "Sep", "Okt", "Nov", "Dec"] + }; +}(jQuery)); \ No newline at end of file From 61c2dd6d49c74270c36e28d0e24073929e00b1ef Mon Sep 17 00:00:00 2001 From: Enrico Rubboli Date: Tue, 10 Apr 2012 16:44:17 +0200 Subject: [PATCH 05/13] fix header comments --- js/locales/bootstrap-datepicker.it.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/js/locales/bootstrap-datepicker.it.js b/js/locales/bootstrap-datepicker.it.js index e0abc60..8b9f885 100644 --- a/js/locales/bootstrap-datepicker.it.js +++ b/js/locales/bootstrap-datepicker.it.js @@ -1,6 +1,6 @@ /** - * Spanish translation for bootstrap-datepicker - * Bruno Bonamin + * Italian translation for bootstrap-datepicker + * Enrico Rubboli */ ;(function($){ $.fn.datepicker.dates['it'] = { From 7b406db4451c1b8b2e29f38174978ef09d686e03 Mon Sep 17 00:00:00 2001 From: Andrew Rowls Date: Sun, 15 Apr 2012 15:36:36 -0400 Subject: [PATCH 06/13] Provide build .less file to produce standalone .css file --HG-- rename : build.less => build/build.less --- README.md | 6 ++- build.less => build/build.less | 9 ++--- build/build_standalone.less | 69 ++++++++++++++++++++++++++++++++++ 3 files changed, 77 insertions(+), 7 deletions(-) rename build.less => build/build.less (88%) create mode 100644 build/build_standalone.less diff --git a/README.md b/README.md index 21ae17e..f27ca20 100644 --- a/README.md +++ b/README.md @@ -90,7 +90,11 @@ Call the datepicker via javascript: ## Dependencies -Requires bootstrap's dropdown component (`dropdowns.less`). +Requires bootstrap's dropdown component (`dropdowns.less`) for some styles, and bootstrap's sprites (`sprites.less` and associated images) for arrows. + +A standalone .css file (including necessary dropdown styles and alternative, text-based arrows) can be generated by running `build/build_standalone.less` through the `lessc` compiler: + + $ lessc build/build_standalone.less datepicker.css ## Options diff --git a/build.less b/build/build.less similarity index 88% rename from build.less rename to build/build.less index f6b3415..2a5326c 100644 --- a/build.less +++ b/build/build.less @@ -1,13 +1,10 @@ -// Datepicker .css buildfile. Includes select mixins/variables from bootstrap +// Datepicker .less buildfile. Includes select mixins/variables from bootstrap // and imports the included datepicker.less to output a minimal datepicker.css // // Usage: -// lessc build.css css/datepicker.css +// lessc build.less datepicker.css // // Variables and mixins copied from bootstrap 2.0.2 -// -// Mixins must be included individually, else some (eg, .clearfix) will be -// included in the built .css // Variables @grayLight: #999; @@ -65,4 +62,4 @@ } } -@import "less/datepicker.less"; +@import "../less/datepicker.less"; diff --git a/build/build_standalone.less b/build/build_standalone.less new file mode 100644 index 0000000..b0dc24b --- /dev/null +++ b/build/build_standalone.less @@ -0,0 +1,69 @@ +// Datepicker standalone .less buildfile. Includes all necessary mixins/variables/rules from bootstrap +// and imports the included datepicker.less to output a minimal standalone datepicker.css +// +// Usage: +// lessc build_standalone.less datepicker.css +// +// Variables, mixins, and rules copied from bootstrap 2.0.2 + +@import "build.less"; + +// Dropdown css + +@zindexDropdown: 1000; +@grayDark: #333; +@baseLineHeight: 18px; +@tableBackground: transparent; // overall background-color +@dropdownBackground: @white; +@dropdownBorder: rgba(0,0,0,.2); +@dropdownLinkColor: @grayDark; +@dropdownLinkColorHover: @white; +@dropdownLinkBackgroundHover: @linkColor; + +// Drop shadows +.box-shadow(@shadow) { + -webkit-box-shadow: @shadow; + -moz-box-shadow: @shadow; + box-shadow: @shadow; +} + +// The dropdown menu (ul) +// ---------------------- +.datepicker.dropdown-menu { + position: absolute; + top: 100%; + left: 0; + z-index: @zindexDropdown; + float: left; + display: none; // none by default, but block on "open" of the menu + min-width: 160px; + list-style: none; + background-color: @dropdownBackground; + border: 1px solid #ccc; + border: 1px solid rgba(0,0,0,.2); + .border-radius(5px); + .box-shadow(0 5px 10px rgba(0,0,0,.2)); + -webkit-background-clip: padding-box; + -moz-background-clip: padding; + background-clip: padding-box; + *border-right-width: 2px; + *border-bottom-width: 2px; + + // Normally inherited from bootstrap's `body` + color: #333333; + font-family: "Helvetica Neue",Helvetica,Arial,sans-serif; + font-size:13px; + line-height: @baseLineHeight; + + th, td { + padding: 4px 5px; + } +} + +// Alternative arrows +// May require `charset="UTF-8"` in your `` tag +.datepicker { + .prev, .next {font-style:normal;} + .prev:after {content:"«";} + .next:after {content:"»";} +} From 9e1969d92e9712ebfa208cf080431de97e17c91c Mon Sep 17 00:00:00 2001 From: Andrew Rowls Date: Sun, 15 Apr 2012 21:07:42 -0400 Subject: [PATCH 07/13] Trigger changeDate on keyboard navigation --- js/bootstrap-datepicker.js | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/js/bootstrap-datepicker.js b/js/bootstrap-datepicker.js index 9f897b9..4f50b29 100644 --- a/js/bootstrap-datepicker.js +++ b/js/bootstrap-datepicker.js @@ -475,7 +475,8 @@ this.show(); return; } - var dir, day, month; + var dateChanged = false, + dir, day, month; switch(e.keyCode){ case 27: // escape this.hide(); @@ -497,6 +498,7 @@ this.setValue(); this.update(); e.preventDefault(); + dateChanged = true; break; case 38: // up case 40: // down @@ -514,12 +516,28 @@ this.setValue(); this.update(); e.preventDefault(); + dateChanged = true; break; case 13: // enter this.hide(); e.preventDefault(); break; } + if (dateChanged){ + this.element.trigger({ + type: 'changeDate', + date: this.date + }); + var element; + if (this.isInput) { + element = this.element; + } else if (this.component){ + element = this.element.find('input'); + } + if (element) { + element.change(); + } + } }, showMode: function(dir) { From cbef138e0aef60d081c245b9a46f15fd86bca39b Mon Sep 17 00:00:00 2001 From: Andrew Rowls Date: Sun, 15 Apr 2012 22:43:23 -0400 Subject: [PATCH 08/13] Don't split with regexes - tricky cross-browser breakages http://blog.stevenlevithan.com/archives/cross-browser-split --- js/bootstrap-datepicker.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/js/bootstrap-datepicker.js b/js/bootstrap-datepicker.js index 4f50b29..797ec18 100644 --- a/js/bootstrap-datepicker.js +++ b/js/bootstrap-datepicker.js @@ -602,7 +602,9 @@ validParts: /dd?|mm?|MM?|yy(?:yy)?/g, nonpunctuation: /[^ -\/:-@\[-`{-~\t\n\r]+/g, parseFormat: function(format){ - var separators = format.split(this.validParts), + // IE treats \0 as a string end in inputs (truncating the value), + // so it's a bad format delimiter, anyway + var separators = format.replace(this.validParts, '\0').split('\0'), parts = format.match(this.validParts); if (!separators || !separators.length || !parts || parts.length == 0){ throw new Error("Invalid date format."); From fd9eb6bb7e9a9785f960b3ff98aac105df5e3d32 Mon Sep 17 00:00:00 2001 From: Reinier Goltstein Date: Tue, 17 Apr 2012 10:35:43 +0200 Subject: [PATCH 09/13] Added Dutch localization --- js/locales/bootstrap-datepicker.nl.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 js/locales/bootstrap-datepicker.nl.js diff --git a/js/locales/bootstrap-datepicker.nl.js b/js/locales/bootstrap-datepicker.nl.js new file mode 100644 index 0000000..cf5413b --- /dev/null +++ b/js/locales/bootstrap-datepicker.nl.js @@ -0,0 +1,13 @@ +/** + * Dutch translation for bootstrap-datepicker + * Reinier Goltstein + */ +;(function($){ + $.fn.datepicker.dates['nl'] = { + days: ["Zondag", "Maandag", "Dinsdag", "Woensdag", "Donderdag", "Vrijdag", "Zaterdag", "Zondag"], + daysShort: ["Zo", "Ma", "Di", "Wo", "Do", "Vr", "Za", "Zo"], + daysMin: ["Zo", "Ma", "Di", "Wo", "Do", "Vr", "Za", "Zo"], + months: ["Januari", "Februari", "Maart", "April", "Mei", "Juni", "Juli", "Augustus", "September", "Oktober", "November", "December"], + monthsShort: ["Jan", "Feb", "Mrt", "Apr", "Mei", "Jun", "Jul", "Aug", "Sep", "Okt", "Nov", "Dec"] + }; +}(jQuery)); From 5c854dff6c219f5b72ed6b42fb7ca136a11e80ff Mon Sep 17 00:00:00 2001 From: Phoenix Zerin Date: Sat, 21 Apr 2012 15:53:52 -0500 Subject: [PATCH 10/13] Handle string and unusual values for weekStart non-catastrophically. --- js/bootstrap-datepicker.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/js/bootstrap-datepicker.js b/js/bootstrap-datepicker.js index 797ec18..cbc7a1a 100644 --- a/js/bootstrap-datepicker.js +++ b/js/bootstrap-datepicker.js @@ -75,8 +75,8 @@ break; } - this.weekStart = options.weekStart||this.element.data('date-weekstart')||dates[this.language].weekStart||0; - this.weekEnd = this.weekStart == 0 ? 6 : this.weekStart - 1; + this.weekStart = parseInt(options.weekStart||this.element.data('date-weekstart')||dates[this.language].weekStart||0); + this.weekEnd = ((this.weekStart + 6) % 7); this.startDate = -Infinity; this.endDate = Infinity; this.setStartDate(options.startDate||this.element.data('date-startdate')); From f0067a438be6d7ff0c8d7e559243c43f746a7ead Mon Sep 17 00:00:00 2001 From: Phoenix Zerin Date: Sat, 21 Apr 2012 16:03:11 -0500 Subject: [PATCH 11/13] Implicitly convert weekStart to an int and mod by 7 to prevent weird values from destroying the integrity of the calendar. --- js/bootstrap-datepicker.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/bootstrap-datepicker.js b/js/bootstrap-datepicker.js index cbc7a1a..f979330 100644 --- a/js/bootstrap-datepicker.js +++ b/js/bootstrap-datepicker.js @@ -75,7 +75,7 @@ break; } - this.weekStart = parseInt(options.weekStart||this.element.data('date-weekstart')||dates[this.language].weekStart||0); + this.weekStart = ((options.weekStart||this.element.data('date-weekstart')||dates[this.language].weekStart||0) % 7); this.weekEnd = ((this.weekStart + 6) % 7); this.startDate = -Infinity; this.endDate = Infinity; From 03ec433bf2d93a152e14ed3b4f9dec8f62c12683 Mon Sep 17 00:00:00 2001 From: Andrew Rowls Date: Sun, 22 Apr 2012 01:34:24 -0400 Subject: [PATCH 12/13] Accept language setting from data-attributes --- js/bootstrap-datepicker.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/js/bootstrap-datepicker.js b/js/bootstrap-datepicker.js index 797ec18..0b11da1 100644 --- a/js/bootstrap-datepicker.js +++ b/js/bootstrap-datepicker.js @@ -24,7 +24,8 @@ var Datepicker = function(element, options){ this.element = $(element); - this.language = options.language in dates ? options.language : "en"; + this.language = options.language||this.element.data('date-language')||"en"; + this.language = this.language in dates ? this.language : "en"; this.format = DPGlobal.parseFormat(options.format||this.element.data('date-format')||'mm/dd/yyyy'); this.picker = $(DPGlobal.template) .appendTo('body') From 90fd19122ee6a2e62ea3c578162f361a8f07f63e Mon Sep 17 00:00:00 2001 From: Anderson Fortaleza Date: Sun, 22 Apr 2012 13:21:57 -0300 Subject: [PATCH 13/13] Autoclose now woks for component datepicker --- js/bootstrap-datepicker.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/js/bootstrap-datepicker.js b/js/bootstrap-datepicker.js index 0b11da1..01c10b6 100644 --- a/js/bootstrap-datepicker.js +++ b/js/bootstrap-datepicker.js @@ -48,6 +48,10 @@ } else { if (this.component){ this.component.on('click', $.proxy(this.show, this)); + var element = this.element.find('input'); + element.on({ + blur: $.proxy(this._hide, this) + }) } else { this.element.on('click', $.proxy(this.show, this)); }