# photonic/3.37/include/js/admin/editor.js

Photonic Gallery &amp; Lightbox for Flickr, SmugMug &amp; Others, version 3.37. 79 lines.

- Page: https://pluginprobe.com/plugins/photonic/3.37/code/include/js/admin/editor.js
- Raw: https://pluginprobe.com/plugins/photonic/3.37/raw/include/js/admin/editor.js
- Modified: 2026-04-21T23:57:10+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/photonic/3.37/code/include/js/admin/editor.js#L10-L20`.

```javascript
document.addEventListener('DOMContentLoaded', () => {
	const PhotonicEditor = () => {
		const wpEditor = document.getElementById('wp-content-wrap');
		const wizardButton = document.querySelector('#photonic-add-gallery');
		const mceTab = document.getElementById('content-tmce'), htmlTab = document.getElementById('content-html');
		const nativeMediaLibrary = new PhotonicWPNativeUI(sendDataToWizard, getDataFromWizard);
		let photonicEditorSelection = '';

		const isBlock = !!(wp.data && wp.data.select('core/block-editor') && document.body.classList.contains('block-editor-page'));
		let isTinyMCE = wpEditor ? wpEditor.classList.contains('tmce-active') : false;
		let lastClickedTab = isTinyMCE ? mceTab : htmlTab;

		if (!isBlock && !isTinyMCE) {
			nativeMediaLibrary.waitForIFrame();
		}

		if (wizardButton) {
			wizardButton.addEventListener('click', e => {
				const textArea = document.querySelector('textarea#content');
				const start = textArea.selectionStart;
				const end = textArea.selectionEnd;
				photonicEditorSelection = textArea.value.substring(start, end);
			});
		}

		if (mceTab && htmlTab) {
			[mceTab, htmlTab].forEach(button => {
				button.addEventListener('click', e => {
					if (lastClickedTab.id !== button.id) {
						lastClickedTab = button;
						if (button.id === htmlTab.id) {
							nativeMediaLibrary.waitForIFrame();
						}
					}
				});
			});
		}

		function parseEditorSelection(selection) {
			if (selection !== '' && top.wp !== undefined && top.wp.shortcode !== undefined) {
				let shortcode = top.wp.shortcode.next(Photonic_Editor_JS.shortcode, selection.trim());
				let moreShortcode = top.wp.shortcode.next(Photonic_Editor_JS.shortcode, selection.trim(), 1); // Only one shortcode at a time

				if (shortcode !== undefined && moreShortcode === undefined && shortcode.content.length === selection.trim().length) { // Selection is a valid shortcode
					return {
						shortcode: shortcode
					}
				}
				else { // Selection is not a valid shortcode
					return {
						shortcode: null,
						error: 'Not a shortcode'
					}
				}
			}
			else if (selection === '') { // Selection is blank
				return {
					shortcode: ''
				}
			}
			return null;
		}

		function sendDataToWizard(messageChannel) {
			messageChannel.port1.postMessage({
				type: 'photonicShortcode',
				object: parseEditorSelection(photonicEditorSelection),
			});
		}

		function getDataFromWizard(data) {
			const win = window.dialogArguments || opener || parent || top;
			win.send_to_editor(data.html);
		}
	};

	PhotonicEditor();
});

```
