Skip to content
This repository has been archived by the owner on Aug 15, 2018. It is now read-only.

Commit

Permalink
updated to the latest fckeditor plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh Adams committed Jan 17, 2009
1 parent 7e08590 commit e6469db
Show file tree
Hide file tree
Showing 5 changed files with 130 additions and 207 deletions.
5 changes: 4 additions & 1 deletion vendor/plugins/fckeditor/README
Expand Up @@ -72,6 +72,10 @@ Then instead of the normal textarea helper from Rails use this one

<%= fckeditor_textarea("object", "field", :toolbarSet => 'Simple', :width => '100%', :height => '200px') %>

Unless if you are using a model-less form. If so, then you should use 'modelless' as object's name. So, use this one

<%= fckeditor_textarea('modelless', "field", :toolbarSet => 'Simple', :width => '100%', :height => '200px') %>

Thats it unless you are using AJAX

AJAX
Expand Down Expand Up @@ -115,4 +119,3 @@ If you install elsewhere then you will need to update spell_check.rb in the plug

FCKConfig.SpellChecker = 'SpellerPages';


95 changes: 10 additions & 85 deletions vendor/plugins/fckeditor/app/controllers/fckeditor_controller.rb
Expand Up @@ -2,92 +2,17 @@
require 'tmpdir'

class FckeditorController < ActionController::Base
before_filter :login_required
UPLOADED = "/uploads"
UPLOADED_ROOT = RAILS_ROOT + "/public" + UPLOADED
MIME_TYPES=[
"application/x-cpio",
"image/x-freehand",
"application/x-lzh",
"image/jpeg",
"text/comma-separated-values",
"audio/x-realaudio",
"x-world/x-vrml",
"application/ruby",
"application/postscript",
"application/x-latex",
"audio/basic",
"image/x-xwindowdump",
"application/x-netcdf",
"image/x-rgb",
"application/msword",
"application/x-director",
"application/x-shar",
"application/x-gzip",
"text/xml",
"text/plain",
"image/x-portable-bitmap",
"image/x-cmu-raster",
"application/zip",
"application/tar",
"application/x-troff",
"application/x-javascript",
"application/x-csh",
"image/tiff",
"image/x-xpixmap",
"audio/x-aiff",
"video/quicktime",
"application/x-authorware-seg",
"video/mpeg",
"audio/mpegurl",
"text/html",
"application/x-texinfo",
"audio/midi",
"application/x-hdf",
"application/x-authorware-bin",
"application/x-wais-source",
"text/richtext",
"application/x-tex",
"application/rtf",
"application/oda",
"application/x-ustar",
"video/x-sgi-movie",
"audio/mpeg",
"image/svg+xml",
"application/x-sv4crc",
"application/octet-stream",
"image/png",
"image/x-portable-graymap",
"application/x-troff-man",
"video/msvideo",
"audio/wav",
"application/x-troff-ms",
"application/java-archive",
"audio/x-pn-realaudio",
"image/gif",
"image/x-xbitmap",
"text/x-setext",
"application/x-sv4cpio",
"application/pdf",
"application/x-dvi",
"application/x-tcl",
"image/x-portable-pixmap",
"application/x-sh",
"application/x-troff-me",
"application/x-gtar",
"image/ief",
"image/x-portable-anymap",
"text/css",
"application/x-shockwave-flash",
"application/futuresplash",
"application/x-bcpio",
"audio/x-pn-realaudio-plugin",
"application/x-authorware-map",
"text/tab-separated-values",
"image/jpg",
"image/jpeg",
"image/pjpeg"
]
MIME_TYPES = [
"image/jpg",
"image/jpeg",
"image/pjpeg",
"image/gif",
"image/png",
"application/x-shockwave-flash"
]

RXML = <<-EOL
xml.instruct!
#=> <?xml version="1.0" encoding="utf-8" ?>
Expand Down Expand Up @@ -208,7 +133,7 @@ def current_directory_path
end

def upload_directory_path
uploaded = request.relative_url_root.to_s+"#{UPLOADED}/#{params[:Type]}"
uploaded = ActionController::Base.relative_url_root.to_s+"#{UPLOADED}/#{params[:Type]}"
"#{uploaded}#{params[:CurrentFolder]}"
end

Expand Down
7 changes: 0 additions & 7 deletions vendor/plugins/fckeditor/app/models/fyle.rb

This file was deleted.

13 changes: 0 additions & 13 deletions vendor/plugins/fckeditor/db/migrate/001_create_fyles.rb

