forked from yaronkoren/TinyMCE-old
-
Notifications
You must be signed in to change notification settings - Fork 1
/
MW_tinymce-test.js
855 lines (788 loc) · 33.5 KB
/
MW_tinymce-test.js
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
/**
* TinyMCE extension setup
*
* Set's parameters for the editor using defaults unless over-ridden in LocalSettings.php
*
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License v2 or later
* @filesource
*/
var editor = tinymce.activeEditor,
mw_server = 'https://' + mw.config.get( 'wgServer' ) + '/',
mw_scriptPath = mw.config.get( 'wgScriptPath' ),
mw_api = mw_scriptPath + '/api.php',
mw_extensionAssetsPath = mw.config.get( 'wgExtensionAssetsPath' ),
mw_namespaces = mw.config.get( 'wgNamespaceIds' ),
mw_url_protocols = mw.config.get( 'wgUrlProtocols' ),
mw_canonical_namespace = mw.config.get( "wgCanonicalNamespace" ),
mw_title = mw.config.get( "wgTitle" ),
tinyMCETemplates = mw.config.get( 'wgTinyMCETemplates' ),
tinyMCETagList = mw.config.get( 'wgTinyMCETagList' ),
tinyMCELanguage = mw.config.get( 'wgTinyMCELanguage' ),
tinyMCEDirectionality = mw.config.get( 'wgTinyMCEDirectionality' ),
tinyMCESettings = mw.config.get( 'wgTinyMCESettings' ) ? mw.config.get( 'wgTinyMCESettings' ) : { ".tinymce, #wpTextbox1": [] },
tinyMCEVersion = mw.config.get( 'wgTinyMCEVersion' ),
tinyMCELangURL = null,
mw_skin = mw.config.get( 'skin' ),
mw_skin_css = '/load.php?debug=false&lang=en-gb&modules=mediawiki.legacy.commonPrint%2Cshared%7Cmediawiki.sectionAnchor%7Cmediawiki.skinning.interface%7Cskins.' + mw_skin + '.styles&only=styles&skin=' + mw_skin ,
mw_shared_css = '/resources/src/mediawiki.legacy/shared.css',
mw_htmlInvariants = [ //these tags have no wiki code equivalents so don't need converting
'abbr', 'b', 'bdi', 'bdo',
'caption', 'center', 'reference',// 'code',
'data', 'del', 'dfn',
'ins', 'kbd', 'mark', 'p', 'q',
'rb', 'rp', 'rt', 'rtc', 'ruby',
's', 'strike', //'span',
'time', 'tt', 'u',
'link', 'meta', 'var', 'wbr',
],
mw_htmlPairsStatic = [ //now just non-nestable
'a',
// 'abbr',
'b',
// 'bdi',
// 'caption', 'center', 'cite',
'code', // although code is a wiki invariant html tag treat as static pair so contained wiki code correctly parsed
// 'data', 'del', 'dfn',
'img',
'h1', 'h2', 'h3', 'h4', 'h5', 'h6',
'i',
// 'ins', 'mark',
'p', // 'pre',
// 'rb', 'rp', 'rt', 'rtc',
// 's', 'strike',
'svg',
// 'time', 'tt', 'u',
],
mw_htmlBlockPairsStatic = [
'h1', 'h2', 'h3', 'h4', 'h5', 'h6',
'ol', 'ul', 'li',
'p', 'pre', 'ppre', 'pnowiki',
'blockquote',
'dl','dd','dt',
'div',
'hr',
// 'code',
// 'source',
'table',
],
mw_htmlSingle = [
// 'br', //don't render properly if process as a preserved tag!
'dd', 'dt', 'hr', 'li',
// 'link', 'meta', 'wbr',
],
mw_htmlVoid = [
'area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input', 'keygen', 'link', 'meta', 'param', 'source', 'track', 'wbr',
],
mw_htmlSingleOnly = [
'br', 'hr', 'link', 'meta', 'wbr', // these are html tags too
],
mw_extensionSingleOnly = [
'references', 'ref',
],
mw_htmlNestable = [
'bdo', 'big',
'blockquote', 'code',
'dd', 'div', 'dl', 'dt', 'em', 'font',
'kbd', 'li', 'ol', 'q', 'ruby',
'samp', 'small', 'span', 'strong', 'sub', 'sup',
'table', 'td', 'th', 'tr', 'ul', 'var', 'tbody',
],
mw_htmlInsideTable = [
'td', 'th', 'tr',
],
mw_htmlList = [
'ol', 'ul',
],
mw_htmlInsideList = [
'li',
],
mw_plainTextTagsBlock = [
'pre', /*'ppre',*/ 'pnowiki', 'source', 'comment',
],
mw_plainTextTagsInLine = [
'nowiki',
],
mw_plainTextTagsAllowedCommands = [
'Undo', 'Redo',
'SelectAll', 'Cut', 'Copy', 'Paste',
'ToggleSidebar','Delete', 'ForwardDelete',
'InsertUnorderedList', 'InsertOrderedList',
'mceInsertContent', 'mceVisualBlocks', 'mceToggleFormat',
'wikiToggleRefText', 'mwt-insertReference',
],
// the following will be used so TinyMCE doesn't filter out parser tags defined in the wiki
mw_preservedTagsList = mw_htmlPairsStatic.concat(mw_htmlSingleOnly, mw_htmlNestable, mw_htmlInvariants).join("|") + "|" + tinyMCETagList,
mw_parserValidElements = tinyMCETagList.split("|").join("[*],") + '[*]',
mw_parserCustomElements = '~' + tinyMCETagList.split("|").join(",~"),
// for some reason, setting short_ended_elements overwrites the defaults, so we include them here
mw_parserShortElements = tinyMCETagList.split("|").join(" ") + ' area base basefont br col frame hr img input isindex link meta param embed source wbr track' ;
//set up other mw related constants
// set up language url if language not 'en'
if ( tinyMCELanguage !== 'en' ) {
tinyMCELanguage = tinyMCELanguage.replace(/^([^-]*)(-)([^-]*)$/i, function( match, $1, $2, $3 ) {
// tinymce expects '-' to be '_' and part after '_' to be upper case
if ( $2 == '-' ) $2 = '_';
return $1 + $2 + $3.toUpperCase;
});
tinyMCELangURL = mw_extensionAssetsPath + '/TinyMCE/tinymce/langs/' +
tinyMCELanguage + '.js';
};
//get the local language name of the 'file' namespace
mw_fileNamespace = 'file';
for (var key in mw_namespaces ) {
if ( mw_namespaces[key] == 6 ) {
mw_fileNamespace = key;
}
};
//
// now some global functions that are used by plugins
//
var setContent = function ( editor, content, args ) {
// sets the content of the editor window
editor.focus();
editor.undoManager.transact( function () {
editor.setContent( content, args );
});
editor.focus();
editor.selection.setCursorLocation();
editor.nodeChanged();
};
var setSelection = function ( editor, content, args ) {
// sets the content of the selection. If nothing is selected
// it will insert content at the cursor. If the selection is
// contained in non-editable elements, the whole of the top
// level non-editable element is replaced with the content
var nonEditableParents = [],
bm;
editor.focus();
nonEditableParents = editor.dom.getParents( editor.selection.getNode(),function ( aNode ) {
if ( aNode.contentEditable === 'false' ) {
return aNode
}
});
if ( nonEditableParents.length > 0 ) {
editor.selection.select ( nonEditableParents[ nonEditableParents.length - 1 ] );
}
editor.undoManager.transact ( function () {
editor.selection.setContent ( content, args );
});
editor.nodeChanged();
bm = editor.selection.getBookmark();
editor.selection.moveToBookmark( bm )
};
var getContent = function ( editor, args ) {
return editor.getContent( args );
};
var getSelection = function ( editor, args ) {
return editor.selection.getContent( args );
};
var htmlDecode = function ( value ) {
return tinymce.DOM.decode( value );
};
var htmlEncode = function (value) {
return tinymce.DOM.encode( value );
};
var createUniqueNumber = function() {
return Math.floor( ( Math.random() * 100000000 ) + Date.now());
};
var translate = function( message, p1, p2, p3,p4, p5, p6 ) {
return mw.msg( message, p1, p2, p3,p4, p5, p6 )
};
var toggleEnabledState = function( editor, selectors, on ) {
// function to toggle a button's enabled state dependend
// on which nodes are selected in the editor
// if 'on' = true then the button is toggled on when the
// given selectors are true otherwise it's toggled off
return function (api) {
editor.on('NodeChange', function (e) {
var selectedNode = e.element,
parents;
api.setDisabled( on );
for (var selector in selectors) {
if (selectedNode.className.indexOf( selectors[ selector ]) > -1) {
editor.off('NodeChange', true);
return api.setDisabled( !on );
}
}
parents = $( selectedNode ).parents( selectors.join(",") );
if (parents.length > 0 ) {
editor.off('NodeChange', !on );
return api.setDisabled(false);
}
});
};
};
var doUpload = function(fileType, fileToUpload, fileName, fileSummary, ignoreWarnings){
var uploadData = new FormData(),
uploadDetails;
uploadData.append("action", "upload");
uploadData.append("filename", fileName);
uploadData.append("text", fileSummary);
uploadData.append("token", mw.user.tokens.get( 'csrfToken' ) );
uploadData.append("ignorewarnings", ignoreWarnings );
if (fileType == 'File') uploadData.append("file", fileToUpload);
if (fileType == 'URL') uploadData.append("url", fileToUpload);
uploadData.append("format", 'json');
//as we now have created the data to send, we send it...
$.ajax( { //http://stackoverflow.com/questions/6974684/how-to-send-formdata-objects-with-ajax-requests-in-jquery
url: mw_api,
contentType: false,
processData: false,
type: 'POST',
async: false,
data: uploadData,//the formdata object we created above
success: function(data){
uploadDetails = data;
},
error:function(xhr,status, error){
uploadDetails['responseText'] = xhr.responseText;
console.log(error);
}
});
return uploadDetails;
}
var checkUploadDetail = function (editor, uploadDetails, ignoreWarnings, uploadName) {
var message,
result = [];
if (typeof uploadDetails == "undefined") {
message = mw.msg("tinymce-upload-alert-unknown-error-uploading",
uploadName );
result["state"] = 'error';
} else if (typeof uploadDetails.responseText != "undefined") {
message = mw.msg("tinymce-upload-alert-error-uploading",uploadDetails.responseText);
editor.windowManager.alert(message);
result["state"] = 'error';
} else if (typeof uploadDetails.error != "undefined") {
message = mw.msg("tinymce-upload-alert-error-uploading",uploadDetails.error.info);
// if the error is because the file exists then we can ignore and
// use the existing file
if (uploadDetails.error.code == "fileexists-no-change") {
result["state"] = 'exists';
} else {
result["state"] = 'error';
editor.windowManager.alert(message);
}
} else if (typeof uploadDetails.upload.warnings != "undefined" && (!ignoreWarnings)) {
message = mw.msg("tinymce-upload-alert-warnings-encountered", uploadName) + "\n\n" ;
for (warning in uploadDetails.upload.warnings) {
warningDetails = uploadDetails.upload.warnings[warning];
if (warning == 'badfilename') {
message = message + " " + mw.msg("tinymce-upload-alert-destination-filename-not-allowed") + "\n";
editor.windowManager.alert(message);
result["state"] = 'error';
} else if (warning == 'exists') {
editor.windowManager.confirm(mw.msg("tinymce-upload-confirm-file-already-exists", uploadName),
function(ok) {
if (ok) {
result["state"] = 'exists';
} else {
result["state"] = 'error';
}
});
} else if (warning == 'duplicate') {
result["state"] = 'duplicate';
result["url"] = uploadDetails.upload.imageinfo.url;
result["page"] = uploadDetails.upload.imageinfo.canonicaltitle;
} else {
message = message + " " + mw.msg("tinymce-upload-alert-other-warning",warning) + "\n"
editor.windowManager.alert(message);
result["state"] = 'error';
}
}
} else if (typeof uploadDetails.upload.imageinfo != "undefined") {
result["state"] = 'ok';
result["url"] = uploadDetails.upload.imageinfo.url;
result["page"] = uploadDetails.upload.imageinfo.canonicaltitle;
}
return result;
}
var debug = function( editor, scope, debug, text ) {
var tinyMCEDebugFlags = editor.getParam( "tinyMCEDebugFlags" )
if ( debug == 'true' ) {
var d = new Date()
v = editor.getParam( "mwt_version" ),
id = editor.getParam( "id" );
var print_r = function ( printthis ) {
var output = '';
if ($.isArray(printthis) || typeof(printthis) == 'object') {
for(var i in printthis) {
output += i + ' : ' + printthis[i] + '\n';
}
} else {
output += printthis;
}
return output;
}
console.log( "TinyMCE Extension version " + v + " Debug Log on selector " + id + " for " + scope + " at " + d );
console.log( print_r( text ));
console.log( "END LOG" );
console.log( "" );
}
if ( tinyMCEDebugFlags.debug == 'true' ) debugger;
}
// a parameter used for passing global functions into plugins
var utility = {
setContent: setContent,
setSelection: setSelection,
getContent: getContent,
getSelection: getSelection,
htmlDecode: htmlDecode,
htmlEncode: htmlEncode,
createUniqueNumber: createUniqueNumber,
toggleEnabledState: toggleEnabledState,
translate: translate,
doUpload: doUpload,
checkUploadDetail: checkUploadDetail,
debug: debug
};
//
// these are default setting used if not overridden in LocalSettings.php
//
var defaultSettings = function(selector) {
return {
selector: selector,
auto_focus: true,
base_url: mw_extensionAssetsPath + '/TinyMCE/tinymce',
theme_url: mw_extensionAssetsPath + '/TinyMCE/tinymce/themes/silver/theme.min.js',
skin_url: mw_extensionAssetsPath + '/TinyMCE/tinymce/skins/ui/oxide',
icons_url: mw_extensionAssetsPath + '/TinyMCE/custom_plugins/mediawiki/plugins/mw_wikiparser/icons/icons.js',
icons: 'mwt',
language_url: tinyMCELangURL,
language: tinyMCELanguage,
wiki_utility: utility,
mwt_version: tinyMCEVersion,
tinyMCEDebugFlags: {
settings: false,
debug: false,
anteOnBeforeSetContent: false,
anteOnGetContent: false,
anteOnPastePostProcess: false,
postOnBeforeSetContent: false,
postOnGetContent: false,
postOnPastePostProcess: false
},
content_css:
[
mw_scriptPath + mw_skin_css,
// mw_scriptPath + mw_shared_css,
mw_extensionAssetsPath + '/TinyMCE/MW_tinymce.css',
mw_extensionAssetsPath + '/SyntaxHighlight_GeSHi/modules/pygments.wrapper.css',
mw_extensionAssetsPath + '/SyntaxHighlight_GeSHi/modules/pygments.generated.css',
],
content_css_cors: true,
external_plugins: {
'advlist': mw_extensionAssetsPath + '/TinyMCE/tinymce/plugins/advlist/plugin.js',
'anchor': mw_extensionAssetsPath + '/TinyMCE/tinymce/plugins/anchor/plugin.js',
'autoresize': mw_extensionAssetsPath + '/TinyMCE/tinymce/plugins/autoresize/plugin.js',
'autosave': mw_extensionAssetsPath + '/TinyMCE/tinymce/plugins/autosave/plugin.js',
'charmap': mw_extensionAssetsPath + '/TinyMCE/tinymce/plugins/charmap/plugin.js',
'insertdatetime': mw_extensionAssetsPath + '/TinyMCE/tinymce/plugins/insertdatetime/plugin.js',
'lists': mw_extensionAssetsPath + '/TinyMCE/tinymce/plugins/lists/plugin.js',
'noneditable': mw_extensionAssetsPath + '/TinyMCE/tinymce/plugins/noneditable/plugin.js',
'preview': mw_extensionAssetsPath + '/TinyMCE/tinymce/plugins/preview/plugin.js',
'save': mw_extensionAssetsPath + '/TinyMCE/tinymce/plugins/save/plugin.js',
'searchreplace': mw_extensionAssetsPath + '/TinyMCE/tinymce/plugins/searchreplace/plugin.js',
'template': mw_extensionAssetsPath + '/TinyMCE/tinymce/plugins/template/plugin.js',
'visualblocks': mw_extensionAssetsPath + '/TinyMCE/tinymce/plugins/visualblocks/plugin.js',
'visualchars': mw_extensionAssetsPath + '/TinyMCE/tinymce/plugins/visualchars/plugin.js',
'wikilink': mw_extensionAssetsPath + '/TinyMCE/custom_plugins/mediawiki/plugins/mw_wikilink/plugin.js',
'wikilists': mw_extensionAssetsPath + '/TinyMCE/custom_plugins/mediawiki/plugins/mw_wikilists/plugin.js',
'wikinonbreaking': mw_extensionAssetsPath + '/TinyMCE/custom_plugins/mediawiki/plugins/mw_wikinonbreaking/plugin.js',
'wikinonrenderinglinebreak': mw_extensionAssetsPath + '/TinyMCE/custom_plugins/mediawiki/plugins/mw_wikinonrenderinglinebreak/plugin.js',
'wikiparser': mw_extensionAssetsPath + '/TinyMCE/custom_plugins/mediawiki/plugins/mw_wikiparser/plugin.js',
'wikipaste': mw_extensionAssetsPath + '/TinyMCE/custom_plugins/mediawiki/plugins/mw_wikipaste/plugin.js',
'wikireference': mw_extensionAssetsPath + '/TinyMCE/custom_plugins/mediawiki/plugins/mw_wikireference/plugin.js',
'wikitable': mw_extensionAssetsPath + '/TinyMCE/custom_plugins/mediawiki/plugins/mw_wikitable/plugin.js',
'wikitemplate': mw_extensionAssetsPath + '/TinyMCE/custom_plugins/mediawiki/plugins/mw_wikitemplate/plugin.js',
'wikitext': mw_extensionAssetsPath + '/TinyMCE/custom_plugins/mediawiki/plugins/mw_wikitext/plugin.js',
'wikitoggle': mw_extensionAssetsPath + '/TinyMCE/custom_plugins/mediawiki/plugins/mw_wikitoggle/plugin.js',
'wikiupload': mw_extensionAssetsPath + '/TinyMCE/custom_plugins/mediawiki/plugins/mw_wikiupload/plugin.js',
},
//
// *** tinymce configuration ***
//
// ** mediawiki related settings**
//
// single new lines: set non_rendering_newline_character to false if you don't use non-rendering single new lines in wiki
wiki_non_rendering_newline_character: '𝔓', // was ¶
// set the page title
wiki_page_mwtPageTitle: mw_canonical_namespace + ':' + mw_title,
// set the path to the wiki api
wiki_api_path: mw_api,
// set the valid wiki namespaces
wiki_namespaces: mw_namespaces,
// set the local name of the 'file' namespace
wiki_fileNamespace: mw_fileNamespace,
// set the valid wiki protocols
wiki_url_protocols: mw_url_protocols,
// following allowed html tags are taken from
// https://phabricator.wikimedia.org/source/mediawiki/browse/REL1_29/includes/Sanitizer.php
wiki_extension_tags_list: tinyMCETagList,
wiki_preserved_tags_list: mw_preservedTagsList,
wiki_preserved_single_tags_list: mw_htmlSingle.concat(mw_htmlInsideTable).join("|"),
wiki_preserved_pairs_static_tags_list: mw_htmlPairsStatic.join("|"),
wiki_preserved_pairs_nestable_tags_list: mw_htmlNestable.join("|"),
wiki_preserved_pairs_tags_list: mw_htmlPairsStatic.concat(mw_htmlNestable).join("|"),
wiki_block_tags: mw_htmlBlockPairsStatic.join("|"),
wiki_invariant_tags: mw_htmlInvariants.join("|"),
wiki_plain_text_tags_block: mw_plainTextTagsBlock,
wiki_plain_text_tags_inline: mw_plainTextTagsInLine,
wiki_plain_text_tags_allowed_commands: mw_plainTextTagsAllowedCommands,
wiki_template_classes: [
'mcePartOfTemplate',
],
mediawikiTemplateClasses: [
'mcePartOfTemplate',
],
// ws tools flag to deco9de html enities on input
decodeHtmlEntitiesOnInput: false,
//
// ** TinyMCE editor settings **
//
// the following codes are used to display placeholders in the editor window for
// mediawiki markup that is not rendered in the page window. These allow them to be
// identified and edited in the TinyMCE editore window
//
// single new lines: set non_rendering_newline_character to false if you don't use non-rendering single new lines in wiki
showPlaceholders: false,
branding: false,
entity_encoding: 'raw',
automatic_uploads: true,
paste_data_images: true,
paste_word_valid_elements: 'b,strong,i,em,h1,h2,h3,h4,h5,table,tr,th,td,ol,ul,li,a,sub,sup,strike,br,del,div,p',
paste_webkit_styles: "none",
invalid_styles: {
'ol': 'list-style',
'ul': 'list-style',
},
browser_spellcheck: true,
visual: false,
nonbreaking_force_tab: true,
nonbreaking_wrap: false,
wikimagic_context_toolbar: true,
browsercontextmenu_context_toolbar: true,
contextmenu: "undo redo | cut copy paste insert | link wikimagic table | styleselect removeformat | browsercontextmenu",
convert_fonts_to_spans: true,
link_title: false,
link_allow_external_targets: true,
link_assume_external_targets: true,
link_class_list: [
{title: 'External', value: 'mwt-nonEditable mwt-wikiMagic mwt-externallink'},
{title: 'Internal', value: 'mwt-nonEditable mwt-wikiMagic mwt-internallink'},
],
allow_html_in_named_anchor: true,
target_list: false,
table_default_attributes: {
class: 'wikitable'
},
table_class_list: [
{title: 'None', value: ''},
{title: 'Wikitable', value: 'wikitable'}
],
table_cell_class_list: [
{title: 'None', value: ''}
],
table_row_class_list: [
{title: 'None', value: ''}
],
height: 500,
autoresize_max_height: 600,
statusbar: false,
// the default text direction for the editor
directionality: tinyMCEDirectionality,
// don't wrap the editable element?
nowrap: false,
// enable resizing for element like images, tables or media objects
object_resizing: true,
// define the element what all inline elements needs to be wrapped in
// forced_root_block: 'p',
forced_root_block: true,
forced_root_block_attrs: {
'class': 'mwt-paragraph'
},
remove_trailing_brs: false,
// indentation depth
indentation: "25px",
indent_use_margin: true,
// keep current style on pressing return
keep_styles: true,
// save plugin
save_enablewhendirty: true,
// Allow style tags in body and unordered lists in spans (inline)
valid_children: "+span[ul],+span[div],+em[div],+big[div],+small[div],-p[p],+pre[p],+p[pre]",//+p[div]",
extended_valid_elements: "span[*],pre[*],big,small," + mw_parserValidElements,
custom_elements: mw_parserCustomElements,
noneditable_noneditable_class: 'fa',
// Set the ID of the body tag in iframe to bodyContent, so styles do
// apply in a correct manner. This may be dangerous.
body_id: 'bodyContent',
// Allowable file types for file picker
// file_picker_types: 'file image media',
// Enable/disable options in upload popup
image_description: true,
image_title: true,
image_dimensions: true,
image_advtab: true,
image_class_list: [
{title: mw.msg("tinymce-upload-type-label-file"), value: 'File'},
{title: mw.msg("tinymce-upload-type-label-url"), value: 'URL'},
{title: mw.msg("tinymce-upload-type-label-wiki"), value: 'Wiki'}
],
images_dataimg_filter: function(img) {
return false;
},
font_formats: 'Andale Mono=andale mono,times; Arial=arial,helvetica,sans-serif; Arial Black=arial black,avant garde; Book Antiqua=book antiqua,palatino; Comic Sans MS=comic sans ms,sans-serif; Courier New=courier new,courier; Georgia=georgia,palatino; Helvetica=helvetica; Impact=impact,chicago; Symbol=symbol; Tahoma=tahoma,arial,helvetica,sans-serif; Terminal=terminal,monaco; Times New Roman=times new roman,times; Trebuchet MS=trebuchet ms,geneva; Verdana=verdana,geneva; Webdings=webdings; Wingdings=wingdings,zapf dingbats',
menubar: false, //'edit insert view format table tools',
contextmenu_never_use_native: false,
// fontawesome configuration
// tinymce configuration
toolbar_sticky: true,
toolbar: 'undo redo | cut copy paste insert selectall | fontselect fontsizeselect bold italic underline strikethrough subscript superscript forecolor backcolor | alignleft aligncenter alignright alignjustify | bullist numlist advlist outdent indent | wikilink wikiunlink table image media | formatselect removeformat| visualchars visualblocks| searchreplace | wikimagic wikisourcecode wikitext wikiupload | wikitoggle nonbreaking singlelinebreak reference comment template',
//style_formats_merge: true,
style_formats: [
{
title: "Table", items: [
{title: "Sortable", selector: "table", classes: "sortable"},
{title: "Wikitable", selector: "table", classes: "wikitable"},
{title: "Contenttable", selector: "table", classes: "contenttable"},
]
},
{
title: "Cell", items: [
{title: "Left", selector: "td", format: "alignleft", icon: "alignleft"},
{title: "Center", selector: "td", format: "aligncenter", icon: "aligncenter"},
{title: "Right", selector: "td", format: "alignright", icon: "alignright"},
{title: "Align Top", selector: "td", styles: {verticalalign: "top"}},
{title: "Align Middle", selector: "td", styles: {verticalalign: "middle"}},
{title: "Align Bottom", selector: "td", styles: {verticalalign: "bottom"}}
]
},
{title: "Pre", block: "pre", classes: "mw_pre_from_space"},
{title: "Paragraph", block: "p"}
],
formats: {
// Changes the default formats to have Tinymce mediawiki attributes
/* 'a|b|code|img|h1|h2|h3|h4|h5|h6|i|p|svg|br|hr|link|meta|wbr|bdo|big|blockquote|code|dd|div|dl|dt|em|font|kbd|li|ol|q|ruby|samp|small|span|strong|sub|sup|table|td|th|tr|ul|var|tbody|abbr
|b|bdi|bdo|caption|center|reference|data|del|dfn|ins|kbd|mark|p|q|rb|rp|rt|rtc|ruby|s|strike|time|tt|u|link|meta|var|wbr|gallery|indicator|html|categorytree|ref|references|imagemap|inputbox
|poem|source|syntaxhighlight|templatedata|headertabs|editinline|includeonly|onlyinclude|noinclude|nowiki'
*/
h1: { block: 'h1', attributes: { 'data-mwt-headingSpacesBefore': ' ' , 'data-mwt-headingSpacesAfter': ' ' , 'class': 'mwt-heading' } } ,
h2: { block: 'h2', attributes: { 'data-mwt-headingSpacesBefore': ' ' , 'data-mwt-headingSpacesAfter': ' ' , 'class': 'mwt-heading' } } ,
h3: { block: 'h3', attributes: { 'data-mwt-headingSpacesBefore': ' ' , 'data-mwt-headingSpacesAfter': ' ' , 'class': 'mwt-heading' } } ,
h4: { block: 'h4', attributes: { 'data-mwt-headingSpacesBefore': ' ' , 'data-mwt-headingSpacesAfter': ' ' , 'class': 'mwt-heading' } } ,
h5: { block: 'h5', attributes: { 'data-mwt-headingSpacesBefore': ' ' , 'data-mwt-headingSpacesAfter': ' ' , 'class': 'mwt-heading' } } ,
h6: { block: 'h6', attributes: { 'data-mwt-headingSpacesBefore': ' ' , 'data-mwt-headingSpacesAfter': ' ' , 'class': 'mwt-heading' } } ,
li: { block: 'li', attributes: { 'data-mwt-headingSpacesBefore': ' ' , 'data-mwt-headingSpacesAfter': ' ' , 'class': 'mwt-list' } } ,
p: { block: 'p', attributes: { 'class': 'mwt-paragraph' } },
pre: { block: 'pre', attributes: { 'data-mwt-type': 'pre' , 'class': 'mwt-heading' /*, 'data-mwt-headingSpacesAfter': ' '*/ } },
pre2: { block: 'pre', attributes: { 'data-mwt-type': 'ppre' , 'class': 'mwt-ppre' /*, 'data-mwt-headingSpacesAfter': ' '*/ } },
code: { inline: 'code', attributes: { 'data-mwt-type': 'code' , 'class': 'mwt-code' /*, 'data-mwt-headingSpacesAfter': ' '*/ } },
nowiki: { inline: 'span', attributes: { 'data-mwt-type': 'nowiki' , 'class': 'mwt-nowiki' /*, 'data-mwt-headingSpacesAfter': ' '*/ } },
pnowiki: { inline: 'span', attributes: { 'data-mwt-type': 'pnowiki' , 'class': 'mwt-pnowiki' /*, 'data-mwt-headingSpacesAfter': ' '*/ } },
source: { inline: 'span', attributes: { 'data-mwt-type': 'nowiki' , 'class': 'mwt-source' /*, 'data-mwt-headingSpacesAfter': ' '*/ } },
comment: { inline: 'span', attributes: { 'data-mwt-type': 'comment' , 'class': 'mwt-comment' /*, 'data-mwt-headingSpacesAfter': ' '*/ } },
// removePreserveHtmlTag: { selector: '*.mwt-preserveHtml', attributes: { 'class': '' } },
removePreserveHtmlTag: { selector: mw_preservedTagsList.split("|").join(".mwt-preserveHtml,") + ".mwt-preserveHtml", attributes: { 'class': '' } },
removeformat: [
// Configures `clear formatting` to remove mw_preserveHTML class, if assigned to element
{ selector: mw_preservedTagsList.split("|").join(","), classes: 'mwt-preserveHtml', remove: 'empty' },
]
},
block_formats: 'Paragraph=p;Heading 1=h1;Heading 2=h2;Heading 3=h3;Heading 4=h4;Heading 5=h5;Heading 6=h6;Pre(without markup)=pre;Pre(with markup)=pre2;Code=code;Nowiki=nowiki',
images_upload_credentials: true,
template_selected_content_classes: "selectedcontent",
setup: function (editor) {
editor.on('PreInit', function() {
// we need to tell the editor which wiki parser tags
// or short ended as we can't find this out from the wiki itself
// Standard ones are identified above
var shortEndedElements = editor.schema.getShortEndedElements();
var extensionShortEndedTags = editor.getParam( "mediawikiExtensionTagsShortEnded" )
for (tag in mw_extensionSingleOnly) {
shortEndedElements[ mw_extensionSingleOnly[ tag ]] = {};
}
if ( extensionShortEndedTags ) {
for (tag in extensionShortEndedTags) {
shortEndedElements[ extensionShortEndedTags[ tag ] ] = {};
}
}
});
editor.on('SkinLoaded', function(e) {
var _toolbarResizeFactor = tinymce.activeEditor.getParam("toolbarResize");
/**
* dynamicallyAccessCSS
*
* @link https://github.com/Frazer/dynamicallyAccessCSS.js
* @license MIT
*
* @author Frazer Kirkman
* @published 2016
*/
function getStyleSheetRules( styleSheet ) {
if ( styleSheet.cssRules && styleSheet.cssRules.length > 0 ) {
return styleSheet.cssRules;
} else if ( styleSheet.rules && styleSheet.ruleslength > 0 ) {
return styleSheet.rules;
} else {
return [];
}
}
function getCSSRules( selector, returnArray) {
var styleSheetRules = [];
let styleSheets = Array.from( document.styleSheets ).filter(
( styleSheet ) => {
return !styleSheet.href || styleSheet.href.startsWith(window.location.origin);
}
)
if( !styleSheets[0] ){
// Create the <style> tag
var style = document.createElement( "style" );
// WebKit hack :(
style.appendChild( document.createTextNode( "" ));
// Add the <style> element to the page
document.head.appendChild( style );
}
let targetStyleSheetsRules = [];
styleSheets.forEach( function( styleSheet ) {
styleSheetRules = getStyleSheetRules( styleSheet );
for ( var x = 0; x < styleSheetRules.length; x++ ) {
if ( styleSheetRules[x].selectorText == selector ) {
targetStyleSheetsRules = targetStyleSheetsRules.concat( styleSheetRules[x] );
}
}
});
return targetStyleSheetsRules;
}
var myRules = getCSSRules( '.tox-tbtn', true );
myRules.forEach( function( thisRule ){
thisRule.style.transform = "scale(" + _toolbarResizeFactor + ")";
thisRule.style.setProperty ( "height", 34 * _toolbarResizeFactor + "px", "important" );
thisRule.style.setProperty ( "width", "auto", "important" );
});
});
},
init_instance_callback: function (instance) {
// For some reason, in some installations this only works as an inline function,
// instead of a named function defined elsewhere.
var minimizeOnBlur = $("textarea#" + instance.id).hasClass('mceMinimizeOnBlur');
if (minimizeOnBlur) {
var mcePane = $("textarea#" + instance.id).prev();
// Keep a little sliver of the toolbar so that users see it.
mcePane.find(".mce-toolbar-grp").css("height", "10px");
mcePane.find(".mce-toolbar-grp .mce-flow-layout").hide("medium");
}
},
file_picker_callback: function (cb, value, meta) {
var input = document.createElement('input');
input.setAttribute('type', 'file');
input.onchange = function () {
var file = this.files[0];
var reader = new FileReader();
reader.onload = function (e) {
var fileContent = file;
// call the callback and populate the src field with the file name
// and srccontent field with the content of the file
cb(e.target.result, {srccontent: fileContent, src: file.name});
};
reader.readAsDataURL(file);
};
input.click();
},
};
};
window.mwTinyMCEInit = function( tinyMCESelector, settings ) {
var customSettings = updateSettings( tinyMCESelector, settings ),
target = tinymce.DOM.get( tinyMCESelector.substring( 1 ) ),
editor = '';
//remove the minimize on blur class as this throws PF multiple fields
// remove any existing editor on the element first otherwise may not
// work when initialising PageForms multiple fields
if( target && target.nextSibling && target.nextSibling.classList.contains( 'tox-tinymce' )) {
editor = tinymce.get( target.id );
if ( !editor ) {
target.nextSibling.remove();
}
}
if ( !editor ) {
tinymce.init( customSettings ).then( function(editors) {
if( target && target.nextSibling && target.nextSibling.classList.contains( 'tox-tinymce' )) {
tinymce.DOM.show( target.nextSibling );
}
});
}
};
var updateSettings = function( tinyMCESelector, settings ) {
var defaultSet = defaultSettings(tinyMCESelector);
if ( settings ) {
$.each(settings, function (k, v) {
if ( k.endsWith( '+' ) ) {
// adding to default parameter
k = k.slice( 0, - 1 );
if ( defaultSet[k] === undefined ) {
defaultSet[k] = v;
} else if ($.type( defaultSet[k] ) === "string") {
defaultSet[k] = defaultSet[k] + v;
} else if (Array.isArray ( defaultSet[k] ) ) {
defaultSet[k] = defaultSet[k].concat( v );
} else if ( Object.keys( defaultSet[k]).length > 0 ) {
$.extend( defaultSet[k], v );
}
} else if ( k.endsWith( '-' ) ) {
// removing from default parameter
k = k.slice( 0, - 1 );
if ( defaultSet[k] === undefined ) {
// do nothing
} else if ($.type( defaultSet[k] ) === "string") {
// if default value is a string remove the value from it
var str = defaultSet[k],
regex,
matcher;
regex = '\\s*' + v + '\\s*';
matcher = new RegExp(regex, 'gm');
str = str.replace(matcher, ' ');
defaultSet[k] = str;
} else if (Array.isArray ( defaultSet[k] ) ) {
// if default value is an array remove the element with
// key == value from it
var i = 0,
arr = defaultSet[k];
while (i < arr.length) {
if (arr[i] === v) {
arr.splice(i, 1);
} else {
++i;
}
}
defaultSet[k] = arr;
} else if ( Object.keys( defaultSet[k] ).length > 0 ) {
// if default value is an object remove the element with
// key == value from it
var obj = defaultSet[k];
$.each( v, function ( key, val ) {
if ( obj[ val ] ) {
delete obj[ val ];
}
});
defaultSet[k] = obj;
} else if ( v == '' ) {
// if the value is blank remove the key from the default values
// key == value from it
var obj = defaultSet;
if ( obj[ k ]) {
delete obj[ k ];
}
defaultSet = obj;
}
} else {
//replacing default parameter
defaultSet[k] = v;
}
});
}
return defaultSet;
};
Object.keys( tinyMCESettings ).forEach( function(selector, index) {
window.mwTinyMCEInit( selector, this[selector] );
}, tinyMCESettings );
// Let others know we're done here
$( document ).trigger( 'TinyMCELoaded' );