~ted/lazr-js/annoying-debug-message

« back to all changes in this revision

Viewing changes to src-js/lazrjs/yui/editor/editor-lists.js

  • Committer: Launchpad Patch Queue Manager
  • Date: 2010-09-09 14:20:30 UTC
  • mfrom: (182.1.3 yui-3.2)
  • Revision ID: launchpad@pqm.canonical.com-20100909142030-13w6vo0ixfysxc15
[r=beuno] Update lazr-js to yui-3.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
Copyright (c) 2010, Yahoo! Inc. All rights reserved.
 
3
Code licensed under the BSD License:
 
4
http://developer.yahoo.com/yui/license.html
 
5
version: 3.2.0
 
6
build: 2676
 
7
*/
 
8
YUI.add('editor-lists', function(Y) {
 
9
 
 
10
    /**
 
11
     * Handles list manipulation inside the Editor. Adds keyboard manipulation and execCommand support. Adds overrides for the <a href="Plugin.ExecCommand.html#method_COMMANDS.insertorderedlist">insertorderedlist</a> and <a href="Plugin.ExecCommand.html#method_COMMANDS.insertunorderedlist">insertunorderedlist</a> execCommands.
 
12
     * @module editor
 
13
     * @submodule editor-lists
 
14
     */     
 
15
    /**
 
16
     * Handles list manipulation inside the Editor. Adds keyboard manipulation and execCommand support. Adds overrides for the <a href="Plugin.ExecCommand.html#method_COMMANDS.insertorderedlist">insertorderedlist</a> and <a href="Plugin.ExecCommand.html#method_COMMANDS.insertunorderedlist">insertunorderedlist</a> execCommands.
 
17
     * @class Plugin.EditorLists
 
18
     * @constructor
 
19
     * @extends Base
 
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(), sel, li, 
 
35
            newLi, newList, sTab, par, moved = false, tag, focusEnd = false;
 
36
 
 
37
            if (Y.UA.ie && e.changedType === 'enter') {
 
38
                if (e.changedNode.test(LI + ', ' + LI + ' *')) {
 
39
                    e.changedEvent.halt();
 
40
                    e.preventDefault();
 
41
                    li = e.changedNode;
 
42
                    newLi = inst.Node.create('<' + LI + '>' + EditorLists.NON + '</' + LI + '>');
 
43
                        
 
44
                    if (!li.test(LI)) {
 
45
                        li = li.ancestor(LI);
 
46
                    }
 
47
                    li.insert(newLi, 'after');
 
48
                    
 
49
                    sel = new inst.Selection();
 
50
                    sel.selectNode(newLi.get('firstChild'), true, false);
 
51
                }
 
52
            }
 
53
            if (e.changedType === 'tab') {
 
54
                if (e.changedNode.test(LI + ', ' + LI + ' *')) {
 
55
                    e.changedEvent.halt();
 
56
                    e.preventDefault();
 
57
                    li = e.changedNode;
 
58
                    sTab = e.changedEvent.shiftKey;
 
59
                    par = li.ancestor(OL + ',' + UL);
 
60
                    tag = UL;
 
61
 
 
62
 
 
63
                    if (par.get('tagName').toLowerCase() === OL) {
 
64
                        tag = OL;
 
65
                    }
 
66
                    
 
67
                    if (!li.test(LI)) {
 
68
                        li = li.ancestor(LI);
 
69
                    }
 
70
                    if (sTab) {
 
71
                        if (li.ancestor(LI)) {
 
72
                            li.ancestor(LI).insert(li, 'after');
 
73
                            moved = true;
 
74
                            focusEnd = true;
 
75
                        }
 
76
                    } else {
 
77
                        //li.setStyle('border', '1px solid red');
 
78
                        if (li.previous(LI)) {
 
79
                            newList = inst.Node.create('<' + tag + '></' + tag + '>');
 
80
                            li.previous(LI).append(newList);
 
81
                            newList.append(li);
 
82
                            moved = true;
 
83
                        }
 
84
                    }
 
85
                }
 
86
                if (moved) {
 
87
                    if (!li.test(LI)) {
 
88
                        li = li.ancestor(LI);
 
89
                    }
 
90
                    li.all(EditorLists.REMOVE).remove();
 
91
                    if (Y.UA.ie) {
 
92
                        li = li.append(EditorLists.NON).one(EditorLists.NON_SEL);
 
93
                    }
 
94
                    //Selection here..
 
95
                    (new inst.Selection()).selectNode(li, true, focusEnd);
 
96
                }
 
97
            }
 
98
        },
 
99
        initializer: function() {
 
100
            this.get(HOST).on('nodeChange', Y.bind(this._onNodeChange, this));
 
101
        }
 
102
    }, {
 
103
        /**
 
104
        * The non element placeholder, used for positioning the cursor and filling empty items
 
105
        * @property REMOVE
 
106
        * @static
 
107
        */
 
108
        NON: '<span class="yui-non">&nbsp;</span>',
 
109
        /**
 
110
        * The selector query to get all non elements
 
111
        * @property NONSEL
 
112
        * @static
 
113
        */
 
114
        NON_SEL: 'span.yui-non',
 
115
        /**
 
116
        * The items to removed from a list when a list item is moved, currently removes BR nodes
 
117
        * @property REMOVE
 
118
        * @static
 
119
        */
 
120
        REMOVE: 'br',
 
121
        /**
 
122
        * editorLists
 
123
        * @property NAME
 
124
        * @static
 
125
        */
 
126
        NAME: 'editorLists',
 
127
        /**
 
128
        * lists
 
129
        * @property NS
 
130
        * @static
 
131
        */
 
132
        NS: 'lists',
 
133
        ATTRS: {
 
134
            host: {
 
135
                value: false
 
136
            }
 
137
        }
 
138
    });
 
139
 
 
140
 
 
141
    Y.namespace('Plugin');
 
142
 
 
143
    Y.Plugin.EditorLists = EditorLists;
 
144
 
 
145
    Y.mix(Y.Plugin.ExecCommand.COMMANDS, {
 
146
        /**
 
147
        * Override for the insertunorderedlist method from the <a href="Plugin.EditorLists.html">EditorLists</a> plugin.
 
148
        * @for ExecCommand
 
149
        * @method COMMANDS.insertunorderedlist
 
150
        * @static
 
151
        * @param {String} cmd The command executed: insertunorderedlist
 
152
        * @return {Node} Node instance of the item touched by this command.
 
153
        */
 
154
        insertunorderedlist: function(cmd) {
 
155
            var inst = this.get('host').getInstance(), out;
 
156
            this.get('host')._execCommand(cmd, '');
 
157
        },
 
158
        /**
 
159
        * Override for the insertorderedlist method from the <a href="Plugin.EditorLists.html">EditorLists</a> plugin.
 
160
        * @for ExecCommand
 
161
        * @method COMMANDS.insertorderedlist
 
162
        * @static
 
163
        * @param {String} cmd The command executed: insertorderedlist
 
164
        * @return {Node} Node instance of the item touched by this command.
 
165
        */
 
166
        insertorderedlist: function(cmd) {
 
167
            var inst = this.get('host').getInstance(), out;
 
168
            this.get('host')._execCommand(cmd, '');
 
169
        }
 
170
    });
 
171
 
 
172
 
 
173
 
 
174
 
 
175
}, '3.2.0' ,{skinnable:false, requires:['editor-base']});