Вход Регистрация
Файл: plugins/google_map_location/static/js/jquery.ui.autocomplete.js
Строк: 721
<?php
/*!
 * jQuery UI Autocomplete 1.10.3
 * http://jqueryui.com
 *
 * Copyright 2013 jQuery Foundation and other contributors
 * Released under the MIT license.
 * http://jquery.org/license
 *
 * http://api.jqueryui.com/autocomplete/
 *
 * Depends:
 *    jquery.ui.core.js
 *    jquery.ui.widget.js
 *    jquery.ui.position.js
 *    jquery.ui.menu.js
 */
(function( $, undefined ) {

// used to prevent race conditions with remote data sources
var requestIndex 0;

$.
widget"ui.autocomplete", {
    
version"1.10.3",
    
defaultElement"<input>",
    
options: {
        
appendTonull,
        
autoFocusfalse,
        
delay300,
        
minLength1,
        
position: {
            
my"left top",
            
at"left bottom",
            
collision"none"
        
},
        
sourcenull,

        
// callbacks
        
changenull,
        
closenull,
        
focusnull,
        
opennull,
        
responsenull,
        
searchnull,
        
selectnull
    
},

    
pending0,

    
_create: function() {
        
// Some browsers only repeat keydown events, not keypress events,
        // so we use the suppressKeyPress flag to determine if we've already
        // handled the keydown event. #7269
        // Unfortunately the code for & in keypress is the same as the up arrow,
        // so we use the suppressKeyPressRepeat flag to avoid handling keypress
        // events when we know the keydown event was used to modify the
        // search term. #7799
        
var suppressKeyPresssuppressKeyPressRepeatsuppressInput,
            
nodeName this.element[0].nodeName.toLowerCase(),
            
isTextarea nodeName === "textarea",
            
isInput nodeName === "input";

        
this.isMultiLine =
            
// Textareas are always multi-line
            
isTextarea true :
            
// Inputs are always single-line, even if inside a contentEditable element
            // IE also treats inputs as contentEditable
            
isInput false :
            
// All other element types are determined by whether or not they're contentEditable
            
this.element.prop"isContentEditable" );

        
this.valueMethod this.elementisTextarea || isInput "val" "text" ];
        
this.isNewMenu true;

        
this.element
            
.addClass"ui-autocomplete-input" )
            .
attr"autocomplete""off" );

        
this._onthis.element, {
            
keydown: function( event ) {
                
/*jshint maxcomplexity:15*/
                
if ( this.element.prop"readOnly" ) ) {
                    
suppressKeyPress true;
                    
suppressInput true;
                    
suppressKeyPressRepeat true;
                    return;
                }

                
suppressKeyPress false;
                
suppressInput false;
                
suppressKeyPressRepeat false;
                var 
keyCode = $.ui.keyCode;
                switch( 
event.keyCode ) {
                case 
keyCode.PAGE_UP:
                    
suppressKeyPress true;
                    
this._move"previousPage"event );
                    break;
                case 
keyCode.PAGE_DOWN:
                    
suppressKeyPress true;
                    
this._move"nextPage"event );
                    break;
                case 
keyCode.UP:
                    
suppressKeyPress true;
                    
this._keyEvent"previous"event );
                    break;
                case 
keyCode.DOWN:
                    
suppressKeyPress true;
                    
this._keyEvent"next"event );
                    break;
                case 
keyCode.ENTER:
                case 
keyCode.NUMPAD_ENTER:
                    
// when menu is open and has focus
                    
if ( this.menu.active ) {
                        
// #6055 - Opera still allows the keypress to occur
                        // which causes forms to submit
                        
suppressKeyPress true;
                        
event.preventDefault();
                        
this.menu.selectevent );
                    }
                    break;
                case 
keyCode.TAB:
                    if ( 
this.menu.active ) {
                        
this.menu.selectevent );
                    }
                    break;
                case 
keyCode.ESCAPE:
                    if ( 
this.menu.element.is":visible" ) ) {
                        
this._valuethis.term );
                        
this.closeevent );
                        
// Different browsers have different default behavior for escape
                        // Single press can mean undo or clear
                        // Double press in IE means clear the whole form
                        
event.preventDefault();
                    }
                    break;
                default:
                    
suppressKeyPressRepeat true;
                    
// search timeout should be triggered before the input value is changed
                    