This file was deleted.

217 changes: 116 additions & 101 deletions vendor/plugins/fckeditor/lib/fckeditor.rb
@@ -1,108 +1,123 @@
# Fckeditor
module Fckeditor
PLUGIN_NAME = 'fckeditor'
PLUGIN_PATH = "#{RAILS_ROOT}/vendor/plugins/#{PLUGIN_NAME}"
PLUGIN_PUBLIC_PATH = "#{PLUGIN_PATH}/public"
PLUGIN_CONTROLLER_PATH = "#{PLUGIN_PATH}/app/controllers"
PLUGIN_VIEWS_PATH = "#{PLUGIN_PATH}/app/views"
PLUGIN_HELPER_PATH = "#{PLUGIN_PATH}/app/helpers"

module Helper
def fckeditor_textarea(object, field, options = {})
var = instance_variable_get("@#{object}")
if var
value = var.send(field.to_sym)
value = value.nil? ? "" : value
else
value = ""
klass = Kernel.const_get("#{object}".camelcase)
instance_variable_set("@#{object}", eval("#{klass}.new()"))
end
id = options[:id] || fckeditor_element_id(object, field) # Stupid, awful hack for content_section filters
name = "#{object}[#{field}]"

fckeditor_textarea_tag(name, value, options.merge({:id => id}))
end

def fckeditor_textarea_tag(name, value='', options={})
options[:id] ||= name
cols = options[:cols].nil? ? '' : "cols='"+options[:cols]+"'"
rows = options[:rows].nil? ? '' : "rows='"+options[:rows]+"'"

width = options[:width].nil? ? '100%' : options[:width]
height = options[:height].nil? ? '100%' : options[:height]

toolbarSet = options[:toolbarSet].nil? ? 'Default' : options[:toolbarSet]

if options[:ajax]
inputs = "<input type='hidden' id='#{options[:id]}_hidden' name='#{name}'>\n" <<
"<textarea class='#{options[:className]}' id='#{options[:id]}' #{cols} #{rows} name='#{options[:id]}'>#{value}</textarea>\n"
else
inputs = "<textarea class='#{options[:className]}' id='#{options[:id]}' #{cols} #{rows} name='#{name}'>#{value}</textarea>\n"
end

js_path = "#{ActionController::Base.relative_url_root}/javascripts"
base_path = "#{js_path}/fckeditor/"
return inputs <<
javascript_tag("jQuery(document).ready(function(){ var oFCKeditor = new FCKeditor('#{options[:id]}', '#{width}', '#{height}', '#{toolbarSet}');\n" <<
"oFCKeditor.BasePath = \"#{base_path}\"\n" <<
"oFCKeditor.Config['CustomConfigurationsPath'] = '#{js_path}/fckcustom.js';\n" <<
"oFCKeditor.ReplaceTextarea(); });\n")
end


def fckeditor_form_remote_tag(options = {})
editors = options[:editors]
before = ""
editors.keys.each do |e|
editors[e].each do |f|
before += fckeditor_before_js(e, f)
end
end
options[:before] = options[:before].nil? ? before : before + options[:before]
form_remote_tag(options)
end

def fckeditor_remote_form_for(object_name, *args, &proc)
options = args.last.is_a?(Hash) ? args.pop : {}
concat(fckeditor_form_remote_tag(options), proc.binding)
fields_for(object_name, *(args << options), &proc)
concat('</form>', proc.binding)
end
alias_method :fckeditor_form_remote_for, :fckeditor_remote_form_for

def fckeditor_element_id(object, field)
id = eval("@#{object}.id")
"#{object}_#{id}_#{field}_editor"
end

def fckeditor_div_id(object, field)
id = eval("@#{object}.id")
"div-#{object}-#{id}-#{field}-editor"
end

def fckeditor_before_js(object, field, options = {})
id = options[:id] || fckeditor_element_id(object, field) # I really need to set the ID ..
"var oEditor = FCKeditorAPI.GetInstance('"+id+"'); document.getElementById('"+id+"_hidden').value = oEditor.GetXHTML();"
end
end
PLUGIN_NAME = 'fckeditor'
PLUGIN_PATH = "#{RAILS_ROOT}/vendor/plugins/#{PLUGIN_NAME}"
PLUGIN_PUBLIC_PATH = "#{PLUGIN_PATH}/public"
PLUGIN_CONTROLLER_PATH = "#{PLUGIN_PATH}/app/controllers"
PLUGIN_VIEWS_PATH = "#{PLUGIN_PATH}/app/views"
PLUGIN_HELPER_PATH = "#{PLUGIN_PATH}/app/helpers"

