Is there anyone who could help me with integrating this javascript to xwiki - KiCad Web Viewer | Climbers.net ?
At the begining I attached the javascript as JavaScriptExtension in objects of the page and I added CSS as StyleSheetExtension in the same way. I set both of them to be used on this page or on demand so I expect they are loaded automatically on this page. Then I inserted following code to the page:
{{velocity}}
{{html clean="false"}}
$doc.getAttachment('interior.svg').getContentAsString()
<script>
KiCadWebView.schematic('my_schematic');
</script>
{{/html}}
{{/velocity}}
But it says these errors in web inspector:
- Uncaught ReferenceError: KiCadWebView is not defined
- Uncaught Error: Mismatched anonymous define() module:… in require.min.js
It seems like the javascript (JSX) is loaded after the code above… But it doesn’t work even if I enter whole the javascript code in JSX. As I found here the second error is related to requirejs but I don’t understand the background so I just tried copy & paste solution from another thread:
{{velocity}}
{{html clean="false"}}
$doc.getAttachment('interior.svg').getContentAsString()
<script>
require.config({
paths: {
'KiCad': 'https://xwiki.example/bin/download/KiCad%20Web%20Viewer/WebHome/KiCadWebView'
}
});
require(['KiCad'], function(KiCad) {
KiCadWebView.schematic('my_schematic');
});
</script>
{{/html}}
{{/velocity}}
This is close to desired result but there is still error in web inspector:
- Uncaught ReferenceError: SVGPanZoom is not defined
Although the SVGPanZoom is in the javascript library (KiCadWebView.js).
Then I tried the most trivial way:
{{velocity}}
{{html clean="false"}}
$doc.getAttachment('interior.svg').getContentAsString()
<script>
$doc.getAttachment('KiCadWebView.js').getContentAsString()
KiCadWebView.schematic('my_schematic');
</script>
{{/html}}
{{/velocity}}
But it’s almost same:
- Uncaught ReferenceError: SVGPanZoom is not defined
- Mismatched anonymous define() module: function () { ‘use strict’;
Any help is appreciated!