summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNathaniel Catchpole2015-11-13 10:24:03 (GMT)
committerNathaniel Catchpole2015-11-13 10:24:03 (GMT)
commit19b0f88e41e9269fbee66a0f37beaa6b67f94d1c (patch)
tree0856b6aa7b952bc64e1db4aaa3c4469378121afa
parent5ba8a96aa55fc01fb6364f2b0a152f3d44818560 (diff)
Revert "Issue #2608434 by Wim Leers, DuaelFr: Links on images can only have href attribute"
This reverts commit 5ba8a96aa55fc01fb6364f2b0a152f3d44818560.
-rw-r--r--core/modules/ckeditor/js/plugins/drupallink/plugin.js77
1 files changed, 48 insertions, 29 deletions
diff --git a/core/modules/ckeditor/js/plugins/drupallink/plugin.js b/core/modules/ckeditor/js/plugins/drupallink/plugin.js
index 9addd4c..1717971 100644
--- a/core/modules/ckeditor/js/plugins/drupallink/plugin.js
+++ b/core/modules/ckeditor/js/plugins/drupallink/plugin.js
@@ -9,27 +9,6 @@
'use strict';
- function parseAttributes(element) {
- var parsedAttributes = {};
-
- var domElement = element.$;
- var attribute = null;
- var attributeName;
- for (var attrIndex = 0; attrIndex < domElement.attributes.length; attrIndex++) {
- attribute = domElement.attributes.item(attrIndex);
- attributeName = attribute.nodeName.toLowerCase();
- // Don't consider data-cke-saved- attributes; they're just there to work
- // around browser quirks.
- if (attributeName.substring(0, 15) === 'data-cke-saved-') {
- continue;
- }
- // Store the value for this attribute, unless there's a data-cke-saved-
- // alternative for it, which will contain the quirk-free, original value.
- parsedAttributes[attributeName] = element.data('cke-saved-' + attributeName) || attribute.nodeValue;
- }
- return parsedAttributes;
- }
-
CKEDITOR.plugins.add('drupallink', {
init: function (editor) {
// Add the commands for link and unlink.
@@ -54,16 +33,35 @@
var drupalImageUtils = CKEDITOR.plugins.drupalimage;
var focusedImageWidget = drupalImageUtils && drupalImageUtils.getFocusedWidget(editor);
var linkElement = getSelectedLink(editor);
+ var linkDOMElement = null;
// Set existing values based on selected element.
var existingValues = {};
if (linkElement && linkElement.$) {
- existingValues = parseAttributes(linkElement);
+ linkDOMElement = linkElement.$;
+
+ // Populate an array with the link's current attributes.
+ var attribute = null;
+ var attributeName;
+ for (var attrIndex = 0; attrIndex < linkDOMElement.attributes.length; attrIndex++) {
+ attribute = linkDOMElement.attributes.item(attrIndex);
+ attributeName = attribute.nodeName.toLowerCase();
+ // Don't consider data-cke-saved- attributes; they're just there
+ // to work around browser quirks.
+ if (attributeName.substring(0, 15) === 'data-cke-saved-') {
+ continue;
+ }
+ // Store the value for this attribute, unless there's a
+ // data-cke-saved- alternative for it, which will contain the
+ // quirk-free, original value.
+ existingValues[attributeName] = linkElement.data('cke-saved-' + attributeName) || attribute.nodeValue;
+ }
}
// Or, if an image widget is focused, we're editing a link wrapping
// an image widget.
else if (focusedImageWidget && focusedImageWidget.data.link) {
- existingValues = CKEDITOR.tools.clone(focusedImageWidget.data.link);
+ var url = focusedImageWidget.data.link.url;
+ existingValues.href = url.protocol + url.url;
}
// Prepare a save callback to be used upon saving the dialog.
@@ -71,7 +69,14 @@
// If an image widget is focused, we're not editing an independent
// link, but we're wrapping an image widget in a link.
if (focusedImageWidget) {
- focusedImageWidget.setData('link', CKEDITOR.tools.extend(returnValues.attributes, focusedImageWidget.data.link));
+ var urlMatch = returnValues.attributes.href.match(urlRegex);
+ focusedImageWidget.setData('link', {
+ type: 'url',
+ url: {
+ protocol: urlMatch[1],
+ url: urlMatch[2]
+ }
+ });
editor.fire('saveSnapshot');
return;
}
@@ -268,6 +273,8 @@
return null;
}
+ var urlRegex = /^((?:http|https):\/\/)?(.*)$/;
+
/**
* The image2 plugin is currently tightly coupled to the link plugin: it
* calls CKEDITOR.plugins.link.parseLinkAttributes().
@@ -282,14 +289,26 @@
*/
CKEDITOR.plugins.link = CKEDITOR.plugins.link || {
parseLinkAttributes: function (editor, element) {
- return parseAttributes(element);
+ var href = (element && (element.data('cke-saved-href') || element.getAttribute('href'))) || '';
+ var urlMatch = href.match(urlRegex);
+ return {
+ type: 'url',
+ url: {
+ protocol: urlMatch[1],
+ url: urlMatch[2]
+ }
+ };
},
getLinkAttributes: function (editor, data) {
var set = {};
- for (var attributeName in data) {
- if (data.hasOwnProperty(attributeName)) {
- set[attributeName] = data[attributeName];
- }
+
+ var protocol = (data.url && typeof data.url.protocol !== 'undefined') ? data.url.protocol : 'http://';
+ var url = (data.url && CKEDITOR.tools.trim(data.url.url)) || '';
+ set['data-cke-saved-href'] = (url.indexOf('/') === 0) ? url : protocol + url;
+
+ // Browser need the "href" fro copy/paste link to work. (#6641)
+ if (set['data-cke-saved-href']) {
+ set.href = set['data-cke-saved-href'];
}
// Remove all attributes which are not currently set.