diff --git a/static/js/util.js b/static/js/util.js index 22c0cbd438..e3493f55cd 100644 --- a/static/js/util.js +++ b/static/js/util.js @@ -56,6 +56,27 @@ exports.lower_bound = function (array, arg1, arg2, arg3, arg4) { return first; }; +// Produces an easy-to-read preview on an HTML element. Currently +// only used for including in error report emails; be sure to discuss +// with other developers before using it in a user-facing context +// because it is not XSS-safe. +exports.preview_node = function (node) { + if (node.constructor === jQuery) { + node = node[0]; + } + + var tag = node.tagName.toLowerCase(); + var className = node.className.length ? node.className : false; + var id = node.id.length ? node.id : false; + + var node_preview = "<" + tag + + (id ? " id='" + id + "'" : "") + + (className ? " class='" + className + "'" : "") + + ">"; + + return node_preview; +}; + exports.same_stream_and_topic = function util_same_stream_and_topic(a, b) { // Streams and topics are case-insensitive. return ((a.stream_id === b.stream_id) &&