Created
September 20, 2010 11:20
-
-
Save jaymzcd/587753 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from django import forms | |
| from django.utils.safestring import mark_safe | |
| from django.conf import settings | |
| class SimpleBBWidget(forms.Textarea): | |
| widget_buttons = u""" | |
| <button class="default" onclick="return surround('[b]','[/b]');"><b>B</b></button> | |
| <button class="default" onclick="return surround('[i]','[/i]');"><i>I</i></button> | |
| <button class="default" onclick="return insert_link();"><u>link</u></button> | |
| """ | |
| pre_buttons = u""" | |
| <div style="margin-bottom:10px;" class="cms-toolbar"> | |
| """ | |
| post_buttons = u""" | |
| </div> | |
| <textarea %(attrs)s cols="120" rows="15" style="width:100%%;" name=%(name)s>%(value)s</textarea> | |
| """ | |
| def render(self, name, value, attrs=None): | |
| if value is None: value = '' | |
| if attrs: | |
| attr_out = ' '.join([x+'="'+attrs[x]+'"' for x in attrs]) | |
| widget = (pre_buttons + widget_string + post_buttons) % { 'value' : value, 'attrs' : attr_out, 'name' : name, 'margin': 'style="margin-right:10px;"' } | |
| return mark_safe(widget) | |
| class Media: | |
| js = (settings.MEDIA_URL+'js/bbcode.widget.js',) | |
| css = { | |
| 'all': (settings.MEDIA_URL+'css/post-toolbar.css',) | |
| } | |
| class AdvancedBBWidget(SimpleBBWidget): | |
| widget_buttons = super(AdvancedBBWidget).widget_buttons + u""" <button class="default" onclick="return surround('[h]','[/h]');" %(margin)s><b>Heading</b></button> | |
| <button class="yellow" onclick="return insert_readmore();" %(margin)s>Read More</button> | |
| <button class="green" onclick="return insert_img();">post image</button> | |
| <button class="green" onclick="return insert_urlimg();" %(margin)s>url image</button> | |
| <button class="orange" onclick="return insert_youtube();">youtube</button> | |
| <button class="orange" onclick="return insert_vimeo();" %(margin)s>vimeo</button> | |
| <button class="purple" onclick="return insert_map();" %(margin)s>map</button> | |
| <button class="default" onclick="return surround('[pre]','[/pre]');">pre</button> | |
| <button class="red" onclick="return surround('[raw]','[/raw]');">raw HTML</button> | |
| """ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment