frame.js revision 6e43f558138d36538a82459ec79e0279ffae22e0
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrmYUI.add('frame', function(Y) {
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm /**
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm * Creates a wrapper around an iframe. It loads the content either from a local
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm * file or from script and creates a local YUI instance bound to that new window and document.
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm * @module editor
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm * @submodule frame
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm */
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm /**
ddc251b3cf95b0097b6a5ee39ea132bd4d7d5cbcjohanengelen * Creates a wrapper around an iframe. It loads the content either from a local
ddc251b3cf95b0097b6a5ee39ea132bd4d7d5cbcjohanengelen * file or from script and creates a local YUI instance bound to that new window and document.
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm * @class Frame
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm * @for Frame
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm * @extends Base
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm * @constructor
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm */
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm var Frame = function() {
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm Frame.superclass.constructor.apply(this, arguments);
6656f193fdace606d1b162d6dea0223bc295f0a6cilix };
6656f193fdace606d1b162d6dea0223bc295f0a6cilix
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm Y.extend(Frame, Y.Base, {
77a4a003111bd5cfb771d4849801c898aeb889b0cilix /**
77a4a003111bd5cfb771d4849801c898aeb889b0cilix * @private
04c99c338ffdc6e10cb6f5c18f6f06b3f555e8ebcilix * @property _ready
04c99c338ffdc6e10cb6f5c18f6f06b3f555e8ebcilix * @description Internal reference set when the content is ready.
04c99c338ffdc6e10cb6f5c18f6f06b3f555e8ebcilix * @type Boolean
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm */
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm _ready: null,
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm /**
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm * @private
d9c673867f424647c1586c356cc0ac1d34d0a98ajohanengelen * @property _rendered
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm * @description Internal reference set when render is called.
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm * @type Boolean
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm */
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm _rendered: null,
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm /**
ddc251b3cf95b0097b6a5ee39ea132bd4d7d5cbcjohanengelen * @private
ddc251b3cf95b0097b6a5ee39ea132bd4d7d5cbcjohanengelen * @property _iframe
ddc251b3cf95b0097b6a5ee39ea132bd4d7d5cbcjohanengelen * @description Internal Node reference to the iFrame or the window
ddc251b3cf95b0097b6a5ee39ea132bd4d7d5cbcjohanengelen * @type Node
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm */
8c39cbeab9949a0a7d6ae66b768a7352019e42f8johanengelen _iframe: null,
072916d0ef7dccd696b59381f50bcf776abccefbjohanengelen /**
dc98accfae7a38326b92d74fa4330ac8ccb5b778jfbarraud * @private
dc98accfae7a38326b92d74fa4330ac8ccb5b778jfbarraud * @property _instance
dc98accfae7a38326b92d74fa4330ac8ccb5b778jfbarraud * @description Internal reference to the YUI instance bound to the iFrame or window
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm * @type YUI
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm */
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm _instance: null,
8d9f5d586a04809427ce1df284a5720112177991cilix /**
70eb1fc448cb08acf3468f80fa2296c03b32afd2cilix * @private
c169f6cddd2da06cfb761339f445bbd8866f72a8buliabyak * @method _create
0563fd55cbad59e8a878e6d4cbbdd8e47f74488djohanengelen * @description Create the iframe or Window and get references to the Document & Window
0cc5b8d2f7b87c4222ee3662071bef1cb1f22b06bgk * @return {Object} Hash table containing references to the new Document & Window
0563fd55cbad59e8a878e6d4cbbdd8e47f74488djohanengelen */
f4db63be4e929f4706410914295deccaceea19cdcilix _create: function(cb) {
ab99111a42436818e6902e044c8f3af2b724263bcilix var win, doc, res, node;
b0c42c0dfcd02cc05126371948489a5a88b2e4b3cilix
3d0482af18ffb591c1d8ddecf516629e1bcd2ae4cilix this._iframe = Y.Node.create(Frame.HTML);
64aee804a6a47424f7994e60558351b8cf2ea4dbcilix this._iframe.setStyle('visibility', 'hidden');
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix this._iframe.set('src', this.get('src'));
044d712d4d03f8354962d54e47cfac2346a69ccccilix this.get('container').append(this._iframe);
61cfd957cd023c4f432ea0c7307784a56bf978e9cilix
e54ce05030e6aab675331e18f46f029f55ed1bf0cilix this._iframe.set('height', '99%');
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm var html = '',
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm extra_css = ((this.get('extracss')) ? '<style id="extra_css">' + this.get('extracss') + '</style>' : '');
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm Y.log('Creating the document from javascript', 'info', 'frame');
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm html = Y.substitute(Frame.PAGE_HTML, {
072916d0ef7dccd696b59381f50bcf776abccefbjohanengelen DIR: this.get('dir'),
8c39cbeab9949a0a7d6ae66b768a7352019e42f8johanengelen LANG: this.get('lang'),
dc98accfae7a38326b92d74fa4330ac8ccb5b778jfbarraud TITLE: this.get('title'),
dc98accfae7a38326b92d74fa4330ac8ccb5b778jfbarraud META: Frame.META,
dc98accfae7a38326b92d74fa4330ac8ccb5b778jfbarraud LINKED_CSS: this.get('linkedcss'),
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm CONTENT: this.get('content'),
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm BASE_HREF: this.get('basehref'),
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm DEFAULT_CSS: Frame.DEFAULT_CSS,
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm EXTRA_CSS: extra_css
0563fd55cbad59e8a878e6d4cbbdd8e47f74488djohanengelen });
8d9f5d586a04809427ce1df284a5720112177991cilix if (Y.config.doc.compatMode != 'BackCompat') {
70eb1fc448cb08acf3468f80fa2296c03b32afd2cilix Y.log('Adding Doctype to frame', 'info', 'frame');
c169f6cddd2da06cfb761339f445bbd8866f72a8buliabyak html = Frame.DOC_TYPE + "\n" + html;
0563fd55cbad59e8a878e6d4cbbdd8e47f74488djohanengelen } else {
0cc5b8d2f7b87c4222ee3662071bef1cb1f22b06bgk Y.log('DocType skipped because we are in BackCompat Mode.', 'warn', 'frame');
0563fd55cbad59e8a878e6d4cbbdd8e47f74488djohanengelen }
f4db63be4e929f4706410914295deccaceea19cdcilix
b0c42c0dfcd02cc05126371948489a5a88b2e4b3cilix Y.log('Injecting content into iframe', 'info', 'frame');
b0c42c0dfcd02cc05126371948489a5a88b2e4b3cilix
3d0482af18ffb591c1d8ddecf516629e1bcd2ae4cilix
64aee804a6a47424f7994e60558351b8cf2ea4dbcilix res = this._resolveWinDoc();
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix res.doc.open();
044d712d4d03f8354962d54e47cfac2346a69ccccilix res.doc.write(html);
61cfd957cd023c4f432ea0c7307784a56bf978e9cilix res.doc.close();
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm if (this.get('designMode')) {
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm res.doc.designMode = 'on';
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm }
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm if (!res.doc.documentElement) {
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm Y.log('document.documentElement was not found, running timer', 'warn', 'frame');
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm var timer = Y.later(1, this, function() {
8c39cbeab9949a0a7d6ae66b768a7352019e42f8johanengelen if (res.doc && res.doc.documentElement) {
92fe3142613d000eff89db8a983b3b18b14eee79johanengelen Y.log('document.documentElement found inside timer', 'info', 'frame');
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm cb(res);
072916d0ef7dccd696b59381f50bcf776abccefbjohanengelen timer.cancel();
92fe3142613d000eff89db8a983b3b18b14eee79johanengelen }
42e99769805c14a5cc01c805faa3c3b03f9dd1c0johanengelen }, null, true);
dc98accfae7a38326b92d74fa4330ac8ccb5b778jfbarraud } else {
92fe3142613d000eff89db8a983b3b18b14eee79johanengelen Y.log('document.documentElement found', 'info', 'frame');
dc98accfae7a38326b92d74fa4330ac8ccb5b778jfbarraud cb(res);
dc98accfae7a38326b92d74fa4330ac8ccb5b778jfbarraud }
92fe3142613d000eff89db8a983b3b18b14eee79johanengelen
dc98accfae7a38326b92d74fa4330ac8ccb5b778jfbarraud },
dc98accfae7a38326b92d74fa4330ac8ccb5b778jfbarraud /**
92fe3142613d000eff89db8a983b3b18b14eee79johanengelen * @private
dc98accfae7a38326b92d74fa4330ac8ccb5b778jfbarraud * @method _resolveWinDoc
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm * @description Resolves the document and window from an iframe or window instance
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm * @param {Object} c The YUI Config to add the window and document to
92fe3142613d000eff89db8a983b3b18b14eee79johanengelen * @return {Object} Object hash of window and document references, if a YUI config was passed, it is returned.
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm */
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm _resolveWinDoc: function(c) {
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm var config = (c) ? c : {};
92fe3142613d000eff89db8a983b3b18b14eee79johanengelen config.win = Y.Node.getDOMNode(this._iframe.get('contentWindow'));
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm config.doc = Y.Node.getDOMNode(this._iframe.get('contentWindow.document'));
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm if (!config.doc) {
92fe3142613d000eff89db8a983b3b18b14eee79johanengelen config.doc = Y.config.doc;
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm }
0563fd55cbad59e8a878e6d4cbbdd8e47f74488djohanengelen if (!config.win) {
0563fd55cbad59e8a878e6d4cbbdd8e47f74488djohanengelen config.win = Y.config.win;
0563fd55cbad59e8a878e6d4cbbdd8e47f74488djohanengelen }
0563fd55cbad59e8a878e6d4cbbdd8e47f74488djohanengelen return config;
0563fd55cbad59e8a878e6d4cbbdd8e47f74488djohanengelen },
0563fd55cbad59e8a878e6d4cbbdd8e47f74488djohanengelen /**
8d9f5d586a04809427ce1df284a5720112177991cilix * @private
92fe3142613d000eff89db8a983b3b18b14eee79johanengelen * @method _onDomEvent
8d9f5d586a04809427ce1df284a5720112177991cilix * @description Generic handler for all DOM events fired by the iframe or window. This handler
70eb1fc448cb08acf3468f80fa2296c03b32afd2cilix * takes the current EventFacade and augments it to fire on the Frame host. It adds two new properties
92fe3142613d000eff89db8a983b3b18b14eee79johanengelen * to the EventFacade called frameX and frameY which adds the scroll and xy position of the iframe
70eb1fc448cb08acf3468f80fa2296c03b32afd2cilix * to the original pageX and pageY of the event so external nodes can be positioned over the frame.
c169f6cddd2da06cfb761339f445bbd8866f72a8buliabyak * @param {Event.Facade} e
c169f6cddd2da06cfb761339f445bbd8866f72a8buliabyak */
c169f6cddd2da06cfb761339f445bbd8866f72a8buliabyak _onDomEvent: function(e) {
6f4a90e526af850ffc36064f58f09c190f3b633fjohanengelen var xy, node;
6f4a90e526af850ffc36064f58f09c190f3b633fjohanengelen
6f4a90e526af850ffc36064f58f09c190f3b633fjohanengelen //Y.log('onDOMEvent: ' + e.type, 'info', 'frame');
f4db63be4e929f4706410914295deccaceea19cdcilix e.frameX = e.frameY = 0;
f4db63be4e929f4706410914295deccaceea19cdcilix
f4db63be4e929f4706410914295deccaceea19cdcilix if (e.pageX > 0 || e.pageY > 0) {
ab99111a42436818e6902e044c8f3af2b724263bcilix if (e.type.substring(0, 3) !== 'key') {
ab99111a42436818e6902e044c8f3af2b724263bcilix node = this._instance.one('win');
ab99111a42436818e6902e044c8f3af2b724263bcilix xy = this._iframe.getXY();
b0c42c0dfcd02cc05126371948489a5a88b2e4b3cilix e.frameX = xy[0] + e.pageX - node.get('scrollLeft');
b0c42c0dfcd02cc05126371948489a5a88b2e4b3cilix e.frameY = xy[1] + e.pageY - node.get('scrollTop');
b0c42c0dfcd02cc05126371948489a5a88b2e4b3cilix }
3d0482af18ffb591c1d8ddecf516629e1bcd2ae4cilix }
3d0482af18ffb591c1d8ddecf516629e1bcd2ae4cilix
3d0482af18ffb591c1d8ddecf516629e1bcd2ae4cilix e.frameTarget = e.target;
64aee804a6a47424f7994e60558351b8cf2ea4dbcilix e.frameCurrentTarget = e.currentTarget;
64aee804a6a47424f7994e60558351b8cf2ea4dbcilix e.frameEvent = e;
64aee804a6a47424f7994e60558351b8cf2ea4dbcilix
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix this.fire('dom:' + e.type, e);
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix },
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix initializer: function() {
044d712d4d03f8354962d54e47cfac2346a69ccccilix this.publish('ready', {
044d712d4d03f8354962d54e47cfac2346a69ccccilix emitFacade: true,
044d712d4d03f8354962d54e47cfac2346a69ccccilix defaultFn: this._defReadyFn
61cfd957cd023c4f432ea0c7307784a56bf978e9cilix });
61cfd957cd023c4f432ea0c7307784a56bf978e9cilix },
61cfd957cd023c4f432ea0c7307784a56bf978e9cilix destructor: function() {
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm var inst = this.getInstance();
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm inst.one('doc').detachAll();
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm inst = null;
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm this._iframe.remove();
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm },
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm /**
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm * @private
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm * @method _DOMPaste
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm * @description Simple pass thru handler for the paste event so we can do content cleanup
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm * @param {Event.Facade} e
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm */
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm _DOMPaste: function(e) {
6656f193fdace606d1b162d6dea0223bc295f0a6cilix var inst = this.getInstance(),
6656f193fdace606d1b162d6dea0223bc295f0a6cilix data = '', win = inst.config.win;
6656f193fdace606d1b162d6dea0223bc295f0a6cilix
6656f193fdace606d1b162d6dea0223bc295f0a6cilix if (e._event.originalTarget) {
6656f193fdace606d1b162d6dea0223bc295f0a6cilix data = e._event.originalTarget;
6656f193fdace606d1b162d6dea0223bc295f0a6cilix }
6656f193fdace606d1b162d6dea0223bc295f0a6cilix if (e._event.clipboardData) {
6656f193fdace606d1b162d6dea0223bc295f0a6cilix data = e._event.clipboardData.getData('Text');
6656f193fdace606d1b162d6dea0223bc295f0a6cilix }
6656f193fdace606d1b162d6dea0223bc295f0a6cilix
6656f193fdace606d1b162d6dea0223bc295f0a6cilix if (win.clipboardData) {
6656f193fdace606d1b162d6dea0223bc295f0a6cilix data = win.clipboardData.getData('Text');
6656f193fdace606d1b162d6dea0223bc295f0a6cilix if (data === '') { // Could be empty, or failed
6656f193fdace606d1b162d6dea0223bc295f0a6cilix // Verify failure
6656f193fdace606d1b162d6dea0223bc295f0a6cilix if (!win.clipboardData.setData('Text', data)) {
6656f193fdace606d1b162d6dea0223bc295f0a6cilix data = null;
d7e43efbcb4e431ff2fc52941513cc1bd614afa5cilix }
6656f193fdace606d1b162d6dea0223bc295f0a6cilix }
6656f193fdace606d1b162d6dea0223bc295f0a6cilix }
6656f193fdace606d1b162d6dea0223bc295f0a6cilix
6656f193fdace606d1b162d6dea0223bc295f0a6cilix
6656f193fdace606d1b162d6dea0223bc295f0a6cilix e.frameTarget = e.target;
6656f193fdace606d1b162d6dea0223bc295f0a6cilix e.frameCurrentTarget = e.currentTarget;
6656f193fdace606d1b162d6dea0223bc295f0a6cilix e.frameEvent = e;
6656f193fdace606d1b162d6dea0223bc295f0a6cilix
6656f193fdace606d1b162d6dea0223bc295f0a6cilix if (data) {
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm e.clipboardData = {
fbb4eb8b63e74d9441220a73a8ca858425be4bd4johanengelen data: data,
71146abe8aba032d73788a625fee5769a581bd3ccilix getData: function() {
77a4a003111bd5cfb771d4849801c898aeb889b0cilix return data;
04c99c338ffdc6e10cb6f5c18f6f06b3f555e8ebcilix }
fbb4eb8b63e74d9441220a73a8ca858425be4bd4johanengelen };
9ce14357bb94b9dd92ad40bf43ef435a257b355acilix } else {
9ce14357bb94b9dd92ad40bf43ef435a257b355acilix Y.log('Failed to collect clipboard data', 'warn', 'frame');
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm e.clipboardData = null;
71146abe8aba032d73788a625fee5769a581bd3ccilix }
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm this.fire('dom:paste', e);
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm },
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm /**
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm * @private
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm * @method _defReadyFn
eaa9bdc7bf7b73397e536edd47490d84e4420bd8bryce * @description Binds DOM events, sets the iframe to visible and fires the ready event
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm */
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm _defReadyFn: function() {
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm var inst = this.getInstance(),
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm fn = Y.bind(this._onDomEvent, this),
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm kfn = ((Y.UA.ie) ? Y.throttle(fn, 200) : fn);
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm inst.Node.DOM_EVENTS.activate = 1;
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm inst.Node.DOM_EVENTS.focusin = 1;
c90010388b0d4045c26e81c2be28beedcb36c7d3cilix inst.Node.DOM_EVENTS.deactivate = 1;
c90010388b0d4045c26e81c2be28beedcb36c7d3cilix inst.Node.DOM_EVENTS.focusout = 1;
c90010388b0d4045c26e81c2be28beedcb36c7d3cilix
c90010388b0d4045c26e81c2be28beedcb36c7d3cilix //Y.each(inst.Node.DOM_EVENTS, function(v, k) {
c90010388b0d4045c26e81c2be28beedcb36c7d3cilix Y.each(Frame.DOM_EVENTS, function(v, k) {
77a4a003111bd5cfb771d4849801c898aeb889b0cilix if (v === 1) {
77a4a003111bd5cfb771d4849801c898aeb889b0cilix if (k !== 'focus' && k !== 'blur' && k !== 'paste') {
77a4a003111bd5cfb771d4849801c898aeb889b0cilix //Y.log('Adding DOM event to frame: ' + k, 'info', 'frame');
262d0c3f05130d86368d95f110aa8ccab5f83e5ccilix if (k.substring(0, 3) === 'key') {
262d0c3f05130d86368d95f110aa8ccab5f83e5ccilix inst.on(k, kfn, inst.config.doc);
262d0c3f05130d86368d95f110aa8ccab5f83e5ccilix } else {
262d0c3f05130d86368d95f110aa8ccab5f83e5ccilix inst.on(k, fn, inst.config.doc);
262d0c3f05130d86368d95f110aa8ccab5f83e5ccilix }
77a4a003111bd5cfb771d4849801c898aeb889b0cilix }
77a4a003111bd5cfb771d4849801c898aeb889b0cilix }
77a4a003111bd5cfb771d4849801c898aeb889b0cilix }, this);
23d859f2ce09c04ed802cb4912cc9c50f512f0a2bgk
2d107ef9730aff3f4d776ae0c2f7d983e289ce02joncruz inst.Node.DOM_EVENTS.paste = 1;
23d859f2ce09c04ed802cb4912cc9c50f512f0a2bgk
23d859f2ce09c04ed802cb4912cc9c50f512f0a2bgk inst.on('paste', Y.bind(this._DOMPaste, this), inst.one('body'));
23d859f2ce09c04ed802cb4912cc9c50f512f0a2bgk
23d859f2ce09c04ed802cb4912cc9c50f512f0a2bgk //Adding focus/blur to the window object
77a4a003111bd5cfb771d4849801c898aeb889b0cilix inst.on('focus', fn, inst.config.win);
147c8e03bb214f85cd5906ddc6413c4293c4baa9cilix inst.on('blur', fn, inst.config.win);
147c8e03bb214f85cd5906ddc6413c4293c4baa9cilix
147c8e03bb214f85cd5906ddc6413c4293c4baa9cilix inst._use = inst.use;
77a4a003111bd5cfb771d4849801c898aeb889b0cilix inst.use = Y.bind(this.use, this);
77a4a003111bd5cfb771d4849801c898aeb889b0cilix
77a4a003111bd5cfb771d4849801c898aeb889b0cilix this._iframe.setStyles({
77a4a003111bd5cfb771d4849801c898aeb889b0cilix visibility: 'inherit'
77a4a003111bd5cfb771d4849801c898aeb889b0cilix });
77a4a003111bd5cfb771d4849801c898aeb889b0cilix inst.one('body').setStyle('display', 'block');
77a4a003111bd5cfb771d4849801c898aeb889b0cilix },
77a4a003111bd5cfb771d4849801c898aeb889b0cilix /**
77a4a003111bd5cfb771d4849801c898aeb889b0cilix * @private
77a4a003111bd5cfb771d4849801c898aeb889b0cilix * @method _onContentReady
77a4a003111bd5cfb771d4849801c898aeb889b0cilix * @description Called once the content is available in the frame/window and calls the final use call
77a4a003111bd5cfb771d4849801c898aeb889b0cilix * on the internal instance so that the modules are loaded properly.
77a4a003111bd5cfb771d4849801c898aeb889b0cilix */
77a4a003111bd5cfb771d4849801c898aeb889b0cilix _onContentReady: function(e) {
77a4a003111bd5cfb771d4849801c898aeb889b0cilix if (!this._ready) {
77a4a003111bd5cfb771d4849801c898aeb889b0cilix this._ready = true;
77a4a003111bd5cfb771d4849801c898aeb889b0cilix var inst = this.getInstance(),
77a4a003111bd5cfb771d4849801c898aeb889b0cilix args = Y.clone(this.get('use'));
77a4a003111bd5cfb771d4849801c898aeb889b0cilix
77a4a003111bd5cfb771d4849801c898aeb889b0cilix this.fire('contentready');
77a4a003111bd5cfb771d4849801c898aeb889b0cilix
23d859f2ce09c04ed802cb4912cc9c50f512f0a2bgk Y.log('On available for body of iframe', 'info', 'frame');
97a20864afec63a0b7bb757b628ee2ae596cf648cilix if (e) {
97a20864afec63a0b7bb757b628ee2ae596cf648cilix inst.config.doc = Y.Node.getDOMNode(e.target);
97a20864afec63a0b7bb757b628ee2ae596cf648cilix }
97a20864afec63a0b7bb757b628ee2ae596cf648cilix //TODO Circle around and deal with CSS loading...
97a20864afec63a0b7bb757b628ee2ae596cf648cilix args.push(Y.bind(function() {
97a20864afec63a0b7bb757b628ee2ae596cf648cilix Y.log('Callback from final internal use call', 'info', 'frame');
97a20864afec63a0b7bb757b628ee2ae596cf648cilix if (inst.Selection) {
97a20864afec63a0b7bb757b628ee2ae596cf648cilix inst.Selection.DEFAULT_BLOCK_TAG = this.get('defaultblock');
77a4a003111bd5cfb771d4849801c898aeb889b0cilix }
77a4a003111bd5cfb771d4849801c898aeb889b0cilix
77a4a003111bd5cfb771d4849801c898aeb889b0cilix this.fire('ready');
77a4a003111bd5cfb771d4849801c898aeb889b0cilix }, this));
77a4a003111bd5cfb771d4849801c898aeb889b0cilix Y.log('Calling use on internal instance: ' + args, 'info', 'frame');
77a4a003111bd5cfb771d4849801c898aeb889b0cilix inst.use.apply(inst, args);
2d2706a9d621c0da51b7c4178fd5c7c5e4765122joncruz
77a4a003111bd5cfb771d4849801c898aeb889b0cilix inst.one('doc').get('documentElement').addClass('yui-js-enabled');
77a4a003111bd5cfb771d4849801c898aeb889b0cilix }
77a4a003111bd5cfb771d4849801c898aeb889b0cilix },
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm /**
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm * @private
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm * @method _resolveBaseHref
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm * @description Resolves the basehref of the page the frame is created on. Only applies to dynamic content.
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm * @param {String} href The new value to use, if empty it will be resolved from the current url.
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm * @return {String}
b802808a0226a87371021393c4f1da776aa6a6adjohanengelen */
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm _resolveBaseHref: function(href) {
b802808a0226a87371021393c4f1da776aa6a6adjohanengelen if (!href || href === '') {
dda97aeba7480d08320ebceecae13b8531db1b81johanengelen href = Y.config.doc.location.href;
a2fbdfc8e80d3d1845bf0d5df989726ae2ffd5bfjohanengelen if (href.indexOf('?') !== -1) { //Remove the query string
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm href = href.substring(0, href.indexOf('?'));
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm }
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm href = href.substring(0, href.lastIndexOf('/')) + '/';
ecda720053ff791e35dae3c5c1177bc225b6cdf1johanengelen }
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm return href;
46c4893a7458eda6edcd064121bc000634af7a09johanengelen },
46c4893a7458eda6edcd064121bc000634af7a09johanengelen /**
46c4893a7458eda6edcd064121bc000634af7a09johanengelen * @private
46c4893a7458eda6edcd064121bc000634af7a09johanengelen * @method _getHTML
46c4893a7458eda6edcd064121bc000634af7a09johanengelen * @description Get the content from the iframe
46c4893a7458eda6edcd064121bc000634af7a09johanengelen * @param {String} html The raw HTML from the body of the iframe.
46c4893a7458eda6edcd064121bc000634af7a09johanengelen * @return {String}
46c4893a7458eda6edcd064121bc000634af7a09johanengelen */
46c4893a7458eda6edcd064121bc000634af7a09johanengelen _getHTML: function(html) {
46c4893a7458eda6edcd064121bc000634af7a09johanengelen if (this._ready) {
46c4893a7458eda6edcd064121bc000634af7a09johanengelen var inst = this.getInstance();
46c4893a7458eda6edcd064121bc000634af7a09johanengelen html = inst.one('body').get('innerHTML');
46c4893a7458eda6edcd064121bc000634af7a09johanengelen }
46c4893a7458eda6edcd064121bc000634af7a09johanengelen return html;
46c4893a7458eda6edcd064121bc000634af7a09johanengelen },
46c4893a7458eda6edcd064121bc000634af7a09johanengelen /**
46c4893a7458eda6edcd064121bc000634af7a09johanengelen * @private
46c4893a7458eda6edcd064121bc000634af7a09johanengelen * @method _setHTML
46c4893a7458eda6edcd064121bc000634af7a09johanengelen * @description Set the content of the iframe
46c4893a7458eda6edcd064121bc000634af7a09johanengelen * @param {String} html The raw HTML to set the body of the iframe to.
46c4893a7458eda6edcd064121bc000634af7a09johanengelen * @return {String}
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm */
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm _setHTML: function(html) {
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm if (this._ready) {
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm var inst = this.getInstance();
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm inst.one('body').set('innerHTML', html);
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm } else {
ecda720053ff791e35dae3c5c1177bc225b6cdf1johanengelen //This needs to be wrapped in a contentready callback for the !_ready state
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm this.on('contentready', Y.bind(function(html, e) {
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm var inst = this.getInstance();
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm inst.one('body').set('innerHTML', html);
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm }, this, html));
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm }
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm return html;
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm },
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm /**
93bb287e28a818fd5ba61b99d012e0500a49ccf6johanengelen * @private
93bb287e28a818fd5ba61b99d012e0500a49ccf6johanengelen * @method _setLinkedCSS
93bb287e28a818fd5ba61b99d012e0500a49ccf6johanengelen * @description Set's the linked CSS on the instance..
93bb287e28a818fd5ba61b99d012e0500a49ccf6johanengelen */
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm _getLinkedCSS: function(urls) {
93bb287e28a818fd5ba61b99d012e0500a49ccf6johanengelen if (!Y.Lang.isArray(urls)) {
93bb287e28a818fd5ba61b99d012e0500a49ccf6johanengelen urls = [urls];
2d107ef9730aff3f4d776ae0c2f7d983e289ce02joncruz }
93bb287e28a818fd5ba61b99d012e0500a49ccf6johanengelen var str = '';
93bb287e28a818fd5ba61b99d012e0500a49ccf6johanengelen if (!this._ready) {
93bb287e28a818fd5ba61b99d012e0500a49ccf6johanengelen Y.each(urls, function(v) {
93bb287e28a818fd5ba61b99d012e0500a49ccf6johanengelen if (v !== '') {
93bb287e28a818fd5ba61b99d012e0500a49ccf6johanengelen str += '<link rel="stylesheet" href="' + v + '" type="text/css">';
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm }
93bb287e28a818fd5ba61b99d012e0500a49ccf6johanengelen });
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm } else {
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm str = urls;
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm }
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm return str;
0fc5ce7045233dae7e15fdc86774370f1b1d73cbjohanengelen },
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm /**
0fc5ce7045233dae7e15fdc86774370f1b1d73cbjohanengelen * @private
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm * @method _setLinkedCSS
93bb287e28a818fd5ba61b99d012e0500a49ccf6johanengelen * @description Set's the linked CSS on the instance..
93bb287e28a818fd5ba61b99d012e0500a49ccf6johanengelen */
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm _setLinkedCSS: function(css) {
93bb287e28a818fd5ba61b99d012e0500a49ccf6johanengelen if (this._ready) {
2d107ef9730aff3f4d776ae0c2f7d983e289ce02joncruz var inst = this.getInstance();
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm inst.Get.css(css);
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm }
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm return css;
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm },
93bb287e28a818fd5ba61b99d012e0500a49ccf6johanengelen /**
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm * @private
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm * @method _setExtraCSS
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm * @description Set's the extra CSS on the instance..
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm */
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm _setExtraCSS: function(css) {
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm if (this._ready) {
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm var inst = this.getInstance(),
93bb287e28a818fd5ba61b99d012e0500a49ccf6johanengelen node = inst.get('#extra_css');
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm node.remove();
5be124ad592f5c71eca838ad2eaac9ffa953605fcilix inst.one('head').append('<style id="extra_css">' + css + '</style>');
73d455c08e8062e257dd052d2d690b9300434351cilix }
5be124ad592f5c71eca838ad2eaac9ffa953605fcilix return css;
73d455c08e8062e257dd052d2d690b9300434351cilix },
5be124ad592f5c71eca838ad2eaac9ffa953605fcilix /**
5be124ad592f5c71eca838ad2eaac9ffa953605fcilix * @private
5be124ad592f5c71eca838ad2eaac9ffa953605fcilix * @method _instanceLoaded
5be124ad592f5c71eca838ad2eaac9ffa953605fcilix * @description Called from the first YUI instance that sets up the internal instance.
5be124ad592f5c71eca838ad2eaac9ffa953605fcilix * This loads the content into the window/frame and attaches the contentready event.
5be124ad592f5c71eca838ad2eaac9ffa953605fcilix * @param {YUI} inst The internal YUI instance bound to the frame/window
5be124ad592f5c71eca838ad2eaac9ffa953605fcilix */
5be124ad592f5c71eca838ad2eaac9ffa953605fcilix _instanceLoaded: function(inst) {
5be124ad592f5c71eca838ad2eaac9ffa953605fcilix this._instance = inst;
5be124ad592f5c71eca838ad2eaac9ffa953605fcilix this._onContentReady();
5be124ad592f5c71eca838ad2eaac9ffa953605fcilix
5be124ad592f5c71eca838ad2eaac9ffa953605fcilix var doc = this._instance.config.doc;
5be124ad592f5c71eca838ad2eaac9ffa953605fcilix
5be124ad592f5c71eca838ad2eaac9ffa953605fcilix if (this.get('designMode')) {
5be124ad592f5c71eca838ad2eaac9ffa953605fcilix if (!Y.UA.ie) {
5be124ad592f5c71eca838ad2eaac9ffa953605fcilix try {
73d455c08e8062e257dd052d2d690b9300434351cilix //Force other browsers into non CSS styling
73d455c08e8062e257dd052d2d690b9300434351cilix doc.execCommand('styleWithCSS', false, false);
73d455c08e8062e257dd052d2d690b9300434351cilix doc.execCommand('insertbronreturn', false, false);
1e944d29efb206f5d0b5d1069cb098e22169d548cilix } catch (err) {}
79d46cc367c4181803d9a7a327b163643f23e8a7cilix }
1e944d29efb206f5d0b5d1069cb098e22169d548cilix }
79d46cc367c4181803d9a7a327b163643f23e8a7cilix },
79d46cc367c4181803d9a7a327b163643f23e8a7cilix //BEGIN PUBLIC METHODS
1e944d29efb206f5d0b5d1069cb098e22169d548cilix /**
5ce8d034d9fe78f969629cfe65d1a2518f173ba9cilix * @method use
5ce8d034d9fe78f969629cfe65d1a2518f173ba9cilix * @description This is a scoped version of the normal YUI.use method & is bound to this frame/window.
1e944d29efb206f5d0b5d1069cb098e22169d548cilix * At setup, the inst.use method is mapped to this method.
1e944d29efb206f5d0b5d1069cb098e22169d548cilix */
73d455c08e8062e257dd052d2d690b9300434351cilix use: function() {
73d455c08e8062e257dd052d2d690b9300434351cilix Y.log('Calling augmented use after ready', 'info', 'frame');
73d455c08e8062e257dd052d2d690b9300434351cilix var inst = this.getInstance(),
04c99c338ffdc6e10cb6f5c18f6f06b3f555e8ebcilix args = Y.Array(arguments),
04c99c338ffdc6e10cb6f5c18f6f06b3f555e8ebcilix cb = false;
04c99c338ffdc6e10cb6f5c18f6f06b3f555e8ebcilix
147c8e03bb214f85cd5906ddc6413c4293c4baa9cilix if (Y.Lang.isFunction(args[args.length - 1])) {
04c99c338ffdc6e10cb6f5c18f6f06b3f555e8ebcilix cb = args.pop();
04c99c338ffdc6e10cb6f5c18f6f06b3f555e8ebcilix }
bb78cf2c3a2ee8ea2c98433128556847f03f5799cilix if (cb) {
bb78cf2c3a2ee8ea2c98433128556847f03f5799cilix args.push(function() {
147c8e03bb214f85cd5906ddc6413c4293c4baa9cilix Y.log('Internal callback from augmented use', 'info', 'frame');
bb78cf2c3a2ee8ea2c98433128556847f03f5799cilix cb.apply(inst, arguments);
04c99c338ffdc6e10cb6f5c18f6f06b3f555e8ebcilix
04c99c338ffdc6e10cb6f5c18f6f06b3f555e8ebcilix });
04c99c338ffdc6e10cb6f5c18f6f06b3f555e8ebcilix }
04c99c338ffdc6e10cb6f5c18f6f06b3f555e8ebcilix inst._use.apply(inst, args);
bb78cf2c3a2ee8ea2c98433128556847f03f5799cilix },
732fb09f9c502000068a77667c3356cbbd5d39d5cilix /**
732fb09f9c502000068a77667c3356cbbd5d39d5cilix * @method delegate
732fb09f9c502000068a77667c3356cbbd5d39d5cilix * @description A delegate method passed to the instance's delegate method
732fb09f9c502000068a77667c3356cbbd5d39d5cilix * @param {String} type The type of event to listen for
732fb09f9c502000068a77667c3356cbbd5d39d5cilix * @param {Function} fn The method to attach
732fb09f9c502000068a77667c3356cbbd5d39d5cilix * @param {String} cont The container to act as a delegate, if no "sel" passed, the body is assumed as the container.
732fb09f9c502000068a77667c3356cbbd5d39d5cilix * @param {String} sel The selector to match in the event (optional)
732fb09f9c502000068a77667c3356cbbd5d39d5cilix * @return {EventHandle} The Event handle returned from Y.delegate
732fb09f9c502000068a77667c3356cbbd5d39d5cilix */
732fb09f9c502000068a77667c3356cbbd5d39d5cilix delegate: function(type, fn, cont, sel) {
732fb09f9c502000068a77667c3356cbbd5d39d5cilix var inst = this.getInstance();
04c99c338ffdc6e10cb6f5c18f6f06b3f555e8ebcilix if (!inst) {
04c99c338ffdc6e10cb6f5c18f6f06b3f555e8ebcilix Y.log('Delegate events can not be attached until after the ready event has fired.', 'error', 'iframe');
04c99c338ffdc6e10cb6f5c18f6f06b3f555e8ebcilix return false;
04c99c338ffdc6e10cb6f5c18f6f06b3f555e8ebcilix }
2d2706a9d621c0da51b7c4178fd5c7c5e4765122joncruz if (!sel) {
04c99c338ffdc6e10cb6f5c18f6f06b3f555e8ebcilix sel = cont;
04c99c338ffdc6e10cb6f5c18f6f06b3f555e8ebcilix cont = 'body';
04c99c338ffdc6e10cb6f5c18f6f06b3f555e8ebcilix }
04c99c338ffdc6e10cb6f5c18f6f06b3f555e8ebcilix return inst.delegate(type, fn, cont, sel);
04c99c338ffdc6e10cb6f5c18f6f06b3f555e8ebcilix },
c0cd5511d3b975ebe07d019c1f5528108725e438johanengelen /**
73d455c08e8062e257dd052d2d690b9300434351cilix * @method getInstance
73d455c08e8062e257dd052d2d690b9300434351cilix * @description Get a reference to the internal YUI instance.
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm * @return {YUI} The internal YUI instance
c0cd5511d3b975ebe07d019c1f5528108725e438johanengelen */
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm getInstance: function() {
c0cd5511d3b975ebe07d019c1f5528108725e438johanengelen return this._instance;
c0cd5511d3b975ebe07d019c1f5528108725e438johanengelen },
c0cd5511d3b975ebe07d019c1f5528108725e438johanengelen /**
c0cd5511d3b975ebe07d019c1f5528108725e438johanengelen * @method render
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm * @description Render the iframe into the container config option or open the window.
c0cd5511d3b975ebe07d019c1f5528108725e438johanengelen * @param {String/HTMLElement/Node} node The node to render to
c0cd5511d3b975ebe07d019c1f5528108725e438johanengelen * @return {Y.Frame}
c0cd5511d3b975ebe07d019c1f5528108725e438johanengelen * @chainable
c0cd5511d3b975ebe07d019c1f5528108725e438johanengelen */
c0cd5511d3b975ebe07d019c1f5528108725e438johanengelen render: function(node) {
c0cd5511d3b975ebe07d019c1f5528108725e438johanengelen if (this._rendered) {
c0cd5511d3b975ebe07d019c1f5528108725e438johanengelen Y.log('Frame already rendered.', 'warn', 'frame');
c0cd5511d3b975ebe07d019c1f5528108725e438johanengelen return this;
c0cd5511d3b975ebe07d019c1f5528108725e438johanengelen }
c0cd5511d3b975ebe07d019c1f5528108725e438johanengelen this._rendered = true;
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm if (node) {
c0cd5511d3b975ebe07d019c1f5528108725e438johanengelen this.set('container', node);
c0cd5511d3b975ebe07d019c1f5528108725e438johanengelen }
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm this._create(Y.bind(function(res) {
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm var inst, timer,
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm cb = Y.bind(function(i) {
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm Y.log('Internal instance loaded with node-base', 'info', 'frame');
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm this._instanceLoaded(i);
56542e2b97ec8826cc692153b0e2d4f5ac8ef913johanengelen }, this),
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm args = Y.clone(this.get('use')),
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm config = {
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm debug: false,
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm win: res.win,
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm doc: res.doc
56542e2b97ec8826cc692153b0e2d4f5ac8ef913johanengelen },
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm fn = Y.bind(function() {
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm Y.log('New Modules Loaded into main instance', 'info', 'frame');
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm config = this._resolveWinDoc(config);
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm inst = YUI(config);
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm inst.log = Y.log; //Dump the instance logs to the parent instance.
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm
56542e2b97ec8826cc692153b0e2d4f5ac8ef913johanengelen Y.log('Creating new internal instance with node-base only', 'info', 'frame');
56542e2b97ec8826cc692153b0e2d4f5ac8ef913johanengelen try {
56542e2b97ec8826cc692153b0e2d4f5ac8ef913johanengelen inst.use('node-base', cb);
56542e2b97ec8826cc692153b0e2d4f5ac8ef913johanengelen if (timer) {
56542e2b97ec8826cc692153b0e2d4f5ac8ef913johanengelen clearInterval(timer);
93bb287e28a818fd5ba61b99d012e0500a49ccf6johanengelen }
93bb287e28a818fd5ba61b99d012e0500a49ccf6johanengelen } catch (e) {
93bb287e28a818fd5ba61b99d012e0500a49ccf6johanengelen timer = setInterval(function() {
93bb287e28a818fd5ba61b99d012e0500a49ccf6johanengelen Y.log('[TIMER] Internal use call failed, retrying', 'info', 'frame');
93bb287e28a818fd5ba61b99d012e0500a49ccf6johanengelen fn();
93bb287e28a818fd5ba61b99d012e0500a49ccf6johanengelen }, 350);
93bb287e28a818fd5ba61b99d012e0500a49ccf6johanengelen Y.log('Internal use call failed, retrying', 'info', 'frame');
93bb287e28a818fd5ba61b99d012e0500a49ccf6johanengelen }
56542e2b97ec8826cc692153b0e2d4f5ac8ef913johanengelen }, this);
93bb287e28a818fd5ba61b99d012e0500a49ccf6johanengelen
93bb287e28a818fd5ba61b99d012e0500a49ccf6johanengelen args.push(fn);
56542e2b97ec8826cc692153b0e2d4f5ac8ef913johanengelen
56542e2b97ec8826cc692153b0e2d4f5ac8ef913johanengelen Y.log('Adding new modules to main instance: ' + args, 'info', 'frame');
fb5a72174252e0e79107dcad3bf5a2bbd73e349cjohanengelen Y.use.apply(Y, args);
fb5a72174252e0e79107dcad3bf5a2bbd73e349cjohanengelen
fb5a72174252e0e79107dcad3bf5a2bbd73e349cjohanengelen }, this));
af8d25189f88abf89cdbe0e180e271c94079624fbuliabyak
af8d25189f88abf89cdbe0e180e271c94079624fbuliabyak return this;
af8d25189f88abf89cdbe0e180e271c94079624fbuliabyak },
fb5a72174252e0e79107dcad3bf5a2bbd73e349cjohanengelen /**
af8d25189f88abf89cdbe0e180e271c94079624fbuliabyak * @private
a0334366488989ef25fb812d7030d298c0917c96johanengelen * @method _handleFocus
fb5a72174252e0e79107dcad3bf5a2bbd73e349cjohanengelen * @description Does some tricks on focus to set the proper cursor position.
a0334366488989ef25fb812d7030d298c0917c96johanengelen */
fb5a72174252e0e79107dcad3bf5a2bbd73e349cjohanengelen _handleFocus: function() {
fb5a72174252e0e79107dcad3bf5a2bbd73e349cjohanengelen var inst = this.getInstance(),
a0334366488989ef25fb812d7030d298c0917c96johanengelen sel = new inst.Selection();
a0334366488989ef25fb812d7030d298c0917c96johanengelen
fb5a72174252e0e79107dcad3bf5a2bbd73e349cjohanengelen if (sel.anchorNode) {
fb5a72174252e0e79107dcad3bf5a2bbd73e349cjohanengelen var n = sel.anchorNode,
fb5a72174252e0e79107dcad3bf5a2bbd73e349cjohanengelen c = n.get('childNodes');
f9504c822b72a774b910958446fd1e730235b7cbjoncruz
a0334366488989ef25fb812d7030d298c0917c96johanengelen if (c.size() == 1) {
fb5a72174252e0e79107dcad3bf5a2bbd73e349cjohanengelen if (c.item(0).test('br')) {
fb5a72174252e0e79107dcad3bf5a2bbd73e349cjohanengelen sel.selectNode(n, true, false);
fb5a72174252e0e79107dcad3bf5a2bbd73e349cjohanengelen }
fb5a72174252e0e79107dcad3bf5a2bbd73e349cjohanengelen }
fb5a72174252e0e79107dcad3bf5a2bbd73e349cjohanengelen }
fb5a72174252e0e79107dcad3bf5a2bbd73e349cjohanengelen },
fb5a72174252e0e79107dcad3bf5a2bbd73e349cjohanengelen /**
fb5a72174252e0e79107dcad3bf5a2bbd73e349cjohanengelen * @method focus
fb5a72174252e0e79107dcad3bf5a2bbd73e349cjohanengelen * @description Set the focus to the iframe
fb5a72174252e0e79107dcad3bf5a2bbd73e349cjohanengelen * @param {Function} fn Callback function to execute after focus happens
fb5a72174252e0e79107dcad3bf5a2bbd73e349cjohanengelen * @return {Frame}
fb5a72174252e0e79107dcad3bf5a2bbd73e349cjohanengelen * @chainable
fb5a72174252e0e79107dcad3bf5a2bbd73e349cjohanengelen */
fb5a72174252e0e79107dcad3bf5a2bbd73e349cjohanengelen focus: function(fn) {
fb5a72174252e0e79107dcad3bf5a2bbd73e349cjohanengelen if (Y.UA.ie) {
fb5a72174252e0e79107dcad3bf5a2bbd73e349cjohanengelen try {
fb5a72174252e0e79107dcad3bf5a2bbd73e349cjohanengelen Y.one('win').focus();
fb5a72174252e0e79107dcad3bf5a2bbd73e349cjohanengelen this.getInstance().one('win').focus();
fb5a72174252e0e79107dcad3bf5a2bbd73e349cjohanengelen } catch (ierr) {
fb5a72174252e0e79107dcad3bf5a2bbd73e349cjohanengelen Y.log('Frame focus failed', 'warn', 'frame');
fb5a72174252e0e79107dcad3bf5a2bbd73e349cjohanengelen }
fb5a72174252e0e79107dcad3bf5a2bbd73e349cjohanengelen if (fn === true) {
fb5a72174252e0e79107dcad3bf5a2bbd73e349cjohanengelen this._handleFocus();
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm }
42e99769805c14a5cc01c805faa3c3b03f9dd1c0johanengelen if (Y.Lang.isFunction(fn)) {
42e99769805c14a5cc01c805faa3c3b03f9dd1c0johanengelen fn();
42e99769805c14a5cc01c805faa3c3b03f9dd1c0johanengelen }
42e99769805c14a5cc01c805faa3c3b03f9dd1c0johanengelen } else {
42e99769805c14a5cc01c805faa3c3b03f9dd1c0johanengelen try {
42e99769805c14a5cc01c805faa3c3b03f9dd1c0johanengelen Y.one('win').focus();
42e99769805c14a5cc01c805faa3c3b03f9dd1c0johanengelen Y.later(100, this, function() {
42e99769805c14a5cc01c805faa3c3b03f9dd1c0johanengelen this.getInstance().one('win').focus();
42e99769805c14a5cc01c805faa3c3b03f9dd1c0johanengelen if (fn === true) {
56542e2b97ec8826cc692153b0e2d4f5ac8ef913johanengelen this._handleFocus();
a797dcb8e284cab19f60b3eff93a53a62abda263johanengelen }
56542e2b97ec8826cc692153b0e2d4f5ac8ef913johanengelen if (Y.Lang.isFunction(fn)) {
56542e2b97ec8826cc692153b0e2d4f5ac8ef913johanengelen fn();
56542e2b97ec8826cc692153b0e2d4f5ac8ef913johanengelen }
56542e2b97ec8826cc692153b0e2d4f5ac8ef913johanengelen });
56542e2b97ec8826cc692153b0e2d4f5ac8ef913johanengelen } catch (ferr) {
ddc251b3cf95b0097b6a5ee39ea132bd4d7d5cbcjohanengelen Y.log('Frame focus failed', 'warn', 'frame');
ddc251b3cf95b0097b6a5ee39ea132bd4d7d5cbcjohanengelen }
ddc251b3cf95b0097b6a5ee39ea132bd4d7d5cbcjohanengelen }
ddc251b3cf95b0097b6a5ee39ea132bd4d7d5cbcjohanengelen return this;
ddc251b3cf95b0097b6a5ee39ea132bd4d7d5cbcjohanengelen },
ddc251b3cf95b0097b6a5ee39ea132bd4d7d5cbcjohanengelen /**
bdd7add6c064afee52d2eabeaa18f745430e5a4djohanengelen * @method show
ddc251b3cf95b0097b6a5ee39ea132bd4d7d5cbcjohanengelen * @description Show the iframe instance
ddc251b3cf95b0097b6a5ee39ea132bd4d7d5cbcjohanengelen * @return {Frame}
42e99769805c14a5cc01c805faa3c3b03f9dd1c0johanengelen * @chainable
42ba1b712b7b430669fc49aa9facb439181081becilix */
42ba1b712b7b430669fc49aa9facb439181081becilix show: function() {
42ba1b712b7b430669fc49aa9facb439181081becilix this._iframe.setStyles({
42ba1b712b7b430669fc49aa9facb439181081becilix position: 'static',
42ba1b712b7b430669fc49aa9facb439181081becilix left: ''
42ba1b712b7b430669fc49aa9facb439181081becilix });
42ba1b712b7b430669fc49aa9facb439181081becilix if (Y.UA.gecko) {
42ba1b712b7b430669fc49aa9facb439181081becilix try {
42ba1b712b7b430669fc49aa9facb439181081becilix this._instance.config.doc.designMode = 'on';
42ba1b712b7b430669fc49aa9facb439181081becilix } catch (e) { }
42ba1b712b7b430669fc49aa9facb439181081becilix this.focus();
42ba1b712b7b430669fc49aa9facb439181081becilix }
42ba1b712b7b430669fc49aa9facb439181081becilix return this;
42ba1b712b7b430669fc49aa9facb439181081becilix },
42ba1b712b7b430669fc49aa9facb439181081becilix /**
42ba1b712b7b430669fc49aa9facb439181081becilix * @method hide
42ba1b712b7b430669fc49aa9facb439181081becilix * @description Hide the iframe instance
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm * @return {Frame}
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm * @chainable
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm */
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm hide: function() {
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm this._iframe.setStyles({
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm position: 'absolute',
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm left: '-999999px'
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm });
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm return this;
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm }
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm }, {
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm /**
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm * @static
* @property DOM_EVENTS
* @description The DomEvents that the frame automatically attaches and bubbles
* @type Object
*/
DOM_EVENTS: {
dblclick: 1,
click: 1,
paste: 1,
mouseup: 1,
mousedown: 1,
keyup: 1,
keydown: 1,
keypress: 1,
activate: 1,
deactivate: 1,
focusin: 1,
focusout: 1
},
/**
* @static
* @property DEFAULT_CSS
* @description The default css used when creating the document.
* @type String
*/
//DEFAULT_CSS: 'html { height: 95%; } body { padding: 7px; background-color: #fff; font: 13px/1.22 arial,helvetica,clean,sans-serif;*font-size:small;*font:x-small; } a, a:visited, a:hover { color: blue !important; text-decoration: underline !important; cursor: text !important; } img { cursor: pointer !important; border: none; }',
DEFAULT_CSS: 'body { background-color: #fff; font: 13px/1.22 arial,helvetica,clean,sans-serif;*font-size:small;*font:x-small; } a, a:visited, a:hover { color: blue !important; text-decoration: underline !important; cursor: text !important; } img { cursor: pointer !important; border: none; }',
/**
* @static
* @property HTML
* @description The template string used to create the iframe
* @type String
*/
//HTML: '<iframe border="0" frameBorder="0" marginWidth="0" marginHeight="0" leftMargin="0" topMargin="0" allowTransparency="true" width="100%" height="99%"></iframe>',
HTML: '<iframe border="0" frameBorder="0" marginWidth="0" marginHeight="0" leftMargin="0" topMargin="0" allowTransparency="true" width="100%" height="99%"></iframe>',
/**
* @static
* @property PAGE_HTML
* @description The template used to create the page when created dynamically.
* @type String
*/
PAGE_HTML: '<html dir="{DIR}" lang="{LANG}"><head><title>{TITLE}</title>{META}<base href="{BASE_HREF}"/>{LINKED_CSS}<style id="editor_css">{DEFAULT_CSS}</style>{EXTRA_CSS}</head><body>{CONTENT}</body></html>',
/**
* @static
* @property DOC_TYPE
* @description The DOCTYPE to prepend to the new document when created. Should match the one on the page being served.
* @type String
*/
DOC_TYPE: '<!DOCTYPE HTML PUBLIC "-/'+'/W3C/'+'/DTD HTML 4.01/'+'/EN" "http:/'+'/www.w3.org/TR/html4/strict.dtd">',
/**
* @static
* @property META
* @description The meta-tag for Content-Type to add to the dynamic document
* @type String
*/
//META: '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/><meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7">',
META: '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>',
/**
* @static
* @property NAME
* @description The name of the class (frame)
* @type String
*/
NAME: 'frame',
ATTRS: {
/**
* @attribute title
* @description The title to give the blank page.
* @type String
*/
title: {
value: 'Blank Page'
},
/**
* @attribute dir
* @description The default text direction for this new frame. Default: ltr
* @type String
*/
dir: {
value: 'ltr'
},
/**
* @attribute lang
* @description The default language. Default: en-US
* @type String
*/
lang: {
value: 'en-US'
},
/**
* @attribute src
* @description The src of the iframe/window. Defaults to javascript:;
* @type String
*/
src: {
//Hackish, IE needs the false in the Javascript URL
value: 'javascript' + ((Y.UA.ie) ? ':false' : ':') + ';'
},
/**
* @attribute designMode
* @description Should designMode be turned on after creation.
* @writeonce
* @type Boolean
*/
designMode: {
writeOnce: true,
value: false
},
/**
* @attribute content
* @description The string to inject into the body of the new frame/window.
* @type String
*/
content: {
value: '<br>',
setter: '_setHTML',
getter: '_getHTML'
},
/**
* @attribute basehref
* @description The base href to use in the iframe.
* @type String
*/
basehref: {
value: false,
getter: '_resolveBaseHref'
},
/**
* @attribute use
* @description Array of modules to include in the scoped YUI instance at render time. Default: ['none', 'selector-css2']
* @writeonce
* @type Array
*/
use: {
writeOnce: true,
value: ['substitute', 'node', 'node-style', 'selector-css3']
},
/**
* @attribute container
* @description The container to append the iFrame to on render.
* @type String/HTMLElement/Node
*/
container: {
value: 'body',
setter: function(n) {
return Y.one(n);
}
},
/**
* @attribute id
* @description Set the id of the new Node. (optional)
* @type String
* @writeonce
*/
id: {
writeOnce: true,
getter: function(id) {
if (!id) {
id = 'iframe-' + Y.guid();
}
return id;
}
},
/**
* @attribute linkedcss
* @description An array of url's to external linked style sheets
* @type String
*/
linkedcss: {
value: '',
getter: '_getLinkedCSS',
setter: '_setLinkedCSS'
},
/**
* @attribute extracss
* @description A string of CSS to add to the Head of the Editor
* @type String
*/
extracss: {
value: '',
setter: '_setExtraCSS'
},
/**
* @attribute host
* @description A reference to the Editor instance
* @type Object
*/
host: {
value: false
},
/**
* @attribute defaultblock
* @description The default tag to use for block level items, defaults to: p
* @type String
*/
defaultblock: {
value: 'p'
}
}
});
Y.Frame = Frame;
}, '@VERSION@' ,{requires:['base', 'node', 'selector-css3', 'substitute'], skinnable:false });