root.libs.composum.nodes.commons.components.js.codeEditor.min.js Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of composum-nodes-commons Show documentation
Show all versions of composum-nodes-commons Show documentation
general components and objects to use the Sling API
(function(){CPM.namespace("core.components");(function(d,e,c){d.CodeEditorWidget=e.Widget.extend({initialize:function(a){e.Widget.prototype.initialize.apply(this,[a]);this.$editor=this.$(".code-editor");this.$findText=this.$(".search .find-text");this.$findNext=this.$(".search .find-next");this.$findPrev=this.$(".search .find-prev");this.$matchCase=this.$(".match-case");this.$findRegEx=this.$(".find-regex");this.$replText=this.$(".replace .replace-text");this.$replCurrent=this.$(".replace .replace");
this.$replAll=this.$(".replace .replace-all");this.$undo=this.$(".undo");this.$redo=this.$(".redo");this.initEditor(_.bind(function(a){this.ace.setReadOnly(!0);this.ace.navigateFileStart()},this));this.$el.resize(_.bind(this.resize,this));this.$el.on("splitpaneresize",_.bind(this.resize,this));this.$(".editor-toolbar .start-editing").click(_.bind(this.openEditDialog,this));this.searchOptions={wrap:!0,caseSensitive:!1,regExp:!1};this.$findText.on("input",_.bind(function(a){this.findText()},this));
this.$findText.keypress(_.bind(function(a){this.findText()},this));this.$findNext.click(_.bind(this.findNext,this));this.$findPrev.click(_.bind(this.findPrev,this));this.$matchCase.change(_.bind(this.toggleCaseSensitive,this));this.$findRegEx.change(_.bind(this.toggleRegExp,this));this.$replCurrent.click(_.bind(this.replace,this));this.$replAll.click(_.bind(this.replaceAll,this));this.$undo.click(_.bind(this.undo,this));this.$redo.click(_.bind(this.redo,this))},initEditor:function(a){this.ace=ace.edit(this.$editor[0]);
this.ace.setTheme("ace/theme/clouds");var b=this.$editor.attr("data-type");b&&this.ace.getSession().setMode("ace/mode/"+b);this.loadText(a)},setSaveCommand:function(a){this.ace.commands.addCommand({name:"save",bindKey:{win:"Ctrl-S",mac:"Command-S"},exec:a})},getValue:function(){return this.ace.getValue()},setValue:function(a,b){this.ace.setValue(a);b&&this.$el.trigger("change",[a])},openEditDialog:function(){this.dialog=c.getView("#text-edit-dialog",d.CodeEditorDialog);this.dialog.editSource(this)},
getPath:function(){return this.$editor.attr("data-path")},loadText:function(a){var b=this.getPath();b&&c.ajaxGet("/bin/cpm/nodes/property.bin"+c.encodePath(b),{contentType:"text/plain;charset\x3dUTF-8",dataType:"text"},_.bind(function(b){this.ace.setValue(b);this.ace.clearSelection();_.isFunction(a)&&a(b)},this),_.bind(function(a){c.alert("danger",c.i18n.get("Error"),c.i18n.get("Error on loading text"),a)},this))},saveText:function(a){var b=this.getPath();b&&c.ajaxPut("/bin/cpm/nodes/property.update.bin"+
c.encodePath(b),this.ace.getValue(),{contentType:"text/plain;charset\x3dUTF-8",dataType:"text"},void 0,void 0,_.bind(function(b,d,e){200===b.status?_.isFunction(a)&&a(b):c.alert("danger",c.i18n.get("Error"),c.i18n.get("Error on updating text"),b)},this))},reset:function(){this.ace.destroy()},resize:function(){this.ace.resize()},findText:function(a){a||(a=this.$findText.val());a&&(this.searchOptions.backwards=!1,this.ace.findAll(a,this.searchOptions,!1))},findNext:function(){this.searchOptions.backwards=
!1;this.ace.findNext(this.searchOptions,!1)},findPrev:function(){this.searchOptions.backwards=!0;this.ace.findPrevious(this.searchOptions,!1)},toggleCaseSensitive:function(a){this.searchOptions.caseSensitive=a?a.currentTarget.checked:!this.searchOptions.caseSensitive;this.findText()},toggleRegExp:function(a){this.searchOptions.regExp=a?a.currentTarget.checked:!this.searchOptions.regExp;this.findText()},replace:function(){var a=this.$replText.val();a&&this.ace.replace(a,this.searchOptions)},replaceAll:function(){var a=
this.$replText.val();a&&this.ace.replaceAll(a,this.searchOptions)},undo:function(){this.ace.undo()},redo:function(){this.ace.redo()}});e.register(".widget.code-editor-widget",d.CodeEditorWidget);d.CodeEditorDialog=d.Dialog.extend({initialize:function(a){c.components.Dialog.prototype.initialize.apply(this,[a]);this.editor=c.getWidget(this.el,".widget.code-editor-widget",d.CodeEditorWidget);this.$("button.save").click(_.bind(this.saveAndContinue,this));this.$("button.save-and-close").click(_.bind(this.saveAndClose,
this))},saveAndContinue:function(a,b){this.cursor=this.editor.ace.getCursorPosition();this.editor.saveText(_.bind(function(a){this.source&&this.source.loadText(_.bind(function(a){this.source.ace.navigateTo(this.cursor.row,this.cursor.column);this.source.ace.scrollToRow(Math.max(this.cursor.row-2,0))},this));_.isFunction(b)&&b()},this))},saveAndClose:function(a){this.saveAndContinue(a,_.bind(function(){this.hide()},this))},editSource:function(a){this.source=a;a=this.source.getPath();var b=this.source.$editor.attr("data-type");
this.selection=this.source.ace.getSelectionRange();this.cursor=this.source.ace.getCursorPosition();this.doEdit(a,b,_.bind(function(){this.editor.ace.setReadOnly(!1);this.editor.ace.scrollToRow(Math.max(this.cursor.row-2,0));this.editor.ace.navigateTo(this.cursor.row,this.cursor.column);this.editor.ace.focus()},this))},editFile:function(a,b){this.source=void 0;this.doEdit(a,b,_.bind(function(){this.editor.ace.setReadOnly(!1);this.editor.ace.focus()},this))},doEdit:function(a,b,c){this.$(".modal-title").text(a);
this.editor.$editor.attr("data-path",a);this.editor.$editor.attr("data-type",b);this.show(_.bind(function(){this.editor.initEditor(c);this.editor.setSaveCommand(_.bind(function(a){this.saveAndContinue()},this))},this))},reset:function(){d.Dialog.prototype.reset.apply(this);this.editor.reset()}})})(CPM.core.components,CPM.widgets,CPM.core)})();
© 2015 - 2025 Weber Informatics LLC | Privacy Policy