changeset 127:2d299909e074

Adding markdown help to comments and forums. Still need to add it to a few other places that use the markItUp editor.
author Brian Neal <bgneal@gmail.com>
date Mon, 16 Nov 2009 01:00:28 +0000
parents b0d62247c3e4
children 48621ba5c385
files gpp/comments/forms.py gpp/core/templatetags/script_tags.py gpp/core/views.py gpp/forums/templatetags/forum_tags.py gpp/templates/comments/comment_form.html gpp/templates/core/markdown_help.html gpp/templates/downloads/download_detail.html gpp/templates/forums/edit_post.html gpp/templates/forums/new_post.html gpp/templates/forums/new_topic.html gpp/templates/forums/show_form.html gpp/templates/forums/topic.html gpp/templates/news/story.html gpp/templates/polls/poll_results.html gpp/templates/potd/view.html gpp/urls.py media/icons/help.png media/js/comments.js media/js/forums.js
diffstat 19 files changed, 330 insertions(+), 69 deletions(-) [+]
line wrap: on
line diff
--- a/gpp/comments/forms.py	Sat Nov 14 20:30:31 2009 +0000
+++ b/gpp/comments/forms.py	Mon Nov 16 01:00:28 2009 +0000
@@ -66,7 +66,9 @@
 
     class Media:
         css = {
-            'all': settings.GPP_THIRD_PARTY_CSS['markitup'],
+            'all': (settings.GPP_THIRD_PARTY_CSS['markitup'] +
+                settings.GPP_THIRD_PARTY_CSS['jquery-ui']),
         }
-        js = settings.GPP_THIRD_PARTY_JS['markitup'] + \
-            ('js/comments.js', )
+        js = (settings.GPP_THIRD_PARTY_JS['markitup'] + 
+                settings.GPP_THIRD_PARTY_JS['jquery-ui'] +
+                ('js/comments.js', ))
--- a/gpp/core/templatetags/script_tags.py	Sat Nov 14 20:30:31 2009 +0000
+++ b/gpp/core/templatetags/script_tags.py	Mon Nov 16 01:00:28 2009 +0000
@@ -7,21 +7,22 @@
 register = template.Library()
 
 @register.simple_tag
-def script_tags(library):
+def script_tags(libraries):
     s = ''
-    if library in settings.GPP_THIRD_PARTY_CSS:
-        for path in settings.GPP_THIRD_PARTY_CSS[library]:
-            prefix = ''
-            if not path.startswith('http'):
-                prefix = settings.MEDIA_URL
-            s += '<link rel="stylesheet" href="%s%s" type="text/css" />' % (prefix, path)
+    for library in libraries.split():
+        if library in settings.GPP_THIRD_PARTY_CSS:
+            for path in settings.GPP_THIRD_PARTY_CSS[library]:
+                prefix = ''
+                if not path.startswith('http'):
+                    prefix = settings.MEDIA_URL
+                s += '<link rel="stylesheet" href="%s%s" type="text/css" />' % (prefix, path)
 
-    if library in settings.GPP_THIRD_PARTY_JS:
-        for path in settings.GPP_THIRD_PARTY_JS[library]:
-            prefix = ''
-            if not path.startswith('http'):
-                prefix = settings.MEDIA_URL
-            s += '<script type="text/javascript" src="%s%s"></script>' % (prefix, path)
+        if library in settings.GPP_THIRD_PARTY_JS:
+            for path in settings.GPP_THIRD_PARTY_JS[library]:
+                prefix = ''
+                if not path.startswith('http'):
+                    prefix = settings.MEDIA_URL
+                s += '<script type="text/javascript" src="%s%s"></script>' % (prefix, path)
 
     return s
 
