1var _debug = false; 2var bUsingConfirmPopupForPreventingReload = false; 3var PF = { 4 events: {}, 5 tools: { 6 versionCompare: function (v1, v2, operator) { 7 this.php_js = this.php_js || {}; 8 this.php_js.ENV = this.php_js.ENV || {}; 9 10 var i = 0, 11 x = 0, 12 compare = 0, 13 vm = { 14 'dev': -6, 15 'alpha': -5, 16 'a': -5, 17 'beta': -4, 18 'b': -4, 19 'RC': -3, 20 'rc': -3, 21 '#': -2, 22 'p': 1, 23 'pl': 1 24 }, 25 prepVersion = function (v) { 26 v = ('' + v) 27 .replace(/[_\-+]/g, '.'); 28 v = v.replace(/([^.\d]+)/g, '.$1.') 29 .replace(/\.{2,}/g, '.'); 30 return (!v.length ? [-8] : v.split('.')); 31 }; 32 33 numVersion = function (v) { 34 return !v ? 0 : (isNaN(v) ? vm[v] || -7 : parseInt(v, 10)); 35 }; 36 v1 = prepVersion(v1); 37 v2 = prepVersion(v2); 38 x = Math.max(v1.length, v2.length); 39 for (i = 0; i < x; i++) { 40 if (v1[i] == v2[i]) { 41 continue; 42 } 43 v1[i] = numVersion(v1[i]); 44 v2[i] = numVersion(v2[i]); 45 if (v1[i] < v2[i]) { 46 compare = -1; 47 break; 48 } else if (v1[i] > v2[i]) { 49 compare = 1; 50 break; 51 } 52 } 53 if (!operator) { 54 return compare; 55 } 56 57 switch (operator) { 58 case '>': 59 case 'gt': 60 return (compare > 0); 61 case '>=': 62 case 'ge': 63 return (compare >= 0); 64 case '<=': 65 case 'le': 66 return (compare <= 0); 67 case '==': 68 case '=': 69 case 'eq': 70 return (compare === 0); 71 case '<>': 72 case '!=': 73 case 'ne': 74 return (compare !== 0); 75 case '': 76 case '<': 77 case 'lt': 78 return (compare < 0); 79 default: 80 return null; 81 } 82 } 83 }, 84 85 url: { 86 make: function (url, params) { 87 url = getParam('sBaseURL') + trim(url, '/'); 88 if (params) { 89 url += '?'; 90 var iteration = 0; 91 for (var i in params) { 92 iteration++; 93 if (iteration != 1) { 94 url += '&'; 95 } 96 url += i + '=' + params[i]; 97 } 98 } 99 100 return url; 101 }, 102 103 send: function (url, relocation) { 104 url = (url.substr(0, 7) == 'http://' ? url : PF.url.make(url)); 105 if (relocation) { 106 window.location.href = url; 107 return; 108 } 109 110 history.pushState(null, null, url); 111 } 112 }, 113 114 event: { 115 trigger: function (name, param) { 116 if (typeof (PF.events[name]) != 'object') { 117 return; 118 } 119 120 $.each(PF.events[name], function (name, callback) { 121 callback(param); 122 }); 123 }, 124 125 on: function (name, callback) { 126 if (typeof (PF.events[name]) != 'object') { 127 PF.events[name] = new Array(); 128 } 129 PF.events[name].push(callback); 130 } 131 }, 132 133 popup: function (url) { 134 url = this.url.make(url); 135 var popup = $('<a href="' + url + '" class="popup"></a>'); 136 popup.prependTo('body'); 137 $Core.loadInit(); 138 popup.trigger('click'); 139 }, 140 clicks: {}, 141 add: function (cmd, cb) { 142 this.clicks[cmd] = cb; 143 return this; 144 }, 145 waitUntil: function (when, cb) { 146 if (when()) { 147 cb(); 148 } else { 149 window.setTimeout(PF.waitUntil, 1e3, when, cb); 150 } 151 }, 152 _cmds: {}, 153 cmd: function (name, cb) { 154 this._cmds[name] = cb; 155 return this; 156 }, 157 158 isMobile: /Android.+Mobile|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) 159}; 160 161(function ($) { 162 $(document).on('click', '.js_item_active_link', function () { 163 var aParams = $.getParams(this.href), 164 sParams = '', 165 ctn = $(this).closest('td,th'); 166 167 for (sVar in aParams) { 168 sParams += '&' + sVar + '=' + aParams[sVar] + ''; 169 } 170 sParams = sParams.substr(1, sParams.length); 171 172 if ($(this).hasClass('js_remove_default')) { 173 $('.js_remove_default').each(function () { 174 $('.js_item_is_active:first', ctn).addClass('hide').hide(); 175 $('.js_item_is_not_active:first', ctn).removeClass('hide').show(); 176 }); 177 } 178 179 if (aParams['active'] == '1') { 180 $('.js_item_is_not_active:first', ctn).addClass('hide').hide(); 181 $('.js_item_is_active:first', ctn).removeClass('hide').show(); 182 } else { 183 $('.js_item_is_active:first', ctn).addClass('hide').hide(); 184 $('.js_item_is_not_active:first', ctn).removeClass('hide').show(); 185 } 186 187 $Core.ajaxMessage();
188 $.ajaxCall(aParams['call'], sParams + '&global_ajax_message=true'); 189 190 return false; 191 }).on('click', '[data-cmd]', function (evt) { 192 var name = $(this).data('cmd') || 'empty'; 193 if (PF._cmds.hasOwnProperty(name)) { 194 return PF._cmds[name]($(this), evt); 195 } 196 }).on('click', '.external_link_warning', function (e) { 197 var object = $(this); 198 var href = object.attr('href'); 199 if (empty(href) || object.hasClass('play_link')) { 200 return false; 201 } 202 203 var link = '<a onclick="$Core.closeDialog(this);" href="' + href + '" style="word-break: break-word;" target="_blank">' + href + '</a>'; 204 var message = oTranslations['this_link_leads_to_an_untrusted_site_are_you_sure_you_want_to_proceed'].replace('{link}', link); 205 $Core.jsConfirm({message: message}, function () { 206 var newTab = window.open(); 207 newTab.location.href = href; 208 }); 209 return false; 210 }).on('core.moderation_changed', function () { 211 var number = $('.js_global_item_moderate:checked').length; 212 if (!number) { 213 $('#moderation_drop_down').addClass('hide'); 214 } else { 215 $('#moderation_badge').html(number); 216 $('#moderation_drop_down').removeClass('hide'); 217 } 218 }).on('change', '.js_global_item_moderate', function () { 219 $(document).trigger('core.moderation_changed'); 220 221 var t = $(this), 222 parentModerationRow = t.closest('.moderation_row').parent(); 223 224 if (t.prop('checked')) { 225 parentModerationRow.addClass('active'); 226 } else { 227 parentModerationRow.removeClass('active'); 228 } 229 }); 230 231 PF.cmd('core.moderation_action', function (btn, evt) { 232 var rel = btn.attr('rel'), 233 action = btn.attr('href').replace('#', ''), 234 holder = $('#js_global_multi_form_ids'); 235 holder.html(''); 236 237 $('.js_global_item_moderate:checked').each(function (a, b) { 238 $('<input type="hidden" name="item_moderate[]" class="js_global_item_moderate"/>').val($(b).val()).appendTo(holder); 239 }); 240 241 if (btn.attr('rel') == 'mail.mailThreadAction' && 242 btn.attr('href').replace('#', '') == 'forward') { 243 var sGlobalModeration = ''; 244 $('.js_global_item_moderate').each(function () { 245 sGlobalModeration += ',' + parseInt(btn.val()); 246 }); 247 $Core.box('mail.compose', 500, 'forward_thread_id=' + 248 $('#js_forward_thread_id').val() + '&forwards=' + 249 sGlobalModeration); 250 $Core.moderationLinkClear(); 251 } else if (btn.attr('rel') == 'mail.archive' && 252 btn.attr('href').replace('#', '') == 'export') { 253 btn.parents('form:first').submit(); 254 $Core.moderationLinkClear(); 255 } else if (btn.attr('rel') == 'mail.moderation' && 256 btn.attr('href').replace('#', '') == 'move') { 257 $Core.box('mail.listFolders', 400); 258 } else { 259 var processAction = function () { 260 $('.moderation_process').show(); 261 var params = 'action=' + btn.attr('href').replace('#', ''); 262 if (btn.data('extra')) { 263 params += btn.data('extra'); 264 } 265 $('#js_global_multi_form_holder').ajaxCall(btn.attr('rel'), params); 266 $Core.moderationLinkClear(); 267 holder.html(''); 268 }; 269 if (btn.attr('href') == '#delete') { 270 $Core.jsConfirm({message: btn.data('message') ? $Core.htmlEntityEncode(btn.data('message')) : oTranslations['are_you_sure']}, function () { 271 processAction(); 272 }, function () { 273 holder.html(''); 274 return false; 275 }); 276 } else { 277 processAction(); 278 } 279 } 280 evt.preventDefault(); 281 return false; 282 }).cmd('core.tab_item', function (btn, evt) { 283 var ul = btn.closest('ul'), 284 pane = $(btn.attr('href')); 285 286 $('li', ul).removeClass('active'); 287 btn.closest('li').addClass('active'); 288 289 $('.tab-pane', pane.closest('.tab-content')).removeClass('active'); 290 pane.addClass('active'); 291 292 evt.preventDefault(); 293 return false; 294 295 }).cmd('core.toggle_check_all', function (btn) { 296 if (btn.data('checked_all')) { 297 btn.data('checked_all', false).html(btn.data('txt1')); 298 btn.removeClass('active'); 299 $('.js_global_item_moderate').each(function () { 300 var t = $(this); 301 t.prop('checked', false); 302 t.closest('.moderation_row').parent().removeClass('active'); 303 }); 304 } else { 305 btn.data('checked_all', true).html(btn.data('txt2')); 306 btn.addClass('active'); 307 $('.js_global_item_moderate').each(function () { 308 var t = $(this); 309 t.prop('checked', true); 310 t.closest('.moderation_row').parent().addClass('active'); 311 }); 312 } 313 $(document).trigger('core.moderation_changed'); 314 }).cmd('core.toggle_placeholder', function (btn) { 315 btn.closest('.collapse-placeholder').toggleClass('open'); 316 }).cmd('core.toggle_sub_menu', function (btn, evt) { 317 btn.closest('li').find('ul').toggleClass('in'); 318 evt.preventDefault(); 319 return false;
320 }).cmd('core.table_sort', function (btn) { 321 322 var arr = btn.data('table_sort').split('|'), 323 val = arr[1]; 324 325 if (btn.hasClass('asc')) { 326 val = arr[2]; 327 } else if (arr[0] == 'desc') { 328 val = arr[2]; 329 } 330 window.location.href = window.location.pathname + $.query.set(arr[3], val) + ""; 331 }).cmd('profile.reposition_cover_save', function () { 332 $('.pages_header_cover img, .profiles_banner_bg .cover img').draggable('destroy'); 333 $('.profiles_banner').removeClass('editing'); 334 $('#save_reposition_cover').remove(); 335 $.ajaxCall(pf_reposition.module + '.repositionCoverPhoto', 'id=' + pf_reposition.id + '&position=' + pf_reposition.top); 336 }); 337})(jQuery); 338 339function getParameterByName(name) { 340 var match = RegExp('[?&]' + name + '=([^&]*)').exec(decodeURIComponent(window.location.search)); 341 return match && decodeURIComponent(match[1].replace(/\+/g, ' ')); 342} 343 344var Admin_Demo_Message = function (message) { 345 $('#admin_demo_message').remove(); 346 var t = $('<div id="admin_demo_message">' + message + '</div>'); 347 $('body').prepend(t); 348 t.animate({ 349 'margin-bottom': 0 350 }); 351 352 setTimeout(function () { 353 t.animate({ 354 'margin-bottom': '-70px' 355 }); 356 }, 3000); 357}; 358 359var $Cache = { 360 users_mention: [] 361}; 362var $oEventHistory = {}; 363var $oStaticHistory = {}; 364var $bDocumentIsLoaded = false; 365var $bIsSample = false; 366 367if (typeof window.console == 'undefined') { 368 window.console = { 369 log: function (sTxt) { 370 } 371 }; 372} 373if (typeof window.console.log == 'undefined') { 374 window.console.log = function (sTxt) { 375 }; 376} 377 378$.fn.message = function (sMessage, sType) { 379 switch (sType) { 380 case 'valid': 381 sClass = 'valid_message'; 382 break; 383 case 'error': 384 sClass = 'error_message';
385 break; 386 case 'public': 387 sClass = 'public_message'; 388 break; 389 } 390 391 this.html(this.html() + '<div class="' + sClass + '">' + sMessage + '</\div>'); 392 393 return this; 394}; 395 396$.getParams = function (sUrl) { 397 var aArgs = sUrl.split('#'); 398 var aArgsFinal = aArgs[1].split('?'); 399 var aFinal = aArgsFinal[1].split('&'); 400 401 var aUrlParams = Array(); 402 403 for (count = 0; count < aFinal.length; count++) { 404 var aArg = aFinal[count].split('='); 405 406 aUrlParams[aArg[0]] = aArg[1]; 407 } 408 409 return aUrlParams; 410}; 411 412$.ajaxProcess = function (sMessage, sSize) { 413 sMessage = (sMessage ? sMessage : getPhrase('processing')); 414 415 if (empty(sSize)) { 416 sSize = 'small'; 417 } 418 419 return '<span style="margin-left:4px; margin-right:4px; font-size:9pt; font-weight:normal;"><img src="' + eval('oJsImages.ajax_' + sSize + '') + '" class="v_middle" /> ' + (sMessage === 'no_message' ? '' : sMessage + '...') + '</span>'; 420}; 421 422$Ready(function () { 423 $('.audio_player:not(.built)').each(function () { 424 var t = $(this), 425 onPlay = t.data('onplay'); 426 t.addClass('built'); 427 var audio = document.createElement('audio'); 428 audio.setAttribute('src', t.data('src')); 429 audio.setAttribute('controls', 'controls'); 430 audio.setAttribute('preload', 'none'); 431 432 t.get(0).appendChild(audio); 433 434 if (onPlay) { 435 audio.addEventListener('play', function () { 436 $.ajax({ 437 url: onPlay 438 }); 439 }); 440 } 441 }); 442 443 $('[data-component="dropzone"]').each(function () { 444 445 if (typeof $(this).data('dropzone-id') != 'undefined') { 446 $Core.dropzone.dropzone_id = $(this).data('dropzone-id'); 447 } else { 448 $Core.dropzone.dropzone_id = 'dropzone'; 449 } 450 451 if (!$(this).prop('built')) { 452 if (typeof $Core.dropzone.instance[$Core.dropzone.dropzone_id] != 'undefined' && $Core.dropzone.instance[$Core.dropzone.dropzone_id] !== null) { 453 $Core.dropzone.instance[$Core.dropzone.dropzone_id].destroy(); 454 } 455 $Core.dropzone.init($(this)); 456 } 457 }); 458 459 PF.event.on('on_page_column_init_end', function () { 460 $('[data-component="breadcrumb"]').not('.built').each(function () { 461 $(this).addClass('built').asBreadcrumbs({ 462 onReady: function () { 463 $(this.element).css({ 464 'overflow': 'visible', 465 'max-width': '100%', 466 }); 467 } 468 }); 469 }); 470 }); 471 472 $(document).on('click touchend', '.dropzone-component .dz-preview', function () { 473 var t = $(this), 474 error = t.find('.dz-error-message'), 475 img = t.find('img'); 476 477 if (t.find('.dz-error-message span').html() === '') { 478 return; 479 } 480 error.css('opacity', 1); 481 t.addClass('active'); 482 img.css('filter', 'blur(8px)'); 483 setTimeout(function () { 484 error.css('opacity', 0); 485 img.css('filter', 'none'); 486 t.removeClass('active'); 487 }, 3000); 488 }); 489}); 490 491$Core.player = { 492 load: function (params) { 493 var t = $('#' + params.id), 494 html = ''; 495 if (t.hasClass('played')) { 496 return ''; 497 } 498 t.addClass('played'); 499 if (params.type != 'music') { 500 return ''; 501 } 502 503 var audio = document.createElement('audio'); 504 audio.setAttribute('src', params.play); 505 audio.setAttribute('controls', 'controls'); 506 audio.setAttribute('preload', 'none'); 507 508 // audio.setAttribute("autoplay","autoplay"); 509 510 t.get(0).appendChild(audio); 511 512 if (typeof (params.on_start) == 'function') { 513 audio.addEventListener('play', params.on_start); 514 } 515 } 516}; 517 518$Core.dropzone = { 519 instance: {}, 520 dropzone_id: '', 521 init: function (t) { 522 var autoProcessQueue = false, 523 uploadMultiple = true; 524 525 if (typeof t.data('auto-process-queue') !== 'undefined') { 526 autoProcessQueue = t.data('auto-process-queue'); 527 } 528 529 if (typeof t.data('upload-multiple') !== 'undefined') { 530 uploadMultiple = t.data('upload-multiple'); 531 } 532 533 if (typeof t.data('submit-button') !== 'undefined') { 534 $(document).on('click', t.data('submit-button'), function () { 535 if (typeof $Core.dropzone.instance[$Core.dropzone.dropzone_id] !== 'object') { 536 return; 537 } 538 if (t.data('submit-button') === '#activity_feed_submit' && typeof $sCurrentForm !== 'undefined' && $sCurrentForm === 'global_attachment_status') { 539 return; 540 } 541 $Core.clearActivityFeedError(); 542 $Core.dropzone.instance[$Core.dropzone.dropzone_id].processQueue(); 543 }); 544 } 545 //prevent init again 546 t.prop('built', true).addClass('dont-unbind-children'); 547 548 $Core.dropzone.instance[$Core.dropzone.dropzone_id] = new Dropzone('#' + t.prop('id'), { 549 url: t.data('url'), 550 forceConvertFile: t.data('force-convert-file') ? t.data('force-convert-file') : '', 551 hiddenInputName: t.data('hidden-input-name') ? t.data('hidden-input-name') : '', 552 parentElementId: t.data('parent-element-id') ? t.data('parent-element-id') : '', 553 keepHiddenInput: t.data('keep-hidden-input') ? t.data('keep-hidden-input') : false, 554 paramName: t.data('param-name') ? t.data('param-name') : 'file', 555 maxFiles: (t.data('max-files') !== null) ? t.data('max-files') : null, 556 uploadStyle: (t.data('upload-style') !== null) ? t.data('upload-style') : null, 557 errorMessageOutside: (t.data('error-message-outside') !== null) ? t.data('error-message-outside') == true : null, 558 maxFilesize: t.data('max-size') ? t.data('max-size') : 256, // MB 559 maxThumbnailFilesize: t.data('max-size') ? t.data('max-size') : 256, 560 acceptedFiles: t.data('accepted-files'), 561 clickable: t.data('clickable') ? t.data('clickable') : true, 562 autoProcessQueue: autoProcessQueue, 563 parallelUploads: 1000, 564 uploadMultiple: uploadMultiple, 565 previewTemplate: t.data('preview-template') ? $(t.data('preview-template')).html() : Dropzone.prototype.defaultOptions.previewTemplate, 566 dictDefaultMessage: (typeof oTranslations['dz_default_message'] !== 'undefined') ? oTranslations['dz_default_message'] : Dropzone.prototype.defaultOptions.dictDefaultMessage, 567 dictFallbackMessage: (typeof oTranslations['dz_fallback_message'] !== 'undefined') ? oTranslations['dz_fallback_message'] : Dropzone.prototype.defaultOptions.dictFallbackMessage, 568 dictFallbackText: (typeof oTranslations['dz_fallback_text'] !== 'undefined') ? oTranslations['dz_fallback_text'] : Dropzone.prototype.defaultOptions.dictFallbackText, 569 dictFileTooBig: (typeof oTranslations['dz_file_too_big'] !== 'undefined') ? oTranslations['dz_file_too_big'] : Dropzone.prototype.defaultOptions.dictFileTooBig, 570 dictInvalidFileType: (typeof oTranslations['dz_invalid_file_type'] !== 'undefined') ? oTranslations['dz_invalid_file_type'] : Dropzone.prototype.defaultOptions.dictInvalidFileType, 571 dictResponseError: (typeof oTranslations['dz_response_error'] !== 'undefined') ? oTranslations['dz_response_error'] : Dropzone.prototype.defaultOptions.dictResponseError, 572 dictCancelUpload: (typeof oTranslations['dz_cancel_upload'] !== 'undefined') ? oTranslations['dz_cancel_upload'] : Dropzone.prototype.defaultOptions.dictCancelUpload, 573 dictCancelUploadConfirmation: (typeof oTranslations['dz_cancel_upload_confirmation'] !== 'undefined') ? oTranslations['dz_cancel_upload_confirmation'] : Dropzone.prototype.defaultOptions.dictCancelUploadConfirmation, 574 dictRemoveFile: (typeof oTranslations['dz_remove_file'] !== 'undefined') ? oTranslations['dz_remove_file'] : Dropzone.prototype.defaultOptions.dictRemoveFile, 575 dictRemoveFileConfirmation: (typeof oTranslations['dz_remove_file_confirmation'] !== 'undefined') ? oTranslations['dz_remove_file_confirmation'] : Dropzone.prototype.defaultOptions.dictRemoveFileConfirmation, 576 dictMaxFilesExceeded: (typeof oTranslations['dz_max_files_exceeded'] !== 'undefined') ? oTranslations['dz_max_files_exceeded'] : Dropzone.prototype.defaultOptions.dictMaxFilesExceeded, 577 dropzoneId: $Core.dropzone.dropzone_id, 578 init: function () { 579 // on sending: append data 580 this.on('sending', function (data, xhr, formData) { 581 if (t.data('on-sending')) { 582 $Core.executeFunctionByName(t.data('on-sending'), window, data, xhr, 583 formData, t); 584 } 585 }); 586 587 // on error method 588 this.on('error', function (file, message) { 589 if (t.data('on-error')) { 590 $Core.executeFunctionByName(t.data('on-error'), window, t, file, message); 591 } 592 }); 593 594 // on success method 595 this.on('success', function (file, response) { 596 if (t.data('on-success')) { 597 $Core.executeFunctionByName(t.data('on-success'), window, t, file, response); 598 } 599 }); 600 601 this.on('removedfile', function (file) { 602 if (typeof file.item_id !== 'undefined' && file.item_id !== 0 && t.data('on-remove') !== 'undefined') {
603 $.ajaxCall(t.data('on-remove'), 'id=' + file.item_id); 604 } 605 606 if (t.data('on-removedfile')) { 607 $Core.executeFunctionByName(t.data('on-removedfile'), window, t, file); 608 } 609 if (this.options.dropzoneId == 'photo_feed' && this.files.length == 0) { 610 $bButtonSubmitActive = false; 611 $('.activity_feed_form_button .button').addClass('button_not_active'); 612 } 613 }); 614 615 this.on('thumbnail', function(file, dataUrl) { 616 if (this.options.dropzoneId == 'photo_feed' && !$Core.Photo.iTotalError) { 617 $bButtonSubmitActive = true; 618 $('.activity_feed_form_button .button').removeClass('button_not_active'); 619 } 620 }); 621 622 // on added file 623 this.on('addedfile', function (file) { 624 var th = this; 625 if (t.data('on-addedfile')) { 626 $Core.executeFunctionByName(t.data('on-addedfile'), window, t, file); 627 } 628 if ((t.data('max-files') == 1 && t.data('upload-style') == 'mini') || t.data('single-mode') == true) { 629 t.removeClass('dz-error').parent().children('.dz-error-message').remove(); 630 th.removeAllFilesExceptLast(); 631 } 632 // Create the remove button 633 var removeButton = Dropzone.createElement( 634 '<div class="dz-remove-file">' + 635 ((typeof t.data('not-show-remove-icon') !== 'undefined') ? '<span>' : '<i class="ico ico-close"></i><span style="display:none">') + 636 this.options.dictRemoveFile + '</span></div>'); 637 638 // Capture the Dropzone instance as closure. 639 var _this = this; 640 641 if (typeof t.data('not-remove-file') !== 'undefined') { 642 return; 643 } 644 // Listen to the click event 645 removeButton.addEventListener('click', function (e) { 646 // Make sure the button click doesn't submit the form: 647 e.preventDefault(); 648 e.stopPropagation(); 649 650 if (t.data('remove-button-action')) { 651 $Core.executeFunctionByName(t.data('remove-button-action'), window, t); 652 } 653 if ((t.data('max-files') == 1 && t.data('upload-style') == 'mini') || t.data('single-mode') == true) { 654 t.removeClass('dz-error').parent().find('.dz-error-message').remove(); 655 } 656 657 _this.removeFile(file); 658 659 }); 660 661 // Add the button to the file preview element. 662 if ($('[data-dz-remove-file]', file.previewElement).length) { 663 $('[data-dz-remove-file]', file.previewElement).append(removeButton); 664 } else { 665 file.previewElement.appendChild(removeButton); 666 } 667 }); 668 669 this.on('queuecomplete', function () { 670 if (t.data('on-queuecomplete')) { 671 $Core.executeFunctionByName(t.data('on-queuecomplete'), window, t); 672 } 673 }); 674 // init function 675 if (t.data('on-init')) { 676 $Core.executeFunctionByName(t.data('on-init'), window, t); 677 } 678 }, 679 }); 680 }, 681 destroy: function (id) { 682 if (typeof id === 'undefined') { 683 id = 'dropzone'; 684 } 685 var destroyInstance = this.instance[id]; 686 if (typeof destroyInstance === 'object' && typeof destroyInstance.destroy === 'function') { 687 // process customize destroy function 688 var element = $(destroyInstance.element); 689 if (typeof element !== 'undefined' && typeof element.data('on-destroy') !== 'undefined') { 690 $Core.executeFunctionByName(element.data('on-destroy'), window, destroyInstance); 691 } 692 693 destroyInstance.destroy(); 694 } 695 }, 696 setFileError: function (id, file, message) { 697 var dropzone = this.instance[id]; 698 dropzone._errorProcessing([file], message, null) 699 } 700}; 701 702$Core.executeFunctionByName = function (functionName, context /*, args */) { 703 var args = [].slice.call(arguments).splice(2), 704 namespaces = functionName.split('.'), 705 func = namespaces.pop(); 706 707 for (var i = 0; i < namespaces.length; i++) { 708 context = context[namespaces[i]]; 709 } 710
711 return context[func].apply(context, args); 712}; 713 714$Core.getCurrentFeedIds = function () { 715 var sMoreFeedIds = ''; 716 $('.js_parent_feed_entry').each(function () { 717 sMoreFeedIds += $(this).attr('id').replace('js_item_feed_', '') + ','; 718 }); 719 720 return sMoreFeedIds; 721}; 722 723$Core.processForm = function (sSelector, bReset) { 724 if (bReset === true) { 725 $(sSelector).find('.button:first').removeClass('button_off').attr('disabled', false); 726 $(sSelector).find('.table_clear_ajax').hide(); 727 } else { 728 $(sSelector).find('.button:first').addClass('button_off').attr('disabled', true); 729 $(sSelector).find('.table_clear_ajax').show(); 730 } 731}; 732 733$Core.exists = function (sSelector) { 734 return ($(sSelector).length > 0 ? true : false); 735}; 736 737$Core.searchFriends = function ($aParams) { 738 if (typeof ($Core.searchFriendsInput) == 'undefined') { 739 return; 740 } 741 $Core.searchFriendsInput.init($aParams); 742}; 743 744$Core.loadStaticFile = function ($aFiles) { 745 $Core.loadStaticFiles($aFiles); 746}; 747 748var sCustomHistoryUrl = ''; 749$Core.loadStaticFiles = function ($aFiles) { 750 if (typeof ($aFiles) == 'string') { 751 $aFiles = new Array($aFiles); 752 } 753 if (typeof ($Core.core_bundle_files) == 'undefined') { 754 $Core.core_bundle_files = []; 755 } 756 757 if (!$bDocumentIsLoaded) { 758 if (!isset($Cache['post_static_files'])) { 759 $Cache['post_static_files'] = new Array(); 760 } 761 762 $Cache['post_static_files'].push($aFiles); 763 764 return; 765 } 766 767 /* $Core.loadInit is triggered before this function finishes loading all the JS files we use this counter to control loadInit and make it wait for all JS files*/ 768 $Core.dynamic_js_files = 0; 769 770 if (typeof $aFiles == 'undefined') 771 return; 772 773 var unique = $aFiles.filter(function (itm, i) { 774 return i == $aFiles.indexOf(itm); 775 }); 776 777 $aFiles = unique; 778 779 $($aFiles).each(function ($sKey, $sFile) { 780 if (substr($sFile, -3) == '.js' && !isset($oStaticHistory[$sFile]) && ($Core.core_bundle_files.indexOf($sFile) == -1)) { 781 $Core.dynamic_js_files++; 782 } 783 }); 784 785 $($aFiles).each(function ($sKey, $sFile) { 786 if (!isset($oStaticHistory[$sFile]) && ($Core.core_bundle_files.indexOf($sFile) == -1)) { 787 $oStaticHistory[$sFile] = true; 788 if (substr($sFile, -3) == '.js') { 789 var sAjaxFile = /^(https:|http:)?\/\//.test($sFile.trim()) ? $sFile : getParam('sBaseURL').replace('/index.php', '') + $sFile; 790 $.ajax(sAjaxFile + '?v=' + getParam('sStaticVersion') + '').always(function () { 791 $Core.dynamic_js_files--; 792 }); 793 } else if (substr($sFile, -4) == '.css') { 794 var sCustomId = ''; 795 if (substr($sFile, -10) == 'custom.css') { 796 sCustomHistoryUrl = $sFile; 797 sCustomId = 'js_custom_css_loader'; 798 } 799 $('head').prepend('<link ' + sCustomId + ' rel="stylesheet" type="text/css" href="' + $sFile + '" />'); 800 } else if (/^(https:|http:)?\/\//.test($sFile.trim())) { 801 $('head').prepend('<script src="' + $sFile + '" type="text/javascript" /></script>'); 802 $Core.dynamic_js_files--; 803 } else { 804 eval($sFile); 805 } 806 } else { 807 if (substr($sFile, -10) == 'custom.css') { 808 sCustomHistoryUrl = $sFile; 809 } 810 } 811 }); 812 813 if (!empty(sCustomHistoryUrl)) { 814 $('#js_custom_css_loader').remove(); 815 $('head').append('<link id="js_custom_css_loader" rel="stylesheet" type="text/css" href="' + sCustomHistoryUrl + '" />'); 816 } 817}; 818 819var lastClassName; 820$Core.openPanel = function (obj) { 821 $('#header_search_form').hide(); 822 $('._search').show(); 823 if (lastClassName) { 824 $('#panel').removeClass(lastClassName).attr('style', ''); 825 lastClassName = null; 826 } 827 828 PF.event.trigger('openPanel', obj); 829 830 if (obj instanceof jQuery) { 831 if (obj.find('span').length) { 832 obj.find('span').html('').hide(); 833 } 834 835 if (obj.hasClass('active')) { 836 obj.removeClass('active'); 837 $('body').removeClass('panel_is_active'); 838 839 return; 840 } 841 842 if (obj.data('class')) { 843 lastClassName = obj.data('class'); 844 var panel = $('#panel').addClass(obj.data('class')); 845 panel.css({ 846 top: (obj.offset().top - $(window).scrollTop()) 847 }); 848 } 849 850 $('.notifications a.active').removeClass('active'); 851 obj.addClass('active'); 852 $('body').addClass('panel_is_active').removeClass('user_block_is_active'); 853 854 $('#panel').html('<i class="fa fa-spin fa-circle-o-notch"></i>'); 855 856 $.ajax({ 857 url: obj.data('open'), 858 contentType: 'application/json', 859 success: function (e) { 860 $('#panel').html(e.content); 861 PF.event.trigger('openPanelSuccess', e.content); 862 $('#panel').find('._block').remove(); 863 $Core.loadInit(); 864 } 865 }) 866 } 867}; 868 869$Core.ajaxLoadMorePaging = function (t, url, sendData) { 870 if (t.find('.next_page').length) { 871 t.find('.next_page').addClass('focus'); 872 $.ajax({ 873 url: url, 874 contentType: 'application/json', 875 data: sendData, 876 success: function (e) { 877 if (typeof (e.content) == 'string') { 878 var position = $(window).scrollTop(); 879 if (t.data('pagination')) { 880 var pager = t.parents('.pagination'); 881 pager.replaceWith(e.content); 882 } else { 883 //remove duplication content 884 t.parent().find('.mail_duplication_content').remove(); 885 t.before(e.content);
886 PF.event.trigger('ajaxLoadMorePagingSuccess', e.content); 887 t.remove(); 888 } 889 $(window).scrollTop(position); 890 $Core.loadInit(); 891 } else { 892 t.remove(); 893 } 894 } 895 }); 896 } 897}; 898 899var iPageLoadMore = 1; 900PF.event.on('on_page_change_start', function () { 901 iPageLoadMore = 1; 902}); 903 904$Core.pageSectionMenuShow = function (sId) { 905 $('.page_section_menu_holder').hide(); 906 $('.page_section_menu ul li').removeClass('active'); 907 $(sId).show(); 908 $('.page_section_menu ul li a').each(function () { 909 if ($(this).attr('rel') == sId.replace('#', '')) { 910 $(this).parent().addClass('active'); 911 912 return false; 913 } 914 }); 915}; 916 917$Core.moderationLinkClear = function () { 918 var aCookies = document.cookie.split(';'); 919 $(aCookies).each(function (sKey, sValue) { 920 if (sValue.match(/js_item_m/i)) { 921 var aParts = explode('=', sValue); 922 923 deleteCookie(trim(aParts[0].replace(getParam('sJsCookiePrefix'), ''))); 924 } 925 }); 926 927 $('.moderate_link').removeClass('moderate_link_active'); 928 $('#js_global_multi_form_ids').html(''); 929 $('.js_global_multi_total').html('0'); 930 $('.moderation_holder').addClass('not_active'); 931 $('.moderation_holder a.moderation_drop').removeClass('is_clicked'); 932 $('.moderation_holder ul').hide(); 933 $('.moderation_action_unselect').hide(); 934 $('.moderation_action_select').show(); 935}; 936 937$Core.moderationLinkClick = function (oObj, sType) { 938 var sView = (typeof moderationViewString !== 'undefined') ? moderationViewString : ''; 939 var sName = 'js_item_m_' + $(oObj).attr('rel') + '_' + $(oObj).attr('href').replace('#', ''); 940 var sCookieName = 'js_' + (sView != '' ? sView + '_' : '') + 'item_m_' + $(oObj).attr('rel') + '_' + $(oObj).attr('href').replace('#', ''); 941 942 if (($(oObj).hasClass('moderate_link_active') && sType != 'select') || sType == 'unselect') { 943 $(oObj).parent().removeClass('moderator_active'); 944 $(oObj).removeClass('moderate_link_active'); 945 $('#js_global_multi_form_ids').find('.' + sName).remove(); 946 deleteCookie(sCookieName); 947 } else { 948 if (!$(oObj).hasClass('moderate_link_active')) { 949 $(oObj).parent().addClass('moderator_active'); 950 $(oObj).addClass('moderate_link_active'); 951 $('#js_global_multi_form_ids').append('<div class="' + sName + '"><input class="js_global_item_moderate" type="hidden" name="item_moderate[]" value="' + $(oObj).attr('href').replace('#', '') + '" /></div>'); 952 setCookie(sCookieName, $(oObj).attr('rel') + '_' + $(oObj).attr('href').replace('#', ''), 1); 953 } 954 } 955 var iTotalItems = $('.moderate_link_active').length; 956 $('.js_global_multi_total').html(iTotalItems); 957 958 if (iTotalItems) { 959 $('.moderation_holder').removeClass('not_active'); 960 } else { 961 $('.moderation_holder').addClass('not_active'); 962 } 963 964 return false; 965}; 966 967/** 968 * Define privacy contents. 969 */ 970(function ($) { 971 var _debug = true; 972 973 $(document).on('click', '.popup', function () { 974 var caption = ($(this).data('caption')) ? $(this).data('caption') : '', 975 href = $(this).attr('href') || document.location.href; 976 977 // fix is_ajax_popup issues. 978 $(this).attr('href', href + (/\?/.test(href) ? '&is_ajax_popup=1' : '?is_ajax_popup=1')); 979 tb_show(caption, $(this).attr('href'), $(this)); 980 return false; 981 }).on('click', 'a.thickbox', function () { 982 var aExtra = $(this).html().match(/userid="([0-9a-z]?)"/i); 983 var sHref = this.href; 984 if (aExtra != null && isset(aExtra[1])) { 985 sHref += 'userid_' + aExtra[1] + '/'; 986 } 987 988 var bReturn = tb_show('', sHref, this); 989 990 return bReturn === true; 991 }); 992 993 994 // On click privacy items 995 $(document).on('click', '[data-toggle="user_privacy"]', function () { 996 var element = $(this), 997 container = element.closest('.open'), 998 input = container.find('input:first'), 999 button = container.find('[data-toggle="dropdown"]'), 1000 rel = element.attr('rel'); 1001 // processs data 1002 input.val(rel); 1003 1004 container.find('.is_active_image').removeClass('is_active_image'); 1005 element.addClass('is_active_image'); 1006 1007 var $sContent = element.html(); 1008 1009 if ($sContent.toLowerCase().indexOf('<span>') > -1) { 1010 var $aParts = explode('<span>', $sContent); 1011 if (!isset($aParts[1])) { 1012 $aParts = explode('<SPAN>', $sContent); 1013 } 1014 1015 $sContent = $aParts[0]; 1016 } 1017 1018 button.find('span.txt-label').text($sContent); 1019 1020 container.find('.fa.fa-privacy').replaceWith($('<i/>', {class: 'fa fa-user-privacy fa-user-privacy-' + rel})); 1021 }); 1022 1023 1024 // On click privacy items 1025 $(document).on('click', '[data-toggle="privacy_item"]', function () { 1026 var element = $(this), 1027 isInlinePrivacy = !!element.data('privacy-inline'), 1028 container = element.closest(isInlinePrivacy ? '.privacy_setting_div' : '.open'),
1029 input = container.find('input:first'), 1030 button = container.find('[data-toggle="dropdown"]'), 1031 rel = element.attr('rel'); 1032 // processs data 1033 input.val(rel); 1034 1035 container.find('.is_active_image').removeClass('is_active_image'); 1036 element.addClass('is_active_image'); 1037 if (isInlinePrivacy) { 1038 element.closest('li[role="presentation"]').addClass('is_active_image'); 1039 } else { 1040 var $sContent = element.text(); 1041 1042 if ($sContent.toLowerCase().indexOf('<span>') > -1) { 1043 var $aParts = explode('<span>', $sContent); 1044 if (!isset($aParts[1])) { 1045 $aParts = explode('<SPAN>', $sContent); 1046 } 1047 1048 $sContent = $aParts[0]; 1049 } 1050 1051 button.find('span.txt-label').text($sContent); 1052 1053 container.find('.fa.fa-privacy').replaceWith($('<i/>', {class: 'fa fa-privacy fa-privacy-' + rel})); 1054 } 1055 }); 1056 1057 /** 1058 * click on like toggle 1059 */ 1060 $(document).on('click', '[data-toggle="like_toggle_cmd"]', function () { 1061 var element = $(this), 1062 obj = element.data(), 1063 liked = !!obj.liked, 1064 extras = '', 1065 method = !liked ? 'like.add' : 'like.delete'; 1066 if (!$('body').hasClass('_is_guest_user')) { 1067 if (element.parents('.comment-mini-content-commands').length) { 1068 var allElement = $('.comment-mini-content-commands').find('[data-toggle="like_toggle_cmd"][data-feed_id="' + obj.feed_id + '"][data-type_id="' + obj.type_id + '"]'); 1069 1070 allElement.data('liked', !liked ? true : false); 1071 allElement.removeClass('unlike liked').addClass(liked ? 'unlike' : 'liked'); 1072 allElement.find('span').text(!liked ? obj.label2 : obj.label1); 1073 } else { 1074 element.data('liked', !liked ? true : false); 1075 element.removeClass('unlike liked').addClass(liked ? 'unlike' : 'liked'); 1076 element.find('span').text(!liked ? obj.label2 : obj.label1); 1077 } 1078 } 1079 1080 var i = element.parents('.comment_mini_content_holder:first'); 1081 if (i.hasClass('_is_app')) { 1082 extras += 'custom_app_id=' + i.data('app-id') + '&'; 1083 } 1084 1085 $.ajaxCall(method, extras + 'type_id=' + obj.type_id + '&item_id=' + obj.item_id + '&parent_id=' + obj.feed_id + '&custom_inline=' + obj.is_custom + '&table_prefix=' + obj.table_prefix, 'GET'); 1086 1087 _debug && console.log(obj); 1088 }); 1089 1090 /** 1091 * 1092 * click to view more messages 1093 */ 1094 $(document).on('click', '.mail_view_more', function () { 1095 var parent = $(this).parent(); 1096 var offset = $(parent).find('.mail_thread_holder').length; 1097 $(this).hide(); 1098 parent.find('#mail-pf-loading-message').show(); 1099 $.ajaxCall('mail.viewMoreThreadMail', 'offset=' + offset + '&thread_id=' + $(this).attr('rel'), 'GET'); 1100 return false; 1101 }); 1102 1103})(jQuery); 1104 1105var cacheShadownInfo = false; 1106var shadow = null; 1107var minHeight = null; 1108 1109$Core.resizeTextarea = function (oObj) { 1110 if (typeof oObj != "undefined") { 1111 if (cacheShadownInfo === false) { 1112 minHeight = oObj.height(); 1113 cacheShadownInfo = true; 1114 shadow = $('<div></div>').css( 1115 { 1116 position: 'absolute', 1117 top: -10000, 1118 left: -10000, 1119 width: oObj.width(), 1120 fontSize: oObj.css('fontSize'), 1121 fontFamily: oObj.css('fontFamily'), 1122 lineHeight: oObj.css('lineHeight'), 1123 resize: 'none' 1124 }).appendTo(document.body); 1125 } 1126 1127 if (typeof oObj.val() != "undefined") { 1128 var val = oObj.val().replace(/</g, '<') 1129 .replace(/>/g, '>') 1130 .replace(/&/g, '&') 1131 .replace(/\n/g, '<br/>.'); 1132 if (shadow.width() != oObj.width() || shadow.css('fontSize') != oObj.css('fontSize') || shadow.css('fontFamily') != oObj.css('fontFamily') || shadow.css('lineHeight') != oObj.css('lineHeight')) { 1133 minHeight = oObj.height(); 1134 shadow.css( 1135 { 1136 width: oObj.width(), 1137 fontSize: oObj.css('fontSize'), 1138 fontFamily: oObj.css('fontFamily'), 1139 lineHeight: oObj.css('lineHeight') 1140 }); 1141 } 1142 shadow.html(val); 1143 } 1144 1145 oObj.css('height', Math.max(shadow.height(), minHeight) + parseInt(oObj.css('padding-top')) 1146 + parseInt(parseInt(oObj.css('padding-bottom')))); 1147 } 1148}; 1149 1150$Core.getObjectPosition = function (sId) { 1151 if ($('#' + sId).length <= 0) { 1152 return false;
1153 } 1154 1155 var curleft = 0; 1156 var curtop = 0; 1157 var obj = document.getElementById(sId); 1158 if (obj.offsetParent) { 1159 do { 1160 curleft += obj.offsetLeft; 1161 curtop += obj.offsetTop; 1162 } while (obj = obj.offsetParent); 1163 } 1164 1165 return {left: curleft, top: curtop}; 1166}; 1167 1168$Core.getFriends = function (aParams) { 1169 tb_show('', $.ajaxBox('friend.search', 'height=410&width=600&input=' + aParams['input'] + '&type=' + (isset(aParams['type']) ? aParams['type'] : '') + '')); 1170}; 1171 1172$Core.browseUsers = function (aParams) { 1173 tb_show('', $.ajaxBox('user.browse', 'height=410&width=600&input=' + aParams['input'] + '')); 1174}; 1175 1176$Core.composeMessage = function (aParams) { 1177 if (aParams === undefined) { 1178 aParams = new Array(); 1179 } 1180 1181 tb_show('', $.ajaxBox('mail.compose', 'height=300&width=500' + (!isset(aParams['user_id']) ? '' : '&id=' + aParams['user_id']) + '&no_remove_box=true')); 1182}; 1183 1184$Core.addAsFriend = function (iUserId, bInSuggestionsBlock) { 1185 if (typeof oParams.sFriendshipDirection != 'undefined' && oParams.sFriendshipDirection == 'one_way_friendships') { 1186 $.ajaxCall('friend.processRequest', 'user_id=' + iUserId + '&type=add'); 1187 } else { 1188 tb_show('', $.ajaxBox('friend.request', 'width=420&user_id=' + iUserId + '' + 1189 ((typeof bInSuggestionsBlock !== 'undefined' && bInSuggestionsBlock) ? '&suggestion=1' : ''))); 1190 } 1191 return false; 1192}; 1193 1194$Core.getParams = function (sHref) { 1195 var aParams = new Array(); 1196 var aUrlParts = explode('/', sHref); 1197 var iRequest = 0; 1198 for (count in aUrlParts) { 1199 if (empty(aUrlParts[count])) { 1200 continue; 1201 } 1202 1203 aUrlParts[count] = aUrlParts[count].replace('#', ''); 1204 if (aUrlParts[count].match(/_/i)) { 1205 var aUrlParams = explode('_', aUrlParts[count]); 1206 1207 aParams[aUrlParams[0]] = aUrlParams[1]; 1208 } else { 1209 iRequest++; 1210 1211 aParams['req' + iRequest] = aUrlParts[count]; 1212 } 1213 } 1214 1215 return aParams; 1216}; 1217 1218$Core.getRequests = function (sHref, bReturnPath) { 1219 var sParams = ''; 1220 var sUrlString = ''; 1221 var sModuleName = oCore['core.section_module']; 1222 1223 switch (oCore['core.url_rewrite']) { 1224 case '1': 1225 if (getParam('sHostedVersionId') == '') { 1226 var oReq = new RegExp("" + getParam('sJsHome') + "(.*?)$", "i"); 1227 var aMatches = oReq.exec(sHref + (getParam('sHostedVersionId') == '' ? '' : getParam('sHostedVersionId') + '/')); 1228 var aParts = explode('/', aMatches[1]); 1229 1230 sUrlString = '/' + aMatches[1]; 1231 } else { 1232 var aParts = explode('/', ltrim(sHref.pathname, '/')); 1233 sUrlString = sHref.pathname; 1234 } 1235 break; 1236 case '3': 1237 if (oCore['profile.is_user_profile']) { 1238 var aProfileMatches = sHref.match(/http:\/\/(.*?)\.(.*?)/i); 1239 sModuleName = aProfileMatches[1]; 1240 } 1241 1242 var oReq = new RegExp("" + oParams['sJsHome'] + "(.*?)$", "i"); 1243 var aMatches = oReq.exec(sHref); 1244 1245 sUrlString = sModuleName + '/' + (aMatches != null && isset(aMatches[1]) ? aMatches[1] : ''); 1246 break; 1247 default: 1248 var oReq = new RegExp("(.*?)=\/(.*?)$", "i"); 1249 var aMatches = oReq.exec(sHref); 1250 if (aMatches !== null) { 1251 var aParts = explode('/', aMatches[2]); 1252 1253 sUrlString = aMatches[2]; 1254 } 1255 1256 break; 1257 } 1258 1259 if (bReturnPath === true) { 1260 return '/' + ltrim(sUrlString, '/'); 1261 } 1262 1263 return $Core.parseUrlString(sUrlString); 1264}; 1265 1266$Core.parseUrlString = function (sUrlString) { 1267 var sParams = ''; 1268 var aUrlParts = explode('/', sUrlString); 1269 var iRequest = 0; 1270 var iLoadCount = 0; 1271 1272 for (count in aUrlParts) { 1273 if (empty(aUrlParts[count]) || aUrlParts[count] == '#') { 1274 continue; 1275 } 1276 1277 iLoadCount++; 1278 1279 if (iLoadCount != 1 && aUrlParts[count].match(/_/i)) { 1280 var aUrlParams = explode('_', aUrlParts[count]); 1281 1282 sParams += '&' + aUrlParams[0] + '=' + aUrlParams[1]; 1283 } else { 1284 iRequest++; 1285 1286 sParams += '&req' + iRequest + '=' + aUrlParts[count]; 1287 } 1288 } 1289 1290 return sParams; 1291}; 1292 1293$Core.reverseUrl = function (sForm, aSkip) { 1294 var aForms = explode('&', sForm); 1295 var sUrlParam = ''; 1296 for (count in aForms) { 1297 var aFormParts = aForms[count].match(/(.*?)=(.*?)$/i); 1298 if (aFormParts !== null) { 1299 if (isset(aSkip)) { 1300 if (in_array(aFormParts[1], aSkip)) { 1301 continue; 1302 } 1303 } 1304
1305 sUrlParam += aFormParts[1] + '_' + encodeURIComponent(aFormParts[2]) + '/'; 1306 } 1307 } 1308 1309 return sUrlParam; 1310}; 1311 1312$Core.getHashParam = function (sHref) { 1313 var sParams = ''; 1314 var aParams = $.getParams(sHref); 1315 1316 for (var sKey in aParams) { 1317 sParams += '&' + sKey + '=' + aParams[sKey]; 1318 } 1319 sParams = ltrim(sParams, '&'); 1320 1321 return sParams; 1322}; 1323 1324$Core.box = function ($sRequest, $sWidth, $sParams) { 1325 tb_show('', $.ajaxBox($sRequest, 'width=' + $sWidth + ($sParams ? '&' + $sParams : ''))); 1326 1327 return false; 1328}; 1329 1330$Core.ajax = function (sCall, $oParams) { 1331 var sParams = '&' + getParam('sGlobalTokenName') + '[ajax]=true&' + getParam('sGlobalTokenName') + '[call]=' + sCall; 1332 1333 if (!sParams.match(/\[security_token\]/i)) { 1334 sParams += '&' + getParam('sGlobalTokenName') + '[security_token]=' + oCore['log.security_token']; 1335 } 1336 1337 if (isset($oParams['params'])) { 1338 if (typeof ($oParams['params']) == 'string') { 1339 sParams += $oParams['params']; 1340 } else { 1341 $.each($oParams['params'], function ($sKey, $sValue) { 1342 sParams += '&' + $sKey + '=' + encodeURIComponent($sValue) + ''; 1343 }); 1344 } 1345 } 1346 1347 $.ajax( 1348 { 1349 type: (isset($oParams['type']) ? $oParams['type'] : 'GET'), 1350 url: getParam('sJsAjax'), 1351 dataType: 'html', 1352 data: sParams, 1353 success: $oParams['success'] 1354 }); 1355}; 1356 1357$Core.popup = function (sUrl, aParams) { 1358 oDate = new Date(); 1359 iId = oDate.getTime(); 1360 var sParams = ''; 1361 var iCount = 0; 1362 var bCenter = false; 1363 for (count in aParams) { 1364 if (count == 'center') { 1365 bCenter = true; 1366 continue; 1367 } 1368 1369 iCount++; 1370 if (iCount != 1) { 1371 sParams += ','; 1372 } 1373 1374 sParams += count + '=' + aParams[count]; 1375 } 1376 1377 if (bCenter === true) { 1378 sParams += ',left=' + (($(window).width() - aParams['width']) / 2) + ',top=' + (($(window).height() - aParams['height']) / 2) + ''; 1379 } 1380 1381 window.open(sUrl, iId, sParams); 1382}; 1383 1384$Core.processing = function () { 1385 $('.ajax_processing').remove(); 1386 $('body').prepend('<div class="ajax_processing"><i class="fa fa-spin fa-circle-o-notch"></i></div>'); 1387}; 1388 1389$Core.processingEnd = function () { 1390 $('.ajax_processing').fadeOut(); 1391}; 1392 1393$Core.closeAjaxMessage = function () { 1394 if ($('#table_hover_action_holder').length > 0) { 1395 $('#table_hover_action_holder i.fa-spin').remove(); 1396 } 1397 $('#global_ajax_message').hide(); 1398} 1399 1400$Core.ajaxMessage = function () { 1401 if ($('#table_hover_action_holder').length > 0 && $('#table_hover_action_holder').is(':visible')) { 1402 $('#table_hover_action_holder i.fa-spin').remove(); 1403 $('#table_hover_action_holder').prepend('<i class="fa fa-spin fa-circle-o-notch"></i>'); 1404 } else { 1405 $('#global_ajax_message').html('<i class="fa fa-spin fa-circle-o-notch"></i>').show(); 1406 } 1407}; 1408 1409/** 1410 * Used for the accordion effect on sections with many categories 1411 */ 1412$Core.toggleCategory = function (sName, iId) { 1413 $('.' + sName).toggle(); 1414 $('#show_more_' + iId).toggle(); 1415 $('#show_less_' + iId).toggle(); 1416}; 1417 1418/** 1419 * Refine $Core.page method then export 1420 */ 1421(function ($) { 1422 var _xhr, 1423 _debug = false, 1424 _loading = false; 1425 1426 function abortRequest() { 1427 try { 1428 if (_xhr) _xhr.abort(); 1429 } catch (e) { 1430 } 1431 _xhr = null; 1432 _loading = false; 1433 } 1434 1435 function reloadPage(url) { 1436 1437 if (_loading) abortRequest(); 1438 1439 $(document).trigger('click.bs.dropdown.data-api'); 1440 PF.event.trigger('on_page_change_start'); 1441 1442 _xhr = $.ajax({ 1443 timeout: 30000, // max timeout when a page is requested (in milliseconds) 1444 url: url, 1445 contentType: 'application/json', 1446 cache: true, 1447 beforeSend: function () { 1448 NProgress.start(); 1449 _loading = true; 1450 _debug && console.log('before send'); 1451 }, 1452 complete: function (e) { 1453 if (e.responseText.substr(0, 1) != '{') { 1454 eval(e.responseText); 1455 return; 1456 } 1457 e = $.parseJSON(e.responseText); 1458 $Core.show_page(e); 1459 }, error: function () { 1460 // reload page again. 1461 window.location.href = window.location.href; 1462 } 1463 }) 1464 .fail(function () { 1465 _debug && console.log('_xhr faile'); 1466 }) 1467 .always(function () { 1468 _loading = false;
1469 _debug && console.log('_xhr always'); 1470 //Remove back on visitor page when change to other page 1471 $('#main .row_image:not(.no_change)').css('background-image', 'none'); 1472 NProgress.done(); 1473 $iReloadIteration = 0; 1474 }) 1475 .done(function (e) { 1476 setTimeout(function () { 1477 var hash = window.location.hash; 1478 if (!empty(hash) && $(hash).length) { 1479 var fix_top = 0; 1480 if ($('.admincp-fixed-menu #header').length) { 1481 fix_top = $('.admincp-fixed-menu #header').height(); 1482 } 1483 $('html, body').animate({scrollTop: ($(hash).offset().top) - fix_top}, 'fast'); 1484 } 1485 }, 200); 1486 _debug && console.log('_xhr done ', e); 1487 }); 1488 _debug && console.log('done'); 1489 } 1490 1491 // export to $Core 1492 $Core.page = reloadPage; 1493})(jQuery); 1494 1495if (!isset(page_editor_meta)) { 1496 var page_editor_meta; 1497} 1498 1499var cacheCurrentBody = null; 1500 1501$Core.refresh_counter = function (iNumberRequest, iNumberNotification, iNumberMessage) { 1502 if (iNumberRequest != -1 && $('#js_total_new_friend_requests').length > 0) { 1503 if (iNumberRequest > 0) { 1504 $("span#js_total_new_friend_requests").html(iNumberRequest).show(); 1505 } else { 1506 $("span#js_total_new_friend_requests").hide(); 1507 } 1508 } 1509 1510 if (iNumberNotification != -1 && $('#js_total_new_notifications').length > 0) { 1511 if (iNumberNotification > 0) { 1512 $("span#js_total_new_notifications").html(iNumberNotification).show(); 1513 } else { 1514 $("span#js_total_new_notifications").hide(); 1515 } 1516 } 1517 1518 if ((typeof pf_im_node_server === 'undefined' || pf_im_node_server == '') && iNumberMessage != -1 && $('#js_total_new_messages').length > 0) { 1519 if (iNumberMessage > 0) { 1520 $("span#js_total_new_messages").html(iNumberMessage).show(); 1521 } else { 1522 $("span#js_total_new_messages").hide(); 1523 } 1524 } 1525}; 1526 1527$Core.show_page = function ($aParams) { 1528 $Core.buildPageFromCache = false; 1529 if (typeof CorePageAjaxBrowsingStart == 'function') { 1530 CorePageAjaxBrowsingStart($aParams); 1531 } 1532 1533 if (isset($aParams['is_sample']) && $aParams['is_sample']) { 1534 $bIsSample = true; 1535 } 1536 1537 if (isset($aParams['phrases'])) { 1538 for (sKey in $aParams['phrases']) { 1539 if (!isset(oTranslations[sKey])) { 1540 oTranslations[sKey] = $aParams['phrases'][sKey]; 1541 } 1542 } 1543 } 1544 1545 $('.js_user_tool_tip_holder').remove(); 1546 1547 $('#js_user_profile_css').remove(); 1548 1549 1550 if (isset($aParams['profilecss'])) { 1551 $('body').append($aParams['profilecss']); 1552 } 1553 1554 if (!empty($aParams['files'])) { 1555 $Core.loadStaticFiles($aParams['files']); 1556 } 1557 1558 PF.event.trigger('before_append_content'); 1559 1560 if ($aParams['keep_body']) { 1561 PF.event.trigger('before_cache_current_body'); 1562 1563 cacheCurrentBody = { 1564 contentObject: $('#content').html(), 1565 main: $('#main').html(), 1566 mainClass: $('#main').attr('class'), 1567 scrollTop: $(window).scrollTop(), 1568 id: $('body').attr('id'), 1569 title: document.title, 1570 class: $('body').attr('class'), 1571 url: window.location.href, 1572 location_6: $('.location_6').length ? $('.location_6').html() : '' 1573 }; 1574 } else { 1575 cacheCurrentBody = null; 1576 } 1577 1578 var emptyLocation = [], 1579 main = $('#main'); 1580 1581 var blockHtml; 1582 1583 for (var location in $aParams['blocks']) { 1584 blockHtml = $aParams['blocks'][location].join(''); 1585 emptyLocation[location] = blockHtml.trim() == ''; 1586 $('._block[data-location="' + location + '"]').html(blockHtml); 1587 } 1588 1589 var emptyLeft = emptyLocation[1] && emptyLocation[9]; 1590 var emptyRight = emptyLocation[3] && emptyLocation[10]; 1591 1592 if (!main.hasClass('force') && !$bIsSample) { 1593 main[emptyLeft ? 'addClass' : 'removeClass']('empty-left'); 1594 main[emptyRight ? 'addClass' : 'removeClass']('empty-right'); 1595 } 1596 1597 PF.event.trigger('on_page_column_init_end'); 1598 1599 $('#public_message').remove(); 1600 $('._block_menu_sub').html($aParams['menuSub']); 1601 $('._block_top').html($aParams['search']); 1602 $('._block_breadcrumb').html($aParams['breadcrumb']); 1603 $('._block_h1').html($aParams['h1']); 1604 $('._block_error').html($aParams['error']); 1605 1606 // controller_e 1607 if ($('#page_editor_popup').length) { 1608 page_editor_meta = $aParams['meta']; 1609 $('#page_editor_popup').attr('href', $aParams['controller_e']); 1610 } 1611 1612 $('body').attr('id', 'page_' + $aParams['id']); 1613 $('body').attr('class', $aParams['class']); 1614 1615 if (isset($aParams['customcss'])) { 1616 var sCustomCss = ''; 1617 $('#js_global_custom_css').remove(); 1618 for (sKey in $aParams['customcss']) { 1619 sCustomCss += $aParams['customcss'][sKey]; 1620 } 1621 if (!empty(sCustomCss)) { 1622 } 1623 } 1624 1625 //rebuild main menu 1626 if ($aParams['selected_menu'] != null) { 1627 $('.site_menu a.menu_is_selected').removeClass('menu_is_selected'); 1628 var selectedMenus = $aParams['selected_menu'].split(',');
1629 selectedMenus.forEach(function(menu) { 1630 $('.site_menu li[rel="menu' + menu + '"] > a').addClass('menu_is_selected'); 1631 }) 1632 } 1633 1634 var pageTitle = ''; 1635 if ($aParams['title'] != null && typeof $aParams['title'] != 'undefined') { 1636 pageTitle = $aParams['title'].replace(new RegExp(''', 'g'), "'"); 1637 } 1638 if (self == top) { 1639 document.title = pageTitle; 1640 } else { 1641 window.parent.document.title = pageTitle; 1642 } 1643 1644 $('._block_content').html('' + $aParams['content'] + ''); 1645 1646 $Core.refresh_counter($aParams['iNumberRequest'], $aParams['iNumberNotification'], $aParams['iNumberMessage']); 1647 1648 // update profile user id 1649 oCore['profile.user_id'] = $aParams['profile_user_id']; 1650 1651 $('body').css('cursor', 'auto'); 1652 1653 // check floating addthis 1654 if ($('.addthis_block').length === 0) { 1655 $('.addthis-smartlayers').hide(); 1656 } else { 1657 $('.addthis-smartlayers').show(); 1658 } 1659 1660 var loadInit = setInterval(function () { 1661 if ($Core.dynamic_js_files <= 0) { 1662 $Core.loadInit(); 1663 PF.event.trigger('on_page_change_end'); 1664 clearInterval(loadInit); 1665 } 1666 }, 500); 1667 1668 scroll(0, 0); 1669 1670 $Behavior.loadTinymceEditor = function () { 1671 }; 1672}; 1673 1674$(document).on('pageChangeStart', function () { 1675 // remove collapse 1676 $('.collapse').each(function() { 1677 if (!$(this).hasClass('collapse-fixed') && !$(this).closest('.collapse-fixed').length) { 1678 $(this).removeClass('in'); 1679 } 1680 }); 1681}); 1682 1683 1684$Core.updatePageHistory = function () { 1685 var $sLocation = window.location.hash.replace('#!', ''); 1686 if (empty($sLocation)) { 1687 $sLocation = '/'; 1688 } 1689 1690 $oEventHistory[$sLocation] = $('#main_content_holder').html(); 1691}; 1692 1693$(window).load(function () { 1694 if ($('.nano').length) { 1695 $('.nano, .nano-content').addClass('dont-unbind'); 1696 $('.nano').css('visibility', 'visible').nanoScroller(); 1697 $('.nano, .nano-content, .nano-pane').addClass('dont-unbind'); 1698 } 1699}); 1700 1701var popped = ('state' in window.history), initialURL = location.href; 1702 1703$Core.init = function () { 1704 if ($Core.hasPushState()) { 1705 window.addEventListener("popstate", function (e) { 1706 var h = document.location.href; 1707 if ((h.substr(h.length - 1)) == '#') { 1708 return; 1709 } 1710 var initialPop = !popped && location.href == initialURL; 1711 popped = true; 1712 if (initialPop) return; 1713 // what should be control 1714 $Core.page(document.location.href); 1715 1716 }); 1717 } 1718 1719 $bDocumentIsLoaded = true; 1720 $(document).ready(function () { 1721 if ($('.nano').length) { 1722 $('.nano').css('visibility', 'visible').nanoScroller(); 1723 $('.nano, .nano-content, .nano-pane').addClass('dont-unbind'); 1724 } 1725 1726 $('*:not(.star-rating, .dont-unbind)').each(function () { 1727 if ($(this).closest('.dont-unbind-children').length == 0) { 1728 $(this).unbind(); 1729 } 1730 }); 1731 1732 if ($('ul.dropdown-menu.dont-unbind-children li a').length) { 1733 $('ul.dropdown-menu.dont-unbind-children li a').off('click'); 1734 } 1735 1736 // init click 1737 $Core.initClickAllLinks(); 1738 $Core.initAjaxPaging(); 1739 1740 $.each($Behavior, function () { 1741 try { 1742 this(this); 1743 } catch (e) { /* Catch App bug */ 1744 } 1745 1746 }); 1747 1748 $.each($Events, function () { 1749 try { 1750 this(this); 1751 } catch (e) { /* Catch App bug */ 1752 } 1753 }); 1754 1755 PF.event.trigger('on_document_ready_end'); 1756 1757 var hash = window.location.hash; 1758 if (!empty(hash) && $(hash).length) { 1759 var fix_top = 0; 1760 if ($('.admincp-fixed-menu #header').length) { 1761 fix_top = $('.admincp-fixed-menu #header').height(); 1762 } 1763 $('html, body').animate({scrollTop: ($(hash).offset().top) - fix_top}, 'fast'); 1764 } 1765 }); 1766 1767 $('script,link').each(function () { 1768 if (!empty(this.src)) { 1769 var $sVar = this.src; 1770 1771 if (this.src.indexOf('f=') !== -1) { 1772 var $aFiles = explode('f=', $sVar); 1773 var $aParts = explode('&v=', $aFiles[1]); 1774 var $aGetFiles = explode(',', $aParts[0]); 1775 $($aGetFiles).each(function ($sKey, $sFile) { 1776 if (substr($sFile, 0, 7) == 'module/') { 1777 $oStaticHistory[getParam('sJsHome') + $sFile] = true; 1778 } else { 1779 $oStaticHistory[getParam('sJsStatic') + 'jscript/' + $sFile] = true; 1780 } 1781 }); 1782 return; 1783 } 1784 } else if (!empty(this.href)) { 1785 var $sVar = this.href; 1786 1787 if (this.href.indexOf('f=') !== -1) { 1788 var $aFiles = explode('f=', $sVar); 1789 var $aParts = explode('&v=', $aFiles[1]); 1790 var $aGetFiles = explode(',', $aParts[0]); 1791 $($aGetFiles).each(function ($sKey, $sFile) { 1792 $oStaticHistory[getParam('sJsHome') + $sFile] = true; 1793 }); 1794 return; 1795 } 1796 } 1797 1798 if (!empty($sVar)) { 1799 var $aParts = explode('?', $sVar); 1800 $oStaticHistory[$aParts[0]] = true; 1801 } 1802 }); 1803 1804 if (isset($Cache['post_static_files'])) { 1805 $($Cache['post_static_files']).each(function ($sKey, $mValue) { 1806 $Core.loadStaticFiles($mValue); 1807 }); 1808 } 1809}; 1810 1811$Core.hasPushState = function () { 1812 return (typeof (window.history.pushState) == 'function' ? true : false); 1813}; 1814 1815/** 1816 * Adds a hash to the URL string, which is used to emulate a AJAX page 1817 *
1818 * @param object oObject Is the anchor object (this) 1819 */ 1820$Core.addUrlPager = function (oObject, bShort) { 1821 if ($Core.hasPushState()) { 1822 window.history.pushState('', '', oObject.href); 1823 } else { 1824 window.location = '#!' + (bShort ? oObject.href : $Core.getRequests(oObject.href, true)); 1825 } 1826}; 1827 1828$Core.reloadPage = function () { 1829 /* which is why we have these fallbacks*/ 1830 if (typeof window.location.reload == 'function') window.location.reload(); 1831 else if (typeof history != 'undefined' && history.go == 'function') history.go(0); 1832}; 1833 1834$Core.publicMessageSlideDown = function () { 1835 $('#public_message').animate({'margin-bottom': '-50px'}, 'fast', function () { 1836 $('#public_message').html('').hide(); 1837 }); 1838 $('.has-public-message').removeClass('has-public-message'); 1839}; 1840 1841$Core.jsConfirm = function (params, doYes, doNo, loadRight) { 1842 var title = (params.hasOwnProperty('title') && params.title) ? params.title : oTranslations['confirm']; 1843 var message = (params.hasOwnProperty('message') && params.message) ? params.message : oTranslations['are_you_sure']; 1844 var yesBtn = (params.hasOwnProperty('btn_yes') && params.btn_yes) ? params.btn_yes : oTranslations['yes']; 1845 var noBtn = (params.hasOwnProperty('btn_no') && params.btn_no) ? params.btn_no : oTranslations['no']; 1846 var buttons = {}; 1847 1848 if (!loadRight) { 1849 if (!(params.hasOwnProperty('no_yes') && params.no_yes)) { 1850 buttons[yesBtn] = { 1851 'class': 'btn btn-primary dont-unbind', 1852 text: yesBtn, 1853 click: function () { 1854 $(this).dialog("close"); 1855 if (doYes && (typeof doYes === "function")) { 1856 doYes(); 1857 return true; 1858 } 1859 } 1860 }; 1861 } 1862 } 1863 1864 buttons[noBtn] = { 1865 'class': 'btn btn-default dont-unbind', 1866 text: noBtn, 1867 click: function () { 1868 $(this).dialog("close"); 1869 if (doNo && (typeof doNo === "function")) { 1870 doNo(); 1871 return false; 1872 } 1873 } 1874 }; 1875 1876 if (loadRight) { 1877 if (!(params.hasOwnProperty('no_yes') && params.no_yes)) { 1878 buttons[yesBtn] = { 1879 'class': 'btn btn-primary dont-unbind', 1880 text: yesBtn, 1881 click: function () { 1882 $(this).dialog("close"); 1883 if (doYes && (typeof doYes === "function")) { 1884 doYes(); 1885 return true; 1886 } 1887 } 1888 }; 1889 } 1890 } 1891 1892 var $aAllBoxIndex = new Array(); 1893 $('.js_box_holder').each(function () { 1894 $aAllBoxIndex.push(parseInt($(this).css('z-index'))); 1895 }); 1896 1897 var wrapper = $('<div />', { 1898 'class': 'js_box_holder dont-unbind-children', 1899 id: 'js-confirm-popup-wrapper', 1900 'css': { 1901 'z-index': (parseInt(Math.max.apply(Math, $aAllBoxIndex)) + 1), 1902 }, 1903 }); 1904 1905 if ($('.js_box_holder').length > 0) { 1906 wrapper.insertAfter($('.js_box_holder').last()); 1907 } else { 1908 wrapper.prependTo('body'); 1909 } 1910 1911 let oConfirmPopup = $(document.createElement('div')); 1912 oConfirmPopup.attr({title: title, class: 'confirm'}) 1913 .html(message) 1914 .dialog({ 1915 classes: { 1916 "ui-dialog": "js_box", 1917 "ui-dialog-titlebar": "js_box_title", 1918 "ui-dialog-content": "js_box_content", 1919 "ui-dialog-titlebar-close": "js_box_close", 1920 "ui-dialog-buttonpane": "js_box_buttonpane" 1921 } 1922 , 1923 buttons: buttons 1924 , 1925 close: function (event) { 1926 $(this).closest('.js_box_holder').remove(); 1927 $('body').css('overflow', 'auto'); 1928 $Core.enableScroll(); 1929 if (typeof event === 'object' && event.hasOwnProperty('currentTarget') && $(event.currentTarget).length && ($(event.currentTarget).hasClass('js_box_close') || $(event.currentTarget).closest('.js_box_close').length)) { 1930 bUsingConfirmPopupForPreventingReload = false; 1931 } 1932 }, 1933 draggable: true, 1934 modal: true, 1935 resizable: false, 1936 minWidth: Math.min(550, $(window).width() - 20), 1937 appendTo: "#js-confirm-popup-wrapper" 1938 }); 1939 1940 if (oConfirmPopup.closest('.js_box').length && params.hasOwnProperty('is_prevent_reload')) { 1941 bUsingConfirmPopupForPreventingReload = true; 1942 } 1943 1944 $Core.disableScroll(); 1945}; 1946 1947$Core.closeDialog = function (obj) { 1948 $(obj).closest('.ui-dialog-content').dialog('close'); 1949}; 1950 1951// This function is using to prevent XSS Injection. This works like htmlentities function in PHP. 1952$Core.htmlEntityEncode = function(str) { 1953 return str.replace(/[\u00A0-\u9999<>\&]/g, function(i) {
1954 return '&#' + i.charCodeAt(0) + ';'; 1955 }); 1956} 1957 1958$Core.b64DecodeUnicode = function (str) { 1959 return decodeURIComponent(Array.prototype.map.call(atob(str), function (c) { 1960 return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2); 1961 }).join('')); 1962}; 1963 1964$Core.searchTable = function (obj, table_id, column_index) { 1965 var filter, table, tr, td, i, 1966 index = $('#' + column_index).index(); 1967 filter = obj.value.toUpperCase(); 1968 table = document.getElementById(table_id); 1969 tr = table.getElementsByTagName("tr"); 1970 // Loop through all table rows, and hide those who don't match the search query 1971 for (i = 0; i < tr.length; i++) { 1972 td = tr[i].getElementsByTagName("td")[index]; 1973 if (td) { 1974 if ($(td).text().toUpperCase().indexOf(filter) > -1) { 1975 tr[i].style.display = ""; 1976 } else { 1977 tr[i].style.display = "none"; 1978 } 1979 } 1980 } 1981}; 1982 1983$Core.sortTable = function (obj, table_id) { 1984 var table, rows, switching, i, x, y, shouldSwitch, dir, switchcount = 0; 1985 table = document.getElementById(table_id); 1986 var n = $(obj).index(); 1987 switching = true; 1988 //Set the sorting direction to ascending: 1989 dir = "asc"; 1990 /*Make a loop that will continue until 1991 no switching has been done:*/ 1992 while (switching) { 1993 //start by saying: no switching is done: 1994 switching = false; 1995 rows = table.getElementsByTagName("tr"); 1996 /*Loop through all table rows (except the 1997 first, which contains table headers):*/ 1998 for (i = 1; i < (rows.length - 1); i++) { 1999 //start by saying there should be no switching: 2000 shouldSwitch = false; 2001 /*Get the two elements you want to compare, 2002 one from current row and one from the next:*/ 2003 x = rows[i].getElementsByTagName("td")[n]; 2004 y = rows[i + 1].getElementsByTagName("td")[n]; 2005 /*check if the two rows should switch place, 2006 based on the direction, asc or desc:*/ 2007 var xhtml = $(x).text().toLowerCase().trim(), 2008 yhtml = $(y).text().toLowerCase().trim(); 2009 if (dir == "asc") { 2010 if (xhtml > yhtml) { 2011 //if so, mark as a switch and break the loop: 2012 shouldSwitch = true; 2013 break; 2014 } 2015 } else if (dir == "desc") { 2016 if (xhtml < yhtml) { 2017 //if so, mark as a switch and break the loop: 2018 shouldSwitch = true; 2019 break; 2020 } 2021 } 2022 } 2023 if (shouldSwitch) { 2024 /*If a switch has been marked, make the switch 2025 and mark that a switch has been done:*/ 2026 rows[i].parentNode.insertBefore(rows[i + 1], rows[i]); 2027 switching = true; 2028 //Each time a switch is done, increase this count by 1: 2029 switchcount++; 2030 } else { 2031 /*If no switching has been done AND the direction is "asc", 2032 set the direction to "desc" and run the while loop again.*/ 2033 if (switchcount == 0 && dir == "asc") { 2034 dir = "desc"; 2035 switching = true; 2036 } 2037 } 2038 } 2039}; 2040 2041$Core.uploadForm = { 2042 toggleForm: function (obj) { 2043 $(obj).closest('.js_upload_form_wrapper').toggleClass('show-current'); 2044 }, 2045 2046 deleteImage: function (obj, type, field) { 2047 $Core.uploadForm.toggleForm(obj); 2048 var wrapper = $(obj).closest('.js_upload_form_wrapper'); 2049 if (wrapper.length > 0) { 2050 wrapper.find('.js_upload_form_current').remove(); 2051 wrapper.find('.js_upload_form .js_hide_upload_form').remove(); 2052 wrapper.append($('<input />', { 2053 type: "hidden", 2054 name: "val[" + field + "]", 2055 value: 1, 2056 id: "js_upload_remove_file_" + type 2057 })); 2058 } 2059 }, 2060 2061 dismissUpload: function (obj, type) { 2062 $Core.uploadForm.toggleForm(obj); 2063 $Core.dropzone.instance[type].removeAllFiles(); 2064 }, 2065 2066 onSuccessUpload: function (ele, file, response) { 2067 response = JSON.parse(response); 2068 2069 2070 // process error 2071 if (typeof response.error !== 'undefined' && typeof response.type !== 'undefined') { 2072 return $Core.dropzone.setFileError(response.type, file, response.error); 2073 } 2074 2075 // upload successfully 2076 if (typeof response.file !== 'undefined' && typeof response.type !== 'undefined' && typeof response.field_name !== 'undefined') { 2077 var input = ele.find('.dz-preview #js_upload_form_file_' + response.type); 2078 file.item_id = response.file; 2079 if (input.length > 0) { 2080 input.val(response.file); 2081 input.attr('name', 'val[' + response.field_name + ']'); 2082 } 2083 } 2084 } 2085}; 2086 2087$Core.slideAlert = function (sParent, sMessage, sType, sExtraClass) { 2088 //support display utf-8 2089 var tempDiv = document.createElement('div'); 2090 tempDiv.innerHTML = sMessage; 2091 sMessage = tempDiv.innerText;
2092 var sId = 'pf_alert_' + sType + '_' + Math.floor((Math.random() * 1000) + 1); 2093 var ele = $('<div />', { 2094 'class': 'alert alert-' + sType + ' slide-down-alert alert-dismissable fade in ' + sExtraClass, 2095 id: sId, 2096 text: sMessage 2097 }).css('display', 'none').append($('<a href="javascript:void(0);" class="close" onclick="$(this).parent().slideUp();event.stopPropagation();" aria-label="' + oTranslations['close'] + '">×</a>')); 2098 var parent = $(sParent); 2099 if (parent.length > 0) { 2100 if (parent.find('.pf-alert-wrapper').length == 0) { 2101 var wrapper = $('<div />', {'class': 'pf-alert-wrapper ' + sExtraClass}).appendTo(sParent); 2102 } else { 2103 var wrapper = parent.find('.pf-alert-wrapper'); 2104 } 2105 ele.prependTo(wrapper).slideDown(); 2106 setTimeout(function () { 2107 $('#' + sId).slideUp() 2108 }, 1500); 2109 } 2110}; 2111 2112$Core.submitFriendRequest = function () { 2113 $('#container_submit_friend_request').fadeOut('fast', function () { 2114 $('#friend_request_alert').fadeIn(); 2115 setTimeout(function () { 2116 tb_remove(); 2117 }, 3000) 2118 }); 2119}; 2120 2121$Core.onSubmitForm = function (form, isAdmin) { 2122 var ele = $(form).find('input[type=submit], button[type=submit]'); 2123 ele.addClass('disabled'); 2124 if (typeof isAdmin != 'undefined' && isAdmin) { 2125 ele.prop('disabled', true); 2126 } 2127}; 2128 2129/* 2130 * Search item button 2131 */ 2132(function ($) { 2133 PF.cmd('core.search_items', function (btn, evt) { 2134 btn.closest('form').submit(); 2135 }); 2136})(jQuery); 2137 2138Core_drag = 2139 { 2140 init: function (aParams) { 2141 $(document).ready(function () { 2142 $(aParams['table']).tableDnD( 2143 { 2144 dragHandle: 'drag_handle', 2145 onDragClass: 'drag_my_class', 2146 onDrop: function (oTable, oRow) { 2147 iCnt = 0; 2148 sParams = ''; 2149 $('.drag_handle input').each(function () { 2150 iCnt++; 2151 2152 sParams += '&' + $(this).attr('name') + '=' + iCnt; 2153 }); 2154 2155 $('.drag_handle_input').each(function () { 2156 sParams += '&' + $(this).attr('name') + '=' + $(this).attr('value'); 2157 }); 2158 2159 if (aParams['ajax'].substr(0, 7) == 'http://' || aParams['ajax'].substr(0, 8) == 'https://') { 2160 $Core.processing(); 2161 $.ajax({ 2162 url: aParams['ajax'], 2163 type: 'POST', 2164 data: sParams, 2165 success: function (e) { 2166 $('.ajax_processing').remove(); 2167 if (typeof e == 'object' && typeof e.run == 'string') { 2168 eval(e.run); 2169 } 2170 } 2171 }); 2172 } else { 2173 $Core.ajaxMessage(); 2174 $.ajaxCall(aParams['ajax'], sParams + '&global_ajax_message=true'); 2175 } 2176 } 2177 }); 2178 2179 $(aParams['table'] + " tr.checkRow").hover( 2180 function () { 2181 $(this.cells[0]).addClass('drag_show_handle'); 2182 }, 2183 function () { 2184 $(this.cells[0]).removeClass('drag_show_handle'); 2185 } 2186 ); 2187 }); 2188 } 2189 }; 2190 2191$(document).on('focus', '.activity-feed-status-form', function () { 2192 $(this).addClass('activity-feed-status-form-active'); 2193}); 2194 2195$(document).on('blur', '.activity-feed-status-form', function () { 2196 $(this).removeClass('activity-feed-status-form-active'); 2197}); 2198 2199$Core.searchFriend = { 2200 sPrivacyInputName: null, 2201 sSearchByValue: null, 2202 sFriendModuleId: null, 2203 sFriendItemId: null, 2204 inputSelector: null, 2205 initialized: false, 2206 searching: false, 2207 searchAction: null, 2208 2209 init: function (inputSelector, params) { 2210 this.sPrivacyInputName = params.sPrivacyInputName; 2211 this.sSearchByValue = params.sSearchByValue; 2212 this.sFriendModuleId = params.sFriendModuleId; 2213 this.sFriendItemId = params.sFriendItemId; 2214 this.inputSelector = inputSelector; 2215 this.itemWidth = 0; 2216 this.maxItemsInARow = 0; 2217 this.itemCount = 0; 2218 this.showOverflow = false; 2219 2220 if (!this.initialized) { 2221 // init input 2222 $(document).on('focus', inputSelector, function () { 2223 if (this.value == $Core.searchFriend.sSearchByValue) { 2224 this.value = ''; 2225 $(this).removeClass('default_value'); 2226 } 2227 }).on('blur', inputSelector, function () { 2228 if (this.value == '') { 2229 this.value = $Core.searchFriend.sSearchByValue; 2230 $(this).addClass('default_value'); 2231 } 2232 }).on('click', '#selected_friends_list li', function () { 2233 if (typeof $(this).data('id') === 'undefined') { 2234 return; 2235 } 2236 $('#js_friends_checkbox_' + $(this).data('id')).trigger('click'); 2237 2238 // pop 1 member in overflow list 2239 var overflow = $('li[data-overflow="true"]'); 2240 if (overflow.length) { 2241 $(overflow[0]).removeClass('hide').attr('data-overflow', false); 2242 } else { 2243 $('#selected_friend_view_more').addClass('hide'); 2244 } 2245 }).on('click', '#deselect_all_friends', function () { 2246 let _this = $(this), 2247 selectFriendList = $('#selected_friends_list'); 2248 $('#js_selected_friends .js_cached_friend_name').each(function() { 2249 let userId = $(this).find('input[type="hidden"]:first').val(); 2250 if (parseInt(userId) > 0) { 2251 let itemCheckboxUser = $('#js_friends_checkbox_' + userId); 2252 if (itemCheckboxUser.length) { 2253 itemCheckboxUser.trigger('click'); 2254 } else { 2255 if (function_exists('plugin_removeFriendToSelectList')) { 2256 plugin_removeFriendToSelectList(userId); 2257 }
2258 if ($('#js_friend_input_' + userId)) { 2259 $('#js_friend_input_' + userId).remove(); 2260 } 2261 $('[data-id=' + userId + ']', $('#selected_friends_list')).remove(); 2262 $(this).remove(); 2263 var selectedCount = $('li', selectFriendList).length - 2; 2264 $('span', _this).html(selectedCount); 2265 selectedCount === 0 && _this.addClass('hide'); 2266 $('li', selectFriendList).length === 1 && _this.addClass('hide'); 2267 $Core.searchFriend.itemCount--; 2268 } 2269 } 2270 }); 2271 $(this).addClass('hide'); 2272 $Core.searchFriend.showOverflow = false; 2273 }).on('click', '#selected_friend_view_more', function () { 2274 $Core.searchFriend.showOverflow = true; 2275 $(this).addClass('hide'); 2276 $('li[data-overflow="true"]', $('#selected_friends_list')).toggleClass('hide'); 2277 }); 2278 this.initialized = true; 2279 PF.event.trigger('on_search_friend_init_completed'); 2280 } 2281 }, 2282 2283 search: function () { 2284 if ($Core.searchFriend.searching) { 2285 return; 2286 } 2287 2288 clearTimeout($Core.searchFriend.searchAction); 2289 $Core.searchFriend.searchAction = setTimeout(function () { 2290 var paramsArray = [ 2291 'friend_module_id=' + $Core.searchFriend.sFriendModuleId, 2292 'friend_item_id=' + $Core.searchFriend.sFriendItemId, 2293 'find=' + $($Core.searchFriend.inputSelector).val(), 2294 'input=' + $Core.searchFriend.sPrivacyInputName, 2295 ]; 2296 $Core.searchFriend.searching = true; 2297 $Core.searchFriend.showLoader(); 2298 $.ajaxCall('friend.searchAjax', paramsArray.join('&')); 2299 }, 500); 2300 }, 2301 2302 selectFriend: function (ele) { 2303 var th = $(ele), 2304 friendList = $('#selected_friends_list'); 2305 2306 if ($('#js_friends_checkbox_' + th.data('id')).prop('checked')) { 2307 $('#js_friends_checkbox_' + th.data('id')).prop('checked', false); 2308 th.removeClass('active'); 2309 $('.item-outer', th).removeClass('active'); 2310 } else { 2311 $('#js_friends_checkbox_' + th.data('id')).prop('checked', true); 2312 th.addClass('active'); 2313 $('.item-outer', th).addClass('active'); 2314 } 2315 2316 if (th.data('can-message')) { 2317 this.addFriendToSelectList($('#js_friends_checkbox_' + th.data('id')), 2318 th.data('id'), $('#js_friends_checkbox_' + th.data('id')).prop('checked')); 2319 } 2320 2321 if (this.itemWidth == 0 && $('li', friendList).length > 2) { 2322 var lastLi = $('li', friendList).last(); 2323 this.itemWidth = lastLi.width() + parseInt(lastLi.css('margin-right')); 2324 this.maxItemsInARow = parseInt(friendList.width() / this.itemWidth) - 1; 2325 } 2326 }, 2327 2328 addFriendToSelectList: function (oObject, sId, bForce) { 2329 if (oObject.checked || bForce) { 2330 iCnt = 0; 2331 $('.js_cached_friend_name').each(function () { 2332 iCnt++; 2333 }); 2334 2335 if (function_exists('plugin_addFriendToSelectList')) { 2336 plugin_addFriendToSelectList(sId); 2337 } 2338 2339 // add to selected list 2340 var friendItem = $(oObject).closest('article'), 2341 selectedFriend = $('#selected_friend_template').clone(), 2342 selectedFriendList = $('#selected_friends_list'), 2343 notOverflow = this.showOverflow || this.maxItemsInARow == 0 || this.itemCount < this.maxItemsInARow, 2344 viewMore = $('#selected_friend_view_more'); 2345 2346 $('#js_selected_friends').append('<div class="js_cached_friend_name row1 js_cached_friend_id_' + 2347 sId + '' + (iCnt ? '' : ' row_first') + 2348 '"><span style="display:none;">' + sId + 2349 '</span><input type="hidden" name="val[' + this.sPrivacyInputName + 2350 '][]" value="' + sId + 2351 '" /><a role="button" onclick="$(\'#search-friend-' + sId + '\').trigger(\'click\')"></a> ' + 2352 $('.item-user', friendItem).html() + '</div>'); 2353 2354 // clone image 2355 $('.selected-user-item,.img-wrapper', selectedFriend).prepend($('.user_rows_image', friendItem).html()); 2356 // remove attribute id 2357 selectedFriend.removeAttr('id'); 2358 selectedFriend.attr('data-id', sId); 2359 if (notOverflow) { 2360 selectedFriend.removeClass('hide'); 2361 } else { 2362 selectedFriend.attr('data-overflow', true); 2363 } 2364 2365 $('#selected_friends_list').append(selectedFriend); 2366 if (!notOverflow) { 2367 $('li', selectedFriendList).last().after(viewMore); 2368 viewMore.removeClass('hide'); 2369 } 2370 2371 $('#deselect_all_friends').removeClass('hide'); 2372 $('#deselect_all_friends span').html($('#selected_friends_list li').length - 2); 2373 this.itemCount++; 2374 } else { 2375 if (function_exists('plugin_removeFriendToSelectList')) { 2376 plugin_removeFriendToSelectList(sId); 2377 } 2378 2379 $('.js_cached_friend_id_' + sId).remove(); 2380 $('#js_friend_input_' + sId).remove(); 2381 $('[data-id=' + sId + ']', $('#selected_friends_list')).remove(); 2382 var selectedCount = $('#selected_friends_list li').length - 2; 2383 $('#deselect_all_friends span').html(selectedCount); 2384 selectedCount === 0 && $('#deselect_all_friends').addClass('hide'); 2385 $('#selected_friends_list li').length === 1 && $('#deselect_all_friends').addClass('hide'); 2386 this.itemCount--; 2387 } 2388 }, 2389 2390 updateFriendsList: function () { 2391 $Core.searchFriend.searching = false;
2392 this.updateCheckBoxes(); 2393 if (typeof $.mCustomScrollbar === 'function') { 2394 $(".friend-search-invite-container", '#js_friend_search_content').mCustomScrollbar({ 2395 theme: "minimal-dark", 2396 }).addClass('dont-unbind-children'); 2397 } 2398 }, 2399 2400 removeFromSelectList: function (sId) { 2401 $('.js_cached_friend_id_' + sId + '').remove(); 2402 $('#js_friends_checkbox_' + sId).attr('checked', false); 2403 $('#js_friend_input_' + sId).remove(); 2404 $('.js_cached_friend_id_' + sId).remove(); 2405 this.itemCount--; 2406 2407 return false; 2408 }, 2409 2410 cancelFriendSelection: function () { 2411 if (function_exists('plugin_cancelFriendSelection')) { 2412 plugin_cancelFriendSelection(); 2413 } 2414 2415 $('#js_selected_friends').html(''); 2416 $Core.loadInit(); 2417 tb_remove(); 2418 }, 2419 2420 updateCheckBoxes: function () { 2421 $('.js_cached_friend_name').each(function () { 2422 $('#js_friends_checkbox_' + $(this).find('span').html()).prop('checked', true).closest('article').addClass('active'); 2423 }); 2424 }, 2425 2426 showLoader: function () { 2427 $('#js_friend_search_content').html($.ajaxProcess(oTranslations['loading'], 'large')); 2428 }, 2429 2430 checkForEnter: function (event) { 2431 if ($Core.searchFriend.searching) { 2432 return; 2433 } 2434 2435 clearTimeout($Core.searchFriend.searchAction); 2436 $Core.searchFriend.searchAction = setTimeout(function () { 2437 var paramsArray = [ 2438 'friend_module_id=' + $Core.searchFriend.sFriendModuleId, 2439 'friend_item_id=' + $Core.searchFriend.sFriendItemId, 2440 'find=' + $($Core.searchFriend.inputSelector).val(), 2441 'input=' + $Core.searchFriend.sPrivacyInputName, 2442 ]; 2443 $Core.searchFriend.searching = true; 2444 $Core.searchFriend.showLoader(); 2445 $.ajaxCall('friend.searchAjax', paramsArray.join('&')); 2446 }, 500); 2447 }, 2448 2449 selectSearchFriends: function () { 2450 if (function_exists('plugin_selectSearchFriends')) { 2451 plugin_selectSearchFriends(); 2452 } else { 2453 $Core.loadInit(); 2454 tb_remove(); 2455 } 2456 }, 2457 2458 cancelSearchFriends: function () { 2459 if (function_exists('plugin_cancelSearchFriends')) { 2460 plugin_cancelSearchFriends(); 2461 } else { 2462 this.cancelFriendSelection(); 2463 } 2464 }, 2465}; 2466 2467$Core.tokenfield = { 2468 isAjax: false, 2469 2470 init: function (ele) { 2471 var params = { 2472 delimiter: [','], 2473 }; 2474 2475 // search friends 2476 if (ele.data('search') === 'friends') { 2477 params.autocomplete = { 2478 source: $Cache.friends.map(function (a) { 2479 return { 2480 id: a.user_id, 2481 value: a.user_id, 2482 label: a.full_name, 2483 user_image: a.user_image, 2484 }; 2485 }), 2486 delay: 100, 2487 }; 2488 params.showAutocompleteOnFocus = true; 2489 params.allowEditing = false; 2490 } 2491 2492 if (ele.data('allow-editing') == false) { 2493 params.allowEditing = false; 2494 } 2495 2496 if (typeof ele.data('type') !== 'undefined') { 2497 params.inputType = ele.data('type'); 2498 } 2499 2500 ele.addClass('built') 2501 .on('tokenfield:removetoken', function (event) { 2502 if (ele.data('multiple-input') == true) { 2503 $('#tokenfield-' + ele.data('input-name') + '-' + event.attrs.value).remove(); 2504 } 2505 }).on('tokenfield:createtoken', function (event) { 2506 var duplicated = false; 2507 if (ele.data('check-duplicate') == true) { 2508 var existingTokens = ele.tokenfield('getTokens'); 2509 $.each(existingTokens, function (index, token) { 2510 if (typeof token.value === 'undefined' || 2511 typeof event.attrs.value === 'undefined' || 2512 token.value === event.attrs.value) { 2513 event.preventDefault(); 2514 duplicated = true; 2515 } 2516 }); 2517 } 2518 2519 if (ele.data('multiple-input') == true && !duplicated) { 2520 var inputId = 'tokenfield-' + ele.data('input-name') + '-' + event.attrs.value; 2521 if ($('#' + inputId).length) { 2522 return; 2523 } 2524 2525 $('<input type="hidden" name="' + ele.data('input-name') + 2526 '[]" value="' + event.attrs.value + '" id="' + inputId + '">').insertBefore(ele); 2527 } 2528 }).on('tokenfield:initialize', function () { 2529 // don't unbind all children 2530 ele.closest('.tokenfield').addClass('dont-unbind-children'); 2531 if (typeof ele.data('bs.tokenfield').$input.autocomplete('instance') === 2532 'undefined') { 2533 return; 2534 } 2535 2536 var input = ele.data('bs.tokenfield').$input; 2537 // custom render autocomplete result list 2538 input.autocomplete('instance')._renderItem = function (ul, item) { 2539 var userImage = item.user_image; 2540 if (item.user_image.indexOf('no_image_user') === -1) { 2541 userImage = '<img src=' + item.user_image + '>'; 2542 } 2543 2544 return $('<li class="search-friend-item"></li>').data('item.autocomplete', item).append('<div class="friend-image">' + userImage + '</div>').append('<span class="friend-name">' + item.label + '</span>').appendTo(ul); 2545 }; 2546 // add class to ul 2547 input.autocomplete('widget').addClass('search-friend-list'); 2548 }).tokenfield(params); 2549 2550 if (ele.data('type') === 'email') { 2551 ele.on('tokenfield:createdtoken', function (e) { 2552 // Über-simplistic e-mail validation 2553 var re = /\S+@\S+\.\S+/;
2554 var valid = re.test(e.attrs.value); 2555 if (!valid) { 2556 $(e.relatedTarget).addClass('invalid'); 2557 } 2558 }); 2559 } 2560 // init values 2561 if (typeof $Core.tokenfieldValues !== 'undefined' && typeof $Core.tokenfieldValues[ele.data('input-name')] !== 'undefined') { 2562 ele.tokenfield('setTokens', $Core.tokenfieldValues[ele.data('input-name')]); 2563 } 2564 2565 ele.tokenfield('update'); 2566 }, 2567 2568 globalInit: function () { 2569 $('[data-component="tokenfield"]').not('.built').each(function () { 2570 var th = $(this); 2571 2572 if (th.data('search') === 'friends' && typeof $Cache.friends === 'undefined') { 2573 $Core.searchFriendsInput.buildFriends(); 2574 PF.waitUntil(function () { 2575 return (typeof $Cache.friends !== 'undefined'); 2576 }, function () { 2577 $Core.tokenfield.init(th); 2578 }); 2579 2580 return; 2581 } 2582 2583 $Core.tokenfield.init(th); 2584 }); 2585 } 2586}; 2587 2588PF.event.on('on_page_column_init_end', function () { 2589 $Core.tokenfield.isAjax = true; 2590 $Core.tokenfield.globalInit(); 2591}); 2592 2593$Core.ProfilePhoto = { 2594 hadPhoto: false, 2595 firstZoom: true, 2596 firstOffset: true, 2597 modified: false, 2598 currentRotation: 0, 2599 2600 cropProfilePhoto: function (profileImage, serverId) { 2601 $Core.customizeImageContainer = function (bgContainer) { 2602 bgContainer.append('<img class="cropit-preview-image-bg" src="' + getParam('sJsHome') + 'module/user/static/image/crop-area.png' + '">'); 2603 2604 return bgContainer; 2605 }; 2606 2607 // use ajax to get image 2608 if (typeof serverId !== 'undefined' && serverId != 0) { 2609 // add loading icon 2610 $('form', '#profile_crop_me').addClass('hide'); 2611 $('div.fa-4x', '#profile_crop_me').removeClass('hide'); 2612 $.ajaxCall('profile.getTempProfileImage', 'profile_image=' + profileImage); 2613 return false; 2614 } 2615 2616 $('form', '#profile_crop_me').removeClass('hide').addClass('dont-unbind-children'); 2617 $('div.fa-4x', '#profile_crop_me').addClass('hide'); 2618 $('.cropit-preview-background-container', '.image-editor').remove(); 2619 $('.cropit-preview-image-container', '.image-editor').remove(); 2620 $('.image-editor').cropit('destroy'); 2621 $('.image-editor').cropit({ 2622 imageState: { 2623 src: profileImage, 2624 }, 2625 smallImage: 'allow', 2626 maxZoom: 2, 2627 imageBackground: true, 2628 allowDragNDrop: false, 2629 onZoomChange: function () { 2630 if (!$Core.ProfilePhoto.firstZoom) { 2631 $Core.ProfilePhoto.modified = true; 2632 } else { 2633 $Core.ProfilePhoto.firstZoom = false;
2634 } 2635 }, 2636 onOffsetChange: function () { 2637 if (!$Core.ProfilePhoto.firstOffset) { 2638 $Core.ProfilePhoto.modified = true; 2639 } else { 2640 $Core.ProfilePhoto.firstOffset = false; 2641 } 2642 } 2643 }); 2644 2645 $('.export').click(function () { 2646 var imageData = $('.image-editor').cropit('export'); 2647 window.open(imageData); 2648 }); 2649 }, 2650 2651 onSuccessUpload: function (ele, file, response) { 2652 if (typeof response === 'string') { 2653 var data = JSON.parse(response), 2654 profileCropMeContainer = $('#profile_crop_me'); 2655 profileCropMeContainer.removeClass('profile-image-uploading profile-image-error'); 2656 this.cropProfilePhoto(data.imagePath); 2657 if (data.hasOwnProperty('pendingPhoto')) { 2658 if (data.hasOwnProperty('warningMessage')) { 2659 window.parent.sCustomMessageString = data['warningMessage']; 2660 tb_show(data.hasOwnProperty('warningTitle') ? data['warningTitle'] : '', $.ajaxBox('core.message', 'height=150&width=300')); 2661 } 2662 } else if (data.hasOwnProperty('tempFileId')) { 2663 if (profileCropMeContainer.find('.js_temp_file_id').length) { 2664 profileCropMeContainer.find('.js_temp_file_id').val(data['tempFileId']); 2665 } else { 2666 $('<input/>', { 2667 type: 'hidden', 2668 value: data['tempFileId'], 2669 class: 'js_temp_file_id', 2670 name: 'val[temp_file]', 2671 }).prependTo(profileCropMeContainer.find('form:first')); 2672 } 2673 } 2674 if ($('.profile-image .profile_image_holder form label').length) { 2675 $('.profile-image .profile_image_holder form label').attr('onclick', '$Core.ProfilePhoto.update(\'' + data.imagePath + '\', ' + data.serverId +')'); 2676 } 2677 } else if (typeof response.run !== 'undefined') { 2678 eval(response.run); 2679 } 2680 this.enableCropFormButtons(); 2681 }, 2682 2683 onAddedFile: function () { 2684 $('#profile_crop_me').addClass('profile-image-uploading').removeClass('profile-image-error'); 2685 this.showHiddenBox(); 2686 this.disableCropFormButtons(); 2687 }, 2688 2689 onError: function () { 2690 $('#profile_crop_me').removeClass('profile-image-uploading'); 2691 $('#profile_crop_me').addClass('profile-image-error'); 2692 this.enableCropFormButtons(); 2693 }, 2694 2695 update: function (photo, serverId) { 2696 if (photo === false) { 2697 $('#profile_crop_me').removeClass('profile-image-error'); 2698 $('.dropzone-button', '#user-dropzone').trigger('click'); 2699 } else { 2700 this.showHiddenBox(); 2701 this.cropProfilePhoto(photo, serverId); 2702 } 2703 }, 2704 2705 showHiddenBox: function () { 2706 $Core.ProfilePhoto.modified = false; 2707 $Core.ProfilePhoto.firstZoom = $Core.ProfilePhoto.firstOffset = true; 2708 $('#profile_photo_form').removeClass('hidden'); 2709 if (typeof $Core.disableScroll !== 'undefined' && (typeof hidden === 'undefined' || !hidden)) { 2710 $Core.disableScroll(); 2711 } 2712 }, 2713 2714 closeHiddenBox: function (ele) { 2715 $('#profile_photo_form').addClass('hidden'); 2716 if (typeof $Core.enableScroll !== 'undefined' && (typeof hidden === 'undefined' || !hidden)) { 2717 $Core.enableScroll(); 2718 } 2719 }, 2720 2721 save: function () { 2722 let _form = $('#update-profile-image-form'); 2723 if (!_form.find('.js_rotation_degree').length) { 2724 _form.append('<input class="js_rotation_degree" type="hidden" name="val[rotation]" value="' + this.currentRotation + '"/>'); 2725 } else { 2726 $('.js_rotation_degree', _form).val(this.currentRotation); 2727 } 2728 if ($('.image-editor').length) { 2729 if (!_form.find('.js_zoom').length) { 2730 _form.append('<input class="js_zoom" type="hidden" name="val[zoom]" value="' + $('.image-editor').cropit('zoom') + '"/>'); 2731 } else { 2732 $('.js_zoom', _form).val($('.image-editor').cropit('zoom')); 2733 } 2734 2735 let cropCoordinate = $('.image-editor').cropit('offset'), 2736 previewSize = $('.image-editor').cropit('previewSize'); 2737 if (typeof cropCoordinate === "object" && cropCoordinate) { 2738 if (!_form.find('.js_crop_coordinate').length) { 2739 _form.append('<input class="js_crop_coordinate offset_x" type="hidden" name="val[crop_coordinate][x]" value="' + cropCoordinate.x + '"/>'); 2740 _form.append('<input class="js_crop_coordinate offset_y" type="hidden" name="val[crop_coordinate][y]" value="' + cropCoordinate.y + '"/>'); 2741 } else { 2742 $('.js_crop_coordinate.offset_x', _form).val(cropCoordinate.x); 2743 $('.js_crop_coordinate.offset_y', _form).val(cropCoordinate.y); 2744 } 2745 } 2746 2747 if (typeof previewSize === "object" && previewSize) { 2748 if (!_form.find('.js_preview_size').length) { 2749 _form.append('<input class="js_preview_size width" type="hidden" name="val[preview_size][width]" value="' + previewSize.width + '"/>'); 2750 _form.append('<input class="js_preview_size height" type="hidden" name="val[preview_size][height]" value="' + previewSize.height + '"/>'); 2751 } else { 2752 $('.js_preview_size.width', _form).val(previewSize.width); 2753 $('.js_preview_size.height', _form).val(previewSize.height); 2754 } 2755 } 2756 } 2757 _form.submit(); 2758 if ($('.rotate_button', $('#profile_crop_me')).length) { 2759 $('.rotate_button', $('#profile_crop_me')).find('button').prop('disabled', true); 2760 } 2761 }, 2762 2763 showError: function (message) { 2764 // error message 2765 $('[data-dz-errormessage]', '#user-dropzone').text(message); 2766 $('.dz-error-message', '#user-dropzone').insertAfter($('#user-dropzone')); 2767 2768 $('#user-dropzone').addClass('dz-error'); 2769 $('.dz-preview', '#user-dropzone').addClass('dz-error'); 2770 $('#profile_crop_me').removeClass('profile-image-uploading').addClass('profile-image-error'); 2771 }, 2772 2773 disableCropFormButtons: function () { 2774 $('#profile_crop_me .rotate_button input').prop('disabled', true); 2775 $('#profile_crop_me .rotate_button a').addClass('disabled'); 2776 }, 2777 2778 enableCropFormButtons: function () { 2779 $('#profile_crop_me .rotate_button input').prop('disabled', false); 2780 $('#profile_crop_me .rotate_button a').removeClass('disabled'); 2781 } 2782}; 2783 2784$(document).on('click', '.rotate-cw', function () { 2785 $('.image-editor').cropit('rotateCW'); 2786 $Core.ProfilePhoto.modified = true; 2787 $Core.ProfilePhoto.currentRotation = ($Core.ProfilePhoto.currentRotation + 90) % 360; 2788}); 2789 2790$(document).on('click', '.rotate-ccw', function () { 2791 $('.image-editor').cropit('rotateCCW'); 2792 $Core.ProfilePhoto.modified = true; 2793 $Core.ProfilePhoto.currentRotation = ($Core.ProfilePhoto.currentRotation + 270) % 360; 2794}); 2795 2796$Core.checkAttachmentHolder = function () { 2797 $('.attachment_list').each(function () { 2798 var list = $(this); 2799 if (list.find('.attachment-row').length === 0) { 2800 list.closest('.attachment_holder_view').remove(); 2801 $('.no-attachment', list).removeClass('hide'); 2802 } 2803 }); 2804}; 2805 2806//custom input range 2807$(document).on('input', '.cropit-btn-edit input', function () { 2808 $('.cropit-btn-edit input').css('background', 'linear-gradient(to right, #2681d5 0%, #2681d5 ' + this.value * 100 + '%, #dcdcdc ' + this.value * 100 + '%, #dcdcdc 100%)'); 2809}); 2810 2811var isFF = true; 2812var addRule = (function (style) { 2813 var sheet = document.head.appendChild(style).sheet; 2814 return function (selector, css) { 2815 if (isFF) { 2816 if (sheet.cssRules.length > 0) { 2817 sheet.deleteRule(0); 2818 } 2819
2820 try { 2821 sheet.insertRule(selector + "{" + css + "}", 0); 2822 } catch (ex) { 2823 isFF = false; 2824 } 2825 } 2826 }; 2827})(document.createElement("style")); 2828 2829addRule('.cropit-btn-edit input::-moz-range-track', 'background: #dcdcdc'); 2830 2831$(document).on('input', '.cropit-btn-edit input', function () { 2832 addRule('.cropit-btn-edit input::-moz-range-track', 'background: linear-gradient(to right, #2681d5 0%, #2681d5 ' + this.value * 100 + '%, #dcdcdc ' + this.value * 100 + '%, #dcdcdc 100%)'); 2833}); 2834//end custom 2835 2836//check ie fix input range 2837$Core.getIEVersion = function () { 2838 var sAgent = window.navigator.userAgent; 2839 var Idx = sAgent.indexOf("MSIE"); 2840 2841 // If IE, return version number. 2842 if (Idx > 0) 2843 return parseInt(sAgent.substring(Idx + 5, sAgent.indexOf(".", Idx))); 2844 2845 // If IE 11 then look for Updated user agent string. 2846 else if (!!navigator.userAgent.match(/Trident\/7\./)) 2847 return 11; 2848 else 2849 return 0; //It is not IE 2850}; 2851//end check 2852 2853$Core.FriendRequest = { 2854 panel: { 2855 accept: function (requestId, message) { 2856 var requestRow = $('#drop_down_' + requestId, '#request-panel-body'); 2857 2858 $('.panel_rows_time', requestRow).text(message); 2859 $('.panel_action', requestRow).remove(); 2860 requestRow.addClass('friend-request-accepted'); 2861 2862 // update counter 2863 $Core.FriendRequest.panel.descreaseCounter(); 2864 2865 setTimeout(function () { 2866 $('.panel_row', requestRow).slideUp(200, function () { 2867 requestRow.remove(); 2868 $Core.FriendRequest.panel.checkAndClosePanel(); 2869 }); 2870 }, 2e3); 2871 }, 2872 2873 deny: function (requestId) { 2874 var requestRow = $('#drop_down_' + requestId, '#request-panel-body'); 2875 2876 // update counter 2877 $Core.FriendRequest.panel.descreaseCounter(); 2878 2879 $('.panel_row', requestRow).fadeOut(400, function () { 2880 requestRow.remove(); 2881 $Core.FriendRequest.panel.checkAndClosePanel(); 2882 }); 2883 }, 2884 2885 descreaseCounter: function () { 2886 }, 2887 2888 checkAndClosePanel: function () { 2889 if ($('li', '#request-panel-body').length === 0) { 2890 $('#hd-request').trigger('click'); 2891 } 2892 } 2893 }, 2894 2895 manageAll: { 2896 accept: function (requestId, message) { 2897 var requestRow = $('#request-' + requestId); 2898 2899 $('.moderation_row', requestRow).css({ 2900 visibility: 'hidden' 2901 }); 2902 $('.item-info', requestRow).text(message); 2903 $('#drop_down_' + requestId, requestRow).remove(); 2904 requestRow.addClass('friend-request-accepted'); 2905 setTimeout(function () { 2906 requestRow.fadeOut(400, function () { 2907 $(this).remove(); 2908 $Core.FriendRequest.manageAll.checkReload(); 2909 }); 2910 }, 2e3); 2911 }, 2912 2913 deny: function (requestId) { 2914 $('#request-' + requestId).slideUp(400, function () { 2915 $('#request-' + requestId).remove(); 2916 $Core.FriendRequest.manageAll.checkReload(); 2917 }); 2918 }, 2919 2920 checkReload: function () { 2921 if ($('#collection-friends-incoming').children().length === 0) { 2922 window.location.reload(); 2923 } 2924 } 2925 } 2926}; 2927 2928$Core.dropdownTooltip = { 2929 tooltipElement: null, 2930 registeredClosing: null, 2931 timeout: 1e3, 2932 debug: false, // enable this when debugging 2933 2934 openTooltip: function (tooltip) { 2935 this.debug('openTooltip'); 2936 this.tooltipElement = tooltip; 2937 tooltip.addClass('open'); 2938 $('a', tooltip).attr('aria-expanded', true); 2939 this.dismissClose(); 2940 }, 2941 2942 closeTooltip: function () { 2943 this.debug('closeTooltip'); 2944 this.tooltipElement.removeClass('open'); 2945 $('a', this.tooltipElement).attr('aria-expanded', false); 2946 }, 2947 2948 registerClose: function (tooltip) { 2949 this.debug('registerClose'); 2950 this.tooltipElement = tooltip; 2951 this.registeredClosing = setTimeout(function () { 2952 $Core.dropdownTooltip.closeTooltip(); 2953 }, this.timeout); 2954 }, 2955 2956 dismissClose: function () { 2957 this.debug('dismissClose'); 2958 clearTimeout(this.registeredClosing); 2959 }, 2960 2961 debug: function (msg) { 2962 if (!this.debug) { 2963 return; 2964 } 2965 console.log('$Core.dropdownTooltip:', msg); 2966 } 2967}; 2968 2969$(document).on('mouseover', '[data-component="dropdown-tooltip"] >a, [data-component="dropdown-tooltip"] >ul', function () { 2970 $Core.dropdownTooltip.openTooltip($(this).closest('[data-component="dropdown-tooltip"]')); 2971}).on('mouseout', '[data-component="dropdown-tooltip"] >a, [data-component="dropdown-tooltip"] >ul', function () { 2972 $Core.dropdownTooltip.registerClose($(this).closest('[data-component="dropdown-tooltip"]')); 2973}); 2974 2975$Core.Privacy = { 2976 sWrapperSelector: '', 2977 2978 sCustomPrivacySelector: '', 2979 2980 sPrivacyArray: '', 2981 2982 phrases: { 2983 custom_privacy: '', 2984 create_friends_list: '' 2985 }, 2986 2987 updateCustomList: function () { 2988 $('#js_temp_privacy_error_message').hide(); 2989 var checkedCustomList = $('[data-component="custom-list-checkbox"]:checked', this.sWrapperSelector), 2990 $iCnt = checkedCustomList.length; 2991 2992 if (!$iCnt) { 2993 $('#js_temp_privacy_error_message').show(); 2994 } else { 2995 $($Core.Privacy.sCustomPrivacySelector).html(''); 2996 var aList = []; 2997 2998 checkedCustomList.each(function () { 2999 $($Core.Privacy.sCustomPrivacySelector).append('<div><input type="hidden" name="val' +
3000 (empty($Core.Privacy.sPrivacyArray) ? '' : '[' + $Core.Privacy.sPrivacyArray + ']') + 3001 '[privacy_list][]" value="' + this.value + 3002 '" class="privacy_list_array" /></div>'); 3003 aList.push(this.value); 3004 }); 3005 3006 if ($('#photo_id').length > 0) { 3007 $.ajaxCall('privacy.addItemToFriendsLists', $.param( 3008 {lists: aList, item_id: $('#photo_id').val(), module: 'photo'})); 3009 } 3010 3011 tb_remove(); 3012 } 3013 3014 return false; 3015 }, 3016 3017 populateCustomListCheckbox: function () { 3018 $('.privacy_list_array', $Core.Privacy.sCustomPrivacySelector).each(function () { 3019 var customList = $('[data-component="custom-list-checkbox"][value="' + this.value + '"]'); 3020 if (customList.length) { 3021 customList.attr('checked', true); 3022 } 3023 }); 3024 }, 3025 3026 showCreateListForm: function () { 3027 $('#js_create_custom_friend_list_holder').show(); 3028 $('#js_custom_list_actual_holder, #js_temp_privacy_error_message, #custom-list-empty').hide(); 3029 // update popup title 3030 $('.js_box_title', $(this.sWrapperSelector).closest('.js_box')).text(this.phrases.create_friends_list); 3031 }, 3032 3033 hideCreateListForm: function () { 3034 $('#js_create_custom_friend_list_holder').hide(); 3035 3036 if ($('[data-component="custom-list"]').children().length) { 3037 $('#js_custom_list_actual_holder').show(); 3038 } else { 3039 $('#custom-list-empty').show(); 3040 } 3041 3042 // update popup title 3043 $('.js_box_title', $(this.sWrapperSelector).closest('.js_box')).text(this.phrases.custom_privacy); 3044 }, 3045 3046 addList: function (form, event) { 3047 event.preventDefault(); 3048 $(form).ajaxCall('friend.addFriendsList'); 3049 }, 3050 3051 addListDone: function (name, value) { 3052 var checkbox = $('#custom-list-checkbox-template').clone(); 3053 checkbox.removeClass('hide').attr('id', ''); 3054 $('span', checkbox).text(name); 3055 $('input', checkbox).val(value).attr('checked', true); 3056 $('[data-component="custom-list"]').append(checkbox); 3057 3058 this.hideCreateListForm(); 3059 this.resetAddListForm(); 3060 }, 3061 3062 resetAddListForm: function () { 3063 $('#js_add_new_list').val(''); 3064 $('.item-user-selected').remove(); 3065 } 3066}; 3067 3068$Core.CoverPhoto = { 3069 bIsResponsive: $(window).width() <= 991, 3070 maxUploadFileSize: 0, 3071 sDefaultCoverPhoto: '', 3072 sDefaultCoverPhotoUrl: '', 3073 iTempFileId: 0, 3074 aImageInfo: {}, 3075 aRequestParams: {}, 3076 bIsDefaultPhoto: false, 3077 phrases: { 3078 upload_error: '', 3079 photo_larger_than_limit: '', 3080 change_photo: '', 3081 cancel: '', 3082 }, 3083 reset: function() { 3084 this.sDefaultCoverPhoto = ''; 3085 this.iTempFileId = 0; 3086 this.aImageInfo = {}; 3087 this.aRequestParams = {}; 3088 }, 3089 initRepositionCover: function() { 3090 if (typeof $Core.coverPhotoPositionTop !== "undefined" && typeof pf_reposition !== "undefined" && $Core.coverPhotoPositionTop !== 0) { 3091 pf_reposition.top = $Core.coverPhotoPositionTop; 3092 } 3093 }, 3094 processAfterUploading: function(params) { 3095 let profileCoverContainer = $('.profiles_banner_bg'); 3096 if (profileCoverContainer.length) { 3097 let defaultPhoto = profileCoverContainer.find('.js_default_background_image'); 3098 if (defaultPhoto.length) { 3099 this.bIsDefaultPhoto = true; 3100 } 3101 3102 let parentEleForRedirectToPhotoDetail = profileCoverContainer.find('#cover_bg_container').length ? profileCoverContainer.find('#cover_bg_container').closest('a') : null; 3103 3104 if (!this.bIsDefaultPhoto && this.sDefaultCoverPhoto === '') { 3105 let firstEle = profileCoverContainer.find('.js_background_image:first'); 3106 if (firstEle.prop('tagName').toUpperCase() === 'IMG') { 3107 this.sDefaultCoverPhoto = firstEle.attr('src') ? firstEle.attr('src') : ''; 3108 } else { 3109 let cssBackgroundImageValue = firstEle.css('background-image'); 3110 if (typeof cssBackgroundImageValue !== "undefined" && cssBackgroundImageValue !== '') { 3111 cssBackgroundImageValue = cssBackgroundImageValue.match(/url\((?:"|')?([^"']+)(?:"|')?\)/); 3112 if (typeof cssBackgroundImageValue === "object" && cssBackgroundImageValue.length === 2) { 3113 this.sDefaultCoverPhoto = cssBackgroundImageValue[1]; 3114 } 3115 } 3116 } 3117 3118 if (this.sDefaultCoverPhoto !== '' && parentEleForRedirectToPhotoDetail.length && parentEleForRedirectToPhotoDetail.attr('href')) { 3119 this.sDefaultCoverPhotoUrl = parentEleForRedirectToPhotoDetail.attr('href'); 3120 } 3121 } 3122 3123 this.iTempFileId = params['tempFileId']; 3124 this.aImageInfo = params['imageInfo']; 3125 3126 let imageObject = new Image(); 3127 imageObject.src = params['imagePath']; 3128 imageObject.onload = function() { 3129 $('#uploading-cover').hide(); 3130 profileCoverContainer.find('.js_background_image').each(function() { 3131 let tagName = $(this).prop('tagName').toUpperCase(), 3132 isImageTag = tagName === 'IMG', 3133 canDisplay = ($Core.CoverPhoto.bIsResponsive && $(this).hasClass('is_responsive')) 3134 || (!$Core.CoverPhoto.bIsResponsive && !$(this).hasClass('is_responsive')); 3135 3136 if (isImageTag) { 3137 $(this).attr('src', params['imagePath']); 3138 } 3139 3140 let cssInline = canDisplay ? 'display: block !important;' : ''; 3141 if (!isImageTag) { 3142 cssInline += 'background-image: url("' + params['imagePath'] + '");'; 3143 } 3144 3145 $(this).attr('style', cssInline); 3146 }); 3147 3148 $Core.CoverPhoto.reposition.init(params['moduleId'], params['itemId']); 3149 3150 if (typeof pf_reposition !== "undefined") { 3151 pf_reposition.top = 0; 3152 } 3153 3154 $('img', '#cover_bg_container').css({top: '0px'}); 3155 3156 if ($Core.CoverPhoto.bIsDefaultPhoto) { 3157 defaultPhoto.addClass('hide'); 3158 } else if (parentEleForRedirectToPhotoDetail !== null) { 3159 parentEleForRedirectToPhotoDetail.attr('href', 'javascript:void(0);'); 3160 } 3161 } 3162 } 3163 }, 3164 submitUpload: function(form) { 3165 let _form = $(form), 3166 inputEle = _form.find('input[type="file"]'), 3167 formData = new FormData(), 3168 globalTokenName = getParam('sGlobalTokenName'), 3169 parentObject = this; 3170 let targetFile = inputEle[0].files[0]; 3171 if (typeof targetFile !== "object") { 3172 return false;
3173 } 3174 3175 if (!Object.keys(this.aRequestParams).length) { 3176 _form.find('input[type="hidden"]').each(function() { 3177 let _name = $(this).attr('name'); 3178 if (typeof _name === 'string' && _name !== '') { 3179 parentObject.aRequestParams[_name] = $(this).val(); 3180 formData.append(_name, $(this).val()); 3181 } 3182 }); 3183 } 3184 3185 formData.append(globalTokenName + '[ajax]', true); 3186 formData.append(globalTokenName + '[call]', 'user.uploadTempCover'); 3187 formData.append(globalTokenName + '[security_token]', oCore['log.security_token']); 3188 formData.append(globalTokenName + '[is_admincp]', 0); 3189 formData.append(globalTokenName + '[is_user_profile]', (oCore['profile.is_user_profile'] ? '1' : '0')); 3190 formData.append(globalTokenName + '[profile_user_id]', (oCore['profile.user_id'] ? oCore['profile.user_id'] : '0')); 3191 formData.append('image', targetFile); 3192 3193 let xhr = new XMLHttpRequest(); 3194 xhr.onload = function(){ 3195 if (xhr.readyState !== 4) { 3196 return; 3197 } 3198 let response = $.parseJSON(xhr.responseText);
3199 try { 3200 if (response.hasOwnProperty('error')) { 3201 window.parent.sCustomMessageString = response['error']; 3202 tb_show(response['error_title'], $.ajaxBox('core.message', 'height=150&width=300')); 3203 $('#uploading-cover').hide(); 3204 } else { 3205 eval(response['eval']); 3206 } 3207 } catch (_error) { 3208 console.log("Invalid JSON response from server."); 3209 } 3210 }; 3211 xhr.upload.onprogress = function (e) { 3212 if (!$('#uploading-cover').length) { 3213 return false; 3214 } 3215 if ($(window).width() <= 991) { 3216 $('#uploading-cover').addClass('is-responsive'); 3217 } else { 3218 $('#uploading-cover').removeClass('is-responsive'); 3219 } 3220 $('#uploading-cover').show(); 3221 if (e.lengthComputable) { 3222 $('.progress-bar').css({width: (Math.floor(e.loaded / e.total * 100)) + '%'}); 3223 } 3224 return true; 3225 }; 3226 xhr.open("POST", getParam('sJsAjax'), true); 3227 3228 let headers = { 3229 "Accept": "application/json", 3230 "Cache-Control": "no-cache", 3231 "X-Requested-With": "XMLHttpRequest" 3232 }; 3233 3234 for (headerName in headers) { 3235 headerValue = headers[headerName]; 3236 if (headerValue) { 3237 xhr.setRequestHeader(headerName, headerValue); 3238 } 3239 } 3240 3241 xhr.send(formData); 3242 3243 return false; 3244 }, 3245 openUploadImage: function() { 3246 let uploadForm = $('#js_user_upload_cover_photo'); 3247 if (!uploadForm.length) { 3248 return false; 3249 } 3250 3251 let inputFile = uploadForm.find('input[type="file"]'); 3252 inputFile.val(''); 3253 inputFile.trigger('click'); 3254 3255 return false; 3256 }, 3257 submitForm: function () { 3258 $('#js_cover_photo_iframe_loader_error').hide(); 3259 $('#js_activity_feed_form').hide(); 3260 $('.profiles_banner').addClass('cover-uploading'); 3261 3262 var form = $('#change-cover-form'); 3263 3264 if (this.maxUploadFileSize && $('#global_attachment_photo_file_input')[0].files[0].size > this.maxUploadFileSize * 1000) { 3265 $('#js_activity_feed_form').show(); 3266 $Core.jsConfirm({ 3267 title: this.phrases.upload_error, 3268 message: this.phrases.photo_larger_than_limit, 3269 btn_yes: this.phrases.change_photo, 3270 btn_no: this.phrases.cancel, 3271 }, function () { 3272 setTimeout(function () { 3273 $('a#js_change_cover_photo').trigger('click'); 3274 }, 10); 3275 }, function () { 3276 $('.profiles_banner').removeClass('cover-uploading'); 3277 }); 3278 $('.profiles_banner').removeClass('cover-uploading'); 3279 return; 3280 } 3281 3282 // show uploading div 3283 $('#uploading-cover').show(); 3284 3285 // ajax submit 3286 $.ajax({ 3287 url: form.attr('action'), 3288 type: 'POST', 3289 3290 // Form data 3291 data: new FormData(form[0]), 3292 3293 // Tell jQuery not to process data or worry about content-type 3294 // You *must* include these options! 3295 cache: false, 3296 contentType: false, 3297 processData: false, 3298 3299 // Custom XMLHttpRequest 3300 xhr: function () { 3301 var myXhr = $.ajaxSettings.xhr(); 3302 if (myXhr.upload) { 3303 // For handling the progress of the upload 3304 myXhr.upload.addEventListener('progress', function (e) { 3305 if (e.lengthComputable) { 3306 $('.progress-bar', '#uploading-cover').css({width: (Math.floor(e.loaded / e.total * 100)) + '%'}); 3307 } 3308 }, false); 3309 } 3310 return myXhr; 3311 }, 3312 3313 success: function (res) { 3314 var regex = /<script[^>]*>(.*)<\/script>/g, 3315 js = regex.exec(res); 3316 3317 if (js.length === 2) { 3318 eval(js[1]); 3319 } else { 3320 // close popup 3321 js_box_remove(form[0]); 3322 // preview image 3323 this.previewCover($('#global_attachment_photo_file_input')[0]); 3324 // set z-index cover bg 3325 $('.profiles_banner_bg .cover_bg').css({'z-index': 1}); 3326 } 3327 }, 3328 }); 3329 }, 3330 3331 previewCover: function (input) { 3332 if (input.files && input.files[0]) { 3333 var reader = new FileReader(); 3334 3335 reader.onload = function (e) { 3336 $('#cover_bg_container img').attr('src', e.target.result); 3337 }; 3338 3339 reader.readAsDataURL(input.files[0]); 3340 } 3341 }, 3342 3343 reposition: {
3344 init: function (sModule, iId) { 3345 pf_reposition.module = sModule; 3346 pf_reposition.id = iId; 3347 $('.profiles_banner').addClass('editing'); 3348 3349 let bCanInitDefaultPhoto = !$Core.CoverPhoto.iTempFileId && $Core.CoverPhoto.sDefaultCoverPhoto === '', 3350 targetImg = false; 3351 3352 if ($('.pages_header_cover img').length) { 3353 targetImg = $('.pages_header_cover img'); 3354 height = targetImg.height(); 3355 width = targetImg.width(); 3356 } else if ($('.profiles_banner_bg .cover img').length) { 3357 targetImg = $('.profiles_banner_bg .cover img'); 3358 height = targetImg.height(); 3359 width = targetImg.width(); 3360 } 3361 3362 if (!targetImg) { 3363 return false; 3364 } 3365 3366 let parentEleForRedirectToPhotoDetail = targetImg.closest('a'); 3367 if (bCanInitDefaultPhoto) { 3368 $Core.CoverPhoto.sDefaultCoverPhoto = targetImg.attr('src'); 3369 if (parentEleForRedirectToPhotoDetail.length) { 3370 let photoUrl = parentEleForRedirectToPhotoDetail.attr('href'); 3371 if (typeof photoUrl === 'string' && photoUrl.match(/\/photo\/[0-9]+/)) { 3372 $Core.CoverPhoto.sDefaultCoverPhotoUrl = photoUrl; 3373 } 3374 } 3375 } 3376 3377 if ($Core.CoverPhoto.sDefaultCoverPhotoUrl !== '') { 3378 parentEleForRedirectToPhotoDetail.attr('href', 'javascript:void(0);'); 3379 } 3380 3381 if (!$Core.CoverPhoto.bIsResponsive) { 3382 $.globalVars = { 3383 originalTop: 0, 3384 originalLeft: 0, 3385 maxHeight: height - $("#cover_bg_container").height(), 3386 maxWidth: width - $("#cover_bg_container").width() 3387 }; 3388 3389 $('.pages_header_cover img, .profiles_banner_bg .cover img').draggable({ 3390 axis: 'y', 3391 start: function (event, ui) { 3392 if (ui.position != undefined) { 3393 $.globalVars.originalTop = ui.position.top; 3394 $.globalVars.originalLeft = ui.position.left; 3395 } 3396 }, 3397 drag: function (event, ui) { 3398 var newTop = ui.position.top; 3399 var newLeft = ui.position.left; 3400 if (ui.position.top < 0 && ui.position.top * -1 > $.globalVars.maxHeight) { 3401 newTop = $.globalVars.maxHeight * -1; 3402 } 3403 if (ui.position.top > 0) { 3404 newTop = 0; 3405 } 3406 if (ui.position.left < 0 && ui.position.left * -1 > $.globalVars.maxWidth) { 3407 newLeft = $.globalVars.maxWidth * -1; 3408 } 3409 if (ui.position.left > 0) { 3410 newLeft = 0; 3411 } 3412 ui.position.top = newTop; 3413 ui.position.left = newLeft; 3414 }, 3415 stop: function (evt, ui) { 3416 pf_reposition.top = ui.position.top; 3417 } 3418 }); 3419 } 3420 }, 3421 3422 cancel: function () { 3423 if (!$Core.CoverPhoto.bIsResponsive) { 3424 $('.pages_header_cover img, .profiles_banner_bg .cover img').draggable('destroy'); 3425 } 3426 3427 let profileBanner = $('.profiles_banner_bg'), 3428 defaultPhoto = profileBanner.find('.cover .js_default_background_image'); 3429 3430 profileBanner.find('.js_background_image').each(function() { 3431 let tagName = $(this).prop('tagName').toUpperCase(), 3432 isImageTag = tagName === 'IMG', 3433 cssInline = ''; 3434 if (isImageTag) { 3435 $(this).attr('src', $Core.CoverPhoto.sDefaultCoverPhoto); 3436 } else if ($Core.CoverPhoto.sDefaultCoverPhoto !== '') { 3437 cssInline = 'background-image: url("' + $Core.CoverPhoto.sDefaultCoverPhoto + '");'; 3438 } 3439 if ($Core.CoverPhoto.bIsDefaultPhoto || $Core.CoverPhoto.sDefaultCoverPhoto === '') { 3440 cssInline += 'display: none !important;' 3441 } 3442 3443 if (cssInline !== '') { 3444 $(this).attr('style', cssInline); 3445 } 3446 3447 if ($(this).closest('#cover_bg_container').length) { 3448 let parentEleForRedirectToPhotoDetail = $(this).closest('#cover_bg_container').closest('a'); 3449 if (parentEleForRedirectToPhotoDetail.length && $Core.CoverPhoto.sDefaultCoverPhotoUrl !== '') { 3450 parentEleForRedirectToPhotoDetail.attr('href', $Core.CoverPhoto.sDefaultCoverPhotoUrl); 3451 } 3452 } 3453 }); 3454 3455 if ($Core.CoverPhoto.bIsDefaultPhoto) { 3456 defaultPhoto.removeClass('hide'); 3457 } 3458 3459 $Core.CoverPhoto.reset(); 3460 3461 var top = 0; 3462 if (typeof $Core.coverPhotoPositionTop !== 'undefined') { 3463 top = $Core.coverPhotoPositionTop; 3464 } 3465 $('img', '#cover_bg_container').css({top: top + 'px'}); 3466 3467 $('.profiles_banner').removeClass('editing'); 3468 }, 3469 processAfterSubmit: function(params) { 3470 if (typeof params === 'object') { 3471 if (params.hasOwnProperty('url')) { 3472 window.location.href = params['url']; 3473 } else if (params.hasOwnProperty('back')) { 3474 $('.pages_header_cover img, .profiles_banner_bg .cover img').draggable('destroy'); 3475 $('.profiles_banner').removeClass('editing'); 3476 } 3477 } 3478 }, 3479 save: function () { 3480 if ($Core.CoverPhoto.iTempFileId) {
3481 let requestParams = Object.keys($Core.CoverPhoto.aRequestParams).length ? $Core.CoverPhoto.aRequestParams : {}, 3482 actionButtons = $('#js_cover_reposition_actions button'); 3483 3484 actionButtons.prop('disabled', true); 3485 requestParams['temp_file_id'] = $Core.CoverPhoto.iTempFileId; 3486 requestParams['temp_file_info'] = $Core.CoverPhoto.aImageInfo; 3487 requestParams['reposition_item_id'] = pf_reposition.id; 3488 requestParams['reposition_position'] = pf_reposition.top; 3489 requestParams['reposition_module_id'] = pf_reposition.module; 3490 $.ajax({ 3491 url: PF.url.make('photo/frame'), 3492 type: 'POST', 3493 data: requestParams, 3494 success: function(response) { 3495 eval(response); 3496 } 3497 }); 3498 } else { 3499 let params = { 3500 id: pf_reposition.id, 3501 position: pf_reposition.top, 3502 } 3503 this.processAfterSubmit({back: 1}); 3504 $.fn.ajaxCall(pf_reposition.module + '.repositionCoverPhoto', $.param(params), null, null, function() { 3505 let targetImg = $('.pages_header_cover img').length ? $('.pages_header_cover img') : ($('.profiles_banner_bg .cover img').length ? $('.profiles_banner_bg .cover img') : null); 3506 if (targetImg === null) { 3507 return false; 3508 } 3509 if (targetImg.closest('a').length && $Core.CoverPhoto.sDefaultCoverPhotoUrl) { 3510 targetImg.closest('a').attr('href', $Core.CoverPhoto.sDefaultCoverPhotoUrl); 3511 } 3512 }); 3513 } 3514 3515 $Core.coverPhotoPositionTop = pf_reposition.top; 3516 } 3517 } 3518}; 3519 3520$Core.toggleButton = function (event) { 3521 var obj = $(event.target) 3522 var p = obj.closest('.item_is_active_holder'); 3523 3524 if (p.hasClass('item_selection_not_active')) { 3525 p.find('.item_is_active input').prop('checked', true); 3526 p.addClass('item_selection_active').removeClass('item_selection_not_active'); 3527 } else { 3528 p.find('.item_is_not_active input').prop('checked', true); 3529 p.removeClass('item_selection_active').addClass('item_selection_not_active'); 3530 } 3531 3532 p.find('.item_is_active input').trigger('change'); 3533}; 3534 3535$Core.disableScroll = function () { 3536 if ($('body').css('position') == 'fixed' && $Core.scrollPos) { 3537 return; 3538 } 3539 $Core.scrollPos = $(window).scrollTop(); 3540 $('body').css({ 3541 overflow: 'hidden', 3542 position: 'fixed', 3543 width: '100%', 3544 top: -$Core.scrollPos 3545 }); 3546 $('#js_global_tooltip').css('transform', 'translateY(' + $Core.scrollPos + 'px)'); 3547}; 3548 3549$Core.enableScroll = function () { 3550 if ($('.js_box_image_holder:visible, .js_box_holder:visible').length == 0) { 3551 $('body').css({ 3552 overflow: '', 3553 position: '', 3554 width: '', 3555 top: '' 3556 }); 3557 $('#js_global_tooltip').css('transform', ''); 3558 $(window).scrollTop($Core.scrollPos); 3559 $Core.scrollPos = 0; 3560 } 3561}; 3562 3563$Core.processFriendRequest = { 3564 addAsFriend: function (userId, isInSuggestionsBlock) { 3565 if (typeof oParams.sFriendshipDirection != 'undefined' && oParams.sFriendshipDirection == 'one_way_friendships') { 3566 $.ajaxCall('friend.processRequest', 'user_id=' + userId + '&type=add'); 3567 } else { 3568 tb_show('', $.ajaxBox('friend.request', 'width=420&friend_request_ajax=1&user_id=' + userId + 3569 ((typeof isInSuggestionsBlock !== 'undefined' && isInSuggestionsBlock) ? '&suggestion=1' : ''))); 3570 } 3571 return false; 3572 }, 3573 removeBtn: function (parent) { 3574 var targetElement = !empty(parent) ? $(parent).find('.add_as_friend_button') : $('.add_as_friend_button'); 3575 if (targetElement.length) { 3576 targetElement.remove(); 3577 } 3578 }, 3579 confirmRequest: function (params) { 3580 if ($('._is_profile_view').length) { 3581 localStorage.setItem('confirmRequestMessage', params['message']); 3582 $Core.reloadPage(); 3583 } else { 3584 tb_remove(); 3585 $('#public_message').html(params['message']).show(); 3586 $Behavior.addModerationListener(); 3587 } 3588 }, 3589 callRequestCancel: function (requestId) { 3590 $Core.jsConfirm({message: oTranslations['are_you_sure_you_want_to_cancel_this_friend_request']}, function () { 3591 $.ajaxCall('friend.deleteRequest', 'request_id=' + requestId + '&friend_request_ajax=1'); 3592 }, function () { 3593 }); 3594 return false;
3595 }, 3596 callUnfriend: function (friend_user_id) { 3597 $Core.jsConfirm({message: oTranslations['are_you_sure_you_want_to_unfriend_this_user']}, function () { 3598 $.ajaxCall('friend.delete', 'friend_user_id=' + friend_user_id + '&friend_request_ajax=1'); 3599 }, function () { 3600 }); 3601 return false; 3602 }, 3603 3604}; 3605 3606$Core.initAjaxPaging = function () { 3607 $('a.ajax-paging').off('click').on('click', function () { 3608 var oParent = $(this).closest('.js_pager_buttons'), 3609 sAjaxBlock = oParent.data('block'), 3610 sContainer = oParent.data('content-container'); 3611 3612 if ($(sContainer).length > 0 && sAjaxBlock) { 3613 if ($(this).data('params').indexOf('type=loadmore') === -1) { 3614 $(sContainer).html( 3615 '<i class="ajax-paging-loading fa fa-spin fa-circle-o-notch"></i>'); 3616 } else { 3617 $(sContainer + ' .js_pager_view_more_link').remove(); 3618 $(sContainer).append( 3619 '<i class="ajax-paging-loading fa fa-spin fa-circle-o-notch"></i>'); 3620 } 3621 $.ajaxCall('core.ajaxPaging', $(this).data('params') + '&block=' + 3622 sAjaxBlock + '&container=' + sContainer, 'GET'); 3623 } 3624 return false; 3625 }); 3626}; 3627 3628var bAjaxLinkIsClicked = false; 3629var bCanByPassClick = false; 3630var sClickProfileName = ''; 3631var historyStateData = []; 3632var lastPushState; 3633$Core.initClickAllLinks = function () { 3634 if (!$Core.hasPushState() || $('#admincp_base').length) { 3635 return; 3636 } 3637 3638 if (oParams.bOffFullAjaxMode) { 3639 return; 3640 } 3641 3642 $('a, ._a').each(function () { 3643 if (!$(this).prop('built') && !$(this).hasClass('dont-unbind') && !$(this).closest('dont-unbind-children')) { 3644 $(this).off('click'); 3645 } 3646 }); 3647 3648 $('a, ._a').on('click', function (e) { 3649 if (close_warning_checked) { 3650 return; 3651 } 3652 // fix issue hold command on click to open new tab instead of ajax 3653 if (e.metaKey || e.ctrlKey || e.altKey) 3654 return; 3655 3656 var $sLink = $(this).attr('href'); 3657 if (!$sLink) { 3658 $sLink = $(this).data('href'); 3659 } 3660 3661 if (!$sLink) { 3662 return; 3663 } 3664 3665 if ((substr($sLink, 0, 7) != 'http://' && substr($sLink, 0, 8) != 'https://') 3666 || substr($sLink, -1) == '#' 3667 || $sLink == '#' 3668 ) { 3669 return; 3670 } 3671 3672 if ($(this).hasClass('no_ajax_link') 3673 || $(this).hasClass('thickbox') 3674 || $(this).hasClass('popup') 3675 || $(this).hasClass('ajax') 3676 || $(this).hasClass('no_ajax') 3677 || $(this).hasClass('inlinePopup') 3678 || $(this).hasClass('sJsConfirm') 3679 || $(this).attr('target') === '_blank' 3680 || $(this).attr('onclick') !== undefined) { 3681 return; 3682 } 3683 if ($sLink !== window.location.href) { 3684 historyStateData.push({ 3685 path: window.location.href, 3686 scrollTop: $(window).scrollTop(), 3687 counter: 0 3688 }); 3689 } 3690 if ($(this).hasClass('keepPopup') && $(this).closest('.js_box').length > 0) { 3691 js_box_remove($(this)); 3692 $(this).addClass('popup'); 3693 tb_show('', $(this).attr('href'), $(this)); 3694 return false; 3695 } 3696 var $aUrlParts = parse_url($sLink); 3697 3698 if ($aUrlParts['host'] != getParam('sJsHostname') && (($aUrlParts['host'] + ':' + $aUrlParts['port']) != getParam('sJsHostname'))) { 3699 return; 3700 } 3701 3702 if (isset($aUrlParts['path']) && $aUrlParts['path'].indexOf('/admincp/') !== -1) { 3703 return; 3704 } 3705 3706 if (!isset($aUrlParts['query'])) { 3707 var sTempHost = $aUrlParts['scheme'] + '://' + $aUrlParts['host'] + $aUrlParts['path']; 3708 $aUrlParts['query'] = sTempHost.replace(getParam('sJsHome'), '/'); 3709 } 3710 3711 if (isset($aUrlParts['query'])) { 3712 var aUrlParts = explode('/', $aUrlParts['query']); 3713 if (aUrlParts[1] == 'user' && aUrlParts[2] == 'logout') { 3714 return; 3715 } 3716 } 3717 3718 if (bCanByPassClick === true && aUrlParts[1] != sClickProfileName) { 3719 bCanByPassClick = false; 3720 return; 3721 } 3722 3723 if ($('#noteform').length > 0) { 3724 $('#noteform').hide(); 3725 } 3726 3727 if ($('#user_profile_photo').length > 0) { 3728 $('#user_profile_photo').imgAreaSelect({hide: true}); 3729 } 3730 3731 $('.ajax_link_reset').hide(); 3732 $('div#core_js_messages').html(''); 3733 3734 bAjaxLinkIsClicked = true; 3735 3736 $('body').css('cursor', 'wait'); 3737 3738 $(document).trigger('pageChangeStart'); 3739 3740 if ($('.site_menu a.menu_is_selected').length) { 3741 $Core.lastActiveMenu = $('.site_menu a.menu_is_selected').closest('li').attr('rel'); 3742 } else { 3743 $Core.lastActiveMenu = undefined; 3744 } 3745 3746 $('.site_menu a.menu_is_selected').removeClass('menu_is_selected'); 3747 if ($(this).parents('.site_menu:first').length) { 3748 $('.site_menu a.menu_is_selected').removeClass('menu_is_selected'); 3749 $(this).addClass('menu_is_selected'); 3750 var rel = $(this).parent().attr('rel'); 3751 $('.site_menu li[rel="' + rel + '"] > a').addClass('menu_is_selected'); 3752 } 3753 3754 $('.js_user_tool_tip_holder').hide(); 3755 $('#js_global_tooltip').hide(); 3756 3757 if (typeof BehaviorlinkClickAllAClick == 'function') { 3758 var bReturn = BehaviorlinkClickAllAClick($aUrlParts); 3759 if (bReturn == true) { 3760 return false;
3761 } 3762 } 3763 3764 if (cacheCurrentBody === null) { 3765 lastPushState = window.location.href; 3766 } 3767 3768 if (self == top) { 3769 history.pushState(null, null, $sLink); 3770 } else { 3771 window.parent.history.pushState(null, null, $sLink); 3772 } 3773 $Core.page($sLink); 3774 3775 $('.js_box').each(function () { 3776 if ($(this).children().length > 0) { 3777 js_box_remove($(this).children(":first")); 3778 } 3779 }); 3780 return false; 3781 }); 3782 3783 if (historyStateData.length) { 3784 historyStateData.forEach(function (history, index) { 3785 if (history.path === window.location.href) { 3786 $('html, body').animate({ 3787 scrollTop: history.scrollTop 3788 }, 50); 3789 setTimeout(function () { 3790 if (window.scrollY >= history.scrollTop || history.counter >= getParam('iLimitLoadMore')) { 3791 historyStateData.splice(index, 1); 3792 } else { 3793 historyStateData[index]['counter'] = history.counter + 1; 3794 } 3795 }, 60); 3796 } 3797 }) 3798 } 3799}; 3800 3801$Core.loadedInit = false; 3802$Core.loadInit = function (forceIt) { 3803 if ($Core.dynamic_js_files > 0 && forceIt !== true) { 3804 setTimeout(function () { 3805 $Core.loadInit(); 3806 }, 100); 3807 3808 return false; 3809 } 3810 if ($Core.loadedInit) { 3811 $('*:not(.star-rating, .dont-unbind)').each(function () { 3812 if ($(this).closest('.dont-unbind-children').length == 0) { 3813 $(this).unbind(); 3814 } 3815 }); 3816 3817 if ($('ul.dropdown-menu.dont-unbind-children li a').length) { 3818 $('ul.dropdown-menu.dont-unbind-children li a').off('click'); 3819 } 3820 } 3821 3822 // init click 3823 $Core.initClickAllLinks(); 3824 $Core.initAjaxPaging(); 3825 3826 $.each($Behavior, function () { 3827 try { 3828 this(this); 3829 } catch (e) { 3830 /* help Fix many bug here*/ 3831 } 3832 }); 3833 $Core.loadedInit = true; 3834 PF.event.trigger('on_page_load_init_end'); 3835}; 3836 3837$Core.isInView = function (elem, item) { 3838 if (!$Core.exists(elem)) { 3839 return false; 3840 } 3841 3842 var docViewTop = $(window).scrollTop(); 3843 var docViewBottom = docViewTop + $(window).height(); 3844 3845 var elemTop = $(elem).offset().top; 3846 var elemBottom = (elemTop + $(elem).height()); 3847 if (item) { 3848 elemBottom = (elemBottom - parseInt(item)); 3849 } 3850 3851 return ((docViewTop < elemTop) && (docViewBottom > elemBottom)); 3852}; 3853 3854$Core.buildMenu = function (rebuild) { 3855 if(rebuild) { 3856 $('[data-component="menu"]').each(function () { 3857 $(this).css('overflow', 'hidden'); 3858 }); 3859 } 3860 setTimeout(function () { 3861 reuild = rebuild || false; 3862 if($('[data-component="menu"]:not(\'.built\')').length || rebuild){ 3863 3864 $('[data-component="menu"]').each(function () { 3865 var parentClass = $(this).parent().attr('class'); 3866 if ($('body').width() < 601 && (parentClass.indexOf('sub-section-menu') !== -1 || parentClass.indexOf('sub_section_menu') !== -1)) { 3867 return false; 3868 } 3869 3870 var th = $(this), 3871 firstMenuItem = $('li:visible:first', th), 3872 lastMenuItem = $('>li:not(.explorer):visible:last', th), 3873 check_dropdown_more = $('li.dropdown .dropdown-menu:not(.js_dropdown_menu_sub)', th); 3874 3875 //clear dropdown 3876 if (check_dropdown_more.find('li').length > 0) { 3877 check_dropdown_more.children().insertBefore($('li.dropdown', th)); 3878 $('>li.explorer', th).addClass('hide'); 3879 //update var 3880 var th = $(this), 3881 firstMenuItem = $('li:visible:first', th), 3882 lastMenuItem = $('li:not(.explorer):visible:last', th); 3883 } 3884 3885 if (typeof firstMenuItem.offset() === 'undefined' || typeof lastMenuItem.offset() === 'undefined') { 3886 return; 3887 } else { 3888 var checkOffsetTop = firstMenuItem.offset().top + 20, // 20 for threshold 3889 lastItemOffsetTop = lastMenuItem.offset().top; 3890 } 3891 if (checkOffsetTop > lastItemOffsetTop) { 3892 $('>div', th).hide(); 3893 th.addClass('built'); 3894 th.css('overflow', 'visible'); 3895 return; 3896 } 3897 3898 var explorerItem = $('>li.explorer', th).removeClass('hide'), 3899 itemSize = $('>li:not(.explorer)', th).length, 3900 explorerMenu = $('ul', explorerItem); 3901 3902 function shouldMoveMenuItem() { 3903 th.find('>
3903li:not(.explorer):last').prependTo(explorerMenu); 3904 return checkOffsetTop < explorerItem.offset().top; 3905 } 3906 3907 for (var i = 0; i < itemSize; i++) { 3908 if (!shouldMoveMenuItem()) { 3909 $('>div', th).fadeOut(); 3910 th.addClass('built'); 3911 th.css('overflow', 'visible'); 3912 return; 3913 } 3914 } 3915 }); 3916 } 3917 }, 500); 3918}; 3919 3920$Behavior.buildMenu = function () { 3921 $Core.buildMenu(); 3922}; 3923 3924var buildMenuResizeDebounce; 3925 3926$(window).on('resize',function() { 3927 $Core.buildMenu(); 3928 clearTimeout(buildMenuResizeDebounce); 3929 buildMenuResizeDebounce = setTimeout(function () { 3930 $Core.buildMenu(true); 3931 }, 100); 3932}); 3933 3934$Behavior.moderationChanged = function () { 3935 $(document).trigger('core.moderation_changed'); 3936} 3937 3938$Behavior.imageHoverHolder = function () { 3939 $('#panels .block .title').off('click').click(function () { 3940 var t = $(this).parent(); 3941 if (t.find('.content').length) { 3942 t.find('.content').first().toggle(); 3943 } 3944 }); 3945 3946 $('#show-side-panel').off('click').click(function () { 3947 var b = $('body'); 3948 if (b.hasClass('show-side-panel-mode')) { 3949 b.removeClass('show-side-panel-mode'); 3950 return; 3951 } 3952 3953 b.addClass('show-side-panel-mode'); 3954 }); 3955 3956 $('body').click(function () { 3957 $('.image_hover_menu_link').each(function () { 3958 if ($(this).hasClass('image_hover_active')) { 3959 $(this).removeClass('image_hover_active'); 3960 $(this).parent().find('.image_hover_menu:first').hide(); 3961 $(this).hide(); 3962 } 3963 }); 3964 }); 3965 3966 $('.image_hover_holder').off('mouseover').mouseover(function () { 3967 if (!empty($(this).find('.image_hover_menu:first').html())) { 3968 $(this).addClass('image_hover_holder_hover').find('.image_hover_menu_link:first').show(); 3969 } 3970 }); 3971 3972 $('.image_hover_holder').off('mouseout').mouseout(function () { 3973 if (!$(this).find('.image_hover_menu_link').hasClass('image_hover_active')) { 3974 $(this).removeClass('image_hover_holder_hover').find('.image_hover_menu_link:first').hide(); 3975 } 3976 }); 3977 3978 $('.image_hover_menu_link').off('click').click(function () { 3979 var oMenu = $(this).parent().find('.image_hover_menu:first'); 3980 if ($(this).hasClass('image_hover_active')) { 3981 $(this).removeClass('image_hover_active'); 3982 oMenu.hide(); 3983 return false; 3984 } 3985 3986 $('.image_hover_menu_link').each(function () { 3987 if ($(this).hasClass('image_hover_active')) { 3988 $(this).removeClass('image_hover_active'); 3989 $(this).parent().find('.image_hover_menu:first').hide(); 3990 $(this).hide(); 3991 } 3992 }); 3993 $(this).addClass('image_hover_active'); 3994 oMenu.show(); 3995 return false; 3996 }); 3997}; 3998 3999$Behavior.targetBlank = function () { 4000 $('.targetBlank').click(function () { 4001 window.open($(this).get(0).href); 4002 return false; 4003 }); 4004}; 4005 4006var bCacheIsHover = false; 4007$Behavior.dropDown = function () { 4008 $('.dropContent').mouseover(function () { 4009 bCacheIsHover = true; 4010 }); 4011 4012 $('.dropContent').mouseout(function () { 4013 bCacheIsHover = false; 4014 }); 4015 4016 $('body').click(function () { 4017 if (!bCacheIsHover) { 4018 $('.dropContent').hide(); 4019 $('.sub_menu_bar li a').each(function () { 4020 if ($(this).hasClass('is_already_open')) { 4021 $(this).removeClass('is_already_open'); 4022 } 4023 }); 4024 } 4025 }); 4026}; 4027 4028/** 4029 * Drop down auto jump 4030 */ 4031$Behavior.goJump = function () { 4032 $('.goJump').change(function () { 4033 // Empty value, do nothing 4034 if ($(this).get(0).value == "") { 4035 return false; 4036 } 4037 4038 // Is this a delete link? If it is make sure they confirm they want to delete the item 4039 if ($(this).get(0).value.search(/delete/i) != -1 && !confirm(getPhrase('are_you_sure'))) { 4040 return false; 4041 } 4042 4043 // All set lets send them to the new page 4044 window.location.href = $(this).get(0).value; 4045 }); 4046}; 4047 4048$Behavior.inlinePopup = function () { 4049 $('.inlinePopup').click(function () { 4050 var $aParams = $.getParams($(this).get(0).href); 4051 var sParams = '&tb=true'; 4052 for (sVar in $aParams) { 4053 sParams += '&' + sVar + '=' + $aParams[sVar] + ''; 4054 } 4055 sParams = sParams.substr(1, sParams.length); 4056 4057 tb_show($(this).get(0).title, $.ajaxBox($aParams['call'], sParams)); 4058 4059 return false;
4060 }); 4061}; 4062 4063$Behavior.blockClick = function () { 4064 $('.block .menu ul li a').click(function () { 4065 $(this).parents('.block:first').find('li').removeClass('active'); 4066 $(this).parent().addClass('active'); 4067 4068 if (this.href.match(/#/)) { 4069 var aParts = explode('#', this.href); 4070 var aParams = explode('?', aParts[1]); 4071 var aParamParts = explode('&', aParams[1]); 4072 var aRequest = []; 4073 for (count in aParamParts) { 4074 var aPart = explode('=', aParamParts[count]); 4075 4076 aRequest[aPart[0]] = aPart[1]; 4077 } 4078 4079 $('.js_block_click_lis_cache').remove(); 4080 $.ajaxCall(aParams[0], aParams[1] + '&js_block_click_lis_cache=true', 'GET'); 4081 } 4082 4083 return false; 4084 }); 4085}; 4086 4087$Behavior.deleteLink = function () { 4088 $('.delete_link').click(function () { 4089 var obj = $(this); 4090 $Core.jsConfirm({}, function () { 4091 $aParams = $.getParams(obj.get(0).href); 4092 var sParams = ''; 4093 for (sVar in $aParams) { 4094 sParams += '&' + sVar + '=' + $aParams[sVar] + ''; 4095 } 4096 sParams = sParams.substr(1, sParams.length); 4097 4098 $.ajaxCall($aParams['call'], sParams); 4099 }, function () { 4100 }); 4101 4102 return false; 4103 }); 4104}; 4105 4106$Behavior.globalToolTip = function () { 4107 if ($('#js_global_tooltip').length <= 0) { 4108 $('body').prepend('<div id="js_global_tooltip" style="display:none;"></div>'); 4109 } 4110 4111 if (!PF.isMobile) {
4112 $('.js_hover_title').mouseover(function () { 4113 var _this = $(this), 4114 offset = _this.offset(), 4115 sContent = '', 4116 globalTooltip = $('#js_global_tooltip'); 4117 if (_this.find('.js_hover_info').length && _this.find('.js_hover_info').html() !== null && _this.find('.js_hover_info').html().length < 1) { 4118 } else { 4119 globalTooltip.css('display', 'block'); 4120 if (_this.find('.js_hover_info').length > 0) { 4121 sContent = _this.find('.js_hover_info').html(); 4122 if (_this[0].hasAttribute('title')) { 4123 _this.removeAttr('title'); 4124 } 4125 } else { 4126 var oParent = _this.parent(); 4127 if (!empty(oParent.attr('title'))) { 4128 oParent.data('title', oParent.attr('title')).removeAttr('title'); 4129 sContent = oParent.data('title'); 4130 } else if (typeof oParent.data('title') !== "undefined" && oParent.data('title') !== '') { 4131 sContent = oParent.data('title'); 4132 } else if (oParent.hasClass('img-wrapper') && oParent.parent()[0].hasAttribute('title') && oParent.parent().attr('title') !== '') { 4133 sContent = oParent.parent().attr('title'); 4134 oParent.parent().removeAttr('title'); 4135 if (_this[0].hasAttribute('alt')) { 4136 _this.removeAttr('alt'); 4137 } 4138 oParent.data('title', sContent); 4139 } else if (_this[0].hasAttribute('alt')) { 4140 oParent.data('title', _this.attr('alt')); 4141 _this.removeAttr('alt'); 4142 } 4143 } 4144 4145 if (sContent !== '') { 4146 globalTooltip.html('<div id="js_global_tooltip_display">' + sContent + '</div>'); 4147 globalTooltip.css('top', (offset.top - ($('#js_global_tooltip_display').height() + 10)) + 'px'); 4148 4149 var pos = ($(window).width() - (offset.left + globalTooltip.width())); 4150 if (pos < 10) { 4151 offset.left = (offset.left - globalTooltip.width()) + 20; 4152 } 4153 globalTooltip.css('left', (offset.left - 10) + 'px'); 4154 } 4155 } 4156 }).mouseout(function() { 4157 $('#js_global_tooltip').hide() 4158 .html('') 4159 .css('top', '0px') 4160 .css('left', '0px'); 4161 }); 4162 } 4163}; 4164 4165$Behavior.clearTextareaValue = function () { 4166 $('.js_comment_text_area #text').focus(function () { 4167 if ($(this).val() == $('#js_comment_write_phrase').html()) { 4168 $(this).val(''); 4169 } 4170 }); 4171}; 4172 4173$Behavior.loadEditor = function () { 4174 if ((!getParam('bWysiwyg') || typeof (bForceDefaultEditor) != 'undefined') && typeof (Editor) == 'object') { 4175 Editor.getEditors(); 4176 } 4177}; 4178 4179$Behavior.globalInit = function () { 4180 if (!oParams.hasOwnProperty('bIsAdminCP') || (oParams.hasOwnProperty('bIsAdminCP') && !oParams.bIsAdminCP)) { 4181 $('input[type="text"]:not(.form-control)').addClass('form-control'); 4182 } 4183 $('.js_pager_view_more_link:not(.built)').each(function () { 4184 var t = $(this), 4185 isInView = false, 4186 lastItem = t.parent().find('.pf_video_last_item_paging').val(), 4187 nextPage = t.find('.next_page'), 4188 sPagingVar = nextPage.data('paging') ? nextPage.data('paging') : '' 4189 url = nextPage.attr('href'); 4190 if (typeof lastItem == 'undefined') { 4191 lastItem = 0; 4192 } else { 4193 t.parent().find('.pf_video_last_item_paging').remove(); 4194 } 4195 t.addClass('built'); 4196 var sendData = 'core[ajax]=true' + (t.data('pagination') ? '&pagination=1' : '') + '&last-item=' + lastItem + '&sPagingVar=' + sPagingVar; 4197 if ($(window).width() > 480 && iPageLoadMore <= oParams.iLimitLoadMore && $(window).height() < $('body').height()) { 4198 window.handleItemLoadMoreScroll && $(window).off('scroll', handleItemLoadMoreScroll); 4199 handleItemLoadMoreScroll = function () { 4200 if ($Core.isInView !== undefined) { 4201 if ($Core.isInView(t, 100) && !isInView) { 4202 $Core.ajaxLoadMorePaging(t, url, sendData); 4203 isInView = true; 4204 iPageLoadMore++; 4205 } 4206 } 4207 }; 4208 $(window).on('scroll', handleItemLoadMoreScroll); 4209 } else { 4210 t.addClass('show_load_more'); 4211 nextPage.addClass('dont-unbind'); 4212 nextPage.addClass('btn btn-primary btn-round btn-gradient global_view_more no_ajax_link mobile_load_more').on('click', function (event) { 4213 $Core.ajaxLoadMorePaging(t, url, sendData); 4214 event.preventDefault(); 4215 $(this).removeClass('btn btn-primary btn-round btn-gradient global_view_more mobile_load_more'); 4216 isInView = true; 4217 iPageLoadMore++; 4218 return false;
4219 }); 4220 } 4221 }); 4222 4223 if ($('.set_to_fixed').length) { 4224 $('.set_to_fixed:not(.built)').addClass('dont-unbind').each(function () { 4225 var t = $(this), 4226 o = t.offset(), 4227 isFixed = false; 4228 4229 t.addClass('built'); 4230 4231 window.handleFixedProfileMenu && $(window).off('scroll', handleFixedProfileMenu); 4232 handleFixedProfileMenu = function () { 4233 var total; 4234 var dataClass = t.data('class') || 'profile_menu_is_fixed'; 4235 if ($('body').hasClass(dataClass)) { 4236 total = (o.top - ($(this).scrollTop() + t.height())); 4237 } else { 4238 total = (o.top - $(this).scrollTop()); 4239 } 4240 if (total <= 1 && !isFixed) { 4241 isFixed = true; 4242 $('body').addClass(dataClass); 4243 var menu_more_fixed = $('.profiles_menu ul[data-component="menu"],.profiles-menu ul[data-component="menu"]'); 4244 if (menu_more_fixed.length > 0) { 4245 menu_more_fixed.removeClass('built'); 4246 menu_more_fixed.css('overflow', 'hidden'); 4247 $Behavior.buildMenu(); 4248 4249 } 4250 } 4251 4252 if (isFixed && total >= 2) { 4253 isFixed = false; 4254 $('body').removeClass(dataClass); 4255 var menu_more_fixed = $('.profiles_menu ul[data-component="menu"]'); 4256 4257 if (menu_more_fixed.length > 0) { 4258 menu_more_fixed.removeClass('built'); 4259 menu_more_fixed.css('overflow', 'hidden'); 4260 $Behavior.buildMenu(); 4261 4262 } 4263 } 4264 }; 4265 $(window).on('scroll', handleFixedProfileMenu); 4266 }); 4267 } 4268 4269 $('.user_block_toggle').click(function () { 4270 $('body').toggleClass('user_block_is_active'); 4271 }); 4272 4273 $('.mobile_menu').click(function () { 4274 $('body').toggleClass('show_mobile_menu'); 4275 $('body').removeClass('panel_is_active'); 4276 }); 4277 4278 $('.feed_form_toggle').unbind().click(function () { 4279 $('.feed_form_menu').slideToggle('fast'); 4280 }); 4281 4282 $('.feed_form_share:not(.active)').click(function () { 4283 var t = $(this), 4284 f = t.parents('form:first'); 4285 4286 t.addClass('feed_form_share'); 4287 $.ajax({ 4288 url: f.attr('action'), 4289 type: 'POST', 4290 data: f.serialize(), 4291 complete: function (e) { 4292 $Core.resetFeedForm(f); 4293 eval(e.responseText); 4294 } 4295 }); 4296 4297 return false; 4298 }); 4299 4300 $('.cancel_post').click(function () { 4301 $('._load_is_feed').removeClass('active'); 4302 $('body').removeClass('panel_is_active'); 4303 $('#panel').hide(); 4304 }); 4305 $('.feed_form_textarea textarea').keydown(function () { 4306 $Core.resizeTextarea($(this)); 4307 }); 4308 4309 $('.feed_form_textarea textarea:not(.dont-unbind)').click(function () { 4310 var t = $(this); 4311 4312 t.addClass('dont-unbind'); 4313 t.parents('form:first').addClass('active'); 4314 }); 4315 4316 $('._panel').click(function () { 4317 $Core.openPanel($(this)); 4318 4319 return false; 4320 }); 4321 4322 if ($('.mosaicflow_load:not(.built_flow)').length) { 4323 var mLoad = setInterval(function () { 4324 if (typeof (jQuery().mosaicflow) == 'function') { 4325 if ($('.mosaicflow_load.built_flow').length == 0) { 4326 4327 4328 $('.mosaicflow_load').mosaicflow({ 4329 minItemWidth: $('.mosaicflow_load').data('width'), 4330 itemHeightCalculation: 'auto' 4331 }); 4332 4333 $('.mosaicflow_load').addClass('built_flow'); 4334 } else { 4335 var firstContainer = $('.mosaicflow_load.built_flow').first(); 4336 $('.mosaicflow_load:not(.built_flow)').each(function () { 4337 $(this).find('article.photos_row').each(function () { 4338 firstContainer.mosaicflow('add', $(this)); 4339 }); 4340 $(this).remove(); 4341 }); 4342 } 4343 clearInterval(mLoad); 4344 } 4345 }, 500); 4346 } 4347 4348 $('.image_deferred:not(.built)').each(function () { 4349 var t = $(this), 4350 src = t.data('src'), 4351 i = new Image(); 4352 4353 t.addClass('built'); 4354 if (!src) { 4355 t.addClass('no_image'); 4356 return; 4357 } 4358 4359 t.addClass('has_image'); 4360 i.onerror = function (e, u) { 4361 var fallback = t.data('fallback'); 4362 if (fallback) { 4363 var fallbackImage = new Image(); 4364 fallbackImage.onload = function () { 4365 t.attr('src', fallback); 4366 t.attr('data-fallback', ''); 4367 } 4368 fallbackImage.onerror = function () { 4369 t.replaceWith(''); 4370 } 4371 fallbackImage.src = fallback; 4372 } else { 4373 t.replaceWith(''); 4374 } 4375 }; 4376 i.onload = function (e) { 4377 t.attr('src', src); 4378 }; 4379 i.src = src; 4380 }); 4381 4382 $('.image_load:not(.built)').each(function () { 4383 var t = $(this), 4384 src = t.data('src'), 4385 fallback = t.data('fallback'), 4386 image = new Image(); 4387 4388 t.addClass('built'); 4389 if (!src) { 4390 t.addClass('no_image'); 4391 return; 4392 } 4393 4394 t.addClass('has_image'); 4395 image.onload = function (e) { 4396 if (t.hasClass('parent-block')) { 4397 var parentClass = t.data('apply'); 4398 var main = t.data('main'); 4399 if (parentClass) { 4400 if (main) { 4401 $(main + ' .' + parentClass).css('background-image', 'url("' + src + '")'); 4402 } else { 4403 $('#main .' + parentClass).css('background-image', 'url("' + src + '")'); 4404 } 4405 } 4406 } else { 4407 t.css('background-image', 'url("' + src + '")'); 4408 } 4409 }; 4410 4411 if (fallback) { 4412 var fallbackImage = new Image(); 4413 4414 image.onerror = function () { 4415 fallbackImage.src = fallback; 4416 }; 4417 4418 fallbackImage.onload = function (e) { 4419 if (t.hasClass('parent-block')) { 4420 var parentClass = t.data('apply'); 4421 var main = t.data('main'); 4422 if (parentClass) { 4423 if (main) { 4424 $(main + ' .' + parentClass).css('background-image', 'url("' + fallback + '")'); 4425 } else { 4426 $('#main .' + parentClass).css('background-image', 'url("' + fallback + '")'); 4427 } 4428 } 4429 } else { 4430 t.css('background-image', 'url("' + fallback + '")'); 4431 } 4432 }; 4433 } 4434 4435 image.src = src; 4436 }); 4437 4438 $('.moderate_link:not(.built)').each(function () { 4439 var t = $(this), 4440 parents, 4441 html = '', 4442 obj; 4443 var location = t.data('id'); 4444 if (location == 'mod') { 4445 t.html('<i class="fa"></i>'); 4446 } 4447 t.addClass('built'); 4448 if (t.parents('.table_row:first').length) { 4449 parents = t.parents('.table_row:first').parent(); 4450 } else if (t.parents('.moderation_row:first').length) { 4451 parents = t.parents('.moderation_row:first'); 4452 } else { 4453 parents = t.parents('article:first'); 4454 } 4455 4456 obj = $('<div class="_moderator">' + html + '</div>'); 4457 4458 // html += t.clone(); 4459 4460 parents.before(obj); 4461 4462 // parents.find('.') 4463 4464 if (t.parent().find('.row_edit_bar_parent').length) { 4465 4466 t.parent().find('.row_edit_bar_parent').prependTo(obj); 4467 } 4468 t.prependTo(obj); 4469 if (location == 'user') { 4470 //t.parent().remove(); 4471 } 4472 4473 if (obj.width() > 0) { 4474 parents.addClass('has-visible-moderator'); 4475 } 4476 }); 4477 4478 // Confirm before deleting an item 4479 $('.sJsConfirm').off('click').on('click', function () { 4480 var message = ($(this).data('message')) ? $(this).data('message') : oTranslations['are_you_sure'], 4481 loadRight = $(this).data('right'), 4482 url = $(this).attr('href'), 4483 form = $(this).closest('form'); 4484 4485 if ($(this).is('a')) { 4486 if (url == '' || url == '#') { 4487 url = window.location.href; 4488 } 4489 $Core.jsConfirm({message: message}, function () { 4490 window.location.href = url; 4491 }, function () { 4492 }, loadRight); 4493 return false;
4494 } else if (($(this).is('input[type="submit"]') || $(this).is('button')) && $(this).closest('form').length > 0) { 4495 $('<input />').attr('type', 'hidden') 4496 .attr('name', $(this).attr('name')) 4497 .attr('value', $(this).attr('value')) 4498 .appendTo(form); 4499 4500 $Core.jsConfirm({message: message}, function () { 4501 form.submit(); 4502 }, function () { 4503 }, loadRight); 4504 return false; 4505 } 4506 return confirm(message); 4507 }); 4508 4509 $('#select_lang_pack').off('click').on('click', function () { 4510 tb_show(oTranslations['language_packages'], $.ajaxBox('language.select', 'height=300&width=300')); 4511 4512 return false; 4513 }); 4514 4515 if (!oCore['core.is_admincp']) { 4516 if ($('#country_iso').length > 0 && !empty(oCore['core.country_iso'])) { 4517 if (empty($('#country_iso').val())) { 4518 $('#js_country_iso_option_' + oCore['core.country_iso']).attr('selected', true); 4519 } 4520 } 4521 } 4522 4523 $('.js_item_active').each(function () { 4524 var t = $(this).find('input'), 4525 i = t.parents('.item_is_active_holder:first'); 4526 4527 if (t.prop('checked')) { 4528 if (t.parent().hasClass('item_is_active')) { 4529 i.addClass('item_selection_active'); 4530 } else { 4531 i.addClass('item_selection_not_active'); 4532 } 4533 } 4534 $(this).removeClass('hide'); 4535 }); 4536 4537 $('.js_item_active').off('click', $Core.toggleButton).on('click', $Core.toggleButton); 4538 4539 if ($('.moderate_link').length > 0) { 4540 $('.moderation_drop').unbind('click'); 4541 $('.moderation_drop').click(function () { 4542 if (parseInt($('.js_global_multi_total').html()) === 0) { 4543 return false; 4544 } 4545 4546 if ($(this).hasClass('is_clicked')) { 4547 $('.moderation_holder ul').hide(); 4548 $(this).removeClass('is_clicked'); 4549 } else { 4550 $('.moderation_holder ul').show(); 4551 $(this).addClass('is_clicked'); 4552 } 4553 4554 return false; 4555 }); 4556 4557 var iEmptyModLinks = 0; 4558 var iSelectItems = 0; 4559 var sView = (typeof moderationViewString !== 'undefined') ? moderationViewString : ''; 4560 $('.moderate_link').each(function () { 4561 var sCookieName = 'js_' + (sView != '' ? sView + '_' : '') + 'item_m_' + $(this).attr('rel') + '_' + $(this).attr('href').replace('#', ''); 4562 if (getCookie(sCookieName)) { 4563 $(this).addClass('moderate_link_active'); 4564 $(this).parent().addClass('moderator_active'); 4565 iSelectItems++; 4566 } else { 4567 iEmptyModLinks++; 4568 } 4569 }); 4570 4571 if (iEmptyModLinks === 0) { 4572 $('.moderation_action_unselect').show(); 4573 $('.moderation_action_select').hide(); 4574 } 4575 4576 $('.js_global_multi_total').html(iSelectItems); 4577 $('.js_global_multi_total').parent().show(); 4578 } 4579 4580 $('.moderation_clear_all').click(function () { 4581 $Core.moderationLinkClear(); 4582 4583 return false; 4584 }); 4585 4586 $('.moderation_action').click(function () { 4587 var sType = $(this).attr('rel'); 4588 4589 $(this).hide(); 4590 4591 if (sType == 'select') { 4592 $('.moderation_action_unselect').show(); 4593 } else { 4594 $('.moderation_action_select').show(); 4595 } 4596 4597 $('.moderate_link').each(function () { 4598 $Core.moderationLinkClick(this, sType); 4599 }); 4600 4601 return false; 4602 }); 4603 4604 $('.moderate_link').unbind('click'); 4605 $('.moderate_link').click(function () { 4606 return $Core.moderationLinkClick(this); 4607 }); 4608 4609 $('.page_section_menu ul li a').click(function () { 4610 // remove error message when click another tab 4611 $('#core_js_messages').remove(); 4612 4613 var sRel = $(this).attr('rel'); 4614 if (empty(sRel)) { 4615 return true; 4616 } 4617 $('.page_section_menu ul li').removeClass('active'); 4618 $('.page_section_menu_holder').hide(); 4619 $('#' + sRel).show(); 4620 $(this).parent().addClass('active'); 4621 4622 if ($('#page_section_menu_form').length > 0) { 4623 $('#page_section_menu_form').val(sRel); 4624 } 4625 // set current tab 4626 $('#current_tab').val($(this).attr('href').replace('#', '')); 4627 4628 return false; 4629 }); 4630 4631 $('.js_date_picker').each(function () { 4632 var $this = $(this), 4633 $holder = $this.closest('.js_datepicker_holder'), 4634 $year = $('.js_datepicker_year', $holder), 4635 minYear, 4636 maxYear, 4637 sFormat = oParams['sDateFormat']; 4638 4639 if (typeof pf_select_date_sort_desc !== 'undefined' && pf_select_date_sort_desc) { 4640 minYear = $('option:last', $year).val() || 0; 4641 maxYear = parseInt($('option:eq(0)', $year).val()) > 0 ? $('option:eq(0)', $year).val() : (parseInt($('option:eq(1)', $year).val()) > 0 ? $('option:eq(1)', $year).val() : 0); 4642 } else { 4643 minYear = parseInt($('option:eq(0)', $year).val()) > 0 ? $('option:eq(0)', $year).val() : (parseInt($('option:eq(1)', $year).val()) > 0 ? $('option:eq(1)', $year).val() : 0); 4644 maxYear = $('option:last', $year).val() || 0; 4645 } 4646 4647 if (minYear && maxYear && minYear > maxYear) { 4648 var temp = minYear; 4649 minYear = maxYear; 4650 maxYear = temp; 4651 } 4652 4653 sFormat = sFormat.charAt(0) + '/' + sFormat.charAt(1) + '/' + sFormat.charAt(2); 4654 sFormat = sFormat.replace('D', 'd').replace('M', 'm').replace('Y', 'yy'); 4655 4656 $this.datepicker('destroy'); 4657 4658 if (!minYear) { 4659 minYear = '-100'; 4660 } 4661 if (!maxYear) { 4662 maxYear = '+10'; 4663 } 4664 4665 $('.js_date_picker', $holder).prop('readonly', true); 4666 $this.datepicker({ 4667 dateFormat: sFormat, 4668 changeYear: true, 4669 yearRange: minYear + ':' + maxYear, 4670 beforeShow: function () { 4671 $this.trigger("datepicker.before_show", minYear, maxYear); 4672 }, 4673 onSelect: function (dateText) { 4674 var aParts = explode('/', dateText), 4675 sMonth, 4676 sDay, 4677 sYear; 4678 4679 switch (oParams['sDateFormat']) { 4680 case 'YMD': 4681 sMonth = ltrim(aParts[1], '0'); 4682 sDay = ltrim(aParts[2], '0'); 4683 sYear = aParts[0]; 4684 break; 4685 case 'DMY': 4686 sMonth = ltrim(aParts[1], '0'); 4687 sDay = ltrim(aParts[0], '0'); 4688 sYear = aParts[2]; 4689 break; 4690 default: 4691 sMonth = ltrim(aParts[0], '0'); 4692 sDay = ltrim(aParts[1], '0'); 4693 sYear = aParts[2]; 4694 break; 4695 } 4696 4697 $('.js_datepicker_month', $holder).val(sMonth).trigger('change'); 4698 $('.js_datepicker_day', $holder).val(sDay).trigger('change'); 4699 $('.js_datepicker_year', $holder).val(sYear).trigger('change'); 4700 } 4701 }); 4702 4703 $holder.find('.js_datepicker_image').click(function () { 4704 $this.datepicker('show'); 4705 }); 4706 4707 }); 4708 4709 if ($('.js_date_picker_meridiem_select').length) { 4710 function onChangeMeridiemPicker(event) { 4711 var ele = event.target, 4712 prefix = $(ele).data('prefix'), 4713 hourSelect = $('#' + prefix + 'hour'); 4714 if (hourSelect.length) { 4715 var selectedOption = hourSelect.find('option:selected'), 4716 timeValue = selectedOption.data('value'), 4717 meridiem = $(ele).val(); 4718 if (meridiem === 'am') { 4719 hourSelect.find('option').each(function(index, item) { 4720 $(item).attr('value', $(item).data('value-am')); 4721 }); 4722 hourSelect.val(selectedOption.data('value-am')); 4723 } else { 4724 hourSelect.find('option').each(function(index, item) { 4725 $(item).attr('value', $(item).data('value-pm')); 4726 }); 4727 hourSelect.val( selectedOption.data('value-pm')); 4728 } 4729 } 4730 return false;
4731 } 4732 $('.js_date_picker_meridiem_select').off('change', onChangeMeridiemPicker).on('change', onChangeMeridiemPicker); 4733 } 4734 4735 $('#js_login_as_page').click(function () { 4736 $Core.box('pages.login', 500); 4737 return false; 4738 }); 4739 4740 $('.mobile_view_options').click(function () { 4741 $('#js_mobile_form_holder').toggle(); 4742 4743 return false; 4744 }); 4745 4746 if (typeof $.browser != 'undefined' && $.browser.msie && parseInt($.browser.version, 10) < 8 && !getParam('bJsIsMobile')) { 4747 $('#js_update_internet_explorer').show(); 4748 } 4749}; 4750 4751$Behavior.fixLayoutGrid = function () { 4752 if ($('section#site-header').length) { 4753 $('#content-holder').css({ 4754 minHeight: Math.max($(window).height() - $('section#site-header').height() - $('footer').height(), $('#left').height()) 4755 }); 4756 } 4757 4758 PF.event.trigger('on_page_column_init_end'); 4759}; 4760 4761$Behavior.janRainLoader = function () { 4762 if ($Core.hasPushState()) { 4763 $('._a_multiple_back').on('click', function() { 4764 if (self == top) { 4765 history.back(); 4766 } else { 4767 window.parent.history.back(); 4768 } 4769 return false; 4770 }); 4771 } 4772 $('._a_back').click(function () { 4773 $('.imgareaselect-outer').remove(); 4774 $('.imgareaselect-selection').each(function () { 4775 $(this).parent().remove(); 4776 }); 4777 4778 if (typeof (cacheCurrentBody.main) == 'string') { 4779 $Core.buildPageFromCache = true; 4780 $('#main').html(cacheCurrentBody.main); 4781 $('#main').attr('class', cacheCurrentBody.mainClass); 4782 $('body').attr('id', cacheCurrentBody.id); 4783 $('body').attr('class', cacheCurrentBody.class); 4784 // breadcrumb 4785 $('.location_6').html(cacheCurrentBody['location_6']); 4786 4787 // reset active menu 4788 $('.site_menu a.menu_is_selected').removeClass('menu_is_selected'); 4789 if (typeof $Core.lastActiveMenu !== 'undefined') { 4790 $('li[rel=' + $Core.lastActiveMenu + '] > a').addClass('menu_is_selected'); 4791 var selectedMenu = $('.site_menu:first li a.menu_is_selected:last'); 4792 var html = selectedMenu.length ? selectedMenu.html() : ''; 4793 $('.js-btn-collapse-main-nav').each(function () { 4794 if ($(this).hasClass('link')) { 4795 html = selectedMenu.length ? selectedMenu.clone() : ''; 4796 $(this).empty().append(html); 4797 } else { 4798 $(this).html(html); 4799 } 4800 }); 4801 } 4802 4803 history.pushState(null, null, lastPushState); 4804 document.title = cacheCurrentBody.title; 4805 $('html, body').animate({ 4806 scrollTop: cacheCurrentBody.scrollTop 4807 }, 400); 4808 $Core.loadInit(); 4809 } 4810 $('.js_pager_view_more_link').last().removeClass('built'); 4811 4812 $Behavior.globalInit(); 4813 }); 4814}; 4815 4816var close_warning_checked = false; 4817var close_warning_enabled = true; 4818 4819$Core.reloadValidation = { 4820 initEleData: {}, 4821 changedEleData: {}, 4822 init: function() { 4823 this.reset(true); 4824 this.store(); 4825 this.validate(); 4826 }, 4827 initClosePopupWithForm: function (ele) { 4828 var oEle = $(ele), oForm = oEle.find('form'); 4829 if (!oForm.length) { 4830 return false; 4831 } 4832 var formId = oForm.attr('id'); 4833 if (formId === undefined || formId === '') { 4834 oForm.attr('id', oEle.attr('id') + '_form_' + Math.random().toString(36).substring(7)); 4835 } 4836 var form = oForm.get(0); 4837 this.store(form); 4838 this.validate(form); 4839 return true; 4840 }, 4841 preventReload: function(hardReload) { 4842 var isPrevent = false; 4843 if (hardReload !== true) { 4844 if (typeof hardReload === 'string') { 4845 isPrevent = this.changedEleData.hasOwnProperty(hardReload) && Object.keys(this.changedEleData[hardReload]).length; 4846 } else { 4847 isPrevent = Object.keys(this.changedEleData).length; 4848 if (isPrevent) { 4849 isPrevent = false; 4850 $.each($Core.reloadValidation.changedEleData, function(key, changedValues) { 4851 if (typeof changedValues === 'object') { 4852 isPrevent = Object.keys(changedValues).length; 4853 } 4854 if (isPrevent) { 4855 return false; 4856 } 4857 }); 4858 } 4859 } 4860 } 4861 4862 close_warning_enabled = !!isPrevent; 4863 close_warning_checked = !!isPrevent; 4864 window.onbeforeunload = isPrevent ? function () { 4865 return false;
4866 } : null; 4867 }, 4868 checkPrivacyFormChange: function() { 4869 var _this = $(this), 4870 parentForm = null, 4871 parentObjectId = _this.closest('.privacy_setting_div').data('parent-object-id'); 4872 4873 if (!parentObjectId) { 4874 parentForm = _this.closest('form'); 4875 if (!parentForm.length) { 4876 return false; 4877 } 4878 } 4879 4880 var parentId = parentObjectId ? parentObjectId : parentForm.attr('id'); 4881 if (!parentId) { 4882 return false; 4883 } 4884 4885 if (!$Core.reloadValidation.changedEleData.hasOwnProperty(parentId)) { 4886 $Core.reloadValidation.changedEleData[parentId] = {}; 4887 } 4888 4889 var eleVal = _this.attr('rel'), 4890 parentDiv = _this.closest('.privacy_setting_div'), 4891 inputName = parentDiv.find('input[type="hidden"]').attr('name'), 4892 isChanged = eleVal !== $Core.reloadValidation.initEleData[parentId][inputName]; 4893 4894 if (isChanged) { 4895 $Core.reloadValidation.changedEleData[parentId][inputName] = true; 4896 } else if ($Core.reloadValidation.changedEleData[parentId].hasOwnProperty(inputName)) { 4897 delete $Core.reloadValidation.changedEleData[parentId][inputName]; 4898 } 4899 $Core.reloadValidation.preventReload(parentObjectId ? parentObjectId : null); 4900 }, 4901 store: function(obj, forceInput) { 4902 var parentObject = this, 4903 parentObjectContainer = $(obj).length ? $(obj) : null, 4904 parentObjectId = parentObjectContainer !== null ? parentObjectContainer.attr('id') : null, 4905 closeWarnings = parentObjectContainer !== null ? $('.close_warning', parentObjectContainer) : $('form .close_warning'), 4906 uploadForms = parentObjectContainer !== null ? $('[data-component="dropzone"][data-upload-multiple="false"][data-auto-process-queue="true"][data-upload-style="mini"]', parentObjectContainer) : $('form [data-component="dropzone"][data-upload-multiple="false"][data-auto-process-queue="true"][data-upload-style="mini"]'), 4907 privacyForms = parentObjectContainer !== null ? $('.privacy_setting_div', parentObjectContainer) : $('form .privacy_setting_div'); 4908 if (forceInput && parentObjectContainer) { 4909 closeWarnings = $(parentObjectContainer).find('input, select, textarea'); 4910 } 4911 4912 closeWarnings.each(function() { 4913 var _this = $(this), 4914 eleName = this.name, 4915 eleType = this.type || this.tagName.toLowerCase(); 4916 parentObjectId = parentObjectContainer !== null ? parentObjectId : _this.closest('form').attr('id'); 4917 if (parentObjectId) { 4918 if (!parentObject.initEleData.hasOwnProperty(parentObjectId)) { 4919 parentObject.initEleData[parentObjectId] = {}; 4920 } 4921 if (!isset(parentObject.initEleData[parentObjectId][eleName])) { 4922 if (['radio', 'checkbox'].indexOf(eleType) !== -1) { 4923 if (eleType === 'radio') { 4924 parentObject.initEleData[parentObjectId][eleName] = $('input[type="radio"][name="' + eleName + '"]:checked').length ? trim($('input[type="radio"][name="' + eleName + '"]:checked').val()) : ''; 4925 } else { 4926 parentObject.initEleData[parentObjectId][eleName] = _this.prop('checked') ? [trim(_this.val())] : []; 4927 } 4928 } else if (eleType === 'textarea' && _this.data('ckeditor_built')) { 4929 parentObject.initEleData[parentObjectId][eleName] = trim(CKEDITOR.instances[_this.attr('id')].getData()); 4930 } else { 4931 var eleVal = _this.val(); 4932 if (typeof eleVal === "undefined" || eleVal === null) { 4933 eleVal = ''; 4934 } 4935 parentObject.initEleData[parentObjectId][eleName] = typeof eleVal === 'string' ? trim(eleVal) : eleVal; 4936 } 4937 } else if (Array.isArray(parentObject.initEleData[parentObjectId][eleName])) { 4938 if (eleType === 'checkbox' && _this.prop('checked')) { 4939 parentObject.initEleData[parentObjectId][eleName].push(trim(_this.val())); 4940 } 4941 } 4942 } 4943 }); 4944 4945 if (uploadForms.length) { 4946 uploadForms.each(function() { 4947 var _formThis = $(this); 4948 parentObjectId = parentObjectContainer !== null ? parentObjectId : _formThis.closest('form').attr('id'); 4949 //Only support upload forms with single file 4950 if (_formThis.closest('.special_close_warning').length && _formThis.closest('.js_upload_form_wrapper').length && parentObjectId) { 4951 var dropzoneId = _formThis.data('dropzone-id'), 4952 dropzoneObject = $Core.dropzone.instance[dropzoneId], 4953 isFormEdit = _formThis.closest('.js_upload_form_wrapper').find('.js_upload_form_current a.remove').length; 4954 dropzoneObject.off('success').on('success', function(file, response) { 4955 if (_formThis.data('on-success')) { 4956 $Core.executeFunctionByName(_formThis.data('on-success'), window, _formThis, file, response); 4957 } 4958 if (!parentObject.changedEleData.hasOwnProperty(parentObjectId)) { 4959 parentObject.changedEleData[parentObjectId] = {}; 4960 } 4961 parentObject.changedEleData[parentObjectId][dropzoneId] = true; 4962 parentObject.preventReload(); 4963 if (_formThis.find('div.dz-remove-file').length) { 4964 _formThis.find('div.dz-remove-file').on('click', function() { 4965 if (!isFormEdit && parentObject.changedEleData[parentObjectId].hasOwnProperty(dropzoneId)) { 4966 delete parentObject.changedEleData[parentObjectId][dropzoneId]; 4967 } 4968 parentObject.preventReload(); 4969 }); 4970 } 4971 }); 4972 if (isFormEdit) { 4973 var removeImageBtn = _formThis.closest('.js_upload_form_wrapper').find('.js_upload_form_current a.remove'), 4974 currentOnclickContent = removeImageBtn.attr('onclick'); 4975 if (currentOnclickContent.match(/Core.uploadForm.deleteImage/)) { 4976 removeImageBtn.attr('onclick', '$Core.reloadValidation.changedEleData["' + parentObjectId + '"]["' + dropzoneId + '"] = true; $Core.reloadValidation.preventReload(); ' + currentOnclickContent); 4977 } 4978 } 4979 } 4980 }); 4981 } 4982 4983 if (privacyForms.length) { 4984 privacyForms.each(function() { 4985 var _privacyThis = $(this); 4986 parentObjectId = parentObjectContainer !== null ? parentObjectId : _privacyThis.closest('form').attr('id'); 4987 if (_privacyThis.closest('.special_close_warning').length && parentObjectId) { 4988 if (!parentObject.initEleData.hasOwnProperty(parentObjectId)) { 4989 parentObject.initEleData[parentObjectId] = {}; 4990 } 4991 if (parentObjectContainer !== null) { 4992 _privacyThis.data('parent-object-id', parentObjectId); 4993 } 4994 var inputEle = _privacyThis.find('input[type="hidden"]'), 4995 inputEleName = inputEle.attr('name'); 4996 parentObject.initEleData[parentObjectId][inputEleName] = inputEle.val(); 4997 privacyForms.find('[data-toggle="privacy_item"]').on('click', parentObject.checkPrivacyFormChange); 4998 } 4999 }); 5000 } 5001 }, 5002 validate: function(obj, forceInput) { 5003 var parentObject = this, 5004 parentObjectContainer = $(obj).length ? $(obj) : null, 5005 parentObjectId = parentObjectContainer !== null ? parentObjectContainer.attr('id') : null, 5006 closeWarnings = parentObjectContainer !== null ? $('.close_warning', parentObjectContainer) : $('form .close_warning'); 5007 if (forceInput && parentObjectContainer) { 5008 closeWarnings = $(parentObjectContainer).find('input, select, textarea'); 5009 } 5010 closeWarnings.each(function() { 5011 var _this = $(this), 5012 eleType = this.type || this.tagName.toLowerCase(), 5013 eleName = this.name, 5014 parentForm = _this.closest('form'); 5015 if (parentObjectContainer === null) { 5016 parentObjectId = parentForm.attr('id'); 5017 } 5018 5019 if (parentObjectId && parentObject.initEleData.hasOwnProperty(parentObjectId)) { 5020 var initEleData = parentObject.initEleData[parentObjectId].hasOwnProperty(eleName) ? parentObject.initEleData[parentObjectId][eleName] : '', 5021 isEdit = typeof initEleData !== "undefined" && initEleData !== '' && initEleData !== null; 5022 if (!_this.closest('form').hasClass('dont-unbind-children')) { 5023 _this.closest('form').addClass('dont-unbind-children'); 5024 } 5025 if (!parentObject.changedEleData.hasOwnProperty(parentObjectId)) { 5026 parentObject.changedEleData[parentObjectId] = {}; 5027 } 5028 5029 if (eleType === 'textarea' && _this.data('ckeditor_built')) { 5030 var onChangeCKeditor = function() { 5031 var isNotChange = true, 5032 eleVal = trim(CKEDITOR.instances[_this.attr('id')].getData()); 5033 if ((!isEdit && typeof eleVal !== "undefined" && eleVal !== '' && eleVal !== null) || (isEdit && eleVal !== initEleData)) { 5034 isNotChange = false;
5035 parentObject.changedEleData[parentObjectId][eleName] = true; 5036 } 5037 if (isNotChange && parentObject.changedEleData[parentObjectId].hasOwnProperty(eleName)) { 5038 delete parentObject.changedEleData[parentObjectId][eleName]; 5039 } 5040 parentObject.preventReload(); 5041 } 5042 if (typeof CKEDITOR.instances[_this.attr('id')].model === "object") { 5043 CKEDITOR.instances[_this.attr('id')].model.document.on('change', onChangeCKeditor); 5044 } else { 5045 CKEDITOR.instances[_this.attr('id')].on('change', onChangeCKeditor); 5046 } 5047 } else { 5048 _this.on('change keydown', function () { 5049 var _this = $(this), 5050 eleVal = '', 5051 isNotChange = true; 5052 if (eleType === 'radio') { 5053 eleVal = $('[name="' + eleName + '"]:checked', parentForm).val(); 5054 } else if (eleType === 'checkbox') { 5055 var tempValue = []; 5056 $('[name="' + eleName + '"]:checked', parentForm).each(function(){ 5057 tempValue.push(_this.val()); 5058 }); 5059 eleVal = tempValue; 5060 } else { 5061 eleVal = _this.val(); 5062 } 5063 5064 if (Array.isArray(eleVal)) { 5065 if (eleVal.toString() !== initEleData.toString()) { 5066 isNotChange = false; 5067 parentObject.changedEleData[parentObjectId][eleName] = true; 5068 } 5069 } else if ((!isEdit && typeof eleVal !== "undefined" && eleVal !== '' && eleVal !== null) || (isEdit && eleVal !== initEleData)) { 5070 isNotChange = false; 5071 parentObject.changedEleData[parentObjectId][eleName] = true; 5072 } 5073 if (isNotChange && parentObject.changedEleData[parentObjectId].hasOwnProperty(eleName)) { 5074 delete parentObject.changedEleData[parentObjectId][eleName]; 5075 } 5076 parentObject.preventReload(parentObjectContainer !== null ? parentObjectId : null); 5077 }); 5078 } 5079 } 5080 }); 5081 }, 5082 reset: function(resetVariable, parentObjectId, deleteParentObject) { 5083 if (resetVariable && typeof close_warning_checked !== "undefined" && typeof close_warning_enabled !== "undefined") { 5084 close_warning_enabled = false; 5085 close_warning_checked = false; 5086 } 5087 if (parentObjectId) { 5088 if (this.initEleData.hasOwnProperty(parentObjectId) && deleteParentObject) { 5089 delete this.initEleData[parentObjectId]; 5090 } 5091 if (this.changedEleData.hasOwnProperty(parentObjectId)) { 5092 if (deleteParentObject) { 5093 delete this.changedEleData[parentObjectId]; 5094 } else { 5095 this.changedEleData[parentObjectId] = {}; 5096 } 5097 } 5098 } else { 5099 this.initEleData = {}; 5100 this.changedEleData = {}; 5101 window.onbeforeunload = null; 5102 } 5103 } 5104} 5105 5106$Core.googleAuth = { 5107 oAuthObject: null, 5108 initGoogleLoginOnHeader: function () { 5109 var guestHeader = $('.guest-login-small, .guest_login_small, .login-menu-btns-xs'); 5110 if (!guestHeader.length || guestHeader.find('.js_google_button').length) { 5111 return false; 5112 } 5113 $Core.ajax('user.addGoogleLoginBtn', { 5114 type: 'GET', 5115 params: { 5116 'small_size': true 5117 }, 5118 success: function (oData) { 5119 if (oData.length) { 5120 guestHeader.addClass('google-login-wrapper'); 5121 guestHeader.append(oData); 5122 } 5123 } 5124 }); 5125 }, 5126 attachGoogleSignIn: function (element) { 5127 if ($(element).prop('built')) { 5128 return false; 5129 } 5130 $(element).prop('built', true).addClass('dont-unbind'); 5131 $(element).on('click', function () { 5132 $Core.googleAuth.oAuthObject.requestAccessToken(); 5133 }); 5134 }, 5135 buildGoogleSignInButton: function (id) { 5136 if (typeof google === "undefined" || typeof google.accounts === "undefined" 5137 || !$(id).length || $(id).prop('built') || !getParam('sGoogleOAuthId')) { 5138 return false; 5139 } 5140 if (this.oAuthObject !== null) { 5141 $Core.googleAuth.attachGoogleSignIn($(id).get(0)); 5142 } 5143 try { 5144 $Core.googleAuth.oAuthObject = google.accounts.oauth2.initTokenClient({ 5145 client_id: getParam('sGoogleOAuthId'), 5146 ux_mode: 'popup', 5147 scope: 'email profile', 5148 callback: function (response) { 5149 if (response.access_token) { 5150 NProgress.start(); 5151 $.ajaxCall('user.authGoogleUserLogin', $.param({ 5152 'token': response.access_token 5153 })); 5154 } 5155 }, 5156 }); 5157 $Core.googleAuth.attachGoogleSignIn($(id).get(0)); 5158 } catch (e) { 5159 console.log('Error Init', e) 5160 } 5161 } 5162} 5163 5164$Behavior.close_warning_event = function () { 5165 $('input[type="submit"]').on('submit click', function () { 5166 $Core.reloadValidation.preventReload(true); 5167 }); 5168 $('button[type="submit"]').on('submit click', function () { 5169 $Core.reloadValidation.preventReload(true); 5170 }); 5171 $('form').on('submit', function () { 5172 $Core.reloadValidation.preventReload(true); 5173 }); 5174}; 5175 5176$Behavior.addExpanderListener = function () { 5177 $('[data-expand="expander"]').off('click').click(function () { 5178 var $this = $(this), 5179 target = $($this.data('target')); 5180 if (target.length) { 5181 target.toggleClass('close'); 5182 } 5183 }); 5184 5185 var ft = $('#section-footer'), st = $('#content-stage'); 5186 5187 if (ft.length && st.length && ((ft.offset().top + ft.outerHeight(true)) < $(window).height())) { 5188 var lm = st.parent(); 5189 st.css({ 5190 minHeight: $(window).height() - st.offset().top - ft.outerHeight(true) - parseInt(lm.css('margin-bottom')) - 1 5191 }); 5192 } 5193}; 5194 5195$Behavior.addModerationListener = function () { 5196 var m = $('#public_message'); 5197 if (m.length && m.html().length && (typeof $Core.buildPageFromCache !== 'undefined' || !$Core.buildPageFromCache)) { 5198 m.show(); 5199 m.animate({ 5200 'margin-bottom': '0px', 5201 }, 'fast', function () { 5202 if (m.data('auto-close') != false) { 5203 setTimeout(function () { 5204 $Core.publicMessageSlideDown(); 5205 }, 3000); 5206 } 5207 }); 5208 } 5209 5210 $(window).on('moderation_ended', function () { 5211 /* Search for moderation rows */ 5212 if ($('.moderation_row:visible').length < 1) { 5213 if ($('a.pager_previous_link').length > 0 && 5214 $('a.pager_previous_link:first').attr('href') != '#') { 5215 window.location.href = $('a.pager_previous_link:first').attr('href'); 5216 return; 5217 } 5218 5219 if (window.location.href.indexOf('page_1') > (-1)) { 5220 window.location.href = window.location.href.replace('/page_1', ''); 5221 return; 5222 } 5223 5224 return $Core.reloadPage(); 5225 5226 /* Check if we have a pager */ 5227 5228 if ($('a.pager_next_link').length > 0) { 5229 if (isset($Core.Pager) && isset($Core.Pager.count) && 5230 ($Core.Pager.count - $Core.Pager.size) > 20) { 5231 window.location.href = $('a.pager_next_link:first').attr('href'); 5232 return; 5233 } 5234 window.location.href = $('a.pager_next_link:first').attr('href'); 5235 } else { 5236 window.location.href = window.location.href; 5237 } 5238 } else if ($('.moderation_row:first').is(':animated')) { 5239 setTimeout('$(window).trigger("moderation_ended");', 1000); 5240 } 5241 }); 5242}; 5243 5244/* We use the block core.delayed-block as placeholder */ 5245$Behavior.loadDelayedBlocks = function () { 5246 if (isset($Core.delayedBlocks) && Object.prototype.toString.call($Core.delayedBlocks).indexOf('Array') > (-1)) { 5247 // we could issue several ajax calls (one per location) 5248 $.ajaxCall('core.loadDelayedBlocks', 'locations=' + $Core.delayedBlocks.join(',')); 5249 } 5250 5251 /* We load the main content (the middle column) here */ 5252 if ($('#delayed_block').length > 0) { 5253 if ( //oCore['profile.is_user_profile'] == true ||
5254 (oParams['sController'] == 'core.index-member') || 5255 (oCore['sController'] == 'pages.view')) { 5256 } else { 5257 var sContent = $('#delayed_block').html(); 5258 // Get the params from the url 5259 var sUrl = $Core.getRequests(window.location.href, true); 5260 var aUrl = sUrl.split('/'); 5261 var oUrlParams = {}; 5262 var aTemp = []; 5263 5264 for (var count in aUrl) { 5265 if (aUrl[count].indexOf('_') > (-1)) { 5266 aTemp = aUrl[count].split('_'); 5267 oUrlParams[aTemp[0]] = aTemp[1]; 5268 } 5269 oUrlParams['req' + j] = aUrl[count]; 5270 } 5271 var sParams = $.param({params: oUrlParams}); 5272 5273 //setTimeout(function(){ /* Uncomment to test */ 5274 $.ajaxCall('core.loadDelayedBlocks', 'loadContent=' + sContent + '&' + sParams, 'GET'); 5275 // }, 2000); 5276 } 5277 } 5278 /* Any extra delayed loading is done here, for example with the comments */ 5279 if ($('.load_delayed').length > 0) { 5280 var oGet = {}; 5281 $('.load_delayed').each(function () { 5282 if ($(this).attr('id') == undefined || $(this).attr('id').length < 1) { 5283 $(this).attr('id', 'load_delayed_' + Math.floor(Math.random() * 999)); 5284 } 5285 oGet[$(this).find('.block_id').html()] = { 5286 block_id: $(this).find('.block_id').html(), 5287 block_name: $(this).find('.block_name').html(), 5288 block_param: $(this).find('.block_param').html() 5289 }; 5290 }); 5291 var sParams = encodeURIComponent(JSON.stringify(oGet)); 5292 $.ajaxCall('core.loadDelayedBlocks', 'delayedTemplates=' + sParams, 'GET'); 5293 } 5294}; 5295 5296/************************ Compatibility Features (Mostly due to IE8) *******************************/ 5297/* Production steps of ECMA-262, Edition 5, 15.4.4.19 5298 Reference: http://es5.github.com/#x15.4.4.19 5299 Taken from https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Array/map 5300*/ 5301if (!Array.prototype.map) { 5302 Array.prototype.map = function (callback, thisArg) { 5303 5304 var T, A, k; 5305 5306 if (this == null) { 5307 throw new TypeError(" this is null or not defined"); 5308 } 5309 var O = Object(this); 5310 var len = O.length >>> 0; 5311 if (typeof callback !== "function") { 5312 throw new TypeError(callback + " is not a function"); 5313 } 5314 if (thisArg) { 5315 T = thisArg; 5316 } 5317 A = new Array(len); 5318 k = 0; 5319 while (k < len) { 5320 5321 var kValue, mappedValue; 5322 if (k in O) { 5323 5324 kValue = O[k]; 5325 mappedValue = callback.call(T, kValue, k, O); 5326 A[k] = mappedValue; 5327 } 5328 k++; 5329 } 5330 return A; 5331 }; 5332} 5333/* Taken from https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Array/filter */ 5334if (!Array.prototype.filter) { 5335 Array.prototype.filter = function (fun /*, thisp */) { 5336 "use strict"; 5337 5338 if (this == null) 5339 throw new TypeError(); 5340 5341 var t = Object(this); 5342 var len = t.length >>> 0; 5343 if (typeof fun != "function") 5344 throw new TypeError(); 5345 5346 var res = []; 5347 var thisp = arguments[1]; 5348 for (var count = 0; count < len; count++) { 5349 if (count in t) { 5350 var val = t[count]; 5351 if (fun.call(thisp, val, j, t)) 5352 res.push(val); 5353 } 5354 } 5355 5356 return res; 5357 }; 5358} 5359 5360$Behavior.setIndexJsBox = function () { 5361 $('.js_box').unbind('click'); 5362 $('.js_box').click(function () { 5363 var $aAllBoxIndexInner = new Array(); 5364 $('.js_box').each(function () { 5365 $aAllBoxIndexInner.push(parseInt($(this).css('z-index'))); 5366 }); 5367 5368 $(this).css( 5369 { 5370 'z-index': (parseInt(Math.max.apply(Math, $aAllBoxIndexInner)) + 1) 5371 }); 5372 }); 5373} 5374 5375$Behavior.searchFriendBlock = function () { 5376 $Core.searchFriend.sSearchByValue = $('.js_is_enter').val(); 5377 5378 if ($.browser.mozilla) { 5379 $(document).on('keypress', '.js_is_enter', $Core.searchFriend.checkForEnter); 5380 } else { 5381 $(document).on('keyup', '.js_is_enter', $Core.searchFriend.checkForEnter); 5382 } 5383}; 5384 5385$Behavior.friend_block_search_init = function () { 5386 $Core.searchFriend.updateCheckBoxes(); 5387}; 5388 5389$Behavior.generateTokenfield = function () { 5390 if ($Core.tokenfield.isAjax == false) { 5391 return; 5392 } 5393 $Core.tokenfield.globalInit(); 5394}; 5395 5396$Behavior.buildBLockToggle = function () { 5397 $('.layout-left .block:not(.built-toggle):not(.no-toggle), .layout-right .block:not(.built-toggle):not(.no-toggle)').each(function () { 5398 var toggle = $(this).data('toggle'), 5399 bodyWidth = $('body').width(); 5400 if (toggle == false || bodyWidth >= 992) { 5401 return; 5402 } else if (typeof toggle == 'number' && toggle) { 5403 if ((bodyWidth < 992 && bodyWidth >= 767 && toggle != 992) || 5404 (bodyWidth < 767 && bodyWidth >= 480 && toggle != 767) || 5405 (bodyWidth < 480 && toggle != 480) 5406 ) { 5407 return; 5408 } 5409 } else if (typeof toggle == 'string' && toggle) {
5410 var toggleWidths = toggle.split(','); 5411 if (toggleWidths.length) { 5412 if ((bodyWidth < 992 && bodyWidth >= 767 && toggleWidths.indexOf('992') === -1) || 5413 (bodyWidth < 767 && bodyWidth >= 480 && toggleWidths.indexOf('767') === -1) || 5414 (bodyWidth < 480 && toggleWidths.indexOf('480') === -1) 5415 ) { 5416 return; 5417 } 5418 } 5419 } 5420 5421 $(this).addClass('built-toggle'); 5422 if ($(this).height() >= 120 && $(this).attr('id') != 'js_block_border_core_menusub') { 5423 $('<div class="toggle-button shown dont-unbind"><span class="ico ico-angle-down"></span></div>').on('click', function () { 5424 $(this).parent().toggleClass('full'); 5425 }).appendTo($(this)); 5426 $(this).addClass('has-toggle'); 5427 } 5428 }); 5429} 5430 5431$Behavior.searchFriendsComponent = function () { 5432 if ($Core.searchFriendsParams) { 5433 $Core.searchFriends($Core.searchFriendsParams); 5434 } 5435}; 5436 5437$Behavior.loadProfilePhotoForm = function () { 5438 if ($('._is_profile_view').length > 0 && $('#profile_photo_form').length === 0) { 5439 tb_show(oTranslations['update_profile_picture'], $.ajaxBox('profile.updateProfilePhoto', 'width=650'), null, null, null, null, true, 'profile_photo_form'); 5440 5441 $(document).on('click', '#profile-image-upload-again', function () { 5442 $('#profile_crop_me').removeClass('profile-image-error'); 5443 $('.dropzone-button', '#user-dropzone').trigger('click'); 5444 }); 5445 5446 $(document).off('click', '#profile_photo_form .js_box_close a').on('click', '#profile_photo_form .js_box_close a', function () { 5447 if ($Core.ProfilePhoto.modified) { 5448 $Core.jsConfirm({ 5449 'title': oTranslations['close'], 5450 'message': oTranslations['close_without_save_your_changes'], 5451 'btn_yes': oTranslations['close'] 5452 }, function () { 5453 $Core.ProfilePhoto.closeHiddenBox(); 5454 }, function () { 5455 }); 5456 } else { 5457 $Core.ProfilePhoto.closeHiddenBox(); 5458 } 5459 }); 5460 } 5461}; 5462$Core.initSelectize = function () { 5463 setTimeout(function () { 5464 $('.js_core_init_selectize_form_group select:not(.selectized)').each(function () { 5465 var eleParent = $(this).closest('.js_core_init_selectize_form_group'); 5466 $(this).parent().addClass('dont-unbind-children'); 5467 var plugin = []; 5468 if ($(this).prop('multiple')) { 5469 plugin = ['remove_button']; 5470 } 5471 $(this).selectize({ 5472 plugins: plugin, 5473 onInitialize: function () { 5474 if (!(/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent))) { 5475 if (eleParent.hasClass('selectize-mcustomscroll')) { 5476 var isIE11 = !!window.MSInputMethodContext && !!document.documentMode; 5477 // true on IE11 5478 if(isIE11) return; 5479 eleParent.find('.selectize-dropdown').mCustomScrollbar({ 5480 theme: "dark-thin", 5481 scrollbarPosition: "inside", 5482 }).addClass('dont-unbind-children'); 5483 } 5484 } 5485 } 5486 }); 5487 }); 5488 }, 100); 5489} 5490$Behavior.initSelectize = function () { 5491 $Core.initSelectize(); 5492}; 5493 5494//init scroll sign-up form 5495$Behavior.initScrollSignup = function () { 5496 // Just init custom scrollbar on desktop view. 5497 if (!(/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent))) { 5498 //Init scrollbar landingpage 5499 $('#js_block_border_user_register .content').mCustomScrollbar({ 5500 theme: "dark-thin", 5501 scrollbarPosition: "inside", 5502 }).addClass('dont-unbind-children'); 5503 } 5504} 5505 5506//reinit repostion cover photo of user in case load ajax content. 5507$Behavior.processRepositionCoverProfilePhoto = function () { 5508 var profileBanner = $('.profiles_banner'); 5509 if (profileBanner.length && profileBanner.hasClass('editing')) { 5510 if (profileBanner.find('.cover_section_menu_item.reposition a:first').length) { 5511 profileBanner.find('.cover_section_menu_item.reposition a:first').get(0).click(); 5512 } 5513 } 5514}; 5515 5516$Behavior.processFriendRequest = function () { 5517 if ($('#page_profile_index').length) { 5518 var confirmMessage = localStorage.getItem('confirmRequestMessage'); 5519 if (!empty(confirmMessage)) { 5520 $('#public_message').html(confirmMessage).show(); 5521 $Behavior.addModerationListener(); 5522 localStorage.setItem('confirmRequestMessage', ''); 5523 } 5524 } 5525}; 5526 5527$Behavior.coreDropdownCheck = function () { 5528 if ($(".js_core_action_dropdown_check").length) { 5529 $('.js_core_action_dropdown_check .dropdown-menu').each(function () { 5530 if ($(this).children().length) { 5531 $(this).closest(".dropdown,.dropup").show(); 5532 } 5533 }); 5534 } 5535}; 5536 5537$Behavior.disableButtonWhenClick = function () { 5538 var disabledCheckBtn = $(".js_core_action_button_disable_check"); 5539 if (disabledCheckBtn.length) { 5540 disabledCheckBtn.each(function () { 5541 $(this).off('click').on('click', function () { 5542 $(this).prop('disabled', true); 5543 $(this).parents('form:first').submit(); 5544 }) 5545 }); 5546 } 5547}; 5548 5549$Behavior.disabledKeyboardActionsForContenteditable = function() { 5550 $('div[contenteditable="true"]').each(function() { 5551 let _this = $(this); 5552 if (!_this.attr('allow_html') && ((!_this.closest('.dont-unbind-children').length && !_this.hasClass('dont-unbind')) || !_this.prop('built'))) { 5553 _this.prop('built', true); 5554 _this.on('keydown', function(e) { 5555 let bCanAction = true; 5556 if (e.ctrlKey || e.metaKey) { 5557 switch (e.keyCode) { 5558 case 66: //ctr+b 5559 case 98: //ctr+B 5560 case 73: //ctr+i 5561 case 105: //ctr+I 5562 case 85: //ctr+u 5563 case 117: //ctr+U 5564 bCanAction = false;
5565 break; 5566 } 5567 } 5568 if (!bCanAction) { 5569 e.preventDefault(); 5570 } 5571 }); 5572 } 5573 }); 5574} 5575 5576$Behavior.initPasswordViewableField = function () { 5577 if (typeof navigator === "object" && /Edge|Edg/.test(navigator.userAgent)) { 5578 return false; //Won't init on Edge browser 5579 } 5580 $('form').find('input[type="password"]').each(function () { 5581 var ele = $(this); 5582 if (ele.data('skip-password-viewable') || (!ele.data('password-viewable') 5583 && !ele.closest('#js_login_form, #js_signup_block, #js_change_password_form, #admincp_login').length)) { 5584 return false; 5585 } 5586 var randNumber = (Date.now() + Math.floor(Math.random() * 1000000)).toString(), 5587 inputId = 'js_password_' + randNumber; 5588 if (!ele.prop('password-built')) { 5589 $('<div class="input-group input-password-viewable-holder" id="' + inputId + '_holder"></div>').insertBefore(ele.get(0)); 5590 ele.appendTo($('#' + inputId + '_holder')); 5591 var parent = ele.parent(); 5592 ele.prop('password-built', true).addClass(inputId + ' input-password-viewable'); 5593 var iconView = '<span class="holder-input" style="display: none"><span title="' + getPhrase('hide_password') + '" class="show_password_' + inputId + ' btn btn-default ' + inputId + '_hide" ' + 5594 'data-show="' + inputId + '_show" data-type="password" data-input-id="' + inputId + '"><i class="ico ico-eye-off"></i></span></span>' + 5595 '<span class="input-group-btn holder-input"><span title="' + getPhrase('show_password') + '" class="show_password_' + inputId + ' btn btn-default ' + inputId + '_show" ' + 5596 'data-show="' + inputId + '_hide" data-type="text" data-input-id="' + inputId + '"><i class="ico ico-eye"></i></span></span>'; 5597 parent.append(iconView); 5598 $(document).on('click', '.show_password_' + inputId, function () { 5599 $(this).closest('span.holder-input').insertBefore($(this).closest('span.holder-input').prev('span')); 5600 $(this).closest('span.holder-input').removeClass('input-group-btn').css('display', 'none'); 5601 $('.' + $(this).data('show')).closest('span.holder-input').addClass('input-group-btn').css('display', 'table-cell'); 5602 $(this).closest('.input-password-viewable-holder').find('input.' + $(this).data('input-id')).attr('type', $(this).data('type')); 5603 }); 5604 } 5605 5606 return true; 5607 }) 5608}, 5609 5610$Core.updateActiveMenu = function() { 5611 if ($('.page_section_menu ul li.active a').length && $('#current_tab').length) { 5612 let href = $('.page_section_menu ul li.active a').attr('href'); 5613 if (typeof href === "string" && href !== '') { 5614 $('#current_tab').val(href.replace('#', '')); 5615 } 5616 } 5617} 5618 5619$Core.addNoticeMessage = function (sMessage, bDontShow) { 5620 var sClass = 'public_message'; 5621 $('body').find('#' + sClass).remove(); 5622 $('body').append('<div id="' + sClass + '" class="' + sClass + '">' + sMessage + '</div>'); 5623 5624 if (!bDontShow) { 5625 var m = $('#' + sClass); 5626 m.show(); 5627 m.animate({ 5628 'margin-bottom': '0px', 5629 }, 'fast', function () { 5630 if (m.data('auto-close') != false) { 5631 setTimeout(function () { 5632 $Core.publicMessageSlideDown(); 5633 }, 3000); 5634 } 5635 }); 5636 } 5637 return this; 5638} 5639$Core.timeCounter = { 5640 oCurrent: {}, 5641 oInterval: {}, 5642 oPaused: {}, 5643 start: function (ele, limit, countdown, end_reset) { 5644 if (!$(ele).length) { 5645 return false; 5646 } 5647 this.stop(ele); 5648 if (countdown) { 5649 this.oCurrent[ele] = limit ? limit : 60; 5650 } else { 5651 this.oCurrent[ele] = 0; 5652 } 5653 this.oInterval[ele] = setInterval(countTimer, 1000); 5654 function countTimer() { 5655 if ($Core.timeCounter.oPaused.hasOwnProperty(ele) && $Core.timeCounter.oPaused[ele]) { 5656 return; 5657 } 5658 if (countdown) { 5659 --$Core.timeCounter.oCurrent[ele]; 5660 } else { 5661 ++$Core.timeCounter.oCurrent[ele]; 5662 } 5663 var totalSeconds = $Core.timeCounter.oCurrent[ele], 5664 hour = Math.floor(totalSeconds / 3600), 5665 minute = Math.floor((totalSeconds - hour * 3600) / 60), 5666 seconds = totalSeconds - (hour * 3600 + minute * 60), 5667 showHour = hour > 0; 5668 if (hour < 10) 5669 hour = "0" + hour; 5670 if (minute < 10) 5671 minute = "0" + minute; 5672 if (seconds < 10) 5673 seconds = "0" + seconds; 5674 $(ele).html((showHour ? (hour + ":") : '') + minute + ":" + seconds); 5675 if ((limit && limit == $Core.timeCounter.oCurrent[ele] && !countdown) || $Core.timeCounter.oCurrent[ele] === 0) { 5676 end_reset ? $Core.timeCounter.reset(ele) : $Core.timeCounter.stop(ele); 5677 } 5678 } 5679 }, 5680 pause: function (ele) {
5681 this.oPaused[ele] = true; 5682 }, 5683 resume: function (ele) { 5684 this.oPaused[ele] = false; 5685 }, 5686 stop: function (ele) { 5687 typeof this.oInterval[ele] !== "undefined" && clearInterval(this.oInterval[ele]); 5688 this.oInterval[ele] = null; 5689 }, 5690 reset: function (ele, keep_zero) { 5691 this.stop(ele); 5692 keep_zero ? $(ele).html('00:00') : $(ele).empty(); 5693 } 5694} 5695 5696$Core.initSearchMembers = function () { 5697 if (typeof $Core.searchMembersInput == 'undefined' || typeof $Core.searchMembersParams == "undefined" || !$Core.searchMembersParams) { 5698 return; 5699 } 5700 $Core.searchMembersInput.init($Core.searchMembersParams); 5701}; 5702 5703$Behavior.feed_initGoogleMapsForFeeds = function() { 5704 if (typeof $Core.FeedPlace !== "undefined") { 5705 $Core.FeedPlace.quickInit(); 5706 } 5707} 5708 5709PF.event.on('before_append_content', function() { 5710 if (typeof $Core.searchMembersParams !== "undefined") { 5711 $Core.searchMembersParams = null; 5712 } 5713}); 5714 5715PF.event.on('on_document_ready_end', function () { 5716 $Core.reloadValidation.init(); 5717 $Core.googleAuth.initGoogleLoginOnHeader(); 5718 $Core.CoverPhoto.initRepositionCover(); 5719 $Core.updateActiveMenu(); 5720 $Core.initSearchMembers(); 5721}); 5722PF.event.on('on_page_change_end', function () { 5723 $Core.reloadValidation.init(); 5724 $Core.CoverPhoto.reset(); 5725 $Core.googleAuth.initGoogleLoginOnHeader(); 5726 $Core.CoverPhoto.initRepositionCover(); 5727 $Core.updateActiveMenu(); 5728 $Core.initSearchMembers(); 5729});
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.