Commits

wolframkriesing committed 107b325

+ some more reflection basically

Comments (0)

Files changed (3)

dojox/docs/demos/Viewer.html

 </head>
 <body class="tundra">
 	<style>
+		body{
+			margin-top:3em;
+		}
 		.pageNavi{
 			position:fixed;
 			top:0;
+			left:300px;
 			background-color:white;
 			border:1px outset black;
 			padding:0.5em;
 				text-decoration:none;
 				color:black;
 			}
+			.quickNavi .letter .links a.inherited{
+				color:grey;
+			}
 			.quickNavi .letter .links a:hover{
 				text-decoration:underline;
 			}
 	</style>
 
-	<div class="class">
-		<div dojoType="PageNavi" moduleName="dojox.form.Rating"></div>
+	<div class="overview">
+		<div id="pageNavi" dojoType="PageNavi" moduleName="dojox.form.Rating"></div>
 		<div class="doc"></div>
 		<div class="api">
 			<h1>Methods</h1>
 					doc:reflect.module.__doc__
 				});
 				var t = new dojox.dtl.Template(templates.classDoc);
-				dojo.query(".class .doc")[0].innerHTML = t.render(c);
+				dojo.query(".overview .doc")[0].innerHTML = t.render(c);
 			}
 			
 			// Create methods section.
 		dojo.declare("PageNavi", [dijit._Widget, dojox.dtl._HtmlTemplated], {
 			//widgetsInTemplate: true,
 			templateString:
-					'<div class="pageNavi11" dojoAttachEvent="onmouseover:onMouseOver, onmouseout:onMouseOut">'
-					+'<span class="quickNavi">'
-						+'{% for key,values in tplData.items %}'
-							+'<span class="letter">{{ key.toUpperCase }}'
-								+'<div class="links">{% for v in values %}'
-									+'<a href="#{{ v }}">{{ v }}</a><br />'
-								+'{% endfor %}</div>'
-							+'</span>'
-						+'{% endfor %}'
+					'<div class="pageNavi" dojoAttachEvent="onmouseover:onMouseOver, onmouseout:onMouseOut" dojoAttachPoint="domNode">'
+						+'<span class="quickNavi">'
+							+'{% for key,values in tplData.items %}'
+								+'<span class="letter">{{ key.toUpperCase }}'
+									+'<div class="links">{% for v in values %}'
+										+'<a href="#{{ v.name }}" dojoAttachEvent="onclick:hide" class="{{ v.cssClass }}">{{ v.name }}</a><br />'
+									+'{% endfor %}</div>'
+								+'</span>'
+							+'{% endfor %}'
 						+'</span>'
-						//+'show inherited <input dojoType="dijit.form.CheckBox" value="false" dojoAttachPoint="input" />'
 					+'</div>'
 			,
 			
 			moduleName:"",
 			hideTimeout:null,
-			constructor:function(){
-				// Create quickNavi
+			constructor:function(params){
+				dojo.mixin(this, params);
 				var data = [];
-this.moduleName = "dojox.form.Rating";
-				var reflect = new dojox.lang.Reflection(this.moduleName)
-				var api = reflect.getApi();
+				this.reflect = new dojox.lang.Reflection(this.moduleName)
+				var api = this.reflect.getApi(true);
 				for (var i in api){
 					data = data.concat(dojo.map(api[i], function(x){ return x }));
 				}
 				this.data = data;
-console.log(this.data, api, this.moduleName);
 				
 				this.tplData = {};
-				//this.specials = ["^get", "^set", "^on", ".+Node$"];
-				//this.render();
-				this.tplData = this._getSortedData();
-console.log(this.tplData);
+				this._classMethods = this.reflect.getMethods(); // Get only the methods directly implemented in this.moduleName!
+				var data = this._getSortedData();
+				for (var i in data){
+					for (var j=0, l=data[i].length; j<l; j++){
+						data[i][j] = {name:data[i][j], cssClass:this._classMethods.indexOf(data[i][j])==-1 ? "inherited" : ""};
+					}
+				}
+				this.tplData = data;
 			},
+// dont use postCreate, Neil's dtl doesnt provide domNode properly in there :-(
 			
-			postCreate:function(){
-				this.inherited("postCreate", arguments);
-console.log(this.domNode);
+			__init:function(){
+				if (this.__done) return;
+				this.__done = true;
+				dojo.query(".links a", this.domNode)
+					.forEach(dojo.hitch(this, function(node){
+						node._name = dojo.trim(node.innerHTML);
+						node._isInherited = this._classMethods.indexOf(node._name)==-1;
+					}));
 			},
 			
 			onMouseOver:function(e){
-console.log("over", e, e.target);
+				this.__init();
 				if (this.hideTimeout){
 					clearTimeout(this.hideTimeout);
 					this.hideTimeout = null;
 				}
-console.log("this.domNode = ", this.domNode);
-console.log('dojo.query(".links", this.domNode) = ', dojo.query(".links", this.domNode));
 				dojo.query(".links", this.domNode).style({display:"block"});
 			},
 			
 			onMouseOut:function(e){
 				var t = e.target;
-				if (dojo.hasClass(t, "letter") || dojo.hasClass(t, "links")){
-					this.hideTimeout = setTimeout(dojo.hitch(this, "hide"), 200);
-				}
+				this.hideTimeout = setTimeout(dojo.hitch(this, "hide"), 200);
 			},
 			
 			hide:function(){
+				this.hideTimeout = null;
 				dojo.query(".links", this.domNode).style({display:"none"});
 			},
 			
-			//render:function(){
-			//	var sorted = this._getSortedData();
-			//	var c = new dojox.dtl.Context({data:sorted});
-			//	var t = new dojox.dtl.Template(this.templateString);
-			//	dojo.query(".quickNavi", this.node)[0].innerHTML = t.render(c);
-			//},
-			//
 			_getSortedData:function(){
 				var first, ret = {};
 				var d = dojo.clone(this.data);
 			
 		});
 		
-		
 dojo.require("dojox.lang.Reflection");
 dojo.require("dojox.testing.DocTest");
 var d = new dojox.testing.DocTest();

dojox/dtl/demos/demo_HtmlTemplated.html

 					dojo.require("dijit.form.Button");
 
 					dojo.declare("Fruit", [dijit._Widget, dojox.dtl._HtmlTemplated], {
-						widgetsInTemplate: true,
+						//widgetsInTemplate: true,
 						items: ["apple", "banana", "orange"],
 						keyUp: function(e){
 							if((e.type == "click" || e.keyCode == dojo.keys.ENTER) && this.input.value){
 							}
 						},
 						// Note, the load tag here is superfluous, since _HtmlTemplate has a dojo.require for it.
-						templateString: '<!--{% load dojox.dtl.contrib.dijit %}--><div><input dojoAttachEvent="onkeyup: keyUp" dojoAttachPoint="input"> <button dojoType="dijit.form.Button" dojoAttachPoint="button" dojoAttachEvent="onClick: keyUp">Add/Remove Item</button><ul><!--{% for item in items %}--><li><button dojoType="dijit.form.Button parsed" title="Fruit: {{ item }}"><!--{{ item }}--><script type="dojo/connect" event="onClick" args="e">console.debug("You clicked", this.containerNode.innerHTML);</' + 'script></button></li><!--{% endfor %}--></ul></div>'
+						templateString: '<!--{% load dojox.dtl.contrib.dijit %}--><div><input dojoAttachEvent="onkeyup: keyUp" dojoAttachPoint="input"> <button dojoType="dijit.form.Button" dojoAttachPoint="button" dojoAttachEvent="onClick: keyUp">Add/Remove Item</button><ul><!--{% for item in items %}--><li><button dojo_Type="dijit.form.Button parsed" title="Fruit: {{ item }}"><!--{{ item }}--><script type="dojo/connect" event="onClick" args="e">console.debug("You clicked", this.containerNode.innerHTML);</' + 'script></button></li><!--{% endfor %}--></ul></div>'
 					});
 
 	        dojo.require("dojo.parser");

dojox/lang/Reflection.js

 			return false;
 		},
 		
-		getApi:function(){
+		getApi:function(includeInherited){
 			// >>> var api = new dojox.lang.Reflection("dojox.lang.Reflection").getApi()
 			// >>> api.methods.indexOf("getApi")!=-1 && api.methods.indexOf("getMethods")!=-1
 			// true
-			var m = this.module;
-			// Is the current module a class?
-			if (m.prototype && m.prototype.declaredClass==this.moduleName){
-				return this._getClassApi();
-			}
-			return {};
+			var ret = {
+				methods:this.getMethods(includeInherited),
+				properties:this.getProperties()
+			};
+			return ret;
 		},
 		
 		getMethods:function(includeInherited){
 				}
 			};
 			var all = includeInherited==true;
-			var methods = this.getApi().methods;
-			if (!all){
-				var ret = [], m;
-				for (var i=0, l=methods.length; i<l; i++){
-					m = methods[i];
-					if (!this.module.superclass[m] || this.module.superclass[m].toString() != this.module.prototype[m].toString()){
-						ret.push(m);
-					}
+			var ret = [];
+			var m = this.module, p = m.prototype, s = m.superclass;
+			for (var i in p){
+				if (typeof p[i]=="function" && (all || (!s[i] || s[i].toString() != p[i].toString()))){
+					ret.push(i);
 				}
-				methods = ret;
 			}
-			return methods;
+			return ret;
 		},
 		
-		_getClassApi:function(){
-			var m = this.module;
-			var ret = {methods:[], properties:[]};
-			for (var i in m.prototype){
-				switch(typeof m.prototype[i]){
-					case "function":
-						ret.methods.push(i);
-						break;
-					default:
-						ret.properties.push(i);
-						break;
+		getProperties:function(includeInherited){
+			var all = includeInherited==true;
+			var ret = [];
+			var m = this.module, p = m.prototype, s = m.superclass;
+			for (var i in p){
+				if (typeof p[i]!="function" && (all || (""+s[i] != ""+p[i]))){
+					ret.push(i);
 				}
 			}
+			return ret;
+		},
+		
+		isInherited:function(name){
 			
-			return ret;
 		}
 	}
 );
 		}
 	}
 };
-dojox.lang.Reflection.prototype._getClassApi.__doc__ = {
-	summary:"Get the API of a class, all methods, properties, etc.",
-	params:{}
-};