Skip to main content
1-Visitor
December 9, 2015
Question

Including a Javascript library shared between widgets

  • December 9, 2015
  • 1 reply
  • 2264 views

We want to create multiple widgets in an extension, all of which reference a Javascript library (specifically JQuery UI in this case, but we would like a general solution).

How can we package an extension so that all the widgets reference this library?

If we include the same JS library in multiple widgets will this break the extension?

1 reply

1-Visitor
December 10, 2015

Create a Widget with the library, and then on the documentation say that the other widgets depends on this one. All will be executed on the same context.

1-Visitor
January 18, 2016

I added a library JS to "metadata.xml. But I can't call the function from the new library. For example, with this library http://www.jqueryscript.net/other/jQuery-Plugin-To-Generate-Animated-Dynamic-Gauges-dynameter.html.

I tried this in .runtime.js:

this.afterRender = function () {

        var self = this;

var domElementId = this.jqElementId;

var widgetElement = this.jqElement;

gaugeDynaMeterElementId = domElementId + '-widget-gaugeDynaMeter-container';

        gaugeDynaMeterEl = $('<div id="'+ gaugeDynaMeterElementId +'"></div>');

        widgetElement.append(gaugeDynaMeterEl);

      

        var gaugeResult;

        var gaugeDom = $("div#" + gaugeDynaMeterElementId);

      

        $(function(){

        gaugeResult = gaugeDynaMeterElementId.dynameter({

            width: 200,

    label: 'Voltage',

    value: 280,

    min: 0.0,

    max: 300,

    unit: 'V',

    regions: {

    235.0: 'warn',

    250.0: 'error'

    }

            });

        });

            

      

    bindToolTip();

    };