public/javascript/libs/select2.js
function () {

            var selector = ".select2-choices", selection;

            this.searchContainer = this.container.find(".select2-search-field");
            this.selection = selection = this.container.find(selector);

            var _this = this;
            this.selection.on("mousedown", ".select2-search-choice", function (e) {
                //killEvent(e);
                _this.search[0].focus();
                _this.selectChoice($(this));
            })

            // rewrite labels from original element to focusser
            this.search.attr("id", "s2id_autogen"+nextUid());
            $("label[for='" + this.opts.element.attr("id") + "']")
                .attr('for', this.search.attr('id'));

            this.search.on("input paste", this.bind(function() {
                if (!this.isInterfaceEnabled()) return;
                if (!this.opened()) {
                    this.open();
                }
            }));

            this.search.attr("tabindex", this.elementTabIndex);

            this.keydowns = 0;
            this.search.on("keydown", this.bind(function (e) {
                if (!this.isInterfaceEnabled()) return;

                ++this.keydowns;
                var selected = selection.find(".select2-search-choice-focus");
                var prev = selected.prev(".select2-search-choice:not(.select2-locked)");
                var next = selected.next(".select2-search-choice:not(.select2-locked)");
                var pos = getCursorInfo(this.search);

                if (selected.length &&
                    (e.which == KEY.LEFT || e.which == KEY.RIGHT || e.which == KEY.BACKSPACE || e.which == KEY.DELETE || e.which == KEY.ENTER)) {
                    var selectedChoice = selected;
                    if (e.which == KEY.LEFT && prev.length) {
                        selectedChoice = prev;
                    }
                    else if (e.which == KEY.RIGHT) {
                        selectedChoice = next.length ? next : null;
                    }
                    else if (e.which === KEY.BACKSPACE) {
                        this.unselect(selected.first());
                        this.search.width(10);
                        selectedChoice = prev.length ? prev : next;
                    } else if (e.which == KEY.DELETE) {
                        this.unselect(selected.first());
                        this.search.width(10);
                        selectedChoice = next.length ? next : null;
                    } else if (e.which == KEY.ENTER) {
                        selectedChoice = null;
                    }

                    this.selectChoice(selectedChoice);
                    killEvent(e);
                    if (!selectedChoice || !selectedChoice.length) {
                        this.open();
                    }
                    return;
                } else if (((e.which === KEY.BACKSPACE && this.keydowns == 1)
                    || e.which == KEY.LEFT) && (pos.offset == 0 && !pos.length)) {

                    this.selectChoice(selection.find(".select2-search-choice:not(.select2-locked)").last());
                    killEvent(e);
                    return;
                } else {
                    this.selectChoice(null);
                }

                if (this.opened()) {
                    switch (e.which) {
                    case KEY.UP:
                    case KEY.DOWN:
                        this.moveHighlight((e.which === KEY.UP) ? -1 : 1);
                        killEvent(e);
                        return;
                    case KEY.ENTER:
                        this.selectHighlighted();
                        killEvent(e);
                        return;
                    case KEY.TAB:
                        this.selectHighlighted({noFocus:true});
                        this.close();
                        return;
                    case KEY.ESC:
                        this.cancel(e);
                        killEvent(e);
                        return;
                    }
                }

                if (e.which === KEY.TAB || KEY.isControl(e) || KEY.isFunctionKey(e)
                 || e.which === KEY.BACKSPACE || e.which === KEY.ESC) {
                    return;
                }

                if (e.which === KEY.ENTER) {
                    if (this.opts.openOnEnter === false) {
                        return;
                    } else if (e.altKey || e.ctrlKey || e.shiftKey || e.metaKey) {
                        return;
                    }
                }

                this.open();

                if (e.which === KEY.PAGE_UP || e.which === KEY.PAGE_DOWN) {
                    // prevent the page from scrolling
                    killEvent(e);
                }

                if (e.which === KEY.ENTER) {
                    // prevent form from being submitted
                    killEvent(e);
                }

            }));

            this.search.on("keyup", this.bind(function (e) {
                this.keydowns = 0;
                this.resizeSearch();
            })
            );

            this.search.on("blur", this.bind(function(e) {
                this.container.removeClass("select2-container-active");
                this.search.removeClass("select2-focused");
                this.selectChoice(null);
                if (!this.opened()) this.clearSearch();
                e.stopImmediatePropagation();
                this.opts.element.trigger($.Event("select2-blur"));
            }));

            this.container.on("click", selector, this.bind(function (e) {
                if (!this.isInterfaceEnabled()) return;
                if ($(e.target).closest(".select2-search-choice").length > 0) {
                    // clicked inside a select2 search choice, do not open
                    return;
                }
                this.selectChoice(null);
                this.clearPlaceholder();
                if (!this.container.hasClass("select2-container-active")) {
                    this.opts.element.trigger($.Event("select2-focus"));
                }
                this.open();
                this.focusSearch();
                e.preventDefault();
            }));

            this.container.on("focus", selector, this.bind(function () {
                if (!this.isInterfaceEnabled()) return;
                if (!this.container.hasClass("select2-container-active")) {
                    this.opts.element.trigger($.Event("select2-focus"));
                }
                this.container.addClass("select2-container-active");
                this.dropdown.addClass("select2-drop-active");
                this.clearPlaceholder();
            }));

            this.initContainerWidth();
            this.opts.element.addClass("select2-offscreen");

            // set the placeholder if necessary
            this.clearSearch();
        }
