From bc824ed02167c80ae8bbcc50beb66e5884e06c63 Mon Sep 17 00:00:00 2001 From: Sam Georges Date: Sat, 24 May 2014 15:18:08 +1000 Subject: [PATCH] Create public function for getting the ACE editor Improve API --- .../codeeditor/assets/js/codeeditor.js | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/modules/backend/formwidgets/codeeditor/assets/js/codeeditor.js b/modules/backend/formwidgets/codeeditor/assets/js/codeeditor.js index e6eda5b46..c685c8c3a 100644 --- a/modules/backend/formwidgets/codeeditor/assets/js/codeeditor.js +++ b/modules/backend/formwidgets/codeeditor/assets/js/codeeditor.js @@ -106,11 +106,11 @@ /* * Set language and theme */ - assetManager.load({ + assetManager.load({ js:[ options.vendorPath + '/mode-' + options.language + '.js', options.vendorPath + '/theme-' + options.theme + '.js' - ] + ] }, function(){ editor.setTheme('ace/theme/'+options.theme) var inline = options.language === 'php' @@ -142,7 +142,7 @@ /* * Toolbar */ - + this.$toolbar.find('>ul>li>a') .each(function(){ var abbr = $(this).find('>abbr'), @@ -178,6 +178,10 @@ }) } + CodeEditor.prototype.getEditorObject = function() { + return this.editor + } + CodeEditor.prototype.toggleFullscreen = function() { this.$el.toggleClass('editor-fullscreen') this.$fullscreenEnable.toggle() @@ -202,7 +206,8 @@ var old = $.fn.codeEditor $.fn.codeEditor = function (option) { - return this.each(function () { + var args = Array.prototype.slice.call(arguments, 1), result + this.each(function () { var $this = $(this) var data = $this.data('oc.codeEditor') var options = $.extend({}, CodeEditor.DEFAULTS, $this.data(), typeof option == 'object' && option) @@ -210,8 +215,11 @@ $this.data('oc.codeEditor', (data = new CodeEditor(this, options))) $this.trigger('oc.codeEditorReady') } - if (typeof option == 'string') data[option].call($this) + if (typeof option == 'string') result = data[option].apply(data, args) + if (typeof result != 'undefined') return false }) + + return result ? result : this } $.fn.codeEditor.Constructor = CodeEditor