Commits

Petar Radosevic committed 0b3f4ad

Added auto-preview setting

  • Participants
  • Parent commits 4804690

Comments (0)

Files changed (2)

File markitup/settings.py

 
 MARKITUP_PREVIEW_FILTER = getattr(settings, 'MARKITUP_PREVIEW_FILTER',
                                   getattr(settings, 'MARKITUP_FILTER', None))
+
+# Automaticly enable the markitup preview
+MARKITUP_PREVIEW_AUTO = getattr(settings, 'MARKITUP_PREVIEW_AUTO', 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/widgets.py

 
     def render(self, name, value, attrs=None):
         html = super(MarkItUpWidget, self).render(name, value, attrs)
+
+        if settings.MARKITUP_PREVIEW_AUTO:
+            preview_auto = "$('a[title=\"Preview\"]').trigger('mouseup');"
+        else: preview_auto = ''
+
         html += ('<script type="text/javascript">'
                  '$(document).ready(function() {'
-                 '  $("#%s").markItUp(mySettings);'
+                 '  $("#%(id)s").markItUp(mySettings);'
+                 '  %(preview_auto)s '
                  '});'
-                 '</script>' % attrs['id'])
+                 '</script>' % {'id': attrs['id'],
+                                'preview_auto': preview_auto })
         return mark_safe(html)
 
 
     """
     Add vLargeTextarea class to MarkItUpWidget so it looks more
     similar to other admin textareas.
-    
+
     """
     pass