if( v.hasOwnProperty( p ) ) return false;\r
};\r
return true;\r
+ },\r
+ \r
+ matchTest : function( array1, array2 ){\r
+ var i = array2.length;\r
+ for( ; i; ){\r
+ if( array1.indexOf( array2[ --i ] ) === -1 ) return false;\r
+ };\r
+ return true;\r
}\r
};\r
\r
});\r
\r
/*\r
- * JavaScript 1.6, Array.indexOfを下位互換実装する\r
* original\r
+ * JavaScript 1.6, Array.indexOfを下位互換実装する\r
* http://www.inazumatv.com/contents/archives/7965\r
*/\r
\r
return -1;\r
});\r
\r
+\r
+/*\r
+ * Window\r
+ * by http://nurucom-archives.hp.infoseek.co.jp/digital/trans-uri.html\r
+ */\r
+\r
+/* 正規表現が使われているため、まだ投入しない itozyun\r
+window.encodeURI || (window.encodeURI = function (x) {\r
+ return ("" + x).replace(/[^!#$&-;=?-Z_a-z~]/g, function (s) {\r
+ var c = s.charCodeAt(0), p = "%";\r
+ return (\r
+ c < 16 ? "%0" + c.toString(16) :\r
+ c < 128 ? p + c.toString(16) :\r
+ c < 2048 ? p + (c >> 6 | 192).toString(16) + p + (c & 63 | 128).toString(16) :\r
+ p + (c >> 12 | 224).toString(16) + p + (c >> 6 & 63 | 128).toString(16) + p + (c & 63 | 128).toString(16)\r
+ ).toUpperCase();\r
+ });\r
+});\r
+\r
+window.encodeURIComponent || (window.encodeURIComponent = function (x) {\r
+ return ("" + x).replace(/[^!'-*.0-9A-Z_a-z~-]/g, function (s) {\r
+ var c = s.charCodeAt(0), p = "%";\r
+ return (\r
+ c < 16 ? "%0" + c.toString(16) :\r
+ c < 128 ? p + c.toString(16) :\r
+ c < 2048 ? p + (c >> 6 | 192).toString(16) + p + (c & 63 | 128).toString(16) :\r
+ p + (c >> 12 | 224).toString(16) + p + (c >> 6 & 63 | 128).toString(16) + p + (c & 63 | 128).toString(16)\r
+ ).toUpperCase();\r
+ });\r
+});\r
+\r
+window.decodeURI || (window.decodeURI = function (x) {\r
+ return ("" + x).replace(/%(E(0%[AB]|[1-CEF]%[89AB]|D%[89])[0-9A-F]|C[2-9A-F]|D[0-9A-F])%[89AB][0-9A-F]|%[0-7][0-9A-F]/ig, function (s) {\r
+ var c = parseInt(s.substring(1), 16);\r
+ return String.fromCharCode(\r
+ c < 128 ? c :\r
+ c < 224 ? (c & 31) << 6 | parseInt(s.substring(4), 16) & 63 :\r
+ ((c & 15) << 6 | parseInt(s.substring(4), 16) & 63) << 6 | parseInt(s.substring(7), 16) & 63\r
+ );\r
+ });\r
+});\r
+*/\r
+\r
+// 手抜き\r
+window.decodeURIComponent || (window.decodeURIComponent = window.decodeURI);\r
+\r
+\r
+/*\r
+ * String\r
+ */\r
+\r
+// replace(RegExp, Function)対応\r
+if (window.ActiveXObject ? !Number.prototype.toFixed : (!navigator.taintEnabled && !document.createElement("input").setSelectionRange))\r
+ (function () {\r
+ var g = String.prototype.replace;\r
+ String.prototype.replace = function (x, y) {\r
+ var s = this, z = y;\r
+ // 第二引数が関数\r
+ if (y instanceof Function) {\r
+ // 第一引数が正規表現\r
+ if (x instanceof RegExp) {\r
+ // その上、グローバルマッチ\r
+ if (x.global || /^\/.*g$/.test(x)) {\r
+ var r = [], m;\r
+ while ((m = x.exec(s)) != null) {\r
+ var i = m.index;\r
+ r[r.length] = s.slice(0, i);\r
+ s = s.slice(i + m[0].length);\r
+ r[r.length] = y.apply(null, m.concat(i, this));\r
+ }\r
+ r[r.length] = s;\r
+ return r.join("");\r
+ }\r
+ var m = x.exec(s);\r
+ if (!m)\r
+ return s;\r
+ z = y.apply(null, m.concat(m.index, s));\r
+ }\r
+ else {\r
+ var i = s.indexOf(x);\r
+ if (i < 0)\r
+ return s;\r
+ z = y(x, i, s);\r
+ }\r
+ }\r
+ return g.call(s, x, z);\r
+ };\r
+ })();
\ No newline at end of file
return;\r
};\r
killPrivateFlag = false; // onKill 内で PrivateInstance.kill() を防ぐため\r
- X.Type.isFunction( instance.onKill ) === true && instance.onKill();\r
+ // onKill() === false の場合、kill のキャンセル\r
+ // private は false での キャンセル は無視される\r
+ if( X.Type.isFunction( instance.onKill ) && instance.onKill() === false && !def.isPrivate ){\r
+ return;\r
+ };\r
for( p in instance ){\r
if( instance.hasOwnProperty && !instance.hasOwnProperty( p ) ) continue;\r
delete instance[ p ];\r
def.userList.splice( i, 1 );\r
};\r
};\r
- // myCallback の削除\r
- // myCallback を受け取った API への通知\r
},\r
instanceOf : function( klass ){\r
var Super = this;\r
def.live && def.live.push( instance );\r
};\r
if( def.Super ){\r
+ // klass.prototype に移動\r
instance.Super = def.SuperProto;\r
instance.SuperConstructor = superConstructor;\r
};\r
};\r
\r
function superConstructor(){\r
- X.Class._getClassDef( this ).SuperConstructor.apply( this, arguments );\r
+ var s = X.Class._getClassDef( this ).SuperConstructor;\r
+ s && s.apply( this, arguments );\r
};\r
\r
return {\r
X.Class.create(\r
'EventDispatcher',\r
{\r
- _listeners : null,\r
- _dispatching : 0, // dispatch 中の unlisten で使用\r
- _unlistens : null, // dispatch 中の unlisten で使用\r
- _needsIndex : false, // listening で index を返す\r
+ _listeners : null,\r
+ _dispatching : 0, // dispatch 中の unlisten で使用\r
+ _unlistens : null, // dispatch 中の unlisten で使用\r
+ _needsIndex : false, // listening で index を返す\r
+ _killReserved : false,\r
+ \r
listen : function( type, arg1, arg2, arg3 ){\r
var list = this._listeners,\r
f;\r
* dispatch 中に dispatch が呼ばれるケースがあるため、\r
* _dispatching では その深さを保存する\r
* _dispatching が 0 のときに unlistens を削除する\r
- * \r
- * dispatch( 250, e );\r
- * とすると、タイマー後に dispatch する。\r
+ *\r
*/\r
- dispatch : function( e, e1 ){\r
+ dispatch : function( e ){\r
// dispatch 中の listen は?\r
var list = this._listeners,\r
ret = X.Callback.NONE,\r
this.unlisten( e.type, this._unlistens[ --i ] );\r
};\r
delete this._dispatching;\r
- delete this._unlistens; \r
+ delete this._unlistens;\r
+ \r
+ this._killReserved && this.kill();\r
};\r
\r
return ret;\r
},\r
\r
+ onKill : function(){\r
+ if( this._dispatching ){\r
+ this._killReserved = true;\r
+ return false;\r
+ };\r
+ this._listeners && this.unlisten();\r
+ },\r
+ \r
asyncDispatch : function( delay, e ){\r
return X.Timer.once( delay, this, this.dispatch, [ e ] );\r
}\r
*/\r
function unlock(){ lock = 0; };\r
\r
- if( X.UA.IE ){\r
+ if( X.UA.IE && X.UA.IE < 9 ){\r
resize = function(){\r
- var size, i, l;\r
+ var size;\r
if( !lock++ ){\r
size = X.Dom.getSize();\r
- if( w !== size[ 0 ] || h !== size[ 1 ] ){// VIEW_RESIZED\r
- w = size[ 0 ];\r
- h = size[ 1 ];\r
- X.Dom.dispatch( { type : X.Dom.Event.VIEW_RESIZED, w : w, h : h } );\r
- };\r
- X.Timer.once( 1, unlock );// delay unlock\r
+ ( w !== size[ 0 ] || h !== size[ 1 ] ) &&\r
+ X.Dom.dispatch( { type : X.Dom.Event.VIEW_RESIZED, w : w = size[ 0 ], h : h = size[ 1 ] } );\r
+ X.Timer.once( 1, unlock );\r
};\r
};\r
} else {\r
resize = function( e ){\r
!lock++ && X.Timer.once( 40, delayResize );\r
- e.stopPropagation && e.stopPropagation();\r
- e.preventDefault && e.preventDefault();\r
- return false;\r
+ return X.Callback.PREVENT_DEFAULT | X.Callback.STOP_PROPAGATION;\r
};\r
delayResize = function(){\r
- var size = X.Dom.getSize(),\r
- i, l;\r
- if( w !== size[ 0 ] || h !== size[ 1 ] ){// VIEW_RESIZED\r
- w = size[ 0 ];\r
- h = size[ 1 ];\r
- X.Dom.dispatch( { type : X.Dom.Event.VIEW_RESIZED, w : w, h : h } );\r
- };\r
+ var size = X.Dom.getSize();\r
+ ( w !== size[ 0 ] || h !== size[ 1 ] ) &&\r
+ X.Dom.dispatch( { type : X.Dom.Event.VIEW_RESIZED, w : w = size[ 0 ], h : h = size[ 1 ] } );\r
X.Timer.once( 1, unlock );\r
};\r
};\r
X.Dom = X.Class._override(\r
new X.EventDispatcher(),\r
{\r
- ready : false,\r
- active : true,\r
- _root : null,\r
- \r
+ readyState : -1,\r
+ active : true,\r
+ _root : null,\r
+ \r
+ /*\r
+ * X.Dom.Event.XDOM_READY 以後に listen した場合の対策\r
+ */\r
+ listen : function( type ){\r
+ if( type <= X.Dom.readyState ){\r
+ var size = X.Dom.getSize();\r
+ X.Dom.asyncDispatch( 0, { type : type, w : size[ 0 ], h : size[ 1 ] } );\r
+ };\r
+ return X.EventDispatcher.prototype.listen.apply( X.Dom, arguments );\r
+ },\r
getPointerPosition : function(){\r
\r
},\r
},\r
_init : function(){\r
var s, size, b, x;\r
- if( X.Dom.ready ) return X.Callback.UN_LISTEN;\r
+ if( X.Dom.Event.DOM_PRE_INIT <= X.Dom.readyState ) return X.Callback.UN_LISTEN;\r
if( s = X.Dom._script ){\r
s.parentNode.removeChild( s );\r
s.onreadystatechange = X.emptyFunction;\r
delete X.Dom._script;\r
};\r
delete X.Dom._init;\r
- X.Dom.ready = true;\r
+ X.Dom.readyState = X.Dom.Event.DOM_PRE_INIT;\r
\r
- /* if( X.UA.IE ) */ X.Dom._root = ( document.compatMode !== "CSS1Compat" ? document.body : document.documentElement );\r
+ /* if( X.UA.IE ) */ X.Dom._root = ( document.compatMode !== 'CSS1Compat' ? document.body : document.documentElement );\r
size = X.Dom.getSize();\r
\r
X.Dom.asyncDispatch( 0, { type : X.Dom.Event.DOM_PRE_INIT, w : size[ 0 ], h : size[ 1 ] } );\r
\r
X.Dom.listenOnce( X.Dom.Event.DOM_PRE_INIT, function(){\r
var size = X.Dom.getSize();\r
+ X.Dom.readyState = X.Dom.Event.DOM_INIT;\r
X.Dom.asyncDispatch( 0, { type : X.Dom.Event.DOM_INIT, w : size[ 0 ], h : size[ 1 ] } );\r
} );\r
\r
X.Dom.listenOnce( X.Dom.Event.DOM_INIT, function(){\r
var size = X.Dom.getSize();\r
\r
- X.UA.IE && X.UA.IE < 9?\r
+ X.UA.IE && X.UA.IE < 9 ?\r
X.Timer.add( 100, resize ) :\r
X.Dom.Node._window.listen( 'resize', resize ); \r
- \r
+ X.Dom.readyState = X.Dom.Event.XDOM_READY;\r
X.Dom.asyncDispatch( 0, { type : X.Dom.Event.XDOM_READY, w : size[ 0 ], h : size[ 1 ] } );\r
} );\r
\r
\r
getSize :\r
X.UA.IE ?\r
- new Function( 'return [ X.Dom._root.clientWidth, X.Dom._root.clientHeight ]' ) :\r
- new Function( 'return [ window.innerWidth, window.innerHeight ]' ),\r
+ new Function( 'return[X.Dom._root.clientWidth,X.Dom._root.clientHeight]' ) :\r
+ new Function( 'return[window.innerWidth,window.innerHeight]' ),\r
getScrollPosition :\r
window.pageXOffset !== undefined ?\r
- new Function( 'return [window.pageXOffset,window.pageYOffset]' ) :\r
+ new Function( 'return[window.pageXOffset,window.pageYOffset]' ) :\r
window.scrollLeft !== undefined ?\r
- new Function( 'return [window.scrollLeft,window.scrollTop]') :\r
- new Function( 'return [X.Dom._root.scrollLeft,X.Dom._root.scrollTop]' ),\r
+ new Function( 'return[window.scrollLeft,window.scrollTop]') :\r
+ new Function( 'return[X.Dom._root.scrollLeft,X.Dom._root.scrollTop]' ),\r
getDocumentSize : function(){\r
// Opera は互換モードでは document.body.scrollHeight、標準モードでは document.documentElement.scrollHeight でページの高さが取れる。と思ってたんだけど、例外があった。\r
// http://orera.g.hatena.ne.jp/edvakf/20100515/1273908051\r
ATTR : 16 // _getCharSize, width, height, x, y\r
};\r
\r
+\r
+/*\r
+ * original\r
+ * AS3で相対パスを絶対パスに変換する\r
+ * http://www.shin-go.net/motionlab/?p=449\r
+ */\r
+X.Dom.baseURL = ( function( parts ){\r
+ var last = 1 < parts.length && parts[ parts.length - 1 ];\r
+ if( last !== false && ( last === '' || //末尾が/で終わるとき\r
+ last.indexOf( '.' ) !== -1 ) ){//末尾がファイル名で終わる時\r
+ \r
+ --parts.length;\r
+ };\r
+ return parts.join( '/' );\r
+})( location.href.split( '?' )[ 0 ].split( '#' )[ 0 ].split( '/' ) );\r
+\r
X.Dom.getAbsolutePath = function( path ){\r
- var url;\r
- //path = path.split( '?' )[ 0 ].split( '#' )[ 0 ];\r
- if( path.indexOf( 'http' ) === 0 ) return path;\r
- if( path.indexOf( '//' ) === 0 ) return location.protocol + path;\r
- if( path.charAt( 0 ) === '/' ) return location.protocol + '//' + location.host + path;\r
- url = location.href.split( '?' )[ 0 ].split( '#' )[ 0 ].split( '/' );\r
- --url.length;\r
- // ../\r
- return url.join( '/' ) + '/' + path;\r
-};\r
+ var s = '/',\r
+ ss = '//',\r
+ _ary, ary, i = 0;\r
\r
-// width, height は css or attr に数値があり Block 要素であり、overflow:hidden または 子がない場合にその値を返す\r
+ if( 'http:file'.indexOf( path.substr( 0, 4 ) ) !== -1 ) return path;\r
+ \r
+ _ary = X.Dom.baseURL.split( ss );\r
+ ary = _ary[ 1 ].split( s );\r
\r
-// X.Timer.once( .. onload );\r
+ if( path.charAt( 0 ) === s ) return [ _ary[ 0 ], ss, ary[ 0 ], path ].join( '' );\r
+ \r
+ if( path.substr( 0, 2 ) === './' ){\r
+ path = path.substr( 2 );\r
+ } else {\r
+ while( path.substr( i, 3 ) === '../' ){\r
+ --ary.length;\r
+ i += 3;\r
+ };\r
+ if( i ) path = path.substr( i );\r
+ };\r
+ return [ _ary[ 0 ], ss, ary.join( s ), s, path ].join( '' );\r
+};\r
this._xnodeType = 1;\r
arguments[ 1 ] && this.attr( arguments[ 1 ] );\r
css = arguments[ 2 ];\r
- this[ X.Type.isString( css ) ? 'cssText' : 'css' ]( css );\r
+ css && this[ X.Type.isString( css ) ? 'cssText' : 'css' ]( css );\r
} else\r
if( Node._newByText ){\r
Node._newByText = false;\r
this._className = v.className;\r
this._classText = ' class="' + this._className + '" ';\r
this.cssText( v.style.cssText );\r
+ // attr\r
+ \r
if( X.UA.IE && X.UA.IE < 5 ){\r
v.setAttribute( 'UID', '' + uid );\r
} else {\r
// document.createElement of ie4 is only for OPTION & IMAGE.\r
document.appendChild ? (function( isChild ){\r
var tag = this._tag, node, frg;\r
- if( tag === 'input' ){\r
- // ie7 以下では createElement では name 等が働かない!\r
- };\r
+/*\r
+ * http://d.hatena.ne.jp/uupaa/20080718/1216362040\r
+ * DOM Rangeが使える環境(Firefox2+,Opera9+,Safari3+)なら、innerHTMLいらずで、ガーって書けます。\r
+ * return document.createRange().createContextualFragment("<div><select><option></option></select></div>");\r
+ * \r
+ * ie7 以下では iframe の frameborder や、input name は、createElement 後に aetAttribute しても無視される\r
+ */\r
+\r
if( !( node = this._rawNode ) ){\r
this._isNew = true;\r
- node = this._rawNode = ( tag ? document.createElement( tag ) : document.createTextNode( this._text ) );\r
+ node = this._rawNode = (\r
+ tag && X.UA.IE ?\r
+ document.createElement( [\r
+ '<', this._tag,\r
+ 'UID="', this._uid, '"',\r
+ this._id ? ' id="' + this._id + '"' : '',\r
+ this._classText,\r
+ ( this._attrUpdated ? ( this._attrText = X.Dom.Attr.objToAttrText( this._attrs ) ) : this._attrText ),\r
+ this._styleText,\r
+ '>' ].join( '' ) ) :\r
+ tag ?\r
+ document.createElement( tag ) :\r
+ document.createTextNode( this._text ) );\r
};\r
// fragument がある場合 children も足して\r
// Mozilla: 1.0+, IE: 6.0+, Netscape: 2.0+, Safari: 1.0+, Opera: 7.0+\r
};\r
};\r
\r
-/*\r
- * http://d.hatena.ne.jp/uupaa/20080718/1216362040\r
- * DOM Rangeが使える環境(Firefox2+,Opera9+,Safari3+)なら、innerHTMLいらずで、ガーって書けます。\r
- * return document.createRange().createContextualFragment("<div style='background-color: blue; height: 100px; width: 100px;'><select><option></option></select></div>");\r
- */\r
- \r
return node;\r
}) :\r
document.all ? (function( skipRemove, skipContainsDirty ){\r
return this._htmlText;\r
};\r
};\r
- html = [ '<', this._tag, ' id="', ( this._id || ( 'ie4uid' + this._uid ) ), '"', this._classText, this._attrText, this._styleText, '>' ];\r
+ html = [\r
+ '<', this._tag, ' id="', ( this._id || ( 'ie4uid' + this._uid ) ), '"',\r
+ this._classText,\r
+ ( this._attrUpdated ? ( this._attrText = X.Dom.Attr.objToAttrText( this._attrs ) ) : this._attrText ),\r
+ this._styleText,\r
+ '>' ];\r
+ delete this._attrUpdated;\r
+ \r
+ \r
if( ( children = this._xnodes ) && ( l = children.length ) ){\r
for( i = 0; i < l; ++i ){\r
html[ html.length ] = children[ i ]._create( true, true );\r
eChildren = node.childNodes,\r
attrs, p, _child, i, l;\r
this.parent = parent;\r
- if( this._xnodeType !== 1 ) return;\r
+ if( this._xnodeType !== 1 ) return this;\r
if( this._isNew ){\r
if( _children && !document.createDocumentFragment ){\r
Node._dom1cleanUp( this ); // docFrg が使えない場合、doc 追加後に子を追加\r
};\r
- node.UID = this._uid;\r
- if( this._id ) node.id = this._id;\r
- if( this._className ) node.className = this._className;\r
- // ie では createElement に <div class=...> HTML 文字列を渡すことができる\r
- // 動的に生成した iframe に後から frameborder 等を設定しても無視される ie7\r
- if( attrs = this._attrs ){\r
- for( p in attrs ){\r
- node[ p ] = attrs[ p ];\r
+ if( !X.UA.IE ){\r
+ node.UID = this._uid;\r
+ if( this._id ) node.id = this._id;\r
+ if( this._className ) node.className = this._className;\r
+ // ie では createElement に <div class=...> HTML 文字列を渡すことができる\r
+ // 動的に生成した iframe に後から frameborder 等を設定しても無視される ie7\r
+ if( attrs = this._attrs ){\r
+ for( p in attrs ){\r
+ node[ p ] = attrs[ p ];\r
+ };\r
};\r
+ node.style.cssText = this._cssText; \r
};\r
- node.style.cssText = this._cssText;\r
this._restoreEvent();// イベントの復帰\r
delete this._isNew;\r
};\r
this.parent = parent;\r
delete this._ie4dirty;\r
\r
- if( this._xnodeType !== 1 ) return;\r
+ if( this._xnodeType !== 1 ) return this;\r
\r
delete this._rawNode;\r
delete this._ie4dirtyChildren;\r
};\r
\r
/* --------------------------------------\r
- * Before , After\r
+ * Before , After, Replace\r
*/\r
Node.prototype.before = function( v ){\r
- var l;\r
- if( this._xnodeType !== 1 || !this.parent ) return this;\r
+ var parent, l;\r
+ if( this._xnodeType !== 1 || !( parent = this.parent ) ) return this;\r
l = arguments.length;\r
if( 1 < l ){\r
v = [ this.getOrder() ];\r
for( ; l; ){\r
v[ l ] = arguments[ --l ];\r
};\r
- return this.parent.appendAt.apply( this.parent, v );\r
+ parent.appendAt.apply( parent, v );\r
+ return this;\r
};\r
- return this.parent.appendAt( this.getOrder(), v );\r
+ parent.appendAt( this.getOrder(), v );\r
+ return this;\r
};\r
\r
Node.prototype.after = function( v ){\r
- var l;\r
- if( this._xnodeType !== 1 || !this.parent ) return this;\r
+ var parent, l;\r
+ if( this._xnodeType !== 1 || !( parent = this.parent ) ) return this;\r
l = arguments.length;\r
if( 1 < l ){\r
v = [ this.getOrder() + 1 ];\r
for( ; l; ){\r
v[ l ] = arguments[ --l ];\r
};\r
- return this.parent.appendAt.apply( this.parent, v );\r
+ parent.appendAt.apply( parent, v );\r
+ return this;\r
};\r
- return this.parent.appendAt( this.getOrder() + 1, v );\r
+ parent.appendAt( this.getOrder() + 1, v );\r
+ return this;\r
+};\r
+\r
+Node.prototype.replace = function( v ){\r
+ if( !this.parent ) return this;\r
+ return arguments.length === 1 ? this.before( v ).remove() : this.before.apply( this, arguments ).remove();\r
};\r
\r
/* --------------------------------------\r
if( !elm ) return;\r
this._migrateEvent();// イベントの退避\r
this._htmlText = elm.outerHTML;\r
- elm.removeAttribute( 'id' ); \r
+ elm.removeAttribute( 'id' );\r
}) :\r
(function(){});\r
\r
(function(){});\r
\r
/* --------------------------------------\r
- * replace\r
- */\r
-\r
-/* --------------------------------------\r
* destory\r
*/\r
Node.prototype.destroy = function(){\r
var elm = this._ie4getRawNode ? this._ie4getRawNode() : this._rawNode,\r
- children = this._xnodes;\r
+ children = this._xnodes, i, l;\r
\r
if( children ){\r
for( i = 0, l = children.length; i < l; ++i ){\r
return children[ index ] = xnode;\r
};\r
\r
-// listen, unlisten, listening\r
\r
/* --------------------------------------\r
* prevNode, nextNode, firstChild, lastChild\r
Node.prototype.toggleClass = function(){\r
\r
};\r
-Node.prototype.hasClass = function(){\r
- /*\r
- var cnames = ( elm.className || '' ).split( ' ' ),\r
+Node.prototype.hasClass = function( className ){\r
+ var cnames = ( this._className || '' ).split( ' ' ),\r
_cnames = className.split( ' ' ),\r
- _cname,\r
- i = _cnames.length;\r
+ i = _cnames.length,\r
+ _cname;\r
for( ; i; ){\r
_cname = _cnames[ --i ];\r
if( _cname === '' ) continue;\r
if( cnames.indexOf( _cname ) === -1 ) return false;\r
};\r
- return true; */\r
+ return true;\r
};\r
\r
/* --------------------------------------\r
X.Dom.Event = function( e ){
//this._event = e;
this.type = e.type;
- this.target = e.target; // xnode
+
+ //http://www.quirksmode.org/js/events_properties.html
+ this.target = e.target.nodeType === 3 ? e.target.parentNode : e.target;// defeat Safari bug // xnode
+
this.currentTarget = e.currentTarget; // xnode
this.relatedTarget = e.relatedTarget; // xnode
this.eventPhase = e.eventPhase;
};
if( X.UA.IE && 5 <= X.UA.IE ){
- this.offsetX = e.offsetX;
+ this.offsetX = e.offsetX; // イベントターゲット左上からの座標
this.offsetY = e.offsetY;
+ } else {
+ this.offsetX = e.x - e.srcElement.offsetLeft; // e.x はイベントが発生要素の親要素を基準にした座標。
+ this.offsetY = e.y - e.srcElement.offsetTop;
};
this.keyCode = e.keyCode;
X.Dom.Event.VIEW_ACTIVATE = 3;
X.Dom.Event.VIEW_DEACTIVATE = 4;
X.Dom.Event.VIEW_RESIZED = 5;
+// on_screen_keyboard_show
+// on_screen_keyboard_hide
// before_commit_update
X.Dom.Event.COMMIT_UPDATE = 6;
// hash_change
X.Dom.Node._window.listenOnce( 'load', X.Dom._init );
//
-X.Dom.listenOnce( X.Dom.Event.XDOM_READY, function(e){ console.log( 'X.Dom XDomReady ' + X.Dom.ready ) } );
+X.Dom.listenOnce( X.Dom.Event.XDOM_READY, function(e){ console.log( 'X.Dom XDomReady ' + X.Dom.readyState ) } );
X.Dom.listenOnce( X.Dom.Event.VIEW_RESIZED, function(e){ console.log( 'X.Dom VIEW_RESIZED ' + e.w + 'x' + e.h ) } );
r.appendTo = r.appendToRoot = r.before = r.after = r.clone = r.remove = r.destroy = r.prevNode = r.nextNode = new Function( 'return this' );
if( body.childNodes ){
+ /*
+ * body.innerHTML(可能なら outerHTML を使って属性を控える)
+ */
createTree = function( xnode, elm, skipCleanup ){
var children = elm.childNodes,
i = 0,
case 1 :
if( !xnode._xnodes ) xnode._xnodes = [];
xnode._xnodes[ xnode._xnodes.length ] = _xnode = new Node( child );
+ // attr の取得
_xnode.parent = xnode;
child.childNodes.length && createTree( _xnode, child, skipCleanup || 0 <= X.skipCleanupTagNames.indexOf( child.tagName.toLowerCase() ) );
break;
r._xnodes = [];
Node.skipCreate = true;
+ /*
+ * http://support.microsoft.com/kb/812417/ja
+ * PRB: outerHTML の HTML 要素のプロパティは、既定の属性は表示されません。
+ *
+ * body.innerHTML でなく、 body.outerHTML
+ */
r._xnodes.push.apply( r._xnodes, X.Dom.parse( body.innerHTML, true ) );
delete Node.skipCreate;
createTree( r, body.children );
/* --------------------------------------
* x, y
- * position:absolute かつ x か y が設定されていたら、再描画しないでその値を返す。
- * position:absolute の指定で自動で top,left を補う必要あり?
+ * position:absolute かつ x か y が設定されていたら、再描画しないで css オブジェクトから計算した値を返す。 float は?
+ * position:absolute の指定で自動で top,left を補う必要あり? -> X.Dom.Style
* 親要素 border 外側からの値。 IE, Firefox, Safari, Chrome の offsetLeft/Topでは、border 内側なので補正する。
* transformX, Y は加える? アニメーション中は?
*/
for( p in nameOrObj ){\r
this.__attr( node, attrs, p, nameOrObj[ p ] );\r
};\r
- this._attrText = X.Dom.Attr.objToAttrText( this._attrs );\r
+ delete this._attrText; // = X.Dom.Attr.objToAttrText( attrs );\r
return this;\r
} else\r
if( 1 < arguments.length ){\r
this._ie4getRawNode ? ( this._rawNode || this._ie4getRawNode() ) : this._rawNode,\r
attrs, nameOrObj, arguments[ 1 ]\r
);\r
- //if( !attrs[ name ] ){\r
- // !this._attrText ? ( this._attrText = '' ) : ( this._attrText += ' ' );\r
- // this._attrText += X.Dom.Attr.noValue[ name ] ? name : name + '="' + v + '"';\r
- // attrs[ name ] = v;\r
- //} else {\r
- // attrs[ name ] = v;\r
- this._attrText = X.Dom.Attr.objToAttrText( attrs );\r
- //};\r
+ delete this._attrText; // = X.Dom.Attr.objToAttrText( attrs );\r
return this;\r
} else\r
if( typeof nameOrObj === 'string' ){\r
return me._DICTIONARY_UNCAMELIZE[ str ] = uncamelized.toLowerCase();
},
+/*
+ * CSS における display, position, float プロパティの相互関係
+ * http://d.hatena.ne.jp/elm200/20080201/1201874740
+ *
+ * CSS21:9.7 Relationships between ’display’, ’position’, and ’float’
+ * http://www.w3.org/TR/CSS21/visuren.html#dis-pos-flo
+ *
+ * display:none? -yes-> 非表示
+ * ↓
+ * position:absolute? -yes-> float:none,display:block;
+ * ↓
+ * float:none? -no-> display:block;
+ * ↓
+ * display:そのまま
+ *
+ *
+display position float
+block static|relative none
+block static|relative right|left
+block absolute none
+inline static|relative none
+
+_DISPLAY_NONE
+_ABSOLUTE_BOX
+_FLOAT_BOX
+_GRNERAL
+ */
objToCssText : function( obj ){
var css = [],
me = X.Dom.Style,
// unitID, name 単位指定のプロパティ取得 geter
// obj setter
// name, value setter
+
X.Dom.Node.prototype.css = function( nameOrObj /* orUnitID, valuOrUnitOrName */ ){
var XDomStyle = X.Dom.Style,
args = arguments,
// getter unit
// unit 付の値取得は fontSize と 画像サイズが確定していないと正確に取れない。内部のみにする?
if( !css ) return;
- if( !X.Dom.Style._GET_VALUE_WITH_UNIT[ name = XDomStyle.camelize( args[ 1 ] ) ] ) return null;
+ if( !XDomStyle._GET_VALUE_WITH_UNIT[ name = XDomStyle.camelize( args[ 1 ] ) ] ) return null;
p = XDomStyle._getProperty( this, css, unit, name );
v = p.pxTo( unit );
p.kill();
if( this.xnode.dispatch( { type : X.Dom.Event.ANIME_BEFORE_STOP, target : this.xnode } ) & X.Callback.PREVENT_DEFAULT ){\r
return;\r
};\r
- this.xnode.dispatch( { type : X.Dom.Event.ANIME_STOP, target : this.xnode } );\r
opt_goEndPosition && this.tick( this.startTime + this.duration );\r
- unregisterQueue( this ); \r
+ unregisterQueue( this );\r
+ this.xnode.dispatch( { type : X.Dom.Event.ANIME_STOP, target : this.xnode } ); \r
},\r
tick :\r
transition ?\r
/* --------------------------------------
* getByID
*/
+X.Dom.getByID =
+ document.getElementById ?
+ (function( id ){
+ return new X.Dom.Node( document.getElementById( id ) );
+ }) :
+ document.all ?
+ (function( id ){
+ return new X.Dom.Node( document.all[ id ] );
+ }) :
+ (function( id ){});
+
/* --------------------------------------
* getByTag
*/
-Node.prototype.getByTag = function( tag ){
- var parent = this.parent, elm, tags;
- if( !parent || this._xnodeType !== -1 ) return;
- if( document.getElementsByTagName ){
- if( !( elm = this._rawNode ) ) return;
- new X.Dom.NodeList( elm.getElementsByTagName( tag ) );
- } else
- if( document.all ){
- if( !( elm = this._ie4getRawNode() ) ) return;
- Node.root._ie4reserved === true && Node.root._ie4startUpdate();
- new X.Dom.NodeList( elm.all.tags( tag ) );
- } else {
-
- };
-};
+Node.prototype.getByTag =
+ document.getElementsByTagName ?
+ function( tag ){
+ var parent = this.parent, elm, tags;
+ if( !parent || this._xnodeType !== -1 ) return;
+ if( !( elm = this._rawNode ) ) return;
+ return new X.Dom.NodeList( document.getElementsByTagName( tag ) );
+ } :
+ document.all ?
+ (function( tag ){
+ var parent = this.parent, elm, tags;
+ if( !parent || this._xnodeType !== -1 ) return;
+ if( !( elm = this._ie4getRawNode() ) ) return;
+ Node.root._ie4reserved === true && Node.root._ie4startUpdate();
+ return new X.Dom.NodeList( elm.all.tags( tag ) );
+ }) :
+ (function( tag ){});
/* --------------------------------------
* getByClass
}) :
document.getElementsByTagName ?
(function( className ){
- var parent = this.parent, elm;
- var live = parent.getElementsByTagName( '*' ),
- nodes = [],
+ var parent = this.parent,
+ live = parent.getElementsByTagName( '*' ),
+ nodes = [],
+ test = X.matchTest,
node, i;
+ className = className.split( ' ' );
for( i = live.length; i; ){
nodes[ --i ] = live[ i ];
};
for( i = nodes.length; i; ){
node = nodes[ --i ];
- ( node.nodeType !== 1 || !node.className || !node.className.length || Node.hasClass( node, className ) === false ) && nodes.splice( i, 1 );
+ ( node.nodeType !== 1 || !node.className || !node.className.length || !test( node.className.split( ' ' ), className ) ) && nodes.splice( i, 1 );
};
return new X.Dom.NodeList( nodes );
}) :
(function( parent, className ){
var live = parent.all,
nodes = [],
+ test = X.matchTest,
node, i;
for( i = live.length; i; ){
nodes[ --i ] = live[ i ];
};
for( i = nodes.length; i; ){
node = nodes[ --i ];
- ( !node.className || !node.className.length || Node.hasClass( node, className ) === false ) && nodes.splice( i, 1 );
+ ( !node.className || !node.className.length || !test( node.className.split( ' ' ), className ) ) && nodes.splice( i, 1 );
};
return new X.Dom.NodeList( nodes );
}) :
(function(){});
-X.Dom.find = function( v ){
- var selectors = X.Dom.Query.parse( v ),
+X.Dom.find = Node.prototype.find = function( v ){
+ var root = this.cnstructor === Node ? this : Node.root,
+ selectors = X.Dom.Query._parse( v ),
l, i, nodes, _nodes, selector,
name, key, operator, value,
j, m;
};
-X.Dom.Query.parse = function( query ){
+X.Dom.Query._parse = function( query ){
var HASH_SELECTOR = {
' ' : 0,
'>' : 1,
escape = chr === '\\' && !escape;
};
return result;
-};
\ No newline at end of file
+};
+
var FULL = X.Css; // something unigue value;\r
var FLOOR = Math.floor;\r
\r
+/*\r
+ * uinode によって指定可能な css は異なる\r
+ * + 直接 xnode.css() に渡す値\r
+ * + uinode 内で加工してから xnode.css() に渡す値\r
+ * ChromeBox での css3 の fallback\r
+ * + layoutManager で使う値がある\r
+ * x, y, gap, childW, childH など\r
+ */\r
+\r
X.Css.Option = {\r
BORDER_STYLE : 'none,hidden,dotted,dashed,solid,double,groove,ridge,inset,outset'.split(','),\r
POSITION_X : 'left,center,right'.split(','),\r
for( var id in IdToName ){\r
NameToID[ IdToName[ id ] ] = id;\r
};\r
-})( X.UI.Event.IdToName, X.UI.Event.NameToID );
\ No newline at end of file
+})( X.UI.Event.IdToName, X.UI.Event.NameToID );\r
+\r
POINTERS[ i ] && ( touches[ touches.length ] = POINTERS[ i ] );\r
};\r
numTouches = touches.length;\r
- }\r
+ } else\r
// touch\r
- else if ( type & TOUCH ){ //sourceEventType.match(/touch/)) {\r
+ if ( type & TOUCH ){ //sourceEventType.match(/touch/)) {\r
touches = Hammer.DO_TOUCHES_FIX && type & END ? [] : e.touches;\r
numTouches = touches.length;\r
- }\r
+ } else\r
// mouse\r
- else if( !touch_triggered ){\r
+ if( !touch_triggered ){\r
numTouches = ( type & END ) ? 0 : 1;\r
touches = numTouches === 0 ? [] : [{\r
identifier : 1,\r
if( !this.types[ type ] ) return;\r
var e = Utils.extend( {}, gesture );\r
e.type = type;\r
- console.log( 'trigger : ' + type )\r
+ console.log( 'trigger : ' + type );\r
return this.uinode.dispatch( e );\r
};\r
\r
Constructor : function( layout, args ){\r
this.SuperConstructor( layout, args );\r
\r
+ // xnode の追加が可能\r
+ \r
var nodes = this.nodes,\r
i = nodes.length,\r
node;\r
Constructor : function( layout, args ){
this.SuperConstructor( layout, args );
- if( X.Dom.ready === true ){
+ if( X.Dom.readyState === X.Dom.Event.XDOM_READY ){
X.Timer.once( 0, this, this.start );
} else {
X.Dom.listenOnce( X.Dom.Event.XDOM_READY, this, this.start );