Changeset 27806
- Timestamp:
- 01/03/09 08:32:48 (4 years ago)
- Location:
- lang/javascript/tagBuilder
- Files:
-
- 1 added
- 2 modified
-
TagBuilder.class.js (modified) (4 diffs)
-
sample3.html (modified) (1 diff)
-
sample4.html (added)
Legend:
- Unmodified
- Added
- Removed
-
lang/javascript/tagBuilder/TagBuilder.class.js
r27756 r27806 23 23 if (this.expr instanceof Array) return this.expr[0].toLowerCase(); 24 24 }, 25 tagNameIs: function (t) { 26 return this.getTagName().eqi(t.toLowerCase()); 27 }, 28 isTr: function (t) { 29 if (this.tagNameIs("tr")) { 30 checkTagName(this.parent.tagName,"table"); 31 return true; 32 } 33 return false; 34 }, 25 35 get: function () { 26 36 return this.target.value; … … 51 61 }, 52 62 remove: function () { 53 if (this.parent && !this.parent.removeChild) {63 if (this.parent && !this.parent.removeChild) { 54 64 alert(Object.toJSON(this.parent)); 55 65 } 56 66 if (!this.parent) alert("Parent is null"); 67 if (this.isTr()) { 68 var target=this.target; 69 var rmIdx=-1; 70 $A(this.parent.rows).each(function (e,idx) { 71 if (e===target) { 72 rmIdx=idx; 73 } 74 }); 75 if (rmIdx<0) alert("Index not found"); 76 this.parent.deleteRow(rmIdx); 77 return; 78 } 57 79 this.parent.removeChild(this.target); 58 80 }, 59 81 insertBefore:function (e,idx) { 82 if (idx==null) idx=0; 83 checkNull(this.parentBuilder,"parentBuilder").add( 84 e, 85 this.indexFromParent()-idx 86 ); 87 }, 88 insertAfter:function (e,idx) { 89 if (idx==null) idx=0; 90 checkNull(this.parentBuilder,"parentBuilder").add( 91 e, 92 this.indexFromParent()+1+idx 93 ); 94 }, 95 indexFromParent: function () { 96 var res=-1; 97 this.getSiblings().each(function (e,i) { 98 if (e===t.target) res=i; 99 }); 100 if (res<0) alert("Index not found"); 101 return res; 102 }, 103 getSiblings: function () { 104 if (this.target==null) alert("getSiblings: Target is not set"); 105 if (this.siblings) return this.siblings; 106 if (this.isTr()) { 107 return this.siblings=$A(this.parent.rows); 108 } 109 return this.siblings=$A(this.childNodes); 110 }, 60 111 add:function (a, idx) { 61 112 var target=this.target; … … 67 118 if (a instanceof Array) return this.addArray(a,idx); 68 119 if (a instanceof Function) return a(this,idx); 69 if (a instanceof TagBuilder) {a.render(target,idx);return this;} 120 if (a instanceof TagBuilder) { 121 a.parentBuilder=this; 122 a.render(target,idx); 123 return this; 124 } 70 125 if (typeof(a)=="object" && a.render instanceof Function) { 71 126 a.render(this,idx);return this; … … 170 225 return typeof(e)=="object" && e.tagName; 171 226 } 227 function checkNull(v,msg){ 228 if (v==null) alert(msg+" is null"); 229 return v; 230 } 172 231 173 232 function tag(a) { -
lang/javascript/tagBuilder/sample3.html
r27754 r27806 4 4 <script src="prototype.js"></script> 5 5 <script src="TagBuilder.class.js"></script> 6 <script src="misc/WindowWidget.class.js"></script>7 <script src="misc/Mouse.js"></script>8 6 <script> 9 7 var list; 8 var data=["foo","bar","baz"]; 10 9 function exec() { 11 10 $tag("button").target.disabled=true; 12 var w=new WindowWidget(["span","test"]); 13 w.show(); 11 $tag("body").add(["table",{border:1}, 12 ["tr",["td","No"],["td","Str"],["td","Button"]], 13 function (tagBuilder) { 14 data.each(function (str,no) { 15 var tr=tag("tr", 16 ["td",no], 17 ["td",str], 18 ["td",["button",{onclick:rm},"Remove"]] 19 ); 20 tagBuilder.add(tr); 21 function rm() { 22 tr.remove(); 23 } 24 }); 25 } 26 ]); 14 27 } 15 28 </script> 16 29 </head> 17 <body 18 onmousemove="Mouse.handleEvents(event,'move')" 19 onmousedown="Mouse.handleEvents(event,'down')" 20 onmouseup="Mouse.handleEvents(event,'up')"> 30 <body id="body"> 21 31 <h1>Tag Builder Test 3</h1> 22 <p>* Requires programs on ./misc/ directory </p>23 32 <button id="button" onclick="exec()">Start</button> 24 33 </body>
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)