Skip to content
This repository has been archived by the owner on Feb 19, 2019. It is now read-only.

Commit

Permalink
Trying to get a presets selector to work; updated package.json
Browse files Browse the repository at this point in the history
  • Loading branch information
lmorchard committed Feb 3, 2011
1 parent 8730c68 commit b71bb94
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 34 deletions.
76 changes: 50 additions & 26 deletions data/js/options.js
@@ -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,
Expand All @@ -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; });

Expand All @@ -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) {
Expand Down
12 changes: 10 additions & 2 deletions data/options.html
Expand Up @@ -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>
Expand Down
2 changes: 1 addition & 1 deletion lib/main.js
Expand Up @@ -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'),
Expand Down
11 changes: 6 additions & 5 deletions package.json
@@ -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.