-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjslog_jq.min.js
22 lines (21 loc) · 9.64 KB
/
jslog_jq.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
/*
jslog - v1.2 - 19/Mar/2013
Copyright (C) 2013 by Abhishek Dev
MIT License @ http://bit.ly/abhishekdevMIT-License
*/
var jslog=function(d,g,i){var b=function(c,a){var f=d.extend(b.defaults,a);this.counter=0;this.config=f;this.setLogLevel(this.getOfflineState("_log_level")||c);this.ui=new b.UI(this)};b.defaults={name:"JSLOG",persistState:true,normalizeDomain:true,onLog:null,noCSSFile:false,isFormattedLogText:true,pipeConsole:true};b.levels={NONE:-1,ERROR:1,WARN:2,INFO:3,DEBUG:4};b.prototype.setLogLevel=function(c){c=""+c.toUpperCase();b.levels[c]?(this.level=c,this.setOfflineState("_log_level",c)):alert("JSLOG set with invalid level: "+
c+", setting level to NONE")};b.prototype.getLogLevel=function(){return this.level};b.prototype.isDebugEnabled=function(){return b.levels[this.getLogLevel()]>=b.levels.DEBUG};b.prototype.isInfoEnabled=function(){return b.levels[this.getLogLevel()]>=b.levels.INFO};b.prototype.isWarnEnabled=function(){return b.levels[this.getLogLevel()]>=b.levels.WARN};b.prototype.isErrorEnabled=function(){return b.levels[this.getLogLevel()]>=b.levels.ERROR};b.prototype.log=function(c,a){var f=b.levels[this.level]||
-1,e,c=c.toUpperCase();e=b.levels[c]||0;if(e===0)c="DEBUG",e=b.levels.DEBUG;f>=e&&(++this.counter,this.config.pipeConsole&&b.util.toConsole&&b.util.toConsole(c,a),this.ui.addLog(this,c,a),this.config.onLog&&this.config.onLog.call(this,c,a))};b.prototype.debug=function(c,a){this.log("DEBUG",c,a)};b.prototype.info=function(c,a){this.log("INFO",c,a)};b.prototype.warn=function(c,a){this.log("WARN",c,a)};b.prototype.error=function(c,a,f){this.log("ERROR",c+b.util.getErrorDetails(a),f)};b.prototype.clearLog=
function(){this.counter=0;this.ui.clearLog()};b.prototype.setOfflineState=function(c,a){return this.config.persistState?b.util.setOfflineState(this.config.name+c,a):null};b.prototype.getOfflineState=function(c){return this.config.persistState?b.util.getOfflineState(this.config.name+c):null};b.prototype.toString=function(){return this.ui.$log.text()};b.prototype.toArray=function(c){var a=this.toString().split("\r\n");a.pop();c===-1&&(a=a.reverse());return a};b.util={setOfflineState:function(){var c;
return window.localStorage?function(a,c){localStorage.removeItem(a);localStorage[a]=c;return true}:function(a,c){var b=a+"="+escape(c);window.location.protocol.toUpperCase()=="HTTPS:"&&(b+="; secure");document.cookie=b;return null}}(),getOfflineState:function(){var c;return window.localStorage?function(a){return localStorage[a]}:function(a){var c=a+"=",a=document.cookie,b=null,d;if(a.length>0&&(d=a.indexOf(c),d!=-1)){d+=c.length;c=a.indexOf(";",d);if(c==-1)c=a.length;b=unescape(a.substring(d,c))}return b}}(),
getFormattedTime:function(){var c=new Date,a=c.getHours(),b=c.getMinutes(),e=c.getSeconds(),c=c.getMilliseconds(),a=""+a;a+=(b<10?":0":":")+b;a+=(e<10?":0":":")+e;a+=(c<10?",0":",")+c;return a},getErrorDetails:function(c){var a="";c!=null&&c!=""&&(a="\n -- Error Info --",a+="\n name: "+c.name,a+="\n number: "+(c.number?c.number:"N/A"),a+="\n message: "+c.message,a+="\n description: "+c.description);return a},toConsole:function(){function c(a,c){var b=a.toLowerCase(),b=console[b];typeof b=="function"?
b.call(console,c):console.log(c)}return window.console?c:null}(),htmlEncode:function(c){return d("<div/>").text(c).html()}};b.UI=function(c){var a=/msie/.test(navigator.userAgent.toLowerCase());c.config.noCSSFile&&!d("#jslog_style").length&&d('<style id="jslog_style">.jslog{font-family:Tahoma,Helvetica,Arial;color:#002b36;font-size:9px;line-height:normal;letter-spacing:normal;position:fixed;_position:absolute;z-index:10000;top:2px;left:2px}.jslog select,.jslog input{font:99% Tahoma,Helvetica,Arial}.jslog .dontDisplay{display:none}.jslog .counter{cursor:pointer;position:absolute;background-color:#fdf6e3;border:1px solid #b58900;padding:2px;user-select:none;box-shadow:0 0 3px #aaa}.jslog .content{text-align:left;border:1px solid #b58900;width:400px;position:absolute;top:20px;left:0;background-color:white;box-shadow:0 0 3px #aaa}.jslog .header{padding:2px;border-bottom:1px solid #eee8d5;background-color:#fdf6e3;box-shadow:0 1px 2px #eee8d5;position:relative}.jslog .header label{color:#586e75;padding-right:3px;border-right:1px solid #bbb}.jslog .header input{cursor:pointer;color:#002b36;margin:0 1px}.jslog .header .clear{color:#268bd2;margin-left:3px}.jslog .header .close{color:#dc322f;font:monospace;cursor:pointer;display:block;height:16px;line-height:16px;overflow:hidden;position:absolute;right:1px;text-align:center;top:1px;vertical-align:middle;width:16px}.jslog .log{height:240px;overflow:auto;font-family:Consolas,"Andale Mono WT","Andale Mono","Lucida Console","Lucida Sans Typewriter","DejaVu Sans Mono","Bitstream Vera Sans Mono","Liberation Mono","Nimbus Mono L",Monaco,"Courier New",Courier,monospace;font-size:11px;margin:0;padding:0;list-style:none inside}.jslog .log li{word-wrap:break-word;border-bottom:1px solid #ccc}.jslog .log li.odd{background-color:#fff}.jslog .log li.even{background-color:#f6f6f6}.jslog .log li ins{padding:0 3px;float:left;font-weight:bold;text-decoration:none;overflow:hidden}.jslog .log li ins .noTextFormat{width:40px}.jslog .log li pre{display:none}.jslog .log li em{font-style:normal;padding:0 5px 0 3px;color:#6c71c4;*float:left;overflow:hidden}.jslog .log li.DEBUG ins{background-color:blue;color:white}.jslog .log li.INFO ins{background-color:#10ff10;color:#073642}.jslog .log li.WARN ins{background-color:yellow;color:#586e75}.jslog .log li.ERROR ins{background-color:#dc322f;color:white}.jslog .footer{display:none;padding-left:2px;border-top:1px solid black;background-color:#fdf6e3}</style>').appendTo("head");
this.isIE=a;this.name=c.config.name;this.persistState=c.config.persistState;this.build(c)};b.UI.prototype.build=function(c){var a=this,b=a.name,b=d('<div id="'+b+'_container" class="jslog"><div id="'+b+'_handle" class="counter" title="JavaScript Log Count : Double-Click to toggle details.">0</div><div id="'+b+'_body" class="content dontDisplay"><div id="'+b+'_header" class="header"><label id="'+b+'_LogLevel" >Log Level : <select id="'+b+'_selectLogLevel" class="levelList"><option id="'+b+'_noneLevel" value="NONE" >None</option><option id="'+
b+'_errorLevel" value="ERROR" >ERROR</option><option id="'+b+'_warnLevel" value="WARN" >WARN</option><option id="'+b+'_infoLevel" value="INFO" >INFO</option><option id="'+b+'_debugLevel" value="DEBUG" >DEBUG</option></select></label><input type="button" id="'+b+'_clear" class="clear" value="Clear"/><input type="button" id="'+b+'_viewPlain" class="export" value="Export"/>'+(a.toClipboard?'<input type="button" id="'+b+'_copyToClipBoard" class="copyToClpBrd" value="Copy To Clipboard"/>':"")+'<span id="'+
b+'_closeBtn" class="close" title="Close">X</span></div><ol id="'+b+'_logDisplay" class="log"></ol><div id="'+b+'_footer" class="footer"></div></div></div>'),e=a.getOfflineState("_logui_visibility");a.$me=b;a.$counter=b.children(".counter");a.$content=b.children(".content");a.$log=a.$content.children(".log");a.$me.toggleClass("noTextFormat",!c.config.isFormattedLogText);a.$content.toggleClass("dontDisplay",e=="false").find(".levelList").val(c.level);d.fn.draggable&&a.$me.draggable({containment:"document",
handle:a.$counter}).css("position","");a.$counter.bind("dblclick",function(){a.toggle()});a.$content.delegate(".clear","click",function(){c.clearLog()}).delegate(".levelList","change",function(){c.setLogLevel(this.options[this.selectedIndex].value)}).delegate(".close","click",function(){a.close()}).delegate(".export","click",function(){a.exportView()}).delegate(".copyToClpBrd","click",function(){a.toClipboard&&a.toClipboard()});d(function(){a.$me.prependTo("body")})};b.UI.prototype.destroy=function(){};
b.UI.prototype.toggle=function(){this.$content.hasClass("dontDisplay")?this.open():this.close()};b.UI.prototype.open=function(){this.$content.removeClass("dontDisplay");this.setOfflineState("_logui_visibility",true)};b.UI.prototype.close=function(){this.$content.addClass("dontDisplay");this.setOfflineState("_logui_visibility",false)};b.UI.prototype.clearLog=function(){this.$counter.text(0);this.$log.empty()};b.UI.prototype.addLog=function(c,a,f){var e=b.util.getFormattedTime(),g=a,h="</div></li>";
c.config.isFormattedLogText&&(e+=Array(14-e.length).join(" "),a+=Array(7-a.length).join(" "),h=" "+h);a="<li><ins>"+a+"</ins><em>"+e+"</em><span>"+b.util.htmlEncode(f)+'</span><div style="clear: both;">'+h;a=d(a);a.addClass((c.counter%2==0?"odd":"even")+" "+g);this.$counter.text(c.counter);this.$log.prepend(a)};b.UI.prototype.setOfflineState=function(c,a){return this.persistState?b.util.setOfflineState(this.name+c,a):null};b.UI.prototype.getOfflineState=function(c){return this.persistState?
b.util.getOfflineState(this.name+c):null};b.UI.prototype.toUIString=function(c){var a="";this.isIE?(a=this.$log.html().replace(/\r\n/g,"_jslog_LINEBREAK"),a=d(a).text(),a=b.util.htmlEncode(a).replace(/_jslog_LINEBREAK/g,c?"<br/>":"\r\n")):(a=this.$log.text(),a=b.util.htmlEncode(a));return a};if(window.clipboardData)b.UI.prototype.toClipboard=function(){var b=this.toUIString();window.clipboardData.setData("text",b);alert("Logs copied to clipboard")};b.UI.prototype.exportView=function(){var b=window.open("",
"jsLogger","width=750, height=400, location=0, resizable=1, menubar=1, scrollbars=1"),a;b&&(a=this.toUIString(true),b.document.write('<html><head><title>jsLog : Export View</title></head><body onLoad="self.focus()"><pre>'+a+"</pre></body></html>"))};return function(){var c=d("html").data("jslog"),a=function(){};a.prototype=d.extend({counter:0,config:{},clearLog:a,debug:a,error:a,getLogLevel:a,getOfflineState:a,info:a,isDebugEnabled:a,isInfoEnabled:a,isWarnEnabled:a,log:a,setLogLevel:a,setOfflineState:a,
toArray:a,toString:a,warn:a},i);return c===true?new b(g):new a}()}(jQuery,"DEBUG",{});