From b4f1e020cfd619d748ec9174c8b6dfcf50146b59 Mon Sep 17 00:00:00 2001 From: Kerrick Long Date: Wed, 13 Jul 2011 01:46:56 -0500 Subject: [PATCH] New option to set popup width! --- fancy-settings/manifest.js | 21 +++++++++++++++++++++ html/popup.html | 1 + js/common.js | 35 +++++++++++++++++++++++++---------- 3 files changed, 47 insertions(+), 10 deletions(-) diff --git a/fancy-settings/manifest.js b/fancy-settings/manifest.js index 8ef8b60..fc1fd06 100755 --- a/fancy-settings/manifest.js +++ b/fancy-settings/manifest.js @@ -91,6 +91,27 @@ this.manifest = { "name": "freshCutoffDescription", "type": "description", "text": "

This setting allows you to choose the oldest reddit posts you’d like to see. Anything posted before the value you’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": "

This setting allows you to set the width of the browser action popup." } ] }; diff --git a/html/popup.html b/html/popup.html index 370ddd0..cea3ed0 100644 --- a/html/popup.html +++ b/html/popup.html @@ -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); diff --git a/js/common.js b/js/common.js index b5a0d7a..1902300 100644 --- a/js/common.js +++ b/js/common.js @@ -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 = '

    '; + listHTML = '
      '; staleCounter = 0; utils.forEachIn(cache.get(url).posts, function (name, value) { @@ -580,7 +595,7 @@ Popup.prototype.createListHTML = function (url) { listHTML += '
    ' if (staleCounter > 0) { - listHTML += '
    Hiding ' + staleCounter.toString() + ' stale posts. Visit the options page to change your Fresh Content preferences.
    '; + listHTML += '
    Hiding ' + staleCounter.toString() + ' stale posts. Visit the options page to change your Fresh Content preferences.
    '; } return listHTML;