Fixed IE9 compatibility

This commit is contained in:
benweet 2014-06-09 13:49:37 +01:00
commit 0636ad1c44
7 changed files with 997 additions and 976 deletions

View File

@ -179,8 +179,6 @@ define([
var selection = rangy.getSelection(); var selection = rangy.getSelection();
selection.removeAllRanges(); selection.removeAllRanges();
selection.addRange(range, this.selectionStart > this.selectionEnd); selection.addRange(range, this.selectionStart > this.selectionEnd);
selection.detach();
range.detach();
}; };
this.setSelectionStartEnd = function(start, end) { this.setSelectionStartEnd = function(start, end) {
if(start === undefined) { if(start === undefined) {
@ -232,9 +230,7 @@ define([
selectionEnd = offset + (range + '').length; selectionEnd = offset + (range + '').length;
} }
} }
selectionRange.detach();
} }
selection.detach();
self.setSelectionStartEnd(selectionStart, selectionEnd); self.setSelectionStartEnd(selectionStart, selectionEnd);
} }
undoMgr.saveSelectionState(); undoMgr.saveSelectionState();

View File

@ -9,11 +9,12 @@ define([
"logger", "logger",
"settings", "settings",
"eventMgr", "eventMgr",
"classes/AsyncTask", "classes/AsyncTask"
], function(_, $, constants, core, utils, storage, logger, settings, eventMgr, AsyncTask) { ], function(_, $, constants, core, utils, storage, logger, settings, eventMgr, AsyncTask) {
var connected = false; var connected = false;
var authorizationMgrMap = {}; var authorizationMgrMap = {};
function AuthorizationMgr(accountId) { function AuthorizationMgr(accountId) {
var permissionList = { var permissionList = {
profile: true profile: true
@ -63,12 +64,10 @@ define([
task.onRun(function() { task.onRun(function() {
if(isOffline === true) { if(isOffline === true) {
connected = false; connected = false;
task.error(new Error("Operation not available in offline mode.|stopPublish")); return task.error(new Error("Operation not available in offline mode.|stopPublish"));
return;
} }
if(connected === true) { if(connected === true) {
task.chain(); return task.chain();
return;
} }
window.delayedFunction = function() { window.delayedFunction = function() {
gapi.load("client", function() { gapi.load("client", function() {
@ -108,7 +107,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) {
@ -118,6 +117,7 @@ define([
task.onRun(function() { task.onRun(function() {
var currentToken = gapi.auth.getToken(); var currentToken = gapi.auth.getToken();
var newToken; var newToken;
function getTokenInfo() { function getTokenInfo() {
$.ajax({ $.ajax({
url: 'https://www.googleapis.com/oauth2/v1/tokeninfo', url: 'https://www.googleapis.com/oauth2/v1/tokeninfo',
@ -145,12 +145,13 @@ define([
handleError(error, task); handleError(error, task);
}); });
} }
var authuser = 0; var authuser = 0;
var immediate; var immediate;
function localAuthenticate() { function localAuthenticate() {
if(authuser > 5) { if(authuser > 5) {
task.error(new Error('Unable to authenticate user ' + authorizationMgr.getUserId() + ', please sign in with Google.')); return task.error(new Error('Unable to authenticate user ' + authorizationMgr.getUserId() + ', please sign in with Google.'));
return;
} }
if(immediate === false) { if(immediate === false) {
task.timeout = constants.ASYNC_TASK_LONG_TIMEOUT; task.timeout = constants.ASYNC_TASK_LONG_TIMEOUT;
@ -162,16 +163,6 @@ 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) {
@ -193,10 +184,10 @@ define([
} }
}); });
} }
function oauthRedirect() { function oauthRedirect() {
if(immediate === true) { if(immediate === true) {
task.chain(localAuthenticate); return task.chain(localAuthenticate);
return;
} }
utils.redirectConfirm('You are being redirected to <strong>Google</strong> authorization page.', function() { utils.redirectConfirm('You are being redirected to <strong>Google</strong> authorization page.', function() {
task.chain(localAuthenticate); task.chain(localAuthenticate);
@ -204,6 +195,7 @@ define([
task.error(new Error('Operation canceled.')); task.error(new Error('Operation canceled.'));
}); });
} }
function startAuthenticate() { function startAuthenticate() {
immediate = true; immediate = true;
if(authorizationMgr.token && authorizationMgr.isAuthorized(permission)) { if(authorizationMgr.token && authorizationMgr.isAuthorized(permission)) {
@ -215,9 +207,11 @@ define([
} }
task.chain(oauthRedirect); task.chain(oauthRedirect);
} }
startAuthenticate(); startAuthenticate();
}); });
} }
googleHelper.refreshGdriveToken = function(accountId) { googleHelper.refreshGdriveToken = function(accountId) {
var task = new AsyncTask(); var task = new AsyncTask();
connect(task); connect(task);
@ -266,7 +260,7 @@ define([
method = 'PUT'; method = 'PUT';
} }
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);
@ -289,18 +283,17 @@ define([
'path': path, 'path': path,
'method': method, 'method': method,
'params': { 'params': {
'uploadType': 'multipart', 'uploadType': 'multipart'
}, },
'headers': headers, 'headers': headers,
'body': multipartRequestBody, 'body': multipartRequestBody
}); });
request.execute(function(response) { request.execute(function(response) {
if(response && response.id) { if(response && response.id) {
// Upload success // Upload success
result = response; result = response;
result.content = content; result.content = content;
task.chain(); return task.chain();
return;
} }
var error = response.error; var error = response.error;
// Handle error // Handle error
@ -343,8 +336,7 @@ define([
if(response && response.id) { if(response && response.id) {
// Rename success // Rename success
result = response; result = response;
task.chain(); return task.chain();
return;
} }
var error = response.error; var error = response.error;
// Handle error // Handle error
@ -374,6 +366,7 @@ define([
authenticate(task, 'gdrive', accountId); authenticate(task, 'gdrive', accountId);
task.onRun(function() { task.onRun(function() {
var nextPageToken; var nextPageToken;
function retrievePageOfChanges() { function retrievePageOfChanges() {
runWithToken(accountId, function() { runWithToken(accountId, function() {
var request; var request;
@ -391,8 +384,7 @@ define([
request.execute(function(response) { request.execute(function(response) {
if(!response || !response.largestChangeId) { if(!response || !response.largestChangeId) {
// Handle error // Handle error
handleError(response.error, task); return handleError(response.error, task);
return;
} }
// Retrieve success // Retrieve success
newChangeId = response.largestChangeId; newChangeId = response.largestChangeId;
@ -409,6 +401,7 @@ define([
}); });
}); });
} }
task.chain(retrievePageOfChanges); task.chain(retrievePageOfChanges);
}); });
task.onSuccess(function() { task.onSuccess(function() {
@ -430,8 +423,7 @@ define([
task.onRun(function() { task.onRun(function() {
function recursiveDownloadMetadata() { function recursiveDownloadMetadata() {
if(ids.length === 0) { if(ids.length === 0) {
task.chain(); return task.chain();
return;
} }
var id = ids[0]; var id = ids[0];
var headers = {}; var headers = {};
@ -463,6 +455,7 @@ define([
handleError(error, task); handleError(error, task);
}); });
} }
task.chain(recursiveDownloadMetadata); task.chain(recursiveDownloadMetadata);
}); });
task.onSuccess(function() { task.onSuccess(function() {
@ -486,8 +479,7 @@ define([
task.onRun(function() { task.onRun(function() {
function recursiveDownloadContent() { function recursiveDownloadContent() {
if(objects.length === 0) { if(objects.length === 0) {
task.chain(); return task.chain();
return;
} }
var object = objects[0]; var object = objects[0];
result.push(object); result.push(object);
@ -502,8 +494,7 @@ define([
} }
if(!file) { if(!file) {
objects.shift(); objects.shift();
task.chain(recursiveDownloadContent); return task.chain(recursiveDownloadContent);
return;
} }
var url = file.downloadUrl; var url = file.downloadUrl;
// if file is a real time document // if file is a real time document
@ -537,6 +528,7 @@ define([
handleError(error, task); handleError(error, task);
}); });
} }
task.chain(recursiveDownloadContent); task.chain(recursiveDownloadContent);
}); });
task.onSuccess(function() { task.onSuccess(function() {
@ -615,16 +607,14 @@ define([
errorMsg = "Google error (" + error.code + ": " + error.message + ")."; errorMsg = "Google error (" + error.code + ": " + error.message + ").";
if(error.code >= 500 && error.code < 600) { if(error.code >= 500 && error.code < 600) {
// Retry as described in Google's best practices // Retry as described in Google's best practices
task.retry(new Error(errorMsg)); return task.retry(new Error(errorMsg));
return;
} }
else if(error.code === 401 || error.code === 403 || error.code == "token_refresh_required") { else if(error.code === 401 || error.code === 403 || error.code == "token_refresh_required") {
_.each(authorizationMgrMap, function(authorizationMgr) { _.each(authorizationMgrMap, function(authorizationMgr) {
authorizationMgr.setRefreshFlag(); authorizationMgr.setRefreshFlag();
}); });
errorMsg = "Access to Google account is not authorized."; errorMsg = "Access to Google account is not authorized.";
task.retry(new Error(errorMsg), 1); return task.retry(new Error(errorMsg), 1);
return;
} }
else if(error.code === 0 || error.code === -1) { else if(error.code === 0 || error.code === -1) {
connected = false; connected = false;
@ -640,11 +630,11 @@ define([
} }
var pickerLoaded = false; var pickerLoaded = false;
function loadPicker(task) { function loadPicker(task) {
task.onRun(function() { task.onRun(function() {
if(pickerLoaded === true) { if(pickerLoaded === true) {
task.chain(); return task.chain();
return;
} }
$.ajax({ $.ajax({
url: "//www.google.com/jsapi", url: "//www.google.com/jsapi",
@ -673,12 +663,14 @@ define([
googleHelper.picker = function(callback, pickerType, accountId) { googleHelper.picker = function(callback, pickerType, accountId) {
var docs = []; var docs = [];
var picker; var picker;
function hidePicker() { function hidePicker() {
if(picker !== undefined) { if(picker !== undefined) {
picker.setVisible(false); picker.setVisible(false);
$(".modal-backdrop, .picker").remove(); $(".modal-backdrop, .picker").remove();
} }
} }
var task = new AsyncTask(); var task = new AsyncTask();
// Add some time for user to choose his files // Add some time for user to choose his files
task.timeout = constants.ASYNC_TASK_LONG_TIMEOUT; task.timeout = constants.ASYNC_TASK_LONG_TIMEOUT;
@ -741,7 +733,7 @@ define([
} }
}); });
picker = pickerBuilder.build(); picker = pickerBuilder.build();
$(utils.createBackdrop()).click(function() { $(utils.createBackdrop()).on('click.backdrop', function() {
hidePicker(); hidePicker();
task.chain(); task.chain();
}); });
@ -812,6 +804,7 @@ define([
handleError(error, task); handleError(error, task);
}); });
} }
function publish() { function publish() {
var url = "https://www.googleapis.com/blogger/v3/blogs/" + blogId + "/posts/" + postId; var url = "https://www.googleapis.com/blogger/v3/blogs/" + blogId + "/posts/" + postId;
if(isDraft) { if(isDraft) {
@ -843,6 +836,7 @@ define([
handleError(error, task); handleError(error, task);
}); });
} }
function getBlogId() { function getBlogId() {
if(blogId !== undefined) { if(blogId !== undefined) {
task.chain(uploadPost); task.chain(uploadPost);
@ -871,6 +865,7 @@ define([
handleError(error, task); handleError(error, task);
}); });
} }
task.chain(getBlogId); task.chain(getBlogId);
}); });
task.onSuccess(function() { task.onSuccess(function() {
@ -933,6 +928,7 @@ define([
handleError(error, task); handleError(error, task);
}); });
} }
function getBlogId() { function getBlogId() {
if(blogId !== undefined) { if(blogId !== undefined) {
task.chain(uploadPage); task.chain(uploadPage);
@ -961,6 +957,7 @@ define([
handleError(error, task); handleError(error, task);
}); });
} }
task.chain(getBlogId); task.chain(getBlogId);
}); });
task.onSuccess(function() { task.onSuccess(function() {

View File

@ -117,7 +117,7 @@ define([
}; };
DomObject.prototype.createToggler = function(backdrop) { DomObject.prototype.createToggler = function(backdrop) {
var backdropElt; var $backdropElt;
var pushedEvents = 0; var pushedEvents = 0;
this.toggle = function(show) { this.toggle = function(show) {
if(show === this.isOpen) { if(show === this.isOpen) {
@ -127,7 +127,7 @@ define([
if(this.isOpen) { if(this.isOpen) {
this.$elt.addClass('panel-open').trigger('show.layout.toggle'); this.$elt.addClass('panel-open').trigger('show.layout.toggle');
if(backdrop) { if(backdrop) {
$(backdropElt = utils.createBackdrop(wrapperL1.elt)).click(_.bind(function() { $backdropElt = $(utils.createBackdrop(wrapperL1.elt)).on('click.backdrop', _.bind(function() {
this.toggle(false); this.toggle(false);
}, this)); }, this));
this.$elt.addClass('bring-to-front'); this.$elt.addClass('bring-to-front');
@ -140,8 +140,11 @@ define([
} }
else { else {
this.$elt.trigger('hide.layout.toggle'); this.$elt.trigger('hide.layout.toggle');
backdropElt && backdropElt.removeBackdrop(); if($backdropElt) {
backdropElt = undefined; $backdropElt.off('click.backdrop');
$backdropElt[0].removeBackdrop();
$backdropElt = undefined;
}
transitionEndCallbacks.push(_.bind(function() { transitionEndCallbacks.push(_.bind(function() {
if(--pushedEvents === 0) { if(--pushedEvents === 0) {
!this.isOpen && this.$elt.removeClass('panel-open bring-to-front').trigger('hidden.layout.toggle'); !this.isOpen && this.$elt.removeClass('panel-open bring-to-front').trigger('hidden.layout.toggle');

View File

@ -91,8 +91,7 @@ define([
var syncIndex = createSyncIndex(doc.id); var syncIndex = createSyncIndex(doc.id);
var fileDesc = fileMgr.getFileFromSyncIndex(syncIndex); var fileDesc = fileMgr.getFileFromSyncIndex(syncIndex);
if(fileDesc !== undefined) { if(fileDesc !== undefined) {
eventMgr.onError('"' + fileDesc.title + '" was already imported.'); return eventMgr.onError('"' + fileDesc.title + '" was already imported.');
return;
} }
importIds.push(doc.id); importIds.push(doc.id);
}); });
@ -109,16 +108,14 @@ define([
var fileDesc = fileMgr.getFileFromSyncIndex(syncIndex); var fileDesc = fileMgr.getFileFromSyncIndex(syncIndex);
if(fileDesc !== undefined) { if(fileDesc !== undefined) {
eventMgr.onError('File ID is already synchronized with "' + fileDesc.title + '".'); eventMgr.onError('File ID is already synchronized with "' + fileDesc.title + '".');
callback(true); return callback(true);
return;
} }
} }
var parentId = utils.getInputTextValue('#input-sync-export-' + providerId + '-parentid'); var parentId = utils.getInputTextValue('#input-sync-export-' + providerId + '-parentid');
var data = gdriveProvider.serializeContent(content, discussionListJSON); var data = gdriveProvider.serializeContent(content, discussionListJSON);
googleHelper.upload(fileId, parentId, title, data, undefined, undefined, accountId, function(error, result) { googleHelper.upload(fileId, parentId, title, data, undefined, undefined, accountId, function(error, result) {
if(error) { if(error) {
callback(error); return callback(error);
return;
} }
var syncAttributes = createSyncAttributes(result.id, result.etag, content, title, discussionListJSON); var syncAttributes = createSyncAttributes(result.id, result.etag, content, title, discussionListJSON);
callback(undefined, syncAttributes); callback(undefined, syncAttributes);
@ -128,7 +125,7 @@ define([
gdriveProvider.syncUp = function(content, contentCRC, title, titleCRC, discussionList, discussionListCRC, syncAttributes, callback) { gdriveProvider.syncUp = function(content, contentCRC, title, titleCRC, discussionList, discussionListCRC, syncAttributes, callback) {
if( if(
(syncAttributes.contentCRC == contentCRC) && // Content CRC hasn't changed (syncAttributes.contentCRC == contentCRC) && // Content CRC hasn't changed
(syncAttributes.titleCRC == titleCRC) && // Content CRC hasn't changed (syncAttributes.titleCRC == titleCRC) && // Title CRC hasn't changed
(syncAttributes.discussionListCRC == discussionListCRC) // Discussion list CRC hasn't changed (syncAttributes.discussionListCRC == discussionListCRC) // Discussion list CRC hasn't changed
) { ) {
return callback(undefined, false); return callback(undefined, false);
@ -144,8 +141,7 @@ define([
var data = gdriveProvider.serializeContent(content, discussionList); var data = gdriveProvider.serializeContent(content, discussionList);
googleHelper.upload(syncAttributes.id, undefined, title, data, undefined, syncAttributes.etag, accountId, function(error, result) { googleHelper.upload(syncAttributes.id, undefined, title, data, undefined, syncAttributes.etag, accountId, function(error, result) {
if(error) { if(error) {
callback(error, true); return callback(error, true);
return;
} }
syncAttributes.etag = result.etag; syncAttributes.etag = result.etag;
// Remove this deprecated flag if any // Remove this deprecated flag if any
@ -167,8 +163,7 @@ define([
var lastChangeId = parseInt(storage[accountId + ".gdrive.lastChangeId"], 10); var lastChangeId = parseInt(storage[accountId + ".gdrive.lastChangeId"], 10);
googleHelper.checkChanges(lastChangeId, accountId, function(error, changes, newChangeId) { googleHelper.checkChanges(lastChangeId, accountId, function(error, changes, newChangeId) {
if(error) { if(error) {
callback(error); return callback(error);
return;
} }
var interestingChanges = []; var interestingChanges = [];
_.each(changes, function(change) { _.each(changes, function(change) {

View File

@ -1336,7 +1336,7 @@ div.dropdown-menu, {
color: @link-hover-color; color: @link-hover-color;
} }
h1, h2, h3, h4, h5, h6 { h1, h2, h3, h4, h5, h6 {
margin: 0.8em 0; margin: 1em 0;
} }
} }

View File

@ -349,6 +349,36 @@ define([
].join("")); ].join(""));
}; };
var $windowElt = $(window);
utils.iframe = function(url, width, height) {
var $backdropElt = $(utils.createBackdrop());
var result = crel('iframe', {
src: url,
frameborder: 0,
class: 'modal-content modal-iframe'
});
document.body.appendChild(result);
function placeIframe() {
var actualWidth = window.innerWidth - 20;
actualWidth > width && (actualWidth = width);
var actualHeight = window.innerHeight - 50;
actualHeight > height && (actualHeight = height);
result.setAttribute('width', actualWidth);
result.setAttribute('height', actualHeight);
}
placeIframe();
$windowElt.on('resize.iframe', placeIframe);
function removeIframe() {
$backdropElt.off('click.backdrop');
$backdropElt[0].removeBackdrop();
$windowElt.off('resize.iframe');
result.parentNode.removeChild(result);
}
result.removeIframe = removeIframe;
$backdropElt.on('click.backdrop', removeIframe);
return result;
};
// Shows a dialog to force the user to click a button before opening oauth popup // Shows a dialog to force the user to click a button before opening oauth popup
var redirectCallbackConfirm; var redirectCallbackConfirm;
var redirectCallbackCancel; var redirectCallbackCancel;