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