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

View File

@ -108,6 +108,7 @@ define([
'https://www.googleapis.com/auth/photos' 'https://www.googleapis.com/auth/photos'
] ]
}; };
var oauthIframes = [];
function authenticate(task, permission, accountId) { function authenticate(task, permission, accountId) {
var authorizationMgr = authorizationMgrMap[accountId]; var authorizationMgr = authorizationMgrMap[accountId];
if(!authorizationMgr) { if(!authorizationMgr) {
@ -161,6 +162,16 @@ define([
immediate: immediate, immediate: immediate,
authuser: immediate === false ? '' : authuser authuser: immediate === false ? '' : authuser
}, function(authResult) { }, 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(); newToken = gapi.auth.getToken();
gapi.auth.setToken(currentToken); gapi.auth.setToken(currentToken);
if(!authResult || authResult.error) { if(!authResult || authResult.error) {
@ -257,7 +268,7 @@ define([
var headers = { var headers = {
'Content-Type': 'multipart/mixed; boundary="' + boundary + '"', 'Content-Type': 'multipart/mixed; boundary="' + boundary + '"',
}; };
var base64Data = utils.encodeBase64(content); var base64Data = utils.encodeBase64(content);
var multipartRequestBody = [ var multipartRequestBody = [
delimiter, delimiter,