Skip to content

Instantly share code, notes, and snippets.

@hongkheng
Created December 26, 2014 09:04
Show Gist options
  • Save hongkheng/474a30cbc8a4767f7d58 to your computer and use it in GitHub Desktop.
Save hongkheng/474a30cbc8a4767f7d58 to your computer and use it in GitHub Desktop.
Using AMD for custom jqueryUI widget
/* A small jqueryui widget for extending selectmenu */
(function( factory ) {
if ( typeof define === "function" && define.amd ) {
// AMD. Register as an anonymous module.
define([
"jquery"
], factory );
} else {
// Browser globals
factory( jQuery );
}
}(function( $ ) {
return $.widget("ui.customselectmenu", $.ui.selectmenu, {
// default options
options: {
optionArray: []
},
_create: function() {
this._super();
console.log(this.element);
}
});
}));
/* How to require the custom widget */
require.config({
paths: {
jquery: "/jquery/dist/jquery.min",
jqueryui: "/jquery-ui/jquery-ui.min",
customselectmenu: "/ui.customselectmenu"
},
shim: {
customselectmenu: ["jqueryui"],
}
}); // end require.config
require(["jquery","jqueryui", "customselectmenu"], function($, customselectmenu){
// Test if the widget is loaded using the jquery namespace
console.log($.ui.customselectmenu);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment