Skip to content

Commit

Permalink
Added manifest support
Browse files Browse the repository at this point in the history
  • Loading branch information
Frank Kohlhepp committed Apr 18, 2011
1 parent cf31be9 commit a036d5f
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 70 deletions.
37 changes: 35 additions & 2 deletions source/js/classes/fancy-settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
};
}());
45 changes: 29 additions & 16 deletions source/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand All @@ -15,26 +20,30 @@
"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"
}
]
},
{
"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"
}
Expand All @@ -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"
}
]
}
Expand All @@ -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"
}
]
}
Expand Down
68 changes: 16 additions & 52 deletions source/settings.js
Original file line number Diff line number Diff line change
@@ -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);
// });
});

0 comments on commit a036d5f

Please sign in to comment.