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