- /**
- * Sets the value of a property, and updates the widget accordingly
- *
- * @param {string} property Name of property
- * @param {Mixed} value Value to set property with
- */
- configure: function ( context, property, value ) {
- var newCSS,
- $result, $results, $spanForWidth, childrenWidth,
- i, expWidth, maxWidth, text;
-
- // Validate creation using fallback values
- switch ( property ) {
- case 'fetch':
- case 'cancel':
- case 'special':
- case 'result':
- case 'update':
- case '$region':
- case 'expandFrom':
- context.config[ property ] = value;
- break;
- case 'suggestions':
- context.config[ property ] = value;
- // Update suggestions
- if ( context.data !== undefined ) {
- if ( context.data.$textbox.val().length === 0 ) {
- // Hide the div when no suggestion exist
- $.suggestions.hide( context );
- } else {
- // Rebuild the suggestions list
- context.data.$container.show();
- // Update the size and position of the list
- newCSS = {
- top: context.config.$region.offset().top + context.config.$region.outerHeight(),
- bottom: 'auto',
- width: context.config.$region.outerWidth(),
- height: 'auto'
- };
-
- // Process expandFrom, after this it is set to left or right.
- context.config.expandFrom = ( function ( expandFrom ) {
- var regionWidth, docWidth, regionCenter, docCenter,
- docDir = $( document.documentElement ).css( 'direction' ),
- $region = context.config.$region;
-
- // Backwards compatible
- if ( context.config.positionFromLeft ) {
- expandFrom = 'left';
-
- // Catch invalid values, default to 'auto'
- } else if ( $.inArray( expandFrom, [ 'left', 'right', 'start', 'end', 'auto' ] ) === -1 ) {
- expandFrom = 'auto';
- }
+ if ( delayed ) {
+ // To avoid many started/aborted requests while typing, we're gonna take a short
+ // break before trying to fetch data.
+ context.data.timerID = setTimeout( maybeFetch, context.config.delay );
+ } else {
+ maybeFetch();
+ }
+ },
+
+ /**
+ * @param {Object} context
+ */
+ special: function ( context ) {
+ // Allow custom rendering - but otherwise don't do any rendering
+ if ( typeof context.config.special.render === 'function' ) {
+ // Wait for the browser to update the value
+ setTimeout( function () {
+ // Render special
+ var $special = context.data.$container.find( '.suggestions-special' );
+ context.config.special.render.call( $special, context.data.$textbox.val(), context );
+ }, 1 );
+ }
+ },
+
+ /**
+ * Sets the value of a property, and updates the widget accordingly
+ *
+ * @param {Object} context
+ * @param {string} property Name of property
+ * @param {Mixed} value Value to set property with
+ */
+ configure: function ( context, property, value ) {
+ var newCSS,
+ $result, $results, $spanForWidth, childrenWidth,
+ i, expWidth, maxWidth, text;
+
+ // Validate creation using fallback values
+ switch ( property ) {
+ case 'fetch':
+ case 'cancel':
+ case 'special':
+ case 'result':
+ case 'update':
+ case '$region':
+ case 'expandFrom':
+ context.config[ property ] = value;
+ break;
+ case 'suggestions':
+ context.config[ property ] = value;
+ // Update suggestions
+ if ( context.data !== undefined ) {
+ if ( context.data.$textbox.val().length === 0 ) {
+ // Hide the div when no suggestion exist
+ $.suggestions.hide( context );
+ } else {
+ // Rebuild the suggestions list
+ context.data.$container.show();
+ // Update the size and position of the list
+ newCSS = {
+ top: context.config.$region.offset().top + context.config.$region.outerHeight(),
+ bottom: 'auto',
+ width: context.config.$region.outerWidth(),
+ height: 'auto'
+ };
+
+ // Process expandFrom, after this it is set to left or right.
+ context.config.expandFrom = ( function ( expandFrom ) {
+ var regionWidth, docWidth, regionCenter, docCenter,
+ docDir = $( document.documentElement ).css( 'direction' ),
+ $region = context.config.$region;
+
+ // Backwards compatible
+ if ( context.config.positionFromLeft ) {
+ expandFrom = 'left';
+
+ // Catch invalid values, default to 'auto'
+ } else if ( $.inArray( expandFrom, [ 'left', 'right', 'start', 'end', 'auto' ] ) === -1 ) {
+ expandFrom = 'auto';
+ }