~ubuntu-branches/ubuntu/utopic/moodle/utopic

« back to all changes in this revision

Viewing changes to lib/yuilib/3.9.1/build/editor-lists/editor-lists.js

  • Committer: Package Import Robot
  • Author(s): Thijs Kinkhorst
  • Date: 2014-05-12 16:10:38 UTC
  • mfrom: (36.1.3 sid)
  • Revision ID: package-import@ubuntu.com-20140512161038-puyqf65k4e0s8ytz
Tags: 2.6.3-1
New upstream release.

Show diffs side-by-side

added added

removed removed

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