• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright (c) 2013 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5'use strict';
6
7/**
8 * @fileoverview A scrollbar-like control with constant text hi/lo values.
9 */
10base.require('ui');
11base.require('base.properties');
12base.require('ui.value_bar');
13
14base.exportTo('ui', function() {
15
16  /**
17   * @constructor
18   */
19  var TextEndValueBar = ui.define('text-end-value-bar');
20
21  TextEndValueBar.prototype = {
22    __proto__: ui.ValueBar.prototype,
23
24    decorate: function() {
25      this.lowestValueProperties_ = {textContent: ''};
26      this.highestValueProperties_ = {textContent: ''};
27      ui.ValueBar.prototype.decorate.call(this);
28      this.classList.add('text-end-value-bar');
29    },
30
31    get lowestValueProperties() {
32      return this.lowestValueProperties_;
33    },
34
35    set lowestValueProperties(newValue) {
36      console.assert(typeof newValue === 'object' &&
37          (newValue.style || newValue.textContent));
38      this.lowestValueProperties_ = newValue;
39      base.dispatchPropertyChange(this, 'lowestValue',
40          this.lowestValue, this.lowestValue);
41    },
42
43    get highestValueProperties() {
44      return this.highestValueProperties_;
45    },
46
47    set highestValueProperties(newValue) {
48      console.assert(typeof newValue === 'object' &&
49          (newValue.style || newValue.textContent));
50      this.highestValueProperties_ = newValue;
51      base.dispatchPropertyChange(this, 'highestValue',
52          this.highestValue, this.highestValue);
53    },
54
55    copyOwnProperties_: function(dst, src) {
56      if (!src)
57        return;
58      Object.keys(src).forEach(function(key) {
59        dst[key] = src[key];
60      });
61    },
62
63    updateLowestValueElement: function(element) {
64      this.copyOwnProperties_(element.style,
65          this.lowestValueProperties_.style);
66      element.textContent = this.lowestValueProperties_.textContent || '';
67    },
68
69    updateHighestValueElement: function(element) {
70      this.copyOwnProperties_(element.style,
71          this.highestValueProperties_.style);
72      element.textContent = this.highestValueProperties_.textContent || '';
73    },
74
75  };
76
77  return {
78    TextEndValueBar: TextEndValueBar
79  };
80});
81