Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 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
                if (node) {
493
                    node.remove();
494
                }
495
 
496
                inst.one('head').append('<style id="extra_css">' + css + '</style>');
497
            } else {
498
                //This needs to be wrapped in a contentready callback for the !_ready state
499
                this.once(EVENT_CONTENT_READY, Y.bind(this._setExtraCSS, this, css));
500
            }
501
 
502
            return css;
503
        },
504
        /**
505
        * @private
506
        * @method _instanceLoaded
507
        * @description Called from the first YUI instance that sets up the internal instance.
508
        * This loads the content into the window/frame and attaches the contentready event.
509
        * @param {YUI} inst The internal YUI instance bound to the frame/window
510
        */
511
        _instanceLoaded: function(inst) {
512
            this._instance = inst;
513
            this._onContentReady();
514
 
515
            var doc = this._instance.config.doc;
516
 
517
            if (this.get('designMode')) {
518
                if (!Y.UA.ie) {
519
                    try {
520
                        //Force other browsers into non CSS styling
521
                        doc.execCommand('styleWithCSS', false, false);
522
                        doc.execCommand('insertbronreturn', false, false);
523
                    } catch (err) {}
524
                }
525
            }
526
        },
527
        //BEGIN PUBLIC METHODS
528
        /**
529
        * @method use
530
        * @description This is a scoped version of the normal YUI.use method & is bound to this frame/window.
531
        * At setup, the inst.use method is mapped to this method.
532
        */
533
        use: function() {
534
            var inst = this.getInstance(),
535
                args = Y.Array(arguments),
536
                cb = false;
537
 
538
            if (Y.Lang.isFunction(args[args.length - 1])) {
539
                cb = args.pop();
540
            }
541
            if (cb) {
542
                args.push(function() {
543
                    cb.apply(inst, arguments);
544
 
545
                });
546
            }
547
 
548
            return inst.__use.apply(inst, args);
549
        },
550
        /**
551
        * @method delegate
552
        * @description A delegate method passed to the instance's delegate method
553
        * @param {String} type The type of event to listen for
554
        * @param {Function} fn The method to attach
555
        * @param {String} cont The container to act as a delegate, if no "sel" passed, the body is assumed as the container.
556
        * @param {String} sel The selector to match in the event (optional)
557
        * @return {EventHandle} The Event handle returned from Y.delegate
558
        */
559
        delegate: function(type, fn, cont, sel) {
560
            var inst = this.getInstance();
561
            if (!inst) {
562
                return false;
563
            }
564
            if (!sel) {
565
                sel = cont;
566
                cont = 'body';
567
            }
568
            return inst.delegate(type, fn, cont, sel);
569
        },
570
        /**
571
        * @method getInstance
572
        * @description Get a reference to the internal YUI instance.
573
        * @return {YUI} The internal YUI instance
574
        */
575
        getInstance: function() {
576
            return this._instance;
577
        },
578
        /**
579
        * @method render
580
        * @description Render the iframe into the container config option or open the window.
581
        * @param {String/HTMLElement/Node} node The node to render to
582
        * @return {Frame}
583
        * @chainable
584
        */
585
        render: function(node) {
586
            if (this._rendered) {
587
                return this;
588
            }
589
            this._rendered = true;
590
            if (node) {
591
                this.set('container', node);
592
            }
593
 
594
            this._create(Y.bind(function(res) {
595
 
596
                var inst, timer,
597
                    cb = Y.bind(function(i) {
598
                        this._instanceLoaded(i);
599
                    }, this),
600
                    args = Y.clone(this.get('use')),
601
                    config = {
602
                        debug: false,
603
                        win: res.win,
604
                        doc: res.doc
605
                    },
606
                    fn = Y.bind(function() {
607
                        config = this._resolveWinDoc(config);
608
                        inst = YUI(config);
609
                        inst.host = this.get(HOST); //Cross reference to Editor
610
 
611
                        try {
612
                            inst.use('node-base', cb);
613
                            if (timer) {
614
                                clearInterval(timer);
615
                            }
616
                        } catch (e) {
617
                            timer = setInterval(function() {
618
                                fn();
619
                            }, 350);
620
                        }
621
                    }, this);
622
 
623
                args.push(fn);
624
 
625
                Y.use.apply(Y, args);
626
 
627
            }, this));
628
 
629
            return this;
630
        },