function () {

            var selector = ".select2-choices", selection;

            this.searchContainer = this.container.find(".select2-search-field");
            this.selection = selection = this.container.find(selector);

            var _this = this;
            this.selection.on("mousedown", ".select2-search-choice", function (e) {
                //killEvent(e);
                _this.search[0].focus();
                _this.selectChoice($(this));
            })

            // rewrite labels from original element to focusser
            this.search.attr("id", "s2id_autogen"+nextUid());
            $("label[for='" + this.opts.element.attr("id") + "']")
                .attr('for', this.search.attr('id'));

            this.search.on("input paste", this.bind(function() {
                if (!this.isInterfaceEnabled()) return;
                if (!this.opened()) {
                    this.open();
                }
            }));

            this.search.attr("tabindex", this.elementTabIndex);

            this.keydowns = 0;
            this.search.on("keydown", this.bind(function (e) {
                if (!this.isInterfaceEnabled()) return;

                ++this.keydowns;
                var selected = selection.find(".select2-search-choice-focus");
                var prev = selected.prev(".select2-search-choice:not(.select2-locked)");
                var next = selected.next(".select2-search-choice:not(.select2-locked)");
                var pos = getCursorInfo(this.search);

                if (selected.length &&
                    (e.which == KEY.LEFT || e.which == KEY.RIGHT || e.which == KEY.BACKSPACE || e.which == KEY.DELETE || e.which == KEY.ENTER)) {
                    var selectedChoice = selected;
                    if (e.which == KEY.LEFT && prev.length) {
                        selectedChoice = prev;
                    }
                    else if (e.which == KEY.RIGHT) {
                        selectedChoice = next.length ? next : null;
                    }
                    else if (e.which === KEY.BACKSPACE) {
                        this.unselect(selected.first());
                        this.search.width(10);
                        selectedChoice = prev.length ? prev : next;
                    } else if (e.which == KEY.DELETE) {
                        this.unselect(selected.first());
                        this.search.width(10);
                        selectedChoice = next.length ? next : null;
                    } else if (e.which == KEY.ENTER) {
                        selectedChoice = null;
                    }

                    this.selectChoice(selectedChoice);
                    killEvent(e);
                    if (!selectedChoice || !selectedChoice.length) {
                        this.open();
                    }
                    return;
                } else if (((e.which === KEY.BACKSPACE && this.keydowns == 1)
                    || e.which == KEY.LEFT) && (pos.offset == 0 && !pos.length)) {

                    this.selectChoice(selection.find(".select2-search-choice:not(.select2-locked)").last());
                    killEvent(e);
                    return;
                } else {
                    this.selectChoice(null);
                }

                if (this.opened()) {
                    switch (e.which) {
                    case KEY.UP:
                    case KEY.DOWN:
                        this.moveHighlight((e.which === KEY.UP) ? -1 : 1);
                        killEvent(e);
                        return;
                    case KEY.ENTER:
                        this.selectHighlighted();
                        killEvent(e);
                        return;
                    case KEY.TAB:
                        this.selectHighlighted({noFocus:true});
                        this.close();
                        return;
                    case KEY.ESC:
                        this.cancel(e);
                        killEvent(e);
                        return;
                    }
                }

                if (e.which === KEY.TAB || KEY.isControl(e) || KEY.isFunctionKey(e)
                 || e.which === KEY.BACKSPACE || e.which === KEY.ESC) {
                    return;
                }

                if (e.which === KEY.ENTER) {
                    if (this.opts.openOnEnter === false) {
                        return;
                    } else if (e.altKey || e.ctrlKey || e.shiftKey || e.metaKey) {
                        return;
                    }
                }

                this.open();

                if (e.which === KEY.PAGE_UP || e.which === KEY.PAGE_DOWN) {
                    // prevent the page from scrolling
                    killEvent(e);
                }

                if (e.which === KEY.ENTER) {
                    // prevent form from being submitted
                    killEvent(e);
                }

            }));

            this.search.on("keyup", this.bind(function (e) {
                this.keydowns = 0;
                this.resizeSearch();
            })
            );

            this.search.on("blur", this.bind(function(e) {
                this.container.removeClass("select2-container-active");
                this.search.removeClass("select2-focused");
                this.selectChoice(null);
                if (!this.opened()) this.clearSearch();
                e.stopImmediatePropagation();
                this.opts.element.trigger($.Event("select2-blur"));
            }));

            this.container.on("click", selector, this.bind(function (e) {
                if (!this.isInterfaceEnabled()) return;
                if ($(e.target).closest(".select2-search-choice").length > 0) {
                    // clicked inside a select2 search choice, do not open
                    return;
                }
                this.selectChoice(null);
                this.clearPlaceholder();
                if (!this.container.hasClass("select2-container-active")) {
                    this.opts.element.trigger($.Event("select2-focus"));
                }
                this.open();
                this.focusSearch();
                e.preventDefault();
            }));

            this.container.on("focus", selector, this.bind(function () {
                if (!this.isInterfaceEnabled()) return;
                if (!this.container.hasClass("select2-container-active")) {
                    this.opts.element.trigger($.Event("select2-focus"));
                }
                this.container.addClass("select2-container-active");
                this.dropdown.addClass("select2-drop-active");
                this.clearPlaceholder();
            }));

            this.initContainerWidth();
            this.opts.element.addClass("select2-offscreen");

            // set the placeholder if necessary
            this.clearSearch();
        }
