-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #90 from netgen/fix-editor-resource-type-detection
Fix editor resource type detection
- Loading branch information
Showing
5 changed files
with
84 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
130 changes: 65 additions & 65 deletions
130
...sh_legacy/ngremotemedia/design/standard/javascript/plugins/ngremotemedia/editor_plugin.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,84 +1,84 @@ | ||
/* eslint-disable prefer-arrow-callback */ | ||
(function (tinymce) { | ||
function insertMediaCallback(data, caption, align, cssClass) { | ||
var imageUrl = ''; | ||
if (data.type === 'image') { | ||
if (data.variation_url !== null) { | ||
imageUrl = data.variation_url; | ||
} else if (data.url !== null) { | ||
imageUrl = data.url; | ||
} | ||
} else if (data.type === 'video' && data.thumbnail_url !== null && data.thumbnail_url !== '') { | ||
imageUrl = data.thumbnail_url; | ||
} | ||
function insertMediaCallback(data, caption, align, cssClass) { | ||
var imageUrl = ''; | ||
if (data.mediaType === 'image') { | ||
if (data.variation_url !== null) { | ||
imageUrl = data.variation_url; | ||
} else if (data.url !== null) { | ||
imageUrl = data.url; | ||
} | ||
} else if (data.mediaType === 'video' && data.thumbnail_url !== null && data.thumbnail_url !== '') { | ||
imageUrl = data.thumbnail_url; | ||
} | ||
|
||
let previewUrl = imageUrl !== '' ? imageUrl : '/extension/ezoe/design/standard/images/tango/mail-attachment.png'; | ||
let elementClass = "ezoeItemCustomTag ngremotemedia"; | ||
let alignAttr = ''; | ||
let previewUrl = imageUrl !== '' ? imageUrl : '/extension/ezoe/design/standard/images/tango/mail-attachment.png'; | ||
let elementClass = "ezoeItemCustomTag ngremotemedia"; | ||
let alignAttr = ''; | ||
|
||
if (typeof align !== 'undefined' && align !== '') { | ||
elementClass += (' ezoeAlign' + align); | ||
alignAttr = 'align="'+align+'"'; | ||
} | ||
if (typeof align !== 'undefined' && align !== '') { | ||
elementClass += (' ezoeAlign' + align); | ||
alignAttr = 'align="'+align+'"'; | ||
} | ||
|
||
let html = '<img type="custom" src="'+previewUrl+'"' | ||
+ 'data-mce-src="'+previewUrl+'"' | ||
+ alignAttr | ||
+ 'customattributes=\'caption|'+caption+'attribute_separationcssclass|'+cssClass+'attribute_separationcoords|'+JSON.stringify(data.image_variations) | ||
+ 'attribute_separationresourceId|'+data.resourceId+'attribute_separationresourceType|'+data.type+'attribute_separationimage_url|'+imageUrl | ||
+ 'attribute_separationvariation|'+data.selected_variation+'\'"'+'class="'+elementClass+'" style="">'; | ||
let html = '<img type="custom" src="'+previewUrl+'"' | ||
+ 'data-mce-src="'+previewUrl+'"' | ||
+ alignAttr | ||
+ 'customattributes=\'caption|'+caption+'attribute_separationcssclass|'+cssClass+'attribute_separationcoords|'+JSON.stringify(data.image_variations) | ||
+ 'attribute_separationresourceId|'+data.resourceId+'attribute_separationresourceType|'+data.type+'attribute_separationimage_url|'+imageUrl | ||
+ 'attribute_separationvariation|'+data.selected_variation+'\'"'+'class="'+elementClass+'" style="">'; | ||
|
||
tinymce.execCommand('mceInsertContent', false, html); | ||
} | ||
tinymce.execCommand('mceInsertContent', false, html); | ||
} | ||
|
||
tinymce.PluginManager.add("ngremotemedia", function (editor) { | ||
const fieldId = editor.settings.ez_attribute_id; | ||
tinymce.PluginManager.add("ngremotemedia", function (editor) { | ||
const fieldId = editor.settings.ez_attribute_id; | ||
|
||
window[`remoteMedia` + fieldId].setEditorInsertCallback(insertMediaCallback); | ||
window[`remoteMedia` + fieldId].setEditorInsertCallback(insertMediaCallback); | ||
|
||
// Add a button that opens a modal | ||
editor.addButton("ngremotemedia", { | ||
title: "Insert remote media", | ||
image: "/bundles/netgenremotemedia/img/cloud-upload-alt.svg", | ||
onclick() { | ||
let attributeType = tinymce.activeEditor.selection.getNode().getAttribute('type'); | ||
let attributeString = tinymce.activeEditor.selection.getNode().getAttribute('customattributes'); | ||
let hasNgrmClass = tinymce.activeEditor.selection.getNode().classList.contains('ngremotemedia'); | ||
// Add a button that opens a modal | ||
editor.addButton("ngremotemedia", { | ||
title: "Insert remote media", | ||
image: "/bundles/netgenremotemedia/img/cloud-upload-alt.svg", | ||
onclick() { | ||
let attributeType = tinymce.activeEditor.selection.getNode().getAttribute('type'); | ||
let attributeString = tinymce.activeEditor.selection.getNode().getAttribute('customattributes'); | ||
let hasNgrmClass = tinymce.activeEditor.selection.getNode().classList.contains('ngremotemedia'); | ||
|
||
var data = {}; | ||
if (attributeType === 'custom' && hasNgrmClass === true && attributeString) { | ||
data.align = tinymce.activeEditor.selection.getNode().getAttribute('align'); | ||
let attributes = attributeString.split('attribute_separation'); | ||
var data = {}; | ||
if (attributeType === 'custom' && hasNgrmClass === true && attributeString) { | ||
data.align = tinymce.activeEditor.selection.getNode().getAttribute('align'); | ||
let attributes = attributeString.split('attribute_separation'); | ||
|
||
attributes.forEach(function (attribute) { | ||
let attributeKey = attribute.split('|')[0]; | ||
let attributeValue = attribute.split('|')[1]; | ||
attributes.forEach(function (attribute) { | ||
let attributeKey = attribute.split('|')[0]; | ||
let attributeValue = attribute.split('|')[1]; | ||
|
||
if (attributeKey === 'coords' || attributeKey === 'image_variations') { | ||
try { | ||
data['image_variations'] = JSON.parse(attributeValue); | ||
} catch(e) { | ||
data['image_variations'] = {}; | ||
} | ||
if (attributeKey === 'coords' || attributeKey === 'image_variations') { | ||
try { | ||
data['image_variations'] = JSON.parse(attributeValue); | ||
} catch(e) { | ||
data['image_variations'] = {}; | ||
} | ||
|
||
return; | ||
} | ||
return; | ||
} | ||
|
||
data[attributeKey] = attributeValue; | ||
}); | ||
} | ||
data[attributeKey] = attributeValue; | ||
}); | ||
} | ||
|
||
window[`remoteMedia` + fieldId].openEditorInsertModal(data); | ||
}, | ||
}); | ||
window[`remoteMedia` + fieldId].openEditorInsertModal(data); | ||
}, | ||
}); | ||
|
||
return { | ||
getMetadata() { | ||
return { | ||
getMetadata() { | ||
return { | ||
name: "Netgen remote media", | ||
url: "https://github.com/netgen/NetgenRemoteMediaBundle", | ||
}; | ||
}, | ||
name: "Netgen remote media", | ||
url: "https://github.com/netgen/NetgenRemoteMediaBundle", | ||
}; | ||
}); | ||
}, | ||
}; | ||
}); | ||
})(tinymce); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters