From 6458149cd5d491eed047217be594f22ae71a32f8 Mon Sep 17 00:00:00 2001 From: alekseybobkov Date: Wed, 22 Apr 2015 21:33:07 -0700 Subject: [PATCH] Disposing the code editor --- .../codeeditor/assets/js/codeeditor.js | 34 ++++++++++++++++--- modules/cms/assets/js/october.cmspage.js | 2 ++ 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/modules/backend/formwidgets/codeeditor/assets/js/codeeditor.js b/modules/backend/formwidgets/codeeditor/assets/js/codeeditor.js index 2f7f7bd97..dd2c680b1 100644 --- a/modules/backend/formwidgets/codeeditor/assets/js/codeeditor.js +++ b/modules/backend/formwidgets/codeeditor/assets/js/codeeditor.js @@ -16,10 +16,15 @@ +function ($) { "use strict"; + var Base = $.oc.foundation.base, + BaseProto = Base.prototype + // CODEEDITOR CLASS DEFINITION // ============================ var CodeEditor = function(element, options) { + Base.call(this) + this.options = options this.$el = $(element) this.$textarea = this.$el.find('>textarea:first') @@ -35,6 +40,9 @@ this.init(); } + CodeEditor.prototype = Object.create(BaseProto) + CodeEditor.prototype.constructor = CodeEditor + CodeEditor.DEFAULTS = { fontSize: 12, wordWrap: 'off', @@ -136,8 +144,8 @@ editor.setReadOnly(options.readOnly) editor.getSession().setFoldStyle(options.codeFolding) editor.setFontSize(options.fontSize) - editor.on('blur', function(){ self.$el.removeClass('editor-focus') }) - editor.on('focus', function(){ self.$el.addClass('editor-focus') }) + editor.on('blur.codeeditor', function(){ self.$el.removeClass('editor-focus') }) + editor.on('focus.codeeditor', function(){ self.$el.addClass('editor-focus') }) this.setWordWrap(options.wordWrap) editor.renderer.setScrollMargin(options.margin, options.margin, 0, 0) @@ -164,8 +172,8 @@ ; this.$fullscreenDisable.hide() - this.$fullscreenEnable.on('click', '>a', $.proxy(this.toggleFullscreen, this)) - this.$fullscreenDisable.on('click', '>a', $.proxy(this.toggleFullscreen, this)) + this.$fullscreenEnable.on('click.codeeditor', '>a', $.proxy(this.toggleFullscreen, this)) + this.$fullscreenDisable.on('click.codeeditor', '>a', $.proxy(this.toggleFullscreen, this)) /* * Hotkeys @@ -182,6 +190,24 @@ }) } + CodeEditor.prototype.dispose = function() { + this.editor.off('.codeeditor') + this.editor.destroy() + + this.$fullscreenEnable.off('.codeeditor') + this.$fullscreenDisable.off('.codeeditor') + + this.$el = null + this.$textarea = null + this.$toolbar = null + this.$code = null + this.editor = null + this.$fullscreenEnable = null + this.$fullscreenDisable = null + + BaseProto.dispose.call(this) + } + CodeEditor.prototype.setWordWrap = function(mode) { var session = this.editor.getSession(), renderer = this.editor.renderer diff --git a/modules/cms/assets/js/october.cmspage.js b/modules/cms/assets/js/october.cmspage.js index 435197e1c..129565508 100644 --- a/modules/cms/assets/js/october.cmspage.js +++ b/modules/cms/assets/js/october.cmspage.js @@ -146,6 +146,8 @@ CmsPage.prototype.onBeforeTabClose = function(ev) { if ($.fn.table !== undefined) $('[data-control=table]', ev.relatedTarget).table('dispose') + + $('[data-control=codeeditor]', ev.relatedTarget).codeEditor('dispose') } CmsPage.prototype.onBeforeRequest = function(ev) {