2
Copyright (c) 2010, Yahoo! Inc. All rights reserved.
3
Code licensed under the BSD License:
4
http://developer.yahoo.com/yui/license.html
8
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.
13
* @submodule editor-lists
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
22
var EditorLists = function() {
23
EditorLists.superclass.constructor.apply(this, arguments);
24
}, LI = 'li', OL = 'ol', UL = 'ul', HOST = 'host';
26
Y.extend(EditorLists, Y.Base, {
28
* Listener for host's nodeChange event and captures the tabkey interaction only when inside a list node.
30
* @method _onNodeChange
31
* @param {Event} e The Event facade passed from the host.
33
_onNodeChange: function(e) {
34
var inst = this.get(HOST).getInstance(), sel, li,
35
newLi, newList, sTab, par, moved = false, tag, focusEnd = false;
37
if (Y.UA.ie && e.changedType === 'enter') {
38
if (e.changedNode.test(LI + ', ' + LI + ' *')) {
39
e.changedEvent.halt();
42
newLi = inst.Node.create('<' + LI + '>' + EditorLists.NON + '</' + LI + '>');
47
li.insert(newLi, 'after');
49
sel = new inst.Selection();
50
sel.selectNode(newLi.get('firstChild'), true, false);
53
if (e.changedType === 'tab') {
54
if (e.changedNode.test(LI + ', ' + LI + ' *')) {
55
e.changedEvent.halt();
58
sTab = e.changedEvent.shiftKey;
59
par = li.ancestor(OL + ',' + UL);
63
if (par.get('tagName').toLowerCase() === OL) {
71
if (li.ancestor(LI)) {
72
li.ancestor(LI).insert(li, 'after');
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);
90
li.all(EditorLists.REMOVE).remove();
92
li = li.append(EditorLists.NON).one(EditorLists.NON_SEL);
95
(new inst.Selection()).selectNode(li, true, focusEnd);
99
initializer: function() {
100
this.get(HOST).on('nodeChange', Y.bind(this._onNodeChange, this));
104
* The non element placeholder, used for positioning the cursor and filling empty items
108
NON: '<span class="yui-non"> </span>',
110
* The selector query to get all non elements
114
NON_SEL: 'span.yui-non',
116
* The items to removed from a list when a list item is moved, currently removes BR nodes
141
Y.namespace('Plugin');
143
Y.Plugin.EditorLists = EditorLists;
145
Y.mix(Y.Plugin.ExecCommand.COMMANDS, {
147
* Override for the insertunorderedlist method from the <a href="Plugin.EditorLists.html">EditorLists</a> plugin.
149
* @method COMMANDS.insertunorderedlist
151
* @param {String} cmd The command executed: insertunorderedlist
152
* @return {Node} Node instance of the item touched by this command.
154
insertunorderedlist: function(cmd) {
155
var inst = this.get('host').getInstance(), out;
156
this.get('host')._execCommand(cmd, '');
159
* Override for the insertorderedlist method from the <a href="Plugin.EditorLists.html">EditorLists</a> plugin.
161
* @method COMMANDS.insertorderedlist
163
* @param {String} cmd The command executed: insertorderedlist
164
* @return {Node} Node instance of the item touched by this command.
166
insertorderedlist: function(cmd) {
167
var inst = this.get('host').getInstance(), out;
168
this.get('host')._execCommand(cmd, '');
175
}, '3.2.0' ,{skinnable:false, requires:['editor-base']});