diff --git a/app/assets/javascripts/notes.js b/app/assets/javascripts/notes.js index 2834ad61e..922b42745 100644 --- a/app/assets/javascripts/notes.js +++ b/app/assets/javascripts/notes.js @@ -360,7 +360,11 @@ Danbooru.Note = { var $note_box = Danbooru.Note.Box.find(id); var text = $textarea.val(); $note_body.data("original-body", text); - Danbooru.Note.Body.set_text($note_body, text); + Danbooru.Note.Body.set_text($note_body, "Loading..."); + $.get("/note_previews.json", {body: text}).success(function(data) { + Danbooru.Note.Body.set_text($note_body, data.body); + $note_body.show(); + }); $this.dialog("close"); if (id.match(/\d/)) { @@ -386,8 +390,11 @@ Danbooru.Note = { var id = $this.data("id"); var $note_body = Danbooru.Note.Body.find(id); var text = $textarea.val(); - Danbooru.Note.Body.set_text($note_body, text); - $note_body.show(); + Danbooru.Note.Body.set_text($note_body, "Loading..."); + $.get("/note_previews.json", {body: text}).success(function(data) { + Danbooru.Note.Body.set_text($note_body, data.body); + $note_body.show(); + }); }, cancel: function() { diff --git a/app/controllers/note_previews_controller.rb b/app/controllers/note_previews_controller.rb new file mode 100644 index 000000000..81c464689 --- /dev/null +++ b/app/controllers/note_previews_controller.rb @@ -0,0 +1,12 @@ +class NotePreviewsController < ApplicationController + respond_to :json + + def show + @body = DText.sanitize(params[:body].to_s) + respond_with(@body) do |format| + format.json do + render :json => {:body => @body}.to_json + end + end + end +end diff --git a/config/routes.rb b/config/routes.rb index 58543ec82..4f53f744d 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -120,6 +120,7 @@ Danbooru::Application.routes.draw do end end resources :note_versions, :only => [:index] + resource :note_previews, :only => [:show] resources :pools do member do put :revert