editor-lists-debug.js revision c653ab6f9e382f9eca2d44393ee71262257fbe55
457N/AYUI.add('editor-lists', function(Y) {
457N/A
457N/A /**
457N/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.
457N/A * @module editor
457N/A * @submodule editor-lists
457N/A */
457N/A /**
457N/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.
457N/A * @class Plugin.EditorLists
457N/A * @constructor
457N/A * @extends Base
457N/A */
457N/A
457N/A var EditorLists = function() {
457N/A EditorLists.superclass.constructor.apply(this, arguments);
457N/A }, LI = 'li', OL = 'ol', UL = 'ul', HOST = 'host';
457N/A
457N/A Y.extend(EditorLists, Y.Base, {
457N/A /**
457N/A * Listener for host's nodeChange event and captures the tabkey interaction only when inside a list node.
457N/A * @private
700N/A * @method _onNodeChange
457N/A * @param {Event} e The Event facade passed from the host.
457N/A */
457N/A _onNodeChange: function(e) {
457N/A var inst = this.get(HOST).getInstance(), sel, li,
457N/A newLi, newList, sTab, par, moved = false, tag, focusEnd = false;
457N/A
618N/A if (e.changedType === 'tab') {
457N/A if (e.changedNode.test(LI + ', ' + LI + ' *')) {
457N/A Y.log('Overriding TAB to move lists around', 'info', 'editorLists');
844N/A e.changedEvent.halt();
844N/A e.preventDefault();
618N/A li = e.changedNode;
457N/A sTab = e.changedEvent.shiftKey;
457N/A par = li.ancestor(OL + ',' + UL);
457N/A tag = UL;
457N/A
457N/A if (par.get('tagName').toLowerCase() === OL) {
457N/A tag = OL;
457N/A }
457N/A Y.log('ShiftKey: ' + sTab, 'info', 'editorLists');
457N/A
457N/A if (!li.test(LI)) {
457N/A li = li.ancestor(LI);
457N/A }
457N/A if (sTab) {
457N/A if (li.ancestor(LI)) {
457N/A Y.log('Shifting list up one level', 'info', 'editorLists');
457N/A li.ancestor(LI).insert(li, 'after');
457N/A moved = true;
457N/A focusEnd = true;
457N/A }
457N/A } else {
457N/A //li.setStyle('border', '1px solid red');
727N/A if (li.previous(LI)) {
634N/A Y.log('Shifting list down one level', 'info', 'editorLists');
457N/A newList = inst.Node.create('<' + tag + '></' + tag + '>');
457N/A li.previous(LI).append(newList);
457N/A newList.append(li);
457N/A moved = true;
457N/A }
457N/A }
457N/A }
457N/A if (moved) {
457N/A if (!li.test(LI)) {
727N/A li = li.ancestor(LI);
457N/A }
457N/A li.all(EditorLists.REMOVE).remove();
457N/A if (Y.UA.ie) {
457N/A li = li.append(EditorLists.NON).one(EditorLists.NON_SEL);
457N/A }
457N/A //Selection here..
457N/A Y.log('Selecting the new node', 'info', 'editorLists');
457N/A (new inst.Selection()).selectNode(li, true, focusEnd);
457N/A }
457N/A }
457N/A },
initializer: function() {
this.get(HOST).on('nodeChange', Y.bind(this._onNodeChange, this));
}
}, {
/**
* 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;
}, '@VERSION@' ,{requires:['editor-base'], skinnable:false});