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