(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 = ' 

' } ] }, { type: 'html', html: '
' } ] } ] } ], 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); } } } }; }); })();