~michael.nelson/ubuntu-webcatalog/1267731-import-sca-apps-error

« back to all changes in this revision

Viewing changes to src/webcatalog/static/yui/3.10.3/build/exec-command/exec-command-debug.js

  • Committer: Tarmac
  • Author(s): Stephen Stewart
  • Date: 2013-06-26 09:19:32 UTC
  • mfrom: (184.1.4 ubuntu-global-nav)
  • Revision ID: tarmac-20130626091932-8urtuli368k8p7ds
[r=beuno,jonas-drange] add ubuntu global nav to apps.ubuntu.com

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
YUI 3.10.3 (build 2fb5187)
 
3
Copyright 2013 Yahoo! Inc. All rights reserved.
 
4
Licensed under the BSD License.
 
5
http://yuilibrary.com/license/
 
6
*/
 
7
 
 
8
YUI.add('exec-command', function (Y, NAME) {
 
9
 
 
10
 
 
11
    /**
 
12
     * Plugin for the frame module to handle execCommands for Editor
 
13
     * @class Plugin.ExecCommand
 
14
     * @extends Base
 
15
     * @constructor
 
16
     * @module editor
 
17
     * @submodule exec-command
 
18
     */
 
19
        var ExecCommand = function() {
 
20
            ExecCommand.superclass.constructor.apply(this, arguments);
 
21
        },
 
22
        /**
 
23
        * This method is meant to normalize IE's in ability to exec the proper command on elements with CSS styling.
 
24
        * @method fixIETags
 
25
        * @protected
 
26
        * @param {String} cmd The command to execute
 
27
        * @param {String} tag The tag to create
 
28
        * @param {String} rule The rule that we are looking for.
 
29
        */
 
30
        fixIETags = function(cmd, tag, rule) {
 
31
            var inst = this.getInstance(),
 
32
                doc = inst.config.doc,
 
33
                sel = doc.selection.createRange(),
 
34
                o = doc.queryCommandValue(cmd),
 
35
                html, reg, m, p, d, s, c;
 
36
 
 
37
            if (o) {
 
38
                html = sel.htmlText;
 
39
                reg = new RegExp(rule, 'g');
 
40
                m = html.match(reg);
 
41
 
 
42
                if (m) {
 
43
                    html = html.replace(rule + ';', '').replace(rule, '');
 
44
 
 
45
                    sel.pasteHTML('<var id="yui-ie-bs">');
 
46
 
 
47
                    p = doc.getElementById('yui-ie-bs');
 
48
                    d = doc.createElement('div');
 
49
                    s = doc.createElement(tag);
 
50
 
 
51
                    d.innerHTML = html;
 
52
                    if (p.parentNode !== inst.config.doc.body) {
 
53
                        p = p.parentNode;
 
54
                    }
 
55
 
 
56
                    c = d.childNodes;
 
57
 
 
58
                    p.parentNode.replaceChild(s, p);
 
59
 
 
60
                    Y.each(c, function(f) {
 
61
                        s.appendChild(f);
 
62
                    });
 
63
                    sel.collapse();
 
64
                    if (sel.moveToElementText) {
 
65
                        sel.moveToElementText(s);
 
66
                    }
 
67
                    sel.select();
 
68
                }
 
69
            }
 
70
            this._command(cmd);
 
71
        };
 
72
 
 
73
        Y.extend(ExecCommand, Y.Base, {
 
74
            /**
 
75
            * An internal reference to the keyCode of the last key that was pressed.
 
76
            * @private
 
77
            * @property _lastKey
 
78
            */
 
79
            _lastKey: null,
 
80
            /**
 
81
            * An internal reference to the instance of the frame plugged into.
 
82
            * @private
 
83
            * @property _inst
 
84
            */
 
85
            _inst: null,
 
86
            /**
 
87
            * Execute a command on the frame's document.
 
88
            * @method command
 
89
            * @param {String} action The action to perform (bold, italic, fontname)
 
90
            * @param {String} value The optional value (helvetica)
 
91
            * @return {Node/NodeList} Should return the Node/Nodelist affected
 
92
            */
 
93
            command: function(action, value) {
 
94
                var fn = ExecCommand.COMMANDS[action];
 
95
 
 
96
                Y.log('execCommand(' + action + '): "' + value + '"', 'info', 'exec-command');
 
97
                if (fn) {
 
98
                    Y.log('OVERIDE execCommand(' + action + '): "' + value + '"', 'info', 'exec-command');
 
99
                    return fn.call(this, action, value);
 
100
                } else {
 
101
                    return this._command(action, value);
 
102
                }
 
103
            },
 
104
            /**
 
105
            * The private version of execCommand that doesn't filter for overrides.
 
106
            * @private
 
107
            * @method _command
 
108
            * @param {String} action The action to perform (bold, italic, fontname)
 
109
            * @param {String} value The optional value (helvetica)
 
110
            */
 
111
            _command: function(action, value) {
 
112
                var inst = this.getInstance();
 
113
                try {
 
114
                    try {
 
115
                        inst.config.doc.execCommand('styleWithCSS', null, 1);
 
116
                    } catch (e1) {
 
117
                        try {
 
118
                            inst.config.doc.execCommand('useCSS', null, 0);
 
119
                        } catch (e2) {
 
120
                        }
 
121
                    }
 
122
                    Y.log('Using default browser execCommand(' + action + '): "' + value + '"', 'info', 'exec-command');
 
123
                    inst.config.doc.execCommand(action, null, value);
 
124
                } catch (e) {
 
125
                    Y.log(e.message, 'warn', 'exec-command');
 
126
                }
 
127
            },
 
128
            /**
 
129
            * Get's the instance of YUI bound to the parent frame
 
130
            * @method getInstance
 
131
            * @return {YUI} The YUI instance bound to the parent frame
 
132
            */
 
133
            getInstance: function() {
 
134
                if (!this._inst) {
 
135
                    this._inst = this.get('host').getInstance();
 
136
                }
 
137
                return this._inst;
 
138
            },
 
139
            initializer: function() {
 
140
                Y.mix(this.get('host'), {
 
141
                    execCommand: function(action, value) {
 
142
                        return this.exec.command(action, value);
 
143
                    },
 
144
                    _execCommand: function(action, value) {
 
145
                        return this.exec._command(action, value);
 
146
                    }
 
147
                });
 
148
 
 
149
                this.get('host').on('dom:keypress', Y.bind(function(e) {
 
150
                    this._lastKey = e.keyCode;
 
151
                }, this));
 
152
            },
 
153
            _wrapContent: function(str, override) {
 
154
                var useP = (this.getInstance().host.editorPara && !override ? true : false);
 
155
 
 
156
                if (useP) {
 
157
                    str = '<p>' + str + '</p>';
 
158
                } else {
 
159
                    str = str + '<br>';
 
160
                }
 
161
                return str;
 
162
            }
 
163
        }, {
 
164
            /**
 
165
            * execCommand
 
166
            * @property NAME
 
167
            * @static
 
168
            */
 
169
            NAME: 'execCommand',
 
170
            /**
 
171
            * exec
 
172
            * @property NS
 
173
            * @static
 
174
            */
 
175
            NS: 'exec',
 
176
            ATTRS: {
 
177
                host: {
 
178
                    value: false
 
179
                }
 
180
            },
 
181
            /**
 
182
            * Static object literal of execCommand overrides
 
183
            * @property COMMANDS
 
184
            * @static
 
185
            */
 
186
            COMMANDS: {
 
187
                /**
 
188
                * Wraps the content with a new element of type (tag)
 
189
                * @method COMMANDS.wrap
 
190
                * @static
 
191
                * @param {String} cmd The command executed: wrap
 
192
                * @param {String} tag The tag to wrap the selection with
 
193
                * @return {NodeList} NodeList of the items touched by this command.
 
194
                */
 
195
                wrap: function(cmd, tag) {
 
196
                    var inst = this.getInstance();
 
197
                    return (new inst.EditorSelection()).wrapContent(tag);
 
198
                },
 
199
                /**
 
200
                * Inserts the provided HTML at the cursor, should be a single element.
 
201
                * @method COMMANDS.inserthtml
 
202
                * @static
 
203
                * @param {String} cmd The command executed: inserthtml
 
204
                * @param {String} html The html to insert
 
205
                * @return {Node} Node instance of the item touched by this command.
 
206
                */
 
207
                inserthtml: function(cmd, html) {
 
208
                    var inst = this.getInstance();
 
209
                    if (inst.EditorSelection.hasCursor() || Y.UA.ie) {
 
210
                        return (new inst.EditorSelection()).insertContent(html);
 
211
                    } else {
 
212
                        this._command('inserthtml', html);
 
213
                    }
 
214
                },
 
215
                /**
 
216
                * Inserts the provided HTML at the cursor, and focuses the cursor afterwards.
 
217
                * @method COMMANDS.insertandfocus
 
218
                * @static
 
219
                * @param {String} cmd The command executed: insertandfocus
 
220
                * @param {String} html The html to insert
 
221
                * @return {Node} Node instance of the item touched by this command.
 
222
                */
 
223
                insertandfocus: function(cmd, html) {
 
224
                    var inst = this.getInstance(), out, sel;
 
225
                    if (inst.EditorSelection.hasCursor()) {
 
226
                        html += inst.EditorSelection.CURSOR;
 
227
                        out = this.command('inserthtml', html);
 
228
                        sel = new inst.EditorSelection();
 
229
                        sel.focusCursor(true, true);
 
230
                    } else {
 
231
                        this.command('inserthtml', html);
 
232
                    }
 
233
                    return out;
 
234
                },
 
235
                /**
 
236
                * Inserts a BR at the current cursor position
 
237
                * @method COMMANDS.insertbr
 
238
                * @static
 
239
                * @param {String} cmd The command executed: insertbr
 
240
                */
 
241
                insertbr: function() {
 
242
                    var inst = this.getInstance(),
 
243
                        sel = new inst.EditorSelection(),
 
244
                        html = '<var>|</var>', last = null,
 
245
                        q = (Y.UA.webkit) ? 'span.Apple-style-span,var' : 'var',
 
246
                        insert = function(n) {
 
247
                            var c = inst.Node.create('<br>');
 
248
                            n.insert(c, 'before');
 
249
                            return c;
 
250
                        };
 
251
 
 
252
                    if (sel._selection.pasteHTML) {
 
253
                        sel._selection.pasteHTML(html);
 
254
                    } else {
 
255
                        this._command('inserthtml', html);
 
256
                    }
 
257
 
 
258
 
 
259
                    inst.all(q).each(function(n) {
 
260
                        var g = true, s;
 
261
                        if (Y.UA.webkit) {
 
262
                            g = false;
 
263
                            if (n.get('innerHTML') === '|') {
 
264
                                g = true;
 
265
                            }
 
266
                        }
 
267
                        if (g) {
 
268
                            last = insert(n);
 
269
                            if ((!last.previous() || !last.previous().test('br')) && Y.UA.gecko) {
 
270
                                s = last.cloneNode();
 
271
                                last.insert(s, 'after');
 
272
                                last = s;
 
273
                            }
 
274
                            n.remove();
 
275
                        }
 
276
                    });
 
277
                    if (Y.UA.webkit && last) {
 
278
                        insert(last);
 
279
                        sel.selectNode(last);
 
280
                    }
 
281
                },
 
282
                /**
 
283
                * Inserts an image at the cursor position
 
284
                * @method COMMANDS.insertimage
 
285
                * @static
 
286
                * @param {String} cmd The command executed: insertimage
 
287
                * @param {String} img The url of the image to be inserted
 
288
                * @return {Node} Node instance of the item touched by this command.
 
289
                */
 
290
                insertimage: function(cmd, img) {
 
291
                    return this.command('inserthtml', '<img src="' + img + '">');
 
292
                },
 
293
                /**
 
294
                * Add a class to all of the elements in the selection
 
295
                * @method COMMANDS.addclass
 
296
                * @static
 
297
                * @param {String} cmd The command executed: addclass
 
298
                * @param {String} cls The className to add
 
299
                * @return {NodeList} NodeList of the items touched by this command.
 
300
                */
 
301
                addclass: function(cmd, cls) {
 
302
                    var inst = this.getInstance();
 
303
                    return (new inst.EditorSelection()).getSelected().addClass(cls);
 
304
                },
 
305
                /**
 
306
                * Remove a class from all of the elements in the selection
 
307
                * @method COMMANDS.removeclass
 
308
                * @static
 
309
                * @param {String} cmd The command executed: removeclass
 
310
                * @param {String} cls The className to remove
 
311
                * @return {NodeList} NodeList of the items touched by this command.
 
312
                */
 
313
                removeclass: function(cmd, cls) {
 
314
                    var inst = this.getInstance();
 
315
                    return (new inst.EditorSelection()).getSelected().removeClass(cls);
 
316
                },
 
317
                /**
 
318
                * Adds a forecolor to the current selection, or creates a new element and applies it
 
319
                * @method COMMANDS.forecolor
 
320
                * @static
 
321
                * @param {String} cmd The command executed: forecolor
 
322
                * @param {String} val The color value to apply
 
323
                * @return {NodeList} NodeList of the items touched by this command.
 
324
                */
 
325
                forecolor: function(cmd, val) {
 
326
                    var inst = this.getInstance(),
 
327
                        sel = new inst.EditorSelection(), n;
 
328
 
 
329
                    if (!Y.UA.ie) {
 
330
                        this._command('useCSS', false);
 
331
                    }
 
332
                    if (inst.EditorSelection.hasCursor()) {
 
333
                        if (sel.isCollapsed) {
 
334
                            if (sel.anchorNode && (sel.anchorNode.get('innerHTML') === '&nbsp;')) {
 
335
                                sel.anchorNode.setStyle('color', val);
 
336
                                n = sel.anchorNode;
 
337
                            } else {
 
338
                                n = this.command('inserthtml', '<span style="color: ' + val + '">' + inst.EditorSelection.CURSOR + '</span>');
 
339
                                sel.focusCursor(true, true);
 
340
                            }
 
341
                            return n;
 
342
                        } else {
 
343
                            return this._command(cmd, val);
 
344
                        }
 
345
                    } else {
 
346
                        this._command(cmd, val);
 
347
                    }
 
348
                },
 
349
                /**
 
350
                * Adds a background color to the current selection, or creates a new element and applies it
 
351
                * @method COMMANDS.backcolor
 
352
                * @static
 
353
                * @param {String} cmd The command executed: backcolor
 
354
                * @param {String} val The color value to apply
 
355
                * @return {NodeList} NodeList of the items touched by this command.
 
356
                */
 
357
                backcolor: function(cmd, val) {
 
358
                    var inst = this.getInstance(),
 
359
                        sel = new inst.EditorSelection(), n;
 
360
 
 
361
                    if (Y.UA.gecko || Y.UA.opera) {
 
362
                        cmd = 'hilitecolor';
 
363
                    }
 
364
                    if (!Y.UA.ie) {
 
365
                        this._command('useCSS', false);
 
366
                    }
 
367
                    if (inst.EditorSelection.hasCursor()) {
 
368
                        if (sel.isCollapsed) {
 
369
                            if (sel.anchorNode && (sel.anchorNode.get('innerHTML') === '&nbsp;')) {
 
370
                                sel.anchorNode.setStyle('backgroundColor', val);
 
371
                                n = sel.anchorNode;
 
372
                            } else {
 
373
                                n = this.command('inserthtml',
 
374
                                    '<span style="background-color: ' + val + '">' + inst.EditorSelection.CURSOR + '</span>');
 
375
                                sel.focusCursor(true, true);
 
376
                            }
 
377
                            return n;
 
378
                        } else {
 
379
                            return this._command(cmd, val);
 
380
                        }
 
381
                    } else {
 
382
                        this._command(cmd, val);
 
383
                    }
 
384
                },
 
385
                /**
 
386
                * Sugar method, calles backcolor
 
387
                * @method COMMANDS.hilitecolor
 
388
                * @static
 
389
                * @param {String} cmd The command executed: backcolor
 
390
                * @param {String} val The color value to apply
 
391
                * @return {NodeList} NodeList of the items touched by this command.
 
392
                */
 
393
                hilitecolor: function() {
 
394
                    return ExecCommand.COMMANDS.backcolor.apply(this, arguments);
 
395
                },
 
396
                /**
 
397
                * Adds a font name to the current selection, or creates a new element and applies it
 
398
                * @method COMMANDS.fontname2
 
399
                * @deprecated
 
400
                * @static
 
401
                * @param {String} cmd The command executed: fontname
 
402
                * @param {String} val The font name to apply
 
403
                * @return {NodeList} NodeList of the items touched by this command.
 
404
                */
 
405
                fontname2: function(cmd, val) {
 
406
                    this._command('fontname', val);
 
407
                    var inst = this.getInstance(),
 
408
                        sel = new inst.EditorSelection();
 
409
 
 
410
                    if (sel.isCollapsed && (this._lastKey !== 32)) {
 
411
                        if (sel.anchorNode.test('font')) {
 
412
                            sel.anchorNode.set('face', val);
 
413
                        }
 
414
                    }
 
415
                },
 
416
                /**
 
417
                * Adds a fontsize to the current selection, or creates a new element and applies it
 
418
                * @method COMMANDS.fontsize2
 
419
                * @deprecated
 
420
                * @static
 
421
                * @param {String} cmd The command executed: fontsize
 
422
                * @param {String} val The font size to apply
 
423
                * @return {NodeList} NodeList of the items touched by this command.
 
424
                */
 
425
                fontsize2: function(cmd, val) {
 
426
                    this._command('fontsize', val);
 
427
 
 
428
                    var inst = this.getInstance(),
 
429
                        sel = new inst.EditorSelection(), p;
 
430
 
 
431
                    if (sel.isCollapsed && sel.anchorNode && (this._lastKey !== 32)) {
 
432
                        if (Y.UA.webkit) {
 
433
                            if (sel.anchorNode.getStyle('lineHeight')) {
 
434
                                sel.anchorNode.setStyle('lineHeight', '');
 
435
                            }
 
436
                        }
 
437
                        if (sel.anchorNode.test('font')) {
 
438
                            sel.anchorNode.set('size', val);
 
439
                        } else if (Y.UA.gecko) {
 
440
                            p = sel.anchorNode.ancestor(inst.EditorSelection.DEFAULT_BLOCK_TAG);
 
441
                            if (p) {
 
442
                                p.setStyle('fontSize', '');
 
443
                            }
 
444
                        }
 
445
                    }
 
446
                },
 
447
                /**
 
448
                * Overload for COMMANDS.list
 
449
                * @method COMMANDS.insertorderedlist
 
450
                * @static
 
451
                * @param {String} cmd The command executed: list, ul
 
452
                */
 
453
                insertunorderedlist: function() {
 
454
                    this.command('list', 'ul');
 
455
                },
 
456
                /**
 
457
                * Overload for COMMANDS.list
 
458
                * @method COMMANDS.insertunorderedlist
 
459
                * @static
 
460
                * @param {String} cmd The command executed: list, ol
 
461
                */
 
462
                insertorderedlist: function() {
 
463
                    this.command('list', 'ol');
 
464
                },
 
465
                /**
 
466
                * Noramlizes lists creation/destruction for IE. All others pass through to native calls
 
467
                * @method COMMANDS.list
 
468
                * @static
 
469
                * @param {String} cmd The command executed: list (not used)
 
470
                * @param {String} tag The tag to deal with
 
471
                */
 
472
                list: function(cmd, tag) {
 
473
                    var inst = this.getInstance(), html, self = this,
 
474
                        /*
 
475
                        The yui3- class name below is not a skinnable class,
 
476
                        it's a utility class used internally by editor and
 
477
                        stripped when completed, calling getClassName on this
 
478
                        is a waste of resources.
 
479
                        */
 
480
                        DIR = 'dir', cls = 'yui3-touched',
 
481
                        dir, range, div, elm, n, str, s, par, list, lis,
 
482
                        useP = (inst.host.editorPara ? true : false), tmp,
 
483
                        sdir, hasPParent, fc,
 
484
                        sel = new inst.EditorSelection();
 
485
 
 
486
                    cmd = 'insert' + ((tag === 'ul') ? 'un' : '') + 'orderedlist';
 
487
 
 
488
                    if (Y.UA.ie && !sel.isCollapsed) {
 
489
                        range = sel._selection;
 
490
                        html = range.htmlText;
 
491
                        div = inst.Node.create(html) || inst.one('body');
 
492
 
 
493
                        if (div.test('li') || div.one('li')) {
 
494
                            this._command(cmd, null);
 
495
                            return;
 
496
                        }
 
497
                        if (div.test(tag)) {
 
498
                            elm = range.item ? range.item(0) : range.parentElement();
 
499
                            n = inst.one(elm);
 
500
                            lis = n.all('li');
 
501
 
 
502
                            str = '<div>';
 
503
                            lis.each(function(l) {
 
504
                                str = self._wrapContent(l.get('innerHTML'));
 
505
                            });
 
506
                            str += '</div>';
 
507
                            s = inst.Node.create(str);
 
508
                            if (n.get('parentNode').test('div')) {
 
509
                                n = n.get('parentNode');
 
510
                            }
 
511
                            if (n && n.hasAttribute(DIR)) {
 
512
                                if (useP) {
 
513
                                    s.all('p').setAttribute(DIR, n.getAttribute(DIR));
 
514
                                } else {
 
515
                                    s.setAttribute(DIR, n.getAttribute(DIR));
 
516
                                }
 
517
                            }
 
518
                            if (useP) {
 
519
                                n.replace(s.get('innerHTML'));
 
520
                            } else {
 
521
                                n.replace(s);
 
522
                            }
 
523
                            if (range.moveToElementText) {
 
524
                                range.moveToElementText(s._node);
 
525
                            }
 
526
                            range.select();
 
527
                        } else {
 
528
                            par = Y.one(range.parentElement());
 
529
                            if (!par.test(inst.EditorSelection.BLOCKS)) {
 
530
                                par = par.ancestor(inst.EditorSelection.BLOCKS);
 
531
                            }
 
532
                            if (par) {
 
533
                                if (par.hasAttribute(DIR)) {
 
534
                                    dir = par.getAttribute(DIR);
 
535
                                }
 
536
                            }
 
537
                            if (html.indexOf('<br>') > -1) {
 
538
                                html = html.split(/<br>/i);
 
539
                            } else {
 
540
                                tmp = inst.Node.create(html),
 
541
                                ps = tmp ? tmp.all('p') : null;
 
542
 
 
543
                                if (ps && ps.size()) {
 
544
                                    html = [];
 
545
                                    ps.each(function(n) {
 
546
                                        html.push(n.get('innerHTML'));
 
547
                                    });
 
548
                                } else {
 
549
                                    html = [html];
 
550
                                }
 
551
                            }
 
552
                            list = '<' + tag + ' id="ie-list">';
 
553
                            Y.each(html, function(v) {
 
554
                                var a = inst.Node.create(v);
 
555
                                if (a && a.test('p')) {
 
556
                                    if (a.hasAttribute(DIR)) {
 
557
                                        dir = a.getAttribute(DIR);
 
558
                                    }
 
559
                                    v = a.get('innerHTML');
 
560
                                }
 
561
                                list += '<li>' + v + '</li>';
 
562
                            });
 
563
                            list += '</' + tag + '>';
 
564
                            range.pasteHTML(list);
 
565
                            elm = inst.config.doc.getElementById('ie-list');
 
566
                            elm.id = '';
 
567
                            if (dir) {
 
568
                                elm.setAttribute(DIR, dir);
 
569
                            }
 
570
                            if (range.moveToElementText) {
 
571
                                range.moveToElementText(elm);
 
572
                            }
 
573
                            range.select();
 
574
                        }
 
575
                    } else if (Y.UA.ie) {
 
576
                        par = inst.one(sel._selection.parentElement());
 
577
                        if (par.test('p')) {
 
578
                            if (par && par.hasAttribute(DIR)) {
 
579
                                dir = par.getAttribute(DIR);
 
580
                            }
 
581
                            html = Y.EditorSelection.getText(par);
 
582
                            if (html === '') {
 
583
                                sdir = '';
 
584
                                if (dir) {
 
585
                                    sdir = ' dir="' + dir + '"';
 
586
                                }
 
587
                                list = inst.Node.create(Y.Lang.sub('<{tag}{dir}><li></li></{tag}>', { tag: tag, dir: sdir }));
 
588
                                par.replace(list);
 
589
                                sel.selectNode(list.one('li'));
 
590
                            } else {
 
591
                                this._command(cmd, null);
 
592
                            }
 
593
                        } else {
 
594
                            this._command(cmd, null);
 
595
                        }
 
596
                    } else {
 
597
                        inst.all(tag).addClass(cls);
 
598
                        if (sel.anchorNode.test(inst.EditorSelection.BLOCKS)) {
 
599
                            par = sel.anchorNode;
 
600
                        } else {
 
601
                            par = sel.anchorNode.ancestor(inst.EditorSelection.BLOCKS);
 
602
                        }
 
603
                        if (!par) { //No parent, find the first block under the anchorNode
 
604
                            par = sel.anchorNode.one(inst.EditorSelection.BLOCKS);
 
605
                        }
 
606
 
 
607
                        if (par && par.hasAttribute(DIR)) {
 
608
                            dir = par.getAttribute(DIR);
 
609
                        }
 
610
                        if (par && par.test(tag)) {
 
611
                            hasPParent = par.ancestor('p');
 
612
                            html = inst.Node.create('<div/>');
 
613
                            elm = par.all('li');
 
614
                            elm.each(function(h) {
 
615
                                html.append(self._wrapContent(h.get('innerHTML'), hasPParent));
 
616
                            });
 
617
                            if (dir) {
 
618
                                if (useP) {
 
619
                                    html.all('p').setAttribute(DIR, dir);
 
620
                                } else {
 
621
                                    html.setAttribute(DIR, dir);
 
622
                                }
 
623
                            }
 
624
                            if (useP) {
 
625
                                html = inst.Node.create(html.get('innerHTML'));
 
626
                            }
 
627
                            fc = html.get('firstChild');
 
628
                            par.replace(html);
 
629
                            sel.selectNode(fc);
 
630
                        } else {
 
631
                            this._command(cmd, null);
 
632
                        }
 
633
                        list = inst.all(tag);
 
634
                        if (dir) {
 
635
                            if (list.size()) {
 
636
                                //Changed to a List
 
637
                                list.each(function(n) {
 
638
                                    if (!n.hasClass(cls)) {
 
639
                                        n.setAttribute(DIR, dir);
 
640
                                    }
 
641
                                });
 
642
                            }
 
643
                        }
 
644
 
 
645
                        list.removeClass(cls);
 
646
                    }
 
647
                },
 
648
                /**
 
649
                * Noramlizes alignment for Webkit Browsers
 
650
                * @method COMMANDS.justify
 
651
                * @static
 
652
                * @param {String} cmd The command executed: justify (not used)
 
653
                * @param {String} val The actual command from the justify{center,all,left,right} stubs
 
654
                */
 
655
                justify: function(cmd, val) {
 
656
                    if (Y.UA.webkit) {
 
657
                        var inst = this.getInstance(),
 
658
                            sel = new inst.EditorSelection(),
 
659
                            aNode = sel.anchorNode, html,
 
660
                            bgColor = aNode.getStyle('backgroundColor');
 
661
 
 
662
                            this._command(val);
 
663
                            sel = new inst.EditorSelection();
 
664
                            if (sel.anchorNode.test('div')) {
 
665
                                html = '<span>' + sel.anchorNode.get('innerHTML') + '</span>';
 
666
                                sel.anchorNode.set('innerHTML', html);
 
667
                                sel.anchorNode.one('span').setStyle('backgroundColor', bgColor);
 
668
                                sel.selectNode(sel.anchorNode.one('span'));
 
669
                            }
 
670
                    } else {
 
671
                        this._command(val);
 
672
                    }
 
673
                },
 
674
                /**
 
675
                * Override method for COMMANDS.justify
 
676
                * @method COMMANDS.justifycenter
 
677
                * @static
 
678
                */
 
679
                justifycenter: function() {
 
680
                    this.command('justify', 'justifycenter');
 
681
                },
 
682
                /**
 
683
                * Override method for COMMANDS.justify
 
684
                * @method COMMANDS.justifyleft
 
685
                * @static
 
686
                */
 
687
                justifyleft: function() {
 
688
                    this.command('justify', 'justifyleft');
 
689
                },
 
690
                /**
 
691
                * Override method for COMMANDS.justify
 
692
                * @method COMMANDS.justifyright
 
693
                * @static
 
694
                */
 
695
                justifyright: function() {
 
696
                    this.command('justify', 'justifyright');
 
697
                },
 
698
                /**
 
699
                * Override method for COMMANDS.justify
 
700
                * @method COMMANDS.justifyfull
 
701
                * @static
 
702
                */
 
703
                justifyfull: function() {
 
704
                    this.command('justify', 'justifyfull');
 
705
                }
 
706
            }
 
707
        });
 
708
 
 
709
        if (Y.UA.ie) {
 
710
            ExecCommand.COMMANDS.bold = function() {
 
711
                fixIETags.call(this, 'bold', 'b', 'FONT-WEIGHT: bold');
 
712
            };
 
713
            ExecCommand.COMMANDS.italic = function() {
 
714
                fixIETags.call(this, 'italic', 'i', 'FONT-STYLE: italic');
 
715
            };
 
716
            ExecCommand.COMMANDS.underline = function() {
 
717
                fixIETags.call(this, 'underline', 'u', 'TEXT-DECORATION: underline');
 
718
            };
 
719
        }
 
720
 
 
721
        Y.namespace('Plugin');
 
722
        Y.Plugin.ExecCommand = ExecCommand;
 
723
 
 
724
 
 
725
 
 
726
}, '3.10.3', {"requires": ["frame"]});