Fixed the stupid parent() bug.
[jquery.git] / tmpl / tmpl.js
1 $.fn.get = function(i) {
2         return i == null ?
3                 this.$$unclean ? $.sibling(this.$$unclean[0]) : this.cur :
4                         (this.get())[i];
5 };
6
7 $.fn._get = function(i) {
8         return i == null ? this.cur : this.cur[i];
9 };
10
11 $.fn.set = function(a,b) {
12         return this.each(function(){
13                 if ( b == null )
14                         for ( var j in a )
15                                 this[$.attr(j)] = a[j];
16                 else {
17                         if ( b.constructor != String ) { // TODO: Fix this
18                                 for ( var i in b ) {    
19                                         var c = $.Select(i,this);
20                                         for ( var j in c )
21                                                 c[j][$.attr(a)] = b[i];
22                                 }
23                         } else
24                                 this[$.attr(a)] = b;
25                 }
26         });
27 };
28
29 function $C(a) {
30   if ( a.indexOf('<') >= 0 ) {
31     if ( a.indexOf('<tr') >= 0 ) {
32       var r = $C("table").html("<tbody>"+a+"</tbody>");
33       r.$$unclean = r.get(0).childNodes[0].childNodes;
34     } else {
35       var r = $C("div").html(a);
36       r.$$unclean = r.get(0).childNodes;
37     }
38     return r;
39   } else {
40     return $(document.createElement(a),document);
41   }
42 };
43
44 $.fn.appendTo = function() {
45         var self = this;
46         var a = arguments;
47         return this.each(function(){
48                 for ( var i = 0; i < a.length; i++ ) {
49                         if ( self.$$unclean )
50                                 $(a[i]).append( self.get() );
51                         else
52                                 $(a[i]).append( this );
53                 }
54         });
55 };
56
57 $.clean = function(a) {
58         var r = [];
59         for ( var i = 0; i < a.length; i++ ) {
60                 if ( a[i].constructor == String ) {
61                         // Cool, but has scary side-effects
62                         //a[i] = a[i].replace( /#([a-zA-Z0-9_-]+)/g, " id='$1' " );
63                         //a[i] = a[i].replace( /\.([a-zA-Z0-9_-]+)/g, " class='$1' " );
64                         var div = document.createElement("div");
65                         div.innerHTML = a[i];
66                         for ( var j = 0; j < div.childNodes.length; j++ )
67                                 r[r.length] = div.childNodes[j];
68                 } else if ( a[i].length ) {
69                         for ( var j = 0; j < a[i].length; j++ )
70                                 r[r.length] = a[i][j];
71                 } else {
72                         r[r.length] = a[i];
73                 }
74         }
75         return r;
76 };
77
78 // Frequently-used Accessors
79 window.cssQuery = $.Select;
80 document.getElementsByClass = function(a){return $.Select("."+a)};
81 document.getElementsBySelector = $.Select;
82
83         
84         // Make Xpath Axes Sane
85         //var re = new RegExp( "/?descendant::", "i" );
86         //t = t.replace( re, " " );
87         //var re = new RegExp( "/?child::", "i" );
88         //t = t.replace( re, "/" );
89         // If only...
90         //var re = new RegExp( "/?following-sibling::", "i" );
91         //t = t.replace( re, " + " );
92         //var re = new RegExp( "/?preceding-sibling::", "i" );
93         //t = t.replace( re, " ~ " );
94         //var re = new RegExp( "/?self::", "i" );
95         //t = t.replace( re, "" );
96         //var re = new RegExp( "/?parent::", "i" );
97         //t = t.replace( re, " .. " );
98         
99         // following
100         // preceding
101         // ancestor
102         // ancestor-or-self
103         // descendant-or-self
104
105 // Deprecated
106 //style: function(a,b){ return this.css(a,b); },