[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/lib/yuilib/3.17.2/editor-lists/ -> editor-lists.js (source)

   1  /*
   2  YUI 3.17.2 (build 9c3c78e)
   3  Copyright 2014 Yahoo! Inc. All rights reserved.
   4  Licensed under the BSD License.
   5  http://yuilibrary.com/license/
   6  */
   7  
   8  YUI.add('editor-lists', function (Y, NAME) {
   9  
  10  
  11      /**
  12       * Handles list manipulation inside the Editor. Adds keyboard manipulation and execCommand support.
  13       * Adds overrides for the <a href="Plugin.ExecCommand.html#method_COMMANDS.insertorderedlist">insertorderedlist</a>
  14       * and <a href="Plugin.ExecCommand.html#method_COMMANDS.insertunorderedlist">insertunorderedlist</a> execCommands.
  15       * @class Plugin.EditorLists
  16       * @constructor
  17       * @extends Base
  18       * @module editor
  19       * @submodule editor-lists
  20       */
  21  
  22      var EditorLists = function() {
  23          EditorLists.superclass.constructor.apply(this, arguments);
  24      }, LI = 'li', OL = 'ol', UL = 'ul', HOST = 'host';
  25  
  26      Y.extend(EditorLists, Y.Base, {
  27          /**
  28          * Listener for host's nodeChange event and captures the tabkey interaction only when inside a list node.
  29          * @private
  30          * @method _onNodeChange
  31          * @param {Event} e The Event facade passed from the host.
  32          */
  33          _onNodeChange: function(e) {
  34              var inst = this.get(HOST).getInstance(), li,
  35                  newList, sTab, par, moved = false, tag, focusEnd = false;
  36  
  37              if (e.changedType === 'tab') {
  38                  if (e.changedNode.test(LI + ', ' + LI + ' *')) {
  39                      e.changedEvent.halt();
  40                      e.preventDefault();
  41                      li = e.changedNode;
  42                      sTab = e.changedEvent.shiftKey;
  43                      par = li.ancestor(OL + ',' + UL);
  44                      tag = UL;
  45  
  46                      if (par.get('tagName').toLowerCase() === OL) {
  47                          tag = OL;
  48                      }
  49  
  50                      if (!li.test(LI)) {
  51                          li = li.ancestor(LI);
  52                      }
  53                      if (sTab) {
  54                          if (li.ancestor(LI)) {
  55                              li.ancestor(LI).insert(li, 'after');
  56                              moved = true;
  57                              focusEnd = true;
  58                          }
  59                      } else {
  60                          //li.setStyle('border', '1px solid red');
  61                          if (li.previous(LI)) {
  62                              newList = inst.Node.create('<' + tag + '></' + tag + '>');
  63                              li.previous(LI).append(newList);
  64                              newList.append(li);
  65                              moved = true;
  66                          }
  67                      }
  68                  }
  69                  if (moved) {
  70                      if (!li.test(LI)) {
  71                          li = li.ancestor(LI);
  72                      }
  73                      li.all(EditorLists.REMOVE).remove();
  74                      if (Y.UA.ie) {
  75                          li = li.append(EditorLists.NON).one(EditorLists.NON_SEL);
  76                      }
  77                      //Selection here..
  78                      (new inst.EditorSelection()).selectNode(li, true, focusEnd);
  79                  }
  80              }
  81          },
  82          initializer: function() {
  83              this.get(HOST).on('nodeChange', Y.bind(this._onNodeChange, this));
  84          }
  85      }, {
  86          /**
  87          * The non element placeholder, used for positioning the cursor and filling empty items
  88          * @property NON
  89          * @static
  90          */
  91          NON: '<span class="yui-non">&nbsp;</span>',
  92          /**
  93          * The selector query to get all non elements
  94          * @property NONSEL
  95          * @static
  96          */
  97          NON_SEL: 'span.yui-non',
  98          /**
  99          * The items to removed from a list when a list item is moved, currently removes BR nodes
 100          * @property REMOVE
 101          * @static
 102          */
 103          REMOVE: 'br',
 104          /**
 105          * editorLists
 106          * @property NAME
 107          * @static
 108          */
 109          NAME: 'editorLists',
 110          /**
 111          * lists
 112          * @property NS
 113          * @static
 114          */
 115          NS: 'lists',
 116          ATTRS: {
 117              host: {
 118                  value: false
 119              }
 120          }
 121      });
 122  
 123      Y.namespace('Plugin');
 124  
 125      Y.Plugin.EditorLists = EditorLists;
 126  
 127  
 128  
 129  }, '3.17.2', {"requires": ["editor-base"]});


Generated: Thu Aug 11 10:00:09 2016 Cross-referenced by PHPXref 0.7.1