MDL-43864 editor_atto: added a prevent autolink button to atto
This commit is contained in:
committed by
Damyon Wiese
parent
18ce3fe4ee
commit
bed1abbc89
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Strings for component 'atto_noautolink', language 'en'.
|
||||
*
|
||||
* @package atto_noautolink
|
||||
* @copyright 2014 Andrew Davis <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
$string['pluginname'] = 'Prevent auto-link';
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Atto text editor integration version file.
|
||||
*
|
||||
* @package atto_noautolink
|
||||
* @copyright 2014 Andrew Davis <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
$plugin->version = 2014020300; // The current plugin version (Date: YYYYMMDDXX).
|
||||
$plugin->requires = 2013110500; // Requires this Moodle version.
|
||||
$plugin->component = 'atto_noautolink'; // Full name of the plugin (used for diagnostics).
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
YUI.add('moodle-atto_noautolink-button', function (Y, NAME) {
|
||||
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Atto text editor noautolink plugin.
|
||||
*
|
||||
* @package editor-atto
|
||||
* @copyright 2014 Andrew Davis <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
M.atto_noautolink = M.atto_noautolink || {
|
||||
/**
|
||||
* Initialise the plugin - Allow the user to mark text to be ignored by the glossary autolink filter.
|
||||
*
|
||||
* @method init
|
||||
* @param {Object} Initialisation settings for this plugin
|
||||
* @param {string} params.elementid The editor identifier
|
||||
* @param {string} params.group The button group
|
||||
*/
|
||||
init: function(params) {
|
||||
var click = function(e, elementid) {
|
||||
e.preventDefault();
|
||||
if (!M.editor_atto.is_active(elementid)) {
|
||||
M.editor_atto.focus(elementid);
|
||||
}
|
||||
|
||||
M.editor_atto.toggle_inline_selection_class(elementid, ['nolink']);
|
||||
|
||||
// Clean the YUI ids from the HTML.
|
||||
M.editor_atto.text_updated(elementid);
|
||||
};
|
||||
|
||||
var iconurl = M.util.image_url('e/prevent_autolink', 'core');
|
||||
M.editor_atto.add_toolbar_button(params.elementid, 'noautolink', iconurl, params.group, click);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
}, '@VERSION@', {"requires": ["node"]});
|
||||
+1
@@ -0,0 +1 @@
|
||||
YUI.add("moodle-atto_noautolink-button",function(e,t){M.atto_noautolink=M.atto_noautolink||{init:function(e){var t=function(e,t){e.preventDefault(),M.editor_atto.is_active(t)||M.editor_atto.focus(t),M.editor_atto.toggle_inline_selection_class(t,["nolink"]),M.editor_atto.text_updated(t)},n=M.util.image_url("e/prevent_autolink","core");M.editor_atto.add_toolbar_button(e.elementid,"noautolink",n,e.group,t)}}},"@VERSION@",{requires:["node"]});
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
YUI.add('moodle-atto_noautolink-button', function (Y, NAME) {
|
||||
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Atto text editor noautolink plugin.
|
||||
*
|
||||
* @package editor-atto
|
||||
* @copyright 2014 Andrew Davis <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
M.atto_noautolink = M.atto_noautolink || {
|
||||
/**
|
||||
* Initialise the plugin - Allow the user to mark text to be ignored by the glossary autolink filter.
|
||||
*
|
||||
* @method init
|
||||
* @param {Object} Initialisation settings for this plugin
|
||||
* @param {string} params.elementid The editor identifier
|
||||
* @param {string} params.group The button group
|
||||
*/
|
||||
init: function(params) {
|
||||
var click = function(e, elementid) {
|
||||
e.preventDefault();
|
||||
if (!M.editor_atto.is_active(elementid)) {
|
||||
M.editor_atto.focus(elementid);
|
||||
}
|
||||
|
||||
M.editor_atto.toggle_inline_selection_class(elementid, ['nolink']);
|
||||
|
||||
// Clean the YUI ids from the HTML.
|
||||
M.editor_atto.text_updated(elementid);
|
||||
};
|
||||
|
||||
var iconurl = M.util.image_url('e/prevent_autolink', 'core');
|
||||
M.editor_atto.add_toolbar_button(params.elementid, 'noautolink', iconurl, params.group, click);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
}, '@VERSION@', {"requires": ["node"]});
|
||||
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"name": "moodle-atto_noautolink-button",
|
||||
"builds": {
|
||||
"moodle-atto_noautolink-button": {
|
||||
"jsfiles": [
|
||||
"button.js"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Atto text editor noautolink plugin.
|
||||
*
|
||||
* @package editor-atto
|
||||
* @copyright 2014 Andrew Davis <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
M.atto_noautolink = M.atto_noautolink || {
|
||||
/**
|
||||
* Initialise the plugin - Allow the user to mark text to be ignored by the glossary autolink filter.
|
||||
*
|
||||
* @method init
|
||||
* @param {Object} Initialisation settings for this plugin
|
||||
* @param {string} params.elementid The editor identifier
|
||||
* @param {string} params.group The button group
|
||||
*/
|
||||
init: function(params) {
|
||||
var click = function(e, elementid) {
|
||||
e.preventDefault();
|
||||
if (!M.editor_atto.is_active(elementid)) {
|
||||
M.editor_atto.focus(elementid);
|
||||
}
|
||||
|
||||
M.editor_atto.toggle_inline_selection_class(elementid, ['nolink']);
|
||||
|
||||
// Clean the YUI ids from the HTML.
|
||||
M.editor_atto.text_updated(elementid);
|
||||
};
|
||||
|
||||
var iconurl = M.util.image_url('e/prevent_autolink', 'core');
|
||||
M.editor_atto.add_toolbar_button(params.elementid, 'noautolink', iconurl, params.group, click);
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"moodle-atto_noautolink-button": {
|
||||
"requires": ["node"]
|
||||
}
|
||||
}
|
||||
@@ -35,7 +35,7 @@ if ($ADMIN->fulltree) {
|
||||
$default = 'collapse = collapse
|
||||
style1 = title, bold, italic
|
||||
list = unorderedlist, orderedlist
|
||||
links = link, unlink
|
||||
links = link, unlink, noautolink
|
||||
files = image, media, managefiles
|
||||
style2 = underline, strike, subscript, superscript
|
||||
align = align
|
||||
|
||||
+66
-1
@@ -84,6 +84,10 @@ M.editor_atto = M.editor_atto || {
|
||||
'tfoot',
|
||||
'ul',
|
||||
'video'],
|
||||
|
||||
PLACEHOLDER_FONTNAME: 'yui-tmp',
|
||||
ALL_NODES_SELECTOR: '[style],font[face]',
|
||||
FONT_FAMILY: 'fontFamily',
|
||||
|
||||
/**
|
||||
* List of attached button handlers to prevent duplicates.
|
||||
@@ -1332,8 +1336,69 @@ M.editor_atto = M.editor_atto || {
|
||||
// All other browsers are great!
|
||||
document.execCommand('insertHTML', false, html);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Change the formatting for the current selection.
|
||||
* Wraps the selection in spans and adds the provides classes.
|
||||
*
|
||||
* If the selection covers multiple block elements, multiple spans will be inserted to preserve the original structure.
|
||||
*
|
||||
* @method toggle_inline_selection_class
|
||||
* @param {String} elementid - The editor elementid.
|
||||
* @param {Array} toggleclasses - Class names to be toggled on or off.
|
||||
*/
|
||||
toggle_inline_selection_class: function(elementid, toggleclasses) {
|
||||
var selectionparentnode = M.editor_atto.get_selection_parent_node(),
|
||||
root = Y.one('body'),
|
||||
nodes,
|
||||
items = [],
|
||||
parentspan,
|
||||
currentnode,
|
||||
newnode,
|
||||
i = 0;
|
||||
|
||||
if (!selectionparentnode) {
|
||||
// No selection, nothing to format.
|
||||
return;
|
||||
}
|
||||
|
||||
// Add a bogus fontname as the browsers handle inserting fonts into multiple blocks correctly.
|
||||
document.execCommand('fontname', false, M.editor_atto.PLACEHOLDER_FONTNAME);
|
||||
nodes = root.all(M.editor_atto.ALL_NODES_SELECTOR);
|
||||
|
||||
// Create a list of all nodes that have our bogus fontname.
|
||||
nodes.each(function(node, index) {
|
||||
if (node.getStyle(M.editor_atto.FONT_FAMILY) === M.editor_atto.PLACEHOLDER_FONTNAME) {
|
||||
node.setStyle(M.editor_atto.FONT_FAMILY, '');
|
||||
if (!node.compareTo(root)) {
|
||||
items.push(Y.Node.getDOMNode(nodes.item(index)));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Replace the fontname tags with spans
|
||||
for (i = 0; i < items.length; i++) {
|
||||
currentnode = Y.one(items[i]);
|
||||
|
||||
// Check for an existing span to add the nolink class to.
|
||||
parentspan = currentnode.ancestor('.editor_atto_content span');
|
||||
if (!parentspan) {
|
||||
newnode = Y.Node.create('<span></span>');
|
||||
newnode.append(items[i].innerHTML);
|
||||
currentnode.replace(newnode);
|
||||
|
||||
currentnode = newnode;
|
||||
} else {
|
||||
currentnode = parentspan;
|
||||
}
|
||||
|
||||
// Toggle the classes on the spans.
|
||||
for (var j = 0; j < toggleclasses.length; j++) {
|
||||
currentnode.toggleClass(toggleclasses[j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
var CONTROLMENU_NAME = "Controlmenu",
|
||||
CONTROLMENU;
|
||||
|
||||
+4
-3
File diff suppressed because one or more lines are too long
+66
-1
@@ -84,6 +84,10 @@ M.editor_atto = M.editor_atto || {
|
||||
'tfoot',
|
||||
'ul',
|
||||
'video'],
|
||||
|
||||
PLACEHOLDER_FONTNAME: 'yui-tmp',
|
||||
ALL_NODES_SELECTOR: '[style],font[face]',
|
||||
FONT_FAMILY: 'fontFamily',
|
||||
|
||||
/**
|
||||
* List of attached button handlers to prevent duplicates.
|
||||
@@ -1332,8 +1336,69 @@ M.editor_atto = M.editor_atto || {
|
||||
// All other browsers are great!
|
||||
document.execCommand('insertHTML', false, html);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Change the formatting for the current selection.
|
||||
* Wraps the selection in spans and adds the provides classes.
|
||||
*
|
||||
* If the selection covers multiple block elements, multiple spans will be inserted to preserve the original structure.
|
||||
*
|
||||
* @method toggle_inline_selection_class
|
||||
* @param {String} elementid - The editor elementid.
|
||||
* @param {Array} toggleclasses - Class names to be toggled on or off.
|
||||
*/
|
||||
toggle_inline_selection_class: function(elementid, toggleclasses) {
|
||||
var selectionparentnode = M.editor_atto.get_selection_parent_node(),
|
||||
root = Y.one('body'),
|
||||
nodes,
|
||||
items = [],
|
||||
parentspan,
|
||||
currentnode,
|
||||
newnode,
|
||||
i = 0;
|
||||
|
||||
if (!selectionparentnode) {
|
||||
// No selection, nothing to format.
|
||||
return;
|
||||
}
|
||||
|
||||
// Add a bogus fontname as the browsers handle inserting fonts into multiple blocks correctly.
|
||||
document.execCommand('fontname', false, M.editor_atto.PLACEHOLDER_FONTNAME);
|
||||
nodes = root.all(M.editor_atto.ALL_NODES_SELECTOR);
|
||||
|
||||
// Create a list of all nodes that have our bogus fontname.
|
||||
nodes.each(function(node, index) {
|
||||
if (node.getStyle(M.editor_atto.FONT_FAMILY) === M.editor_atto.PLACEHOLDER_FONTNAME) {
|
||||
node.setStyle(M.editor_atto.FONT_FAMILY, '');
|
||||
if (!node.compareTo(root)) {
|
||||
items.push(Y.Node.getDOMNode(nodes.item(index)));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Replace the fontname tags with spans
|
||||
for (i = 0; i < items.length; i++) {
|
||||
currentnode = Y.one(items[i]);
|
||||
|
||||
// Check for an existing span to add the nolink class to.
|
||||
parentspan = currentnode.ancestor('.editor_atto_content span');
|
||||
if (!parentspan) {
|
||||
newnode = Y.Node.create('<span></span>');
|
||||
newnode.append(items[i].innerHTML);
|
||||
currentnode.replace(newnode);
|
||||
|
||||
currentnode = newnode;
|
||||
} else {
|
||||
currentnode = parentspan;
|
||||
}
|
||||
|
||||
// Toggle the classes on the spans.
|
||||
for (var j = 0; j < toggleclasses.length; j++) {
|
||||
currentnode.toggleClass(toggleclasses[j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
var CONTROLMENU_NAME = "Controlmenu",
|
||||
CONTROLMENU;
|
||||
|
||||
+66
-1
@@ -82,6 +82,10 @@ M.editor_atto = M.editor_atto || {
|
||||
'tfoot',
|
||||
'ul',
|
||||
'video'],
|
||||
|
||||
PLACEHOLDER_FONTNAME: 'yui-tmp',
|
||||
ALL_NODES_SELECTOR: '[style],font[face]',
|
||||
FONT_FAMILY: 'fontFamily',
|
||||
|
||||
/**
|
||||
* List of attached button handlers to prevent duplicates.
|
||||
@@ -1330,6 +1334,67 @@ M.editor_atto = M.editor_atto || {
|
||||
// All other browsers are great!
|
||||
document.execCommand('insertHTML', false, html);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Change the formatting for the current selection.
|
||||
* Wraps the selection in spans and adds the provides classes.
|
||||
*
|
||||
* If the selection covers multiple block elements, multiple spans will be inserted to preserve the original structure.
|
||||
*
|
||||
* @method toggle_inline_selection_class
|
||||
* @param {String} elementid - The editor elementid.
|
||||
* @param {Array} toggleclasses - Class names to be toggled on or off.
|
||||
*/
|
||||
toggle_inline_selection_class: function(elementid, toggleclasses) {
|
||||
var selectionparentnode = M.editor_atto.get_selection_parent_node(),
|
||||
root = Y.one('body'),
|
||||
nodes,
|
||||
items = [],
|
||||
parentspan,
|
||||
currentnode,
|
||||
newnode,
|
||||
i = 0;
|
||||
|
||||
if (!selectionparentnode) {
|
||||
// No selection, nothing to format.
|
||||
return;
|
||||
}
|
||||
|
||||
// Add a bogus fontname as the browsers handle inserting fonts into multiple blocks correctly.
|
||||
document.execCommand('fontname', false, M.editor_atto.PLACEHOLDER_FONTNAME);
|
||||
nodes = root.all(M.editor_atto.ALL_NODES_SELECTOR);
|
||||
|
||||
// Create a list of all nodes that have our bogus fontname.
|
||||
nodes.each(function(node, index) {
|
||||
if (node.getStyle(M.editor_atto.FONT_FAMILY) === M.editor_atto.PLACEHOLDER_FONTNAME) {
|
||||
node.setStyle(M.editor_atto.FONT_FAMILY, '');
|
||||
if (!node.compareTo(root)) {
|
||||
items.push(Y.Node.getDOMNode(nodes.item(index)));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Replace the fontname tags with spans
|
||||
for (i = 0; i < items.length; i++) {
|
||||
currentnode = Y.one(items[i]);
|
||||
|
||||
// Check for an existing span to add the nolink class to.
|
||||
parentspan = currentnode.ancestor('.editor_atto_content span');
|
||||
if (!parentspan) {
|
||||
newnode = Y.Node.create('<span></span>');
|
||||
newnode.append(items[i].innerHTML);
|
||||
currentnode.replace(newnode);
|
||||
|
||||
currentnode = newnode;
|
||||
} else {
|
||||
currentnode = parentspan;
|
||||
}
|
||||
|
||||
// Toggle the classes on the spans.
|
||||
for (var j = 0; j < toggleclasses.length; j++) {
|
||||
currentnode.toggleClass(toggleclasses[j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user