1(function($) { 2 var monthNames = ['January', 'February', 'March', 'April', 'May', 'June', 3 'July', 'August', 'September', 'October', 'November', 'December']; 4 5 function getToday() 6 { 7 var date = new Date(); 8 return new Date(date.getFullYear(), date.getMonth(), date.getDate()); 9 } 10 11 function areDatesEqual(date1, date2) 12 { 13 return String(date1) == String(date2); 14 } 15 16 function daysInMonth(year, month) 17 { 18 if (year instanceof Date) return daysInMonth(year.getFullYear(), year.getMonth()); 19 if (month == 1) { 20 var leapYear = (year % 4 == 0) && 21 (!(year % 100 == 0) || (year % 400 == 0)); 22 return leapYear ? 29 : 28; 23 } else if (month == 3 || month == 5 || month == 8 || month == 10) { 24 return 30; 25 } else { 26 return 31; 27 } 28 } 29 30 function dayAfter(date) 31 { 32 var year = date.getFullYear(); 33 var month = date.getMonth(); 34 var day = date.getDate(); 35 var lastDay = daysInMonth(date); 36 return (day == lastDay) ? 37 ((month == 11) ? 38 new Date(year + 1, 0, 1) : 39 new Date(year, month + 1, 1) 40 ) : 41 new Date(year, month, day + 1); 42 } 43 44 function dayBefore(date) 45 { 46 var year = date.getFullYear(); 47 var month = date.getMonth(); 48 var day = date.getDate(); 49 return (day == 1) ? 50 ((month == 0) ? 51 new Date(year - 1, 11, daysInMonth(year - 1, 11)) : 52 new Date(year, month - 1, daysInMonth(year, month - 1)) 53 ) : 54 new Date(year, month, day - 1); 55 } 56 57 function monthAfter(year, month) 58 { 59 return (month == 11) ? 60 new Date(year + 1, 0, 1) : 61 new Date(year, month + 1, 1); 62 } 63 64 function formatDate(date, usa) 65 { 66 return (usa ? 67 ((date.getMonth() + 1) + '/' + date.getDate()) : 68 (date.getDate() + '/' + (date.getMonth() + 1)) 69 ) + '/' + date.getFullYear(); 70 } 71 72 function parseDate(date, usa) 73 { 74 if (usa) return new Date(date); 75 a = date.split(/[\.\-\/]/); 76 var day = a.shift(); 77 var month = a.shift(); 78 a.unshift(day); 79 a.unshift(month); 80 return new Date(a.join('/')); 81 } 82 83 function formatTime(hour, minute, iso) 84 { 85 var printMinute = minute; 86 if (minute < 10) printMinute = '0' + minute; 87 88 if (iso) { 89 var printHour = hour 90 if (printHour < 10) printHour = '0' + hour; 91 return printHour + ':' + printMinute; 92 } else { 93 var printHour = hour % 12; 94 if (printHour == 0) printHour = 12; 95 var half = (hour < 12) ? ' AM' : ' PM'; 96 if (printHour < 10) 97 { 98 printHour = '0' + printHour; 99 } 100 return printHour + ':' + printMinute + half; 101 } 102 } 103 104 function getChineseAmPm(hour) 105 { 106 var s = ''; 107 if (hour >=0 && hour <=5) 108 { 109 s = '忍'; 110 } 111 else if (hour <= 11) 112 { 113 s = 'ä¸å?'; 114 } 115 else if (hour <= 17) 116 { 117 s = 'ä¸å?'; 118 } 119 else 120 { 121 s = 'æä¸'; 122 } 123 return s; 124 } 125 126 function parseTime(text) 127 { 128 var match = match = /(\d+)\s*[:\-\.,]\s*(\d+)\s*(am|pm)?/i.exec(text); 129 if (match && match.length >= 3) { 130 var hour = Number(match[1]); 131 var minute = Number(match[2]) 132 if (hour == 12 && match[3]) hour -= 12; 133 if (match[3] && match[3].toLowerCase() == 'pm') hour += 12; 134 return { 135 hour: hour, 136 minute: minute 137 }; 138 } else { 139 return null; 140 } 141 } 142 143 /** 144 * Generates calendar header, with month name, << and >> controls, and 145 * initials for days of the week. 146 */ 147 function renderCalendarHeader(element, year, month, options) 148 { 149 //Prepare thead element 150 var thead = $('<thead />'); 151 var titleRow = $('<tr />').appendTo(thead); 152 153 //Generate << (back a month) link 154 $('<th />').addClass('monthCell').append( 155 $('<a href="javascript:;">«</a>') 156 .addClass('prevMonth') 157 .mousedown(function(e) { 158 renderCalendarPage(element,
159 month == 0 ? (year - 1) : year, 160 month == 0 ? 11 : (month - 1), options 161 ); 162 e.preventDefault(); 163 }) 164 ).appendTo(titleRow); 165 166 //Generate month title 167 $('<th />').addClass('monthCell').attr('colSpan', 5).append( 168 $('<a href="javascript:;">' + monthNames[month] + ' ' + 169 year + '</a>').addClass('monthName') 170 ).appendTo(titleRow); 171 172 //Generate >> (forward a month) link 173 $('<th />').addClass('monthCell').append( 174 $('<a href="javascript:;">»</a>') 175 .addClass('nextMonth') 176 .mousedown(function() { 177 renderCalendarPage(element, 178 month == 11 ? (year + 1) : year, 179 month == 11 ? 0 : (month + 1), options 180 ); 181 }) 182 ).appendTo(titleRow); 183 184 //Generate weekday initials row 185 var dayNames = $('<tr />').appendTo(thead); 186 $.each(String('SMTWTFS').split(''), function(k, v) { 187 $('<td />').addClass('dayName').append(v).appendTo(dayNames); 188 }); 189 190 return thead; 191 } 192 193 function renderCalendarPage(element, year, month, options) 194 { 195 options = options || {}; 196 197 var today = getToday(); 198 199 var date = new Date(year, month, 1); 200 201 //Wind end date forward to saturday week after month 202 var endDate = monthAfter(year, month); 203 var ff = 6 - endDate.getDay(); 204 if (ff < 6) ff += 7; 205 for (var i = 0; i < ff; i++) endDate = dayAfter(endDate); 206 207 var table = $('<table />'); 208 renderCalendarHeader(element, year, month, options).appendTo(table); 209 210 var tbody = $('<tbody />').appendTo(table); 211 var row = $('<tr />'); 212 213 //Rewind date to monday week before month 214 var rewind = date.getDay() + 7; 215 for (var i = 0; i < rewind; i++) date = dayBefore(date); 216 217 while (date <= endDate) { 218 var td = $('<td />') 219 .addClass('day') 220 .append( 221 $('<a href="javascript:;">' + 222 date.getDate() + '</a>' 223 ).click((function() { 224 var thisDate = date; 225 226 return function() { 227 if (options && options.selectDate) { 228 options.selectDate(thisDate); 229 } 230 } 231 }())) 232 ) 233 .appendTo(row); 234 235 var isToday = areDatesEqual(date, today); 236 var isSelected = options.selected && 237 areDatesEqual(options.selected, date); 238 239 if (isToday) td.addClass('today'); 240 if (isSelected) td.addClass('selected'); 241 if (isToday && isSelected) td.addClass('today_selected'); 242 if (date.getMonth() != month) td.addClass('nonMonth'); 243 244 dow = date.getDay(); 245 if (dow == 6) { 246 tbody.append(row); 247 row = $('<tr />'); 248 } 249 date = dayAfter(date); 250 } 251 if (row.children().length) { 252 tbody.append(row); 253 } else { 254 row.remove(); 255 } 256 257 element.empty().append(table); 258 } 259 260 function renderTimeSelect(element, options) 261 { 262 var selection = options.selection && parseTime(options.selection); 263 if (selection) { 264 //selection.minute = Math.floor(selection.minute / 15.0) * 15; 265 selection.minute = Math.floor(selection.minute / 5.0) * 5; 266 } 267 var startTime = options.startTime && 268 (options.startTime.hour * 60 + options.startTime.minute); 269 270 var scrollTo; //Element to scroll the dropdown box to when shown 271 var ul = $('<ul />'); 272 for (var hour = 0; hour < 24; hour++) { 273 //for (var minute = 0; minute < 60; minute += 15) { 274 for (var minute = 0; minute < 60; minute += 5) { 275 if (startTime && startTime > (hour * 60 + minute)) continue; 276 277 (function() { 278 var timeText = formatTime(hour, minute, options.isoTime); 279 var fullText = timeText; 280 if (startTime != null) { 281 var duration = (hour * 60 + minute) - startTime; 282 if (duration < 60) { 283 fullText += ' (' + duration + ' mins)'; 284 } else if (duration == 60) { 285 fullText += ' (1 hr)'; 286 } else { 287 fullText += ' (' + (duration / 60.0) + ' hrs)'; 288 } 289 } 290 var li = $('<li />').append( 291 $('<a href="javascript:;">' + fullText + '</a>') 292 .click(function() { 293 if (options && options.selectTime) { 294 options.selectTime(timeText); 295 } 296 var time_data = $(this).text(); 297 $('#service_time_data').val(time_data); 298 }).mousemove(function() { 299 $('li.selected', ul).removeClass('selected'); 300 }) 301 ).appendTo(ul); 302 303 //Set to scroll to the default hour, unless already set 304 if (!scrollTo && hour == options.defaultHour) { 305 scrollTo = li; 306 } 307 308 if (selection && 309 selection.hour == hour && 310 selection.minute == minute) 311 { 312 //Highlight selected item 313 li.addClass('selected'); 314 315 //Set to scroll to the selected hour 316 // 317 //This is set even if scrollTo is already set, since 318 //scrolling to selected hour is more important than 319 //scrolling to default hour 320 scrollTo = li; 321 } 322 })(); 323 } 324 } 325 if (scrollTo) { 326 //Set timeout of zero so code runs immediately after any calling 327 //functions are finished (this is needed, since box hasn't been 328 //added to the DOM yet) 329 setTimeout(function() { 330 //Scroll the dropdown box so that scrollTo item is in 331 //the middle 332 element[0].scrollTop = 333 scrollTo[0].offsetTop - scrollTo.height() * 2; 334 }, 0); 335 } 336 element.empty().append(ul); 337 } 338
339 $.fn.calendricalDate = function(options) 340 { 341 options = options || {}; 342 options.padding = options.padding || 4; 343 344 return this.each(function() { 345 var element = $(this); 346 var div; 347 var within = false; 348 349 element.bind('focus click', function() { 350 if (div) return; 351 var offset = element.position(); 352 var padding = element.css('padding-left'); 353 div = $('<div />') 354 .addClass('calendricalDatePopup') 355 .mouseenter(function() { within = true; }) 356 .mouseleave(function() { within = false; }) 357 .mousedown(function(e) { 358 e.preventDefault(); 359 }) 360 .css({ 361 position: 'absolute', 362 left: offset.left, 363 top: offset.top + element.height() + 364 options.padding * 2 365 }); 366 element.after(div); 367 368 var selected = parseDate(element.val(), options.usa); 369 if (!selected.getFullYear()) selected = getToday(); 370 371 renderCalendarPage( 372 div, 373 selected.getFullYear(), 374 selected.getMonth(), { 375 selected: selected, 376 selectDate: function(date) { 377 within = false; 378 element.val(formatDate(date, options.usa)); 379 div.remove(); 380 div = null; 381 if (options.endDate) { 382 var endDate = parseDate( 383 options.endDate.val(), options.usa 384 ); 385 if (endDate >= selected) { 386 options.endDate.val(formatDate( 387 new Date( 388 date.getTime() + 389 endDate.getTime() - 390 selected.getTime() 391 ), 392 options.usa 393 )); 394 } 395 } 396 } 397 } 398 ); 399 }).blur(function() { 400 if (within){ 401 if (div) element.focus(); 402 return; 403 } 404 if (!div) return; 405 div.remove(); 406 div = null; 407 }); 408 }); 409 }; 410 411 $.fn.calendricalDateRange = function(options) 412 { 413 if (this.length >= 2) { 414 $(this[0]).calendricalDate($.extend({ 415 endDate: $(this[1]) 416 }, options)); 417 $(this[1]).calendricalDate(options); 418 } 419 return this; 420 }; 421 422 $.fn.calendricalTime = function(options) 423 { 424 options = options || {}; 425 options.padding = options.padding || 4; 426 427 return this.each(function() { 428 var element = $(this); 429 var div; 430 var within = false; 431 432 element.bind('focus click', function() { 433 if (div) return; 434 435 var useStartTime = options.startTime; 436 if (useStartTime) { 437 if (options.startDate && options.endDate && 438 !areDatesEqual(parseDate(options.startDate.val()), 439 parseDate(options.endDate.val()))) 440 useStartTime = false; 441 } 442 443 var offset = element.position(); 444 div = $('<div />') 445 .addClass('calendricalTimePopup') 446 .mouseenter(function() { within = true; }) 447 .mouseleave(function() { within = false; }) 448 .mousedown(function(e) { 449 e.preventDefault(); 450 }) 451 .css({ 452 position: 'absolute', 453 left: offset.left, 454 top: offset.top + element.height() + 455 options.padding * 2 456 }); 457 if (useStartTime) { 458 div.addClass('calendricalEndTimePopup'); 459 } 460 461 element.after(div); 462 463 var opts = { 464 selection: element.val(), 465 selectTime: function(time) { 466 within = false;
467 element.val(time); 468 div.remove(); 469 div = null; 470 }, 471 isoTime: options.isoTime || false, 472 defaultHour: (options.defaultHour != null) ? 473 options.defaultHour : 8 474 }; 475 476 if (useStartTime) { 477 opts.startTime = parseTime(options.startTime.val()); 478 } 479 480 renderTimeSelect(div, opts); 481 }).blur(function() { 482 if (within){ 483 if (div) element.focus(); 484 return; 485 } 486 if (!div) return; 487 div.remove(); 488 div = null; 489 }); 490 }); 491 }, 492 493 $.fn.calendricalTimeRange = function(options) 494 { 495 if (this.length >= 2) { 496 $(this[0]).calendricalTime(options); 497 $(this[1]).calendricalTime($.extend({ 498 startTime: $(this[0]) 499 }, options)); 500 } 501 return this; 502 }; 503 504 $.fn.calendricalDateTimeRange = function(options) 505 { 506 if (this.length >= 4) { 507 $(this[0]).calendricalDate($.extend({ 508 endDate: $(this[2]) 509 }, options)); 510 $(this[1]).calendricalTime(options); 511 $(this[2]).calendricalDate(options); 512 $(this[3]).calendricalTime($.extend({ 513 startTime: $(this[1]), 514 startDate: $(this[0]), 515 endDate: $(this[2]) 516 }, options)); 517 } 518 return this; 519 }; 520})(jQuery); 521/* 522 * A time picker for jQuery 523 * 524 * Dual licensed under the MIT and GPL licenses. 525 * Copyright (c) 2009 Anders Fajerson 526 * @name timePicker 527 * @author Anders Fajerson (http://perifer.se) 528 * @example $("#mytime").timePicker(); 529 * @example $("#mytime").timePicker({step:30, startTime:"15:00", endTime:"18:00"}); 530 * 531 * Based on timePicker by Sam Collet (http://www.texotela.co.uk/code/jquery/timepicker/) 532 * 533 * Options: 534 * step: # of minutes to step the time by 535 * startTime: beginning of the range of acceptable times 536 * endTime: end of the range of acceptable times 537 * separator: separator string to use between hours and minutes (e.g. ':') 538 * show24Hours: use a 24-hour scheme 539 */ 540 541(function($){ 542 $.fn.timePicker = function(options) { 543 // Build main options before element iteration 544 var settings = $.extend({}, $.fn.timePicker.defaults, options); 545 546 return this.each(function() { 547 $.timePicker(this, settings); 548 }); 549 }; 550 551 $.timePicker = function (elm, settings) { 552 var e = $(elm)[0]; 553 return e.timePicker || (e.timePicker = new jQuery._timePicker(e, settings)); 554 }; 555 556 $.timePicker.version = '0.3'; 557 558 $._timePicker = function(elm, settings) { 559 560 var tpOver = false; 561 var keyDown = false; 562 var startTime = timeToDate(settings.startTime, settings); 563 var endTime = timeToDate(settings.endTime, settings); 564 var selectedClass = "selected"; 565 var selectedSelector = "li." + selectedClass; 566 567 $(elm).attr('autocomplete', 'OFF'); // Disable browser autocomplete 568 569 var times = []; 570 var time = new Date(startTime); // Create a new date object. 571 while(time <= endTime) { 572 times[times.length] = formatTime(time, settings); 573 time = new Date(time.setMinutes(time.getMinutes() + settings.step)); 574 } 575 576 var $tpDiv = $('<div class="time-picker'+ (settings.show24Hours ? '' : ' time-picker-12hours') +'"></div>'); 577 var $tpList = $('<ul></ul>'); 578 579 // Build the list. 580 for(var i = 0; i < times.length; i++) { 581 $tpList.append("<li>" + times[i] + "</li>"); 582 } 583 $tpDiv.append($tpList); 584 // Append the timPicker to the body and position it. 585 $tpDiv.appendTo('body').hide(); 586 587 // Store the mouse state, used by the blur event. Use mouseover instead of 588 // mousedown since Opera fires blur before mousedown. 589 $tpDiv.mouseover(function() { 590 tpOver = true; 591 }).mouseout(function() { 592 tpOver = false; 593 }); 594 595 $("li", $tpList).mouseover(function() { 596 if (!keyDown) { 597 $(selectedSelector, $tpDiv).removeClass(selectedClass); 598 $(this).addClass(selectedClass); 599 } 600 }).mousedown(function() { 601 tpOver = true; 602 }).click(function() { 603 setTimeVal(elm, this, $tpDiv, settings); 604 tpOver = false;
605 }); 606 607 var showPicker = function() { 608 if ($tpDiv.is(":visible")) { 609 return false; 610 } 611 $("li", $tpDiv).removeClass(selectedClass); 612 613 // Position 614 var elmOffset = $(elm).offset(); 615 $tpDiv.css({'top':elmOffset.top + elm.offsetHeight, 'left':elmOffset.left}); 616 617 // Show picker. This has to be done before scrollTop is set since that 618 // can't be done on hidden elements. 619 $tpDiv.show(); 620 621 // Try to find a time in the list that matches the entered time. 622 var time = elm.value ? timeStringToDate(elm.value, settings) : startTime; 623 var startMin = startTime.getHours() * 60 + startTime.getMinutes(); 624 var min = (time.getHours() * 60 + time.getMinutes()) - startMin; 625 var steps = Math.round(min / settings.step); 626 var roundTime = normaliseTime(new Date(0, 0, 0, 0, (steps * settings.step + startMin), 0)); 627 roundTime = (startTime < roundTime && roundTime <= endTime) ? roundTime : startTime; 628 var $matchedTime = $("li:contains(" + formatTime(roundTime, settings) + ")", $tpDiv); 629 630 if ($matchedTime.length) { 631 $matchedTime.addClass(selectedClass); 632 // Scroll to matched time. 633 $tpDiv[0].scrollTop = $matchedTime[0].offsetTop; 634 } 635 return true; 636 }; 637 // Attach to click as well as focus so timePicker can be shown again when 638 // clicking on the input when it already has focus. 639 $(elm).focus(showPicker).click(showPicker); 640 // Hide timepicker on blur 641 $(elm).blur(function() { 642 if (!tpOver) { 643 $tpDiv.hide(); 644 } 645 }); 646 // Keypress doesn't repeat on Safari for non-text keys. 647 // Keydown doesn't repeat on Firefox and Opera on Mac. 648 // Using kepress for Opera and Firefox and keydown for the rest seems to 649 // work with up/down/enter/esc. 650 var event = ($.browser.opera || $.browser.mozilla) ? 'keypress' : 'keydown'; 651 $(elm)[event](function(e) { 652 var $selected; 653 keyDown = true; 654 var top = $tpDiv[0].scrollTop; 655 switch (e.keyCode) { 656 case 38: // Up arrow. 657 // Just show picker if it's hidden. 658 if (showPicker()) { 659 return false; 660 }; 661 $selected = $(selectedSelector, $tpList); 662 var prev = $selected.prev().addClass(selectedClass)[0]; 663 if (prev) { 664 $selected.removeClass(selectedClass); 665 // Scroll item into view. 666 if (prev.offsetTop < top) { 667 $tpDiv[0].scrollTop = top - prev.offsetHeight; 668 } 669 } 670 else { 671 // Loop to next item. 672 $selected.removeClass(selectedClass); 673 prev = $("li:last", $tpList).addClass(selectedClass)[0]; 674 $tpDiv[0].scrollTop = prev.offsetTop - prev.offsetHeight; 675 } 676 return false; 677 break; 678 case 40: // Down arrow, similar in behaviour to up arrow. 679 if (showPicker()) { 680 return false; 681 }; 682 $selected = $(selectedSelector, $tpList); 683 var next = $selected.next().addClass(selectedClass)[0]; 684 if (next) { 685 $selected.removeClass(selectedClass); 686 if (next.offsetTop + next.offsetHeight > top + $tpDiv[0].offsetHeight) { 687 $tpDiv[0].scrollTop = top + next.offsetHeight; 688 } 689 } 690 else { 691 $selected.removeClass(selectedClass); 692 next = $("li:first", $tpList).addClass(selectedClass)[0]; 693 $tpDiv[0].scrollTop = 0; 694 } 695 return false; 696 break; 697 case 13: // Enter 698 if ($tpDiv.is(":visible")) { 699 var sel = $(selectedSelector, $tpList)[0]; 700 setTimeVal(elm, sel, $tpDiv, settings); 701 } 702 return false; 703 break; 704 case 27: // Esc 705 $tpDiv.hide(); 706 return false; 707 break; 708 } 709 return true; 710 }); 711 $(elm).keyup(function(e) { 712 keyDown = false; 713 }); 714 // Helper function to get an inputs current time as Date object. 715 // Returns a Date object. 716 this.getTime = function() {
717 return timeStringToDate(elm.value, settings); 718 }; 719 // Helper function to set a time input. 720 // Takes a Date object or string. 721 this.setTime = function(time) { 722 elm.value = formatTime(timeToDate(time, settings), settings); 723 // Trigger element's change events. 724 $(elm).change(); 725 }; 726 727 }; // End fn; 728 729 // Plugin defaults. 730 $.fn.timePicker.defaults = { 731 step:30, 732 startTime: new Date(0, 0, 0, 0, 0, 0), 733 endTime: new Date(0, 0, 0, 23, 30, 0), 734 separator: ':', 735 show24Hours: true 736 }; 737 738 // Private functions. 739 740 function setTimeVal(elm, sel, $tpDiv, settings) { 741 // Update input field 742 elm.value = $(sel).text(); 743 // Trigger element's change events. 744 $(elm).change(); 745 // Keep focus for all but IE (which doesn't like it) 746 if (!$.browser.msie) { 747 elm.focus(); 748 } 749 // Hide picker 750 $tpDiv.hide(); 751 } 752 753 function formatTime(time, settings) { 754 var h = time.getHours(); 755 var hours = settings.show24Hours ? h : (((h + 11) % 12) + 1); 756 var minutes = time.getMinutes(); 757 return formatNumber(hours) + settings.separator + formatNumber(minutes) + (settings.show24Hours ? '' : ((h < 12) ? ' AM' : ' PM')); 758 } 759 760 function formatNumber(value) { 761 return (value < 10 ? '0' : '') + value; 762 } 763 764 function timeToDate(input, settings) { 765 return (typeof input == 'object') ? normaliseTime(input) : timeStringToDate(input, settings); 766 } 767 768 function timeStringToDate(input, settings) { 769 if (input) { 770 var array = input.split(settings.separator); 771 var hours = parseFloat(array[0]); 772 var minutes = parseFloat(array[1]); 773 774 // Convert AM/PM hour to 24-hour format. 775 if (!settings.show24Hours) { 776 if (hours === 12 && input.indexOf('AM') !== -1) { 777 hours = 0; 778 } 779 else if (hours !== 12 && input.indexOf('PM') !== -1) { 780 hours += 12; 781 } 782 } 783 var time = new Date(0, 0, 0, hours, minutes, 0); 784 return normaliseTime(time); 785 } 786 return null; 787 } 788 789 /* Normalise time object to a common date. */ 790 function normaliseTime(time) { 791 time.setFullYear(2001); 792 time.setMonth(0); 793 time.setDate(0); 794 return time; 795 } 796 797})(jQuery); 798 799//# sourceMappingURL=sourcemap/language_en.js.map
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.