--- a/src/pyams_skin/resources/js/myams.js Thu Dec 20 18:40:36 2018 +0100
+++ b/src/pyams_skin/resources/js/myams.js Thu Dec 20 18:41:40 2018 +0100
@@ -1032,10 +1032,11 @@
var defaults = {
async: typeof(callback) === 'function'
};
- var settings = $.extend({}, defaults, options);
+ var settings = $.extend({}, defaults, options),
+ deferred = [],
+ index;
if (checker instanceof Array) {
- var deferred = [];
- for (var index = 0; index < checker.length; index++) {
+ for (index = 0; index < checker.length; index++) {
if (checker[index] === undefined) {
deferred.push(ams.getScript(source[index], {async: true}));
}
@@ -1048,7 +1049,18 @@
callCallbacks(false, options);
}
} else if (checker === undefined) {
- if (typeof(source) === 'string') {
+ if (source instanceof Array) {
+ for (index = 0; index < source.length; index++) {
+ deferred.push(ams.getScript(source[index], {async: true}));
+ }
+ if (deferred.length > 0) {
+ $.when.apply($, deferred).then(function () {
+ callCallbacks(true, options);
+ });
+ } else {
+ callCallbacks(false, options);
+ }
+ } else if (typeof(source) === 'string') {
ams.getScript(source, function () {
callCallbacks(true, options);
}, settings);
@@ -4698,6 +4710,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) {