--- a/src/pyams_skin/resources/js/myams-plugins.js Thu Dec 20 18:40:36 2018 +0100
+++ b/src/pyams_skin/resources/js/myams-plugins.js Thu Dec 20 18:41:40 2018 +0100
@@ -1464,6 +1464,71 @@
},
/**
+ * HTML editor with syntax highlight
+ */
+ editor: function(element) {
+ var editors = $('.text-editor textarea', element);
+ if (editors.length > 0) {
+ ams.ajax && ams.ajax.check(globals.ace,
+ ams.baseURL + 'ext/ace/ace.js',
+ function(first_load) {
+
+ var initEditors = function() {
+ globals.ace_loaded = true;
+ editors.each(function() {
+
+ // Find textarea attributes
+ var textarea = $(this),
+ widget = textarea.parents('.text-editor'),
+ data = widget.data(),
+ modeList = ace.require('ace/ext/modelist'),
+ mode = modeList.getModeForPath(widget.data('ams-editor-filename') || 'editor.txt').mode;
+
+ // Create editor DIV
+ var textEditor = $('<div>', {
+ position: 'absolute',
+ width: textarea.width(),
+ height: textarea.height(),
+ 'class': textarea.attr('class')
+ }).insertBefore(textarea);
+ textarea.css('display', 'none');
+
+ // Initialize editor
+ var editor = ace.edit(textEditor[0]),
+ dataOptions = {
+ mode: mode,
+ tabSize: 4,
+ useSoftTabs: false,
+ showGutter: true,
+ showLineNumbers: true,
+ printMargin: 132,
+ showInvisibles: true
+ },
+ settings = $.extend({}, dataOptions, data.amsEditorOptions);
+ settings = ams.executeFunctionByName(data.amsEditorInitCallback, textarea, settings) || settings;
+ editor.setOptions(settings);
+ editor.session.setValue(textarea.val());
+ editor.session.on('change', function() {
+ textarea.val(editor.session.getValue());
+ });
+ widget.data('editor', editor);
+ ams.executeFunctionByName(data.amsEditorAfterInitCallback, textarea, editor, settings);
+ });
+ };
+
+ if (first_load) {
+ ace.config.set('basePath', ams.baseURL + 'ext/ace');
+ ams.ajax.check(globals.ace_loaded, [
+ ams.baseURL + 'ext/ace/ext-modelist.js'
+ ], initEditors);
+ } else {
+ initEditors();
+ }
+ });
+ }
+ },
+
+ /**
* Image area select plug-in
*/
imgareaselect: function(element) {