~ubuntu-branches/ubuntu/precise/maas/precise-updates

« back to all changes in this revision

Viewing changes to src/maasserver/static/jslibs/yui/3.4.1/build/editor-base/editor-base.js

Tags: 1.2+bzr1373+dfsg-0ubuntu1~12.04.4
* SECURITY UPDATE: failure to authenticate downloaded content (LP: #1039513)
  - debian/patches/CVE-2013-1058.patch: Authenticate downloaded files with
    GnuPG and MD5SUM files. Thanks to Julian Edwards.
  - CVE-2013-1058
* SECURITY UPDATE: configuration options may be loaded from current working
  directory (LP: #1158425)
  - debian/patches/CVE-2013-1057-1-2.patch: Do not load configuration
    options from the current working directory. Thanks to Julian Edwards.
  - CVE-2013-1057

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
YUI 3.4.1 (build 4118)
3
 
Copyright 2011 Yahoo! Inc. All rights reserved.
4
 
Licensed under the BSD License.
5
 
http://yuilibrary.com/license/
6
 
*/
7
 
YUI.add('editor-base', function(Y) {
8
 
 
9
 
 
10
 
    /**
11
 
     * Base class for Editor. Handles the business logic of Editor, no GUI involved only utility methods and events.
12
 
     *
13
 
     *      var editor = new Y.EditorBase({
14
 
     *          content: 'Foo'
15
 
     *      });
16
 
     *      editor.render('#demo');
17
 
     *
18
 
     * @class EditorBase
19
 
     * @extends Base
20
 
     * @module editor
21
 
     * @main editor
22
 
     * @submodule editor-base
23
 
     * @constructor
24
 
     */
25
 
    
26
 
    var EditorBase = function() {
27
 
        EditorBase.superclass.constructor.apply(this, arguments);
28
 
    }, LAST_CHILD = ':last-child', BODY = 'body';
29
 
 
30
 
    Y.extend(EditorBase, Y.Base, {
31
 
        /**
32
 
        * Internal reference to the Y.Frame instance
33
 
        * @property frame
34
 
        */
35
 
        frame: null,
36
 
        initializer: function() {
37
 
            var frame = new Y.Frame({
38
 
                designMode: true,
39
 
                title: EditorBase.STRINGS.title,
40
 
                use: EditorBase.USE,
41
 
                dir: this.get('dir'),
42
 
                extracss: this.get('extracss'),
43
 
                linkedcss: this.get('linkedcss'),
44
 
                defaultblock: this.get('defaultblock'),
45
 
                host: this
46
 
            }).plug(Y.Plugin.ExecCommand);
47
 
 
48
 
 
49
 
            frame.after('ready', Y.bind(this._afterFrameReady, this));
50
 
            frame.addTarget(this);
51
 
 
52
 
            this.frame = frame;
53
 
 
54
 
            this.publish('nodeChange', {
55
 
                emitFacade: true,
56
 
                bubbles: true,
57
 
                defaultFn: this._defNodeChangeFn
58
 
            });
59
 
            
60
 
            //this.plug(Y.Plugin.EditorPara);
61
 
        },
62
 
        destructor: function() {
63
 
            this.frame.destroy();
64
 
 
65
 
            this.detachAll();
66
 
        },
67
 
        /**
68
 
        * Copy certain styles from one node instance to another (used for new paragraph creation mainly)
69
 
        * @method copyStyles
70
 
        * @param {Node} from The Node instance to copy the styles from 
71
 
        * @param {Node} to The Node instance to copy the styles to
72
 
        */
73
 
        copyStyles: function(from, to) {
74
 
            if (from.test('a')) {
75
 
                //Don't carry the A styles
76
 
                return;
77
 
            }
78
 
            var styles = ['color', 'fontSize', 'fontFamily', 'backgroundColor', 'fontStyle' ],
79
 
                newStyles = {};
80
 
 
81
 
            Y.each(styles, function(v) {
82
 
                newStyles[v] = from.getStyle(v);
83
 
            });
84
 
            if (from.ancestor('b,strong')) {
85
 
                newStyles.fontWeight = 'bold';
86
 
            }
87
 
            if (from.ancestor('u')) {
88
 
                if (!newStyles.textDecoration) {
89
 
                    newStyles.textDecoration = 'underline';
90
 
                }
91
 
            }
92
 
            to.setStyles(newStyles);
93
 
        },
94
 
        /**
95
 
        * Holder for the selection bookmark in IE.
96
 
        * @property _lastBookmark
97
 
        * @private
98
 
        */
99
 
        _lastBookmark: null,
100
 
        /**
101
 
        * Resolves the e.changedNode in the nodeChange event if it comes from the document. If
102
 
        * the event came from the document, it will get the last child of the last child of the document
103
 
        * and return that instead.
104
 
        * @method _resolveChangedNode
105
 
        * @param {Node} n The node to resolve
106
 
        * @private
107
 
        */
108
 
        _resolveChangedNode: function(n) {
109
 
            var inst = this.getInstance(), lc, lc2, found;
110
 
            if (inst && n && n.test('html')) {
111
 
                lc = inst.one(BODY).one(LAST_CHILD);
112
 
                while (!found) {
113
 
                    if (lc) {
114
 
                        lc2 = lc.one(LAST_CHILD);
115
 
                        if (lc2) {
116
 
                            lc = lc2;
117
 
                        } else {
118
 
                            found = true;
119
 
                        }
120
 
                    } else {
121
 
                        found = true;
122
 
                    }
123
 
                }
124
 
                if (lc) {
125
 
                    if (lc.test('br')) {
126
 
                        if (lc.previous()) {
127
 
                            lc = lc.previous();
128
 
                        } else {
129
 
                            lc = lc.get('parentNode');
130
 
                        }
131
 
                    }
132
 
                    if (lc) {
133
 
                        n = lc;
134
 
                    }
135
 
                }
136
 
            }
137
 
            if (!n) {
138
 
                //Fallback to make sure a node is attached to the event
139
 
                n = inst.one(BODY);
140
 
            }
141
 
            return n;
142
 
        },
143
 
        /**
144
 
        * The default handler for the nodeChange event.
145
 
        * @method _defNodeChangeFn
146
 
        * @param {Event} e The event
147
 
        * @private
148
 
        */
149
 
        _defNodeChangeFn: function(e) {
150
 
            var startTime = (new Date()).getTime();
151
 
            var inst = this.getInstance(), sel, cur,
152
 
                btag = inst.Selection.DEFAULT_BLOCK_TAG;
153
 
 
154
 
            if (Y.UA.ie) {
155
 
                try {
156
 
                    sel = inst.config.doc.selection.createRange();
157
 
                    if (sel.getBookmark) {
158
 
                        this._lastBookmark = sel.getBookmark();
159
 
                    }
160
 
                } catch (ie) {}
161
 
            }
162
 
 
163
 
            e.changedNode = this._resolveChangedNode(e.changedNode);
164
 
 
165
 
            /*
166
 
            * @TODO
167
 
            * This whole method needs to be fixed and made more dynamic.
168
 
            * Maybe static functions for the e.changeType and an object bag
169
 
            * to walk through and filter to pass off the event to before firing..
170
 
            */
171
 
            
172
 
            switch (e.changedType) {
173
 
                case 'keydown':
174
 
                    if (!Y.UA.gecko) {
175
 
                        if (!EditorBase.NC_KEYS[e.changedEvent.keyCode] && !e.changedEvent.shiftKey && !e.changedEvent.ctrlKey && (e.changedEvent.keyCode !== 13)) {
176
 
                            //inst.later(100, inst, inst.Selection.cleanCursor);
177
 
                        }
178
 
                    }
179
 
                    break;
180
 
                case 'tab':
181
 
                    if (!e.changedNode.test('li, li *') && !e.changedEvent.shiftKey) {
182
 
                        e.changedEvent.frameEvent.preventDefault();
183
 
                        if (Y.UA.webkit) {
184
 
                            this.execCommand('inserttext', '\t');
185
 
                        } else if (Y.UA.gecko) {
186
 
                            this.frame.exec._command('inserthtml', EditorBase.TABKEY);
187
 
                        } else if (Y.UA.ie) {
188
 
                            this.execCommand('inserthtml', EditorBase.TABKEY);
189
 
                        }
190
 
                    }
191
 
                    break;
192
 
                case 'backspace-up':
193
 
                    // Fixes #2531090 - Joins text node strings so they become one for bidi
194
 
                    if (Y.UA.webkit && e.changedNode) {
195
 
                                    e.changedNode.set('innerHTML', e.changedNode.get('innerHTML'));
196
 
                            }
197
 
                    break;
198
 
            }
199
 
            if (Y.UA.webkit && e.commands && (e.commands.indent || e.commands.outdent)) {
200
 
                /*
201
 
                * When executing execCommand 'indent or 'outdent' Webkit applies
202
 
                * a class to the BLOCKQUOTE that adds left/right margin to it
203
 
                * This strips that style so it is just a normal BLOCKQUOTE
204
 
                */
205
 
                var bq = inst.all('.webkit-indent-blockquote');
206
 
                if (bq.size()) {
207
 
                    bq.setStyle('margin', '');
208
 
                }
209
 
            }
210
 
 
211
 
            var changed = this.getDomPath(e.changedNode, false),
212
 
                cmds = {}, family, fsize, classes = [],
213
 
                fColor = '', bColor = '';
214
 
 
215
 
            if (e.commands) {
216
 
                cmds = e.commands;
217
 
            }
218
 
            
219
 
            var normal = false;
220
 
 
221
 
            Y.each(changed, function(el) {
222
 
                var tag = el.tagName.toLowerCase(),
223
 
                    cmd = EditorBase.TAG2CMD[tag];
224
 
 
225
 
                if (cmd) {
226
 
                    cmds[cmd] = 1;
227
 
                }
228
 
 
229
 
                //Bold and Italic styles
230
 
                var s = el.currentStyle || el.style;
231
 
                
232
 
                if ((''+s.fontWeight) == 'normal') {
233
 
                    normal = true;
234
 
                }
235
 
                if ((''+s.fontWeight) == 'bold') { //Cast this to a string
236
 
                    cmds.bold = 1;
237
 
                }
238
 
                if (Y.UA.ie) {
239
 
                    if (s.fontWeight > 400) {
240
 
                        cmds.bold = 1;
241
 
                    }
242
 
                }
243
 
                if (s.fontStyle == 'italic') {
244
 
                    cmds.italic = 1;
245
 
                }
246
 
 
247
 
                if (s.textDecoration == 'underline') {
248
 
                    cmds.underline = 1;
249
 
                }
250
 
                if (s.textDecoration == 'line-through') {
251
 
                    cmds.strikethrough = 1;
252
 
                }
253
 
                
254
 
                var n = inst.one(el);
255
 
                if (n.getStyle('fontFamily')) {
256
 
                    var family2 = n.getStyle('fontFamily').split(',')[0].toLowerCase();
257
 
                    if (family2) {
258
 
                        family = family2;
259
 
                    }
260
 
                    if (family) {
261
 
                        family = family.replace(/'/g, '').replace(/"/g, '');
262
 
                    }
263
 
                }
264
 
 
265
 
                fsize = EditorBase.NORMALIZE_FONTSIZE(n);
266
 
 
267
 
 
268
 
                var cls = el.className.split(' ');
269
 
 
270
 
                Y.each(cls, function(v) {
271
 
                    if (v !== '' && (v.substr(0, 4) !== 'yui_')) {
272
 
                        classes.push(v);
273
 
                    }
274
 
                });
275
 
 
276
 
                fColor = EditorBase.FILTER_RGB(n.getStyle('color'));
277
 
                var bColor2 = EditorBase.FILTER_RGB(s.backgroundColor);
278
 
                if (bColor2 !== 'transparent') {
279
 
                    if (bColor2 !== '') {
280
 
                        bColor = bColor2;
281
 
                    }
282
 
                }
283
 
                
284
 
            });
285
 
            
286
 
            if (normal) {
287
 
                delete cmds.bold;
288
 
                delete cmds.italic;
289
 
            }
290
 
 
291
 
            e.dompath = inst.all(changed);
292
 
            e.classNames = classes;
293
 
            e.commands = cmds;
294
 
 
295
 
            //TODO Dont' like this, not dynamic enough..
296
 
            if (!e.fontFamily) {
297
 
                e.fontFamily = family;
298
 
            }
299
 
            if (!e.fontSize) {
300
 
                e.fontSize = fsize;
301
 
            }
302
 
            if (!e.fontColor) {
303
 
                e.fontColor = fColor;
304
 
            }
305
 
            if (!e.backgroundColor) {
306
 
                e.backgroundColor = bColor;
307
 
            }
308
 
 
309
 
            var endTime = (new Date()).getTime();
310
 
        },
311
 
        /**
312
 
        * Walk the dom tree from this node up to body, returning a reversed array of parents.
313
 
        * @method getDomPath
314
 
        * @param {Node} node The Node to start from 
315
 
        */
316
 
        getDomPath: function(node, nodeList) {
317
 
                        var domPath = [], domNode,
318
 
                inst = this.frame.getInstance();
319
 
 
320
 
            domNode = inst.Node.getDOMNode(node);
321
 
            //return inst.all(domNode);
322
 
 
323
 
            while (domNode !== null) {
324
 
                
325
 
                if ((domNode === inst.config.doc.documentElement) || (domNode === inst.config.doc) || !domNode.tagName) {
326
 
                    domNode = null;
327
 
                    break;
328
 
                }
329
 
                
330
 
                if (!inst.DOM.inDoc(domNode)) {
331
 
                    domNode = null;
332
 
                    break;
333
 
                }
334
 
                
335
 
                //Check to see if we get el.nodeName and nodeType
336
 
                if (domNode.nodeName && domNode.nodeType && (domNode.nodeType == 1)) {
337
 
                    domPath.push(domNode);
338
 
                }
339
 
 
340
 
                if (domNode == inst.config.doc.body) {
341
 
                    domNode = null;
342
 
                    break;
343
 
                }
344
 
 
345
 
                domNode = domNode.parentNode;
346
 
            }
347
 
 
348
 
            /*{{{ Using Node 
349
 
            while (node !== null) {
350
 
                if (node.test('html') || node.test('doc') || !node.get('tagName')) {
351
 
                    node = null;
352
 
                    break;
353
 
                }
354
 
                if (!node.inDoc()) {
355
 
                    node = null;
356
 
                    break;
357
 
                }
358
 
                //Check to see if we get el.nodeName and nodeType
359
 
                if (node.get('nodeName') && node.get('nodeType') && (node.get('nodeType') == 1)) {
360
 
                    domPath.push(inst.Node.getDOMNode(node));
361
 
                }
362
 
 
363
 
                if (node.test('body')) {
364
 
                    node = null;
365
 
                    break;
366
 
                }
367
 
 
368
 
                node = node.get('parentNode');
369
 
            }
370
 
            }}}*/
371
 
 
372
 
            if (domPath.length === 0) {
373
 
                domPath[0] = inst.config.doc.body;
374
 
            }
375
 
 
376
 
            if (nodeList) {
377
 
                return inst.all(domPath.reverse());
378
 
            } else {
379
 
                return domPath.reverse();
380
 
            }
381
 
 
382
 
        },
383
 
        /**
384
 
        * After frame ready, bind mousedown & keyup listeners
385
 
        * @method _afterFrameReady
386
 
        * @private
387
 
        */
388
 
        _afterFrameReady: function() {
389
 
            var inst = this.frame.getInstance();
390
 
            
391
 
            this.frame.on('dom:mouseup', Y.bind(this._onFrameMouseUp, this));
392
 
            this.frame.on('dom:mousedown', Y.bind(this._onFrameMouseDown, this));
393
 
            this.frame.on('dom:keydown', Y.bind(this._onFrameKeyDown, this));
394
 
 
395
 
            if (Y.UA.ie) {
396
 
                this.frame.on('dom:activate', Y.bind(this._onFrameActivate, this));
397
 
                this.frame.on('dom:beforedeactivate', Y.bind(this._beforeFrameDeactivate, this));
398
 
            }
399
 
            this.frame.on('dom:keyup', Y.bind(this._onFrameKeyUp, this));
400
 
            this.frame.on('dom:keypress', Y.bind(this._onFrameKeyPress, this));
401
 
            this.frame.on('dom:paste', Y.bind(this._onPaste, this));
402
 
 
403
 
            inst.Selection.filter();
404
 
            this.fire('ready');
405
 
        },
406
 
        /**
407
 
        * Caches the current cursor position in IE.
408
 
        * @method _beforeFrameDeactivate
409
 
        * @private
410
 
        */
411
 
        _beforeFrameDeactivate: function(e) {
412
 
            if (e.frameTarget.test('html')) { //Means it came from a scrollbar
413
 
                return;
414
 
            }
415
 
            var inst = this.getInstance(),
416
 
                sel = inst.config.doc.selection.createRange();
417
 
            
418
 
            if (sel.compareEndPoints && !sel.compareEndPoints('StartToEnd', sel)) {
419
 
                sel.pasteHTML('<var id="yui-ie-cursor">');
420
 
            }
421
 
        },
422
 
        /**
423
 
        * Moves the cached selection bookmark back so IE can place the cursor in the right place.
424
 
        * @method _onFrameActivate
425
 
        * @private
426
 
        */
427
 
        _onFrameActivate: function(e) {
428
 
            if (e.frameTarget.test('html')) { //Means it came from a scrollbar
429
 
                return;
430
 
            }
431
 
            var inst = this.getInstance(),
432
 
                sel = new inst.Selection(),
433
 
                range = sel.createRange(),
434
 
                cur = inst.all('#yui-ie-cursor');
435
 
 
436
 
            if (cur.size()) {
437
 
                cur.each(function(n) {
438
 
                    n.set('id', '');
439
 
                    if (range.moveToElementText) {
440
 
                        try {
441
 
                            range.moveToElementText(n._node);
442
 
                            var moved = range.move('character', -1);
443
 
                            if (moved === -1) { //Only move up if we actually moved back.
444
 
                                range.move('character', 1);
445
 
                            }
446
 
                            range.select();
447
 
                            range.text = '';
448
 
                        } catch (e) {}
449
 
                    }
450
 
                    n.remove();
451
 
                });
452
 
            }
453
 
        },
454
 
        /**
455
 
        * Fires nodeChange event
456
 
        * @method _onPaste
457
 
        * @private
458
 
        */
459
 
        _onPaste: function(e) {
460
 
            this.fire('nodeChange', { changedNode: e.frameTarget, changedType: 'paste', changedEvent: e.frameEvent });
461
 
        },
462
 
        /**
463
 
        * Fires nodeChange event
464
 
        * @method _onFrameMouseUp
465
 
        * @private
466
 
        */
467
 
        _onFrameMouseUp: function(e) {
468
 
            this.fire('nodeChange', { changedNode: e.frameTarget, changedType: 'mouseup', changedEvent: e.frameEvent  });
469
 
        },
470
 
        /**
471
 
        * Fires nodeChange event
472
 
        * @method _onFrameMouseDown
473
 
        * @private
474
 
        */
475
 
        _onFrameMouseDown: function(e) {
476
 
            this.fire('nodeChange', { changedNode: e.frameTarget, changedType: 'mousedown', changedEvent: e.frameEvent  });
477
 
        },
478
 
        /**
479
 
        * Caches a copy of the selection for key events. Only creating the selection on keydown
480
 
        * @property _currentSelection
481
 
        * @private
482
 
        */
483
 
        _currentSelection: null,
484
 
        /**
485
 
        * Holds the timer for selection clearing
486
 
        * @property _currentSelectionTimer
487
 
        * @private
488
 
        */
489
 
        _currentSelectionTimer: null,
490
 
        /**
491
 
        * Flag to determine if we can clear the selection or not.
492
 
        * @property _currentSelectionClear
493
 
        * @private
494
 
        */
495
 
        _currentSelectionClear: null,
496
 
        /**
497
 
        * Fires nodeChange event
498
 
        * @method _onFrameKeyDown
499
 
        * @private
500
 
        */
501
 
        _onFrameKeyDown: function(e) {
502
 
            var inst, sel;
503
 
            if (!this._currentSelection) {
504
 
                if (this._currentSelectionTimer) {
505
 
                    this._currentSelectionTimer.cancel();
506
 
                }
507
 
                this._currentSelectionTimer = Y.later(850, this, function() {
508
 
                    this._currentSelectionClear = true;
509
 
                });
510
 
                
511
 
                inst = this.frame.getInstance();
512
 
                sel = new inst.Selection(e);
513
 
 
514
 
                this._currentSelection = sel;
515
 
            } else {
516
 
                sel = this._currentSelection;
517
 
            }
518
 
 
519
 
            inst = this.frame.getInstance();
520
 
            sel = new inst.Selection();
521
 
 
522
 
            this._currentSelection = sel;
523
 
            
524
 
            if (sel && sel.anchorNode) {
525
 
                this.fire('nodeChange', { changedNode: sel.anchorNode, changedType: 'keydown', changedEvent: e.frameEvent });
526
 
                if (EditorBase.NC_KEYS[e.keyCode]) {
527
 
                    this.fire('nodeChange', { changedNode: sel.anchorNode, changedType: EditorBase.NC_KEYS[e.keyCode], changedEvent: e.frameEvent });
528
 
                    this.fire('nodeChange', { changedNode: sel.anchorNode, changedType: EditorBase.NC_KEYS[e.keyCode] + '-down', changedEvent: e.frameEvent });
529
 
                }
530
 
            }
531
 
        },
532
 
        /**
533
 
        * Fires nodeChange event
534
 
        * @method _onFrameKeyPress
535
 
        * @private
536
 
        */
537
 
        _onFrameKeyPress: function(e) {
538
 
            var sel = this._currentSelection;
539
 
 
540
 
            if (sel && sel.anchorNode) {
541
 
                this.fire('nodeChange', { changedNode: sel.anchorNode, changedType: 'keypress', changedEvent: e.frameEvent });
542
 
                if (EditorBase.NC_KEYS[e.keyCode]) {
543
 
                    this.fire('nodeChange', { changedNode: sel.anchorNode, changedType: EditorBase.NC_KEYS[e.keyCode] + '-press', changedEvent: e.frameEvent });
544
 
                }
545
 
            }
546
 
        },
547
 
        /**
548
 
        * Fires nodeChange event for keyup on specific keys
549
 
        * @method _onFrameKeyUp
550
 
        * @private
551
 
        */
552
 
        _onFrameKeyUp: function(e) {
553
 
            var inst = this.frame.getInstance(),
554
 
                sel = new inst.Selection(e);
555
 
 
556
 
            if (sel && sel.anchorNode) {
557
 
                this.fire('nodeChange', { changedNode: sel.anchorNode, changedType: 'keyup', selection: sel, changedEvent: e.frameEvent  });
558
 
                if (EditorBase.NC_KEYS[e.keyCode]) {
559
 
                    this.fire('nodeChange', { changedNode: sel.anchorNode, changedType: EditorBase.NC_KEYS[e.keyCode] + '-up', selection: sel, changedEvent: e.frameEvent  });
560
 
                }
561
 
            }
562
 
            if (this._currentSelectionClear) {
563
 
                this._currentSelectionClear = this._currentSelection = null;
564
 
            }
565
 
        },
566
 
        /**
567
 
        * Pass through to the frame.execCommand method
568
 
        * @method execCommand
569
 
        * @param {String} cmd The command to pass: inserthtml, insertimage, bold
570
 
        * @param {String} val The optional value of the command: Helvetica
571
 
        * @return {Node/NodeList} The Node or Nodelist affected by the command. Only returns on override commands, not browser defined commands.
572
 
        */
573
 
        execCommand: function(cmd, val) {
574
 
            var ret = this.frame.execCommand(cmd, val),
575
 
                inst = this.frame.getInstance(),
576
 
                sel = new inst.Selection(), cmds = {},
577
 
                e = { changedNode: sel.anchorNode, changedType: 'execcommand', nodes: ret };
578
 
 
579
 
            switch (cmd) {
580
 
                case 'forecolor':
581
 
                    e.fontColor = val;
582
 
                    break;
583
 
                case 'backcolor':
584
 
                    e.backgroundColor = val;
585
 
                    break;
586
 
                case 'fontsize':
587
 
                    e.fontSize = val;
588
 
                    break;
589
 
                case 'fontname':
590
 
                    e.fontFamily = val;
591
 
                    break;
592
 
            }
593
 
 
594
 
            cmds[cmd] = 1;
595
 
            e.commands = cmds;
596
 
 
597
 
            this.fire('nodeChange', e);
598
 
 
599
 
            return ret;
600
 
        },
601
 
        /**
602
 
        * Get the YUI instance of the frame
603
 
        * @method getInstance
604
 
        * @return {YUI} The YUI instance bound to the frame.
605
 
        */
606
 
        getInstance: function() {
607
 
            return this.frame.getInstance();
608
 
        },
609
 
        /**
610
 
        * Renders the Y.Frame to the passed node.
611
 
        * @method render
612
 
        * @param {Selector/HTMLElement/Node} node The node to append the Editor to
613
 
        * @return {EditorBase}
614
 
        * @chainable
615
 
        */
616
 
        render: function(node) {
617
 
            this.frame.set('content', this.get('content'));
618
 
            this.frame.render(node);
619
 
            return this;
620
 
        },
621
 
        /**
622
 
        * Focus the contentWindow of the iframe
623
 
        * @method focus
624
 
        * @param {Function} fn Callback function to execute after focus happens
625
 
        * @return {EditorBase}
626
 
        * @chainable
627
 
        */
628
 
        focus: function(fn) {
629
 
            this.frame.focus(fn);
630
 
            return this;
631
 
        },
632
 
        /**
633
 
        * Handles the showing of the Editor instance. Currently only handles the iframe
634
 
        * @method show
635
 
        * @return {EditorBase}
636
 
        * @chainable
637
 
        */
638
 
        show: function() {
639
 
            this.frame.show();
640
 
            return this;
641
 
        },
642
 
        /**
643
 
        * Handles the hiding of the Editor instance. Currently only handles the iframe
644
 
        * @method hide
645
 
        * @return {EditorBase}
646
 
        * @chainable
647
 
        */
648
 
        hide: function() {
649
 
            this.frame.hide();
650
 
            return this;
651
 
        },
652
 
        /**
653
 
        * (Un)Filters the content of the Editor, cleaning YUI related code. //TODO better filtering
654
 
        * @method getContent
655
 
        * @return {String} The filtered content of the Editor
656
 
        */
657
 
        getContent: function() {
658
 
            var html = '', inst = this.getInstance();
659
 
            if (inst && inst.Selection) {
660
 
                html = inst.Selection.unfilter();
661
 
            }
662
 
            //Removing the _yuid from the objects in IE
663
 
            html = html.replace(/ _yuid="([^>]*)"/g, '');
664
 
            return html;
665
 
        }
666
 
    }, {
667
 
        /**
668
 
        * @static
669
 
        * @method NORMALIZE_FONTSIZE
670
 
        * @description Pulls the fontSize from a node, then checks for string values (x-large, x-small)
671
 
        * and converts them to pixel sizes. If the parsed size is different from the original, it calls
672
 
        * node.setStyle to update the node with a pixel size for normalization.
673
 
        */
674
 
        NORMALIZE_FONTSIZE: function(n) {
675
 
            var size = n.getStyle('fontSize'), oSize = size;
676
 
            
677
 
            switch (size) {
678
 
                case '-webkit-xxx-large':
679
 
                    size = '48px';
680
 
                    break;
681
 
                case 'xx-large':
682
 
                    size = '32px';
683
 
                    break;
684
 
                case 'x-large':
685
 
                    size = '24px';
686
 
                    break;
687
 
                case 'large':
688
 
                    size = '18px';
689
 
                    break;
690
 
                case 'medium':
691
 
                    size = '16px';
692
 
                    break;
693
 
                case 'small':
694
 
                    size = '13px';
695
 
                    break;
696
 
                case 'x-small':
697
 
                    size = '10px';
698
 
                    break;
699
 
            }
700
 
            if (oSize !== size) {
701
 
                n.setStyle('fontSize', size);
702
 
            }
703
 
            return size;
704
 
        },
705
 
        /**
706
 
        * @static
707
 
        * @property TABKEY
708
 
        * @description The HTML markup to use for the tabkey
709
 
        */
710
 
        TABKEY: '<span class="tab">&nbsp;&nbsp;&nbsp;&nbsp;</span>',
711
 
        /**
712
 
        * @static
713
 
        * @method FILTER_RGB
714
 
        * @param String css The CSS string containing rgb(#,#,#);
715
 
        * @description Converts an RGB color string to a hex color, example: rgb(0, 255, 0) converts to #00ff00
716
 
        * @return String
717
 
        */
718
 
        FILTER_RGB: function(css) {
719
 
            if (css.toLowerCase().indexOf('rgb') != -1) {
720
 
                var exp = new RegExp("(.*?)rgb\\s*?\\(\\s*?([0-9]+).*?,\\s*?([0-9]+).*?,\\s*?([0-9]+).*?\\)(.*?)", "gi");
721
 
                var rgb = css.replace(exp, "$1,$2,$3,$4,$5").split(',');
722
 
            
723
 
                if (rgb.length == 5) {
724
 
                    var r = parseInt(rgb[1], 10).toString(16);
725
 
                    var g = parseInt(rgb[2], 10).toString(16);
726
 
                    var b = parseInt(rgb[3], 10).toString(16);
727
 
 
728
 
                    r = r.length == 1 ? '0' + r : r;
729
 
                    g = g.length == 1 ? '0' + g : g;
730
 
                    b = b.length == 1 ? '0' + b : b;
731
 
 
732
 
                    css = "#" + r + g + b;
733
 
                }
734
 
            }
735
 
            return css;
736
 
        },        
737
 
        /**
738
 
        * @static
739
 
        * @property TAG2CMD
740
 
        * @description A hash table of tags to their execcomand's
741
 
        */
742
 
        TAG2CMD: {
743
 
            'b': 'bold',
744
 
            'strong': 'bold',
745
 
            'i': 'italic',
746
 
            'em': 'italic',
747
 
            'u': 'underline',
748
 
            'sup': 'superscript',
749
 
            'sub': 'subscript',
750
 
            'img': 'insertimage',
751
 
            'a' : 'createlink',
752
 
            'ul' : 'insertunorderedlist',
753
 
            'ol' : 'insertorderedlist'
754
 
        },
755
 
        /**
756
 
        * Hash table of keys to fire a nodeChange event for.
757
 
        * @static
758
 
        * @property NC_KEYS
759
 
        * @type Object
760
 
        */
761
 
        NC_KEYS: {
762
 
            8: 'backspace',
763
 
            9: 'tab',
764
 
            13: 'enter',
765
 
            32: 'space',
766
 
            33: 'pageup',
767
 
            34: 'pagedown',
768
 
            35: 'end',
769
 
            36: 'home',
770
 
            37: 'left',
771
 
            38: 'up',
772
 
            39: 'right',
773
 
            40: 'down',
774
 
            46: 'delete'
775
 
        },
776
 
        /**
777
 
        * The default modules to use inside the Frame
778
 
        * @static
779
 
        * @property USE
780
 
        * @type Array
781
 
        */
782
 
        USE: ['substitute', 'node', 'selector-css3', 'selection', 'stylesheet'],
783
 
        /**
784
 
        * The Class Name: editorBase
785
 
        * @static
786
 
        * @property NAME
787
 
        */
788
 
        NAME: 'editorBase',
789
 
        /**
790
 
        * Editor Strings.  By default contains only the `title` property for the
791
 
        * Title of frame document (default "Rich Text Editor").
792
 
        *
793
 
        * @static
794
 
        * @property STRINGS
795
 
        */
796
 
        STRINGS: {
797
 
            title: 'Rich Text Editor'
798
 
        },
799
 
        ATTRS: {
800
 
            /**
801
 
            * The content to load into the Editor Frame
802
 
            * @attribute content
803
 
            */
804
 
            content: {
805
 
                value: '<br class="yui-cursor">',
806
 
                setter: function(str) {
807
 
                    if (str.substr(0, 1) === "\n") {
808
 
                        str = str.substr(1);
809
 
                    }
810
 
                    if (str === '') {
811
 
                        str = '<br class="yui-cursor">';
812
 
                    }
813
 
                    if (str === ' ') {
814
 
                        if (Y.UA.gecko) {
815
 
                            str = '<br class="yui-cursor">';
816
 
                        }
817
 
                    }
818
 
                    return this.frame.set('content', str);
819
 
                },
820
 
                getter: function() {
821
 
                    return this.frame.get('content');
822
 
                }
823
 
            },
824
 
            /**
825
 
            * The value of the dir attribute on the HTML element of the frame. Default: ltr
826
 
            * @attribute dir
827
 
            */
828
 
            dir: {
829
 
                writeOnce: true,
830
 
                value: 'ltr'
831
 
            },
832
 
            /**
833
 
            * @attribute linkedcss
834
 
            * @description An array of url's to external linked style sheets
835
 
            * @type String
836
 
            */            
837
 
            linkedcss: {
838
 
                value: '',
839
 
                setter: function(css) {
840
 
                    if (this.frame) {
841
 
                        this.frame.set('linkedcss', css);
842
 
                    }
843
 
                    return css;
844
 
                }
845
 
            },
846
 
            /**
847
 
            * @attribute extracss
848
 
            * @description A string of CSS to add to the Head of the Editor
849
 
            * @type String
850
 
            */            
851
 
            extracss: {
852
 
                value: false,
853
 
                setter: function(css) {
854
 
                    if (this.frame) {
855
 
                        this.frame.set('extracss', css);
856
 
                    }
857
 
                    return css;
858
 
                }
859
 
            },
860
 
            /**
861
 
            * @attribute defaultblock
862
 
            * @description The default tag to use for block level items, defaults to: p
863
 
            * @type String
864
 
            */            
865
 
            defaultblock: {
866
 
                value: 'p'
867
 
            }
868
 
        }
869
 
    });
870
 
 
871
 
    Y.EditorBase = EditorBase;
872
 
 
873
 
    /**
874
 
    * @event nodeChange
875
 
    * @description Fired from several mouse/key/paste event points.
876
 
    * @param {Event.Facade} event An Event Facade object with the following specific properties added:
877
 
    * <dl>
878
 
    *   <dt>changedEvent</dt><dd>The event that caused the nodeChange</dd>
879
 
    *   <dt>changedNode</dt><dd>The node that was interacted with</dd>
880
 
    *   <dt>changedType</dt><dd>The type of change: mousedown, mouseup, right, left, backspace, tab, enter, etc..</dd>
881
 
    *   <dt>commands</dt><dd>The list of execCommands that belong to this change and the dompath that's associated with the changedNode</dd>
882
 
    *   <dt>classNames</dt><dd>An array of classNames that are applied to the changedNode and all of it's parents</dd>
883
 
    *   <dt>dompath</dt><dd>A sorted array of node instances that make up the DOM path from the changedNode to body.</dd>
884
 
    *   <dt>backgroundColor</dt><dd>The cascaded backgroundColor of the changedNode</dd>
885
 
    *   <dt>fontColor</dt><dd>The cascaded fontColor of the changedNode</dd>
886
 
    *   <dt>fontFamily</dt><dd>The cascaded fontFamily of the changedNode</dd>
887
 
    *   <dt>fontSize</dt><dd>The cascaded fontSize of the changedNode</dd>
888
 
    * </dl>
889
 
    * @type {Event.Custom}
890
 
    */
891
 
 
892
 
    /**
893
 
    * @event ready
894
 
    * @description Fired after the frame is ready.
895
 
    * @param {Event.Facade} event An Event Facade object.
896
 
    * @type {Event.Custom}
897
 
    */
898
 
 
899
 
 
900
 
 
901
 
 
902
 
 
903
 
}, '3.4.1' ,{skinnable:false, requires:['base', 'frame', 'node', 'exec-command', 'selection']});