631
        /**
632
        * @private
633
        * @method _handleFocus
634
        * @description Does some tricks on focus to set the proper cursor position.
635
        */
636
        _handleFocus: function() {
637
            var inst = this.getInstance(),
638
                sel = new inst.EditorSelection(),
639
                n, c, b, par;
640
 
641
            if (sel.anchorNode) {
642
                n = sel.anchorNode;
643
 
644
                if (n.test('p') && n.get('innerHTML') === '') {
645
                    n = n.get('parentNode');
646
                }
647
                c = n.get('childNodes');
648
 
649
                if (c.size()) {
650
                    if (c.item(0).test('br')) {
651
                        sel.selectNode(n, true, false);
652
                    } else if (c.item(0).test('p')) {
653
                        n = c.item(0).one('br.yui-cursor');
654
                        if (n) {
655
                            n = n.get('parentNode');
656
                        }
657
                        if (!n) {
658
                            n = c.item(0).get('firstChild');
659
                        }
660
                        if (!n) {
661
                            n = c.item(0);
662
                        }
663
                        if (n) {
664
                            sel.selectNode(n, true, false);
665
                        }
666
                    } else {
667
                        b = inst.one('br.yui-cursor');
668
                        if (b) {
669
                            par = b.get('parentNode');
670
                            if (par) {
671
                                sel.selectNode(par, true, false);
672
                            }
673
                        }
674
                    }
675
                }
676
            }
677
        },
678
        /**
679
        * Validates linkedcss property
680
        *
681
        * @method _validateLinkedCSS
682
        * @private
683
        */
684
        _validateLinkedCSS: function(value) {
685
            return Lang.isString(value) || Lang.isArray(value);
686
        },
687
        /**
688
        * @method focus
689
        * @description Set the focus to the iframe
690
        * @param {Function} fn Callback function to execute after focus happens
691
        * @return {Frame}
692
        * @chainable
693
        */
694
        focus: function(fn) {
695
            if (Y.UA.ie && Y.UA.ie < 9) {
696
                try {
697
                    Y.one('win').focus();
698
                    if (this.getInstance()) {
699
                        if (this.getInstance().one('win')) {
700
                            this.getInstance().one('win').focus();
701
                        }
702
                    }
703
                } catch (ierr) {
704
                }
705
                if (fn === true) {
706
                    this._handleFocus();
707
                }
708
                if (Y.Lang.isFunction(fn)) {
709
                    fn();
710
                }
711
            } else {
712
                try {
713
                    Y.one('win').focus();
714
                    Y.later(100, this, function() {
715
                        if (this.getInstance()) {
716
                            if (this.getInstance().one('win')) {
717
                                this.getInstance().one('win').focus();
718
                            }
719
                        }
720
                        if (fn === true) {
721
                            this._handleFocus();
722
                        }
723
                        if (Y.Lang.isFunction(fn)) {
724
                            fn();
725
                        }
726
                    });
727
                } catch (ferr) {
728
                }
729
            }
730
            return this;
731
        },
732
        /**
733
        * @method show
734
        * @description Show the iframe instance
735
        * @return {Frame}
736
        * @chainable
737
        */
738
        show: function() {
739
            this._iframe.setStyles({
740
                position: 'static',
741
                left: ''
742
            });
743
            if (Y.UA.gecko) {
744
                try {
745
                    if (this.getInstance()) {
746
                        this.getInstance().config.doc.designMode = 'on';
747
                    }
748
                } catch (e) { }
749
                this.focus();
750
            }
751
            return this;
752
        },
753
        /**
754
        * @method hide
755
        * @description Hide the iframe instance
756
        * @return {Frame}
757
        * @chainable
758
        */
759
        hide: function() {
760
            this._iframe.setStyles({
761
                position: 'absolute',
762
                left: '-999999px'
763
            });
764
            return this;
765
        }
