Fixed date picker
authorAlexander Ebert <ebert@woltlab.com>
Thu, 31 Jan 2013 00:04:09 +0000 (01:04 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Thu, 31 Jan 2013 00:04:09 +0000 (01:04 +0100)
wcfsetup/install/files/acp/templates/header.tpl
wcfsetup/install/files/js/WCF.js

index 43fad7faa62b01e2985b044340cadbd97f9563e7..0a0a3cc4201f378ee76693718db3b536e5f9ebcf 100644 (file)
                        {/if}
                        
                        WCF.Language.addObject({
+                               '__days': [ '{lang}wcf.date.day.sunday{/lang}', '{lang}wcf.date.day.monday{/lang}', '{lang}wcf.date.day.tuesday{/lang}', '{lang}wcf.date.day.wednesday{/lang}', '{lang}wcf.date.day.thursday{/lang}', '{lang}wcf.date.day.friday{/lang}', '{lang}wcf.date.day.saturday{/lang}' ],
+                               '__daysShort': [ '{lang}wcf.date.day.sun{/lang}', '{lang}wcf.date.day.mon{/lang}', '{lang}wcf.date.day.tue{/lang}', '{lang}wcf.date.day.wed{/lang}', '{lang}wcf.date.day.thu{/lang}', '{lang}wcf.date.day.fri{/lang}', '{lang}wcf.date.day.sat{/lang}' ],
+                               '__months': [ '{lang}wcf.date.month.january{/lang}', '{lang}wcf.date.month.february{/lang}', '{lang}wcf.date.month.march{/lang}', '{lang}wcf.date.month.april{/lang}', '{lang}wcf.date.month.may{/lang}', '{lang}wcf.date.month.june{/lang}', '{lang}wcf.date.month.july{/lang}', '{lang}wcf.date.month.august{/lang}', '{lang}wcf.date.month.september{/lang}', '{lang}wcf.date.month.october{/lang}', '{lang}wcf.date.month.november{/lang}', '{lang}wcf.date.month.december{/lang}' ], 
+                               '__monthsShort': [ '{lang}wcf.date.month.jan{/lang}', '{lang}wcf.date.month.feb{/lang}', '{lang}wcf.date.month.mar{/lang}', '{lang}wcf.date.month.apr{/lang}', '{lang}wcf.date.month.may{/lang}', '{lang}wcf.date.month.jun{/lang}', '{lang}wcf.date.month.jul{/lang}', '{lang}wcf.date.month.aug{/lang}', '{lang}wcf.date.month.sep{/lang}', '{lang}wcf.date.month.oct{/lang}', '{lang}wcf.date.month.nov{/lang}', '{lang}wcf.date.month.dec{/lang}' ],
                                'wcf.global.button.add': '{lang}wcf.global.button.add{/lang}',
                                'wcf.global.button.cancel': '{lang}wcf.global.button.cancel{/lang}',
                                'wcf.global.button.close': '{lang}wcf.global.button.close{/lang}',
@@ -60,8 +64,8 @@
                                'wcf.date.relative.minutes': '{capture assign=relativeMinutes}{lang}wcf.date.relative.minutes{/lang}{/capture}{@$relativeMinutes|encodeJS}',
                                'wcf.date.relative.hours': '{capture assign=relativeHours}{lang}wcf.date.relative.hours{/lang}{/capture}{@$relativeHours|encodeJS}',
                                'wcf.date.relative.pastDays': '{capture assign=relativePastDays}{lang}wcf.date.relative.pastDays{/lang}{/capture}{@$relativePastDays|encodeJS}',
+                               'wcf.date.dateFormat': '{lang}wcf.date.dateFormat{/lang}',
                                'wcf.date.dateTimeFormat': '{lang}wcf.date.dateTimeFormat{/lang}',
-                               '__days': [ '{lang}wcf.date.day.sunday{/lang}', '{lang}wcf.date.day.monday{/lang}', '{lang}wcf.date.day.tuesday{/lang}', '{lang}wcf.date.day.wednesday{/lang}', '{lang}wcf.date.day.thursday{/lang}', '{lang}wcf.date.day.friday{/lang}', '{lang}wcf.date.day.saturday{/lang}' ],
                                'wcf.global.thousandsSeparator': '{capture assign=thousandsSeparator}{lang}wcf.global.thousandsSeparator{/lang}{/capture}{@$thousandsSeparator|encodeJS}',
                                'wcf.global.decimalPoint': '{capture assign=decimalPoint}{lang}wcf.global.decimalPoint{/lang}{/capture}{$decimalPoint|encodeJS}',
                                'wcf.global.page.next': '{capture assign=pageNext}{lang}wcf.global.page.next{/lang}{/capture}{@$pageNext|encodeJS}',
index e8fc12cd0a6b78361bc22c13831cf6a9d94d0c22..8bc92d20c700834cf1c08e4c9e5831182fff426c 100755 (executable)
@@ -2104,8 +2104,6 @@ WCF.Date.Picker = {
         * Convert PHPs date() format to jQuery UIs date picker format.
         */
        _convertDateFormat: function() {
-               var format = WCF.Language.get('wcf.date.dateFormat');
-               
                // replacement table
                // format of PHP date() => format of jQuery UI date picker
                //
@@ -2120,7 +2118,7 @@ WCF.Date.Picker = {
                // W    ISO-8601 week number of year, weeks starting on Monday
                // t    Number of days in the given month
                // L    Whether it's a leap year
-               var replacementTable = {
+               var $replacementTable = {
                        // day
                        'd': 'dd',
                        'D': 'D',
@@ -2146,12 +2144,13 @@ WCF.Date.Picker = {
                // do the actual replacement
                // this is not perfect, but a basic implementation and should work in 99% of the cases
                // TODO: support literals (magics are escaped in PHP date() by an \, in jQuery UI DatePicker they are enclosed in '')
-               this._dateFormat = format.replace(/([^dDjlzFmMnoYyU\\]*(?:\\.[^dDjlzFmMnoYyU\\]*)*)([dDjlzFmMnoYyU])/g, function(match, part1, part2, offset, string) {
-                       $.each(replacementTable, function(key, item) {
-                               if(part2 == key) {
-                                       part2 = item;
+               this._dateFormat = WCF.Language.get('wcf.date.dateFormat').replace(/([^dDjlzFmMnoYyU\\]*(?:\\.[^dDjlzFmMnoYyU\\]*)*)([dDjlzFmMnoYyU])/g, function(match, part1, part2, offset, string) {
+                       for (var $key in $replacementTable) {
+                               if (part2 == $key) {
+                                       part2 = $replacementTable[$key];
                                }
-                       });
+                       }
+                       
                        return part1 + part2;
                });
        },
@@ -2162,36 +2161,34 @@ WCF.Date.Picker = {
        _initDatePicker: function() {
                $('input[type=date]:not(.jsDatePicker)').each($.proxy(function(index, input) {
                        var $input = $(input);
-                       var inputName = $input.prop('name');
-                       var inputValue = $input.prop('value'); // should be Y-m-d, must be interpretable by Date
+                       var $inputName = $input.prop('name');
+                       var $inputValue = $input.prop('value'); // should be Y-m-d, must be interpretable by Date
                        
                        // update $input
                        $input.prop('type', 'text').addClass('jsDatePicker');
                        
                        // insert a hidden element representing the actual date
-                       $input.prop('name', inputName + 'Text')
-                       $input.before('<input type="hidden" id="' + $input.prop('id') + 'DatePicker" name="' + inputName + '" value="' + inputValue + '" />');
+                       $input.removeAttr('name');
+                       $input.before('<input type="hidden" id="' + $input.wcfIdentify() + 'DatePicker" name="' + $inputName + '" value="' + $inputValue + '" />');
                        
                        // init date picker
                        $input.datepicker({
+                               altField: '#' + $input.wcfIdentify() + 'DatePicker',
+                               altFormat: 'yy-mm-dd', // PHPs strtotime() understands this best
                                changeMonth: true,
                                changeYear: true,
-                               showOtherMonths: true,
                                dateFormat: this._dateFormat,
-                               yearRange: '1900:2038', // TODO: make it configurable?
-                               
-                               altField: '#' + $input.prop('id') + 'DatePicker',
-                               altFormat: 'yy-mm-dd', // PHPs strtotime() understands this best
-                               
                                dayNames: WCF.Language.get('__days'),
                                dayNamesMin: WCF.Language.get('__daysShort'),
                                dayNamesShort: WCF.Language.get('__daysShort'),
                                monthNames: WCF.Language.get('__months'),
-                               monthNamesShort: WCF.Language.get('__monthsShort')
+                               monthNamesShort: WCF.Language.get('__monthsShort'),
+                               showOtherMonths: true,
+                               yearRange: '1900:2038'
                        });
                        
                        // format default date
-                       $input.datepicker('setDate', new Date(inputValue));
+                       $input.datepicker('setDate', new Date($inputValue));
                        
                        // bug workaround: setDate creates the widget but unfortunately doesn't hide it...
                        $input.datepicker('widget').hide();