this.filterBar = null;
}
+Palette.createChild = function(type, parentElement, className) {
+ var element = document.createElement(type);
+ parentElement.appendChild(element);
+ if (className) {
+ element.className = className;
+ }
+ return element;
+};
+
Palette.prototype.create = function(document, parentElement) {
var palette = this;
- var createChild = function(type, parentElement) {
- var element = document.createElement(type);
- parentElement.appendChild(element);
- return element;
- };
- var table = createChild("table", parentElement);
- table.class = "palette";
+ var table = Palette.createChild("div", parentElement, "palette");
+ table.width="300px";
- var row = createChild("tr", table);
- row.style.display = "block";
+ this.tooltip = new Tooltip();
- createChild("td", row).innerText = "Filter:";
- this.filterBar = createChild("input", createChild("td", row));
+ var row = Palette.createChild("div", table, "header");
+ row.style.visibility = "visible";
+
+ Palette.createChild("span", row).textContent = "Filter:";
+ this.filterBar = Palette.createChild("input", Palette.createChild("span", row));
+ this.filterBar.type = "search";
this.filterBar.onkeyup = function() {
palette.filter(palette.filterBar.value)
};
- var go = document.createElement("button");
- createChild("td", row).appendChild(go);
- go.innerText = "Redraw"
+ this.filterBar.onclick = this.filterBar.onkeyup;
+ var go = Palette.createChild("button", Palette.createChild("span", row));
+ go.textContent = "Redraw"
go.onclick = function() {
palette.onchange();
};
+ // CURRENTLY HIDDEN.
+ var tmp = Palette.createChild("button", Palette.createChild("span", row));
+ tmp.textContent = "Copy"
+ tmp.onclick = function() {
+ var textarea = new TextArea();
+ textarea.show("header", "Now is the time for all good men\nto come to the aid of their country");
+ };
+ tmp.style.display = "none";
+
for (var opt in opts) {
try {
if (opts.hasOwnProperty(opt)) {
var type = opts[opt].type;
var isFunction = type.indexOf("function(") == 0;
- var row = createChild("tr", table);
- var div = createChild("div", createChild("td", row));
- var a = createChild("a", div);
- a.innerText = opt;
- a.href = "http://dygraphs.com/options.html#" + opt;
- a.title = Dygraph.OPTIONS_REFERENCE[opt].description;
- a.target="_blank";
+ var row = Palette.createChild("div", table);
+ row.onmouseover = function(source, title, type, body, e) {
+ return function(e) {
+ palette.tooltip.show(source, e, title, type, body);
+ };
+ } (row, opt, type, Dygraph.OPTIONS_REFERENCE[opt].description);
+ row.onmouseout = function() { palette.tooltip.hide(); };
+
+ var div = Palette.createChild("span", row, "name");
+ div.textContent = opt;
+
+ var value = Palette.createChild("span", row, "option");
if (isFunction) {
- var input = createChild("button", createChild("td", row));
+ var input = Palette.createChild("button", value);
input.onclick = function(opt, palette) {
return function(event) {
var entry = palette.model[opt];
var inputValue = entry.functionString;
if (inputValue == null || inputValue.length == 0) {
- inputValue = type + "{ }";
+ inputValue = opts[opt].type + "{\n\n}";
}
- var value = prompt("enter function", inputValue);
- if (value != null) {
- if (value.length == 0) {
- value = null;
- }
+ var textarea = new TextArea();
+ textarea.show(opt, inputValue);
+ textarea.okCallback = function(value) {
if (value != inputValue) {
entry.functionString = value;
- entry.input.innerText = value ? "defined" : "not defined";
+ entry.input.textContent = value ? "defined" : "not defined";
palette.onchange();
}
}
}
}(opt, this);
} else {
- var input = createChild("input", createChild("td", row));
+ var input = Palette.createChild("input", value, "textInput");
+ if (type == "boolean") {
+ input.size = "5";
+ input.maxlength = "5";
+ }
input.onkeypress = function(event) {
var keycode = event.which;
if (keycode == 13 || keycode == 8) {
input.value = value.join(", ");
}
} else if (type.indexOf("function(") == 0) {
- input.innerText = value ? "defined" : "not defined";
+ input.textContent = value ? "defined" : "not defined";
this.model[opt].functionString = value ? value.toString() : null;
} else {
if (value) {
Palette.prototype.filter = function(pattern) {
pattern = pattern.toLowerCase();
+ var even = true;
for (var opt in this.model) {
if (this.model.hasOwnProperty(opt)) {
var row = this.model[opt].row;
- row.style.display = (opt.toLowerCase().indexOf(pattern) >= 0) ? "block" : "none";
+ var matches = opt.toLowerCase().indexOf(pattern) >= 0;
+ row.style.display = matches ? "block" : "none";
+ if (matches) {
+ row.className = even ? "even" : "odd";
+ even = !even;
+ }
}
}
}