JsniBundle : javascript library is unavailable

118 views
Skip to first unread message

Raphael Garnier

unread,
Feb 25, 2015, 5:16:11 PM2/25/15
to gwtq...@googlegroups.com
Hi,

Actually I like to use JsniBundle to embed external javascript libraries. Unfortunately it doesn't work for this one.

The generator create the file SVGMorpheusWrapper_SVGMorpheusJsniResource_Impl, with the following content :

public native void svgMorpheus()/*-{
(function(window, document, console){


function SVGMorpheus(element, options, callback) {
  if (!element) {
    throw new Error('SVGMorpheus > "element" is required');
  }


  if(typeof element === typeof '') {
    element=document.querySelector(element);
    if (!element) {
      throw new Error('SVGMorpheus > "element" query is not related to an existing DOM node');
    }
  }

...

return SVGMorpheus;

}.apply($wnd, [$wnd, $doc, $wnd.console]));
}-*/;


When I use $wnd.SVGMorpheus, I have this error : Uncaught TypeError: undefined is not a function 
There is no problem when the file is loaded with <script> tag.

I use an other library that works perfectly. The generated file looks like :

public native void nprogress()/*-{
(function(window, document, console){

;(function(root, factory) {
  if (typeof define === 'function' && define.amd) {
    define(factory);
  } else if (typeof exports === 'object') {
    module.exports = factory();
  } else {
    root.NProgress = factory();
  }


})(this, function() {
  var NProgress = {};

...

  return NProgress;
});

}.apply($wnd, [$wnd, $doc, $wnd.console]));
}-*/
;

and I can use $wnd.NProgess as well.

The construction of the functions is different and it seems that the 2nd way is better. Any solution to use the 1st one ?

Thanks !

Raphael Garnier

unread,
Mar 24, 2015, 7:34:16 AM3/24/15
to gwtq...@googlegroups.com
Problem solved using prepend and postpend :

 @LibrarySource(value = "fr/agfahealthcare/cassis/resources/js/svg-morpheus.js",
   prepend
= "$wnd.SVGMorpheus = (function(window, document, console){\n",
   postpend
= "\nreturn SVGMorpheus;\n}.apply($wnd, [$wnd, $doc, $wnd.console]));")
 
void svgMorpheus();

Reply all
Reply to author
Forward
0 new messages