Permalink
Browse files

Trying to get a presets selector to work; updated package.json

  • Loading branch information...
lmorchard committed Feb 3, 2011
1 parent 8730c68 commit b71bb9458a305542e34724bb7bf3ccfc483a3a0b
Showing with 67 additions and 34 deletions.
  1. +50 −26 data/js/options.js
  2. +10 −2 data/options.html
  3. +1 −1 lib/main.js
  4. +6 −5 package.json
View
@@ -1,5 +1,10 @@
var Options = (function () {
+ var DEFAULT_PRESETS = [
+ ['Production', 'http://snippets.mozilla.com/%STARTPAGE_VERSION%/%NAME%/%VERSION%/%APPBUILDID%/%BUILD_TARGET%/%LOCALE%/%CHANNEL%/%OS_VERSION%/%DISTRIBUTION%/%DISTRIBUTION_VERSION%/'],
+ ['Staging', 'http://snippets.stage.mozilla.com/%STARTPAGE_VERSION%/%NAME%/%VERSION%/%APPBUILDID%/%BUILD_TARGET%/%LOCALE%/%CHANNEL%/%OS_VERSION%/%DISTRIBUTION%/%DISTRIBUTION_VERSION%/'],
+ ];
+
var $this = {
update_url: null,
@@ -11,13 +16,57 @@ var Options = (function () {
],
init: function () {
+ $this.presets = JSON.parse(localStorage["presets"])
+ if (!$this.presets) {
+ $this.presets = DEFAULT_PRESETS;
+ localStorage["presets"] = JSON.stringify($this.presets);
+ }
+ console.log("PRESETS " + $this.presets.length);
+
$(document).ready($this.ready);
+
return this;
},
ready: function () {
-
$this.createFields();
+ // TODO: Make this work!
+ // $this.createPresets();
+ $this.wireUpControls();
+ postMessage({ type: 'fetch_update_url' });
+ },
+
+ onMessage: function (event) {
+ switch (event.type) {
+ case 'receive_update_url':
+ $this.update_url = event.update_url;
+ $this.updateFields($this.parseUrlFields($this.update_url));
+ break;
+ };
+ },
+
+ createFields: function () {
+ var url_fields = $('#option_controls ul.url_fields');
+ $('li:not(.template)', url_fields).remove();
+ var tmpl = $('li.template', url_fields);
+
+ for (var i=0, name; name=$this.fields[i]; i++) {
+ tmpl.cloneTemplate({
+ 'label': name, 'input @name': name
+ }).appendTo(url_fields);
+ }
+ },
+
+ createPresets: function () {
+ var html = '<select name="presets">';
+ for (var i=0, pair; pair=$this.presets[i]; i++) {
+ html += '<option value="'+pair[1]+'">'+pair[0]+'</option>';
+ }
+ html += '</select>';
+ $('.presets_field li').append(html);
+ },
+
+ wireUpControls: function () {
$('#option_controls').submit(function () { return false; });
@@ -37,31 +86,6 @@ var Options = (function () {
return false;
});
- postMessage({ type: 'fetch_update_url' });
-
- },
-
- onMessage: function (event) {
- switch (event.type) {
- case 'receive_update_url':
- $this.update_url = event.update_url;
- var fields = $this.parseUrlFields($this.update_url);
- $this.updateFields(fields);
- break;
- };
- },
-
- createFields: function () {
- $('#option_controls ul li:not(.template)').remove();
- var tmpl = $('#option_controls li.template');
- var ul = $('#option_controls ul');
-
- for (var i=0, name; name=$this.fields[i]; i++) {
- tmpl.cloneTemplate({
- 'label': name,
- 'input @name': name
- }).appendTo(ul);
- }
},
parseUrlFields: function (url) {
View
@@ -5,13 +5,21 @@
<body>
<form id="option_controls">
- <fieldset><legend>Snippets update URL</legend>
- <ul>
+ <fieldset><legend>about:home snippets service</legend>
+ <ul class="url_fields">
<li class="template field">
<label>Label</label>
<input type="text" name="sample" size="40" />
</li>
</ul>
+ <!--
+ <ul class="presets_field">
+ <li class="field">
+ <label>Presets</label>
+ <select name="presets"> </select>
+ </li>
+ </ul>
+ -->
<div class="submit">
<button class="change">Change update URL</button>
<button class="restore">Restore defaults</button>
View
@@ -44,7 +44,7 @@ exports.main = function (options, callbacks) {
content: 'SNIPPETS!',
width: 100,
panel: panel.Panel({
- width: 350, height: 700,
+ width: 350, height: 750,
contentURL: data.url('options.html'),
contentScriptFile: [
data.url('js/jquery-1.5.min.js'),
View
@@ -1,9 +1,10 @@
{
+ "id": "jid0-WRIDmRdJMF3XFFZZwnaBhDniAN8",
"name": "home-snippets-switcher",
+ "version": "0.2",
+ "fullName": "about:home snippet service switcher",
+ "description": "Helps you to manage the snippet service used for about:home",
"license": "MPL 1.1/GPL 2.0/LGPL 2.1",
- "author": "",
- "version": "0.1",
- "fullName": "home-snippets-switcher",
- "id": "jid0-WRIDmRdJMF3XFFZZwnaBhDniAN8",
- "description": "a basic add-on"
+ "author": "l.m.orchard <l.m.orchard@pobox.com> (http://lmorchard.com)",
+ "url": "http://github.com/lmorchard/home-snippets-switcher"
}

0 comments on commit b71bb94

Please sign in to comment.