~jonas-drange/ubuntu-webcatalog/tos-redirect

« back to all changes in this revision

Viewing changes to src/webcatalog/static/yui/3.10.3/build/editor-lists/editor-lists.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('editor-lists', function (Y, NAME) {
 
9
 
 
10
 
 
11
    /**
 
12
     * Handles list manipulation inside the Editor. Adds keyboard manipulation and execCommand support.
 
13
     * Adds overrides for the <a href="Plugin.ExecCommand.html#method_COMMANDS.insertorderedlist">insertorderedlist</a>
 
14
     * and <a href="Plugin.ExecCommand.html#method_COMMANDS.insertunorderedlist">insertunorderedlist</a> execCommands.
 
15
     * @class Plugin.EditorLists
 
16
     * @constructor
 
17
     * @extends Base
 
18
     * @module editor
 
19
     * @submodule editor-lists
 
20
     */
 
21
 
 
22
    var EditorLists = function() {
 
23
        EditorLists.superclass.constructor.apply(this, arguments);
 
24
    }, LI = 'li', OL = 'ol', UL = 'ul', HOST = 'host';
 
25
 
 
26
    Y.extend(EditorLists, Y.Base, {
 
27
        /**
 
28
        * Listener for host's nodeChange event and captures the tabkey interaction only when inside a list node.
 
29
        * @private
 
30
        * @method _onNodeChange
 
31
        * @param {Event} e The Event facade passed from the host.
 
32
        */
 
33
        _onNodeChange: function(e) {
 
34
            var inst = this.get(HOST).getInstance(), li,
 
35
                newList, sTab, par, moved = false, tag, focusEnd = false;
 
36
 
 
37
            if (e.changedType === 'tab') {
 
38
                if (e.changedNode.test(LI + ', ' + LI + ' *')) {
 
39
                    e.changedEvent.halt();
 
40
                    e.preventDefault();
 
41
                    li = e.changedNode;
 
42
                    sTab = e.changedEvent.shiftKey;
 
43
                    par = li.ancestor(OL + ',' + UL);
 
44
                    tag = UL;
 
45
 
 
46
                    if (par.get('tagName').toLowerCase() === OL) {
 
47
                        tag = OL;
 
48
                    }
 
49
 
 
50
                    if (!li.test(LI)) {
 
51
                        li = li.ancestor(LI);
 
52
                    }
 
53
                    if (sTab) {
 
54
                        if (li.ancestor(LI)) {
 
55
                            li.ancestor(LI).insert(li, 'after');
 
56
                            moved = true;
 
57
                            focusEnd = true;
 
58
                        }
 
59
                    } else {
 
60
                        //li.setStyle('border', '1px solid red');
 
61
                        if (li.previous(LI)) {
 
62
                            newList = inst.Node.create('<' + tag + '></' + tag + '>');
 
63
                            li.previous(LI).append(newList);
 
64
                            newList.append(li);
 
65
                            moved = true;
 
66
                        }
 
67
                    }
 
68
                }
 
69
                if (moved) {
 
70
                    if (!li.test(LI)) {
 
71
                        li = li.ancestor(LI);
 
72
                    }
 
73
                    li.all(EditorLists.REMOVE).remove();
 
74
                    if (Y.UA.ie) {
 
75
                        li = li.append(EditorLists.NON).one(EditorLists.NON_SEL);
 
76
                    }
 
77
                    //Selection here..
 
78
                    (new inst.EditorSelection()).selectNode(li, true, focusEnd);
 
79
                }
 
80
            }
 
81
        },
 
82
        initializer: function() {
 
83
            this.get(HOST).on('nodeChange', Y.bind(this._onNodeChange, this));
 
84
        }
 
85
    }, {
 
86
        /**
 
87
        * The non element placeholder, used for positioning the cursor and filling empty items
 
88
        * @property REMOVE
 
89
        * @static
 
90
        */
 
91
        NON: '<span class="yui-non">&nbsp;</span>',
 
92
        /**
 
93
        * The selector query to get all non elements
 
94
        * @property NONSEL
 
95
        * @static
 
96
        */
 
97
        NON_SEL: 'span.yui-non',
 
98
        /**
 
99
        * The items to removed from a list when a list item is moved, currently removes BR nodes
 
100
        * @property REMOVE
 
101
        * @static
 
102
        */
 
103
        REMOVE: 'br',
 
104
        /**
 
105
        * editorLists
 
106
        * @property NAME
 
107
        * @static
 
108
        */
 
109
        NAME: 'editorLists',
 
110
        /**
 
111
        * lists
 
112
        * @property NS
 
113
        * @static
 
114
        */
 
115
        NS: 'lists',
 
116
        ATTRS: {
 
117
            host: {
 
118
                value: false
 
119
            }
 
120
        }
 
121
    });
 
122
 
 
123
    Y.namespace('Plugin');
 
124
 
 
125
    Y.Plugin.EditorLists = EditorLists;
 
126
 
 
127
 
 
128
 
 
129
}, '3.10.3', {"requires": ["editor-base"]});