Skip to content

Commit

Permalink
Move Preferences out of content to the Add-ons Manager
Browse files Browse the repository at this point in the history
  • Loading branch information
mnoorenberghe committed Jan 28, 2018
1 parent 4dc2063 commit f98e090
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 226 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
build:
mkdir -p output
zip -r -FS output/bugzillajs.xpi js css icon.png icon64.png manifest.json
zip -r -FS output/bugzillajs.xpi js css icon.png icon64.png manifest.json options/options.js options/options.html

clean:
mkdir -p output && rm -R output/
Expand Down
121 changes: 0 additions & 121 deletions css/bugzillajs.css
Original file line number Diff line number Diff line change
@@ -1,124 +1,3 @@
#prefs {
padding:10px;
background-color:#f3f3f3;
border: 1px solid #777777;
border-radius: 5px 5px 5px 5px;
box-shadow: 0 0 30px #333333;
left: 50%;
margin: auto auto auto -200px;
position: fixed;
top: 40px;
z-index: 2;
}

#prefs .header {
overflow: auto;
margin-bottom: 1em;
min-width: 400px;
height: 350px;
resize: both;
}

#prefs h3 {
margin: 1em 0 0;
}
#prefs h3:first-child {
margin-top: 0;
}
#prefs p {
font-size: 0.9em;
margin: 0 0 5px;
color: #555;
}
#prefs input {
margin-right: 10px;
}
#prefs label {
font-size: 0.9em;
}

#prefs a.refresh {
background-color: #FFFFFF;
background-image: -webkit-gradient(
linear,
left bottom,
left top,
color-stop(0.33, rgb(232,232,232)),
color-stop(0.84, rgb(255,255,255))
);
background-image: -moz-linear-gradient(
center bottom,
rgb(232,232,232) 33%,
rgb(255,255,255) 84%
);
border: 1px solid #AAAAAA;
border-radius: 3px 3px 3px 3px;
box-shadow: 0 -2px 0 #DDDDDD inset;
color: #333333;
display: inline-block;
padding: 3px 7px;
text-decoration: none;
margin-right: 10px;
}

#prefs a.refresh:active {
background-image: -webkit-gradient(
linear,
left bottom,
left top,
color-stop(0.33, rgb(255,255,255)),
color-stop(0.84, rgb(232,232,232))
);
background-image: -moz-linear-gradient(
center bottom,
rgb(255,255,255) 33%,
rgb(232,232,232) 84%
);
}

#prefs a {
color: #333;
}

#prefs a:hover {
text-decoration: none;
}

#prefs a.refresh:hover {
border: 1px solid #777;
color: #000;
}

#prefs label {
color: #444;
}

#prefs label:hover {
color: #000;
cursor: pointer;
}

#prefs .cta,
#prefs .cta2 {
display: block;
padding-bottom: 4px;
text-decoration: border;
opacity: 0.7;
}

#prefs .cta:hover,
#prefs .cta2:hover {
opacity: 0.9;
}

#prefs .cta {
color: red;
}
#prefs .cta2 {
color: green;
margin-bottom: 1em;
}

