From e05137417a2a61cdc3ed4b62142c460d8942e565 Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Sun, 21 Nov 2010 11:13:11 +0100 Subject: [PATCH] Tweak the commenting interface a bit. --- sphinx/builders/websupport.py | 19 ++-- sphinx/themes/basic/static/websupport.js | 131 +++++++++++------------ sphinx/websupport/__init__.py | 9 +- sphinx/websupport/storage/differ.py | 2 +- 4 files changed, 83 insertions(+), 78 deletions(-) diff --git a/sphinx/builders/websupport.py b/sphinx/builders/websupport.py index d4c08c295e..c883fdf171 100644 --- a/sphinx/builders/websupport.py +++ b/sphinx/builders/websupport.py @@ -78,8 +78,7 @@ class WebSupportBuilder(PickleHTMLBuilder, VersioningBuilderMixin): self.indexer = self.search self.indexer.init_indexing(changed=docnames) - def handle_page(self, pagename, addctx, templatename='page.html', - outfilename=None, event_arg=None): + def _render_page(self, pagename, addctx, templatename, event_arg=None): # This is mostly copied from StandaloneHTMLBuilder. However, instead # of rendering the template and saving the html, create a context # dict and pickle it. @@ -116,10 +115,13 @@ class WebSupportBuilder(PickleHTMLBuilder, VersioningBuilderMixin): for item in ['sidebar', 'relbar', 'script', 'css']: if hasattr(template_module, item): doc_ctx[item] = getattr(template_module, item)() - if 'script' not in self.globalcontext: - self.globalcontext['script'] = doc_ctx['script'] - if 'css' not in self.globalcontext: - self.globalcontext['css'] = doc_ctx['css'] + + return ctx, doc_ctx + + def handle_page(self, pagename, addctx, templatename='page.html', + outfilename=None, event_arg=None): + ctx, doc_ctx = self._render_page(pagename, addctx, + templatename, event_arg) if not outfilename: outfilename = path.join(self.outdir, 'pickles', @@ -136,6 +138,11 @@ class WebSupportBuilder(PickleHTMLBuilder, VersioningBuilderMixin): copyfile(self.env.doc2path(pagename), source_name) def handle_finish(self): + # get global values for css and script files + _, doc_ctx = self._render_page('tmp', {}, 'page.html') + self.globalcontext['css'] = doc_ctx['css'] + self.globalcontext['script'] = doc_ctx['script'] + PickleHTMLBuilder.handle_finish(self) VersioningBuilderMixin.finish(self) diff --git a/sphinx/themes/basic/static/websupport.js b/sphinx/themes/basic/static/websupport.js index d04336eaa3..94123c5340 100644 --- a/sphinx/themes/basic/static/websupport.js +++ b/sphinx/themes/basic/static/websupport.js @@ -431,6 +431,10 @@ } var id = link.attr('id'); + if (!id) { + // Didn't click on one of the voting arrows. + return; + } // If it is an unvote, the new vote value is 0, // Otherwise it's 1 for an upvote, or -1 for a downvote. var value = 0; @@ -535,21 +539,18 @@ ul.children().children("[id^='cd']") .each(function() { var comment = $(this).data('comment'); - if (recursive) { + if (recursive) comment.children = getChildren($(this).find('#cl' + comment.id), true); - } children.push(comment); }); return children; } - /** - * Create a div to display a comment in. - */ + /** Create a div to display a comment in. */ function createCommentDiv(comment) { // Prettify the comment rating. comment.pretty_rating = comment.rating + ' point' + - (comment.rating == 1 ? '' : 's'); + (comment.rating == 1 ? '' : 's'); // Create a div for this comment. var context = $.extend({}, opts, comment); var div = $(renderTemplate(commentTemplate, context)); @@ -563,15 +564,12 @@ if (comment.text != '[deleted]') { div.find('a.reply').show(); - if (comment.proposal_diff) { + if (comment.proposal_diff) div.find('#sp' + comment.id).show(); - } - if (opts.moderator && !comment.displayed) { + if (opts.moderator && !comment.displayed) div.find('#cm' + comment.id).show(); - } - if (opts.moderator || (opts.username == comment.username)) { + if (opts.moderator || (opts.username == comment.username)) div.find('#dc' + comment.id).show(); - } } return div; } @@ -597,6 +595,7 @@ }); } + /** Flash an error message briefly. */ function showError(message) { $(document.createElement('div')).attr({'class': 'popup-error'}) .append($(document.createElement('div')) @@ -607,9 +606,7 @@ .fadeOut("slow"); } - /** - * Add a link the user uses to open the comments popup. - */ + /** Add a link the user uses to open the comments popup. */ $.fn.comment = function() { return this.each(function() { var id = $(this).attr('id').substring(1); @@ -621,7 +618,7 @@ .append( $(document.createElement('a')).attr({ href: '#', - 'class': 'sphinx-comment' + addcls, + 'class': 'sphinx-comment-open' + addcls, id: 'ao' + id }) .append($(document.createElement('img')).attr({ @@ -676,34 +673,53 @@ opts = jQuery.extend(opts, COMMENT_OPTIONS); } - var replyTemplate = '\ -
  • \ -
    \ -
    \ - \ - \ - \ - \ -
    \ -
    \ -
  • '; + var popupTemplate = '\ +
    \ +

    \ + Sort by:\ + top\ + newest\ + oldest\ +

    \ +
    Comments
    \ +
    \ + loading comments...
    \ + \ +

    Add a comment:

    \ +
    \ + \ +

    \ + \ + Propose a change ▹\ + \ + \ + Propose a change ▿\ + \ +

    \ + \ + \ + \ + \ +
    \ +
    '; var commentTemplate = '\ -
    \ +
    \
    \ \ \ @@ -718,15 +734,9 @@

    \ \ reply ▿\ - \ - proposal ▹\ - \ - \ - proposal ▿\ - \ - \ + proposal ▹\ + proposal ▿\ + \

    \
    '; - var popupTemplate = '\ -
    \ -
    Comments
    \ -
    \ - \ -

    \ - \ - Propose a change ▹\ - \ - \ - Propose a change ▿\ - \ -

    \ - \ - \ - \ - \ -

    \ - Sort by:\ - top\ - newest\ - oldest\ -

    \ -
    \ -
    loading comments...
    \ -
      \ -
      '; + var replyTemplate = '\ +
    • \ +
      \ +
      \ + \ + \ + \ + \ +
      \ +
      \ +
    • '; $(document).ready(function() { init(); @@ -775,6 +769,7 @@ })(jQuery); $(document).ready(function() { + /** Add comment anchors for all paragraphs that are commentable. */ $('.sphinx-has-comment').comment(); /** Highlight search words in search results. */ diff --git a/sphinx/websupport/__init__.py b/sphinx/websupport/__init__.py index a97a589dc2..9f8d9e304c 100644 --- a/sphinx/websupport/__init__.py +++ b/sphinx/websupport/__init__.py @@ -213,9 +213,12 @@ class WebSupport(object): 'search_results': results, 'docroot': '../', # XXX } - document = self.get_document('search') - document['body'] = self.results_template.render(ctx) - document['title'] = 'Search Results' + document = { + 'body': self.results_template.render(ctx), + 'title': 'Search Results', + 'sidebar': '', + 'relbar': '' + } return document def get_data(self, node_id, username=None, moderator=False): diff --git a/sphinx/websupport/storage/differ.py b/sphinx/websupport/storage/differ.py index d52250718f..8e430a137a 100644 --- a/sphinx/websupport/storage/differ.py +++ b/sphinx/websupport/storage/differ.py @@ -58,7 +58,7 @@ class CombinedHtmlDiff(object): if next is not None and next[0] == '?': tag = 'ins' if prefix == '+' else 'del' text = self._highlight_text(text, next, tag) - css_class = 'prop_added' if prefix == '+' else 'prop_removed' + css_class = 'prop-added' if prefix == '+' else 'prop-removed' return '%s\n' % (css_class, text.rstrip())