|
1 | 1 | class CkeditorController < ApplicationController |
2 | 2 | skip_before_filter :verify_authenticity_token, :only => [:create] |
3 | 3 | before_filter :swf_options, :only => [:images, :files, :create] |
| 4 | + respond_to :html, :xml, :json |
4 | 5 | layout "ckeditor" |
5 | 6 |
|
6 | 7 | # GET /ckeditor/images |
7 | 8 | def images |
8 | | - @images = Ckeditor.image_model.find(:all, :order=>"id DESC") |
9 | | - |
10 | | - respond_to do |format| |
11 | | - format.html {} |
12 | | - format.xml { render :xml=>@images } |
13 | | - end |
| 9 | + @images = Ckeditor.image_model.order("id DESC") |
| 10 | + respond_with(@images) |
14 | 11 | end |
15 | 12 |
|
16 | 13 | # GET /ckeditor/files |
17 | 14 | def files |
18 | | - @files = Ckeditor.file_model.find(:all, :order=>"id DESC") |
19 | | - |
20 | | - respond_to do |format| |
21 | | - format.html {} |
22 | | - format.xml { render :xml=>@files } |
23 | | - end |
| 15 | + @files = Ckeditor.file_model.order("id DESC") |
| 16 | + respond_with(@files) |
24 | 17 | end |
25 | 18 |
|
26 | 19 | # POST /ckeditor/create/:kind |
@@ -48,7 +41,7 @@ def create |
48 | 41 |
|
49 | 42 | if @record.valid? && @record.save |
50 | 43 | @text = params[:CKEditor].blank? ? @record.to_json(:only=>[:id, :type], :methods=>[:url, :content_type, :size, :filename, :format_created_at], :root => "asset") : %Q"<script type='text/javascript'> |
51 | | - window.parent.CKEDITOR.tools.callFunction(#{params[:CKEditorFuncNum]}, '#{escape_single_quotes(@record.url_content)}'); |
| 44 | + window.parent.CKEDITOR.tools.callFunction(#{params[:CKEditorFuncNum]}, '#{Ckeditor::Utils.escape_single_quotes(@record.url_content)}'); |
52 | 45 | </script>" |
53 | 46 |
|
54 | 47 | render :text => @text |
@@ -80,9 +73,4 @@ def swf_options |
80 | 73 | @file_types_description ||= "Images" |
81 | 74 | @file_upload_limit ||= 10 |
82 | 75 | end |
83 | | - |
84 | | - def escape_single_quotes(str) |
85 | | - str.gsub('\\','\0\0').gsub('</','<\/').gsub(/\r\n|\n|\r/, "\\n").gsub(/["']/) { |m| "\\#{m}" } |
86 | | - end |
87 | | - |
88 | 76 | end |
0 commit comments