mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
8f23fa99a5
The 'admin' module will be split off from 'framework', where 'framework' only provides (mostly) frontend-agnostic PHP classes. For example, HTMLEditorField.php has a TinyMCEConfig.php driver, but doesn't come with its own JS includes.
55 lines
1.2 KiB
JavaScript
55 lines
1.2 KiB
JavaScript
/**
|
|
* plugin.js
|
|
*
|
|
* Released under LGPL License.
|
|
* Copyright (c) 1999-2015 Ephox Corp. All rights reserved
|
|
*
|
|
* License: http://www.tinymce.com/license
|
|
* Contributing: http://www.tinymce.com/contributing
|
|
*/
|
|
|
|
/*global tinymce:true */
|
|
|
|
tinymce.PluginManager.add('anchor', function(editor) {
|
|
function showDialog() {
|
|
var selectedNode = editor.selection.getNode(), name = '';
|
|
var isAnchor = selectedNode.tagName == 'A' && editor.dom.getAttrib(selectedNode, 'href') === '';
|
|
|
|
if (isAnchor) {
|
|
name = selectedNode.name || selectedNode.id || '';
|
|
}
|
|
|
|
editor.windowManager.open({
|
|
title: 'Anchor',
|
|
body: {type: 'textbox', name: 'name', size: 40, label: 'Name', value: name},
|
|
onsubmit: function(e) {
|
|
var id = e.data.name;
|
|
|
|
if (isAnchor) {
|
|
selectedNode.id = id;
|
|
} else {
|
|
editor.selection.collapse(true);
|
|
editor.execCommand('mceInsertContent', false, editor.dom.createHTML('a', {
|
|
id: id
|
|
}));
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
editor.addCommand('mceAnchor', showDialog);
|
|
|
|
editor.addButton('anchor', {
|
|
icon: 'anchor',
|
|
tooltip: 'Anchor',
|
|
onclick: showDialog,
|
|
stateSelector: 'a:not([href])'
|
|
});
|
|
|
|
editor.addMenuItem('anchor', {
|
|
icon: 'anchor',
|
|
text: 'Anchor',
|
|
context: 'insert',
|
|
onclick: showDialog
|
|
});
|
|
}); |