Disposing the code editor

This commit is contained in:
alekseybobkov 2015-04-22 21:33:07 -07:00
parent 35f742c8f5
commit 6458149cd5
2 changed files with 32 additions and 4 deletions

View File

@ -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

View File

@ -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) {