module Helper
def fckeditor_textarea(object, field, options = {})
if object == 'modelless'
var = object
else
var = instance_variable_get("@#{object}")
end

if var
begin
value = var.send(field.to_sym)
rescue NoMethodError
value = ''
end

value = value.nil? ? "" : value
else
value = ""
klass = "#{object}".camelcase.constantize
instance_variable_set("@#{object}", eval("#{klass}.new()"))
end

id = fckeditor_element_id(object, field)

cols = options[:cols].nil? ? '' : "cols='"+options[:cols]+"'"
rows = options[:rows].nil? ? '' : "rows='"+options[:rows]+"'"

width = options[:width].nil? ? '100%' : options[:width]
height = options[:height].nil? ? '100%' : options[:height]

toolbarSet = options[:toolbarSet].nil? ? 'Default' : options[:toolbarSet]

if var == 'modelless'
inputs_name = "#{field}"
else
inputs_name = "#{object}[#{field}]"
end

if options[:ajax]
inputs = "<input type='hidden' id='#{id}_hidden' name='#{inputs_name}'>\n" <<
"<textarea id='#{id}' #{cols} #{rows} name='#{id}'>#{value}</textarea>\n"
else
inputs = "<textarea id='#{id}' #{cols} #{rows} name='#{inputs_name}'>#{value}</textarea>\n"
end

js_path = "#{ActionController::Base.relative_url_root}/javascripts"
base_path = "#{js_path}/fckeditor/"
return inputs <<
javascript_tag("var oFCKeditor = new FCKeditor('#{id}', '#{width}', '#{height}', '#{toolbarSet}');\n" <<
"oFCKeditor.BasePath = \"#{base_path}\"\n" <<
"oFCKeditor.Config['CustomConfigurationsPath'] = '#{js_path}/fckcustom.js';\n" <<
"oFCKeditor.ReplaceTextarea();\n")
end

def fckeditor_form_remote_tag(options = {})
editors = options[:editors]
before = ""
editors.keys.each do |e|
editors[e].each do |f|
before += fckeditor_before_js(e, f)
end
end
options[:before] = options[:before].nil? ? before : before + options[:before]
form_remote_tag(options)
end

def fckeditor_remote_form_for(object_name, *args, &proc)
options = args.last.is_a?(Hash) ? args.pop : {}
concat(fckeditor_form_remote_tag(options), proc.binding)
fields_for(object_name, *(args << options), &proc)
concat('</form>', proc.binding)
end
alias_method :fckeditor_form_remote_for, :fckeditor_remote_form_for

def fckeditor_element_id(object, field)
if object == 'modelless'
id = eval("@#{object}.object_id")
else
id = eval("@#{object}.id")
end

"#{object}_#{id}_#{field}_editor"
end

def fckeditor_div_id(object, field)
id = eval("@#{object}.id")
"div-#{object}-#{id}-#{field}-editor"
end

def fckeditor_before_js(object, field)
id = fckeditor_element_id(object, field)
"var oEditor = FCKeditorAPI.GetInstance('"+id+"'); document.getElementById('"+id+"_hidden').value = oEditor.GetXHTML();"
end
end
end

include ActionView
module ActionView::Helpers::AssetTagHelper
alias_method :rails_javascript_include_tag, :javascript_include_tag
# <%= javascript_include_tag :defaults, :fckeditor %>
def javascript_include_tag(*sources)
main_sources, application_source = [], []
if sources.include?(:fckeditor)
sources.delete(:fckeditor)
sources.push('fckeditor/fckeditor')
end
unless sources.empty?
main_sources = rails_javascript_include_tag(*sources).split("\n")
application_source = main_sources.pop if main_sources.last.include?('application.js')
end
[main_sources.join("\n"), application_source].join("\n")
end
alias_method :rails_javascript_include_tag, :javascript_include_tag

# <%= javascript_include_tag :defaults, :fckeditor %>
def javascript_include_tag(*sources)
main_sources, application_source = [], []
if sources.include?(:fckeditor)
sources.delete(:fckeditor)
sources.push('fckeditor/fckeditor')
end
unless sources.empty?
main_sources = rails_javascript_include_tag(*sources).split("\n")
application_source = main_sources.pop if main_sources.last.include?('application.js')
end
[main_sources.join("\n"), application_source].join("\n")
end
end

0 comments on commit e6469db

Please sign in to comment.