How can I reference my js libraries in custom extension widget
Hi Guys,
I have one question.
How can one add a js library for a custom widget extension without copying it directly into the extension.runtime.js?
We have made a custom extension which uses d3.js and d3-tip.js (newest version, not that depricated and modified version). We had to copy its contents directly into the extension.runtime.js.
I have looked at CustomChartWidgets (which they messed up FontLabel widget btw..) and there is a subfolder in ui folder:
ui/barChart/include/d3/d3.js
in barChart.runtime.js is following function (jquery):
(function () {
// loader for extension libs
$('head').append('<link rel="stylesheet" href="../Common/extensions/chartWidget_ExtensionPackage/ui/barChart/include/nvd3/nv.d3.css" type="text/css">');
$('head').append('<script type="text/javascript" src="../Common/extensions/chartWidget_ExtensionPackage/ui/barChart/include/d3/d3.js"></script>');
}());
so I made the same, but you know referencing my extension and my libraries.
(function(){
$("body").append('<script type="text/javascript” src="../Common/extensions/NetworkSchema/ui/include/d3/d3.js"></script>');
$("body").append('<script type="text/javascript” src="../Common/extensions/NetworkSchema/ui/include/d3/d3_tip.js"></script>');
}());
I also made a pure js version of it:
document.getElementsByTagName('body')[0].appendChild('<script type="text/javascript” src="../Common/extensions/NetworkSchema/ui/include/d3/d3.js"></script>');
document.getElementsByTagName('body')[0].appendChild('<script type="text/javascript” src="../Common/extensions/NetworkSchema/ui/include/d3/d3_tip.js"></script>');
But neither of those seem to do the trick.
Any advice?
One followup - how does the concat function (which makes that combined.extension.js) handles duplicate libraries?
If I add one extension which contains let say myLibrary.js and then I add another which has the same library (directly and/or as reference/link), what could happen?
Is that being taken care off somehow?
Is there any way how to reference from my extension js libraries that I need?
Let say that I have access to target machine, so I can copy libraries directly into the Thingworx/Common directory. Is that wise even?
Why I need to do it?
We had append d3.js directly into our extension.runtime.js, but there must be a bug in TW 6.5.2 extension import parsing function.
There are special characters inside our extension (d3.js contains special characters like euler numbers, pi etc...) and after extension has been added combine.extension.js
contained jibberish like this:
var ε = 1e-6, ε2 = ε * ε, π = Math.PI, τ = 2 * π, τε = τ - ε, halfπ = π / 2, d3_radians = π / 180, d3_degrees = 180 / π;
instead of this:
var ε = 1e-6, ε2 = ε * ε, π = Math.PI, τ = 2 * π, τε = τ - ε, halfπ = π / 2, d3_radians = π / 180, d3_degrees = 180 / π;
so we had to manually repair entire combined.etension.js, which is pain
further more, if we add another extension now, it makes that CAT process again and we end up at the same place.
We have not noticed this behaveuior in TW 6.6 and 7.1
If I make my libraries being referenced indirectly, this might help us avoid that issue.
Thanks
Tomas

