Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: chrome/common/extensions/docs/examples/api/fontSettings/slider.js

Issue 23434003: UI refresh of Advanced Font Settings Extension (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: keep original name Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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 Slider control. Based on Chromium's MediaControls.Slider.
9 */
10
11 /**
12 * Creates a slider control.
13 *
14 * @param {HTMLElement} container The containing div element.
15 * @param {number} value Initial value
16 * @param {number} min Minimum value
17 * @param {number} max Maximum value
18 * @param {function(number)} onChange Value change handler.
19 * @param {function(boolean)} onDrag Drag begin/end handler.
yoshiki 2013/08/28 02:53:35 Is 'onDrag' and/or 'onChange' are optional paramet
falken 2013/08/28 08:36:16 Done. Actually I don't need on drag anywhere, so I
20 * @constructor
21 */
22
23 function Slider(container, value, min, max, onChange, onDrag) {
24 this.container_ = container;
25 this.onChange_ = onChange;
26 this.onDrag_ = onDrag;
27
28 var document = this.container_.ownerDocument;
29
30 this.container_.classList.add('slider');
31
32 this.input_ = document.createElement('input');
33 this.input_.type = 'range';
34 this.input_.min = min;
35 this.input_.max = max;
36 this.input_.value = value;
37 this.container_.appendChild(this.input_);
38
39 this.input_.addEventListener(
40 'change', this.onInputChange_.bind(this));
41 this.input_.addEventListener(
42 'mousedown', this.onInputDrag_.bind(this, true));
43 this.input_.addEventListener(
44 'mouseup', this.onInputDrag_.bind(this, false));
45
46 this.bar_ = document.createElement('div');
47 this.bar_.className = 'bar';
48 this.container_.appendChild(this.bar_);
49
50 this.filled_ = document.createElement('div');
51 this.filled_.className = 'filled';
52 this.bar_.appendChild(this.filled_);
53
54 var leftCap = document.createElement('div');
55 leftCap.className = 'cap left';
56 this.bar_.appendChild(leftCap);
57
58 var rightCap = document.createElement('div');
59 rightCap.className = 'cap right';
60 this.bar_.appendChild(rightCap);
61
62 this.updateFilledWidth_();
63 };
64
65 Slider.prototype.getValue = function() {
yoshiki 2013/08/28 02:53:35 Please write JSdoc.
falken 2013/08/28 08:36:16 Done.
66 return this.input_.value;
67 };
68
69 Slider.prototype.setValue = function(value) {
70 this.input_.value = value;
71 this.updateFilledWidth_();
72 };
73
74 Slider.prototype.getInput = function() {
75 return this.input_;
76 }
77
78 Slider.prototype.updateFilledWidth_ = function() {
79 var proportion =(this.input_.value - this.input_.min) /
yoshiki 2013/08/28 02:53:35 Add a space after "=".
falken 2013/08/28 08:36:16 Done.
80 (this.input_.max - this.input_.min);
81 this.filled_.style.width = proportion * 100 + '%';
82 };
83
84 Slider.prototype.onInputChange_ = function() {
85 this.updateFilledWidth_();
86 if (this.onChange_) {
yoshiki 2013/08/28 02:53:35 Curly brackets are unnecessary, since there is onl
falken 2013/08/28 08:36:16 Done.
87 this.onChange_(this.input_.value);
88 }
89 };
90
91 Slider.prototype.isDragging = function() {
92 return this.isDragging_;
93 };
94
95 Slider.prototype.onInputDrag_ = function(on) {
96 this.isDragging_ = on;
97 if (this.onDrag_)
98 this.onDrag_(on);
99 };
100
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698