1 2/** 3 * jquery-simple-datetimepicker (jquery.simple-dtpicker.js) 4 * v1.12.0 5 * (c) Masanori Ohgita - 2014. 6 * https://github.com/mugifly/jquery-simple-datetimepicker 7 */ 8 9 (function($) { 10 var lang = { 11 en: { 12 days: ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa'], 13 months: [ "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" ], 14 sep: '-', 15 format: 'YYYY-MM-DD hh:mm', 16 prevMonth: 'Previous month', 17 nextMonth: 'Next month', 18 today: 'Today' 19 }, 20 ro:{ 21 days: ['Dum', 'Lun', 'Mar', 'Mie', 'Joi', 'Vin', 'Sâm'], 22 months: ['Ian', 'Feb', 'Mar', 'Apr', 'Mai', 'Iun', 'Iul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'], 23 sep: '.', 24 format: 'DD.MM.YYYY hh:mm', 25 prevMonth: 'Luna precedentÄ', 26 nextMonth: 'Luna urmÄtoare', 27 today: 'Azi' 28 }, 29 30 ja: { 31 days: ['æ¥', 'æ', 'ç«', 'æ°´', 'æ¨', 'é', 'å'], 32 months: [ "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12" ], 33 sep: '/', 34 format: 'YYYY/MM/DD hh:mm' 35 }, 36 ru: { 37 days: ['ÐÑ', 'Ðн', 'ÐÑ', 'СÑ', 'ЧÑ', 'ÐÑ', 'Сб'], 38 months: [ "Янв", "Фев", "ÐаÑ", "ÐпÑ", "Ðай", "ÐÑн", "ÐÑл", "Ðвг", "Сен", "ÐкÑ", "ÐоÑ", "Ðек" ], 39 format: 'DD.MM.YYYY hh:mm' 40 }, 41 br: { 42 days: ['Dom', 'Seg', 'Ter', 'Qua', 'Qui', 'Sex', 'Sáb'], 43 months: [ "Janeiro", "Fevereiro", "Março", "Abril", "Maio", "Junho", "Julho", "Agosto", "Setembro", "Outubro", "Novembro", "Dezembro" ], 44 format: 'DD/MM/YYYY hh:mm' 45 }, 46 pt: { 47 days: ['dom', 'seg', 'ter', 'qua', 'qui', 'sex', 'sáb'], 48 months: [ "janeiro", "fevereiro", "março", "abril", "maio", "junho", "julho", "agosto", "setembro", "outubro", "novembro", "dezembro" ] 49 }, 50 cn: { 51 days: ['æ¥', 'ä¸', 'äº', 'ä¸', 'å', 'äº', 'å '], 52 months: [ "䏿", "äºæ", "䏿", "åæ", "äºæ", "å æ", "䏿", "å «æ", "乿", "åæ", "å䏿", "åäºæ" ] 53 }, 54 de: { 55 days: ['So', 'Mo', 'Di', 'Mi', 'Do', 'Fr', 'Sa'], 56 months: [ "Jan", "Feb", "März", "Apr", "Mai", "Juni", "Juli", "Aug", "Sept", "Okt", "Nov", "Dez" ], 57 format: 'DD.MM.YYYY hh:mm' 58 }, 59 sv: { 60 days: ['Sö', 'MÃ¥', 'Ti', 'On', 'To', 'Fr', 'Lö'], 61 months: [ "Jan", "Feb", "Mar", "Apr", "Maj", "Juni", "Juli", "Aug", "Sept", "Okt", "Nov", "Dec" ] 62 }, 63 id: { 64 days: ['Min','Sen','Sel', 'Rab', 'Kam', 'Jum', 'Sab'], 65 months: [ "Jan", "Feb", "Mar", "Apr", "Mei", "Jun", "Jul", "Agu", "Sep", "Okt", "Nov", "Des" ] 66 }, 67 it: { 68 days: ['Dom','Lun','Mar', 'Mer', 'Gio', 'Ven', 'Sab'], 69 months: [ "Gen", "Feb", "Mar", "Apr", "Mag", "Giu", "Lug", "Ago", "Set", "Ott", "Nov", "Dic" ], 70 format: 'DD/MM/YYYY hh:mm' 71 }, 72 tr: { 73 days: ['Pz', 'Pzt', 'Sal', 'Ãar', 'Per', 'Cu', 'Cts'], 74 months: [ "Ock", "Åub", "Mar", "Nis", "May", "Haz", "Tem", "Agu", "Eyl", "Ekm", "Kas", "Arlk" ] 75 }, 76 es: { 77 days: ['dom', 'lun', 'mar', 'miér', 'jue', 'vié', 'sáb'], 78 months: [ "ene", "feb", "mar", "abr", "may", "jun", "jul", "ago", "sep", "oct", "nov", "dic" ], 79 format: 'DD/MM/YYYY hh:mm' 80 }, 81 ko: { 82 days: ['ì¼', 'ì', 'í', 'ì', '목', 'ê¸', 'í '], 83 months: [ "1ì", "2ì", "3ì", "4ì", "5ì", "6ì", "7ì", "8ì", "9ì", "10ì", "11ì", "12ì" ] 84 }, 85 nl: { 86 days: ['zo', 'ma', 'di', 'wo', 'do', 'vr', 'za'], 87 months: [ "jan", "feb", "mrt", "apr", "mei", "jun", "jul", "aug", "sep", "okt", "nov", "dec" ], 88 format: 'DD-MM-YYYY hh:mm' 89 }, 90 cz: { 91 days: ['Ne', 'Po', 'Ãt', 'St', 'Ät', 'Pá', 'So'], 92 months: [ "Led", "Ãno", "BÅe", "Dub", "KvÄ", "Äer", "Ävc", "Srp", "ZáÅ", "ÅÃj", "Lis", "Pro" ], 93 format: 'DD.MM.YYYY hh:mm' 94 }, 95 fr: { 96 days: ['Dim', 'Lun', 'Mar', 'Mer', 'Jeu', 'Ven', 'Sam'], 97 months: [ "Janvier", "Février", "Mars", "Avril", "Mai", "Juin", "Juillet", "Août", "Septembre", "Octobre", "Novembre", "Décembre" ], 98 format: 'DD-MM-YYYY hh:mm' 99 }, 100 pl: { 101 days: ['N', 'Pn', 'Wt', 'År', 'Cz', 'Pt', 'So'], 102 months: [ "StyczeÅ", "Luty", "Marzec", "KwiecieÅ", "Maj", "Czerwiec", "Lipiec", "SierpieÅ", "WrzesieÅ", "Październik", "Listopad", "GrudzieÅ" ], 103 sep: '-', 104 format: 'YYYY-MM-DD hh:mm', 105 prevMonth: 'Poprzedni miesiÄ c', 106 nextMonth: 'NastÄpny miesiÄ c', 107 today: 'Dzisiaj' 108 }, 109 gr: { 110 days: ['ÎÏ ', 'Îε', 'ΤÏ', 'Τε', 'Πε', 'Πα', 'Σα'], 111 months: [ "Îαν", "Φεβ", "ÎαÏ", "ÎÏÏ", "ÎαÏ", "ÎÎ¿Ï Î½", "ÎÎ¿Ï Î»", "ÎÏ Î³", "ΣεÏ", "ÎκÏ", "Îοε", "Îεκ" ], 112 sep: '-', 113 format: 'DD-MM-YYYY hh:mm', 114 prevMonth: 'Î Ïοηγ. μήναÏ', 115 nextMonth: 'ÎÏÏμ. μήναÏ', 116 today: 'ΣήμεÏα' 117 } 118 }; 119 /* ----- */ 120 121 /** 122 PickerHandler Object 123 **/ 124 var PickerHandler = function($picker, $input){ 125 this.$pickerObject = $picker; 126 this.$inputObject = $input; 127 }; 128 129 /* Get a picker */ 130 PickerHandler.prototype.getPicker = function(){ 131 return this.$pickerObject; 132 }; 133 134 /* Get a input-field */ 135 PickerHandler.prototype.getInput = function(){ 136 return this.$inputObject; 137 }; 138 139 /* Get the display state of a picker */ 140 PickerHandler.prototype.isShow = function(){ 141 var is_show = true; 142 if (this.$pickerObject.css('display') == 'none') { 143 is_show = false;
144 } 145 return is_show; 146 }; 147 148 /* Show a picker */ 149 PickerHandler.prototype.show = function(){ 150 var $picker = this.$pickerObject; 151 var $input = this.$inputObject; 152 153 $picker.show(); 154 155 ActivePickerId = $input.data('pickerId'); 156 157 if ($input != null && $picker.data('isInline') === false) { // Float mode 158 // Relocate a picker to position of the appended input-field 159 this._relocate(); 160 } 161 }; 162 163 /* Hide a picker */ 164 PickerHandler.prototype.hide = function(){ 165 var $picker = this.$pickerObject; 166 var $input = this.$inputObject; 167 $picker.hide(); 168 }; 169 170 /* Get a selected date from a picker */ 171 PickerHandler.prototype.getDate = function(){ 172 var $picker = this.$pickerObject; 173 var $input = this.$inputObject; 174 return getPickedDate($picker); 175 }; 176 177 /* Set a specific date to a picker */ 178 PickerHandler.prototype.setDate = function(date){ 179 var $picker = this.$pickerObject; 180 var $input = this.$inputObject; 181 if (!isObj('Date', date)) { 182 date = new Date(date); 183 } 184 185 draw_date($picker, { 186 "isAnim": true, 187 "isOutputToInputObject": true 188 }, date); 189 }; 190 191 /* Destroy a picker */ 192 PickerHandler.prototype.destroy = function(){ 193 var $picker = this.$pickerObject; 194 var picker_id = $picker.data('pickerId'); 195 PickerObjects[picker_id] = null; 196 $picker.remove(); 197 }; 198 199 /* Relocate a picker to position of the appended input-field. */ 200 PickerHandler.prototype._relocate = function(){ 201 var $picker = this.$pickerObject; 202 var $input = this.$inputObject; 203 204 if ($input != null && $picker.data('isInline') === false) { // Float mode 205 // Move position of a picker - vertical 206 var input_outer_height = $input.outerHeight({'margin': true}); 207 if (!isObj('Number', input_outer_height)) { 208 input_outer_height = $input.outerHeight(); 209 } 210 var picker_outer_height = $picker.outerHeight({'margin': true}); 211 if (!isObj('Number', picker_outer_height)) { 212 picker_outer_height = $picker.outerHeight(); 213 } 214 215 if(parseInt($(window).height()) <= ($input.offset().top - $(document).scrollTop() + input_outer_height + picker_outer_height) ){ 216 // Display to top of an input-field 217 $picker.parent().css('top', ($input.offset().top - (input_outer_height / 2) - picker_outer_height) + 'px'); 218 } else { 219 // Display to bottom of an input-field 220 $picker.parent().css('top', ($input.offset().top + input_outer_height) + 'px'); 221 } 222 // Move position of a picker - horizontal 223 $picker.parent().css('left', $input.offset().left + 'px'); 224 // Display on most top of the z-index 225 $picker.parent().css('z-index', 100000); 226 } 227 }; 228 229 /* ----- */ 230 231 var PickerObjects = []; 232 var InputObjects = []; 233 var ActivePickerId = -1; 234 235 var getParentPickerObject = function(obj) { 236 return $(obj).closest('.datepicker'); 237 }; 238 239 var getPickersInputObject = function($obj) { 240 var $picker = getParentPickerObject($obj); 241 if ($picker.data("inputObjectId") != null) { 242 return $(InputObjects[$picker.data("inputObjectId")]); 243 } 244 return null; 245 }; 246 247 var setToNow = function($obj) { 248 var $picker = getParentPickerObject($obj); 249 var date = new Date(); 250 draw($picker, { 251 "isAnim": true, 252 "isOutputToInputObject": true 253 }, date.getFullYear(), date.getMonth(), date.getDate(), date.getHours(), date.getMinutes()); 254 }; 255 256 var beforeMonth = function($obj) { 257 var $picker = getParentPickerObject($obj); 258 259 if ($picker.data('stateAllowBeforeMonth') === false) { // Not allowed 260 return; 261 } 262 263 var date = getPickedDate($picker); 264 var targetMonth_lastDay = new Date(date.getFullYear(), date.getMonth(), 0).getDate(); 265 if (targetMonth_lastDay < date.getDate()) { 266 date.setDate(targetMonth_lastDay); 267 } 268 draw($picker, { 269 "isAnim": true, 270 "isOutputToInputObject": true 271 }, date.getFullYear(), date.getMonth() - 1, date.getDate(), date.getHours(), date.getMinutes()); 272 273 var todayDate = new Date(); 274 var isCurrentYear = todayDate.getFullYear() == date.getFullYear(); 275 var isCurrentMonth = isCurrentYear && todayDate.getMonth() == date.getMonth(); 276 277 if (!isCurrentMonth || !$picker.data("futureOnly")) { 278 if (targetMonth_lastDay < date.getDate()) { 279 date.setDate(targetMonth_lastDay); 280 } 281 draw($picker, { 282 "isAnim": true, 283 "isOutputToInputObject": true 284 }, date.getFullYear(), date.getMonth() - 1, date.getDate(), date.getHours(), date.getMinutes()); 285 } 286 }; 287 288 var nextMonth = function($obj) { 289 var $picker = getParentPickerObject($obj); 290 var date = getPickedDate($picker); 291 var targetMonth_lastDay = new Date(date.getFullYear(), date.getMonth() + 1, 0).getDate(); 292 if (targetMonth_lastDay < date.getDate()) { 293 date.setDate(targetMonth_lastDay); 294 } 295 296 // Check a last date of a next month 297 if (getLastDate(date.getFullYear(), date.getMonth() + 1) < date.getDate()) { 298 date.setDate(getLastDate(date.getFullYear(), date.getMonth() + 1)); 299 } 300 301 draw($picker, { 302 "isAnim": true, 303 "isOutputToInputObject": true 304 }, date.getFullYear(), date.getMonth() + 1, date.getDate(), date.getHours(), date.getMinutes()); 305 }; 306 307 /** 308 Check a last date of a specified year and month 309 **/ 310 var getLastDate = function(year, month) { 311 var date = new Date(year, month + 1, 0); 312 return date.getDate(); 313 }; 314 315 var getDateFormat = function(format, locale, is_date_only) { 316 if (format == "default"){ 317 // Default format 318 format = translate(locale,'format'); 319 if (is_date_only) { 320 // Convert the format to date-only (ex: YYYY/MM/DD) 321 format = format.substring(0, format.search(' ')); 322 } 323 } 324 return format; // Return date-format 325 }; 326 327 var normalizeYear = function (year) { 328 if (year < 99) { // change year for 4 digits 329 var date = new Date(); 330 return parseInt(year) + parseInt(date.getFullYear().toString().substr(0, 2) + "00"); 331 } 332 return year; 333 }; 334 335 var parseDate = function (str, opt_date_format) { 336 var re, m, date; 337 if(opt_date_format != null){ 338 // Parse date & time with date-format 339 340 // Match a string with date format 341 var df = opt_date_format.replace(/(-|\/)/g, '[-\/]') 342 .replace(/YYYY/gi, '(\\d{2,4})') 343 .replace(/(YY|MM|DD|hh|mm)/g, '(\\d{1,2})') 344 .replace(/(M|D|h|m)/g, '(\\d{1,2})'); 345 re = new RegExp(df); 346 m = re.exec(str); 347 if( m != null){ 348 349 // Generate the formats array (convert-table) 350 var formats = []; 351 var format_buf = ''; 352 var format_before_c = ''; 353 var df_ = opt_date_format; 354 while (df_ != null && 0 < df_.length) { 355 var format_c = df_.substring(0, 1); df_ = df_.substring(1, df_.length); 356 if (format_before_c != format_c) { 357 if(/(YYYY|YY|MM|DD|mm|dd|M|D|h|m)/.test(format_buf)){ 358 formats.push( format_buf ); 359 format_buf = ''; 360 } else { 361 format_buf = ''; 362 } 363 } 364 format_buf += format_c; 365 format_before_c = format_c; 366 } 367 if (format_buf !== '' && /(YYYY|YY|MM|DD|mm|dd|M|D|h|m)/.test(format_buf)){ 368 formats.push( format_buf ); 369 } 370 371 // Convert a string (with convert-table) to a date object 372 var year, month, day, hour, min; 373 var is_successful = false;
374 for(var i = 0; i < formats.length; i++){ 375 if(m.length < i){ 376 break; 377 } 378 379 var f = formats[i]; 380 var d = m[i+1]; // Matched part of date 381 if(f == 'YYYY'){ 382 year = normalizeYear(d); 383 is_successful = true; 384 } else if(f == 'YY'){ 385 year = parseInt(d) + 2000; 386 is_successful = true; 387 } else if(f == 'MM' || f == 'M'){ 388 month = parseInt(d) - 1; 389 is_successful = true; 390 } else if(f == 'DD' || f == 'D'){ 391 day = d; 392 is_successful = true; 393 } else if(f == 'hh' || f == 'h'){ 394 hour = d; 395 is_successful = true; 396 } else if(f == 'mm' || f == 'm'){ 397 min = d; 398 is_successful = true; 399 } 400 } 401 402 date = new Date(year, month, day, hour, min); 403 404 if(is_successful === true && isNaN(date) === false && isNaN(date.getDate()) === false){ // Parse successful 405 return date; 406 } 407 } 408 } 409 410 // Parse date & time with common format 411 re = /^(\d{2,4})[-\/](\d{1,2})[-\/](\d{1,2}) (\d{1,2}):(\d{1,2})$/; 412 m = re.exec(str); 413 if (m !== null) { 414 m[1] = normalizeYear(m[1]); 415 date = new Date(m[1], m[2] - 1, m[3], m[4], m[5]); 416 } else { 417 // Parse for date-only 418 re = /^(\d{2,4})[-\/](\d{1,2})[-\/](\d{1,2})$/; 419 m = re.exec(str); 420 if(m !== null) { 421 m[1] = normalizeYear(m[1]); 422 date = new Date(m[1], m[2] - 1, m[3]); 423 } 424 } 425 426 if(isNaN(date) === false && isNaN(date.getDate()) === false){ // Parse successful 427 return date; 428 } 429 return false; 430 }; 431 432 var getFormattedDate = function(date, date_format) { 433 if(date == null){ 434 date = new Date(); 435 } 436 437 var y = date.getFullYear(); 438 var m = date.getMonth() + 1; 439 var d = date.getDate(); 440 var hou = date.getHours(); 441 var min = date.getMinutes(); 442 443 date_format = date_format.replace(/YYYY/gi, y) 444 .replace(/YY/g, y - 2000)/* century */ 445 .replace(/MM/g, zpadding(m)) 446 .replace(/M/g, m) 447 .replace(/DD/g, zpadding(d)) 448 .replace(/D/g, d) 449 .replace(/hh/g, zpadding(hou)) 450 .replace(/h/g, hou) 451 .replace(/mm/g, zpadding(min)) 452 .replace(/m/g, min); 453 return date_format; 454 }; 455 456 var outputToInputObject = function($picker) { 457 var $inp = getPickersInputObject($picker); 458 if ($inp == null) { 459 return; 460 } 461 var date = getPickedDate($picker); 462 var locale = $picker.data("locale"); 463 var format = getDateFormat($picker.data("dateFormat"), locale, $picker.data('dateOnly')); 464 465 var old = $inp.val(); 466 $inp.val(getFormattedDate(date, format));
467 if (old != $inp.val()) { // only trigger if it actually changed to avoid a nasty loop condition 468 $inp.trigger("change"); 469 } 470 }; 471 472 var getPickedDate = function($obj) { 473 var $picker = getParentPickerObject($obj); 474 return $picker.data("pickedDate"); 475 }; 476 477 var zpadding = function(num) { 478 num = ("0" + num).slice(-2); 479 return num; 480 }; 481 482 var draw_date = function($picker, option, date) { 483 //console.log("draw_date - " + date.toString()); 484 draw($picker, option, date.getFullYear(), date.getMonth(), date.getDate(), date.getHours(), date.getMinutes()); 485 }; 486 var translate = function(locale, s) { 487 if (typeof lang[locale][s] !== "undefined"){ 488 return lang[locale][s]; 489 } 490 return lang.en[s]; 491 }; 492 var draw = function($picker, option, year, month, day, hour, min) { 493 var date = new Date(); 494 495 if (hour != null) { 496 date = new Date(year, month, day, hour, min, 0); 497 } else if (year != null) { 498 date = new Date(year, month, day); 499 } else { 500 date = new Date(); 501 } 502 503 /* Read options */ 504 var isTodayButton = $picker.data("todayButton"); 505 var isScroll = option.isAnim; /* It same with isAnim */ 506 if($picker.data("timelistScroll") === false) {// If disabled by user option. 507 isScroll = false; 508 } 509 510 var isAnim = option.isAnim; 511 if($picker.data("animation") === false){ // If disabled by user option. 512 isAnim = false; 513 } 514 515 var isFutureOnly = $picker.data("futureOnly"); 516 var minDate = $picker.data("minDate"); 517 var maxDate = $picker.data("maxDate"); 518 519 var isOutputToInputObject = option.isOutputToInputObject; 520 521 var minuteInterval = $picker.data("minuteInterval"); 522 var firstDayOfWeek = $picker.data("firstDayOfWeek"); 523 524 var allowWdays = $picker.data("allowWdays"); 525 if (allowWdays == null || isObj('Array', allowWdays) === false || allowWdays.length <= 0) { 526 allowWdays = null; 527 } 528 529 var minTime = $picker.data("minTime"); 530 var maxTime = $picker.data("maxTime"); 531 532 /* Check a specified date */ 533 var todayDate = new Date(); 534 if (isFutureOnly) { 535 if (date.getTime() < todayDate.getTime()) { // Already passed 536 date.setTime(todayDate.getTime()); 537 } 538 } 539 if(allowWdays != null && allowWdays.length <= 6) { 540 while (true) { 541 if ($.inArray(date.getDay(), allowWdays) == -1) { // Unallowed wday 542 // Slide a date 543 date.setDate(date.getDate() + 1); 544 } else { 545 break; 546 } 547 } 548 } 549 550 /* Read locale option */ 551 var locale = $picker.data("locale"); 552 if (!lang.hasOwnProperty(locale)) { 553 locale = 'en'; 554 } 555 556 /* Calculate dates */ 557 var firstWday = new Date(date.getFullYear(), date.getMonth(), 1).getDay() - firstDayOfWeek; 558 var lastDay = new Date(date.getFullYear(), date.getMonth() + 1, 0).getDate(); 559 var beforeMonthLastDay = new Date(date.getFullYear(), date.getMonth(), 0).getDate(); 560 var dateBeforeMonth = new Date(date.getFullYear(), date.getMonth(), 0); 561 var dateNextMonth = new Date(date.getFullYear(), date.getMonth() + 2, 0); 562 var isCurrentYear = todayDate.getFullYear() == date.getFullYear(); 563 var isCurrentMonth = isCurrentYear && todayDate.getMonth() == date.getMonth(); 564 var isCurrentDay = isCurrentMonth && todayDate.getDate() == date.getDate(); 565 var isPastMonth = false; 566 if (date.getFullYear() < todayDate.getFullYear() || (isCurrentYear && date.getMonth() < todayDate.getMonth())) { 567 isPastMonth = true; 568 } 569 570 /* Collect each part */ 571 var $header = $picker.children('.datepicker_header'); 572 var $inner = $picker.children('.datepicker_inner_container'); 573 var $calendar = $picker.children('.datepicker_inner_container').children('.datepicker_calendar'); 574 var $table = $calendar.children('.datepicker_table'); 575 var $timelist = $picker.children('.datepicker_inner_container').children('.datepicker_timelist'); 576 577 /* Grasp a point that will be changed */ 578 var changePoint = ""; 579 var oldDate = getPickedDate($picker); 580 if(oldDate != null){ 581 if(oldDate.getMonth() != date.getMonth() || oldDate.getDate() != date.getDate()){ 582 changePoint = "calendar"; 583 } else if (oldDate.getHours() != date.getHours() || oldDate.getMinutes() != date.getMinutes()){ 584 if(date.getMinutes() === 0 || date.getMinutes() % minuteInterval === 0){ 585 changePoint = "timelist"; 586 } 587 } 588 } 589
590 /* Save newly date to Picker data */ 591 $($picker).data("pickedDate", date); 592 593 /* Fade-out animation */ 594 if (isAnim === true) { 595 if(changePoint == "calendar"){ 596 $calendar.stop().queue([]); 597 $calendar.fadeTo("fast", 0.8); 598 }else if(changePoint == "timelist"){ 599 $timelist.stop().queue([]); 600 $timelist.fadeTo("fast", 0.8); 601 } 602 } 603 /* Remind timelist scroll state */ 604 var drawBefore_timeList_scrollTop = $timelist.scrollTop(); 605 606 /* New timelist */ 607 var timelist_activeTimeCell_offsetTop = -1; 608 609 /* Header ----- */ 610 $header.children().remove(); 611 612 var cDate = new Date(date.getTime()); 613 cDate.setMinutes(59); 614 cDate.setHours(23); 615 cDate.setSeconds(59); 616 cDate.setDate(0); // last day of previous month 617 618 var $link_before_month = null; 619 if ((!isFutureOnly || !isCurrentMonth) && ((minDate == null) || (minDate < cDate.getTime())) 620 ) { 621 $link_before_month = $('<a>'); 622 $link_before_month.text('<'); 623 $link_before_month.prop('alt', translate(locale,'prevMonth')); 624 $link_before_month.prop('title', translate(locale,'prevMonth') ); 625 $link_before_month.click(function() { 626 beforeMonth($picker); 627 }); 628 $picker.data('stateAllowBeforeMonth', true); 629 } else { 630 $picker.data('stateAllowBeforeMonth', false); 631 } 632 633 cDate.setMinutes(0); 634 cDate.setHours(0); 635 cDate.setSeconds(0); 636 cDate.setDate(1); // First day of next month 637 cDate.setMonth(date.getMonth() + 1); 638 639 var $now_month = $('<span>'); 640 $now_month.text(date.getFullYear() + " " + translate(locale, 'sep') + " " + translate(locale, 'months')[date.getMonth()]); 641 642 var $link_next_month = null; 643 if ((maxDate == null) || (maxDate > cDate.getTime())) { 644 $link_next_month = $('<a>'); 645 $link_next_month.text('>'); 646 $link_next_month.prop('alt', translate(locale,'nextMonth')); 647 $link_next_month.prop('title', translate(locale,'nextMonth')); 648 $link_next_month.click(function() { 649 nextMonth($picker); 650 }); 651 } 652 653 if (isTodayButton) { 654 var $link_today = $('<a/>'); 655 /* 656 This icon resource from a part of "FontAwesome" by Dave Gandy - http://fontawesome.io". 657 http://fortawesome.github.io/Font-Awesome/license/ 658 Thankyou. 659 */ 660 $link_today.html( decodeURIComponent('%3c%3fxml%20version%3d%221%2e0%22%20encoding%3d%22UTF%2d8%22%20standalone%3d%22no%22%3f%3e%3csvg%20%20xmlns%3adc%3d%22http%3a%2f%2fpurl%2eorg%2fdc%2felements%2f1%2e1%2f%22%20%20xmlns%3acc%3d%22http%3a%2f%2fcreativecommons%2eorg%2fns%23%22%20xmlns%3ardf%3d%22http%3a%2f%2fwww%2ew3%2eorg%2f1999%2f02%2f22%2drdf%2dsyntax%2dns%23%22%20%20xmlns%3asvg%3d%22http%3a%2f%2fwww%2ew3%2eorg%2f2000%2fsvg%22%20xmlns%3d%22http%3a%2f%2fwww%2ew3%2eorg%2f2000%2fsvg%22%20%20version%3d%221%2e1%22%20%20width%3d%22100%25%22%20%20height%3d%22100%25%22%20viewBox%3d%220%200%2010%2010%22%3e%3cg%20transform%3d%22translate%28%2d5%2e5772299%2c%2d26%2e54581%29%22%3e%3cpath%20d%3d%22m%2014%2e149807%2c31%2e130932%20c%200%2c%2d0%2e01241%200%2c%2d0%2e02481%20%2d0%2e0062%2c%2d0%2e03721%20L%2010%2e57723%2c28%2e153784%207%2e0108528%2c31%2e093719%20c%200%2c0%2e01241%20%2d0%2e0062%2c0%2e02481%20%2d0%2e0062%2c0%2e03721%20l%200%2c2%2e97715%20c%200%2c0%2e217084%200%2e1798696%2c0%2e396953%200%2e3969534%2c0%2e396953%20l%202%2e3817196%2c0%200%2c%2d2%2e38172%201%2e5878132%2c0%200%2c2%2e38172%202%2e381719%2c0%20c%200%2e217084%2c0%200%2e396953%2c%2d0%2e179869%200%2e396953%2c%2d0%2e396953%20l%200%2c%2d2%2e97715%20m%201%2e383134%2c%2d0%2e427964%20c%200%2e06823%2c%2d0%2e08063%200%2e05582%2c%2d0%2e210882%20%2d0%2e02481%2c%2d0%2e279108%20l%20%2d1%2e358324%2c%2d1%2e128837%200%2c%2d2%2e530576%20c%200%2c%2d0%2e111643%20%2d0%2e08683%2c%2d0%2e198477%20%2d0%2e198477%2c%2d0%2e198477%20l%20%2d1%2e190859%2c0%20c%20%2d0%2e111643%2c0%20%2d0%2e198477%2c0%2e08683%20%2d0%2e198477%2c0%2e198477%20l%200%2c1%2e209467%20%2d1%2e513384%2c%2d1%2e265289%20c%20%2d0%2e2605%2c%2d0%2e217083%20%2d0%2e682264%2c%2d0%2e217083%20%2d0%2e942764%2c0%20L%205%2e6463253%2c30%2e42386%20c%20%2d0%2e080631%2c0%2e06823%20%2d0%2e093036%2c0%2e198476%20%2d0%2e024809%2c0%2e279108%20l%200%2e3845485%2c0%2e458976%20c%200%2e031012%2c0%2e03721%200%2e080631%2c0%2e06203%200%2e1302503%2c0%2e06823%200%2e055821%2c0%2e0062%200%2e1054407%2c%2d0%2e01241%200%2e1488574%2c%2d0%2e04342%20l%204%2e2920565%2c%2d3%2e578782%204%2e292058%2c3%2e578782%20c%200%2e03721%2c0%2e03101%200%2e08063%2c0%2e04342%200%2e13025%2c0%2e04342%200%2e0062%2c0%200%2e01241%2c0%200%2e01861%2c0%200%2e04962%2c%2d0%2e0062%200%2e09924%2c%2d0%2e03101%200%2e130251%2c%2d0%2e06823%20l%200%2e384549%2c%2d0%2e458976%22%20%2f%3e%3c%2fg%3e%3c%2fsvg%3e') ); 661 $link_today.addClass('icon-home'); 662 $link_today.prop('alt', translate(locale,'today')); 663 $link_today.prop('title', translate(locale,'today')); 664 $link_today.click(function() { 665 setToNow($picker); 666 }); 667 $header.append($link_today); 668 } 669 670 if ($link_before_month != null) { 671 $header.append($link_before_month); 672 } 673 $header.append($now_month); 674 if ($link_next_month != null) { 675 $header.append($link_next_month); 676 } 677 678 /* Calendar > Table ----- */ 679 $table.children().remove(); 680 var $tr = $('<tr>'); 681 $table.append($tr); 682 683 /* Output wday cells */ 684 var firstDayDiff = 7 + firstDayOfWeek; 685 var daysOfWeek = translate(locale,'days'); 686 var $td; 687 for (var i = 0; i < 7; i++) { 688 $td = $('<th>'); 689 $td.text(daysOfWeek[((i + firstDayDiff) % 7)]); 690 $tr.append($td); 691 } 692 693 /* Output day cells */
694 var cellNum = Math.ceil((firstWday + lastDay) / 7) * 7; 695 i = 0; 696 if(firstWday < 0){ 697 i = -7; 698 } 699 var realDayObj = new Date(date.getTime()); 700 realDayObj.setHours(0); 701 realDayObj.setMinutes(0); 702 realDayObj.setSeconds(0); 703 for (var zz = 0; i < cellNum; i++) { 704 var realDay = i + 1 - firstWday; 705 706 var isPast = isPastMonth || (isCurrentMonth && realDay < todayDate.getDate()); 707 708 if (i % 7 === 0) { 709 $tr = $('<tr>'); 710 $table.append($tr); 711 } 712 713 $td = $('<td>'); 714 $td.data("day", realDay); 715 716 $tr.append($td); 717 718 if (firstWday > i) {/* Before months day */ 719 $td.text(beforeMonthLastDay + realDay); 720 $td.addClass('day_another_month'); 721 $td.data("dateStr", dateBeforeMonth.getFullYear() + "/" + (dateBeforeMonth.getMonth() + 1) + "/" + (beforeMonthLastDay + realDay)); 722 realDayObj.setDate(beforeMonthLastDay + realDay); 723 realDayObj.setMonth(dateBeforeMonth.getMonth() ); 724 realDayObj.setYear(dateBeforeMonth.getFullYear() ); 725 } else if (i < firstWday + lastDay) {/* Now months day */ 726 $td.text(realDay); 727 $td.data("dateStr", (date.getFullYear()) + "/" + (date.getMonth() + 1) + "/" + realDay); 728 realDayObj.setDate( realDay ); 729 realDayObj.setMonth( date.getMonth() ); 730 realDayObj.setYear( date.getFullYear() ); 731 } else {/* Next months day */ 732 $td.text(realDay - lastDay); 733 $td.addClass('day_another_month'); 734 $td.data("dateStr", dateNextMonth.getFullYear() + "/" + (dateNextMonth.getMonth() + 1) + "/" + (realDay - lastDay)); 735 realDayObj.setDate( realDay - lastDay ); 736 realDayObj.setMonth( dateNextMonth.getMonth() ); 737 realDayObj.setYear( dateNextMonth.getFullYear() ); 738 } 739 740 /* Check a wday */ 741 var wday = ((i + firstDayDiff) % 7); 742 if(allowWdays != null) { 743 if ($.inArray(wday, allowWdays) == -1) { 744 $td.addClass('day_in_unallowed'); 745 continue; // Skip 746 } 747 } else if (wday === 0) {/* Sunday */ 748 $td.addClass('wday_sun'); 749 } else if (wday == 6) {/* Saturday */ 750 $td.addClass('wday_sat'); 751 } 752 753 /* Set a special mark class */ 754 if (realDay == date.getDate()) { /* selected day */ 755 $td.addClass('active'); 756 } 757 758 if (isCurrentMonth && realDay == todayDate.getDate()) { /* today */ 759 $td.addClass('today'); 760 } 761 762 var realDayObjMN = new Date(realDayObj.getTime()); 763 realDayObjMN.setHours(23); 764 realDayObjMN.setMinutes(59); 765 realDayObjMN.setSeconds(59); 766 767 if ( 768 // compare to 23:59:59 on the current day (if MIN is 1pm, then we still need to show this day 769 ((minDate != null) && (minDate > realDayObjMN.getTime())) || ((maxDate != null) && (maxDate < realDayObj.getTime())) // compare to 00:00:00 770 ) { // Out of range day 771 $td.addClass('out_of_range'); 772 } else if (isFutureOnly && isPast) { // Past day 773 $td.addClass('day_in_past'); 774 } else { 775 /* Set event-handler to day cell */ 776 $td.click(function() { 777 if ($(this).hasClass('hover')) { 778 $(this).removeClass('hover'); 779 } 780 $(this).addClass('active'); 781 782 var $picker = getParentPickerObject($(this)); 783 var targetDate = new Date($(this).data("dateStr")); 784 var selectedDate = getPickedDate($picker); 785 draw($picker, { 786 "isAnim": false, 787 "isOutputToInputObject": true 788 }, targetDate.getFullYear(), targetDate.getMonth(), targetDate.getDate(), selectedDate.getHours(), selectedDate.getMinutes()); 789 if ($picker.data("dateOnly") === true && $picker.data("isInline") === false && $picker.data("closeOnSelected")){ 790 // Close a picker 791 ActivePickerId = -1; 792 $picker.hide(); 793 } 794 }); 795 796 $td.hover(function() { 797 if (! $(this).hasClass('active')) { 798 $(this).addClass('hover'); 799 } 800 }, function() { 801 if ($(this).hasClass('hover')) { 802 $(this).removeClass('hover'); 803 } 804 }); 805 } 806 807 /* ---- */ 808 } 809 810 if ($picker.data("dateOnly") === true) { 811 /* dateOnly mode */ 812 $timelist.css("display", "none"); 813 } else { 814 /* Timelist ----- */ 815 $timelist.children().remove(); 816 817 /* Set height to Timelist (Calendar innerHeight - Calendar padding) */
818 if ($calendar.innerHeight() > 0) { 819 $timelist.css("height", $calendar.innerHeight() - 10 + 'px'); 820 } 821 822 realDayObj = new Date(date.getTime()); 823 $timelist.css("height", $calendar.innerHeight() - 10 + 'px'); 824 825 /* Output time cells */ 826 var hour_ = minTime[0]; 827 var min_ = minTime[1]; 828 829 while( hour_*100+min_ < maxTime[0]*100+maxTime[1] ){ 830 831 var $o = $('<div>'); 832 var is_past_time = hour_ < todayDate.getHours() || (hour_ == todayDate.getHours() && min_ < todayDate.getMinutes()); 833 var is_past = isCurrentDay && is_past_time; 834 835 $o.addClass('timelist_item'); 836 $o.text(zpadding(hour_) + ":" + zpadding(min_)); 837 838 $o.data("hour", hour_); 839 $o.data("min", min_); 840 841 $timelist.append($o); 842 843 realDayObj.setHours(hour_); 844 realDayObj.setMinutes(min_); 845 846 if ( 847 ((minDate != null) && (minDate > realDayObj.getTime())) || ((maxDate != null) && (maxDate < realDayObj.getTime())) 848 ) { // Out of range cell 849 $o.addClass('out_of_range'); 850 } else if (isFutureOnly && is_past) { // Past cell 851 $o.addClass('time_in_past'); 852 } else { // Normal cell 853 /* Set event handler to time cell */ 854 $o.click(function() { 855 if ($(this).hasClass('hover')) { 856 $(this).removeClass('hover'); 857 } 858 $(this).addClass('active'); 859 860 var $picker = getParentPickerObject($(this)); 861 var date = getPickedDate($picker); 862 var hour = $(this).data("hour"); 863 var min = $(this).data("min"); 864 draw($picker, { 865 "isAnim": false, 866 "isOutputToInputObject": true 867 }, date.getFullYear(), date.getMonth(), date.getDate(), hour, min); 868 869 if ($picker.data("isInline") === false && $picker.data("closeOnSelected")){ 870 // Close a picker 871 ActivePickerId = -1; 872 $picker.hide(); 873 } 874 }); 875 876 $o.hover(function() { 877 if (! $(this).hasClass('active')) { 878 $(this).addClass('hover'); 879 } 880 }, function() { 881 if ($(this).hasClass('hover')) { 882 $(this).removeClass('hover'); 883 } 884 }); 885 } 886 887 if (hour_ == date.getHours() && min_ == date.getMinutes()) { /* selected time */ 888 $o.addClass('active'); 889 timelist_activeTimeCell_offsetTop = $o.offset().top; 890 } 891 892 min_ += minuteInterval; 893 if (min_ >= 60){ 894 min_ = min_ - 60; 895 hour_++; 896 } 897 898 } 899 900 /* Scroll the timelist */ 901 if(isScroll === true){ 902 /* Scroll to new active time-cell position */ 903 $timelist.scrollTop(timelist_activeTimeCell_offsetTop - $timelist.offset().top); 904 }else{ 905 /* Scroll to position that before redraw. */ 906 $timelist.scrollTop(drawBefore_timeList_scrollTop); 907 } 908 } 909 910 /* Fade-in animation */ 911 if (isAnim === true) { 912 if(changePoint == "calendar"){ 913 $calendar.fadeTo("fast", 1.0); 914 }else if(changePoint == "timelist"){ 915 $timelist.fadeTo("fast", 1.0); 916 } 917 } 918 919 /* Output to InputForm */ 920 if (isOutputToInputObject === true) { 921 outputToInputObject($picker); 922 } 923 }; 924 925 /* Check for object type */ 926 var isObj = function(type, obj) { 927 /* http://qiita.com/Layzie/items/465e715dae14e2f601de */ 928 var clas = Object.prototype.toString.call(obj).slice(8, -1); 929 return obj !== undefined && obj !== null && clas === type; 930 }; 931 932 var init = function($obj, opt) { 933 /* Container */ 934 var $picker = $('<div>'); 935 936 $picker.destroy = function() { 937 window.alert('destroy!'); 938 }; 939 940 $picker.addClass('datepicker'); 941 $obj.append($picker); 942 943 /* Set current date */ 944 if(!opt.current) { 945 opt.current = new Date(); 946 } else { 947 var format = getDateFormat(opt.dateFormat, opt.locale, opt.dateOnly); 948 var date = parseDate(opt.current, format); 949 if (date) { 950 opt.current = date; 951 } else { 952 opt.current = new Date(); 953 } 954 } 955 956 /* Set options data to container object */ 957 if (opt.inputObjectId != null) { 958 $picker.data("inputObjectId", opt.inputObjectId); 959 } 960 $picker.data("dateOnly", opt.dateOnly); 961 $picker.data("pickerId", PickerObjects.length); 962 $picker.data("dateFormat", opt.dateFormat); 963 $picker.data("locale", opt.locale); 964 $picker.data("firstDayOfWeek", opt.firstDayOfWeek); 965 $picker.data("animation", opt.animation); 966 $picker.data("closeOnSelected", opt.closeOnSelected); 967 $picker.data("timelistScroll", opt.timelistScroll); 968 $picker.data("calendarMouseScroll", opt.calendarMouseScroll); 969 $picker.data("todayButton", opt.todayButton); 970 $picker.data('futureOnly', opt.futureOnly); 971 $picker.data('onShow', opt.onShow); 972 $picker.data('onHide', opt.onHide); 973 $picker.data('onInit', opt.onInit); 974 $picker.data('allowWdays', opt.allowWdays); 975 976 var minDate = Date.parse(opt.minDate); 977 if (isNaN(minDate)) { // invalid date? 978 $picker.data('minDate', null); // set to null 979 } else { 980 $picker.data('minDate', minDate); 981 } 982 983 var maxDate = Date.parse(opt.maxDate); 984 if (isNaN(maxDate)) { // invalid date? 985 $picker.data('maxDate', null); // set to null 986 } else { 987 $picker.data('maxDate', maxDate); 988 } 989 $picker.data("state", 0); 990
991 if( 5 <= opt.minuteInterval && opt.minuteInterval <= 30 ){ 992 $picker.data("minuteInterval", opt.minuteInterval); 993 } else { 994 $picker.data("minuteInterval", 30); 995 } 996 opt.minTime = opt.minTime.split(':'); 997 opt.maxTime = opt.maxTime.split(':'); 998 999 if(! ((opt.minTime[0] >= 0 ) && (opt.minTime[0] <24 ))){ 1000 opt.minTime[0]="00"; 1001 } 1002 if(! ((opt.maxTime[0] >= 0 ) && (opt.maxTime[0] <24 ))){ 1003 opt.maxTime[0]="23"; 1004 } 1005 if(! ((opt.minTime[1] >= 0 ) && (opt.minTime[1] <60 ))){ 1006 opt.minTime[1]="00"; 1007 } 1008 if(! ((opt.maxTime[1] >= 0 ) && (opt.maxTime[1] <24 ))){ 1009 opt.maxTime[1]="59"; 1010 } 1011 opt.minTime[0]=parseInt(opt.minTime[0]); 1012 opt.minTime[1]=parseInt(opt.minTime[1]); 1013 opt.maxTime[0]=parseInt(opt.maxTime[0]); 1014 opt.maxTime[1]=parseInt(opt.maxTime[1]); 1015 $picker.data('minTime', opt.minTime); 1016 $picker.data('maxTime', opt.maxTime); 1017 1018 /* Header */ 1019 var $header = $('<div>'); 1020 $header.addClass('datepicker_header'); 1021 $picker.append($header); 1022 /* InnerContainer*/ 1023 var $inner = $('<div>'); 1024 $inner.addClass('datepicker_inner_container'); 1025 $picker.append($inner); 1026 /* Calendar */ 1027 var $calendar = $('<div>'); 1028 $calendar.addClass('datepicker_calendar'); 1029 var $table = $('<table>'); 1030 $table.addClass('datepicker_table'); 1031 $calendar.append($table); 1032 $inner.append($calendar); 1033 /* Timelist */ 1034 var $timelist = $('<div>'); 1035 $timelist.addClass('datepicker_timelist'); 1036 $inner.append($timelist); 1037 1038 /* Set event handler to picker */ 1039 $picker.hover( 1040 function(){ 1041 ActivePickerId = $(this).data("pickerId"); 1042 }, 1043 function(){ 1044 ActivePickerId = -1; 1045 } 1046 ); 1047 1048 /* Set event-handler to calendar */ 1049 if (opt.calendarMouseScroll) { 1050 if (window.sidebar) { // Mozilla Firefox 1051 $calendar.bind('DOMMouseScroll', function(e){ // Change a month with mouse wheel scroll for Fx 1052 var $picker = getParentPickerObject($(this)); 1053 1054 // up,left [delta < 0] down,right [delta > 0] 1055 var delta = e.originalEvent.detail; 1056 /* 1057 // this code need to be commented - it's seems to be unnecessary 1058 // normalization (/3) is not needed as we move one month back or forth 1059 if(e.originalEvent.axis !== undefined && e.originalEvent.axis == e.originalEvent.HORIZONTAL_AXIS){ 1060 e.deltaX = delta; 1061 e.deltaY = 0; 1062 } else { 1063 e.deltaX = 0; 1064 e.deltaY = delta; 1065 } 1066 e.deltaX /= 3; 1067 e.deltaY /= 3; 1068 */ 1069 if(delta > 0) { 1070 nextMonth($picker); 1071 } else { 1072 beforeMonth($picker); 1073 } 1074 return false; 1075 }); 1076 } else { // Other browsers 1077 $calendar.bind('mousewheel', function(e){ // Change a month with mouse wheel scroll 1078 var $picker = getParentPickerObject($(this)); 1079 // up [delta > 0] down [delta < 0] 1080 if(e.originalEvent.wheelDelta /120 > 0) { 1081 beforeMonth($picker); 1082 } else { 1083 nextMonth($picker); 1084 } 1085 return false; 1086 }); 1087 } 1088 } 1089 1090 PickerObjects.push($picker); 1091 1092 draw_date($picker, { 1093 "isAnim": true, 1094 "isOutputToInputObject": opt.autodateOnStart 1095 }, opt.current); 1096 }; 1097 1098 var getDefaults = function() { 1099 return { 1100 "current": null, 1101 "dateFormat": "default", 1102 "locale": "en", 1103 "animation": true, 1104 "minuteInterval": 30, 1105 "firstDayOfWeek": 0, 1106 "closeOnSelected": false, 1107 "timelistScroll": true, 1108 "calendarMouseScroll": true, 1109 "todayButton": true, 1110 "dateOnly": false, 1111 "futureOnly": false, 1112 "minDate" : null, 1113 "maxDate" : null, 1114 "autodateOnStart": true, 1115 "minTime":"00:00", 1116 "maxTime":"23:59", 1117 "onShow": null, 1118 "onHide": null, 1119 "allowWdays": null 1120 }; 1121 }; 1122 1123 /** 1124 * Initialize dtpicker 1125 */ 1126 $.fn.dtpicker = function(config) { 1127 var date = new Date(); 1128 var defaults = getDefaults(); 1129 1130 defaults.inputObjectId = undefined; 1131 var options = $.extend(defaults, config); 1132 1133 return this.each(function(i) { 1134 init($(this), options); 1135 }); 1136 }; 1137 1138 /** 1139 * Initialize dtpicker, append to Text input field 1140 * */ 1141 $.fn.appendDtpicker = function(config) { 1142 var date = new Date(); 1143 var defaults = getDefaults(); 1144 1145 defaults.inline = false; 1146 var options = $.extend(defaults, config); 1147 1148 return this.each(function(i) { 1149 /* Checking exist a picker */ 1150 var input = this; 1151 if(0 < $(PickerObjects[$(input).data('pickerId')]).length) { 1152 console.log("dtpicker - Already exist appended picker"); 1153 return; 1154 } 1155 1156 /* Add input-field with inputsObjects array */ 1157 var inputObjectId = InputObjects.length; 1158 InputObjects.push(input); 1159 1160 options.inputObjectId = inputObjectId; 1161 1162 /* Current date */ 1163 var date, strDate, strTime; 1164 if($(input).val() != null && $(input).val() !== ""){ 1165 options.current = $(input).val(); 1166 } 1167 1168 /* Make parent-div for picker */ 1169 var $d = $('<div>'); 1170 if(options.inline){ // Inline mode 1171 $d.insertAfter(input); 1172 } else { // Float mode 1173 $d.css("position","absolute"); 1174 $('body').append($d); 1175 } 1176 1177 /* Initialize picker */ 1178 1179 var pickerId = PickerObjects.length; 1180 1181 var $picker_parent = $($d).dtpicker(options); // call dtpicker() method 1182 1183 var $picker = $picker_parent.children('.datepicker'); 1184 1185 /* Link input-field with picker*/ 1186 $(input).data('pickerId', pickerId); 1187 1188 /* Set event handler to input-field */ 1189 1190 $(input).keyup(function() { 1191 var $input = $(this); 1192 var $picker = $(PickerObjects[$input.data('pickerId')]); 1193 if ($input.val() != null && ( 1194 $input.data('beforeVal') == null || 1195 ( $input.data('beforeVal') != null && $input.data('beforeVal') != $input.val()) ) 1196 ) { /* beforeValue == null || beforeValue != nowValue */ 1197 var format = getDateFormat($picker.data('dateFormat'), $picker.data('locale'), $picker.data('dateOnly')); 1198 var date = parseDate($input.val(), format); 1199 //console.log("dtpicker - inputKeyup - format: " + format + ", date: " + $input.val() + " -> " + date); 1200 if (date) { 1201 draw_date($picker, { 1202 "isAnim":true, 1203 "isOutputToInputObject":false 1204 }, date); 1205 } 1206 } 1207 $input.data('beforeVal', $input.val()); 1208 }); 1209 1210 $(input).change(function(){ 1211 $(this).trigger('keyup'); 1212 }); 1213 1214 var handler = new PickerHandler($picker, $(input)); 1215 1216 if(options.inline === true){ 1217 /* inline mode */ 1218 $picker.data('isInline',true); 1219 } else { 1220 /* float mode */ 1221 $picker.data('isInline',false); 1222 $picker_parent.css({ 1223 "zIndex": 100 1224 }); 1225 $picker.css("width","auto"); 1226 1227 /* Hide this picker */ 1228 $picker.hide(); 1229 1230 /* Set onClick event handler for input-field */ 1231 $(input).on('click, focus',function(){ 1232 var $input = $(this); 1233 var $picker = $(PickerObjects[$input.data('pickerId')]); 1234 1235 // Generate the handler of a picker 1236 var handler = new PickerHandler($picker, $input); 1237 // Get the display state of a picker 1238 var is_showed = handler.isShow(); 1239 if (!is_showed) { 1240 // Show a picker 1241 handler.show(); 1242 1243 // Call a event-hanlder 1244 var func = $picker.data('onShow'); 1245 if (func != null) { 1246 console.log("dtpicker- Call the onShow handler"); 1247 func(handler); 1248 } 1249 } 1250 }); 1251 1252 // Set an event handler for resizing of a window 1253 (function(handler){ 1254 $(window).resize(function(){ 1255 handler._relocate(); 1256 }); 1257 $(window).scroll(function(){ 1258 handler._relocate(); 1259 }); 1260 })(handler); 1261 } 1262 1263 // Set an event handler for removing of an input-field 1264 $(input).bind('destroyed', function() { 1265 var $input = $(this); 1266 var $picker = $(PickerObjects[$input.data('pickerId')]); 1267 // Generate the handler of a picker 1268 var handler = new PickerHandler($picker, $input); 1269 // Destroy a picker 1270 handler.destroy(); 1271 }); 1272 1273 // Call a event-handler 1274 var func = $picker.data('onInit'); 1275 if (func != null) { 1276 console.log("dtpicker- Call the onInit handler"); 1277 func(handler); 1278 } 1279 }); 1280 }; 1281 1282 /** 1283 * Handle a appended dtpicker 1284 * */ 1285 var methods = { 1286 show : function( ) { 1287 var $input = $(this); 1288 var $picker = $(PickerObjects[$input.data('pickerId')]); 1289 if ($picker != null) { 1290 var handler = new PickerHandler($picker, $input); 1291 // Show a picker 1292 handler.show(); 1293 } 1294 }, 1295 hide : function( ) { 1296 var $input = $(this); 1297 var $picker = $(PickerObjects[$input.data('pickerId')]); 1298 if ($picker != null) { 1299 var handler = new PickerHandler($picker, $input); 1300 // Hide a picker 1301 handler.hide(); 1302 } 1303 }, 1304 setDate : function( date ) { 1305 var $input = $(this); 1306 var $picker = $(PickerObjects[$input.data('pickerId')]); 1307 if ($picker != null) { 1308 var handler = new PickerHandler($picker, $input); 1309 // Set a date 1310 handler.setDate(date); 1311 } 1312 }, 1313 getDate : function( ) { 1314 var $input = $(this); 1315 var $picker = $(PickerObjects[$input.data('pickerId')]); 1316 if ($picker != null) { 1317 var handler = new PickerHandler($picker, $input); 1318 // Get a date 1319 return handler.getDate(); 1320 } 1321 }, 1322 destroy : function( ) { 1323 var $input = $(this); 1324 var $picker = $(PickerObjects[$input.data('pickerId')]); 1325 if ($picker != null) { 1326 var handler = new PickerHandler($picker, $input); 1327 // Destroy a picker 1328 handler.destroy(); 1329 } 1330 } 1331 }; 1332 1333 $.fn.handleDtpicker = function( method ) { 1334 if ( methods[method] ) { 1335 return methods[ method ].apply( this, Array.prototype.slice.call( arguments, 1 )); 1336 } else if ( typeof method === 'object' || ! method ) { 1337 return methods.init.apply( this, arguments ); 1338 } else { 1339 $.error( 'Method ' + method + ' does not exist on jQuery.handleDtpicker' ); 1340 } 1341 }; 1342 1343 if (!window.console) { // Not available a console on this environment. 1344 window.console = {}; 1345 window.console.log = function(){}; 1346 } 1347 1348 /* Define a special event for catch when destroy of an input-field. */ 1349 $.event.special.destroyed = { 1350 remove: function(o) { 1351 if (o.handler) { 1352 o.handler.apply(this, arguments); 1353 } 1354 } 1355 }; 1356 1357 /* Set event handler to Body element, for hide a floated-picker */ 1358 $(function(){ 1359 $('body').click(function(){ 1360 for(var i=0;i<PickerObjects.length;i++){ 1361 var $picker = $(PickerObjects[i]); 1362 if(ActivePickerId != i){ /* if not-active picker */ 1363 if($picker.data("inputObjectId") != null && $picker.data("isInline") === false && $picker.css('display') != 'none'){ 1364 /* if append input-field && float picker */ 1365 1366 // Hide a picker 1367 var $input = InputObjects[$picker.data("inputObjectId")]; 1368 var handler = new PickerHandler($picker, $input); 1369 handler.hide(); 1370 1371 // Call a event-hanlder 1372 var func = $picker.data('onHide'); 1373 if (func != null) { 1374 console.log("dtpicker- Call the onHide handler"); 1375 func(handler); 1376 } 1377 } 1378 } 1379 } 1380 }); 1381 }); 1382 1383})(jQuery);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.