リビジョン | 066d5d49b3e4d37eac0b417efdb06aa1fc16ccdf (tree) |
---|---|
日時 | 2014-09-22 13:04:37 |
作者 | itozyun <itozyun@user...> |
コミッター | itozyun |
Version 0.6.83, fix X.Type.isImage & X.Util.NinjaIframe.
@@ -63,7 +63,7 @@ X.Type = { | ||
63 | 63 | isImage : |
64 | 64 | function( v ){ |
65 | 65 | if( v && v.constructor === window.Image ) return true; |
66 | - if( v && v.constructor === window.HTMLImageElement ) return true; | |
66 | + if( v && window.HTMLImageElement && v.constructor === window.HTMLImageElement ) return true; // ie6- は constructor が undef、HTMLImageElement が undef なので、HTMLElement の存在確認が必要 | |
67 | 67 | if( X.UA.WebKit < 525.13 ){ // Safari3- |
68 | 68 | if( v && v.src !== undefined && v.onload !== undefined && X.Type.isNumber( v.height ) && X.Type.isNumber( v.width ) && X.Type.isBoolean( v.complete ) ){ |
69 | 69 | return true; |
@@ -279,7 +279,7 @@ if( X.UA.iOS ){ | ||
279 | 279 | window.addEventListener( 'scroll', function(){ |
280 | 280 | var last; |
281 | 281 | if( X_Timer_timerId ){ |
282 | - X_Timer_CLEAR_TIMEOUT( X_Timer_timerId ); | |
282 | + window.clearTimeout( X_Timer_timerId ); | |
283 | 283 | last = X_Timer_endTime - X.getTime(); |
284 | 284 | X_Timer_timerId = X_Timer_SET_TIMEOUT( X_Timer_onTimeout, 0 < last ? last : 0 ); |
285 | 285 | }; |
@@ -114,8 +114,8 @@ X.Dom = X.Class._override( | ||
114 | 114 | h.appendTo = h.appendToRoot = h.before = h.after = h.clone = h.remove = h.destroy = h.prevNode = h.nextNode = h.createText = h.append = h.appendAt = h.empty = h.html = h.text = |
115 | 115 | r.appendTo = r.appendToRoot = r.before = r.after = r.clone = r.remove = r.destroy = r.prevNode = r.nextNode = new Function( 'return this' ); |
116 | 116 | |
117 | - r._root = h._root = r; | |
118 | - r.parent = h; | |
117 | + r._root = h._root = r; | |
118 | + r.parent = h; | |
119 | 119 | h._xnodes = [ r ]; |
120 | 120 | |
121 | 121 | X.Dom.listenOnce( X.Dom.Event.DOM_PRE_INIT, function(){ |
@@ -16,7 +16,7 @@ X.Dom.DTD = { | ||
16 | 16 | META : true, |
17 | 17 | PARAM : true, |
18 | 18 | EMBED : true |
19 | - },//, | |
19 | + }, | |
20 | 20 | |
21 | 21 | TAG_FIX : |
22 | 22 | X.UA.IE && 4 <= X.UA.IE && X.UA.IE < 5 ? |
@@ -181,11 +181,11 @@ Node._getType = function( v ){ | ||
181 | 181 | if( !v ) return 0; |
182 | 182 | if( v === window ) return Node.IS_WINDOW; |
183 | 183 | if( v === document ) return Node.IS_DOCUMENT; |
184 | - if( X.Type.isImage( v ) ) return Node.IS_IMAGE; | |
185 | 184 | if( v.constructor === Node ) return Node.IS_XNODE; |
186 | 185 | if( v.constructor === X.Dom.NodeList ) return Node.IS_XNODE_LIST; |
187 | 186 | if( X.Type.isHTMLElement( v ) ) return Node.IS_RAW_HTML; |
188 | 187 | if( v.nodeType === 3 ) return Node.IS_RAW_TEXT; |
188 | + if( X.Type.isImage( v ) ) return Node.IS_IMAGE; | |
189 | 189 | if( typeof v === 'string' ){ |
190 | 190 | return '<' === v.charAt( 0 ) && v.charAt( v.length - 1 ) === '>' ? Node.IS_HTML_STRING : Node.IS_STRING; |
191 | 191 | }; |
@@ -5,10 +5,10 @@ X.Util.NinjaIframe = X.EventDispatcher.inherits( | ||
5 | 5 | |
6 | 6 | xnodeIframe : null, |
7 | 7 | |
8 | - _iwin : null, | |
8 | + _iwin : null, | |
9 | 9 | |
10 | - _html : null, | |
11 | - _name : null, | |
10 | + _html : '', | |
11 | + _name : '', | |
12 | 12 | _ready : false, |
13 | 13 | |
14 | 14 | Constructor : function( html ){ |
@@ -95,7 +95,11 @@ X.Util.NinjaIframe = X.EventDispatcher.inherits( | ||
95 | 95 | return this; |
96 | 96 | }; |
97 | 97 | |
98 | - this._iwin.location.reload(); | |
98 | + if( X.UA.IE5 || X.UA.IE55 ){ | |
99 | + this._iwin.location.href = 'about:blank'; // reload() では、IE5.5(IETester)で2回目移行の操作でerrorが出る(doc取得やopen,writeで) | |
100 | + } else { | |
101 | + this._iwin.location.reload(); | |
102 | + }; | |
99 | 103 | |
100 | 104 | if( !opt_html ) return this; |
101 | 105 |
@@ -120,17 +124,15 @@ X.Util.NinjaIframe = X.EventDispatcher.inherits( | ||
120 | 124 | ); |
121 | 125 | |
122 | 126 | function X_Util_NinjaIframe_writeToIframe( that ){ |
123 | -var raw = that.xnodeIframe._rawObject, | |
124 | - idoc = raw.contentDocument || that._iwin.document, | |
125 | - html = that._html; | |
126 | - | |
127 | + var raw = that.xnodeIframe._rawObject, | |
128 | + idoc = raw.contentDocument || that._iwin.document, | |
129 | + html = that._html; | |
130 | + | |
127 | 131 | delete that._html; |
128 | 132 | that._ready = true; |
129 | - | |
130 | - console.log( 'iframe import. ' + html ); | |
131 | - | |
133 | + | |
132 | 134 | idoc.open(); |
133 | - idoc.writeln( html ); // ここで script を書き出すので2度呼ばれる? | |
135 | + idoc.writeln( html ); | |
134 | 136 | idoc.close(); |
135 | 137 | }; |
136 | 138 |
@@ -19,12 +19,13 @@ X.Net = { | ||
19 | 19 | |
20 | 20 | // TODO chashe |
21 | 21 | // TODO iframe useful or not. |
22 | + // TODO file: では http: は使えない | |
22 | 23 | jsonp : function( url, useIframe ){ |
23 | 24 | return new X_NET_Queue( X_NET_TYPE_JSONP, url ); |
24 | 25 | }, |
25 | 26 | |
26 | 27 | image : function( url, useIframe ){ |
27 | - | |
28 | + return new X_NET_Queue( X_NET_TYPE_IMAGE, url ); | |
28 | 29 | }, |
29 | 30 | |
30 | 31 | amountQueue : function(){ |
@@ -43,12 +44,14 @@ var X_NET_IWrapper = function(){}; | ||
43 | 44 | var X_NET_TYPE_XHR = 1, |
44 | 45 | X_NET_TYPE_JSONP = 2, |
45 | 46 | X_NET_TYPE_FORM = 3, |
47 | + X_NET_TYPE_IMAGE = 4, | |
46 | 48 | |
47 | 49 | X_NET_QUEUE_LIST = [], |
48 | 50 | |
49 | 51 | X_NET_XHRWrapper, |
50 | 52 | X_NET_JSONPWrapper, |
51 | - X_NET_FORMWrapper, | |
53 | + X_NET_FormWrapper, | |
54 | + X_NET_ImageWrapper, | |
52 | 55 | |
53 | 56 | X_NET_currentWrapper, |
54 | 57 | X_NET_currentQueue, |
@@ -137,7 +140,10 @@ function X_NET_shiftQueue(){ | ||
137 | 140 | X_NET_currentWrapper = X_NET_JSONPWrapper; |
138 | 141 | break; |
139 | 142 | case X_NET_TYPE_FORM : |
140 | - X_NET_currentWrapper = X_NET_FORMWrapper; | |
143 | + X_NET_currentWrapper = X_NET_FormWrapper; | |
144 | + break; | |
145 | + case X_NET_TYPE_IMAGE : | |
146 | + X_NET_currentWrapper = X_NET_ImageWrapper; | |
141 | 147 | break; |
142 | 148 | }; |
143 | 149 |
@@ -1,22 +1,43 @@ | ||
1 | 1 | // https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest |
2 | 2 | // https://web.archive.org/web/20071101021832/http://web.paulownia.jp/script/ajax/xmlhttp4.html |
3 | +// https://web.archive.org/web/20091029170015/http://wiki.paulownia.jp/ajax/xmlhttprequest | |
4 | +/* | |
5 | + * http://ponpon-village.net/ajax/xmlhttp.htm | |
6 | + * IE のバージョンによっては、ActiveXObject("Msxml2.XMLHTTP.5.0") , ActiveXObject("Msxml2.XMLHTTP.4.0") , | |
7 | +ActiveXObject("Msxml2.XMLHTTP.3.0") , ActiveXObject("Msxml2.XMLHTTP") なども使用出来る。 | |
3 | 8 | |
9 | +http://vird2002.s8.xrea.com/javascript/XMLHttpRequest.html | |
10 | +// --- 使うべきオブジェクト | |
11 | +new ActiveXObject( 'Msxml2.XMLHTTP.3.0' ); // バージョン3.0 広範に利用されているので、今後も bugfix を行う | |
12 | +new ActiveXObject( 'Msxml2.XMLHTTP.6.0' ); // バージョン6.0 は最新版なので bugfix を続ける | |
13 | + | |
14 | +// --- 使うべきではないオブジェクト | |
15 | +new ActiveXObject( 'Microsoft.XMLHTTP' ); // Microsoft接頭辞は古いので指定すべきではない | |
16 | +new ActiveXObject( 'Msxml.XMLHTTP' ); // Msxml2接頭辞を指定すべき | |
17 | +new ActiveXObject( 'Msxml2.XMLHTTP' ); // バージョンを省略すると 3.0 として扱われるので、バージョンは明記すべき | |
18 | +new ActiveXObject( 'Msxml2.XMLHTTP.4.0' ); // バージョン4.0 は bugfix が行われないので、3.0 か 6.0 を指定すべき | |
19 | +new ActiveXObject( 'Msxml2.XMLHTTP.5.0' ); // バージョン5.0 は bugfix が行われないので、3.0 か 6.0 を指定すべき | |
20 | + | |
21 | + */ | |
4 | 22 | var X_Net_XHR_W3C = window[ 'XMLHttpRequest' ] && new XMLHttpRequest(), |
5 | 23 | X_Net_XHR_X_DOMAIN = window[ 'XDomainRequest' ] && new XDomainRequest(), |
6 | 24 | X_Net_XHR_VERSION = 0, |
7 | 25 | X_Net_XHR_ACTIVE_X = 5 <= X.UA.IE && X.UA.IE < 8 && X.UA.ActiveX && ( new Function( [ |
8 | 26 | 'var x=".XMLHTTP",', |
9 | 27 | 'm="MSXML2"+x,', |
10 | - 'v=[m+".6.0",m+".3.0",m,"Microsoft"+x,m+".4.0"],', | |
28 | + 'v=[m+".6.0",m+".3.0",m+".5.0",m+".4.0",m,"Microsoft"+x],', | |
11 | 29 | 'i=-1;', |
12 | - 'for(;i<3;){', | |
30 | + 'for(;i<5;){', | |
13 | 31 | 'try{', |
14 | - 'return new ActiveXObject(v[++i]);', | |
32 | + 'return[++i,new ActiveXObject(v[i])];', | |
15 | 33 | '}catch(e){}', |
16 | 34 | '}' |
17 | 35 | ].join( '' ) ) )(); |
18 | 36 | |
19 | - | |
37 | +if( X_Net_XHR_ACTIVE_X ){ | |
38 | + X_Net_XHR_VERSION = [ 6, 3, 5, 4, 2, 1 ][ X_Net_XHR_ACTIVE_X[ 0 ] ]; | |
39 | + X_Net_XHR_ACTIVE_X = X_Net_XHR_ACTIVE_X[ 1 ]; | |
40 | +}; | |
20 | 41 | |
21 | 42 | X.Net.XHR = { |
22 | 43 | // Opera7.6+, Safari1.2+, khtml3.?+, Gecko0.9.7+ |
@@ -89,15 +110,15 @@ if( X.Net.XHR.W3C || X_Net_XHR_ACTIVE_X ){ | ||
89 | 110 | if( X_Net_XHR_X_DOMAIN ){ |
90 | 111 | if( false /* isXDomain( url ) */ ){ // isXDomain |
91 | 112 | //if( raw !== X_Net_XHR_X_DOMAIN ){ |
92 | - X_NET_XHRWrapper._migrateEvent(); | |
113 | + X_EventDispatcher_migrateEvent( this ); | |
93 | 114 | X_NET_XHRWrapper._rawObject = X_Net_XHR_X_DOMAIN; |
94 | - X_NET_XHRWrapper._restoreEvent(); | |
115 | + X_EventDispatcher_restoreEvent( this ); | |
95 | 116 | //}; |
96 | 117 | } else { |
97 | 118 | //if( raw === X_Net_XHR_X_DOMAIN ){ |
98 | - X_NET_XHRWrapper._migrateEvent(); | |
119 | + X_EventDispatcher_migrateEvent( this ); | |
99 | 120 | X_NET_XHRWrapper._rawObject = X_Net_XHR_W3C || X_Net_XHR_ACTIVE_X; |
100 | - X_NET_XHRWrapper._restoreEvent(); | |
121 | + X_EventDispatcher_restoreEvent( this); | |
101 | 122 | //}; |
102 | 123 | }; |
103 | 124 | }; |
@@ -213,6 +234,7 @@ if( X.Net.XHR.W3C || X_Net_XHR_ACTIVE_X ){ | ||
213 | 234 | break; |
214 | 235 | case 'json' : |
215 | 236 | case 'moz-json' : |
237 | + data = raw[ 'response' ] || raw[ 'responseText' ]; // とりあえず | |
216 | 238 | break; |
217 | 239 | case 'document' : |
218 | 240 | case 'xml' : |
@@ -222,6 +244,7 @@ if( X.Net.XHR.W3C || X_Net_XHR_ACTIVE_X ){ | ||
222 | 244 | break; |
223 | 245 | case 'blob' : |
224 | 246 | case 'arraybuffer' : |
247 | + data = raw[ 'response' ] || raw[ 'responseText' ]; // とりあえず | |
225 | 248 | break; |
226 | 249 | }; |
227 | 250 |
@@ -6,6 +6,10 @@ | ||
6 | 6 | * http://kozo002.blogspot.jp/2012/07/ie9iframewindowparent.html |
7 | 7 | */ |
8 | 8 | |
9 | +/* | |
10 | + * IE6(IETester) で動かない,localhost | |
11 | + */ | |
12 | + | |
9 | 13 | X.Net.JSONP = { |
10 | 14 | cb : function( accessKey, jsonString, time, opt_json2FileSize ){ |
11 | 15 | if( accessKey !== X_NET_JSONP_ACCESS_KEY ) return; |
@@ -62,6 +66,7 @@ function X_NET_JSONP_loadScriptInNinjaIframe( url ){ | ||
62 | 66 | '<script src="', url, '"></script>' */ |
63 | 67 | '<script id="jp"></script>', |
64 | 68 | '<script>', |
69 | + 'nw=0;', | |
65 | 70 | 'function cb(o){nw-=+new Date;parent.X.Net.JSONP.cb(' + X_NET_JSONP_ACCESS_KEY + ',parent.JSON.stringify(o),-nw)}', |
66 | 71 | 'function tm(){jp.src="', url ,'";nw=+new Date}', |
67 | 72 | 'setTimeout(tm,16);', |
@@ -0,0 +1,116 @@ | ||
1 | +/* | |
2 | + * original | |
3 | + * LICENSE: MIT? | |
4 | + * URL: http://d.hatena.ne.jp/uupaa/20080413/1208067631 | |
5 | + * AUTHOR: uupaa.js@gmail.com | |
6 | + * | |
7 | + */ | |
8 | + | |
9 | +var X_Net_Image_hasImage = !!window[ 'Image' ]; | |
10 | + | |
11 | +if( !X_Net_Image_hasImage ){ | |
12 | + alert( 'no Image!' ); | |
13 | +}; | |
14 | + | |
15 | +/* | |
16 | + * TODO | |
17 | + * new Image() のときに Image オブジェクトを作るもの(IE8-)と、HTMLImageElement を作るものがある。 | |
18 | + * Image は、X.EventDispatcher で、<img> は X.Dom.Node で。 | |
19 | + */ | |
20 | +X_NET_ImageWrapper = ( X_Net_Image_hasImage ? X.EventDispatcher : X.Dom.Node ).inherits( | |
21 | + 'X.Net.Image', | |
22 | + X.Class.POOL_OBJECT, | |
23 | + { | |
24 | + _rawObject : X_Net_Image_hasImage && new Image, | |
25 | + | |
26 | + tick : 0, | |
27 | + timerID : 0, | |
28 | + finish : false, | |
29 | + abspath : null, | |
30 | + delay : null, | |
31 | + timeout : 0, | |
32 | + | |
33 | + Constructor : X_Net_Image_hasImage ? | |
34 | + (function(){ | |
35 | + this.listen( [ 'load', 'error', 'abort', X.Event.SUCCESS, X.Event.ERROR, X.Event.KILL_INSTANCE ] ); | |
36 | + }) : | |
37 | + (function(){ | |
38 | + this.SuperConstructor( document.createElement( 'img' ) ) | |
39 | + .appendTo( X.Dom.Node._systemNode ) | |
40 | + .listen( [ 'load', 'error', 'abort', X.Event.SUCCESS, X.Event.ERROR, X.Event.KILL_INSTANCE ] ); | |
41 | + }), | |
42 | + | |
43 | + load : function( abspath, opt_delay, opt_timeout ){ | |
44 | + this.abspath = abspath; | |
45 | + this.delay = opt_delay || 100; | |
46 | + this.timeout = opt_timeout || 10000; | |
47 | + this.timerID = X.Timer.add( this.delay, 0, this, this._detect ); | |
48 | + | |
49 | + X_Net_Image_hasImage ? ( this._rawObject.src = abspath ) : this.attr( 'src', abspath ); | |
50 | + }, | |
51 | + | |
52 | + handleEvent : function( e ){ | |
53 | + var size; | |
54 | + switch( e.type ){ | |
55 | + case 'error' : | |
56 | + case 'abort' : // TODO ?? | |
57 | + if( this.finish ) return; | |
58 | + this.finish = true; | |
59 | + this.timerID && X.Timer.remove( this.timerID ); | |
60 | + this.timerID = this.asyncDispatch( 0, { type : X.Event.ERROR } ); | |
61 | + break; | |
62 | + case 'load' : | |
63 | + // if( finish === true ) return; // これがあると firefox3.6 で駄目、、、 | |
64 | + // if( timer ) return; // これがあると safari3.2 で駄目、、、 | |
65 | + this.finish = true; | |
66 | + this.timerID && X.Timer.remove( this.timerID ); | |
67 | + if( X.UA.Opera && !this._rawObject.complete ){ | |
68 | + this.timerID = this.asyncDispatch( 0, { type : X.Event.ERROR } ); | |
69 | + return; | |
70 | + }; | |
71 | + size = X.Dom.Image.getActualDimension( X.UA.IE < 9 && X_Net_Image_hasImage ? this.abspath : this ); | |
72 | + this.timerID = this.asyncDispatch( 0, { | |
73 | + type : X.Event.SUCCESS, | |
74 | + src : this.abspath, | |
75 | + w : size[ 0 ], | |
76 | + h : size[ 1 ] | |
77 | + } ); | |
78 | + break; | |
79 | + case X.Event.SUCCESS : | |
80 | + case X.Event.ERROR : | |
81 | + this.timerID && X.Timer.remove( this.timerID ); | |
82 | + this.timerID = this.asyncDispatch( 0, X.Event.COMPLETE ); | |
83 | + break; | |
84 | + case X.Event.KILL_INSTANCE : | |
85 | + this.timerID && X.Timer.remove( this.timerID ); | |
86 | + !X_Net_Image_hasImage && this.destroy(); // if xnode | |
87 | + this.unlisten(); | |
88 | + break; | |
89 | + }; | |
90 | + }, | |
91 | + _detect : function(){ | |
92 | + if( this.finish ) return; | |
93 | + if( this._rawObject && this._rawObject.complete ){ | |
94 | + this.finish = true; | |
95 | + if( this._rawObject.width ) return; | |
96 | + X.Timer.remove( this.timerID ); | |
97 | + this.timerID = this.asyncDispatch( 0, X.Event.ERROR ); | |
98 | + } else | |
99 | + if( this.timeout < ( this.tick += this.delay ) ){ | |
100 | + this.finish = true; | |
101 | + X.Timer.remove( this.timerID ); | |
102 | + this.timerID = this.asyncDispatch( 0, X.Event.TIMEOUT ); | |
103 | + }; | |
104 | + }, | |
105 | + cancel : function(){ | |
106 | + this._rawObject && this._rawObject.abort(); | |
107 | + }, | |
108 | + | |
109 | + reset : function(){ | |
110 | + this.timerID && X.Timer.remove( this.timerID ); | |
111 | + this.timerID = 0; | |
112 | + this.finished = false; | |
113 | + this.abspath = null; | |
114 | + } | |
115 | + } | |
116 | +); |