diff --git a/source/js/classes/fancy-settings.js b/source/js/classes/fancy-settings.js index bf80147..11c04ae 100644 --- a/source/js/classes/fancy-settings.js +++ b/source/js/classes/fancy-settings.js @@ -82,7 +82,40 @@ } }); - this.FancySettings.initWithManifest = function (name) { - //TBI + this.FancySettings.initWithManifest = function (name, callback) { + var request = new Request({ + "url": name + }); + request.addEvent("complete", function () { + var response = request.response.text; + + // Remove single line comments + response = response.replace(/\/\/.*\n/g, ""); + + try { + response = JSON.parse(response); + } catch (e) { + throw "errorParsingManifest"; + } + + var settings = new FancySettings(response.name); + settings.manifestOutput = {}; + + response.tabs.each(function (tab) { + tab.groups.each(function (group) { + group.settings.each(function (setting) { + var output = settings.create(tab.name, group.name, setting.type, setting); + if (typeOf(setting.name) === "string" && setting.name !== "") { + settings.manifestOutput[setting.name] = output; + } + }) + }); + }); + + if (typeOf(callback) === "function") { + callback(settings); + } + }); + request.send(); }; }()); diff --git a/source/manifest.json b/source/manifest.json index 0296d5f..71c2c7a 100755 --- a/source/manifest.json +++ b/source/manifest.json @@ -5,6 +5,11 @@ // so you might wanna consider specifing // your settings manually in the settings.js // file. Instructions are included. +// +// Even if you choose to use the manifest file, +// you can manually customize the settings. +// Enter a name for each setting, and you +// can access them in the settings.js file. { "name": "My Extension", "tabs": [ @@ -15,13 +20,15 @@ "name": "Group 1", "settings": [ { + "name": "description1", "type": "description", "text": "This is a description. You can write any text inside of this." }, { + "name": "button1", "type": "button", - "label": "This describes the action:" - "text": "Button Text" + "label": "Describe the action:", + "text": "Go" } ] }, @@ -29,12 +36,14 @@ "name": "Group 2", "settings": [ { + "name": "textBox1", "type": "text", - "label": "Enter for information:" + "label": "Enter for information:", "text": "e.g. \"sample\"", "masked": false }, { + "name": "checkbox1", "type": "checkbox", "label": "Enable this" } @@ -49,22 +58,24 @@ "name": "Group 3", "settings": [ { + "name": "slider1", "type": "slider", - "label": "Pair of shoes", + "label": "Sound volume:", "max": 100, "min": 0, "step": 1 }, { + "name": "popupButton1", "type": "popupButton", - "label": "Choose this:", + "label": "Soup should be:", "options": [ { - "value": "value_1", - "name": "Value 1" + "value": "hot", + "text": "Hot and yummy" }, { - "value": "value_2" + "value": "cold" } ] } @@ -74,28 +85,30 @@ "name": "Group 4", "settings": [ { + "name": "listBox1", "type": "listBox", - "label": "Choose this:", + "label": "Soup should be:", "options": [ { - "value": "value_1", - "name": "Value 1" + "value": "hot", + "text": "Hot and yummy" }, { - "value": "value_2" + "value": "cold" } ] }, { + "name": "radioButtons1", "type": "radioButtons", - "label": "Choose this:", + "label": "Soup should be:", "options": [ { - "value": "value_1", - "name": "Value 1" + "value": "hot", + "text": "Hot and yummy" }, { - "value": "value_2" + "value": "cold" } ] } diff --git a/source/settings.js b/source/settings.js index cee1acf..7c6e147 100755 --- a/source/settings.js +++ b/source/settings.js @@ -1,60 +1,24 @@ window.addEvent("domready", function () { - var settings = new FancySettings("My Extension"); - //var settings = new FancySettings.initWithManifest("manifest.json"); + // Option 1: Use the manifest: - // Add your settings here - // Example: - // settings.create("Tab 1", "Group 1", "text", { - // "label": "Enter your Birthday:", - // "text": "e.g. \"18\"" + // new FancySettings.initWithManifest("manifest.json", function (settings) { + // settings.manifestOutput.button1.addEvent("action", function () { + // alert("hello, here i am"); + // }); // }); - // - // or use the manifest and replace the line above with - // var settings = new FancySettings.initWithManifest("manifest.json"); + // Option 2: Do everything manually: - - - - - - settings.create("General", "Behavior", "text", { - "name": "label", - "label": "GMail Label:", - "text": "e.g. \"notifications\"" - }); - settings.create("test", "Behavior", "radioButtons", { - "name": "open_emails_in", - "label": "Open Emails in:", - "options": [ - { - "value": "new_tab", - "text": "a new tab" - }, - { - "value": "new_window", - "text": "a new window" - }, - { - "value": "gmail_tab", - "text": "an already open GMail tab" - }, - { - "value": "active_tab", - "text": "the active tab" - } - ] - }); - - settings.create("General", "Google Apps", "checkbox", { - "name": "google_apps_enabled", - "label": "Enable Google Apps" - }); - settings.create("General", "Google Apps", "text", { - "name": "google_apps_domain", - "label": "Domain:", - "text": "e.g. \"example.com\"" - }); + // var settings = new FancySettings("My Extension"); + // + // var checkbox1 = settings.create("tabName", "groupName", "checkbox", { + // "name": "checkbox1", + // "label": "Enable this" + // }); + // + // checkbox1.addEvent("action", function (value) { + // alert("you toggled me: " + value); + // }); });