From: itozyun Date: Tue, 11 Feb 2014 21:50:54 +0000 (+0900) Subject: Version 0.6.17, X.Dom.Query work a little. X-Git-Url: http://git.osdn.jp/view?a=commitdiff_plain;h=df4575c24267b984d159fa0e69a60831d18bdc8d;p=pettanr%2FclientJs.git Version 0.6.17, X.Dom.Query work a little. --- diff --git a/0.4.x/test/index.html b/0.4.x/test/index.html index 01f0bb4..d99f1ce 100644 --- a/0.4.x/test/index.html +++ b/0.4.x/test/index.html @@ -35,6 +35,8 @@

テストインデックス

ぺったんR html 実証サンプル

+
version 0.4 (14.01.11)
+
ぺったんR html 実証サンプル version 0.4
version 0.3 (13.09.23)
ぺったんR html 実証サンプル version 0.3
version 0.2 (13.08.10)
diff --git a/0.6.x/js/core/00_X.js b/0.6.x/js/core/00_X.js index 5dfe13e..93757f8 100644 --- a/0.6.x/js/core/00_X.js +++ b/0.6.x/js/core/00_X.js @@ -1,9 +1,9 @@ -if( !window['console'] ) console = { log : function(){} }; +if( !window['console'] ) console = { log : function(a){alert(a)} }; var undefined, X = X || { - VERSION : '0.6.13', + VERSION : '0.6.17', bootTime : + new Date, @@ -11,11 +11,13 @@ var undefined, emptyFunction : new Function, + // defer の場合もあるので、document.readyState を見る inHead : (function( s ){ + if( !s ) return; s = s[ s.length - 1 ]; // Dom0 || Dom1 return ( s.parentElement || s.parentNode ).tagName.toLowerCase() === 'head'; - })( document.scripts || document.getElementsByTagName( 'script' ) || document.all.tags( 'script' ) ), + })( document.scripts || document.getElementsByTagName && document.getElementsByTagName( 'script' ) || document.all && document.all.tags( 'script' ) ), parse : function( v ){ var _v, n; @@ -39,23 +41,6 @@ var undefined, return v; }, - skipCleanupTagNames : 'pre,textarea,code,kbd,samp,xmp,plaintext,listing'.split( ',' ), - - cleanupWhiteSpace : function( text ){ - var _ = ' ', __ = ' '; - text.indexOf( '\r\n' ) !== -1 && ( text = text.split( '\r\n' ).join( _ ) ); - text.indexOf( '\n\r' ) !== -1 && ( text = text.split( '\n\r' ).join( _ ) ); - text.indexOf( '\t' ) !== -1 && ( text = text.split( '\t' ).join( _ ) ); - text.indexOf( '\r' ) !== -1 && ( text = text.split( '\r' ).join( _ ) ); - text.indexOf( '\n' ) !== -1 && ( text = text.split( '\n' ).join( _ ) ); - text.indexOf( '\f' ) !== -1 && ( text = text.split( '\f' ).join( _ ) ); - text.indexOf( '\b' ) !== -1 && ( text = text.split( '\b' ).join( _ ) ); - while( text.indexOf( __ ) !== -1 ){ - text = text.split( __ ).join( _ ); - }; - return text; - }, - isEmptyObject : function( v ){ if( v.length !== 0 ) return false; for( var p in v ){ @@ -70,6 +55,10 @@ var undefined, if( array1.indexOf( array2[ --i ] ) === -1 ) return false; }; return true; + }, + + findFromArray : function( fakeArray, elm ){ + } }; diff --git a/0.6.x/js/core/00_builtin.js b/0.6.x/js/core/00_builtin.js index f2a5207..71dc2cd 100644 --- a/0.6.x/js/core/00_builtin.js +++ b/0.6.x/js/core/00_builtin.js @@ -12,7 +12,10 @@ Function.prototype.apply || (Function.prototype.apply = function (x, y) { if( x === window ){ x.__apply = void 0; } else { - delete x.__apply ? x.__apply : x.constructor.prototype.__apply ; + if( x.constructor && x.constructor.prototype.__apply ){ + delete x.__apply; + } else + if( x.__apply ) delete x.__apply; }; x.__apply = this; @@ -41,7 +44,11 @@ Function.prototype.apply || (Function.prototype.apply = function (x, y) { if( x === window ){ x.__apply = void 0; } else { - delete x.__apply ? x.__apply : x.constructor.prototype.__apply ; + //delete x.__apply ? x.__apply : x.constructor.prototype.__apply ; + if( x.constructor && x.constructor.prototype.__apply ){ + delete x.__apply; + } else + if( x.__apply ) delete x.__apply; }; return r; }); @@ -161,7 +168,7 @@ window.decodeURI || (window.decodeURI = function (x) { */ // 手抜き -window.decodeURIComponent || (window.decodeURIComponent = window.decodeURI); +//window.decodeURIComponent || (window.decodeURIComponent = window.decodeURI); /* @@ -169,6 +176,7 @@ window.decodeURIComponent || (window.decodeURIComponent = window.decodeURI); */ // replace(RegExp, Function)対応 +/* if (window.ActiveXObject ? !Number.prototype.toFixed : (!navigator.taintEnabled && !document.createElement("input").setSelectionRange)) (function () { var g = String.prototype.replace; @@ -204,4 +212,6 @@ if (window.ActiveXObject ? !Number.prototype.toFixed : (!navigator.taintEnabled } return g.call(s, x, z); }; - })(); \ No newline at end of file + })(); */ + + diff --git a/0.6.x/js/core/06_XEventDispatcher.js b/0.6.x/js/core/06_XEventDispatcher.js index 0cf8f6c..5c4aac4 100644 --- a/0.6.x/js/core/06_XEventDispatcher.js +++ b/0.6.x/js/core/06_XEventDispatcher.js @@ -10,12 +10,21 @@ X.EventDispatcher = _dispatching : 0, // dispatch 中の unlisten で使用 _unlistens : null, // dispatch 中の unlisten で使用 _needsIndex : false, // listening で index を返す + _reserves : null, _killReserved : false, listen : function( type, arg1, arg2, arg3 ){ var list = this._listeners, - f; + r, f; + if( this._dispatching ){ + // todo + // reserve + if( !this._reserves ) this._reserves = []; + this._reserves[ this._reserves.length ] = [ type, arg1, arg2, arg3 ]; + return this; + } else if( this.listening( type, arg1, arg2, arg3 ) ) return this; + if( !list ) list = this._listeners = {}; if( !( list = list[ type ] ) ) list = this._listeners[ type ] = []; list[ list.length ] = f = @@ -33,7 +42,7 @@ X.EventDispatcher = }, unlisten : function( type, arg1, arg2, arg3 ){ var list = this._listeners, - i, f; + unlistens, i, f; if( !list ) return this; if( type === undefined ){ // 全て削除 @@ -51,14 +60,27 @@ X.EventDispatcher = return this; }; + if( this._reserves ){ + for( i = this._reserves.length; i; ){ + f = this._reserves[ --i ]; + if( f[ 0 ] === type && f[ 1 ] === arg1 && f[ 2 ] === arg2 && f[ 3 ] === arg3 ){ + this._reserves.splice( i, 1 ); + if( !this._reserves.legth ) delete this._reserves; + return this; + }; + }; + }; + this._needsIndex = true; i = this.listening( type, arg1, arg2, arg3 ); delete this._needsIndex; if( i === false ) return this; f = ( list = list[ type ] )[ i ]; - if( this._dispatching ){ - this._unlistens[ this._unlistens.length ] = f; + if( unlistens = this._unlistens ){ + ( unlistens = unlistens[ type ] ) ? + ( unlistens[ unlistens.length ] = f ) : + ( this._unlistens[ type ] = [ f ] ); } else { delete f.once; f.kill === X.Callback._kill && f.kill(); @@ -71,10 +93,16 @@ X.EventDispatcher = return this; }, listening : function( type, arg1, arg2, arg3 ){ - var list = this._listeners, i, f; + var list = this._listeners, unlistens, i, f; if( type === undefined ) return !!list; if( !list || !( list = list[ type ] ) ) return false; if( arg1 === undefined ) return true; + if( ( unlistens = this._unlistens ) && ( unlistens = unlistens[ type ] ) ){ + for( i = unlistens.length; i; ){ + f = unlistens[ --i ]; + if( f === arg1 || ( f.same && f.same( arg1, arg2, arg3 ) ) ) return false; + }; + }; for( i = list.length; i; ){ f = list[ --i ]; if( f === arg1 || ( f.same && f.same( arg1, arg2, arg3 ) ) ) return this._needsIndex ? i : true; @@ -89,25 +117,30 @@ X.EventDispatcher = */ dispatch : function( e ){ // dispatch 中の listen は? - var list = this._listeners, - ret = X.Callback.NONE, - i, f, r, sysOnly; + var list = this._listeners, + ret = X.Callback.NONE, + type = e.type, + unlistens, i, l, f, r, sysOnly; - if( !list || !( list = list[ e.type ] ) ) return ret; + if( !list || !( list = list[ type ] ) ) return ret; ++this._dispatching; - this._unlistens = this._unlistens || []; + + // todo: + // type も保存 + this._unlistens = this._unlistens || {}; + unlistens = this._unlistens[ type ]; for( i = 0; i < list.length; ++i ){ f = list[ i ]; - if( this._unlistens.length && this._unlistens.indexOf( f ) !== -1 ){ - continue; - }; + if( unlistens && unlistens.indexOf( f ) !== -1 ) continue; r = typeof f === 'function' ? f( e ) : f.handleEvent( e ); if( f.once === true || r & X.Callback.UN_LISTEN ){ - this._unlistens[ this._unlistens.length ] = f; + unlistens ? + ( unlistens[ unlistens.length ] = f ) : + ( unlistens = this._unlistens[ type ] = [ f ] ); }; if( r & X.Callback.STOP_NOW ){ @@ -118,13 +151,30 @@ X.EventDispatcher = if( ( --this._dispatching ) === 0 ){ // dispatch 中に unlisten された要素の削除 - for( i = this._unlistens.length ; i; ){ - this.unlisten( e.type, this._unlistens[ --i ] ); - }; + unlistens = this._unlistens; delete this._dispatching; - delete this._unlistens; + delete this._unlistens; + + for( type in unlistens ){ + list = unlistens[ type ]; + for( i = list.length; i; ){ + this.unlisten( type, list[ --i ] ); + }; + unlistens.length = 0; + }; - this._killReserved && this.kill(); + if( this._killReserved ){ + this.kill(); + } else + if( list = this._reserves ){ + for( i = 0, l = list.length; i < l; ++i ){ + f = list[ i ]; + this.listen( f[ 0 ], f[ 1 ], f[ 2 ], f[ 3 ] ); + f.length = 0; + }; + list.length = 0; + delete this._reserves; + }; }; return ret; diff --git a/0.6.x/js/dom/10_XDom.js b/0.6.x/js/dom/10_XDom.js index 0cdeed8..d51ae76 100644 --- a/0.6.x/js/dom/10_XDom.js +++ b/0.6.x/js/dom/10_XDom.js @@ -114,16 +114,23 @@ })( window, document ); -X.Dom.Dirty = { - CLEAN : 0, - TREE : 1, // width, height, x, y - CONTENT : 2, // width, height, x, y textNode の内容 - CLASSNAME : 4, // _getCharSize, width, height, x, y - CSS : 8, // _getCharSize, width, height, x, y - ATTR : 16 // _getCharSize, width, height, x, y +X.Dom.skipCleanupTagNames = 'pre,textarea,code,kbd,samp,xmp,plaintext,listing'.split( ',' ); + +X.Dom.cleanupWhiteSpace = function( text ){ + var _ = ' ', __ = ' '; + text.indexOf( '\r\n' ) !== -1 && ( text = text.split( '\r\n' ).join( _ ) ); + text.indexOf( '\n\r' ) !== -1 && ( text = text.split( '\n\r' ).join( _ ) ); + text.indexOf( '\t' ) !== -1 && ( text = text.split( '\t' ).join( _ ) ); + text.indexOf( '\r' ) !== -1 && ( text = text.split( '\r' ).join( _ ) ); + text.indexOf( '\n' ) !== -1 && ( text = text.split( '\n' ).join( _ ) ); + text.indexOf( '\f' ) !== -1 && ( text = text.split( '\f' ).join( _ ) ); + text.indexOf( '\b' ) !== -1 && ( text = text.split( '\b' ).join( _ ) ); + while( text.indexOf( __ ) !== -1 ){ + text = text.split( __ ).join( _ ); + }; + return text; }; - /* * original * AS3で相対パスを絶対パスに変換する @@ -162,3 +169,13 @@ X.Dom.getAbsolutePath = function( path ){ }; return [ _ary[ 0 ], ss, ary.join( s ), s, path ].join( '' ); }; + + +X.Dom.Dirty = { + CLEAN : 0, + TREE : 1, // width, height, x, y + CONTENT : 2, // width, height, x, y textNode の内容 + CLASSNAME : 4, // _getCharSize, width, height, x, y + CSS : 8, // _getCharSize, width, height, x, y + ATTR : 16 // _getCharSize, width, height, x, y +}; \ No newline at end of file diff --git a/0.6.x/js/dom/11_XDomNode.js b/0.6.x/js/dom/11_XDomNode.js index 960cc1f..cf650fb 100644 --- a/0.6.x/js/dom/11_XDomNode.js +++ b/0.6.x/js/dom/11_XDomNode.js @@ -21,6 +21,7 @@ X.Dom.Node = X.EventDispatcher.inherits( _attrs : null, // X.Dom.Attr _attrText : '', + _attrUpdated : false, _css : null, // X.Dom.Style _cssText : '', _styleText : '', @@ -147,6 +148,20 @@ Node.createText = function( text ){ return new Node( text ); }; + +Node.getRoot = function( xnode ){ + return Node._document; + //return xnode.root._rawNode.documentElement ? node : node.ownerDocument || node.document; +}; + // XMLかどうかを判別する +Node.isXmlDocument = + X.UA.IE && X.UA.IE < 5 ? + X.emptyFunction : + (function( root ){ + return root._rawNode.createElement( 'p' ).tagName !== root._rawNode.createElement( 'P' ).tagName; + }); + + /* -------------------------------------- * Dom Core 1 */ @@ -187,7 +202,7 @@ Node._systemNode = null;// = Node._chashe[ ? ] */ Node.prototype._create = // document.createElement of ie4 is only for OPTION & IMAGE. - document.appendChild ? (function( isChild ){ + document.getElementById ? (function( isChild ){ var tag = this._tag, node, frg; /* * http://d.hatena.ne.jp/uupaa/20080718/1216362040 @@ -203,7 +218,7 @@ Node.prototype._create = tag && X.UA.IE ? document.createElement( [ '<', this._tag, - 'UID="', this._uid, '"', + ' UID="', this._uid, '"', this._id ? ' id="' + this._id + '"' : '', this._classText, ( this._attrUpdated ? ( this._attrText = X.Dom.Attr.objToAttrText( this._attrs ) ) : this._attrText ), @@ -212,6 +227,7 @@ Node.prototype._create = tag ? document.createElement( tag ) : document.createTextNode( this._text ) ); + delete this._attrUpdated; }; // fragument がある場合 children も足して // Mozilla: 1.0+, IE: 6.0+, Netscape: 2.0+, Safari: 1.0+, Opera: 7.0+ @@ -242,14 +258,13 @@ Node.prototype._create = }; }; html = [ - '<', this._tag, ' id="', ( this._id || ( 'ie4uid' + this._uid ) ), '"', + '<', this._tag, ' id=', ( this._id || ( 'ie4uid' + this._uid ) ), this._classText, ( this._attrUpdated ? ( this._attrText = X.Dom.Attr.objToAttrText( this._attrs ) ) : this._attrText ), this._styleText, '>' ]; delete this._attrUpdated; - if( ( children = this._xnodes ) && ( l = children.length ) ){ for( i = 0; i < l; ++i ){ html[ html.length ] = children[ i ]._create( true, true ); @@ -261,10 +276,10 @@ Node.prototype._create = (function(){}); Node.prototype._afterCreate = - ( document.appendChild ) ? (function( parent ){ + ( document.getElementById ) ? (function( parent ){ var _children = this._xnodes, node = this._rawNode, - eChildren = node.childNodes, + eChildren = node && node.nodeType === 1 && node.childNodes, attrs, p, _child, i, l; this.parent = parent; if( this._xnodeType !== 1 ) return this; @@ -338,7 +353,7 @@ Node.prototype.create = function( tag, opt_attrs, opt_css ){ elm = this._ie4getRawNode ? this._ie4getRawNode() : this._rawNode; if( elm && !Node.skipCreate ){ - if( document.appendChild ){ + if( document.getElementById ){ // ie では iframe の frameborder が無視されるので、