modeler/angular/app/scripts/lib/$/select2/dev.js
function local(options) {
        var data = options, // data elements
            dataText,
            text = function (item) { return ""+item.text; }; // function used to retrieve the text portion of a data item that is matched against the search

        if (!$.isArray(data)) {
            text = data.text;
            // if text is not a function we assume it to be a key name
            if (!$.isFunction(text)) {
              dataText = data.text; // we need to store this in a separate variable because in the next step data gets reset and data.text is no longer available
              text = function (item) { return item[dataText]; };
            }
            data = data.results;
        }

        return function (query) {
            var t = query.term, filtered = { results: [] }, process;
            if (t === "") {
                query.callback({results: data});
                return;
            }

            process = function(datum, collection) {
                var group, attr;
                datum = datum[0];
                if (datum.children) {
                    group = {};
                    for (attr in datum) {
                        if (datum.hasOwnProperty(attr)) group[attr]=datum[attr];
                    }
                    group.children=[];
                    $(datum.children).each2(function(i, childDatum) { process(childDatum, group.children); });
                    if (group.children.length) {
                        collection.push(group);
                    }
                } else {
                    if (query.matcher(t, text(datum))) {
                        collection.push(datum);
                    }
                }
            };

            $(data).each2(function(i, datum) { process(datum, filtered.results); });
            query.callback(filtered);
        };
    }
function local(options) {
        var data = options, // data elements
            dataText,
            text = function (item) { return ""+item.text; }; // function used to retrieve the text portion of a data item that is matched against the search

        if (!$.isArray(data)) {
            text = data.text;
            // if text is not a function we assume it to be a key name
            if (!$.isFunction(text)) {
              dataText = data.text; // we need to store this in a separate variable because in the next step data gets reset and data.text is no longer available
              text = function (item) { return item[dataText]; };
            }
            data = data.results;
        }

        return function (query) {
            var t = query.term, filtered = { results: [] }, process;
            if (t === "") {
                query.callback({results: data});
                return;
            }

            process = function(datum, collection) {
                var group, attr;
                datum = datum[0];
                if (datum.children) {
                    group = {};
                    for (attr in datum) {
                        if (datum.hasOwnProperty(attr)) group[attr]=datum[attr];
                    }
                    group.children=[];
                    $(datum.children).each2(function(i, childDatum) { process(childDatum, group.children); });
                    if (group.children.length) {
                        collection.push(group);
                    }
                } else {
                    if (query.matcher(t, text(datum))) {
                        collection.push(datum);
                    }
                }
            };

            $(data).each2(function(i, datum) { process(datum, filtered.results); });
            query.callback(filtered);
        };
    }
function local ( options ) { var data = options , // data elements dataText , text = function ( item ) { return "" + item . text ; } ; // function used to retrieve the text portion of a data item that is matched against the search if ( ! $ . isArray ( data ) ) { text = data . text ; // if text is not a function we assume it to be a key name if ( ! $ . isFunction ( text ) ) { dataText = data . text ; // we need to store this in a separate variable because in the next step data gets reset and data.text is no longer available text = function ( item ) { return item [ dataText ] ; } ; } data = data . results ; } return function ( query ) { var t = query . term , filtered = { results : [ ] } , process ; if ( t === "" ) { query . callback ( { results : data } ) ; return ; } process = function ( datum , collection ) { var group , attr ; datum = datum [ 0 ] ; if ( datum . children ) { group = { } ; for ( attr in datum ) { if ( datum . hasOwnProperty ( attr ) ) group [ attr ] = datum [ attr ] ; } group . children = [ ] ; $ ( datum . children ) . each2 ( function ( i , childDatum ) { process ( childDatum , group . children ) ; } ) ; if ( group . children . length ) { collection . push ( group ) ; } } else { if ( query . matcher ( t , text ( datum ) ) ) { collection . push ( datum ) ; } } } ; $ ( data ) . each2 ( function ( i , datum ) { process ( datum , filtered . results ) ; } ) ; query . callback ( filtered ) ; } ; }
Produces a query function that works with a local array

@param options object containing configuration parameters. The options parameter can either be an array or an
object.

If the array form is used it is assumed that it contains objects with 'id' and 'text' keys.

If the object form is used ti is assumed that it contains 'data' and 'text' keys. The 'data' key should contain
an array of objects that will be used as choices. These objects must contain at least an 'id' key. The 'text'
key can either be a String in which case it is expected that each element in the 'data' array has a key with the
value of 'text' which will be used to match choices. Alternatively, text can be a function(item) that can extract
the text.
Produces a query function that works with a local array