4 * <li>ポップアップブロックされないように、pointer event, click event 内でインスタンスを作る
\r
5 * <li>win.kill() で別窓を閉じる
\r
6 * <li>win.kill() 以外で閉じられた場合、ユーザーの[x]ボタン操作や、他のscriptによって閉じられた場合、X.Event.UNLOAD イベントを発して自身を kill する。
\r
10 * <dt>X.Event.UNLOAD<dd>win.kill() 以外で閉じられた場合に通知、自身はkillする
\r
11 * <dt>X.Event.ERROR<dd>他ドメインに遷移した等の理由で win.write() による書き換えに失敗した場合
\r
14 * @example // 別ページの表示
\r
15 * win = X.Util.Window( { url : 'other.html' } );
\r
17 * win = X.Util.Window( { html : '<p>Hello,world!</p>' } );
\r
21 * @alias X.Util.Window
\r
22 * @class Window 別窓(別タブ)
\r
23 * @extends {EventDispatcher}
\r
25 var X_Window = X[ 'Util' ][ 'Window' ] = X_EventDispatcher[ 'inherits' ](
\r
28 /** @lends X.Util.Window.prototype */
\r
30 'Constructor' : function( options ){
\r
31 var url = options[ 'url' ],
\r
32 page = window.open( url || ''/* 'about:blank' */, options[ 'name' ] || '', options[ 'params' ] || '' ),
\r
33 html = options[ 'html' ],
\r
34 doc = X_Script_try( X_Object_find, [ page, 'document' ] );
\r
36 X_ViewPort[ 'listenOnce' ]( X_EVENT_UNLOAD, this, X_Util_Window_handleEvent );
\r
37 this[ 'listenOnce' ]( [ X_EVENT_UNLOAD, X_EVENT_KILL_INSTANCE ], X_Util_Window_handleEvent );
\r
39 X_Pair_create( this, {
\r
41 timerID : X_Timer_add( options[ 'interval' ] || 500, 0, this, X_Util_Window_onTimer )
\r
45 this[ 'write' ]( html );
\r
52 * <li>ユーザーの[x]クリック操作等
\r
53 * <li>別窓内の script, または他の script
\r
57 'closed' : function(){
\r
58 var pair = X_Pair_get( this );
\r
60 return pair ? X_Script_try( X_Object_find, [ pair.page, 'closed' ] ) : true;
\r
65 * @param {string} url
\r
66 * @return {Window} チェーンメソッド
\r
68 'url' : function( url ){
\r
69 var pair = X_Pair_get( this );
\r
71 pair && ( pair.location.href = url );
\r
76 * @param {string=} opt_html html文字列
\r
77 * @return {Window} チェーンメソッド
\r
79 'write' : function( opt_html ){
\r
80 var pair = X_Pair_get( this ),
\r
81 doc = pair && X_Script_try( X_Object_find, [ pair.page, 'document' ] );
\r
85 doc.write( opt_html || '' ); // TODO 無毒化
\r
88 this[ 'asyncDispatch' ]( X_EVENT_ERROR );
\r
95 * 別窓の値にアクセスする, X.Object.find 参照
\r
96 * @param {string} selector 'navigator>mineTypes>hoge'
\r
99 'find' : function( selector ){
\r
100 var pair = X_Pair_get( this );
\r
102 if( pair ) return X_Script_try( X_Object_find, [ pair.page, selector ] );
\r
107 * @return {Window} チェーンメソッド
\r
109 'focus' : function(){
\r
110 var pair = X_Pair_get( this );
\r
112 pair && pair[ 'focus' ]();
\r
118 function X_Util_Window_onTimer( e ){
\r
119 var pair = X_Pair_get( this );
\r
121 if( this[ 'closed' ]() ){
\r
122 this[ 'asyncDispatch' ]( X_EVENT_UNLOAD );
\r
123 delete pair.timerID;
\r
124 return X_CALLBACK_UN_LISTEN;
\r
128 function X_Util_Window_handleEvent( e ){
\r
129 var pair = X_Pair_get( this ),
\r
130 page = pair && pair.page;
\r
133 case X_EVENT_UNLOAD :
\r
137 case X_EVENT_KILL_INSTANCE :
\r
138 if( page && !this[ 'closed' ]() ){
\r
139 if( 9 < X_UA[ 'IEHost' ] ){
\r
142 page.open( 'about:blank', '_self' ).close();
\r
144 X_Pair_release( this, page );
\r
146 pair.timerID && X_Timer_remove( pair.timerID );
\r
147 X_ViewPort[ 'unlisten' ]( X_EVENT_UNLOAD, this, X_Util_Window_handleEvent );
\r