Better js code to apply CKEditor.replace, mainly to select only textarea.name=$name.

code cleaning.
This commit is contained in:
2015-08-18 19:24:18 +02:00
parent cfec9dc7f8
commit 923089baa1
4 changed files with 40 additions and 33 deletions
@@ -62,7 +62,7 @@ feature -- Forms ...
sum.set_text_value (a_node.summary) sum.set_text_value (a_node.summary)
end end
sum.set_label ("Summary") sum.set_label ("Summary")
sum.set_description ("This is the summary") sum.set_description ("Text displayed in short view.")
sum.set_is_required (False) sum.set_is_required (False)
create fset.make create fset.make
+5 -3
View File
@@ -8,6 +8,7 @@ deferred class
CMS_EDITOR CMS_EDITOR
feature -- Initialisation feature -- Initialisation
load_assets : STRING load_assets : STRING
-- Loads all assest needed to show the editor -- Loads all assest needed to show the editor
deferred deferred
@@ -60,8 +61,6 @@ feature -- Javascript
Result := "var " + editor_variable (a_textarea) + "; " Result := "var " + editor_variable (a_textarea) + "; "
end end
javascript_if_selected (a_select_field : WSF_FORM_SELECT; a_value : STRING; a_code : STRING) : STRING javascript_if_selected (a_select_field : WSF_FORM_SELECT; a_value : STRING; a_code : STRING) : STRING
-- Javascript that executes a_code if a_value is selected at a_select_field -- Javascript that executes a_code if a_value is selected at a_select_field
do do
@@ -100,7 +99,10 @@ feature -- Helper
editor_variable (a_textarea : WSF_FORM_TEXTAREA) : STRING editor_variable (a_textarea : WSF_FORM_TEXTAREA) : STRING
-- Returns the variable name that stores the editor instance of the given textarea -- Returns the variable name that stores the editor instance of the given textarea
do do
Result := "editor_" + a_textarea.name Result := "cms_ckeditor_" + a_textarea.name
end end
note
copyright: "2011-2015, Jocelyn Fiat, Javier Velilla, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
end end
+6 -1
View File
@@ -24,7 +24,9 @@ feature -- Javascript
-- <Precursor> -- <Precursor>
do do
-- Replaces the textarea with an editor instance. Save the instance in a variable -- Replaces the textarea with an editor instance. Save the instance in a variable
Result := editor_variable(a_textarea) + " = CKEDITOR.replace( '" + a_textarea.name + "' );" Result := "$(%"textarea[name="+ a_textarea.name +"]%").each(function() {"
Result.append (editor_variable (a_textarea) + " = CKEDITOR.replace(this);")
Result.append ("});")
end end
javascript_restore_textarea (a_textarea : WSF_FORM_TEXTAREA) : STRING javascript_restore_textarea (a_textarea : WSF_FORM_TEXTAREA) : STRING
@@ -34,4 +36,7 @@ feature -- Javascript
Result := "if (" + editor_variable (a_textarea) + " != undefined) " + editor_variable (a_textarea) + ".destroy();" Result := "if (" + editor_variable (a_textarea) + " != undefined) " + editor_variable (a_textarea) + ".destroy();"
end end
note
copyright: "2011-2015, Jocelyn Fiat, Javier Velilla, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
end end
+7 -7
View File
@@ -24,15 +24,15 @@ feature -- Initialisation
make (a_name: like name) make (a_name: like name)
-- <Precursor> -- <Precursor>
do do
precursor(a_name) Precursor (a_name)
-- By default we don't replace the textarea by an editor -- By default we don't replace the textarea by an editor
editor := False; editor_activated := False;
end end
feature -- Access feature -- Access
editor : BOOLEAN editor_activated : BOOLEAN
-- True if the textarea should be replaced by the editor. Default is false. -- True if the textarea should be replaced by the editor. Default is false.
format_field : detachable WSF_FORM_SELECT format_field : detachable WSF_FORM_SELECT
@@ -45,13 +45,13 @@ feature -- Editor
show_as_editor show_as_editor
-- The textarea will be replaced by a wysiwyg editor -- The textarea will be replaced by a wysiwyg editor
do do
editor := True editor_activated := True
end end
show_as_editor_if_selected (a_select_field : WSF_FORM_SELECT; a_value : STRING) show_as_editor_if_selected (a_select_field : WSF_FORM_SELECT; a_value : STRING)
-- Replaces the textarea only if a_select_field has a_value (or the value gets selected) -- Replaces the textarea only if a_select_field has a_value (or the value gets selected)
do do
editor := True editor_activated := True
format_field := a_select_field format_field := a_select_field
condition_value := a_value condition_value := a_value
end end
@@ -61,8 +61,8 @@ feature -- Conversion
append_item_to_html (a_theme: WSF_THEME; a_html: STRING_8) append_item_to_html (a_theme: WSF_THEME; a_html: STRING_8)
do do
-- Add javascript to replace textarea with editor -- Add javascript to replace textarea with editor
precursor(a_theme, a_html) Precursor (a_theme, a_html)
if editor then if editor_activated then
a_html.append (load_assets) a_html.append (load_assets)
a_html.append ("<script type=%"text/javascript%">"); a_html.append ("<script type=%"text/javascript%">");
if attached format_field as l_field and then attached condition_value as l_value then if attached format_field as l_field and then attached condition_value as l_value then