Chris Craik | 1983215 | 2015-04-16 15:43:38 -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 | 1983215 | 2015-04-16 15:43:38 -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 | 1983215 | 2015-04-16 15:43:38 -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 FilterHasDuration(minValueOrExpected, opt_maxValue) { |
| 16 | if (minValueOrExpected !== undefined && opt_maxValue !== undefined) { |
| 17 | this.minValue = minValueOrExpected; |
| 18 | this.maxValue = opt_maxValue; |
| 19 | } else { |
| 20 | this.expected = minValueOrExpected; |
| 21 | } |
| 22 | }; |
Chris Craik | 1983215 | 2015-04-16 15:43:38 -0700 | [diff] [blame] | 23 | |
Chris Craik | 44c2820 | 2015-05-12 17:25:16 -0700 | [diff] [blame^] | 24 | FilterHasDuration.prototype = { |
| 25 | __proto__: tv.e.tquery.Filter.prototype, |
Chris Craik | 1983215 | 2015-04-16 15:43:38 -0700 | [diff] [blame] | 26 | |
| 27 | evaluate: function(context) { |
| 28 | if (context.event.duration === undefined) |
| 29 | return false; |
| 30 | if (this.minValue !== undefined && this.maxValue !== undefined) { |
| 31 | return context.event.duration >= this.minValue && |
| 32 | context.event.duration <= this.maxValue; |
| 33 | } |
| 34 | return this.matchValue_(context.event.duration, this.expected); |
| 35 | } |
Chris Craik | 44c2820 | 2015-05-12 17:25:16 -0700 | [diff] [blame^] | 36 | }; |
| 37 | tv.c.ScriptingObjectRegistry.register( |
| 38 | function(minValueOrExpected, opt_maxValue) { |
| 39 | return new FilterHasDuration(minValueOrExpected, opt_maxValue); |
| 40 | }, |
| 41 | { |
| 42 | name: 'hasDuration' |
| 43 | } |
| 44 | ); |
| 45 | return { |
| 46 | FilterHasDuration: FilterHasDuration |
| 47 | }; |
| 48 | }); |
| 49 | </script> |