Merge branch 'pre' of insomnia247.nl:/home/benweet/stackedit into pre

This commit is contained in:
benweet 2014-05-19 19:08:03 +01:00
commit 0e64598127
2 changed files with 52 additions and 37 deletions

View File

@ -91,7 +91,6 @@ define([
var isScrollPreview = false;
var isEditorMoving = false;
var isPreviewMoving = false;
var scrollingHelper = $('<div>');
function getDestScrollTop(srcScrollTop, srcSectionList, destSectionList) {
// Find the section corresponding to the offset
var sectionIndex;
@ -108,6 +107,34 @@ define([
return destSection.startOffset + destSection.height * posInSection;
}
var timeoutId;
var currentEndCb;
function animate(elt, startValue, endValue, stepCb, endCb) {
if(currentEndCb) {
clearTimeout(timeoutId);
currentEndCb();
}
currentEndCb = endCb;
var diff = endValue - startValue;
var startTime = Date.now();
function tick() {
var currentTime = Date.now();
var progress = (currentTime - startTime) / 200;
if(progress < 1) {
var scrollTop = startValue + diff * Math.cos((1 - progress) * Math.PI / 2 );
elt.scrollTop = scrollTop;
stepCb(scrollTop);
timeoutId = setTimeout(tick, 1);
}
else {
currentEndCb = undefined;
elt.scrollTop = endValue;
endCb();
}
}
tick();
}
var doScrollSync = _.throttle(function() {
if(!isPreviewVisible || mdSectionList.length === 0 || mdSectionList.length !== htmlSectionList.length) {
return;
@ -134,24 +161,12 @@ define([
lastPreviewScrollTop = previewScrollTop;
return;
}
scrollingHelper.stop('scrollSyncFx', true).css('value', 0).animate({
value: destScrollTop - previewScrollTop
}, {
easing: 'easeOutSine',
duration: 200,
queue: 'scrollSyncFx',
step: function(now) {
animate($previewElt[0], previewScrollTop, destScrollTop, function(currentScrollTop) {
isPreviewMoving = true;
lastPreviewScrollTop = previewScrollTop + now;
$previewElt.scrollTop(lastPreviewScrollTop);
},
done: function() {
setTimeout(function() {
lastPreviewScrollTop = currentScrollTop;
}, function() {
isPreviewMoving = false;
}, 10);
},
}).dequeue('scrollSyncFx');
});
}
else if(isScrollPreview === true) {
if(Math.abs(previewScrollTop - lastPreviewScrollTop) <= 9) {
@ -170,23 +185,12 @@ define([
lastEditorScrollTop = editorScrollTop;
return;
}
scrollingHelper.stop('scrollSyncFx', true).css('value', 0).animate({
value: destScrollTop - editorScrollTop
}, {
easing: 'easeOutSine',
duration: 200,
queue: 'scrollSyncFx',
step: function(now) {
animate($editorElt[0], editorScrollTop, destScrollTop, function(currentScrollTop) {
isEditorMoving = true;
lastEditorScrollTop = editorScrollTop + now;
$editorElt.scrollTop(lastEditorScrollTop);
},
done: function() {
setTimeout(function() {
lastEditorScrollTop = currentScrollTop;
}, function() {
isEditorMoving = false;
}, 10);
},
}).dequeue('scrollSyncFx');
});
}
}, 100);

View File

@ -108,6 +108,7 @@ define([
'https://www.googleapis.com/auth/photos'
]
};
var oauthIframes = [];
function authenticate(task, permission, accountId) {
var authorizationMgr = authorizationMgrMap[accountId];
if(!authorizationMgr) {
@ -161,6 +162,16 @@ define([
immediate: immediate,
authuser: immediate === false ? '' : authuser
}, function(authResult) {
// Hack to clean window from old oauth iframes
authorizationMgr.$oauthIframe && authorizationMgr.$oauthIframe.remove();
var currentOauthIframes = _.filter(document.querySelectorAll('iframe'), function(iframe) {
var src = iframe.getAttribute('src');
return src && src.indexOf('https://accounts.google.com/o/oauth2/auth') === 0;
});
authorizationMgr.$oauthIframe = $(_.difference(currentOauthIframes, oauthIframes));
oauthIframes = currentOauthIframes;
newToken = gapi.auth.getToken();
gapi.auth.setToken(currentToken);
if(!authResult || authResult.error) {