blob: c8b91b7c43a21eb30072f94e150990b774756fac [file] [log] [blame]
Chris Craik19832152015-04-16 15:43:38 -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 Craik19832152015-04-16 15:43:38 -07009<link rel="import" href="/extras/tquery/filter.html">
10
Chris Craik44c28202015-05-12 17:25:16 -070011<script>
12'use strict';
Chris Craik19832152015-04-16 15:43:38 -070013
Chris Craik44c28202015-05-12 17:25:16 -070014tv.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 Craik19832152015-04-16 15:43:38 -070023
Chris Craik44c28202015-05-12 17:25:16 -070024 FilterHasDuration.prototype = {
25 __proto__: tv.e.tquery.Filter.prototype,
Chris Craik19832152015-04-16 15:43:38 -070026
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 Craik44c28202015-05-12 17:25:16 -070036 };
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>