From 9390f62431dfa8174b52d0aef45df7b4c7da138e Mon Sep 17 00:00:00 2001 From: Robert Konigsberg Date: Fri, 28 Dec 2012 22:39:26 -0500 Subject: [PATCH] jquery-ify the palette object. --- experimental/palette/multi-palette.js | 6 +- experimental/palette/palette.js | 176 +++++++++++++++++----------------- experimental/palette/tooltip.js | 17 +++- 3 files changed, 105 insertions(+), 94 deletions(-) diff --git a/experimental/palette/multi-palette.js b/experimental/palette/multi-palette.js index 5556f19..2307030 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,10 +121,10 @@ 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() { diff --git a/experimental/palette/palette.js b/experimental/palette/palette.js index 65ef612..8948333 100644 --- a/experimental/palette/palette.js +++ b/experimental/palette/palette.js @@ -38,103 +38,98 @@ function Palette(scope) { this.root = 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(parentElement) { var palette = this; - var table = Palette.createChild("div", parentElement[0], "palette"); - this.root = table; - table.width="300px"; + var table = $("
") + .addClass("palette") + .width(300) + .appendTo(parentElement); + this.root = table; this.tooltip = new Tooltip(); - // Build the header - var header = Palette.createChild("div", table, "header"); - header.style.visibility = "visible"; - // One row per option. - for (var opt in opts) { + $.each(opts, function(opt, optEntry) { try { - if (opts.hasOwnProperty(opt)) { - var type = opts[opt].type; + var scope = optEntry.scope || [ "global" ]; // Scope can be empty, infer "global" only. + var valid = scope[0] == "*" || $.inArray(palette.scope, scope) >= 0; + if (!valid) { + return; + } - var scope = opts[opt].scope || [ "global" ]; // Scope can be empty, infer "global" only. - var valid = scope[0] == "*" || $.inArray(this.scope, scope) >= 0; - if (!valid) { - continue; - } + var type = optEntry.type; + var isFunction = type.indexOf("function(") == 0; + + var input; + if (isFunction) { + input = $("