1 // Copyright (c) 2012 Google, Inc.
3 // Permission is hereby granted, free of charge, to any person obtaining a copy
4 // of this software and associated documentation files (the "Software"), to deal
5 // in the Software without restriction, including without limitation the rights
6 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 // copies of the Software, and to permit persons to whom the Software is
8 // furnished to do so, subject to the following conditions:
10 // The above copyright notice and this permission notice shall be included in
11 // all copies or substantial portions of the Software.
13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * @fileoverview Dygraphs options palette text area.
24 * @author konigsberg@google.com (Robert Konigsberg)
28 function TextArea(parent
) {
29 var body
= document
.getElementsByTagName("body")[0];
33 this.elem
= Palette
.createChild("div", parent
, "textarea");
34 this.title
= Palette
.createChild("div", this.elem
, "title");
35 this.textarea
= Palette
.createChild("textarea", this.elem
, "editor");
36 this.buttons
= Palette
.createChild("div", this.elem
, "buttons");
37 this.ok
= Palette
.createChild("button", this.buttons
);
38 this.ok
.textContent
= "OK";
39 this.cancel
= Palette
.createChild("button", this.buttons
);
40 this.cancel
.textContent
= "Cancel";
43 this.ok
.onclick
= function() {
45 textarea
.okCallback(textarea
.textarea
.value
);
47 this.cancel
.onclick
= function() {
49 textarea
.cancelCallback();
51 this.reposition
= function() {
52 var left
= (document
.documentElement
.clientWidth
- textarea
.elem
.offsetWidth
) / 2;
53 var top
= (document
.documentElement
.clientHeight
- textarea
.elem
.offsetHeight
) / 2;
54 console
.log("reposition", left
, top
);
55 textarea
.elem
.style
.left
= Math
.max(left
, 0) + "px";
56 textarea
.elem
.style
.top
= Math
.max(top
, 0) + "px";
59 this.background
= Palette
.createChild("div", body
, "background");
60 this.background
.id
= "modalBackground";
64 TextArea
.prototype.cancelCallback
= function() {
67 TextArea
.prototype.okCallback
= function(content
) {
70 TextArea
.prototype.show
= function(title
, content
) {
71 this.title
.textContent
= title
;
72 this.textarea
.value
= content
;
78 var sums
= function(adds
, subtracts
, field
) {
80 for (var idx
in adds
) {
81 total
+= parseInt(adds
[idx
][field
]);
83 for (var idx2
in subtracts
) {
84 total
-= parseInt(subtracts
[idx2
][field
]);
88 this.elem
.style
.display
= "block";
89 this.background
.style
.display
= "block";
91 this.elem
.style
.height
= height
+ "px";
92 this.elem
.style
.width
= width
+ "px";
94 this.textarea
.style
.height
= (-18 + sums([this.elem
], [this.title
, this.buttons
], "offsetHeight")) + "px";
95 this.textarea
.style
.width
= (-16 + sums([this.elem
], [ ], "offsetWidth")) + "px";
98 window
.addEventListener('resize', this.reposition
, false);
99 document
.documentElement
.addEventListener('onscroll', this.reposition
);
102 TextArea
.prototype.hide
= function() {
103 this.elem
.style
.display
= "none";
104 this.background
.style
.display
= "none";
105 window
.removeEventListener("resize", this.reposition
);
106 document
.documentElement
.removeEventListener("onscroll", this.reposition
);