I'm working on a Drupal 7 module to integrate an existing jQuery plugin (smallworld.js). I've added it successfully through the Libraries 2.x API in my module:
$libraries['smallworld.js'] = array(
'name' => 'SmallWorld.js',
'vendor url' => 'http://mikefowler.me/smallworld.js/',
'download url' => 'https://github.com/mikefowler/smallworld.js',
'version' => '1.0', //no version actually defined in code
'files' => array(
'js' => array('src/smallworld.js'),
'js' => array('src/smallworld.jquery.js'),
),
);
and have confirmed that the files are loading correctly. However, when I try and access the file in my Drupal jQuery, ex:
(function ($) {
Drupal.behaviors.smallworld = {
attach: function (context, settings) {
$.getJSON('/sites/all/libraries/smallworld.js/dist/world.json', function (data) {
$('.map').smallworld({
geojson: data,
});
});
}
};
}(jQuery));
It doesn't trigger, giving me the console error message "Smallworld is not a constructer."
The two files it is loading are the Smallworld library and a smaller jquery wrapper that registers the library as a jquery plugin:
$.extend($.fn, {
smallworld: function (options) {
var opts = $.extend({}, $.fn.smallworld.defaults, options);
return this.each(function () {
$(this).data('smallworld', new Smallworld(this, opts));
return this;
});
}
});
Does this wrapper also needed to be added to the same Drupal jquery namespace? If a jquery library is added through Libraries API, is there special namespacing to consider when accessing it?