fix for #148 and better caching of user designs

This commit is contained in:
Hannes Mannerheim 2015-05-19 15:22:52 +02:00
parent 95435143de
commit a28089c89e
2 changed files with 51 additions and 12 deletions

View File

@ -428,6 +428,12 @@ function setNewCurrentStream(stream,actionOnSuccess,setLocation) {
$('#feed').show();
$('#feed-header-inner h2').css('opacity','0.2');
$('#feed-header-inner h2').animate({opacity:'1'},1000);
// also mark this stream as the current stream immediately, if a saved copy exists
addStreamToHistoryMenuAndMarkAsCurrent(streamHeader, defaultStreamName);
// and change design immediately
changeDesign(window.oldStreamsDesigns[window.currentStream]);
}
// otherwise we fade out and wait for stream to load
@ -439,18 +445,6 @@ function setNewCurrentStream(stream,actionOnSuccess,setLocation) {
$('#feed-header-inner h2').html(h2FeedHeader);
});
}
// add this stream to history menu if it doesn't exist there (but not if this is me or if we're not logged in)
if($('.stream-selection[data-stream-header="' + streamHeader + '"]').length==0
&& streamHeader != '@' + window.loggedIn.screen_name
&& typeof window.loggedIn.screen_name != 'undefined') {
$('#history-container').append('<a class="stream-selection" data-stream-header="' + streamHeader + '" href="' + $('.stream-selection.public-timeline').attr('href') + convertStreamToPath(defaultStreamName) + '">' + streamHeader + '<i class="chev-right"></i></a>');
updateHistoryLocalStorage();
}
// mark this stream as current in menu
$('.stream-selection').removeClass('current');
$('.stream-selection[data-stream-header="' + streamHeader + '"]').addClass('current');
// if this is user's user feed, i.e. followers etc, we want a profile card, which we need to get from user_timeline since the users/show api action is broken (auth doesn't work)
@ -484,6 +478,9 @@ function setNewCurrentStream(stream,actionOnSuccess,setLocation) {
window.clearInterval(checkForNewQueetsInterval);
checkForNewQueetsInterval=window.setInterval(function(){checkForNewQueets()},window.timeBetweenPolling);
// add this stream to the history menu
addStreamToHistoryMenuAndMarkAsCurrent(streamHeader, defaultStreamName);
remove_spinner();
$('#feed-body').html(''); // empty feed only now so the scrollers don't flicker on and off
$('#new-queets-bar').parent().addClass('hidden'); document.title = window.siteTitle; // hide new queets bar if it's visible there
@ -526,6 +523,9 @@ function setNewCurrentStream(stream,actionOnSuccess,setLocation) {
window.clearInterval(checkForNewQueetsInterval);
checkForNewQueetsInterval=window.setInterval(function(){checkForNewQueets()},window.timeBetweenPolling);
// add this stream to the history menu
addStreamToHistoryMenuAndMarkAsCurrent(streamHeader, defaultStreamName);
remove_spinner();
$('#feed-body').html(''); // empty feed only now so the scrollers don't flicker on and off
$('#new-queets-bar').parent().addClass('hidden'); document.title = window.siteTitle; // hide new queets bar if it's visible there
@ -539,6 +539,32 @@ function setNewCurrentStream(stream,actionOnSuccess,setLocation) {
});
}
}
/* ·
·
· Add this stream to history menu if it doesn't exist there (but not if this is me or if we're not logged in)
· and mark this stream as current in menu
·
· @param streamHeader: the header to show in the menu
· @param defaultStreamName: the stream to link in the history menu
· @returns: relative path
·
· · · · · · · · · */
function addStreamToHistoryMenuAndMarkAsCurrent(streamHeader, defaultStreamName) {
if($('.stream-selection[data-stream-header="' + streamHeader + '"]').length==0
&& streamHeader != '@' + window.loggedIn.screen_name
&& typeof window.loggedIn.screen_name != 'undefined') {
$('#history-container').append('<a class="stream-selection" data-stream-header="' + streamHeader + '" href="' + window.siteInstanceURL + convertStreamToPath(defaultStreamName) + '">' + streamHeader + '<i class="chev-right"></i></a>');
updateHistoryLocalStorage();
}
$('.stream-selection').removeClass('current');
$('.stream-selection[data-stream-header="' + streamHeader + '"]').addClass('current');
}
/* ·

View File

@ -447,34 +447,47 @@ function changeDesign(obj) {
typeof obj.userBackgroundColor != 'undefined') {
if(obj.userLinkColor == null) {
changeLinkColor(window.defaultLinkColor);
obj.linkcolor = window.defaultLinkColor;
}
else if(obj.userLinkColor.length == 6) {
changeLinkColor('#' + obj.userLinkColor);
obj.linkcolor = obj.userLinkColor;
}
else {
changeLinkColor(window.defaultLinkColor);
}
if(obj.userBackgroundColor == null) {
$('body').css('background-color',window.defaultBackgroundColor);
obj.backgroundcolor = window.defaultBackgroundColor;
}
else if(obj.userBackgroundColor.length == 6) {
$('body').css('background-color','#' + obj.userBackgroundColor);
obj.backgroundcolor = obj.userBackgroundColor;
}
else {
$('body').css('background-color',window.defaultBackgroundColor);
obj.backgroundcolor = window.defaultBackgroundColor;
}
// background image
if(obj.userBackgroundImage.length > 0) {
$('body').css('background-image','url(\'' + obj.userBackgroundImage + '\')');
obj.background_image = obj.userBackgroundImage;
}
else {
$('body').css('background-image','url(\'\')');
}
}
// remember the design for this stream
window.oldStreamsDesigns[window.currentStream] = {backgroundcolor:obj.backgroundcolor, linkcolor:obj.linkcolor, background_image:obj.background_image};
console.log(window.oldStreamsDesigns[window.currentStream]);
}
// create object to remember designs on page load
window.oldStreamsDesigns = new Object();
/* ·
·