766
    }, {
767
        /**
768
        * @static
769
        * @property THROTTLE_TIME
770
        * @description The throttle time for key events in IE
771
        * @type Number
772
        * @default 100
773
        */
774
        THROTTLE_TIME: 100,
775
        /**
776
        * @static
777
        * @property DOM_EVENTS
778
        * @description The DomEvents that the frame automatically attaches and bubbles
779
        * @type Object
780
        */
781
        DOM_EVENTS: {
782
            dblclick: 1,
783
            click: 1,
784
            paste: 1,
785
            mouseup: 1,
786
            mousedown: 1,
787
            keyup: 1,
788
            keydown: 1,
789
            keypress: 1,
790
            activate: 1,
791
            deactivate: 1,
792
            beforedeactivate: 1,
793
            focusin: 1,
794
            focusout: 1
795
        },
796
 
797
        /**
798
        * @static
799
        * @property DEFAULT_CSS
800
        * @description The default css used when creating the document.
801
        * @type String
802
        */
803
        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; }',
804
        /**
805
        * The template string used to create the iframe, deprecated to use DOM instead of innerHTML
806
        * @static
807
        * @property HTML
808
        * @type String
809
        * @deprecated
810
        */
811
        //HTML: '<iframe border="0" frameBorder="0" marginWidth="0" marginHeight="0" leftMargin="0" topMargin="0" allowTransparency="true" width="100%" height="99%"></iframe>',
812
        /**
813
        * Attributes to auto add to the dynamic iframe under the hood
814
        * @static
815
        * @property IFRAME_ATTRS
816
        * @type Object
817
        */
818
        IFRAME_ATTRS: {
819
            border: '0',
820
            frameBorder: '0',
821
            marginWidth: '0',
822
            marginHeight: '0',
823
            leftMargin: '0',
824
            topMargin: '0',
825
            allowTransparency: 'true',
826
            width: "100%",
827
            height: "99%"
828
        },
829
        /**
830
        * @static
831
        * @property PAGE_HTML
832
        * @description The template used to create the page when created dynamically.
833
        * @type String
834
        */
835
        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>',
836
 
837
        /**
838
        * @static
839
        * @method getDocType
840
        * @description Parses document.doctype and generates a DocType to match the parent page, if supported.
841
        * For IE8, it grabs document.all[0].nodeValue and uses that. For IE < 8, it falls back to Frame.DOC_TYPE.
842
        * @return {String} The normalized DocType to apply to the iframe
843
        */
844
        getDocType: function() {
845
            var dt = Y.config.doc.doctype,
846
                str = Frame.DOC_TYPE;
847
 
848
            if (dt) {
849
                str = '<!DOCTYPE ' + dt.name + ((dt.publicId) ? ' ' + dt.publicId : '') + ((dt.systemId) ? ' ' + dt.systemId : '') + '>';
850
            } else {
851
                if (Y.config.doc.all) {
852
                    dt = Y.config.doc.all[0];
853
                    if (dt.nodeType) {
854
                        if (dt.nodeType === 8) {
855
                            if (dt.nodeValue) {
856
                                if (dt.nodeValue.toLowerCase().indexOf('doctype') !== -1) {
857
                                    str = '<!' + dt.nodeValue + '>';
858
                                }
859
                            }
860
                        }
861
                    }
862
                }
863
            }
864
            return str;
865
        },
866
        /**
867
        * @static
868
        * @property DOC_TYPE
869
        * @description The DOCTYPE to prepend to the new document when created. Should match the one on the page being served.
870
        * @type String
871
        */
872
        DOC_TYPE: '<!DOCTYPE HTML PUBLIC "-/'+'/W3C/'+'/DTD HTML 4.01/'+'/EN" "http:/'+'/www.w3.org/TR/html4/strict.dtd">',
873
        /**
874
        * @static
875
        * @property META
876
        * @description The meta-tag for Content-Type to add to the dynamic document
877
        * @type String
878
        */
879
        META: '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/><meta http-equiv="X-UA-Compatible" content="IE=7">',
880
        //META: '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>',
881
        /**
882
        * @static
883
        * @property NAME
884
        * @description The name of the class (frame)
885
        * @type String
886
        */
887
        NAME: 'frame',
888
        /**
889
        * The namespace on which Frame plugin will reside.
890
        *
891
        * @property NS
892
        * @type String
893
        * @default 'frame'
894
        * @static
895
        */
