Method: EditableContent::ViewHelpers#insert_editable_content

Defined in:
lib/editable_content/view_helpers.rb

#insert_editable_contentObject

This function inserts the code needed for editing editable content into the head section of the page.

Each editable field needs will need one editor and they are created with the create_content_editor function

Note

This function creates an unobtursive javascript event handler that launches the editor. It uses content_for to save the code in the following variables: stylesheet_list, javascript_list, and javascript_data. It assumes that you will have the following in your head section.

<%= yield :stylesheet_list %>
<%= yield :javascript_list %>
<script type="text/javascript">
  <%= yield :javascript_data %>
</script>

Usage

<%= insert_editable_content -%>
<%= create_content_editor("maintext") -%>
<%= create_content_editor("contacttext") -%>


29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/editable_content/view_helpers.rb', line 29

def insert_editable_content()
  if 
    content_for(:stylesheet_list) { stylesheet_link_tag "markitup/skins/simple/style.css" }
    content_for(:stylesheet_list) { stylesheet_link_tag "markitup/sets/textile/style.css" }
    content_for(:javascript_list) { javascript_include_tag "markitup/jquery.markitup.js" }
    content_for(:javascript_list) { javascript_include_tag "markitup/sets/textile/set.js" }
    content_for(:javascript_data) { "\n      var content_id = 0;\n      var content_name = \"\";\n\n      function openEditor(name, controller, action) {\n        content_name = name;\n        $.get(\"/contents/edit\",\n          {p_name:name, p_controller:controller, p_action:action},\n          jQuery.proxy(this, function(data) {\n            content_id = data.id;\n            $(\"#ec_edit_textarea\").val(data.content);\n            $(\"#ec_edit_dialog_form\").dialog('open');\n        }));\n      }\n\n      $(function() {\n        // a workaround for a flaw in the demo system (http://dev.jqueryui.com/ticket/4375), ignore!\n        $(\"#ec_edit_dialog_form\").dialog(\"destroy\");\n\n        $(\"#ec_edit_textarea\").markItUp(mySettings);\n\n        $(\"#ec_edit_dialog_form\").dialog({\n          autoOpen: false,\n          height: 375,\n          width: 1000,\n          modal: true,\n          buttons: {\n            'Save': function() {\n              $.post(\"/contents/update\",\n                {p_id:content_id, p_content:$(\"#ec_edit_textarea\").val()},\n                jQuery.proxy(this, function(data) {\n                  $(\"#ec_edit_frame_\" + content_name).html(data);\n                })\n              );\n              $(this).dialog('close');\n            },\n            Cancel: function() {\n              $(this).dialog('close');\n            }\n          },\n          close: function() {\n            $(\"#ec_edit_textarea\").html(\"\");\n          }\n        });\n      });\n"
    }

    editor_text = "      <div id=\"ec_edit_dialog_form\" title=\"Edit Content\" style=\"padding: 0; display: none;\">\n        <form style=\"padding: 5px 0 0 0;\" >\n          <textarea name=\"ec_edit_textarea\" id=\"ec_edit_textarea\" cols=\"80\" style=\"width: 99.5%; height: 200px; min_height: 200px;\" class=\"ui_widget_content ui_corner_all\" ></textarea>\n        </form>\n      </div>\n"
    editor_text.html_safe
  end
end