Chris Craik | beca7ae | 2015-04-07 13:29:55 -0700 | [diff] [blame] | 1 | <!DOCTYPE html> |
| 2 | <!-- |
| 3 | Copyright 2015 The Chromium Authors. All rights reserved. |
| 4 | Use of this source code is governed by a BSD-style license that can be |
| 5 | found in the LICENSE file. |
| 6 | --> |
| 7 | |
Chris Craik | 44c2820 | 2015-05-12 17:25:16 -0700 | [diff] [blame^] | 8 | <link rel="import" href="/core/scripting_controller.html"> |
Chris Craik | beca7ae | 2015-04-07 13:29:55 -0700 | [diff] [blame] | 9 | <link rel="import" href="/extras/tquery/filter.html"> |
| 10 | |
Chris Craik | 44c2820 | 2015-05-12 17:25:16 -0700 | [diff] [blame^] | 11 | <script> |
| 12 | 'use strict'; |
Chris Craik | beca7ae | 2015-04-07 13:29:55 -0700 | [diff] [blame] | 13 | |
Chris Craik | 44c2820 | 2015-05-12 17:25:16 -0700 | [diff] [blame^] | 14 | tv.exportTo('tv.e.tquery', function() { |
| 15 | function FilterIsTopLevel(opt_subExpression) { |
| 16 | this.subExpression = opt_subExpression; |
| 17 | } |
Chris Craik | beca7ae | 2015-04-07 13:29:55 -0700 | [diff] [blame] | 18 | |
Chris Craik | 44c2820 | 2015-05-12 17:25:16 -0700 | [diff] [blame^] | 19 | FilterIsTopLevel.prototype = { |
| 20 | __proto__: tv.e.tquery.Filter.prototype, |
Chris Craik | beca7ae | 2015-04-07 13:29:55 -0700 | [diff] [blame] | 21 | |
| 22 | set subExpression(expr) { |
Chris Craik | 44c2820 | 2015-05-12 17:25:16 -0700 | [diff] [blame^] | 23 | this.subExpression_ = tv.e.tquery.Filter.normalizeFilterExpression(expr); |
Chris Craik | beca7ae | 2015-04-07 13:29:55 -0700 | [diff] [blame] | 24 | }, |
| 25 | |
| 26 | get subExpression() { |
| 27 | return this.subExpression_; |
| 28 | }, |
| 29 | |
| 30 | evaluate: function(context) { |
| 31 | if (context.ancestors.length > 0) |
| 32 | return false; |
| 33 | if (!this.subExpression) |
| 34 | return true; |
| 35 | return this.subExpression.evaluate(context); |
| 36 | } |
Chris Craik | 44c2820 | 2015-05-12 17:25:16 -0700 | [diff] [blame^] | 37 | }; |
| 38 | tv.c.ScriptingObjectRegistry.register( |
| 39 | function(subExpression) { |
| 40 | return new FilterIsTopLevel(subExpression); |
| 41 | }, |
| 42 | { |
| 43 | name: 'isTopLevel' |
| 44 | } |
| 45 | ); |
| 46 | return { |
| 47 | FilterIsTopLevel: FilterIsTopLevel |
| 48 | }; |
| 49 | }); |
| 50 | </script> |