@@ -1234,6 +1234,56 @@ var Item = Base.extend(Callback, /** @lends Item# */{
12341234 return this . _parent ? this . _parent . isInserted ( ) : false ;
12351235 } ,
12361236
1237+ // DOCS: Item#getItems
1238+ getItems : function ( match ) {
1239+ var children = this . children ,
1240+ items = [ ] ;
1241+ for ( var i = 0 , l = children && children . length ; i < l ; i ++ ) {
1242+ var child = children [ i ] ;
1243+ if ( child . matches ( match ) )
1244+ items . push ( child ) ;
1245+ items . push . apply ( items , child . getItems ( match ) ) ;
1246+ }
1247+ return items ;
1248+ } ,
1249+
1250+ // DOCS: Item#matches
1251+ matches : function ( match ) {
1252+ // matchObject() is used to match against objects in a nested manner.
1253+ // This is useful for matching against Item#data.
1254+ function matchObject ( obj1 , obj2 ) {
1255+ for ( var i in obj1 ) {
1256+ if ( obj1 . hasOwnProperty ( i ) ) {
1257+ var val1 = obj1 [ i ] ,
1258+ val2 = obj2 [ i ] ;
1259+ if ( Base . isPlainObject ( val1 ) && Base . isPlainObject ( val2 ) ) {
1260+ if ( ! matchObject ( val1 , val2 ) )
1261+ return false ;
1262+ } else if ( ! Base . equals ( val1 , val2 ) ) {
1263+ return false ;
1264+ }
1265+ }
1266+ }
1267+ return true ;
1268+ }
1269+ for ( var key in match ) {
1270+ if ( match . hasOwnProperty ( key ) ) {
1271+ var value = this [ key ] ,
1272+ compare = match [ key ] ;
1273+ if ( compare instanceof RegExp ) {
1274+ if ( ! compare . test ( value ) )
1275+ return false ;
1276+ } else if ( Base . isPlainObject ( compare ) ) {
1277+ if ( ! matchObject ( compare , value ) )
1278+ return false ;
1279+ } else if ( ! Base . equals ( value , compare ) ) {
1280+ return false ;
1281+ }
1282+ }
1283+ }
1284+ return true ;
1285+ } ,
1286+
12371287 equals : function ( item ) {
12381288 // Note: We do not compare name and selected state.
12391289 return item === this || item && this . _class === item . _class
0 commit comments