[Checkins] SVN: z3c.widget/sandbox/src/z3c/widget/tiny/ added
locale support, changed mce option handling
Bernd Dorn
bernd.dorn at fhv.at
Sun Apr 16 13:42:43 EDT 2006
Log message for revision 67072:
added locale support, changed mce option handling
Changed:
U z3c.widget/sandbox/src/z3c/widget/tiny/htmlfile/configure.zcml
U z3c.widget/sandbox/src/z3c/widget/tiny/widget.py
-=-
Modified: z3c.widget/sandbox/src/z3c/widget/tiny/htmlfile/configure.zcml
===================================================================
--- z3c.widget/sandbox/src/z3c/widget/tiny/htmlfile/configure.zcml 2006-04-16 09:25:09 UTC (rev 67071)
+++ z3c.widget/sandbox/src/z3c/widget/tiny/htmlfile/configure.zcml 2006-04-16 17:42:43 UTC (rev 67072)
@@ -14,6 +14,13 @@
<widget
field="data"
class="z3c.widget.tiny.widget.TinyWidget"
+ height="30"
+ mce_theme="advanced"
+ mce_theme_advanced_toolbar_location="top"
+ mce_theme_advanced_toolbar_align="left"
+ mce_theme_advanced_statusbar_location="bottom"
+ mce_entity_encoding="raw"
+ mce_convert_newlines_to_brs="true"
/>
</browser:form>
Modified: z3c.widget/sandbox/src/z3c/widget/tiny/widget.py
===================================================================
--- z3c.widget/sandbox/src/z3c/widget/tiny/widget.py 2006-04-16 09:25:09 UTC (rev 67071)
+++ z3c.widget/sandbox/src/z3c/widget/tiny/widget.py 2006-04-16 17:42:43 UTC (rev 67072)
@@ -28,15 +28,25 @@
template = """%(widget_html)s<script type="text/javascript">
tinyMCE.init({
-mode : "exact",
-language : "%(language)s",
-theme : "%(theme)s",
-%(optionals)s
-elements : "%(name)s"}
+mode : "exact", %(options)s
+elements : "%(name)s"
+}
);
</script>
"""
+OPT_PREFIX="mce_"
+OPT_PREFIX_LEN = len(OPT_PREFIX)
+MCE_LANGS=[]
+import glob
+import os
+
+# initialize the language files
+for langFile in glob.glob(
+ os.path.join(os.path.dirname(__file__),'tiny_mce','langs') + '/??.js'):
+ MCE_LANGS.append(os.path.basename(langFile)[:2])
+
+
class TinyWidget(TextAreaWidget):
@@ -46,44 +56,94 @@
>>> from zope.publisher.browser import TestRequest
>>> from zope.schema import Text
>>> field = Text(__name__='foo', title=u'on')
- >>> request = TestRequest(form={'field.foo': u'Hello\\r\\nworld!'})
+ >>> request = TestRequest(
+ ... form={'field.foo': u'Hello\\r\\nworld!'})
+
+ By default, only the needed options to MCE are passed to
+ the init method.
+
>>> widget = TinyWidget(field, request)
>>> print widget()
<textarea cols="60" id="field.foo" name="field.foo" rows="15" >Hello
world!</textarea><script type="text/javascript">
tinyMCE.init({
- mode : "exact",
- language : "en",
- theme : "advanced",
- elements : "field.foo"}
+ mode : "exact",
+ elements : "field.foo"
+ }
);
</script>
+ All variables defined on the object which start with ``mce_`` are
+ passed to the init method. Python booleans are converted
+ automatically to their js counterparts.
+
+ For a complete list of options see:
+ http://tinymce.moxiecode.com/tinymce/docs/reference_configuration.html
+
+ >>> widget = TinyWidget(field, request)
+ >>> widget.mce_theme="advanced"
+ >>> widget.mce_ask=True
+ >>> print widget()
+ <textarea ...
+ tinyMCE.init({
+ mode : "exact", ask : true, theme : "advanced",
+ elements : "field.foo"
+ }
+ );
+ </script>
+
+ Also the string literals "true" and "false" are converted to js
+ booleans. This is usefull for widgets created by zcml.
+
+ >>> widget = TinyWidget(field, request)
+ >>> widget.mce_ask='true'
+ >>> print widget()
+ <textarea ...
+ mode : "exact", ask : true,
+ ...
+ </script>
+
+ Languages are taken from the tiny_mce/langs directory (currently
+ only the ones with an iso name are registered).
+
+ >>> print MCE_LANGS
+ ['ar', 'ca', 'cs', 'cy', 'da', 'de', 'el', 'en', 'es', 'fa', \
+ 'fi', 'fr', 'he', 'hu', 'is', 'it', 'ja', 'ko', 'nb', 'nl', \
+ 'nn', 'pl', 'pt', 'ru', 'si', 'sk', 'sv', 'th', 'tr', 'vi']
+
+ If the language is found it is added to the mce options. To test
+ this behaviour we simply set the language directly, even though it
+ is a readonly attribute (don't try this at home)
+
+ >>> request.locale.id.language='de'
+ >>> print widget()
+ <textarea ...
+ mode : "exact", ask : true, language : "de",
+ ...
+ </script>
+
"""
- theme="advanced"
- valid_elements = None
- language="en"
- inline_styles=None
- valid_elements=None
- optionals = ['inline_styles','valid_elements']
-
def __call__(self,*args,**kw):
if haveResourceLibrary:
resourcelibrary.need('tiny_mce')
- # elements == id
- # mode = exact
- optionals = []
- for k in self.optionals:
- v = getattr(self,k,None)
- v = v==True and 'true' or v==False and 'false' or v
- if v is not None:
- optionals.append('%s : "%s"' % (k,v))
- optionals = ','.join(optionals)
+ mceOptions = []
+ for k in dir(self):
+ if k.startswith(OPT_PREFIX):
+ v = getattr(self,k,None)
+ v = v==True and 'true' or v==False and 'false' or v
+ if v in ['true','false']:
+ mceOptions.append('%s : %s' % (k[OPT_PREFIX_LEN:],v))
+ elif v is not None:
+ mceOptions.append('%s : "%s"' % (k[OPT_PREFIX_LEN:],v))
+ mceOptions = ', '.join(mceOptions)
+ if mceOptions:
+ mceOptions += ', '
+ if self.request.locale.id.language in MCE_LANGS:
+ mceOptions += ('language : "%s", ' % \
+ self.request.locale.id.language)
widget_html = super(TinyWidget,self).__call__(*args,**kw)
return template % {"widget_html": widget_html,
"name": self.name,
- "theme": self.theme,
- "optionals": optionals,
- "language": self.language}
+ "options": mceOptions}
More information about the Checkins
mailing list