Luke Plant avatar Luke Plant committed 5d8a412

Added copy of WYMeditor template and widget for extending

Comments (0)

Files changed (2)

semanticeditor/templates/semanticeditor/editorwidget.html

+{% load mptt_tags %}
+{% full_tree_for_model cms.Page as pages %}
+<script type="text/javascript">
+    jQuery('#id_{{ name }}').wymeditor({
+        lang: '{{ language }}',
+        skin: 'django',
+        skinPath: "{{ CMS_MEDIA_URL }}javascript/wymeditor/skins/django/",
+        updateSelector: '.submit-row input[type=submit],',
+        updateEvent: 'click',
+        postInit: function(wym) {
+            wym.resizable({handles: "s", maxHeight: 600});
+            //construct the button's html
+            html = "<li class='wym_tools_pagelink'>"
+                 + "<a name='PageLink' href='#'"
+                 + " title='Page link'"
+                 + " style='background-image:"
+                 + " url({{ CMS_MEDIA_URL }}javascript/wymeditor/skins/django/icons.png);"
+                 + " background-position-y: -623px;'>"
+                 + "Page link"
+                 + "</a></li>";
+
+            //add the button to the tools box
+            jQuery(wym._box)
+            .find(wym._options.toolsSelector + wym._options.toolsListSelector)
+            .append(html);
+
+            //construct the dialog's html
+            html = "<body class='wym_dialog wym_dialog_pagelink'"
+                 + " onload='WYMeditor.INIT_DIALOG(" + WYMeditor.INDEX + ")'"
+                 + ">"
+                 + "<form>"
+                 + "<fieldset>"
+                 + "<input type='hidden' class='wym_dialog_type' value='"
+                 + "Pages"
+                 + "' />"
+                 + "<legend>Page link</legend>"
+                 + "<div class='row'>"
+                 + "<label>Page</label>"
+                 + "<select class='wym_select_page_link'>"
+                 {% for page in pages %}
+                 + "<option value='{{ page.get_absolute_url }}'>{{ page.get_ancestors|tree_path:" > " }}{% if page.get_ancestors %} > {% endif %}{{ page }}</option>"
+                 {% endfor %}
+                 + "</select>"
+                 + "</div>"
+                 + "<div class='row'>"
+                 + "<label>Title</label>"
+                 + "<input type='text' class='wym_title' value='' size='40' />"
+                 + "</div>"
+                 + "<div class='row row-indent'>"
+                 + "<input class='wym_submit wym_submit_pagelink' type='button'"
+                 + " value='{Submit}' />"
+                 + "<input class='wym_cancel' type='button'"
+                 + "value='{Cancel}' />"
+                 + "</div>"
+                 + "</fieldset>"
+                 + "</form>"
+                 + "</body>";
+            //handle click event on wrap button
+            jQuery(wym._box)
+            .find('li.wym_tools_pagelink a').click(function() {
+                wym.dialog('Page link', html);
+                return(false);
+            });
+        },
+        //handle click event on dialog's submit button
+        postInitDialog: function( wym, wdw ) {
+            var body = wdw.document.body;
+            jQuery(body)
+                .find('input.wym_submit_pagelink')
+                .click(function() {
+                    var href  = jQuery(body).find('.wym_select_page_link').val();
+                    var title = jQuery(body).find('.wym_title').val();
+                    wym.insert('<a href="' + href + '" title="' + title + '">' + title + '</a>');
+                    wdw.close();
+                });
+        },
+    });
+    </script>

semanticeditor/widgets.py

+# Override for widgets in django-cms
+
+# Include all the normal ones
+from cms.admin.widgets import *
+from django import forms
+from cms.settings import CMS_MEDIA_URL
+
+class SemanticEditor(WYMEditor):
+    def _media(self):
+        extra_media = forms.Media({})
+        return super(SemanticEditor, self)._media() + extra_media
+
+    def render_extra(self, name, value, attrs=None):
+        context = {
+            'name': name,
+            'language': self.language,
+            'CMS_MEDIA_URL': CMS_MEDIA_URL,
+        }
+        return mark_safe(render_to_string(
+            'semanticeditor/editorwidget.html', context))
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.