this._searchTimeoutevent );
                    break;
                }
            },
            
keypress: function( event ) {
                if ( 
suppressKeyPress ) {
                    
suppressKeyPress false;
                    if ( !
this.isMultiLine || this.menu.element.is":visible" ) ) {
                        
event.preventDefault();
                    }
                    return;
                }
                if ( 
suppressKeyPressRepeat ) {
                    return;
                }

                
// replicate some key handlers to allow them to repeat in Firefox and Opera
                
var keyCode = $.ui.keyCode;
                switch( 
event.keyCode ) {
                case 
keyCode.PAGE_UP:
                    
this._move"previousPage"event );
                    break;
                case 
keyCode.PAGE_DOWN:
                    
this._move"nextPage"event );
                    break;
                case 
keyCode.UP:
                    
this._keyEvent"previous"event );
                    break;
                case 
keyCode.DOWN:
                    
this._keyEvent"next"event );
                    break;
                }
            },
            
input: function( event ) {
                if ( 
suppressInput ) {
                    
suppressInput false;
                    
event.preventDefault();
                    return;
                }
                
this._searchTimeoutevent );
            },
            
focus: function() {
                
this.selectedItem null;
                
this.previous this._value();
            },
            
blur: function( event ) {
                if ( 
this.cancelBlur ) {
                    
delete this.cancelBlur;
                    return;
                }

                
clearTimeoutthis.searching );
                
this.closeevent );
                
this._changeevent );
            }
        });

        
this._initSource();
        
this.menu = $( "<ul>" )
            .
addClass"ui-autocomplete ui-front" )
            .
appendTothis._appendTo() )
            .
menu({
                
// disable ARIA support, the live region takes care of that
                
rolenull
            
})
            .
hide()
            .
data"ui-menu" );

        
this._onthis.menu.element, {
            
mousedown: function( event ) {
                
// prevent moving focus out of the text field
                
event.preventDefault();

                
// IE doesn't prevent moving focus even with event.preventDefault()
                // so we set a flag to know when we should ignore the blur event
                
this.cancelBlur true;
                
this._delay(function() {
                    
delete this.cancelBlur;
                });

                
// clicking on the scrollbar causes focus to shift to the body
                // but we can't detect a mouseup or a click immediately afterward
                // so we have to track the next mousedown and close the menu if
                // the user clicks somewhere outside of the autocomplete
                
var menuElement this.menu.element];
                if ( !$( 
event.target ).closest".ui-menu-item" ).length ) {
                    
this._delay(function() {
                        var 
that this;
                        
this.document.one"mousedown", function( event ) {
                            if ( 
event.target !== that.element] &&
                                    
event.target !== menuElement &&
                                    !$.
containsmenuElementevent.target ) ) {
                                
that.close();
                            }
                        });
                    });
                }
            },
            
menufocus: function( eventui ) {
                
// support: Firefox
                // Prevent accidental activation of menu items in Firefox (#7024 #9118)
                
if ( this.isNewMenu ) {
                    
this.isNewMenu false;
                    if ( 
event.originalEvent && /^mouse/.testevent.originalEvent.type ) ) {
                        
this.menu.blur();

                        
this.document.one"mousemove", function() {
                            $( 
event.target ).triggerevent.originalEvent );
                        });

                        return;
                    }
                }

                var 
item ui.item.data"ui-autocomplete-item" );
                if ( 
false !== this._trigger"focus"event, { itemitem } ) ) {
                    
// use value to match what will end up in the input, if it was a key event
                    
if ( event.originalEvent && /^key/.testevent.originalEvent.type ) ) {
                        
this._valueitem.value );
                    }
                } else {
                    
// Normally the input is populated with the item's value as the
                    // menu is navigated, causing screen readers to notice a change and
                    // announce the item. Since the focus event was canceled, this doesn't
                    // happen, so we update the live region so that screen readers can
                    // still notice the change and announce it.
                    
this.liveRegion.textitem.value );
                }
            },
            
menuselect: function( eventui ) {
                var 
item ui.item.data"ui-autocomplete-item" ),
                    
previous this.previous;

                
// only trigger when focus was lost (click on menu)
                
