1;(function(){ 2 3if (BX.date) 4 return; 5 6BX.date = BX.Main.Date; 7 8/************************************** calendar class **********************************/ 9 10var obCalendarSingleton = null; 11 12/* 13params: { 14 node: bind element || document.body 15 16 value - start value in site format (using 'field' param if 'value' does not exist) 17 callback - date check handler. can return false to prevent calendar closing. 18 callback_after - another handler, called after date picking 19 20 field - field to read/write data 21 22 bTime = true - whether to enable time control 23 bHideTime = false - whether to hide time control by default 24 25 currentTime - current UTC time() 26 27} 28*/ 29 30 31BX.calendar = function(params) 32{ 33 return BX.calendar.get().Show(params); 34}; 35 36BX.calendar.get = function() 37{ 38 if (!obCalendarSingleton) 39 obCalendarSingleton = new BX.JCCalendar(); 40 41 return obCalendarSingleton; 42}; 43 44// simple func for compatibility with the oldies 45BX.calendar.InsertDaysBack = function(input, days) 46{ 47 if (days != '') 48 { 49 var d = new Date(); 50 if(days > 0) 51 { 52 d.setTime(d.valueOf() - days*86400000); 53 } 54 55 input.value = BX.date.format(BX.date.convertBitrixFormat(BX.message('FORMAT_DATE')), d, null); 56 } 57 else 58 { 59 input.value = ''; 60 } 61}; 62 63BX.calendar.ValueToString = function(value, bTime, bUTC) 64{ 65 return BX.date.format( 66 BX.date.convertBitrixFormat(BX.message(bTime ? 'FORMAT_DATETIME' : 'FORMAT_DATE')), 67 value, 68 null, 69 !!bUTC 70 ); 71}; 72 73BX.calendar.ValueToStringFormat = function(value, bitrixFormat, bUTC) 74{ 75 return BX.date.format( 76 BX.date.convertBitrixFormat(bitrixFormat), 77 value, 78 null, 79 !!bUTC 80 ); 81}; 82 83 84BX.CalendarPeriod = 85{ 86 Init: function(inputFrom, inputTo, selPeriod) 87 { 88 if((inputFrom.value != "" || inputTo.value != "") && selPeriod.value == "") 89 selPeriod.value = "interval"; 90 91 selPeriod.onchange(); 92 }, 93 94 ChangeDirectOpts: function(peroidValue, selPParent) // "week" || "others" 95 { 96 var selDirect = BX.findChild(selPParent, {'className':'adm-select adm-calendar-direction'}, true); 97 98 if(peroidValue == "week") 99 { 100 selDirect.options[0].text = BX.message('JSADM_CALEND_PREV_WEEK'); 101 selDirect.options[1].text = BX.message('JSADM_CALEND_CURR_WEEK'); 102 selDirect.options[2].text = BX.message('JSADM_CALEND_NEXT_WEEK'); 103 } 104 else 105 { 106 selDirect.options[0].text = BX.message('JSADM_CALEND_PREV'); 107 selDirect.options[1].text = BX.message('JSADM_CALEND_CURR'); 108 selDirect.options[2].text = BX.message('JSADM_CALEND_NEXT'); 109 } 110 }, 111 112 SaveAndClearInput: function(oInput) 113 { 114 if(!window.SavedPeriodValues) 115 window.SavedPeriodValues = {}; 116 117 window.SavedPeriodValues[oInput.id] = oInput.value; 118 oInput.value=""; 119 }, 120 121 RestoreInput: function(oInput) 122 { 123 if(!window.SavedPeriodValues || !window.SavedPeriodValues[oInput.id]) 124 return; 125 126 oInput.value = window.SavedPeriodValues[oInput.id]; 127 delete(window.SavedPeriodValues[oInput.id]); 128 }, 129 130 OnChangeP: function(sel) 131 { 132 var selPParent = sel.parentNode.parentNode; 133 var bShowFrom, bShowTo, bShowDirect, bShowSeparate; 134 bShowFrom = bShowTo = bShowDirect = bShowSeparate = false; 135 136 var inputFromWrap = BX.findChild(selPParent, {'className':'adm-input-wrap adm-calendar-inp adm-calendar-first'}); 137 var inputToWrap = BX.findChild(selPParent, {'className':'adm-input-wrap adm-calendar-second'}); 138 var selDirectWrap = BX.findChild(selPParent, {'className':'adm-select-wrap adm-calendar-direction'}); 139 var separator = BX.findChild(selPParent, {'className':'adm-calendar-separate'}); 140 var inputFrom = BX.findChild(selPParent, {'className':'adm-input adm-calendar-from'},true); 141 var inputTo = BX.findChild(selPParent, {'className':'adm-input adm-calendar-to'},true); 142 143 // define who must be shown 144 switch (sel.value) 145 { 146 case "day": 147 case "week": 148 case "month": 149 case "quarter": 150 case "year": 151 bShowDirect=true; 152 BX.CalendarPeriod.OnChangeD(selDirectWrap.children[0]); 153 break; 154 155 case "before": 156 bShowTo = true; 157 break; 158 159 case "after": 160 bShowFrom = true; 161 break; 162 163 case "exact": 164 bShowFrom= true; 165 break; 166 167 case "interval": 168 bShowFrom = bShowTo = bShowSeparate = true; 169 BX.CalendarPeriod.RestoreInput(inputFrom); 170 BX.CalendarPeriod.RestoreInput(inputTo); 171 172 break; 173 174 case "": 175 BX.CalendarPeriod.SaveAndClearInput(inputFrom); 176 BX.CalendarPeriod.SaveAndClearInput(inputTo); 177 break; 178 179 default: 180 break; 181 182 } 183 184 BX.CalendarPeriod.ChangeDirectOpts(sel.value, selPParent); 185 186 inputFromWrap.style.display = (bShowFrom? 'inline-block':'none'); 187 inputToWrap.style.display = (bShowTo? 'inline-block':'none'); 188 selDirectWrap.style.display = (bShowDirect? 'inline-block':'none'); 189 separator.style.display = (bShowSeparate? 'inline-block':'none'); 190 }, 191 192 193 OnChangeD: function(sel) 194 { 195 var selPParent = sel.parentNode.parentNode; 196 var inputFrom = BX.findChild(selPParent, {'className':'adm-input adm-calendar-from'},true); 197 var inputTo = BX.findChild(selPParent, {'className':'adm-input adm-calendar-to'},true); 198 var selPeriod = BX.findChild(selPParent, {'className':'adm-select adm-calendar-period'},true); 199 200 var offset=0; 201 202 switch (sel.value) 203 { 204 case "previous": 205 offset = -1; 206 break; 207 208 case "next": 209 offset = 1; 210 break; 211 212 case "current": 213 default: 214 break; 215 216 } 217 218 var from = false;
219 var to = false; 220 221 var today = new Date(); 222 var year = today.getFullYear(); 223 var month = today.getMonth(); 224 var day = today.getDate(); 225 var dayW = today.getDay(); 226 227 if (dayW == 0) 228 dayW = 7; 229 230 switch (selPeriod.value) 231 { 232 case "day": 233 from = new Date(year, month, day+offset, 0, 0, 0); 234 to = new Date(year, month, day+offset, 23, 59, 59); 235 break; 236 237 case "week": 238 from = new Date(year, month, day-dayW+1+offset*7, 0, 0, 0); 239 to = new Date(year, month, day+(7-dayW)+offset*7, 23, 59, 59); 240 break; 241 242 case "month": 243 from = new Date(year, month+offset, 1, 0, 0, 0); 244 to = new Date(year, month+1+offset, 0, 23, 59, 59); 245 break; 246 247 case "quarter": 248 var quarterNum = Math.floor((month/3))+offset; 249 from = new Date(year, 3*(quarterNum), 1, 0, 0, 0); 250 to = new Date(year, 3*(quarterNum+1), 0, 23, 59, 59); 251 break; 252 253 case "year": 254 from = new Date(year+offset, 0, 1, 0, 0, 0); 255 to = new Date(year+1+offset, 0, 0, 23, 59, 59); 256 break; 257 258 default: 259 break; 260 } 261 262 var format = window[inputFrom.name+"_bTime"] ? BX.message('FORMAT_DATETIME') : BX.message('FORMAT_DATE'); 263 264 if(from) 265 { 266 inputFrom.value = BX.formatDate(from, format); 267 BX.addClass(inputFrom,"adm-calendar-inp-setted"); 268 } 269 270 if(to) 271 { 272 inputTo.value = BX.formatDate(to, format); 273 BX.addClass(inputTo,"adm-calendar-inp-setted"); 274 } 275 } 276}; 277 278 279BX.JCCalendar = function() 280{ 281 this.params = {}; 282 283 this.bAmPm = BX.isAmPmMode(); 284 285 this.popup = null; 286 this.popup_month = null; 287 this.popup_year = null; 288 this.month_popup_classname = ''; 289 this.year_popup_classname = ''; 290 291 this.value = null; 292 293 this.control_id = Math.random(); 294 295 this._layers = {}; 296 this._current_layer = null; 297 298 this.DIV = null; 299 this.PARTS = {}; 300 301 this.weekStart = 0; 302 this.numRows = 6; 303 304 this._create = function(params) 305 { 306 this.popup = new BX.PopupWindow('calendar_popup_' + this.control_id, params.node, { 307 closeByEsc: true, 308 autoHide: false, 309 content: this._get_content(), 310 zIndex: 3000, 311 bindOptions: {forceBindPosition: true} 312 }); 313 314 BX.bind(this.popup.popupContainer, 'click', this.popup.cancelBubble); 315 }; 316 317 this._auto_hide_disable = function() 318 { 319 BX.unbind(document, 'click', BX.proxy(this._auto_hide, this)); 320 }; 321 322 this._auto_hide_enable = function() 323 { 324 BX.bind(document, 'click', BX.proxy(this._auto_hide, this)); 325 }; 326 327 this._auto_hide = function(e) 328 { 329 this._auto_hide_disable(); 330 this.popup.close(); 331 }; 332 333 this._get_content = function() 334 { 335 var _layer_onclick = BX.delegate(function(e) { 336 e = e||window.event; 337 this.SetDate(new Date(parseInt(BX.proxy_context.getAttribute('data-date'))), e.type=='dblclick') 338 }, this); 339 340 this.DIV = BX.create('DIV', { 341 props: {className: 'bx-calendar'}, 342 children: [ 343 BX.create('DIV', { 344 props: { 345 className: 'bx-calendar-header' 346 }, 347 children: [ 348 BX.create('A', { 349 attrs: {href: 'javascript:void(0)'}, 350 props: {className: 'bx-calendar-left-arrow'}, 351 events: {click: BX.proxy(this._prev, this)} 352 }), 353 354 BX.create('SPAN', { 355 props: {className: 'bx-calendar-header-content'}, 356 children: [ 357 (this.PARTS.MONTH = BX.create('A', { 358 attrs: {href: 'javascript:void(0)'}, 359 props: {className: 'bx-calendar-top-month'}, 360 events: {click: BX.proxy(this._menu_month, this)} 361 })), 362 363 (this.PARTS.YEAR = BX.create('A', { 364 attrs: {href: 'javascript:void(0)'}, 365 props: {className: 'bx-calendar-top-year'}, 366 events: {click: BX.proxy(this._menu_year, this)} 367 })) 368 ] 369 }), 370 371 BX.create('A', { 372 attrs: {href: 'javascript:void(0)'}, 373 props: {className: 'bx-calendar-right-arrow'}, 374 events: {click: BX.proxy(this._next, this)} 375 }) 376 ] 377 }), 378 379 (this.PARTS.WEEK = BX.create('DIV', { 380 props: { 381 className: 'bx-calendar-name-day-wrap' 382 } 383 })), 384 385 (this.PARTS.LAYERS = BX.create('DIV', { 386 props: { 387 className: 'bx-calendar-cell-block' 388 }, 389 events: { 390 click: BX.delegateEvent({className: 'bx-calendar-cell'}, _layer_onclick), 391 dblclick: BX.delegateEvent({className: 'bx-calendar-cell'}, _layer_onclick) 392 } 393 })), 394 395 (this.PARTS.TIME = BX.create('DIV', { 396 props: { 397 className: 'bx-calendar-set-time-wrap' 398 }, 399 events: { 400 click: BX.delegateEvent( 401 {attr: 'data-action'}, 402 BX.delegate(this._time_actions, this) 403 ) 404 }, 405 html: '<a href="javascript:void(0)" data-action="time_show" class="bx-calendar-set-time"><i></i>'+BX.message('CAL_TIME_SET')+'</a><div class="bx-calendar-form-block"><span class="bx-calendar-form-text">'+BX.message('CAL_TIME')+'</span><span class="bx-calendar-form"><input type="text" class="bx-calendar-form-input" maxwidth="2" onkeyup="BX.calendar.get()._check_time()" /><span class="bx-calendar-form-separator"></span><input type="text" class="bx-calendar-form-input" maxwidth="2" onkeyup="BX.calendar.get()._check_time()" />'+(this.bAmPm?'<span class="bx-calendar-AM-PM-block"><span class="bx-calendar-AM-PM-text" data-action="time_ampm"></span><span class="bx-calendar-form-arrow-r"><a href="javascript:void(0)" class="bx-calendar-form-arrow-top" data-action="time_ampm_up"><i></i></a><a href="javascript:void(0)" class="bx-calendar-form-arrow-bottom" data-action="time_ampm_down"><i></i></a></span></span>':'')+'</span><a href="javascript:void(0)" data-action="time_hide" class="bx-calendar-form-close"><i></i></a></div>' 406 })), 407 408 BX.create('DIV', { 409 props: {className: 'bx-calendar-button-block'}, 410 events: { 411 click: BX.delegateEvent( 412 {attr: 'data-action'}, 413 BX.delegate(this._button_actions, this) 414 ) 415 }, 416 html: '<a href="javascript:void(0)" class="bx-calendar-button bx-calendar-button-select" data-action="submit"><span class="bx-calendar-button-left"></span><span class="bx-calendar-button-text">'+BX.message('CAL_BUTTON')+'</span><span class="bx-calendar-button-right"></span></a><a href="javascript:void(0)" class="bx-calendar-button bx-calendar-button-cancel" data-action="cancel"><span class="bx-calendar-button-left"></span><span class="bx-calendar-button-text">'+BX.message('JS_CORE_WINDOW_CLOSE')+'</span><span class="bx-calendar-button-right"></span></a>' 417 }) 418 ] 419 }); 420 421 this.PARTS.TIME_INPUT_H = BX.findChild(this.PARTS.TIME, {tag: 'INPUT'}, true); 422 this.PARTS.TIME_INPUT_M = this.PARTS.TIME_INPUT_H.nextSibling.nextSibling; 423 424 if (this.bAmPm) 425 this.PARTS.TIME_AMPM = this.PARTS.TIME_INPUT_M.nextSibling.firstChild; 426 427 var spinner = (new BX.JCSpinner({
428 input: this.PARTS.TIME_INPUT_H, 429 callback_change: BX.proxy(this._check_time, this), 430 bSaveValue: false 431 })).Show(); 432 spinner.className = 'bx-calendar-form-arrow-l'; 433 this.PARTS.TIME_INPUT_H.parentNode.insertBefore(spinner, this.PARTS.TIME_INPUT_H); 434 435 spinner = (new BX.JCSpinner({ 436 input: this.PARTS.TIME_INPUT_M, 437 callback_change: BX.proxy(this._check_time, this), 438 bSaveValue: true 439 })).Show(); 440 spinner.className = 'bx-calendar-form-arrow-r'; 441 if (!this.PARTS.TIME_INPUT_M.nextSibling) 442 this.PARTS.TIME_INPUT_M.parentNode.appendChild(spinner); 443 else 444 this.PARTS.TIME_INPUT_M.parentNode.insertBefore(spinner, this.PARTS.TIME_INPUT_M.nextSibling); 445 446 for (var i = 0; i < 7; i++) 447 { 448 this.PARTS.WEEK.appendChild(BX.create('SPAN', { 449 props: { 450 className: 'bx-calendar-name-day' 451 }, 452 text: BX.message('DOW_' + ((i + this.weekStart) % 7)) 453 })); 454 } 455 456 return this.DIV; 457 }; 458 459 this._time_actions = function() 460 { 461 switch (BX.proxy_context.getAttribute('data-action')) 462 { 463 case 'time_show': 464 BX.addClass(this.PARTS.TIME, 'bx-calendar-set-time-opened'); 465 this.popup.adjustPosition(); 466 break; 467 case 'time_hide': 468 BX.removeClass(this.PARTS.TIME, 'bx-calendar-set-time-opened'); 469 this.popup.adjustPosition(); 470 break; 471 case 'time_ampm': 472 this.PARTS.TIME_AMPM.innerHTML = this.PARTS.TIME_AMPM.innerHTML == 'AM' ? 'PM' : 'AM'; 473 break; 474 case 'time_ampm_up': 475 this._check_time({bSaveValue: false}, null, 12); 476 return; 477 break; 478 case 'time_ampm_down': 479 this._check_time({bSaveValue: false}, null, -12); 480 return; 481 break; 482 } 483 484 this._check_time(); 485 }; 486 487 this._button_actions = function() 488 { 489 switch (BX.proxy_context.getAttribute('data-action')) 490 { 491 case 'submit': 492 this.SaveValue(); 493 break; 494 case 'cancel': 495 this.Close(); 496 break; 497 } 498 }; 499 500 this._check_time = function(params, value, direction) 501 { 502 var h = parseInt(this.PARTS.TIME_INPUT_H.value.substring(0,5),10)||0, 503 m = parseInt(this.PARTS.TIME_INPUT_M.value.substring(0,5),10)||0, 504 bChanged = false; 505 506 if (!!params && !params.bSaveValue) 507 { 508 this.value.setUTCHours(this.value.getUTCHours() + direction); 509 } 510 else if (!isNaN(h)) 511 { 512 if (this.bAmPm) 513 { 514 if (h != 12 && this.PARTS.TIME_AMPM.innerHTML == 'PM') 515 { 516 h += 12; 517 } 518 } 519 520 bChanged = true; 521 this.value.setUTCHours(h % 24); 522 } 523 524 if (!isNaN(m)) 525 { 526 bChanged = true; 527 this.value.setUTCMinutes(m % 60); 528 } 529 530 if (bChanged) 531 { 532 this.SetValue(this.value); 533 } 534 }; 535 536 this._set_layer = function() 537 { 538 var layerId = parseInt(this.value.getUTCFullYear() + '' + BX.util.str_pad_left(this.value.getUTCMonth()+'', 2, "0")); 539 540 if (!this._layers[layerId]) 541 { 542 this._layers[layerId] = this._create_layer(); 543 this._layers[layerId].BXLAYERID = layerId; 544 } 545 546 if (this._current_layer) 547 { 548 var v = new Date(this.value.valueOf()); 549 v.setUTCHours(0); v.setUTCMinutes(0); 550 551 var cur_value = BX.findChild(this._layers[layerId], { 552 tag: 'A', 553 className: 'bx-calendar-active' 554 }, true), 555 new_value = BX.findChild(this._layers[layerId], { 556 tag: 'A', 557 attr: { 558 'data-date' : v.valueOf() + '' 559 } 560 }, true); 561 562 if (cur_value) 563 { 564 BX.removeClass(cur_value, 'bx-calendar-active'); 565 } 566 567 if (new_value) 568 { 569 BX.addClass(new_value, 'bx-calendar-active'); 570 } 571 572 this._replace_layer(this._current_layer, this._layers[layerId]); 573 } 574 else 575 { 576 this.PARTS.LAYERS.appendChild(this._layers[layerId]); 577 } 578 579 this._current_layer = this._layers[layerId]; 580 }; 581 582 this._replace_layer = function(old_layer, new_layer) 583 { 584 if (old_layer != new_layer) 585 { 586 if (!BX.browser.IsIE() || BX.browser.IsDoctype()) 587 { 588 var dir = old_layer.BXLAYERID > new_layer.BXLAYERID ? 1 : -1; 589 590 var old_top = 0; 591 var new_top = -dir * old_layer.offsetHeight; 592 593 old_layer.style.position = 'relative'; 594 old_layer.style.top = "0px"; 595 old_layer.style.zIndex = 5; 596 597 new_layer.style.position = 'absolute'; 598 new_layer.style.top = new_top + 'px'; 599 new_layer.style.zIndex = 6; 600 601 this.PARTS.LAYERS.appendChild(new_layer); 602 603 var delta = 15; 604 605 var f; 606 (f = function() { 607 new_top += dir * delta; 608 old_top += dir * delta; 609 610 if (dir * new_top < 0) 611 { 612 old_layer.style.top = old_top + 'px'; 613 new_layer.style.top = new_top + 'px'; 614 setTimeout(f, 10); 615 } 616 else 617 { 618 old_layer.parentNode.removeChild(old_layer); 619 620 new_layer.style.top = "0px"; 621 new_layer.style.position = 'static'; 622 new_layer.style.zIndex = 0; 623 } 624 })(); 625 } 626 else 627 {
628 this.PARTS.LAYERS.replaceChild(new_layer, old_layer); 629 } 630 } 631 }; 632 633 this._create_layer = function() 634 { 635 var l = BX.create('DIV', { 636 props: { 637 className: 'bx-calendar-layer' 638 } 639 }); 640 641 var month_start = new Date(this.value); 642 month_start.setUTCHours(0); 643 month_start.setUTCMinutes(0); 644 645 month_start.setUTCDate(1); 646 647 if (month_start.getUTCDay() != this.weekStart) 648 { 649 var d = month_start.getUTCDay() - this.weekStart; 650 d += d < 0 ? 7 : 0; 651 month_start.setUTCDate(month_start.getUTCDate()-d); 652 } 653 654 var cur_month = this.value.getUTCMonth(), 655 cur_day = this.value.getUTCDate(), 656 s = ''; 657 for (var i = 0; i < this.numRows; i++) 658 { 659 s += '<div class="bx-calendar-range' 660 +(i == this.numRows-1 ? ' bx-calendar-range-noline' : '') 661 +'">'; 662 663 for (var j = 0; j < 7; j++) 664 { 665 d = month_start.getUTCDate(); 666 var wd = month_start.getUTCDay(); 667 var className = 'bx-calendar-cell'; 668 669 if (cur_month != month_start.getUTCMonth()) 670 className += ' bx-calendar-date-hidden'; 671 else if (cur_day == d) 672 className += ' bx-calendar-active'; 673 674 675 if (wd == 0 || wd == 6) 676 className += ' bx-calendar-weekend'; 677 678 s += '<a href="javascript:void(0)" class="'+className+'" data-date="' + month_start.valueOf() + '">' + d + '</a>'; 679 680 month_start.setUTCDate(month_start.getUTCDate()+1); 681 } 682 s += '</div>'; 683 } 684 685 l.innerHTML = s; 686 687 return l; 688 }; 689 690 this._prev = function() 691 { 692 this.SetMonth(this.value.getUTCMonth()-1); 693 }; 694 695 this._next = function() 696 { 697 this.SetMonth(this.value.getUTCMonth()+1); 698 }; 699 700 this._menu_month_content = function() 701 { 702 var months = '', cur_month = this.value.getMonth(), i; 703 for (i = 0; i < 12; i++) 704 { 705 months += '<span class="bx-calendar-month'+(i == cur_month ? ' bx-calendar-month-active' : '')+'" data-bx-month="' + i + '">' + BX.message('MONTH_' + (i + 1)) + '</span>'; 706 } 707 708 return '<div class="bx-calendar-month-popup"><div class="bx-calendar-month-title" data-bx-month="' + this.value.getUTCMonth() + '">' + BX.message('MONTH_' + (this.value.getUTCMonth() + 1)) + '</div><div class="bx-calendar-month-content">' + months + '</div></div>'; 709 }; 710 711 this._menu_month = function() 712 { 713 if (!this.popup_month) 714 { 715 this.popup_month = new BX.PopupWindow( 716 'calendar_popup_month_' + this.control_id, this.PARTS.MONTH, 717 { 718 content: this._menu_month_content(), 719 zIndex: 3001, 720 closeByEsc: true, 721 autoHide: true, 722 offsetTop: -29, 723 offsetLeft: -1, 724 className: this.month_popup_classname, 725 events: { 726 onPopupShow: BX.delegate(function() { 727 if (this.popup_year) 728 { 729 this.popup_year.close(); 730 } 731 }, this) 732 } 733 } 734 ); 735 736 BX.bind(this.popup_month.popupContainer, 'click', BX.proxy(this.month_popup_click, this)); 737 this.popup_month.BXMONTH = this.value.getUTCMonth(); 738 } 739 else if (this.popup_month.BXMONTH != this.value.getUTCMonth()) 740 { 741 this.popup_month.setContent(this._menu_month_content()); 742 this.popup_month.BXMONTH = this.value.getUTCMonth(); 743 } 744 745 this.popup_month.show(); 746 }; 747 748 this.month_popup_click = function(e) 749 { 750 var target = e.target || e.srcElement; 751 if (target && target.getAttribute && target.getAttribute('data-bx-month')) 752 { 753 this.SetMonth(parseInt(target.getAttribute('data-bx-month'))); 754 this.popup_month.close(); 755 } 756 }; 757 758 this._menu_year_content = function() 759 { 760 var s = '<div class="bx-calendar-year-popup"><div class="bx-calendar-year-title" data-bx-year="' + this.value.getUTCFullYear() + '">' + this.value.getUTCFullYear() + '</div><div class="bx-calendar-year-content" id="bx-calendar-year-content">'; 761 762 for (var i=-3; i <= 3; i++) 763 { 764 s += '<span class="bx-calendar-year-number' + (i == 0?' bx-calendar-year-active' : '') + '" data-bx-year="' + (this.value.getUTCFullYear() - i) + '">' + (this.value.getUTCFullYear() - i)+'</span>'; 765 } 766 767 s += '</div><input data-bx-year-input="Y" type="text" class="bx-calendar-year-input" maxlength="4" /></div>'; 768 769 return s; 770 }; 771 772 this._menu_year = function() 773 { 774 if (!this.popup_year) 775 { 776 this.popup_year = new BX.PopupWindow( 777 'calendar_popup_year_' + this.control_id, this.PARTS.YEAR, 778 { 779 content: this._menu_year_content(), 780 zIndex: 3001, 781 closeByEsc: true, 782 autoHide: true, 783 offsetTop: -29, 784 offsetLeft: -1, 785 className: this.year_popup_classname, 786 events: { 787 onPopupShow: BX.delegate(function() { 788 if (this.popup_month) 789 { 790 this.popup_month.close(); 791 } 792 }, this) 793 } 794 } 795 ); 796 797 BX.bind(this.popup_year.popupContainer, 'click', BX.proxy(this.year_popup_click, this)); 798 BX.bind(this.popup_year.popupContainer, 'keyup', BX.proxy(this.year_popup_keyup, this)); 799 this.popup_year.BXYEAR = this.value.getUTCFullYear(); 800 } 801 else if (this.popup_year.BXYEAR != this.value.getUTCFullYear()) 802 { 803 this.popup_year.setContent(this._menu_year_content()); 804 this.popup_year.BXYEAR = this.value.getUTCFullYear(); 805 } 806 807 this.popup_year.show(); 808 }; 809 810 this.year_popup_click = function(e) 811 { 812 var target = e.target || e.srcElement; 813 if (target && target.getAttribute && target.getAttribute('data-bx-year')) 814 { 815 this.SetYear(parseInt(target.getAttribute('data-bx-year'))); 816 this.popup_year.close(); 817 } 818 }; 819 this.year_popup_keyup = function(e) 820 { 821 var target = e.target || e.srcElement; 822 if (target && target.getAttribute && target.getAttribute('data-bx-year-input') == 'Y') 823 { 824 var value = parseInt(target.value); 825 if(value >= 1900 && value <= 2100) 826 { 827 this.SetYear(value); 828 this.popup_year.close(); 829 } 830 } 831 }; 832 833 this._check_date = function(v) 834 { 835 var res = v; 836 837 if (BX.type.isString(v)) 838 { 839 res = BX.parseDate(v, true); 840 } 841 842 if (!BX.type.isDate(res) || isNaN(res.valueOf())) 843 { 844 res = BX.date.convertToUTC(new Date()); 845 if (this.params.bHideTime) 846 { 847 res.setUTCHours(0); 848 res.setUTCMinutes(0); 849 } 850 } 851 852 res.setUTCMilliseconds(0); 853 res.setUTCSeconds(0); 854 855 res.BXCHECKED = true; 856 857 return res; 858 }; 859}; 860 861BX.JCCalendar.prototype.Show = function(params) 862{ 863 if (!BX.isReady) 864 { 865 BX.ready(BX.delegate(function() {this.Show(params)}, this)); 866 return; 867 } 868 869 params.node = params.node||document.body; 870 871 if (BX.type.isNotEmptyString(params.node)) 872 { 873 var n = BX(params.node); 874 if (!n) 875 { 876 n = document.getElementsByName(params.node); 877 if (n && n.length > 0) 878 { 879 n = n[0] 880 } 881 } 882 params.node = n; 883 } 884 885 if (!params.node) 886 return; 887 888 if (!!params.field) 889 { 890 if (BX.type.isString(params.field)) 891 { 892 n = BX(params.field); 893 if (!!n) 894 { 895 params.field = n; 896 } 897 else 898 {
899 if (params.form) 900 { 901 if (BX.type.isString(params.form)) 902 { 903 params.form = document.forms[params.form]; 904 } 905 } 906 907 if (BX.type.isDomNode(params.form) && !!params.form[params.field]) 908 { 909 params.field = params.form[params.field]; 910 } 911 else 912 { 913 n = document.getElementsByName(params.field); 914 if (n && n.length > 0) 915 { 916 n = n[0]; 917 params.field = n; 918 } 919 } 920 } 921 922 if (BX.type.isString(params.field)) 923 { 924 params.field = BX(params.field); 925 } 926 } 927 } 928 929 var bShow = !this.popup || !this.popup.isShown() || this.params.node != params.node; 930 931 this.params = params; 932 933 this.params.bTime = typeof this.params.bTime == 'undefined' ? true : !!this.params.bTime; 934 this.params.bHideTime = typeof this.params.bHideTime == 'undefined' ? true : !!this.params.bHideTime; 935 this.params.bUseSecond = typeof this.params.bUseSecond == 'undefined' ? true : !!this.params.bUseSecond; 936 937 this.weekStart = parseInt(this.params.weekStart || this.params.weekStart || BX.message('WEEK_START')); 938 if (isNaN(this.weekStart)) 939 this.weekStart = 1; 940 941 if (!this.popup) 942 { 943 this._create(this.params); 944 } 945 else 946 { 947 this.popup.setBindElement(this.params.node); 948 } 949 950 var bHideTime = !!this.params.bHideTime; 951 if (this.params.value) 952 { 953 this.SetValue(this.params.value); 954 bHideTime = this.value.getUTCHours() <= 0 && this.value.getUTCMinutes() <= 0; 955 } 956 else if (this.params.field) 957 { 958 this.SetValue(this.params.field.value); 959 bHideTime = this.value.getUTCHours() <= 0 && this.value.getUTCMinutes() <= 0; 960 } 961 else if (!!this.params.currentTime) 962 { 963 this.SetValue(this.params.currentTime); 964 } 965 else 966 { 967 this.SetValue(); 968 } 969 970 if (!!this.params.bTime) 971 BX.removeClass(this.DIV, 'bx-calendar-time-disabled'); 972 else 973 BX.addClass(this.DIV, 'bx-calendar-time-disabled'); 974 975 if (!!bHideTime) 976 BX.removeClass(this.PARTS.TIME, 'bx-calendar-set-time-opened'); 977 else 978 BX.addClass(this.PARTS.TIME, 'bx-calendar-set-time-opened'); 979 980 if (bShow) 981 { 982 this._auto_hide_disable(); 983 this.popup.show(); 984 setTimeout(BX.proxy(this._auto_hide_enable, this), 0); 985 } 986 987 this.params.bSetFocus = typeof this.params.bSetFocus == 'undefined' ? true : !!this.params.bSetFocus; 988 if(this.params.bSetFocus) 989 { 990 params.node.blur(); 991 } 992 else 993 { 994 BX.bind(params.node, 'keyup', BX.defer(function(){ 995 this.SetValue(params.node.value); 996 if(!!this.params.bTime) 997 { 998 if(this.value.getUTCHours() <= 0 && this.value.getUTCMinutes() <= 0) 999 BX.removeClass(this.PARTS.TIME, 'bx-calendar-set-time-opened'); 1000 else 1001 BX.addClass(this.PARTS.TIME, 'bx-calendar-set-time-opened'); 1002 } 1003 }, this)); 1004 } 1005 1006 return this; 1007}; 1008 1009BX.JCCalendar.prototype.SetDay = function(d) 1010{ 1011 this.value.setUTCDate(d); 1012 return this.SetValue(this.value); 1013}; 1014 1015BX.JCCalendar.prototype.SetMonth = function(m) 1016{ 1017 if (this.popup_month) 1018 this.popup_month.close(); 1019 1020 this.value.setUTCMonth(m); 1021 1022 if(m < 0) 1023 m += 12; 1024 else if (m >= 12) 1025 m -= 12; 1026 1027 while(this.value.getUTCMonth() > m) 1028 { 1029 this.value.setUTCDate(this.value.getUTCDate()-1); 1030 } 1031 1032 return this.SetValue(this.value); 1033}; 1034 1035BX.JCCalendar.prototype.SetYear = function(y) 1036{ 1037 if (this.popup_year) 1038 this.popup_year.close(); 1039 this.value.setUTCFullYear(y); 1040 return this.SetValue(this.value); 1041}; 1042 1043BX.JCCalendar.prototype.SetDate = function(v, bSet) 1044{ 1045 v = this._check_date(v); 1046 v.setUTCHours(this.value.getUTCHours()); 1047 v.setUTCMinutes(this.value.getUTCMinutes()); 1048 v.setUTCSeconds(this.value.getUTCSeconds()); 1049 1050 if (this.params.bTime && !bSet) 1051 { 1052 return this.SetValue(v); 1053 } 1054 else 1055 { 1056 this.SetValue(v); 1057 this.SaveValue(); 1058 } 1059}; 1060 1061BX.JCCalendar.prototype.SetValue = function(v) 1062{ 1063 this.value = (v && v.BXCHECKED) ? v : this._check_date(v); 1064 1065 this.PARTS.MONTH.innerHTML = BX.message('MONTH_' + (this.value.getUTCMonth()+1)); 1066 this.PARTS.YEAR.innerHTML = this.value.getUTCFullYear(); 1067 1068 if (!!this.params.bTime) 1069 { 1070 var h = this.value.getUTCHours(); 1071 if (this.bAmPm) 1072 { 1073 if (h >= 12) 1074 { 1075 this.PARTS.TIME_AMPM.innerHTML = 'PM'; 1076 1077 if (h != 12) 1078 h -= 12; 1079 } 1080 else 1081 { 1082 this.PARTS.TIME_AMPM.innerHTML = 'AM'; 1083 1084 if (h == 0) 1085 h = 12; 1086 } 1087 } 1088 1089 this.PARTS.TIME_INPUT_H.value = BX.util.str_pad_left(h.toString(), 2, "0"); 1090 this.PARTS.TIME_INPUT_M.value = BX.util.str_pad_left(this.value.getUTCMinutes().toString(), 2, "0"); 1091 } 1092 1093 this._set_layer(); 1094 1095 return this; 1096}; 1097 1098BX.JCCalendar.prototype.SaveValue = function() 1099{ 1100 if (this.popup_month) 1101 this.popup_month.close(); 1102 if (this.popup_year) 1103 this.popup_year.close(); 1104 1105 var bSetValue = true; 1106 if (!!this.params.callback) 1107 { 1108 var res = this.params.callback.apply(this, [new Date(this.value.valueOf()+this.value.getTimezoneOffset()*60000)]); 1109 if (res === false) 1110 bSetValue = false;
1111 } 1112 1113 if (bSetValue) 1114 { 1115 var bTime = !!this.params.bTime && BX.hasClass(this.PARTS.TIME, 'bx-calendar-set-time-opened'); 1116 1117 if (this.params.field) 1118 { 1119 var format = BX.message(bTime ? 'FORMAT_DATETIME' : 'FORMAT_DATE'); 1120 1121 if(bTime && !this.params.bUseSecond) 1122 { 1123 format = format.replace(':SS', ''); 1124 } 1125 1126 this.params.field.value = BX.calendar.ValueToStringFormat(this.value, format, true); 1127 BX.fireEvent(this.params.field, 'change'); 1128 } 1129 1130 this.popup.close(); 1131 1132 if (!!this.params.callback_after) 1133 { 1134 this.params.callback_after.apply(this, [new Date(this.value.valueOf()+this.value.getTimezoneOffset()*60000), bTime]); 1135 } 1136 } 1137 1138 return this; 1139}; 1140 1141BX.JCCalendar.prototype.Close = function() 1142{ 1143 if (!!this.popup) 1144 this.popup.close(); 1145 1146 return this; 1147}; 1148 1149BX.JCSpinner = function(params) 1150{ 1151 params = params || {}; 1152 this.params = { 1153 input: params.input || null, 1154 1155 delta: params.delta || 1, 1156 1157 timeout_start: params.timeout_start || 1000, 1158 timeout_cont: params.timeout_cont || 150, 1159 1160 callback_start: params.callback_start || null, 1161 callback_change: params.callback_change || null, 1162 callback_finish: params.callback_finish || null, 1163 1164 bSaveValue: typeof params.bSaveValue == 'undefined' ? !!params.input : !!params.bSaveValue 1165 }; 1166 1167 this.mousedown = false; 1168 this.direction = 1; 1169}; 1170 1171BX.JCSpinner.prototype.Show = function() 1172{ 1173 this.node = BX.create('span', { 1174 events: { 1175 mousedown: BX.delegateEvent( 1176 {attr: 'data-dir'}, 1177 BX.delegate(this.Start, this) 1178 ) 1179 }, 1180 html: '<a href="javascript:void(0)" class="bx-calendar-form-arrow bx-calendar-form-arrow-top" data-dir="1"><i></i></a><a href="javascript:void(0)" class="bx-calendar-form-arrow bx-calendar-form-arrow-bottom" data-dir="-1"><i></i></a>' 1181 }); 1182 return this.node; 1183}; 1184 1185BX.JCSpinner.prototype.Start = function() 1186{ 1187 this.mousedown = true; 1188 this.direction = BX.proxy_context.getAttribute('data-dir') > 0 ? 1 : -1; 1189 BX.bind(document, "mouseup", BX.proxy(this.MouseUp, this)); 1190 this.ChangeValue(true); 1191}; 1192 1193BX.JCSpinner.prototype.ChangeValue = function(bFirst) 1194{ 1195 if(!this.mousedown) 1196 return; 1197 1198 if (this.params.input) 1199 { 1200 var v = parseInt(this.params.input.value, 10) + this.params.delta * this.direction; 1201 1202 if (this.params.bSaveValue) 1203 this.params.input.value = v; 1204 1205 if (!!bFirst && this.params.callback_start) 1206 this.params.callback_start(this.params, v, this.direction); 1207 1208 if (this.params.callback_change) 1209 this.params.callback_change(this.params, v, this.direction); 1210 1211 setTimeout( 1212 BX.proxy(this.ChangeValue, this), 1213 !!bFirst ? this.params.timeout_start : this.params.timeout_cont 1214 ); 1215 } 1216}; 1217 1218BX.JCSpinner.prototype.MouseUp = function() 1219{ 1220 this.mousedown = false; 1221 BX.unbind(document, "mouseup", BX.proxy(this.MouseUp, this)); 1222 1223 if (this.params.callback_finish) 1224 this.params.callback_finish(this.params, this.params.input.value); 1225}; 1226 1227/**************** compatibility hacks ***************************/ 1228 1229window.jsCalendar = { 1230 Show: function(obj, field, fieldFrom, fieldTo, bTime, serverTime, form_name, bHideTimebar) 1231 { 1232 return BX.calendar({ 1233 node: obj, field: field, form: form_name, bTime: !!bTime, currentTime: serverTime, bHideTimebar: !!bHideTimebar 1234 }); 1235 }, 1236 1237 ValueToString: BX.calendar.ValueToString 1238}; 1239 1240 1241/************ clock popup transferred from timeman **************/ 1242 1243BX.CClockSelector = function(params) 1244{ 1245 this.params = params; 1246 1247 this.params.popup_buttons = this.params.popup_buttons || [ 1248 new BX.PopupWindowButton({ 1249 text : BX.message('CAL_BUTTON'), 1250 className : "popup-window-button-create", 1251 events : {click : BX.proxy(this.setValue, this)} 1252 }) 1253 ]; 1254 1255 this.isReady = false; 1256 1257 this.WND = new BX.PopupWindow( 1258 this.params.popup_id || 'clock_selector_popup', 1259 this.params.node, 1260 this.params.popup_config || { 1261 titleBar: BX.message('CAL_TIME'), 1262 offsetLeft: -45, 1263 offsetTop: -135, 1264 autoHide: true, 1265 closeIcon: true, 1266 closeByEsc: true, 1267 zIndex: this.params.zIndex 1268 } 1269 ); 1270 1271 this.SHOW = false;
1272 BX.addCustomEvent(this.WND, "onPopupClose", BX.delegate(this.onPopupClose, this)); 1273 1274 this.obClocks = {}; 1275 this.CLOCK_ID = this.params.clock_id || 'clock_selector'; 1276}; 1277 1278BX.CClockSelector.prototype.Show = function() 1279{ 1280 if (!this.isReady) 1281 { 1282 //BX.timeman.showWait(this.parent.DIV); 1283 1284 BX.addCustomEvent('onClockRegister', BX.proxy(this.onClockRegister, this)); 1285 return BX.ajax.get('/bitrix/tools/clock_selector.php', {start_time: this.params.start_time, clock_id: this.CLOCK_ID, sessid: BX.bitrix_sessid()}, BX.delegate(this.Ready, this)); 1286 } 1287 1288 this.WND.setButtons(this.params.popup_buttons); 1289 this.WND.show(); 1290 1291 this.SHOW = true; 1292 1293 if (window['bxClock_' + this.obClocks[this.CLOCK_ID]]) 1294 { 1295 setTimeout("window['bxClock_" + this.obClocks[this.CLOCK_ID] + "'].CalculateCoordinates()", 40); 1296 } 1297 1298 return true; 1299}; 1300 1301BX.CClockSelector.prototype.onClockRegister = function(obClocks) 1302{ 1303 if (obClocks[this.CLOCK_ID]) 1304 { 1305 this.obClocks[this.CLOCK_ID] = obClocks[this.CLOCK_ID]; 1306 BX.removeCustomEvent('onClockRegister', BX.proxy(this.onClockRegister, this)); 1307 } 1308}; 1309 1310BX.CClockSelector.prototype.Ready = function(data) 1311{ 1312 this.content = this.CreateContent(data); 1313 this.WND.setContent(this.content); 1314 1315 this.isReady = true; 1316 //BX.timeman.closeWait(); 1317 1318 setTimeout(BX.proxy(this.Show, this), 30); 1319}; 1320 1321BX.CClockSelector.prototype.CreateContent = function(data) 1322{ 1323 return BX.create('DIV', { 1324 events: {click: BX.PreventDefault}, 1325 html: 1326 '<div class="bx-tm-popup-clock">' + data + '</div>' 1327 }); 1328}; 1329 1330BX.CClockSelector.prototype.setValue = function(e) 1331{ 1332 if (this.params.callback) 1333 { 1334 var input = BX.findChild(this.content, {tagName: 'INPUT'}, true); 1335 this.params.callback.apply(this.params.node, [input.value]); 1336 } 1337 1338 return BX.PreventDefault(e); 1339}; 1340 1341BX.CClockSelector.prototype.closeWnd = function(e) 1342{ 1343 this.WND.close(); 1344 return (e || window.event) ? BX.PreventDefault(e) : true; 1345}; 1346 1347BX.CClockSelector.prototype.setNode = function(node) 1348{ 1349 this.WND.setBindElement(node); 1350}; 1351 1352BX.CClockSelector.prototype.setTime = function(timestamp) 1353{ 1354 this.params.start_time = timestamp; 1355 if (window['bxClock_' + this.obClocks[this.CLOCK_ID]]) 1356 { 1357 window['bxClock_' + this.obClocks[this.CLOCK_ID]].SetTime(parseInt(timestamp/3600), parseInt((timestamp%3600)/60)); 1358 } 1359}; 1360 1361BX.CClockSelector.prototype.setCallback = function(cb) 1362{ 1363 this.params.callback = cb; 1364}; 1365 1366BX.CClockSelector.prototype.onPopupClose = function() 1367{ 1368 this.SHOW = false;
1369}; 1370 1371})();
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.