Statistics
| Branch: | Tag: | Revision:

root / doc / build / html / _static / websupport.js @ 6de88ee1

History | View | Annotate | Download (24.7 kB)

1 6de88ee1 Stauros Kroustouris
/*
2 6de88ee1 Stauros Kroustouris
 * websupport.js
3 6de88ee1 Stauros Kroustouris
 * ~~~~~~~~~~~~~
4 6de88ee1 Stauros Kroustouris
 *
5 6de88ee1 Stauros Kroustouris
 * sphinx.websupport utilties for all documentation.
6 6de88ee1 Stauros Kroustouris
 *
7 6de88ee1 Stauros Kroustouris
 * :copyright: Copyright 2007-2011 by the Sphinx team, see AUTHORS.
8 6de88ee1 Stauros Kroustouris
 * :license: BSD, see LICENSE for details.
9 6de88ee1 Stauros Kroustouris
 *
10 6de88ee1 Stauros Kroustouris
 */
11 6de88ee1 Stauros Kroustouris
12 6de88ee1 Stauros Kroustouris
(function($) {
13 6de88ee1 Stauros Kroustouris
  $.fn.autogrow = function() {
14 6de88ee1 Stauros Kroustouris
    return this.each(function() {
15 6de88ee1 Stauros Kroustouris
    var textarea = this;
16 6de88ee1 Stauros Kroustouris
17 6de88ee1 Stauros Kroustouris
    $.fn.autogrow.resize(textarea);
18 6de88ee1 Stauros Kroustouris
19 6de88ee1 Stauros Kroustouris
    $(textarea)
20 6de88ee1 Stauros Kroustouris
      .focus(function() {
21 6de88ee1 Stauros Kroustouris
        textarea.interval = setInterval(function() {
22 6de88ee1 Stauros Kroustouris
          $.fn.autogrow.resize(textarea);
23 6de88ee1 Stauros Kroustouris
        }, 500);
24 6de88ee1 Stauros Kroustouris
      })
25 6de88ee1 Stauros Kroustouris
      .blur(function() {
26 6de88ee1 Stauros Kroustouris
        clearInterval(textarea.interval);
27 6de88ee1 Stauros Kroustouris
      });
28 6de88ee1 Stauros Kroustouris
    });
29 6de88ee1 Stauros Kroustouris
  };
30 6de88ee1 Stauros Kroustouris
31 6de88ee1 Stauros Kroustouris
  $.fn.autogrow.resize = function(textarea) {
32 6de88ee1 Stauros Kroustouris
    var lineHeight = parseInt($(textarea).css('line-height'), 10);
33 6de88ee1 Stauros Kroustouris
    var lines = textarea.value.split('\n');
34 6de88ee1 Stauros Kroustouris
    var columns = textarea.cols;
35 6de88ee1 Stauros Kroustouris
    var lineCount = 0;
36 6de88ee1 Stauros Kroustouris
    $.each(lines, function() {
37 6de88ee1 Stauros Kroustouris
      lineCount += Math.ceil(this.length / columns) || 1;
38 6de88ee1 Stauros Kroustouris
    });
39 6de88ee1 Stauros Kroustouris
    var height = lineHeight * (lineCount + 1);
40 6de88ee1 Stauros Kroustouris
    $(textarea).css('height', height);
41 6de88ee1 Stauros Kroustouris
  };
42 6de88ee1 Stauros Kroustouris
})(jQuery);
43 6de88ee1 Stauros Kroustouris
44 6de88ee1 Stauros Kroustouris
(function($) {
45 6de88ee1 Stauros Kroustouris
  var comp, by;
46 6de88ee1 Stauros Kroustouris
47 6de88ee1 Stauros Kroustouris
  function init() {
48 6de88ee1 Stauros Kroustouris
    initEvents();
49 6de88ee1 Stauros Kroustouris
    initComparator();
50 6de88ee1 Stauros Kroustouris
  }
51 6de88ee1 Stauros Kroustouris
52 6de88ee1 Stauros Kroustouris
  function initEvents() {
53 6de88ee1 Stauros Kroustouris
    $('a.comment-close').live("click", function(event) {
54 6de88ee1 Stauros Kroustouris
      event.preventDefault();
55 6de88ee1 Stauros Kroustouris
      hide($(this).attr('id').substring(2));
56 6de88ee1 Stauros Kroustouris
    });
57 6de88ee1 Stauros Kroustouris
    $('a.vote').live("click", function(event) {
58 6de88ee1 Stauros Kroustouris
      event.preventDefault();
59 6de88ee1 Stauros Kroustouris
      handleVote($(this));
60 6de88ee1 Stauros Kroustouris
    });
61 6de88ee1 Stauros Kroustouris
    $('a.reply').live("click", function(event) {
62 6de88ee1 Stauros Kroustouris
      event.preventDefault();
63 6de88ee1 Stauros Kroustouris
      openReply($(this).attr('id').substring(2));
64 6de88ee1 Stauros Kroustouris
    });
65 6de88ee1 Stauros Kroustouris
    $('a.close-reply').live("click", function(event) {
66 6de88ee1 Stauros Kroustouris
      event.preventDefault();
67 6de88ee1 Stauros Kroustouris
      closeReply($(this).attr('id').substring(2));
68 6de88ee1 Stauros Kroustouris
    });
69 6de88ee1 Stauros Kroustouris
    $('a.sort-option').live("click", function(event) {
70 6de88ee1 Stauros Kroustouris
      event.preventDefault();
71 6de88ee1 Stauros Kroustouris
      handleReSort($(this));
72 6de88ee1 Stauros Kroustouris
    });
73 6de88ee1 Stauros Kroustouris
    $('a.show-proposal').live("click", function(event) {
74 6de88ee1 Stauros Kroustouris
      event.preventDefault();
75 6de88ee1 Stauros Kroustouris
      showProposal($(this).attr('id').substring(2));
76 6de88ee1 Stauros Kroustouris
    });
77 6de88ee1 Stauros Kroustouris
    $('a.hide-proposal').live("click", function(event) {
78 6de88ee1 Stauros Kroustouris
      event.preventDefault();
79 6de88ee1 Stauros Kroustouris
      hideProposal($(this).attr('id').substring(2));
80 6de88ee1 Stauros Kroustouris
    });
81 6de88ee1 Stauros Kroustouris
    $('a.show-propose-change').live("click", function(event) {
82 6de88ee1 Stauros Kroustouris
      event.preventDefault();
83 6de88ee1 Stauros Kroustouris
      showProposeChange($(this).attr('id').substring(2));
84 6de88ee1 Stauros Kroustouris
    });
85 6de88ee1 Stauros Kroustouris
    $('a.hide-propose-change').live("click", function(event) {
86 6de88ee1 Stauros Kroustouris
      event.preventDefault();
87 6de88ee1 Stauros Kroustouris
      hideProposeChange($(this).attr('id').substring(2));
88 6de88ee1 Stauros Kroustouris
    });
89 6de88ee1 Stauros Kroustouris
    $('a.accept-comment').live("click", function(event) {
90 6de88ee1 Stauros Kroustouris
      event.preventDefault();
91 6de88ee1 Stauros Kroustouris
      acceptComment($(this).attr('id').substring(2));
92 6de88ee1 Stauros Kroustouris
    });
93 6de88ee1 Stauros Kroustouris
    $('a.delete-comment').live("click", function(event) {
94 6de88ee1 Stauros Kroustouris
      event.preventDefault();
95 6de88ee1 Stauros Kroustouris
      deleteComment($(this).attr('id').substring(2));
96 6de88ee1 Stauros Kroustouris
    });
97 6de88ee1 Stauros Kroustouris
    $('a.comment-markup').live("click", function(event) {
98 6de88ee1 Stauros Kroustouris
      event.preventDefault();
99 6de88ee1 Stauros Kroustouris
      toggleCommentMarkupBox($(this).attr('id').substring(2));
100 6de88ee1 Stauros Kroustouris
    });
101 6de88ee1 Stauros Kroustouris
  }
102 6de88ee1 Stauros Kroustouris
103 6de88ee1 Stauros Kroustouris
  /**
104 6de88ee1 Stauros Kroustouris
   * Set comp, which is a comparator function used for sorting and
105 6de88ee1 Stauros Kroustouris
   * inserting comments into the list.
106 6de88ee1 Stauros Kroustouris
   */
107 6de88ee1 Stauros Kroustouris
  function setComparator() {
108 6de88ee1 Stauros Kroustouris
    // If the first three letters are "asc", sort in ascending order
109 6de88ee1 Stauros Kroustouris
    // and remove the prefix.
110 6de88ee1 Stauros Kroustouris
    if (by.substring(0,3) == 'asc') {
111 6de88ee1 Stauros Kroustouris
      var i = by.substring(3);
112 6de88ee1 Stauros Kroustouris
      comp = function(a, b) { return a[i] - b[i]; };
113 6de88ee1 Stauros Kroustouris
    } else {
114 6de88ee1 Stauros Kroustouris
      // Otherwise sort in descending order.
115 6de88ee1 Stauros Kroustouris
      comp = function(a, b) { return b[by] - a[by]; };
116 6de88ee1 Stauros Kroustouris
    }
117 6de88ee1 Stauros Kroustouris
118 6de88ee1 Stauros Kroustouris
    // Reset link styles and format the selected sort option.
119 6de88ee1 Stauros Kroustouris
    $('a.sel').attr('href', '#').removeClass('sel');
120 6de88ee1 Stauros Kroustouris
    $('a.by' + by).removeAttr('href').addClass('sel');
121 6de88ee1 Stauros Kroustouris
  }
122 6de88ee1 Stauros Kroustouris
123 6de88ee1 Stauros Kroustouris
  /**
124 6de88ee1 Stauros Kroustouris
   * Create a comp function. If the user has preferences stored in
125 6de88ee1 Stauros Kroustouris
   * the sortBy cookie, use those, otherwise use the default.
126 6de88ee1 Stauros Kroustouris
   */
127 6de88ee1 Stauros Kroustouris
  function initComparator() {
128 6de88ee1 Stauros Kroustouris
    by = 'rating'; // Default to sort by rating.
129 6de88ee1 Stauros Kroustouris
    // If the sortBy cookie is set, use that instead.
130 6de88ee1 Stauros Kroustouris
    if (document.cookie.length > 0) {
131 6de88ee1 Stauros Kroustouris
      var start = document.cookie.indexOf('sortBy=');
132 6de88ee1 Stauros Kroustouris
      if (start != -1) {
133 6de88ee1 Stauros Kroustouris
        start = start + 7;
134 6de88ee1 Stauros Kroustouris
        var end = document.cookie.indexOf(";", start);
135 6de88ee1 Stauros Kroustouris
        if (end == -1) {
136 6de88ee1 Stauros Kroustouris
          end = document.cookie.length;
137 6de88ee1 Stauros Kroustouris
          by = unescape(document.cookie.substring(start, end));
138 6de88ee1 Stauros Kroustouris
        }
139 6de88ee1 Stauros Kroustouris
      }
140 6de88ee1 Stauros Kroustouris
    }
141 6de88ee1 Stauros Kroustouris
    setComparator();
142 6de88ee1 Stauros Kroustouris
  }
143 6de88ee1 Stauros Kroustouris
144 6de88ee1 Stauros Kroustouris
  /**
145 6de88ee1 Stauros Kroustouris
   * Show a comment div.
146 6de88ee1 Stauros Kroustouris
   */
147 6de88ee1 Stauros Kroustouris
  function show(id) {
148 6de88ee1 Stauros Kroustouris
    $('#ao' + id).hide();
149 6de88ee1 Stauros Kroustouris
    $('#ah' + id).show();
150 6de88ee1 Stauros Kroustouris
    var context = $.extend({id: id}, opts);
151 6de88ee1 Stauros Kroustouris
    var popup = $(renderTemplate(popupTemplate, context)).hide();
152 6de88ee1 Stauros Kroustouris
    popup.find('textarea[name="proposal"]').hide();
153 6de88ee1 Stauros Kroustouris
    popup.find('a.by' + by).addClass('sel');
154 6de88ee1 Stauros Kroustouris
    var form = popup.find('#cf' + id);
155 6de88ee1 Stauros Kroustouris
    form.submit(function(event) {
156 6de88ee1 Stauros Kroustouris
      event.preventDefault();
157 6de88ee1 Stauros Kroustouris
      addComment(form);
158 6de88ee1 Stauros Kroustouris
    });
159 6de88ee1 Stauros Kroustouris
    $('#s' + id).after(popup);
160 6de88ee1 Stauros Kroustouris
    popup.slideDown('fast', function() {
161 6de88ee1 Stauros Kroustouris
      getComments(id);
162 6de88ee1 Stauros Kroustouris
    });
163 6de88ee1 Stauros Kroustouris
  }
164 6de88ee1 Stauros Kroustouris
165 6de88ee1 Stauros Kroustouris
  /**
166 6de88ee1 Stauros Kroustouris
   * Hide a comment div.
167 6de88ee1 Stauros Kroustouris
   */
168 6de88ee1 Stauros Kroustouris
  function hide(id) {
169 6de88ee1 Stauros Kroustouris
    $('#ah' + id).hide();
170 6de88ee1 Stauros Kroustouris
    $('#ao' + id).show();
171 6de88ee1 Stauros Kroustouris
    var div = $('#sc' + id);
172 6de88ee1 Stauros Kroustouris
    div.slideUp('fast', function() {
173 6de88ee1 Stauros Kroustouris
      div.remove();
174 6de88ee1 Stauros Kroustouris
    });
175 6de88ee1 Stauros Kroustouris
  }
176 6de88ee1 Stauros Kroustouris
177 6de88ee1 Stauros Kroustouris
  /**
178 6de88ee1 Stauros Kroustouris
   * Perform an ajax request to get comments for a node
179 6de88ee1 Stauros Kroustouris
   * and insert the comments into the comments tree.
180 6de88ee1 Stauros Kroustouris
   */
181 6de88ee1 Stauros Kroustouris
  function getComments(id) {
182 6de88ee1 Stauros Kroustouris
    $.ajax({
183 6de88ee1 Stauros Kroustouris
     type: 'GET',
184 6de88ee1 Stauros Kroustouris
     url: opts.getCommentsURL,
185 6de88ee1 Stauros Kroustouris
     data: {node: id},
186 6de88ee1 Stauros Kroustouris
     success: function(data, textStatus, request) {
187 6de88ee1 Stauros Kroustouris
       var ul = $('#cl' + id);
188 6de88ee1 Stauros Kroustouris
       var speed = 100;
189 6de88ee1 Stauros Kroustouris
       $('#cf' + id)
190 6de88ee1 Stauros Kroustouris
         .find('textarea[name="proposal"]')
191 6de88ee1 Stauros Kroustouris
         .data('source', data.source);
192 6de88ee1 Stauros Kroustouris
193 6de88ee1 Stauros Kroustouris
       if (data.comments.length === 0) {
194 6de88ee1 Stauros Kroustouris
         ul.html('<li>No comments yet.</li>');
195 6de88ee1 Stauros Kroustouris
         ul.data('empty', true);
196 6de88ee1 Stauros Kroustouris
       } else {
197 6de88ee1 Stauros Kroustouris
         // If there are comments, sort them and put them in the list.
198 6de88ee1 Stauros Kroustouris
         var comments = sortComments(data.comments);
199 6de88ee1 Stauros Kroustouris
         speed = data.comments.length * 100;
200 6de88ee1 Stauros Kroustouris
         appendComments(comments, ul);
201 6de88ee1 Stauros Kroustouris
         ul.data('empty', false);
202 6de88ee1 Stauros Kroustouris
       }
203 6de88ee1 Stauros Kroustouris
       $('#cn' + id).slideUp(speed + 200);
204 6de88ee1 Stauros Kroustouris
       ul.slideDown(speed);
205 6de88ee1 Stauros Kroustouris
     },
206 6de88ee1 Stauros Kroustouris
     error: function(request, textStatus, error) {
207 6de88ee1 Stauros Kroustouris
       showError('Oops, there was a problem retrieving the comments.');
208 6de88ee1 Stauros Kroustouris
     },
209 6de88ee1 Stauros Kroustouris
     dataType: 'json'
210 6de88ee1 Stauros Kroustouris
    });
211 6de88ee1 Stauros Kroustouris
  }
212 6de88ee1 Stauros Kroustouris
213 6de88ee1 Stauros Kroustouris
  /**
214 6de88ee1 Stauros Kroustouris
   * Add a comment via ajax and insert the comment into the comment tree.
215 6de88ee1 Stauros Kroustouris
   */
216 6de88ee1 Stauros Kroustouris
  function addComment(form) {
217 6de88ee1 Stauros Kroustouris
    var node_id = form.find('input[name="node"]').val();
218 6de88ee1 Stauros Kroustouris
    var parent_id = form.find('input[name="parent"]').val();
219 6de88ee1 Stauros Kroustouris
    var text = form.find('textarea[name="comment"]').val();
220 6de88ee1 Stauros Kroustouris
    var proposal = form.find('textarea[name="proposal"]').val();
221 6de88ee1 Stauros Kroustouris
222 6de88ee1 Stauros Kroustouris
    if (text == '') {
223 6de88ee1 Stauros Kroustouris
      showError('Please enter a comment.');
224 6de88ee1 Stauros Kroustouris
      return;
225 6de88ee1 Stauros Kroustouris
    }
226 6de88ee1 Stauros Kroustouris
227 6de88ee1 Stauros Kroustouris
    // Disable the form that is being submitted.
228 6de88ee1 Stauros Kroustouris
    form.find('textarea,input').attr('disabled', 'disabled');
229 6de88ee1 Stauros Kroustouris
230 6de88ee1 Stauros Kroustouris
    // Send the comment to the server.
231 6de88ee1 Stauros Kroustouris
    $.ajax({
232 6de88ee1 Stauros Kroustouris
      type: "POST",
233 6de88ee1 Stauros Kroustouris
      url: opts.addCommentURL,
234 6de88ee1 Stauros Kroustouris
      dataType: 'json',
235 6de88ee1 Stauros Kroustouris
      data: {
236 6de88ee1 Stauros Kroustouris
        node: node_id,
237 6de88ee1 Stauros Kroustouris
        parent: parent_id,
238 6de88ee1 Stauros Kroustouris
        text: text,
239 6de88ee1 Stauros Kroustouris
        proposal: proposal
240 6de88ee1 Stauros Kroustouris
      },
241 6de88ee1 Stauros Kroustouris
      success: function(data, textStatus, error) {
242 6de88ee1 Stauros Kroustouris
        // Reset the form.
243 6de88ee1 Stauros Kroustouris
        if (node_id) {
244 6de88ee1 Stauros Kroustouris
          hideProposeChange(node_id);
245 6de88ee1 Stauros Kroustouris
        }
246 6de88ee1 Stauros Kroustouris
        form.find('textarea')
247 6de88ee1 Stauros Kroustouris
          .val('')
248 6de88ee1 Stauros Kroustouris
          .add(form.find('input'))
249 6de88ee1 Stauros Kroustouris
          .removeAttr('disabled');
250 6de88ee1 Stauros Kroustouris
        var ul = $('#cl' + (node_id || parent_id));
251 6de88ee1 Stauros Kroustouris
        if (ul.data('empty')) {
252 6de88ee1 Stauros Kroustouris
          $(ul).empty();
253 6de88ee1 Stauros Kroustouris
          ul.data('empty', false);
254 6de88ee1 Stauros Kroustouris
        }
255 6de88ee1 Stauros Kroustouris
        insertComment(data.comment);
256 6de88ee1 Stauros Kroustouris
        var ao = $('#ao' + node_id);
257 6de88ee1 Stauros Kroustouris
        ao.find('img').attr({'src': opts.commentBrightImage});
258 6de88ee1 Stauros Kroustouris
        if (node_id) {
259 6de88ee1 Stauros Kroustouris
          // if this was a "root" comment, remove the commenting box
260 6de88ee1 Stauros Kroustouris
          // (the user can get it back by reopening the comment popup)
261 6de88ee1 Stauros Kroustouris
          $('#ca' + node_id).slideUp();
262 6de88ee1 Stauros Kroustouris
        }
263 6de88ee1 Stauros Kroustouris
      },
264 6de88ee1 Stauros Kroustouris
      error: function(request, textStatus, error) {
265 6de88ee1 Stauros Kroustouris
        form.find('textarea,input').removeAttr('disabled');
266 6de88ee1 Stauros Kroustouris
        showError('Oops, there was a problem adding the comment.');
267 6de88ee1 Stauros Kroustouris
      }
268 6de88ee1 Stauros Kroustouris
    });
269 6de88ee1 Stauros Kroustouris
  }
270 6de88ee1 Stauros Kroustouris
271 6de88ee1 Stauros Kroustouris
  /**
272 6de88ee1 Stauros Kroustouris
   * Recursively append comments to the main comment list and children
273 6de88ee1 Stauros Kroustouris
   * lists, creating the comment tree.
274 6de88ee1 Stauros Kroustouris
   */
275 6de88ee1 Stauros Kroustouris
  function appendComments(comments, ul) {
276 6de88ee1 Stauros Kroustouris
    $.each(comments, function() {
277 6de88ee1 Stauros Kroustouris
      var div = createCommentDiv(this);
278 6de88ee1 Stauros Kroustouris
      ul.append($(document.createElement('li')).html(div));
279 6de88ee1 Stauros Kroustouris
      appendComments(this.children, div.find('ul.comment-children'));
280 6de88ee1 Stauros Kroustouris
      // To avoid stagnating data, don't store the comments children in data.
281 6de88ee1 Stauros Kroustouris
      this.children = null;
282 6de88ee1 Stauros Kroustouris
      div.data('comment', this);
283 6de88ee1 Stauros Kroustouris
    });
284 6de88ee1 Stauros Kroustouris
  }
285 6de88ee1 Stauros Kroustouris
286 6de88ee1 Stauros Kroustouris
  /**
287 6de88ee1 Stauros Kroustouris
   * After adding a new comment, it must be inserted in the correct
288 6de88ee1 Stauros Kroustouris
   * location in the comment tree.
289 6de88ee1 Stauros Kroustouris
   */
290 6de88ee1 Stauros Kroustouris
  function insertComment(comment) {
291 6de88ee1 Stauros Kroustouris
    var div = createCommentDiv(comment);
292 6de88ee1 Stauros Kroustouris
293 6de88ee1 Stauros Kroustouris
    // To avoid stagnating data, don't store the comments children in data.
294 6de88ee1 Stauros Kroustouris
    comment.children = null;
295 6de88ee1 Stauros Kroustouris
    div.data('comment', comment);
296 6de88ee1 Stauros Kroustouris
297 6de88ee1 Stauros Kroustouris
    var ul = $('#cl' + (comment.node || comment.parent));
298 6de88ee1 Stauros Kroustouris
    var siblings = getChildren(ul);
299 6de88ee1 Stauros Kroustouris
300 6de88ee1 Stauros Kroustouris
    var li = $(document.createElement('li'));
301 6de88ee1 Stauros Kroustouris
    li.hide();
302 6de88ee1 Stauros Kroustouris
303 6de88ee1 Stauros Kroustouris
    // Determine where in the parents children list to insert this comment.
304 6de88ee1 Stauros Kroustouris
    for(i=0; i < siblings.length; i++) {
305 6de88ee1 Stauros Kroustouris
      if (comp(comment, siblings[i]) <= 0) {
306 6de88ee1 Stauros Kroustouris
        $('#cd' + siblings[i].id)
307 6de88ee1 Stauros Kroustouris
          .parent()
308 6de88ee1 Stauros Kroustouris
          .before(li.html(div));
309 6de88ee1 Stauros Kroustouris
        li.slideDown('fast');
310 6de88ee1 Stauros Kroustouris
        return;
311 6de88ee1 Stauros Kroustouris
      }
312 6de88ee1 Stauros Kroustouris
    }
313 6de88ee1 Stauros Kroustouris
314 6de88ee1 Stauros Kroustouris
    // If we get here, this comment rates lower than all the others,
315 6de88ee1 Stauros Kroustouris
    // or it is the only comment in the list.
316 6de88ee1 Stauros Kroustouris
    ul.append(li.html(div));
317 6de88ee1 Stauros Kroustouris
    li.slideDown('fast');
318 6de88ee1 Stauros Kroustouris
  }
319 6de88ee1 Stauros Kroustouris
320 6de88ee1 Stauros Kroustouris
  function acceptComment(id) {
321 6de88ee1 Stauros Kroustouris
    $.ajax({
322 6de88ee1 Stauros Kroustouris
      type: 'POST',
323 6de88ee1 Stauros Kroustouris
      url: opts.acceptCommentURL,
324 6de88ee1 Stauros Kroustouris
      data: {id: id},
325 6de88ee1 Stauros Kroustouris
      success: function(data, textStatus, request) {
326 6de88ee1 Stauros Kroustouris
        $('#cm' + id).fadeOut('fast');
327 6de88ee1 Stauros Kroustouris
        $('#cd' + id).removeClass('moderate');
328 6de88ee1 Stauros Kroustouris
      },
329 6de88ee1 Stauros Kroustouris
      error: function(request, textStatus, error) {
330 6de88ee1 Stauros Kroustouris
        showError('Oops, there was a problem accepting the comment.');
331 6de88ee1 Stauros Kroustouris
      }
332 6de88ee1 Stauros Kroustouris
    });
333 6de88ee1 Stauros Kroustouris
  }
334 6de88ee1 Stauros Kroustouris
335 6de88ee1 Stauros Kroustouris
  function deleteComment(id) {
336 6de88ee1 Stauros Kroustouris
    $.ajax({
337 6de88ee1 Stauros Kroustouris
      type: 'POST',
338 6de88ee1 Stauros Kroustouris
      url: opts.deleteCommentURL,
339 6de88ee1 Stauros Kroustouris
      data: {id: id},
340 6de88ee1 Stauros Kroustouris
      success: function(data, textStatus, request) {
341 6de88ee1 Stauros Kroustouris
        var div = $('#cd' + id);
342 6de88ee1 Stauros Kroustouris
        if (data == 'delete') {
343 6de88ee1 Stauros Kroustouris
          // Moderator mode: remove the comment and all children immediately
344 6de88ee1 Stauros Kroustouris
          div.slideUp('fast', function() {
345 6de88ee1 Stauros Kroustouris
            div.remove();
346 6de88ee1 Stauros Kroustouris
          });
347 6de88ee1 Stauros Kroustouris
          return;
348 6de88ee1 Stauros Kroustouris
        }
349 6de88ee1 Stauros Kroustouris
        // User mode: only mark the comment as deleted
350 6de88ee1 Stauros Kroustouris
        div
351 6de88ee1 Stauros Kroustouris
          .find('span.user-id:first')
352 6de88ee1 Stauros Kroustouris
          .text('[deleted]').end()
353 6de88ee1 Stauros Kroustouris
          .find('div.comment-text:first')
354 6de88ee1 Stauros Kroustouris
          .text('[deleted]').end()
355 6de88ee1 Stauros Kroustouris
          .find('#cm' + id + ', #dc' + id + ', #ac' + id + ', #rc' + id +
356 6de88ee1 Stauros Kroustouris
                ', #sp' + id + ', #hp' + id + ', #cr' + id + ', #rl' + id)
357 6de88ee1 Stauros Kroustouris
          .remove();
358 6de88ee1 Stauros Kroustouris
        var comment = div.data('comment');
359 6de88ee1 Stauros Kroustouris
        comment.username = '[deleted]';
360 6de88ee1 Stauros Kroustouris
        comment.text = '[deleted]';
361 6de88ee1 Stauros Kroustouris
        div.data('comment', comment);
362 6de88ee1 Stauros Kroustouris
      },
363 6de88ee1 Stauros Kroustouris
      error: function(request, textStatus, error) {
364 6de88ee1 Stauros Kroustouris
        showError('Oops, there was a problem deleting the comment.');
365 6de88ee1 Stauros Kroustouris
      }
366 6de88ee1 Stauros Kroustouris
    });
367 6de88ee1 Stauros Kroustouris
  }
368 6de88ee1 Stauros Kroustouris
369 6de88ee1 Stauros Kroustouris
  function showProposal(id) {
370 6de88ee1 Stauros Kroustouris
    $('#sp' + id).hide();
371 6de88ee1 Stauros Kroustouris
    $('#hp' + id).show();
372 6de88ee1 Stauros Kroustouris
    $('#pr' + id).slideDown('fast');
373 6de88ee1 Stauros Kroustouris
  }
374 6de88ee1 Stauros Kroustouris
375 6de88ee1 Stauros Kroustouris
  function hideProposal(id) {
376 6de88ee1 Stauros Kroustouris
    $('#hp' + id).hide();
377 6de88ee1 Stauros Kroustouris
    $('#sp' + id).show();
378 6de88ee1 Stauros Kroustouris
    $('#pr' + id).slideUp('fast');
379 6de88ee1 Stauros Kroustouris
  }
380 6de88ee1 Stauros Kroustouris
381 6de88ee1 Stauros Kroustouris
  function showProposeChange(id) {
382 6de88ee1 Stauros Kroustouris
    $('#pc' + id).hide();
383 6de88ee1 Stauros Kroustouris
    $('#hc' + id).show();
384 6de88ee1 Stauros Kroustouris
    var textarea = $('#pt' + id);
385 6de88ee1 Stauros Kroustouris
    textarea.val(textarea.data('source'));
386 6de88ee1 Stauros Kroustouris
    $.fn.autogrow.resize(textarea[0]);
387 6de88ee1 Stauros Kroustouris
    textarea.slideDown('fast');
388 6de88ee1 Stauros Kroustouris
  }
389 6de88ee1 Stauros Kroustouris
390 6de88ee1 Stauros Kroustouris
  function hideProposeChange(id) {
391 6de88ee1 Stauros Kroustouris
    $('#hc' + id).hide();
392 6de88ee1 Stauros Kroustouris
    $('#pc' + id).show();
393 6de88ee1 Stauros Kroustouris
    var textarea = $('#pt' + id);
394 6de88ee1 Stauros Kroustouris
    textarea.val('').removeAttr('disabled');
395 6de88ee1 Stauros Kroustouris
    textarea.slideUp('fast');
396 6de88ee1 Stauros Kroustouris
  }
397 6de88ee1 Stauros Kroustouris
398 6de88ee1 Stauros Kroustouris
  function toggleCommentMarkupBox(id) {
399 6de88ee1 Stauros Kroustouris
    $('#mb' + id).toggle();
400 6de88ee1 Stauros Kroustouris
  }
401 6de88ee1 Stauros Kroustouris
402 6de88ee1 Stauros Kroustouris
  /** Handle when the user clicks on a sort by link. */
403 6de88ee1 Stauros Kroustouris
  function handleReSort(link) {
404 6de88ee1 Stauros Kroustouris
    var classes = link.attr('class').split(/\s+/);
405 6de88ee1 Stauros Kroustouris
    for (var i=0; i<classes.length; i++) {
406 6de88ee1 Stauros Kroustouris
      if (classes[i] != 'sort-option') {
407 6de88ee1 Stauros Kroustouris
        by = classes[i].substring(2);
408 6de88ee1 Stauros Kroustouris
      }
409 6de88ee1 Stauros Kroustouris
    }
410 6de88ee1 Stauros Kroustouris
    setComparator();
411 6de88ee1 Stauros Kroustouris
    // Save/update the sortBy cookie.
412 6de88ee1 Stauros Kroustouris
    var expiration = new Date();
413 6de88ee1 Stauros Kroustouris
    expiration.setDate(expiration.getDate() + 365);
414 6de88ee1 Stauros Kroustouris
    document.cookie= 'sortBy=' + escape(by) +
415 6de88ee1 Stauros Kroustouris
                     ';expires=' + expiration.toUTCString();
416 6de88ee1 Stauros Kroustouris
    $('ul.comment-ul').each(function(index, ul) {
417 6de88ee1 Stauros Kroustouris
      var comments = getChildren($(ul), true);
418 6de88ee1 Stauros Kroustouris
      comments = sortComments(comments);
419 6de88ee1 Stauros Kroustouris
      appendComments(comments, $(ul).empty());
420 6de88ee1 Stauros Kroustouris
    });
421 6de88ee1 Stauros Kroustouris
  }
422 6de88ee1 Stauros Kroustouris
423 6de88ee1 Stauros Kroustouris
  /**
424 6de88ee1 Stauros Kroustouris
   * Function to process a vote when a user clicks an arrow.
425 6de88ee1 Stauros Kroustouris
   */
426 6de88ee1 Stauros Kroustouris
  function handleVote(link) {
427 6de88ee1 Stauros Kroustouris
    if (!opts.voting) {
428 6de88ee1 Stauros Kroustouris
      showError("You'll need to login to vote.");
429 6de88ee1 Stauros Kroustouris
      return;
430 6de88ee1 Stauros Kroustouris
    }
431 6de88ee1 Stauros Kroustouris
432 6de88ee1 Stauros Kroustouris
    var id = link.attr('id');
433 6de88ee1 Stauros Kroustouris
    if (!id) {
434 6de88ee1 Stauros Kroustouris
      // Didn't click on one of the voting arrows.
435 6de88ee1 Stauros Kroustouris
      return;
436 6de88ee1 Stauros Kroustouris
    }
437 6de88ee1 Stauros Kroustouris
    // If it is an unvote, the new vote value is 0,
438 6de88ee1 Stauros Kroustouris
    // Otherwise it's 1 for an upvote, or -1 for a downvote.
439 6de88ee1 Stauros Kroustouris
    var value = 0;
440 6de88ee1 Stauros Kroustouris
    if (id.charAt(1) != 'u') {
441 6de88ee1 Stauros Kroustouris
      value = id.charAt(0) == 'u' ? 1 : -1;
442 6de88ee1 Stauros Kroustouris
    }
443 6de88ee1 Stauros Kroustouris
    // The data to be sent to the server.
444 6de88ee1 Stauros Kroustouris
    var d = {
445 6de88ee1 Stauros Kroustouris
      comment_id: id.substring(2),
446 6de88ee1 Stauros Kroustouris
      value: value
447 6de88ee1 Stauros Kroustouris
    };
448 6de88ee1 Stauros Kroustouris
449 6de88ee1 Stauros Kroustouris
    // Swap the vote and unvote links.
450 6de88ee1 Stauros Kroustouris
    link.hide();
451 6de88ee1 Stauros Kroustouris
    $('#' + id.charAt(0) + (id.charAt(1) == 'u' ? 'v' : 'u') + d.comment_id)
452 6de88ee1 Stauros Kroustouris
      .show();
453 6de88ee1 Stauros Kroustouris
454 6de88ee1 Stauros Kroustouris
    // The div the comment is displayed in.
455 6de88ee1 Stauros Kroustouris
    var div = $('div#cd' + d.comment_id);
456 6de88ee1 Stauros Kroustouris
    var data = div.data('comment');
457 6de88ee1 Stauros Kroustouris
458 6de88ee1 Stauros Kroustouris
    // If this is not an unvote, and the other vote arrow has
459 6de88ee1 Stauros Kroustouris
    // already been pressed, unpress it.
460 6de88ee1 Stauros Kroustouris
    if ((d.value !== 0) && (data.vote === d.value * -1)) {
461 6de88ee1 Stauros Kroustouris
      $('#' + (d.value == 1 ? 'd' : 'u') + 'u' + d.comment_id).hide();
462 6de88ee1 Stauros Kroustouris
      $('#' + (d.value == 1 ? 'd' : 'u') + 'v' + d.comment_id).show();
463 6de88ee1 Stauros Kroustouris
    }
464 6de88ee1 Stauros Kroustouris
465 6de88ee1 Stauros Kroustouris
    // Update the comments rating in the local data.
466 6de88ee1 Stauros Kroustouris
    data.rating += (data.vote === 0) ? d.value : (d.value - data.vote);
467 6de88ee1 Stauros Kroustouris
    data.vote = d.value;
468 6de88ee1 Stauros Kroustouris
    div.data('comment', data);
469 6de88ee1 Stauros Kroustouris
470 6de88ee1 Stauros Kroustouris
    // Change the rating text.
471 6de88ee1 Stauros Kroustouris
    div.find('.rating:first')
472 6de88ee1 Stauros Kroustouris
      .text(data.rating + ' point' + (data.rating == 1 ? '' : 's'));
473 6de88ee1 Stauros Kroustouris
474 6de88ee1 Stauros Kroustouris
    // Send the vote information to the server.
475 6de88ee1 Stauros Kroustouris
    $.ajax({
476 6de88ee1 Stauros Kroustouris
      type: "POST",
477 6de88ee1 Stauros Kroustouris
      url: opts.processVoteURL,
478 6de88ee1 Stauros Kroustouris
      data: d,
479 6de88ee1 Stauros Kroustouris
      error: function(request, textStatus, error) {
480 6de88ee1 Stauros Kroustouris
        showError('Oops, there was a problem casting that vote.');
481 6de88ee1 Stauros Kroustouris
      }
482 6de88ee1 Stauros Kroustouris
    });
483 6de88ee1 Stauros Kroustouris
  }
484 6de88ee1 Stauros Kroustouris
485 6de88ee1 Stauros Kroustouris
  /**
486 6de88ee1 Stauros Kroustouris
   * Open a reply form used to reply to an existing comment.
487 6de88ee1 Stauros Kroustouris
   */
488 6de88ee1 Stauros Kroustouris
  function openReply(id) {
489 6de88ee1 Stauros Kroustouris
    // Swap out the reply link for the hide link
490 6de88ee1 Stauros Kroustouris
    $('#rl' + id).hide();
491 6de88ee1 Stauros Kroustouris
    $('#cr' + id).show();
492 6de88ee1 Stauros Kroustouris
493 6de88ee1 Stauros Kroustouris
    // Add the reply li to the children ul.
494 6de88ee1 Stauros Kroustouris
    var div = $(renderTemplate(replyTemplate, {id: id})).hide();
495 6de88ee1 Stauros Kroustouris
    $('#cl' + id)
496 6de88ee1 Stauros Kroustouris
      .prepend(div)
497 6de88ee1 Stauros Kroustouris
      // Setup the submit handler for the reply form.
498 6de88ee1 Stauros Kroustouris
      .find('#rf' + id)
499 6de88ee1 Stauros Kroustouris
      .submit(function(event) {
500 6de88ee1 Stauros Kroustouris
        event.preventDefault();
501 6de88ee1 Stauros Kroustouris
        addComment($('#rf' + id));
502 6de88ee1 Stauros Kroustouris
        closeReply(id);
503 6de88ee1 Stauros Kroustouris
      })
504 6de88ee1 Stauros Kroustouris
      .find('input[type=button]')
505 6de88ee1 Stauros Kroustouris
      .click(function() {
506 6de88ee1 Stauros Kroustouris
        closeReply(id);
507 6de88ee1 Stauros Kroustouris
      });
508 6de88ee1 Stauros Kroustouris
    div.slideDown('fast', function() {
509 6de88ee1 Stauros Kroustouris
      $('#rf' + id).find('textarea').focus();
510 6de88ee1 Stauros Kroustouris
    });
511 6de88ee1 Stauros Kroustouris
  }
512 6de88ee1 Stauros Kroustouris
513 6de88ee1 Stauros Kroustouris
  /**
514 6de88ee1 Stauros Kroustouris
   * Close the reply form opened with openReply.
515 6de88ee1 Stauros Kroustouris
   */
516 6de88ee1 Stauros Kroustouris
  function closeReply(id) {
517 6de88ee1 Stauros Kroustouris
    // Remove the reply div from the DOM.
518 6de88ee1 Stauros Kroustouris
    $('#rd' + id).slideUp('fast', function() {
519 6de88ee1 Stauros Kroustouris
      $(this).remove();
520 6de88ee1 Stauros Kroustouris
    });
521 6de88ee1 Stauros Kroustouris
522 6de88ee1 Stauros Kroustouris
    // Swap out the hide link for the reply link
523 6de88ee1 Stauros Kroustouris
    $('#cr' + id).hide();
524 6de88ee1 Stauros Kroustouris
    $('#rl' + id).show();
525 6de88ee1 Stauros Kroustouris
  }
526 6de88ee1 Stauros Kroustouris
527 6de88ee1 Stauros Kroustouris
  /**
528 6de88ee1 Stauros Kroustouris
   * Recursively sort a tree of comments using the comp comparator.
529 6de88ee1 Stauros Kroustouris
   */
530 6de88ee1 Stauros Kroustouris
  function sortComments(comments) {
531 6de88ee1 Stauros Kroustouris
    comments.sort(comp);
532 6de88ee1 Stauros Kroustouris
    $.each(comments, function() {
533 6de88ee1 Stauros Kroustouris
      this.children = sortComments(this.children);
534 6de88ee1 Stauros Kroustouris
    });
535 6de88ee1 Stauros Kroustouris
    return comments;
536 6de88ee1 Stauros Kroustouris
  }
537 6de88ee1 Stauros Kroustouris
538 6de88ee1 Stauros Kroustouris
  /**
539 6de88ee1 Stauros Kroustouris
   * Get the children comments from a ul. If recursive is true,
540 6de88ee1 Stauros Kroustouris
   * recursively include childrens' children.
541 6de88ee1 Stauros Kroustouris
   */
542 6de88ee1 Stauros Kroustouris
  function getChildren(ul, recursive) {
543 6de88ee1 Stauros Kroustouris
    var children = [];
544 6de88ee1 Stauros Kroustouris
    ul.children().children("[id^='cd']")
545 6de88ee1 Stauros Kroustouris
      .each(function() {
546 6de88ee1 Stauros Kroustouris
        var comment = $(this).data('comment');
547 6de88ee1 Stauros Kroustouris
        if (recursive)
548 6de88ee1 Stauros Kroustouris
          comment.children = getChildren($(this).find('#cl' + comment.id), true);
549 6de88ee1 Stauros Kroustouris
        children.push(comment);
550 6de88ee1 Stauros Kroustouris
      });
551 6de88ee1 Stauros Kroustouris
    return children;
552 6de88ee1 Stauros Kroustouris
  }
553 6de88ee1 Stauros Kroustouris
554 6de88ee1 Stauros Kroustouris
  /** Create a div to display a comment in. */
555 6de88ee1 Stauros Kroustouris
  function createCommentDiv(comment) {
556 6de88ee1 Stauros Kroustouris
    if (!comment.displayed && !opts.moderator) {
557 6de88ee1 Stauros Kroustouris
      return $('<div class="moderate">Thank you!  Your comment will show up '
558 6de88ee1 Stauros Kroustouris
               + 'once it is has been approved by a moderator.</div>');
559 6de88ee1 Stauros Kroustouris
    }
560 6de88ee1 Stauros Kroustouris
    // Prettify the comment rating.
561 6de88ee1 Stauros Kroustouris
    comment.pretty_rating = comment.rating + ' point' +
562 6de88ee1 Stauros Kroustouris
      (comment.rating == 1 ? '' : 's');
563 6de88ee1 Stauros Kroustouris
    // Make a class (for displaying not yet moderated comments differently)
564 6de88ee1 Stauros Kroustouris
    comment.css_class = comment.displayed ? '' : ' moderate';
565 6de88ee1 Stauros Kroustouris
    // Create a div for this comment.
566 6de88ee1 Stauros Kroustouris
    var context = $.extend({}, opts, comment);
567 6de88ee1 Stauros Kroustouris
    var div = $(renderTemplate(commentTemplate, context));
568 6de88ee1 Stauros Kroustouris
569 6de88ee1 Stauros Kroustouris
    // If the user has voted on this comment, highlight the correct arrow.
570 6de88ee1 Stauros Kroustouris
    if (comment.vote) {
571 6de88ee1 Stauros Kroustouris
      var direction = (comment.vote == 1) ? 'u' : 'd';
572 6de88ee1 Stauros Kroustouris
      div.find('#' + direction + 'v' + comment.id).hide();
573 6de88ee1 Stauros Kroustouris
      div.find('#' + direction + 'u' + comment.id).show();
574 6de88ee1 Stauros Kroustouris
    }
575 6de88ee1 Stauros Kroustouris
576 6de88ee1 Stauros Kroustouris
    if (opts.moderator || comment.text != '[deleted]') {
577 6de88ee1 Stauros Kroustouris
      div.find('a.reply').show();
578 6de88ee1 Stauros Kroustouris
      if (comment.proposal_diff)
579 6de88ee1 Stauros Kroustouris
        div.find('#sp' + comment.id).show();
580 6de88ee1 Stauros Kroustouris
      if (opts.moderator && !comment.displayed)
581 6de88ee1 Stauros Kroustouris
        div.find('#cm' + comment.id).show();
582 6de88ee1 Stauros Kroustouris
      if (opts.moderator || (opts.username == comment.username))
583 6de88ee1 Stauros Kroustouris
        div.find('#dc' + comment.id).show();
584 6de88ee1 Stauros Kroustouris
    }
585 6de88ee1 Stauros Kroustouris
    return div;
586 6de88ee1 Stauros Kroustouris
  }
587 6de88ee1 Stauros Kroustouris
588 6de88ee1 Stauros Kroustouris
  /**
589 6de88ee1 Stauros Kroustouris
   * A simple template renderer. Placeholders such as <%id%> are replaced
590 6de88ee1 Stauros Kroustouris
   * by context['id'] with items being escaped. Placeholders such as <#id#>
591 6de88ee1 Stauros Kroustouris
   * are not escaped.
592 6de88ee1 Stauros Kroustouris
   */
593 6de88ee1 Stauros Kroustouris
  function renderTemplate(template, context) {
594 6de88ee1 Stauros Kroustouris
    var esc = $(document.createElement('div'));
595 6de88ee1 Stauros Kroustouris
596 6de88ee1 Stauros Kroustouris
    function handle(ph, escape) {
597 6de88ee1 Stauros Kroustouris
      var cur = context;
598 6de88ee1 Stauros Kroustouris
      $.each(ph.split('.'), function() {
599 6de88ee1 Stauros Kroustouris
        cur = cur[this];
600 6de88ee1 Stauros Kroustouris
      });
601 6de88ee1 Stauros Kroustouris
      return escape ? esc.text(cur || "").html() : cur;
602 6de88ee1 Stauros Kroustouris
    }
603 6de88ee1 Stauros Kroustouris
604 6de88ee1 Stauros Kroustouris
    return template.replace(/<([%#])([\w\.]*)\1>/g, function() {
605 6de88ee1 Stauros Kroustouris
      return handle(arguments[2], arguments[1] == '%' ? true : false);
606 6de88ee1 Stauros Kroustouris
    });
607 6de88ee1 Stauros Kroustouris
  }
608 6de88ee1 Stauros Kroustouris
609 6de88ee1 Stauros Kroustouris
  /** Flash an error message briefly. */
610 6de88ee1 Stauros Kroustouris
  function showError(message) {
611 6de88ee1 Stauros Kroustouris
    $(document.createElement('div')).attr({'class': 'popup-error'})
612 6de88ee1 Stauros Kroustouris
      .append($(document.createElement('div'))
613 6de88ee1 Stauros Kroustouris
               .attr({'class': 'error-message'}).text(message))
614 6de88ee1 Stauros Kroustouris
      .appendTo('body')
615 6de88ee1 Stauros Kroustouris
      .fadeIn("slow")
616 6de88ee1 Stauros Kroustouris
      .delay(2000)
617 6de88ee1 Stauros Kroustouris
      .fadeOut("slow");
618 6de88ee1 Stauros Kroustouris
  }
619 6de88ee1 Stauros Kroustouris
620 6de88ee1 Stauros Kroustouris
  /** Add a link the user uses to open the comments popup. */
621 6de88ee1 Stauros Kroustouris
  $.fn.comment = function() {
622 6de88ee1 Stauros Kroustouris
    return this.each(function() {
623 6de88ee1 Stauros Kroustouris
      var id = $(this).attr('id').substring(1);
624 6de88ee1 Stauros Kroustouris
      var count = COMMENT_METADATA[id];
625 6de88ee1 Stauros Kroustouris
      var title = count + ' comment' + (count == 1 ? '' : 's');
626 6de88ee1 Stauros Kroustouris
      var image = count > 0 ? opts.commentBrightImage : opts.commentImage;
627 6de88ee1 Stauros Kroustouris
      var addcls = count == 0 ? ' nocomment' : '';
628 6de88ee1 Stauros Kroustouris
      $(this)
629 6de88ee1 Stauros Kroustouris
        .append(
630 6de88ee1 Stauros Kroustouris
          $(document.createElement('a')).attr({
631 6de88ee1 Stauros Kroustouris
            href: '#',
632 6de88ee1 Stauros Kroustouris
            'class': 'sphinx-comment-open' + addcls,
633 6de88ee1 Stauros Kroustouris
            id: 'ao' + id
634 6de88ee1 Stauros Kroustouris
          })
635 6de88ee1 Stauros Kroustouris
            .append($(document.createElement('img')).attr({
636 6de88ee1 Stauros Kroustouris
              src: image,
637 6de88ee1 Stauros Kroustouris
              alt: 'comment',
638 6de88ee1 Stauros Kroustouris
              title: title
639 6de88ee1 Stauros Kroustouris
            }))
640 6de88ee1 Stauros Kroustouris
            .click(function(event) {
641 6de88ee1 Stauros Kroustouris
              event.preventDefault();
642 6de88ee1 Stauros Kroustouris
              show($(this).attr('id').substring(2));
643 6de88ee1 Stauros Kroustouris
            })
644 6de88ee1 Stauros Kroustouris
        )
645 6de88ee1 Stauros Kroustouris
        .append(
646 6de88ee1 Stauros Kroustouris
          $(document.createElement('a')).attr({
647 6de88ee1 Stauros Kroustouris
            href: '#',
648 6de88ee1 Stauros Kroustouris
            'class': 'sphinx-comment-close hidden',
649 6de88ee1 Stauros Kroustouris
            id: 'ah' + id
650 6de88ee1 Stauros Kroustouris
          })
651 6de88ee1 Stauros Kroustouris
            .append($(document.createElement('img')).attr({
652 6de88ee1 Stauros Kroustouris
              src: opts.closeCommentImage,
653 6de88ee1 Stauros Kroustouris
              alt: 'close',
654 6de88ee1 Stauros Kroustouris
              title: 'close'
655 6de88ee1 Stauros Kroustouris
            }))
656 6de88ee1 Stauros Kroustouris
            .click(function(event) {
657 6de88ee1 Stauros Kroustouris
              event.preventDefault();
658 6de88ee1 Stauros Kroustouris
              hide($(this).attr('id').substring(2));
659 6de88ee1 Stauros Kroustouris
            })
660 6de88ee1 Stauros Kroustouris
        );
661 6de88ee1 Stauros Kroustouris
    });
662 6de88ee1 Stauros Kroustouris
  };
663 6de88ee1 Stauros Kroustouris
664 6de88ee1 Stauros Kroustouris
  var opts = {
665 6de88ee1 Stauros Kroustouris
    processVoteURL: '/_process_vote',
666 6de88ee1 Stauros Kroustouris
    addCommentURL: '/_add_comment',
667 6de88ee1 Stauros Kroustouris
    getCommentsURL: '/_get_comments',
668 6de88ee1 Stauros Kroustouris
    acceptCommentURL: '/_accept_comment',
669 6de88ee1 Stauros Kroustouris
    deleteCommentURL: '/_delete_comment',
670 6de88ee1 Stauros Kroustouris
    commentImage: '/static/_static/comment.png',
671 6de88ee1 Stauros Kroustouris
    closeCommentImage: '/static/_static/comment-close.png',
672 6de88ee1 Stauros Kroustouris
    loadingImage: '/static/_static/ajax-loader.gif',
673 6de88ee1 Stauros Kroustouris
    commentBrightImage: '/static/_static/comment-bright.png',
674 6de88ee1 Stauros Kroustouris
    upArrow: '/static/_static/up.png',
675 6de88ee1 Stauros Kroustouris
    downArrow: '/static/_static/down.png',
676 6de88ee1 Stauros Kroustouris
    upArrowPressed: '/static/_static/up-pressed.png',
677 6de88ee1 Stauros Kroustouris
    downArrowPressed: '/static/_static/down-pressed.png',
678 6de88ee1 Stauros Kroustouris
    voting: false,
679 6de88ee1 Stauros Kroustouris
    moderator: false
680 6de88ee1 Stauros Kroustouris
  };
681 6de88ee1 Stauros Kroustouris
682 6de88ee1 Stauros Kroustouris
  if (typeof COMMENT_OPTIONS != "undefined") {
683 6de88ee1 Stauros Kroustouris
    opts = jQuery.extend(opts, COMMENT_OPTIONS);
684 6de88ee1 Stauros Kroustouris
  }
685 6de88ee1 Stauros Kroustouris
686 6de88ee1 Stauros Kroustouris
  var popupTemplate = '\
687 6de88ee1 Stauros Kroustouris
    <div class="sphinx-comments" id="sc<%id%>">\
688 6de88ee1 Stauros Kroustouris
      <p class="sort-options">\
689 6de88ee1 Stauros Kroustouris
        Sort by:\
690 6de88ee1 Stauros Kroustouris
        <a href="#" class="sort-option byrating">best rated</a>\
691 6de88ee1 Stauros Kroustouris
        <a href="#" class="sort-option byascage">newest</a>\
692 6de88ee1 Stauros Kroustouris
        <a href="#" class="sort-option byage">oldest</a>\
693 6de88ee1 Stauros Kroustouris
      </p>\
694 6de88ee1 Stauros Kroustouris
      <div class="comment-header">Comments</div>\
695 6de88ee1 Stauros Kroustouris
      <div class="comment-loading" id="cn<%id%>">\
696 6de88ee1 Stauros Kroustouris
        loading comments... <img src="<%loadingImage%>" alt="" /></div>\
697 6de88ee1 Stauros Kroustouris
      <ul id="cl<%id%>" class="comment-ul"></ul>\
698 6de88ee1 Stauros Kroustouris
      <div id="ca<%id%>">\
699 6de88ee1 Stauros Kroustouris
      <p class="add-a-comment">Add a comment\
700 6de88ee1 Stauros Kroustouris
        (<a href="#" class="comment-markup" id="ab<%id%>">markup</a>):</p>\
701 6de88ee1 Stauros Kroustouris
      <div class="comment-markup-box" id="mb<%id%>">\
702 6de88ee1 Stauros Kroustouris
        reStructured text markup: <i>*emph*</i>, <b>**strong**</b>, \
703 6de88ee1 Stauros Kroustouris
        <tt>``code``</tt>, \
704 6de88ee1 Stauros Kroustouris
        code blocks: <tt>::</tt> and an indented block after blank line</div>\
705 6de88ee1 Stauros Kroustouris
      <form method="post" id="cf<%id%>" class="comment-form" action="">\
706 6de88ee1 Stauros Kroustouris
        <textarea name="comment" cols="80"></textarea>\
707 6de88ee1 Stauros Kroustouris
        <p class="propose-button">\
708 6de88ee1 Stauros Kroustouris
          <a href="#" id="pc<%id%>" class="show-propose-change">\
709 6de88ee1 Stauros Kroustouris
            Propose a change &#9657;\
710 6de88ee1 Stauros Kroustouris
          </a>\
711 6de88ee1 Stauros Kroustouris
          <a href="#" id="hc<%id%>" class="hide-propose-change">\
712 6de88ee1 Stauros Kroustouris
            Propose a change &#9663;\
713 6de88ee1 Stauros Kroustouris
          </a>\
714 6de88ee1 Stauros Kroustouris
        </p>\
715 6de88ee1 Stauros Kroustouris
        <textarea name="proposal" id="pt<%id%>" cols="80"\
716 6de88ee1 Stauros Kroustouris
                  spellcheck="false"></textarea>\
717 6de88ee1 Stauros Kroustouris
        <input type="submit" value="Add comment" />\
718 6de88ee1 Stauros Kroustouris
        <input type="hidden" name="node" value="<%id%>" />\
719 6de88ee1 Stauros Kroustouris
        <input type="hidden" name="parent" value="" />\
720 6de88ee1 Stauros Kroustouris
      </form>\
721 6de88ee1 Stauros Kroustouris
      </div>\
722 6de88ee1 Stauros Kroustouris
    </div>';
723 6de88ee1 Stauros Kroustouris
724 6de88ee1 Stauros Kroustouris
  var commentTemplate = '\
725 6de88ee1 Stauros Kroustouris
    <div id="cd<%id%>" class="sphinx-comment<%css_class%>">\
726 6de88ee1 Stauros Kroustouris
      <div class="vote">\
727 6de88ee1 Stauros Kroustouris
        <div class="arrow">\
728 6de88ee1 Stauros Kroustouris
          <a href="#" id="uv<%id%>" class="vote" title="vote up">\
729 6de88ee1 Stauros Kroustouris
            <img src="<%upArrow%>" />\
730 6de88ee1 Stauros Kroustouris
          </a>\
731 6de88ee1 Stauros Kroustouris
          <a href="#" id="uu<%id%>" class="un vote" title="vote up">\
732 6de88ee1 Stauros Kroustouris
            <img src="<%upArrowPressed%>" />\
733 6de88ee1 Stauros Kroustouris
          </a>\
734 6de88ee1 Stauros Kroustouris
        </div>\
735 6de88ee1 Stauros Kroustouris
        <div class="arrow">\
736 6de88ee1 Stauros Kroustouris
          <a href="#" id="dv<%id%>" class="vote" title="vote down">\
737 6de88ee1 Stauros Kroustouris
            <img src="<%downArrow%>" id="da<%id%>" />\
738 6de88ee1 Stauros Kroustouris
          </a>\
739 6de88ee1 Stauros Kroustouris
          <a href="#" id="du<%id%>" class="un vote" title="vote down">\
740 6de88ee1 Stauros Kroustouris
            <img src="<%downArrowPressed%>" />\
741 6de88ee1 Stauros Kroustouris
          </a>\
742 6de88ee1 Stauros Kroustouris
        </div>\
743 6de88ee1 Stauros Kroustouris
      </div>\
744 6de88ee1 Stauros Kroustouris
      <div class="comment-content">\
745 6de88ee1 Stauros Kroustouris
        <p class="tagline comment">\
746 6de88ee1 Stauros Kroustouris
          <span class="user-id"><%username%></span>\
747 6de88ee1 Stauros Kroustouris
          <span class="rating"><%pretty_rating%></span>\
748 6de88ee1 Stauros Kroustouris
          <span class="delta"><%time.delta%></span>\
749 6de88ee1 Stauros Kroustouris
        </p>\
750 6de88ee1 Stauros Kroustouris
        <div class="comment-text comment"><#text#></div>\
751 6de88ee1 Stauros Kroustouris
        <p class="comment-opts comment">\
752 6de88ee1 Stauros Kroustouris
          <a href="#" class="reply hidden" id="rl<%id%>">reply &#9657;</a>\
753 6de88ee1 Stauros Kroustouris
          <a href="#" class="close-reply" id="cr<%id%>">reply &#9663;</a>\
754 6de88ee1 Stauros Kroustouris
          <a href="#" id="sp<%id%>" class="show-proposal">proposal &#9657;</a>\
755 6de88ee1 Stauros Kroustouris
          <a href="#" id="hp<%id%>" class="hide-proposal">proposal &#9663;</a>\
756 6de88ee1 Stauros Kroustouris
          <a href="#" id="dc<%id%>" class="delete-comment hidden">delete</a>\
757 6de88ee1 Stauros Kroustouris
          <span id="cm<%id%>" class="moderation hidden">\
758 6de88ee1 Stauros Kroustouris
            <a href="#" id="ac<%id%>" class="accept-comment">accept</a>\
759 6de88ee1 Stauros Kroustouris
          </span>\
760 6de88ee1 Stauros Kroustouris
        </p>\
761 6de88ee1 Stauros Kroustouris
        <pre class="proposal" id="pr<%id%>">\
762 6de88ee1 Stauros Kroustouris
<#proposal_diff#>\
763 6de88ee1 Stauros Kroustouris
        </pre>\
764 6de88ee1 Stauros Kroustouris
          <ul class="comment-children" id="cl<%id%>"></ul>\
765 6de88ee1 Stauros Kroustouris
        </div>\
766 6de88ee1 Stauros Kroustouris
        <div class="clearleft"></div>\
767 6de88ee1 Stauros Kroustouris
      </div>\
768 6de88ee1 Stauros Kroustouris
    </div>';
769 6de88ee1 Stauros Kroustouris
770 6de88ee1 Stauros Kroustouris
  var replyTemplate = '\
771 6de88ee1 Stauros Kroustouris
    <li>\
772 6de88ee1 Stauros Kroustouris
      <div class="reply-div" id="rd<%id%>">\
773 6de88ee1 Stauros Kroustouris
        <form id="rf<%id%>">\
774 6de88ee1 Stauros Kroustouris
          <textarea name="comment" cols="80"></textarea>\
775 6de88ee1 Stauros Kroustouris
          <input type="submit" value="Add reply" />\
776 6de88ee1 Stauros Kroustouris
          <input type="button" value="Cancel" />\
777 6de88ee1 Stauros Kroustouris
          <input type="hidden" name="parent" value="<%id%>" />\
778 6de88ee1 Stauros Kroustouris
          <input type="hidden" name="node" value="" />\
779 6de88ee1 Stauros Kroustouris
        </form>\
780 6de88ee1 Stauros Kroustouris
      </div>\
781 6de88ee1 Stauros Kroustouris
    </li>';
782 6de88ee1 Stauros Kroustouris
783 6de88ee1 Stauros Kroustouris
  $(document).ready(function() {
784 6de88ee1 Stauros Kroustouris
    init();
785 6de88ee1 Stauros Kroustouris
  });
786 6de88ee1 Stauros Kroustouris
})(jQuery);
787 6de88ee1 Stauros Kroustouris
788 6de88ee1 Stauros Kroustouris
$(document).ready(function() {
789 6de88ee1 Stauros Kroustouris
  // add comment anchors for all paragraphs that are commentable
790 6de88ee1 Stauros Kroustouris
  $('.sphinx-has-comment').comment();
791 6de88ee1 Stauros Kroustouris
792 6de88ee1 Stauros Kroustouris
  // highlight search words in search results
793 6de88ee1 Stauros Kroustouris
  $("div.context").each(function() {
794 6de88ee1 Stauros Kroustouris
    var params = $.getQueryParameters();
795 6de88ee1 Stauros Kroustouris
    var terms = (params.q) ? params.q[0].split(/\s+/) : [];
796 6de88ee1 Stauros Kroustouris
    var result = $(this);
797 6de88ee1 Stauros Kroustouris
    $.each(terms, function() {
798 6de88ee1 Stauros Kroustouris
      result.highlightText(this.toLowerCase(), 'highlighted');
799 6de88ee1 Stauros Kroustouris
    });
800 6de88ee1 Stauros Kroustouris
  });
801 6de88ee1 Stauros Kroustouris
802 6de88ee1 Stauros Kroustouris
  // directly open comment window if requested
803 6de88ee1 Stauros Kroustouris
  var anchor = document.location.hash;
804 6de88ee1 Stauros Kroustouris
  if (anchor.substring(0, 9) == '#comment-') {
805 6de88ee1 Stauros Kroustouris
    $('#ao' + anchor.substring(9)).click();
806 6de88ee1 Stauros Kroustouris
    document.location.hash = '#s' + anchor.substring(9);
807 6de88ee1 Stauros Kroustouris
  }
808 6de88ee1 Stauros Kroustouris
});