Based on github.com/hakimel/Ladda/pull/7 i rewrote spin.js to a class like Ladda itself. I used define instead require (http://bardevblog.wordpress.com/2013/01/05/re-learning-backbone-js-require-js-and-amd/). Now spinner is a object too.
Ladda.bind()
doesn't seems to work (or i don't understand what to expect). You could create a new button object: Ladda.create()
;
See: http://plnkr.co/edit/DuIVFP0UP8sSoek9gEZc
//https://github.com/requirejs/example-jquery-cdn
requirejs.config({
//"baseUrl": "js/lib",
enforceDefine: true,
"paths": {
"app": "app",
"jquery": "//ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min",
"spin": "spin",
"ladda": "ladda"
},
shim: {
"spin": {exports: "Spinner"},
"ladda": {
depends: "spin",
exports: "Ladda"
},
}
});
// Load the main app module to start the app
requirejs(["app/main"]);
app/main.js:
define(["jquery",'ladda','spin'], function($,ladda) {
//the jquery.alpha.js and jquery.beta.js plugins have been loaded.
$(function() {
console.log("$: " + typeof $);
console.log("ladda: " + typeof Ladda);
console.log("spin: " + typeof Spinner);
Ladda.bind($('button')[0]); //don't work ????????????
//return;
//Ladda.create('.ladda-button');
var l = Ladda.create($('button')[1]);
l.start();
// Will display a progress bar for 50% of the button width
l.setProgress( 5 );
// Stop loading
l.stop();
// Toggle between loading/not loading states
l.toggle();
// Check the current state
l.isLoading();
});
});