Blame docs/html/_static/websupport.js

Packit ea1746
/*
Packit ea1746
 * websupport.js
Packit ea1746
 * ~~~~~~~~~~~~~
Packit ea1746
 *
Packit ea1746
 * sphinx.websupport utilities for all documentation.
Packit ea1746
 *
Packit ea1746
 * :copyright: Copyright 2007-2016 by the Sphinx team, see AUTHORS.
Packit ea1746
 * :license: BSD, see LICENSE for details.
Packit ea1746
 *
Packit ea1746
 */
Packit ea1746
Packit ea1746
(function($) {
Packit ea1746
  $.fn.autogrow = function() {
Packit ea1746
    return this.each(function() {
Packit ea1746
    var textarea = this;
Packit ea1746
Packit ea1746
    $.fn.autogrow.resize(textarea);
Packit ea1746
Packit ea1746
    $(textarea)
Packit ea1746
      .focus(function() {
Packit ea1746
        textarea.interval = setInterval(function() {
Packit ea1746
          $.fn.autogrow.resize(textarea);
Packit ea1746
        }, 500);
Packit ea1746
      })
Packit ea1746
      .blur(function() {
Packit ea1746
        clearInterval(textarea.interval);
Packit ea1746
      });
Packit ea1746
    });
Packit ea1746
  };
Packit ea1746
Packit ea1746
  $.fn.autogrow.resize = function(textarea) {
Packit ea1746
    var lineHeight = parseInt($(textarea).css('line-height'), 10);
Packit ea1746
    var lines = textarea.value.split('\n');
Packit ea1746
    var columns = textarea.cols;
Packit ea1746
    var lineCount = 0;
Packit ea1746
    $.each(lines, function() {
Packit ea1746
      lineCount += Math.ceil(this.length / columns) || 1;
Packit ea1746
    });
Packit ea1746
    var height = lineHeight * (lineCount + 1);
Packit ea1746
    $(textarea).css('height', height);
Packit ea1746
  };
Packit ea1746
})(jQuery);
Packit ea1746
Packit ea1746
(function($) {
Packit ea1746
  var comp, by;
Packit ea1746
Packit ea1746
  function init() {
Packit ea1746
    initEvents();
Packit ea1746
    initComparator();
Packit ea1746
  }
Packit ea1746
Packit ea1746
  function initEvents() {
Packit ea1746
    $(document).on("click", 'a.comment-close', function(event) {
Packit ea1746
      event.preventDefault();
Packit ea1746
      hide($(this).attr('id').substring(2));
Packit ea1746
    });
Packit ea1746
    $(document).on("click", 'a.vote', function(event) {
Packit ea1746
      event.preventDefault();
Packit ea1746
      handleVote($(this));
Packit ea1746
    });
Packit ea1746
    $(document).on("click", 'a.reply', function(event) {
Packit ea1746
      event.preventDefault();
Packit ea1746
      openReply($(this).attr('id').substring(2));
Packit ea1746
    });
Packit ea1746
    $(document).on("click", 'a.close-reply', function(event) {
Packit ea1746
      event.preventDefault();
Packit ea1746
      closeReply($(this).attr('id').substring(2));
Packit ea1746
    });
Packit ea1746
    $(document).on("click", 'a.sort-option', function(event) {
Packit ea1746
      event.preventDefault();
Packit ea1746
      handleReSort($(this));
Packit ea1746
    });
Packit ea1746
    $(document).on("click", 'a.show-proposal', function(event) {
Packit ea1746
      event.preventDefault();
Packit ea1746
      showProposal($(this).attr('id').substring(2));
Packit ea1746
    });
Packit ea1746
    $(document).on("click", 'a.hide-proposal', function(event) {
Packit ea1746
      event.preventDefault();
Packit ea1746
      hideProposal($(this).attr('id').substring(2));
Packit ea1746
    });
Packit ea1746
    $(document).on("click", 'a.show-propose-change', function(event) {
Packit ea1746
      event.preventDefault();
Packit ea1746
      showProposeChange($(this).attr('id').substring(2));
Packit ea1746
    });
Packit ea1746
    $(document).on("click", 'a.hide-propose-change', function(event) {
Packit ea1746
      event.preventDefault();
Packit ea1746
      hideProposeChange($(this).attr('id').substring(2));
Packit ea1746
    });
Packit ea1746
    $(document).on("click", 'a.accept-comment', function(event) {
Packit ea1746
      event.preventDefault();
Packit ea1746
      acceptComment($(this).attr('id').substring(2));
Packit ea1746
    });
Packit ea1746
    $(document).on("click", 'a.delete-comment', function(event) {
Packit ea1746
      event.preventDefault();
Packit ea1746
      deleteComment($(this).attr('id').substring(2));
Packit ea1746
    });
Packit ea1746
    $(document).on("click", 'a.comment-markup', function(event) {
Packit ea1746
      event.preventDefault();
Packit ea1746
      toggleCommentMarkupBox($(this).attr('id').substring(2));
Packit ea1746
    });
Packit ea1746
  }
Packit ea1746
Packit ea1746
  /**
Packit ea1746
   * Set comp, which is a comparator function used for sorting and
Packit ea1746
   * inserting comments into the list.
Packit ea1746
   */
Packit ea1746
  function setComparator() {
Packit ea1746
    // If the first three letters are "asc", sort in ascending order
Packit ea1746
    // and remove the prefix.
Packit ea1746
    if (by.substring(0,3) == 'asc') {
Packit ea1746
      var i = by.substring(3);
Packit ea1746
      comp = function(a, b) { return a[i] - b[i]; };
Packit ea1746
    } else {
Packit ea1746
      // Otherwise sort in descending order.
Packit ea1746
      comp = function(a, b) { return b[by] - a[by]; };
Packit ea1746
    }
Packit ea1746
Packit ea1746
    // Reset link styles and format the selected sort option.
Packit ea1746
    $('a.sel').attr('href', '#').removeClass('sel');
Packit ea1746
    $('a.by' + by).removeAttr('href').addClass('sel');
Packit ea1746
  }
Packit ea1746
Packit ea1746
  /**
Packit ea1746
   * Create a comp function. If the user has preferences stored in
Packit ea1746
   * the sortBy cookie, use those, otherwise use the default.
Packit ea1746
   */
Packit ea1746
  function initComparator() {
Packit ea1746
    by = 'rating'; // Default to sort by rating.
Packit ea1746
    // If the sortBy cookie is set, use that instead.
Packit ea1746
    if (document.cookie.length > 0) {
Packit ea1746
      var start = document.cookie.indexOf('sortBy=');
Packit ea1746
      if (start != -1) {
Packit ea1746
        start = start + 7;
Packit ea1746
        var end = document.cookie.indexOf(";", start);
Packit ea1746
        if (end == -1) {
Packit ea1746
          end = document.cookie.length;
Packit ea1746
          by = unescape(document.cookie.substring(start, end));
Packit ea1746
        }
Packit ea1746
      }
Packit ea1746
    }
Packit ea1746
    setComparator();
Packit ea1746
  }
Packit ea1746
Packit ea1746
  /**
Packit ea1746
   * Show a comment div.
Packit ea1746
   */
Packit ea1746
  function show(id) {
Packit ea1746
    $('#ao' + id).hide();
Packit ea1746
    $('#ah' + id).show();
Packit ea1746
    var context = $.extend({id: id}, opts);
Packit ea1746
    var popup = $(renderTemplate(popupTemplate, context)).hide();
Packit ea1746
    popup.find('textarea[name="proposal"]').hide();
Packit ea1746
    popup.find('a.by' + by).addClass('sel');
Packit ea1746
    var form = popup.find('#cf' + id);
Packit ea1746
    form.submit(function(event) {
Packit ea1746
      event.preventDefault();
Packit ea1746
      addComment(form);
Packit ea1746
    });
Packit ea1746
    $('#s' + id).after(popup);
Packit ea1746
    popup.slideDown('fast', function() {
Packit ea1746
      getComments(id);
Packit ea1746
    });
Packit ea1746
  }
Packit ea1746
Packit ea1746
  /**
Packit ea1746
   * Hide a comment div.
Packit ea1746
   */
Packit ea1746
  function hide(id) {
Packit ea1746
    $('#ah' + id).hide();
Packit ea1746
    $('#ao' + id).show();
Packit ea1746
    var div = $('#sc' + id);
Packit ea1746
    div.slideUp('fast', function() {
Packit ea1746
      div.remove();
Packit ea1746
    });
Packit ea1746
  }
Packit ea1746
Packit ea1746
  /**
Packit ea1746
   * Perform an ajax request to get comments for a node
Packit ea1746
   * and insert the comments into the comments tree.
Packit ea1746
   */
Packit ea1746
  function getComments(id) {
Packit ea1746
    $.ajax({
Packit ea1746
     type: 'GET',
Packit ea1746
     url: opts.getCommentsURL,
Packit ea1746
     data: {node: id},
Packit ea1746
     success: function(data, textStatus, request) {
Packit ea1746
       var ul = $('#cl' + id);
Packit ea1746
       var speed = 100;
Packit ea1746
       $('#cf' + id)
Packit ea1746
         .find('textarea[name="proposal"]')
Packit ea1746
         .data('source', data.source);
Packit ea1746
Packit ea1746
       if (data.comments.length === 0) {
Packit ea1746
         ul.html('
  • No comments yet.
  • ');
    Packit ea1746
             ul.data('empty', true);
    Packit ea1746
           } else {
    Packit ea1746
             // If there are comments, sort them and put them in the list.
    Packit ea1746
             var comments = sortComments(data.comments);
    Packit ea1746
             speed = data.comments.length * 100;
    Packit ea1746
             appendComments(comments, ul);
    Packit ea1746
             ul.data('empty', false);
    Packit ea1746
           }
    Packit ea1746
           $('#cn' + id).slideUp(speed + 200);
    Packit ea1746
           ul.slideDown(speed);
    Packit ea1746
         },
    Packit ea1746
         error: function(request, textStatus, error) {
    Packit ea1746
           showError('Oops, there was a problem retrieving the comments.');
    Packit ea1746
         },
    Packit ea1746
         dataType: 'json'
    Packit ea1746
        });
    Packit ea1746
      }
    Packit ea1746
    Packit ea1746
      /**
    Packit ea1746
       * Add a comment via ajax and insert the comment into the comment tree.
    Packit ea1746
       */
    Packit ea1746
      function addComment(form) {
    Packit ea1746
        var node_id = form.find('input[name="node"]').val();
    Packit ea1746
        var parent_id = form.find('input[name="parent"]').val();
    Packit ea1746
        var text = form.find('textarea[name="comment"]').val();
    Packit ea1746
        var proposal = form.find('textarea[name="proposal"]').val();
    Packit ea1746
    Packit ea1746
        if (text == '') {
    Packit ea1746
          showError('Please enter a comment.');
    Packit ea1746
          return;
    Packit ea1746
        }
    Packit ea1746
    Packit ea1746
        // Disable the form that is being submitted.
    Packit ea1746
        form.find('textarea,input').attr('disabled', 'disabled');
    Packit ea1746
    Packit ea1746
        // Send the comment to the server.
    Packit ea1746
        $.ajax({
    Packit ea1746
          type: "POST",
    Packit ea1746
          url: opts.addCommentURL,
    Packit ea1746
          dataType: 'json',
    Packit ea1746
          data: {
    Packit ea1746
            node: node_id,
    Packit ea1746
            parent: parent_id,
    Packit ea1746
            text: text,
    Packit ea1746
            proposal: proposal
    Packit ea1746
          },
    Packit ea1746
          success: function(data, textStatus, error) {
    Packit ea1746
            // Reset the form.
    Packit ea1746
            if (node_id) {
    Packit ea1746
              hideProposeChange(node_id);
    Packit ea1746
            }
    Packit ea1746
            form.find('textarea')
    Packit ea1746
              .val('')
    Packit ea1746
              .add(form.find('input'))
    Packit ea1746
              .removeAttr('disabled');
    Packit ea1746
    	var ul = $('#cl' + (node_id || parent_id));
    Packit ea1746
            if (ul.data('empty')) {
    Packit ea1746
              $(ul).empty();
    Packit ea1746
              ul.data('empty', false);
    Packit ea1746
            }
    Packit ea1746
            insertComment(data.comment);
    Packit ea1746
            var ao = $('#ao' + node_id);
    Packit ea1746
            ao.find('img').attr({'src': opts.commentBrightImage});
    Packit ea1746
            if (node_id) {
    Packit ea1746
              // if this was a "root" comment, remove the commenting box
    Packit ea1746
              // (the user can get it back by reopening the comment popup)
    Packit ea1746
              $('#ca' + node_id).slideUp();
    Packit ea1746
            }
    Packit ea1746
          },
    Packit ea1746
          error: function(request, textStatus, error) {
    Packit ea1746
            form.find('textarea,input').removeAttr('disabled');
    Packit ea1746
            showError('Oops, there was a problem adding the comment.');
    Packit ea1746
          }
    Packit ea1746
        });
    Packit ea1746
      }
    Packit ea1746
    Packit ea1746
      /**
    Packit ea1746
       * Recursively append comments to the main comment list and children
    Packit ea1746
       * lists, creating the comment tree.
    Packit ea1746
       */
    Packit ea1746
      function appendComments(comments, ul) {
    Packit ea1746
        $.each(comments, function() {
    Packit ea1746
          var div = createCommentDiv(this);
    Packit ea1746
          ul.append($(document.createElement('li')).html(div));
    Packit ea1746
          appendComments(this.children, div.find('ul.comment-children'));
    Packit ea1746
          // To avoid stagnating data, don't store the comments children in data.
    Packit ea1746
          this.children = null;
    Packit ea1746
          div.data('comment', this);
    Packit ea1746
        });
    Packit ea1746
      }
    Packit ea1746
    Packit ea1746
      /**
    Packit ea1746
       * After adding a new comment, it must be inserted in the correct
    Packit ea1746
       * location in the comment tree.
    Packit ea1746
       */
    Packit ea1746
      function insertComment(comment) {
    Packit ea1746
        var div = createCommentDiv(comment);
    Packit ea1746
    Packit ea1746
        // To avoid stagnating data, don't store the comments children in data.
    Packit ea1746
        comment.children = null;
    Packit ea1746
        div.data('comment', comment);
    Packit ea1746
    Packit ea1746
        var ul = $('#cl' + (comment.node || comment.parent));
    Packit ea1746
        var siblings = getChildren(ul);
    Packit ea1746
    Packit ea1746
        var li = $(document.createElement('li'));
    Packit ea1746
        li.hide();
    Packit ea1746
    Packit ea1746
        // Determine where in the parents children list to insert this comment.
    Packit ea1746
        for(i=0; i < siblings.length; i++) {
    Packit ea1746
          if (comp(comment, siblings[i]) <= 0) {
    Packit ea1746
            $('#cd' + siblings[i].id)
    Packit ea1746
              .parent()
    Packit ea1746
              .before(li.html(div));
    Packit ea1746
            li.slideDown('fast');
    Packit ea1746
            return;
    Packit ea1746
          }
    Packit ea1746
        }
    Packit ea1746
    Packit ea1746
        // If we get here, this comment rates lower than all the others,
    Packit ea1746
        // or it is the only comment in the list.
    Packit ea1746
        ul.append(li.html(div));
    Packit ea1746
        li.slideDown('fast');
    Packit ea1746
      }
    Packit ea1746
    Packit ea1746
      function acceptComment(id) {
    Packit ea1746
        $.ajax({
    Packit ea1746
          type: 'POST',
    Packit ea1746
          url: opts.acceptCommentURL,
    Packit ea1746
          data: {id: id},
    Packit ea1746
          success: function(data, textStatus, request) {
    Packit ea1746
            $('#cm' + id).fadeOut('fast');
    Packit ea1746
            $('#cd' + id).removeClass('moderate');
    Packit ea1746
          },
    Packit ea1746
          error: function(request, textStatus, error) {
    Packit ea1746
            showError('Oops, there was a problem accepting the comment.');
    Packit ea1746
          }
    Packit ea1746
        });
    Packit ea1746
      }
    Packit ea1746
    Packit ea1746
      function deleteComment(id) {
    Packit ea1746
        $.ajax({
    Packit ea1746
          type: 'POST',
    Packit ea1746
          url: opts.deleteCommentURL,
    Packit ea1746
          data: {id: id},
    Packit ea1746
          success: function(data, textStatus, request) {
    Packit ea1746
            var div = $('#cd' + id);
    Packit ea1746
            if (data == 'delete') {
    Packit ea1746
              // Moderator mode: remove the comment and all children immediately
    Packit ea1746
              div.slideUp('fast', function() {
    Packit ea1746
                div.remove();
    Packit ea1746
              });
    Packit ea1746
              return;
    Packit ea1746
            }
    Packit ea1746
            // User mode: only mark the comment as deleted
    Packit ea1746
            div
    Packit ea1746
              .find('span.user-id:first')
    Packit ea1746
              .text('[deleted]').end()
    Packit ea1746
              .find('div.comment-text:first')
    Packit ea1746
              .text('[deleted]').end()
    Packit ea1746
              .find('#cm' + id + ', #dc' + id + ', #ac' + id + ', #rc' + id +
    Packit ea1746
                    ', #sp' + id + ', #hp' + id + ', #cr' + id + ', #rl' + id)
    Packit ea1746
              .remove();
    Packit ea1746
            var comment = div.data('comment');
    Packit ea1746
            comment.username = '[deleted]';
    Packit ea1746
            comment.text = '[deleted]';
    Packit ea1746
            div.data('comment', comment);
    Packit ea1746
          },
    Packit ea1746
          error: function(request, textStatus, error) {
    Packit ea1746
            showError('Oops, there was a problem deleting the comment.');
    Packit ea1746
          }
    Packit ea1746
        });
    Packit ea1746
      }
    Packit ea1746
    Packit ea1746
      function showProposal(id) {
    Packit ea1746
        $('#sp' + id).hide();
    Packit ea1746
        $('#hp' + id).show();
    Packit ea1746
        $('#pr' + id).slideDown('fast');
    Packit ea1746
      }
    Packit ea1746
    Packit ea1746
      function hideProposal(id) {
    Packit ea1746
        $('#hp' + id).hide();
    Packit ea1746
        $('#sp' + id).show();
    Packit ea1746
        $('#pr' + id).slideUp('fast');
    Packit ea1746
      }
    Packit ea1746
    Packit ea1746
      function showProposeChange(id) {
    Packit ea1746
        $('#pc' + id).hide();
    Packit ea1746
        $('#hc' + id).show();
    Packit ea1746
        var textarea = $('#pt' + id);
    Packit ea1746
        textarea.val(textarea.data('source'));
    Packit ea1746
        $.fn.autogrow.resize(textarea[0]);
    Packit ea1746
        textarea.slideDown('fast');
    Packit ea1746
      }
    Packit ea1746
    Packit ea1746
      function hideProposeChange(id) {
    Packit ea1746
        $('#hc' + id).hide();
    Packit ea1746
        $('#pc' + id).show();
    Packit ea1746
        var textarea = $('#pt' + id);
    Packit ea1746
        textarea.val('').removeAttr('disabled');
    Packit ea1746
        textarea.slideUp('fast');
    Packit ea1746
      }
    Packit ea1746
    Packit ea1746
      function toggleCommentMarkupBox(id) {
    Packit ea1746
        $('#mb' + id).toggle();
    Packit ea1746
      }
    Packit ea1746
    Packit ea1746
      /** Handle when the user clicks on a sort by link. */
    Packit ea1746
      function handleReSort(link) {
    Packit ea1746
        var classes = link.attr('class').split(/\s+/);
    Packit ea1746
        for (var i=0; i
    Packit ea1746
          if (classes[i] != 'sort-option') {
    Packit ea1746
    	by = classes[i].substring(2);
    Packit ea1746
          }
    Packit ea1746
        }
    Packit ea1746
        setComparator();
    Packit ea1746
        // Save/update the sortBy cookie.
    Packit ea1746
        var expiration = new Date();
    Packit ea1746
        expiration.setDate(expiration.getDate() + 365);
    Packit ea1746
        document.cookie= 'sortBy=' + escape(by) +
    Packit ea1746
                         ';expires=' + expiration.toUTCString();
    Packit ea1746
        $('ul.comment-ul').each(function(index, ul) {
    Packit ea1746
          var comments = getChildren($(ul), true);
    Packit ea1746
          comments = sortComments(comments);
    Packit ea1746
          appendComments(comments, $(ul).empty());
    Packit ea1746
        });
    Packit ea1746
      }
    Packit ea1746
    Packit ea1746
      /**
    Packit ea1746
       * Function to process a vote when a user clicks an arrow.
    Packit ea1746
       */
    Packit ea1746
      function handleVote(link) {
    Packit ea1746
        if (!opts.voting) {
    Packit ea1746
          showError("You'll need to login to vote.");
    Packit ea1746
          return;
    Packit ea1746
        }
    Packit ea1746
    Packit ea1746
        var id = link.attr('id');
    Packit ea1746
        if (!id) {
    Packit ea1746
          // Didn't click on one of the voting arrows.
    Packit ea1746
          return;
    Packit ea1746
        }
    Packit ea1746
        // If it is an unvote, the new vote value is 0,
    Packit ea1746
        // Otherwise it's 1 for an upvote, or -1 for a downvote.
    Packit ea1746
        var value = 0;
    Packit ea1746
        if (id.charAt(1) != 'u') {
    Packit ea1746
          value = id.charAt(0) == 'u' ? 1 : -1;
    Packit ea1746
        }
    Packit ea1746
        // The data to be sent to the server.
    Packit ea1746
        var d = {
    Packit ea1746
          comment_id: id.substring(2),
    Packit ea1746
          value: value
    Packit ea1746
        };
    Packit ea1746
    Packit ea1746
        // Swap the vote and unvote links.
    Packit ea1746
        link.hide();
    Packit ea1746
        $('#' + id.charAt(0) + (id.charAt(1) == 'u' ? 'v' : 'u') + d.comment_id)
    Packit ea1746
          .show();
    Packit ea1746
    Packit ea1746
        // The div the comment is displayed in.
    Packit ea1746
        var div = $('div#cd' + d.comment_id);
    Packit ea1746
        var data = div.data('comment');
    Packit ea1746
    Packit ea1746
        // If this is not an unvote, and the other vote arrow has
    Packit ea1746
        // already been pressed, unpress it.
    Packit ea1746
        if ((d.value !== 0) && (data.vote === d.value * -1)) {
    Packit ea1746
          $('#' + (d.value == 1 ? 'd' : 'u') + 'u' + d.comment_id).hide();
    Packit ea1746
          $('#' + (d.value == 1 ? 'd' : 'u') + 'v' + d.comment_id).show();
    Packit ea1746
        }
    Packit ea1746
    Packit ea1746
        // Update the comments rating in the local data.
    Packit ea1746
        data.rating += (data.vote === 0) ? d.value : (d.value - data.vote);
    Packit ea1746
        data.vote = d.value;
    Packit ea1746
        div.data('comment', data);
    Packit ea1746
    Packit ea1746
        // Change the rating text.
    Packit ea1746
        div.find('.rating:first')
    Packit ea1746
          .text(data.rating + ' point' + (data.rating == 1 ? '' : 's'));
    Packit ea1746
    Packit ea1746
        // Send the vote information to the server.
    Packit ea1746
        $.ajax({
    Packit ea1746
          type: "POST",
    Packit ea1746
          url: opts.processVoteURL,
    Packit ea1746
          data: d,
    Packit ea1746
          error: function(request, textStatus, error) {
    Packit ea1746
            showError('Oops, there was a problem casting that vote.');
    Packit ea1746
          }
    Packit ea1746
        });
    Packit ea1746
      }
    Packit ea1746
    Packit ea1746
      /**
    Packit ea1746
       * Open a reply form used to reply to an existing comment.
    Packit ea1746
       */
    Packit ea1746
      function openReply(id) {
    Packit ea1746
        // Swap out the reply link for the hide link
    Packit ea1746
        $('#rl' + id).hide();
    Packit ea1746
        $('#cr' + id).show();
    Packit ea1746
    Packit ea1746
        // Add the reply li to the children ul.
    Packit ea1746
        var div = $(renderTemplate(replyTemplate, {id: id})).hide();
    Packit ea1746
        $('#cl' + id)
    Packit ea1746
          .prepend(div)
    Packit ea1746
          // Setup the submit handler for the reply form.
    Packit ea1746
          .find('#rf' + id)
    Packit ea1746
          .submit(function(event) {
    Packit ea1746
            event.preventDefault();
    Packit ea1746
            addComment($('#rf' + id));
    Packit ea1746
            closeReply(id);
    Packit ea1746
          })
    Packit ea1746
          .find('input[type=button]')
    Packit ea1746
          .click(function() {
    Packit ea1746
            closeReply(id);
    Packit ea1746
          });
    Packit ea1746
        div.slideDown('fast', function() {
    Packit ea1746
          $('#rf' + id).find('textarea').focus();
    Packit ea1746
        });
    Packit ea1746
      }
    Packit ea1746
    Packit ea1746
      /**
    Packit ea1746
       * Close the reply form opened with openReply.
    Packit ea1746
       */
    Packit ea1746
      function closeReply(id) {
    Packit ea1746
        // Remove the reply div from the DOM.
    Packit ea1746
        $('#rd' + id).slideUp('fast', function() {
    Packit ea1746
          $(this).remove();
    Packit ea1746
        });
    Packit ea1746
    Packit ea1746
        // Swap out the hide link for the reply link
    Packit ea1746
        $('#cr' + id).hide();
    Packit ea1746
        $('#rl' + id).show();
    Packit ea1746
      }
    Packit ea1746
    Packit ea1746
      /**
    Packit ea1746
       * Recursively sort a tree of comments using the comp comparator.
    Packit ea1746
       */
    Packit ea1746
      function sortComments(comments) {
    Packit ea1746
        comments.sort(comp);
    Packit ea1746
        $.each(comments, function() {
    Packit ea1746
          this.children = sortComments(this.children);
    Packit ea1746
        });
    Packit ea1746
        return comments;
    Packit ea1746
      }
    Packit ea1746
    Packit ea1746
      /**
    Packit ea1746
       * Get the children comments from a ul. If recursive is true,
    Packit ea1746
       * recursively include childrens' children.
    Packit ea1746
       */
    Packit ea1746
      function getChildren(ul, recursive) {
    Packit ea1746
        var children = [];
    Packit ea1746
        ul.children().children("[id^='cd']")
    Packit ea1746
          .each(function() {
    Packit ea1746
            var comment = $(this).data('comment');
    Packit ea1746
            if (recursive)
    Packit ea1746
              comment.children = getChildren($(this).find('#cl' + comment.id), true);
    Packit ea1746
            children.push(comment);
    Packit ea1746
          });
    Packit ea1746
        return children;
    Packit ea1746
      }
    Packit ea1746
    Packit ea1746
      /** Create a div to display a comment in. */
    Packit ea1746
      function createCommentDiv(comment) {
    Packit ea1746
        if (!comment.displayed && !opts.moderator) {
    Packit ea1746
          return $('
    Thank you! Your comment will show up '
    Packit ea1746
                   + 'once it is has been approved by a moderator.');
    Packit ea1746
        }
    Packit ea1746
        // Prettify the comment rating.
    Packit ea1746
        comment.pretty_rating = comment.rating + ' point' +
    Packit ea1746
          (comment.rating == 1 ? '' : 's');
    Packit ea1746
        // Make a class (for displaying not yet moderated comments differently)
    Packit ea1746
        comment.css_class = comment.displayed ? '' : ' moderate';
    Packit ea1746
        // Create a div for this comment.
    Packit ea1746
        var context = $.extend({}, opts, comment);
    Packit ea1746
        var div = $(renderTemplate(commentTemplate, context));
    Packit ea1746
    Packit ea1746
        // If the user has voted on this comment, highlight the correct arrow.
    Packit ea1746
        if (comment.vote) {
    Packit ea1746
          var direction = (comment.vote == 1) ? 'u' : 'd';
    Packit ea1746
          div.find('#' + direction + 'v' + comment.id).hide();
    Packit ea1746
          div.find('#' + direction + 'u' + comment.id).show();
    Packit ea1746
        }
    Packit ea1746
    Packit ea1746
        if (opts.moderator || comment.text != '[deleted]') {
    Packit ea1746
          div.find('a.reply').show();
    Packit ea1746
          if (comment.proposal_diff)
    Packit ea1746
            div.find('#sp' + comment.id).show();
    Packit ea1746
          if (opts.moderator && !comment.displayed)
    Packit ea1746
            div.find('#cm' + comment.id).show();
    Packit ea1746
          if (opts.moderator || (opts.username == comment.username))
    Packit ea1746
            div.find('#dc' + comment.id).show();
    Packit ea1746
        }
    Packit ea1746
        return div;
    Packit ea1746
      }
    Packit ea1746
    Packit ea1746
      /**
    Packit ea1746
       * A simple template renderer. Placeholders such as <%id%> are replaced
    Packit ea1746
       * by context['id'] with items being escaped. Placeholders such as <#id#>
    Packit ea1746
       * are not escaped.
    Packit ea1746
       */
    Packit ea1746
      function renderTemplate(template, context) {
    Packit ea1746
        var esc = $(document.createElement('div'));
    Packit ea1746
    Packit ea1746
        function handle(ph, escape) {
    Packit ea1746
          var cur = context;
    Packit ea1746
          $.each(ph.split('.'), function() {
    Packit ea1746
            cur = cur[this];
    Packit ea1746
          });
    Packit ea1746
          return escape ? esc.text(cur || "").html() : cur;
    Packit ea1746
        }
    Packit ea1746
    Packit ea1746
        return template.replace(/<([%#])([\w\.]*)\1>/g, function() {
    Packit ea1746
          return handle(arguments[2], arguments[1] == '%' ? true : false);
    Packit ea1746
        });
    Packit ea1746
      }
    Packit ea1746
    Packit ea1746
      /** Flash an error message briefly. */
    Packit ea1746
      function showError(message) {
    Packit ea1746
        $(document.createElement('div')).attr({'class': 'popup-error'})
    Packit ea1746
          .append($(document.createElement('div'))
    Packit ea1746
                   .attr({'class': 'error-message'}).text(message))
    Packit ea1746
          .appendTo('body')
    Packit ea1746
          .fadeIn("slow")
    Packit ea1746
          .delay(2000)
    Packit ea1746
          .fadeOut("slow");
    Packit ea1746
      }
    Packit ea1746
    Packit ea1746
      /** Add a link the user uses to open the comments popup. */
    Packit ea1746
      $.fn.comment = function() {
    Packit ea1746
        return this.each(function() {
    Packit ea1746
          var id = $(this).attr('id').substring(1);
    Packit ea1746
          var count = COMMENT_METADATA[id];
    Packit ea1746
          var title = count + ' comment' + (count == 1 ? '' : 's');
    Packit ea1746
          var image = count > 0 ? opts.commentBrightImage : opts.commentImage;
    Packit ea1746
          var addcls = count == 0 ? ' nocomment' : '';
    Packit ea1746
          $(this)
    Packit ea1746
            .append(
    Packit ea1746
              $(document.createElement('a')).attr({
    Packit ea1746
                href: '#',
    Packit ea1746
                'class': 'sphinx-comment-open' + addcls,
    Packit ea1746
                id: 'ao' + id
    Packit ea1746
              })
    Packit ea1746
                .append($(document.createElement('img')).attr({
    Packit ea1746
                  src: image,
    Packit ea1746
                  alt: 'comment',
    Packit ea1746
                  title: title
    Packit ea1746
                }))
    Packit ea1746
                .click(function(event) {
    Packit ea1746
                  event.preventDefault();
    Packit ea1746
                  show($(this).attr('id').substring(2));
    Packit ea1746
                })
    Packit ea1746
            )
    Packit ea1746
            .append(
    Packit ea1746
              $(document.createElement('a')).attr({
    Packit ea1746
                href: '#',
    Packit ea1746
                'class': 'sphinx-comment-close hidden',
    Packit ea1746
                id: 'ah' + id
    Packit ea1746
              })
    Packit ea1746
                .append($(document.createElement('img')).attr({
    Packit ea1746
                  src: opts.closeCommentImage,
    Packit ea1746
                  alt: 'close',
    Packit ea1746
                  title: 'close'
    Packit ea1746
                }))
    Packit ea1746
                .click(function(event) {
    Packit ea1746
                  event.preventDefault();
    Packit ea1746
                  hide($(this).attr('id').substring(2));
    Packit ea1746
                })
    Packit ea1746
            );
    Packit ea1746
        });
    Packit ea1746
      };
    Packit ea1746
    Packit ea1746
      var opts = {
    Packit ea1746
        processVoteURL: '/_process_vote',
    Packit ea1746
        addCommentURL: '/_add_comment',
    Packit ea1746
        getCommentsURL: '/_get_comments',
    Packit ea1746
        acceptCommentURL: '/_accept_comment',
    Packit ea1746
        deleteCommentURL: '/_delete_comment',
    Packit ea1746
        commentImage: '/static/_static/comment.png',
    Packit ea1746
        closeCommentImage: '/static/_static/comment-close.png',
    Packit ea1746
        loadingImage: '/static/_static/ajax-loader.gif',
    Packit ea1746
        commentBrightImage: '/static/_static/comment-bright.png',
    Packit ea1746
        upArrow: '/static/_static/up.png',
    Packit ea1746
        downArrow: '/static/_static/down.png',
    Packit ea1746
        upArrowPressed: '/static/_static/up-pressed.png',
    Packit ea1746
        downArrowPressed: '/static/_static/down-pressed.png',
    Packit ea1746
        voting: false,
    Packit ea1746
        moderator: false
    Packit ea1746
      };
    Packit ea1746
    Packit ea1746
      if (typeof COMMENT_OPTIONS != "undefined") {
    Packit ea1746
        opts = jQuery.extend(opts, COMMENT_OPTIONS);
    Packit ea1746
      }
    Packit ea1746
    Packit ea1746
      var popupTemplate = '\
    Packit ea1746
        
    \
    Packit ea1746
          

    \

    Packit ea1746
            Sort by:\
    Packit ea1746
            best rated\
    Packit ea1746
            newest\
    Packit ea1746
            oldest\
    Packit ea1746
          

    \
    Packit ea1746
          
    Comments
    \
    Packit ea1746
          
    \
    Packit ea1746
            loading comments... \
    Packit ea1746
          
      \
      Packit ea1746
            
      \
      Packit ea1746
            

      Add a comment\

      Packit ea1746
              (markup):

      \
      Packit ea1746
            
      \
      Packit ea1746
              reStructured text markup: *emph*, **strong**, \
      Packit ea1746
              ``code``, \
      Packit ea1746
              code blocks: :: and an indented block after blank line\
      Packit ea1746
            <form method="post" id="cf<%id%>" class="comment-form" action="">\
      Packit ea1746
              <textarea name="comment" cols="80"></textarea>\
      Packit ea1746
              

      \

      Packit ea1746
                \
      Packit ea1746
                  Propose a change ▹\
      Packit ea1746
                \
      Packit ea1746
                \
      Packit ea1746
                  Propose a change ▿\
      Packit ea1746
                \
      Packit ea1746
              

      \
      Packit ea1746
              
      Packit ea1746
                        spellcheck="false"></textarea>\
      Packit ea1746
              <input type="submit" value="Add comment" />\
      Packit ea1746
              <input type="hidden" name="node" value="<%id%>" />\
      Packit ea1746
              <input type="hidden" name="parent" value="" />\
      Packit ea1746
            </form>\
      Packit ea1746
            \
      Packit ea1746
          ';
      Packit ea1746
      Packit ea1746
        var commentTemplate = '\
      Packit ea1746
          
      \
      Packit ea1746
            
      \
      Packit ea1746
              
      \
      Packit ea1746
                \
      Packit ea1746
                  \
      Packit ea1746
                \
      Packit ea1746
                \
      Packit ea1746
                  \
      Packit ea1746
                \
      Packit ea1746
              \
      Packit ea1746
              
      \
      Packit ea1746
                \
      Packit ea1746
                  \
      Packit ea1746
                \
      Packit ea1746
                \
      Packit ea1746
                  \
      Packit ea1746
                \
      Packit ea1746
              \
      Packit ea1746
            \
      Packit ea1746
            
      \
      Packit ea1746
              

      \

      Packit ea1746
                <%username%>\
      Packit ea1746
                <%pretty_rating%>\
      Packit ea1746
                <%time.delta%>\
      Packit ea1746
              

      \
      Packit ea1746
              
      <#text#>
      \
      Packit ea1746
              

      \

      Packit ea1746
                reply ▹\
      Packit ea1746
                reply ▿\
      Packit ea1746
                proposal ▹\
      Packit ea1746
                proposal ▿\
      Packit ea1746
                delete\
      Packit ea1746
                
      Packit ea1746
                  accept\
      Packit ea1746
                \
      Packit ea1746
              

      \
      Packit ea1746
              
      \
      Packit ea1746
      <#proposal_diff#>\
      Packit ea1746
              \
      Packit ea1746
                
        \
        Packit ea1746
                \
        Packit ea1746
                
        \
        Packit ea1746
              \
        Packit ea1746
            ';
        Packit ea1746
        Packit ea1746
          var replyTemplate = '\
        Packit ea1746
            
      • \
      • Packit ea1746
              
        \
        Packit ea1746
                <form id="rf<%id%>">\
        Packit ea1746
                  <textarea name="comment" cols="80"></textarea>\
        Packit ea1746
                  <input type="submit" value="Add reply" />\
        Packit ea1746
                  <input type="button" value="Cancel" />\
        Packit ea1746
                  <input type="hidden" name="parent" value="<%id%>" />\
        Packit ea1746
                  <input type="hidden" name="node" value="" />\
        Packit ea1746
                </form>\
        Packit ea1746
              \
        Packit ea1746
            ';
        Packit ea1746
        Packit ea1746
          $(document).ready(function() {
        Packit ea1746
            init();
        Packit ea1746
          });
        Packit ea1746
        })(jQuery);
        Packit ea1746
        Packit ea1746
        $(document).ready(function() {
        Packit ea1746
          // add comment anchors for all paragraphs that are commentable
        Packit ea1746
          $('.sphinx-has-comment').comment();
        Packit ea1746
        Packit ea1746
          // highlight search words in search results
        Packit ea1746
          $("div.context").each(function() {
        Packit ea1746
            var params = $.getQueryParameters();
        Packit ea1746
            var terms = (params.q) ? params.q[0].split(/\s+/) : [];
        Packit ea1746
            var result = $(this);
        Packit ea1746
            $.each(terms, function() {
        Packit ea1746
              result.highlightText(this.toLowerCase(), 'highlighted');
        Packit ea1746
            });
        Packit ea1746
          });
        Packit ea1746
        Packit ea1746
          // directly open comment window if requested
        Packit ea1746
          var anchor = document.location.hash;
        Packit ea1746
          if (anchor.substring(0, 9) == '#comment-') {
        Packit ea1746
            $('#ao' + anchor.substring(9)).click();
        Packit ea1746
            document.location.hash = '#s' + anchor.substring(9);
        Packit ea1746
          }
        Packit ea1746
        });