if ( this.element[0] !== this.document[0].activeElement ) {
                    
this.element.focus();
                    
this.previous previous;
                    
// #6109 - IE triggers two focus events and the second
                    // is asynchronous, so we need to reset the previous
                    // term synchronously and asynchronously :-(
                    
this._delay(function() {
                        
this.previous previous;
                        
this.selectedItem item;
                    });
                }

                if ( 
false !== this._trigger"select"event, { itemitem } ) ) {
                    
this._valueitem.value );
                }
                
// reset the term after the select event
                // this allows custom select handling to work properly
                
this.term this._value();

                
this.closeevent );
                
this.selectedItem item;
            }
        });

        
this.liveRegion = $( "<span>", {
                
role"status",
                
"aria-live""polite"
            
})
            .
addClass"ui-helper-hidden-accessible" )
            .
insertBeforethis.element );

        
// turning off autocomplete prevents the browser from remembering the
        // value when navigating through history, so we re-enable autocomplete
        // if the page is unloaded before the widget is destroyed. #7790
        
this._onthis.window, {
            
beforeunload: function() {
                
this.element.removeAttr"autocomplete" );
            }
        });
    },

    
_destroy: function() {
        
clearTimeoutthis.searching );
        
this.element
            
.removeClass"ui-autocomplete-input" )
            .
removeAttr"autocomplete" );
        
this.menu.element.remove();
        
this.liveRegion.remove();
    },

    
_setOption: function( keyvalue ) {
        
this._superkeyvalue );
        if ( 
key === "source" ) {
            
this._initSource();
        }
        if ( 
key === "appendTo" ) {
            
this.menu.element.appendTothis._appendTo() );
        }
        if ( 
key === "disabled" && value && this.xhr ) {
            
this.xhr.abort();
        }
    },

    
_appendTo: function() {
        var 
element this.options.appendTo;

        if ( 
element ) {
            
element element.jquery || element.nodeType ?
                $( 
element ) :
                
this.document.findelement ).eq);
        }

        if ( !
element ) {
            
element this.element.closest".ui-front" );
        }

        if ( !
element.length ) {
            
element this.document[0].body;
        }

        return 
element;
    },

    
_initSource: function() {
        var array, 
url,
            
that this;
        if ( $.
isArray(this.options.source) ) {
            array = 
this.options.source;
            
this.source = function( requestresponse ) {
                
response( $.ui.autocomplete.filter( array, request.term ) );
            };
        } else if ( 
typeof this.options.source === "string" ) {
            
url this.options.source;
            
this.source = function( requestresponse ) {
                if ( 
that.xhr ) {
                    
that.xhr.abort();
                }
                
that.xhr = $.ajax({
                    
urlurl,
                    
datarequest,
                    
dataType"json",
                    
success: function( data ) {
                        
responsedata );
                    },
                    
error: function() {
                        
response( [] );
                    }
                });
            };
        } else {
            
this.source this.options.source;
        }
    },

    
_searchTimeout: function( event ) {
        
clearTimeoutthis.searching );
        
this.searching this._delay(function() {
            
// only search if the value has changed
            
if ( this.term !== this._value() ) {
                
this.selectedItem null;
                
this.searchnullevent );
            }
        }, 
this.options.delay );
    },

    
search: function( valueevent ) {
        
value value != null value this._value();

        
// always save the actual value, not the one passed as an argument
        
this.term this._value();

        if ( 
value.length this.options.minLength ) {
            return 
this.closeevent );
        }

        if ( 
this._trigger"search"event ) === false ) {
            return;
        }

        return 
this._searchvalue );
    },

    
_search: function( value ) {
        
this.pending++;
        
this.element.addClass"ui-autocomplete-loading" );
        
this.cancelSearch false;

        
this.source( { termvalue }, this._response() );
    },

    
_response: function() {
        var 
that this,
            
index = ++requestIndex;

        return function( 
content ) {
            if ( 
index === requestIndex ) {
                
that.__responsecontent );
            }

            
that.pending--;
            if ( !
that.pending ) {
                
that.element.removeClass"ui-autocomplete-loading" );
            }
        };
    },

    
__response: function( content ) {
        if ( 
content ) {
            
content this._normalizecontent );
        }
        
this._trigger"response"null, { contentcontent } );
        if ( !
this.options.disabled && content && content.length && !this.cancelSearch ) {
            
this._suggestcontent );
            
this._trigger"open" );
        } else {
            
// use ._close() instead of .close() so we don't cancel future searches
            
this._close();
        }
    },

    
