1(function ($) { 2 3 "use strict"; 4 5 function createEventForm() { 6 7 var $instance = ''; 8 var instance = ''; 9 var blockForm = false; 10 var valid = false; 11 var captchaContainer = null; 12 var $theForm = null; 13 var glob = { 14 options: null, 15 template: { 16 preloader: null 17 } 18 }; 19 20 this.init = function (atts) { 21 22 glob.options = atts; 23 24 instance = '#' + glob.options.id; 25 $instance = $(instance); 26 27 $theForm = $instance; 28 $theForm.toggleClass('active'); 29 $theForm.find('.stec-layout-event-create-form-preview-right-event-toggle').toggleClass('active'); 30 31 glob.template.preloader = $instance.children(".stec-preloader-template").html(); 32 33 datePicker.set(); 34 colorPicker.set(); 35 36 // Only 1 calendar; hide the selector 37 if ( $theForm.find('[name="calendar_id"]').children().length == 2 ) { 38 39 $theForm.find('[name="calendar_id"]').val($theForm 40 .find('[name="calendar_id"] option:last').val()); 41 42 $theForm.find('[name="calendar_id"]').parents('div:first').hide(); 43 44 var color = $theForm.find('[name="calendar_id"]').find('option:selected').data('color'); 45 46 $theForm.find('[name="event_color"]').css({ 47 background: color 48 }).val(color); 49 50 } 51 52 if ( glob.options.captcha.enabled == '1' ) { 53 captchaContainer = null; 54 55 if ( $theForm.find('.stec-layout-event-create-form-g-recaptcha').children().length <= 0 ) { 56 captchaContainer = window.grecaptcha.render($theForm.find('.stec-layout-event-create-form-g-recaptcha').get(0), { 57 sitekey: glob.options.captcha.site_key, 58 callback: function (response) { 59 if ( response.length != 0 ) { 60 valid = true; 61 } 62 } 63 }); 64 } 65 } else { 66 // captcha is disabled 67 valid = true; 68 } 69 70 if ( glob.options.selector ) { 71 72 if ( $('.stec-create-form-popup-blackscreen').length <= 0 ) { 73 $('<div class="stec-create-form-popup-blackscreen"></div>').appendTo('body'); 74 } 75 76 $theForm.addClass('is-popup'); 77 78 $theForm.hide(); 79 } 80 81 bindControls(); 82 }; 83 84 var helper = { 85 86 isMobile: function () { 87 return (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) ? true : false; 88 }, 89 90 clickHandle: function (sub) { 91 92 var tap = sub ? 'vclick.' + sub : 'vclick'; 93 var click = sub ? 'click.' + sub : 'click'; 94 95 return this.isMobile() ? tap : click; 96 97 } 98 }; 99 100 var check_disabled_fields = function () { 101 102 switch ( $('input[name="repeat_endson"]').filter(":checked").val() ) { 103 104 case '0' : 105 //never 106 $theForm.find('input[name="repeat_occurences"]').attr('disabled', 'disabled'); 107 $theForm.find('input[name="repeat_ends_on_date"]').attr('disabled', 'disabled'); 108 break; 109 case '1' : 110 // after n 111 $theForm.find('input[name="repeat_occurences"]').removeAttr('disabled'); 112 $theForm.find('input[name="repeat_ends_on_date"]').attr('disabled', 'disabled'); 113 break; 114 case '2' : 115 // on date 116 $theForm.find('input[name="repeat_occurences"]').attr('disabled', 'disabled'); 117 $theForm.find('input[name="repeat_ends_on_date"]').removeAttr('disabled'); 118 break; 119 } 120 121 }; 122 123 var update_rrule = function () { 124 125 var freq = $theForm.find('select[name="event_repeat"]').val(); 126 var byweekday = []; 127 128 switch ( freq ) { 129 case '0' : 130 freq = false;
131 break; 132 case '1' : 133 freq = RRule.DAILY; 134 break; 135 case '2' : 136 freq = RRule.WEEKLY; 137 138 $theForm.find('.stec-layout-event-create-form-inner-weekly-by-day') 139 .find('input[type="checkbox"]') 140 .filter(':checked') 141 .each(function () { 142 143 byweekday.push(RRule[$(this).attr('name')]); 144 145 }); 146 147 break; 148 case '3' : 149 freq = RRule.MONTHLY; 150 break; 151 case '4' : 152 freq = RRule.YEARLY; 153 break; 154 } 155 156 var interval = $theForm.find('input[name="repeat_gap"]').val(); 157 var count = false; 158 var until = false; 159 160 switch ( $theForm.find('input[name="repeat_endson"]').filter(":checked").val() ) { 161 162 case '0' : 163 //never 164 count = false; 165 until = false;
166 break; 167 168 case '1' : 169 // after n 170 count = $theForm.find('input[name="repeat_occurences"]').val(); 171 until = false; 172 173 break; 174 175 case '2' : 176 // on date 177 count = false; 178 until = new Date($theForm.find('input[name="repeat_ends_on_date"]').val()); 179 break; 180 } 181 182 var rr_options = {}; 183 184 rr_options.freq = freq; 185 186 if ( count > 0 ) { 187 rr_options.count = count; 188 } 189 190 if ( until ) { 191 rr_options.until = until; 192 } 193 194 if ( interval > 0 ) { 195 rr_options.interval = interval; 196 } 197 198 if ( byweekday.length > 0 ) { 199 rr_options.byweekday = byweekday; 200 } 201 202 var the_rule = ''; 203 204 if ( freq !== false ) { 205 // Set rule 206 the_rule = new RRule(rr_options); 207 208 209 } else { 210 // Empty rrule 211 the_rule = new RRule(); 212 213 } 214 215 var rrule = the_rule.toString(); 216 217 $theForm.find('input[name="rrule"]').val(rrule); 218 219 }; 220 221 var datePicker = { 222 223 set: function () { 224 225 var parent = this; 226 227 $theForm.find('[name="start_date"]') 228 .datepicker("destroy") 229 .datepicker({ 230 setDate: glob.options.year + '-' + glob.options.month + '-' + glob.options.day, 231 showAnim: 0, 232 minDate: glob.options.create_event_form_allow_expired == 1 ? null : 0, 233 dateFormat: "yy-mm-dd", 234 onSelect: function () { 235 $theForm.find('[name="end_date"]').datepicker('option', 'minDate', $(this).val()); 236 datePicker.generalTimeFix(); 237 } 238 }) 239 .datepicker("setDate", new Date(glob.options.year, glob.options.month, glob.options.day)); 240 241 $theForm.find('[name="end_date"]') 242 .datepicker("destroy") 243 .datepicker({ 244 setDate: glob.options.year + '-' + glob.options.month + '-' + glob.options.day, 245 showAnim: 0, 246 minDate: glob.options.create_event_form_allow_expired == 1 ? null : 0, 247 dateFormat: "yy-mm-dd", 248 onSelect: function () { 249 $theForm.find('[name="start_date"]').datepicker('option', 'maxDate', $(this).val()); 250 datePicker.generalTimeFix(); 251 } 252 }) 253 .datepicker("setDate", new Date(glob.options.year, glob.options.month, glob.options.day)); 254 255 $theForm.find('[name="repeat_ends_on_date"]') 256 .datepicker("destroy") 257 .datepicker(); 258 }, 259 260 generalTimeFix: function () { 261 262 var $startDate = $theForm.find('[name="start_date"]'); 263 var $endDate = $theForm.find('[name="end_date"]'); 264 265 var $startHours = $theForm.find('[name="start_time_hours"]'); 266 var $endHours = $theForm.find('[name="end_time_hours"]'); 267 268 var $startMinutes = $theForm.find('[name="start_time_minutes"]'); 269 var $endMinutes = $theForm.find('[name="end_time_minutes"]'); 270 271 var start = new Date($startDate.val()); 272 start.setHours($startHours.val()); 273 start.setMinutes($startMinutes.val()); 274 275 276 var end = new Date($endDate.val()); 277 end.setHours($endHours.val()); 278 end.setMinutes($endMinutes.val()); 279 280 if ( start.getTime() > end.getTime() ) { 281 $endHours.children().eq($startHours.children().filter(':selected').index()).prop('selected', true); 282 $endMinutes.children().eq($startMinutes.children().filter(':selected').index()).prop('selected', true); 283 } 284 285 } 286 287 }; 288 289 var colorPicker = { 290 291 set: function () { 292 // init colorpicker 293 $theForm.find('.stec-layout-event-create-form-inner-colorpicker').each(function (i) { 294 295 var th = this; 296 297 var color = $(th).val(); 298 299 $(th).css({ 300 backgroundColor: color 301 }); 302 303 $(th).ColorPicker({ 304 klass: 'colorpicker-' + glob.options.id, 305 id: 'colorpicker-' + i + '-' + glob.options.id, 306 color: color, 307 onShow: function (colpkr) { 308 $(colpkr).show(); 309 return false;
310 }, 311 onHide: function (colpkr) { 312 $(colpkr).hide(); 313 return false; 314 }, 315 onChange: function (hsb, hex, rgb) { 316 $(th).attr("title", "#" + hex); 317 318 $(th).css({ 319 backgroundColor: "#" + hex 320 }); 321 322 $(th).val("#" + hex); 323 } 324 }); 325 326 }); 327 } 328 329 }; 330 331 var submitEvent = function () { 332 333 if ( blockForm === true ) { 334 335 return; 336 337 } 338 339 if ( valid === false ) { 340 341 return false; 342 343 } 344 345 if ( glob.options.create_event_form_allow_expired != 1 ) { 346 347 var startDate = $theForm.find('[name="start_date"]').val(); 348 var startTimeHours = parseInt($theForm.find('[name="start_time_hours"]').val(), 10); 349 var startTimeMinutes = parseInt($theForm.find('[name="start_time_minutes"]').val(), 10); 350 351 var now = window.moment(); 352 var eventDate = window.moment(startDate).hour(startTimeHours).minutes(startTimeMinutes); 353 354 if ( eventDate.isBefore(now) ) { 355 return false; 356 } 357 } 358 359 var eventOverview = { 360 title: $theForm.find('[name="title"]').val(), 361 calendar_id: $theForm.find('[name="calendar_id"]').val() 362 }; 363 364 if ( $.trim(eventOverview.title) == '' || isNaN(parseInt(eventOverview.calendar_id, 10)) === true ) { 365 return false; 366 } 367 368 var formData = new FormData($theForm.find('form')[0]); 369 370 formData.append('action', 'stec_public_ajax_action'); 371 formData.append('task', 'front_create_event'); 372 373 $.ajax({ 374 375 cache: false, 376 processData: false, 377 contentType: false, 378 dataType: "json", 379 type: 'POST', 380 url: window.ajaxurl, 381 data: formData, 382 beforeSend: function () { 383 384 blockForm = true; 385 386 $(glob.template.preloader).appendTo($theForm.find('.stec-layout-event-create-form-inner-submit-flexbox')); 387 388 $instance.trigger('stecCreateFormBeforeSend', [$instance]); 389 390 }, 391 392 success: function (data) { 393 394 $theForm.find('.stec-preloader').remove(); 395 396 if ( data.error == '1' || !data.event ) { 397 398 $theForm.find('.stec-layout-event-create-form-inner-submit-flexbox .fa-times').show(); 399 400 $instance.trigger('stecCreateFormSubmitError', [$instance, data]); 401 402 return false; 403 } 404 405 $theForm.find('.stec-layout-event-create-form-inner-submit-flexbox .fa-check').show(); 406 407 $instance.trigger('stecCreateFormSubmit', [$instance, data]); 408 409 }, 410 411 error: function (xhr, status, thrown) { 412 413 $theForm.find('.stec-preloader').remove(); 414 415 $theForm.find('.stec-layout-event-create-form-inner-submit-flexbox .fa-times').show(); 416 417 console.log(xhr + " " + status + " " + thrown); 418 419 $instance.trigger('stecCreateFormSubmitAjaxError', [$instance, xhr, status, thrown]); 420 }, 421 422 complete: function () { 423 424 setTimeout(function () { 425 426 $theForm.find('.stec-layout-event-create-form-inner-submit-flexbox i:visible').fadeTo(250, 0, function () { 427 $(this).css('opacity', '1').hide(); 428 }); 429 430 blockForm = false; 431 432 if ( glob.options.captcha.enabled == '1' ) { 433 valid = false; 434 window.grecaptcha.reset(captchaContainer); 435 } 436 437 }, 1000); 438 439 } 440 }); 441 }; 442 443 var deleteEvent = function (eventId) { 444 445 if ( blockForm === true ) { 446 return; 447 } 448 449 if ( isNaN(eventId) ) { 450 return; 451 } 452 453 var $event = $instance.$events.find('.stec-layout-event-awaiting-approval[data-id="' + eventId + '"]'); 454 455 $.ajax({ 456 dataType: "json", 457 type: 'POST', 458 url: window.ajaxurl, 459 data: { 460 action: 'stec_public_ajax_action', 461 task: 'front_delete_event', 462 id: eventId 463 }, 464 beforeSend: function () { 465 466 $event.find('.stec-layout-event-preview-left-approval-cancel').text(window.stecLang.deleting); 467 468 blockForm = true; 469 }, 470 471 success: function (data) { 472 473 if ( data.error == '0' ) { 474 475 $event.find('.stec-layout-event-preview-left-approval-cancel') 476 .addClass('stec-layout-event-preview-left-approval-cancel-success') 477 .text(window.stecLang.deleted); 478 $event.find('.stec-layout-event-preview-right .fa-check').show(); 479 480 } 481 482 if ( data.error == '1' ) { 483 484 $event.find('.stec-layout-event-preview-left-approval-cancel').text(window.stecLang.error); 485 $event.find('.stec-layout-event-preview-right .fa-times').show(); 486 487 } 488 489 }, 490 491 error: function (xhr, status, thrown) { 492 $event.find('.stec-layout-event-preview-left-approval-cancel').text(window.stecLang.error); 493 $event.find('.stec-layout-event-preview-right .fa-times').show();
494 console.log(xhr + " " + status + " " + thrown); 495 }, 496 497 complete: function () { 498 setTimeout(function () { 499 blockForm = false; 500 }, 1000); 501 } 502 }); 503 }; 504 505 var bindControls = function () { 506 507 if ( glob.options.selector ) { 508 509 $(document).on(helper.clickHandle(), '.stec-create-form-popup-blackscreen', function (e) { 510 $theForm.hide(); 511 $('.stec-create-form-popup-blackscreen').hide(); 512 }); 513 514 $(document).on(helper.clickHandle(), glob.options.selector, function (e) { 515 e.preventDefault(); 516 $theForm.css({ 517 top: $(window).scrollTop() 518 }).toggle(); 519 $('.stec-create-form-popup-blackscreen').toggle(); 520 }); 521 } 522 523 $(document).on("change", instance + (' .stec-event-create-form input[name="repeat_endson"]'), function (e) { 524 check_disabled_fields(); 525 }); 526 527 // calendar select 528 $(document).on('submit', instance + (' .stec-layout-event-create-form-inner form'), function (e) { 529 530 e.preventDefault(); 531 532 update_rrule(); 533 534 submitEvent(); 535 536 }); 537 538 // calendar select 539 $(document).on('change', instance + (' .stec-event-create-form [name="calendar_id"]'), function (e) { 540 541 var color = $(this).find('option:selected').data('color'); 542 543 $theForm.find('[name="event_color"]').css({ 544 background: color 545 }).val(color); 546 547 }); 548 549 // datetime change 550 $(document).on('change', 551 instance + (' .stec-event-create-form [name="start_date"]') + ',' + 552 instance + (' .stec-event-create-form [name="end_date"]') + ',' + 553 instance + (' .stec-event-create-form [name="start_time_hours"]') + ',' + 554 instance + (' .stec-event-create-form [name="end_time_hours"]') + ',' + 555 instance + (' .stec-event-create-form [name="start_time_minutes"]') + ',' + 556 instance + (' .stec-event-create-form [name="end_time_minutes"]') 557 , function (e) { 558 datePicker.generalTimeFix(); 559 }); 560 561 // all day 562 $(document).on('change', instance + ' .stec-event-create-form input[name="all_day"]', function () { 563 564 if ( $(this).is(':checked') ) { 565 566 $theForm.find('[name="start_time_hours"]').val($('[name="start_time_hours"]').children().first().val()); 567 $theForm.find('[name="start_time_minutes"]').val($('[name="start_time_minutes"]').children().first().val()); 568 569 $theForm.find('[name="end_time_hours"]').val($('[name="end_time_hours"]').children().last().val()); 570 $theForm.find('[name="end_time_minutes"]').val($('[name="end_time_minutes"]').children().last().val()); 571 572 $theForm.find('.stec-layout-event-create-form-time').hide(); 573 $theForm.find('.stec-layout-event-create-form-time').prev('p').hide(); 574 575 } else { 576 577 $theForm.find('.stec-layout-event-create-form-time').css('display', 'flex'); 578 $theForm.find('.stec-layout-event-create-form-time').prev('p').show(); 579 580 $theForm.find('[name="start_time_hours"]').val($('[name="start_time_hours"]').children().first().val()); 581 $theForm.find('[name="start_time_minutes"]').val($('[name="start_time_minutes"]').children().first().val()); 582 583 $theForm.find('[name="end_time_hours"]').val($('[name="end_time_hours"]').children().first().val()); 584 $theForm.find('[name="end_time_minutes"]').val($('[name="end_time_minutes"]').children().first().val()); 585 586 } 587 588 }); 589 590 591 // repeat toggle 592 $(document).on('change', instance + ' .stec-event-create-form select[name="event_repeat"]', function () { 593 594 if ( parseInt($(this).val(), 10) !== 0 ) { 595 596 $theForm.find('.stec-layout-event-create-form-inner-repeat-sub').css('display', 'block'); 597 $theForm.find('.stec-layout-event-create-form-inner-repeat-gap-block').css('display', 'block'); 598 599 if ( $(this).val() == '2' ) { 600 601 $theForm.find('.stec-layout-event-create-form-inner-weekly-by-day').show(); 602 603 } else { 604 605 $theForm.find('.stec-layout-event-create-form-inner-weekly-by-day').hide(); 606 607 } 608 609 } else { 610 611 $theForm.find('.stec-layout-event-create-form-inner-repeat-sub').hide(); 612 $theForm.find('.stec-layout-event-create-form-inner-repeat-gap-block').hide(); 613 $theForm.find('.stec-layout-event-create-form-inner-weekly-by-day').hide(); 614 } 615 }); 616 617 // upload image 618 $(document).on(helper.clickHandle(), instance + (' .stec-layout-event-create-form-inner-date-image'), function (e) { 619 620 e.preventDefault(); 621 e.stopPropagation(); 622 623 $(this).next().trigger('click'); 624 }); 625 626 $(document).on('change', instance + (' .stec-layout-event-create-form-inner-date-image-file'), function (e) { 627 628 $theForm.find('.stec-layout-event-create-form-inner-date-image').val(this.files[0].name); 629 630 }); 631 632 $(document).on(helper.clickHandle(), instance + (' .stec-layout-event-preview-right-event-toggle'), function (e) { 633 634 $('.stec-create-form-popup-blackscreen').hide(); 635 $theForm.hide(); 636 637 }); 638 639 /* Not implemented in standalone form yet 640 $(document).on(helper.clickHandle(), $instance.$events.path + ('.stec-layout-event-awaiting-approval-cancel'), function (e) { 641 var eventId = parseInt($(this).parents('.stec-layout-event-awaiting-approval').first().attr('data-id'), 10); 642 createEventForm.deleteEvent(eventId); 643 }); 644 */ 645 646 }; 647 648 649 } 650 651 $(document).ready(function () { 652 653 // Set boostrap datetimepicker to no conflict mode 654 if ( typeof $.fn.datepicker.noConflict === 'function' ) { 655 $.fn.bootstrapDP = $.fn.datepicker.noConflict(); 656 } 657 658 if ( typeof window.stachethemes_ec_create_form_instance !== "undefined" ) { 659 $(window.stachethemes_ec_create_form_instance).each(function () { 660
661 var cef = new createEventForm(); 662 cef.init(this); 663 664 }); 665 } 666 }); 667 668})(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.