X-Git-Url: https://adrianiainlam.tk/git/?a=blobdiff_plain;f=experimental%2Fpalette%2Fmulti-palette.js;h=ee01a4c2ff1219379f3954c4cfa836c335fc2fdf;hb=65129ba82d4efe12714be88fa3c792149c00ca10;hp=5556f1909a05b66f37e43ec51709de75255922c9;hpb=b5c7c7a99d83e928e06c45bff23b07bdff4c46f4;p=dygraphs.git diff --git a/experimental/palette/multi-palette.js b/experimental/palette/multi-palette.js index 5556f19..ee01a4c 100644 --- a/experimental/palette/multi-palette.js +++ b/experimental/palette/multi-palette.js @@ -98,7 +98,7 @@ MultiPalette.prototype.createPalette_ = function(key, scope, value) { .text(value)); var palette = new Palette(scope); palette.create(this.root); - palette.root.style.display = "none"; + palette.root.hide(); var self = this; palette.onchange = function() { self.onchange(); @@ -121,58 +121,71 @@ MultiPalette.prototype.conditionallyAddSingleSeries_ = function(series) { MultiPalette.prototype.activate = function(key) { if (this.activePalette) { - this.activePalette.root.style.display = "none"; + this.activePalette.root.hide(); } this.activePalette = this.palettes[key]; - this.activePalette.root.style.display = "block"; + this.activePalette.root.show(); } MultiPalette.prototype.showHash = function() { var hash = this.read(); var textarea = new TextArea(); - textarea.cancel.style.display = "none"; - - /* - * JSON.stringify isn't built to be nice to functions. The following fixes - * this. - * - * First, val.toString only does part of the work, turning it into - * "function () {\n alert(\"p-click!\");\n}", - * - * {start,end}Marker make the surrounding quotes easy to find, and then - * remove them. It also converts the instances of \n and \" so the - * result looks like: - * function () { - * alert("p-click!"); - * }", - */ - var startMarker = "<~%!<"; - var endMarker = ">!%~>"; - var replacer = function(key, val) { - if (typeof val === 'function') { - return startMarker + val.toString() + endMarker; - } - return val; - } - var text = JSON.stringify(hash, replacer, 2); - while(true) { - var start = text.indexOf(startMarker); - var end = text.indexOf(endMarker); - if (start == -1) { - break; - } - var substring = text.substring(start + startMarker.length, end); - while(substring.indexOf("\\n") >= 0) { - substring = substring.replace("\\n", "\n"); + + var hashToString = function(hash) { + /* + * JSON.stringify isn't built to be nice to functions. The following fixes + * this. + * + * First, val.toString only does part of the work, turning it into + * "function () {\n alert(\"p-click!\");\n}", + * + * {start,end}Marker make the surrounding quotes easy to find, and then + * remove them. It also converts the instances of \n and \" so the + * result looks like: + * function () { + * alert("p-click!"); + * }", + */ + var startMarker = "<~%!<"; + var endMarker = ">!%~>"; + var replacer = function(key, val) { + if (typeof val === 'function') { + return startMarker + val.toString() + endMarker; + } + return val; } - while(substring.indexOf("\\\"") >= 0) { - substring = substring.replace("\\\"", "\""); + var text = JSON.stringify(hash, replacer, 2); + while(true) { + var start = text.indexOf(startMarker); + var end = text.indexOf(endMarker); + if (start == -1) { + break; + } + var substring = text.substring(start + startMarker.length, end); + while(substring.indexOf("\\n") >= 0) { + substring = substring.replace("\\n", "\n"); + } + while(substring.indexOf("\\\"") >= 0) { + substring = substring.replace("\\\"", "\""); + } + text = text.substring(0, start - 1) + + substring + + text.substring(end + endMarker.length + 1); } - text = text.substring(0, start - 1) - + substring - + text.substring(end + endMarker.length + 1); + return text; } + + var text = hashToString(hash); + var self = this; textarea.show("options", text); + textarea.okCallback = function(value) { + if (value != text) { + var newHash; + eval("newHash = " + value + ";"); + self.write(newHash); + self.onchange(); + } + }; } /**