2 var X_ViewPort_readyState,
3 X_ViewPort_active = !!window.parent || !!document.activeElement, // parent は frameに読み込まれた場合のieのerror回避
4 X_ViewPort_rootElement,
8 X_ViewPort_baseFontSize,
10 X_Dom_detectFontSize = !( X.UA.IE < 9 || X.UA.iOS ) && function(){
11 var size = Node._fontSizeNode._rawObject.offsetHeight;
12 if( X_ViewPort_baseFontSize !== size ){
13 X_ViewPort_baseFontSize && X_ViewPort.asyncDispatch( { type : X.Event.BASE_FONT_RESIZED, fontSize : size, w : X_ViewPort_width, h : X_ViewPort_height } );
14 X_ViewPort_baseFontSize = size;
18 X_ViewPort_orientationFlag,
19 X_Dom_orientationchange = window[ 'orientation' ] !== undefined && function( e ){
20 X_ViewPort_orientationFlag = true;
21 !X.UA.Android && X_ViewPort_resize();
22 //console.log( '-- orientationchange : ' + X.ViewPort.getSize[ 0 ] + ' ' + X.ViewPort.getSize[ 1 ] );
25 X_ViewPort = X.Class._override(
26 new X.EventDispatcher( window ),
29 handleEvent : function( e ){
34 // ie では a href="javascript" な要素でも beforeunload が起こる
35 href = e.target && e.target.attr && e.target.attr( 'href' );
36 if( href && href.indexOf && href.indexOf( 'javascript:' ) === 0 ) return X.Callback.PREVENT_DEFAULT | X.Callback.STOP_PROPAGATION;
38 return X_ViewPort.dispatch( X.Event.BEFORE_UNLOAD );
40 X_ViewPort.dispatch( X.Event.UNLOAD );
42 X.ViewPort.unlisten();
43 Node._document.unlisten();
44 Node._html._actualRemove( true );
46 case 'visibilitychange' :
47 X_ViewPort.dispatch( { type : ( X_ViewPort_active = document[ 'hidden' ] ) ? X.Event.VIEW_DEACTIVATE : X.Event.VIEW_ACTIVATE } );
49 case 'webkitvisibilitychange' :
50 X_ViewPort.dispatch( { type : ( X_ViewPort_active = document[ 'webkitHidden' ] ) ? X.Event.VIEW_DEACTIVATE : X.Event.VIEW_ACTIVATE } );
54 X_ViewPort_active = true;
55 X_ViewPort.dispatch( X.Event.VIEW_ACTIVATE );
59 X_ViewPort_active = false;
60 X_ViewPort.dispatch( X.Event.VIEW_DEACTIVATE );
71 listen : function( type, arg1, arg2, arg3 ){
72 if( type <= X_ViewPort_readyState ){
74 * X.Event.XDOM_READY 以後に listen した場合の対策
76 X_ViewPort.asyncDispatch( { type : type, w : X_ViewPort_width, h : X_ViewPort_height } );
78 type && arg1 && X_ViewPort.listen( type, arg1, arg2, arg3 );
83 listenOnce : function( type, arg1, arg2, arg3 ){
84 if( type <= X_ViewPort_readyState ){
86 * X.Event.XDOM_READY 以後に listen した場合の対策
88 X_ViewPort.asyncDispatch( { type : type, w : X_ViewPort_width, h : X_ViewPort_height } );
90 type && arg1 && X_ViewPort.listenOnce( type, arg1, arg2, arg3 );
94 unlisten : function( type, arg1, arg2, arg3 ){
95 type && arg1 && X_ViewPort.unlisten( type, arg1, arg2, arg3 );
99 listening : function( type, arg1, arg2, arg3 ){
100 return X_ViewPort.listening( type, arg1, arg2, arg3 );
103 asyncDispatch : function(){
104 return X_ViewPort.asyncDispatch.apply( X_ViewPort, arguments );
107 getPointerPosition : function(){
111 /* 要素が視界に入った http://remysharp.com/2009/01/26/element-in-view-event-plugin/ */
112 inView : function( elm ){
116 getSize : function(){
117 return [ X_ViewPort_width, X_ViewPort_height ];
119 //https://developer.mozilla.org/en-US/docs/Web/API/Element.getBoundingClientRect
120 //use window.pageXOffset and window.pageYOffset instead of window.scrollX and window.scrollY
121 //(((t = document.documentElement) || (t = document.body.parentNode)) && typeof t.ScrollLeft == 'number' ? t : document.body).ScrollLeft;
122 //(((t = document.documentElement) || (t = document.body.parentNode)) && typeof t.ScrollTop == 'number' ? t : document.body).ScrollTop
124 getDocumentSize : function(){
125 // Opera は互換モードでは document.body.scrollHeight、標準モードでは document.documentElement.scrollHeight でページの高さが取れる。と思ってたんだけど、例外があった。
126 // http://orera.g.hatena.ne.jp/edvakf/20100515/1273908051
127 //http://onozaty.hatenablog.com/entry/20060803/p1
128 // Safari2.0.4では標準・互換どちらも document.body
130 Node._body._updateTimerID && Node._body._startUpdate();
132 ( document.documentElement && document.documentElement.clientWidth ?
133 new Function( 'return[document.documentElement.clientWidth,document.documentElement.clientHeight]' ) :
134 new Function( 'return[document.body.clientWidth,document.body.clientHeight]' )
137 X_ViewPort_rootElement.scrollWidth || X_ViewPort_rootElement.offsetWidth,
138 X_ViewPort_rootElement.scrollHeight || X_ViewPort_rootElement.offsetHeight
143 window.pageXOffset !== undefined ?
145 Node._body._updateTimerID && Node._body._startUpdate();
146 return[ window.pageXOffset, window.pageYOffset ];
148 window.scrollLeft !== undefined ?
150 Node._body._updateTimerID && Node._body._startUpdate();
151 return[ window.scrollLeft, window.scrollTop ];
154 Node._body._updateTimerID && Node._body._startUpdate();
156 return[ X_ViewPort_rootElement.scrollLeft || document.body.scrollLeft, X_ViewPort_rootElement.scrollTop || document.body.scrollTop ];
159 getScrollbarSize : function(){
160 return [ X.Dom.BoxModel.vScrollbarSize, X.Dom.BoxModel.hScrollbarSize ];
163 getBaseFontSize : function(){
164 if( Node._body._updateTimerID ){
165 Node._body._startUpdate();
166 return X_ViewPort_baseFontSize = Node._fontSizeNode._rawObject.offsetHeight;
168 return X_ViewPort_baseFontSize;
175 /* -----------------------------------------------
177 * original : uupaa.js
180 * https://w3g.jp/blog/studies/ios7_1_minimal-ui_warning
181 * iOS7.0からあったiPad Safariの高さ100%コンテンツでlandscape(横向き)時に起きる不具合
183 * http://looxu.blogspot.jp/2013/11/ios7mobile-safariwindowinnerheight.html
184 * iOS7にて、Mobile Safariのwindow.innerHeightを正しく取得する方法
186 * http://tenderfeel.xsrv.jp/javascript/1182/
189 * http://sssslide.com/www.slideshare.net/hiroakiwakamatsu/javascript-14514208
190 * 1. 傾き時の画面サイズ取得ー 対処方法の例
191 * (1)ー? タイマーを使って、画面サイズ取得の タイミングを少しだけ遅延させる
192 * window.onorientationchange = function() { setTimeout(function() { alert("W: " + window.innerWidth + ", H: " + window.innerHeight); }, 200); }
193 * 横に傾けた時、正常に横向け時の 幅と高さが取得できている ただし、端末によってはうまく取得できな い場合がある(Galaxy S IIIとか・・・) 7
195 * http://sssslide.com/www.slideshare.net/hiroakiwakamatsu/ss-12718639
198 * getBoundingClientRect で fontsize の調査
200 var X_ViewPort_resize =
201 // iOS もループで回す,,,iOS3.1.3, iOS6 で確認
202 X.UA.IE < 9 || X.UA.iOS ?
205 if( !X_ViewPort_lock ){
206 size = X_ViewPort_getWindowSize();
207 if( X_ViewPort_width !== size[ 0 ] || X_ViewPort_height !== size[ 1 ] ){
208 X_ViewPort_width = size[ 0 ];
209 X_ViewPort_height = size[ 1 ];
210 X.Timer.once( 100, X_Dom_detectFinishResizing );
211 X_ViewPort_lock = true;
215 size = Node._fontSizeNode._rawObject.offsetHeight;
216 if( X_ViewPort_baseFontSize !== size ){
217 X_ViewPort_baseFontSize && X_ViewPort.asyncDispatch( { type : X.Event.BASE_FONT_RESIZED, fontSize : size, w : X_ViewPort_width, h : X_ViewPort_height } );
218 X_ViewPort_baseFontSize = size;
223 console.log( '-- resize : ' + X_Timer_now() );
225 !X_ViewPort_lock && ( X_ViewPort_lock = true ) && X.Timer.once( 100, X_Dom_detectFinishResizing );
226 return X.Callback.PREVENT_DEFAULT | X.Callback.STOP_PROPAGATION;
229 function X_Dom_detectFinishResizing(){
230 var size = X_ViewPort_getWindowSize();
231 if( X_ViewPort_width !== size[ 0 ] || X_ViewPort_height !== size[ 1 ] ){
232 X_ViewPort_width = size[ 0 ];
233 X_ViewPort_height = size[ 1 ];
234 X.Timer.once( 100, X_Dom_detectFinishResizing );
236 console.log( '-- detectFinishResizing : ' + X_Timer_now() );
238 X_ViewPort.asyncDispatch( { type : X.Event.VIEW_RESIZED, fontSize : X_ViewPort_baseFontSize, w : X_ViewPort_width, h : X_ViewPort_height } );
239 X_ViewPort_lock = false;
240 if( X_ViewPort_orientationFlag ){
241 X_ViewPort_orientationFlag = false;
242 X_ViewPort.asyncDispatch( 100, { type : X.Event.VIEW_TURNED, orientation : window.orientation } );
247 X_TEMP.onDomContentLoaded = function(){
248 var s, size, elmHtml, elmHead, elmBody, html, head, body;
250 if( X_TEMP.SYSTEM_EVENT_PRE_INIT <= X_ViewPort_readyState ) return X_Callback_UN_LISTEN;
251 X_ViewPort_readyState = X_TEMP.SYSTEM_EVENT_PRE_INIT;
253 // DOMContentLoaded の無いブラウザで X_TEMP.onDomContentLoaded への参照が残り続けるのを回避
254 X_TEMP.onDomContentLoaded && Node._document.unlisten( 'DOMContentLoaded', X_TEMP.onDomContentLoaded );
255 delete X_TEMP.onDomContentLoaded;
257 elmHtml = document.documentElement ||
258 X_UA_DOM.W3C ? document.getElementsByTagName( 'html' )[ 0 ] :
259 X_UA_DOM.IE4 ? document.all.tags( 'html' )[ 0 ] : null;
262 X_UA_DOM.W3C ? document.getElementsByTagName( 'head' )[ 0 ] :
263 X_UA_DOM.IE4 ? document.all.tags( 'head' )[ 0 ] : null;
265 elmBody = document.body;
267 X_ViewPort_rootElement = document.compatMode !== 'CSS1Compat' ? elmBody : elmHtml || elmBody;
269 html = Node._html = elmHtml && new Node( elmHtml );
271 head = Node._head = elmHead && new Node( elmHead );
273 body = Node._body = new Node( elmBody );
275 body._root = html._root = head._root = body;// _root は html だろ
276 body.parent = head.parent = html;
277 html._xnodes = [ head, body ];
279 Node.root = body; // 後方互換
281 html.appendTo = html.appendToRoot = html.before = html.after = html.clone = html.remove = html.destroy = html.prevNode = html.nextNode =
282 html.create = html.createText = html.createAt = html.createTextAt = html.append = html.appendAt = html.empty = html.html = html.text =
283 head.appendTo = head.appendToRoot = head.before = head.after = head.clone = head.remove = head.destroy = head.prevNode = head.nextNode =
284 head.empty = head.html = head.text =
285 body.appendTo = body.appendToRoot = body.before = body.after = body.clone = body.remove = body.destroy = body.prevNode = body.nextNode = new Function( 'return this' );
287 X.ViewPort.listenOnce( X_TEMP.SYSTEM_EVENT_PRE_INIT, function(){
288 X_ViewPort_readyState = X_TEMP.SYSTEM_EVENT_XTREE;
289 if( X_TEMP.X_Dom_useBuilder ) X_TEMP.X_Dom_useBuilder = !!document.body.children.length;
290 !X_TEMP.X_Dom_useBuilder && X_ViewPort.asyncDispatch( X_TEMP.SYSTEM_EVENT_XTREE );
293 X.ViewPort.listenOnce( X_TEMP.SYSTEM_EVENT_XTREE, function(){
294 X_ViewPort_readyState = X_TEMP.SYSTEM_EVENT_INIT;
295 //X.UA.Opera7 && alert( 'bc' );
296 Node._body.appendAt( 0,
297 Node._systemNode = Node.create( 'div', { 'class' : 'hidden-system-node' } ),
298 Node._fontSizeNode = Node.create( 'div', { 'class' : 'hidden-system-node' } ).cssText( 'line-height:1;height:1em;' ).text( 'X' )
301 X_ViewPort.asyncDispatch( X_TEMP.SYSTEM_EVENT_INIT );
304 X.ViewPort.listenOnce( X_TEMP.SYSTEM_EVENT_INIT, function(){
305 var size = X_ViewPort_getWindowSize();
307 if( X_Dom_orientationchange ){
308 X.ViewPort.listen( 'orientationchange', X_Dom_orientationchange );
311 if( X_Dom_detectFontSize ){
312 X.ViewPort.listen( 'resize', X_ViewPort_resize );
313 X.Timer.add( 333, X_Dom_detectFontSize );
315 X.Timer.add( 333, X_ViewPort_resize );
318 X_ViewPort_baseFontSize = Node._fontSizeNode._rawObject.offsetHeight;
320 X_ViewPort_readyState = X.Event.XDOM_READY;
321 X_ViewPort.asyncDispatch( { type : X.Event.XDOM_READY, w : X_ViewPort_width = size[ 0 ], h : X_ViewPort_height = size[ 1 ] } );
324 console.log( X_ViewPort.asyncDispatch( X_TEMP.SYSTEM_EVENT_PRE_INIT ) );
327 .listen( 'beforeunload', X_ViewPort )
328 .listenOnce( 'unload', X_ViewPort );
330 //ブラウザの戻るボタンで戻ったときに呼ばれるイベントとかキャッシュとかそこらへんのこと
331 //http://d.hatena.ne.jp/koumiya/20080916/1221580149
333 if( document[ 'hidden' ] !== undefined ) {// iOS 7+
334 Node._document.listen( 'visibilitychange', X_ViewPort );
336 if( document[ 'webkitHidden' ] !== undefined ) {
337 Node._document.listen( 'webkitvisibilitychange', X_ViewPort );
339 if( X.UA.iOS && window[ 'onpageshow' ] !== undefined ) {
340 X.ViewPort.listen( 'pageshow', X_ViewPort )
341 .listen( 'pagehide', X_ViewPort );
343 X.ViewPort.listen( 'focus', X_ViewPort )
344 .listen( 'blur', X_ViewPort );
347 return X_Callback_UN_LISTEN;
350 function X_ViewPort_getWindowSize(){
352 [ X_ViewPort_rootElement.clientWidth, X_ViewPort_rootElement.clientHeight ] :
353 [ window.innerWidth, window.innerHeight ];
357 console.log( 'X.Dom dom:w3c=' + X_UA_DOM.W3C + ' ev:w3c=' + X_UA_EVENT.W3C );