3
Copyright 2012 Yahoo! Inc. All rights reserved.
4
Licensed under the BSD License.
5
http://yuilibrary.com/license/
7
YUI.add('editor-lists', function(Y) {
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
16
* @submodule editor-lists
19
var EditorLists = function() {
20
EditorLists.superclass.constructor.apply(this, arguments);
21
}, LI = 'li', OL = 'ol', UL = 'ul', HOST = 'host';
23
Y.extend(EditorLists, Y.Base, {
25
* Listener for host's nodeChange event and captures the tabkey interaction only when inside a list node.
27
* @method _onNodeChange
28
* @param {Event} e The Event facade passed from the host.
30
_onNodeChange: function(e) {
31
var inst = this.get(HOST).getInstance(), sel, li,
32
newLi, newList, sTab, par, moved = false, tag, focusEnd = false;
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();
40
sTab = e.changedEvent.shiftKey;
41
par = li.ancestor(OL + ',' + UL);
44
if (par.get('tagName').toLowerCase() === OL) {
47
Y.log('ShiftKey: ' + sTab, 'info', 'editorLists');
53
if (li.ancestor(LI)) {
54
Y.log('Shifting list up one level', 'info', 'editorLists');
55
li.ancestor(LI).insert(li, 'after');
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);
74
li.all(EditorLists.REMOVE).remove();
76
li = li.append(EditorLists.NON).one(EditorLists.NON_SEL);
79
Y.log('Selecting the new node', 'info', 'editorLists');
80
(new inst.EditorSelection()).selectNode(li, true, focusEnd);
84
initializer: function() {
85
this.get(HOST).on('nodeChange', Y.bind(this._onNodeChange, this));
89
* The non element placeholder, used for positioning the cursor and filling empty items
93
NON: '<span class="yui-non"> </span>',
95
* The selector query to get all non elements
99
NON_SEL: 'span.yui-non',
101
* The items to removed from a list when a list item is moved, currently removes BR nodes
125
Y.namespace('Plugin');
127
Y.Plugin.EditorLists = EditorLists;
131
}, '3.5.1' ,{skinnable:false, requires:['editor-base']});