|
0
|
1 |
/* |
|
|
2 |
Copyright (c) 2009, Yahoo! Inc. All rights reserved. |
|
|
3 |
Code licensed under the BSD License: |
|
|
4 |
http://developer.yahoo.net/yui/license.txt |
|
|
5 |
version: 3.0.0b1 |
|
|
6 |
build: 1163 |
|
|
7 |
*/ |
|
|
8 |
YUI.add('io-xdr', function(Y) { |
|
|
9 |
|
|
|
10 |
/** |
|
|
11 |
* Extends the IO base class to provide an alternate, Flash transport, for making |
|
|
12 |
* cross-domain requests. |
|
|
13 |
* @module io |
|
|
14 |
* @submodule io-xdr |
|
|
15 |
*/ |
|
|
16 |
|
|
|
17 |
/** |
|
|
18 |
* @event io:xdrReady |
|
|
19 |
* @description This event is fired by YUI.io when the specified transport is |
|
|
20 |
* ready for use. |
|
|
21 |
* @type Event Custom |
|
|
22 |
*/ |
|
|
23 |
var E_XDR_READY = 'io:xdrReady'; |
|
|
24 |
|
|
|
25 |
/** |
|
|
26 |
* @description Method that creates the Flash transport swf. |
|
|
27 |
* |
|
|
28 |
* @method _swf |
|
|
29 |
* @private |
|
|
30 |
* @static |
|
|
31 |
* @param {string} uri - location of IO.swf. |
|
|
32 |
* @param {string} yid - YUI instance id. |
|
|
33 |
* @return void |
|
|
34 |
*/ |
|
|
35 |
function _swf(uri, yid) { |
|
|
36 |
var XDR_SWF = '<object id="yuiIoSwf" type="application/x-shockwave-flash" data="' + |
|
|
37 |
uri + '" width="0" height="0">' + |
|
|
38 |
'<param name="movie" value="' + uri + '">' + |
|
|
39 |
'<param name="FlashVars" value="yid=' + yid + '">' + |
|
|
40 |
'<param name="allowScriptAccess" value="sameDomain">' + |
|
|
41 |
'</object>'; |
|
|
42 |
Y.get('body').appendChild(Y.Node.create(XDR_SWF)); |
|
|
43 |
} |
|
|
44 |
|
|
|
45 |
Y.mix(Y.io, { |
|
|
46 |
|
|
|
47 |
/** |
|
|
48 |
* @description Map of IO transports. |
|
|
49 |
* |
|
|
50 |
* @property _transport |
|
|
51 |
* @private |
|
|
52 |
* @static |
|
|
53 |
* @type object |
|
|
54 |
*/ |
|
|
55 |
_transport: {}, |
|
|
56 |
|
|
|
57 |
/** |
|
|
58 |
* @description Object that stores callback handlers for cross-domain requests |
|
|
59 |
* when using Flash as the transport. |
|
|
60 |
* |
|
|
61 |
* @property _fn |
|
|
62 |
* @private |
|
|
63 |
* @static |
|
|
64 |
* @type object |
|
|
65 |
*/ |
|
|
66 |
_fn: {}, |
|
|
67 |
|
|
|
68 |
/** |
|
|
69 |
* @description Method for accessing the transport's interface for making a |
|
|
70 |
* cross-domain transaction. |
|
|
71 |
* |
|
|
72 |
* @method _xdr |
|
|
73 |
* @private |
|
|
74 |
* @static |
|
|
75 |
* @param {string} uri - qualified path to transaction resource. |
|
|
76 |
* @param {object} o - Transaction object generated by _create() in io-base. |
|
|
77 |
* @param {object} c - configuration object for the transaction. |
|
|
78 |
* @return object |
|
|
79 |
*/ |
|
|
80 |
_xdr: function(uri, o, c) { |
|
|
81 |
if (c.on) { |
|
|
82 |
this._fn[o.id] = c.on; |
|
|
83 |
} |
|
|
84 |
o.c.send(uri, c, o.id); |
|
|
85 |
|
|
|
86 |
return o; |
|
|
87 |
}, |
|
|
88 |
|
|
|
89 |
|
|
|
90 |
/** |
|
|
91 |
* @description Fires event "io:xdrReady" |
|
|
92 |
* |
|
|
93 |
* @method xdrReady |
|
|
94 |
* @private |
|
|
95 |
* @static |
|
|
96 |
* @param {number} id - transaction id |
|
|
97 |
* @param {object} c - configuration object for the transaction. |
|
|
98 |
* |
|
|
99 |
* @return void |
|
|
100 |
*/ |
|
|
101 |
xdrReady: function(id) { |
|
|
102 |
Y.fire(E_XDR_READY, id); |
|
|
103 |
}, |
|
|
104 |
|
|
|
105 |
/** |
|
|
106 |
* @description Method to initialize the desired transport. |
|
|
107 |
* |
|
|
108 |
* @method transport |
|
|
109 |
* @public |
|
|
110 |
* @static |
|
|
111 |
* @param {object} o - object of transport configurations. |
|
|
112 |
* @return void |
|
|
113 |
*/ |
|
|
114 |
transport: function(o) { |
|
|
115 |
switch (o.id) { |
|
|
116 |
case 'flash': |
|
|
117 |
_swf(o.src, o.yid); |
|
|
118 |
this._transport.flash = Y.config.doc.getElementById('yuiIoSwf'); |
|
|
119 |
break; |
|
|
120 |
} |
|
|
121 |
} |
|
|
122 |
}); |
|
|
123 |
|
|
|
124 |
|
|
|
125 |
|
|
|
126 |
}, '3.0.0b1' ,{requires:['io-base']}); |