1. Simon Meers
  2. django-markitup

Commits

Carl Meyer  committed f5c1a65 Merge

merge MARKITUP_AUTO_PREVIEW setting (thanks Petar Radosevic)

  • Participants
  • Parent commits 260f66b, 0b3f4ad
  • Branches default

Comments (0)

Files changed (6)

File README.txt

View file
  • Ignore whitespace
 ``MarkupField``. It has the same format as ``MARKITUP_FILTER``; by
 default it is set equal to ``MARKITUP_FILTER``.
 
+MARKITUP_AUTO_PREVIEW
+---------------------
+
+If set to ``True``, the preview window will be activated by
+default. Defaults to ``False``.
+
 JQUERY_URL
 ----------
 

File markitup/settings.py

View file
  • Ignore whitespace
-"""
-settings for django-markitup
-
-Time-stamp: <2009-11-11 12:28:49 carljm settings.py>
-
-"""
 from django.conf import settings
 import posixpath
 
 
 MARKITUP_PREVIEW_FILTER = getattr(settings, 'MARKITUP_PREVIEW_FILTER',
                                   getattr(settings, 'MARKITUP_FILTER', None))
+MARKITUP_AUTO_PREVIEW = getattr(settings, 'MARKITUP_AUTO_PREVIEW', False)
 MARKITUP_MEDIA_URL = getattr(settings, 'MARKITUP_MEDIA_URL', settings.MEDIA_URL)
 MARKITUP_SET = getattr(settings, 'MARKITUP_SET', 'markitup/sets/default')
 MARKITUP_SKIN = getattr(settings, 'MARKITUP_SKIN', 'markitup/skins/simple')

File markitup/templates/markitup/editor.html

View file
  • Ignore whitespace
 <script type="text/javascript">
 $(document).ready(function() {
   $("#{{ textarea_id }}").markItUp(mySettings);
+  {% if AUTO_PREVIEW %}$('a[title="Preview"]').trigger('mouseup');{% endif %}
 });
 </script>

File markitup/templatetags/markitup_tags.py

View file
  • Ignore whitespace
 
 @register.inclusion_tag('markitup/editor.html')
 def markitup_editor(textarea_id):
-    return {'textarea_id': textarea_id}
+    return {'textarea_id': textarea_id,
+            'AUTO_PREVIEW': settings.MARKITUP_AUTO_PREVIEW}

File markitup/widgets.py

View file
  • Ignore whitespace
 """
 widgets for django-markitup
 
-Time-stamp: <2009-11-06 14:28:29 carljm widgets.py>
+Time-stamp: <2010-01-06 11:46:37 carljm widgets.py>
 
 """
 from django import forms
 
     def render(self, name, value, attrs=None):
         html = super(MarkItUpWidget, self).render(name, value, attrs)
+
+        if settings.MARKITUP_AUTO_PREVIEW:
+            auto_preview = "$('a[title=\"Preview\"]').trigger('mouseup');"
+        else: auto_preview = ''
+
         html += ('<script type="text/javascript">'
                  '$(document).ready(function() {'
-                 '  $("#%s").markItUp(mySettings);'
+                 '  $("#%(id)s").markItUp(mySettings);'
+                 '  %(auto_preview)s '
                  '});'
-                 '</script>' % attrs['id'])
+                 '</script>' % {'id': attrs['id'],
+                                'auto_preview': auto_preview })
         return mark_safe(html)
 
 
     """
     Add vLargeTextarea class to MarkItUpWidget so it looks more
     similar to other admin textareas.
-    
+
     """
     pass

File tests/tests.py

View file
  • Ignore whitespace
 
                       
 class RenderTests(MIUTestCase):
+    look_for = '$("#my_id").markItUp(mySettings);'
+    
     def test_widget_render(self):
         widget = MarkItUpWidget()
-        self.assertIn('$("#my_id").markItUp(mySettings);',
+        self.assertIn(self.look_for,
                       widget.render('name', 'value', {'id': 'my_id'}))
 
     def test_templatetag_render(self):
         template = """{% load markitup_tags %}{% markitup_editor "my_id" %}"""
-        self.assertIn('$("#my_id").markItUp(mySettings);',
+        self.assertIn(self.look_for,
                       self.render(template))
 
+class AutoPreviewRenderTests(RenderTests):
+    look_for = "$('a[title=\"Preview\"]').trigger('mouseup');"
+    
+    def setUp(self):
+        self._old_auto = settings.MARKITUP_AUTO_PREVIEW
+        settings.MARKITUP_AUTO_PREVIEW = True
+
+    def tearDown(self):
+        settings.MARKITUP_AUTO_PREVIEW = self._old_auto
+    
 
 class TemplatetagMediaUrlTests(MIUTestCase):
     prefix = '/media'