/**
* jQuery dump plugin. Inspect object properties in a popup window.
*
* Copyright (c) 2012 Block Alexander
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*/
(function ($) {
var __jqdump__dump_OFF = false; // global OFF switch
var position = { left: 100, top: 120 }; // popup window position
var defaultDepth = 2; // default dump depth
/**
* Dump object content in popup window with prettyprint and subnavigation
*
*
* // dump navigator properties
* $.dump(window.navigator, 1, "window.navigator");
*
* // this may be used to disable all following function calls
* $.dump("off");
*
*
* @param(obj): object to dump, or "off" string to disable all dump calls
* @param(iDepth): number, optional dumping depth, default 2
* @param(sHistoryPath): string, optional global properties path relative to the initial dump object value, used for display only.
* @returns: null
*/
$.dump = function (obj, iDepth, sHistoryPath) {
if (typeof(obj) == "string" && /^off$/i.test(obj)) { __jqdump__dump_OFF = true; }
return __jqdump__dump(obj, iDepth, sHistoryPath);
};
/**
* Dump object content in popup window with prettyprint and subnavigation
*
*
* $("#element").dump(1);
* // same as
* $.dump($("#element"), 1, "(#element)");
*
*
* Call type: window.dump/$.dump( ... )
* @param(iDepth): number, optional dumping depth, default 2
* @returns: null
*/
$.fn.dump = function (iDepth) {
return __jqdump__dump(this, iDepth, this.selector? "("+ this.selector +")" : "");
};
/**
* Dump object content in popup window with prettyprint and subnavigation
*
* @param(obj): object to dump
* @param(iDepth): number, optional dumping depth, default 2
* @param(sHistoryPath): string, optional global properties path relative to the initial dump object value, used for display only.
* @returns: null
*/
function __jqdump__dump (obj, iDepth, sHistoryPath) {
if (__jqdump__dump_OFF) { return null; }
// store current object value to allow continious/recursive dump browsing via window.opener.__jqdump__
__jqdump__ = {data: obj, dump: __jqdump__dump };
// provide defaults as needed
iDepth = (typeof(iDepth) == "number" && iDepth > 0? parseInt(iDepth, 10) : defaultDepth);
sHistoryPath = (typeof(sHistoryPath) == "string" && sHistoryPath.length > 0? sHistoryPath : "OBJECT");
// adjust new window position
position = { top: (position.top - 30) % 120, left: (position.left - 10) % 100 };
// try to popup blank page
var dumpWindow = window.open("about:blank", "_blank"
, "width=600,height=800,menubar=0,left="+ position.left +",top="+ position.top
+",location=0,toolbar=0,status=0,scrollbars=1,resizable=1", true);
// popup blocked?
if (!dumpWindow || dumpWindow.closed == true) {
if (confirm("Dump Window couldn't showup cause of popup blocker.\nContinue using current window?")) {
dumpWindow = window;
} else {
return null;
}
}
// fill the page with dump content
dumpWindow.document.write("