| <!DOCTYPE html> |
| <!-- |
| Copyright 2015 The Chromium Authors. All rights reserved. |
| Use of this source code is governed by a BSD-style license that can be |
| found in the LICENSE file. |
| --> |
| |
| <link rel="import" href="/core/scripting_controller.html"> |
| <link rel="import" href="/extras/tquery/filter.html"> |
| |
| <script> |
| 'use strict'; |
| |
| tv.exportTo('tv.e.tquery', function() { |
| function FilterHasDuration(minValueOrExpected, opt_maxValue) { |
| if (minValueOrExpected !== undefined && opt_maxValue !== undefined) { |
| this.minValue = minValueOrExpected; |
| this.maxValue = opt_maxValue; |
| } else { |
| this.expected = minValueOrExpected; |
| } |
| }; |
| |
| FilterHasDuration.prototype = { |
| __proto__: tv.e.tquery.Filter.prototype, |
| |
| evaluate: function(context) { |
| if (context.event.duration === undefined) |
| return false; |
| if (this.minValue !== undefined && this.maxValue !== undefined) { |
| return context.event.duration >= this.minValue && |
| context.event.duration <= this.maxValue; |
| } |
| return this.matchValue_(context.event.duration, this.expected); |
| } |
| }; |
| tv.c.ScriptingObjectRegistry.register( |
| function(minValueOrExpected, opt_maxValue) { |
| return new FilterHasDuration(minValueOrExpected, opt_maxValue); |
| }, |
| { |
| name: 'hasDuration' |
| } |
| ); |
| return { |
| FilterHasDuration: FilterHasDuration |
| }; |
| }); |
| </script> |