1function ajaxCall(url, data, options, successCallback, completeCallback, errorCallback) { 2 if ( ! options ) { 3 options = {}; 4 } 5 if (options.useQueue) { 6 ajaxCallQueue.request(url, data, options, successCallback, completeCallback); 7 return; 8 } 9 10 var suppressErrors = undefined === options.suppressErrors ? false :options.suppressErrors; 11 var enableCsrf = undefined === options.enableCsrf ? false :options.enableCsrf; 12 var enableSimpleSign = undefined === options.enableSimpleSign ? false :options.enableSimpleSign; 13 const suppressNotify = options.suppressNotify || false; 14 15 if ( options.btn ) { 16 options.btn.attr( 'disabled', 'disabled' ); 17 } 18 var method = "post"; 19 if ( options.method ) { 20 method = options.method; 21 } 22 23 if (enableCsrf && window.csrfToken !== undefined) { 24 if (typeof data === 'object') { 25 data['_csrf'] = window.csrfToken; 26 } 27 else if (typeof data === 'string') { 28 data += '&_csrf='+window.csrfToken; 29 } 30 } 31 if (enableSimpleSign && window.requestTime !== undefined && window.requestSimpleSign !== undefined) { 32 if (typeof data === 'object') { 33 data['requestTime'] = window.requestTime; 34 data['requestSimpleSign'] = window.requestSimpleSign; 35 } 36 else if (typeof data === 'string') { 37 data += '&requestTime='+window.requestTime; 38 data += '&requestSimpleSign='+window.requestSimpleSign; 39 } 40 } 41 if ( typeof(Storage) !== 'undefined' ) { 42 try { 43 var session = localStorage.getItem('session'); 44 var visit = localStorage.getItem('visit'); 45 var visitor = localStorage.getItem('visitor'); 46 var hash = localStorage.getItem('hash'); 47 if (session && hash) { 48 if (typeof data === 'object') { 49 data['gcSession'] = session; 50 data['gcVisit'] = visit; 51 data['gcVisitor'] = visitor; 52 data['gcSessionHash'] = hash; 53 } else if (typeof data === 'string') { 54 data += '&gcSession=' + session; 55 data += '&gcVisit=' + visit; 56 data += '&gcVisitor=' + visitor; 57 data += '&gcSessionHash=' + hash; 58 } 59 } 60 } catch (e) { 61 // Ð Ñежиме блокиÑÐ¾Ð²Ð°Ð½Ð¸Ñ ÐºÑк (как минимÑм Ñ Ñом) бÑоÑÐ°ÐµÑ Ð¾ÑÐ¸Ð±ÐºÑ Ð¿Ñи доÑÑÑпе к 62 // localStorage, Ñ Ð¾ÑÑ Ð¾Ð±ÑÐµÐºÑ Ð¾Ð¿Ñеделен 63 } 64 } 65 66 var async = true; 67 if (options.async === false) { 68 async = false; 69 } 70 71 var params = { 72 url: url, 73 type: method, 74 data: data, 75 async: async, 76 complete: function ( jqResponse, status ) { 77 78 error_text_value = 'ÐÑибка'; 79 if (typeof Yii != 'undefined') { 80 error_text_value = Yii.t( "common", "Error" ); 81 } 82 83 if ( options.btn ) { 84 options.btn.removeAttr( 'disabled' ); 85 } 86 87 try { 88 response = $.parseJSON(jqResponse.responseText); 89 } catch (exception) { 90 response = jqResponse; 91 response.success = false; 92 response.message = "ÐеизвеÑÑÐ½Ð°Ñ Ð¾Ñибка"; 93 } 94 95 if (status === 'success') { 96 if ( response.success ) { 97 if (!suppressNotify && response.message && response.message.length > 0) { 98 var message = response.message; 99 var messageOptions = { type: "success" }; 100 if (window.isPageRedesigned) { 101 showRedesignAlert('success', message) 102 } else { 103 if ( $.toast ) { 104 $.toast.config.width = Math.min(500, $(window).width() * 0.95); 105 $.toast(message, messageOptions); 106 } 107 else { 108 console.log(message); 109 } 110 } 111 } 112 if ( successCallback ) { 113 successCallback( response ); 114 } 115 } 116 else { 117 if ( !suppressErrors ) { 118 if (window.isPageRedesigned && typeof showRedesignAlert === 'function') { 119 showRedesignAlert('danger', response.message) 120 } else { 121 if ( $.toast ) { 122 $.toast.config.width = Math.min(500, $(window).width() * 0.95); 123 if (response.only_last_error) { 124 $('.toast .danger').remove(); 125 } 126 $.toast(error_text_value + ": " + response.message, { 127 type: "danger", 128 sticky: response.toast_sticky === true, 129 }); 130 } else { 131 alert(response.message); 132 } 133 } 134 135 } 136 if (errorCallback) { 137 errorCallback(response); 138 } 139 } 140 } 141 else { 142 if ( jqResponse.readyState == 0 ) { 143 return; 144 } 145 if ( !suppressErrors ) { 146 if ($.toast) { 147 $.toast.config.width = Math.min(500, $(window).width() * 0.95); 148 $.toast( error_text_value + ": " + jqResponse.statusText, {type: "danger"}); 149 } else { 150 alert(response.message); 151 } 152 } 153 console.error('error', jqResponse.statusText); 154 console.error(jqResponse.responseText); 155 if (errorCallback) { 156 errorCallback(response); 157 } 158 } 159 if (completeCallback) { 160 completeCallback(response); 161 } 162 } 163 }; 164 165 if (options.crossDomain) { 166 params.crossDomain = true; 167 } 168 169 $.ajax(params); 170} 171 172var ajaxCallQueue = new (function () { 173 /** @private */ 174 let self = this; 175 176 this.limit = 4; 177 /** @private */ 178 this.active = 0; 179 /** @private */ 180 this.queue = []; 181 182 this.request = function (url, data, options, successCallback, completeCallback) { 183 this.queue.push({ 184 url: url, 185 data: data, 186 options: options, 187 successCallback: successCallback, 188 completeCallback: completeCallback 189 }); 190 this.processQueue(); 191 } 192 193 /** 194 * @private 195 */ 196 this.processQueue = function () { 197 if (this.queue.length === 0) { 198 return; 199 } 200 201 if (this.active >= this.limit) { 202 return; 203 } 204 205 this.active++; 206 let request = this.queue.shift(); 207 request.options.useQueue = false;
208 209 ajaxCall( 210 request.url, 211 request.data, 212 request.options, 213 function (response) { 214 try { 215 request.successCallback(response); 216 } catch ($e) { 217 console.error($e); 218 } 219 }, 220 function () { 221 if (request.completeCallback) { 222 try { 223 request.completeCallback(); 224 } catch ($e) { 225 console.error($e); 226 } 227 } 228 self.active--; 229 self.processQueue(); 230 }, 231 ); 232 } 233})(); 234 235function bodyScrollTo( $el, padding ) { 236 if ( padding == null ) { 237 padding = 400; 238 } 239 $( "body,html" ).animate({ 240 scrollTop: Math.round( $el.offset().top ) - padding 241 }, 200 ); 242} 243 244 245 246function initUploadify( $fileElem, options ) { 247 248 var defaultButtonText = Yii.t('common', 'ÐобавиÑÑ ÑайлÑ'); 249 if ( $fileElem.attr( 'title') ) { 250 defaultButtonText = $fileElem.attr( 'title'); 251 } 252 var url = options.url ? options.url : ( 253 '/fileservice/widget/upload?deprecated=17' 254 + '&secure=' + window.isEnabledSecureUpload 255 + '&host=' + window.fileserviceUploadHost 256 ); 257 var finalOptions = { 258 auto: true, 259 buttonText: options.buttonText ? options.buttonText : defaultButtonText, 260 width: options.width ? options.width : 200, 261 itemTemplate: options.itemTemplate ? options.itemTemplate : false, 262 fileSizeLimit: options.fileSizeLimit ? options.fileSizeLimit : '2GB', 263 formData: { 264 userId: options.userId 265 }, 266 uploadScript: url, 267 onUploadError: function (file, errorCode, errorMsg) { 268 alert("ERROR"); 269 }, 270 onUploadComplete: options.onUploadComplete ? options.onUploadComplete : function (e, res) { 271 $hiddenInputEl = $(options.valueElemSelector); 272 oldVal = $hiddenInputEl.val(); 273 newVal = oldVal; 274 if (newVal && newVal.length > 0) { 275 newVal += ","; 276 } 277 newVal += res; 278 279 $hiddenInputEl.val(newVal); 280 //location.href = location.href; 281 }, 282 multi: options.hasOwnProperty('multi') ? options.multi : true 283 }; 284 if (options.onQueueComplete) { 285 finalOptions.onQueueComplete = options.onQueueComplete; 286 } 287 if (options.onUpload) { 288 finalOptions.onUpload = options.onUpload; 289 } else if (window.isEnabledSecureUpload && window.fileserviceUploadHost) { 290 finalOptions.onUpload = getUploadifySecretLink; 291 } 292 293 if (options.other) { 294 $.each(options.other, function(key, callback) { 295 finalOptions[key] = callback; 296 }); 297 } 298 $fileElem.uploadifive(finalOptions); 299 300 if ( options.fileSizeLimit ) { 301 var fileSizeLimitWarning = options.fileSizeLimitWarning ? options.fileSizeLimitWarning : Yii.t('common', 'ÐакÑ. ÑÐ°Ð·Ð¼ÐµÑ 2 ÐÐ'); 302 var warning = $("<p class='text-muted'>" + fileSizeLimitWarning + "</p>"); 303 $fileElem.parent().after(warning); 304 } 305} 306 307window.errCount = 0; 308 309function sendError(message) { 310 window.errCount++; 311 if (window.errCount <= 10) { 312 $.ajax({ 313 url: '/pl/gc/log', 314 method: 'POST', 315 data: {data: message} 316 }); 317 } 318} 319 320function sendCreateLinkError(http, message, exc) { 321 var postMessage = ''; 322 var toastMessage = ''; 323 if (http.responseJSON) { 324 postMessage += (http.responseJSON ? ('json: ' + JSON.stringify(http.responseJSON)) : ''); 325 } 326 327 toastMessage += 'status: ' + http.status + '; '; 328 toastMessage += (http.statusText ? ('statusText: ' + http.statusText + '; ') : ''); 329 postMessage += toastMessage; 330 331 postMessage += (message ? ('message: ' + message + ' /// ') : ''); 332 333 postMessage += (exc ? ('exc: ' + exc + ' /// ') : ''); 334 335 if ($.isFunction($.fn.toast)) { 336 $.toast(toastMessage, {type: "danger"}); 337 } 338 console.log(postMessage); 339 sendError(postMessage); 340} 341 342function getUploadifySecretLink(filesToUpload, settings) { 343 var secureDirectUploadUri = '/fileservice/widget/secure-direct-upload'; 344 try { 345 var session = localStorage.getItem('session');
346 var requestParams = {"fs_ref": window.location.href}; 347 348 if (session !== undefined && session != null){ 349 var objSession = jQuery.parseJSON(session); 350 351 if (objSession.hasOwnProperty('user_id') && objSession.user_id != null) { 352 requestParams.fs_u = objSession.user_id; 353 } else { 354 requestParams.fs_u = -1; 355 } 356 } 357 358 secureDirectUploadUri += '?' + jQuery.param(requestParams); 359 } catch (err) { 360 } 361 362 if (typeof settings !== 'undefined' && settings !== null) { 363 delete settings.uploadScript; 364 } 365 366 $.ajax({ 367 url: '/fileservice/widget/create-secret-link', 368 method: 'GET', 369 data: { 370 host: window.fileserviceUploadHost, 371 uri: secureDirectUploadUri, 372 expires: 600 373 }, 374 success: function (data) { 375 if (data.link) { 376 if (typeof settings !== 'undefined' && settings !== null) { 377 settings.uploadScript = data.link; 378 } 379 } else { 380 ajaxCall('/fileservice/widget/log-error', {m: 'No link'}, {}); 381 } 382 }, 383 error: function (http, message, exc) { 384 sendCreateLinkError(http, message, exc); 385 }, 386 async: false 387 }); 388} 389 390function panelPutTaskAside( task_id ) { 391 $('.aside-loading').css('opacity', 1); 392 $('.aside-link').css('opacity', 0).css('cursor', 'default'); 393 $.ajax({ 394 url: '/tasks/control/task/setNew', 395 method: 'post', 396 data: {'id': task_id }, 397 success: function(data) { 398 panelLoad(); 399 } 400 }); 401} 402function panelFinishTask( task_id, result ) { 403 $('.aside-loading').css('opacity', 1); 404 $.ajax({ 405 url: '/tasks/control/task/setCompleted', 406 method: 'post', 407 data: {'id': task_id, result: result }, 408 success: function(data) { 409 panelLoad(); 410 } 411 }); 412 413 return false; 414} 415 416function panelLoad() { 417 $.ajax({ 418 url: '/tasks/control/task/getPanel', 419 success: function(data) { 420 $('#task-panel-placeholder').html( data ); 421 } 422 }); 423} 424 425function setElLoading( el ) { 426 $(el).html('<div class="text-center padding-10"><img src="/public/img/loading.gif"></div>'); 427} 428 429 430$( function() { 431 $('.editable .edit-link').click( function() { 432 $(this).parents('.editable').toggleClass('edit'); 433 $(this).parents('.editable').find( 'input').focus(); 434 }); 435}) 436 437$( function() { 438 $( '.action-link').click( function() { 439 if ( $(this).data('gc-confirm' ) ) { 440 if ( ! confirm( $(this).data('gc-confirm' ) ) ) { 441 return false; 442 } 443 } 444 $( '.page-main-form' ).find( 'input[name=action]').val( $(this).data('action' ) ); 445 $( '.page-main-form' ).submit(); 446 }); 447}) 448 449 450function extend(Child, Parent) { 451 var F = function() { } 452 F.prototype = Parent.prototype 453 Child.prototype = new F() 454 Child.prototype.constructor = Child 455 Child.superclass = Parent.prototype 456} 457 458function mixin(cls, mixin) { 459 for (var key in mixin) { 460 if (cls.prototype[key]) { 461 // console.log("Class " + cls + " already has a method named " + key + "!"); 462 } 463 else { 464 cls.prototype[key] = mixin[key]; 465 } 466 } 467} 468 469 470$( function() { 471 if ( $('.date-input').datetimepicker ) { 472 $('.date-input').datetimepicker({ 473 timepicker: false, closeOnDateSelect: true, format:'d.m.Y', 474 step: 20, lang:'ru', dayOfWeekStart: 1, todayButton: false, validateOnBlur: true, allowBlank: true, yearStart: '2013', yearEnd: '2020', lazyInit: false 475 }); 476 477 $('.date-time-input').datetimepicker({ 478 timepicker: true, closeOnDateSelect: false, format:'d.m.Y H:i', 479 step: 20, lang:'ru', dayOfWeekStart: 1, todayButton: false, validateOnBlur: true, allowBlank: true, yearStart: '2013', yearEnd: '2020', lazyInit: false 480 }); 481 } 482}); 483 484 485$.fn.scrollTo = function( target, options, callback ){ 486 if(typeof options == 'function' && arguments.length == 2){ callback = options; options = target; } 487 var settings = $.extend({ 488 scrollTarget : target, 489 offsetTop : 50, 490 duration : 500, 491 easing : 'swing' 492 }, options); 493 return this.each(function(){ 494 var scrollPane = $(this); 495 var scrollTarget = (typeof settings.scrollTarget == "number") ? settings.scrollTarget : $(settings.scrollTarget); 496 var scrollY = (typeof scrollTarget == "number") ? scrollTarget : scrollTarget.offset().top + scrollPane.scrollTop() - parseInt(settings.offsetTop); 497 scrollPane.animate({scrollTop : scrollY }, parseInt(settings.duration), settings.easing, function(){ 498 if (typeof callback == 'function') { callback.call(this); } 499 }); 500 }); 501}; 502 503function getThumbnailUrl( hash, width, height ) {
504 var result = "/fileservice/file/thumbnail/h/" + hash + "/s/" + width + "x" + height; 505 if (window.accountId) { 506 result += '/a/'+window.accountId; 507 } 508 if ( window.fileserviceThumbnailHost ) { 509 result = "//" + window.fileserviceThumbnailHost + result; 510 } 511 return result; 512} 513function getBorderedThumbnailUrl( hash, width, height, borderName) { 514 515 if ( borderName == "" ) { 516 return getThumbnailUrl(hash, width, height); 517 } 518 519 var result = "/fileservice/file/bordered/h/" + hash + "/s/" + width + "x" + height + "/b/" + borderName; 520 if (window.accountId) { 521 result += '/a/'+window.accountId; 522 } 523 if ( window.fileserviceThumbnailHost ) { 524 result = "//" + window.fileserviceThumbnailHost + result; 525 } 526 return result; 527} 528function getDownloadUrl( hash ) { 529 var result = "/pl/fileservice/user/file/download?h=" + hash; 530 531 return result; 532} 533 534function isImage(hash) { 535 let hashParts = hash.split("."); 536 if (hashParts.length === 2) { 537 let imgExts = ['jpeg', 'jpg', 'gif', 'png', 'heic']; 538 return imgExts.includes(hashParts[1]); 539 } else { 540 return false; 541 } 542} 543 544function isVideo(hash) { 545 var hashParts = hash.toLowerCase().split("."); 546 if (hashParts.length === 2) { 547 var imgExts = ['mp4', 'mov']; 548 return imgExts.includes(hashParts[1]); 549 } else { 550 return false; 551 } 552} 553 554/** 555 * Ðогда нÑжно обновиÑÑ ÐºÐ°ÑÑÐ¸Ð½ÐºÑ Ð² Ð¾Ð±Ñ Ð¾Ð´ кÑÑа бÑаÑзеÑа 556 */ 557function updateThumbnailVersion(hash, version) { 558 if (!window.thumbnailVersions) { 559 window.thumbnailVersions = {}; 560 } 561 window.thumbnailVersions[hash] = version; 562} 563 564function getVideoThumbnailUrl( hash, width, height ) { 565 var url = "/pl/fileservice/video/preview-redirect/?file-hash=" + hash; 566 if (window.thumbnailVersions && hash in window.thumbnailVersions) { 567 url += '&v=' + window.thumbnailVersions[hash]; 568 } 569 return url; 570} 571 572function gcGetFileObj( row ) { 573 var title = row.title; 574 if ( ! title ) title = row.filename; 575 if ( ! title ) title = row.hash; 576 577 var result = { 578 hash: row.hash, 579 title: title, 580 description: row.description, 581 getThumbnailUrl: function( width, height ) { 582 return "/fileservice/file/thumbnail/h/" + this.hash + "/s/" + width + "x" + height; 583 }, 584 getDownloadUrl: function() { 585 return "/pl/fileservice/user/file/download?h=" + this.hash; 586 } 587 }; 588 return result; 589} 590 591var getProp = function(o, name, defaultValue) { 592 return undefined === o[name] ? defaultValue : o[name]; 593}; 594 595$(function () { 596 if ($('#blueimp-gallery').length == 0) { 597 var $el = $('<div id="blueimp-gallery" class="blueimp-gallery blueimp-gallery-controls"><div class="slides next-click"></div><h3 class="title"></h3><a class="prev">â¹</a><a class="next next-click">âº</a><a class="play-pause"></a><ol class="indicator"></ol></div>') 598 $el.hide(); 599 $el.appendTo($(document.body)); 600 } 601}); 602 603$(function () { 604 function handleAction(href, target) { 605 var accountDomains = window.accountDomains || []; 606 var pathsToWrap = window.pathsToWrap || []; 607 var authingUrl = window.authingUrl || ''; 608 var openInExternalApp = target === '_blank'; 609 var mainDomain = window.mainDomain || ''; 610 if (!href.startsWith('https://') && !href.startsWith('http://')) { 611 const locationHref = new URL(location.href); 612 href = locationHref.origin + href; 613 openInExternalApp = false; 614 } 615 if (accountDomains.includes((new URL(href)).host)) { 616 openInExternalApp = false; 617 } 618 619 var url = new URL(href); 620 for (var path of pathsToWrap) { 621 if (url.pathname.startsWith(path)) { 622 openInExternalApp = true; 623 href = authingUrl !== '' && mainDomain === url.host 624 ? authingUrl + '&redirectUrl=' + encodeURIComponent(url.href) 625 : url.href; 626 break; 627 } 628 } 629 630 window.appHandleAction({ 631 type: "navigate", 632 url: href, 633 openInExternalApp: openInExternalApp 634 }); 635 } 636 $(".lt-block-wrapper a:visible, .xdget-block.xdget-html a:visible, .xdget-block.xdget-lessonContent a:visible, .lite-page a:visible") 637 .on('click', function (event) { 638 const elem = event.currentTarget; 639 640 if ( 641 !elem || 642 !elem.href 643 ) { 644 return; 645 } 646 647 if ( 648 elem && 649 elem.href && 650 typeof elem.href === 'string' && 651 elem.href.indexOf('#') >= 0 652 ) { 653 const cleanThisHref = document.location.href.replace(/\#.*$/, ''); 654 const cleanAnchorHref = elem.href.replace(/\#.*$/, ''); 655 if (cleanThisHref === cleanAnchorHref) { 656 return; 657 } 658 } 659 660 if (!elem.href.startsWith('#') && !elem.href.startsWith('javascript:') && window.appHandleAction) { 661 event.preventDefault(); 662 handleAction(elem.href, elem.target); 663 return false;
664 } 665 }); 666}); 667 668$( function() { 669 $('.editable-link').each( function( index, el ) { 670 $el = $(el) 671 $wrapper = $el.parents('.editable-link-wrapper') 672 673 if ( $wrapper.length == 0 ) { 674 $wrapper = $('<span class="editable-link-wrapper"/>') 675 $el.replaceWith( $wrapper ) 676 $el.appendTo( $wrapper ) 677 } 678 679 $link = $('<a class="link"/>') 680 if ( $el.data('header')) { 681 $header = $('<h1/>') 682 $link.appendTo( $header ) 683 $header.appendTo( $wrapper ) 684 } 685 else { 686 $link.appendTo( $wrapper ) 687 } 688 689 var value = null; 690 691 if ( $el.val() != "" ) { 692 value = $el.val(); 693 } else if ( $el.attr("placeholder") && $el.attr("placeholder") != "" ) { 694 if(!window.isPageRedesigned) { 695 value = $el.attr("placeholder"); 696 } else { 697 value = Yii.t( "common", "change" ); 698 $link.addClass('rd-fake-link rd-first-letter-up'); 699 } 700 } else { 701 value = 'измениÑÑ'; 702 703 if (typeof Yii != 'undefined') { 704 value = Yii.t( "common", "change" ); 705 } 706 $wrapper.addClass( 'no-value' ); 707 if(window.isPageRedesigned) { 708 $link.addClass('rd-fake-link rd-first-letter-up'); 709 } 710 } 711 712 if (window.isPageRedesigned && typeof Yii != 'undefined') { 713 if (value === 'male') { 714 value = Yii.t("user", "Male"); 715 } 716 if (value === 'female') { 717 value = Yii.t("user", "Female"); 718 } 719 } 720 721 $link.html(value); 722 723 $link.click( function() { 724 $(this).parents('.editable-link-wrapper').addClass('edit-mode') 725 }) 726 727 }) 728}) 729 730window.runOneTimeOnElement = function($el, key, callback) { 731 if ($el.data(key)) { 732 return; 733 } 734 $el.data(key, callback($el)); 735}; 736window.eachAndRunOneTimeOnElement = function($each, key, callback) { 737 $each.each(function(index, el) { 738 runOneTimeOnElement($(el), key, callback); 739 }); 740} 741 742function objectToQueryString (a) { 743 var prefix, s, add, name, r20, output; 744 s = []; 745 r20 = /%20/g; 746 add = function (key, value) { 747 // If value is a function, invoke it and return its value 748 value = ( typeof value == 'function' ) ? value() : ( value == null ? "" : value ); 749 s[ s.length ] = encodeURIComponent(key) + "=" + encodeURIComponent(value); 750 }; 751 if (a instanceof Array) { 752 for (name in a) { 753 add(name, a[name]); 754 } 755 } else { 756 for (prefix in a) { 757 buildParams(prefix, a[ prefix ], add); 758 } 759 } 760 output = s.join("&").replace(r20, "+"); 761 return output; 762}; 763function buildParams(prefix, obj, add) { 764 var name, i, l, rbracket; 765 rbracket = /\[\]$/; 766 if (obj instanceof Array) { 767 for (i = 0, l = obj.length; i < l; i++) { 768 if (rbracket.test(prefix)) { 769 add(prefix, obj[i]); 770 } else { 771 buildParams(prefix + "[" + ( typeof obj[i] === "object" ? i : "" ) + "]", obj[i], add); 772 } 773 } 774 } else if (typeof obj == "object") { 775 // Serialize object item. 776 for (name in obj) { 777 buildParams(prefix + "[" + name + "]", obj[ name ], add); 778 } 779 } else { 780 // Serialize scalar item. 781 add(prefix, obj); 782 } 783} 784 785$.fn.serializeObject = function() 786{ 787 var o = {}; 788 var a = this.serializeArray(); 789 $.each(a, function() { 790 if (o[this.name] !== undefined) { 791 if (!o[this.name].push) { 792 o[this.name] = [o[this.name]]; 793 } 794 o[this.name].push(this.value || ''); 795 } else { 796 o[this.name] = this.value || ''; 797 } 798 }); 799 return o; 800}; 801 802window.gcIsHiddenTab = function(){ 803 var hidden, state; 804 805 if (typeof document.hidden !== "undefined") { 806 state = "visibilityState"; 807 } else if (typeof document.mozHidden !== "undefined") { 808 state = "mozVisibilityState"; 809 } else if (typeof document.msHidden !== "undefined") { 810 state = "msVisibilityState"; 811 } else if (typeof document.webkitHidden !== "undefined") { 812 state = "webkitVisibilityState"; 813 } 814 815 return document[state] == "hidden"; 816}; 817window.gcIsActiveTab = !window.gcIsHiddenTab(); 818$(window).focus(function() { 819 window.gcIsActiveTab = true; 820}); 821 822$(window).blur(function() { 823 window.gcIsActiveTab = false;
824}); 825 826window.gcGetCookie = function(name) { 827 var matches = document.cookie.match(new RegExp( 828 "(?:^|; )" + name.replace(/([\.$?*|{}\(\)\[\]\\\/\+^])/g, '\\$1') + "=([^;]*)" 829 )); 830 return matches ? decodeURIComponent(matches[1]) : undefined; 831}; 832 833window.gcSetCookie = function gcSetCookie(name, value, options) { 834 options = options || {}; 835 836 var expires = options.expires; 837 838 if (typeof expires == "number" && expires) { 839 var d = new Date(); 840 d.setTime(d.getTime() + expires * 1000); 841 expires = options.expires = d; 842 } 843 if (expires && expires.toUTCString) { 844 options.expires = expires.toUTCString(); 845 } 846 847 value = encodeURIComponent(value); 848 849 var updatedCookie = name + "=" + value; 850 851 for (var propName in options) { 852 updatedCookie += "; " + propName; 853 var propValue = options[propName]; 854 if (propValue !== true) { 855 updatedCookie += "=" + propValue; 856 } 857 } 858 859 document.cookie = updatedCookie; 860}; 861 862 863function addParamToLocation( key, value) 864{ 865 key = encodeURI(key); value = encodeURI(value); 866 867 var kvp = document.location.search.substr(1).split('&'); 868 869 var i=kvp.length; var x; while(i--) 870 { 871 x = kvp[i].split('='); 872 873 if (x[0]==key) 874 { 875 x[1] = value; 876 kvp[i] = x.join('='); 877 break; 878 } 879 } 880 881 if(i<0) {kvp[kvp.length] = [key,value].join('=');} 882 883 //this will reload the page, it's likely better to store this until finished 884 document.location.search = kvp.join('&'); 885} 886 887function removeParamFromLocation( key ) 888{ 889 key = encodeURI(key); 890 891 var kvp = document.location.search.substr(1).split('&'); 892 893 var i=kvp.length; var x; while(i--) 894 { 895 x = kvp[i].split('='); 896 897 898 if (x[0]==key) 899 { 900 kvp[i] = null 901 break; 902 } 903 } 904 var search = kvp.join("&") != "&" ? kvp.join('&') : ""; 905//alert(kvp.length > 0 kvp.join('&') : "") 906 //this will reload the page, it's likely better to store this until finished 907 document.location.search = search; 908} 909 910 911function escapeDoubleQuotes(str) { 912 return str.replace(/\\([\s\S])|(")/g,"\\$1$2"); 913} 914 915function setVisibilityRelation( checkboxSelector, paramsSelector ) { 916 var $checkboxSelector = $(checkboxSelector) 917 var $paramsSelector = $(paramsSelector) 918 var changed = function() { 919 var checked = $checkboxSelector.prop('checked'); 920 if ( checked ) $paramsSelector.show(); else $paramsSelector.hide(); 921 } 922 $checkboxSelector.click( changed ) 923 changed(); 924} 925 926function getParamFromLocation( key ) 927{ 928 key = encodeURI(key); 929 930 var kvp = document.location.search.substr(1).split('&'); 931 932 var i=kvp.length; var x; while(i--) 933 { 934 x = kvp[i].split('='); 935 936 937 if (x[0]==key) 938 { 939 return x[1]; 940 } 941 } 942 return null; 943} 944 945function getParamFromHash( key ) 946{ 947 key = encodeURI(key); 948 949 var kvp = document.location.hash.substr(1).split('&'); 950 951 var i=kvp.length; var x; while(i--) 952{ 953 x = kvp[i].split('='); 954 955 956 if (x[0]==key) 957 { 958 var res = x[1]; 959 return res; 960 } 961} 962 return null; 963} 964 965var gcParseUrl = function(url) { 966 var urlEl = document.createElement('a'); 967 urlEl.href = url; 968 return urlEl; 969}; 970 971var gcAddResourceElement = function(tag, attr, createElementCallback) { 972 var resources = {}; 973 974 return function(resourceUrl) { 975 if (!resources.hasOwnProperty(resourceUrl)) { 976 var list = document.getElementsByTagName(tag); 977 var i = list.length, exists = false; 978 while (i--) { 979 var url = gcParseUrl(list[i][attr]); 980 if (url.pathname+url.search == resourceUrl) { 981 exists = true; 982 break; 983 } 984 } 985 if (!exists) { 986 resources[resourceUrl] = createElementCallback(resourceUrl); 987 console.log('loaded '+resourceUrl); 988 } 989 } 990 }; 991}; 992 993var gcAddScriptElement = (function() { 994 return gcAddResourceElement('script', 'src', function (resourceUrl) { 995 var script = document.createElement("script"); 996 script.type = "text/javascript"; 997 script.src = resourceUrl; 998 document.getElementsByTagName('head')[0].appendChild(script); 999 return script; 1000 }); 1001})(); 1002 1003var gcAddLinkElement = (function() { 1004 return gcAddResourceElement('link', 'href', function (resourceUrl) { 1005 var link = document.createElement("link"); 1006 link.rel = "stylesheet"; 1007 link.src = resourceUrl; 1008 document.getElementsByTagName('head')[0].appendChild(link); 1009 return link; 1010 }); 1011})(); 1012 1013 1014 1015function replaceAll(str, find, replace) { 1016 return str.replace(new RegExp(find, 'g'), replace); 1017} 1018 1019serializeObj = function(obj, prefix) { 1020 var str = [], p; 1021 for(p in obj) { 1022 if (obj.hasOwnProperty(p)) { 1023 var k = prefix ? prefix + "[" + p + "]" : p, v = obj[p]; 1024 if ( typeof v === "undefined" ) { 1025 continue; 1026 } 1027 if ( v == null ) { 1028 continue; 1029 } 1030 str.push((v !== null && typeof v === "object") ? 1031 serializeObj(v, k) : 1032 encodeURIComponent(k) + "=" + encodeURIComponent(v)); 1033 } 1034 } 1035 return str.join("&"); 1036}; 1037 1038function initListSearch( element, selector ) { 1039 1040 var filter = function( value ) { 1041 value = value.toLowerCase(); 1042 var found = false;
1043 element.find(selector).each(function () { 1044 var text = $(this).html().toLowerCase(); 1045 if (value == "") { 1046 $(this).show(); 1047 found = true; 1048 } 1049 else { 1050 if (text.indexOf(value) > -1) { 1051 $(this).show(); 1052 found = true; 1053 } 1054 else { 1055 $(this).hide(); 1056 } 1057 } 1058 1059 }) 1060 return found; 1061 }; 1062 1063 var placeholderValue = window.isPageRedesigned ? 'ÐоиÑк' : 'поиÑк'; 1064 var notFound = 'ниÑего не найдено'; 1065 if (typeof Yii != 'undefined') { 1066 placeholderValue = window.isPageRedesigned ? Yii.t("common", "ÐоиÑк") : Yii.t("common", "search"); 1067 notFound = Yii.t("common", "ниÑего не найдено"); 1068 } 1069 1070 var liStyle = window.isPageRedesigned ? 'margin: 0; list-style: none; padding: 8px 12px;' : 'margin: 0; list-style: none; padding: 5px 3px;'; 1071 1072 var $searchRuleBlock = $("<li style='" + liStyle + "'><input class='search-input' placeholder='" + placeholderValue + "' type='text'/><div class='nothing-found-label' style='padding-top: 10px; background: lightyellow; display:none'>" + notFound + "</div></li>") 1073 if(window.isPageRedesigned) { 1074 if(element.find('li:not(.hidden):not(:has(input))').length >= 5) { 1075 $searchRuleBlock.prependTo ( element ) 1076 } 1077 } else { 1078 $searchRuleBlock.prependTo ( element ) 1079 } 1080 var searchRuleInput = $searchRuleBlock.find('input') 1081 searchRuleInput.keyup( function() { 1082 if ( filter( $(this).val() ) ) { 1083 $searchRuleBlock.find('.nothing-found-label').hide() 1084 } 1085 else { 1086 $searchRuleBlock.find('.nothing-found-label').show() 1087 } 1088 }); 1089} 1090 1091function initDropdownSearch( $dropdownMenu ) { 1092 1093 $dropdownMenu = $dropdownMenu.find('.dropdown-menu') 1094 1095 initListSearch( $dropdownMenu, 'a' ); 1096 1097 $dropdownMenu.parent().on( 'show.bs.dropdown', function() { 1098 setTimeout( function() { 1099 $dropdownMenu.find('.search-input').focus(); 1100 }) 1101 }) 1102 1103 1104 1105 1106} 1107 1108 1109function number_format( number, decimals, dec_point, thousands_sep ) { // Format a number with grouped thousands 1110 // 1111 // + original by: Jonas Raoni Soares Silva (http://www.jsfromhell.com) 1112 // + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net) 1113 // + bugfix by: Michael White (http://crestidg.com) 1114 1115 var i, j, kw, kd, km; 1116 1117 // input sanitation & defaults 1118 if( isNaN(decimals = Math.abs(decimals)) ){ 1119 decimals = 2; 1120 } 1121 if( dec_point == undefined ){ 1122 dec_point = ","; 1123 } 1124 if( thousands_sep == undefined ){ 1125 thousands_sep = "."; 1126 } 1127 1128 i = parseInt(number = (+number || 0).toFixed(decimals)) + ""; 1129 1130 if( (j = i.length) > 3 ){ 1131 j = j % 3; 1132 } else{ 1133 j = 0; 1134 } 1135 1136 km = (j ? i.substr(0, j) + thousands_sep : ""); 1137 kw = i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + thousands_sep); 1138 //kd = (decimals ? dec_point + Math.abs(number - i).toFixed(decimals).slice(2) : ""); 1139 kd = (decimals ? dec_point + Math.abs(number - i).toFixed(decimals).replace(/-/, 0).slice(2) : ""); 1140 1141 1142 return km + kw + kd; 1143} 1144 1145 1146function onTelegramAuth(user) { 1147 ajaxCall( "/pl/user/profile/login-with-telegram", { user: user }, {method: 'get'}, function( response ) { 1148 if ( window.afterTelegramAuthCallback ) { 1149 window.afterTelegramAuthCallback(); 1150 } 1151 //alert( response ) 1152 }); 1153} 1154 1155window.phoneChecked = false; 1156window.checkFormPhone = function(form) { 1157 var phoneInput = $(form).find('input.phone-input') 1158 if ( phoneInput.length > 0 && ! window.phoneChecked ) { 1159 ajaxCall( "/pl/user/profile/set-phone", { phone: phoneInput.val() }, {}, function( response ) { 1160 if ( response.data.success) { 1161 window.phoneChecked = true; 1162 $(form).submit() 1163 } 1164 else { 1165 alert( response.data.error ) 1166 } 1167 } ); 1168 return false; 1169 } 1170 else { 1171 return true; 1172 } 1173 1174}; 1175window.tt = function(category, text, params) { 1176 return (typeof Yii != 'undefined') ? Yii.t(category, text, params) : text; 1177}; 1178 1179 1180window.renderIcon = function( icon, $parentEl ) { 1181 1182 let $el = $parentEl.find('.chatium-icon'); 1183 if ( $el.length == 0 ) { 1184 $el = $('<div class="chatium-icon"/>').appendTo( $parentEl ); 1185 } 1186 1187 let url = icon.url; 1188 if ( ! url && icon.image ) { 1189 url = icon.image; 1190 } 1191 if ( icon.hash ) { 1192 url = getThumbnailUrl(icon.hash, 100, 100); 1193 } 1194 if ( url ) { 1195 $el.empty(); 1196 $('<img/>').attr( 'src', url ).appendTo( $el ); 1197 } 1198 else if ( icon.iconCssClass ) { 1199 $el.html("<div class='chatium-icon-text'><span class='" + icon.iconCssClass + "'></span></div>") 1200 $el.addClass('icon-type-icon' ); 1201 } 1202 else { 1203 $el.html( "<div class='chatium-icon-text'>" + ( icon.text ? icon.text : "" ) + "</div>" ); 1204 if ( icon.type ) { 1205 $el.addClass('icon-type-' + icon.type ); 1206 } 1207 1208 } 1209 if ( icon.color ) { 1210 $el.css('color', icon.color) 1211 } 1212 if ( icon.bgColor && !url) { 1213 $el.css('background-color', icon.bgColor) 1214 } 1215};
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.