~michael.nelson/ubuntu-webcatalog/1267731-import-sca-apps-error

« back to all changes in this revision

Viewing changes to src/webcatalog/static/yui/3.10.3/build/recordset-filter/recordset-filter.js

  • Committer: Tarmac
  • Author(s): Stephen Stewart
  • Date: 2013-06-26 09:19:32 UTC
  • mfrom: (184.1.4 ubuntu-global-nav)
  • Revision ID: tarmac-20130626091932-8urtuli368k8p7ds
[r=beuno,jonas-drange] add ubuntu global nav to apps.ubuntu.com

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
YUI 3.10.3 (build 2fb5187)
 
3
Copyright 2013 Yahoo! Inc. All rights reserved.
 
4
Licensed under the BSD License.
 
5
http://yuilibrary.com/license/
 
6
*/
 
7
 
 
8
YUI.add('recordset-filter', function (Y, NAME) {
 
9
 
 
10
/**
 
11
 * Plugin that provides the ability to filter through a recordset.
 
12
 * Uses the filter methods available on Y.Array (see arrayextras submodule) to filter the recordset.
 
13
 * @module recordset
 
14
 * @submodule recordset-filter
 
15
 */
 
16
 
 
17
 
 
18
var YArray = Y.Array,
 
19
Lang = Y.Lang;
 
20
 
 
21
 
 
22
/**
 
23
 * Plugin that provides the ability to filter through a recordset.
 
24
 * Uses the filter methods available on Y.Array (see arrayextras submodule) to filter the recordset. 
 
25
 * @class RecordsetFilter
 
26
 */
 
27
function RecordsetFilter(config) {
 
28
    RecordsetFilter.superclass.constructor.apply(this, arguments);
 
29
}
 
30
 
 
31
Y.mix(RecordsetFilter, {
 
32
    NS: "filter",
 
33
 
 
34
    NAME: "recordsetFilter",
 
35
 
 
36
    ATTRS: {
 
37
    }
 
38
 
 
39
});
 
40
 
 
41
 
 
42
Y.extend(RecordsetFilter, Y.Plugin.Base, {
 
43
 
 
44
 
 
45
    /**
 
46
    Filter through the recordset with a custom filter function, or a key-value
 
47
    pair.
 
48
    
 
49
    @method filter
 
50
    @param {Function|String} filter A custom filter function or a string
 
51
        representing the key to filter by.
 
52
    @param {Any} [value] If filtering by key (_filter_ is a string), further
 
53
        filter by a specific value.
 
54
    @return {Recordset} A new filtered Recordset instance
 
55
    **/
 
56
    filter: function (filter, value) {
 
57
        var recs = this.get('host').get('records'),
 
58
            key;
 
59
 
 
60
        //If a key-value pair is passed in, generate a custom function
 
61
        if (value && Lang.isString(filter)) {
 
62
            key = filter;
 
63
            filter = function(item) {
 
64
                return (item.getValue(key) === value);
 
65
            };
 
66
        }
 
67
 
 
68
        //TODO: PARENT CHILD RELATIONSHIP
 
69
        return new Y.Recordset({
 
70
            records: YArray.filter(recs, filter)
 
71
        });
 
72
    },
 
73
 
 
74
    /**
 
75
    The inverse of filter. Executes the supplied function on each item. Returns
 
76
    a new Recordset containing the items that the supplied function returned
 
77
    `false` for.
 
78
 
 
79
    @method reject
 
80
    @param {Function} filter A boolean function, executed on each item.
 
81
    @return {Recordset} A new Recordset instance containing the items on which
 
82
        the supplied function returned false.
 
83
    **/
 
84
    reject: function (filter) {
 
85
        return new Y.Recordset({
 
86
            records: YArray.reject(this.get('host').get('records'), filter)
 
87
        });
 
88
    },
 
89
 
 
90
    /**
 
91
    Iterates over the Recordset, returning a new Recordset of all the elements
 
92
    that match the supplied regular expression
 
93
 
 
94
    @method grep
 
95
    @param {RegExp} pattern The regular expression to test against each record.
 
96
    @return {Recordset} A Recordset instance containing all the items in the
 
97
        collection that produce a match against the supplied regular
 
98
        expression. If no items match, an empty Recordset instance is returned.
 
99
    **/
 
100
    grep: function (pattern) {
 
101
        return new Y.Recordset({
 
102
            records: YArray.grep(this.get('host').get('records'), pattern)
 
103
        });
 
104
    }
 
105
 
 
106
    //TODO: Add more pass-through methods to arrayextras
 
107
});
 
108
 
 
109
Y.namespace("Plugin").RecordsetFilter = RecordsetFilter;
 
110
 
 
111
 
 
112
}, '3.10.3', {"requires": ["recordset-base", "array-extras", "plugin"]});