--- a/gpp/core/views.py	Sat Nov 14 20:30:31 2009 +0000
+++ b/gpp/core/views.py	Mon Nov 16 01:00:28 2009 +0000
@@ -1,1 +1,17 @@
-# Create your views here.
+"""
+Views for the core application. These are mainly shared, common views
+used by multiple applications.
+"""
+from django.shortcuts import render_to_response
+from django.template import RequestContext
+from django.contrib.auth.decorators import login_required
+from django.views.decorators.http import require_GET
+
+@login_required
+@require_GET
+def markdown_help(request):
+    """
+    This view provides the Markdown help cheat sheet. It is expected
+    to be called via AJAX.
+    """
+    return render_to_response('core/markdown_help.html')
--- a/gpp/forums/templatetags/forum_tags.py	Sat Nov 14 20:30:31 2009 +0000
+++ b/gpp/forums/templatetags/forum_tags.py	Mon Nov 16 01:00:28 2009 +0000
@@ -80,3 +80,17 @@
         fmt = DATE_FMT_12
 
     return date.strftime(fmt)
+
+
+@register.inclusion_tag('forums/show_form.html')
+def show_form(legend_text, form, submit_value, is_ajax, media_url):
+    """
+    This tag displays the common HTML for a forum form.
+    """
+    return {
+        'legend_text': legend_text,
+        'form': form,
+        'submit_value': submit_value,
+        'is_ajax': is_ajax,
+        'MEDIA_URL': media_url,
+    }
--- a/gpp/templates/comments/comment_form.html	Sat Nov 14 20:30:31 2009 +0000
+++ b/gpp/templates/comments/comment_form.html	Mon Nov 16 01:00:28 2009 +0000
@@ -1,8 +1,18 @@
 {% if user.is_authenticated %}
 <form action="{% url comments-post %}" method="post" id="comment-form">
 {{ form.as_p }}
+<a href="#" id="more_smileys">
+<img src="{{ MEDIA_URL }}icons/emoticon_smile.png" alt="More smileys" title="More smileys" /></a>
+<a href="#" id="markdown_help">
+<img src="{{ MEDIA_URL }}icons/help.png" alt="Help" title="Help" /></a>
 <input type="submit" name="post" value="Post Comment" id="comment-form-post"/>
 </form>
