blob: b998c1df1083647a953a27d5719955b69e65f8f5 [file] [log] [blame]
<!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="/base/polymer_utils.html">
<link rel="import" href="/extras/tquery/tquery.html">
<polymer-element name='tv-c-scripting-controller'>
<script>
'use strict';
Polymer({
ready: function() {
this.timeline_ = undefined;
this.scriptObjectNames_ = [];
this.scriptObjectValues_ = [];
// Register all scripting objects.
var objects = tv.b.getPolymerElementsThatSubclass(
'tv-c-scripting-object');
objects.forEach(function(className) {
var obj = document.createElement(className);
if (!obj.scriptName)
return;
this.addScriptObject(obj.scriptName, obj.scriptValue);
// Also make the object available to the DevTools inspector.
window[obj.scriptName] = obj.scriptValue;
}.bind(this));
},
get timeline() {
return this.timeline_;
},
set timeline(t) {
this.timeline_ = t;
this.scriptObjectValues_.forEach(function(v) {
if (v.onTimelineChanged)
v.onTimelineChanged(t);
});
},
addScriptObject: function(name, value) {
this.scriptObjectNames_.push(name);
this.scriptObjectValues_.push(value);
},
executeCommand: function(command) {
var f = new Function(
this.scriptObjectNames_, 'return eval(' + command + ')');
return f.apply(null, this.scriptObjectValues_);
}
});
</script>
</polymer-element>