All Downloads are FREE. Search and download functionalities are using the official Maven repository.

META-INF.resources.org.richfaces.log.js Maven / Gradle / Ivy

There is a newer version: 4.3.7.Final
Show newest version
(function(jquery, richfaces) {
	var logLevels = ['debug', 'info', 'warn', 'error'];
	var logLevelsPadded = {'debug': 'debug', 'info': 'info ', 'warn': 'warn ', 'error': 'error'};
	var logLevelValues = {'debug': 1, 'info': 2, 'warn': 3, 'error': 4};

	var logClassMethods = {

		__import: function(doc, node) {
			if (doc === document) {
				return node;
			}
			
			var result = jquery();
			for (var i = 0; i < node.length; i++) {
				if (doc.importNode) {
					result = result.add(doc.importNode(node[i], true));
				} else {
					var container = doc.createElement("div");
					container.innerHTML = node[i].outerHTML;
					for (var child = container.firstChild; child; child = child.nextSibling) {
						result = result.add(child);
					}
				}
			}
			
			return result;
		},	
			
		__getStyles: function() {
			var head = jQuery("head");
			
			if (head.length == 0) {
				return "";
			}

			try {
				//TODO - BASE element support?
				var clonedHead = head.clone();
				if (clonedHead.children().length == head.children().length) {
					return clonedHead.children(":not(style):not(link[rel='stylesheet'])").remove().end().html();	
				} else {
					var result = new Array();
					head.children("style, link[rel='stylesheet']").each(function() {
						result.push(this.outerHTML);
					});
					
					return result.join('');
				}
			} catch (e) {
				return "";
			}
		},
		
		__openPopup: function() {
			if (!this.__popupWindow || this.__popupWindow.closed) {
				this.__popupWindow = open("", "_richfaces_logWindow", "height=400, width=600, resizable = yes, status=no, " +
				"scrollbars = yes, statusbar=no, toolbar=no, menubar=no, location=no");
				
				var doc = this.__popupWindow.document;
				
				doc.write("" +
						"" + this.__getStyles() + "" +
						"
"); doc.close(); this.__initializeControls(doc); } else { this.__popupWindow.focus(); } }, __hotkeyHandler: function(event) { if (event.ctrlKey && event.shiftKey) { if ((this.hotkey || 'l').toLowerCase() == String.fromCharCode(event.keyCode).toLowerCase()) { this.__openPopup(); } } }, __getTimeAsString: function() { var date = new Date(); var timeString = this.__lzpad(date.getHours(), 2) + ':' + this.__lzpad(date.getMinutes(), 2) + ':' + this.__lzpad(date.getSeconds(), 2) + '.' + this.__lzpad(date.getMilliseconds(), 3); return timeString; }, __lzpad: function(s, length) { s = s.toString(); var a = new Array(); for (var i = 0; i < length - s.length; i++) { a.push('0'); } a.push(s); return a.join(''); }, __getMessagePrefix: function(level) { return logLevelsPadded[level] + '[' + this.__getTimeAsString() + ']: '; }, __setLevelFromSelect: function(event) { this.setLevel(event.target.value); }, __initializeControls : function(doc) { var console = jquery("#richfaces\\.log", doc); var clearBtn = console.children("button.rf-log-element"); if (clearBtn.length == 0) { clearBtn = jquery("", doc).appendTo(console); } clearBtn.click(jquery.proxy(this.clear, this)); var levelSelect = console.children("select.rf-log-element"); if (levelSelect.length == 0) { levelSelect = jquery("