UNPKG

spservices

Version:

Work with SharePoint's Web Services using jQuery

72 lines (65 loc) 3.29 kB
define([ 'jquery', '../core/SPServices.utils', //--------------------------- // We don't need local variables for these dependencies // because they are added to the jQuery namespace. '../core/SPServices.core.js' ], function ( $, utils ) { "use strict"; // Utility function to show the results of a Web Service call formatted well in the browser. $.fn.SPServices.SPDebugXMLHttpResult = function (options) { var opt = $.extend({}, { node: null, // An XMLHttpResult object from an ajax call indent: 0 // Number of indents }, options); var i; var NODE_TEXT = 3; var NODE_CDATA_SECTION = 4; var outString = ""; // For each new subnode, begin rendering a new TABLE outString += "<table class='ms-vb' style='margin-left:" + opt.indent * 3 + "px;' width='100%'>"; // DisplayPatterns are a bit unique, so let's handle them differently if (opt.node.nodeName === "DisplayPattern") { outString += "<tr><td width='100px' style='font-weight:bold;'>" + opt.node.nodeName + "</td><td><textarea readonly='readonly' rows='5' cols='50'>" + opt.node.xml + "</textarea></td></tr>"; // A node which has no children } else if (!opt.node.hasChildNodes()) { outString += "<tr><td width='100px' style='font-weight:bold;'>" + opt.node.nodeName + "</td><td>" + ((opt.node.nodeValue !== null) ? utils.checkLink(opt.node.nodeValue) : "&nbsp;") + "</td></tr>"; if (opt.node.attributes) { outString += "<tr><td colspan='99'>" + utils.showAttrs(opt.node) + "</td></tr>"; } // A CDATA_SECTION node } else if (opt.node.hasChildNodes() && opt.node.firstChild.nodeType === NODE_CDATA_SECTION) { outString += "<tr><td width='100px' style='font-weight:bold;'>" + opt.node.nodeName + "</td><td><textarea readonly='readonly' rows='5' cols='50'>" + opt.node.parentNode.text + "</textarea></td></tr>"; // A TEXT node } else if (opt.node.hasChildNodes() && opt.node.firstChild.nodeType === NODE_TEXT) { outString += "<tr><td width='100px' style='font-weight:bold;'>" + opt.node.nodeName + "</td><td>" + utils.checkLink(opt.node.firstChild.nodeValue) + "</td></tr>"; // Handle child nodes } else { outString += "<tr><td width='100px' style='font-weight:bold;' colspan='99'>" + opt.node.nodeName + "</td></tr>"; if (opt.node.attributes) { outString += "<tr><td colspan='99'>" + utils.showAttrs(opt.node) + "</td></tr>"; } // Since the node has child nodes, recurse outString += "<tr><td>"; for (i = 0; i < opt.node.childNodes.length; i++) { outString += $().SPServices.SPDebugXMLHttpResult({ node: opt.node.childNodes.item(i), indent: opt.indent + 1 }); } outString += "</td></tr>"; } outString += "</table>"; // Return the HTML which we have built up return outString; }; // End $.fn.SPServices.SPDebugXMLHttpResult return $; });