Sha256: 0a8a487e93aad54d772ca01de7cbbe05fd1298b677a2f9707f9c959e107624a9

Contents?: true

Size: 1.6 KB

Versions: 1

Compression:

Stored size: 1.6 KB

Contents

(function($) {
  $('#rack-webconsole form').submit(function(e){
    e.preventDefault();
  });

  $("#rack-webconsole form input").keyup(function(event) {
    function escapeHTML(string) {
      return(string.replace(/&/g,'&').
        replace(/>/g,'>').
        replace(/</g,'&lt;').
        replace(/"/g,'&quot;')
      );
    };

    if (event.which == 13) {
      /*$.post('/webconsole', $("#rack-webconsole form").serialize());*/
      var query = $("#webconsole_query").val();
      $.ajax({
        url: '/webconsole',
        type: 'POST',
        dataType: 'json',
        data: ({query: query, token: "TOKEN"}),
        success: function (data) {
          var q = "<div class='query'>" + escapeHTML(">> " + query) + "</div>";
          var r = "<div class='result'>" + escapeHTML("=> " + data.result) + "</div>";
          $("#rack-webconsole .results").append(q + r);
          $("#rack-webconsole .results_wrapper").scrollTop(
            $("#rack-webconsole .results").height()
          );
          $("#webconsole_query").val('');
        }
      });
    }
  });

  $(document).ready(function() {
    $(this).keypress(function(event) {
      if (event.which == 96) {
        $("#rack-webconsole").slideToggle('fast', function() {
          if ($(this).is(':visible')) {
            $("#rack-webconsole form input").focus();
            $("#rack-webconsole .results_wrapper").scrollTop(
              $("#rack-webconsole .results").height()
            );
          } else {
            $("#rack-webconsole form input").blur();
          }
        });
        event.preventDefault();
      }
    });
  });
})(jQuery);

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rack-webconsole-0.1.2 public/webconsole.js