Actualizar plugin CKEditor a 1.2.3
This commit is contained in:
parent
fd78375294
commit
dda045bde9
23 changed files with 513 additions and 240 deletions
|
@ -1,4 +1,5 @@
|
|||
require 'rake'
|
||||
require 'rails/generators'
|
||||
|
||||
module RedmineCkeditor
|
||||
class RichAssetsGenerator < Rails::Generators::Base
|
||||
|
|
|
@ -128,17 +128,22 @@ module RedmineCkeditor
|
|||
end
|
||||
|
||||
def apply_patch
|
||||
require 'redmine_ckeditor/application_helper_patch'
|
||||
require 'redmine_ckeditor/queries_helper_patch'
|
||||
require 'redmine_ckeditor/rich_files_helper_patch'
|
||||
require 'redmine_ckeditor/journals_controller_patch'
|
||||
require 'redmine_ckeditor/messages_controller_patch'
|
||||
require 'redmine_ckeditor/mail_handler_patch'
|
||||
::ApplicationController.send :helper, ApplicationHelperPatch
|
||||
::JournalsController.prepend JournalsControllerPatch
|
||||
::MailHandler.prepend MailHandlerPatch
|
||||
::MessagesController.prepend MessagesControllerPatch
|
||||
::QueriesController.send :helper, QueriesHelperPatch
|
||||
::Rich::FilesController.send :helper, RichFilesHelperPatch
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
require 'redmine_ckeditor/hooks/views_layouts_hook'
|
||||
require 'redmine_ckeditor/hooks/journal_listener'
|
||||
require 'redmine_ckeditor/helper'
|
||||
require 'redmine_ckeditor/application_helper_patch'
|
||||
require 'redmine_ckeditor/queries_helper_patch'
|
||||
require 'redmine_ckeditor/rich_files_helper_patch'
|
||||
require 'redmine_ckeditor/journals_controller_patch'
|
||||
require 'redmine_ckeditor/messages_controller_patch'
|
||||
require 'redmine_ckeditor/mail_handler_patch'
|
||||
require 'redmine_ckeditor/pdf_patch'
|
||||
require 'redmine_ckeditor/tempfile_patch'
|
||||
|
|
|
@ -1,22 +1,13 @@
|
|||
require_dependency 'application_helper'
|
||||
module RedmineCkeditor
|
||||
module ApplicationHelperPatch
|
||||
include RedmineCkeditor::Helper
|
||||
|
||||
module ApplicationHelper
|
||||
def ckeditor_javascripts
|
||||
root = RedmineCkeditor.assets_root
|
||||
javascript_tag("CKEDITOR_BASEPATH = '#{root}/ckeditor/';") +
|
||||
javascript_include_tag("application", :plugin => "redmine_ckeditor") +
|
||||
javascript_tag(RedmineCkeditor.plugins.map {|name|
|
||||
path = "#{root}/ckeditor-contrib/plugins/#{name}/"
|
||||
"CKEDITOR.plugins.addExternal('#{name}', '#{path}/');"
|
||||
}.join("\n"))
|
||||
end
|
||||
|
||||
def format_activity_description_with_ckeditor(text)
|
||||
if RedmineCkeditor.enabled?
|
||||
simple_format(truncate(HTMLEntities.new.decode(strip_tags(text.to_s)), :length => 120))
|
||||
else
|
||||
format_activity_description_without_ckeditor(text)
|
||||
def format_activity_description(text)
|
||||
if RedmineCkeditor.enabled?
|
||||
simple_format(truncate(HTMLEntities.new.decode(strip_tags(text.to_s)), :length => 120))
|
||||
else
|
||||
super
|
||||
end
|
||||
end
|
||||
end
|
||||
alias_method_chain :format_activity_description, :ckeditor
|
||||
end
|
||||
|
|
37
plugins/redmine_ckeditor/lib/redmine_ckeditor/helper.rb
Normal file
37
plugins/redmine_ckeditor/lib/redmine_ckeditor/helper.rb
Normal file
|
@ -0,0 +1,37 @@
|
|||
module RedmineCkeditor
|
||||
module Helper
|
||||
def ckeditor_javascripts
|
||||
root = RedmineCkeditor.assets_root
|
||||
plugin_script = RedmineCkeditor.plugins.map {|name|
|
||||
"CKEDITOR.plugins.addExternal('#{name}', '#{root}/ckeditor-contrib/plugins/#{name}/');"
|
||||
}.join
|
||||
|
||||
javascript_tag("CKEDITOR_BASEPATH = '#{root}/ckeditor/';") +
|
||||
javascript_include_tag("application", :plugin => "redmine_ckeditor") +
|
||||
javascript_tag(<<-EOT)
|
||||
#{plugin_script}
|
||||
|
||||
CKEDITOR.on("instanceReady", function(event) {
|
||||
var editor = event.editor;
|
||||
var textarea = document.getElementById(editor.name);
|
||||
editor.on("change", function() {
|
||||
textarea.value = editor.getSnapshot();
|
||||
});
|
||||
});
|
||||
|
||||
$(window).on("beforeunload", function() {
|
||||
for (var id in CKEDITOR.instances) {
|
||||
if (CKEDITOR.instances[id].checkDirty()) {
|
||||
return #{l(:text_warn_on_leaving_unsaved).inspect};
|
||||
}
|
||||
}
|
||||
});
|
||||
$(document).on("submit", "form", function() {
|
||||
for (var id in CKEDITOR.instances) {
|
||||
CKEDITOR.instances[id].resetDirty();
|
||||
}
|
||||
});
|
||||
EOT
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,36 +0,0 @@
|
|||
module RedmineCkeditor::Hooks
|
||||
class JournalListener < Redmine::Hook::ViewListener
|
||||
def view_journals_notes_form_after_notes(context)
|
||||
return unless RedmineCkeditor.enabled?
|
||||
|
||||
project = context[:project]
|
||||
journal = context[:journal]
|
||||
javascript_tag <<-EOT
|
||||
(function() {
|
||||
var note_id = "journal_#{journal.id}_notes";
|
||||
CKEDITOR.replace(note_id, #{RedmineCkeditor.options(project).to_json});
|
||||
var note = $("#" + note_id);
|
||||
|
||||
var save_button = note.parent().find(":submit");
|
||||
var preview_button = save_button.next();
|
||||
var cancel_button = preview_button.next().get(0);
|
||||
|
||||
save_button.click(function() {
|
||||
var editor = CKEDITOR.instances[note_id];
|
||||
note.val(editor.getData());
|
||||
editor.destroy();
|
||||
});
|
||||
|
||||
preview_button.hide();
|
||||
var cancel = cancel_button.onclick;
|
||||
cancel_button.onclick = function() {
|
||||
CKEDITOR.instances[note_id].destroy();
|
||||
cancel();
|
||||
return false;
|
||||
};
|
||||
})();
|
||||
EOT
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
module RedmineCkeditor
|
||||
module Hooks
|
||||
class ViewsLayoutsHook < Redmine::Hook::ViewListener
|
||||
def view_layouts_base_html_head(context={})
|
||||
return stylesheet_link_tag('/plugin_assets/redmine_ckeditor/ckeditor-contrib/plugins/codesnippet/lib/highlight/styles/default.css', :media => 'all') +
|
||||
javascript_include_tag('/plugin_assets/redmine_ckeditor/ckeditor-contrib/plugins/codesnippet/lib/highlight/highlight.pack.js') +
|
||||
javascript_include_tag('inithighlight', :plugin => 'redmine_ckeditor')
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,40 +1,24 @@
|
|||
require_dependency 'journals_controller'
|
||||
|
||||
module RedmineCkeditor
|
||||
module JournalsControllerPatch
|
||||
def self.included(base)
|
||||
base.send(:include, InstanceMethods)
|
||||
|
||||
base.class_eval do
|
||||
unloadable
|
||||
alias_method_chain :new, :ckeditor
|
||||
def new
|
||||
unless RedmineCkeditor.enabled?
|
||||
return super
|
||||
end
|
||||
end
|
||||
|
||||
module InstanceMethods
|
||||
def new_with_ckeditor
|
||||
unless RedmineCkeditor.enabled?
|
||||
new_without_ckeditor
|
||||
return
|
||||
end
|
||||
|
||||
@journal = Journal.visible.find(params[:journal_id]) if params[:journal_id]
|
||||
if @journal
|
||||
user = @journal.user
|
||||
text = @journal.notes
|
||||
else
|
||||
user = @issue.author
|
||||
text = @issue.description
|
||||
end
|
||||
@content = "<p>#{ll(I18n.locale, :text_user_wrote, user)}</p>"
|
||||
@content << "<blockquote>#{text}</blockquote><p/>"
|
||||
|
||||
render "new_with_ckeditor"
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
@journal = Journal.visible.find(params[:journal_id]) if params[:journal_id]
|
||||
if @journal
|
||||
user = @journal.user
|
||||
text = @journal.notes
|
||||
else
|
||||
user = @issue.author
|
||||
text = @issue.description
|
||||
end
|
||||
@content = "<p>#{ll(I18n.locale, :text_user_wrote, user)}</p>"
|
||||
@content << "<blockquote>#{text}</blockquote><p/>"
|
||||
|
||||
render "new_with_ckeditor"
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
end
|
||||
end
|
||||
|
||||
JournalsController.send(:include, JournalsControllerPatch)
|
||||
end
|
||||
|
|
|
@ -1,29 +1,18 @@
|
|||
require_dependency 'mail_handler'
|
||||
|
||||
module RedmineCkeditor
|
||||
module MailHandlerPatch
|
||||
extend ActiveSupport::Concern
|
||||
include ActionView::Helpers::TextHelper
|
||||
|
||||
included do
|
||||
unloadable
|
||||
alias_method_chain :cleaned_up_text_body, :ckeditor
|
||||
alias_method_chain :extract_keyword!, :ckeditor
|
||||
end
|
||||
|
||||
def cleaned_up_text_body_with_ckeditor
|
||||
if RedmineCkeditor.enabled?
|
||||
simple_format(cleaned_up_text_body_without_ckeditor)
|
||||
def cleaned_up_text_body(format = true)
|
||||
if format
|
||||
simple_format(super())
|
||||
else
|
||||
cleaned_up_text_body_without_ckeditor
|
||||
super()
|
||||
end
|
||||
end
|
||||
|
||||
def extract_keyword_with_ckeditor!(text, attr, format=nil)
|
||||
text = cleaned_up_text_body_without_ckeditor if RedmineCkeditor.enabled?
|
||||
extract_keyword_without_ckeditor!(text, attr, format)
|
||||
def extract_keyword!(text, attr, format=nil)
|
||||
text = cleaned_up_text_body(false) if RedmineCkeditor.enabled?
|
||||
super(text, attr, format)
|
||||
end
|
||||
end
|
||||
|
||||
MailHandler.send(:include, MailHandlerPatch)
|
||||
end
|
||||
|
|
|
@ -1,32 +1,16 @@
|
|||
require_dependency 'messages_controller'
|
||||
|
||||
module RedmineCkeditor
|
||||
module MessagesControllerPatch
|
||||
def self.included(base)
|
||||
base.send(:include, InstanceMethods)
|
||||
|
||||
base.class_eval do
|
||||
unloadable
|
||||
alias_method_chain :quote, :ckeditor
|
||||
def quote
|
||||
unless RedmineCkeditor.enabled?
|
||||
return super
|
||||
end
|
||||
end
|
||||
|
||||
module InstanceMethods
|
||||
def quote_with_ckeditor
|
||||
unless RedmineCkeditor.enabled?
|
||||
quote_without_ckeditor
|
||||
return
|
||||
end
|
||||
@subject = @message.subject
|
||||
@subject = "RE: #{@subject}" unless @subject.starts_with?('RE:')
|
||||
@content = "<p>#{ll(I18n.locale, :text_user_wrote, @message.author)}</p>"
|
||||
@content << "<blockquote>#{ActionView::Base.full_sanitizer.sanitize(@message.content.to_s)}</blockquote><p/>"
|
||||
|
||||
@subject = @message.subject
|
||||
@subject = "RE: #{@subject}" unless @subject.starts_with?('RE:')
|
||||
@content = "<p>#{ll(I18n.locale, :text_user_wrote, @message.author)}</p>"
|
||||
@content << "<blockquote>#{ActionView::Base.full_sanitizer.sanitize(@message.content.to_s)}</blockquote><p/>"
|
||||
|
||||
render "quote_with_ckeditor"
|
||||
end
|
||||
render "quote_with_ckeditor"
|
||||
end
|
||||
end
|
||||
|
||||
MessagesController.send(:include, MessagesControllerPatch)
|
||||
end
|
||||
|
|
|
@ -1,31 +1,21 @@
|
|||
require_dependency 'redmine/export/pdf'
|
||||
|
||||
module RedmineCkeditor
|
||||
module PDFPatch
|
||||
def self.included(base)
|
||||
base.class_eval do
|
||||
alias_method_chain :formatted_text, :ckeditor
|
||||
alias_method_chain :get_image_filename, :ckeditor
|
||||
alias_method_chain :RDMwriteHTMLCell, :ckeditor
|
||||
end
|
||||
end
|
||||
|
||||
def formatted_text_with_ckeditor(text)
|
||||
html = formatted_text_without_ckeditor(text)
|
||||
def formatted_text(text)
|
||||
html = super
|
||||
html = HTMLEntities.new.decode(html) if RedmineCkeditor.enabled?
|
||||
html
|
||||
end
|
||||
|
||||
def RDMwriteHTMLCell_with_ckeditor(w, h, x, y, txt='', attachments=[], border=0, ln=1, fill=0)
|
||||
def RDMwriteHTMLCell(w, h, x, y, txt='', attachments=[], border=0, ln=1, fill=0)
|
||||
@tmp_images = []
|
||||
RDMwriteHTMLCell_without_ckeditor(w, h, x, y, txt, attachments, border, ln, fill)
|
||||
super
|
||||
@tmp_images.each do |item|
|
||||
#logger.info item
|
||||
File.delete(item) if File.file?(item)
|
||||
end
|
||||
end
|
||||
|
||||
def get_image_filename_with_ckeditor(attrname)
|
||||
def get_image_filename(attrname)
|
||||
img = nil
|
||||
|
||||
if attrname.sub!(/^data:([^\/]+)\/([^;]+);base64,/, '')
|
||||
|
@ -50,12 +40,12 @@ module RedmineCkeditor
|
|||
img = if attrname.include?("/rich/rich_files/rich_files/")
|
||||
Rails.root.join("public#{URI.decode(attrname)}").to_s
|
||||
else
|
||||
get_image_filename_without_ckeditor(attrname)
|
||||
super(attrname)
|
||||
end
|
||||
end
|
||||
img
|
||||
end
|
||||
end
|
||||
|
||||
Redmine::Export::PDF::ITCPDF.send(:include, PDFPatch)
|
||||
end
|
||||
|
||||
Redmine::Export::PDF::ITCPDF.prepend RedmineCkeditor::PDFPatch
|
||||
|
|
|
@ -1,13 +1,12 @@
|
|||
require_dependency 'queries_helper'
|
||||
|
||||
module QueriesHelper
|
||||
def csv_value_with_ckeditor(column, issue, value)
|
||||
if RedmineCkeditor.enabled? && column.name == :description
|
||||
text = Rails::Html::FullSanitizer.new.sanitize(value.to_s)
|
||||
text.gsub(/(?:\r\n\t*)+/, "\r").gsub(" ", " ").strip
|
||||
else
|
||||
csv_value_without_ckeditor(column, issue, value)
|
||||
module RedmineCkeditor
|
||||
module QueriesHelperPatch
|
||||
def csv_value(column, issue, value)
|
||||
if RedmineCkeditor.enabled? && column.name == :description
|
||||
text = Rails::Html::FullSanitizer.new.sanitize(value.to_s)
|
||||
text.gsub(/(?:\r\n\t*)+/, "\r").gsub(" ", " ").strip
|
||||
else
|
||||
super
|
||||
end
|
||||
end
|
||||
end
|
||||
alias_method_chain :csv_value, :ckeditor
|
||||
end
|
||||
|
|
|
@ -1,24 +1,11 @@
|
|||
require_dependency 'rich/files_helper'
|
||||
|
||||
module RedmineCkeditor
|
||||
module RichFilesHelperPatch
|
||||
def self.included(base)
|
||||
base.send(:include, InstanceMethods)
|
||||
base.class_eval do
|
||||
alias_method_chain :thumb_for_file, :redmine
|
||||
end
|
||||
end
|
||||
|
||||
module InstanceMethods
|
||||
def thumb_for_file_with_redmine(file)
|
||||
Redmine::Utils.relative_url_root + if file.simplified_type == "image"
|
||||
file.rich_file.url(:rich_thumb)
|
||||
else
|
||||
"/plugin_assets/redmine_ckeditor/images/document-thumb.png"
|
||||
end
|
||||
def thumb_for_file(file)
|
||||
Redmine::Utils.relative_url_root + if file.simplified_type == "image"
|
||||
file.rich_file.url(:rich_thumb)
|
||||
else
|
||||
"/plugin_assets/redmine_ckeditor/images/document-thumb.png"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Rich::FilesHelper.send(:include, RichFilesHelperPatch)
|
||||
end
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
class Tempfile
|
||||
def initialize_with_binmode(basename, *rest)
|
||||
initialize_without_binmode(basename, *rest).tap do |f|
|
||||
f.binmode if basename == "raw-upload."
|
||||
module RedmineCkeditor
|
||||
module TempfilePatch
|
||||
def initialize(basename, *rest)
|
||||
super.tap do |f|
|
||||
f.binmode if basename == "raw-upload."
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
alias_method_chain :initialize, :binmode
|
||||
end
|
||||
|
||||
Tempfile.prepend RedmineCkeditor::TempfilePatch
|
||||
|
|
|
@ -1,28 +1,20 @@
|
|||
module RedmineCkeditor::WikiFormatting
|
||||
module Helper
|
||||
def replace_editor_tag(field_id)
|
||||
javascript_tag <<-EOT
|
||||
$(document).ready(function() {
|
||||
#{replace_editor_script(field_id)}
|
||||
});
|
||||
EOT
|
||||
end
|
||||
include RedmineCkeditor::Helper
|
||||
|
||||
def replace_editor_script(field_id)
|
||||
def replace_editor_script(field_id, preview_url)
|
||||
<<-EOT
|
||||
(function() {
|
||||
var id = '#{field_id}';
|
||||
var textarea = document.getElementById(id);
|
||||
if (!textarea) return;
|
||||
|
||||
var editor = CKEDITOR.replace(textarea, #{RedmineCkeditor.options(@project).to_json});
|
||||
editor.on("change", function() { textarea.value = editor.getSnapshot(); });
|
||||
})();
|
||||
(function() {
|
||||
var textarea = document.getElementById('#{field_id}');
|
||||
if (!textarea) return;
|
||||
new jsToolBar(textarea).setPreviewUrl('#{preview_url}');
|
||||
CKEDITOR.replace(textarea, #{RedmineCkeditor.options(@project).to_json});
|
||||
})();
|
||||
EOT
|
||||
end
|
||||
|
||||
def overwrite_functions
|
||||
javascript_tag <<-EOT
|
||||
<<-EOT
|
||||
function showAndScrollTo(id, focus) {
|
||||
var elem = $("#" + id);
|
||||
elem.show();
|
||||
|
@ -33,21 +25,30 @@ module RedmineCkeditor::WikiFormatting
|
|||
function destroyEditor(id) {
|
||||
if (CKEDITOR.instances[id]) CKEDITOR.instances[id].destroy();
|
||||
}
|
||||
|
||||
if (!jsToolBar.prototype._showPreview) {
|
||||
jsToolBar.prototype._showPreview = jsToolBar.prototype.showPreview
|
||||
jsToolBar.prototype.showPreview = function(event) {
|
||||
this._showPreview(event);
|
||||
$(this.textarea).next().hide();
|
||||
}
|
||||
}
|
||||
|
||||
if (!jsToolBar.prototype._hidePreview) {
|
||||
jsToolBar.prototype._hidePreview = jsToolBar.prototype.hidePreview
|
||||
jsToolBar.prototype.hidePreview = function(event) {
|
||||
this._hidePreview(event);
|
||||
$(this.textarea).next().show();
|
||||
}
|
||||
}
|
||||
EOT
|
||||
end
|
||||
|
||||
def initial_setup
|
||||
overwrite_functions
|
||||
end
|
||||
|
||||
def wikitoolbar_for(field_id)
|
||||
if params[:format] == "js"
|
||||
javascript_tag(replace_editor_script(field_id))
|
||||
else
|
||||
ckeditor_javascripts +
|
||||
stylesheet_link_tag('editor', :plugin => 'redmine_ckeditor') +
|
||||
initial_setup + replace_editor_tag(field_id)
|
||||
end
|
||||
def wikitoolbar_for(field_id, preview_url = preview_text_path)
|
||||
heads_for_wiki_formatter
|
||||
script = replace_editor_script(field_id, preview_url)
|
||||
script += overwrite_functions if request.format.html?
|
||||
javascript_tag script
|
||||
end
|
||||
|
||||
def initial_page_content(page)
|
||||
|
@ -55,6 +56,16 @@ module RedmineCkeditor::WikiFormatting
|
|||
end
|
||||
|
||||
def heads_for_wiki_formatter
|
||||
unless @heads_for_wiki_formatter_included
|
||||
content_for :header_tags do
|
||||
javascript_include_tag('jstoolbar/jstoolbar') +
|
||||
javascript_include_tag("jstoolbar/lang/jstoolbar-#{current_language.to_s.downcase}") +
|
||||
stylesheet_link_tag('jstoolbar') +
|
||||
ckeditor_javascripts +
|
||||
stylesheet_link_tag('editor', :plugin => 'redmine_ckeditor')
|
||||
end
|
||||
@heads_for_wiki_formatter_included = true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue