Changeset 30632 for branches/2.7/admin
- Timestamp:
- Nov 30, 2014, 6:40:10 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2.7/admin/themes/default/js/datepicker.js
r30111 r30632 1 (function($) { 1 2 jQuery.timepicker.log = jQuery.noop; // that's ugly, but the timepicker is acting weird and throws parsing errors 2 3 4 5 // modify DatePicker internal methods to replace year select by a numeric input 6 var origGenerateMonthYearHeader = $.datepicker._generateMonthYearHeader, 7 origSelectMonthYear = $.datepicker._selectMonthYear; 8 9 $.datepicker._generateMonthYearHeader = function(inst, drawMonth, drawYear, minDate, maxDate, 10 secondary, monthNames, monthNamesShort) { 11 12 var html = origGenerateMonthYearHeader.call(this, inst, drawMonth, drawYear, minDate, maxDate, 13 secondary, monthNames, monthNamesShort); 14 15 var yearshtml = "<input type='number' class='ui-datepicker-year' data-handler='selectYear' data-event='change keyup' value='"+drawYear+"' style='width:4em;margin-left:2px;'>"; 16 17 return html.replace(new RegExp('<select class=\'ui-datepicker-year\'.*</select>', 'gm'), yearshtml); 18 }; 19 20 $.datepicker._selectMonthYear = debounce(function(id, select, period) { 21 if (period === 'M') { 22 origSelectMonthYear.call(this, id, select, period); 23 } 24 else { 25 var target = $(id), 26 inst = this._getInst(target[0]), 27 val = parseInt(select.value, 10); 28 29 if (isNaN(val)) { 30 inst['drawYear'] = ''; 31 } 32 else { 33 var pos = getCursor($('.ui-datepicker-year')[0]); 34 35 inst['selectedYear'] = inst['drawYear'] = val; 36 37 this._notifyChange(inst); 38 this._adjustDate(target); 39 40 $('.ui-datepicker-year').focus(); 41 42 setCursor($('.ui-datepicker-year')[0], pos); 43 } 44 } 45 }, 500); 46 47 48 // plugin definition 3 49 jQuery.fn.pwgDatepicker = function(settings) { 4 50 var options = jQuery.extend(true, { … … 14 60 linked = !!$target.length, 15 61 $start, $end; 16 62 17 63 if (linked) { 18 64 originalValue = $target.val(); … … 23 69 if (date === '') date = null; 24 70 $this.datetimepicker('setDate', date); 25 71 26 72 if ($this.data('datepicker-start') && $start) { 27 73 $start.datetimepicker('option', 'maxDate', date); … … 32 78 } 33 79 } 34 80 35 81 if (!date && linked) { 36 82 $target.val(''); … … 44 90 var buttonPane = $this.datepicker('widget') 45 91 .find('.ui-datepicker-buttonpane'); 46 92 47 93 if (buttonPane.find('.pwg-datepicker-cancel').length == 0) { 48 94 $('<button type="button">'+ options.cancelButton +'</button>') … … 62 108 dateFormat: linked ? 'DD d MM yy' : 'yy-mm-dd', 63 109 timeFormat: 'HH:mm', 64 110 65 111 altField: linked ? $target : null, 66 112 altFormat: 'yy-mm-dd', 67 113 altTimeFormat: options.showTimepicker ? 'HH:mm:ss' : '', 68 114 69 115 autoSize: true, 70 116 changeMonth : true, 71 117 changeYear: true, 72 yearRange: 'c-80:c+20',73 118 altFieldTimeOnly: false, 74 119 showSecond: false, 75 120 alwaysSetTime: false 76 121 }, options)); 77 122 78 123 // attach range pickers 79 124 if ($this.data('datepicker-start')) { 80 125 $start = jQuery('[data-datepicker="'+ $this.data('datepicker-start') +'"]'); 81 126 82 127 $this.datetimepicker('option', 'onClose', function(date) { 83 128 $start.datetimepicker('option', 'maxDate', date); 84 129 }); 85 130 86 131 $this.datetimepicker('option', 'minDate', $start.datetimepicker('getDate')); 87 132 } 88 133 else if ($this.data('datepicker-end')) { 89 134 $end = jQuery('[data-datepicker="'+ $this.data('datepicker-end') +'"]'); 90 135 91 136 $this.datetimepicker('option', 'onClose', function(date) { 92 137 $end.datetimepicker('option', 'minDate', date); 93 138 }); 94 139 } 95 140 96 141 // attach unset button 97 142 if ($this.data('datepicker-unset')) { … … 101 146 }); 102 147 } 103 148 104 149 // set value from linked input 105 150 if (linked) { … … 115 160 } 116 161 } 117 162 118 163 originalDate = $this.datetimepicker('getDate'); 119 164 120 165 // autoSize not handled by timepicker 121 166 if (options.showTimepicker) { … … 124 169 }); 125 170 }; 171 172 173 // functions for custom year input 174 function setCursor(node,pos){ 175 var node = (typeof node == "string" || node instanceof String) ? document.getElementById(node) : node; 176 177 if (!node) { 178 return false; 179 } 180 else if(node.createTextRange) { 181 var textRange = node.createTextRange(); 182 textRange.collapse(true); 183 textRange.moveEnd(pos); 184 textRange.moveStart(pos); 185 textRange.select(); 186 return true; 187 } 188 else if(node.setSelectionRange) { 189 node.setSelectionRange(pos,pos); 190 return true; 191 } 192 193 return false; 194 } 195 196 function getCursor(input) { 197 // Internet Explorer Caret Position (TextArea) 198 if (document.selection && document.selection.createRange) { 199 var range = document.selection.createRange(); 200 var bookmark = range.getBookmark(); 201 return bookmark.charCodeAt(2) - 2; 202 } 203 else { 204 // Firefox Caret Position (TextArea) 205 if (input.setSelectionRange) 206 return input.selectionStart; 207 } 208 209 return 0; 210 } 211 212 function debounce(func, wait, immediate) { 213 var timeout; 214 return function() { 215 var context = this, args = arguments; 216 var later = function() { 217 timeout = null; 218 if (!immediate) func.apply(context, args); 219 }; 220 var callNow = immediate && !timeout; 221 clearTimeout(timeout); 222 timeout = setTimeout(later, wait); 223 if (callNow) func.apply(context, args); 224 }; 225 } 226 227 }(jQuery));
Note: See TracChangeset
for help on using the changeset viewer.