+<div id="smileys_dialog" title="More Smileys">
+<img src="{{ MEDIA_URL }}icons/ajax_busy.gif" alt="Loading" id="smiley_busy" />
+</div>
+<div id="markdown_help_dialog" title="Markdown Help">
+<img src="{{ MEDIA_URL }}icons/ajax_busy.gif" alt="Loading" id="markdown_busy" />
+</div>
 {% else %}
 <p>
 Please <a href="{% url accounts-login %}">login</a> or
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gpp/templates/core/markdown_help.html	Mon Nov 16 01:00:28 2009 +0000
@@ -0,0 +1,167 @@
+<table>
+   <tr><th>&nbsp;</th><th>Type This</th><th>To See This</th></tr>
+   <tr>
+      <th>Paragrahs</th>
+      <td>
+<pre>Paragraphs must be separated by a blank line.
+
+Here is another paragraph.
+</pre></td>
+      <td>
+         <p>Paragraphs must be separated by a blank line.</p>
+         <p>Here is another paragraph.</p>
+      </td>
+   </tr>
+   <tr>
+      <th>Manual Line Breaks</th>
+      <td>
+<pre>To insert a line break  
+end a line with two or more spaces.
+</pre></td>
+      <td>
+         <p>To insert a line break <br />
+         end a line with two or more spaces.</p>
+      </td>
+   </tr>
+   <tr>
+      <th>Emphasis</th>
+      <td>
+<pre>*italic*
+_italic_
+**bold**
+__bold__</pre></td>
+      <td><i>italic</i><br />
+         <i>italic</i><br />
+         <b>bold</b><br />
+         <b>bold</b></td>
+   </tr>
+   <tr>
+      <th>Inline links</th>
+      <td>A link to [Google](http://google.com).</td>
+      <td>A link to <a href="http://google.com">Google</a>.</td>
+   </tr>
+   <tr>
+      <th>Reference links</th>
+      <td>A link to [Google][id]. Then anywhere else in the
+         text, define the link on its own line.<br/>
+         [id]: http://google.com </td>
+      <td>A link to <a href="http://google.com">Google</a>. Then
+      anywhere else in the text, define the link on its own line.</td>
+   </tr>
+   <tr>
+      <th>Inline Images</th>
+      <td>![alt text](/static/icons/emoticon_smile.png "Smile").</td>
+      <td><img src="/static/icons/emoticon_smile.png" alt="alt text" title="Smile" /></td>
+   </tr>
+   <tr>
+      <th>Reference Images</th>
+      <td>![alt text][id]<br />
+      [id]: /static/icons/emoticon_smile.png "Smile"</td>
+      </td>
+      <td><img src="/static/icons/emoticon_smile.png" alt="alt text" title="Smile" /></td>
+   </tr>
+   <tr>
+      <th>Bullet List</th>
+      <td>
+      <pre>* One
+* Two
+* Three</pre></td>
+      <td>
+         <ul>
+         <li>One</li>
+         <li>Two</li>
+         <li>Three</li>
+         </ul>
+      </td>
+   </tr>
+   <tr>
+      <th>Numbered List</th>
+      <td>
+      <pre>1. One
+1. Two
+1. Three</pre></td>
+      <td>
+         <ol>
+         <li>One</li>
+         <li>Two</li>
+         <li>Three</li>
+         </ol>
+      </td>
+   </tr>
+   <tr>
+      <th>Blockquotes</th>
+      <td><pre>John said:
+&gt; Email style angle brackets
+&gt; are used for quotes.</pre></td>
+      <td><p>John said:</p>
+         <blockquote><p>Email-style angle brackets are used for blockquotes.</p></blockquote></td>
+   </tr>
+   <tr>
+      <th>Code Spans</th>
+      <td><pre>`&lt;code&gt;` spans are delimited by backticks.</pre></td>
+      <td><p><code>&lt;code&gt;</code> spans are delimited by backticks.</p></td>
+   </tr>
+   <tr>
+      <th>Code Blocks</th>
+      <td><pre>First insert a blank line.
+
+    Then indent every line 
+    of a code block by at least
+    4 spaces. This is useful to 
+    display tablature.
+</pre></td>
+      <td>
+<p>First insert a blank line.</p>
+
+<pre><code>Then indent every line 
+of a code block by at least
+4 spaces. This is useful to 
+display tablature.
+</code></pre>
+      </td>
+   </tr>
+   <tr>
+      <th>Header 1</th>
+      <td>
+      <pre>Header 1
+========
+</pre></td>
+      <td><h1>Header 1</h1></td>
+   </tr>
+   <tr>
+      <th>Header 2</th>
+      <td>
+      <pre>Header 2
+--------
+</pre></td>
+      <td><h2>Header 2</h2></td>
+   </tr>
+   <tr>
+      <th>Header 1</th>
+      <td><pre># Header 1</pre></td>
+      <td><h1>Header 1</h1></td>
+   </tr>
+   <tr>
+      <th>Header 2</th>
+      <td><pre>## Header 2</pre></td>
+      <td><h2>Header 2</h2></td>
+   </tr>
+   <tr>
+      <th>Header 3</th>
+      <td><pre>### Header 3</pre></td>
+      <td><h3>Header 3</h3></td>
+   </tr>
+   <tr>
+      <th>Header 6</th>
+      <td><pre>###### Header 6</pre></td>
+      <td><h6>Header 6</h6></td>
+   </tr>
+</table>
+<p>
+More help:
+</p>
+<ul>
+   <li><a href="http://daringfireball.net/projects/markdown/basics" target="_blank">Markdown Basics</a></li>
+   <li><a href="http://daringfireball.net/projects/markdown/syntax" target="_blank">Markdown Reference</a></li>
+</ul>
+<p>Hit <code>ESC</code> or click the <code>X</code> to close this window.</p>
--- a/gpp/templates/downloads/download_detail.html	Sat Nov 14 20:30:31 2009 +0000
+++ b/gpp/templates/downloads/download_detail.html	Mon Nov 16 01:00:28 2009 +0000
@@ -8,7 +8,7 @@
 <link rel="stylesheet" type="text/css" href="{{ MEDIA_URL }}css/downloads.css" />
 {% endblock %}
 {% block custom_js %}
-{% script_tags "markitup" %}
+{% script_tags "markitup jquery-ui" %}
 <script type="text/javascript" src="{{ MEDIA_URL }}js/comments.js"></script>
 <script type="text/javascript" src="{{ MEDIA_URL }}js/downloads/rating.js"></script>
 {% endblock %}
--- a/gpp/templates/forums/edit_post.html	Sat Nov 14 20:30:31 2009 +0000
+++ b/gpp/templates/forums/edit_post.html	Mon Nov 16 01:00:28 2009 +0000
@@ -1,4 +1,5 @@
 {% extends 'base.html' %}
+{% load forum_tags %}
 {% block title %}Forums: Edit Post{% endblock %}
 {% block custom_js %}{{ form.media }}{% endblock %}
 {% block content %}
@@ -16,17 +17,6 @@
 </table>
 
 <a name="forum-reply-form"></a>
-<form action="." method="post" id="forums-quick-reply">
-<fieldset>
-<legend>Edit Post</legend>
-{{ form.as_p }}
-<a href="#" id="more_smileys">
-<img src="{{ MEDIA_URL }}icons/emoticon_smile.png" alt="More smileys" title="More smileys" /></a>
-<input type="submit" value="Update Post" id="forums-edit-post" />
-</fieldset>
-</form>
-</div>
-<div id="smileys_dialog" title="More Smileys">
-<img src="{{ MEDIA_URL }}icons/ajax_busy.gif" alt="Loading" id="smiley_busy" />
+{% show_form "Edit Post" form "Update Post" 0 MEDIA_URL %}
 </div>
 {% endblock %}
--- a/gpp/templates/forums/new_post.html	Sat Nov 14 20:30:31 2009 +0000
+++ b/gpp/templates/forums/new_post.html	Mon Nov 16 01:00:28 2009 +0000
@@ -1,4 +1,5 @@
 {% extends 'base.html' %}
+{% load forum_tags %}
 {% block title %}Forums: New Post{% endblock %}
 {% block custom_js %}{{ form.media }}{% endblock %}
 {% block content %}
@@ -13,19 +14,7 @@
 {% if can_post %}
 <div class="forum-block">
 <a name="forum-reply-form"></a>
-<form action="." method="post" id="forums-reply">
-<fieldset>
-<legend>New Post</legend>
-{{ form.as_p }}
-<a href="#" id="more_smileys">
-<img src="{{ MEDIA_URL }}icons/emoticon_smile.png" alt="More smileys" title="More smileys" /></a>
-<input type="submit" value="Submit Post" id="forums-new-post" />
-</fieldset>
-</form>
-</div>
-<div id="smileys_dialog" title="More Smileys">
-<img src="{{ MEDIA_URL }}icons/ajax_busy.gif" alt="Loading" id="smiley_busy" />
-</div>
+{% show_form "New Post" form "Submit Post" 0 MEDIA_URL %}
 {% else %}
    {% if topic.locked %}
    <p>This topic is locked.</p>
@@ -33,4 +22,5 @@
    <p>You don't have permission to post to this topic.</p>
    {% endif %}
 {% endif %}
+</div>
 {% endblock %}
--- a/gpp/templates/forums/new_topic.html	Sat Nov 14 20:30:31 2009 +0000
+++ b/gpp/templates/forums/new_topic.html	Mon Nov 16 01:00:28 2009 +0000
@@ -1,4 +1,5 @@
 {% extends 'base.html' %}
+{% load forum_tags %}
 {% block title %}Forums: New Topic{% endblock %}
 {% block custom_js %}{{ form.media }}{% endblock %}
 {% block content %}
@@ -9,15 +10,5 @@
    <a href="{% url forums-forum_index slug=forum.slug %}">{{ forum.name }}</a>
 </h3>
 
-<form action="." method="post">
-{{ form.as_p }}
-<a href="#" id="more_smileys">
-<img src="{{ MEDIA_URL }}icons/emoticon_smile.png" alt="More smileys" title="More smileys" /></a>
-<input type="submit" name="post" value="Submit" />
-</form>
-
-<div id="smileys_dialog" title="More Smileys">
-<img src="{{ MEDIA_URL }}icons/ajax_busy.gif" alt="Loading" id="smiley_busy" />
-</div>
-
+{% show_form "New Topic" form "Submit" 0 MEDIA_URL %}
 {% endblock %}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gpp/templates/forums/show_form.html	Mon Nov 16 01:00:28 2009 +0000
@@ -0,0 +1,17 @@
+<form action="." method="post">
+<fieldset>
+<legend>{{ legend_text }}</legend>
+{{ form.as_p }}
+<a href="#" id="more_smileys">
+<img src="{{ MEDIA_URL }}icons/emoticon_smile.png" alt="More smileys" title="More smileys" /></a>
+<a href="#" id="markdown_help">
+<img src="{{ MEDIA_URL }}icons/help.png" alt="Help" title="Help" /></a>
+<input type="submit" value="{{ submit_value }}" {% if is_ajax %}id="forums-reply-post"{% endif %} />
+</fieldset>
+</form>
+<div id="smileys_dialog" title="More Smileys">
+<img src="{{ MEDIA_URL }}icons/ajax_busy.gif" alt="Loading" id="smiley_busy" />
+</div>
+<div id="markdown_help_dialog" title="Markdown Help">
+<img src="{{ MEDIA_URL }}icons/ajax_busy.gif" alt="Loading" id="markdown_busy" />
+</div>
--- a/gpp/templates/forums/topic.html	Sat Nov 14 20:30:31 2009 +0000
+++ b/gpp/templates/forums/topic.html	Mon Nov 16 01:00:28 2009 +0000
@@ -1,4 +1,5 @@
 {% extends 'base.html' %}
+{% load forum_tags %}
 {% block title %}Forums: {{ topic.name }}{% endblock %}
 {% block custom_js %}{{ form.media }}{% endblock %}
 {% block content %}
@@ -54,18 +55,7 @@
 
 {% if last_page and can_reply %}
 <a name="forum-reply-form"></a>
-<form action="" method="post" id="forums-quick-reply">
-<fieldset>
-<legend>Reply to &quot;{{ topic.name }}&quot;</legend>
-{{ form.as_p }}
-<a href="#" id="more_smileys">
-<img src="{{ MEDIA_URL }}icons/emoticon_smile.png" alt="More smileys" title="More smileys" /></a>
-<input type="submit" value="Submit Reply" id="forums-reply-post" />
-</fieldset>
-</form>
-<div id="smileys_dialog" title="More Smileys">
-<img src="{{ MEDIA_URL }}icons/ajax_busy.gif" alt="Loading" id="smiley_busy" />
-</div>
+{% show_form "Reply to Topic" form "Submit Reply" 1 MEDIA_URL %}
 {% endif %}
 </div>
 {% endblock %}
--- a/gpp/templates/news/story.html	Sat Nov 14 20:30:31 2009 +0000
+++ b/gpp/templates/news/story.html	Mon Nov 16 01:00:28 2009 +0000
@@ -8,7 +8,7 @@
 {% endblock %}
 {% block custom_js %}
 {% if story.can_comment_on %}
-{% script_tags "markitup" %}
+{% script_tags "markitup jquery-ui" %}
 <script type="text/javascript" src="{{ MEDIA_URL }}js/comments.js"></script>
 {% endif %}
 {% endblock %}
--- a/gpp/templates/polls/poll_results.html	Sat Nov 14 20:30:31 2009 +0000
+++ b/gpp/templates/polls/poll_results.html	Mon Nov 16 01:00:28 2009 +0000
@@ -8,7 +8,7 @@
 {% endblock %}
 {% block custom_js %}
 {% if poll.is_open %}
-{% script_tags "markitup" %}
+{% script_tags "markitup jquery-ui" %}
 <script type="text/javascript" src="{{ MEDIA_URL }}js/comments.js"></script>
 {% endif %}
 {% endblock %}
--- a/gpp/templates/potd/view.html	Sat Nov 14 20:30:31 2009 +0000
+++ b/gpp/templates/potd/view.html	Mon Nov 16 01:00:28 2009 +0000
@@ -7,7 +7,7 @@
 <link rel="stylesheet" type="text/css" href="{{ MEDIA_URL }}css/comments.css" />
 {% endblock %}
 {% block custom_js %}
-{% script_tags "markitup" %}
+{% script_tags "markitup jquery-ui" %}
 <script type="text/javascript" src="{{ MEDIA_URL }}js/comments.js"></script>
 {% endblock %}
 {% block content %}
--- a/gpp/urls.py	Sat Nov 14 20:30:31 2009 +0000
+++ b/gpp/urls.py	Mon Nov 16 01:00:28 2009 +0000
@@ -17,6 +17,7 @@
    (r'^calendar/', include('gcalendar.urls')),
    (r'^comments/', include('comments.urls')),
    (r'^contact/', include('contact.urls')),
+   (r'^core/', include('core.urls')),
    (r'^donations/', include('donations.urls')),
    (r'^downloads/', include('downloads.urls')),
    url(r'^feeds/(?P<url>.*)/$', 
Binary file media/icons/help.png has changed
--- a/media/js/comments.js	Sat Nov 14 20:30:31 2009 +0000
+++ b/media/js/comments.js	Mon Nov 16 01:00:28 2009 +0000
@@ -62,4 +62,54 @@
         return false;
     });
     postText.markItUp(mySettings);
