Permalink
Browse files

first commit

  • Loading branch information...
0 parents commit 2cdda31c7920543f65cd0be8f6862c0e976e5c56 @atalargo committed Jul 20, 2010
Showing with 102 additions and 0 deletions.
  1. +23 −0 README
  2. +14 −0 init.rb
  3. +7 −0 lib/bridges/ckeditor/bridge.rb
  4. +58 −0 lib/bridges/ckeditor/lib/ckeditor_bridge.rb
@@ -0,0 +1,23 @@
+h2. ActiveScaffoldCKeditor
+
+Copyright (c) 2010 Atalargo
+
+MIT License use as you wish, see MIT-LICENSE file
+
+Version 0.2
+
+Provide CKeditor for text area content in ActiveScaffold Form
+
+h3. Installing:
+
+You must have ActiveScaffold and Rails-ckeditor plugin installed and configured
+
+
+* ./script/plugin install git://github.com/atalargo/active_scaffold_ckeditor.git
+
+ To use it, first add CKeditor javascript in your layout like indicated in Rails-ckeditor README.
+ After in a controller where you active ActiveScaffold, active CKeditor for a form_ui column
+
+ active_scaffold :page_contents do |config|
+ columns[:content].form_ui = :ckeditor
+ end
@@ -0,0 +1,14 @@
+##
+## Initialize the environment
+##
+require File.dirname(__FILE__) + '/lib/bridges/ckeditor/bridge.rb'
+
+##
+## Run the install assets script, too, just to make sure
+## But at least rescue the action in production
+##
+begin
+ # require File.dirname(__FILE__) + '/install_assets'
+rescue
+ # raise $! unless Rails.env == 'production'
+end
@@ -0,0 +1,7 @@
+ActiveScaffold.bridge "CKEditor" do
+ require File.join(File.dirname(__FILE__), "/lib/ckeditor_bridge.rb")
+ install do
+ require File.join(File.dirname(__FILE__), "/lib/ckeditor_bridge.rb")
+# ActiveScaffold::Config::Core.send :include, ActiveScaffold::CKEditorBridge
+ end
+end
@@ -0,0 +1,58 @@
+module ActiveScaffold
+ module CKEditorBridge
+ def self.included(base)
+ base.class_eval do
+ include FormColumnHelpers
+ include SearchColumnHelpers
+ include ViewHelpers
+ end
+ end
+
+ module ViewHelpers
+ def self.included(base)
+ base.alias_method_chain :active_scaffold_includes, :ckeditor
+ end
+
+ def active_scaffold_includes_with_ckeditor(*args)
+ ckeditor_js = javascript_tag(%|
+var action_link_close = ActiveScaffold.ActionLink.Abstract.prototype.close;
+ActiveScaffold.ActionLink.Abstract.prototype.close = function() {
+ this.adapter.select('textarea').each(function(elem) {
+ if (/_editor$/.test(elem.id)) {if (CKEDITOR.instances[elem.id]) {CKEDITOR.instances[elem.id].destroy(false);}}
+ });
+ action_link_close.apply(this);
+};
+ |) #if using_ckeditor?
+ active_scaffold_includes_without_ckeditor(*args) + (ckeditor_js || '') #+ (include_ckeditor_if_needed || '')
+ end
+ end
+
+ module FormColumnHelpers
+ def self.included(base)
+ base.alias_method_chain :onsubmit, :ckeditor
+ end
+
+ def active_scaffold_input_ckeditor(column, options)
+ ckeditor_textarea( :record, column.name, :width => "600px", :height => "200px", :language => I18n.locale.to_s, :class => 'CKEditor', :resize_enabled => true, :ajax => true)
+# options[:class] = "#{options[:class]} mceEditor #{column.options[:class]}".strip
+# html = []
+# html << send(override_input(:textarea), column, options)
+# html << javascript_tag("tinyMCE.execCommand('mceAddControl', false, '#{options[:id]}');") if request.xhr? || params[:iframe]
+# html.join "\n"
+ end
+
+ def onsubmit_with_ckeditor
+ submit_js = 'this.select("textarea").each(function(elem) {if (/_editor$/.test(elem.id)) {var oEditor = CKEDITOR.instances[elem.id]; document.getElementById(elem.id+"_hidden").value = oEditor.getData();CKEDITOR.instances[elem.id].destroy(false);}});' #if using_ckeditor?
+ [onsubmit_without_ckeditor, submit_js].compact.join ';'
+ end
+ end
+
+ module SearchColumnHelpers
+ def self.included(base)
+ base.class_eval { alias_method :active_scaffold_search_ckeditor, :active_scaffold_search_text }
+ end
+ end
+ end
+end
+
+ActionView::Base.class_eval {include ActiveScaffold::CKEditorBridge }

0 comments on commit 2cdda31

Please sign in to comment.