|
525
|
1 |
/* |
|
|
2 |
YUI 3.10.3 (build 2fb5187) |
|
|
3 |
Copyright 2013 Yahoo! Inc. All rights reserved. |
|
|
4 |
Licensed under the BSD License. |
|
|
5 |
http://yuilibrary.com/license/ |
|
|
6 |
*/ |
|
|
7 |
|
|
|
8 |
YUI.add('frame', function (Y, NAME) { |
|
|
9 |
|
|
|
10 |
/*jshint maxlen: 500 */ |
|
|
11 |
/** |
|
|
12 |
* Creates a wrapper around an iframe. It loads the content either from a local |
|
|
13 |
* file or from script and creates a local YUI instance bound to that new window and document. |
|
|
14 |
* @class Frame |
|
|
15 |
* @for Frame |
|
|
16 |
* @extends Base |
|
|
17 |
* @constructor |
|
|
18 |
* @module editor |
|
|
19 |
* @submodule frame |
|
|
20 |
*/ |
|
|
21 |
|
|
|
22 |
var Frame = function() { |
|
|
23 |
Frame.superclass.constructor.apply(this, arguments); |
|
|
24 |
}; |
|
|
25 |
|
|
|
26 |
|
|
|
27 |
Y.extend(Frame, Y.Base, { |
|
|
28 |
/** |
|
|
29 |
* @private |
|
|
30 |
* @property _ready |
|
|
31 |
* @description Internal reference set when the content is ready. |
|
|
32 |
* @type Boolean |
|
|
33 |
*/ |
|
|
34 |
_ready: null, |
|
|
35 |
/** |
|
|
36 |
* @private |
|
|
37 |
* @property _rendered |
|
|
38 |
* @description Internal reference set when render is called. |
|
|
39 |
* @type Boolean |
|
|
40 |
*/ |
|
|
41 |
_rendered: null, |
|
|
42 |
/** |
|
|
43 |
* @private |
|
|
44 |
* @property _iframe |
|
|
45 |
* @description Internal Node reference to the iFrame or the window |
|
|
46 |
* @type Node |
|
|
47 |
*/ |
|
|
48 |
_iframe: null, |
|
|
49 |
/** |
|
|
50 |
* @private |
|
|
51 |
* @property _instance |
|
|
52 |
* @description Internal reference to the YUI instance bound to the iFrame or window |
|
|
53 |
* @type YUI |
|
|
54 |
*/ |
|
|
55 |
_instance: null, |
|
|
56 |
/** |
|
|
57 |
* @private |
|
|
58 |
* @method _create |
|
|
59 |
* @description Create the iframe or Window and get references to the Document & Window |
|
|
60 |
* @return {Object} Hash table containing references to the new Document & Window |
|
|
61 |
*/ |
|
|
62 |
_create: function(cb) { |
|
|
63 |
var res, html = '', timer, |
|
|
64 |
//if the src attr is different than the default, don't create the document |
|
|
65 |
create = (this.get('src') === Frame.ATTRS.src.value), |
|
|
66 |
extra_css = ((this.get('extracss')) ? '<style id="extra_css">' + this.get('extracss') + '</style>' : ''); |
|
|
67 |
|
|
|
68 |
this._iframe = Y.one(Y.config.doc.createElement('iframe')); |
|
|
69 |
this._iframe.setAttrs(Frame.IFRAME_ATTRS); |
|
|
70 |
|
|
|
71 |
this._iframe.setStyle('visibility', 'hidden'); |
|
|
72 |
this._iframe.set('src', this.get('src')); |
|
|
73 |
this.get('container').append(this._iframe); |
|
|
74 |
this._iframe.set('height', '99%'); |
|
|
75 |
|
|
|
76 |
if (create) { |
|
|
77 |
html = Y.Lang.sub(Frame.PAGE_HTML, { |
|
|
78 |
DIR: this.get('dir'), |
|
|
79 |
LANG: this.get('lang'), |
|
|
80 |
TITLE: this.get('title'), |
|
|
81 |
META: Frame.META, |
|
|
82 |
LINKED_CSS: this.get('linkedcss'), |
|
|
83 |
CONTENT: this.get('content'), |
|
|
84 |
BASE_HREF: this.get('basehref'), |
|
|
85 |
DEFAULT_CSS: Frame.DEFAULT_CSS, |
|
|
86 |
EXTRA_CSS: extra_css |
|
|
87 |
}); |
|
|
88 |
if (Y.config.doc.compatMode !== 'BackCompat') { |
|
|
89 |
|
|
|
90 |
//html = Frame.DOC_TYPE + "\n" + html; |
|
|
91 |
html = Frame.getDocType() + "\n" + html; |
|
|
92 |
} else { |
|
|
93 |
} |
|
|
94 |
|
|
|
95 |
} |
|
|
96 |
|
|
|
97 |
res = this._resolveWinDoc(); |
|
|
98 |
|
|
|
99 |
if (html) { |
|
|
100 |
res.doc.open(); |
|
|
101 |
res.doc.write(html); |
|
|
102 |
res.doc.close(); |
|
|
103 |
} |
|
|
104 |
|
|
|
105 |
if (!res.doc.documentElement) { |
|
|
106 |
timer = Y.later(1, this, function() { |
|
|
107 |
if (res.doc && res.doc.documentElement) { |
|
|
108 |
cb(res); |
|
|
109 |
timer.cancel(); |
|
|
110 |
} |
|
|
111 |
}, null, true); |
|
|
112 |
} else { |
|
|
113 |
cb(res); |
|
|
114 |
} |
|
|
115 |
|
|
|
116 |
}, |
|
|
117 |
/** |
|
|
118 |
* @private |
|
|
119 |
* @method _resolveWinDoc |
|
|
120 |
* @description Resolves the document and window from an iframe or window instance |
|
|
121 |
* @param {Object} c The YUI Config to add the window and document to |
|
|
122 |
* @return {Object} Object hash of window and document references, if a YUI config was passed, it is returned. |
|
|
123 |
*/ |
|
|
124 |
_resolveWinDoc: function(c) { |
|
|
125 |
var config = (c) ? c : {}; |
|
|
126 |
config.win = Y.Node.getDOMNode(this._iframe.get('contentWindow')); |
|
|
127 |
config.doc = Y.Node.getDOMNode(this._iframe.get('contentWindow.document')); |
|
|
128 |
if (!config.doc) { |
|
|
129 |
config.doc = Y.config.doc; |
|
|
130 |
} |
|
|
131 |
if (!config.win) { |
|
|
132 |
config.win = Y.config.win; |
|
|
133 |
} |
|
|
134 |
return config; |
|
|
135 |
}, |
|
|
136 |
/** |
|
|
137 |
* @private |
|
|
138 |
* @method _onDomEvent |
|
|
139 |
* @description Generic handler for all DOM events fired by the iframe or window. This handler |
|
|
140 |
* takes the current EventFacade and augments it to fire on the Frame host. It adds two new properties |
|
|
141 |
* to the EventFacade called frameX and frameY which adds the scroll and xy position of the iframe |
|
|
142 |
* to the original pageX and pageY of the event so external nodes can be positioned over the frame. |
|
|
143 |
* @param {Event.Facade} e |
|
|
144 |
*/ |
|
|
145 |
_onDomEvent: function(e) { |
|
|
146 |
var xy, node; |
|
|
147 |
|
|
|
148 |
if (!Y.Node.getDOMNode(this._iframe)) { |
|
|
149 |
//The iframe is null for some reason, bail on sending events. |
|
|
150 |
return; |
|
|
151 |
} |
|
|
152 |
|
|
|
153 |
e.frameX = e.frameY = 0; |
|
|
154 |
|
|
|
155 |
if (e.pageX > 0 || e.pageY > 0) { |
|
|
156 |
if (e.type.substring(0, 3) !== 'key') { |
|
|
157 |
node = this._instance.one('win'); |
|
|
158 |
xy = this._iframe.getXY(); |
|
|
159 |
e.frameX = xy[0] + e.pageX - node.get('scrollLeft'); |
|
|
160 |
e.frameY = xy[1] + e.pageY - node.get('scrollTop'); |
|
|
161 |
} |
|
|
162 |
} |
|
|
163 |
|
|
|
164 |
e.frameTarget = e.target; |
|
|
165 |
e.frameCurrentTarget = e.currentTarget; |
|
|
166 |
e.frameEvent = e; |
|
|
167 |
|
|
|
168 |
this.fire('dom:' + e.type, e); |
|
|
169 |
}, |
|
|
170 |
initializer: function() { |
|
|
171 |
this.publish('ready', { |
|
|
172 |
emitFacade: true, |
|
|
173 |
defaultFn: this._defReadyFn |
|
|
174 |
}); |
|
|
175 |
}, |
|
|
176 |
destructor: function() { |
|
|
177 |
var inst = this.getInstance(); |
|
|
178 |
|
|
|
179 |
inst.one('doc').detachAll(); |
|
|
180 |
inst = null; |
|
|
181 |
this._iframe.remove(); |
|
|
182 |
}, |
|
|
183 |
/** |
|
|
184 |
* @private |
|
|
185 |
* @method _DOMPaste |
|
|
186 |
* @description Simple pass thru handler for the paste event so we can do content cleanup |
|
|
187 |
* @param {Event.Facade} e |
|
|
188 |
*/ |
|
|
189 |
_DOMPaste: function(e) { |
|
|
190 |
var inst = this.getInstance(), |
|
|
191 |
data = '', win = inst.config.win; |
|
|
192 |
|
|
|
193 |
if (e._event.originalTarget) { |
|
|
194 |
data = e._event.originalTarget; |
|
|
195 |
} |
|
|
196 |
if (e._event.clipboardData) { |
|
|
197 |
data = e._event.clipboardData.getData('Text'); |
|
|
198 |
} |
|
|
199 |
|
|
|
200 |
if (win.clipboardData) { |
|
|
201 |
data = win.clipboardData.getData('Text'); |
|
|
202 |
if (data === '') { // Could be empty, or failed |
|
|
203 |
// Verify failure |
|
|
204 |
if (!win.clipboardData.setData('Text', data)) { |
|
|
205 |
data = null; |
|
|
206 |
} |
|
|
207 |
} |
|
|
208 |
} |
|
|
209 |
|
|
|
210 |
|
|
|
211 |
e.frameTarget = e.target; |
|
|
212 |
e.frameCurrentTarget = e.currentTarget; |
|
|
213 |
e.frameEvent = e; |
|
|
214 |
|
|
|
215 |
if (data) { |
|
|
216 |
e.clipboardData = { |
|
|
217 |
data: data, |
|
|
218 |
getData: function() { |
|
|
219 |
return data; |
|
|
220 |
} |
|
|
221 |
}; |
|
|
222 |
} else { |
|
|
223 |
e.clipboardData = null; |
|
|
224 |
} |
|
|
225 |
|
|
|
226 |
this.fire('dom:paste', e); |
|
|
227 |
}, |
|
|
228 |
/** |
|
|
229 |
* @private |
|
|
230 |
* @method _defReadyFn |
|
|
231 |
* @description Binds DOM events, sets the iframe to visible and fires the ready event |
|
|
232 |
*/ |
|
|
233 |
_defReadyFn: function() { |
|
|
234 |
var inst = this.getInstance(); |
|
|
235 |
|
|
|
236 |
Y.each(Frame.DOM_EVENTS, function(v, k) { |
|
|
237 |
var fn = Y.bind(this._onDomEvent, this), |
|
|
238 |
kfn = ((Y.UA.ie && Frame.THROTTLE_TIME > 0) ? Y.throttle(fn, Frame.THROTTLE_TIME) : fn); |
|
|
239 |
|
|
|
240 |
if (!inst.Node.DOM_EVENTS[k]) { |
|
|
241 |
inst.Node.DOM_EVENTS[k] = 1; |
|
|
242 |
} |
|
|
243 |
if (v === 1) { |
|
|
244 |
if (k !== 'focus' && k !== 'blur' && k !== 'paste') { |
|
|
245 |
if (k.substring(0, 3) === 'key') { |
|
|
246 |
//Throttle key events in IE |
|
|
247 |
inst.on(k, kfn, inst.config.doc); |
|
|
248 |
} else { |
|
|
249 |
inst.on(k, fn, inst.config.doc); |
|
|
250 |
} |
|
|
251 |
} |
|
|
252 |
} |
|
|
253 |
}, this); |
|
|
254 |
|
|
|
255 |
inst.Node.DOM_EVENTS.paste = 1; |
|
|
256 |
|
|
|
257 |
inst.on('paste', Y.bind(this._DOMPaste, this), inst.one('body')); |
|
|
258 |
|
|
|
259 |
//Adding focus/blur to the window object |
|
|
260 |
inst.on('focus', Y.bind(this._onDomEvent, this), inst.config.win); |
|
|
261 |
inst.on('blur', Y.bind(this._onDomEvent, this), inst.config.win); |
|
|
262 |
|
|
|
263 |
inst.__use = inst.use; |
|
|
264 |
inst.use = Y.bind(this.use, this); |
|
|
265 |
this._iframe.setStyles({ |
|
|
266 |
visibility: 'inherit' |
|
|
267 |
}); |
|
|
268 |
inst.one('body').setStyle('display', 'block'); |
|
|
269 |
}, |
|
|
270 |
/** |
|
|
271 |
* It appears that having a BR tag anywhere in the source "below" a table with a percentage width (in IE 7 & 8) |
|
|
272 |
* if there is any TEXTINPUT's outside the iframe, the cursor will rapidly flickr and the CPU would occasionally |
|
|
273 |
* spike. This method finds all <BR>'s below the sourceIndex of the first table. Does some checks to see if they |
|
|
274 |
* can be modified and replaces then with a <WBR> so the layout will remain in tact, but the flickering will |
|
|
275 |
* no longer happen. |
|
|
276 |
* @method _fixIECursors |
|
|
277 |
* @private |
|
|
278 |
*/ |
|
|
279 |
_fixIECursors: function() { |
|
|
280 |
var inst = this.getInstance(), |
|
|
281 |
tables = inst.all('table'), |
|
|
282 |
brs = inst.all('br'), si; |
|
|
283 |
|
|
|
284 |
if (tables.size() && brs.size()) { |
|
|
285 |
//First Table |
|
|
286 |
si = tables.item(0).get('sourceIndex'); |
|
|
287 |
brs.each(function(n) { |
|
|
288 |
var p = n.get('parentNode'), |
|
|
289 |
c = p.get('children'), b = p.all('>br'); |
|
|
290 |
|
|
|
291 |
if (p.test('div')) { |
|
|
292 |
if (c.size() > 2) { |
|
|
293 |
n.replace(inst.Node.create('<wbr>')); |
|
|
294 |
} else { |
|
|
295 |
if (n.get('sourceIndex') > si) { |
|
|
296 |
if (b.size()) { |
|
|
297 |
n.replace(inst.Node.create('<wbr>')); |
|
|
298 |
} |
|
|
299 |
} else { |
|
|
300 |
if (b.size() > 1) { |
|
|
301 |
n.replace(inst.Node.create('<wbr>')); |
|
|
302 |
} |
|
|
303 |
} |
|
|
304 |
} |
|
|
305 |
} |
|
|
306 |
|
|
|
307 |
}); |
|
|
308 |
} |
|
|
309 |
}, |
|
|
310 |
/** |
|
|
311 |
* @private |
|
|
312 |
* @method _onContentReady |
|
|
313 |
* @description Called once the content is available in the frame/window and calls the final use call |
|
|
314 |
* on the internal instance so that the modules are loaded properly. |
|
|
315 |
*/ |
|
|
316 |
_onContentReady: function(e) { |
|
|
317 |
if (!this._ready) { |
|
|
318 |
this._ready = true; |
|
|
319 |
var inst = this.getInstance(), |
|
|
320 |
args = Y.clone(this.get('use')); |
|
|
321 |
|
|
|
322 |
this.fire('contentready'); |
|
|
323 |
|
|
|
324 |
if (e) { |
|
|
325 |
inst.config.doc = Y.Node.getDOMNode(e.target); |
|
|
326 |
} |
|
|
327 |
//TODO Circle around and deal with CSS loading... |
|
|
328 |
args.push(Y.bind(function() { |
|
|
329 |
if (inst.EditorSelection) { |
|
|
330 |
inst.EditorSelection.DEFAULT_BLOCK_TAG = this.get('defaultblock'); |
|
|
331 |
} |
|
|
332 |
//Moved to here so that the iframe is ready before allowing editing.. |
|
|
333 |
if (this.get('designMode')) { |
|
|
334 |
if(Y.UA.ie) { |
|
|
335 |
inst.config.doc.body.contentEditable = 'true'; |
|
|
336 |
this._ieSetBodyHeight(); |
|
|
337 |
inst.on('keyup', Y.bind(this._ieSetBodyHeight, this), inst.config.doc); |
|
|
338 |
} else { |
|
|
339 |
inst.config.doc.designMode = 'on'; |
|
|
340 |
} |
|
|
341 |
} |
|
|
342 |
this.fire('ready'); |
|
|
343 |
}, this)); |
|
|
344 |
inst.use.apply(inst, args); |
|
|
345 |
|
|
|
346 |
inst.one('doc').get('documentElement').addClass('yui-js-enabled'); |
|
|
347 |
} |
|
|
348 |
}, |
|
|
349 |
_ieHeightCounter: null, |
|
|
350 |
/** |
|
|
351 |
* Internal method to set the height of the body to the height of the document in IE. |
|
|
352 |
* With contenteditable being set, the document becomes unresponsive to clicks, this |
|
|
353 |
* method expands the body to be the height of the document so that doesn't happen. |
|
|
354 |
* @private |
|
|
355 |
* @method _ieSetBodyHeight |
|
|
356 |
*/ |
|
|
357 |
_ieSetBodyHeight: function(e) { |
|
|
358 |
if (!this._ieHeightCounter) { |
|
|
359 |
this._ieHeightCounter = 0; |
|
|
360 |
} |
|
|
361 |
this._ieHeightCounter++; |
|
|
362 |
var run = false, inst, h, bh; |
|
|
363 |
if (!e) { |
|
|
364 |
run = true; |
|
|
365 |
} |
|
|
366 |
if (e) { |
|
|
367 |
switch (e.keyCode) { |
|
|
368 |
case 8: |
|
|
369 |
case 13: |
|
|
370 |
run = true; |
|
|
371 |
break; |
|
|
372 |
} |
|
|
373 |
if (e.ctrlKey || e.shiftKey) { |
|
|
374 |
run = true; |
|
|
375 |
} |
|
|
376 |
} |
|
|
377 |
if (run) { |
|
|
378 |
try { |
|
|
379 |
inst = this.getInstance(); |
|
|
380 |
h = this._iframe.get('offsetHeight'); |
|
|
381 |
bh = inst.config.doc.body.scrollHeight; |
|
|
382 |
if (h > bh) { |
|
|
383 |
h = (h - 15) + 'px'; |
|
|
384 |
inst.config.doc.body.style.height = h; |
|
|
385 |
} else { |
|
|
386 |
inst.config.doc.body.style.height = 'auto'; |
|
|
387 |
} |
|
|
388 |
} catch (e) { |
|
|
389 |
if (this._ieHeightCounter < 100) { |
|
|
390 |
Y.later(200, this, this._ieSetBodyHeight); |
|
|
391 |
} else { |
|
|
392 |
} |
|
|
393 |
} |
|
|
394 |
} |
|
|
395 |
}, |
|
|
396 |
/** |
|
|
397 |
* @private |
|
|
398 |
* @method _resolveBaseHref |
|
|
399 |
* @description Resolves the basehref of the page the frame is created on. Only applies to dynamic content. |
|
|
400 |
* @param {String} href The new value to use, if empty it will be resolved from the current url. |
|
|
401 |
* @return {String} |
|
|
402 |
*/ |
|
|
403 |
_resolveBaseHref: function(href) { |
|
|
404 |
if (!href || href === '') { |
|
|
405 |
href = Y.config.doc.location.href; |
|
|
406 |
if (href.indexOf('?') !== -1) { //Remove the query string |
|
|
407 |
href = href.substring(0, href.indexOf('?')); |
|
|
408 |
} |
|
|
409 |
href = href.substring(0, href.lastIndexOf('/')) + '/'; |
|
|
410 |
} |
|
|
411 |
return href; |
|
|
412 |
}, |
|
|
413 |
/** |
|
|
414 |
* @private |
|
|
415 |
* @method _getHTML |
|
|
416 |
* @description Get the content from the iframe |
|
|
417 |
* @param {String} html The raw HTML from the body of the iframe. |
|
|
418 |
* @return {String} |
|
|
419 |
*/ |
|
|
420 |
_getHTML: function(html) { |
|
|
421 |
if (this._ready) { |
|
|
422 |
var inst = this.getInstance(); |
|
|
423 |
html = inst.one('body').get('innerHTML'); |
|
|
424 |
} |
|
|
425 |
return html; |
|
|
426 |
}, |
|
|
427 |
/** |
|
|
428 |
* @private |
|
|
429 |
* @method _setHTML |
|
|
430 |
* @description Set the content of the iframe |
|
|
431 |
* @param {String} html The raw HTML to set the body of the iframe to. |
|
|
432 |
* @return {String} |
|
|
433 |
*/ |
|
|
434 |
_setHTML: function(html) { |
|
|
435 |
if (this._ready) { |
|
|
436 |
var inst = this.getInstance(); |
|
|
437 |
inst.one('body').set('innerHTML', html); |
|
|
438 |
} else { |
|
|
439 |
//This needs to be wrapped in a contentready callback for the !_ready state |
|
|
440 |
this.on('contentready', Y.bind(function(html) { |
|
|
441 |
var inst = this.getInstance(); |
|
|
442 |
inst.one('body').set('innerHTML', html); |
|
|
443 |
}, this, html)); |
|
|
444 |
} |
|
|
445 |
return html; |
|
|
446 |
}, |
|
|
447 |
/** |
|
|
448 |
* @private |
|
|
449 |
* @method _setLinkedCSS |
|
|
450 |
* @description Set's the linked CSS on the instance.. |
|
|
451 |
*/ |
|
|
452 |
_getLinkedCSS: function(urls) { |
|
|
453 |
if (!Y.Lang.isArray(urls)) { |
|
|
454 |
urls = [urls]; |
|
|
455 |
} |
|
|
456 |
var str = ''; |
|
|
457 |
if (!this._ready) { |
|
|
458 |
Y.each(urls, function(v) { |
|
|
459 |
if (v !== '') { |
|
|
460 |
str += '<link rel="stylesheet" href="' + v + '" type="text/css">'; |
|
|
461 |
} |
|
|
462 |
}); |
|
|
463 |
} else { |
|
|
464 |
str = urls; |
|
|
465 |
} |
|
|
466 |
return str; |
|
|
467 |
}, |
|
|
468 |
/** |
|
|
469 |
* @private |
|
|
470 |
* @method _setLinkedCSS |
|
|
471 |
* @description Set's the linked CSS on the instance.. |
|
|
472 |
*/ |
|
|
473 |
_setLinkedCSS: function(css) { |
|
|
474 |
if (this._ready) { |
|
|
475 |
var inst = this.getInstance(); |
|
|
476 |
inst.Get.css(css); |
|
|
477 |
} |
|
|
478 |
return css; |
|
|
479 |
}, |
|
|
480 |
/** |
|
|
481 |
* @private |
|
|
482 |
* @method _setExtraCSS |
|
|
483 |
* @description Set's the extra CSS on the instance.. |
|
|
484 |
*/ |
|
|
485 |
_setExtraCSS: function(css) { |
|
|
486 |
if (this._ready) { |
|
|
487 |
var inst = this.getInstance(), |
|
|
488 |
node = inst.one('#extra_css'); |
|
|
489 |
|
|
|
490 |
node.remove(); |
|
|
491 |
inst.one('head').append('<style id="extra_css">' + css + '</style>'); |
|
|
492 |
} |
|
|
493 |
return css; |
|
|
494 |
}, |
|
|
495 |
/** |
|
|
496 |
* @private |
|
|
497 |
* @method _instanceLoaded |
|
|
498 |
* @description Called from the first YUI instance that sets up the internal instance. |
|
|
499 |
* This loads the content into the window/frame and attaches the contentready event. |
|
|
500 |
* @param {YUI} inst The internal YUI instance bound to the frame/window |
|
|
501 |
*/ |
|
|
502 |
_instanceLoaded: function(inst) { |
|
|
503 |
this._instance = inst; |
|
|
504 |
this._onContentReady(); |
|
|
505 |
|
|
|
506 |
var doc = this._instance.config.doc; |
|
|
507 |
|
|
|
508 |
if (this.get('designMode')) { |
|
|
509 |
if (!Y.UA.ie) { |
|
|
510 |
try { |
|
|
511 |
//Force other browsers into non CSS styling |
|
|
512 |
doc.execCommand('styleWithCSS', false, false); |
|
|
513 |
doc.execCommand('insertbronreturn', false, false); |
|
|
514 |
} catch (err) {} |
|
|
515 |
} |
|
|
516 |
} |
|
|
517 |
}, |
|
|
518 |
//BEGIN PUBLIC METHODS |
|
|
519 |
/** |
|
|
520 |
* @method use |
|
|
521 |
* @description This is a scoped version of the normal YUI.use method & is bound to this frame/window. |
|
|
522 |
* At setup, the inst.use method is mapped to this method. |
|
|
523 |
*/ |
|
|
524 |
use: function() { |
|
|
525 |
var inst = this.getInstance(), |
|
|
526 |
args = Y.Array(arguments), |
|
|
527 |
cb = false; |
|
|
528 |
|
|
|
529 |
if (Y.Lang.isFunction(args[args.length - 1])) { |
|
|
530 |
cb = args.pop(); |
|
|
531 |
} |
|
|
532 |
if (cb) { |
|
|
533 |
args.push(function() { |
|
|
534 |
cb.apply(inst, arguments); |
|
|
535 |
|
|
|
536 |
}); |
|
|
537 |
} |
|
|
538 |
inst.__use.apply(inst, args); |
|
|
539 |
}, |
|
|
540 |
/** |
|
|
541 |
* @method delegate |
|
|
542 |
* @description A delegate method passed to the instance's delegate method |
|
|
543 |
* @param {String} type The type of event to listen for |
|
|
544 |
* @param {Function} fn The method to attach |
|
|
545 |
* @param {String} cont The container to act as a delegate, if no "sel" passed, the body is assumed as the container. |
|
|
546 |
* @param {String} sel The selector to match in the event (optional) |
|
|
547 |
* @return {EventHandle} The Event handle returned from Y.delegate |
|
|
548 |
*/ |
|
|
549 |
delegate: function(type, fn, cont, sel) { |
|
|
550 |
var inst = this.getInstance(); |
|
|
551 |
if (!inst) { |
|
|
552 |
return false; |
|
|
553 |
} |
|
|
554 |
if (!sel) { |
|
|
555 |
sel = cont; |
|
|
556 |
cont = 'body'; |
|
|
557 |
} |
|
|
558 |
return inst.delegate(type, fn, cont, sel); |
|
|
559 |
}, |
|
|
560 |
/** |
|
|
561 |
* @method getInstance |
|
|
562 |
* @description Get a reference to the internal YUI instance. |
|
|
563 |
* @return {YUI} The internal YUI instance |
|
|
564 |
*/ |
|
|
565 |
getInstance: function() { |
|
|
566 |
return this._instance; |
|
|
567 |
}, |
|
|
568 |
/** |
|
|
569 |
* @method render |
|
|
570 |
* @description Render the iframe into the container config option or open the window. |
|
|
571 |
* @param {String/HTMLElement/Node} node The node to render to |
|
|
572 |
* @return {Frame} |
|
|
573 |
* @chainable |
|
|
574 |
*/ |
|
|
575 |
render: function(node) { |
|
|
576 |
if (this._rendered) { |
|
|
577 |
return this; |
|
|
578 |
} |
|
|
579 |
this._rendered = true; |
|
|
580 |
if (node) { |
|
|
581 |
this.set('container', node); |
|
|
582 |
} |
|
|
583 |
|
|
|
584 |
this._create(Y.bind(function(res) { |
|
|
585 |
|
|
|
586 |
var inst, timer, |
|
|
587 |
cb = Y.bind(function(i) { |
|
|
588 |
this._instanceLoaded(i); |
|
|
589 |
}, this), |
|
|
590 |
args = Y.clone(this.get('use')), |
|
|
591 |
config = { |
|
|
592 |
debug: false, |
|
|
593 |
win: res.win, |
|
|
594 |
doc: res.doc |
|
|
595 |
}, |
|
|
596 |
fn = Y.bind(function() { |
|
|
597 |
config = this._resolveWinDoc(config); |
|
|
598 |
inst = YUI(config); |
|
|
599 |
inst.host = this.get('host'); //Cross reference to Editor |
|
|
600 |
|
|
|
601 |
try { |
|
|
602 |
inst.use('node-base', cb); |
|
|
603 |
if (timer) { |
|
|
604 |
clearInterval(timer); |
|
|
605 |
} |
|
|
606 |
} catch (e) { |
|
|
607 |
timer = setInterval(function() { |
|
|
608 |
fn(); |
|
|
609 |
}, 350); |
|
|
610 |
} |
|
|
611 |
}, this); |
|
|
612 |
|
|
|
613 |
args.push(fn); |
|
|
614 |
|
|
|
615 |
Y.use.apply(Y, args); |
|
|
616 |
|
|
|
617 |
}, this)); |
|
|
618 |
|
|
|
619 |
return this; |
|
|
620 |
}, |
|
|
621 |
/** |
|
|
622 |
* @private |
|
|
623 |
* @method _handleFocus |
|
|
624 |
* @description Does some tricks on focus to set the proper cursor position. |
|
|
625 |
*/ |
|
|
626 |
_handleFocus: function() { |
|
|
627 |
var inst = this.getInstance(), |
|
|
628 |
sel = new inst.EditorSelection(), |
|
|
629 |
n, c, b, par; |
|
|
630 |
|
|
|
631 |
if (sel.anchorNode) { |
|
|
632 |
n = sel.anchorNode; |
|
|
633 |
|
|
|
634 |
if (n.test('p') && n.get('innerHTML') === '') { |
|
|
635 |
n = n.get('parentNode'); |
|
|
636 |
} |
|
|
637 |
c = n.get('childNodes'); |
|
|
638 |
|
|
|
639 |
if (c.size()) { |
|
|
640 |
if (c.item(0).test('br')) { |
|
|
641 |
sel.selectNode(n, true, false); |
|
|
642 |
} else if (c.item(0).test('p')) { |
|
|
643 |
n = c.item(0).one('br.yui-cursor'); |
|
|
644 |
if (n) { |
|
|
645 |
n = n.get('parentNode'); |
|
|
646 |
} |
|
|
647 |
if (!n) { |
|
|
648 |
n = c.item(0).get('firstChild'); |
|
|
649 |
} |
|
|
650 |
if (!n) { |
|
|
651 |
n = c.item(0); |
|
|
652 |
} |
|
|
653 |
if (n) { |
|
|
654 |
sel.selectNode(n, true, false); |
|
|
655 |
} |
|
|
656 |
} else { |
|
|
657 |
b = inst.one('br.yui-cursor'); |
|
|
658 |
if (b) { |
|
|
659 |
par = b.get('parentNode'); |
|
|
660 |
if (par) { |
|
|
661 |
sel.selectNode(par, true, false); |
|
|
662 |
} |
|
|
663 |
} |
|
|
664 |
} |
|
|
665 |
} |
|
|
666 |
} |
|
|
667 |
}, |
|
|
668 |
/** |
|
|
669 |
* @method focus |
|
|
670 |
* @description Set the focus to the iframe |
|
|
671 |
* @param {Function} fn Callback function to execute after focus happens |
|
|
672 |
* @return {Frame} |
|
|
673 |
* @chainable |
|
|
674 |
*/ |
|
|
675 |
focus: function(fn) { |
|
|
676 |
if (Y.UA.ie && Y.UA.ie < 9) { |
|
|
677 |
try { |
|
|
678 |
Y.one('win').focus(); |
|
|
679 |
if (this.getInstance()) { |
|
|
680 |
if (this.getInstance().one('win')) { |
|
|
681 |
this.getInstance().one('win').focus(); |
|
|
682 |
} |
|
|
683 |
} |
|
|
684 |
} catch (ierr) { |
|
|
685 |
} |
|
|
686 |
if (fn === true) { |
|
|
687 |
this._handleFocus(); |
|
|
688 |
} |
|
|
689 |
if (Y.Lang.isFunction(fn)) { |
|
|
690 |
fn(); |
|
|
691 |
} |
|
|
692 |
} else { |
|
|
693 |
try { |
|
|
694 |
Y.one('win').focus(); |
|
|
695 |
Y.later(100, this, function() { |
|
|
696 |
if (this.getInstance()) { |
|
|
697 |
if (this.getInstance().one('win')) { |
|
|
698 |
this.getInstance().one('win').focus(); |
|
|
699 |
} |
|
|
700 |
} |
|
|
701 |
if (fn === true) { |
|
|
702 |
this._handleFocus(); |
|
|
703 |
} |
|
|
704 |
if (Y.Lang.isFunction(fn)) { |
|
|
705 |
fn(); |
|
|
706 |
} |
|
|
707 |
}); |
|
|
708 |
} catch (ferr) { |
|
|
709 |
} |
|
|
710 |
} |
|
|
711 |
return this; |
|
|
712 |
}, |
|
|
713 |
/** |
|
|
714 |
* @method show |
|
|
715 |
* @description Show the iframe instance |
|
|
716 |
* @return {Frame} |
|
|
717 |
* @chainable |
|
|
718 |
*/ |
|
|
719 |
show: function() { |
|
|
720 |
this._iframe.setStyles({ |
|
|
721 |
position: 'static', |
|
|
722 |
left: '' |
|
|
723 |
}); |
|
|
724 |
if (Y.UA.gecko) { |
|
|
725 |
try { |
|
|
726 |
if (this.getInstance()) { |
|
|
727 |
this.getInstance().config.doc.designMode = 'on'; |
|
|
728 |
} |
|
|
729 |
} catch (e) { } |
|
|
730 |
this.focus(); |
|
|
731 |
} |
|
|
732 |
return this; |
|
|
733 |
}, |
|
|
734 |
/** |
|
|
735 |
* @method hide |
|
|
736 |
* @description Hide the iframe instance |
|
|
737 |
* @return {Frame} |
|
|
738 |
* @chainable |
|
|
739 |
*/ |
|
|
740 |
hide: function() { |
|
|
741 |
this._iframe.setStyles({ |
|
|
742 |
position: 'absolute', |
|
|
743 |
left: '-999999px' |
|
|
744 |
}); |
|
|
745 |
return this; |
|
|
746 |
} |
|
|
747 |
}, { |
|
|
748 |
/** |
|
|
749 |
* @static |
|
|
750 |
* @property THROTTLE_TIME |
|
|
751 |
* @description The throttle time for key events in IE |
|
|
752 |
* @type Number |
|
|
753 |
* @default 100 |
|
|
754 |
*/ |
|
|
755 |
THROTTLE_TIME: 100, |
|
|
756 |
/** |
|
|
757 |
* @static |
|
|
758 |
* @property DOM_EVENTS |
|
|
759 |
* @description The DomEvents that the frame automatically attaches and bubbles |
|
|
760 |
* @type Object |
|
|
761 |
*/ |
|
|
762 |
DOM_EVENTS: { |
|
|
763 |
dblclick: 1, |
|
|
764 |
click: 1, |
|
|
765 |
paste: 1, |
|
|
766 |
mouseup: 1, |
|
|
767 |
mousedown: 1, |
|
|
768 |
keyup: 1, |
|
|
769 |
keydown: 1, |
|
|
770 |
keypress: 1, |
|
|
771 |
activate: 1, |
|
|
772 |
deactivate: 1, |
|
|
773 |
beforedeactivate: 1, |
|
|
774 |
focusin: 1, |
|
|
775 |
focusout: 1 |
|
|
776 |
}, |
|
|
777 |
|
|
|
778 |
/** |
|
|
779 |
* @static |
|
|
780 |
* @property DEFAULT_CSS |
|
|
781 |
* @description The default css used when creating the document. |
|
|
782 |
* @type String |
|
|
783 |
*/ |
|
|
784 |
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; }', |
|
|
785 |
/** |
|
|
786 |
* The template string used to create the iframe, deprecated to use DOM instead of innerHTML |
|
|
787 |
* @static |
|
|
788 |
* @property HTML |
|
|
789 |
* @type String |
|
|
790 |
* @deprecated |
|
|
791 |
*/ |
|
|
792 |
//HTML: '<iframe border="0" frameBorder="0" marginWidth="0" marginHeight="0" leftMargin="0" topMargin="0" allowTransparency="true" width="100%" height="99%"></iframe>', |
|
|
793 |
/** |
|
|
794 |
* Attributes to auto add to the dynamic iframe under the hood |
|
|
795 |
* @static |
|
|
796 |
* @property IFRAME_ATTRS |
|
|
797 |
* @type Object |
|
|
798 |
*/ |
|
|
799 |
IFRAME_ATTRS: { |
|
|
800 |
border: '0', |
|
|
801 |
frameBorder: '0', |
|
|
802 |
marginWidth: '0', |
|
|
803 |
marginHeight: '0', |
|
|
804 |
leftMargin: '0', |
|
|
805 |
topMargin: '0', |
|
|
806 |
allowTransparency: 'true', |
|
|
807 |
width: "100%", |
|
|
808 |
height: "99%" |
|
|
809 |
}, |
|
|
810 |
/** |
|
|
811 |
* @static |
|
|
812 |
* @property PAGE_HTML |
|
|
813 |
* @description The template used to create the page when created dynamically. |
|
|
814 |
* @type String |
|
|
815 |
*/ |
|
|
816 |
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>', |
|
|
817 |
|
|
|
818 |
/** |
|
|
819 |
* @static |
|
|
820 |
* @method getDocType |
|
|
821 |
* @description Parses document.doctype and generates a DocType to match the parent page, if supported. |
|
|
822 |
* For IE8, it grabs document.all[0].nodeValue and uses that. For IE < 8, it falls back to Frame.DOC_TYPE. |
|
|
823 |
* @return {String} The normalized DocType to apply to the iframe |
|
|
824 |
*/ |
|
|
825 |
getDocType: function() { |
|
|
826 |
var dt = Y.config.doc.doctype, |
|
|
827 |
str = Frame.DOC_TYPE; |
|
|
828 |
|
|
|
829 |
if (dt) { |
|
|
830 |
str = '<!DOCTYPE ' + dt.name + ((dt.publicId) ? ' ' + dt.publicId : '') + ((dt.systemId) ? ' ' + dt.systemId : '') + '>'; |
|
|
831 |
} else { |
|
|
832 |
if (Y.config.doc.all) { |
|
|
833 |
dt = Y.config.doc.all[0]; |
|
|
834 |
if (dt.nodeType) { |
|
|
835 |
if (dt.nodeType === 8) { |
|
|
836 |
if (dt.nodeValue) { |
|
|
837 |
if (dt.nodeValue.toLowerCase().indexOf('doctype') !== -1) { |
|
|
838 |
str = '<!' + dt.nodeValue + '>'; |
|
|
839 |
} |
|
|
840 |
} |
|
|
841 |
} |
|
|
842 |
} |
|
|
843 |
} |
|
|
844 |
} |
|
|
845 |
return str; |
|
|
846 |
}, |
|
|
847 |
/** |
|
|
848 |
* @static |
|
|
849 |
* @property DOC_TYPE |
|
|
850 |
* @description The DOCTYPE to prepend to the new document when created. Should match the one on the page being served. |
|
|
851 |
* @type String |
|
|
852 |
*/ |
|
|
853 |
DOC_TYPE: '<!DOCTYPE HTML PUBLIC "-/'+'/W3C/'+'/DTD HTML 4.01/'+'/EN" "http:/'+'/www.w3.org/TR/html4/strict.dtd">', |
|
|
854 |
/** |
|
|
855 |
* @static |
|
|
856 |
* @property META |
|
|
857 |
* @description The meta-tag for Content-Type to add to the dynamic document |
|
|
858 |
* @type String |
|
|
859 |
*/ |
|
|
860 |
META: '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/><meta http-equiv="X-UA-Compatible" content="IE=7">', |
|
|
861 |
//META: '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>', |
|
|
862 |
/** |
|
|
863 |
* @static |
|
|
864 |
* @property NAME |
|
|
865 |
* @description The name of the class (frame) |
|
|
866 |
* @type String |
|
|
867 |
*/ |
|
|
868 |
NAME: 'frame', |
|
|
869 |
ATTRS: { |
|
|
870 |
/** |
|
|
871 |
* @attribute title |
|
|
872 |
* @description The title to give the blank page. |
|
|
873 |
* @type String |
|
|
874 |
*/ |
|
|
875 |
title: { |
|
|
876 |
value: 'Blank Page' |
|
|
877 |
}, |
|
|
878 |
/** |
|
|
879 |
* @attribute dir |
|
|
880 |
* @description The default text direction for this new frame. Default: ltr |
|
|
881 |
* @type String |
|
|
882 |
*/ |
|
|
883 |
dir: { |
|
|
884 |
value: 'ltr' |
|
|
885 |
}, |
|
|
886 |
/** |
|
|
887 |
* @attribute lang |
|
|
888 |
* @description The default language. Default: en-US |
|
|
889 |
* @type String |
|
|
890 |
*/ |
|
|
891 |
lang: { |
|
|
892 |
value: 'en-US' |
|
|
893 |
}, |
|
|
894 |
/** |
|
|
895 |
* @attribute src |
|
|
896 |
* @description The src of the iframe/window. Defaults to javascript:; |
|
|
897 |
* @type String |
|
|
898 |
*/ |
|
|
899 |
src: { |
|
|
900 |
//Hackish, IE needs the false in the Javascript URL |
|
|
901 |
value: 'javascript' + ((Y.UA.ie) ? ':false' : ':') + ';' |
|
|
902 |
}, |
|
|
903 |
/** |
|
|
904 |
* @attribute designMode |
|
|
905 |
* @description Should designMode be turned on after creation. |
|
|
906 |
* @writeonce |
|
|
907 |
* @type Boolean |
|
|
908 |
*/ |
|
|
909 |
designMode: { |
|
|
910 |
writeOnce: true, |
|
|
911 |
value: false |
|
|
912 |
}, |
|
|
913 |
/** |
|
|
914 |
* @attribute content |
|
|
915 |
* @description The string to inject into the body of the new frame/window. |
|
|
916 |
* @type String |
|
|
917 |
*/ |
|
|
918 |
content: { |
|
|
919 |
value: '<br>', |
|
|
920 |
setter: '_setHTML', |
|
|
921 |
getter: '_getHTML' |
|
|
922 |
}, |
|
|
923 |
/** |
|
|
924 |
* @attribute basehref |
|
|
925 |
* @description The base href to use in the iframe. |
|
|
926 |
* @type String |
|
|
927 |
*/ |
|
|
928 |
basehref: { |
|
|
929 |
value: false, |
|
|
930 |
getter: '_resolveBaseHref' |
|
|
931 |
}, |
|
|
932 |
/** |
|
|
933 |
* @attribute use |
|
|
934 |
* @description Array of modules to include in the scoped YUI instance at render time. Default: ['none', 'selector-css2'] |
|
|
935 |
* @writeonce |
|
|
936 |
* @type Array |
|
|
937 |
*/ |
|
|
938 |
use: { |
|
|
939 |
writeOnce: true, |
|
|
940 |
value: ['node', 'node-style', 'selector-css3'] |
|
|
941 |
}, |
|
|
942 |
/** |
|
|
943 |
* @attribute container |
|
|
944 |
* @description The container to append the iFrame to on render. |
|
|
945 |
* @type String/HTMLElement/Node |
|
|
946 |
*/ |
|
|
947 |
container: { |
|
|
948 |
value: 'body', |
|
|
949 |
setter: function(n) { |
|
|
950 |
return Y.one(n); |
|
|
951 |
} |
|
|
952 |
}, |
|
|
953 |
/** |
|
|
954 |
* @attribute node |
|
|
955 |
* @description The Node instance of the iframe. |
|
|
956 |
* @type Node |
|
|
957 |
*/ |
|
|
958 |
node: { |
|
|
959 |
readOnly: true, |
|
|
960 |
value: null, |
|
|
961 |
getter: function() { |
|
|
962 |
return this._iframe; |
|
|
963 |
} |
|
|
964 |
}, |
|
|
965 |
/** |
|
|
966 |
* @attribute id |
|
|
967 |
* @description Set the id of the new Node. (optional) |
|
|
968 |
* @type String |
|
|
969 |
* @writeonce |
|
|
970 |
*/ |
|
|
971 |
id: { |
|
|
972 |
writeOnce: true, |
|
|
973 |
getter: function(id) { |
|
|
974 |
if (!id) { |
|
|
975 |
id = 'iframe-' + Y.guid(); |
|
|
976 |
} |
|
|
977 |
return id; |
|
|
978 |
} |
|
|
979 |
}, |
|
|
980 |
/** |
|
|
981 |
* @attribute linkedcss |
|
|
982 |
* @description An array of url's to external linked style sheets |
|
|
983 |
* @type String |
|
|
984 |
*/ |
|
|
985 |
linkedcss: { |
|
|
986 |
value: '', |
|
|
987 |
getter: '_getLinkedCSS', |
|
|
988 |
setter: '_setLinkedCSS' |
|
|
989 |
}, |
|
|
990 |
/** |
|
|
991 |
* @attribute extracss |
|
|
992 |
* @description A string of CSS to add to the Head of the Editor |
|
|
993 |
* @type String |
|
|
994 |
*/ |
|
|
995 |
extracss: { |
|
|
996 |
value: '', |
|
|
997 |
setter: '_setExtraCSS' |
|
|
998 |
}, |
|
|
999 |
/** |
|
|
1000 |
* @attribute host |
|
|
1001 |
* @description A reference to the Editor instance |
|
|
1002 |
* @type Object |
|
|
1003 |
*/ |
|
|
1004 |
host: { |
|
|
1005 |
value: false |
|
|
1006 |
}, |
|
|
1007 |
/** |
|
|
1008 |
* @attribute defaultblock |
|
|
1009 |
* @description The default tag to use for block level items, defaults to: p |
|
|
1010 |
* @type String |
|
|
1011 |
*/ |
|
|
1012 |
defaultblock: { |
|
|
1013 |
value: 'p' |
|
|
1014 |
} |
|
|
1015 |
} |
|
|
1016 |
}); |
|
|
1017 |
|
|
|
1018 |
|
|
|
1019 |
Y.Frame = Frame; |
|
|
1020 |
|
|
|
1021 |
|
|
|
1022 |
|
|
|
1023 |
}, '3.10.3', {"requires": ["base", "node", "selector-css3", "yui-throttle"]}); |