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