Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Qlik Sense Server Mashup - Referencing external javascript library

Hi all,

New to javascript so maybe asking a silly question here.

I am trying to use an external text editor tinyMce (TinyMCE - Home) within my mashup but am having some difficulties in connecting to the js file.

In my html file, I have referenced the file using the below code:

<script src="//tinymce.cachefly.net/4.2/tinymce.min.js"></script>

From here, I am not sure how to reference the external file in my javascript file.  I have the following code but it is throwing up a connection error:

function outputText(){

    require(["//tinymce.cachefly.net/4.2/tinymce.min.js"]);

   

     tinyMCE.init({

        mode: "textareas",

        theme: "simple"

    });};

error.PNG

Would appreciate any assistance on this particular issue but also in general on how to use external libraries in conjunction with mashups!

Cheers,

Joel

1 Solution

Accepted Solutions
Stefan_Walther
Employee
Employee

Some comments:

- RequireJS requires a callback, see How to get started with RequireJS

- remove the .js at the end, this will be added by RequireJS by default

So something like that:

function outputText(){

    require(["//tinymce.cachefly.net/4.2/tinymce.min"], function() {

        tinyMCE.init({

        mode: "textareas",

        theme: "simple"

        });

     

  });

};

Not tested ... but that's the direction I think.

Please mark the appropriate replies as correct or helpful so our team and other members know that your question has been answered to your satisfaction.

Hope this helps!

Regards

Stefan

View solution in original post

3 Replies
Stefan_Walther
Employee
Employee

Some comments:

- RequireJS requires a callback, see How to get started with RequireJS

- remove the .js at the end, this will be added by RequireJS by default

So something like that:

function outputText(){

    require(["//tinymce.cachefly.net/4.2/tinymce.min"], function() {

        tinyMCE.init({

        mode: "textareas",

        theme: "simple"

        });

     

  });

};

Not tested ... but that's the direction I think.

Please mark the appropriate replies as correct or helpful so our team and other members know that your question has been answered to your satisfaction.

Hope this helps!

Regards

Stefan

Not applicable
Author

Hi Stefan,

That worked - Thanks for your help!

Cheers,

Joel

katiepuran
Contributor II
Contributor II

Hi @Stefan_Walther , thank you for the solution on mashup. I am trying similar thing into Extension but cannot get it work. I am post a question in community but no response. It took me more than a day and still no luck. Your knowledge might spot the issue very quick and save my day. Can you please review my code?

TinyMCE-Sense.js

define ([
	"./js/jquery.min",
	"./plugin/tinymce/tinymce.min",
	"./plugin/tinymce/init-tinymce"
], function () {
	return {
		paint: function ($element) {
			var html ="";
			html += '<body>' +
						'<textarea class="tinymce"></textarea>' +
						'<script type="text/javascript" src="js/jquery.min.js"></script>' +
						'<script type="text/javascript" src="plugin/tinymce/tinymce.min.js"></script>' +
						'<script type="text/javascript" src="plugin/tinymce/init-tinymce.js"></script>'	+
					'</body>';
				$element.html(html)
		}
	};
});

2020-03-30_17-43-31.jpg