896
        NS: 'frame',
897
        ATTRS: {
898
            /**
899
            * @attribute title
900
            * @description The title to give the blank page.
901
            * @type String
902
            */
903
            title: {
904
                value: 'Blank Page'
905
            },
906
            /**
907
            * @attribute dir
908
            * @description The default text direction for this new frame. Default: ltr
909
            * @type String
910
            */
911
            dir: {
912
                value: 'ltr'
913
            },
914
            /**
915
            * @attribute lang
916
            * @description The default language. Default: en-US
917
            * @type String
918
            */
919
            lang: {
920
                value: 'en-US'
921
            },
922
            /**
923
            * @attribute src
924
            * @description The src of the iframe/window. Defaults to javascript:;
925
            * @type String
926
            */
927
            src: {
928
                //Hackish, IE needs the false in the Javascript URL
929
                value: 'javascript' + ((Y.UA.ie) ? ':false' : ':') + ';'
930
            },
931
            /**
932
            * @attribute designMode
933
            * @description Should designMode be turned on after creation.
934
            * @writeonce
935
            * @type Boolean
936
            */
937
            designMode: {
938
                writeOnce: true,
939
                value: false
940
            },
941
            /**
942
            * @attribute content
943
            * @description The string to inject into the body of the new frame/window.
944
            * @type String
945
            */
946
            content: {
947
                validator: Lang.isString,
948
                value: '<br>',
949
                setter: '_setHTML',
950
                getter: '_getHTML'
951
            },
952
            /**
953
            * @attribute basehref
954
            * @description The base href to use in the iframe.
955
            * @type String
956
            */
957
            basehref: {
958
                value: false,
959
                getter: '_resolveBaseHref'
960
            },
961
            /**
962
            * @attribute use
963
            * @description Array of modules to include in the scoped YUI instance at render time. Default: ['none', 'selector-css2']
964
            * @writeonce
965
            * @type Array
966
            */
967
            use: {
968
                writeOnce: true,
969
                value: ['node', 'node-style', 'selector-css3']
970
            },
971
            /**
972
            * @attribute container
973
            * @description The container to append the iFrame to on render.
974
            * @type String/HTMLElement/Node
975
            */
976
            container: {
977
                value: 'body',
978
                setter: function(n) {
979
                    return Y.one(n);
980
                }
981
            },
982
            /**
983
            * @attribute node
984
            * @description The Node instance of the iframe.
985
            * @type Node
986
            */
987
            node: {
988
                readOnly: true,
989
                value: null,
990
                getter: function() {
991
                    return this._iframe;
992
                }
993
            },
994
            /**
995
            * @attribute id
996
            * @description Set the id of the new Node. (optional)
997
            * @type String
998
            * @writeonce
999
            */
1000
            id: {
1001
                writeOnce: true,
1002
                getter: function(id) {
1003
                    if (!id) {
1004
                        id = 'iframe-' + Y.guid();
1005
                    }
1006
                    return id;
1007
                }
1008
            },
1009
            /**
1010
            * @attribute linkedcss
1011
            * @description An array of url's to external linked style sheets
1012
            * @type String|Array
1013
            */
1014
            linkedcss: {
1015
                validator: '_validateLinkedCSS',
1016
                getter: '_getLinkedCSS',
1017
                setter: '_setLinkedCSS'
1018
            },
1019
            /**
1020
            * @attribute extracss
1021
            * @description A string of CSS to add to the Head of the Editor
1022
            * @type String
1023
            */
1024
            extracss: {
1025
                validator: Lang.isString,
1026
                setter: '_setExtraCSS'
1027
            },
1028
            /**
1029
            * @attribute defaultblock
1030
            * @description The default tag to use for block level items, defaults to: p
1031
            * @type String
1032
            */
1033
            defaultblock: {
1034
                value: 'p'
1035
            }
1036
        }
1037
    });
1038
 
1039
    Y.namespace('Plugin');
1040
 
1041
    Y.Plugin.Frame = Frame;
1042
 
1043
    Y.Frame = Frame;
1044
 
1045
 
1046
 
1047
}, '3.18.1', {"requires": ["base", "node", "plugin", "selector-css3", "yui-throttle"]});