Files
dokuwiki-plugin-gallery/script.js
Michael Große b0f47b822d Integration into the prosemirror WYSIWYG editor
This integrates the gallery plugin into the prosemirror WYSIWYG editor
plugin.

This is intended to serve as an example or reference implementation on how
to integrate plugins into prosemirror.

ToDo:
- [ ] better rendering of the plugin in the editor
2023-06-08 10:22:21 +02:00

65 lines
1.7 KiB
JavaScript

/* DOKUWIKI:include_once swipebox/js/jquery.swipebox.js */
/* DOKUWIKI:include script/prosemirror.js */
jQuery(function () {
/**
* Add a quicklink to the media popup
*/
function gallery_plugin() {
var $opts = jQuery('#media__opts');
if (!$opts.length) return;
if (!window.opener) return;
var glbl = document.createElement('label');
var glnk = document.createElement('a');
var gbrk = document.createElement('br');
glnk.name = 'gallery_plugin';
glnk.innerHTML = LANG.plugins.gallery.addgal; //FIXME localize
glnk.style.cursor = 'pointer';
glnk.onclick = function () {
var $h1 = jQuery('#media__ns');
if (!$h1.length) return;
var ns = $h1[0].innerHTML;
opener.insertAtCarret('wiki__text', '{{gallery>' + ns + '}}');
if (!dw_mediamanager.keepopen) window.close();
};
$opts[0].appendChild(glbl);
glbl.appendChild(glnk);
$opts[0].appendChild(gbrk);
}
/**
* Display a selected page and hide all others
*/
function gallery_pageselect(e) {
var galid = e.target.hash.substr(10, 4);
var $pages = jQuery('div.gallery__' + galid);
$pages.hide();
jQuery('#' + e.target.hash.substr(1)).show();
return false;
}
// === main ===
// initialize the lightbox mechanism
jQuery("a.lightbox, a[rel^='lightbox']").swipebox({
loopAtEnd: true
});
gallery_plugin();
// hide all pages except the first one
var $pages = jQuery('div.gallery_page');
$pages.hide();
$pages.eq(0).show();
// attach page selector
jQuery('a.gallery_pgsel').click(gallery_pageselect);
});