From 626544136e8324e77af198dad26e4ad3e51f0240 Mon Sep 17 00:00:00 2001 From: Scott Ullrich Date: Sun, 27 Jul 2008 04:30:29 +0000 Subject: Adding firebug lite --- usr/local/www/javascript/firebug-lite.js | 1000 ++++++++++++++++++++++++++++++ usr/local/www/javascript/pi.js | 682 ++++++++++++++++++++ 2 files changed, 1682 insertions(+) create mode 100644 usr/local/www/javascript/firebug-lite.js create mode 100644 usr/local/www/javascript/pi.js (limited to 'usr') diff --git a/usr/local/www/javascript/firebug-lite.js b/usr/local/www/javascript/firebug-lite.js new file mode 100644 index 0000000..e1e4cf2 --- /dev/null +++ b/usr/local/www/javascript/firebug-lite.js @@ -0,0 +1,1000 @@ +/** + * firebug lite + * v1.0 + * 04.11.2008, 8:25 PM ~ + * v1.0a + * 03.27.2008, 5:44 AM ~ 04.01.2008, 21:32 PM + * Azer Koçulu + */ + +var firebug = { + env:{ "cache":{}, "ctmp":[], "dIndex":"console", "init":false, "ml":false, "objCn":[] }, + init:function(){ + firebug.el = {}; // elements + firebug.el.content = {}; + with(firebug){ + + document.documentElement.childNodes[0].appendChild( + new pi.element("link").attribute.set("rel","stylesheet").attribute.set("href","http://firebuglite.appspot.com/firebug-lite.css").environment.getElement() + ); + + /* + * main interface + */ + el.main = new pi.element("DIV").attribute.set("id","Firebug").environment.addStyle({ "width":pi.util.GetWindowSize().width+"px" }).insert(document.body); + el.header = new pi.element("DIV").attribute.addClass("Header").insert(el.main); + el.left = {}; + el.left.container = new pi.element("DIV").attribute.addClass("Left").insert(el.main); + el.right = {}; + el.right.container = new pi.element("DIV").attribute.addClass("Right").insert(el.main); + el.main.child.add(new pi.element("DIV").environment.addStyle({ "clear":"both" })); + + /* + * buttons + */ + el.button = {}; + el.button.container = new pi.element("DIV").attribute.addClass("ButtonContainer").insert(el.header); + el.button.logo = new pi.element("A").attribute.set("title","Firebug Lite").attribute.set("target","_blank").attribute.set("href","http://getfirebug.com/lite.html").update(" ").attribute.addClass("Button Logo").insert(el.button.container); + el.button.inspect = new pi.element("A").attribute.addClass("Button").event.addListener("click",d.inspector.toggle).update("Inspect").insert(el.button.container); + el.button.maximize = new pi.element("A").attribute.addClass("Button Maximize").event.addListener("click",win.maximize).insert(el.button.container); + el.button.minimize = new pi.element("A").attribute.addClass("Button Minimize").event.addListener("click",win.minimize).insert(el.button.container); + el.button.close = new pi.element("A").attribute.addClass("Button Close").event.addListener("click",win.close).insert(el.button.container);; + + if(pi.env.ie||pi.env.webkit){ + el.button.container.environment.addStyle({ "paddingTop":"12px" }); + } + + /* + * navigation + */ + el.nav = {}; + el.nav.container = new pi.element("DIV").attribute.addClass("Nav").insert(el.left.container); + el.nav.console = new pi.element("A").attribute.addClass("Tab Selected").event.addListener("click",d.navigate.curry(window,"console")).update("Console").insert(el.nav.container); + el.nav.html = new pi.element("A").attribute.addClass("Tab").update("HTML").event.addListener("click",d.navigate.curry(window,"html")).insert(el.nav.container); + el.nav.css = new pi.element("A").attribute.addClass("Tab").update("CSS").event.addListener("click",d.navigate.curry(window,"css")).insert(el.nav.container); + el.nav.scripts = new pi.element("A").attribute.addClass("Tab").update("Script").event.addListener("click",d.navigate.curry(window,"scripts")).insert(el.nav.container); + el.nav.dom = new pi.element("A").attribute.addClass("Tab").update("DOM").event.addListener("click",d.navigate.curry(window,"dom")).insert(el.nav.container); + el.nav.xhr = new pi.element("A").attribute.addClass("Tab").update("XHR").event.addListener("click",d.navigate.curry(window,"xhr")).insert(el.nav.container); + + /* + * inspector + */ + + el.borderInspector = new pi.element("DIV").attribute.set("id","FirebugBorderInspector").event.addListener("click",listen.inspector).insert(document.body); + el.bgInspector = new pi.element("DIV").attribute.set("id","FirebugBGInspector").insert(document.body); + + /* + * console + */ + el.left.console = {}; + el.left.console.container = new pi.element("DIV").attribute.addClass("Console").insert(el.left.container); + el.left.console.mlButton = new pi.element("A").attribute.addClass("MLButton").event.addListener("click",d.console.toggleML).insert(el.left.console.container); + el.left.console.monitor = new pi.element("DIV").insert( + new pi.element("DIV").attribute.addClass("Monitor").insert(el.left.console.container) + ); + el.left.console.container.child.add( + new pi.element("DIV").attribute.addClass("InputArrow").update(">>>") + ); + el.left.console.input = new pi.element("INPUT").attribute.set("type","text").attribute.addClass("Input").event.addListener("keydown",listen.consoleTextbox).insert( + new pi.element("DIV").attribute.addClass("InputContainer").insert(el.left.console.container) + ); + + el.right.console = {}; + el.right.console.container = new pi.element("DIV").attribute.addClass("Console Container").insert(el.right.container); + el.right.console.mlButton = new pi.element("A").attribute.addClass("MLButton CloseML").event.addListener("click",d.console.toggleML).insert(el.right.console.container); + el.right.console.input = new pi.element("TEXTAREA").attribute.addClass("Input").insert(el.right.console.container); + el.right.console.run = new pi.element("A").attribute.addClass("Button").event.addListener("click",listen.runMultiline).update("Run").insert(el.right.console.container); + + el.right.console.clear = new pi.element("A").attribute.addClass("Button").event.addListener("click",d.clean.curry(window,el.right.console.input)).update("Clear").insert(el.right.console.container); + + el.button.console = {}; + el.button.console.container = new pi.element("DIV").attribute.addClass("ButtonSet").insert(el.button.container); + el.button.console.clear = new pi.element("A").attribute.addClass("Button").event.addListener("click",d.clean.curry(window,el.left.console.monitor)).update("Clear").insert(el.button.console.container); + + /* + * html + */ + + el.left.html = {}; + el.left.html.container = new pi.element("DIV").attribute.addClass("HTML").insert(el.left.container); + + el.right.html = {}; + el.right.html.container = new pi.element("DIV").attribute.addClass("HTML Container").insert(el.right.container); + + el.right.html.nav = {}; + el.right.html.nav.container = new pi.element("DIV").attribute.addClass("Nav").insert(el.right.html.container); + el.right.html.nav.computedStyle = new pi.element("A").attribute.addClass("Tab Selected").event.addListener("click",d.html.navigate.curry(firebug,"computedStyle")).update("Computed Style").insert(el.right.html.nav.container); + if(!pi.env.ie6) + el.right.html.nav.dom = new pi.element("A").attribute.addClass("Tab").event.addListener("click",d.html.navigate.curry(firebug,"dom")).update("DOM").insert(el.right.html.nav.container); + + el.right.html.content = new pi.element("DIV").attribute.addClass("Content").insert(el.right.html.container); + + el.button.html = {}; + el.button.html.container = new pi.element("DIV").attribute.addClass("ButtonSet HTML").insert(el.button.container); + + /* + * css + */ + + el.left.css = {}; + el.left.css.container = new pi.element("DIV").attribute.addClass("CSS").insert(el.left.container); + + el.right.css = {}; + el.right.css.container = new pi.element("DIV").attribute.addClass("CSS Container").insert(el.right.container); + + el.right.css.nav = {}; + el.right.css.nav.container = new pi.element("DIV").attribute.addClass("Nav").insert(el.right.css.container); + el.right.css.nav.runCSS = new pi.element("A").attribute.addClass("Tab Selected").update("Run CSS").insert(el.right.css.nav.container); + + el.right.css.mlButton = new pi.element("A").attribute.addClass("MLButton CloseML").event.addListener("click",d.console.toggleML).insert(el.right.css.container); + el.right.css.input = new pi.element("TEXTAREA").attribute.addClass("Input").insert(el.right.css.container); + el.right.css.run = new pi.element("A").attribute.addClass("Button").event.addListener("click",listen.runCSS).update("Run").insert(el.right.css.container); + el.right.css.clear = new pi.element("A").attribute.addClass("Button").event.addListener("click",d.clean.curry(window,el.right.css.input)).update("Clear").insert(el.right.css.container); + + el.button.css = {}; + el.button.css.container = new pi.element("DIV").attribute.addClass("ButtonSet CSS").insert(el.button.container); + el.button.css.selectbox = new pi.element("SELECT").event.addListener("change",listen.cssSelectbox).insert(el.button.css.container); + + /* + * scripts + */ + + el.left.scripts = {}; + el.left.scripts.container = new pi.element("DIV").attribute.addClass("Scripts").insert(el.left.container); + + el.right.scripts = {}; + el.right.scripts.container = new pi.element("DIV").attribute.addClass("Scripts Container").insert(el.right.container); + + el.button.scripts = {}; + el.button.scripts.container = new pi.element("DIV").attribute.addClass("ButtonSet Scripts").insert(el.button.container); + el.button.scripts.selectbox = new pi.element("SELECT").event.addListener("change",listen.scriptsSelectbox).insert(el.button.scripts.container); + el.button.scripts.lineNumbers = new pi.element("A").attribute.addClass("Button").event.addListener("click",d.scripts.toggleLineNumbers).update("Show Line Numbers").insert(el.button.scripts.container); + + /* + * dom + */ + + el.left.dom = {}; + el.left.dom.container = new pi.element("DIV").attribute.addClass("DOM").insert(el.left.container); + + el.right.dom = {}; + el.right.dom.container = new pi.element("DIV").attribute.addClass("DOM Container").insert(el.right.container); + + el.button.dom = {}; + el.button.dom.container = new pi.element("DIV").attribute.addClass("ButtonSet DOM").insert(el.button.container); + el.button.dom.label = new pi.element("LABEL").update("Object Path:").insert(el.button.dom.container); + el.button.dom.textbox = new pi.element("INPUT").event.addListener("keydown",listen.domTextbox).update("window").insert(el.button.dom.container); + + /* + * str + */ + + el.left.str = {}; + el.left.str.container = new pi.element("DIV").attribute.addClass("STR").insert(el.left.container); + + el.right.str = {}; + el.right.str.container = new pi.element("DIV").attribute.addClass("STR").insert(el.left.container); + + el.button.str = {}; + el.button.str.container = new pi.element("DIV").attribute.addClass("ButtonSet XHR").insert(el.button.container); + el.button.str.watch = new pi.element("A").attribute.addClass("Button").event.addListener("click",d.navigate.curry(window,"xhr")).update("Back").insert(el.button.str.container); + + /* + * xhr + */ + + el.left.xhr = {}; + el.left.xhr.container = new pi.element("DIV").attribute.addClass("XHR").insert(el.left.container); + + el.right.xhr = {}; + el.right.xhr.container = new pi.element("DIV").attribute.addClass("XHR").insert(el.left.container); + + + el.button.xhr = {}; + el.button.xhr.container = new pi.element("DIV").attribute.addClass("ButtonSet XHR").insert(el.button.container); + el.button.xhr.label = new pi.element("LABEL").update("XHR Path:").insert(el.button.xhr.container); + el.button.xhr.textbox = new pi.element("INPUT").event.addListener("keydown",listen.xhrTextbox).insert(el.button.xhr.container); + el.button.xhr.watch = new pi.element("A").attribute.addClass("Button").event.addListener("click",listen.addXhrObject).update("Watch").insert(el.button.xhr.container); + + // fix ie6 a:hover bug + if(pi.env.ie6) + { + var buttons = [ + el.button.inspect, + el.button.close, + el.button.inspect, + el.button.console.clear, + el.right.console.run, + el.right.console.clear, + el.right.css.run, + el.right.css.clear + ]; + for(var i=0; i>> console.dir("+_value+")"); + d.dom.open(_value,d.console.addLine()); + } + }, + addLine:function(){ + with (firebug) { + return new pi.element("DIV").attribute.addClass("Row").insert(el.left.console.monitor); + } + }, + openObject:function(_index){ + with (firebug) { + d.dom.open(env.objCn[_index], el.left.dom.container, pi.env.ie); + d.navigate("dom"); + } + }, + historyIndex:0, + history:[], + log:function(_values){ + with (firebug) { + if(env.init==false){ + env.ctmp.push(arguments); + return; + } + + var value = ""; + for(var i=0; i0?" ":"")+d.highlight(arguments[i],false,false,true); + } + + d.console.addLine().update(value); + d.console.scroll(); + + } + }, + print: function(_cmd,_text){ + with (firebug){ + d.console.addLine().attribute.addClass("Arrow").update(">>> "+_cmd); + d.console.addLine().update(d.highlight(_text,false,false,true)); + d.console.scroll(); + d.console.historyIndex = d.console.history.push(_cmd); + } + }, + run:function(cmd){ + with(firebug){ + if(cmd.length==0)return; + el.left.console.input.environment.getElement().value = ""; + try { + var result = eval.call(window,cmd); + d.console.print(cmd,result); + } catch(e){ + d.console.addLine().attribute.addClass("Arrow").update(">>> "+cmd); + if(!pi.env.ff){ + d.console.scroll(); + return d.console.addLine().attribute.addClass("Error").update("Error: "+(e.description||e),true); + } + if(e.fileName==null){ + d.console.addLine().attribute.addClass("Error").update("Error: "+e.message,true); + } + var fileName = e.fileName.split("\/").getLastItem(); + d.console.addLine().attribute.addClass("Error").update("Error: "+e.message+" ("+fileName+","+e.lineNumber+")",true); + d.console.scroll(); + } + d.console.scroll(); + } + }, + scroll:function(){ + with(firebug){ + el.left.console.monitor.environment.getElement().parentNode.scrollTop = Math.abs(el.left.console.monitor.environment.getSize().offsetHeight-200); + } + }, + toggleML:function(){ + with(firebug){ + var open = !env.ml; + env.ml = !env.ml; + d.navigateRightColumn("console",open); + el[open?"left":"right"].console.mlButton.environment.addStyle({ display:"none" }); + el[!open?"left":"right"].console.mlButton.environment.addStyle({ display:"block" }); + el.left.console.monitor.environment.addStyle({ "height":(open?233:210)+"px" }); + el.left.console.mlButton.attribute[(open?"add":"remove")+"Class"]("CloseML"); + } + } + }, + css:{ + index:-1, + open:function(_index){ + with (firebug) { + var item = document.styleSheets[_index]; + var uri = item.href; + if(uri.indexOf("http:\/\/")>-1&&getDomain(uri)!=document.domain){ + el.left.css.container.update("Access to restricted URI denied"); + return; + } + var rules = item[pi.env.ie ? "rules" : "cssRules"]; + var str = ""; + for (var i=0; i"; + for(var i=0; i<_css.length; i++){ + var item = _css[i]; + str += "
"+item.replace(/(.+\:)(.+)/,"$1$2;")+"
"; + } + str+="
}
"; + return str; + } + }, + refresh:function(){ + with(firebug){ + el.button.css.selectbox.update(""); + var collection = document.styleSheets; + for(var i=0; i-1){ + // NULL + if(_value==null){ + return "null"; + } + + // BOOLEAN & NUMBER + if (["boolean", "number"].indexOf(typeof _value) > -1) { + return "" + _value + ""; + } + + // FUNCTION + if(typeof _value=="function"){ + return "function()"; + } + + // STRING + return "\""+( !_inObject&&!_inArray?_value : _value.substring(0,35) ).replace(/\n/g,"\\n").replace(/\s/g," ").replace(/>/g,">").replace(/"; + } + // element + else if(isElement){ + if(_value.nodeType==3)return d.highlight(_value.nodeValue); + + if(_inArray||_inObject){ + var result = ""+_value.nodeName.toLowerCase(); + if(_value.getAttribute&&_value.getAttribute("id"))result += "#"+_value.getAttribute("id")+""; + var elClass = _value.getAttribute?_value.getAttribute(pi.env.ie?"className":"class"):""; + if(elClass)result += "."+elClass.split(" ")[0]+""; + return result+""; + } + + var result = "<"+_value.nodeName.toLowerCase()+""; + if(_value.attributes) + for(var i=0; i<_value.attributes.length; i++){ + var item = _value.attributes[i]; + if(pi.env.ie&&Boolean(item.nodeValue)==false)continue; + result += " "+item.nodeName+"=\""+item.nodeValue+"\""; + } + result += ">"; + return result; + } + // array & object + else if(isArray||["object","array"].indexOf(typeof _value)>-1){ + var result = ""; + if(isArray||_value instanceof Array){ + if(_inObject)return "["+_value.length+"]"; + result += "[ "; + + for(var i=0; i<_value.length; i++){ + if((_inObject||_inArray)&&pi.env.ie&&i>3)break; + result += (i > 0 ? ", " : "") + d.highlight(_value[i], false, true, true); + } + result += " ]"; + return result; + } + if(_inObject)return "Object"; + result += "Object"; + var i=0; + for(var key in _value){ + var value = _value[key]; + if((_inObject||_inArray)&&pi.env.ie&&i>3) + break; + result += " "+key+"="+d.highlight(value,true); + i++; + }; + result += ""; + return result; + } else { + if(_inObject) + return ""+_value+""; + return _value; + } + + } + }, + html:{ + nIndex:"computedStyle", + current:null, + highlight:function(_element,_clear,_event){ + with(firebug){ + if(_clear){ + el.bgInspector.environment.addStyle({ "display":"none" }); + return; + } + d.inspector.inspect(_element,true); + } + }, + inspect:function(_element){ + var el = _element, map = [], parent = _element; + while(parent){ + map.push(parent); + if(parent==document.body)break; + parent = parent.parentNode; + } + map = map.reverse(); + with(firebug){ + d.inspector.toggle(); + var parentLayer = el.left.html.container.child.get()[1].childNodes[1].pi; + for(var t=0; map[t];){ + if(t==map.length-1){ + + var link = parentLayer.environment.getElement().previousSibling.pi; + link.attribute.addClass("Selected"); + + if(d.html.current)d.html.current[1].attribute.removeClass("Selected"); + + d.html.current = [_element,link]; + + return;t + } + parentLayer = d.html.openHtmlTree(map[t],parentLayer,map[t+1]); + t++; + } + } + }, + navigate:function(_index,_element){ + with(firebug){ + el.right.html.nav[d.html.nIndex].attribute.removeClass("Selected"); + el.right.html.nav[_index].attribute.addClass("Selected"); + d.html.nIndex = _index; + d.html.openProperties(); + + } + }, + openHtmlTree:function(_element,_parent,_returnParentElementByElement,_event){ + with(firebug){ + var element = _element || document.documentElement, + parent = _parent || el.left.html.container, + returnParentEl = _returnParentElementByElement || null, + returnParentVal = null; + + if(parent!=el.left.html.container){ + var nodeLink = parent.environment.getParent().pi.child.get()[0].pi; + if(d.html.current)d.html.current[1].attribute.removeClass("Selected"); + nodeLink.attribute.addClass("Selected"); + + d.html.current = [_element,nodeLink]; + d.html.openProperties(); + } + + if(element.childNodes&&(element.childNodes.length==0||(element.childNodes.length==1&&element.childNodes[0].nodeType==3)))return; + parent.clean(); + + if(parent.opened&&Boolean(_returnParentElementByElement)==false){ + parent.opened = false; + parent.environment.getParent().pi.child.get()[0].pi.attribute.removeClass("Open"); + return; + } + if (parent != el.left.html.container) { + parent.environment.getParent().pi.child.get()[0].pi.attribute.addClass("Open"); + parent.opened = true; + + } + + for(var i=0; i")); + continue; + } + else if(item.childNodes&&item.childNodes.length==0)continue; + link.attribute.addClass("ParentLink"); + + } + return returnParentVal; + } + }, + openProperties:function(){ + with(firebug){ + + var index = d.html.nIndex; + var node = d.html.current[0]; + d.clean(el.right.html.content); + var str = ""; + switch(index){ + case "computedStyle": + var property = ["opacity","filter","azimuth","background","backgroundAttachment","backgroundColor","backgroundImage","backgroundPosition","backgroundRepeat","border","borderCollapse","borderColor","borderSpacing","borderStyle","borderTop","borderRight","borderBottom","borderLeft","borderTopColor","borderRightColor","borderBottomColor","borderLeftColor","borderTopStyle","borderRightStyle","borderBottomStyle","borderLeftStyle","borderTopWidth","borderRightWidth","borderBottomWidth","borderLeftWidth","borderWidth","bottom","captionSide","clear","clip","color","content","counterIncrement","counterReset","cue","cueAfter","cueBefore","cursor","direction","display","elevation","emptyCells","cssFloat","font","fontFamily","fontSize","fontSizeAdjust","fontStretch","fontStyle","fontVariant","fontWeight","height","left","letterSpacing","lineHeight","listStyle","listStyleImage","listStylePosition","listStyleType","margin","marginTop","marginRight","marginBottom","marginLeft","markerOffset","marks","maxHeight","maxWidth","minHeight","minWidth","orphans","outline","outlineColor","outlineStyle","outlineWidth","overflow","padding","paddingTop","paddingRight","paddingBottom","paddingLeft","page","pageBreakAfter","pageBreakBefore","pageBreakInside","pause","pauseAfter","pauseBefore","pitch","pitchRange","playDuring","position","quotes","richness","right","size","speak","speakHeader","speakNumeral","speakPunctuation","speechRate","stress","tableLayout","textAlign","textDecoration","textIndent","textShadow","textTransform","top","unicodeBidi","verticalAlign","visibility","voiceFamily","volume","whiteSpace","widows","width","wordSpacing","zIndex"].sort(); + var view = document.defaultView?document.defaultView.getComputedStyle(node,null):node.currentStyle; + for(var i=0; i
"+d.highlight(view[item])+"
"; + } + el.right.html.content.update(str); + break; + case "dom": + d.dom.open(node,el.right.html.content,pi.env.ie); + break; + } + } + } + }, + inspector:{ + enabled:false, + el:null, + inspect:function(_element,_bgInspector){ + var el = _element, top = el.offsetTop, left = el.offsetLeft, parent = _element.offsetParent; + while(Boolean(parent)&&parent!=document.firstChild){ + top += parent.offsetTop; + left += parent.offsetLeft; + parent = parent.offsetParent; + if(parent==document.body)break; + }; + + with(firebug){ + el[_bgInspector?"bgInspector":"borderInspector"].environment.addStyle({ + "width":_element.offsetWidth+"px", "height":_element.offsetHeight+"px", + "top":top-(_bgInspector?0:2)+"px", "left":left-(_bgInspector?0:2)+"px", + "display":"block" + }); + + if(!_bgInspector){ + d.inspector.el = _element; + } + }; + }, + toggle:function(){ + with (firebug) { + d.inspector.enabled = !d.inspector.enabled; + el.button.inspect.attribute[(d.inspector.enabled ? "add" : "remove") + "Class"]("Enabled"); + if(d.inspector.enabled==false){ + el.borderInspector.environment.addStyle({ "display":"none" }); + d.inspector.el = null; + } else if(pi.env.dIndex!="html") { + d.navigate("html"); + } + } + } + }, + scripts:{ + index:-1, + lineNumbers:false, + open:function(_index){ + with(firebug){ + d.scripts.index = _index; + el.left.scripts.container.update(""); + var script = document.getElementsByTagName("script")[_index],uri = script.src||document.location.href,source; + + if(uri.indexOf("http:\/\/")>-1&&getDomain(uri)!=document.domain){ + el.left.scripts.container.update("Access to restricted URI denied"); + return; + } + + if(uri!=document.location.href){ + source = env.cache[uri]||pi.xhr.get(uri).responseText; + env.cache[uri] = source; + } else + source = script.innerHTML; + source = source.replace(/\n|\t|<|>/g,function(_ch){ + return ({"<":"<",">":">","\t":"        ","\n":"
"})[_ch]; + }); + + if (!d.scripts.lineNumbers) + el.left.scripts.container.child.add( + new pi.element("DIV").attribute.addClass("CodeContainer").update(source) + ); + else { + source = source.split("
"); + for (var i = 0; i < source.length; i++) { + el.left.scripts.container.child.add(new pi.element("DIV").child.add(new pi.element("DIV").attribute.addClass("LineNumber").update(i + 1), new pi.element("DIV").attribute.addClass("Code").update(" " + source[i]), new pi.element("DIV").environment.addStyle({ + "clear": "both" + }))); + }; + }; + } + }, + toggleLineNumbers:function(){ + with(firebug){ + d.scripts.lineNumbers = !d.scripts.lineNumbers; + el.button.scripts.lineNumbers.attribute[(d.scripts.lineNumbers ? "add" : "remove") + "Class"]("Enabled"); + d.scripts.open( d.scripts.index ); + + } + }, + refresh:function(){ + with(firebug){ + el.button.scripts.selectbox.clean(); + var collection = document.getElementsByTagName("script"); + for(var i=0; i")) + } + } + }, + xhr:{ + objects:[], + addObject:function(){ + with(firebug){ + for(var i=0; i d.console.historyIndex ? + d.console.history[d.console.historyIndex] : + "" + ); + } + }, + cssSelectbox:function(){ + with(firebug){ + d.css.open(el.button.css.selectbox.environment.getElement().selectedIndex); + } + }, + domTextbox:function(_event){ + with(firebug){ + if(_event.keyCode==13){ + d.dom.open(eval(el.button.dom.textbox.environment.getElement().value),el.left.dom.container); + } + } + }, + inspector:function(){ + with(firebug){ + d.html.inspect(d.inspector.el); + } + }, + keyboard:function(_event){ + with(firebug){ + if(_event.keyCode==27&&d.inspector.enabled) + d.inspector.toggle(); + } + }, + mouse:function(_event){ + with(firebug){ + var target = _event[pi.env.ie?"srcElement":"target"]; + if( + d.inspector.enabled&& + target!=document.body&& + target!=document.firstChild&& + target!=document.childNodes[1]&& + target!=el.borderInspector.environment.getElement()&& + target!=el.main.environment.getElement()&& + target.offsetParent!=el.main.environment.getElement() + ) + d.inspector.inspect(target); + } + }, + runMultiline:function(){ + with(firebug){ + d.console.run.call(window,el.right.console.input.environment.getElement().value); + } + }, + runCSS:function(){ + with(firebug){ + var source = el.right.css.input.environment.getElement().value.replace(/\n|\t/g,"").split("}"); + for(var i=0; i0?collection[0]:document.body.appendChild( document.createElement("style") ); + if(!item.match(/.+\{.+\}/))continue; + if(pi.env.ie) + style.styleSheet.addRule(rule[0],rule[1]); + else + style.sheet.insertRule( rule, style.sheet.cssRules.length ); + } + } + }, + scriptsSelectbox:function(){ + with(firebug){ + d.scripts.open(parseInt(el.button.scripts.selectbox.environment.getElement().value)); + } + }, + xhrTextbox:function(_event){ + with(firebug){ + if(_event.keyCode==13){ + d.xhr.addObject.apply(window, el.button.xhr.textbox.environment.getElement().value.split(",")); + } + } + } + } +}; + +window.console = firebug.d.console; +pi.util.AddEvent(window,"resize",firebug.d.refreshSize); +pi.util.AddEvent(document,"mousemove",firebug.listen.mouse); +pi.util.AddEvent(document,"keydown",firebug.listen.keyboard); +pi.util.DOMContentLoaded.push(firebug.init); \ No newline at end of file diff --git a/usr/local/www/javascript/pi.js b/usr/local/www/javascript/pi.js new file mode 100644 index 0000000..0c37c4c --- /dev/null +++ b/usr/local/www/javascript/pi.js @@ -0,0 +1,682 @@ +(function(_scope){ + + /* + * pi.js + * 1.0 + * Azer Koçulu + * http://pi-js.googlecode.com + */ + + _scope.pi = Object(3.14159265358979323846); + var pi = _scope.pi; + pi.version = 1.0; + + pi.env = { + ie: /MSIE/i.test(navigator.userAgent), + ie6: /MSIE 6/i.test(navigator.userAgent), + ie7: /MSIE 7/i.test(navigator.userAgent), + ie8: /MSIE 8/i.test(navigator.userAgent), + firefox: /Firefox/i.test(navigator.userAgent), + opera: /Opera/i.test(navigator.userAgent), + webkit: /Webkit/i.test(navigator.userAgent) + }; + + pi.util = { + IsArray:function(_object){ + return _object && _object != window && ( _object instanceof Array || ( typeof _object.length == "number" && typeof _object.item =="function" ) ) + }, + IsHash:function(_object){ + return _object && typeof _object=="object"&&(_object==window||_object instanceof Object)&&!_object.nodeName&&!pi.util.IsArray(_object) + }, + DOMContentLoaded:[], + AddEvent: function(_element,_eventName,_fn,_useCapture){ + _element[pi.env.ie.toggle("attachEvent","addEventListener")](pi.env.ie.toggle("on","")+_eventName,_fn,_useCapture||false); + return pi.util.AddEvent.curry(this,_element); + }, + RemoveEvent: function(_element,_eventName,_fn,_useCapture){ + return _element[pi.env.ie.toggle("detachEvent","removeEventListener")](pi.env.ie.toggle("on","")+_eventName,_fn,_useCapture||false); + }, + GetWindowSize:function(){ + return { + height:pi.env.ie?Math.max(document.documentElement.clientHeight,document.body.clientHeight):window.innerHeight, + width:pi.env.ie?Math.max(document.documentElement.clientWidth,document.body.clientWidth):window.innerWidth + } + }, + Include:function(_url,_callback){ + var script = new pi.element("script").attribute.set("src",_url), callback = _callback||new Function, done = false, head = pi.get.byTag("head")[0]; + script.environment.getElement().onload = script.environment.getElement().onreadystatechange = function(){ + if(!done && (!this.readyState || this.readyState == "loaded" || this.readyState == "complete")){ + callback.call(this); + done = true; + head.removeChild(script.environment.getElement()); + } + }; + script.insert(head); + }, + Element:{ + addClass:function(_element,_class){ + if( !pi.util.Element.hasClass(_element,_class) ) + pi.util.Element.setClass(_element, pi.util.Element.getClass(_element) + " " + _class ); + }, + getClass:function(_element){ + return _element.getAttribute(pi.env.ie.toggle("className","class"))||""; + }, + hasClass:function(_element,_class){ + return pi.util.Element.getClass(_element).split(" ").indexOf(_class)>-1; + }, + removeClass:function(_element,_class){ + if( pi.util.Element.hasClass(_element,_class) ) + pi.util.Element.setClass( + _element, + pi.util.Element.getClass(_element,_class).split(" ").removeValue(_class).join(" ") + ); + }, + setClass:function(_element,_value){ + _element.setAttribute( pi.env.ie.toggle("className","class"), _value ); + }, + toggleClass:function(){ + if(pi.util.Element.hasClass.apply(this,arguments)) + pi.util.Element.removeClass.apply(this,arguments); + else + pi.util.Element.addClass.apply(this,arguments); + }, + getOpacity:function(_styleObject){ + var styleObject = _styleObject; + if(!pi.env.ie) + return styleObject["opacity"]; + + var alpha = styleObject["filter"].match(/opacity\=(\d+)/i); + return alpha?alpha[1]/100:1; + }, + setOpacity:function(_element,_value){ + if(!pi.env.ie) + return pi.util.Element.addStyle(_element,{ "opacity":_value }); + _value*=100; + pi.util.Element.addStyle(_element,{ "filter":"alpha(opacity="+_value+")" }); + return this._parent_; + }, + getPosition:function(_element){ + var parent = _element,offsetLeft = 0, offsetTop = 0, view = pi.util.Element.getView(_element); + while(parent&&parent!=document.body&&parent!=document.firstChild){ + offsetLeft +=parseInt(parent.offsetLeft); + offsetTop += parseInt(parent.offsetTop); + parent = parent.offsetParent; + }; + return { + "bottom":view["bottom"], + "left":view["left"], + "marginTop":view["marginTop"], + "marginLeft":view["marginLeft"], + "offsetLeft":offsetLeft, + "offsetTop":offsetTop, + "position":view["position"], + "right":view["right"], + "top":view["top"], + "z-index":view["zIndex"] + }; + }, + getSize:function(_element){ + var view = pi.util.Element.getView(_element); + return { + "height":view["height"], + "offsetHeight":_element.offsetHeight, + "offsetWidth":_element.offsetWidth, + "width":view["width"] + } + }, + addStyle:function(_element,_style){ + for(var key in _style){ + key = key=="float"?pi.env.ie.toggle("styleFloat","cssFloat"):key; + if (key == "opacity" && pi.env.ie) { + pi.util.Element.setOpacity(_element,_style[key]); + continue; + } + _element.style[key] = _style[key]; + } + }, + getStyle:function(_element,_property){ + _property = _property=="float"?pi.env.ie.toggle("styleFloat","cssFloat"):_property; + if(_property=="opacity"&&pi.env.ie) + return pi.util.Element.getOpacity(_element.style); + return typeof _property=="string"?_element.style[_property]:_element.style; + }, + getView:function(_element,_property){ + var view = document.defaultView?document.defaultView.getComputedStyle(_element,null):_element.currentStyle; + _property = _property=="float"?pi.env.ie.toggle("styleFloat","cssFloat"):_property; + if(_property=="opacity"&&pi.env.ie) + return pi.util.Element.getOpacity(_element,view); + return typeof _property=="string"?view[_property]:view; + } + }, + CloneObject:function(_object,_fn){ + var tmp = {}; + for(var key in _object) + { + if( pi.util.IsArray( _object[key] ) ){ + tmp[key] = Array.prototype.clone.apply( _object[key] ); + } else + if( pi.util.IsHash( _object[key] ) ){ + tmp[ key ] = pi.util.CloneObject(_object[key]); + if(_fn)_fn.call(tmp,key,_object); + } else + tmp[key] = _object[key]; + } + return tmp; + }, + MergeObjects:function(_object,_source){ + for(var key in _source){ + var value = _source[key]; + if (pi.util.IsArray(_source[key])) { + if(pi.util.IsArray( _object[key] )){ + Array.prototype.push.apply( _source[key], _object[key] ) + } + else + value = _source[key].clone(); + } + else + if (pi.util.IsHash(_source[key])) { + if (pi.util.IsHash(_object[key])) { + value = pi.util.MergeObjects(_object[key], _source[key]); + } else { + value = pi.util.CloneObject( _source[key] ); + } + } + _object[key] = value; + }; + return _object; + } + }; + + pi.get = function(){ + return document.getElementById(arguments[0]); + }; + pi.get.byTag = function(){ + return document.getElementsByTagName(arguments[0]); + }; + pi.get.byClass = function(){ return document.getElementsByClassName.apply(document,arguments); }; + + pi.base = function(){ + this.body = {}; + this.constructor = null; + + this.build = function(_skipClonning){ + var base = this, skipClonning = _skipClonning||false, _private = {}, + fn = function(){ + var _p = pi.util.CloneObject(_private); + if(!skipClonning){ + for(var key in this){ + + if(pi.util.IsArray( this[ key ] ) ){ + this[key] = Array.prototype.clone.apply( this[key] ); + } else + if( pi.util.IsHash(this[key]) ){ + this[key] = pi.util.CloneObject( + this[ key ], + function(_key,_object){ + this[ _key ]._parent_ = this; + } + ); + this[key]._parent_ = this; + } + } + }; + base.createAccessors( _p, this ); + if(base.constructor) + return base.constructor.apply(this,arguments); + return this; + }; + this.movePrivateMembers(this.body,_private); + if(this.constructor){ + fn["$Constructor"] = this.constructor; + } + fn.prototype = this.body; + return fn; + }; + + this.createAccessors = function(_p, _branch){ + var getter = function(_property){ return this[_property]; }, + setter = function(_property,_value){ this[_property] = _value; return _branch._parent_||_branch; }; + + for (var name in _p) { + var isPrivate = name.substring(0, 1) == "_", title = name.substring(1, 2).toUpperCase() + name.substring(2); + if (isPrivate) { + _branch["get" + title] = getter.curry(_p,name); + _branch["set" + title] = setter.curry(_p,name); + } + else + if (pi.util.IsHash(_p[name])){ + if(!_branch[name]) + _branch[name] = {}; + this.createAccessors(_p[name], _branch[name]); + } + }; + }; + + this.movePrivateMembers = function(_object, _branch){ + for (var name in _object) { + var isPrivate = name.substring(0, 1) == "_"; + + if (isPrivate) { + _branch[name] = _object[name]; + delete _object[name]; + } + else + if (pi.util.IsHash(_object[name])){ + _branch[name] = {}; + this.movePrivateMembers(_object[name], _branch[name]); + } + }; + }; + }; + + Function.prototype.extend = function(_prototype,_skipClonning){ + var object = new pi.base, superClass = this; + if(_prototype["$Constructor"]){ + object.constructor = _prototype["$Constructor"]; + delete _prototype["$Constructor"]; + }; + + object.body = superClass==pi.base?_prototype:pi.util.MergeObjects(_prototype,superClass.prototype,2); + object.constructor=object.constructor||function(){ + if(superClass!=pi.base) + superClass.apply(this,arguments); + }; + + return object.build(_skipClonning); + }; + + Function.prototype.curry = function(_scope){ + var fn = this, scope = _scope||window, args = Array.prototype.slice.call(arguments,1); + return function(){ + return fn.apply(scope,args.concat( Array.prototype.slice.call(arguments,0) )); + }; + }; + + pi.element = pi.base.extend({ + "$Constructor":function(_tag){ + this.environment.setElement(document.createElement(_tag||"DIV")); + this.environment.getElement().pi = this; + return this; + }, + "clean":function(){ + var childs = this.child.get(); + while(childs.length){ + childs[0].parentNode.removeChild(childs[0]); + } + }, + "clone":function(_deep){ + return this.environment.getElement().cloneNode(_deep); + }, + "insert":function(_element){ + _element = _element.environment?_element.environment.getElement():_element; + _element.appendChild(this.environment.getElement()); + return this; + }, + "insertAfter":function(_referenceElement){ + _referenceElement = _referenceElement.environment?_referenceElement.environment.getElement():_referenceElement; + _referenceElement.nextSibling?this.insertBefore(_referenceElement.nextSibling):this.insert(_referenceElement.parentNode); + return this; + }, + "insertBefore":function(_referenceElement){ + _referenceElement = _referenceElement.environment?_referenceElement.environment.getElement():_referenceElement; + _referenceElement.parentNode.insertBefore(this.environment.getElement(),_referenceElement); + return this; + }, + "query":function(_expression,_resultType,namespaceResolver,_result){ + return pi.xpath(_expression,_resultType||"ORDERED_NODE_SNAPSHOT_TYPE",this.environment.getElement(),_namespaceResolver,_result); + }, + "remove":function(){ + this.environment.getParent().removeChild( + this.environment.getElement() + ); + }, + "update":function(_value){ + ["TEXTAREA","INPUT"].indexOf(this.environment.getName())>-1? + (this.environment.getElement().value = _value): + (this.environment.getElement().innerHTML = _value); + return this; + }, + "attribute":{ + "getAll":function(_name){ + return this._parent_.environment.getElement().attributes; + }, + "clear":function(_name){ + this.set(_name,""); + return this._parent_; + }, + "get":function(_name){ + return this._parent_.environment.getElement().getAttribute(_name); + }, + "has":function(_name){ + return pi.env.ie?(this.get(_name)!=null):this._parent_.environment.getElement().hasAttribute(_name); + }, + "remove":function(_name){ + this._parent_.environment.getElement().removeAttribute(_name); + return this._parent_; + }, + "set":function(_name,_value){ + this._parent_.environment.getElement().setAttribute(_name,_value); + return this._parent_; + }, + "addClass":function(_classes){ + for (var i = 0; i < arguments.length; i++) { + pi.util.Element.addClass(this._parent_.environment.getElement(),arguments[i]); + }; + return this._parent_; + }, + "clearClass":function(){ + this.setClass(""); + this._parent_; + }, + "getClass":function(){ + return pi.util.Element.getClass( this._parent_.environment.getElement() ); + }, + "hasClass":function(_class){ + return pi.util.Element.hasClass( this._parent_.environment.getElement(), _class ); + }, + "setClass":function(_value){ + return pi.util.Element.setClass( this._parent_.environment.getElement(), _value ); + }, + "removeClass":function(_class){ + pi.util.Element.removeClass( this._parent_.environment.getElement(), _class ); + return this._parent_; + }, + "toggleClass":function(_class){ + pi.util.Element.toggleClass( this._parent_.environment.getElement(), _class ); + } + }, + "child":{ + "get":function(){ + return this._parent_.environment.getElement().childNodes; + }, + "add":function(_elements){ + for (var i = 0; i < arguments.length; i++) { + var el = arguments[i]; + this._parent_.environment.getElement().appendChild( + el.environment ? el.environment.getElement() : el + ); + } + return this._parent_; + }, + "addAfter":function(_element,_referenceElement){ + this.addBefore( + _element.environment?_element.environment.getElement():_element, + (_referenceElement.environment?_referenceElement.environment.getElement():_referenceElement).nextSibling + ); + return this._parent_; + }, + "addBefore":function(_element,_referenceElement){ + this._parent_.environment.getElement().insertBefore( + _element.environment?_element.environment.getElement():_element, + _referenceElement.environment?_referenceElement.environment.getElement():_referenceElement + ); + return this._parent_; + }, + "query":function(_tag,_attributeName,_attributeValue){ + return this._parent_.query( + "{0}{1}".format( (_tag?"{0}".format(_tag):"/*"), _attributeName||_attributeValue?"[contains(concat(' ', @{0}, ' '),' {1} ')]".format(_attributeName||"",_attributeValue||""):"" ) + ); + }, + "remove":function(_element){ + this._parent_.environment.getElement().removeChild(_element.environment?_element.environment.getElement():_element); + } + }, + "environment":{ + "_element":null, + "getParent":function(){ + return this.getElement().parentNode; + }, + "getPosition":function(){ + return pi.util.Element.getPosition(this.getElement()); + }, + "getSize":function(){ + return pi.util.Element.getSize( this.getElement() ); + }, + "addStyle":function(_styleObject){ + pi.util.Element.addStyle(this.getElement(),_styleObject); + return this._parent_; + }, + "getStyle":function(_property){ + return pi.util.Element.getStyle(_property); + }, + "getName":function(){ + return this.getElement().nodeName; + }, + "getType":function(){ + return this.getElement().nodeType; + }, + "getView":function(_property){ + return pi.util.Element.getView(this.getElement(),_property); + } + }, + "event":{ + "addListener":function(_event,_fn,_useCapture){ + pi.util.AddEvent(this._parent_.environment.getElement(),_event,_fn,_useCapture); + return this._parent_; + }, + "removeListener":function(_event,_fn,_useCapture){ + pi.util.RemoveEvent(this._parent_.environment.getElement(),_event,_fn,_useCapture); + return this._parent_; + } + } + }); + + pi.xhr = new pi.base; + pi.xhr.constructor = function(){ + var api; + if(!window.XMLHttpRequest){ + var names = ["Msxml2.XMLHTTP.6.0","Msxml2.XMLHTTP.3.0","Msxml2.XMLHTTP","Microsoft.XMLHTTP"]; + for (var i = 0; i < names.length; i++) { + try { + this.environment.setApi(new ActiveXObject(names[i])); + break; + } catch (e) { continue; } + } + } + else + this.environment.setApi(new XMLHttpRequest()); + this.environment.getApi().onreadystatechange=this.event.readystatechange.curry(this); + return this; + }; + pi.xhr.body = { + "abort":function(){ + this.environment.getApi().abort(); + }, + "send":function(){ + var url = this.environment.getUrl(), data = this.environment.getData(),dataUrl = ""; + + for (var key in data) + dataUrl += "{0}={1}&".format(key, data[key]); + + if (this.environment.getType()=="GET") + url += (url.search("\\?")==-1?"?":"&")+"{0}".format(dataUrl); + + this.environment.getApi().open(this.environment.getType(),url,this.environment.getAsync()); + + for(var key in this.environment.getHeader()) + this.environment.getApi().setRequestHeader(key,this.environment.getHeader()[key]); + + this.environment.getApi().send(this.environment.getType()=="GET"?"":dataUrl); + } + }; + pi.xhr.body.environment = { + "_async":true, "_api":null, "_cache":true, "_callback":[], "_channel":null, "_data":{}, "_header":{}, "_mimeType":null, "_multipart":false, "_type":"GET", "_timeout":0, "_url":"", + "addCallback": function(_options,_fn){ + this.getCallback().push({ "fn":_fn, "options":_options }); + }, + "addHeader": function(_key,_value){ + this.getHeader()[_key] = _value; + }, + "addData": function(_key,_value){ + this.getData()[_key] = _value; + }, + "changeCache":function(_value){ + if(_value==false){ + this.addData("forceCache",Math.round(Math.random()*10000)); + } + this.setCache(_value); + }, + "changeType": function(_value){ + if(_value=="POST"){ + this.addHeader("Content-Type","application/x-www-form-urlencoded"); + } + this.setType(_value); + } + }; + pi.xhr.body.event = { + "readystatechange":function(){ + var readyState = this.environment.getApi().readyState; + var callback=this.environment.getCallback(); + + for (var i = 0; i < callback.length; i++) { + if(callback[i].options.readyState.indexOf(readyState)>-1) + callback[i].fn.apply(this); + } + } + }; + pi.xhr = pi.xhr.build(); + + /* + * xml.xhr.get + */ + + pi.xhr.get = function(_url,_returnPiObject){ + var request = new pi.xhr(); + request.environment.setAsync(false); + request.environment.setUrl(_url); + request.send(); + return _returnPiObject?request:request.environment.getApi(); + }; + + /* + * pi.xpath + */ + + pi.xpath = function(_expression,_resultType,_contextNode,_namespaceResolver,_result){ + var contextNode = _contextNode||document, + expression = _expression||"", + namespaceResolver = _namespaceResolver||null, + result=_result||null, + resultType=_resultType||"ANY_TYPE"; + return document.evaluate(expression, contextNode, namespaceResolver, XPathResult[resultType], result); + }; + + Array.prototype.clone = function(){ + var tmp = []; + Array.prototype.push.apply(tmp,this); + tmp.forEach(function(item,index,object){ + if(item instanceof Array) + object[index] = object[index].clone(); + }); + return tmp; + }; + Array.prototype.count = function(_value){ + var count = 0; + this.forEach(function(){ + count+=Number(arguments[0]==_value); + }); + return count; + }; + + Array.prototype.forEach = Array.prototype.forEach||function(_function){ + for(var i=0; i9?87:48)); + return ((this-remain)/_system).base(_system)+String.fromCharCode(remain+(remain>9?87:48)); + }; + Number.prototype.decimal = function(_system){ + var result = 0, digit = String(this).split(""); + for(var i=0; i58)?digit[i].charCodeAt(0)-87:digit[i]); + result += digit[i]*(Math.pow(_system,digit.length-1-i)); + } + return result; + }; + Number.prototype.range = function(_pattern){ + for( + var value = String(this), isFloat = /\./i.test(value), + i = isFloat.toggle(parseInt(value.split(".")[0]),0), + end = parseInt(value.split(".")[isFloat.toggle(1,0)]), + array = []; i=0; i--) + str="\\u{0}{1}".format(String(obj[i].charCodeAt(0).base(16)).leftpad(4,"0"),str); + return str; + }; + + pi.util.AddEvent( + pi.env.ie?window:document, + pi.env.ie?"load":"DOMContentLoaded", + function(){ + for(var i=0; i