From 5922d977392119d15f40963e8a5d7fe9ca368ade Mon Sep 17 00:00:00 2001 From: Jacob Mason Date: Thu, 12 Aug 2010 17:07:15 -0500 Subject: [PATCH] separate js templates from js scripts --- .../basic/static/websupport-templates.html | 97 ++++++++++++++ sphinx/themes/basic/static/websupport.js | 123 ++++-------------- sphinx/websupport/__init__.py | 3 +- 3 files changed, 122 insertions(+), 101 deletions(-) create mode 100644 sphinx/themes/basic/static/websupport-templates.html diff --git a/sphinx/themes/basic/static/websupport-templates.html b/sphinx/themes/basic/static/websupport-templates.html new file mode 100644 index 000000000..1ea58ab24 --- /dev/null +++ b/sphinx/themes/basic/static/websupport-templates.html @@ -0,0 +1,97 @@ +
+
+
  • +
    +
    + + + + +
    +
    +
  • +
    + +
    +
    +
    + + +
    +
    +

    + <%username%> + <%pretty_rating%> + <%time.delta%> +

    +

    <%text%>

    +

    + + reply ▿ + + proposal ▹ + + + proposal ▿ + + + +

    +
    +	  <#proposal_diff#>
    +	
    +
      +
      +
      +
      +
      + + +
      diff --git a/sphinx/themes/basic/static/websupport.js b/sphinx/themes/basic/static/websupport.js index 2e43c7324..1f00ee465 100644 --- a/sphinx/themes/basic/static/websupport.js +++ b/sphinx/themes/basic/static/websupport.js @@ -31,11 +31,10 @@ })(jQuery); (function($) { - var commentListEmpty, popup, comp; + var commentListEmpty, popup, comp, commentTemplate, replyTemplate; function init() { initTemplates(); - initEvents(); initComparator(); }; @@ -95,12 +94,27 @@ }; function initTemplates() { - // Create our popup div, the same div is recycled each time comments - // are displayed. - popup = $(renderTemplate(popupTemplate, opts)); - // Setup autogrow on the textareas - popup.find('textarea').autogrow(); - $('body').append(popup); + var templateURL = opts.staticDir + '/_static/websupport-templates.html'; + $.get(templateURL, function(data) { + var templates = $(data); + function loadTemplate(id) { + var html = templates.find('#' + id).html(); + html = html.replace(/(<)|(%3C)/g, "<"); + html = html.replace(/(>)|(%3E)/g, ">"); + return html; + }; + // Create our popup div, the same div is recycled each time comments + // are displayed. + // Setup autogrow on the textareas + var popupTemplate = loadTemplate('popup_template'); + popup = $(renderTemplate(popupTemplate, opts)); + popup.find('textarea').autogrow(); + + commentTemplate = loadTemplate('#comment_template'); + replyTemplate = loadTemplate('#reply_template'); + $('body').append(popup); + initEvents(); + }); }; /** @@ -646,102 +660,11 @@ downArrow: '/static/_static/down.png', upArrowPressed: '/static/_static/up-pressed.png', downArrowPressed: '/static/_static/down-pressed.png', + staticDir: '/static', voting: false, moderator: false }, COMMENT_OPTIONS); - var replyTemplate = '
    • \ -
      \ -
      \ - \ - \ - \ - \ -
      \ -
      \ -
    • '; - - var commentTemplate = '
      \ -
      \ -
      \ - \ - \ - \ - \ - \ - \ -
      \ -
      \ - \ - \ - \ - \ - \ - \ -
      \ -
      \ -
      \ -

      \ - <%username%>\ - <%pretty_rating%>\ - <%time.delta%>\ -

      \ -

      <%text%>

      \ -

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

      \ -
      \
      -<#proposal_diff#>\
      -	
      \ -
        \ -
        \ -
        \ -
        '; - - var popupTemplate = ' \ -
        '; - $(document).ready(function() { init(); }); diff --git a/sphinx/websupport/__init__.py b/sphinx/websupport/__init__.py index cc065b7f7..939428a6c 100644 --- a/sphinx/websupport/__init__.py +++ b/sphinx/websupport/__init__.py @@ -376,7 +376,8 @@ class WebSupport(object): ('upArrow', 'up.png'), ('upArrowPressed', 'up-pressed.png'), ('downArrow', 'down.png'), - ('downArrowPressed', 'down-pressed.png') + ('downArrowPressed', 'down-pressed.png'), + ('staticDir', '/' + self.staticdir) ] for key, value in static_urls: self.base_comment_opts[key] = \