span.assignee {
padding-left: 10px;
color: #E41313;
Expand Down
99 changes: 0 additions & 99 deletions js/bugzilla.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ registerPref('gitcomments', {'title': 'Style the comments like Github',
'category': 'bug'});

/** Run the modules **/
addPrefs();
function ifBug(f) {
if (bug_id) {
return f;
Expand All @@ -50,104 +49,6 @@ function repositionScroll() {
}
}

function addPrefs() {
var $appendTo;
var $li = $('<li>');
var $a = $('<a>', {'class': 'bjs-prefs',
'href': '#',
'text': 'BugzillaJS Preferences'});
$li.append($a);

if (is_mozilla_theme) {
$appendTo = $('#moz_login .dropdown li:eq(1)');
$appendTo.after($li);
} else {
$appendTo = $('#header > .links, #links-actions .links');
$appendTo.append($('<span>', {'class': 'separator', 'text': '| '}));
$appendTo.append($li.clone());
}

$('a.bjs-prefs').click(openPrefs);

// Close on <esc>
$(window).bind('close', function(e) {
$('#prefs').remove();
});

}

function openPrefs(e) {
if (e) {
e.preventDefault();
}

$('#prefs').remove();

var $prefs = $('<div>', {'id': 'prefs'});
var $prefs_h = $('<div>', {'class': 'header'});
var $prefs_f = $('<div>', {'class': 'footer'});

$('body').append($prefs);
$prefs.append($prefs_h).append($prefs_f);

$.each(categories, function(v, k) {
var content = k.split(' | '),
title = content[0],
desc = content[1];

var $h3 = $('<h3>', {'text': title}),
$desc = $('<p>', {'text': desc}),
$opts = $('<div>', {'id': 'cat-' + v});

$prefs_h.append($h3);
$prefs_h.append($desc);
$prefs_h.append($opts);
});

$.each(settings_fields, function(k, v) {
var $opt = $('<div>');

$opt.append($('<input>', {'type': 'checkbox',
'id': 'setting_' + v.slug,
'data-slug': v.slug,
'checked': settings[v.slug]}));

$opt.append($('<label>', {'for': 'setting_' + v.slug,
'text': v.details}));

if (v.is_new) {
$opt.find('label').prepend($('<span>', {'class': 'show_new',
'text': 'new'}));
}

$('#cat-' + v.category).append($opt);
});

/* Save button */
var $save = $('<a>', {'class': 'refresh',
'text': 'Save Changes',
'href': '#'});
$save.appendTo($prefs_f);
$save.click(function() {
$('input', $prefs_h).each(function() {
var setting_name = 'settings_' + $(this).attr('data-slug');
browser.storage.sync.set({
[setting_name]: $(this).is(':checked'),
});
});

window.location.reload();
return false;
});

var close_button = $('<a>', {'href': '#', 'text': 'cancel'});
close_button.appendTo($prefs_f);
close_button.click(function(e) {
e.preventDefault();
$(window).trigger('close');
});
}

function registerPref(slug, o) {
/* TODO: integrate these */
registerPref_old(slug,
Expand Down
5 changes: 2 additions & 3 deletions legacy/bugzilla-keyboard.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

/* global registerPref, $, _, settings, unsafeWindow, openPrefs */
/* global registerPref, $, _, settings, unsafeWindow */

registerPref('keyboard', {'title': 'Enable keyboard shortcuts',
'setting_default': false,
Expand Down Expand Up @@ -230,7 +230,7 @@ function initKB() {

addShortcut('gp', 'Go to preferences', './userprefs.cgi');

addShortcut('g,', 'Go to BugzillaJS prefs', openPrefs);
//addShortcut('g,', 'Go to BugzillaJS prefs', openPrefs);

newTable();

Expand Down Expand Up @@ -268,4 +268,3 @@ function initKB() {
}
});
}

4 changes: 2 additions & 2 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"manifest_version": 2,
"name": "BugzillaJS",
"version": "4.1.0",
"version": "4.2.0",

"description": "Add features to Bugzilla.",

Expand Down Expand Up @@ -54,7 +54,7 @@
},

"options_ui": {
"page": "options.html",
"page": "options/options.html",
"browser_style": true
},

Expand Down
58 changes: 58 additions & 0 deletions options/options.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>BugzillaJS Options</title>
</head>
<body>
<div id="prefs">
<p>Changes take effect on the next load of a Bugzilla page.</p>
<!--
See legacy/bugzilla-keyboard.js
<h3>Keyboard Shortcuts</h3>
<p>To view all keyboard shortcuts, type "?" on any page.</p>
<div></div>
-->

<h3>Improve Comments</h3>
<p>Make the comments on bugs more readable.</p>
<div>
<div><label><input id="reporter_assignee" type="checkbox">Highlight reporter and assignee comments</label></div>
<div><label><input id="commentoverflow" type="checkbox">Add scrollbar to overflowing comments</label></div>
<div><label><input id="hidefirst" type="checkbox">Hide the first comment if empty</label></div>
</div>

<h3>Show inline media</h3>
<p>Show images and other types of content right in the comments.</p>
<div>
<div><label><input id="gallery" type="checkbox">Display images and attachments as an inline gallery</label></div>
<div><label><input id="lightbox" type="checkbox">Use lightbox for images</label></div>
<div><label><input id="gravatar" type="checkbox">Show gravatars in comments</label></div>
</div>

<h3>Improve Bugs</h3>
<p>These pertain to editing bugs.</p>
<div>
<div><label><input id="gitcomments" type="checkbox">Style the comments like Github</label></div>
<div><label><input id="removeflags" type="checkbox">Remove flags, status and blocking fields</label></div>
<div><label><input id="removeaccesskeys" type="checkbox">Remove access keys</label></div>
<div><label><input id="dontguess" type="checkbox">Don't guess OS and hardware</label></div>
<div><label><input id="relatedbug" type="checkbox">Add a "new" link for dependent and blocking fields</label></div>
<div><label><input id="browseComponent" type="checkbox">Add a "browse" link for component fields</label></div>
</div>

<h3>Listing Pages</h3>
<p>These modify parts of the pages with lists of bugs.</p>
<div>
<div><label><input id="openall" type="checkbox">Option to open all bugs in tabs</label></div>
</div>

<h3>Miscellaneous</h3>
<p>These are other tidbits that do not fit into other categories.</p>
<div>
<div><label><input id="savedSearchDropDown" type="checkbox">Makes saved searches into a dropdown (requires Mozilla skin)</label></div>
</div>
</div>
<script src="options.js" defer></script>
</body>
</html>
20 changes: 20 additions & 0 deletions options/options.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
browser.storage.sync.get().then((result) => {
for (let [setting, value] of Object.entries(result)) {
if (!setting.startsWith("settings_")) {
continue;
}
let checkbox = document.getElementById(setting.replace(/^settings_/, ""));
if (!checkbox) {
continue;
}
checkbox.checked = value;
}
console.log(result);
});

document.getElementById("prefs").addEventListener("change", function onChange(event) {
let setting_name = 'settings_' + event.target.id;
browser.storage.sync.set({
[setting_name]: event.target.checked,
});
});

0 comments on commit f98e090

Please sign in to comment.