Merge branch 'v3' into RAL

This commit is contained in:
Zixaphir 2014-01-05 09:36:25 -07:00
commit a1d0bf1474
4 changed files with 36 additions and 67 deletions

View File

@ -9534,11 +9534,9 @@
posts = Object.keys(Unread.thread.posts); posts = Object.keys(Unread.thread.posts);
root = Unread.thread.posts[posts[posts.length - 1]].nodes.root; root = Unread.thread.posts[posts[posts.length - 1]].nodes.root;
} }
return $.on(window, 'load', function() { if (Header.getBottomOf(root) < 0) {
if (Header.getBottomOf(root) < 0) { return Header.scrollTo(root, down);
return Header.scrollTo(root, down); }
}
});
}, },
sync: function() { sync: function() {
var lastReadPost, post; var lastReadPost, post;

View File

@ -772,39 +772,24 @@
}; };
$.set = (function() { $.set = (function() {
var items, setAll, setArea, timeout; var items, localItems, set;
items = { items = {};
sync: {}, localItems = {};
local: {} set = $.debounce($.SECOND, function() {
};
timeout = {};
setArea = function(area) {
if (timeout[area]) {
return;
}
return chrome.storage[area].set(items[area], function() {
if (chrome.runtime.lastError) {
c.error(chrome.runtime.lastError.message);
timeout[area] = setTimeout(setArea, $.MINUTE, area);
return;
}
items[area] = {};
return delete timeout[area];
});
};
setAll = $.debounce($.SECOND, function() {
var err, key, _i, _len, _ref; var err, key, _i, _len, _ref;
_ref = $.localKeys; _ref = $.localKeys;
for (_i = 0, _len = _ref.length; _i < _len; _i++) { for (_i = 0, _len = _ref.length; _i < _len; _i++) {
key = _ref[_i]; key = _ref[_i];
if (key in items.sync) { if (key in items) {
items.local[key] = items.sync[key]; (localItems || (localItems = {}))[key] = items[key];
delete items.sync[key]; delete items[key];
} }
} }
try { try {
setArea('local'); chrome.storage.local.set(localItems);
return setArea('sync'); chrome.storage.sync.set(items);
items = {};
return localItems = {};
} catch (_error) { } catch (_error) {
err = _error; err = _error;
return c.error(err.stack); return c.error(err.stack);
@ -812,11 +797,11 @@
}); });
return function(key, val) { return function(key, val) {
if (typeof key === 'string') { if (typeof key === 'string') {
items.sync[key] = val; items[key] = val;
} else { } else {
$.extend(items.sync, key); $.extend(items, key);
} }
return setAll(); return set();
}; };
})(); })();
@ -9532,11 +9517,9 @@
posts = Object.keys(Unread.thread.posts); posts = Object.keys(Unread.thread.posts);
root = Unread.thread.posts[posts[posts.length - 1]].nodes.root; root = Unread.thread.posts[posts[posts.length - 1]].nodes.root;
} }
return $.on(window, 'load', function() { if (Header.getBottomOf(root) < 0) {
if (Header.getBottomOf(root) < 0) { return Header.scrollTo(root, down);
return Header.scrollTo(root, down); }
}
});
}, },
sync: function() { sync: function() {
var lastReadPost, post; var lastReadPost, post;

View File

@ -329,38 +329,28 @@ $.get = (key, val, cb) ->
chrome.storage.sync.get syncItems, done chrome.storage.sync.get syncItems, done
$.set = do -> $.set = do ->
items = items = {}
sync: {} localItems = {}
local: {}
timeout = {}
setArea = (area) -> set = $.debounce $.SECOND, ->
return if timeout[area]
chrome.storage[area].set items[area], ->
if chrome.runtime.lastError
c.error chrome.runtime.lastError.message
timeout[area] = setTimeout setArea, $.MINUTE, area
return
items[area] = {}
delete timeout[area]
setAll = $.debounce $.SECOND, ->
for key in $.localKeys for key in $.localKeys
if key of items.sync if key of items
items.local[key] = items.sync[key] (localItems or= {})[key] = items[key]
delete items.sync[key] delete items[key]
try try
setArea 'local' chrome.storage.local.set localItems
setArea 'sync' chrome.storage.sync.set items
items = {}
localItems = {}
catch err catch err
c.error err.stack c.error err.stack
(key, val) -> (key, val) ->
if typeof key is 'string' if typeof key is 'string'
items.sync[key] = val items[key] = val
else else
$.extend items.sync, key $.extend items, key
setAll() set()
<% } else { %> <% } else { %>

View File

@ -46,11 +46,9 @@ Unread =
# Scroll to the last read post. # Scroll to the last read post.
posts = Object.keys Unread.thread.posts posts = Object.keys Unread.thread.posts
{root} = Unread.thread.posts[posts[posts.length - 1]].nodes {root} = Unread.thread.posts[posts[posts.length - 1]].nodes
# Prevent the browser to scroll back to
# the previous scroll location on page load. # Scroll to the target unless we scrolled past it.
$.on window, 'load', -> Header.scrollTo root, down if Header.getBottomOf(root) < 0
# Scroll to the target unless we scrolled past it.
Header.scrollTo root, down if Header.getBottomOf(root) < 0
sync: -> sync: ->
lastReadPost = Unread.db.get lastReadPost = Unread.db.get