~ubuntu-branches/ubuntu/utopic/moodle/utopic

« back to all changes in this revision

Viewing changes to lib/yuilib/3.9.1/build/editor-base/editor-base-debug.js

  • Committer: Package Import Robot
  • Author(s): Thijs Kinkhorst
  • Date: 2014-05-12 16:10:38 UTC
  • mfrom: (36.1.3 sid)
  • Revision ID: package-import@ubuntu.com-20140512161038-puyqf65k4e0s8ytz
Tags: 2.6.3-1
New upstream release.

Show diffs side-by-side

added added

removed removed

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