dist/toolkit.js
function(input, options) {
        input = $(input);

        if (input.prop('tagName').toLowerCase() !== 'input') {
            throw new Error('TypeAhead must be initialized on an input field');
        }

        var self = this;

        options = this.setOptions(options, input);
        this.element = this.createElement()
            .attr('role', 'listbox')
            .aria('multiselectable', false);

        // The input field to listen against
        this.input = input;

        // Use default callbacks
        $.each({ sorter: 'sort', matcher: 'match', builder: 'build' }, function(key, fn) {
            if (options[key] === false) {
                return;
            }

            var callback;

            if (options[key] === null || $.type(options[key]) !== 'function') {
                callback = self[fn];
            } else {
                callback = options[key];
            }

            options[key] = callback.bind(self);
        });

        // Prefetch source data from URL
        if (options.prefetch && $.type(options.source) === 'string') {
            var url = options.source;

            $.getJSON(url, options.query, function(items) {
                self.cache[url] = items;
            });
        }

        // Enable shadow inputs
        if (options.shadow) {
            this.wrapper = this.render(this.options.shadowTemplate);

            this.shadow = this.input.clone()
                .addClass('is-shadow')
                .removeAttr('id')
                .prop('readonly', true)
                .aria('readonly', true);

            this.input
                .addClass('not-shadow')
                .replaceWith(this.wrapper);

            this.wrapper
                .append(this.shadow)
                .append(this.input);
        }

        // Set ARIA after shadow so that attributes are not inherited
        input
            .attr({
                autocomplete: 'off',
                autocapitalize: 'off',
                autocorrect: 'off',
                spellcheck: 'false',
                role: 'combobox'
            })
            .aria({
                autocomplete: 'list',
                owns: this.element.attr('id'),
                expanded: false
            });

        // Initialize events
        this.addEvents([
            ['keyup', 'input', 'onLookup'],
            ['keydown', 'input', 'onCycle'],
            ['clickout', 'element', 'hide'],
            ['resize', 'window', $.debounce(this.onHide.bind(this))]
        ]);

        this.initialize();
    }
function(input, options) {
        input = $(input);

        if (input.prop('tagName').toLowerCase() !== 'input') {
            throw new Error('TypeAhead must be initialized on an input field');
        }

        var self = this;

        options = this.setOptions(options, input);
        this.element = this.createElement()
            .attr('role', 'listbox')
            .aria('multiselectable', false);

        // The input field to listen against
        this.input = input;

        // Use default callbacks
        $.each({ sorter: 'sort', matcher: 'match', builder: 'build' }, function(key, fn) {
            if (options[key] === false) {
                return;
            }

            var callback;

            if (options[key] === null || $.type(options[key]) !== 'function') {
                callback = self[fn];
            } else {
                callback = options[key];
            }

            options[key] = callback.bind(self);
        });

        // Prefetch source data from URL
        if (options.prefetch && $.type(options.source) === 'string') {
            var url = options.source;

            $.getJSON(url, options.query, function(items) {
                self.cache[url] = items;
            });
        }

        // Enable shadow inputs
        if (options.shadow) {
            this.wrapper = this.render(this.options.shadowTemplate);

            this.shadow = this.input.clone()
                .addClass('is-shadow')
                .removeAttr('id')
                .prop('readonly', true)
                .aria('readonly', true);

            this.input
                .addClass('not-shadow')
                .replaceWith(this.wrapper);

            this.wrapper
                .append(this.shadow)
                .append(this.input);
        }

        // Set ARIA after shadow so that attributes are not inherited
        input
            .attr({
                autocomplete: 'off',
                autocapitalize: 'off',
                autocorrect: 'off',
                spellcheck: 'false',
                role: 'combobox'
            })
            .aria({
                autocomplete: 'list',
                owns: this.element.attr('id'),
                expanded: false
            });

        // Initialize events
        this.addEvents([
            ['keyup', 'input', 'onLookup'],
            ['keydown', 'input', 'onCycle'],
            ['clickout', 'element', 'hide'],
            ['resize', 'window', $.debounce(this.onHide.bind(this))]
        ]);

        this.initialize();
    }
function ( input , options ) { input = $ ( input ) ; if ( input . prop ( 'tagName' ) . toLowerCase ( ) !== 'input' ) { throw new Error ( 'TypeAhead must be initialized on an input field' ) ; } var self = this ; options = this . setOptions ( options , input ) ; this . element = this . createElement ( ) . attr ( 'role' , 'listbox' ) . aria ( 'multiselectable' , false ) ; // The input field to listen against this . input = input ; // Use default callbacks $ . each ( { sorter : 'sort' , matcher : 'match' , builder : 'build' } , function ( key , fn ) { if ( options [ key ] === false ) { return ; } var callback ; if ( options [ key ] === null || $ . type ( options [ key ] ) !== 'function' ) { callback = self [ fn ] ; } else { callback = options [ key ] ; } options [ key ] = callback . bind ( self ) ; } ) ; // Prefetch source data from URL if ( options . prefetch && $ . type ( options . source ) === 'string' ) { var url = options . source ; $ . getJSON ( url , options . query , function ( items ) { self . cache [ url ] = items ; } ) ; } // Enable shadow inputs if ( options . shadow ) { this . wrapper = this . render ( this . options . shadowTemplate ) ; this . shadow = this . input . clone ( ) . addClass ( 'is-shadow' ) . removeAttr ( 'id' ) . prop ( 'readonly' , true ) . aria ( 'readonly' , true ) ; this . input . addClass ( 'not-shadow' ) . replaceWith ( this . wrapper ) ; this . wrapper . append ( this . shadow ) . append ( this . input ) ; } // Set ARIA after shadow so that attributes are not inherited input . attr ( { autocomplete : 'off' , autocapitalize : 'off' , autocorrect : 'off' , spellcheck : 'false' , role : 'combobox' } ) . aria ( { autocomplete : 'list' , owns : this . element . attr ( 'id' ) , expanded : false } ) ; // Initialize events this . addEvents ( [ [ 'keyup' , 'input' , 'onLookup' ] , [ 'keydown' , 'input' , 'onCycle' ] , [ 'clickout' , 'element' , 'hide' ] , [ 'resize' , 'window' , $ . debounce ( this . onHide . bind ( this ) ) ] ] ) ; this . initialize ( ) ; }
Initialize the type ahead.

@param {jQuery} input
@param {Object} [options]
Initialize the type ahead .