Letractively / dynatree

Automatically exported from code.google.com/p/dynatree
0 stars 0 forks source link

Support UMD Loading #374

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What new or enhanced feature are you proposing?

Alter dynatree to support UMD/AMD Loading as per 
https://github.com/umdjs/umd/blob/master/jqueryPlugin.js or 
https://github.com/umdjs/umd/blob/master/jqueryPluginCommonjs.js

What goal would this enhancement help you achieve?

This will allow us to load dynatree in RequireJS without having to use a config 
shim.

Original issue reported on code.google.com by ll...@lloydpickering.com on 8 Nov 2012 at 2:37

GoogleCodeExporter commented 9 years ago
I did  not use  RequireJS so far (only took a quick look at curl.js)

Can you recommend a best practice to do this without breaking standard includes?
And would you expect dynatree to 'require' jQuery?

Original comment by moo...@wwwendt.de on 13 Nov 2012 at 5:33

GoogleCodeExporter commented 9 years ago
would it be enough to add this add the end of the file?

if( typeof define === "function" && define.amd ) {
    define( ["jquery"], function () {
        return jQuery.ui.dynatree;
    });
}

Original comment by moo...@wwwendt.de on 13 Nov 2012 at 5:44

GoogleCodeExporter commented 9 years ago
comment 1: I would expect dynatree would require both jquery and jquery-ui (but 
arguably you could require just jquery-ui, as it is dependent on jquery itself).

In terms of implementation, something along the lines of:

(function (factory) {
    if (typeof define === 'function' && define.amd) {
        // AMD. Register as an anonymous module.
        define(['jquery', 'jquery-ui'], factory);
    } else {
        // Browser globals
        factory(jQuery, jQuery.ui);
    }
}(function ($, jQueryUI) {
    $.ui.dynatree = function () { //dynatree stuff here};
}));

The above should be pretty much enough to support UMD/AMD loading, with one 
problem -the globals that dynatree creates (mainly for debugging I believe). It 
would be better to encapsulate them within the dynatree namespace, so they 
don't litter the global namespace. This way it wont conflict with anything else 
too. An alternative is to create them as a separate namespace as a dependency 
of dynatree, but that's probably overkill.

Original comment by ll...@lloydpickering.com on 14 Nov 2012 at 11:27

GoogleCodeExporter commented 9 years ago

Original comment by moo...@wwwendt.de on 26 Jan 2013 at 4:15

GoogleCodeExporter commented 9 years ago
Any ideas on how to get this to work? Been trying the above mentioned methods 
without any joy

Original comment by rovers...@gmail.com on 27 Aug 2013 at 10:42

GoogleCodeExporter commented 9 years ago
Closing 'Waiting' issues without timely answer

Original comment by moo...@wwwendt.de on 6 Oct 2013 at 2:09