sir_trevor-8.x-1.x-dev/assets/js/scribe-plugins/blockquote.js

assets/js/scribe-plugins/blockquote.js
/**
 * Adds a command for using BLOCKQUOTEs.
 */

'use strict';

var scribeQuotePlugin = function () {

  return function (scribe) {
    var blockquoteCommand = new scribe.api.SimpleCommand('blockquote', 'BLOCKQUOTE');

    blockquoteCommand.execute = function () {
      var command = scribe.getCommand(this.queryState() ? 'outdent' : 'indent');
      command.execute();
    };

    blockquoteCommand.queryEnabled = function () {
      var command = scribe.getCommand(this.queryState() ? 'outdent' : 'indent');
      return command.queryEnabled();
    };

    blockquoteCommand.queryState = function () {
      var selection = new scribe.api.Selection();
      var blockquoteElement = selection.getContaining(function (element) {
        return element.nodeName === 'BLOCKQUOTE';
      });

      return scribe.allowsBlockElements() && !! blockquoteElement;
    };

    scribe.commands.quote = blockquoteCommand;

    /**
     * If the paragraphs option is set to true, we unapply the blockquote on
     * <enter> keypresses if the caret is on a new line.
     */
    if (scribe.allowsBlockElements()) {
      scribe.el.addEventListener('keydown', function (event) {
        if (event.keyCode === 13) { // enter

          var command = scribe.getCommand('blockquote');
          if (command.queryState()) {
            var selection = new scribe.api.Selection();
            if (selection.isCaretOnNewLine()) {
              event.preventDefault();
              command.execute();
            }
          }
        }
      });
    }
  };
};

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc