From 35317b067928f587c2860767291fbe8fc863a20f Mon Sep 17 00:00:00 2001 From: Chris Dodge Date: Wed, 12 Dec 2012 20:47:37 -0500 Subject: [PATCH] more tweeks on CodeMirror. Also do a re-ordering of operations when creating a new Update, put the CodeMirror binding after the form has been inserted into the DOM. It appears to improve some rendering characteristics. --- cms/static/js/views/course_info_edit.js | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/cms/static/js/views/course_info_edit.js b/cms/static/js/views/course_info_edit.js index f176a0ec29..8a8315817a 100644 --- a/cms/static/js/views/course_info_edit.js +++ b/cms/static/js/views/course_info_edit.js @@ -69,6 +69,9 @@ CMS.Views.ClassInfoUpdateView = Backbone.View.extend({ var $newForm = $(this.template({ updateModel : newModel })); + var updateEle = this.$el.find("#course-update-list"); + $(updateEle).prepend($newForm); + var $textArea = $newForm.find(".new-update-content").first(); if (this.$codeMirror == null ) { this.$codeMirror = CodeMirror.fromTextArea($textArea.get(0), { @@ -77,9 +80,7 @@ CMS.Views.ClassInfoUpdateView = Backbone.View.extend({ lineWrapping: true, }); } - - var updateEle = this.$el.find("#course-update-list"); - $(updateEle).prepend($newForm); + $newForm.addClass('editing'); this.$currentPost = $newForm.closest('li'); @@ -94,11 +95,10 @@ CMS.Views.ClassInfoUpdateView = Backbone.View.extend({ onSave: function(event) { var targetModel = this.eventModel(event); - console.log(this.contentEntry(event).val()); targetModel.set({ date : this.dateEntry(event).val(), content : this.$codeMirror.getValue() }); // push change to display, hide the editor, submit the change - this.closeEditor(this); targetModel.save(); + this.closeEditor(this); }, onCancel: function(event) { @@ -158,9 +158,8 @@ CMS.Views.ClassInfoUpdateView = Backbone.View.extend({ self.$currentPost.find('form').hide(); window.$modalCover.unbind('click'); window.$modalCover.hide(); - if (this.$codeMirror != null) - this.$codeMirror.remove(); this.$codeMirror = null; + self.$currentPost.find('.CodeMirror').remove(); }, // Dereferencing from events to screen elements @@ -274,8 +273,7 @@ CMS.Views.ClassInfoHandoutsView = Backbone.View.extend({ this.$form.hide(); window.$modalCover.unbind('click'); window.$modalCover.hide(); - if (this.$codeMirror != null) - this.$codeMirror.remove(); + self.$form.find('.CodeMirror').remove(); this.$codeMirror = null; } }); \ No newline at end of file