blob: 975b8b040deeac6486a9f0c7e986e30505ba1049 [file] [log] [blame]
Chris Craikbeca7ae2015-04-07 13:29:55 -07001<!DOCTYPE html>
2<!--
3Copyright 2015 The Chromium Authors. All rights reserved.
4Use of this source code is governed by a BSD-style license that can be
5found in the LICENSE file.
6-->
7
Chris Craik44c28202015-05-12 17:25:16 -07008<link rel="import" href="/core/scripting_controller.html">
Chris Craikbeca7ae2015-04-07 13:29:55 -07009<link rel="import" href="/extras/tquery/filter.html">
10
Chris Craik44c28202015-05-12 17:25:16 -070011<script>
12'use strict';
Chris Craikbeca7ae2015-04-07 13:29:55 -070013
Chris Craik44c28202015-05-12 17:25:16 -070014tv.exportTo('tv.e.tquery', function() {
15 function FilterIsTopLevel(opt_subExpression) {
16 this.subExpression = opt_subExpression;
17 }
Chris Craikbeca7ae2015-04-07 13:29:55 -070018
Chris Craik44c28202015-05-12 17:25:16 -070019 FilterIsTopLevel.prototype = {
20 __proto__: tv.e.tquery.Filter.prototype,
Chris Craikbeca7ae2015-04-07 13:29:55 -070021
22 set subExpression(expr) {
Chris Craik44c28202015-05-12 17:25:16 -070023 this.subExpression_ = tv.e.tquery.Filter.normalizeFilterExpression(expr);
Chris Craikbeca7ae2015-04-07 13:29:55 -070024 },
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 Craik44c28202015-05-12 17:25:16 -070037 };
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>