42 You can include tiny_mce_src.js in your template using: |
42 You can include tiny_mce_src.js in your template using: |
43 {% block scripts %} |
43 {% block scripts %} |
44 <script type="text/javascript" src="/tiny_mce/tiny_mce_src.js"></script> |
44 <script type="text/javascript" src="/tiny_mce/tiny_mce_src.js"></script> |
45 {% endblock %} |
45 {% endblock %} |
46 """ |
46 """ |
47 MCE_DEF_SETTINGS = { 'mode': "exact", |
47 DEF_MCE_SETTINGS = { 'mode': "exact", |
48 'theme': "simple", |
48 'theme': "simple", |
49 'theme_advanced_toolbar_location': "top", |
49 'theme_advanced_toolbar_location': "top", |
50 'theme_advanced_toolbar_align': "center"} |
50 'theme_advanced_toolbar_align': "center"} |
51 |
51 |
52 mce_settings = MCE_DEF_SETTINGS |
52 mce_settings = DEF_MCE_SETTINGS |
53 |
53 |
54 TINY_MCE_HTML_FMT = u'''<textarea %(attrs)s>%(value)s</textarea> |
54 TINY_MCE_HTML_FMT = u'''\ |
55 <script type="text/javascript"> |
55 <textarea %(attrs)s>%(value)s</textarea> |
56 tinyMCE.init(%(settings_json)s)</script>''' |
56 <script type="text/javascript"> |
|
57 tinyMCE.init(%(settings_json)s) |
|
58 </script>''' |
57 |
59 |
58 def render(self, name, value, attrs=None): |
60 def render(self, name, value, attrs=None): |
59 """Render TinyMCE widget as HTML. |
61 """Render TinyMCE widget as HTML. |
60 """ |
62 """ |
61 if value is None: |
63 if value is None: |
62 value = '' |
64 value = '' |
63 value = smart_unicode(value) |
65 value = smart_unicode(value) |
64 final_attrs = self.build_attrs(attrs, name=name) |
66 final_attrs = self.build_attrs(attrs, name=name) |
65 |
67 |
66 self.mce_settings['elements'] = "id_%s" % name |
68 self.mce_settings['elements'] = "id_%s" % name |
67 |
69 |
68 # convert mce_settings from dict to JSON |
70 # convert mce_settings from dict to JSON |
69 mce_json = simplejson.JSONEncoder().encode(self.mce_settings) |
71 mce_json = simplejson.JSONEncoder().encode(self.mce_settings) |
70 |
72 |
71 return mark_safe( self.TINY_MCE_HTML_FMT % |
73 return mark_safe(self.TINY_MCE_HTML_FMT % |
72 { 'attrs': flatatt(final_attrs), |
74 {'attrs': flatatt(final_attrs), |
73 'value': escape(value), |
75 'value': escape(value), |
74 'settings_json': mce_json}) |
76 'settings_json': mce_json}) |