@@ -71,7 +71,7 @@ angular.module('searchResultApp').controller('loopResultController', ['CONFIG',
7171 // Ensure that hits titles are stream lined.
7272 var hits = data . hits ;
7373 for ( var i in hits . results ) {
74- if ( hits . results [ i ] . hasOwnProperty ( '_highlight' ) ) {
74+ if ( hits . results [ i ] . hasOwnProperty ( '_highlight' ) ) {
7575 hits . results [ i ] . title = hits . results [ i ] . _highlight . title [ 0 ] ;
7676 }
7777 }
@@ -127,6 +127,49 @@ angular.module('searchResultApp').controller('loopResultController', ['CONFIG',
127127 }
128128 } ) ;
129129
130+ /**
131+ * Helper function to ensure that the form is loaded and ready for the
132+ * jQuery hacks.
133+ *
134+ * @param data
135+ * Data from the XHR request.
136+ */
137+ function enabled_no_results_form ( data ) {
138+ // There is currently no safeway to detect if a element is ready. So we
139+ // us a simple timeout.
140+ setTimeout ( function ( ) {
141+ if ( document . getElementById ( 'edit-field-description-und-0-value' ) . length === 0 ) {
142+ enabled_no_results_form ( data ) ;
143+ }
144+ else {
145+ var no_result_text = $scope . Drupal . t ( 'Enter value.' , { } , { 'context' : 'angular' } ) ;
146+ var placeholder_text = $scope . Drupal . t ( 'Enter value.' , { } , { 'context' : 'angular' } ) ;
147+
148+ jQuery ( '.js-chosen-select-area-of-expertise' ) . chosen ( {
149+ no_results_text : no_result_text ,
150+ placeholder_text : placeholder_text
151+ } ) ;
152+
153+ jQuery ( '.js-chosen-select-profession' ) . chosen ( {
154+ no_results_text : no_result_text ,
155+ placeholder_text : placeholder_text
156+ } ) ;
157+
158+ // Make auto-complete deluxe work (hackish).
159+ Drupal . settings . autocomplete_deluxe = data . settings [ 1 ] . data . autocomplete_deluxe ;
160+ jQuery . getScript ( '/' + data . settings [ 0 ] ) . done ( function ( script , textStatus ) {
161+ Drupal . attachBehaviors ( ) ;
162+
163+ // Copy question text into the form.
164+ document . getElementById ( 'edit-field-description-und-0-value' ) . innerHTML = document . getElementById ( 'loop-search-field' ) . value ;
165+ } )
166+ . fail ( function ( jqxhr , settings , exception ) {
167+ console . error ( jqxhr . responseText ) ;
168+ } ) ;
169+ }
170+ } , 100 ) ;
171+ }
172+
130173 /**
131174 * Callback to get the "no results found" create new post form.
132175 */
@@ -136,28 +179,7 @@ angular.module('searchResultApp').controller('loopResultController', ['CONFIG',
136179 url : '/loop_search_node/not_found'
137180 } ) . then ( function successCallback ( response ) {
138181 document . getElementById ( 'no_result_form' ) . innerHTML = response . data . form ;
139-
140- var no_result_text = $scope . Drupal . t ( 'Enter value.' , { } , { 'context' : 'angular' } ) ;
141- var placeholder_text = $scope . Drupal . t ( 'Enter value.' , { } , { 'context' : 'angular' } ) ;
142-
143- jQuery ( '.js-chosen-select-area-of-expertise' ) . chosen ( {
144- no_results_text : no_result_text ,
145- placeholder_text : placeholder_text
146- } ) ;
147-
148- jQuery ( '.js-chosen-select-profession' ) . chosen ( {
149- no_results_text : no_result_text ,
150- placeholder_text : placeholder_text
151- } ) ;
152-
153- // Make auto-complete deluxe work (hackish).
154- Drupal . settings . autocomplete_deluxe = response . data . settings [ 1 ] . data . autocomplete_deluxe ;
155- jQuery . getScript ( response . data . settings [ 0 ] , function ( ) {
156- Drupal . attachBehaviors ( ) ;
157-
158- // Copy question text into the form.
159- document . getElementById ( 'edit-field-description-und-0-value' ) . innerHTML = document . getElementById ( 'loop-search-field' ) . value ;
160- } ) ;
182+ enabled_no_results_form ( response . data ) ;
161183 } ) ;
162184 }
163185 }
0 commit comments