MDL-32843 import YUI 3.5.1
[moodle.git] / lib / yui / 3.5.1 / build / editor-tab / editor-tab.js
blob34ac559dcc9343866f0282ae33cae247485dd8cb
1 /*
2 YUI 3.5.1 (build 22)
3 Copyright 2012 Yahoo! Inc. All rights reserved.
4 Licensed under the BSD License.
5 http://yuilibrary.com/license/
6 */
7 YUI.add('editor-tab', function(Y) {
10     /**
11      * Handles tab and shift-tab indent/outdent support.
12      * @class Plugin.EditorTab
13      * @constructor
14      * @extends Base
15      * @module editor
16      * @submodule editor-tab
17      */
18     
19     var EditorTab = function() {
20         EditorTab.superclass.constructor.apply(this, arguments);
21     }, HOST = 'host';
23     Y.extend(EditorTab, Y.Base, {
24         /**
25         * Listener for host's nodeChange event and captures the tabkey interaction.
26         * @private
27         * @method _onNodeChange
28         * @param {Event} e The Event facade passed from the host.
29         */
30         _onNodeChange: function(e) {
31             var action = 'indent';
33             if (e.changedType === 'tab') {
34                 if (!e.changedNode.test('li, li *')) {
35                     e.changedEvent.halt();
36                     e.preventDefault();
37                     if (e.changedEvent.shiftKey) {
38                         action = 'outdent';
39                     }
41                     this.get(HOST).execCommand(action, '');
42                 }
43             }
44         },
45         initializer: function() {
46             this.get(HOST).on('nodeChange', Y.bind(this._onNodeChange, this));
47         }
48     }, {
49         /**
50         * editorTab
51         * @property NAME
52         * @static
53         */
54         NAME: 'editorTab',
55         /**
56         * tab
57         * @property NS
58         * @static
59         */
60         NS: 'tab',
61         ATTRS: {
62             host: {
63                 value: false
64             }
65         }
66     });
69     Y.namespace('Plugin');
71     Y.Plugin.EditorTab = EditorTab;
74 }, '3.5.1' ,{skinnable:false, requires:['editor-base']});