@@ -119,8 +119,16 @@ define(function (require, exports, module) {
119119 return _ . escape ( String ( item ) ) ;
120120 } ;
121121
122- /** Converts the list of item objects into HTML list items in format required by DropdownEventHandler */
123- DropdownButton . prototype . _renderList = function ( ) {
122+ /**
123+ * Converts the list of item objects into HTML list items in format required by DropdownEventHandler
124+ * @param {!jQueryObject } parent The dropdown element
125+ * @return {!jQueryObject } The dropdown element with the rendered list items appended.
126+ */
127+ DropdownButton . prototype . _renderList = function ( parent ) {
128+ if ( ! parent ) {
129+ return null ;
130+ }
131+
124132 var html = "" ;
125133 this . items . forEach ( function ( item , i ) {
126134 if ( item === "---" ) {
@@ -131,7 +139,14 @@ define(function (require, exports, module) {
131139 html += "</a></li>" ;
132140 }
133141 } . bind ( this ) ) ;
134- return html ;
142+
143+ parent . append ( html ) ;
144+
145+ // Also trigger listRendered handler so that custom event handlers can be
146+ // set up for any custom UI in the list.
147+ $ ( this ) . triggerHandler ( "listRendered" , [ parent ] ) ;
148+
149+ return parent ;
135150 } ;
136151
137152 /**
@@ -145,11 +160,7 @@ define(function (require, exports, module) {
145160
146161 // Remove all list items and then re-create them from this.items.
147162 $ ( "li" , this . $dropdown ) . remove ( ) ;
148- this . $dropdown . append ( this . _renderList ( ) ) ;
149-
150- // Also trigger openDropdown handler so that custom event handlers can be
151- // set up for any custom UI in the list.
152- $ ( this ) . triggerHandler ( "openDropdown" , [ this . $dropdown ] ) ;
163+ this . _renderList ( this . $dropdown ) ;
153164 } ;
154165
155166 /**
@@ -185,20 +196,22 @@ define(function (require, exports, module) {
185196 Menus . closeAll ( ) ;
186197
187198 var $dropdown = $ ( "<ul class='dropdown-menu dropdownbutton-popup' tabindex='-1'>" )
188- . addClass ( this . dropdownExtraClasses ) // (no-op if unspecified)
189- . append ( this . _renderList ( ) )
199+ . addClass ( this . dropdownExtraClasses ) ; // (no-op if unspecified)
200+
201+ this . $dropdown = $dropdown ;
202+ this . _renderList ( this . $dropdown )
190203 . appendTo ( $ ( "body" ) )
191204 . data ( "attached-to" , this . $button [ 0 ] ) ; // keep ModalBar open while dropdown focused
192205
193206 // Calculate position of dropdown
194- var toggleOffset = this . $button . offset ( ) ,
195- posLeft = toggleOffset . left ,
196- posTop = toggleOffset . top + this . $button . outerHeight ( ) ,
197- elementRect = {
198- top : posTop ,
199- left : posLeft ,
200- height : $dropdown . height ( ) ,
201- width : $dropdown . width ( )
207+ var toggleOffset = this . $button . offset ( ) ,
208+ posLeft = toggleOffset . left ,
209+ posTop = toggleOffset . top + this . $button . outerHeight ( ) ,
210+ elementRect = {
211+ top : posTop ,
212+ left : posLeft ,
213+ height : $dropdown . height ( ) ,
214+ width : $dropdown . width ( )
202215 } ,
203216 clip = ViewUtils . getElementClipSize ( $ ( window ) , elementRect ) ;
204217
@@ -228,10 +241,6 @@ define(function (require, exports, module) {
228241 // Manage focus
229242 this . _lastFocus = window . document . activeElement ;
230243 $dropdown . focus ( ) ;
231-
232- this . $dropdown = $dropdown ;
233-
234- $ ( this ) . triggerHandler ( "openDropdown" , [ $dropdown ] ) ;
235244 } ;
236245
237246 /**
0 commit comments