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