diff --git a/lib/FSelectMenu/Bundle/Resources/public/js/modules/fselectmenu.js b/lib/FSelectMenu/Bundle/Resources/public/js/modules/fselectmenu.js index ca03dcb..ad24032 100644 --- a/lib/FSelectMenu/Bundle/Resources/public/js/modules/fselectmenu.js +++ b/lib/FSelectMenu/Bundle/Resources/public/js/modules/fselectmenu.js @@ -1,13 +1,23 @@ -/** - * - init() has to be called only one time for the life of the page; - * newly inserted select menus will automatically be handled without - * having to call init() again. - * - init() is very lightweight, it only set up a few event handlers - * - script can work directly with the native element for most things (e.g. - * getting and changing the value) - */ -define(function() { + + +(function( root,factory ) { + if ( typeof define === "function" && define.amd ) { + + // AMD. Register as an anonymous module. + define([], factory ); + + + } else if (typeof exports === "object") { + // Node/CommonJS: + factory(); + + } else { + + // Browser globals + root.FSelectMenu = factory( ); + } +}(this, function() { var namespace = 'fselectmenu'; @@ -42,6 +52,7 @@ define(function() { selectOption: function($elem) { // .data() tries to convert the value to number this._input.val($elem.attr('data-value')).change(); + $('.fselectmenu-label').html($elem.html()); } , disabled: function() { if (this._input.prop('disabled')) { @@ -133,8 +144,16 @@ define(function() { var root = this._root , offset = root.offset() - , height = root.outerHeight() - , width = root.outerWidth(); + , height = root.outerHeight() + , width = root.outerWidth() + + if (typeof height != "number") { + height = height.height(); + } + if (typeof width != "number") { + width = width.width(); + } + this._options.css({ 'minWidth': width+'px' @@ -358,4 +377,5 @@ define(function() { return { init: init }; -}); +})); +