use of external libraries with a YUI module wrapper

use of external libraries with a YUI module wrapper

av Johannes Burk -
Antall svar: 2
Bilde av Core developers Bilde av Plugin developers

Hey,

I'm currently working on a street map block plugin with some additional geolocation functionality (push latest geolocation via ajax to server and safe it in the $USER session variable). Depend on this plugin I also creating an availability plugin to restrict access by current geolocation - but this is another story.

To render the map I decided to use http://leafletjs.com/. Because both plugins needs leaflet I wrapped the lib into a YUI module like this: https://gist.github.com/jojoob/1f8f35b95d075b82c4e4

And this is how I use the module:

Y.use('M.block_geolocation.leaflet', function() {
  M.block_geolocation.leaflet.load(function() {
    // code that uses leaflet
  }
})

Currently the YUI module lives under my block plugin and the leaflet code under lib/leaflet-0.7.3. It works but I don't think that's a good practice. I also tried to put the YUI code under lib/leaflet but it seems that moodle doesn't tell YUI about code in this directory. At least I was not able to load the module. Is there a standard way for doing stuff like this in moodle?

By the way is there a better way to wrap leaflet with YUI rather than explicit call 'load' and use the slightly ugly callback after Y.Get finished?


For those interested:
https://github.com/jojoob/moodle-block_geolocation
https://github.com/jojoob/moodle-availability_geolocation


Gjennomsnittlig vurdering: -
Som svar til Johannes Burk

Re: use of external libraries with a YUI module wrapper

av Dan Poltawski -

This isn't really an answer - but just in case you haven't seen it you might be interested in future movements towards requirejs and an overhaul of our JS infrastructure - see https://moodle.org/mod/forum/discuss.php?d=268190#p1197236 and https://docs.moodle.org/dev/JS_Framework_Specification

Gjennomsnittlig vurdering:Useful (1)
Som svar til Dan Poltawski

Re: use of external libraries with a YUI module wrapper

av Johannes Burk -
Bilde av Core developers Bilde av Plugin developers
I already found this. But anyway thank you for the direct link to this specific post. This is an interesting discussion.

It seems that my requirement isn't that easy to solve at the moment. Not least because of the inconsistent way YUI is used at the moment.