function ( ) { var selector = ".select2-choices" , selection ; this . searchContainer = this . container . find ( ".select2-search-field" ) ; this . selection = selection = this . container . find ( selector ) ; var _this = this ; this . selection . on ( "mousedown" , ".select2-search-choice" , function ( e ) { //killEvent(e); _this . search [ 0 ] . focus ( ) ; _this . selectChoice ( $ ( this ) ) ; } ) // rewrite labels from original element to focusser this . search . attr ( "id" , "s2id_autogen" + nextUid ( ) ) ; $ ( "label[for='" + this . opts . element . attr ( "id" ) + "']" ) . attr ( 'for' , this . search . attr ( 'id' ) ) ; this . search . on ( "input paste" , this . bind ( function ( ) { if ( ! this . isInterfaceEnabled ( ) ) return ; if ( ! this . opened ( ) ) { this . open ( ) ; } } ) ) ; this . search . attr ( "tabindex" , this . elementTabIndex ) ; this . keydowns = 0 ; this . search . on ( "keydown" , this . bind ( function ( e ) { if ( ! this . isInterfaceEnabled ( ) ) return ; ++ this . keydowns ; var selected = selection . find ( ".select2-search-choice-focus" ) ; var prev = selected . prev ( ".select2-search-choice:not(.select2-locked)" ) ; var next = selected . next ( ".select2-search-choice:not(.select2-locked)" ) ; var pos = getCursorInfo ( this . search ) ; if ( selected . length && ( e . which == KEY . LEFT || e . which == KEY . RIGHT || e . which == KEY . BACKSPACE || e . which == KEY . DELETE || e . which == KEY . ENTER ) ) { var selectedChoice = selected ; if ( e . which == KEY . LEFT && prev . length ) { selectedChoice = prev ; } else if ( e . which == KEY . RIGHT ) { selectedChoice = next . length ? next : null ; } else if ( e . which === KEY . BACKSPACE ) { this . unselect ( selected . first ( ) ) ; this . search . width ( 10 ) ; selectedChoice = prev . length ? prev : next ; } else if ( e . which == KEY . DELETE ) { this . unselect ( selected . first ( ) ) ; this . search . width ( 10 ) ; selectedChoice = next . length ? next : null ; } else if ( e . which == KEY . ENTER ) { selectedChoice = null ; } this . selectChoice ( selectedChoice ) ; killEvent ( e ) ; if ( ! selectedChoice || ! selectedChoice . length ) { this . open ( ) ; } return ; } else if ( ( ( e . which === KEY . BACKSPACE && this . keydowns == 1 ) || e . which == KEY . LEFT ) && ( pos . offset == 0 && ! pos . length ) ) { this . selectChoice ( selection . find ( ".select2-search-choice:not(.select2-locked)" ) . last ( ) ) ; killEvent ( e ) ; return ; } else { this . selectChoice ( null ) ; } if ( this . opened ( ) ) { switch ( e . which ) { case KEY . UP : case KEY . DOWN : this . moveHighlight ( ( e . which === KEY . UP ) ? - 1 : 1 ) ; killEvent ( e ) ; return ; case KEY . ENTER : this . selectHighlighted ( ) ; killEvent ( e ) ; return ; case KEY . TAB : this . selectHighlighted ( { noFocus : true } ) ; this . close ( ) ; return ; case KEY . ESC : this . cancel ( e ) ; killEvent ( e ) ; return ; } } if ( e . which === KEY . TAB || KEY . isControl ( e ) || KEY . isFunctionKey ( e ) || e . which === KEY . BACKSPACE || e . which === KEY . ESC ) { return ; } if ( e . which === KEY . ENTER ) { if ( this . opts . openOnEnter === false ) { return ; } else if ( e . altKey || e . ctrlKey || e . shiftKey || e . metaKey ) { return ; } } this . open ( ) ; if ( e . which === KEY . PAGE_UP || e . which === KEY . PAGE_DOWN ) { // prevent the page from scrolling killEvent ( e ) ; } if ( e . which === KEY . ENTER ) { // prevent form from being submitted killEvent ( e ) ; } } ) ) ; this . search . on ( "keyup" , this . bind ( function ( e ) { this . keydowns = 0 ; this . resizeSearch ( ) ; } ) ) ; this . search . on ( "blur" , this . bind ( function ( e ) { this . container . removeClass ( "select2-container-active" ) ; this . search . removeClass ( "select2-focused" ) ; this . selectChoice ( null ) ; if ( ! this . opened ( ) ) this . clearSearch ( ) ; e . stopImmediatePropagation ( ) ; this . opts . element . trigger ( $ . Event ( "select2-blur" ) ) ; } ) ) ; this . container . on ( "click" , selector , this . bind ( function ( e ) { if ( ! this . isInterfaceEnabled ( ) ) return ; if ( $ ( e . target ) . closest ( ".select2-search-choice" ) . length > 0 ) { // clicked inside a select2 search choice, do not open return ; } this . selectChoice ( null ) ; this . clearPlaceholder ( ) ; if ( ! this . container . hasClass ( "select2-container-active" ) ) { this . opts . element . trigger ( $ . Event ( "select2-focus" ) ) ; } this . open ( ) ; this . focusSearch ( ) ; e . preventDefault ( ) ; } ) ) ; this . container . on ( "focus" , selector , this . bind ( function ( ) { if ( ! this . isInterfaceEnabled ( ) ) return ; if ( ! this . container . hasClass ( "select2-container-active" ) ) { this . opts . element . trigger ( $ . Event ( "select2-focus" ) ) ; } this . container . addClass ( "select2-container-active" ) ; this . dropdown . addClass ( "select2-drop-active" ) ; this . clearPlaceholder ( ) ; } ) ) ; this . initContainerWidth ( ) ; this . opts . element . addClass ( "select2-offscreen" ) ; // set the placeholder if necessary this . clearSearch ( ) ; }
multi
multi