~andreserl/maas/packaging_precise_rebase

« back to all changes in this revision

Viewing changes to debian/extras/jslibs/yui/editor-lists/editor-lists-debug.js

  • Committer: Andres Rodriguez
  • Date: 2013-03-20 18:12:30 UTC
  • mfrom: (145.2.22 precise.sru)
  • Revision ID: andreserl@ubuntu.com-20130320181230-6l5guc0nhlv2z4p7
Re-base againts latest quantal released branch towards SRU

Show diffs side-by-side

added added

removed removed

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