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

This commit is contained in:
benweet 2014-06-09 18:56:15 +01:00
commit c879a3abb8
11 changed files with 1082 additions and 1024 deletions

View File

@ -179,8 +179,6 @@ define([
var selection = rangy.getSelection();
selection.removeAllRanges();
selection.addRange(range, this.selectionStart > this.selectionEnd);
selection.detach();
range.detach();
};
this.setSelectionStartEnd = function(start, end) {
if(start === undefined) {
@ -232,13 +230,12 @@ define([
selectionEnd = offset + (range + '').length;
}
}
selectionRange.detach();
}
selection.detach();
self.setSelectionStartEnd(selectionStart, selectionEnd);
}
undoMgr.saveSelectionState();
}
var nextTickAdjustScroll = false;
var debouncedSave = utils.debounce(function() {
save();
@ -759,9 +756,18 @@ define([
}, 0);
})
.on('mouseup', _.bind(selectionMgr.saveSelectionState, selectionMgr, true, false))
.on('paste', function() {
.on('paste', function(evt) {
undoMgr.currentMode = 'paste';
adjustCursorPosition();
try {
var data = evt.originalEvent.clipboardData.getData("text/plain");
if(data) {
evt.preventDefault();
document.execCommand("insertHTML", false, data);
}
}
catch(e) {
}
})
.on('cut', function() {
undoMgr.currentMode = 'cut';

View File

@ -40,7 +40,9 @@ define([
});
preElt.parentNode.replaceChild(containerElt, preElt);
chart.drawSVG(containerElt, {
'line-width': 2
'line-width': 2,
'font-family': 'sans-serif',
'font-weight': 'normal'
});
}
catch(e) {

View File

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

View File

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

View File

@ -1,8 +1,10 @@
// Credit to https://editorially.com/
Prism.languages.md = (function () {
var urlPattern = /\b((?:[a-z][\w-]+:(?:\/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}\/)(?:[^\s()<>\[\]'"]+|\([^\s()<>\[\]'"]*\))+(?:\([^\s()<>\[\]'"]*\)|[^\s`!()\[\]{}:'".,<>?«»“”‘’]))/gi;
var emailPattern = /[a-z0-9!#$%&'*+\/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+\/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+(?:[A-Z]{2}|com|org|net|edu|gov|mil|biz|info|mobi|name|aero|asia|jobs|museum)\b/gi;
var charInsideUrl = "[-A-Z0-9+&@#/%?=~_|[\\]()!:,.;]",
charEndingUrl = "[-A-Z0-9+&@#/%=~_|[\\])]";
var urlPattern = new RegExp("(=\"|<)?\\b(https?|ftp)(://" + charInsideUrl + "*" + charEndingUrl + ")(?=$|\\W)", "gi");
var emailPattern = /(?:mailto:)?([-.\w]+\@[-a-z0-9]+(\.[-a-z0-9]+)*\.[a-z]+)/gi;
var latex = Prism.languages.latex;
@ -241,9 +243,6 @@ Prism.languages.md = (function () {
}
}
};
md.email = {
pattern: emailPattern
};
md.code = {
pattern: /(^|[^\\])(`+)([^\r]*?[^`])\2(?!`)/g,
lookbehind: true,
@ -297,8 +296,11 @@ Prism.languages.md = (function () {
conflict: //g,
comment: Prism.languages.markup.comment,
tag: Prism.languages.markup.tag,
entity: Prism.languages.markup.entity
entity: Prism.languages.markup.entity,
url: urlPattern,
email: emailPattern
};
for (var c = 6; c >= 1; c--) {
md["h" + c].inside.rest = rest;
}

View File

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

View File

@ -103,6 +103,7 @@ li.L9 { background: #eee }
@line-height-base: 1.45;
@p-margin: 1.1em;
@headings-font-family: inherit;
@headings-font-weight: 300;
@font-face {
font-family: 'fontello';
@ -183,6 +184,7 @@ li.L9 { background: #eee }
.container {
margin-bottom: 180px;
text-align: justify;
}
a code {
@ -229,6 +231,9 @@ hr {
[stroke="#000000"] {
stroke: @text-color;
}
text[stroke="#000000"] {
stroke: none;
}
[fill="#000"], [fill="#000000"], [fill="black"] {
fill: @text-color;
}

View File

@ -130,18 +130,19 @@
@popover-arrow-outer-color: @secondary-border-color;
@popover-title-bg: @transparent;
@alert-border-radius: 0;
@label-warning-bg: spin(darken(@logo-yellow, 4%), -6);
@label-danger-bg: spin(darken(@logo-orange, 4%), -4);
@state-warning-text: spin(darken(@logo-yellow, 14%), -6);
@state-warning-bg: fade(spin(@logo-yellow, -6), 12%);
@state-warning-border: fade(spin(@logo-yellow, -6), 24%);
@state-danger-text: spin(darken(@logo-orange, 18%), -4);
@state-danger-bg: fade(spin(@logo-orange, -4), 10%);
@state-danger-border: fade(spin(@logo-orange, -4), 20%);
@label-warning-bg: spin(darken(@logo-yellow, 4%), -10);
@state-warning-text: spin(darken(@logo-yellow, 14%), -10);
@state-warning-bg: fade(spin(@logo-yellow, -10), 12%);
@state-warning-border: fade(spin(@logo-yellow, -10), 24%);
@label-danger-bg: spin(darken(@logo-orange, 4%), -8);
@state-danger-text: spin(darken(@logo-orange, 18%), -8);
@state-danger-bg: fade(spin(@logo-orange, -8), 10%);
@state-danger-border: fade(spin(@logo-orange, -8), 20%);
body {
tab-size: 4;
text-align: start;
}
* {
@ -192,18 +193,27 @@ body {
.translate(0, 0);
}
.modal-content {
background-color: @secondary-bg-light;
}
}
.modal-body {
.modal-content {
background-color: @secondary-bg-light;
}
.modal-body {
background-color: @secondary-bg-lighter;
padding-bottom: 30px;
}
}
.modal-footer {
.modal-footer {
background-color: @secondary-bg-light;
margin-top: 0;
}
}
.modal-iframe {
display: block;
margin: 30px auto 0;
z-index: 1040;
border-radius: 0;
}
a {
@ -244,6 +254,8 @@ a {
.list-group-item {
padding: 10px 15px;
border-left-width: 0;
border-right-width: 0;
margin-bottom: 0;
.list-group & {
border-radius: 0;
@ -251,9 +263,24 @@ a {
a&:hover,
a&:focus {
color: darken(@secondary, 30%);
border-top-color: @list-group-hover-border-color;
border-bottom-color: @list-group-hover-border-color;
border-color: @list-group-hover-border-color;
}
.checkbox {
float: right;
margin: 0;
padding: 0;
cursor: pointer;
input {
cursor: pointer;
margin: 0 16px;
height: @input-height-slim;
}
}
}
.form-group {
margin-bottom: 1px;
padding: 5px;
}
.text-danger:hover {
@ -765,17 +792,6 @@ a {
font-size: 15px;
border-top-color: @modal-content-separator-color;
}
.checkbox {
float: right;
margin: 0;
padding: 0;
cursor: pointer;
input {
cursor: pointer;
margin: 0 16px;
height: @input-height-slim;
}
}
.input-rename {
width: 220px;
height: @input-height-slim;
@ -922,7 +938,7 @@ a {
width: 220px;
margin: 10px auto 20px;
.btn {
text-align: initial;
text-align: start;
padding-left: 15px;
}
}
@ -1223,11 +1239,6 @@ a {
.h6 { font-size: 0.9em; }
.url,
.email {
color: @tertiary-color-light;
}
.md, .hr {
color: @tertiary-color-light;
font-style: normal;
@ -1248,10 +1259,16 @@ a {
text-decoration: line-through
}
.url,
.email,
.md-underlined-text {
text-decoration: underline;
}
.linkdef .url {
color: @tertiary-color-light;
}
.img,
.imgref {
padding: 0.2em 0.4em;

View File

@ -349,6 +349,36 @@ define([
].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
var redirectCallbackConfirm;
var redirectCallbackCancel;

View File

@ -11,6 +11,7 @@ app.all('*', function(req, res, next) {
res.redirect('https://stackedit.io' + req.url);
}
else {
/\.(eot|ttf|woff)$/.test(req.url) && res.header('Access-Control-Allow-Origin', '*');
next();
}
});