2006/1/25, Dan Jacob <[EMAIL PROTECTED]>:
>
> Once the widget API has become a bit more stable I was thinking of
> adding a standard WYSIWYG widget to TurboGears. Previous posts have
> mentioned TinyMCE and others.Of course it must work well within TG,
> including internationalization and licencing issues.
>
> Is anyone using WYSIWG editors ? What are their personal favorites?

I am using TinyMCE, since they are trying to support as many browsers
as possible (including Safari and Opera), and the generated HTML is
nice and clean. Here is the unfinished widget that I am using (hope it
works, I've stripped it down from non-related code without testing).
The idea was to convert all javascript parameters to Python, so the
widget attributes can be changed on the fly, e.g.:

editor = TinyMCEEditor(labeltext='Contents', name='contents')
editor.attrs['content_css'] = '/static/css/wysiwyg.css'
editor.attrs['language'] = 'en'

Also, it's possible to have multiple widgets on the same form, with
different configurations.


class TinyMCEEditor(Widget):
    javascript=[LocalJSLink('tiny_mce', 'tiny_mce.js'),
        LocalJSLink('', 'filemanager.js')]
    validator = None
    attrs = {
        'file_browser_callback'             : 'selectFile',
        'mode'                              : "exact",
        'elements'                        : [],
        'content_css'                       : None,
        'file_browser_callback'             : 'selectFile',
        'language'                          : 'nl',
        'docs_language'                     : 'nl',
        'width'                             : '100%',
        'height'                            : '400px',
        'plugins'                           : ['paste', 'save',
'table', 'zoom', 'searchreplace', 'print', 'contextmenu'],
        'theme_advanced_buttons1_add_before': [],
        'theme_advanced_buttons2_add'       : ['separator', 'zoom'],
        'theme_advanced_buttons2_add_before': ['cut', 'copy', 'paste',
'pastetext', 'pasteword', 'separator', 'search', 'replace',
'separator'],
        'theme_advanced_buttons3_add_before': ['tablecontrols','separator'],
        'theme_advanced_buttons3_add'       : ['print'],
        'theme_advanced_disable'            : ['help', 'code',
'cleanup', 'visualaid', 'charmap'],
        'theme_advanced_toolbar_location'   : "top",
        'theme_advanced_toolbar_align'      : "left",
        'theme_advanced_path_location'      : "bottom",
        'theme_advanced_blockformats'       : ['p', 'h1', 'h2', 'h3', 'h4'],
        'theme_advanced_layout_manager'     : "SimpleLayout",
        'verify_css_classes'                : True,
        'document_base_url'                 : '/',
        'relative_urls'                     : False,
        'auto_cleanup_word'                 : True
    }
    template = """<div xmlns:py="http://purl.org/kid/ns#"; py:strip="True">
    <?python
editor_pieces = []
for key, val in widget.attrs.items():
    if val is not None:
        if type(val) == bool:
            val=str(val).lower()
        elif type(val) in (list, tuple):
            if key == 'elements' and len(val) == 0:
                val = [widget.name]
            elif not val:
                continue
            val = ', '.join(val)
        editor_pieces.append("%s : '%s'" % (key, val))
editor_js = ',\\n'.join(editor_pieces) ?>
    <script language="javascript" type="text/javascript">
    tinyMCE.init({
        ${editor_js}
    });
    </script>
    <textarea wysiwyg="true" name="${widget.name}" id="${widget.name}"
class="textarea_field">${widget_value}</textarea>
    <span class="field_error"
py:if="widget_error">${str(widget_error)}</span></div>"""

--
Ksenia

Reply via email to