1var rcl_actions = []; 2var rcl_filters = []; 3var rcl_beats = []; 4var rcl_beats_delay = 0; 5var rcl_url_params = rcl_get_value_url_params(); 6 7jQuery(document).ready(function ($) { 8 9 rcl_init_update_requared_checkbox(); 10 11 $.fn.extend({ 12 insertAtCaret: function (myValue) { 13 return this.each(function (i) { 14 if (document.selection) { 15 // ÐÐ»Ñ Ð±ÑаÑзеÑов Ñипа Internet Explorer 16 this.focus(); 17 var sel = document.selection.createRange(); 18 sel.text = myValue; 19 this.focus(); 20 } else if (this.selectionStart || this.selectionStart == '0') { 21 // ÐÐ»Ñ Ð±ÑаÑзеÑов Ñипа Firefox и дÑÑÐ³Ð¸Ñ Webkit-ов 22 var startPos = this.selectionStart; 23 var endPos = this.selectionEnd; 24 var scrollTop = this.scrollTop; 25 this.value = this.value.substring(0, startPos) + myValue + this.value.substring(endPos, this.value.length); 26 this.focus(); 27 this.selectionStart = startPos + myValue.length; 28 this.selectionEnd = startPos + myValue.length; 29 this.scrollTop = scrollTop; 30 } else { 31 this.value += myValue; 32 this.focus(); 33 } 34 }) 35 }, 36 animateCss: function (animationNameStart, functionEnd) { 37 var animationEnd = 'webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend'; 38 this.addClass('animated ' + animationNameStart).one(animationEnd, function () { 39 jQuery(this).removeClass('animated ' + animationNameStart); 40 41 if (functionEnd) { 42 if (typeof functionEnd == 'function') { 43 functionEnd(this); 44 } else { 45 jQuery(this).animateCss(functionEnd); 46 } 47 } 48 }); 49 return this; 50 } 51 }); 52 53}); 54 55function rcl_do_action(action_name) { 56 57 var callbacks_action = rcl_actions[action_name]; 58 59 if (!callbacks_action) 60 return false; 61 62 var args = [].slice.call(arguments, 1); 63 64 callbacks_action.forEach(function (callback, i, callbacks_action) { 65 if (window[callback]) 66 window[callback].apply(this, args); 67 if (typeof callback === 'function') 68 callback.apply(this, args); 69 }); 70} 71 72function rcl_add_action(action_name, callback) { 73 if (!rcl_actions[action_name]) { 74 rcl_actions[action_name] = [callback]; 75 } else { 76 var i = rcl_actions[action_name].length; 77 rcl_actions[action_name][i] = callback; 78 } 79} 80 81function rcl_apply_filters(filter_name) { 82 83 var args = [].slice.call(arguments, 1); 84 85 var callbacks_filter = rcl_filters[filter_name]; 86 87 if (!callbacks_filter) 88 return args[0]; 89 90 callbacks_filter.forEach(function (callback, i, callbacks_filter) { 91 args[0] = window[callback].apply(this, args); 92 }); 93 94 return args[0]; 95} 96 97function rcl_add_filter(filter_name, callback) { 98 if (!rcl_filters[filter_name]) { 99 rcl_filters[filter_name] = [callback]; 100 } else { 101 var i = rcl_filters[filter_name].length; 102 rcl_filters[filter_name][i] = callback; 103 } 104} 105 106function rcl_get_value_url_params() { 107 var tmp_1 = new Array(); 108 var tmp_2 = new Array(); 109 var rcl_url_params = new Array(); 110 var get = location.search; 111 if (get !== '') { 112 tmp_1 = (get.substr(1)).split('&'); 113 for (var i = 0; i < tmp_1.length; i++) { 114 tmp_2 = tmp_1[i].split('='); 115 rcl_url_params[tmp_2[0]] = tmp_2[1]; 116 } 117 } 118 119 return rcl_url_params; 120} 121 122function rcl_is_valid_url(url) { 123 var objRE = /http(s?):\/\/[-\w\.]{3,}\.[A-Za-z]{2,3}/; 124 return objRE.test(url); 125} 126 127function setAttr_rcl(prmName, val) { 128 var res = ''; 129 var d = location.href.split("#")[0].split("?"); 130 var base = d[0]; 131 var query = d[1]; 132 if (query) { 133 var params = query.split("&"); 134 for (var i = 0; i < params.length; i++) { 135 var keyval = params[i].split("="); 136 if (keyval[0] !== prmName) { 137 res += params[i] + '&'; 138 } 139 } 140 } 141 res += prmName + '=' + val; 142 return base + '?' + res; 143} 144 145function rcl_update_history_url(url) { 146 147 if (url != window.location) { 148 if (history.pushState) { 149 window.history.pushState(null, null, url); 150 } 151 } 152 153} 154 155function rcl_init_cookie() { 156 157 jQuery.cookie = function (name, value, options) { 158 if (typeof value !== 'undefined') { 159 options = options || {}; 160 if (value === null) { 161 value = ''; 162 options.expires = -1; 163 } 164 var expires = ''; 165 if (options.expires && (typeof options.expires === 'number' || options.expires.toUTCString)) { 166 var date; 167 if (typeof options.expires === 'number') { 168 date = new Date(); 169 date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000)); 170 } else { 171 date = options.expires; 172 } 173 expires = '; expires=' + date.toUTCString(); 174 } 175 var path = options.path ? '; path=' + (options.path) : ''; 176 var domain = options.domain ? '; domain=' + (options.domain) : ''; 177 var secure = options.secure ? '; secure' : ''; 178 document.cookie = [name, '=', encodeURIComponent(value), 179 expires, path, 180 domain, secure].join(''); 181 } else { 182 var cookieValue = null; 183 if (document.cookie && document.cookie !== '') { 184 var cookies = document.cookie.split(';'); 185 for (var i = 0; i < cookies.length; i++) { 186 var cookie = cookies[i].trim(); 187 if (cookie.substring(0, name.length + 1) === (name + '=')) { 188 cookieValue = decodeURIComponent(cookie.substring(name.length + 1)); 189 break; 190 } 191 } 192 } 193 return cookieValue; 194 } 195 }; 196 197} 198 199function rcl_add_dynamic_field(e) { 200 var parent = jQuery(e).parents('.dynamic-value'); 201 var box = parent.parent('.dynamic-values'); 202 var html = parent.html(); 203 box.append('<span class="dynamic-value">' + html + '</span>'); 204 jQuery(e).attr('onclick', 'rcl_remove_dynamic_field(this);return false;').children('i').toggleClass("fa-plus fa-minus"); 205 box.children('span').last().children('input').val('').focus(); 206} 207 208function rcl_remove_dynamic_field(e) { 209 jQuery(e).parents('.dynamic-value').remove(); 210} 211 212function rcl_rand(min, max) { 213 if (max) { 214 return Math.floor(Math.random() * (max - min + 1)) + min; 215 } else { 216 return Math.floor(Math.random() * (min + 1)); 217 } 218} 219 220function rcl_notice(text, type, time_close) { 221 222 time_close = time_close || false; 223 224 var options = { 225 text: text, 226 type: type, 227 time_close: time_close 228 }; 229 230 options = rcl_apply_filters('rcl_notice_options', options); 231 232 var notice_id = rcl_rand(1, 1000); 233 234 var html = '<div id="notice-' + notice_id + '" class="notice-window type-' + options.type + '"><a href="#" class="close-notice"><i class="rcli fa-times"></i></a>' + options.text + '</div>'; 235 if (!jQuery('#rcl-notice').length) { 236 jQuery('body > div').last().after('<div id="rcl-notice">' + html + '</div>'); 237 } else { 238 if (jQuery('#rcl-notice > div').length) 239 jQuery('#rcl-notice > div:last-child').after(html); 240 else 241 jQuery('#rcl-notice').html(html); 242 } 243 244 if (typeof animateCss !== 'undefined') { 245 jQuery('#rcl-notice > div').last().animateCss('slideInLeft'); 246 } 247 248 if (time_close) { 249 setTimeout(function () { 250 rcl_close_notice('#rcl-notice #notice-' + notice_id) 251 }, options.time_close); 252 } 253} 254 255function rcl_close_notice(e) { 256 257 var timeCook = jQuery(e).data('notice_time'); 258 259 if (timeCook) { 260 261 var idCook = jQuery(e).data('notice_id'); 262 var block = jQuery(e).parents('.rcl-notice'); 263 264 if (typeof animateCss !== 'undefined') { 265 jQuery(block).animateCss('flipOutX', function () { 266 jQuery(block).remove(); 267 }); 268 } else { 269 jQuery(block).remove(); 270 } 271 272 jQuery.cookie(idCook, '1', { 273 expires: timeCook, 274 path: '/' 275 }); 276 277 } else { 278 279 if (typeof animateCss !== 'undefined') { 280 jQuery(e).animateCss('flipOutX', function (e) { 281 jQuery(e).hide(); 282 }); 283 } else { 284 jQuery(e).hide(); 285 } 286 287 } 288 289 return false; 290} 291 292function rcl_preloader_show(e, size) { 293 294 var font_size = (size) ? size : 80; 295 var margin = font_size / 2; 296 297 var options = { 298 size: font_size, 299 margin: margin, 300 icon: 'fa-circle-o-notch', 301 class: 'rcl_preloader' 302 }; 303 304 options = rcl_apply_filters('rcl_preloader_options', options); 305 306 var style = 'style="font-size:' + options.size + 'px;margin: -' + options.margin + 'px 0 0 -' + options.margin + 'px;"'; 307 308 var html = '<div class="' + options.class + '"><i class="rcli ' + options.icon + ' fa-spin" ' + style + '></i></div>'; 309 310 if (typeof (e) === 'string') 311 jQuery(e).after(html); 312 else 313 e.append(html); 314} 315 316function rcl_preloader_hide() { 317 jQuery('.rcl_preloader').remove(); 318} 319 320function rcl_setup_datepicker_options() { 321 322 jQuery.datepicker.setDefaults(jQuery.extend(jQuery.datepicker.regional["ru"])); 323 324 var options = { 325 monthNames: ["ЯнваÑÑ", "ФевÑалÑ", "ÐаÑÑ", "ÐпÑелÑ", "Ðай", "ÐÑнÑ", 326 "ÐÑлÑ", 327 "ÐвгÑÑÑ", "СенÑÑбÑÑ", "ÐкÑÑбÑÑ", "ÐоÑбÑÑ", "ÐекабÑÑ"], 328 dayNamesMin: ["ÐÑ", "Ðн", "ÐÑ", "СÑ", "ЧÑ", "ÐÑ", "Сб"], 329 firstDay: 1, 330 dateFormat: 'yy-mm-dd', 331 yearRange: "1950:c+3", 332 changeYear: true 333 }; 334 335 options = rcl_apply_filters('rcl_datepicker_options', options); 336 337 return options; 338 339} 340 341function rcl_show_datepicker(e) { 342 jQuery(e).datepicker(rcl_setup_datepicker_options()); 343 jQuery(e).datepicker("show"); 344 rcl_add_action('rcl_upload_tab', 'rcl_remove_datepicker_box'); 345} 346 347function rcl_remove_datepicker_box() { 348 jQuery('#ui-datepicker-div').remove(); 349} 350 351function rcl_init_field_file(field_id) { 352 jQuery("#" + field_id).parents('form').attr("enctype", "multipart/form-data"); 353} 354 355function rcl_init_runner(props) { 356 357 var box = jQuery('#rcl-runner-' + props.id); 358 359 box.children('.rcl-runner-box').slider({ 360 value: parseInt(props.value), 361 min: parseInt(props.min), 362 max: parseInt(props.max), 363 step: parseInt(props.step), 364 create: function (event, ui) { 365 var value = box.children('.rcl-runner-box').slider('value'); 366 box.children('.rcl-runner-value').text(value); 367 box.children('.rcl-runner-field').val(value); 368 }, 369 slide: function (event, ui) { 370 box.find('.rcl-runner-value').text(ui.value); 371 box.find('.rcl-runner-field').val(ui.value); 372 } 373 });
374} 375 376function rcl_init_range(props) { 377 378 var box = jQuery('#rcl-range-' + props.id); 379 380 box.children('.rcl-range-box').slider({ 381 range: true, 382 values: [parseInt(props.values[0]), parseInt(props.values[1])], 383 min: parseInt(props.min), 384 max: parseInt(props.max), 385 step: parseInt(props.step), 386 create: function (event, ui) { 387 var values = box.children('.rcl-range-box').slider('values'); 388 box.children('.rcl-range-value').text(values[0] + ' - ' + values[1]); 389 box.children('.rcl-range-min').val(values[0]); 390 box.children('.rcl-range-max').val(values[1]); 391 }, 392 slide: function (event, ui) { 393 box.children('.rcl-range-value').text(ui.values[0] + ' - ' + ui.values[1]); 394 box.find('.rcl-range-min').val(ui.values[0]); 395 box.find('.rcl-range-max').val(ui.values[1]); 396 } 397 }); 398} 399 400function rcl_init_color(id, props) { 401 jQuery("#" + id).wpColorPicker(props); 402} 403 404function rcl_init_field_maxlength(fieldID) { 405 406 var field = jQuery('#' + fieldID); 407 var maxlength = field.attr('maxlength'); 408 409 if (!field.parent().find('.maxlength').length) { 410 411 if (field.val()) { 412 maxlength = maxlength - field.val().length; 413 } 414 415 field.after('<span class="maxlength">' + maxlength + '</span>'); 416 } 417 418 field.on('keyup', function () { 419 var maxlength = jQuery(this).attr('maxlength'); 420 if (!maxlength) 421 return false; 422 var word = jQuery(this); 423 var count = maxlength - word.val().length; 424 jQuery(this).next().text(count); 425 if (word.val().length > maxlength) 426 word.val(word.val().substr(0, maxlength)); 427 }); 428} 429 430function rcl_init_ajax_editor(id, options) { 431 432 if (typeof QTags === 'undefined') 433 return false; 434 435 rcl_do_action('rcl_pre_init_ajax_editor', { 436 id: id, 437 options: options 438 }); 439 440 var qt_options = { 441 id: id, 442 buttons: (options.qt_buttons) ? options.qt_buttons : "strong,em,link,block,del,ins,img,ul,ol,li,code,more,close" 443 }; 444 445 QTags(qt_options); 446 447 QTags._buttonsInit(); 448 449 if (options.tinymce && typeof tinyMCEPreInit != 'undefined') { 450 451 tinyMCEPreInit.qtInit[id] = qt_options; 452 453 tinyMCEPreInit.mceInit[id] = { 454 body_class: id, 455 selector: '#' + id, 456 menubar: false, 457 skin: "lightgray", 458 theme: 'modern', 459 toolbar1: "formatselect,bold,italic,bullist,numlist,blockquote,alignleft,aligncenter,alignright,link,unlink,wp_more,spellchecker,fullscreen,wp_adv", 460 toolbar2: "strikethrough,hr,forecolor,pastetext,removeformat,charmap,outdent,indent,undo,redo,wp_help", 461 wpautop: true 462 }; 463 464 tinymce.init(tinyMCEPreInit.mceInit[id]); 465 tinyMCE.execCommand('mceAddEditor', true, id); 466 467 switchEditors.go(id, 'html'); 468 } 469 470} 471 472function rcl_setup_quicktags(newTags) { 473 474 if (typeof QTags === 'undefined') 475 return false; 476
477 newTags.forEach(function (tagArray, i, newTags) { 478 479 QTags.addButton( 480 tagArray[0], 481 tagArray[1], 482 tagArray[2], 483 tagArray[3], 484 tagArray[4], 485 tagArray[5], 486 tagArray[6] 487 ); 488 489 }); 490 491} 492 493rcl_add_action('rcl_pre_init_ajax_editor', 'rcl_add_ajax_quicktags'); 494 495function rcl_add_ajax_quicktags(editor) { 496 497 if (typeof Rcl === 'undefined' || !Rcl.QTags) 498 return false; 499 500 rcl_setup_quicktags(Rcl.QTags); 501 502} 503 504rcl_add_action('rcl_footer', 'rcl_add_quicktags'); 505 506function rcl_add_quicktags() { 507 508 if (typeof Rcl === 'undefined' || !Rcl.QTags) 509 return false; 510 511 rcl_setup_quicktags(Rcl.QTags); 512 513} 514 515function rcl_proccess_ajax_return(result) { 516 517 var methods = { 518 redirect: function (url) { 519 520 var urlData = url.split('#'); 521 522 if (window.location.origin + window.location.pathname === urlData[0]) { 523 location.reload(); 524 } else { 525 location.replace(url); 526 } 527 528 }, 529 reload: function () { 530 location.reload(); 531 }, 532 current_url: function (url) { 533 rcl_update_history_url(url); 534 }, 535 dialog: function (dialog) { 536 537 if (dialog.content) { 538 539 if (jQuery('#ssi-modalContent').length) 540 ssi_modal.close(); 541 542 var ssiOptions = { 543 className: 'rcl-dialog-tab ' + (dialog.class ? ' ' + dialog.class : ''), 544 sizeClass: dialog.size ? dialog.size : 'auto', 545 content: dialog.content, 546 buttons: [] 547 }; 548 549 if (dialog.buttons) { 550 ssiOptions.buttons = dialog.buttons; 551 } 552 553 var buttonClose = true; 554 555 if ('buttonClose' in dialog) { 556 buttonClose = dialog.buttonClose; 557 } 558 559 if (buttonClose) { 560 561 ssiOptions.buttons.push({ 562 label: Rcl.local.close, 563 closeAfter: true 564 }); 565 566 } 567 568 if ('onClose' in dialog) { 569 ssiOptions.onClose = function (m) { 570 window[dialog.onClose[0]].apply(this, dialog.onClose[1]); 571 }; 572 } 573 574 if (dialog.title) 575 ssiOptions.title = dialog.title; 576 577 ssi_modal.show(ssiOptions); 578 579 } 580 581 if (dialog.close) { 582 ssi_modal.close(); 583 } 584 585 } 586 }; 587 588 for (var method in result) { 589 if (methods[method]) { 590 methods[method](result[method]); 591 } 592 } 593 594} 595 596function rcl_ajax(prop) { 597 598 if (prop.data.ask) { 599 if (!confirm(prop.data.ask)) { 600 rcl_preloader_hide(); 601 return false; 602 } 603 } 604 605 if (typeof Rcl != 'undefined') { 606 if (typeof prop.data === 'string') { 607 prop.data += '&ajax_nonce=' + Rcl.nonce; 608 } else if (typeof prop.data === 'object') { 609 prop.data.ajax_nonce = Rcl.nonce; 610 } 611 } 612 613 var action = false; 614 if (typeof prop.data === 'string') { 615 var propData = prop.data.split('&'); 616 var propObj = {}; 617 for (var key in propData) { 618 propObj[propData[key].split("=")[0]] = propData[key].split("=")[1]; 619 } 620 action = propObj.action; 621 } else if (typeof prop.data === 'object') { 622 action = prop.data.action; 623 } 624 625 if (typeof tinyMCE != 'undefined') 626 tinyMCE.triggerSave(); 627 628 jQuery.ajax({ 629 type: 'POST', 630 data: prop.data, 631 dataType: 'json', 632 url: (typeof ajaxurl !== 'undefined') ? ajaxurl : Rcl.ajaxurl, 633 success: function (result, post) { 634 635 var noticeTime = result.notice_time ? result.notice_time : 5000; 636 637 if (!result) { 638 rcl_notice(Rcl.local.error, 'error', noticeTime); 639 return false; 640 } 641 642 if (result.error || result.errors) { 643 644 rcl_preloader_hide(); 645 646 if (result.errors) { 647 jQuery.each(result.errors, function (index, error) { 648 rcl_notice(error, 'error', noticeTime); 649 }); 650 } else { 651 rcl_notice(result.error, 'error', noticeTime); 652 } 653 654 if (prop.error) 655 prop.error(result); 656 657 return false; 658 659 } 660 661 if (!result.preloader_live) { 662 rcl_preloader_hide(); 663 } 664 665 if (result.success) { 666 rcl_notice(result.success, 'success', noticeTime); 667 } 668 669 if (result.warning) { 670 rcl_notice(result.warning, 'warning', noticeTime); 671 } 672 673 rcl_do_action('rcl_ajax_success', result); 674 675 if (prop.success) { 676 677 prop.success(result); 678 679 } else { 680 681 rcl_proccess_ajax_return(result); 682 683 } 684 685 rcl_do_action(action, result); 686 687 } 688 });
689 690} 691 692 693function rcl_submit_form(e) { 694 695 var form = jQuery(e).parents('form'); 696 697 if (rcl_check_form(form)) 698 form.submit(); 699 700} 701 702function rcl_send_form_data(action, e) { 703 704 var form = jQuery(e).parents('form'); 705 706 if (!rcl_check_form(form)) 707 return false; 708 709 if (e && jQuery(e).parents('.preloader-parent')) { 710 rcl_preloader_show(jQuery(e).parents('.preloader-parent')); 711 } 712 713 if (typeof tinyMCE !== 'undefined') 714 tinyMCE.triggerSave(); 715 716 rcl_ajax({ 717 data: form.serialize() + '&action=' + action 718 }); 719 720} 721 722function rcl_check_form(form) { 723 724 var rclFormFactory = new RclForm(form); 725 726 return rclFormFactory.validate(); 727 728} 729 730function rcl_add_beat(beat_name, delay, data) { 731 732 delay = (delay < 10) ? 10 : delay; 733 734 var data = (data) ? data : false; 735 736 var i = rcl_beats.length; 737 738 rcl_beats[i] = { 739 beat_name: beat_name, 740 delay: delay, 741 data: data 742 }; 743 744} 745 746function rcl_remove_beat(beat_name) { 747 748 if (!rcl_beats) 749 return false; 750 751 var remove = false; 752 var all_beats = rcl_beats; 753
754 all_beats.forEach(function (beat, index, all_beats) { 755 if (beat.beat_name != beat_name) 756 return; 757 delete rcl_beats[index]; 758 remove = true; 759 }); 760 761 return remove; 762 763} 764 765function rcl_exist_beat(beat_name) { 766 767 if (!rcl_beats) 768 return false; 769 770 var exist = false; 771 772 rcl_beats.forEach(function (beat, index, rcl_beats) { 773 if (beat.beat_name != beat_name) 774 return; 775 exist = true; 776 }); 777 778 return exist; 779 780} 781 782function rcl_init_table(table_id) { 783 784 jQuery('#' + table_id).on('click', '.rcl-table__cell-must-sort', function () { 785 786 jQuery('#' + table_id).find('.rcl-table__cell-must-sort, .rcl-table__cell-sort').removeClass('rcl-table__cell-current-sort'); 787 788 var sortCell = jQuery(this); 789 790 var sortby = sortCell.data('sort'); 791 var route = sortCell.attr('data-route'); 792 793 sortCell.addClass('rcl-table__cell-current-sort'); 794 jQuery('#' + table_id).find('[data-' + sortby + '-value]').addClass('rcl-table__cell-current-sort'); 795 796 var list = jQuery('#' + table_id + ' .rcl-table__row-must-sort'); 797 798 list.sort(function (a, b) { 799 var aVal = jQuery(a).find('[data-' + sortby + '-value]').data(sortby + '-value'); 800 var bVal = jQuery(b).find('[data-' + sortby + '-value]').data(sortby + '-value'); 801 802 if (route == 'desc') { 803 return (aVal < bVal) - (aVal > bVal); //по возÑаÑÑÐ°Ð½Ð¸Ñ 804 } else { 805 return (aVal > bVal) - (aVal < bVal); //по ÑбÑÐ²Ð°Ð½Ð¸Ñ 806 } 807 }); 808 809 sortCell.attr('data-route', (route == 'desc' ? 'asc' : 'desc')); 810 811 jQuery('#' + table_id + ' .rcl-table__row-must-sort').remove(); 812 813 list.each(function (i, e) { 814 jQuery('#' + table_id + ' .rcl-table__row-header').after(jQuery(this)); 815 }); 816 817 }); 818 819} 820 821function rcl_table_search(e, key, submit) { 822 823 if (submit) { 824 825 if (typeof submit == 'string') { 826 827 return window[submit].call(this, e, key, submit); 828 829 } else if (key == 'Enter') { 830 jQuery(e).parents('form').submit(); 831 } 832 833 return; 834 835 } 836 837 var table_id = jQuery(e).parents('.rcl-table').attr('id'); 838 839 var inputs = jQuery(e).parents('.rcl-table').find('.rcl-table__row-search input'); 840 841 var search = []; 842 inputs.each(function (i, a) { 843 844 if (jQuery(a).val() !== '') { 845 search.push([jQuery(a).parent().data('rcl-ttitle'), 846 jQuery(a).val()]); 847 } 848 849 }); 850 851 jQuery('#' + table_id + ' .rcl-table__row-must-sort').show(); 852 853 if (!search.length) { 854 return; 855 } 856 857 var list = jQuery('#' + table_id + ' .rcl-table__row-must-sort'); 858 859 list.each(function (i, r) { 860 861 var success = true; 862 863 var cells = jQuery(r).find('.rcl-table__cell'); 864 865 cells.each(function (x, c) { 866 867 search.forEach(function (s) { 868 869 if (jQuery(c).data('rcl-ttitle') == s[0]) { 870 871 var value = jQuery(c).data('value'); 872 873 if (typeof value == 'number' && jQuery(c).data('value') != s[1] || 874 typeof value == 'string' && value.indexOf(s[1]) < 0) { 875 success = false; 876 return; 877 } 878 879 } 880 881 }); 882 883 if (!success) { 884 return; 885 } 886 887 }); 888 889 if (!success) { 890 jQuery(r).hide(); 891 } 892 893 }); 894} 895 896function RclForm(form) { 897 898 this.form = form; 899 this.errors = {}; 900 901 this.validate = function () { 902 903 var valid = true; 904 905 for (var objKey in this.checkForm) { 906 907 var chekObject = this.checkForm[objKey]; 908 909 if (!chekObject.isValid.call(this)) { 910 911 valid = false; 912 913 break; 914 915 } 916 917 } 918 ; 919 920 if (this.errors) { 921 for (var k in this.errors) { 922 this.showError(this.errors[k]); 923 } 924 ; 925 } 926 927 return valid; 928 929 }; 930 931 this.addChekForm = function (id, data) { 932 this.checkForm[id] = data; 933 }; 934 935 this.addChekFields = function (id, data) { 936 this.checkFields[id] = data; 937 }; 938 939 this.addError = function (id, error) { 940 this.errors[id] = error; 941 }; 942 943 this.shake = function (shakeBox) { 944 shakeBox.css('box-shadow', 'red 0px 0px 5px 1px inset').animateCss('shake'); 945 }; 946 947 this.noShake = function (shakeBox) { 948 shakeBox.css('box-shadow', 'none'); 949 }; 950 951 this.showError = function (error) { 952 rcl_notice(error, 'error', 10000); 953 }; 954 955 this.checkForm = { 956 checkFields: { 957 isValid: function () { 958
959 var valid = true; 960 var parent = this; 961 962 this.form.find('input,select,textarea').each(function () { 963 964 var field = jQuery(this); 965 var typeField = field.attr('type'); 966 967 if (field.is('textarea')) { 968 typeField = 'textarea'; 969 } 970 971 var checkFields = rcl_apply_filters('rcl_form_check_rules', parent.checkFields, parent); 972 973 for (var objKey in checkFields) { 974 975 var chekObject = checkFields[objKey]; 976 977 if (chekObject.types.length && jQuery.inArray(typeField, chekObject.types) < 0) { 978 continue; 979 } 980 981 var shakeBox = jQuery.inArray(typeField, ['radio', 982 'checkbox']) < 0 ? field : field.next('label'); 983 984 if (!chekObject.isValid(field)) { 985 986 parent.shake(shakeBox); 987 parent.addError(objKey, chekObject.errorText()); 988 valid = false; 989 return; 990 991 } else { 992 parent.noShake(shakeBox); 993 } 994 995 } 996 ; 997 998 }); 999 1000 return valid; 1001 1002 } 1003 1004 } 1005 1006 }; 1007 1008 this.checkFields = { 1009 required: { 1010 types: [], 1011 isValid: function (field) { 1012 1013 var required = true; 1014 1015 if (!field.prop("required")) 1016 return required; 1017 1018 if (field.prop("disabled")) 1019 return required; 1020 1021 var value = false; 1022 1023 if (field.attr('type') == 'checkbox') { 1024 if (jQuery('input[name="' + field.attr('name') + '"]:checked').val()) 1025 value = true; 1026 } else if (field.attr('type') == 'radio') { 1027 if (jQuery('input[name="' + field.attr('name') + '"]:checked').val()) 1028 value = true; 1029 } else { 1030 if (field.val()) 1031 value = true; 1032 } 1033 1034 if (!value) { 1035 required = false; 1036 } 1037 1038 return required; 1039 1040 }, 1041 errorText: function () { 1042 return Rcl.errors.required; 1043 } 1044 1045 1046 }, 1047 numberRange: { 1048 types: ['number'], 1049 isValid: function (field) { 1050 var range = true; 1051 1052 var val = field.val(); 1053 1054 if (val === '') 1055 return true; 1056 1057 val = parseInt(val); 1058 var min = parseInt(field.attr('min')); 1059 var max = parseInt(field.attr('max')); 1060 1061 if (min != 'undefined' && min > val || max != 'undefined' && max < val) { 1062 range = false; 1063 } 1064 1065 return range; 1066 }, 1067 errorText: function () { 1068 return Rcl.errors.number_range; 1069 } 1070 1071 }, 1072 pattern: { 1073 types: ['text', 'tel'], 1074 isValid: function (field) { 1075 1076 var val = field.val(); 1077 1078 if (!val) 1079 return true; 1080 1081 var pattern = field.attr('pattern'); 1082 1083 if (!pattern) 1084 return true; 1085 1086 var re = new RegExp(pattern); 1087 1088 return re.test(val); 1089 }, 1090 errorText: function () { 1091 return Rcl.errors.pattern; 1092 } 1093 1094 }, 1095 fileMaxSize: { 1096 types: ['file'], 1097 isValid: function (field) { 1098 1099 var valid = true; 1100 1101 field.each(function () { 1102 1103 var maxsize = jQuery(this).data("size"); 1104 var fileInput = jQuery(this)[0]; 1105 var file = fileInput.files[0]; 1106 1107 if (!file) 1108 return; 1109 1110 var filesize = file.size / 1024 / 1024; 1111 1112 if (filesize > maxsize) { 1113 valid = false; 1114 return; 1115 } 1116 1117 }); 1118 1119 return valid; 1120 }, 1121 errorText: function () { 1122 return Rcl.errors.file_max_size; 1123 } 1124 1125 }, 1126 fileAccept: { 1127 types: ['file'], 1128 isValid: function (field) { 1129
1130 var valid = true; 1131 1132 field.each(function () { 1133 1134 var fileInput = jQuery(this)[0]; 1135 var file = fileInput.files[0]; 1136 var accept = fileInput.accept.split(','); 1137 1138 if (!file) 1139 return; 1140 1141 if (accept) { 1142 1143 var fileType = false; 1144 1145 if (file.type) { 1146 1147 for (var i in accept) { 1148 if (accept[i] == file.type) { 1149 fileType = true; 1150 return; 1151 } 1152 } 1153 1154 } 1155 1156 var exts = jQuery(this).data("ext"); 1157 1158 if (!exts) 1159 return; 1160 1161 if (!fileType) { 1162 1163 var exts = exts.split(','); 1164 var filename = file.name; 1165 1166 for (var i in exts) { 1167 if (filename.indexOf('.' + exts[i]) + 1) { 1168 fileType = true; 1169 return; 1170 } 1171 } 1172 1173 } 1174 1175 if (!fileType) { 1176 valid = false; 1177 return; 1178 } 1179 1180 } 1181 1182 }); 1183 1184 return valid; 1185 }, 1186 errorText: function () { 1187 return Rcl.errors.file_accept; 1188 } 1189 1190 } 1191 }; 1192 1193 this.send = function (action, success) { 1194 1195 if (!this.validate()) 1196 return false; 1197 1198 rcl_preloader_show(form); 1199 1200 var sendData = { 1201 data: form.serialize() + '&action=' + action 1202 }; 1203 1204 if (success) { 1205 sendData.success = success; 1206 } 1207 1208 rcl_ajax(sendData); 1209 1210 }; 1211 1212} 1213 1214function rcl_chek_form_field(e) { 1215 1216 var field = jQuery(e); 1217 1218 var rclFormFactory = new RclForm(field.parents('form')); 1219 1220 var result = rclFormFactory.validate({ 1221 check_fields: [field.data('slug')] 1222 }); 1223 1224 return result; 1225 1226} 1227 1228function rcl_init_iconpicker() { 1229 jQuery('.rcl-iconpicker').iconpicker(); 1230} 1231 1232/** new uploader scripts **/ 1233 1234var RclUploaders = []; 1235 1236(function ($) { 1237 1238 $(document).ready(function () { 1239 1240 jQuery('body').on('drop', function (e) { 1241 return false; 1242 }); 1243 jQuery(document.body).on("drop", function (e) { 1244 e.preventDefault(); 1245 }); 1246 1247 RclUploaders.init(); 1248 1249 }); 1250 1251})(jQuery); 1252 1253RclUploaders = new RclClassUploaders(); 1254 1255function RclClassUploaders() { 1256 1257 this.uploaders = []; 1258 1259 this.init = function () { 1260 1261 this.uploaders.forEach(function (uploader, i) { 1262 uploader.init(); 1263 }); 1264 1265 }; 1266 1267 this.add = function (props, sk) { 1268 1269 this.uploaders.push(new RclUploader(props, sk)); 1270 1271 }; 1272 1273 this.get = function (uploader_id) { 1274 1275 var k = false; 1276 1277 this.uploaders.forEach(function (uploader, i) { 1278 1279 if (uploader.uploader_id == uploader_id) 1280 k = i; 1281 }); 1282 1283 if (k !== false) 1284 return this.uploaders[k]; 1285 1286 } 1287 1288 this.isset = function (uploader_id) { 1289 1290 var k = false; 1291 1292 this.uploaders.forEach(function (uploader, i) { 1293 1294 if (uploader.uploader_id == uploader_id) 1295 k = i; 1296 }); 1297 1298 if (k !== false) 1299 return true; 1300 1301 return false; 1302 1303 } 1304 1305} 1306 1307function RclUploader(props, sk) { 1308 1309 this.uploader_id = props.uploader_id; 1310 this.input = jQuery("#rcl-uploader-input-" + this.uploader_id); 1311 this.button = this.input.parent(".rcl-uploader-button"); 1312 this.options = props; 1313 1314 this.getFormData = function (uploader) { 1315 if (!uploader) 1316 uploader = this; 1317 1318 var formData = { 1319 options: JSON.stringify(uploader.options), 1320 is_wp_admin_page: typeof adminpage ? 1 : 0, 1321 sk: sk 1322 }; 1323 1324 formData.action = uploader.options.action; 1325 formData.ajax_nonce = Rcl.nonce; 1326 1327 return formData; 1328 1329 }; 1330 1331 this.init = function () { 1332 1333 if (this.options.dropzone) 1334 rcl_init_dropzone(jQuery("#rcl-dropzone-" + this.uploader_id)); 1335 1336 var uploader_id = this.options.uploader_id; 1337 var uploader = this; 1338 1339 options = { 1340 dataType: 'json', 1341 type: 'POST', 1342 url: Rcl.ajaxurl, 1343 dropZone: this.options.dropzone ? jQuery("#rcl-dropzone-" + this.uploader_id) : false, 1344 formData: this.getFormData(uploader), 1345 loadImageMaxFileSize: this.options.max_size * 1024, 1346 autoUpload: this.options.auto_upload, 1347 singleFileUploads: false, 1348 /*limitMultiFileUploads: this.options.max_files,*/ 1349 maxNumberOfFiles: this.options.max_files, 1350 imageMinWidth: this.options.min_width, 1351 imageMinHeight: this.options.min_height, 1352 imageMaxWidth: 1920, 1353 imageMaxHeight: 1080, 1354 imageCrop: false, 1355 imageForceResize: false, 1356 previewCrop: false, 1357 previewThumbnail: true, 1358 previewCanvas: true, 1359 previewMaxWidth: 900, 1360 previewMaxHeight: 900, 1361 disableExifThumbnail: true, 1362 progressall: function (e, data) { 1363 RclUploaders.get(uploader_id).progressall(e, data); 1364 }, 1365 processstart: function (e, data) { 1366 RclUploaders.get(uploader_id).processstart(e, data); 1367 }, 1368 processdone: function (e, data) { 1369 RclUploaders.get(uploader_id).processdone(e, data); 1370 }, 1371 processfail: function (e, data) { 1372 RclUploaders.get(uploader_id).processfail(e, data); 1373 }, 1374 add: function (e, data) { 1375 RclUploaders.get(uploader_id).add(e, data); 1376 }, 1377 submit: function (e, data) { 1378 RclUploaders.get(uploader_id).submit(e, data); 1379 }, 1380 done: function (e, data) { 1381 RclUploaders.get(uploader_id).done(e, data); 1382 } 1383 }; 1384 1385 this.input.fileupload(options); 1386 1387 /*this.initSortable();*/ 1388 1389 rcl_do_action('rcl_uploader_init', uploader_id); 1390 1391 }; 1392 1393 this.initSortable = function () { 1394 jQuery("#rcl-upload-gallery-" + this.uploader_id).sortable({ 1395 //connectWith: "#rcl-upload-gallery-" + this.uploader_id, 1396 containment: "parent", 1397 //handle: ".field-control .control-move", 1398 cursor: "move", 1399 placeholder: "ui-sortable-placeholder", 1400 distance: 5 1401 }); 1402 } 1403 1404 this.processstart = function (e, data) { 1405 console.log('processstart'); 1406 }; 1407 1408 this.processdone = function (e, data) { 1409 console.log('processdone'); 1410 }; 1411 1412 this.processfail = function (e, data) { 1413 console.log('processfail'); 1414 }; 1415 1416 this.progressall = function (e, data) { 1417 var progress = parseInt(data.loaded / data.total * 100, 10); 1418 jQuery('#rcl-uploader-' + this.uploader_id + ' .rcl-uploader-progress').html('<div class="progress-bar" style="width:' + progress + '%;">' + progress + '%</div>'); 1419 }; 1420 1421 this.add = function (e, data) { 1422 1423 var uploader = this; 1424 var options = uploader.options; 1425 1426 var errors = []; 1427 1428 var inGalleryNow = jQuery('#rcl-upload-gallery-' + uploader.uploader_id + ' .gallery-attachment').length; 1429 1430 jQuery.each(data.files, function (index, file) { 1431 1432 inGalleryNow++; 1433 1434 if (file.size > options.max_size * 1024) { 1435 errors.push(Rcl.errors.file_max_size + '. Max: ' + options.max_size + 'Kb'); 1436 } 1437 1438 }); 1439 1440 if (options.multiple && inGalleryNow > options.max_files) { 1441 errors.push(Rcl.errors.file_max_num + '. Max: ' + options.max_files); 1442 } 1443 1444 errors = this.filterErrors(errors, data.files, uploader); 1445 1446 if (errors.length) {
1447 errors.forEach(function (error, i) { 1448 rcl_notice(error, 'error', 10000); 1449 }); 1450 return false; 1451 } 1452 1453 if (parseInt(options.crop) != 0 && parseInt(options.multiple) == 0 && typeof jQuery.Jcrop != 'undefined') { 1454 if (jQuery.inArray(data.files[0].type, [ 1455 'image/png', 1456 'image/jpg', 1457 'image/jpeg', 1458 'image/gif' 1459 ]) >= 0) { 1460 return this.crop(e, data); 1461 } 1462 } 1463 1464 data.process().done(function () { 1465 data.submit(); 1466 }); 1467 1468 }; 1469 1470 this.filterErrors = function (errors, files, uploader) { 1471 return errors; 1472 }; 1473 1474 this.submit = function (e, data) { 1475 1476 this.animateLoading(true); 1477 1478 if (this.options.crop) { 1479 return this.submitCrop(e, data); 1480 } 1481 1482 }; 1483 1484 this.done = function (e, data) { 1485 1486 rcl_preloader_hide(); 1487 1488 this.animateLoading(false); 1489 1490 jQuery('#rcl-uploader-' + this.uploader_id + ' .rcl-uploader-progress').empty(); 1491 1492 if (data.result.error) { 1493 rcl_notice(data.result.error, 'error', 10000); 1494 return false; 1495 } 1496 1497 if (data.result.success) { 1498 rcl_notice(data.result.success, 'success', 10000); 1499 } 1500 1501 var uploader = this; 1502 1503 if (this.options.multiple) { 1504 jQuery.each(data.result, function (index, file) { 1505 1506 uploader.appendInGallery(file, uploader); 1507 1508 }); 1509 } else { 1510 1511 jQuery('#rcl-upload-gallery-' + this.uploader_id).html(''); 1512 1513 uploader.appendInGallery(data.result, uploader); 1514 } 1515 1516 this.afterDone(e, data); 1517 1518 jQuery('#rcl-preview').remove(); 1519 1520 }; 1521 1522 this.appendInGallery = function (file) { 1523 1524 if (file.html) { 1525 jQuery('#rcl-upload-gallery-' + this.uploader_id).append(file.html); 1526 jQuery('#rcl-gallery-' + this.uploader_id).append(file.html); 1527 jQuery('#rcl-upload-gallery-' + this.uploader_id + ' .gallery-attachment').last().animateCss('flipInX'); 1528 } 1529 }; 1530 1531 this.afterDone = function (e, data) { 1532 1533 }; 1534 1535 this.crop = function (e, data) { 1536 1537 var uploader = this; 1538 var crop = uploader.options.crop; 1539 var minWidthCrop = uploader.options.min_width; 1540 var minHeightCrop = uploader.options.min_height; 1541 1542 jQuery.each(data.files, function (index, file) { 1543 1544 jQuery('#rcl-preview').remove(); 1545 1546 var maxSize = parseInt(uploader.options.max_size); 1547 1548 if (file.size > maxSize * 1024) { 1549 rcl_notice(Rcl.errors.file_max_size + '. Max:' + ' ' + maxSize + 'Kb', 'error', 10000); 1550 return false; 1551 } 1552 1553 var reader = new FileReader(); 1554 reader.onload = function (event) { 1555 var jcrop_api; 1556 var imgUrl = event.target.result; 1557 1558 var maxWidth = window.innerWidth * 0.9; 1559 var maxHeight = window.innerHeight * 0.8; 1560 1561 jQuery('body > div').last().after('<div id=rcl-preview><img style="max-width:' + maxWidth + 'px;max-height:' + maxHeight + 'px;" src="' + imgUrl + '"></div>'); 1562 1563 var image = jQuery('#rcl-preview img'); 1564 1565 image.on('load', function () { 1566 1567 var img = jQuery(this); 1568 var cf = 1; 1569 1570 if (img[0].naturalWidth > img.width()) { 1571 cf = img.width() / img[0].naturalWidth; 1572 } 1573 1574 minWidthCrop *= cf; 1575 minHeightCrop *= cf; 1576 1577 var height = img.height(); 1578 var width = img.width(); 1579 1580 if (height < minHeightCrop || width < minWidthCrop) { 1581 rcl_notice(Rcl.errors.file_min_size + '. Min:' + ' ' + minWidthCrop + '*' + minHeightCrop + ' px', 'error', 10000); 1582 return false; 1583 } 1584 1585 var jcrop_api; 1586 1587 img.Jcrop({ 1588 aspectRatio: (typeof crop.ratio != 'undefined') ? crop.ratio : 1, 1589 minSize: [minWidthCrop, minHeightCrop], 1590 onSelect: function (c) { 1591 img.attr('data-width', width).attr('data-height', height).attr('data-x', c.x).attr('data-y', c.y).attr('data-w', c.w).attr('data-h', c.h); 1592 } 1593 }, 1594 function () { 1595 jcrop_api = this; 1596 }); 1597 1598 ssi_modal.show({ 1599 sizeClass: 'auto', 1600 title: Rcl.local.title_image_upload, 1601 className: 'rcl-hand-uploader', 1602 buttons: [{ 1603 className: 'btn-success', 1604 label: Rcl.local.upload, 1605 closeAfter: true, 1606 method: function () { 1607 data.submit(); 1608 } 1609 }, { 1610 className: 'btn-cancel', 1611 label: Rcl.local.cancel, 1612 closeAfter: true, 1613 method: function () { 1614 jcrop_api.destroy(); 1615 } 1616 }], 1617 content: jQuery('#rcl-preview'), 1618 extendOriginalContent: true 1619 }); 1620 1621 }); 1622 1623 }; 1624
1625 reader.readAsDataURL(file); 1626 1627 }); 1628 1629 }; 1630 1631 this.submitCrop = function (e, data) { 1632 1633 data.formData = this.getFormData(); 1634 1635 var image = jQuery('#rcl-preview img'); 1636 1637 if (parseInt(image.data('w'))) { 1638 1639 var width = image.data('width'); 1640 var height = image.data('height'); 1641 var x = image.data('x'); 1642 var y = image.data('y'); 1643 var w = image.data('w'); 1644 var h = image.data('h'); 1645 1646 data.formData.crop_data = [x, y, w, h]; 1647 data.formData.image_size = [width, height]; 1648 1649 } 1650 1651 } 1652 1653 this.animateLoading = function (status) { 1654 if (status) 1655 this.button.addClass('rcl-bttn__loading'); 1656 else 1657 this.button.removeClass('rcl-bttn__loading'); 1658 } 1659 1660} 1661 1662function rcl_init_uploader(props, securityKey) { 1663 RclUploaders.add(props, securityKey); 1664} 1665 1666function rcl_init_dropzone(dropZone) { 1667 1668 jQuery(document.body).bind("drop", function (e) { 1669 var node = e.target, found = false; 1670 1671 if (dropZone[0]) { 1672 dropZone.removeClass('in-dropzone hover-dropzone'); 1673 do { 1674 if (node === dropZone[0]) { 1675 found = true; 1676 break; 1677 } 1678 node = node.parentNode; 1679 } while (node != null); 1680 1681 if (found) { 1682 e.preventDefault(); 1683 } else { 1684 return false; 1685 } 1686 } 1687 }); 1688 1689 dropZone.bind('dragover', function (e) { 1690 var timeout = window.dropZoneTimeout; 1691 1692 if (!timeout) { 1693 dropZone.addClass('in-dropzone'); 1694 } else { 1695 clearTimeout(timeout); 1696 } 1697 1698 var found = false, node = e.target; 1699 1700 do { 1701 if (node === dropZone[0]) { 1702 found = true; 1703 break; 1704 } 1705 node = node.parentNode; 1706 } while (node != null); 1707 1708 if (found) { 1709 dropZone.addClass('hover-dropzone'); 1710 } else { 1711 dropZone.removeClass('hover-dropzone'); 1712 } 1713 1714 window.dropZoneTimeout = setTimeout(function () { 1715 window.dropZoneTimeout = null; 1716 dropZone.removeClass('in-dropzone hover-dropzone'); 1717 }, 100); 1718 }); 1719} 1720 1721function rcl_delete_attachment(attachment_id, post_id, e) { 1722 1723 if (e) 1724 rcl_preloader_show(jQuery(e).parents('.gallery-attachment')); 1725 1726 var objectData = { 1727 action: 'rcl_ajax_delete_attachment', 1728 post_id: post_id, 1729 attach_id: attachment_id 1730 }; 1731 1732 rcl_ajax({ 1733 rest: true, 1734 data: objectData, 1735 success: function (data) { 1736 1737 jQuery('.gallery-attachment-' + attachment_id).animateCss('flipOutX', function (e) { 1738 jQuery(e).remove(); 1739 }); 1740 1741 } 1742 }); 1743 1744 return false; 1745} 1746 1747function rcl_add_attachment_in_editor(attach_id, editor_name, e) { 1748 1749 var image = jQuery(e).data('html'); 1750 var src = jQuery(e).data('src'); 1751 1752 if (src) 1753 image = '<a href="' + src + '">' + image + '</a>'; 1754 1755 jQuery("textarea[name=" + editor_name + "]").insertAtCaret(image + " "); 1756 1757 if (typeof tinyMCE != 'undefined') { 1758 tinyMCE.editors.forEach(function (editor) { 1759 1760 if (editor.targetElm.name.length === editor_name.length) { 1761 editor.execCommand('mceInsertContent', false, image); 1762 } 1763 }); 1764 } 1765 1766 return false; 1767} 1768 1769/** new uploader scripts end **/ 1770 1771function rcl_update_require_checkbox(e) { 1772 var name = jQuery(e).attr('name'); 1773 var chekval = jQuery('form input[name="' + name + '"]:checked').val(); 1774 if (chekval) 1775 jQuery('form input[name="' + name + '"]').attr('required', false); 1776 else 1777 jQuery('form input[name="' + name + '"]').attr('required', true); 1778} 1779 1780function rcl_init_update_requared_checkbox() { 1781 1782 jQuery('body form').find('.required-checkbox').each(function () { 1783 rcl_update_require_checkbox(this); 1784 });
1785 1786 jQuery('body form').on('click', '.required-checkbox', function () { 1787 rcl_update_require_checkbox(this); 1788 }); 1789 1790}
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.