close: function( event ) {
        
this.cancelSearch true;
        
this._closeevent );
    },

    
_close: function( event ) {
        if ( 
this.menu.element.is":visible" ) ) {
            
this.menu.element.hide();
            
this.menu.blur();
            
this.isNewMenu true;
            
this._trigger"close"event );
        }
    },

    
_change: function( event ) {
        if ( 
this.previous !== this._value() ) {
            
this._trigger"change"event, { itemthis.selectedItem } );
        }
    },

    
_normalize: function( items ) {
        
// assume all items have the right format when the first item is complete
        
if ( items.length && items[0].label && items[0].value ) {
            return 
items;
        }
        return $.
mapitems, function( item ) {
            if ( 
typeof item === "string" ) {
                return {
                    
labelitem,
                    
valueitem
                
};
            }
            return $.
extend({
                
labelitem.label || item.value,
                
valueitem.value || item.label
            
}, item );
        });
    },

    
_suggest: function( items ) {
        var 
ul this.menu.element.empty();
        
this._renderMenuulitems );
        
this.isNewMenu true;
        
this.menu.refresh();

        
// size and position menu
        
ul.show();
        
this._resizeMenu();
        
ul.position( $.extend({
            
ofthis.element
        
}, this.options.position ));

        if ( 
this.options.autoFocus ) {
            
this.menu.next();
        }
    },

    
_resizeMenu: function() {
        var 
ul this.menu.element;
        
ul.outerWidthMath.max(
            
// Firefox wraps long text (possibly a rounding bug)
            // so we add 1px to avoid the wrapping (#7513)
            
ul.width"" ).outerWidth() + 1,
            
this.element.outerWidth()
        ) );
    },

    
_renderMenu: function( ulitems ) {
        var 
that this;
        $.
eachitems, function( indexitem ) {
            
that._renderItemDataulitem );
        });
    },

    
_renderItemData: function( ulitem ) {
        return 
this._renderItemulitem ).data"ui-autocomplete-item"item );
    },

    
_renderItem: function( ulitem ) {
        return $( 
"<li>" )
            .
append( $( "<a>" ).textitem.label ) )
            .
appendToul );
    },

    
_move: function( directionevent ) {
        if ( !
this.menu.element.is":visible" ) ) {
            
this.searchnullevent );
            return;
        }
        if ( 
this.menu.isFirstItem() && /^previous/.testdirection ) ||
                
this.menu.isLastItem() && /^next/.testdirection ) ) {
            
this._valuethis.term );
            
this.menu.blur();
            return;
        }
        
this.menudirection ]( event );
    },

    
widget: function() {
        return 
this.menu.element;
    },

    
_value: function() {
        return 
this.valueMethod.applythis.elementarguments );
    },

    
_keyEvent: function( keyEventevent ) {
        if ( !
this.isMultiLine || this.menu.element.is":visible" ) ) {
            
this._movekeyEventevent );

            
// prevents moving cursor to beginning/end of the text field in some browsers
            
event.preventDefault();
        }
    }
});

$.
extend( $.ui.autocomplete, {
    
escapeRegex: function( value ) {
        return 
value.replace(/[-[]{}()*+?.,\^$|#s]/g, "\$&");
    
},
    
filter: function(array, term) {
        var 
matcher = new RegExp( $.ui.autocomplete.escapeRegex(term), "i" );
        return $.
grep( array, function(value) {
            return 
matcher.testvalue.label || value.value || value );
        });
    }
});


// live region extension, adding a `messages` option
// NOTE: This is an experimental API. We are still investigating
// a full solution for string manipulation and internationalization.
$.widget"ui.autocomplete", $.ui.autocomplete, {
    
options: {
        
messages: {
            
noResults"No search results.",
            
results: function( amount ) {
                return 
amount + ( amount " results are" " result is" ) +
                    
" available, use up and down arrow keys to navigate.";
            }
        }
    },

    
__response: function( content ) {
        var 
message;
        
this._superApplyarguments );
        if ( 
this.options.disabled || this.cancelSearch ) {
            return;
        }
        if ( 
content && content.length ) {
            
message this.options.messages.resultscontent.length );
        } else {
            
message this.options.messages.noResults;
        }
        
this.liveRegion.textmessage );
    }
});

}( 
jQuery ));
?>
Онлайн: 2
Реклама