How can I convert or put jquery namespace plugin into require boilerplate? For intstance,
This is my standard jquery boilerplate usually,
// A namepace structure:
(function($){
// Initial setting.
var pluginName = 'BR_account';
var storageName = 'plugin_' + pluginName;
var methods = {
init : function( options ) {
console.log("this is a jquery plugin boilerplate in requirejs boilerplate"); // nothing returned.
}
};
$.fn[pluginName] = function( method ) {
if ( methods[method] ) {
return methods[method].apply( this, Array.prototype.slice.call( arguments, 1 ));
} else if ( typeof method === 'object' || ! method ) {
return methods.init.apply( this, arguments ); // always change 'init' to something else if you different method name.
} else {
$.error( 'Method ' + method + ' does not exist on jQuery.' + pluginName + '.' );
}
return this;
};
$.fn[pluginName].defaults = {
onSuccess: function() {}
};
})(jQuery);
And this is the require boilerplate usually,
//Filename: boilerplate.js
define([
// These are path alias that we configured in our bootstrap
'jquery', // lib/jquery/jquery
'underscore', // lib/underscore/underscore
'backbone' // lib/backbone/backbone
], function($, _, Backbone){
// Above we have passed in jQuery, Underscore and Backbone
// They will not be accessible in the global scope
return {};
// What we return here will be used by other modules
});
But how can I mix them together - or maybe I shouldn't??
This is my test,
define([
'jquery',
'underscore',
'backbone'
], function($, _, Backbone){
console.log(Backbone); // I get an object of Backbone
// A namepace structure:
(function($){
// Initial setting.
var pluginName = 'BR_account';
var storageName = 'plugin_' + pluginName;
var methods = {
init : function( options ) {
console.log("this is a jquery plugin boilerplate in requirejs boilerplate"); // nothing returned.
}
};
$.fn[pluginName] = function( method ) {
if ( methods[method] ) {
return methods[method].apply( this, Array.prototype.slice.call( arguments, 1 ));
} else if ( typeof method === 'object' || ! method ) {
return methods.init.apply( this, arguments ); // always change 'init' to something else if you different method name.
} else {
$.error( 'Method ' + method + ' does not exist on jQuery.' + pluginName + '.' );
}
return this;
};
$.fn[pluginName].defaults = {
onSuccess: function() {}
};
})(jQuery);
});
It is not working of course. Any ideas?