/* Copyright (c) Business Objects 2006. All rights reserved. */ if (typeof(bobj.html) == 'undefined') { bobj.html = {}; } bobj.html.openTag = function(tag, atts) { var html = '<' + tag; for (var i in atts) { html += ' ' + i + '="'; var value = atts[i]; if (bobj.isArray(value)) { value = value.join(' '); } else if (bobj.isObject(value)) { // create a string of the form "foo:bar;baz:garply" var stringValue = "" for (var k in value) { stringValue += k + ':' + value[k] + ';'; } value = stringValue; } html += value + '"'; } return html + '>' }; bobj.html.closeTag = function(tag) { return ''; }; bobj.html.createHtml = function(tag, atts, innerHtml /*, innerHtml...*/) { var html = bobj.html.openTag(tag, atts); for (var i = 2; i < arguments.length; ++i) { html += arguments[i]; } html += bobj.html.closeTag(tag); return html; }; MochiKit.Iter.forEach( [ 'table', 'ul', 'ol', 'li', 'td', 'tr', 'tbody', 'thead', 'tfoot', 'th', 'input', 'span', 'a', 'div', 'img', 'button', 'tt', 'pre', 'h1', 'h2', 'h3', 'br', 'label', 'textarea', 'form', 'p', 'select', 'option', 'optgroup', 'legend', 'fieldset', 'strong', 'canvas', 'iframe', 'script', 'b' ], function(tagName) { bobj.html[tagName.toUpperCase()] = MochiKit.Base.partial(bobj.html.createHtml, tagName) }); /** * Extract scripts from an html fragment. * * @param html * [String] html fragment * * @return [Object] Returns an object with a list of scripts and html without * scripts i.e. {scripts: [{src:[String], text:[String]},...], * html:[String]} */ bobj.html.extractScripts = function(html) { // Match script tags with or without closing tags // 1 - Attributes of tag that doesn't have closing tag (e.g.