1/** 2 * @copyright (C) 2009 Open Source Matters, Inc. <https://www.joomla.org> 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 * PLEASE NOTE: do NOT use user supplied input in messages as potential HTML markup is NOT sanitized! 314 * 315 * @param {object} messages JavaScript object containing the messages to render. Example: 316 * var messages = { 317 * "message": ["Message one", "Message two"], 318 * "error": ["Error one", "Error two"] 319 * }; 320 * @return {void} 321 */ 322 Joomla.renderMessages = function( messages ) { 323 Joomla.removeMessages(); 324 325 var messageContainer = document.getElementById( 'system-message-container' ), 326 type, typeMessages, messagesBox, title, titleWrapper, i, messageWrapper, alertClass; 327 328 for ( type in messages ) { 329 if ( !messages.hasOwnProperty( type ) ) { continue; } 330 // Array of messages of this type 331 typeMessages = messages[ type ]; 332 333 // Create the alert box 334 messagesBox = document.createElement( 'div' ); 335 336 // Message class 337 alertClass = (type === 'notice') ? 'alert-info' : 'alert-' + type; 338 alertClass = (type === 'message') ? 'alert-success' : alertClass; 339 alertClass = (type === 'error') ? 'alert-error alert-danger' : alertClass; 340 341 messagesBox.className = 'alert ' + alertClass; 342 343 // Close button 344 var buttonWrapper = document.createElement( 'button' ); 345 buttonWrapper.setAttribute('type', 'button'); 346 buttonWrapper.setAttribute('data-dismiss', 'alert'); 347 buttonWrapper.className = 'close'; 348 buttonWrapper.innerHTML = 'Ã'; 349 messagesBox.appendChild( buttonWrapper ); 350 351 // Title 352 title = Joomla.JText._( type ); 353 354 // Skip titles with untranslated strings 355 if ( typeof title != 'undefined' ) { 356 titleWrapper = document.createElement( 'h4' ); 357 titleWrapper.className = 'alert-heading'; 358 titleWrapper.innerHTML = Joomla.JText._( type ); 359 messagesBox.appendChild( titleWrapper ); 360 } 361 362 // Add messages to the message box 363 for ( i = typeMessages.length - 1; i >= 0; i-- ) { 364 messageWrapper = document.createElement( 'div' ); 365 messageWrapper.innerHTML = typeMessages[ i ]; 366 messagesBox.appendChild( messageWrapper ); 367 } 368 369 messageContainer.appendChild( messagesBox ); 370 } 371 }; 372 373 /** 374 * Remove messages 375 * 376 * @return {void} 377 */ 378 Joomla.removeMessages = function() { 379 var messageContainer = document.getElementById( 'system-message-container' ); 380 381 // Empty container with a while for Chrome performance issues 382 while ( messageContainer.firstChild ) messageContainer.removeChild( messageContainer.firstChild ); 383 384 // Fix Chrome bug not updating element height 385 messageContainer.style.display = 'none'; 386 messageContainer.offsetHeight; 387 messageContainer.style.display = ''; 388 }; 389 390 /** 391 * Treat AJAX errors. 392 * Used by some javascripts such as sendtestmail.js and permissions.js 393 * 394 * @param {object} xhr XHR object. 395 * @param {string} textStatus Type of error that occurred. 396 * @param {string} error Textual portion of the HTTP status. 397 * 398 * @return {object} JavaScript object containing the system error message. 399 * 400 * @since 3.6.0 401 */ 402 Joomla.ajaxErrorsMessages = function( xhr, textStatus, error ) { 403 var msg = {}; 404 405 // For jQuery jqXHR 406 if (textStatus === 'parsererror') 407 { 408 // Html entity encode. 409 var encodedJson = xhr.responseText.trim(); 410 411 var buf = []; 412 for (var i = encodedJson.length-1; i >= 0; i--) { 413 buf.unshift( [ '&#', encodedJson[i].charCodeAt(), ';' ].join('') ); 414 } 415 416 encodedJson = buf.join(''); 417 418 msg.error = [ Joomla.JText._('JLIB_JS_AJAX_ERROR_PARSE').replace('%s', encodedJson) ]; 419 } 420 else if (textStatus === 'nocontent') 421 { 422 msg.error = [ Joomla.JText._('JLIB_JS_AJAX_ERROR_NO_CONTENT') ]; 423 } 424 else if (textStatus === 'timeout') 425 { 426 msg.error = [ Joomla.JText._('JLIB_JS_AJAX_ERROR_TIMEOUT') ]; 427 } 428 else if (textStatus === 'abort') 429 { 430 msg.error = [ Joomla.JText._('JLIB_JS_AJAX_ERROR_CONNECTION_ABORT') ]; 431 } 432 // For vannila XHR 433 else if (xhr.responseJSON && xhr.responseJSON.message) 434 { 435 msg.error = [ Joomla.JText._('JLIB_JS_AJAX_ERROR_OTHER').replace('%s', xhr.status) + ' <em>' + xhr.responseJSON.message + '</em>' ]; 436 } 437 else if (xhr.statusText) 438 { 439 msg.error = [ Joomla.JText._('JLIB_JS_AJAX_ERROR_OTHER').replace('%s', xhr.status) + ' <em>' + xhr.statusText + '</em>' ]; 440 } 441 else 442 { 443 msg.error = [ Joomla.JText._('JLIB_JS_AJAX_ERROR_OTHER').replace('%s', xhr.status) ]; 444 } 445 446 return msg; 447 }; 448 449 /** 450 * USED IN: administrator/components/com_cache/views/cache/tmpl/default.php 451 * administrator/components/com_installer/views/discover/tmpl/default_item.php 452 * administrator/components/com_installer/views/update/tmpl/default_item.php 453 * administrator/components/com_languages/helpers/html/languages.php
454 * libraries/joomla/html/html/grid.php 455 * 456 * @param {boolean} isitchecked Flag for checked 457 * @param {node} form The form 458 * 459 * @return {void} 460 */ 461 Joomla.isChecked = function( isitchecked, form ) { 462 if ( typeof form === 'undefined' ) { 463 form = document.getElementById( 'adminForm' ); 464 } 465 466 form.boxchecked.value = isitchecked ? parseInt(form.boxchecked.value) + 1 : parseInt(form.boxchecked.value) - 1; 467 468 // If we don't have a checkall-toggle, done. 469 if ( !form.elements[ 'checkall-toggle' ] ) return; 470 471 // Toggle main toggle checkbox depending on checkbox selection 472 var c = true, i, e, n; 473 474 for ( i = 0, n = form.elements.length; i < n; i++ ) { 475 e = form.elements[ i ]; 476 477 if ( e.type == 'checkbox' && e.name != 'checkall-toggle' && !e.checked ) { 478 c = false; 479 break; 480 } 481 } 482 483 form.elements[ 'checkall-toggle' ].checked = c; 484 }; 485 486 /** 487 * USED IN: libraries/joomla/html/toolbar/button/help.php 488 * 489 * Pops up a new window in the middle of the screen 490 * 491 * @note This will be moved out of core.js into a new file toolbar.js in Joomla 4 492 */ 493 Joomla.popupWindow = function( mypage, myname, w, h, scroll ) { 494 var winl = ( screen.width - w ) / 2, 495 wint = ( screen.height - h ) / 2, 496 winprops = 'height=' + h + 497 ',width=' + w + 498 ',top=' + wint + 499 ',left=' + winl + 500 ',scrollbars=' + scroll + 501 ',resizable'; 502 503 window.open( mypage, myname, winprops ) 504 .window.focus(); 505 }; 506 507 /** 508 * USED IN: libraries/joomla/html/html/grid.php 509 * In other words, on any reorderable table 510 * 511 * @param {string} order The order value 512 * @param {string} dir The direction 513 * @param {string} task The task 514 * @param {node} form The form 515 * 516 * return {void} 517 */ 518 Joomla.tableOrdering = function( order, dir, task, form ) { 519 if ( typeof form === 'undefined' ) { 520 form = document.getElementById( 'adminForm' ); 521 } 522 523 form.filter_order.value = order; 524 form.filter_order_Dir.value = dir; 525 Joomla.submitform( task, form ); 526 }; 527 528 /** 529 * USED IN: administrator/components/com_modules/views/module/tmpl/default.php 530 * 531 * Writes a dynamically generated list 532 * 533 * @param string 534 * The parameters to insert into the <select> tag 535 * @param array 536 * A javascript array of list options in the form [key,value,text] 537 * @param string 538 * The key to display for the initial state of the list 539 * @param string 540 * The original key that was selected 541 * @param string 542 * The original item value that was selected 543 * @param string 544 * The elem where the list will be written 545 * 546 * @deprecated 4.0 No replacement 547 */ 548 window.writeDynaList = function ( selectParams, source, key, orig_key, orig_val, element ) { 549 console.warn('window.writeDynaList() is deprecated without a replacement!'); 550 551 var select = document.createElement('select'); 552 var params = selectParams.split(' '); 553 554 for (var l = 0; l < params.length; l++) { 555 var par = params[l].split('='); 556 557 // make sure the attribute / content can not be used for scripting 558 if (par[0].trim().substr(0, 2).toLowerCase() === "on" 559 || par[0].trim().toLowerCase() === "href") { 560 continue; 561 } 562 563 select.setAttribute(par[0], par[1].replace(/\"/g, '')); 564 } 565 566 var hasSelection = key == orig_key, i, selected, item; 567 568 for (i = 0; i < source.length; i++) { 569 item = source[i]; 570 571 if (item[0] != key) { continue; } 572 573 selected = hasSelection ? orig_val == item[1] : i === 0; 574 575 var el = document.createElement('option'); 576 el.setAttribute('value', item[1]); 577 el.innerText = item[2]; 578 579 if (selected) { 580 el.setAttribute('selected', 'selected'); 581 } 582 583 select.appendChild(el); 584 } 585 586 if (element) { 587 element.appendChild(select); 588 } else { 589 document.body.appendChild(select); 590 } 591 }; 592 593 /** 594 * USED IN: administrator/components/com_content/views/article/view.html.php 595 * actually, probably not used anywhere. 596 * 597 * Changes a dynamically generated list 598 * 599 * @param string 600 * The name of the list to change 601 * @param array 602 * A javascript array of list options in the form [key,value,text] 603 * @param string 604 * The key to display 605 * @param string 606 * The original key that was selected 607 * @param string 608 * The original item value that was selected 609 * 610 * @deprecated 4.0 No replacement 611 */ 612 window.changeDynaList = function ( listname, source, key, orig_key, orig_val ) { 613 console.warn('window.changeDynaList() is deprecated without a replacement!'); 614 615 var list = document.adminForm[ listname ], 616 hasSelection = key == orig_key, 617 i, x, item, opt; 618 619 // empty the list 620 while ( list.firstChild ) list.removeChild( list.firstChild ); 621 622 i = 0; 623 624 for ( x in source ) { 625 if (!source.hasOwnProperty(x)) { continue; } 626 627 item = source[x]; 628 629 if ( item[ 0 ] != key ) { continue; } 630 631 opt = new Option(); 632 opt.value = item[ 1 ]; 633 opt.text = item[ 2 ]; 634 635 if ( ( hasSelection && orig_val == opt.value ) || (!hasSelection && i === 0) ) { 636 opt.selected = true; 637 } 638 639 list.options[ i++ ] = opt; 640 } 641 642 list.length = i; 643 }; 644 645 /** 646 * USED IN: administrator/components/com_menus/views/menus/tmpl/default.php 647 * Probably not used at all 648 * 649 * @param radioObj 650 * @return 651 * 652 * @deprecated 4.0 No replacement 653 */ 654 // return the value of the radio button that is checked 655 // return an empty string if none are checked, or 656 // there are no radio buttons 657 window.radioGetCheckedValue = function ( radioObj ) { 658 console.warn('window.radioGetCheckedValue() is deprecated without a replacement!'); 659 660 if ( !radioObj ) { return ''; } 661 662 var n = radioObj.length, 663 i; 664 665 if ( n === undefined ) { 666 return radioObj.checked ? radioObj.value : ''; 667 } 668 669 for ( i = 0; i < n; i++ ) { 670 if ( radioObj[ i ].checked ) { 671 return radioObj[ i ].value; 672 } 673 } 674 675 return ''; 676 }; 677 678 /** 679 * USED IN: administrator/components/com_users/views/mail/tmpl/default.php 680 * Let's get rid of this and kill it 681 * 682 * @param frmName 683 * @param srcListName 684 * @return 685 * 686 * @deprecated 4.0 No replacement 687 */ 688 window.getSelectedValue = function ( frmName, srcListName ) { 689 console.warn('window.getSelectedValue() is deprecated without a replacement!'); 690 691 var srcList = document[ frmName ][ srcListName ], 692 i = srcList.selectedIndex; 693 694 if ( i !== null && i > -1 ) { 695 return srcList.options[ i ].value; 696 } else { 697 return null; 698 } 699 }; 700 701 /** 702 * USED IN: all over :) 703 * 704 * @param id 705 * @param task 706 * @return 707 * 708 * @deprecated 4.0 Use Joomla.listItemTask() instead 709 */ 710 window.listItemTask = function ( id, task ) { 711 console.warn('window.listItemTask() is deprecated use Joomla.listItemTask() instead'); 712 713 return Joomla.listItemTask( id, task ); 714 }; 715 716 /** 717 * USED IN: all over :) 718 * 719 * @param {string} id The id 720 * @param {string} task The task 721 * 722 * @return {boolean} 723 */ 724 Joomla.listItemTask = function ( id, task ) { 725 var f = document.adminForm, 726 i = 0, cbx, 727 cb = f[ id ]; 728 729 if ( !cb ) return false;
730 731 while ( true ) { 732 cbx = f[ 'cb' + i ]; 733 734 if ( !cbx ) break; 735 736 cbx.checked = false; 737 738 i++; 739 } 740 741 cb.checked = true; 742 f.boxchecked.value = 1; 743 window.submitform( task ); 744 745 return false; 746 }; 747 748 /** 749 * Default function. Usually would be overriden by the component 750 * 751 * @deprecated 4.0 Use Joomla.submitbutton() instead. 752 */ 753 window.submitbutton = function ( pressbutton ) { 754 console.warn('window.submitbutton() is deprecated use Joomla.submitbutton() instead'); 755 756 Joomla.submitbutton( pressbutton ); 757 }; 758 759 /** 760 * Submit the admin form 761 * 762 * @deprecated 4.0 Use Joomla.submitform() instead. 763 */ 764 window.submitform = function ( pressbutton ) { 765 console.warn('window.submitform() is deprecated use Joomla.submitform() instead'); 766 767 Joomla.submitform(pressbutton); 768 }; 769 770 // needed for Table Column ordering 771 /** 772 * USED IN: libraries/joomla/html/html/grid.php 773 * There's a better way to do this now, can we try to kill it? 774 * 775 * @deprecated 4.0 No replacement 776 */ 777 window.saveorder = function ( n, task ) { 778 console.warn('window.saveorder() is deprecated without a replacement!'); 779 780 window.checkAll_button( n, task ); 781 }; 782 783 /** 784 * Checks all the boxes unless one is missing then it assumes it's checked out. 785 * Weird. Probably only used by ^saveorder 786 * 787 * @param integer n The total number of checkboxes expected 788 * @param string task The task to perform 789 * 790 * @return void 791 * 792 * @deprecated 4.0 No replacement 793 */ 794 window.checkAll_button = function ( n, task ) { 795 console.warn('window.checkAll_button() is deprecated without a replacement!'); 796 797 task = task ? task : 'saveorder'; 798 799 var j, box; 800 801 for ( j = 0; j <= n; j++ ) { 802 box = document.adminForm[ 'cb' + j ]; 803 804 if ( box ) { 805 box.checked = true; 806 } else { 807 alert( "You cannot change the order of items, as an item in the list is `Checked Out`" ); 808 return; 809 } 810 } 811 812 Joomla.submitform( task ); 813 }; 814 815 /** 816 * Add Joomla! loading image layer. 817 * 818 * Used in: /administrator/components/com_installer/views/languages/tmpl/default.php 819 * /installation/template/js/installation.js 820 * 821 * @param {String} task The task to do [load, show, hide] (defaults to show). 822 * @param {HTMLElement} parentElement The HTML element where we are appending the layer (defaults to body). 823 * 824 * @return {HTMLElement} The HTML loading layer element. 825 * 826 * @since 3.6.0 827 * 828 * @deprecated 4.0 No direct replacement. 829 * 4.0 will introduce a web component for the loading spinner, therefore the spinner will need to 830 * explicitly be loaded in all relevant pages. 831 */ 832 Joomla.loadingLayer = function(task, parentElement) { 833 // Set default values. 834 task = task || 'show'; 835 parentElement = parentElement || document.body; 836 837 // Create the loading layer (hidden by default). 838 if (task === 'load') 839 { 840 // Gets the site base path 841 var systemPaths = Joomla.getOptions('system.paths') || {}, 842 basePath = systemPaths.root || ''; 843 844 var loadingDiv = document.createElement('div'); 845 846 loadingDiv.id = 'loading-logo'; 847 848 // The loading layer CSS styles are JS hardcoded so they can be used without adding CSS. 849 850 // Loading layer style and positioning. 851 loadingDiv.style['position'] = 'fixed'; 852 loadingDiv.style['top'] = '0'; 853 loadingDiv.style['left'] = '0'; 854 loadingDiv.style['width'] = '100%'; 855 loadingDiv.style['height'] = '100%'; 856 loadingDiv.style['opacity'] = '0.8'; 857 loadingDiv.style['filter'] = 'alpha(opacity=80)'; 858 loadingDiv.style['overflow'] = 'hidden'; 859 loadingDiv.style['z-index'] = '10000'; 860 loadingDiv.style['display'] = 'none'; 861 loadingDiv.style['background-color'] = '#fff'; 862 863 // Loading logo positioning. 864 loadingDiv.style['background-image'] = 'url("' + basePath + '/media/jui/images/ajax-loader.gif")'; 865 loadingDiv.style['background-position'] = 'center'; 866 loadingDiv.style['background-repeat'] = 'no-repeat'; 867 loadingDiv.style['background-attachment'] = 'fixed'; 868 869 parentElement.appendChild(loadingDiv); 870 } 871 // Show or hide the layer. 872 else 873 { 874 if (!document.getElementById('loading-logo')) 875 { 876 Joomla.loadingLayer('load', parentElement); 877 } 878 879 document.getElementById('loading-logo').style['display'] = (task == 'show') ? 'block' : 'none'; 880 } 881 882 return document.getElementById('loading-logo'); 883 }; 884 885 /** 886 * Method to Extend Objects 887 * 888 * @param {Object} destination 889 * @param {Object} source 890 * 891 * @return Object 892 */ 893 Joomla.extend = function (destination, source) { 894 for (var p in source) { 895 if (source.hasOwnProperty(p)) { 896 destination[p] = source[p]; 897 } 898 } 899 900 return destination; 901 }; 902 903 /** 904 * Method to perform AJAX request 905 * 906 * @param {Object} options Request options: 907 * { 908 * url: 'index.php', // Request URL 909 * method: 'GET', // Request method GET (default), POST 910 * data: null, // Data to be sent, see https://developer.mozilla.org/docs/Web/API/XMLHttpRequest/send 911 * perform: true, // Perform the request immediately, or return XMLHttpRequest instance and perform it later 912 * headers: null, // Object of custom headers, eg {'X-Foo': 'Bar', 'X-Bar': 'Foo'} 913 * 914 * onBefore: function(xhr){} // Callback on before the request 915 * onSuccess: function(response, xhr){}, // Callback on the request success 916 * onError: function(xhr){}, // Callback on the request error 917 * } 918 * 919 * @return XMLHttpRequest|Boolean 920 * 921 * @example 922 * 923 * Joomla.request({ 924 * url: 'index.php?option=com_example&view=example', 925 * onSuccess: function(response, xhr){ 926 * console.log(response); 927 * } 928 * }) 929 * 930 * @see https://developer.mozilla.org/docs/Web/API/XMLHttpRequest 931 */ 932 Joomla.request = function (options) { 933 934 // Prepare the options 935 options = Joomla.extend({ 936 url: '', 937 method: 'GET', 938 data: null, 939 perform: true 940 }, options); 941 942 // Use POST for send the data 943 options.method = options.data ? 'POST' : options.method.toUpperCase(); 944 945 // Set up XMLHttpRequest instance 946 try{ 947 var xhr = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject('MSXML2.XMLHTTP.3.0'); 948 949 xhr.open(options.method, options.url, true); 950 951 // Set the headers 952 xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest'); 953 xhr.setRequestHeader('X-Ajax-Engine', 'Joomla!'); 954 955 if (options.method === 'POST') { 956 var token = Joomla.getOptions('csrf.token', ''); 957 958 if (token) { 959 xhr.setRequestHeader('X-CSRF-Token', token); 960 } 961 962 if (typeof(options.data) === 'string' && (!options.headers || !options.headers['Content-Type'])) { 963 xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); 964 } 965 } 966 967 // Custom headers 968 if (options.headers){ 969 for (var p in options.headers) { 970 if (options.headers.hasOwnProperty(p)) { 971 xhr.setRequestHeader(p, options.headers[p]); 972 } 973 } 974 } 975 976 xhr.onreadystatechange = function () { 977 // Request not finished 978 if (xhr.readyState !== 4) return; 979 980 // Request finished and response is ready 981 if (xhr.status === 200) { 982 if(options.onSuccess) { 983 options.onSuccess.call(window, xhr.responseText, xhr); 984 } 985 } else if(options.onError) { 986 options.onError.call(window, xhr); 987 } 988 }; 989 990 // Do request 991 if (options.perform) { 992 if (options.onBefore && options.onBefore.call(window, xhr) === false) { 993 // Request interrupted 994 return xhr; 995 } 996 997 xhr.send(options.data); 998 } 999 1000 } catch (error) { 1001 window.console ? console.log(error) : null; 1002 return false;
1003 } 1004 1005 return xhr; 1006 }; 1007 1008}( 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.