upgrade
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
.map-button {
|
||||
background-repeat: no-repeat !important;
|
||||
background-position: 5px center !important;
|
||||
padding-left: 14px !important;
|
||||
}
|
||||
|
||||
.map-button-pointer {
|
||||
background-image: url("../images/selector.png") !important;
|
||||
}
|
||||
|
||||
.map-button-remove {
|
||||
background-image: url("../images/remove.png") !important;
|
||||
}
|
||||
|
||||
.map-button-active {
|
||||
outline: 1px solid #666 !important;
|
||||
background-color: #ddd !important;
|
||||
}
|
||||
|
||||
.map-canvas-drawer {
|
||||
height: 310px;
|
||||
position: relative;
|
||||
overflow: auto;
|
||||
width: 468px;
|
||||
}
|
||||
2952
main/inc/lib/javascript/ckeditor/plugins/mapping/dialogs/imgmap.js
Normal file
2952
main/inc/lib/javascript/ckeditor/plugins/mapping/dialogs/imgmap.js
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,487 @@
|
||||
(function () {
|
||||
var mapping = (function () {
|
||||
var currentAreaId = null;
|
||||
|
||||
return {
|
||||
imgMap: null,
|
||||
imageSelected: null,
|
||||
mapSelected: null,
|
||||
previousImageMode: null,
|
||||
setMode: function (mode) {
|
||||
if (mode === 'pointer') {
|
||||
this.imgMap.is_drawing = 0;
|
||||
this.imgMap.nextShape = '';
|
||||
} else {
|
||||
this.imgMap.nextShape = mode;
|
||||
}
|
||||
|
||||
this.activateMode(mode);
|
||||
},
|
||||
activateMode: function (mode) {
|
||||
if (mapping.previousImageMode) {
|
||||
mapping.previousImageMode.removeClass('map-button-active');
|
||||
}
|
||||
|
||||
if (mode === 'pointer') {
|
||||
mapping.previousImageMode = mapping.dialog.getContentElement('info', 'btnPointer').getElement();
|
||||
mapping.previousImageMode.addClass('map-button-active');
|
||||
}
|
||||
},
|
||||
setCurrentAreaAttributes: function () {
|
||||
if (currentAreaId !== null) {
|
||||
mapping.imgMap.areas[currentAreaId].ahref = mapping.dialog.getValueOf('info', 'href');
|
||||
mapping.imgMap.areas[currentAreaId].aalt = mapping.dialog.getValueOf('info', 'alt');
|
||||
mapping.imgMap.areas[currentAreaId].atitle = mapping.dialog.getValueOf('info', 'title');
|
||||
}
|
||||
},
|
||||
onSelectedArea: function (obj) {
|
||||
mapping.setPropertiesVisible(true);
|
||||
|
||||
mapping.setCurrentAreaAttributes();
|
||||
|
||||
currentAreaId = obj.aid;
|
||||
|
||||
mapping.dialog.setValueOf('info', 'href', obj.ahref);
|
||||
mapping.dialog.setValueOf('info', 'target', obj.atarget || 'notSet');
|
||||
mapping.dialog.setValueOf('info', 'alt', obj.aalt);
|
||||
mapping.dialog.setValueOf('info', 'title', obj.atitle);
|
||||
},
|
||||
setAreaProperty: function () {
|
||||
var id = currentAreaId;
|
||||
|
||||
if (id !== null) {
|
||||
mapping.imgMap.areas[id][ "a" + this.id ] = this.getValue();
|
||||
mapping.imgMap._recalculate(id);
|
||||
}
|
||||
},
|
||||
setPropertiesVisible: function (shouldShow) {
|
||||
var fieldset = mapping.dialog.getContentElement('info', 'areaProperties');
|
||||
var fieldsetElement = fieldset.getElement();
|
||||
|
||||
if (shouldShow) {
|
||||
fieldsetElement.setStyle('visibility', '');
|
||||
} else {
|
||||
fieldsetElement.setStyle('visibility', 'hidden');
|
||||
}
|
||||
},
|
||||
generateMapHTML: function () {
|
||||
var html = '';
|
||||
|
||||
for (var i = 0; i < this.imgMap.areas.length; i++) {
|
||||
html += (function (area) {
|
||||
if (!area || area.shape === '') {
|
||||
return '';
|
||||
}
|
||||
|
||||
var html = '<area shape="' + area.shape + '"' +
|
||||
' coords="' + area.lastInput + '"';
|
||||
|
||||
if (area.aalt) {
|
||||
html += ' alt="' + area.aalt + '"';
|
||||
}
|
||||
|
||||
if (area.atitle) {
|
||||
html += ' title="' + area.atitle + '"';
|
||||
}
|
||||
|
||||
if (area.ahref) {
|
||||
html += ' href="' + area.ahref + '" data-cke-saved-href="' + area.ahref + '"';
|
||||
}
|
||||
|
||||
if (area.atarget && area.atarget !== 'notSet') {
|
||||
html += ' target="' + area.atarget + '"';
|
||||
}
|
||||
|
||||
html += '/>';
|
||||
|
||||
return html;
|
||||
})(this.imgMap.areas[i]);
|
||||
}
|
||||
|
||||
return html;
|
||||
},
|
||||
setCurrentAreaId: function (id) {
|
||||
currentAreaId = id;
|
||||
},
|
||||
dialog: null
|
||||
};
|
||||
})();
|
||||
|
||||
CKEDITOR.dialog.add('Mapping', function (editor) {
|
||||
var lang = editor.lang.mapping;
|
||||
var canvasDrawer = 'canvasContainer' + CKEDITOR.tools.getNextNumber();
|
||||
var statusContainer = 'statusContainer' + CKEDITOR.tools.getNextNumber();
|
||||
var dialogReady = false;
|
||||
|
||||
(function () {
|
||||
var plugin = editor.plugins.mapping;
|
||||
|
||||
if (CKEDITOR.env.ie && typeof window.CanvasRenderingContext2D === 'undefined') {
|
||||
CKEDITOR.scriptLoader.load(plugin.path + "lib/excanvas.js", show);
|
||||
}
|
||||
|
||||
if (typeof imgmap === 'undefined') {
|
||||
CKEDITOR.scriptLoader.load(plugin.path + "dialogs/imgmap.js", show);
|
||||
}
|
||||
|
||||
var cssNode = CKEDITOR.document.getHead().append('link');
|
||||
cssNode.setAttribute("rel", "stylesheet");
|
||||
cssNode.setAttribute("type", "text/css");
|
||||
cssNode.setAttribute("href", plugin.path + "css/mapping.css");
|
||||
})();
|
||||
|
||||
var show = function () {
|
||||
if (!dialogReady) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (typeof imgmap === 'undefined') {
|
||||
return;
|
||||
}
|
||||
|
||||
if (CKEDITOR.env.ie && typeof window.CanvasRenderingContext2D === 'undefined') {
|
||||
return;
|
||||
}
|
||||
|
||||
mapping.setCurrentAreaId(null);
|
||||
mapping.mapSelected = null;
|
||||
|
||||
var elementSelected = editor.getSelection().getSelectedElement();
|
||||
|
||||
if (!elementSelected || !elementSelected.is("img")) {
|
||||
alert(lang.youMustSelectAnImageBeforeUsingTheMapEditor);
|
||||
|
||||
mapping.dialog.hide();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
mapping.imageSelected = elementSelected;
|
||||
|
||||
var src = null;
|
||||
|
||||
if (mapping.imageSelected.data) {
|
||||
src = mapping.imageSelected.data("cke-saved-src");
|
||||
} else {
|
||||
src = mapping.imageSelected.getAttribute("_cke_saved_src");
|
||||
}
|
||||
|
||||
mapping.imageSelected = mapping.imageSelected.$;
|
||||
|
||||
mapping.imgMap = new imgmap({
|
||||
mode: "editor2",
|
||||
label: '%a',
|
||||
custom_callbacks: {
|
||||
onSelectArea: mapping.onSelectedArea,
|
||||
onRemoveArea: function () {
|
||||
mapping.setCurrentAreaId(null);
|
||||
mapping.setPropertiesVisible(false);
|
||||
},
|
||||
onStatusMessage: function (str) {
|
||||
document.getElementById(statusContainer).innerHTML = str;
|
||||
},
|
||||
onLoadImage: function (pic) {
|
||||
var ckPic = new CKEDITOR.dom.element(pic);
|
||||
ckPic.on("dragstart", function (e) {
|
||||
e.data.preventDefault();
|
||||
});
|
||||
}
|
||||
},
|
||||
pic_container: document.getElementById(canvasDrawer),
|
||||
bounding_box: false,
|
||||
lang: ''
|
||||
});
|
||||
|
||||
mapping.imgMap.loadStrings(imgmapStrings);
|
||||
mapping.imgMap.loadImage(src, parseInt(mapping.imageSelected.style.width || 0, 10), parseInt(mapping.imageSelected.style.height || 0, 10));
|
||||
|
||||
var mapname = mapping.imageSelected.getAttribute('usemap', 2) || mapping.imageSelected.usemap;
|
||||
|
||||
if (mapname) {
|
||||
mapname = mapname.substr(1);
|
||||
var maps = editor.document.$.getElementsByTagName('MAP');
|
||||
|
||||
for (var i = 0; i < maps.length; i++) {
|
||||
if (maps[i].name === mapname || maps[i].id === mapname) {
|
||||
mapping.mapSelected = maps[i];
|
||||
mapping.imgMap.setMapHTML(mapping.mapSelected);
|
||||
|
||||
mapping.dialog.setValueOf('info', 'MapName', mapname);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mapping.imgMap.config.custom_callbacks.onAddArea = function (id) {
|
||||
mapping.setPropertiesVisible(true);
|
||||
mapping.setCurrentAreaAttributes();
|
||||
mapping.setCurrentAreaId(id);
|
||||
|
||||
mapping.dialog.getContentElement('info', 'href').setValue('', true);
|
||||
mapping.dialog.getContentElement('info', 'target').setValue('notSet', true);
|
||||
mapping.dialog.getContentElement('info', 'alt').setValue('', true);
|
||||
mapping.dialog.getContentElement('info', 'title').setValue('', true);
|
||||
};
|
||||
|
||||
if (mapping.mapSelected) {
|
||||
mapping.imgMap.selectedId = 0;
|
||||
mapping.onSelectedArea(mapping.imgMap.areas[0]);
|
||||
|
||||
mapping.setMode('pointer');
|
||||
} else {
|
||||
mapping.activateMode('rect');
|
||||
}
|
||||
};
|
||||
|
||||
var removeMap = function () {
|
||||
editor.fire('saveSnapshot');
|
||||
|
||||
if (mapping.imageSelected && mapping.imageSelected.nodeName === "IMG") {
|
||||
mapping.imageSelected.removeAttribute('usemap', 0);
|
||||
}
|
||||
|
||||
if (mapping.mapSelected) {
|
||||
mapping.mapSelected.parentNode.removeChild(mapping.mapSelected);
|
||||
}
|
||||
|
||||
mapping.dialog.hide();
|
||||
};
|
||||
|
||||
return {
|
||||
title: lang.mappingProperties,
|
||||
minWidth: 600,
|
||||
minHeight: 400,
|
||||
buttons: [
|
||||
{
|
||||
type: 'button',
|
||||
label: lang.removeMap,
|
||||
onClick: removeMap
|
||||
},
|
||||
CKEDITOR.dialog.okButton,
|
||||
CKEDITOR.dialog.cancelButton
|
||||
],
|
||||
contents: [
|
||||
{
|
||||
id: 'info',
|
||||
label: editor.lang.common.generalTab,
|
||||
title: editor.lang.common.generalTab,
|
||||
elements: [
|
||||
{
|
||||
id: 'MapName',
|
||||
type: 'text',
|
||||
label: lang.mapName,
|
||||
onChange: function () {
|
||||
mapping.imgMap.mapname = this.getValue();
|
||||
}
|
||||
},
|
||||
{
|
||||
type: 'hbox',
|
||||
label: 'panels',
|
||||
widths: ['30%', '40%'],
|
||||
children: [
|
||||
{
|
||||
type: 'vbox',
|
||||
children: [
|
||||
{
|
||||
type: 'hbox',
|
||||
children: [
|
||||
{
|
||||
type: 'button',
|
||||
id: 'btnPointer',
|
||||
label: lang.selector,
|
||||
className: 'map-button map-button-pointer',
|
||||
onClick: function () {
|
||||
mapping.setMode('pointer');
|
||||
}
|
||||
},
|
||||
{
|
||||
type: 'button',
|
||||
id: 'btnRemove',
|
||||
label: lang.removeArea,
|
||||
className: 'map-button map-button-remove',
|
||||
onClick: function () {
|
||||
mapping.imgMap.removeArea(mapping.imgMap.currentid);
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
type: 'hbox',
|
||||
children: [
|
||||
{
|
||||
type: 'select',
|
||||
id: 'slcShape',
|
||||
label: lang.shape,
|
||||
items: [
|
||||
[lang.rectangle, 'rect'],
|
||||
[lang.circle, 'circle'],
|
||||
[lang.polygon, 'poly']
|
||||
],
|
||||
onChange: function () {
|
||||
mapping.setMode(this.getValue());
|
||||
}
|
||||
},
|
||||
{
|
||||
type: 'select',
|
||||
id: 'slcZoom',
|
||||
label: lang.zoom,
|
||||
onChange: function () {
|
||||
var scale = this.getValue();
|
||||
var currentImage = document.getElementById(canvasDrawer).getElementsByTagName('img')[0];
|
||||
|
||||
if (!currentImage) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!currentImage.oldwidth) {
|
||||
currentImage.oldwidth = currentImage.width;
|
||||
}
|
||||
|
||||
if (!currentImage.oldheight) {
|
||||
currentImage.oldheight = currentImage.height;
|
||||
}
|
||||
|
||||
currentImage.style.width = (currentImage.oldwidth * scale) + "px";
|
||||
currentImage.style.height = (currentImage.oldheight * scale) + "px";
|
||||
currentImage.style.minWidth = (currentImage.oldwidth * scale) + "px";
|
||||
currentImage.style.minHeight = (currentImage.oldheight * scale) + "px";
|
||||
|
||||
mapping.imgMap.scaleAllAreas(scale);
|
||||
},
|
||||
default: '1',
|
||||
items: [
|
||||
['25%', '0.25'],
|
||||
['50%', '0.5'],
|
||||
['100%', '1'],
|
||||
['200%', '2'],
|
||||
['300%', '3']
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
type: 'fieldset',
|
||||
id: 'areaProperties',
|
||||
label: lang.area,
|
||||
style: 'visibility:hidden',
|
||||
children: [
|
||||
{
|
||||
type: 'hbox',
|
||||
children: [
|
||||
{
|
||||
type: 'text',
|
||||
id: 'href',
|
||||
label: lang.link,
|
||||
onChange: mapping.setAreaProperty
|
||||
},
|
||||
{
|
||||
type: 'button',
|
||||
id: 'browse',
|
||||
label: editor.lang.common.browseServer,
|
||||
style: 'margin-top:10px;',
|
||||
hidden: 'true',
|
||||
filebrowser: 'info:href'
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
type: 'select',
|
||||
id: 'target',
|
||||
label: lang.target,
|
||||
items: [
|
||||
[lang.notSet, 'notSet'],
|
||||
[lang.targetSelf, '_self'],
|
||||
[lang.targetBlank, '_blank'],
|
||||
[lang.targetTop, '_top']
|
||||
],
|
||||
onChange: mapping.setAreaProperty
|
||||
},
|
||||
{
|
||||
type: 'text',
|
||||
id: 'title',
|
||||
label: lang.title,
|
||||
onChange: mapping.setAreaProperty
|
||||
},
|
||||
{
|
||||
type: 'text',
|
||||
id: 'alt',
|
||||
label: lang.alternativeText,
|
||||
onChange: mapping.setAreaProperty
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
type: 'html',
|
||||
html: '<p id="' + statusContainer + '"> </p>'
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
type: 'html',
|
||||
html: '<div id="' + canvasDrawer + '" class="map-canvas-drawer"></div>'
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
onLoad: function () {
|
||||
mapping.dialog = this;
|
||||
},
|
||||
onShow: function () {
|
||||
dialogReady = true;
|
||||
show();
|
||||
},
|
||||
onHide: function () {
|
||||
if (mapping.previousImageMode) {
|
||||
mapping.previousImageMode.removeClass('map-button-active');
|
||||
mapping.previousImageMode = null;
|
||||
}
|
||||
document.getElementById(canvasDrawer).innerHTML = '';
|
||||
},
|
||||
onOk: function () {
|
||||
mapping.setCurrentAreaAttributes();
|
||||
|
||||
if (mapping.imageSelected && mapping.imageSelected.nodeName === "IMG") {
|
||||
var currentGeneratedMap = mapping.generateMapHTML();
|
||||
|
||||
if (!currentGeneratedMap) {
|
||||
removeMap();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
mapping.imgMap.mapid = mapping.imgMap.mapname = mapping.dialog.getValueOf('info', 'MapName');
|
||||
|
||||
var result = editor.fire('mapping.validate', mapping.imgMap);
|
||||
|
||||
if (typeof result !== 'object') {
|
||||
return false;
|
||||
}
|
||||
|
||||
editor.fire('saveSnapshot');
|
||||
|
||||
if (!mapping.mapSelected) {
|
||||
mapping.mapSelected = editor.document.$.createElement('map');
|
||||
mapping.imageSelected.parentNode.appendChild(mapping.mapSelected);
|
||||
}
|
||||
|
||||
mapping.mapSelected.innerHTML = currentGeneratedMap;
|
||||
|
||||
if (mapping.mapSelected.name) {
|
||||
mapping.mapSelected.removeAttribute('name');
|
||||
}
|
||||
|
||||
mapping.mapSelected.name = mapping.imgMap.getMapName();
|
||||
mapping.mapSelected.id = mapping.imgMap.getMapId();
|
||||
|
||||
mapping.imageSelected.setAttribute('usemap', "#" + mapping.mapSelected.name, 0);
|
||||
|
||||
if (CKEDITOR.plugins.mapping && CKEDITOR.plugins.mapping.generate) {
|
||||
CKEDITOR.plugins.mapping.generate(mapping.imageSelected, mapping.mapSelected);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
});
|
||||
})();
|
||||
BIN
main/inc/lib/javascript/ckeditor/plugins/mapping/images/icon.png
Normal file
BIN
main/inc/lib/javascript/ckeditor/plugins/mapping/images/icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 662 B |
Binary file not shown.
|
After Width: | Height: | Size: 792 B |
Binary file not shown.
|
After Width: | Height: | Size: 659 B |
32
main/inc/lib/javascript/ckeditor/plugins/mapping/lang/es.js
Normal file
32
main/inc/lib/javascript/ckeditor/plugins/mapping/lang/es.js
Normal file
@@ -0,0 +1,32 @@
|
||||
CKEDITOR.plugins.setLang('mapping', 'es', {
|
||||
toolbar: 'Insertar/Editar zonas interactivas',
|
||||
mappingProperties: 'Propiedades de Mapping',
|
||||
removeMap: 'Quitar el mapa',
|
||||
youMustSelectAnImageBeforeUsingTheMapEditor: 'Debes elegir una imagen antes de usar el editor de mapas',
|
||||
mapName: 'Nombre del mapa',
|
||||
selector: 'Selector',
|
||||
removeArea: 'Eliminar área',
|
||||
shape: 'Forma',
|
||||
rectangle: 'Rectángulo',
|
||||
circle: 'Círculo',
|
||||
polygon: 'Polígono',
|
||||
zoom: 'Zoom',
|
||||
area: 'Área',
|
||||
link: 'Enlace (URL)',
|
||||
target: 'Destino del enlace',
|
||||
notSet: 'No establecido',
|
||||
targetSelf: 'Esta ventana',
|
||||
targetBlank: 'Ventana nueva',
|
||||
targetTop: 'Ventana principal',
|
||||
title: 'Título',
|
||||
alternativeText: 'Texto alternativo'
|
||||
});
|
||||
|
||||
window.imgmapStrings = {
|
||||
READY: '',
|
||||
RECTANGLE_DRAW: 'Pulsa MAYS para cambiar a cuadrado.',
|
||||
SQUARE_DRAW: '',
|
||||
SQUARE2_DRAW: 'Libera MAYS para cambiar a rectángulo.',
|
||||
POLYGON_DRAW: 'Usa MAYS + click para crear el último punto.',
|
||||
ERR_INVALID_COORDS: 'Coordenadas incorrectas.'
|
||||
};
|
||||
File diff suppressed because one or more lines are too long
218
main/inc/lib/javascript/ckeditor/plugins/mapping/plugin.js
Normal file
218
main/inc/lib/javascript/ckeditor/plugins/mapping/plugin.js
Normal file
@@ -0,0 +1,218 @@
|
||||
/**
|
||||
* @file Mapping plugin for CKEditor
|
||||
* Copyright (C) 2014 BeezNest Latino S.A.C
|
||||
*
|
||||
* Licensed under the terms of any of the following licenses at your
|
||||
* choice:
|
||||
*
|
||||
* - GNU General Public License Version 2 or later (the "GPL")
|
||||
* http://www.gnu.org/licenses/gpl.html
|
||||
*/
|
||||
(function () {
|
||||
CKEDITOR.plugins.add('mapping', {
|
||||
requires: ['dialog'],
|
||||
lang: ['es'],
|
||||
init: function (editor) {
|
||||
var iconPath = this.path + 'images/icon.png';
|
||||
|
||||
CKEDITOR.dialog.add('Mapping', this.path + 'dialogs/mapping.js');
|
||||
|
||||
var mappingCommand = editor.addCommand('Mapping', new CKEDITOR.dialogCommand('Mapping', {
|
||||
allowedContent: 'img[usemap];map[id,name];area[alt,coords,shape,target,title,url]'
|
||||
}));
|
||||
|
||||
mappingCommand.startDisabled = true;
|
||||
|
||||
editor.ui.addButton('Mapping', {
|
||||
label: editor.lang.mapping.toolbar,
|
||||
command: 'Mapping',
|
||||
icon: iconPath
|
||||
});
|
||||
|
||||
editor.on('doubleclick', function (evt) {
|
||||
var element = evt.data.element;
|
||||
var editor = evt.editor;
|
||||
|
||||
if (element.is('area')) {
|
||||
var map = element.getParent().$;
|
||||
var mapId = map.getAttribute('id');
|
||||
var document = editor.document.$;
|
||||
var selectedImage;
|
||||
|
||||
if (document.querySelector) {
|
||||
selectedImage = document.querySelector('img[usemap="#' + mapId + '"]');
|
||||
}
|
||||
if (selectedImage) {
|
||||
editor.getSelection().selectElement(new CKEDITOR.dom.element(selectedImage));
|
||||
|
||||
evt.data.dialog = 'Mapping';
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (element.is('img') && element.hasAttribute('usemap')) {
|
||||
editor.getSelection().selectElement(element);
|
||||
evt.data.dialog = 'Mapping';
|
||||
}
|
||||
}, null, null, 20);
|
||||
|
||||
editor.on('selectionChange', CKEDITOR.tools.bind(function (evt) {
|
||||
var elementPath = evt.data.path;
|
||||
var element = elementPath.lastElement;
|
||||
|
||||
if (!element || !element.is('img')) {
|
||||
this.setState(CKEDITOR.TRISTATE_DISABLED);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
this.setState(element.hasAttribute('usemap') ? CKEDITOR.TRISTATE_ON : CKEDITOR.TRISTATE_OFF);
|
||||
}, mappingCommand));
|
||||
|
||||
if (CKEDITOR.env.ie)
|
||||
return;
|
||||
|
||||
CKEDITOR.on('dialogDefinition', function (e) {
|
||||
if (e.data.name !== 'image')
|
||||
return;
|
||||
|
||||
var definition = e.data.definition;
|
||||
|
||||
e.removeListener();
|
||||
|
||||
definition.onOk = CKEDITOR.tools.override(definition.onOk, function (original) {
|
||||
return function () {
|
||||
original.call(this);
|
||||
|
||||
var selectedImage = this.imageElement;
|
||||
var mapName = selectedImage.getAttribute('usemap');
|
||||
|
||||
if (!mapName)
|
||||
return;
|
||||
|
||||
var map = editor.document.getById(mapName.substr(1));
|
||||
|
||||
if (!map)
|
||||
return;
|
||||
|
||||
CKEDITOR.plugins.mapping.generate(selectedImage.$, map.$);
|
||||
};
|
||||
});
|
||||
});
|
||||
|
||||
editor.on('contentDom', function (e) {
|
||||
var document = e.editor.document.$;
|
||||
var maps = document.getElementsByTagName('map');
|
||||
|
||||
for (var i = 0; i < maps.length; i++) {
|
||||
var map = maps[i];
|
||||
var name = map.name;
|
||||
var imageWithMap = document.querySelector('img[usemap="#' + name + '"]');
|
||||
|
||||
if (imageWithMap) {
|
||||
CKEDITOR.plugins.mapping.generate(imageWithMap, map);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (!CKEDITOR.plugins.mapping) {
|
||||
CKEDITOR.plugins.mapping = {};
|
||||
}
|
||||
|
||||
CKEDITOR.plugins.mapping.generate = function (baseImage, map) {
|
||||
if (CKEDITOR.env.ie) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!baseImage.width) {
|
||||
baseImage.addEventListener('load', function () {
|
||||
baseImage.removeEventListener('load', onLoad);
|
||||
|
||||
CKEDITOR.plugins.mapping.generate(baseImage, map);
|
||||
}, false);
|
||||
return;
|
||||
}
|
||||
|
||||
var doc = baseImage.ownerDocument;
|
||||
var canvas = doc.createElement('canvas');
|
||||
|
||||
canvas.setAttribute('width', baseImage.width);
|
||||
canvas.setAttribute('height', baseImage.height);
|
||||
|
||||
var context = canvas.getContext('2d');
|
||||
|
||||
if (baseImage.attributes['data-cke-saved-src']) {
|
||||
var tmpImg = new Image();
|
||||
tmpImg.src = baseImage.attributes['data-cke-saved-src'].nodeValue;
|
||||
tmpImg.width = baseImage.width;
|
||||
tmpImg.height = baseImage.height;
|
||||
|
||||
context.drawImage(tmpImg, 0, 0, baseImage.width, baseImage.height);
|
||||
} else {
|
||||
context.drawImage(baseImage, 0, 0, baseImage.width, baseImage.height);
|
||||
}
|
||||
|
||||
context.strokeStyle = "#F00";
|
||||
context.lineWidth = 2;
|
||||
context.shadowOffsetX = 0;
|
||||
context.shadowOffsetY = 0;
|
||||
context.shadowBlur = 3;
|
||||
context.shadowColor = "#DDD";
|
||||
|
||||
for (var i = 0; i < map.areas.length; i++) {
|
||||
var area = map.areas[i];
|
||||
var coords = area.coords.split(',');
|
||||
|
||||
switch (area.shape) {
|
||||
case 'circle':
|
||||
context.beginPath();
|
||||
context.arc(coords[0], coords[1], coords[2], 0, Math.PI * 2, true);
|
||||
context.closePath();
|
||||
context.stroke();
|
||||
break;
|
||||
case 'poly':
|
||||
context.beginPath();
|
||||
context.moveTo(coords[0], coords[1]);
|
||||
|
||||
for (var j = 2; j < coords.length; j += 2) {
|
||||
context.lineTo(coords[j], coords[j + 1]);
|
||||
}
|
||||
|
||||
context.closePath();
|
||||
context.stroke();
|
||||
break;
|
||||
default:
|
||||
context.strokeRect(coords[0], coords[1], coords[2] - coords[0], coords[3] - coords[1]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
baseImage.src = canvas.toDataURL();
|
||||
} catch (e) {
|
||||
console.log(e.message);
|
||||
}
|
||||
};
|
||||
},
|
||||
afterInit: function (editor) {
|
||||
if (!(CKEDITOR.env.ie && CKEDITOR.env.quirks)) {
|
||||
return;
|
||||
}
|
||||
|
||||
var dataProcessor = editor.dataProcessor;
|
||||
var htmlFilter = dataProcessor && dataProcessor.htmlFilter;
|
||||
|
||||
htmlFilter.addRules({
|
||||
elements: {
|
||||
map: function (element) {
|
||||
if (element.attributes.id && !element.attributes.name) {
|
||||
element.attributes.name = element.attributes.id;
|
||||
}
|
||||
|
||||
return element;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
})();
|
||||
Reference in New Issue
Block a user