From 939261f7d57d6c816879c14b19a84702c9afec3d Mon Sep 17 00:00:00 2001 From: Randy Stauner Date: Mon, 29 Sep 2014 19:53:24 -0700 Subject: [PATCH] Turn editor features (Behave) on/off via settings refs #3. --- app/scripts/view/request.js | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/app/scripts/view/request.js b/app/scripts/view/request.js index 9a81d1a..4d9b780 100644 --- a/app/scripts/view/request.js +++ b/app/scripts/view/request.js @@ -1,11 +1,12 @@ define([ "underscore", "view", + "settings", "behave", "highlight", "tpl!template/request.htm", "bootstrap-dropdown" -], function(_, View, Behave, hljs, template) { +], function(_, View, settings, Behave, hljs, template) { return View.extend({ name: "request", template: template, @@ -35,6 +36,7 @@ define([ this.$body.val(this.model.get("body")); this.validateBody(); }); + this.listenTo(settings, 'change:editorFeatures', this._setEditorFeatures); }, updateResponse: function() { var res = _.escape(this.model.get("response")); @@ -47,12 +49,22 @@ define([ this.$label = this.$(".editor .label").hide(); this.$body = this.$("textarea"); this.$response = this.$('pre code'); - new Behave({ - textarea: this.$("textarea").get(0), - tabSize: 2 - }); + this._setEditorFeatures(null, settings.get('editorFeatures')); this.updateResponse(); return this; + }, + + _setEditorFeatures: function(m, enabled, o) { + if( this.behave ){ + this.behave.destroy(); + this.behave = null; + } + if( enabled ){ + this.behave = new Behave({ + textarea: this.$body.get(0), + tabSize: 2 + }); + } } }); });