jQuery( document ).ready(function( $ ) { $.ajax( { url: 'config.json', dataType: 'json' } ).done( function( config ) { var c = config; var log = $('#requests'), // where the requests are listed initialWidth = $.cookie('panelWidth'), // save the width of the left panel panel = $('#panel'), // a reference to the left panel inputs = $('.inputs'), // all input divs resizing = false, // if the user is currently resizing the panel canResize = false, // if the user's mouse is in a location where resizing can be activated lastX = null, // track the last mouse x position resizeDetector = function(e){ // function to detect if the user can activate resizing var padding = 5, width = panel.width(), left = width, right = width + padding; if (lastX == e.pageX) return; lastX = e.pageX; if (lastX > left && lastX < right) { canResize = true; document.body.style.cursor = "ew-resize !important"; } else { canResize = false; document.body.style.cursor = null; } }, resizePerformer = function(e){ // attached as a mouse listener to perform resizing of the panel var min = 220, max = window.innerWidth - 400, width = Math.max(Math.min(max, e.pageX), min); e.preventDefault(); panel.width(width); log.css({left:width}); }, $span = $( '' ), safeText = function( string ) { return $span.text( string ).html(); }; panel.width(initialWidth); // set the initial width of the panel, can come from cookie log.css({left:initialWidth+'px'}); // resize the log to fit with the panel $(window).bind('resize', function(){ // listen to resizes to scale the panel/log correctly var min = 220, max = window.innerWidth - 400, width = Math.max(Math.min(max, panel.width()), min); panel.width(width); log.css({left:width}); $.cookie('panelWidth', panel.width()); }).trigger('resize'); $(document).bind('mousemove', resizeDetector); // track the position of the mouse $(document).bind('mousedown', function(e){ // determine if user is activating panel resize if(!canResize) return; e.preventDefault(); resizing = true; $(document) .unbind('mousemove', resizeDetector) .bind('mousemove', resizePerformer); }); $(document).bind('mouseup', function(e){ // stop resizing action and save the panel width if(!resizing) return; resizing = false; $.cookie('panelWidth', panel.width()); $(document) .unbind('mousemove', resizePerformer) .bind('mousemove', resizeDetector); }); // expand/collapse response views $('ul#requests').click(function(e){ var $target = $(e.target), $h2 = $target.is('h2') ? $target : $target.parents('h2'); if (!$h2.is('h2')) return; $li = $h2.parents('li'); $li[$li.hasClass('expanded') ? 'removeClass' : 'addClass']('expanded'); }); // add expand/collapse interations to the response nodes var initializeResponse = function(object){ object.find('ul.object, ul.array').each(function(){ var $this = $(this), $li = $this.parent(), $disclosure = $("▸").addClass('disclosure').click(function(){ $li[$li.hasClass('closed') ? 'removeClass' : 'addClass']('closed'); }); $li.addClass('closed').append($disclosure); }); return object; } // outputs a single line of JSON var rawResponse = function(object, formatter){ return JSON.stringify(object, null, formatter); }; // build the response HTML nodes from the parsed JSON object var formatResponse = function(object, keyPath){ var node, li; if (!keyPath) keyPath = []; if (!object || object.constructor == Array && object.length == 0) return; if ('object' === typeof(object)) { node = $("
").text(variable))
.append(" ")
.append($("").text(help.type))
);
switch(help.description.constructor){
case String:
$node.append($("").text(help.description));
break;
case Object:
var $dl = $('Not available
") break; } }, objectBuilder = function(){ // creates an interface to allow the user to enter values for each key in an object, also shows hints if available var $builder = $("')
.addClass('pretty')
.text(rawResponse(response, "\t"))
);
formats = formats.add($('')
.addClass('raw')
.text(rawResponse(response))
);
$("")
.addClass("response")
.append(formats.hide())
.appendTo(request);
$('')
.addClass('tabs')
.append("- Structured
- Pretty
- Raw
").click(function(e){
var $this = $(this), $children = $this.children(), $li = $children.filter(e.target);
$children.not($li).removeClass('selected');
$li.addClass('selected');
formats.hide().eq($children.index($li)).show();
})
.appendTo(request)
.children().first().trigger('click');
request.addClass('expanded');
/* $.post( '', { action: 'console_request_performed', path: req.path, nonce: '' } ); */
});
});
});
var QueryStringToHash = function QueryStringToHash (query) {
var query_string = {};
var vars = query.split("&");
for (var i=0;i