[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/lib/editor/atto/plugins/rtl/yui/src/button/js/ -> button.js (source)

   1  // This file is part of Moodle - http://moodle.org/
   2  //
   3  // Moodle is free software: you can redistribute it and/or modify
   4  // it under the terms of the GNU General Public License as published by
   5  // the Free Software Foundation, either version 3 of the License, or
   6  // (at your option) any later version.
   7  //
   8  // Moodle is distributed in the hope that it will be useful,
   9  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  10  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  11  // GNU General Public License for more details.
  12  //
  13  // You should have received a copy of the GNU General Public License
  14  // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
  15  
  16  /*
  17   * @package    atto_rtl
  18   * @copyright  2014 Jerome Mouneyrac
  19   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  20   */
  21  
  22  /**
  23   * @module moodle-atto_rtl-button
  24   */
  25  
  26  /**
  27   * Atto text editor rtl plugin.
  28   *
  29   * @namespace M.atto_rtl
  30   * @class button
  31   * @extends M.editor_atto.EditorPlugin
  32   */
  33  
  34  Y.namespace('M.atto_rtl').Button = Y.Base.create('button', Y.M.editor_atto.EditorPlugin, [], {
  35      initializer: function() {
  36          var direction;
  37  
  38          direction = 'ltr';
  39          this.addButton({
  40              icon: 'e/left_to_right',
  41              title: direction,
  42              buttonName: direction,
  43              callback: this._toggleRTL,
  44              callbackArgs: direction,
  45              tags: '[dir=ltr]'
  46          });
  47  
  48          direction = 'rtl';
  49          this.addButton({
  50              icon: 'e/right_to_left',
  51              title: direction,
  52              buttonName: direction,
  53              callback: this._toggleRTL,
  54              callbackArgs: direction,
  55              tags: '[dir=rtl]'
  56          });
  57      },
  58  
  59      /**
  60       * Toggle the RTL/LTR values based on the supplied direction.
  61       *
  62       * @method _toggleRTL
  63       * @param {EventFacade} e
  64       * @param {String} direction
  65       */
  66      _toggleRTL: function(e, direction) {
  67          var host = this.get('host'),
  68              sourceSelection = window.rangy.saveSelection(),
  69              selection = host.getSelection(),
  70              newDirection = {
  71                  rtl: 'ltr',
  72                  ltr: 'rtl'
  73              };
  74          if (selection) {
  75              // Format the selection to be sure it has a tag parent (not the contenteditable).
  76              var parentNode = host.formatSelectionBlock(),
  77                  parentDOMNode = parentNode.getDOMNode();
  78  
  79              var currentDirection = parentDOMNode.getAttribute('dir');
  80              if (currentDirection === direction) {
  81                  parentDOMNode.setAttribute("dir", newDirection[direction]);
  82              } else {
  83                  parentDOMNode.setAttribute("dir", direction);
  84              }
  85  
  86              // Change selection from the containing paragraph to the original one.
  87              window.rangy.restoreSelection(sourceSelection);
  88              // Mark the text as having been updated.
  89              this.markUpdated();
  90          }
  91      }
  92  });


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