Skip to content
This repository has been archived by the owner on Dec 12, 2019. It is now read-only.

Plugin outside of 'js/tinymce/plugins' #33

Closed
peterw8102 opened this issue Jul 27, 2017 · 5 comments
Closed

Plugin outside of 'js/tinymce/plugins' #33

peterw8102 opened this issue Jul 27, 2017 · 5 comments

Comments

@peterw8102
Copy link

I'm trying to keep non-Tinymce plugins outside of the Tinymce tree to make upgrades easier.

This plugin works fine when within js/tinymce/plugins/codemirror directory. However the following fails:

<script src="/tinymce/js/tinymce/tinymce.min.js"></script>
<script src="/myplugins/codemirror/plugin.min.js></script>

The problem is the plugin tries to load 'source.html' from the path provided by TinyMCE as a parameter to tinymce.PluginManager.add()

tinymce.PluginManager.add('codemirror', function(editor, url) {
   ...
   var config = {
      title: 'HTML source code',
      url: url+'/source.html', 
      ...

'url' here will be /tinymce/js/plugins - not where the plugin actually resides.

I've fixed this by working out the path of the currently executing script then using that as the base path for source.html.

/** Work out path of current script **/
var currentPath = (function () {
	var src;
  if (document.currentScript) {
    src = document.currentScript.src;
  }
	else {
		var scripts = document.getElementsByTagName('script');
	  src = scripts[scripts.length-1].src;
	}
	return src.replace(/[^\/]+$/,'');
})();
tinymce.PluginManager.requireLangPack('codemirror');

tinymce.PluginManager.add('codemirror', function(editor, url) {

	function showSourceEditor() {
                /** ..... **/
		var config = {
			title: 'HTML source code',
			url: currentPath+'/source.html',

I really don't like this as a solution and will look for something better. It should be possible though to have the plugin outside of the TinyMCE source tree.

@peterw8102
Copy link
Author

peterw8102 commented Jul 27, 2017

Stripping out the crud the current path can be reduced to:

var currentPath = (document.currentScript ?
                document.currentScript.src :
                Array.prototype.slice.call(document.getElementsByTagName('script')).pop().src
             ) .replace(/[^\/]+$/,'');

Still don't particularly like this. Other suggestions?

@peterw8102
Copy link
Author

I want to push a branch to this repo with suggested changed but don't have permission :(

@thomich thomich closed this as completed Jul 31, 2019
@thomich
Copy link
Collaborator

thomich commented Jul 31, 2019

Please check: #46

@thomich
Copy link
Collaborator

thomich commented Jul 31, 2019

@peterw8102 please check this issue on gitlab.. still open ;).. sorry, just moved the repo...
https://gitlab.com/tinymce-plugins/tinymce-codemirror/issues/33

but as you wrote earlier (#33 (comment)), you can make a MR and we/i will check

@peterw8102
Copy link
Author

Thanks @thomich - I realised after I'd left the other comment so deleted it. I'll start using the new repo and when I get a moment I'll look into this again. It's been quite a while now so I need to refresh my memory.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants