1/** 2 * @copyright Copyright (C) 2005 - 2019 Open Source Matters, Inc. All rights reserved. 3 * @license GNU General Public License version 2 or later; see LICENSE.txt 4 */ 5 6// Only define the Joomla namespace if not defined. 7Joomla = window.Joomla || {}; 8 9// Only define editors if not defined 10Joomla.editors = Joomla.editors || {}; 11 12// An object to hold each editor instance on page, only define if not defined. 13Joomla.editors.instances = Joomla.editors.instances || { 14 /** 15 * ***************************************************************** 16 * All Editors MUST register, per instance, the following callbacks: 17 * ***************************************************************** 18 * 19 * getValue Type Function Should return the complete data from the editor 20 * Example: function () { return this.element.value; } 21 * setValue Type Function Should replace the complete data of the editor 22 * Example: function (text) { return this.element.value = text; } 23 * getSelection Type Function Should return the selected text from the editor 24 * Example: function () { return this.selectedText; } 25 * replaceSelection Type Function Should replace the selected text of the editor 26 * If nothing selected, will insert the data at the cursor 27 * Example: function (text) { return insertAtCursor(this.element, text); } 28 * 29 * USAGE (assuming that jform_articletext is the textarea id) 30 * { 31 * To get the current editor value: 32 * Joomla.editors.instances['jform_articletext'].getValue(); 33 * To set the current editor value: 34 * Joomla.editors.instances['jform_articletext'].setValue('Joomla! rocks'); 35 * To replace(selection) or insert a value at the current editor cursor: 36 * replaceSelection: Joomla.editors.instances['jform_articletext'].replaceSelection('Joomla! rocks') 37 * } 38 * 39 * ********************************************************* 40 * ANY INTERACTION WITH THE EDITORS SHOULD USE THE ABOVE API 41 * ********************************************************* 42 * 43 * jInsertEditorText() @deprecated 4.0 44 */ 45}; 46 47(function( Joomla, document ) { 48 "use strict"; 49 50 /** 51 * Generic submit form 52 * 53 * @param {String} task The given task 54 * @param {node} form The form element 55 * @param {bool} validate The form element 56 * 57 * @returns {void} 58 */ 59 Joomla.submitform = function(task, form, validate) { 60 61 if (!form) { 62 form = document.getElementById('adminForm'); 63 } 64 65 if (task) { 66 form.task.value = task; 67 } 68 69 // Toggle HTML5 validation 70 form.noValidate = !validate; 71 72 if (!validate) { 73 form.setAttribute('novalidate', ''); 74 } else if ( form.hasAttribute('novalidate') ) { 75 form.removeAttribute('novalidate'); 76 } 77 78 // Submit the form. 79 // Create the input type="submit" 80 var button = document.createElement('input'); 81 button.style.display = 'none'; 82 button.type = 'submit'; 83 84 // Append it and click it 85 form.appendChild(button).click(); 86 87 // If "submit" was prevented, make sure we don't get a build up of buttons 88 form.removeChild(button); 89 }; 90 91 /** 92 * Default function. Can be overriden by the component to add custom logic 93 * 94 * @param {bool} task The given task 95 * 96 * @returns {void} 97 */ 98 Joomla.submitbutton = function( pressbutton ) { 99 Joomla.submitform( pressbutton ); 100 }; 101 102 /** 103 * Custom behavior for JavaScript I18N 104 * 105 * @type {{}} 106 * 107 * Allows you to call Joomla.Text._() to get a translated JavaScript string pushed in with Text::script() in Joomla. 108 */ 109 Joomla.Text = { 110 strings: {}, 111 112 /** 113 * Translates a string into the current language. 114 * 115 * @param {String} key The string to translate 116 * @param {String} def Default string 117 * 118 * @returns {String} 119 */ 120 '_': function( key, def ) { 121 122 // Check for new strings in the optionsStorage, and load them 123 var newStrings = Joomla.getOptions('joomla.jtext'); 124 if ( newStrings ) { 125 this.load(newStrings); 126 127 // Clean up the optionsStorage from useless data 128 Joomla.loadOptions({'joomla.jtext': null}); 129 } 130 131 def = def === undefined ? '' : def; 132 key = key.toUpperCase(); 133 134 return this.strings[ key ] !== undefined ? this.strings[ key ] : def; 135 }, 136 137 /** 138 * Load new strings in to Joomla.JText 139 * 140 * @param {Object} object Object with new strings 141 * @returns {Joomla.JText} 142 */ 143 load: function( object ) { 144 for ( var key in object ) { 145 if (!object.hasOwnProperty(key)) continue; 146 this.strings[ key.toUpperCase() ] = object[ key ]; 147 } 148 149 return this; 150 } 151 }; 152 153 /** 154 * Proxy old Joomla.JText to Joomla.Text 155 * 156 * @deprecated 5.0 Use Joomla.Text 157 */ 158 Joomla.JText = Joomla.Text; 159 160 /** 161 * Joomla options storage 162 * 163 * @type {{}} 164 * 165 * @since 3.7.0 166 */ 167 Joomla.optionsStorage = Joomla.optionsStorage || null; 168 169 /** 170 * Get script(s) options 171 * 172 * @param {String} key Name in Storage 173 * @param {mixed} def Default value if nothing found 174 * 175 * @return {mixed} 176 * 177 * @since 3.7.0 178 */ 179 Joomla.getOptions = function( key, def ) { 180 // Load options if they not exists 181 if (!Joomla.optionsStorage) { 182 Joomla.loadOptions(); 183 } 184 185 return Joomla.optionsStorage[key] !== undefined ? Joomla.optionsStorage[key] : def; 186 }; 187 188 /** 189 * Load new options from given options object or from Element 190 * 191 * @param {Object|undefined} options The options object to load. Eg {"com_foobar" : {"option1": 1, "option2": 2}} 192 * 193 * @since 3.7.0 194 */ 195 Joomla.loadOptions = function( options ) { 196 // Load form the script container 197 if (!options) { 198 var elements = document.querySelectorAll('.joomla-script-options.new'), 199 str, element, option, counter = 0; 200 201 for (var i = 0, l = elements.length; i < l; i++) { 202 element = elements[i]; 203 str = element.text || element.textContent; 204 option = JSON.parse(str); 205 206 if (option) { 207 Joomla.loadOptions(option); 208 counter++; 209 } 210 211 element.className = element.className.replace(' new', ' loaded'); 212 } 213 214 if (counter) { 215 return; 216 } 217 } 218 219 // Initial loading 220 if (!Joomla.optionsStorage) { 221 Joomla.optionsStorage = options || {}; 222 } 223 // Merge with existing 224 else if ( options ) { 225 for (var p in options) { 226 if (options.hasOwnProperty(p)) { 227 Joomla.optionsStorage[p] = options[p]; 228 } 229 } 230 } 231 }; 232 233 /** 234 * Method to replace all request tokens on the page with a new one. 235 * 236 * @param {String} newToken The token 237 * 238 * Used in Joomla Installation 239 */ 240 Joomla.replaceTokens = function( newToken ) { 241 if (!/^[0-9A-F]{32}$/i.test(newToken)) { return; } 242 243 var els = document.getElementsByTagName( 'input' ), 244 i, el, n; 245 246 for ( i = 0, n = els.length; i < n; i++ ) { 247 el = els[i]; 248 249 if ( el.type == 'hidden' && el.value == '1' && el.name.length == 32 ) { 250 el.name = newToken; 251 } 252 } 253 }; 254 255 /** 256 * USED IN: administrator/components/com_banners/views/client/tmpl/default.php 257 * Actually, probably not used anywhere. Can we deprecate in favor of <input type="email">? 258 * 259 * Verifies if the string is in a valid email format 260 * 261 * @param {string} text The text for validation 262 * 263 * @return {boolean} 264 * 265 * @deprecated 4.0 No replacement. Use formvalidator 266 */ 267 Joomla.isEmail = function( text ) { 268 console.warn('Joomla.isEmail() is deprecated, use the formvalidator instead'); 269 270 var regex = /^[\w.!#$%&âÃô*+\/=?^`{|}~-]+@[a-z0-9-]+(?:\.[a-z0-9-]{2,})+$/i; 271 return regex.test( text ); 272 }; 273 274 /** 275 * USED IN: all list forms. 276 * 277 * Toggles the check state of a group of boxes 278 * 279 * Checkboxes must have an id attribute in the form cb0, cb1... 280 * 281 * @param {mixed} checkbox The number of box to 'check', for a checkbox element 282 * @param {string} stub An alternative field name 283 * 284 * @return {boolean} 285 */ 286 Joomla.checkAll = function( checkbox, stub ) { 287 if (!checkbox.form) return false;
288 289 stub = stub ? stub : 'cb'; 290 291 var c = 0, 292 i, e, n; 293 294 for ( i = 0, n = checkbox.form.elements.length; i < n; i++ ) { 295 e = checkbox.form.elements[ i ]; 296 297 if ( e.type == checkbox.type && e.id.indexOf( stub ) === 0 ) { 298 e.checked = checkbox.checked; 299 c += e.checked ? 1 : 0; 300 } 301 } 302 303 if ( checkbox.form.boxchecked ) { 304 checkbox.form.boxchecked.value = c; 305 } 306 307 return true; 308 }; 309 310 /** 311 * Render messages send via JSON 312 * Used by some javascripts such as validate.js 313 * 314 * @param {object} messages JavaScript object containing the messages to render. Example: 315 * var messages = { 316 * "message": ["Message one", "Message two"], 317 * "error": ["Error one", "Error two"] 318 * }; 319 * @return {void} 320 */ 321 Joomla.renderMessages = function( messages ) { 322 Joomla.removeMessages(); 323 324 var messageContainer = document.getElementById( 'system-message-container' ), 325 type, typeMessages, messagesBox, title, titleWrapper, i, messageWrapper, alertClass; 326 327 for ( type in messages ) { 328 if ( !messages.hasOwnProperty( type ) ) { continue; } 329 // Array of messages of this type 330 typeMessages = messages[ type ]; 331 332 // Create the alert box 333 messagesBox = document.createElement( 'div' ); 334 335 // Message class 336 alertClass = (type === 'notice') ? 'alert-info' : 'alert-' + type; 337 alertClass = (type === 'message') ? 'alert-success' : alertClass; 338 alertClass = (type === 'error') ? 'alert-error alert-danger' : alertClass; 339 340 messagesBox.className = 'alert ' + alertClass; 341 342 // Close button 343 var buttonWrapper = document.createElement( 'button' ); 344 buttonWrapper.setAttribute('type', 'button'); 345 buttonWrapper.setAttribute('data-dismiss', 'alert'); 346 buttonWrapper.className = 'close'; 347 buttonWrapper.innerHTML = 'Ã'; 348 messagesBox.appendChild( buttonWrapper ); 349 350 // Title 351 title = Joomla.JText._( type ); 352 353 // Skip titles with untranslated strings 354 if ( typeof title != 'undefined' ) { 355 titleWrapper = document.createElement( 'h4' ); 356 titleWrapper.className = 'alert-heading'; 357 titleWrapper.innerHTML = Joomla.JText._( type ); 358 messagesBox.appendChild( titleWrapper ); 359 } 360 361 // Add messages to the message box 362 for ( i = typeMessages.length - 1; i >= 0; i-- ) { 363 messageWrapper = document.createElement( 'div' ); 364 messageWrapper.innerHTML = typeMessages[ i ]; 365 messagesBox.appendChild( messageWrapper ); 366 } 367 368 messageContainer.appendChild( messagesBox ); 369 } 370 }; 371 372 /** 373 * Remove messages 374 * 375 * @return {void} 376 */ 377 Joomla.removeMessages = function() { 378 var messageContainer = document.getElementById( 'system-message-container' ); 379 380 // Empty container with a while for Chrome performance issues 381 while ( messageContainer.firstChild ) messageContainer.removeChild( messageContainer.firstChild ); 382 383 // Fix Chrome bug not updating element height 384 messageContainer.style.display = 'none'; 385 messageContainer.offsetHeight; 386 messageContainer.style.display = ''; 387 }; 388 389 /** 390 * Treat AJAX errors. 391 * Used by some javascripts such as sendtestmail.js and permissions.js 392 * 393 * @param {object} xhr XHR object. 394 * @param {string} textStatus Type of error that occurred. 395 * @param {string} error Textual portion of the HTTP status. 396 * 397 * @return {object} JavaScript object containing the system error message. 398 * 399 * @since 3.6.0 400 */ 401 Joomla.ajaxErrorsMessages = function( xhr, textStatus, error ) { 402 var msg = {}; 403 404 // For jQuery jqXHR 405 if (textStatus === 'parsererror') 406 { 407 // Html entity encode. 408 var encodedJson = xhr.responseText.trim(); 409 410 var buf = []; 411 for (var i = encodedJson.length-1; i >= 0; i--) { 412 buf.unshift( [ '&#', encodedJson[i].charCodeAt(), ';' ].join('') ); 413 } 414 415 encodedJson = buf.join(''); 416 417 msg.error = [ Joomla.JText._('JLIB_JS_AJAX_ERROR_PARSE').replace('%s', encodedJson) ]; 418 } 419 else if (textStatus === 'nocontent') 420 { 421 msg.error = [ Joomla.JText._('JLIB_JS_AJAX_ERROR_NO_CONTENT') ]; 422 } 423 else if (textStatus === 'timeout') 424 { 425 msg.error = [ Joomla.JText._('JLIB_JS_AJAX_ERROR_TIMEOUT') ]; 426 } 427 else if (textStatus === 'abort') 428 { 429 msg.error = [ Joomla.JText._('JLIB_JS_AJAX_ERROR_CONNECTION_ABORT') ]; 430 } 431 // For vannila XHR 432 else if (xhr.responseJSON && xhr.responseJSON.message) 433 { 434 msg.error = [ Joomla.JText._('JLIB_JS_AJAX_ERROR_OTHER').replace('%s', xhr.status) + ' <em>' + xhr.responseJSON.message + '</em>' ]; 435 } 436 else if (xhr.statusText) 437 { 438 msg.error = [ Joomla.JText._('JLIB_JS_AJAX_ERROR_OTHER').replace('%s', xhr.status) + ' <em>' + xhr.statusText + '</em>' ]; 439 } 440 else 441 { 442 msg.error = [ Joomla.JText._('JLIB_JS_AJAX_ERROR_OTHER').replace('%s', xhr.status) ]; 443 } 444 445 return msg; 446 }; 447 448 /** 449 * USED IN: administrator/components/com_cache/views/cache/tmpl/default.php 450 * administrator/components/com_installer/views/discover/tmpl/default_item.php 451 * administrator/components/com_installer/views/update/tmpl/default_item.php 452 * administrator/components/com_languages/helpers/html/languages.php
453 * libraries/joomla/html/html/grid.php 454 * 455 * @param {boolean} isitchecked Flag for checked 456 * @param {node} form The form 457 * 458 * @return {void} 459 */ 460 Joomla.isChecked = function( isitchecked, form ) { 461 if ( typeof form === 'undefined' ) { 462 form = document.getElementById( 'adminForm' ); 463 } 464 465 form.boxchecked.value = isitchecked ? parseInt(form.boxchecked.value) + 1 : parseInt(form.boxchecked.value) - 1; 466 467 // If we don't have a checkall-toggle, done. 468 if ( !form.elements[ 'checkall-toggle' ] ) return; 469 470 // Toggle main toggle checkbox depending on checkbox selection 471 var c = true, i, e, n; 472 473 for ( i = 0, n = form.elements.length; i < n; i++ ) { 474 e = form.elements[ i ]; 475 476 if ( e.type == 'checkbox' && e.name != 'checkall-toggle' && !e.checked ) { 477 c = false; 478 break; 479 } 480 } 481 482 form.elements[ 'checkall-toggle' ].checked = c; 483 }; 484 485 /** 486 * USED IN: libraries/joomla/html/toolbar/button/help.php 487 * 488 * Pops up a new window in the middle of the screen 489 * 490 * @deprecated 4.0 No replacement 491 */ 492 Joomla.popupWindow = function( mypage, myname, w, h, scroll ) { 493 console.warn('Joomla.popupWindow() is deprecated without a replacement!'); 494 495 var winl = ( screen.width - w ) / 2, 496 wint = ( screen.height - h ) / 2, 497 winprops = 'height=' + h + 498 ',width=' + w + 499 ',top=' + wint + 500 ',left=' + winl + 501 ',scrollbars=' + scroll + 502 ',resizable'; 503 504 window.open( mypage, myname, winprops ) 505 .window.focus(); 506 }; 507 508 /** 509 * USED IN: libraries/joomla/html/html/grid.php 510 * In other words, on any reorderable table 511 * 512 * @param {string} order The order value 513 * @param {string} dir The direction 514 * @param {string} task The task 515 * @param {node} form The form 516 * 517 * return {void} 518 */ 519 Joomla.tableOrdering = function( order, dir, task, form ) { 520 if ( typeof form === 'undefined' ) { 521 form = document.getElementById( 'adminForm' ); 522 } 523 524 form.filter_order.value = order; 525 form.filter_order_Dir.value = dir; 526 Joomla.submitform( task, form ); 527 }; 528 529 /** 530 * USED IN: administrator/components/com_modules/views/module/tmpl/default.php 531 * 532 * Writes a dynamically generated list 533 * 534 * @param string 535 * The parameters to insert into the <select> tag 536 * @param array 537 * A javascript array of list options in the form [key,value,text] 538 * @param string 539 * The key to display for the initial state of the list 540 * @param string 541 * The original key that was selected 542 * @param string 543 * The original item value that was selected 544 * @param string 545 * The elem where the list will be written 546 * 547 * @deprecated 4.0 No replacement 548 */ 549 window.writeDynaList = function ( selectParams, source, key, orig_key, orig_val, element ) { 550 console.warn('window.writeDynaList() is deprecated without a replacement!'); 551 552 var select = document.createElement('select'); 553 var params = selectParams.split(' '); 554 555 for (var l = 0; l < params.length; l++) { 556 var par = params[l].split('='); 557 558 // make sure the attribute / content can not be used for scripting 559 if (par[0].trim().substr(0, 2).toLowerCase() === "on" 560 || par[0].trim().toLowerCase() === "href") { 561 continue; 562 } 563 564 select.setAttribute(par[0], par[1].replace(/\"/g, '')); 565 } 566 567 var hasSelection = key == orig_key, i, selected, item; 568 569 for (i = 0; i < source.length; i++) { 570 item = source[i]; 571 572 if (item[0] != key) { continue; } 573 574 selected = hasSelection ? orig_val == item[1] : i === 0; 575 576 var el = document.createElement('option'); 577 el.setAttribute('value', item[1]); 578 el.innerText = item[2]; 579 580 if (selected) { 581 el.setAttribute('selected', 'selected'); 582 } 583 584 select.appendChild(el); 585 } 586 587 if (element) { 588 element.appendChild(select); 589 } else { 590 document.body.appendChild(select); 591 } 592 }; 593 594 /** 595 * USED IN: administrator/components/com_content/views/article/view.html.php 596 * actually, probably not used anywhere. 597 * 598 * Changes a dynamically generated list 599 * 600 * @param string 601 * The name of the list to change 602 * @param array 603 * A javascript array of list options in the form [key,value,text] 604 * @param string 605 * The key to display 606 * @param string 607 * The original key that was selected 608 * @param string 609 * The original item value that was selected 610 * 611 * @deprecated 4.0 No replacement 612 */ 613 window.changeDynaList = function ( listname, source, key, orig_key, orig_val ) { 614 console.warn('window.changeDynaList() is deprecated without a replacement!'); 615 616 var list = document.adminForm[ listname ], 617 hasSelection = key == orig_key, 618 i, x, item, opt; 619 620 // empty the list 621 while ( list.firstChild ) list.removeChild( list.firstChild ); 622 623 i = 0; 624 625 for ( x in source ) { 626 if (!source.hasOwnProperty(x)) { continue; } 627 628 item = source[x]; 629 630 if ( item[ 0 ] != key ) { continue; } 631 632 opt = new Option(); 633 opt.value = item[ 1 ]; 634 opt.text = item[ 2 ]; 635 636 if ( ( hasSelection && orig_val == opt.value ) || (!hasSelection && i === 0) ) { 637 opt.selected = true; 638 } 639 640 list.options[ i++ ] = opt; 641 } 642 643 list.length = i; 644 }; 645 646 /** 647 * USED IN: administrator/components/com_menus/views/menus/tmpl/default.php 648 * Probably not used at all 649 * 650 * @param radioObj 651 * @return 652 * 653 * @deprecated 4.0 No replacement 654 */ 655 // return the value of the radio button that is checked 656 // return an empty string if none are checked, or 657 // there are no radio buttons 658 window.radioGetCheckedValue = function ( radioObj ) { 659 console.warn('window.radioGetCheckedValue() is deprecated without a replacement!'); 660 661 if ( !radioObj ) { return ''; } 662 663 var n = radioObj.length, 664 i; 665 666 if ( n === undefined ) { 667 return radioObj.checked ? radioObj.value : ''; 668 } 669 670 for ( i = 0; i < n; i++ ) { 671 if ( radioObj[ i ].checked ) { 672 return radioObj[ i ].value; 673 } 674 } 675 676 return ''; 677 }; 678 679 /** 680 * USED IN: administrator/components/com_users/views/mail/tmpl/default.php 681 * Let's get rid of this and kill it 682 * 683 * @param frmName 684 * @param srcListName 685 * @return 686 * 687 * @deprecated 4.0 No replacement 688 */ 689 window.getSelectedValue = function ( frmName, srcListName ) { 690 console.warn('window.getSelectedValue() is deprecated without a replacement!'); 691 692 var srcList = document[ frmName ][ srcListName ], 693 i = srcList.selectedIndex; 694 695 if ( i !== null && i > -1 ) { 696 return srcList.options[ i ].value; 697 } else { 698 return null; 699 } 700 }; 701 702 /** 703 * USED IN: all over :) 704 * 705 * @param id 706 * @param task 707 * @return 708 * 709 * @deprecated 4.0 Use Joomla.listItemTask() instead 710 */ 711 window.listItemTask = function ( id, task ) { 712 console.warn('window.listItemTask() is deprecated use Joomla.listItemTask() instead'); 713 714 return Joomla.listItemTask( id, task ); 715 }; 716 717 /** 718 * USED IN: all over :) 719 * 720 * @param {string} id The id 721 * @param {string} task The task 722 * 723 * @return {boolean} 724 */ 725 Joomla.listItemTask = function ( id, task ) { 726 var f = document.adminForm, 727 i = 0, cbx, 728 cb = f[ id ]; 729 730 if ( !cb ) return false;
731 732 while ( true ) { 733 cbx = f[ 'cb' + i ]; 734 735 if ( !cbx ) break; 736 737 cbx.checked = false; 738 739 i++; 740 } 741 742 cb.checked = true; 743 f.boxchecked.value = 1; 744 window.submitform( task ); 745 746 return false; 747 }; 748 749 /** 750 * Default function. Usually would be overriden by the component 751 * 752 * @deprecated 4.0 Use Joomla.submitbutton() instead. 753 */ 754 window.submitbutton = function ( pressbutton ) { 755 console.warn('window.submitbutton() is deprecated use Joomla.submitbutton() instead'); 756 757 Joomla.submitbutton( pressbutton ); 758 }; 759 760 /** 761 * Submit the admin form 762 * 763 * @deprecated 4.0 Use Joomla.submitform() instead. 764 */ 765 window.submitform = function ( pressbutton ) { 766 console.warn('window.submitform() is deprecated use Joomla.submitform() instead'); 767 768 Joomla.submitform(pressbutton); 769 }; 770 771 // needed for Table Column ordering 772 /** 773 * USED IN: libraries/joomla/html/html/grid.php 774 * There's a better way to do this now, can we try to kill it? 775 * 776 * @deprecated 4.0 No replacement 777 */ 778 window.saveorder = function ( n, task ) { 779 console.warn('window.saveorder() is deprecated without a replacement!'); 780 781 window.checkAll_button( n, task ); 782 }; 783 784 /** 785 * Checks all the boxes unless one is missing then it assumes it's checked out. 786 * Weird. Probably only used by ^saveorder 787 * 788 * @param integer n The total number of checkboxes expected 789 * @param string task The task to perform 790 * 791 * @return void 792 * 793 * @deprecated 4.0 No replacement 794 */ 795 window.checkAll_button = function ( n, task ) { 796 console.warn('window.checkAll_button() is deprecated without a replacement!'); 797 798 task = task ? task : 'saveorder'; 799 800 var j, box; 801 802 for ( j = 0; j <= n; j++ ) { 803 box = document.adminForm[ 'cb' + j ]; 804 805 if ( box ) { 806 box.checked = true; 807 } else { 808 alert( "You cannot change the order of items, as an item in the list is `Checked Out`" ); 809 return; 810 } 811 } 812 813 Joomla.submitform( task ); 814 }; 815 816 /** 817 * Add Joomla! loading image layer. 818 * 819 * Used in: /administrator/components/com_installer/views/languages/tmpl/default.php 820 * /installation/template/js/installation.js 821 * 822 * @param {String} task The task to do [load, show, hide] (defaults to show). 823 * @param {HTMLElement} parentElement The HTML element where we are appending the layer (defaults to body). 824 * 825 * @return {HTMLElement} The HTML loading layer element. 826 * 827 * @since 3.6.0 828 * 829 * @deprecated 4.0 No direct replacement. 830 * 4.0 will introduce a web component for the loading spinner, therefore the spinner will need to 831 * explicitly be loaded in all relevant pages. 832 */ 833 Joomla.loadingLayer = function(task, parentElement) { 834 // Set default values. 835 task = task || 'show'; 836 parentElement = parentElement || document.body; 837 838 // Create the loading layer (hidden by default). 839 if (task === 'load') 840 { 841 // Gets the site base path 842 var systemPaths = Joomla.getOptions('system.paths') || {}, 843 basePath = systemPaths.root || ''; 844 845 var loadingDiv = document.createElement('div'); 846 847 loadingDiv.id = 'loading-logo'; 848 849 // The loading layer CSS styles are JS hardcoded so they can be used without adding CSS. 850 851 // Loading layer style and positioning. 852 loadingDiv.style['position'] = 'fixed'; 853 loadingDiv.style['top'] = '0'; 854 loadingDiv.style['left'] = '0'; 855 loadingDiv.style['width'] = '100%'; 856 loadingDiv.style['height'] = '100%'; 857 loadingDiv.style['opacity'] = '0.8'; 858 loadingDiv.style['filter'] = 'alpha(opacity=80)'; 859 loadingDiv.style['overflow'] = 'hidden'; 860 loadingDiv.style['z-index'] = '10000'; 861 loadingDiv.style['display'] = 'none'; 862 loadingDiv.style['background-color'] = '#fff'; 863 864 // Loading logo positioning. 865 loadingDiv.style['background-image'] = 'url("' + basePath + '/media/jui/images/ajax-loader.gif")'; 866 loadingDiv.style['background-position'] = 'center'; 867 loadingDiv.style['background-repeat'] = 'no-repeat'; 868 loadingDiv.style['background-attachment'] = 'fixed'; 869 870 parentElement.appendChild(loadingDiv); 871 } 872 // Show or hide the layer. 873 else 874 { 875 if (!document.getElementById('loading-logo')) 876 { 877 Joomla.loadingLayer('load', parentElement); 878 } 879 880 document.getElementById('loading-logo').style['display'] = (task == 'show') ? 'block' : 'none'; 881 } 882 883 return document.getElementById('loading-logo'); 884 }; 885 886 /** 887 * Method to Extend Objects 888 * 889 * @param {Object} destination 890 * @param {Object} source 891 * 892 * @return Object 893 */ 894 Joomla.extend = function (destination, source) { 895 for (var p in source) { 896 if (source.hasOwnProperty(p)) { 897 destination[p] = source[p]; 898 } 899 } 900 901 return destination; 902 }; 903 904 /** 905 * Method to perform AJAX request 906 * 907 * @param {Object} options Request options: 908 * { 909 * url: 'index.php', // Request URL 910 * method: 'GET', // Request method GET (default), POST 911 * data: null, // Data to be sent, see https://developer.mozilla.org/docs/Web/API/XMLHttpRequest/send 912 * perform: true, // Perform the request immediately, or return XMLHttpRequest instance and perform it later 913 * headers: null, // Object of custom headers, eg {'X-Foo': 'Bar', 'X-Bar': 'Foo'} 914 * 915 * onBefore: function(xhr){} // Callback on before the request 916 * onSuccess: function(response, xhr){}, // Callback on the request success 917 * onError: function(xhr){}, // Callback on the request error 918 * } 919 * 920 * @return XMLHttpRequest|Boolean 921 * 922 * @example 923 * 924 * Joomla.request({ 925 * url: 'index.php?option=com_example&view=example', 926 * onSuccess: function(response, xhr){ 927 * console.log(response); 928 * } 929 * }) 930 * 931 * @see https://developer.mozilla.org/docs/Web/API/XMLHttpRequest 932 */ 933 Joomla.request = function (options) { 934 935 // Prepare the options 936 options = Joomla.extend({ 937 url: '', 938 method: 'GET', 939 data: null, 940 perform: true 941 }, options); 942 943 // Use POST for send the data 944 options.method = options.data ? 'POST' : options.method.toUpperCase(); 945 946 // Set up XMLHttpRequest instance 947 try{ 948 var xhr = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject('MSXML2.XMLHTTP.3.0'); 949 950 xhr.open(options.method, options.url, true); 951 952 // Set the headers 953 xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest'); 954 xhr.setRequestHeader('X-Ajax-Engine', 'Joomla!'); 955 956 if (options.method === 'POST') { 957 var token = Joomla.getOptions('csrf.token', ''); 958 959 if (token) { 960 xhr.setRequestHeader('X-CSRF-Token', token); 961 } 962 963 if (!options.headers || !options.headers['Content-Type']) { 964 xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); 965 } 966 } 967 968 // Custom headers 969 if (options.headers){ 970 for (var p in options.headers) { 971 if (options.headers.hasOwnProperty(p)) { 972 xhr.setRequestHeader(p, options.headers[p]); 973 } 974 } 975 } 976 977 xhr.onreadystatechange = function () { 978 // Request not finished 979 if (xhr.readyState !== 4) return; 980 981 // Request finished and response is ready 982 if (xhr.status === 200) { 983 if(options.onSuccess) { 984 options.onSuccess.call(window, xhr.responseText, xhr); 985 } 986 } else if(options.onError) { 987 options.onError.call(window, xhr); 988 } 989 }; 990 991 // Do request 992 if (options.perform) { 993 if (options.onBefore && options.onBefore.call(window, xhr) === false) { 994 // Request interrupted 995 return xhr; 996 } 997 998 xhr.send(options.data); 999 } 1000 1001 } catch (error) { 1002 window.console ? console.log(error) : null; 1003 return false;
1004 } 1005 1006 return xhr; 1007 }; 1008 1009}( Joomla, document ));
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.