lists.js revision c653ab6f9e382f9eca2d44393ee71262257fbe55
7038N/A /**
7038N/A * 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.
7038N/A * @module editor
7038N/A * @submodule editor-lists
7038N/A */
7038N/A /**
7038N/A * 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.
7038N/A * @class Plugin.EditorLists
7038N/A * @constructor
7038N/A * @extends Base
7038N/A */
7038N/A
7038N/A var EditorLists = function() {
7038N/A EditorLists.superclass.constructor.apply(this, arguments);
7038N/A }, LI = 'li', OL = 'ol', UL = 'ul', HOST = 'host';
7038N/A
7038N/A Y.extend(EditorLists, Y.Base, {
7038N/A /**
7038N/A * Listener for host's nodeChange event and captures the tabkey interaction only when inside a list node.
7038N/A * @private
7038N/A * @method _onNodeChange
7038N/A * @param {Event} e The Event facade passed from the host.
7038N/A */
7038N/A _onNodeChange: function(e) {
7038N/A var inst = this.get(HOST).getInstance(), sel, li,
7038N/A newLi, newList, sTab, par, moved = false, tag, focusEnd = false;
7038N/A
7038N/A if (e.changedType === 'tab') {
7038N/A if (e.changedNode.test(LI + ', ' + LI + ' *')) {
7038N/A Y.log('Overriding TAB to move lists around', 'info', 'editorLists');
7038N/A e.changedEvent.halt();
7038N/A e.preventDefault();
7038N/A li = e.changedNode;
7038N/A sTab = e.changedEvent.shiftKey;
7038N/A par = li.ancestor(OL + ',' + UL);
7038N/A tag = UL;
7038N/A
7038N/A if (par.get('tagName').toLowerCase() === OL) {
7038N/A tag = OL;
7038N/A }
7038N/A Y.log('ShiftKey: ' + sTab, 'info', 'editorLists');
7038N/A
7038N/A if (!li.test(LI)) {
7038N/A li = li.ancestor(LI);
7038N/A }
7038N/A if (sTab) {
7038N/A if (li.ancestor(LI)) {
7038N/A Y.log('Shifting list up one level', 'info', 'editorLists');
7038N/A li.ancestor(LI).insert(li, 'after');
7038N/A moved = true;
7038N/A focusEnd = true;
7038N/A }
7038N/A } else {
7038N/A //li.setStyle('border', '1px solid red');
7038N/A if (li.previous(LI)) {
7038N/A Y.log('Shifting list down one level', 'info', 'editorLists');
7038N/A newList = inst.Node.create('<' + tag + '></' + tag + '>');
7038N/A li.previous(LI).append(newList);
7038N/A newList.append(li);
7038N/A moved = true;
7038N/A }
7038N/A }
7038N/A }
7038N/A if (moved) {
7038N/A if (!li.test(LI)) {
7038N/A li = li.ancestor(LI);
7038N/A }
7038N/A li.all(EditorLists.REMOVE).remove();
7038N/A if (Y.UA.ie) {
7038N/A li = li.append(EditorLists.NON).one(EditorLists.NON_SEL);
7038N/A }
7038N/A //Selection here..
7038N/A Y.log('Selecting the new node', 'info', 'editorLists');
7038N/A (new inst.Selection()).selectNode(li, true, focusEnd);
7038N/A }
7038N/A }
7038N/A },
7038N/A initializer: function() {
7038N/A this.get(HOST).on('nodeChange', Y.bind(this._onNodeChange, this));
7038N/A }
}, {
/**
* The non element placeholder, used for positioning the cursor and filling empty items
* @property REMOVE
* @static
*/
NON: '<span class="yui-non">&nbsp;</span>',
/**
* The selector query to get all non elements
* @property NONSEL
* @static
*/
NON_SEL: 'span.yui-non',
/**
* The items to removed from a list when a list item is moved, currently removes BR nodes
* @property REMOVE
* @static
*/
REMOVE: 'br',
/**
* editorLists
* @property NAME
* @static
*/
NAME: 'editorLists',
/**
* lists
* @property NS
* @static
*/
NS: 'lists',
ATTRS: {
host: {
value: false
}
}
});
Y.namespace('Plugin');
Y.Plugin.EditorLists = EditorLists;