New option to set popup width!

This commit is contained in:
Kerrick Long
2011-07-13 01:46:56 -05:00
parent 9f5ac7f09c
commit b4f1e020cf
3 changed files with 47 additions and 10 deletions
+21
View File
@@ -91,6 +91,27 @@ this.manifest = {
"name": "freshCutoffDescription",
"type": "description",
"text": "<p>This setting allows you to choose the oldest reddit posts you&rsquo;d like to see. Anything posted before the value you&rsquo;ve chosen will be indicated in the browser button's total, but will not be shown in the popup."
},
{
"tab": "Preferences",
"group": "Popup Width",
"name": "popupWidth",
"type": "slider",
"label": "",
"max": 784,
"min": 480,
"step": 1,
"display": true,
"displayModifier": function(value) {
return value.toString() + "px";
}
},
{
"tab": "Preferences",
"group": "Popup Width",
"name": "popupWidthDescription",
"type": "description",
"text": "<p>This setting allows you to set the width of the browser action popup."
}
]
};
+1
View File
@@ -18,6 +18,7 @@
document.getElementById('body').style.width = '700px';
}
});
document.getElementById('body').setAttribute('style', 'max-width: ' + settings.get('popupWidth') + 'px');
}
window.addEventListener('load', initPopup);
+25 -10
View File
@@ -2,7 +2,8 @@ var settings, cache, utils, button, reddit, background;
settings = new Store('settings', {
'cacheTime': 1,
'freshCutoff': 7
'freshCutoff': 7,
'popupWidth': 640
});
cache = new Store('cache');
@@ -50,8 +51,22 @@ MHUtils.prototype.forEachIn = function (object, action) {
action(property, object[property]);
}
}
return true;
};
/**
* Iterates over an array.
* @alias MHUtils.forEach(array, action)
* @return {Boolean} Returns true.
* @method
*/
MHUtils.prototype.forEach = function (array, action) {
for (var i = 0; i < array.length; i++) {
action(array[i]);
}
return true;
}
/*
* JavaScript Pretty Date
* Thanks to Dean Landolt's comment on
@@ -247,7 +262,7 @@ RedditAPI.prototype.getInfo = function (url) {
}
response = this.apiTransmit('GET', reqUrl, false);
settings.set('modhash', response.data.modhash);
cache.set('modhash', response.data.modhash);
postsObj = {};
postCount = 0;
@@ -292,7 +307,7 @@ RedditAPI.prototype.voteUpPost = function (e) {
console.log(oldCache.posts[fullName]);
formData = new FormData();
formData.append('id', fullName);
formData.append('uh', settings.get('modhash'));
formData.append('uh', cache.get('modhash'));
if (voteWas === '1') {
formData.append('dir','0');
@@ -330,7 +345,7 @@ RedditAPI.prototype.voteDownPost = function (e) {
oldCache = cache.get(url);
formData = new FormData();
formData.append('id', fullName);
formData.append('uh', settings.get('modhash'));
formData.append('uh', cache.get('modhash'));
if (voteWas === '1') {
formData.append('dir','-1');
@@ -368,7 +383,7 @@ RedditAPI.prototype.savePost = function (e) {
oldCache = cache.get(url);
formData = new FormData();
formData.append('id', fullName);
formData.append('uh', settings.get('modhash'));
formData.append('uh', cache.get('modhash'));
listItem.setAttribute('data-saved', 'true');
listItem.className.replace(/\bsaved\b/,'');
listItem.className += ' unsave';
@@ -397,7 +412,7 @@ RedditAPI.prototype.unsavePost = function (e) {
oldCache = cache.get(url);
formData = new FormData();
formData.append('id', fullName);
formData.append('uh', settings.get('modhash'));
formData.append('uh', cache.get('modhash'));
listItem.setAttribute('data-saved', 'false');
listItem.className.replace(/\bunsave\b/,'');
listItem.className += ' saved';
@@ -426,7 +441,7 @@ RedditAPI.prototype.hidePost = function (e) {
oldCache = cache.get(url);
formData = new FormData();
formData.append('id', fullName);
formData.append('uh', settings.get('modhash'));
formData.append('uh', cache.get('modhash'));
listItem.setAttribute('data-hidestatus', 'true');
e.srcElement.innerHTML = 'unhide';
e.srcElement.onclick = function (event) {reddit.unhidePost(event)};
@@ -454,7 +469,7 @@ RedditAPI.prototype.unhidePost = function (e) {
oldCache = cache.get(url);
formData = new FormData();
formData.append('id', fullName);
formData.append('uh', settings.get('modhash'));
formData.append('uh', cache.get('modhash'));
listItem.setAttribute('data-hidestatus', 'false');
e.srcElement.innerHTML = 'hide';
e.srcElement.onclick = function (event) {reddit.hidePost(event)};
@@ -528,7 +543,7 @@ Popup.prototype.createListHTML = function (url) {
throw 'Cannot create list HTML for a non-cached URL.';
}
listHTML = '<ol id="posts" data-url="' + url + '">';
listHTML = '<ol id="posts" style="width: ' + settings.get('popupWidth') + 'px;" data-url="' + url + '">';
staleCounter = 0;
utils.forEachIn(cache.get(url).posts, function (name, value) {
@@ -580,7 +595,7 @@ Popup.prototype.createListHTML = function (url) {
listHTML += '</ol>'
if (staleCounter > 0) {
listHTML += '<div class="information">Hiding ' + staleCounter.toString() + ' stale posts. Visit the <a target="_blank" href="/fancy-settings/index.html">options page</a> to change your Fresh Content preferences.</div>';
listHTML += '<div class="information" style="width: ' + settings.get('popupWidth') + 'px;">Hiding ' + staleCounter.toString() + ' stale posts. Visit the <a target="_blank" href="/fancy-settings/index.html">options page</a> to change your Fresh Content preferences.</div>';
}
return listHTML;