1var icms = icms || {}; 2 3$(function(){ 4 for(var module in icms){ 5 if ( typeof(icms[module].onDocumentReady) === 'function' ) { 6 icms[module].onDocumentReady(); 7 } 8 } 9}); 10 11icms.template = (function ($) { 12 13 let self = this; 14 15 this.onDocumentReady = function(){ 16 this.initWidgetTabbed(); 17 this.initScrollTop(); 18 this.initTooltip(); 19 this.initCookieAlert(); 20 this.initHeightTextSpoiler(); 21 this.initInputClickSelect(); 22 this.initActionConfirm(); 23 }; 24 25 this.initInputClickSelect = function(){ 26 $('.icms-click-select').on('click', function(){ 27 $(this).select(); 28 }); 29 }; 30 31 this.initActionConfirm = function(){ 32 $('a.icms-action-confirm, .icms-action-confirm > a').on('click', function(){ 33 let confirm_text = $(this).data('confirm'); 34 if (confirm_text) { 35 if(!confirm(confirm_text)){ return false; } 36 } 37 }); 38 }; 39 40 this.initTooltip = function(){ 41 $('[data-toggle="tooltip"]').tooltip({trigger : 'hover'}); 42 }; 43 44 this.initWidgetTabbed = function(){ 45 $('.icms-widget__tabbed').each(function(){ 46 $('.nav.nav-tabs .nav-link', $(this)).click(function(){ 47 var wid = $(this).data('id'); 48 $('.links-wrap', $(this).closest('.card-header')).hide(); 49 $('#widget-links-'+wid).show(); 50 }); 51 }); 52 }; 53 54 this.initHeightTextSpoiler = function(){ 55 $('.icms-text-spoiler').each(function(){ 56 let block = $(this); 57 let block_height = $('.icms-text-spoiler__wrap', block)[0].scrollHeight; 58 let line_height = parseInt(block.css('line-height').replace('px','')); 59 let visible_height = line_height*5.2; 60 if (visible_height < block_height) { 61 let link = $('<a class="btn-spoiler" href="#"><span class="btn-spoiler-expand">'+LANG_EXPAND+'</span><span class="btn-spoiler-collapse">'+LANG_COLLAPSE+'</span></a>'); 62 link.on('click', function(){ 63 return self.toggleSpoiler(this); 64 }); 65 block.append(link); 66 } 67 }); 68 }; 69 70 this.toggleSpoiler = function(link){ 71 let block = $(link).closest('.icms-text-spoiler'); 72 $(block).toggleClass('expanded'); 73 return false; 74 }; 75 76 this.initCookieAlert = function(){ 77 var block = $('#icms-cookiealert'); 78 if($(block).length === 0){ return; } 79 if(localStorage.getItem('cookiealert_hide')){ return; } 80 $(window).one('scroll', function() { 81 $(block).addClass('show'); 82 }); 83 $('.acceptcookies', block).on('click', function(t) { 84 localStorage.setItem('cookiealert_hide', 1); 85 $(block).removeClass('show'); 86 }); 87 }; 88 89 this.initScrollTop = function(){ 90 var link = $('#scroll-top'); 91 if($(link).length === 0){ return; } 92 if($(window).scrollTop() > 350){ 93 $(link).addClass('position-fixed'); 94 } 95 $(window).on('scroll', function() { 96 if($(this).scrollTop() > 350){ 97 $(link).addClass('position-fixed'); 98 } else { 99 $(link).removeClass('position-fixed'); 100 } 101 }); 102 $(link).on('click', function(t) { 103 window.scrollTo({ 104 top: 0, 105 behavior: 'smooth' 106 }); 107 t.preventDefault(); 108 }); 109 }; 110 111 this.copyToBuffer = function (text, copy_text) { 112 113 let textArea = document.createElement("textarea"); 114 textArea.value = text; 115 textArea.class = 'd-none'; 116 document.body.appendChild(textArea); 117 textArea.select(); 118 document.execCommand("Copy"); 119 textArea.remove(); 120 121 copy_text = copy_text || 'СкопиÑовано'; 122 123 if(typeof (toastr) === 'undefined'){ 124 alert(copy_text); 125 } else { 126 toastr.success(copy_text); 127 } 128 129 return false; 130 }; 131 132 return this; 133 134}).call(icms.template || {},jQuery); 135 136icms.menu = (function ($) { 137 138 this.onDocumentReady = function(){ 139 140 var device_type = $('body').data('device'); 141 142 this.horizontalMenuAutoScroll(device_type); 143 144 if(device_type === 'desktop'){ 145 $('.icms-menu-hovered a.dropdown-toggle').on( 'click', function (e) { 146 e.stopPropagation(); 147 }); 148 } else { 149 $('.icms-menu-hovered .disable-dropdown a.dropdown-toggle').on( 'click', function (e) { 150 e.stopPropagation(); 151 }); 152 $('.dropdown-menu a.dropdown-toggle').on( 'click', function (e) { 153 var $el = $(this); 154 $el.toggleClass('active-dropdown'); 155 if (!$( this ).next().hasClass('show')) { 156 $( this ).parents('.dropdown-menu').first().find('.show').removeClass('show'); 157 } 158 $(this).next('.dropdown-menu').toggleClass('show'); 159 160 $(this).closest('li').toggleClass('show'); 161 162 $(this).parents('li.nav-item.dropdown.show').on('hidden.bs.dropdown', function ( e ) { 163 $('.dropdown-menu .show').removeClass('show'); 164 $el.removeClass('active-dropdown'); 165 }); 166 return false;
167 }); 168 169 $('.nav-item.dropdown').each(function (){ 170 var link = $(this).find('>a'); 171 if(link.attr('href').charAt(0) === '/'){ 172 $(this).find('>ul').append('<li class="dropdown-divider"></li>').append('<li class="nav-item"><a class="dropdown-item" href="'+link.attr('href')+'" >'+LANG_ALL+'</a></li>'); 173 } 174 }); 175 176 $('.icms-user-menu').each(function (){ 177 $(this).on('show.bs.dropdown', function () { 178 $('body').addClass('overflow-hidden'); 179 }).on('hide.bs.dropdown', function () { 180 $('body').removeClass('overflow-hidden'); 181 }); 182 var avatar = $(this).find('.icms-user-menu__summary .icms-user-avatar').clone(); 183 $(avatar).on('click', function(){ return false; }); 184 var nickname = $('<span class="ml-3 text-white">'+$(this).find('.icms-user-menu__nickname').text()+'</span>'); 185 $(nickname).on('click', function(){ return false; }); 186 var header = $('<li class="bg-primary d-flex align-items-center m-0 h5 p-3"><button type="button" class="btn ml-auto text-white p-0"><svg viewBox="0 0 352 512" style="width: 1rem;"><path d="M242.72 256l100.07-100.07c12.28-12.28 12.28-32.19 0-44.48l-22.24-22.24c-12.28-12.28-32.19-12.28-44.48 0L176 189.28 75.93 89.21c-12.28-12.28-32.19-12.28-44.48 0L9.21 111.45c-12.28 12.28-12.28 32.19 0 44.48L109.28 256 9.21 356.07c-12.28 12.28-12.28 32.19 0 44.48l22.24 22.24c12.28 12.28 32.2 12.28 44.48 0L176 322.72l100.07 100.07c12.28 12.28 32.2 12.28 44.48 0l22.24-22.24c12.28-12.28 12.28-32.19 0-44.48L242.72 256z"></path></svg></button></li>'); 187 $(header).prepend(nickname); 188 $(header).prepend(avatar); 189 $(this).find('.icms-user-menu__items').prepend(header); 190 }); 191 192 } 193 }; 194 195 this.horizontalMenuAutoScroll = function(device_type){ 196 $('.mobile-menu-wrapper').each(function(){ 197 let active_link = $(this).find('.active'); 198 if(active_link.length > 0){ 199 $(active_link).get(0).scrollIntoView({block: "end", inline: "nearest"}); 200 } 201 if (device_type !== 'desktop') { 202 let more = $(this).find('.nav-item.dropdown.more'); 203 if (more.length > 0) { 204 let ns = $(more).find('> .dropdown-menu li'); 205 $('.dropdown-item', ns).toggleClass('dropdown-item nav-link'); 206 $(this).find('> ul').append(ns); 207 more.remove(); 208 } 209 } 210 }); 211 }; 212 213 this.initSwipe = function(selector, params){ 214 return $(selector).slick($.extend({ 215 infinite: false, 216 arrows: false, 217 mobileFirst: true, 218 variableWidth: false, 219 responsive: [ 220 {breakpoint: 1024, settings: "unslick"}, 221 {breakpoint: 650, settings: {slidesToShow: 3, slidesToScroll: 3}}, 222 {breakpoint: 320, settings: {slidesToShow: 2, slidesToScroll: 2}} 223 ] 224 }, (params ? params : {}))); 225 }; 226 227 return this; 228 229}).call(icms.menu || {},jQuery); 230 231icms.forms = (function ($) { 232 233 this.wysiwygs_insert_pool = {insert: {}, add: {}, init: {}, save: {}}; 234 this.submitted = false; 235 this.form_changed = false; 236 this.csrf_token = false; 237 this.is_init_unsave_notice = false; 238 239 var _this = this; 240 241 this.addWysiwygsInsertPool = function (field_name, callback){ 242 this.wysiwygs_insert_pool.insert[field_name] = callback; 243 }; 244 245 this.addWysiwygsAddPool = function (field_name, callback){ 246 this.wysiwygs_insert_pool.add[field_name] = callback; 247 }; 248 249 this.addWysiwygsInitPool = function (field_name, callback){ 250 this.wysiwygs_insert_pool.init[field_name] = callback; 251 }; 252 253 this.addWysiwygsSavePool = function (field_name, callback){ 254 this.wysiwygs_insert_pool.save[field_name] = callback; 255 }; 256 257 this.wysiwygBeforeSubmit = function (){ 258 for(var field_name in this.wysiwygs_insert_pool.save) { 259 if(this.wysiwygs_insert_pool.save.hasOwnProperty(field_name)){ 260 if (typeof(this.wysiwygs_insert_pool.save[field_name]) === 'function') { 261 this.wysiwygs_insert_pool.save[field_name](field_name); 262 } 263 } 264 } 265 return this; 266 }; 267 268 this.wysiwygInit = function (field_name, callback){ 269 if (typeof(this.wysiwygs_insert_pool.init[field_name]) === 'function') { 270 this.wysiwygs_insert_pool.init[field_name](field_name, callback); 271 } else if(typeof(callback) === 'function') { 272 callback(); 273 } 274 return this; 275 }; 276 277 this.wysiwygInsertText = function (field_name, text){ 278 if (typeof(this.wysiwygs_insert_pool.insert[field_name]) === 'function') { 279 this.wysiwygs_insert_pool.insert[field_name](field_name, text); 280 } else { 281 $('#'+field_name).val(text).focus(); 282 } 283 return this; 284 }; 285 286 this.wysiwygAddText = function (field_name, text){ 287 if (typeof(this.wysiwygs_insert_pool.add[field_name]) === 'function') { 288 this.wysiwygs_insert_pool.add[field_name](field_name, text); 289 } else { 290 addTextToPosition($('#'+field_name), text); 291 } 292 return this; 293 }; 294 295 this.getCsrfToken = function (){ 296 if(this.csrf_token === false){ 297 this.csrf_token = $('meta[name="csrf-token"]').attr('content'); 298 } 299 return this.csrf_token; 300 }; 301 302 this.setCsrfToken = function (csrf_token){ 303 this.csrf_token = csrf_token; 304 }; 305 306 this.getFilterFormParams = function(form){ 307 308 var form_params = _this.toJSON(form); 309 310 var o = {}; 311 for(var name in form_params){if(form_params.hasOwnProperty(name)){ 312 if(name === 'page'){ continue; } 313 if(form_params[name] && form_params[name] !== ''){ 314 o[name] = form_params[name]; 315 } 316 }} 317 318 return o; 319 320 }; 321 322 this.initFilterForm = function(selector){ 323 324 var form = $(selector); 325 326 var filter_panel = $(form).closest('.icms-filter-panel'); 327 328 var filter_link_open = $(filter_panel).find('.icms-filter-link__open'); 329 var filter_link_close = $(filter_panel).find('.icms-filter-link__close'); 330 331 $(filter_link_open).on('click', function (){ 332 $(this).addClass('d-none'); 333 $(filter_panel).find('.icms-filter-container').removeClass('d-none'); 334 return false;
335 }); 336 $(filter_link_close).on('click', function (){ 337 $(filter_panel).find('.icms-filter-container').addClass('d-none'); 338 $(filter_link_open).removeClass('d-none'); 339 return false; 340 }); 341 342 var change = function (){ 343 344 var sbutton = $(form).find('.buttons button[type = submit]'); 345 346 $(sbutton).prop('disabled', true).addClass('is-busy'); 347 348 var o = _this.getFilterFormParams(form); 349 var submit_uri; 350 351 if(Object.keys(o).length > 0 || $(form).find('.cancel_filter_link').length === 0){ 352 submit_uri = $(form).attr('action'); 353 } else { 354 submit_uri = $(form).find('.cancel_filter_link').attr('href'); 355 } 356 357 o.show_count = 1; 358 359 var query_string = $.param(o); 360 361 $.get(submit_uri+'?'+query_string, function(result){ 362 if(result.filter_link){ 363 $(form).data('filter_link', result.filter_link); 364 } else { 365 $(form).removeData('filter_link'); 366 } 367 setTimeout(function (){ 368 $(sbutton).removeClass('is-busy').val(result.hint).prop('disabled', false).find('span').text(result.hint); 369 }, 200); 370 icms.events.run('icms_content_filter_changed', form); 371 }, 'json'); 372 373 }; 374 375 var delay = function () { 376 var timer = 0; 377 return function () { 378 var context = this, args = arguments; 379 clearTimeout(timer); 380 timer = setTimeout(function () { 381 change.apply(context, args); 382 }, 500); 383 }; 384 }; 385 386 $(form).find('select, input[type=checkbox]').on('change', change); 387 $(form).find('input:not([type=checkbox]), textarea').on('input', delay()); 388 389 $(form).find('.buttons button[type = submit]').on('click', function (){ 390 391 var filter_link = $(form).data('filter_link'); 392 393 if(filter_link){ 394 window.location.href = filter_link; 395 return false; 396 } 397 398 var submit_uri = $(form).attr('action'); 399 400 var o = _this.getFilterFormParams(form); 401 402 var query_string = $.param(o); 403 404 if(query_string.length > 0){ 405 window.location.href = submit_uri+'?'+query_string; 406 } else { 407 408 var cancel_filter_link = $(form).find('.cancel_filter_link').attr('href'); 409 410 if(!cancel_filter_link){ 411 cancel_filter_link = submit_uri; 412 } 413 414 window.location.href = cancel_filter_link; 415 } 416 417 return false; 418 419 }); 420 421 }; 422 423 this.initFormHelpers = function(form_id){ 424 let form = $('#'+form_id); 425 form.on('focus', '.field.ft_string input, .field.ft_text textarea', function (){ 426 $('.pattern_fields_panel').hide(); 427 $('.pattern_fields_panel_hint').show(); 428 $(this).closest('.field').find('.pattern_fields_panel_hint').hide(); 429 $(this).closest('.field').find('.pattern_fields_panel').show(); 430 }); 431 form.on('click', '.pattern_fields > ', function (){ 432 let spacer = $(this).closest('.hint').data('spacer') || false; 433 let spacer_stop = $(this).closest('.hint').data('spacer_stop') || false; 434 let id = $(this).closest('.icms-forms-pattern__fields').data('for_id'); 435 if (typeof(_this.wysiwygs_insert_pool.add[id]) === 'function') { 436 _this.wysiwygs_insert_pool.add[id](id, $(this).text()); return false; 437 } 438 return addTextToPosition($('#'+id), $(this).text(), spacer, spacer_stop); 439 }); 440 $('.field input, .field textarea', form).on('invalid', function (e){ 441 $('.process-save > a, .buttons .btn').removeClass('disabled is-busy'); 442 let name = $(e.target).attr('name'); 443 let lang_tab = $("a[href='#f_"+name+"']", form); 444 if (lang_tab.length > 0) { 445 e.preventDefault(); 446 setTimeout(function(){ 447 lang_tab.trigger('click'); 448 $(e.target).focus(); 449 }, 1); 450 } 451 let tabs_menu = $(e.target).closest('.tabs-menu'); 452 if (tabs_menu.length === 0) { 453 return; 454 } 455 let tab = $(e.target).closest('.tab-pane'); 456 let tab_is_active = tab.hasClass('active'); 457 let tab_id = tab.attr('id'); 458 if (!tab_is_active) { 459 $("a[href='#"+tab_id+"']", tabs_menu).tab('show'); 460 } 461 }); 462 $('.process-save > a').on('click', function(){ 463 $(this).addClass('disabled is-busy'); 464 let submit_class = $(this).data('submit_class'); 465 _this.submit(submit_class); 466 return false;
467 }); 468 $('.auto_copy_value', form).on('click', function (){ 469 $(this).closest('.input-prefix-suffix').find('input').val($(this).data('value')); 470 return false; 471 }); 472 }; 473 474 this.initUnsaveNotice = function(){ 475 476 if (this.is_init_unsave_notice) { 477 return; 478 } 479 this.is_init_unsave_notice = true; 480 481 let init_data = {}; 482 483 $('form').each(function(i){ 484 init_data[i] = _this.toJSON($(this)); 485 $(this).attr('data-notice_id', i); 486 }); 487 488 $(document).on('change', '.form-tabs input, .form-tabs select, .form-tabs textarea', function (e) { 489 let form = $(this).closest('form'); 490 _this.form_changed = JSON.stringify(init_data[form.attr('data-notice_id')]) !== JSON.stringify(_this.toJSON(form)); 491 }); 492 $(document).on('submit', 'form', function () { 493 $(this).find('.button-submit').addClass('disabled is-busy'); 494 icms.forms.submitted = true; 495 }); 496 $(window).on('beforeunload', function (e) { 497 if (_this.form_changed && !_this.submitted) { 498 let ev = e || window.event; 499 let msg = LANG_SUBMIT_NOT_SAVE; 500 if (ev) { 501 ev.returnValue = msg; 502 } 503 return msg; 504 } 505 }); 506 }; 507 508 this.initCollapsedFieldset = function(form_id){ 509 $('#'+form_id).on('click', '.is_collapsed legend', function (){ 510 var _fieldset = $(this).closest('.is_collapsed'); 511 $(_fieldset).toggleClass('is_collapse do_expand'); 512 $.cookie('icms[fieldset_state]['+$(_fieldset).attr('id')+']', $(_fieldset).hasClass('do_expand')); 513 }); 514 $('.is_collapsed', $('#'+form_id)).each(function (){ 515 if($(this).find('.field_error').length > 0 || $.cookie('icms[fieldset_state]['+$(this).attr('id')+']') === 'true'){ 516 $(this).addClass('do_expand').removeClass('is_collapse'); return; 517 } 518 }); 519 }; 520 521 this.toJSON = function(form) { 522 _this.wysiwygBeforeSubmit(); 523 var o = {}; 524 var a = form.serializeArray(); 525 $.each(a, function() { 526 if (o[this.name] !== undefined) { 527 if (!o[this.name].push) { 528 o[this.name] = [o[this.name]]; 529 } 530 o[this.name].push(this.value || ''); 531 } else { 532 o[this.name] = this.value || ''; 533 } 534 }); 535 return o; 536 }; 537 538 this.submit = function(selector){ 539 selector = selector || '.button-submit'; 540 icms.forms.submitted = true; 541 $(selector).addClass('disabled is-busy').trigger('click'); 542 }; 543 544 this.initFieldsetChildList = function (form_id){ 545 $('#'+form_id+' .icms-form-tab__demand').each(function (){ 546 var demand_wrap = $(this).attr('href'); 547 var url = $(this).data('parent_url'); 548 $('#'+$(this).data('parent')).on('change', function (){ 549 var value = $(this).val(); 550 $.post(url, {value: value, form_id: form_id}, function(result){ 551 $(demand_wrap).html(result); 552 }, 'html'); 553 }); 554 }); 555 }; 556 557 this.updateChildList = function (child_id, url, value, current_value, filter_field_name) { 558 559 var child_list = $('#' + child_id); 560 561 $('#f_' + child_id + ' label').addClass('loading'); 562 563 child_list.html(''); 564 565 current_value = current_value || ''; 566 567 if (!$.isArray(current_value)) { 568 current_value = [current_value]; 569 } 570 571 current_value = current_value.map(String); 572 573 $.post(url, {value: value, filter_field_name: filter_field_name}, function (result) { 574 575 for (var k in result) { 576 if (result.hasOwnProperty(k)) { 577 if (typeof result[k].value !== 'undefined') { 578 var _value = result[k].value; 579 var title = result[k].title; 580 } else { 581 var _value = k; 582 var title = result[k]; 583 } 584 child_list.append('<option value="' + _value + '"' + ($.inArray(_value, current_value) !== -1 ? ' selected' : '') + '>
584' + title + '</option>'); 585 } 586 } 587 588 $(child_list).trigger('chosen:updated'); 589 590 $('#f_' + child_id + ' label').removeClass('loading'); 591 592 icms.events.run('icms_forms_updatechildlist', { 593 result: result, 594 child_id: child_id, 595 value: value, 596 current_value: current_value, 597 filter_field_name: filter_field_name 598 }); 599 600 }, 'json'); 601 602 }; 603 604 this.submitAjax = function(form, additional_params){ 605 606 icms.forms.submitted = true; 607 608 /** 609 * СовмеÑÑимоÑÑÑ, пеÑедаÑÑÑÑ Ð² колбÑк 610 * @type coreforms.toJSON.o 611 */ 612 let form_data = this.toJSON($(form)); 613 614 let submit_btn = $(form).find('.button-submit'); 615 616 $(submit_btn).prop('disabled', true).addClass('is-busy'); 617 618 let formData = new FormData(form); 619 620 if(additional_params){ 621 for(let name in additional_params){ 622 formData.set(name, additional_params[name]); 623 } 624 } 625 626 $.ajax({ 627 url: $(form).attr('action'), 628 method: 'POST', 629 data: formData, 630 success: function (result) { 631 632 $('.field_error', form).removeClass('field_error'); 633 $('.is-invalid', form).removeClass('is-invalid'); 634 $('.invalid-feedback', form).remove(); 635 636 $(submit_btn).prop('disabled', false).removeClass('is-busy'); 637 638 if (result.errors === false){ 639 if ("callback" in result){ 640 641 let params = result.callback.split('.'); 642 643 let calling_func = window; 644 for(let id in params){ 645 calling_func = calling_func[params[id]]; 646 } 647 648 calling_func.apply(form, [form_data, result]); 649 650 return; 651 } 652 $('input[type=text], select, textarea', form).val('').triggerHandler('input'); 653 if (result.success_text){ 654 icms.modal.alert(result.success_text); 655 } 656 if (result.redirect_uri){ 657 window.location.href = result.redirect_uri; 658 } 659 return; 660 } 661 662 if (typeof(result.errors) === 'object'){ 663 if(result.message){ 664 icms.modal.alert(result.message, 'danger'); 665 } 666 for(let field_id in result.errors){ 667 let id = field_id.replace(':', '_'); 668 $('#'+id, form).addClass('is-invalid'); 669 $('#f_'+id, form).addClass('field_error').append('<div class="invalid-feedback">' + result.errors[field_id] + '</div>'); 670 $(form).find('ul.tabbed > li > a[href = "#'+$('#f_'+id, form).parents('.tab').attr('id')+'"]').trigger('click'); 671 } 672 673 icms.events.run('icms_forms_submitajax', result); 674 675 icms.modal.resize(); 676 677 icms.forms.submitted = false; 678 679 return; 680 } 681 }, 682 error: function (error) { 683 $(submit_btn).prop('disabled', false).removeClass('is-busy'); 684 icms.modal.alert('<div>Status: '+error.status+'</div>'+error.responseText, 'danger'); 685 }, 686 dataType: 'json', 687 cache: false, 688 contentType: false, 689 processData: false 690 }); 691 692 return false; 693 }; 694 695 this.initSymbolCount = function (field_id, max, min){ 696 $('#'+field_id).wrap("<div class='icms-form__symbols_count_wrap position-relative'></div>"); 697 $('#f_'+field_id+' .icms-form__symbols_count_wrap').append('<div class="symbols_count"><span class="symbols_num"></span></div>'); 698 var symbols_count = $('#f_'+field_id+' .symbols_count'); 699 var symbols_num = $('.symbols_num', symbols_count); 700 if(max){ 701 var type = 'left'; 702 } else { 703 var type = 'total'; 704 } 705 706 var field_id_el = $('#'+field_id); 707 708 $(symbols_num).on('click', function (){ 709 if(max){ 710 if(type === 'total'){ 711 type = 'left'; 712 } else { 713 type = 'total'; 714 } 715 render_symbols_count(); 716 } 717 }); 718 var render_symbols_count = function (){ 719 var num = +$(field_id_el).val().length; 720 if(!num){ 721 $(symbols_num).html(''); $(symbols_count).hide(); return; 722 } 723 if(min){ if(num < min){ 724 $(symbols_num).addClass('overflowing_min'); 725 } else { 726 $(symbols_num).removeClass('overflowing_min'); 727 }} 728 if(max && num > max){ 729 $(symbols_num).addClass('overflowing'); 730 } else { 731 $(symbols_num).removeClass('overflowing'); 732 } 733 if(type === 'total'){ 734 $(symbols_count).fadeIn(); 735 $(symbols_num).html(num); 736 } else { 737 $(symbols_count).fadeIn(); 738 if(num > max){ 739 num = max; 740 $(field_id_el).val($(field_id_el).val().substr(0, max)); 741 } 742 $(symbols_num).html((max - num)); 743 } 744 }; 745 $(field_id_el).on('input', render_symbols_count); 746 icms.events.on('autocomplete_select', function(){ render_symbols_count(); }); 747 render_symbols_count(); 748 }; 749 750 this.getInputVal = function(el){ 751 if($(el).is(':checkbox,:radio')){ 752 var v = $(el+':checked').val(); 753 return typeof v === 'undefined' ? '0' : v; 754 } 755 return $(el).val(); 756 }; 757 this.inputNameToId = function(name){ 758 name = name.replace(/\:|\|/g,'_'); 759 return name; 760 }; 761 this.inputNameToElName = function(name){ 762 name = name.split(':'); 763 return (typeof name !== 'string' && name.length > 1) ? name.shift()+'['+name.join('][')+']' : name; 764 }; 765 this.VDisDisplay = function(field_value, type){ 766 var display; 767 if (Array.isArray(field_value) && field_value.length > 0) { 768 for (var show_key in type) { 769 if ($.inArray(type[show_key], field_value) !== -1) { 770 display = true; 771 } else { 772 display = false;
773 break; 774 } 775 } 776 } else { 777 if (Array.isArray(field_value)) { 778 field_value = ''; 779 } 780 if ($.inArray(field_value, type) !== -1) { 781 return true; 782 } else { 783 display = false; 784 } 785 } 786 return display; 787 }; 788 this.VDListeners = {}; 789 this.VDListenersInitialized = []; 790 this.VDRules = {from:{},depends:{}}; 791 this.addVisibleDepend = function(form_id, field_id, rules){ 792 /* здеÑÑ Ð²Ñе завиÑимоÑÑи Ð¿Ð¾Ð»Ñ field_id */ 793 if(typeof this.VDRules.depends[form_id+'-'+field_id] === 'undefined'){ 794 /* array('is_cats' => array('show' => array('1'))) */ 795 this.VDRules.depends[form_id+'-'+field_id] = rules; 796 } else { 797 $.extend(this.VDRules.depends[form_id+'-'+field_id], rules); 798 } 799 for(var f in rules){if(rules.hasOwnProperty(f)){ 800 if(typeof this.VDRules.from[form_id+'-'+f] === 'undefined'){this.VDRules.from[form_id+'-'+f] = {};} 801 /* здеÑÑ Ð²Ñе, кÑо завиÑÐ¸Ñ Ð¾Ñ Ð¿Ð¾Ð»Ñ f */ 802 if(typeof this.VDRules.from[form_id+'-'+f][field_id] === 'undefined'){ 803 /* array('show' => array('1')) */ 804 this.VDRules.from[form_id+'-'+f][field_id] = rules[f]; 805 } else { 806 $.extend(this.VDRules.from[form_id+'-'+f][field_id], rules[f]); 807 } 808 if(typeof this.VDListeners[form_id+'-'+f] === 'undefined'){ 809 this.VDListeners[form_id+'-'+f] = '#'+form_id+' [name="'+this.inputNameToElName(f)+'"]'; 810 let field_obj = $(this.VDListeners[form_id+'-'+f]); 811 let field_event = field_obj.attr('type') === 'text' ? 'input' : 'change'; 812 field_obj.on(field_event, function (){ 813 814 let name = $(this).attr('name').replace(/\[/g, ':').replace(/\]/g, ''); 815 816 /* пеÑÐµÐ±Ð¾Ñ ÑÐµÑ , кÑо завиÑÐ¸Ñ Ð¾Ñ ÑÑого Ð¿Ð¾Ð»Ñ name */ 817 for(var field in _this.VDRules.from[form_id+'-'+name]){if(_this.VDRules.from[form_id+'-'+name].hasOwnProperty(field)){ 818 819 /* еÑли не бÑÐ´ÐµÑ show */ 820 var display = null; 821 822 /* пеÑÐµÐ±Ð¾Ñ ÑÐµÑ , Ð¾Ñ ÐºÐ¾Ð³Ð¾ завиÑÐ¸Ñ Ð¿Ð¾Ð»Ðµ field */ 823 for(var _from in _this.VDRules.depends[form_id+'-'+field]){if(_this.VDRules.depends[form_id+'-'+field].hasOwnProperty(_from)){ 824 if(typeof _this.VDRules.depends[form_id+'-'+field][_from]['show'] !== 'undefined'){ 825 display = _this.VDisDisplay(_this.getInputVal('#'+form_id+' [name="'+_this.inputNameToElName(_from)+'"]'), _this.VDRules.depends[form_id+'-'+field][_from]['show']); 826 if(display === true){ break; } 827 } 828 }} 829 830 if(display === null){display = true;} 831 832 /* ÑкÑÑÑие ÑилÑнее показа */ 833 if(display){ 834 /* пеÑÐµÐ±Ð¾Ñ ÑÐµÑ , Ð¾Ñ ÐºÐ¾Ð³Ð¾ завиÑÐ¸Ñ Ð¿Ð¾Ð»Ðµ field */ 835 for(var _from in _this.VDRules.depends[form_id+'-'+field]){if(_this.VDRules.depends[form_id+'-'+field].hasOwnProperty(_from)){ 836 if(typeof _this.VDRules.depends[form_id+'-'+field][_from]['hide'] !== 'undefined'){ 837 display = !_this.VDisDisplay(_this.getInputVal('#'+form_id+' [name="'+_this.inputNameToElName(_from)+'"]'), _this.VDRules.depends[form_id+'-'+field][_from]['hide']); 838 if(display === false){ break; } 839 } 840 }} 841 } 842 843 if(display){ 844 $('#f_'+_this.inputNameToId(field)).removeClass('hide_field').prev('.field_tabbed').removeClass('hide_field'); 845 } else { 846 $('#f_'+_this.inputNameToId(field)).addClass('hide_field').prev('.field_tabbed').addClass('hide_field'); 847 } 848 }} 849 }); 850 } 851 }} 852 return this; 853 }; 854 this.VDReInit = function(){ 855 for(var l in this.VDListeners){if(this.VDListeners.hasOwnProperty(l)){ 856 if(this.VDListenersInitialized.indexOf(this.VDListeners[l]) === -1) { 857 $(this.VDListeners[l]).triggerHandler('change'); 858 $(this.VDListeners[l]).triggerHandler('input'); 859 this.VDListenersInitialized.push(this.VDListeners[l]); 860 } 861 }} 862 }; 863 864 return this; 865 866}).call(icms.forms || {},jQuery); 867 868icms.head = (function ($) { 869 870 var self = this; 871 872 this.on_demand = {}; 873 this.loaded = {}; 874 this.loading = {}; 875 876 this.addJs = function(name, event){ 877 if(this.on_demand.js[name]){ 878 var filepath = this.on_demand.root + this.on_demand.js[name]; 879 if (this.loaded[filepath]){ 880 if(event){ 881 icms.events.run(event); 882 } 883 return; 884 } 885 if (!this.loading[filepath]){ 886 this.loading[filepath] = true; 887 var el = document.createElement('script'); 888 el.onload = function() { 889 if(event){ 890 icms.events.run(event); 891 } 892 self.loaded[filepath] = true; 893 }; 894 el.src = filepath; 895 document.body.appendChild(el); 896 } 897 } 898 return this; 899 }; 900 901 this.addCss = function(name){ 902 if(this.on_demand.css[name]){ 903 var filepath = this.on_demand.root + this.on_demand.css[name]; 904 if (!this.loading[filepath]){ 905 this.loading[filepath] = true; 906 var el = document.createElement('link'); 907 el.href = filepath; 908 el.type = 'text/css'; 909 el.rel = 'stylesheet'; 910 document.head.appendChild(el); 911 } 912 } 913 return this; 914 }; 915 916 return this; 917 918}).call(icms.head || {},jQuery); 919 920icms.events = (function ($) { 921 922 this.listeners = {}; 923 924 this.on = function(name, callback){ 925 if (typeof(this.listeners[name]) == 'object'){ 926 this.listeners[name].push(callback); 927 } else { 928 this.listeners[name] = [callback]; 929 } 930 return this; 931 }; 932 933 this.run = function(name, params){ 934 params = params || {}; 935 for(var event_name in this.listeners[name]) { 936 if(this.listeners[name].hasOwnProperty(event_name)){ 937 if (typeof(this.listeners[name][event_name]) === 'function') { 938 this.listeners[name][event_name](params); 939 } 940 } 941 } 942 return this; 943 }; 944 945 return this; 946 947}).call(icms.events || {},jQuery); 948 949icms.pagebar = function(id, initial_page, has_next, is_modal){ 950 951 initial_page = initial_page || 1; 952 953 var page = 1; 954 955 var link = $(id); 956 957 var showMore = function(){ 958 959 var list_wrap = $(link).prev(); 960 961 if(!has_next){ 962 if(initial_page > 1){ 963 return true; 964 } 965 $('body,html').animate({ 966 scrollTop: $(list_wrap).offset().top 967 }, 500 968 ); 969 return false;
970 } 971 972 $(link).addClass('is-busy'); 973 974 page += 1; 975 976 var post_params = $(link).data('url-params'); 977 post_params.page = page; 978 979 $.post($(link).data('url'), post_params, function(data){ 980 981 var first_page_url = $(link).data('first-page-url'); 982 983 $(link).removeClass('is-busy'); 984 985 if (!data.html) { return; } 986 987 has_next = data.has_next; 988 page = data.page; 989 990 $(list_wrap).append(data.html); 991 992 if(!has_next){ 993 $('span', link).html($('span', link).data('to-first')); 994 $(link).attr('href', first_page_url); 995 } 996 997 var _sep = first_page_url.indexOf('?') !== -1 ? '&' : '?'; 998 999 if(!is_modal){ 1000 window.history.pushState({link: first_page_url+_sep+'page='+page}, '', first_page_url+_sep+'page='+page); 1001 } 1002 1003 if(is_modal){ 1004 icms.modal.resize(); 1005 } 1006 1007 }, 'json'); 1008 1009 return false; 1010 1011 }; 1012 1013 $(link).on('click', function (){ 1014 return showMore(); 1015 }); 1016 1017}; 1018 1019$.expr[':'].Contains = $.expr.createPseudo(function(arg) { 1020 return function( elem ) { 1021 return $(elem).text().toUpperCase().indexOf(arg.toUpperCase()) >= 0; 1022 }; 1023}); 1024function setCaretPosition(field, pos) { 1025 var $field = $(field); 1026 if ($field[0].setSelectionRange) { 1027 $field.focus(); 1028 $field[0].setSelectionRange(pos, pos); 1029 } else if ($field[0].createTextRange) { 1030 var range = $field[0].createTextRange(); 1031 range.collapse(true); 1032 range.moveEnd('character', pos); 1033 range.moveStart('character', pos); 1034 range.select(); 1035 } 1036} 1037function getCaretPosition(field) { 1038 var $field = $(field); 1039 if($field.length){ 1040 if (document.selection) { 1041 $field.focus(); 1042 var Sel = document.selection.createRange(); 1043 Sel.moveStart ('character', -$field.val().length); 1044 return Sel.text.length; 1045 } else { 1046 return $field[0].selectionStart || 0; 1047 } 1048 } 1049 return 0; 1050} 1051function addTextToPosition(field_id, text, spacer, spacer_stop){ 1052 var field = $(field_id); 1053 var value = $(field).val(); 1054 var pos = getCaretPosition(field); 1055 var value1 = value.substring(0, pos); 1056 var value2 = value.substring(pos, value.length); 1057 if(spacer){ 1058 var check1 = function(spacer){ // пÑовеÑка пеÑед вÑÑавлÑемÑм 1059 if(value1.length >= spacer.length){ 1060 if(value1.substring(pos - spacer.length, pos) !== spacer){ 1061 return true; 1062 } 1063 } 1064 return false; 1065 }; 1066 var check2 = function(spacer){ // пÑовеÑка поÑле вÑÑавлÑемого ÑекÑÑа 1067 if(value2.length >= spacer.length){ 1068 if(value2.substring(0, spacer.length) !== spacer){ 1069 return true; 1070 } 1071 } 1072 return false; 1073 }; 1074 var insert1 = true, insert2 = true; 1075 if(spacer_stop){ 1076 for(var ss in spacer_stop){if(spacer_stop.hasOwnProperty(ss)){ 1077 if(insert1 && (!spacer_stop[ss] || spacer_stop[ss] == 1) && !check1(ss)){ 1078 insert1 = false; 1079 } 1080 if(insert2 && (!spacer_stop[ss] || spacer_stop[ss] == 2) && !check2(ss)){ 1081 insert2 = false; 1082 } 1083 }} 1084 } 1085 1086 if(insert1 && check1(spacer)){ 1087 text = spacer+text; 1088 } 1089 if(insert2 && check2(spacer)){ 1090 text += spacer; 1091 } 1092 } 1093 $(field).val(value1 + text + value2).trigger('input'); 1094 setCaretPosition(field, pos+text.length); 1095 return false; 1096} 1097function goBack(){ 1098 window.history.go(-1); 1099} 1100function spellcount (num, one, two, many){ 1101 if (num%10==1 && num%100!=11){ 1102 str = one; 1103 } else if(num%10>=2 && num%10<=4 && (num%100<10 || num%100>=20)){ 1104 str = two; 1105 } else { 1106 str = many; 1107 } 1108 return str; 1109} 1110function initMultyTabs(selector, tab_wrap_field){ 1111 tab_wrap_field = tab_wrap_field || '.field'; 1112 $(selector).each(function(indx, element){ 1113 let tabs = $(' > li > a', $(element)); 1114 $(tabs).eq(0).addClass('active'); 1115 $(tabs).on('click', function() { 1116 let tab_field = $(this).attr('href'); 1117 $(this).addClass('active').closest('li').siblings().find('a').removeClass('active'); 1118 $(element).nextAll(tab_wrap_field+':lt('+$(tabs).closest('li').length+')').hide(); 1119 $(tab_field).show(); 1120 return false;
1121 }); 1122 }); 1123}
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.