+
+   $('#smileys_dialog').dialog({autoOpen:false});
+   var firstTime = true;
+   $('#more_smileys').click(function () {
+         $('#smileys_dialog').dialog('open');
+         var postBox = $('#id_comment')[0];
+         if (firstTime) {
+            $.ajax({
+               url: '/smiley/farm/extra/',
+               type: 'GET',
+               dataType: 'html',
+               success: function(data, textStatus) {
+                  var img = $('#smiley_busy');
+                  img.hide();
+                  img.after(data);
+                  $('#smileys_dialog .smiley_farm img').click(function() {
+                     postBox.value += ' ' + this.alt + ' ';
+                     postBox.focus();
+                  });
+                  firstTime = false;
+               },
+               error: function (xhr, textStatus, ex) {
+                  alert('Oops, an error occurred: ' + xhr.statusText + ' - ' + xhr.responseText);
+               }
+            });
+         }
+         return false;
+      });
+   $('#markdown_help_dialog').dialog({autoOpen: false, width: 720, height: 600});
+   var firstTimeMd = true;
+   $('#markdown_help').click(function () {
+         $('#markdown_help_dialog').dialog('open');
+         if (firstTimeMd) {
+            $.ajax({
+               url: '/core/markdown_help/',
+               type: 'GET',
+               dataType: 'html',
+               success: function(data, textStatus) {
+                  var img = $('#markdown_busy');
+                  img.hide();
+                  img.after(data);
+                  firstTimeMd = false;
+               },
+               error: function (xhr, textStatus, ex) {
+                  alert('Oops, an error occurred: ' + xhr.statusText + ' - ' + xhr.responseText);
+               }
+            });
+         }
+         return false;
+      });
 });
--- a/media/js/forums.js	Sat Nov 14 20:30:31 2009 +0000
+++ b/media/js/forums.js	Mon Nov 16 01:00:28 2009 +0000
@@ -110,4 +110,26 @@
          }
          return false;
       });
+   $('#markdown_help_dialog').dialog({autoOpen: false, width: 720, height: 600});
+   var firstTimeMd = true;
+   $('#markdown_help').click(function () {
+         $('#markdown_help_dialog').dialog('open');
+         if (firstTimeMd) {
+            $.ajax({
+               url: '/core/markdown_help/',
+               type: 'GET',
+               dataType: 'html',
+               success: function(data, textStatus) {
+                  var img = $('#markdown_busy');
+                  img.hide();
+                  img.after(data);
+                  firstTimeMd = false;
+               },
+               error: function (xhr, textStatus, ex) {
+                  alert('Oops, an error occurred: ' + xhr.statusText + ' - ' + xhr.responseText);
+               }
+            });
+         }
+         return false;
+      });
 });