[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/lib/yuilib/3.17.2/editor-para-base/ -> editor-para-base-debug.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-para-base', function (Y, NAME) {
   9  
  10  
  11      /**
  12       * Base Plugin for Editor to paragraph auto wrapping and correction.
  13       * @class Plugin.EditorParaBase
  14       * @extends Base
  15       * @constructor
  16       * @module editor
  17       * @submodule editor-para-base
  18       */
  19  
  20  
  21      var EditorParaBase = function() {
  22          EditorParaBase.superclass.constructor.apply(this, arguments);
  23      }, HOST = 'host',
  24      FIRST_P = '> p', P = 'p', BR = '<br>';
  25  
  26  
  27      Y.extend(EditorParaBase, Y.Base, {
  28          /**
  29          * Resolves the ROOT editor element.
  30          * @method _getRoot
  31          * @private
  32          */
  33          _getRoot: function() {
  34              return this.get(HOST).getInstance().EditorSelection.ROOT;
  35          },
  36  
  37          /**
  38          * Utility method to create an empty paragraph when the document is empty.
  39          * @private
  40          * @method _fixFirstPara
  41          */
  42          _fixFirstPara: function() {
  43              Y.log('Fix First Paragraph', 'info', 'editor-para');
  44              var host = this.get(HOST), inst = host.getInstance(), sel, n,
  45                  root = this._getRoot(),
  46                  html = root.getHTML(),
  47                  col = ((html.length) ? true : false);
  48  
  49              if (html === BR) {
  50                  html = '';
  51                  col = false;
  52              }
  53  
  54              root.setHTML('<' + P + '>' + html + inst.EditorSelection.CURSOR + '</' + P + '>');
  55  
  56              n = root.one(FIRST_P);
  57              sel = new inst.EditorSelection();
  58  
  59              sel.selectNode(n, true, col);
  60          },
  61          /**
  62          * Performs a block element filter when the Editor is first ready
  63          * @private
  64          * @method _afterEditorReady
  65          */
  66          _afterEditorReady: function() {
  67              var host = this.get(HOST), inst = host.getInstance(), btag;
  68              if (inst) {
  69                  inst.EditorSelection.filterBlocks();
  70                  btag = inst.EditorSelection.DEFAULT_BLOCK_TAG;
  71                  FIRST_P = '> ' + btag;
  72                  P = btag;
  73              }
  74          },
  75          /**
  76          * Performs a block element filter when the Editor after an content change
  77          * @private
  78          * @method _afterContentChange
  79          */
  80          _afterContentChange: function() {
  81              var host = this.get(HOST), inst = host.getInstance();
  82              if (inst && inst.EditorSelection) {
  83                  inst.EditorSelection.filterBlocks();
  84              }
  85          },
  86          /**
  87          * Performs block/paste filtering after paste.
  88          * @private
  89          * @method _afterPaste
  90          */
  91          _afterPaste: function() {
  92              var host = this.get(HOST), inst = host.getInstance();
  93  
  94              Y.later(50, host, function() {
  95                  inst.EditorSelection.filterBlocks();
  96              });
  97  
  98          },
  99          initializer: function() {
 100              var host = this.get(HOST);
 101              if (host.editorBR) {
 102                  Y.error('Can not plug EditorPara and EditorBR at the same time.');
 103                  return;
 104              }
 105  
 106              host.after('ready', Y.bind(this._afterEditorReady, this));
 107              host.after('contentChange', Y.bind(this._afterContentChange, this));
 108              if (Y.Env.webkit) {
 109                  host.after('dom:paste', Y.bind(this._afterPaste, this));
 110              }
 111          }
 112      }, {
 113          /**
 114          * editorPara
 115          * @static
 116          * @property NAME
 117          */
 118          NAME: 'editorParaBase',
 119          /**
 120          * editorPara
 121          * @static
 122          * @property NS
 123          */
 124          NS: 'editorParaBase',
 125          ATTRS: {
 126              host: {
 127                  value: false
 128              }
 129          }
 130      });
 131  
 132      Y.namespace('Plugin');
 133  
 134      Y.Plugin.EditorParaBase = EditorParaBase;
 135  
 136  
 137  
 138  
 139  }, '3.17.2', {"requires": ["editor-base"]});


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