X-Git-Url: http://git.osdn.jp/view?a=blobdiff_plain;f=0.6.x%2Fjs%2F02_dom%2F08_XNodeSelector.js;h=1208076d2f473a3ee8cdfc6e4078d32cfb8d733b;hb=512e08f4d38eab417f9651277e8a50c08535cb07;hp=5a0857ecf2416e431eeed4c79972aa9f3f3a3313;hpb=50462b7b22a3c42bdbf2fb84d782937f817368f4;p=pettanr%2FclientJs.git diff --git a/0.6.x/js/02_dom/08_XNodeSelector.js b/0.6.x/js/02_dom/08_XNodeSelector.js index 5a0857e..1208076 100644 --- a/0.6.x/js/02_dom/08_XNodeSelector.js +++ b/0.6.x/js/02_dom/08_XNodeSelector.js @@ -1,4 +1,4 @@ -/** +/* * Original code by ofk ( kQuery, ksk ) * http://d.hatena.ne.jp/ofk/comment/20090106/1231258010 * http://d.hatena.ne.jp/ofk/20090111/1231668170 @@ -56,9 +56,6 @@ var // TODO { a : 1, A : 2, _ : 3,,, } X_Node_Selector__ALPHABET = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_-0123456789\\', X_Node_Selector__NUMBER = '+-0123456789'; - -// XMLWrapper のために今だけ外部に公開 -X_NodeSelector_parse = X_Node_Selector__parse; /* * セレクタ文字列の解析、但し一挙に行わず、ひと塊づつ @@ -81,10 +78,11 @@ function X_Node_Selector__parse( query, last ){ chr, chrCode, nameChr, name1st, tmp, escape, quot, start, name, key, value, operator, a, b, not; + query += ' '; while( i < l ){ chr = query.charAt( ++i ); - chrCode = ALPHABET.indexOf( chr ); + chrCode = ALPHABET.indexOf( chr ); // TODO この関数無くす! nameChr = chrCode !== -1; name1st = nameChr && chrCode < 52; switch( phase ){ @@ -198,7 +196,7 @@ function X_Node_Selector__parse( query, last ){ not = true; selector = 0; phase = 0x0; - name = null; + name = null; }; //continue; } else @@ -228,8 +226,32 @@ function X_Node_Selector__parse( query, last ){ return not ? [ i + tmp + 1, [ combinator, 6, result ] ] : [ i, result ]; }; - // セレクター - X[ 'Doc' ][ 'find' ] = X_shortcutFunction = Node.prototype[ 'find' ] = X_NodeList.prototype[ 'find' ] = function ( queryString ){ + /** + * selector を使って Node, NodeList を取得する + * @alias X.Doc.find + * @function + * @param {string} セレクター文字列 + * @return {Node|NodeList} + */ + X[ 'Doc' ][ 'find' ] = X_shortcutFunction = + + /** + * selector を使って Node, NodeList を取得する + * @alias NodeList.prototype.find + * @function + * @param {string} セレクター文字列 + * @return {Node|NodeList} + */ + X_NodeList.prototype[ 'find' ] = X_Node_find; + + /** + * selector を使って Node, NodeList を取得する + * @alias Node.prototype.find + * @function + * @param {string} セレクター文字列 + * @return {Node|NodeList} + */ + function X_Node_find( queryString ){ var HTML = X_Node_html, scope = this.constructor === X_NodeList && this.length ? this : [ this.constructor === Node ? this : X_Node_body ], parents = scope, // 探索元の親要素 XNodeList の場合あり @@ -259,7 +281,7 @@ function X_Node_Selector__parse( query, last ){ /*]@+debug*/ // 文字列以外は空で返す - if( typeof queryString !== 'string' ) return ret; + if( !X_Type_isString( queryString ) ) return ret; xnodes = []; @@ -271,7 +293,7 @@ function X_Node_Selector__parse( query, last ){ if( !parsed ){ parsed = X_Node_Selector__parse( queryString ); - if( typeof parsed === 'number' ){ + if( X_Type_isNumber( parsed ) ){ // error return []; }; @@ -477,7 +499,7 @@ function X_Node_Selector__parse( query, last ){ ); } else // filterが関数の場合 - if( typeof filter === 'function' ){ + if( X_Type_isFunction( filter ) ){ tmp = []; for( i = 0, n = -1; xnode = xnodes[ i ]; ++i ){ if( ( !!filter( xnode ) ) ^ isNot ) tmp[ ++n ] = xnode;