JSHint validation. Part 1.
This commit is contained in:
parent
81db48c1a9
commit
634569f3a9
29
Gruntfile.js
29
Gruntfile.js
@ -1,5 +1,6 @@
|
||||
module.exports = function(grunt) {
|
||||
|
||||
grunt.loadNpmTasks('grunt-contrib-jshint');
|
||||
grunt.loadNpmTasks('grunt-contrib-requirejs');
|
||||
grunt.loadNpmTasks('grunt-contrib-less');
|
||||
grunt.loadNpmTasks('grunt-string-replace');
|
||||
@ -12,6 +13,30 @@ module.exports = function(grunt) {
|
||||
*/
|
||||
grunt.initConfig({
|
||||
pkg: grunt.file.readJSON('package.json'),
|
||||
jshint: {
|
||||
options: {
|
||||
curly: true,
|
||||
browser: true,
|
||||
devel: true,
|
||||
indent: 4,
|
||||
latedef: true,
|
||||
undef: true,
|
||||
unused: true,
|
||||
expr: true,
|
||||
globals: {
|
||||
"define": false,
|
||||
"require": false,
|
||||
},
|
||||
ignores: [
|
||||
'node_modules/**/*.js',
|
||||
'public/libs/**/*.js',
|
||||
'public/res/libs/**/*.js',
|
||||
'public/res/bower-libs/**/*.js',
|
||||
'public/res-min/**/*.js'
|
||||
]
|
||||
},
|
||||
client: ['public/**/*.js'],
|
||||
},
|
||||
requirejs: {
|
||||
compile: {
|
||||
options: {
|
||||
@ -100,8 +125,8 @@ module.exports = function(grunt) {
|
||||
options: {
|
||||
replacements: [
|
||||
{
|
||||
pattern: /(var VERSION = ).*/,
|
||||
replacement: 'var VERSION = "<%= pkg.version %>";'
|
||||
pattern: /(constants\.VERSION = ).*/,
|
||||
replacement: 'constants.VERSION = "<%= pkg.version %>";'
|
||||
},
|
||||
]
|
||||
}
|
||||
|
@ -19,7 +19,8 @@
|
||||
"bower": "~1.2.5",
|
||||
"grunt-bower-requirejs": "~0.7.1",
|
||||
"grunt-bower-task": "~0.3.1",
|
||||
"grunt-bump": "0.0.11"
|
||||
"grunt-bump": "0.0.11",
|
||||
"grunt-contrib-jshint": "~0.7.1"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
|
@ -13,12 +13,12 @@
|
||||
/>
|
||||
<script>
|
||||
// Use ?debug to serve original JavaScript files instead of minified
|
||||
var baseDir = 'res';
|
||||
window.baseDir = 'res';
|
||||
if (!/(\?|&)debug($|&)/.test(location.search)) {
|
||||
baseDir += '-min';
|
||||
window.baseDir += '-min';
|
||||
}
|
||||
var require = {
|
||||
baseUrl: baseDir,
|
||||
window.require = {
|
||||
baseUrl: window.baseDir,
|
||||
deps: ['main']
|
||||
};
|
||||
</script>
|
||||
|
@ -10,10 +10,10 @@
|
||||
<link rel="stylesheet" type="text/css" href="res-min/themes/default.css">
|
||||
<script>
|
||||
// Use http://.../?debug to serve original JavaScript files instead of minified
|
||||
var baseDir = 'res-min';
|
||||
var noStart = true;
|
||||
var require = {
|
||||
baseUrl: baseDir,
|
||||
window.baseDir = 'res-min';
|
||||
window.noStart = true;
|
||||
window.require = {
|
||||
baseUrl: window.baseDir,
|
||||
deps: ['main']
|
||||
};
|
||||
setTimeout(function() {
|
||||
|
28884
public/res-min/main.js
28884
public/res-min/main.js
File diff suppressed because one or more lines are too long
@ -1,15 +1,16 @@
|
||||
define([
|
||||
"underscore",
|
||||
"constants",
|
||||
"utils",
|
||||
"eventMgr",
|
||||
"config"
|
||||
], function(_, utils, eventMgr) {
|
||||
], function(_, constants, utils, eventMgr) {
|
||||
|
||||
var taskQueue = [];
|
||||
|
||||
function AsyncTask(force) {
|
||||
this.finished = false;
|
||||
this.timeout = ASYNC_TASK_DEFAULT_TIMEOUT;
|
||||
this.timeout = constants.ASYNC_TASK_DEFAULT_TIMEOUT;
|
||||
this.retryCounter = 0;
|
||||
this.runCallbacks = [];
|
||||
this.successCallbacks = [];
|
||||
@ -123,7 +124,7 @@ define([
|
||||
};
|
||||
|
||||
var asyncRunning = false;
|
||||
var currentTask = undefined;
|
||||
var currentTask;
|
||||
|
||||
// Determine if user is real by listening to his activity
|
||||
var isUserReal = false;
|
||||
|
@ -1,17 +1,18 @@
|
||||
define([
|
||||
"underscore",
|
||||
"utils",
|
||||
"storage",
|
||||
"ace/range"
|
||||
], function(_, utils, range) {
|
||||
], function(_, utils, storage, range) {
|
||||
var Range = range.Range;
|
||||
|
||||
function FileDescriptor(fileIndex, title, syncLocations, publishLocations) {
|
||||
this.fileIndex = fileIndex;
|
||||
this._title = title || localStorage[fileIndex + ".title"];
|
||||
this._editorScrollTop = parseInt(localStorage[fileIndex + ".editorScrollTop"]) || 0;
|
||||
this._title = title || storage[fileIndex + ".title"];
|
||||
this._editorScrollTop = parseInt(storage[fileIndex + ".editorScrollTop"]) || 0;
|
||||
this._editorSelectRange = (function() {
|
||||
try {
|
||||
var rangeComponents = localStorage[fileIndex + ".editorSelectRange"].split(';');
|
||||
var rangeComponents = storage[fileIndex + ".editorSelectRange"].split(';');
|
||||
rangeComponents = _.map(rangeComponents, function(component) {
|
||||
return parseInt(component);
|
||||
});
|
||||
@ -21,9 +22,9 @@ define([
|
||||
return new Range(0, 0, 0, 0);
|
||||
}
|
||||
})();
|
||||
this._editorEnd = parseInt(localStorage[fileIndex + ".editorEnd"]) || 0;
|
||||
this._previewScrollTop = parseInt(localStorage[fileIndex + ".previewScrollTop"]) || 0;
|
||||
this._selectTime = parseInt(localStorage[fileIndex + ".selectTime"]) || 0;
|
||||
this._editorEnd = parseInt(storage[fileIndex + ".editorEnd"]) || 0;
|
||||
this._previewScrollTop = parseInt(storage[fileIndex + ".previewScrollTop"]) || 0;
|
||||
this._selectTime = parseInt(storage[fileIndex + ".selectTime"]) || 0;
|
||||
this.syncLocations = syncLocations || {};
|
||||
this.publishLocations = publishLocations || {};
|
||||
Object.defineProperty(this, 'title', {
|
||||
@ -32,15 +33,15 @@ define([
|
||||
},
|
||||
set: function(title) {
|
||||
this._title = title;
|
||||
localStorage[this.fileIndex + ".title"] = title;
|
||||
storage[this.fileIndex + ".title"] = title;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(this, 'content', {
|
||||
get: function() {
|
||||
return localStorage[this.fileIndex + ".content"];
|
||||
return storage[this.fileIndex + ".content"];
|
||||
},
|
||||
set: function(content) {
|
||||
localStorage[this.fileIndex + ".content"] = content;
|
||||
storage[this.fileIndex + ".content"] = content;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(this, 'editorScrollTop', {
|
||||
@ -49,7 +50,7 @@ define([
|
||||
},
|
||||
set: function(editorScrollTop) {
|
||||
this._editorScrollTop = editorScrollTop;
|
||||
localStorage[this.fileIndex + ".editorScrollTop"] = editorScrollTop;
|
||||
storage[this.fileIndex + ".editorScrollTop"] = editorScrollTop;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(this, 'editorSelectRange', {
|
||||
@ -58,7 +59,7 @@ define([
|
||||
},
|
||||
set: function(range) {
|
||||
this._editorSelectRange = range;
|
||||
localStorage[this.fileIndex + ".editorSelectRange"] = [
|
||||
storage[this.fileIndex + ".editorSelectRange"] = [
|
||||
range.start.row,
|
||||
range.start.column,
|
||||
range.end.row,
|
||||
@ -72,7 +73,7 @@ define([
|
||||
},
|
||||
set: function(previewScrollTop) {
|
||||
this._previewScrollTop = previewScrollTop;
|
||||
localStorage[this.fileIndex + ".previewScrollTop"] = previewScrollTop;
|
||||
storage[this.fileIndex + ".previewScrollTop"] = previewScrollTop;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(this, 'selectTime', {
|
||||
@ -81,7 +82,7 @@ define([
|
||||
},
|
||||
set: function(selectTime) {
|
||||
this._selectTime = selectTime;
|
||||
localStorage[this.fileIndex + ".selectTime"] = selectTime;
|
||||
storage[this.fileIndex + ".selectTime"] = selectTime;
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -95,7 +96,7 @@ define([
|
||||
FileDescriptor.prototype.removeSyncLocation = function(syncAttributes) {
|
||||
utils.removeIndexFromArray(this.fileIndex + ".sync", syncAttributes.syncIndex);
|
||||
delete this.syncLocations[syncAttributes.syncIndex];
|
||||
localStorage.removeItem(syncAttributes.syncIndex);
|
||||
storage.removeItem(syncAttributes.syncIndex);
|
||||
};
|
||||
|
||||
FileDescriptor.prototype.addPublishLocation = function(publishAttributes) {
|
||||
@ -107,7 +108,7 @@ define([
|
||||
FileDescriptor.prototype.removePublishLocation = function(publishAttributes) {
|
||||
utils.removeIndexFromArray(this.fileIndex + ".publish", publishAttributes.publishIndex);
|
||||
delete this.publishLocations[publishAttributes.publishIndex];
|
||||
localStorage.removeItem(publishAttributes.publishIndex);
|
||||
storage.removeItem(publishAttributes.publishIndex);
|
||||
};
|
||||
|
||||
FileDescriptor.prototype.composeTitle = function() {
|
||||
|
@ -1,13 +1,14 @@
|
||||
define([
|
||||
"underscore",
|
||||
"utils",
|
||||
"storage",
|
||||
"fileSystem"
|
||||
], function(_, utils, fileSystem) {
|
||||
], function(_, utils, storage, fileSystem) {
|
||||
|
||||
function FolderDescriptor(folderIndex, name, fileList) {
|
||||
this.folderIndex = folderIndex;
|
||||
this._name = name || localStorage[folderIndex + ".name"];
|
||||
// Retrieve file list from localStorage
|
||||
this._name = name || storage[folderIndex + ".name"];
|
||||
// Retrieve file list from storage
|
||||
this.fileList = {};
|
||||
_.each(utils.retrieveIndexArray(folderIndex + ".files"), function(fileIndex) {
|
||||
try {
|
||||
@ -16,7 +17,7 @@ define([
|
||||
this.fileList[fileIndex] = fileDesc;
|
||||
}
|
||||
catch(e) {
|
||||
// localStorage can be corrupted
|
||||
// storage can be corrupted
|
||||
// Remove file from folder
|
||||
utils.removeIndexFromArray(folderIndex + ".files", fileIndex);
|
||||
}
|
||||
@ -27,7 +28,7 @@ define([
|
||||
},
|
||||
set: function(name) {
|
||||
this._name = name;
|
||||
localStorage[this.folderIndex + ".name"] = name;
|
||||
storage[this.folderIndex + ".name"] = name;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -1,77 +1,79 @@
|
||||
var VERSION = "2.2.4";
|
||||
define([], function() {
|
||||
var constants = {};
|
||||
constants.VERSION = "2.2.4";
|
||||
|
||||
var MAIN_URL = "https://stackedit.io/";
|
||||
var GOOGLE_ANALYTICS_ACCOUNT_ID = "UA-39556145-1";
|
||||
var GOOGLE_API_KEY = "AIzaSyAeCU8CGcSkn0z9js6iocHuPBX4f_mMWkw";
|
||||
var GOOGLE_DRIVE_APP_ID = "241271498917";
|
||||
var DROPBOX_APP_KEY = "lq6mwopab8wskas";
|
||||
var DROPBOX_APP_SECRET = "851fgnucpezy84t";
|
||||
var BITLY_ACCESS_TOKEN = "317e033bfd48cf31155a68a536b1860013b09c4c";
|
||||
var DEFAULT_FILE_TITLE = "Title";
|
||||
var DEFAULT_FOLDER_NAME = "New folder";
|
||||
var GDRIVE_DEFAULT_FILE_TITLE = "New Markdown document";
|
||||
var EDITOR_DEFAULT_PADDING = 15;
|
||||
var CHECK_ONLINE_PERIOD = 120000;
|
||||
var AJAX_TIMEOUT = 30000;
|
||||
var ASYNC_TASK_DEFAULT_TIMEOUT = 60000;
|
||||
var ASYNC_TASK_LONG_TIMEOUT = 180000;
|
||||
var SYNC_PERIOD = 180000;
|
||||
var USER_IDLE_THRESHOLD = 300000;
|
||||
var IMPORT_FILE_MAX_CONTENT_SIZE = 100000;
|
||||
var IMPORT_IMG_MAX_CONTENT_SIZE = 10000000;
|
||||
var TEMPORARY_FILE_INDEX = "file.tempIndex";
|
||||
var WELCOME_DOCUMENT_TITLE = "Welcome document";
|
||||
var DOWNLOAD_PROXY_URL = "https://stackedit-download-proxy.herokuapp.com/";
|
||||
var PICASA_PROXY_URL = "https://stackedit-picasa-proxy.herokuapp.com/";
|
||||
var SSH_PROXY_URL = "https://stackedit-ssh-proxy.herokuapp.com/";
|
||||
var HTMLTOPDF_URL = "https://stackedit-htmltopdf.herokuapp.com/";
|
||||
constants.MAIN_URL = "https://stackedit.io/";
|
||||
constants.GOOGLE_ANALYTICS_ACCOUNT_ID = "UA-39556145-1";
|
||||
constants.GOOGLE_API_KEY = "AIzaSyAeCU8CGcSkn0z9js6iocHuPBX4f_mMWkw";
|
||||
constants.GOOGLE_DRIVE_APP_ID = "241271498917";
|
||||
constants.DROPBOX_APP_KEY = "lq6mwopab8wskas";
|
||||
constants.DROPBOX_APP_SECRET = "851fgnucpezy84t";
|
||||
constants.BITLY_ACCESS_TOKEN = "317e033bfd48cf31155a68a536b1860013b09c4c";
|
||||
constants.DEFAULT_FILE_TITLE = "Title";
|
||||
constants.DEFAULT_FOLDER_NAME = "New folder";
|
||||
constants.GDRIVE_DEFAULT_FILE_TITLE = "New Markdown document";
|
||||
constants.EDITOR_DEFAULT_PADDING = 15;
|
||||
constants.CHECK_ONLINE_PERIOD = 120000;
|
||||
constants.AJAX_TIMEOUT = 30000;
|
||||
constants.ASYNC_TASK_DEFAULT_TIMEOUT = 60000;
|
||||
constants.ASYNC_TASK_LONG_TIMEOUT = 180000;
|
||||
constants.USER_IDLE_THRESHOLD = 300000;
|
||||
constants.IMPORT_FILE_MAX_CONTENT_SIZE = 100000;
|
||||
constants.IMPORT_IMG_MAX_CONTENT_SIZE = 10000000;
|
||||
constants.TEMPORARY_FILE_INDEX = "file.tempIndex";
|
||||
constants.WELCOME_DOCUMENT_TITLE = "Welcome document";
|
||||
constants.DOWNLOAD_PROXY_URL = "https://stackedit-download-proxy.herokuapp.com/";
|
||||
constants.PICASA_PROXY_URL = "https://stackedit-picasa-proxy.herokuapp.com/";
|
||||
constants.SSH_PROXY_URL = "https://stackedit-ssh-proxy.herokuapp.com/";
|
||||
constants.HTMLTOPDF_URL = "https://stackedit-htmltopdf.herokuapp.com/";
|
||||
|
||||
// Use by Google's client.js
|
||||
var delayedFunction = undefined;
|
||||
function runDelayedFunction() {
|
||||
if(delayedFunction !== undefined) {
|
||||
delayedFunction();
|
||||
// Use by Google's client.js
|
||||
window.delayedFunction = undefined;
|
||||
function runDelayedFunction() {
|
||||
if(window.delayedFunction !== undefined) {
|
||||
window.delayedFunction();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Site dependent
|
||||
var BASE_URL = "http://localhost/";
|
||||
var GOOGLE_CLIENT_ID = '241271498917-lev37kef013q85avc91am1gccg5g8lrb.apps.googleusercontent.com';
|
||||
var GITHUB_CLIENT_ID = 'e47fef6055344579799d';
|
||||
var GATEKEEPER_URL = "https://stackedit-gatekeeper-localhost.herokuapp.com/";
|
||||
var TUMBLR_PROXY_URL = "https://stackedit-tumblr-proxy-local.herokuapp.com/";
|
||||
var WORDPRESS_CLIENT_ID = '23361';
|
||||
var WORDPRESS_PROXY_URL = "https://stackedit-io-wordpress-proxy.herokuapp.com/";
|
||||
// Site dependent
|
||||
constants.BASE_URL = "http://localhost/";
|
||||
constants.GOOGLE_CLIENT_ID = '241271498917-lev37kef013q85avc91am1gccg5g8lrb.apps.googleusercontent.com';
|
||||
constants.GITHUB_CLIENT_ID = 'e47fef6055344579799d';
|
||||
constants.GATEKEEPER_URL = "https://stackedit-gatekeeper-localhost.herokuapp.com/";
|
||||
constants.TUMBLR_PROXY_URL = "https://stackedit-tumblr-proxy-local.herokuapp.com/";
|
||||
constants.WORDPRESS_CLIENT_ID = '23361';
|
||||
constants.WORDPRESS_PROXY_URL = "https://stackedit-io-wordpress-proxy.herokuapp.com/";
|
||||
|
||||
if(location.hostname.indexOf("stackedit.io") === 0) {
|
||||
BASE_URL = MAIN_URL;
|
||||
GOOGLE_CLIENT_ID = '241271498917-t4t7d07qis7oc0ahaskbif3ft6tk63cd.apps.googleusercontent.com';
|
||||
GITHUB_CLIENT_ID = '710fc67886ab1ae8fee6';
|
||||
GATEKEEPER_URL = "https://stackedit-io-gatekeeper.herokuapp.com/";
|
||||
TUMBLR_PROXY_URL = "https://stackedit-io-tumblr-proxy.herokuapp.com/";
|
||||
}
|
||||
if(location.hostname.indexOf("stackedit.io") === 0) {
|
||||
constants.BASE_URL = constants.MAIN_URL;
|
||||
constants.GOOGLE_CLIENT_ID = '241271498917-t4t7d07qis7oc0ahaskbif3ft6tk63cd.apps.googleusercontent.com';
|
||||
constants.GITHUB_CLIENT_ID = '710fc67886ab1ae8fee6';
|
||||
constants.GATEKEEPER_URL = "https://stackedit-io-gatekeeper.herokuapp.com/";
|
||||
constants.TUMBLR_PROXY_URL = "https://stackedit-io-tumblr-proxy.herokuapp.com/";
|
||||
}
|
||||
|
||||
if(location.hostname.indexOf("benweet.github.io") === 0) {
|
||||
BASE_URL = 'http://benweet.github.io/stackedit/';
|
||||
GOOGLE_CLIENT_ID = '241271498917-jpto9lls9fqnem1e4h6ppds9uob8rpvu.apps.googleusercontent.com';
|
||||
GITHUB_CLIENT_ID = 'fa0d09514da8377ee32e';
|
||||
GATEKEEPER_URL = "https://stackedit-gatekeeper.herokuapp.com/";
|
||||
TUMBLR_PROXY_URL = "https://stackedit-tumblr-proxy.herokuapp.com/";
|
||||
WORDPRESS_CLIENT_ID = '3185';
|
||||
WORDPRESS_PROXY_URL = "https://stackedit-wordpress-proxy.herokuapp.com/";
|
||||
}
|
||||
if(location.hostname.indexOf("benweet.github.io") === 0) {
|
||||
constants.BASE_URL = 'http://benweet.github.io/stackedit/';
|
||||
constants.GOOGLE_CLIENT_ID = '241271498917-jpto9lls9fqnem1e4h6ppds9uob8rpvu.apps.googleusercontent.com';
|
||||
constants.GITHUB_CLIENT_ID = 'fa0d09514da8377ee32e';
|
||||
constants.GATEKEEPER_URL = "https://stackedit-gatekeeper.herokuapp.com/";
|
||||
constants.TUMBLR_PROXY_URL = "https://stackedit-tumblr-proxy.herokuapp.com/";
|
||||
constants.WORDPRESS_CLIENT_ID = '3185';
|
||||
constants.WORDPRESS_PROXY_URL = "https://stackedit-wordpress-proxy.herokuapp.com/";
|
||||
}
|
||||
|
||||
if(location.hostname.indexOf("benweet.insomnia247.nl") === 0) {
|
||||
BASE_URL = "http://benweet.insomnia247.nl/stackedit/";
|
||||
GOOGLE_CLIENT_ID = '241271498917-52hae7a08hv7ltenv7km8h7lghno9sk3.apps.googleusercontent.com';
|
||||
GITHUB_CLIENT_ID = 'd2943d6074b2d9c4a830';
|
||||
GATEKEEPER_URL = "https://stackedit-gatekeeper-insomnia.herokuapp.com/";
|
||||
TUMBLR_PROXY_URL = "https://stackedit-tumblr-proxy-beta.herokuapp.com/";
|
||||
}
|
||||
if(location.hostname.indexOf("benweet.insomnia247.nl") === 0) {
|
||||
constants.BASE_URL = "http://benweet.insomnia247.nl/stackedit/";
|
||||
constants.GOOGLE_CLIENT_ID = '241271498917-52hae7a08hv7ltenv7km8h7lghno9sk3.apps.googleusercontent.com';
|
||||
constants.GITHUB_CLIENT_ID = 'd2943d6074b2d9c4a830';
|
||||
constants.GATEKEEPER_URL = "https://stackedit-gatekeeper-insomnia.herokuapp.com/";
|
||||
constants.TUMBLR_PROXY_URL = "https://stackedit-tumblr-proxy-beta.herokuapp.com/";
|
||||
}
|
||||
|
||||
var THEME_LIST = {
|
||||
constants.THEME_LIST = {
|
||||
"default": "Default",
|
||||
"blue-gray": "Blue-Gray",
|
||||
"night": "Night",
|
||||
"school": "School",
|
||||
};
|
||||
};
|
||||
});
|
||||
|
@ -3,7 +3,9 @@ define([
|
||||
"underscore",
|
||||
"crel",
|
||||
"ace",
|
||||
"constants",
|
||||
"utils",
|
||||
"storage",
|
||||
"settings",
|
||||
"eventMgr",
|
||||
"shortcutMgr",
|
||||
@ -22,7 +24,7 @@ define([
|
||||
'ace/ext/spellcheck',
|
||||
'ace/ext/searchbox'
|
||||
|
||||
], function($, _, crel, ace, utils, settings, eventMgr, shortcutMgr, mousetrap, bodyIndexHTML, bodyViewerHTML, settingsTemplateTooltipHTML, settingsUserCustomExtensionTooltipHTML) {
|
||||
], function($, _, crel, ace, constants, utils, storage, settings, eventMgr, shortcutMgr, mousetrap, bodyIndexHTML, bodyViewerHTML, settingsTemplateTooltipHTML, settingsUserCustomExtensionTooltipHTML) {
|
||||
|
||||
var core = {};
|
||||
|
||||
@ -45,7 +47,7 @@ define([
|
||||
}
|
||||
|
||||
function isUserActive() {
|
||||
if(utils.currentTime - userLastActivity > USER_IDLE_THRESHOLD) {
|
||||
if(utils.currentTime - userLastActivity > constants.USER_IDLE_THRESHOLD) {
|
||||
userActive = false;
|
||||
}
|
||||
return userActive && windowUnique;
|
||||
@ -59,9 +61,9 @@ define([
|
||||
}
|
||||
if(windowId === undefined) {
|
||||
windowId = utils.randomString();
|
||||
localStorage.frontWindowId = windowId;
|
||||
storage.frontWindowId = windowId;
|
||||
}
|
||||
var frontWindowId = localStorage.frontWindowId;
|
||||
var frontWindowId = storage.frontWindowId;
|
||||
if(frontWindowId != windowId) {
|
||||
windowUnique = false;
|
||||
if(intervalId !== undefined) {
|
||||
@ -90,12 +92,12 @@ define([
|
||||
}
|
||||
function checkOnline() {
|
||||
// Try to reconnect if we are offline but we have some network
|
||||
if(isOffline === true && navigator.onLine === true && offlineTime + CHECK_ONLINE_PERIOD < utils.currentTime) {
|
||||
if(isOffline === true && navigator.onLine === true && offlineTime + constants.CHECK_ONLINE_PERIOD < utils.currentTime) {
|
||||
offlineTime = utils.currentTime;
|
||||
// Try to download anything to test the connection
|
||||
$.ajax({
|
||||
url: "//www.google.com/jsapi",
|
||||
timeout: AJAX_TIMEOUT,
|
||||
timeout: constants.AJAX_TIMEOUT,
|
||||
dataType: "script"
|
||||
}).done(function() {
|
||||
setOnline();
|
||||
@ -182,8 +184,8 @@ define([
|
||||
|
||||
if(!event.isPropagationStopped()) {
|
||||
$.extend(settings, newSettings);
|
||||
localStorage.settings = JSON.stringify(settings);
|
||||
localStorage.theme = theme;
|
||||
storage.settings = JSON.stringify(settings);
|
||||
storage.theme = theme;
|
||||
}
|
||||
}
|
||||
|
||||
@ -220,7 +222,7 @@ define([
|
||||
aceEditor.setOption("spellcheck", true);
|
||||
aceEditor.renderer.setShowGutter(false);
|
||||
aceEditor.renderer.setPrintMarginColumn(false);
|
||||
aceEditor.renderer.setPadding(EDITOR_DEFAULT_PADDING);
|
||||
aceEditor.renderer.setPadding(constants.EDITOR_DEFAULT_PADDING);
|
||||
aceEditor.session.setUseWrapMode(true);
|
||||
aceEditor.session.setNewLineMode("unix");
|
||||
aceEditor.session.setMode("libs/ace_mode");
|
||||
@ -334,8 +336,8 @@ define([
|
||||
aceEditor.renderer.setScrollMargin(0, bottomMargin, 0, 0);
|
||||
setTimeout(function() {
|
||||
var padding = (aceEditor.renderer.$size.scrollerWidth - settings.maxWidth) / 2;
|
||||
if(padding < EDITOR_DEFAULT_PADDING) {
|
||||
padding = EDITOR_DEFAULT_PADDING;
|
||||
if(padding < constants.EDITOR_DEFAULT_PADDING) {
|
||||
padding = constants.EDITOR_DEFAULT_PADDING;
|
||||
}
|
||||
if(padding !== aceEditor.renderer.$padding) {
|
||||
aceEditor.renderer.setPadding(padding);
|
||||
@ -747,7 +749,7 @@ define([
|
||||
isModalShown = false;
|
||||
(aceEditor && aceEditor.focus()) || $editorElt.focus();
|
||||
// Revert to current theme when settings modal is closed
|
||||
applyTheme(localStorage.theme);
|
||||
applyTheme(storage.theme);
|
||||
}).keyup(function(e) {
|
||||
// Handle enter key in modals
|
||||
if(e.which == 13 && !$(e.target).is("textarea")) {
|
||||
@ -827,7 +829,7 @@ define([
|
||||
$(".action-import-docs-settings").click(function(e) {
|
||||
$("#input-file-import-docs-settings").click();
|
||||
});
|
||||
var newLocalStorage = undefined;
|
||||
var newstorage = undefined;
|
||||
$("#input-file-import-docs-settings").change(function(evt) {
|
||||
var files = (evt.dataTransfer || evt.target).files;
|
||||
$(".modal-settings").modal("hide");
|
||||
@ -836,12 +838,12 @@ define([
|
||||
reader.onload = (function(importedFile) {
|
||||
return function(e) {
|
||||
try {
|
||||
newLocalStorage = JSON.parse(e.target.result);
|
||||
// Compare localStorage version
|
||||
var newVersion = parseInt(newLocalStorage.version.match(/^v(\d+)$/)[1], 10);
|
||||
var currentVersion = parseInt(localStorage.version.match(/^v(\d+)$/)[1], 10);
|
||||
newstorage = JSON.parse(e.target.result);
|
||||
// Compare storage version
|
||||
var newVersion = parseInt(newstorage.version.match(/^v(\d+)$/)[1], 10);
|
||||
var currentVersion = parseInt(storage.version.match(/^v(\d+)$/)[1], 10);
|
||||
if(newVersion > currentVersion) {
|
||||
// We manage localStorage upgrade, not downgrade
|
||||
// We manage storage upgrade, not downgrade
|
||||
eventMgr.onError("Incompatible version. Please upgrade StackEdit.");
|
||||
} else {
|
||||
$('.modal-import-docs-settings').modal('show');
|
||||
@ -857,28 +859,28 @@ define([
|
||||
});
|
||||
});
|
||||
$(".action-import-docs-settings-confirm").click(function(e) {
|
||||
localStorage.clear();
|
||||
storage.clear();
|
||||
var allowedKeys = /^file\.|^focusMode$|^folder\.|^publish\.|^settings$|^sync\.|^theme$|^version$|^welcomeTour$/;
|
||||
_.each(newLocalStorage, function(value, key) {
|
||||
_.each(newstorage, function(value, key) {
|
||||
if(allowedKeys.test(key)) {
|
||||
localStorage[key] = value;
|
||||
storage[key] = value;
|
||||
}
|
||||
});
|
||||
window.location.reload();
|
||||
});
|
||||
// Export settings
|
||||
$(".action-export-docs-settings").click(function(e) {
|
||||
utils.saveAs(JSON.stringify(localStorage), "StackEdit local storage.json");
|
||||
utils.saveAs(JSON.stringify(storage), "StackEdit local storage.json");
|
||||
});
|
||||
|
||||
$(".action-default-settings").click(function() {
|
||||
localStorage.removeItem("settings");
|
||||
localStorage.removeItem("theme");
|
||||
storage.removeItem("settings");
|
||||
storage.removeItem("theme");
|
||||
window.location.reload();
|
||||
});
|
||||
|
||||
$(".action-app-reset").click(function() {
|
||||
localStorage.clear();
|
||||
storage.clear();
|
||||
window.location.reload();
|
||||
});
|
||||
|
||||
@ -974,7 +976,7 @@ define([
|
||||
|
||||
if(viewerMode === false) {
|
||||
// Load theme list
|
||||
var themeOptions = _.reduce(THEME_LIST, function(themeOptions, name, value) {
|
||||
var themeOptions = _.reduce(constants.THEME_LIST, function(themeOptions, name, value) {
|
||||
return themeOptions + '<option value="' + value + '">' + name + '</option>';
|
||||
}, '');
|
||||
document.getElementById('input-settings-theme').innerHTML = themeOptions;
|
||||
|
@ -2,8 +2,9 @@ define([
|
||||
"jquery",
|
||||
"underscore",
|
||||
"crel",
|
||||
"storage",
|
||||
"classes/Extension"
|
||||
], function($, _, crel, Extension) {
|
||||
], function($, _, crel, storage, Extension) {
|
||||
|
||||
var buttonFocusMode = new Extension("buttonFocusMode", 'Button "Focus Mode"', true, true, true);
|
||||
buttonFocusMode.settingsBlock = "When typing, scrolls automatically the editor to always have the caret centered verticaly.";
|
||||
@ -33,7 +34,7 @@ define([
|
||||
aceEditor.container.addEventListener('mousedown', function() {
|
||||
isMouseActive = true;
|
||||
}, true);
|
||||
if(localStorage.focusMode == 'on') {
|
||||
if(storage.focusMode == 'on') {
|
||||
$button.click();
|
||||
}
|
||||
};
|
||||
@ -47,7 +48,7 @@ define([
|
||||
$button.click(function() {
|
||||
_.defer(function() {
|
||||
isFocusModeOn = $button.is('.active');
|
||||
localStorage.focusMode = isFocusModeOn ? 'on' : 'off';
|
||||
storage.focusMode = isFocusModeOn ? 'on' : 'off';
|
||||
isMouseActive = false;
|
||||
aceEditor.focus();
|
||||
doFocusMode();
|
||||
|
@ -1,10 +1,11 @@
|
||||
define([
|
||||
"underscore",
|
||||
"constants",
|
||||
"utils",
|
||||
"classes/Extension",
|
||||
"text!html/dialogAbout.html",
|
||||
"config"
|
||||
], function(_, utils, Extension, dialogAboutHTML) {
|
||||
], function(_, constants, utils, Extension, dialogAboutHTML) {
|
||||
|
||||
var dialogAbout = new Extension("dialogAbout", 'Dialog "About"');
|
||||
|
||||
@ -54,7 +55,7 @@ define([
|
||||
utils.addModal('modal-about', _.template(dialogAboutHTML, {
|
||||
libraries: libraries,
|
||||
projects: projects,
|
||||
version: VERSION
|
||||
version: constants.VERSION
|
||||
}));
|
||||
};
|
||||
|
||||
|
@ -1,11 +1,12 @@
|
||||
define([
|
||||
"jquery",
|
||||
"underscore",
|
||||
"constants",
|
||||
"utils",
|
||||
"classes/Extension",
|
||||
"toMarkdown",
|
||||
"config",
|
||||
], function($, _, utils, Extension, toMarkdown) {
|
||||
], function($, _, constants, utils, Extension, toMarkdown) {
|
||||
|
||||
var dialogOpenHarddrive = new Extension("dialogOpenHarddrive", 'Dialog "Open from"');
|
||||
|
||||
@ -53,7 +54,7 @@ define([
|
||||
fileMgr.selectFile(fileDesc);
|
||||
};
|
||||
})(file);
|
||||
var blob = file.slice(0, IMPORT_FILE_MAX_CONTENT_SIZE);
|
||||
var blob = file.slice(0, constants.IMPORT_FILE_MAX_CONTENT_SIZE);
|
||||
reader.readAsText(blob);
|
||||
});
|
||||
}
|
||||
|
@ -1,13 +1,15 @@
|
||||
define([
|
||||
"jquery",
|
||||
"underscore",
|
||||
"constants",
|
||||
"utils",
|
||||
"storage",
|
||||
"classes/Extension",
|
||||
"classes/FolderDescriptor",
|
||||
"folderList",
|
||||
"fileSystem",
|
||||
"config"
|
||||
], function($, _, utils, Extension, FolderDescriptor, folderList, fileSystem) {
|
||||
], function($, _, constants, utils, storage, Extension, FolderDescriptor, folderList, fileSystem) {
|
||||
|
||||
var documentManager = new Extension("documentManager", 'Document Manager', false, true);
|
||||
|
||||
@ -105,8 +107,8 @@ define([
|
||||
// Delete folders
|
||||
_.each(selectedFolderList, function(folderDesc) {
|
||||
utils.removeIndexFromArray("folder.list", folderDesc.folderIndex);
|
||||
localStorage.removeItem(folderDesc.folderIndex + ".name");
|
||||
localStorage.removeItem(folderDesc.folderIndex + ".files");
|
||||
storage.removeItem(folderDesc.folderIndex + ".name");
|
||||
storage.removeItem(folderDesc.folderIndex + ".files");
|
||||
delete folderList[folderDesc.folderIndex];
|
||||
});
|
||||
eventMgr.onFoldersChanged();
|
||||
@ -314,10 +316,10 @@ define([
|
||||
folderIndex = "folder." + utils.randomString();
|
||||
} while (_.has(folderList, folderIndex));
|
||||
|
||||
localStorage[folderIndex + ".name"] = DEFAULT_FOLDER_NAME;
|
||||
storage[folderIndex + ".name"] = constants.DEFAULT_FOLDER_NAME;
|
||||
|
||||
// Create the folder descriptor
|
||||
var folderDesc = new FolderDescriptor(folderIndex, DEFAULT_FOLDER_NAME);
|
||||
var folderDesc = new FolderDescriptor(folderIndex, constants.DEFAULT_FOLDER_NAME);
|
||||
|
||||
// Add the index to the folder list
|
||||
utils.appendIndexToArray("folder.list", folderIndex);
|
||||
|
@ -1,11 +1,12 @@
|
||||
define([
|
||||
"jquery",
|
||||
"underscore",
|
||||
"constants",
|
||||
"utils",
|
||||
"classes/Extension",
|
||||
"settings",
|
||||
"config",
|
||||
], function($, _, utils, Extension, settings) {
|
||||
], function($, _, constants, utils, Extension, settings) {
|
||||
|
||||
var googleAnalytics = new Extension("googleAnalytics", "Google Analytics", true);
|
||||
googleAnalytics.settingsBlock = '<p>Sends anonymous statistics about usage and errors to help improve StackEdit.</p>';
|
||||
@ -47,7 +48,7 @@ define([
|
||||
// First configure GA
|
||||
_gaq.push([
|
||||
'_setAccount',
|
||||
GOOGLE_ANALYTICS_ACCOUNT_ID
|
||||
constants.GOOGLE_ANALYTICS_ACCOUNT_ID
|
||||
]);
|
||||
trackPageView();
|
||||
|
||||
@ -56,7 +57,7 @@ define([
|
||||
'_trackEvent',
|
||||
"About",
|
||||
'version',
|
||||
VERSION
|
||||
constants.VERSION
|
||||
]);
|
||||
|
||||
// Collect informations about user settings
|
||||
@ -95,20 +96,20 @@ define([
|
||||
'_trackEvent',
|
||||
"Settings",
|
||||
'defaultContent backlink',
|
||||
"" + (settings.defaultContent.indexOf(MAIN_URL) !== -1)
|
||||
"" + (settings.defaultContent.indexOf(constants.MAIN_URL) !== -1)
|
||||
]);
|
||||
_gaq.push([
|
||||
'_trackEvent',
|
||||
"Settings",
|
||||
'commitMsg backlink',
|
||||
"" + (settings.commitMsg.indexOf(MAIN_URL) !== -1)
|
||||
"" + (settings.commitMsg.indexOf(constants.MAIN_URL) !== -1)
|
||||
]);
|
||||
// Check if user has changed sshProxy
|
||||
_gaq.push([
|
||||
'_trackEvent',
|
||||
"Settings",
|
||||
'sshProxy unchanged',
|
||||
"" + (settings.sshProxy == SSH_PROXY_URL)
|
||||
"" + (settings.sshProxy == constants.SSH_PROXY_URL)
|
||||
]);
|
||||
// Check if extensions have been disabled
|
||||
_.each(settings.extensionSettings, function(config, extensionId) {
|
||||
|
@ -1,9 +1,10 @@
|
||||
define([
|
||||
'underscore',
|
||||
'jquery',
|
||||
'storage',
|
||||
'classes/Extension',
|
||||
'bootstrap-tour'
|
||||
], function(_, $, Extension) {
|
||||
], function(_, $, storage, Extension) {
|
||||
|
||||
var welcomeTour = new Extension('welcomeTour', 'Welcome tour', false, true);
|
||||
|
||||
@ -19,7 +20,7 @@ define([
|
||||
}
|
||||
},
|
||||
onEnd: function(tour) {
|
||||
localStorage.welcomeTour = 'done';
|
||||
storage.welcomeTour = 'done';
|
||||
},
|
||||
template: [
|
||||
'<div class="popover tour">',
|
||||
@ -86,7 +87,7 @@ define([
|
||||
reflex: true,
|
||||
},
|
||||
]);
|
||||
if(!_.has(localStorage, 'welcomeTour')) {
|
||||
if(!_.has(storage, 'welcomeTour')) {
|
||||
tour.start();
|
||||
}
|
||||
$('.action-welcome-tour').click(function() {
|
||||
|
@ -1,14 +1,16 @@
|
||||
define([
|
||||
"jquery",
|
||||
"underscore",
|
||||
"constants",
|
||||
"core",
|
||||
"utils",
|
||||
"storage",
|
||||
"settings",
|
||||
"eventMgr",
|
||||
"fileSystem",
|
||||
"classes/FileDescriptor",
|
||||
"text!WELCOME.md"
|
||||
], function($, _, core, utils, settings, eventMgr, fileSystem, FileDescriptor, welcomeContent) {
|
||||
], function($, _, constants, core, utils, storage, settings, eventMgr, fileSystem, FileDescriptor, welcomeContent) {
|
||||
|
||||
var fileMgr = {};
|
||||
|
||||
@ -23,7 +25,7 @@ define([
|
||||
var fileSystemSize = _.size(fileSystem);
|
||||
if(fileSystemSize === 0) {
|
||||
// If fileSystem empty create one file
|
||||
fileDesc = fileMgr.createFile(WELCOME_DOCUMENT_TITLE, welcomeContent);
|
||||
fileDesc = fileMgr.createFile(constants.WELCOME_DOCUMENT_TITLE, welcomeContent);
|
||||
}
|
||||
else {
|
||||
// Select the last selected file
|
||||
@ -41,7 +43,7 @@ define([
|
||||
eventMgr.onFileSelected(fileDesc);
|
||||
|
||||
// Hide the viewer pencil button
|
||||
$(".action-edit-document").toggleClass("hide", fileDesc.fileIndex != TEMPORARY_FILE_INDEX);
|
||||
$(".action-edit-document").toggleClass("hide", fileDesc.fileIndex != constants.TEMPORARY_FILE_INDEX);
|
||||
}
|
||||
|
||||
// Refresh the editor (even if it's the same file)
|
||||
@ -52,17 +54,18 @@ define([
|
||||
content = content !== undefined ? content : settings.defaultContent;
|
||||
if(!title) {
|
||||
// Create a file title
|
||||
title = DEFAULT_FILE_TITLE;
|
||||
title = constants.DEFAULT_FILE_TITLE;
|
||||
var indicator = 2;
|
||||
while (_.some(fileSystem, function(fileDesc) {
|
||||
var checkTitle = function (fileDesc) {
|
||||
return fileDesc.title == title;
|
||||
})) {
|
||||
title = DEFAULT_FILE_TITLE + indicator++;
|
||||
};
|
||||
while (_.some(fileSystem, checkTitle)) {
|
||||
title = constants.DEFAULT_FILE_TITLE + indicator++;
|
||||
}
|
||||
}
|
||||
|
||||
// Generate a unique fileIndex
|
||||
var fileIndex = TEMPORARY_FILE_INDEX;
|
||||
var fileIndex = constants.TEMPORARY_FILE_INDEX;
|
||||
if(!isTemporary) {
|
||||
do {
|
||||
fileIndex = "file." + utils.randomString();
|
||||
@ -76,10 +79,10 @@ define([
|
||||
return sync + syncAttributes.syncIndex + ";";
|
||||
}, ";");
|
||||
|
||||
localStorage[fileIndex + ".title"] = title;
|
||||
localStorage[fileIndex + ".content"] = content;
|
||||
localStorage[fileIndex + ".sync"] = sync;
|
||||
localStorage[fileIndex + ".publish"] = ";";
|
||||
storage[fileIndex + ".title"] = title;
|
||||
storage[fileIndex + ".content"] = content;
|
||||
storage[fileIndex + ".sync"] = sync;
|
||||
storage[fileIndex + ".publish"] = ";";
|
||||
|
||||
// Create the file descriptor
|
||||
var fileDesc = new FileDescriptor(fileIndex, title, syncLocations);
|
||||
@ -107,25 +110,25 @@ define([
|
||||
fileMgr.selectFile();
|
||||
}
|
||||
|
||||
// Remove synchronized locations from localStorage
|
||||
// Remove synchronized locations from storage
|
||||
_.each(fileDesc.syncLocations, function(syncAttributes) {
|
||||
localStorage.removeItem(syncAttributes.syncIndex);
|
||||
storage.removeItem(syncAttributes.syncIndex);
|
||||
});
|
||||
|
||||
// Remove publish locations from localStorage
|
||||
// Remove publish locations from storage
|
||||
_.each(fileDesc.publishLocations, function(publishAttributes) {
|
||||
localStorage.removeItem(publishAttributes.publishIndex);
|
||||
storage.removeItem(publishAttributes.publishIndex);
|
||||
});
|
||||
|
||||
localStorage.removeItem(fileDesc.fileIndex + ".title");
|
||||
localStorage.removeItem(fileDesc.fileIndex + ".content");
|
||||
localStorage.removeItem(fileDesc.fileIndex + ".sync");
|
||||
localStorage.removeItem(fileDesc.fileIndex + ".publish");
|
||||
localStorage.removeItem(fileDesc.fileIndex + ".selectTime");
|
||||
localStorage.removeItem(fileDesc.fileIndex + ".editorStart");
|
||||
localStorage.removeItem(fileDesc.fileIndex + ".editorEnd");
|
||||
localStorage.removeItem(fileDesc.fileIndex + ".editorScrollTop");
|
||||
localStorage.removeItem(fileDesc.fileIndex + ".previewScrollTop");
|
||||
storage.removeItem(fileDesc.fileIndex + ".title");
|
||||
storage.removeItem(fileDesc.fileIndex + ".content");
|
||||
storage.removeItem(fileDesc.fileIndex + ".sync");
|
||||
storage.removeItem(fileDesc.fileIndex + ".publish");
|
||||
storage.removeItem(fileDesc.fileIndex + ".selectTime");
|
||||
storage.removeItem(fileDesc.fileIndex + ".editorStart");
|
||||
storage.removeItem(fileDesc.fileIndex + ".editorEnd");
|
||||
storage.removeItem(fileDesc.fileIndex + ".editorScrollTop");
|
||||
storage.removeItem(fileDesc.fileIndex + ".previewScrollTop");
|
||||
|
||||
eventMgr.onFileDeleted(fileDesc);
|
||||
};
|
||||
@ -150,13 +153,13 @@ define([
|
||||
});
|
||||
};
|
||||
|
||||
var aceEditor = undefined;
|
||||
var aceEditor;
|
||||
eventMgr.addListener('onAceCreated', function(aceEditorParam) {
|
||||
aceEditor = aceEditorParam;
|
||||
});
|
||||
|
||||
eventMgr.addListener("onReady", function() {
|
||||
$editorElt = $("#wmd-input")
|
||||
var $editorElt = $("#wmd-input");
|
||||
fileMgr.selectFile();
|
||||
|
||||
var $fileTitleElt = $('.file-title-navbar');
|
||||
@ -170,7 +173,7 @@ define([
|
||||
fileMgr.deleteFile();
|
||||
});
|
||||
$fileTitleElt.click(function() {
|
||||
if(viewerMode === true) {
|
||||
if(window.viewerMode === true) {
|
||||
return;
|
||||
}
|
||||
$fileTitleElt.addClass('hide');
|
||||
@ -216,7 +219,7 @@ define([
|
||||
window.location.href = ".";
|
||||
});
|
||||
$(".action-welcome-file").click(function() {
|
||||
var fileDesc = fileMgr.createFile(WELCOME_DOCUMENT_TITLE, welcomeContent);
|
||||
var fileDesc = fileMgr.createFile(constants.WELCOME_DOCUMENT_TITLE, welcomeContent);
|
||||
fileMgr.selectFile(fileDesc);
|
||||
});
|
||||
});
|
||||
|
@ -1,13 +1,17 @@
|
||||
/*global Dropbox */
|
||||
define([
|
||||
"jquery",
|
||||
"underscore",
|
||||
"constants",
|
||||
"core",
|
||||
"storage",
|
||||
"logger",
|
||||
"eventMgr",
|
||||
"classes/AsyncTask",
|
||||
"config",
|
||||
], function($, _, core, eventMgr, AsyncTask) {
|
||||
], function($, _, constants, core, storage, logger, eventMgr, AsyncTask) {
|
||||
|
||||
var client = undefined;
|
||||
var client;
|
||||
var authenticated = false;
|
||||
|
||||
var dropboxHelper = {};
|
||||
@ -33,14 +37,14 @@ define([
|
||||
$.ajax({
|
||||
url: "libs/dropbox.min.js",
|
||||
dataType: "script",
|
||||
timeout: AJAX_TIMEOUT
|
||||
timeout: constants.AJAX_TIMEOUT
|
||||
}).done(function() {
|
||||
client = new Dropbox.Client({
|
||||
key: DROPBOX_APP_KEY,
|
||||
secret: DROPBOX_APP_SECRET
|
||||
key: constants.DROPBOX_APP_KEY,
|
||||
secret: constants.DROPBOX_APP_SECRET
|
||||
});
|
||||
client.authDriver(new Dropbox.AuthDriver.Popup({
|
||||
receiverUrl: BASE_URL + "html/dropbox-oauth-receiver.html",
|
||||
receiverUrl: constants.BASE_URL + "html/dropbox-oauth-receiver.html",
|
||||
rememberUser: true
|
||||
}));
|
||||
task.chain();
|
||||
@ -73,7 +77,7 @@ define([
|
||||
if(immediate === false) {
|
||||
// If not immediate we add time for user to enter his
|
||||
// credentials
|
||||
task.timeout = ASYNC_TASK_LONG_TIMEOUT;
|
||||
task.timeout = constants.ASYNC_TASK_LONG_TIMEOUT;
|
||||
}
|
||||
else {
|
||||
client.reset();
|
||||
@ -102,7 +106,7 @@ define([
|
||||
}
|
||||
|
||||
dropboxHelper.upload = function(path, content, callback) {
|
||||
var result = undefined;
|
||||
var result;
|
||||
var task = new AsyncTask();
|
||||
connect(task);
|
||||
authenticate(task);
|
||||
@ -212,7 +216,7 @@ define([
|
||||
}
|
||||
var object = objects[0];
|
||||
result.push(object);
|
||||
var file = undefined;
|
||||
var file;
|
||||
// object may be a file
|
||||
if(object.isFile === true) {
|
||||
file = object;
|
||||
@ -266,11 +270,11 @@ define([
|
||||
}
|
||||
else if(error.status === 400 && error.responseText.indexOf("oauth_nonce") !== -1) {
|
||||
// A bug I guess...
|
||||
_.each(_.keys(localStorage), function(key) {
|
||||
_.each(_.keys(storage), function(key) {
|
||||
// We have to remove the Oauth cache from the
|
||||
// localStorage
|
||||
// storage
|
||||
if(key.indexOf("dropbox-auth") === 0) {
|
||||
localStorage.removeItem(key);
|
||||
storage.removeItem(key);
|
||||
}
|
||||
});
|
||||
authenticated = false;
|
||||
@ -305,7 +309,7 @@ define([
|
||||
$.ajax({
|
||||
url: "https://www.dropbox.com/static/api/1/dropbox.js",
|
||||
dataType: "script",
|
||||
timeout: AJAX_TIMEOUT
|
||||
timeout: constants.AJAX_TIMEOUT
|
||||
}).done(function() {
|
||||
pickerLoaded = true;
|
||||
task.chain(chooserRedirect);
|
||||
@ -323,7 +327,7 @@ define([
|
||||
var paths = [];
|
||||
var task = new AsyncTask();
|
||||
// Add some time for user to choose his files
|
||||
task.timeout = ASYNC_TASK_LONG_TIMEOUT;
|
||||
task.timeout = constants.ASYNC_TASK_LONG_TIMEOUT;
|
||||
connect(task);
|
||||
loadPicker(task);
|
||||
task.onRun(function() {
|
||||
|
@ -1,14 +1,18 @@
|
||||
/*global Github */
|
||||
define([
|
||||
"jquery",
|
||||
"constants",
|
||||
"core",
|
||||
"utils",
|
||||
"storage",
|
||||
"logger",
|
||||
"eventMgr",
|
||||
"classes/AsyncTask",
|
||||
"config"
|
||||
], function($, core, utils, eventMgr, AsyncTask) {
|
||||
], function($, constants, core, utils, storage, logger, eventMgr, AsyncTask) {
|
||||
|
||||
var connected = undefined;
|
||||
var github = undefined;
|
||||
var connected;
|
||||
var github;
|
||||
|
||||
var githubHelper = {};
|
||||
|
||||
@ -33,7 +37,7 @@ define([
|
||||
$.ajax({
|
||||
url: "libs/github.js",
|
||||
dataType: "script",
|
||||
timeout: AJAX_TIMEOUT
|
||||
timeout: constants.AJAX_TIMEOUT
|
||||
}).done(function() {
|
||||
connected = true;
|
||||
task.chain();
|
||||
@ -49,14 +53,14 @@ define([
|
||||
|
||||
// Try to authenticate with Oauth
|
||||
function authenticate(task) {
|
||||
var authWindow = undefined;
|
||||
var intervalId = undefined;
|
||||
var authWindow;
|
||||
var intervalId;
|
||||
task.onRun(function() {
|
||||
if(github !== undefined) {
|
||||
task.chain();
|
||||
return;
|
||||
}
|
||||
var token = localStorage.githubToken;
|
||||
var token = storage.githubToken;
|
||||
if(token !== undefined) {
|
||||
github = new Github({
|
||||
token: token,
|
||||
@ -67,8 +71,8 @@ define([
|
||||
}
|
||||
var errorMsg = "Failed to retrieve a token from GitHub.";
|
||||
// We add time for user to enter his credentials
|
||||
task.timeout = ASYNC_TASK_LONG_TIMEOUT;
|
||||
var code = undefined;
|
||||
task.timeout = constants.ASYNC_TASK_LONG_TIMEOUT;
|
||||
var code;
|
||||
function oauthRedirect() {
|
||||
core.redirectConfirm('You are being redirected to <strong>GitHub</strong> authorization page.', function() {
|
||||
task.chain(getCode);
|
||||
@ -77,29 +81,29 @@ define([
|
||||
});
|
||||
}
|
||||
function getCode() {
|
||||
localStorage.removeItem("githubCode");
|
||||
authWindow = utils.popupWindow('html/github-oauth-client.html?client_id=' + GITHUB_CLIENT_ID, 'stackedit-github-oauth', 960, 600);
|
||||
storage.removeItem("githubCode");
|
||||
authWindow = utils.popupWindow('html/github-oauth-client.html?client_id=' + constants.GITHUB_CLIENT_ID, 'stackedit-github-oauth', 960, 600);
|
||||
authWindow.focus();
|
||||
intervalId = setInterval(function() {
|
||||
if(authWindow.closed === true) {
|
||||
clearInterval(intervalId);
|
||||
authWindow = undefined;
|
||||
intervalId = undefined;
|
||||
code = localStorage.githubCode;
|
||||
code = storage.githubCode;
|
||||
if(code === undefined) {
|
||||
task.error(new Error(errorMsg));
|
||||
return;
|
||||
}
|
||||
localStorage.removeItem("githubCode");
|
||||
storage.removeItem("githubCode");
|
||||
task.chain(getToken);
|
||||
}
|
||||
}, 500);
|
||||
}
|
||||
function getToken() {
|
||||
$.getJSON(GATEKEEPER_URL + "authenticate/" + code, function(data) {
|
||||
$.getJSON(constants.GATEKEEPER_URL + "authenticate/" + code, function(data) {
|
||||
if(data.token !== undefined) {
|
||||
token = data.token;
|
||||
localStorage.githubToken = token;
|
||||
storage.githubToken = token;
|
||||
github = new Github({
|
||||
token: token,
|
||||
auth: "oauth"
|
||||
@ -175,7 +179,7 @@ define([
|
||||
files[filename] = {
|
||||
content: content
|
||||
};
|
||||
githubFunction = gist.update;
|
||||
var githubFunction = gist.update;
|
||||
if(gistId === undefined) {
|
||||
githubFunction = gist.create;
|
||||
}
|
||||
@ -209,8 +213,8 @@ define([
|
||||
var task = new AsyncTask(true);
|
||||
connect(task);
|
||||
// No need for authentication
|
||||
var title = undefined;
|
||||
var content = undefined;
|
||||
var title;
|
||||
var content;
|
||||
task.onRun(function() {
|
||||
var github = new Github({});
|
||||
var gist = github.getGist(gistId);
|
||||
@ -240,7 +244,7 @@ define([
|
||||
};
|
||||
|
||||
function handleError(error, task) {
|
||||
var errorMsg = undefined;
|
||||
var errorMsg;
|
||||
if(error) {
|
||||
logger.error(error);
|
||||
// Try to analyze the error
|
||||
@ -251,7 +255,7 @@ define([
|
||||
errorMsg = "Could not publish on GitHub.";
|
||||
if(error.error === 401 || error.error === 403) {
|
||||
github = undefined;
|
||||
localStorage.removeItem("githubToken");
|
||||
storage.removeItem("githubToken");
|
||||
errorMsg = "Access to GitHub account is not authorized.";
|
||||
task.retry(new Error(errorMsg), 1);
|
||||
return;
|
||||
|
@ -1,20 +1,24 @@
|
||||
/*global gapi, google */
|
||||
define([
|
||||
"underscore",
|
||||
"jquery",
|
||||
"constants",
|
||||
"core",
|
||||
"utils",
|
||||
"storage",
|
||||
"logger",
|
||||
"settings",
|
||||
"eventMgr",
|
||||
"classes/AsyncTask",
|
||||
"config"
|
||||
], function(_, $, core, utils, settings, eventMgr, AsyncTask) {
|
||||
], function(_, $, constants, core, utils, storage, logger, settings, eventMgr, AsyncTask) {
|
||||
|
||||
var connected = false;
|
||||
var authorizationMgr = {};
|
||||
(function() {
|
||||
var permissionList = {};
|
||||
var isAuthorized = false;
|
||||
_.each((localStorage.gdrivePermissions || '').split(';'), function(permission) {
|
||||
_.each((storage.gdrivePermissions || '').split(';'), function(permission) {
|
||||
permission && (permissionList[permission] = true);
|
||||
});
|
||||
authorizationMgr.reset = function() {
|
||||
@ -25,7 +29,7 @@ define([
|
||||
};
|
||||
authorizationMgr.add = function(permission) {
|
||||
permissionList[permission] = true;
|
||||
localStorage.gdrivePermissions = _.keys(permissionList).join(';');
|
||||
storage.gdrivePermissions = _.keys(permissionList).join(';');
|
||||
isAuthorized = true;
|
||||
};
|
||||
authorizationMgr.getListWithNew = function(permission) {
|
||||
@ -57,7 +61,7 @@ define([
|
||||
task.chain();
|
||||
return;
|
||||
}
|
||||
delayedFunction = function() {
|
||||
window.delayedFunction = function() {
|
||||
gapi.load("client,drive-realtime", function() {
|
||||
connected = true;
|
||||
task.chain();
|
||||
@ -66,7 +70,7 @@ define([
|
||||
$.ajax({
|
||||
url: "https://apis.google.com/js/api.js?onload=runDelayedFunction",
|
||||
dataType: "script",
|
||||
timeout: AJAX_TIMEOUT
|
||||
timeout: constants.AJAX_TIMEOUT
|
||||
}).fail(function(jqXHR) {
|
||||
var error = {
|
||||
code: jqXHR.status,
|
||||
@ -106,11 +110,11 @@ define([
|
||||
}
|
||||
function localAuthenticate() {
|
||||
if(immediate === false) {
|
||||
task.timeout = ASYNC_TASK_LONG_TIMEOUT;
|
||||
task.timeout = constants.ASYNC_TASK_LONG_TIMEOUT;
|
||||
}
|
||||
var scopeList = _.chain(scopeMap).pick(authorizationMgr.getListWithNew(permission)).flatten().value();
|
||||
gapi.auth.authorize({
|
||||
'client_id': GOOGLE_CLIENT_ID,
|
||||
'client_id': constants.GOOGLE_CLIENT_ID,
|
||||
'scope': scopeList,
|
||||
'immediate': immediate
|
||||
}, function(authResult) {
|
||||
@ -144,7 +148,7 @@ define([
|
||||
};
|
||||
|
||||
googleHelper.upload = function(fileId, parentId, title, content, contentType, etag, callback) {
|
||||
var result = undefined;
|
||||
var result;
|
||||
var task = new AsyncTask();
|
||||
connect(task);
|
||||
authenticate(task, 'gdrive');
|
||||
@ -222,7 +226,7 @@ define([
|
||||
}
|
||||
else if(error.code === 412) {
|
||||
// We may have missed a file update
|
||||
localStorage.removeItem("gdrive.lastChangeId");
|
||||
storage.removeItem("gdrive.lastChangeId");
|
||||
error = 'Conflict on file ID "' + fileId + '". Please restart the synchronization.';
|
||||
}
|
||||
}
|
||||
@ -239,7 +243,7 @@ define([
|
||||
};
|
||||
|
||||
googleHelper.rename = function(fileId, title, callback) {
|
||||
var result = undefined;
|
||||
var result;
|
||||
var task = new AsyncTask();
|
||||
connect(task);
|
||||
authenticate(task, 'gdrive');
|
||||
@ -276,7 +280,7 @@ define([
|
||||
};
|
||||
|
||||
googleHelper.createRealtimeFile = function(parentId, title, callback) {
|
||||
var result = undefined;
|
||||
var result;
|
||||
var task = new AsyncTask();
|
||||
connect(task);
|
||||
authenticate(task, 'gdrive');
|
||||
@ -317,7 +321,7 @@ define([
|
||||
};
|
||||
|
||||
googleHelper.uploadImg = function(name, content, albumId, callback) {
|
||||
var result = undefined;
|
||||
var result;
|
||||
var task = new AsyncTask();
|
||||
connect(task);
|
||||
authenticate(task, 'picasa');
|
||||
@ -340,14 +344,14 @@ define([
|
||||
}
|
||||
|
||||
$.ajax({
|
||||
url: PICASA_PROXY_URL + "upload/" + albumId,
|
||||
url: constants.PICASA_PROXY_URL + "upload/" + albumId,
|
||||
headers: headers,
|
||||
data: content,
|
||||
processData: false,
|
||||
dataType: "xml",
|
||||
timeout: AJAX_TIMEOUT,
|
||||
timeout: constants.AJAX_TIMEOUT,
|
||||
type: "POST"
|
||||
}).done(function(data, textStatus, jqXHR) {
|
||||
}).done(function(data) {
|
||||
result = data;
|
||||
task.chain();
|
||||
}).fail(function(jqXHR) {
|
||||
@ -377,9 +381,9 @@ define([
|
||||
connect(task);
|
||||
authenticate(task, 'gdrive');
|
||||
task.onRun(function() {
|
||||
var nextPageToken = undefined;
|
||||
var nextPageToken;
|
||||
function retrievePageOfChanges() {
|
||||
var request = undefined;
|
||||
var request;
|
||||
if(nextPageToken === undefined) {
|
||||
request = gapi.client.drive.changes.list({
|
||||
'startChangeId': newChangeId + 1
|
||||
@ -445,11 +449,11 @@ define([
|
||||
url: "https://www.googleapis.com/drive/v2/files/" + id,
|
||||
headers: headers,
|
||||
data: {
|
||||
key: GOOGLE_API_KEY
|
||||
key: constants.GOOGLE_API_KEY
|
||||
},
|
||||
dataType: "json",
|
||||
timeout: AJAX_TIMEOUT
|
||||
}).done(function(data, textStatus, jqXHR) {
|
||||
timeout: constants.AJAX_TIMEOUT
|
||||
}).done(function(data) {
|
||||
result.push(data);
|
||||
ids.shift();
|
||||
task.chain(recursiveDownloadMetadata);
|
||||
@ -480,7 +484,7 @@ define([
|
||||
var result = [];
|
||||
var task = new AsyncTask();
|
||||
// Add some time for user to choose his files
|
||||
task.timeout = ASYNC_TASK_LONG_TIMEOUT;
|
||||
task.timeout = constants.ASYNC_TASK_LONG_TIMEOUT;
|
||||
connect(task);
|
||||
if(!skipAuth) {
|
||||
authenticate(task, 'gdrive');
|
||||
@ -493,7 +497,7 @@ define([
|
||||
}
|
||||
var object = objects[0];
|
||||
result.push(object);
|
||||
var file = undefined;
|
||||
var file;
|
||||
// object may be a file
|
||||
if(object.kind == "drive#file") {
|
||||
file = object;
|
||||
@ -524,11 +528,11 @@ define([
|
||||
url: file.downloadUrl,
|
||||
headers: headers,
|
||||
data: {
|
||||
key: GOOGLE_API_KEY
|
||||
key: constants.GOOGLE_API_KEY
|
||||
},
|
||||
dataType: "text",
|
||||
timeout: AJAX_TIMEOUT
|
||||
}).done(function(data, textStatus, jqXHR) {
|
||||
timeout: constants.AJAX_TIMEOUT
|
||||
}).done(function(data) {
|
||||
file.content = data;
|
||||
objects.shift();
|
||||
task.chain(recursiveDownloadContent);
|
||||
@ -553,7 +557,7 @@ define([
|
||||
};
|
||||
|
||||
googleHelper.loadRealtime = function(fileId, content, callback, errorCallback) {
|
||||
var doc = undefined;
|
||||
var doc;
|
||||
var task = new AsyncTask();
|
||||
connect(task);
|
||||
authenticate(task, 'gdrive');
|
||||
@ -581,7 +585,7 @@ define([
|
||||
};
|
||||
|
||||
function handleError(error, task) {
|
||||
var errorMsg = undefined;
|
||||
var errorMsg;
|
||||
if(error) {
|
||||
logger.error(error);
|
||||
// Try to analyze the error
|
||||
@ -622,10 +626,10 @@ define([
|
||||
$.ajax({
|
||||
url: "//www.google.com/jsapi",
|
||||
data: {
|
||||
key: GOOGLE_API_KEY
|
||||
key: constants.GOOGLE_API_KEY
|
||||
},
|
||||
dataType: "script",
|
||||
timeout: AJAX_TIMEOUT
|
||||
timeout: constants.AJAX_TIMEOUT
|
||||
}).done(function() {
|
||||
google.load('picker', '1', {
|
||||
callback: function() {
|
||||
@ -645,7 +649,7 @@ define([
|
||||
|
||||
googleHelper.picker = function(callback, pickerType) {
|
||||
var docs = [];
|
||||
var picker = undefined;
|
||||
var picker;
|
||||
function hidePicker() {
|
||||
if(picker !== undefined) {
|
||||
picker.setVisible(false);
|
||||
@ -654,27 +658,28 @@ define([
|
||||
}
|
||||
var task = new AsyncTask();
|
||||
// Add some time for user to choose his files
|
||||
task.timeout = ASYNC_TASK_LONG_TIMEOUT;
|
||||
task.timeout = constants.ASYNC_TASK_LONG_TIMEOUT;
|
||||
connect(task);
|
||||
loadPicker(task);
|
||||
task.onRun(function() {
|
||||
var pickerBuilder = new google.picker.PickerBuilder();
|
||||
pickerBuilder.setAppId(GOOGLE_DRIVE_APP_ID);
|
||||
pickerBuilder.setAppId(constants.GOOGLE_DRIVE_APP_ID);
|
||||
var view;
|
||||
if(pickerType == 'doc') {
|
||||
var view = new google.picker.DocsView(google.picker.ViewId.DOCS);
|
||||
view = new google.picker.DocsView(google.picker.ViewId.DOCS);
|
||||
view.setIncludeFolders(true);
|
||||
view.setMimeTypes([
|
||||
"text/x-markdown",
|
||||
"text/plain",
|
||||
"application/octet-stream",
|
||||
"application/vnd.google-apps.drive-sdk." + GOOGLE_DRIVE_APP_ID
|
||||
"application/vnd.google-apps.drive-sdk." + constants.GOOGLE_DRIVE_APP_ID
|
||||
].join(","));
|
||||
pickerBuilder.enableFeature(google.picker.Feature.NAV_HIDDEN);
|
||||
pickerBuilder.enableFeature(google.picker.Feature.MULTISELECT_ENABLED);
|
||||
pickerBuilder.addView(view);
|
||||
}
|
||||
else if(pickerType == 'folder') {
|
||||
var view = new google.picker.DocsView(google.picker.ViewId.FOLDERS);
|
||||
view = new google.picker.DocsView(google.picker.ViewId.FOLDERS);
|
||||
view.setIncludeFolders(true);
|
||||
view.setSelectFolderEnabled(true);
|
||||
view.setMimeTypes('application/vnd.google-apps.folder');
|
||||
@ -746,8 +751,8 @@ define([
|
||||
type: type,
|
||||
contentType: "application/json",
|
||||
dataType: "json",
|
||||
timeout: AJAX_TIMEOUT
|
||||
}).done(function(post, textStatus, jqXHR) {
|
||||
timeout: constants.AJAX_TIMEOUT
|
||||
}).done(function(post) {
|
||||
postId = post.id;
|
||||
task.chain();
|
||||
}).fail(function(jqXHR) {
|
||||
@ -774,8 +779,8 @@ define([
|
||||
},
|
||||
headers: headers,
|
||||
dataType: "json",
|
||||
timeout: AJAX_TIMEOUT
|
||||
}).done(function(blog, textStatus, jqXHR) {
|
||||
timeout: constants.AJAX_TIMEOUT
|
||||
}).done(function(blog) {
|
||||
blogId = blog.id;
|
||||
task.chain(publish);
|
||||
}).fail(function(jqXHR) {
|
||||
|
@ -1,10 +1,12 @@
|
||||
define([
|
||||
"jquery",
|
||||
"constants",
|
||||
"core",
|
||||
"logger",
|
||||
"eventMgr",
|
||||
"settings",
|
||||
"classes/AsyncTask"
|
||||
], function($, core, eventMgr, settings, AsyncTask) {
|
||||
], function($, constants, core, logger, eventMgr, settings, AsyncTask) {
|
||||
|
||||
var sshHelper = {};
|
||||
|
||||
@ -44,8 +46,8 @@ define([
|
||||
data: data,
|
||||
type: "POST",
|
||||
dataType: "json",
|
||||
timeout: AJAX_TIMEOUT
|
||||
}).done(function(response, textStatus, jqXHR) {
|
||||
timeout: constants.AJAX_TIMEOUT
|
||||
}).done(function(response) {
|
||||
if(response.error === undefined) {
|
||||
task.chain();
|
||||
return;
|
||||
@ -69,7 +71,7 @@ define([
|
||||
};
|
||||
|
||||
function handleError(error, task) {
|
||||
var errorMsg = undefined;
|
||||
var errorMsg;
|
||||
if(error) {
|
||||
logger.error(error);
|
||||
// Try to analyze the error
|
||||
|
@ -1,12 +1,15 @@
|
||||
define([
|
||||
"jquery",
|
||||
"constants",
|
||||
"core",
|
||||
"utils",
|
||||
"storage",
|
||||
"logger",
|
||||
"eventMgr",
|
||||
"classes/AsyncTask"
|
||||
], function($, core, utils, eventMgr, AsyncTask) {
|
||||
], function($, constants, core, utils, storage, logger, eventMgr, AsyncTask) {
|
||||
|
||||
var oauthParams = undefined;
|
||||
var oauthParams;
|
||||
|
||||
var tumblrHelper = {};
|
||||
|
||||
@ -29,14 +32,14 @@ define([
|
||||
|
||||
// Try to authenticate with OAuth
|
||||
function authenticate(task) {
|
||||
var authWindow = undefined;
|
||||
var intervalId = undefined;
|
||||
var authWindow;
|
||||
var intervalId;
|
||||
task.onRun(function() {
|
||||
if(oauthParams !== undefined) {
|
||||
task.chain();
|
||||
return;
|
||||
}
|
||||
var serializedOauthParams = localStorage.tumblrOauthParams;
|
||||
var serializedOauthParams = storage.tumblrOauthParams;
|
||||
if(serializedOauthParams !== undefined) {
|
||||
oauthParams = JSON.parse(serializedOauthParams);
|
||||
task.chain();
|
||||
@ -44,10 +47,10 @@ define([
|
||||
}
|
||||
var errorMsg = "Failed to retrieve a token from Tumblr.";
|
||||
// We add time for user to enter his credentials
|
||||
task.timeout = ASYNC_TASK_LONG_TIMEOUT;
|
||||
var oauth_object = undefined;
|
||||
task.timeout = constants.ASYNC_TASK_LONG_TIMEOUT;
|
||||
var oauth_object;
|
||||
function getOauthToken() {
|
||||
$.getJSON(TUMBLR_PROXY_URL + "request_token", function(data) {
|
||||
$.getJSON(constants.TUMBLR_PROXY_URL + "request_token", function(data) {
|
||||
if(data.oauth_token !== undefined) {
|
||||
oauth_object = data;
|
||||
task.chain(oauthRedirect);
|
||||
@ -65,7 +68,7 @@ define([
|
||||
});
|
||||
}
|
||||
function getVerifier() {
|
||||
localStorage.removeItem("tumblrVerifier");
|
||||
storage.removeItem("tumblrVerifier");
|
||||
authWindow = utils.popupWindow('html/tumblr-oauth-client.html?oauth_token=' + oauth_object.oauth_token, 'stackedit-tumblr-oauth', 800, 600);
|
||||
authWindow.focus();
|
||||
intervalId = setInterval(function() {
|
||||
@ -73,20 +76,20 @@ define([
|
||||
clearInterval(intervalId);
|
||||
authWindow = undefined;
|
||||
intervalId = undefined;
|
||||
oauth_object.oauth_verifier = localStorage.tumblrVerifier;
|
||||
oauth_object.oauth_verifier = storage.tumblrVerifier;
|
||||
if(oauth_object.oauth_verifier === undefined) {
|
||||
task.error(new Error(errorMsg));
|
||||
return;
|
||||
}
|
||||
localStorage.removeItem("tumblrVerifier");
|
||||
storage.removeItem("tumblrVerifier");
|
||||
task.chain(getAccessToken);
|
||||
}
|
||||
}, 500);
|
||||
}
|
||||
function getAccessToken() {
|
||||
$.getJSON(TUMBLR_PROXY_URL + "access_token", oauth_object, function(data) {
|
||||
$.getJSON(constants.TUMBLR_PROXY_URL + "access_token", oauth_object, function(data) {
|
||||
if(data.access_token !== undefined && data.access_token_secret !== undefined) {
|
||||
localStorage.tumblrOauthParams = JSON.stringify(data);
|
||||
storage.tumblrOauthParams = JSON.stringify(data);
|
||||
oauthParams = data;
|
||||
task.chain();
|
||||
}
|
||||
@ -121,12 +124,12 @@ define([
|
||||
content: content
|
||||
}, oauthParams);
|
||||
$.ajax({
|
||||
url: TUMBLR_PROXY_URL + "post",
|
||||
url: constants.TUMBLR_PROXY_URL + "post",
|
||||
data: data,
|
||||
type: "POST",
|
||||
dataType: "json",
|
||||
timeout: AJAX_TIMEOUT
|
||||
}).done(function(post, textStatus, jqXHR) {
|
||||
timeout: constants.AJAX_TIMEOUT
|
||||
}).done(function(post) {
|
||||
postId = post.id;
|
||||
task.chain();
|
||||
}).fail(function(jqXHR) {
|
||||
@ -151,7 +154,7 @@ define([
|
||||
};
|
||||
|
||||
function handleError(error, task) {
|
||||
var errorMsg = undefined;
|
||||
var errorMsg;
|
||||
if(error) {
|
||||
logger.error(error);
|
||||
// Try to analyze the error
|
||||
@ -162,7 +165,7 @@ define([
|
||||
errorMsg = "Could not publish on Tumblr.";
|
||||
if(error.code === 401 || error.code === 403) {
|
||||
oauthParams = undefined;
|
||||
localStorage.removeItem("tumblrOauthParams");
|
||||
storage.removeItem("tumblrOauthParams");
|
||||
errorMsg = "Access to Tumblr account is not authorized.";
|
||||
task.retry(new Error(errorMsg), 1);
|
||||
return;
|
||||
|
@ -1,12 +1,15 @@
|
||||
define([
|
||||
"jquery",
|
||||
"constants",
|
||||
"core",
|
||||
"utils",
|
||||
"storage",
|
||||
"logger",
|
||||
"eventMgr",
|
||||
"classes/AsyncTask"
|
||||
], function($, core, utils, eventMgr, AsyncTask) {
|
||||
], function($, constants, core, utils, storage, logger, eventMgr, AsyncTask) {
|
||||
|
||||
var token = undefined;
|
||||
var token;
|
||||
|
||||
var wordpressHelper = {};
|
||||
|
||||
@ -29,18 +32,18 @@ define([
|
||||
|
||||
// Try to authenticate with OAuth
|
||||
function authenticate(task) {
|
||||
var authWindow = undefined;
|
||||
var intervalId = undefined;
|
||||
var authWindow;
|
||||
var intervalId;
|
||||
task.onRun(function() {
|
||||
token = localStorage.wordpressToken;
|
||||
token = storage.wordpressToken;
|
||||
if(token !== undefined) {
|
||||
task.chain();
|
||||
return;
|
||||
}
|
||||
var errorMsg = "Failed to retrieve a token from Wordpress.";
|
||||
// We add time for user to enter his credentials
|
||||
task.timeout = ASYNC_TASK_LONG_TIMEOUT;
|
||||
var code = undefined;
|
||||
task.timeout = constants.ASYNC_TASK_LONG_TIMEOUT;
|
||||
var code;
|
||||
function oauthRedirect() {
|
||||
core.redirectConfirm('You are being redirected to <strong>WordPress</strong> authorization page.', function() {
|
||||
task.chain(getCode);
|
||||
@ -49,29 +52,29 @@ define([
|
||||
});
|
||||
}
|
||||
function getCode() {
|
||||
localStorage.removeItem("wordpressCode");
|
||||
authWindow = utils.popupWindow('html/wordpress-oauth-client.html?client_id=' + WORDPRESS_CLIENT_ID, 'stackedit-wordpress-oauth', 960, 600);
|
||||
storage.removeItem("wordpressCode");
|
||||
authWindow = utils.popupWindow('html/wordpress-oauth-client.html?client_id=' + constants.WORDPRESS_CLIENT_ID, 'stackedit-wordpress-oauth', 960, 600);
|
||||
authWindow.focus();
|
||||
intervalId = setInterval(function() {
|
||||
if(authWindow.closed === true) {
|
||||
clearInterval(intervalId);
|
||||
authWindow = undefined;
|
||||
intervalId = undefined;
|
||||
code = localStorage.wordpressCode;
|
||||
code = storage.wordpressCode;
|
||||
if(code === undefined) {
|
||||
task.error(new Error(errorMsg));
|
||||
return;
|
||||
}
|
||||
localStorage.removeItem("wordpressCode");
|
||||
storage.removeItem("wordpressCode");
|
||||
task.chain(getToken);
|
||||
}
|
||||
}, 500);
|
||||
}
|
||||
function getToken() {
|
||||
$.getJSON(WORDPRESS_PROXY_URL + "authenticate/" + code, function(data) {
|
||||
$.getJSON(constants.WORDPRESS_PROXY_URL + "authenticate/" + code, function(data) {
|
||||
if(data.token !== undefined) {
|
||||
token = data.token;
|
||||
localStorage.wordpressToken = token;
|
||||
storage.wordpressToken = token;
|
||||
task.chain();
|
||||
}
|
||||
else {
|
||||
@ -96,7 +99,7 @@ define([
|
||||
connect(task);
|
||||
authenticate(task);
|
||||
task.onRun(function() {
|
||||
var url = WORDPRESS_PROXY_URL + "post";
|
||||
var url = constants.WORDPRESS_PROXY_URL + "post";
|
||||
var data = {
|
||||
token: token,
|
||||
site: site,
|
||||
@ -110,8 +113,8 @@ define([
|
||||
data: data,
|
||||
type: "POST",
|
||||
dataType: "json",
|
||||
timeout: AJAX_TIMEOUT
|
||||
}).done(function(response, textStatus, jqXHR) {
|
||||
timeout: constants.AJAX_TIMEOUT
|
||||
}).done(function(response) {
|
||||
if(response.body.ID) {
|
||||
postId = response.body.ID;
|
||||
task.chain();
|
||||
@ -149,7 +152,7 @@ define([
|
||||
};
|
||||
|
||||
function handleError(error, task) {
|
||||
var errorMsg = undefined;
|
||||
var errorMsg;
|
||||
if(error) {
|
||||
logger.error(error);
|
||||
// Try to analyze the error
|
||||
@ -159,7 +162,7 @@ define([
|
||||
else {
|
||||
errorMsg = "Could not publish on WordPress.";
|
||||
if((error.code === 400 && error.message == "invalid_token") || error.code === 401 || error.code === 403) {
|
||||
localStorage.removeItem("wordpressToken");
|
||||
storage.removeItem("wordpressToken");
|
||||
errorMsg = "Access to WordPress account is not authorized.";
|
||||
task.retry(new Error(errorMsg), 1);
|
||||
return;
|
||||
|
13
public/res/logger.js
Normal file
13
public/res/logger.js
Normal file
@ -0,0 +1,13 @@
|
||||
define([], function () {
|
||||
|
||||
// Defines the logger object
|
||||
var logger = {
|
||||
log: function () {},
|
||||
info: function () {},
|
||||
warn: function () {},
|
||||
error: function () {}
|
||||
};
|
||||
|
||||
// We can run StackEdit with http://.../?console to print logs in the console
|
||||
return (/(\?|&)console($|&)/).test(location.search) ? console : logger;
|
||||
});
|
@ -1,4 +1,5 @@
|
||||
// RequireJS configuration
|
||||
/*global requirejs */
|
||||
requirejs.config({
|
||||
waitSeconds: 0,
|
||||
packages: [{
|
||||
@ -75,6 +76,12 @@ requirejs.config({
|
||||
deps: ['jquery'],
|
||||
exports: 'toMarkdown'
|
||||
},
|
||||
stacktrace: {
|
||||
exports: 'printStackTrace'
|
||||
},
|
||||
FileSaver: {
|
||||
exports: 'saveAs'
|
||||
},
|
||||
'bootstrap-tour': ['bootstrap'],
|
||||
bootstrap: ['jquery'],
|
||||
'jquery-waitforimages': ['jquery'],
|
||||
@ -107,30 +114,20 @@ catch (e) {
|
||||
throw e;
|
||||
}
|
||||
|
||||
// Defines the logger object
|
||||
var logger = {
|
||||
log: function() {},
|
||||
info: function() {},
|
||||
warn: function() {},
|
||||
error: function() {}
|
||||
};
|
||||
// We can run StackEdit with http://.../?console to print logs in the console
|
||||
if (/(\?|&)console($|&)/.test(location.search)) {
|
||||
logger = console;
|
||||
}
|
||||
|
||||
// Viewer mode is deduced from the body class
|
||||
var viewerMode = /(^| )viewer($| )/.test(document.body.className);
|
||||
window.viewerMode = /(^| )viewer($| )/.test(document.body.className);
|
||||
|
||||
// Light mode is for mobile or viewer
|
||||
var lightMode = viewerMode || /(\?|&)light($|&)/.test(location.search) || (function(a) {
|
||||
if (/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino|android|ipad|playbook|silk/i.test(a) || /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(a.substr(0, 4))) return true;
|
||||
window.lightMode = window.viewerMode || /(\?|&)light($|&)/.test(location.search) || (function(a) {
|
||||
if (/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino|android|ipad|playbook|silk/i.test(a) || /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(a.substr(0, 4))) {
|
||||
return true;
|
||||
}
|
||||
})(navigator.userAgent || navigator.vendor || window.opera);
|
||||
|
||||
// Keep the theme in a global variable
|
||||
var theme = localStorage.theme || 'default';
|
||||
var themeModule = "less!themes/" + theme;
|
||||
if (baseDir.indexOf('-min') !== -1) {
|
||||
if (window.baseDir.indexOf('-min') !== -1) {
|
||||
themeModule = "css!themes/" + theme;
|
||||
}
|
||||
|
||||
@ -139,7 +136,7 @@ if (baseDir.indexOf('-min') !== -1) {
|
||||
require(["jquery", "core", "eventMgr", "synchronizer", "publisher", "mediaImporter", "css",
|
||||
themeModule, ], function($, core, eventMgr) {
|
||||
|
||||
if(typeof(noStart) !== 'undefined' && noStart) {
|
||||
if(window.noStart) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -150,7 +147,7 @@ themeModule, ], function($, core, eventMgr) {
|
||||
|
||||
// If browser has detected a new application cache.
|
||||
if (window.applicationCache) {
|
||||
window.applicationCache.addEventListener('updateready', function(e) {
|
||||
window.applicationCache.addEventListener('updateready', function() {
|
||||
if (window.applicationCache.status === window.applicationCache.UPDATEREADY) {
|
||||
window.applicationCache.swapCache();
|
||||
eventMgr.onMessage('New version available!\nJust refresh the page to upgrade.');
|
||||
|
@ -1,11 +1,12 @@
|
||||
define([
|
||||
"jquery",
|
||||
"underscore",
|
||||
"constants",
|
||||
"classes/Provider",
|
||||
"core",
|
||||
"eventMgr",
|
||||
"providers/gplusProvider"
|
||||
], function($, _, Provider, core, eventMgr) {
|
||||
], function($, _, constants, Provider, core, eventMgr) {
|
||||
|
||||
var mediaImporter = {};
|
||||
|
||||
@ -45,7 +46,7 @@ define([
|
||||
reader.onload = (function(importedFile) {
|
||||
return function(e) {
|
||||
var content = new Uint8Array(e.target.result);
|
||||
providerMap["gplus"].uploadImage(file.name, content, function(error, imageLink) {
|
||||
providerMap.gplus.uploadImage(importedFile.name, content, function(error, imageLink) {
|
||||
if(error) {
|
||||
return;
|
||||
}
|
||||
@ -62,7 +63,7 @@ define([
|
||||
});
|
||||
};
|
||||
})(file);
|
||||
var blob = file.slice(0, IMPORT_IMG_MAX_CONTENT_SIZE);
|
||||
var blob = file.slice(0, constants.IMPORT_IMG_MAX_CONTENT_SIZE);
|
||||
reader.readAsArrayBuffer(blob);
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +1,12 @@
|
||||
define([
|
||||
"jquery",
|
||||
"constants",
|
||||
"eventMgr",
|
||||
"utils",
|
||||
"fileMgr",
|
||||
"classes/Provider",
|
||||
"classes/AsyncTask"
|
||||
], function($, eventMgr, utils, fileMgr, Provider, AsyncTask) {
|
||||
], function($, constants, eventMgr, utils, fileMgr, Provider, AsyncTask) {
|
||||
|
||||
var downloadProvider = new Provider("download");
|
||||
downloadProvider.sharingAttributes = [
|
||||
@ -13,8 +14,8 @@ define([
|
||||
];
|
||||
|
||||
downloadProvider.importPublic = function(importParameters, callback) {
|
||||
var title = undefined;
|
||||
var content = undefined;
|
||||
var title;
|
||||
var content;
|
||||
var task = new AsyncTask(true);
|
||||
task.onRun(function() {
|
||||
var url = importParameters.url;
|
||||
@ -25,14 +26,14 @@ define([
|
||||
}
|
||||
title = url.substring(slashUrl + 1);
|
||||
$.ajax({
|
||||
url: DOWNLOAD_PROXY_URL + "download?url=" + url,
|
||||
url: constants.DOWNLOAD_PROXY_URL + "download?url=" + url,
|
||||
type: "GET",
|
||||
dataType: "text",
|
||||
timeout: AJAX_TIMEOUT
|
||||
}).done(function(result, textStatus, jqXHR) {
|
||||
timeout: constants.AJAX_TIMEOUT
|
||||
}).done(function(result) {
|
||||
content = result;
|
||||
task.chain();
|
||||
}).fail(function(jqXHR) {
|
||||
}).fail(function() {
|
||||
task.error(new Error("Unable to access URL " + url));
|
||||
});
|
||||
});
|
||||
|
@ -1,11 +1,12 @@
|
||||
define([
|
||||
"underscore",
|
||||
"utils",
|
||||
"storage",
|
||||
"classes/Provider",
|
||||
"eventMgr",
|
||||
"fileMgr",
|
||||
"helpers/dropboxHelper"
|
||||
], function(_, utils, Provider, eventMgr, fileMgr, dropboxHelper) {
|
||||
], function(_, utils, storage, Provider, eventMgr, fileMgr, dropboxHelper) {
|
||||
|
||||
var PROVIDER_DROPBOX = "dropbox";
|
||||
|
||||
@ -129,7 +130,7 @@ define([
|
||||
};
|
||||
|
||||
dropboxProvider.syncDown = function(callback) {
|
||||
var lastChangeId = localStorage[PROVIDER_DROPBOX + ".lastChangeId"];
|
||||
var lastChangeId = storage[PROVIDER_DROPBOX + ".lastChangeId"];
|
||||
dropboxHelper.checkChanges(lastChangeId, function(error, changes, newChangeId) {
|
||||
if(error) {
|
||||
callback(error);
|
||||
@ -201,7 +202,7 @@ define([
|
||||
syncAttributes.contentCRC = remoteContentCRC;
|
||||
utils.storeAttributes(syncAttributes);
|
||||
});
|
||||
localStorage[PROVIDER_DROPBOX + ".lastChangeId"] = newChangeId;
|
||||
storage[PROVIDER_DROPBOX + ".lastChangeId"] = newChangeId;
|
||||
callback();
|
||||
});
|
||||
});
|
||||
|
@ -1,12 +1,17 @@
|
||||
/*global gapi */
|
||||
define([
|
||||
"jquery",
|
||||
"underscore",
|
||||
"constants",
|
||||
"utils",
|
||||
"storage",
|
||||
"logger",
|
||||
"classes/Provider",
|
||||
"settings",
|
||||
"eventMgr",
|
||||
"fileMgr",
|
||||
"helpers/googleHelper"
|
||||
], function(_, utils, Provider, settings, eventMgr, fileMgr, googleHelper) {
|
||||
], function($, _, constants, utils, storage, logger, Provider, settings, eventMgr, fileMgr, googleHelper) {
|
||||
|
||||
var PROVIDER_GDRIVE = "gdrive";
|
||||
|
||||
@ -42,7 +47,7 @@ define([
|
||||
return;
|
||||
}
|
||||
var fileDescList = [];
|
||||
var fileDesc = undefined;
|
||||
var fileDesc;
|
||||
_.each(result, function(file) {
|
||||
var syncAttributes = createSyncAttributes(file.id, file.etag, file.content, file.title);
|
||||
syncAttributes.isRealtime = file.isRealtime;
|
||||
@ -150,7 +155,7 @@ define([
|
||||
};
|
||||
|
||||
gdriveProvider.syncDown = function(callback) {
|
||||
var lastChangeId = parseInt(localStorage[PROVIDER_GDRIVE + ".lastChangeId"]);
|
||||
var lastChangeId = parseInt(storage[PROVIDER_GDRIVE + ".lastChangeId"], 10);
|
||||
googleHelper.checkChanges(lastChangeId, function(error, changes, newChangeId) {
|
||||
if(error) {
|
||||
callback(error);
|
||||
@ -238,7 +243,7 @@ define([
|
||||
syncAttributes.titleCRC = remoteTitleCRC;
|
||||
utils.storeAttributes(syncAttributes);
|
||||
});
|
||||
localStorage[PROVIDER_GDRIVE + ".lastChangeId"] = newChangeId;
|
||||
storage[PROVIDER_GDRIVE + ".lastChangeId"] = newChangeId;
|
||||
callback();
|
||||
});
|
||||
});
|
||||
@ -267,22 +272,22 @@ define([
|
||||
};
|
||||
|
||||
// Keep a link to the Pagedown editor
|
||||
var pagedownEditor = undefined;
|
||||
var undoExecute = undefined;
|
||||
var redoExecute = undefined;
|
||||
var setUndoRedoButtonStates = undefined;
|
||||
var pagedownEditor;
|
||||
var undoExecute;
|
||||
var redoExecute;
|
||||
var setUndoRedoButtonStates;
|
||||
eventMgr.addListener("onPagedownConfigure", function(pagedownEditorParam) {
|
||||
pagedownEditor = pagedownEditorParam;
|
||||
});
|
||||
|
||||
// Keep a link to the ACE editor
|
||||
var realtimeContext = undefined;
|
||||
var aceEditor = undefined;
|
||||
var realtimeContext;
|
||||
var aceEditor;
|
||||
var isAceUpToDate = true;
|
||||
eventMgr.addListener('onAceCreated', function(aceEditorParam) {
|
||||
aceEditor = aceEditorParam;
|
||||
// Listen to editor's changes
|
||||
aceEditor.session.on('change', function(e) {
|
||||
aceEditor.session.on('change', function() {
|
||||
// Update the real time model if any
|
||||
realtimeContext && realtimeContext.string && realtimeContext.string.setText(aceEditor.getValue());
|
||||
});
|
||||
@ -492,9 +497,9 @@ define([
|
||||
if(state === undefined) {
|
||||
return;
|
||||
}
|
||||
localStorage.removeItem(PROVIDER_GDRIVE + ".state");
|
||||
storage.removeItem(PROVIDER_GDRIVE + ".state");
|
||||
if(state.action == "create") {
|
||||
googleHelper.upload(undefined, state.folderId, GDRIVE_DEFAULT_FILE_TITLE, settings.defaultContent, undefined, undefined, function(error, file) {
|
||||
googleHelper.upload(undefined, state.folderId, constants.GDRIVE_DEFAULT_FILE_TITLE, settings.defaultContent, undefined, undefined, function(error, file) {
|
||||
if(error) {
|
||||
return;
|
||||
}
|
||||
|
@ -1,17 +1,19 @@
|
||||
define([
|
||||
"jquery",
|
||||
"underscore",
|
||||
"utils",
|
||||
"storage",
|
||||
"classes/Provider",
|
||||
"eventMgr",
|
||||
"helpers/googleHelper"
|
||||
], function(_, utils, Provider, eventMgr, googleHelper) {
|
||||
], function($, _, utils, storage, Provider, eventMgr, googleHelper) {
|
||||
|
||||
var PROVIDER_GPLUS = "gplus";
|
||||
|
||||
var gplusProvider = new Provider(PROVIDER_GPLUS, "Google+");
|
||||
|
||||
function getThumbnailUrl(doc, size) {
|
||||
var result = undefined;
|
||||
var result;
|
||||
_.find(doc.thumbnails, function(thumbnail) {
|
||||
var found = false;
|
||||
thumbnail.url.replace(/(.*\/s)\d.*?(\/[^\/]+)/, function(match, sub1, sub2) {
|
||||
@ -23,12 +25,13 @@ define([
|
||||
return result;
|
||||
}
|
||||
|
||||
var imageDoc = undefined;
|
||||
var imageDoc;
|
||||
var importImagePreferences = utils.retrieveIgnoreError(PROVIDER_GPLUS + ".importImagePreferences");
|
||||
var importImageCallback;
|
||||
function showImportImgDialog() {
|
||||
if(!imageDoc.thumbnails) {
|
||||
eventMgr.onError("Image " + imageDoc.name + " is not accessible.");
|
||||
callback(true);
|
||||
importImageCallback(true);
|
||||
return;
|
||||
}
|
||||
utils.resetModalInputs();
|
||||
@ -43,7 +46,6 @@ define([
|
||||
$(".modal-import-image").modal();
|
||||
}
|
||||
|
||||
var importImageCallback = undefined;
|
||||
gplusProvider.importImage = function(callback) {
|
||||
importImageCallback = callback;
|
||||
googleHelper.picker(function(error, docs) {
|
||||
@ -77,7 +79,7 @@ define([
|
||||
};
|
||||
|
||||
eventMgr.addListener("onReady", function() {
|
||||
$(".action-import-image").click(function(e) {
|
||||
$(".action-import-image").click(function() {
|
||||
var size = utils.getInputIntValue("#input-import-image-size", undefined, 0) || 0;
|
||||
var title = utils.getInputTextValue("#input-import-image-title");
|
||||
var image = getThumbnailUrl(imageDoc, size);
|
||||
@ -91,7 +93,7 @@ define([
|
||||
if(size) {
|
||||
importImagePreferences.size = size;
|
||||
}
|
||||
localStorage[PROVIDER_GPLUS + ".importImagePreferences"] = JSON.stringify(importImagePreferences);
|
||||
storage[PROVIDER_GPLUS + ".importImagePreferences"] = JSON.stringify(importImagePreferences);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -1,7 +1,9 @@
|
||||
define([
|
||||
"jquery",
|
||||
"underscore",
|
||||
"constants",
|
||||
"utils",
|
||||
"storage",
|
||||
"settings",
|
||||
"eventMgr",
|
||||
"fileSystem",
|
||||
@ -18,7 +20,7 @@ define([
|
||||
"providers/sshProvider",
|
||||
"providers/tumblrProvider",
|
||||
"providers/wordpressProvider"
|
||||
], function($, _, utils, settings, eventMgr, fileSystem, fileMgr, sharing, Provider, AsyncTask) {
|
||||
], function($, _, constants, utils, storage, settings, eventMgr, fileSystem, fileMgr, sharing, Provider, AsyncTask) {
|
||||
|
||||
var publisher = {};
|
||||
|
||||
@ -30,11 +32,11 @@ define([
|
||||
];
|
||||
}).compact().object().value();
|
||||
|
||||
// Retrieve publish locations from localStorage
|
||||
// Retrieve publish locations from storage
|
||||
_.each(fileSystem, function(fileDesc) {
|
||||
_.each(utils.retrieveIndexArray(fileDesc.fileIndex + ".publish"), function(publishIndex) {
|
||||
try {
|
||||
var publishAttributes = JSON.parse(localStorage[publishIndex]);
|
||||
var publishAttributes = JSON.parse(storage[publishIndex]);
|
||||
// Store publishIndex
|
||||
publishAttributes.publishIndex = publishIndex;
|
||||
// Replace provider ID by provider module in attributes
|
||||
@ -46,11 +48,11 @@ define([
|
||||
fileDesc.publishLocations[publishIndex] = publishAttributes;
|
||||
}
|
||||
catch(e) {
|
||||
// localStorage can be corrupted
|
||||
// storage can be corrupted
|
||||
eventMgr.onError(e);
|
||||
// Remove publish location
|
||||
utils.removeIndexFromArray(fileDesc.fileIndex + ".publish", publishIndex);
|
||||
localStorage.removeItem(publishIndex);
|
||||
storage.removeItem(publishIndex);
|
||||
}
|
||||
});
|
||||
});
|
||||
@ -95,8 +97,8 @@ define([
|
||||
|
||||
// Recursive function to publish a file on multiple locations
|
||||
var publishAttributesList = [];
|
||||
var publishFileDesc = undefined;
|
||||
var publishHTML = undefined;
|
||||
var publishFileDesc;
|
||||
var publishHTML;
|
||||
function publishLocation(callback, errorFlag) {
|
||||
|
||||
// No more publish location for this document
|
||||
@ -130,7 +132,7 @@ define([
|
||||
}
|
||||
|
||||
// Get the html from the onPreviewFinished callback
|
||||
var previewHtml = undefined;
|
||||
var previewHtml;
|
||||
eventMgr.addListener("onPreviewFinished", function(html) {
|
||||
previewHtml = html;
|
||||
});
|
||||
@ -164,17 +166,17 @@ define([
|
||||
|
||||
// Generate a publishIndex associated to a file and store publishAttributes
|
||||
function createPublishIndex(fileDesc, publishAttributes) {
|
||||
var publishIndex = undefined;
|
||||
var publishIndex;
|
||||
do {
|
||||
publishIndex = "publish." + utils.randomString();
|
||||
} while (_.has(localStorage, publishIndex));
|
||||
} while (_.has(storage, publishIndex));
|
||||
publishAttributes.publishIndex = publishIndex;
|
||||
fileDesc.addPublishLocation(publishAttributes);
|
||||
eventMgr.onNewPublishSuccess(fileDesc, publishAttributes);
|
||||
}
|
||||
|
||||
// Initialize the "New publication" dialog
|
||||
var newLocationProvider = undefined;
|
||||
var newLocationProvider;
|
||||
function initNewLocation(provider) {
|
||||
var defaultPublishFormat = provider.defaultPublishFormat || "markdown";
|
||||
newLocationProvider = provider;
|
||||
@ -246,15 +248,9 @@ define([
|
||||
});
|
||||
publishPreferences.format = publishAttributes.format;
|
||||
publishPreferences.customTmpl = publishAttributes.customTmpl;
|
||||
localStorage[provider.providerId + ".publishPreferences"] = JSON.stringify(publishPreferences);
|
||||
storage[provider.providerId + ".publishPreferences"] = JSON.stringify(publishPreferences);
|
||||
}
|
||||
|
||||
// Listen to offline status changes
|
||||
var isOffline = false;
|
||||
eventMgr.addListener("onOfflineChanged", function(isOfflineParam) {
|
||||
isOffline = isOfflineParam;
|
||||
});
|
||||
|
||||
var initPublishButtonTmpl = [
|
||||
'<li>',
|
||||
' <a href="#"',
|
||||
@ -264,7 +260,7 @@ define([
|
||||
'</li>'
|
||||
].join('');
|
||||
eventMgr.addListener("onReady", function() {
|
||||
if(viewerMode === false) {
|
||||
if(window.viewerMode === false) {
|
||||
// Add every provider in the panel menu
|
||||
var publishMenuElt = document.querySelector('.menu-panel .collapse-publish-on .nav');
|
||||
var publishMenuHtml = _.reduce(providerMap, function(result, provider) {
|
||||
@ -326,7 +322,7 @@ define([
|
||||
customTmpl: settings.pdfTemplate
|
||||
}, previewHtml);
|
||||
var task = new AsyncTask();
|
||||
var pdf = undefined;
|
||||
var pdf;
|
||||
task.onRun(function() {
|
||||
if(isOffline === true) {
|
||||
eventMgr.onError("Operation not available in offline mode.");
|
||||
@ -334,7 +330,7 @@ define([
|
||||
return;
|
||||
}
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open('POST', HTMLTOPDF_URL, true);
|
||||
xhr.open('POST', constants.HTMLTOPDF_URL, true);
|
||||
xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
|
||||
xhr.setRequestHeader('page-size', settings.pdfPageSize);
|
||||
xhr.responseType = 'blob';
|
||||
|
@ -1,8 +1,9 @@
|
||||
define([
|
||||
"underscore",
|
||||
"constants",
|
||||
"storage",
|
||||
"config",
|
||||
"storage"
|
||||
], function(_) {
|
||||
], function (_, constants, storage) {
|
||||
|
||||
var settings = {
|
||||
layoutOrientation: "horizontal",
|
||||
@ -10,8 +11,8 @@ define([
|
||||
editorFontFamily: 'Menlo, Consolas, "Courier New", Courier, monospace',
|
||||
editorFontSize: 12,
|
||||
maxWidth: 960,
|
||||
defaultContent: "\n\n\n> Written with [StackEdit](" + MAIN_URL + ").",
|
||||
commitMsg: "Published with " + MAIN_URL,
|
||||
defaultContent: "\n\n\n> Written with [StackEdit](" + constants.MAIN_URL + ").",
|
||||
commitMsg: "Published with " + constants.MAIN_URL,
|
||||
gdriveFullAccess: true,
|
||||
template: [
|
||||
'<!DOCTYPE html>\n',
|
||||
@ -20,10 +21,10 @@ define([
|
||||
'<meta charset="utf-8">\n',
|
||||
'<title><%= documentTitle %></title>\n',
|
||||
'<link rel="stylesheet" href="',
|
||||
MAIN_URL,
|
||||
constants.MAIN_URL,
|
||||
'res-min/themes/default.css" />\n',
|
||||
'<script type="text/javascript" src="',
|
||||
MAIN_URL,
|
||||
constants.MAIN_URL,
|
||||
'libs/MathJax/MathJax.js?config=TeX-AMS_HTML"></script>\n',
|
||||
'</head>\n',
|
||||
'<body><div class="container"><%= documentHTML %></div></body>\n',
|
||||
@ -36,28 +37,28 @@ define([
|
||||
'<meta charset="utf-8">\n',
|
||||
'<title><%= documentTitle %></title>\n',
|
||||
'<link rel="stylesheet" href="',
|
||||
MAIN_URL,
|
||||
constants.MAIN_URL,
|
||||
'res-min/themes/default.css" />\n',
|
||||
'<script type="text/x-mathjax-config">\n',
|
||||
'MathJax.Hub.Config({ messageStyle: "none" });\n',
|
||||
'</script>\n',
|
||||
'<script type="text/javascript" src="',
|
||||
MAIN_URL,
|
||||
constants.MAIN_URL,
|
||||
'libs/MathJax/MathJax.js?config=TeX-AMS_HTML"></script>\n',
|
||||
'</head>\n',
|
||||
'<body class="pdf"><%= documentHTML %></body>\n',
|
||||
'</html>'
|
||||
].join(""),
|
||||
pdfPageSize: 'A4',
|
||||
sshProxy: SSH_PROXY_URL,
|
||||
sshProxy: constants.SSH_PROXY_URL,
|
||||
shortcuts: {},
|
||||
extensionSettings: {}
|
||||
};
|
||||
|
||||
try {
|
||||
_.extend(settings, JSON.parse(localStorage.settings));
|
||||
_.extend(settings, JSON.parse(storage.settings));
|
||||
}
|
||||
catch(e) {
|
||||
catch (e) {
|
||||
// Ignore parsing error
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
define([
|
||||
"jquery",
|
||||
"underscore",
|
||||
"constants",
|
||||
"utils",
|
||||
"eventMgr",
|
||||
"fileMgr",
|
||||
@ -8,7 +9,7 @@ define([
|
||||
"classes/Provider",
|
||||
"providers/downloadProvider",
|
||||
"providers/gistProvider"
|
||||
], function($, _, utils, eventMgr, fileMgr, AsyncTask, Provider) {
|
||||
], function($, _, constants, utils, eventMgr, fileMgr, AsyncTask, Provider) {
|
||||
|
||||
var sharing = {};
|
||||
|
||||
@ -30,21 +31,21 @@ define([
|
||||
var provider = providerMap[attributes.provider.providerId];
|
||||
// Don't create link if link already exists or provider is not
|
||||
// compatible for sharing
|
||||
if(attributes.sharingLink !== undefined || provider === undefined
|
||||
if(attributes.sharingLink !== undefined || provider === undefined ||
|
||||
// Or document is not published in markdown format
|
||||
|| attributes.format != "markdown") {
|
||||
attributes.format != "markdown") {
|
||||
callback();
|
||||
return;
|
||||
}
|
||||
var task = new AsyncTask();
|
||||
var shortUrl = undefined;
|
||||
var shortUrl;
|
||||
task.onRun(function() {
|
||||
if(isOffline === true) {
|
||||
task.chain();
|
||||
return;
|
||||
}
|
||||
var url = [
|
||||
MAIN_URL,
|
||||
constants.MAIN_URL,
|
||||
'viewer#!provider=',
|
||||
provider.providerId
|
||||
];
|
||||
@ -56,7 +57,7 @@ define([
|
||||
});
|
||||
url = url.join("");
|
||||
$.getJSON("https://api-ssl.bitly.com/v3/shorten", {
|
||||
"access_token": BITLY_ACCESS_TOKEN,
|
||||
"access_token": constants.BITLY_ACCESS_TOKEN,
|
||||
"longUrl": url
|
||||
}, function(response) {
|
||||
if(response.data) {
|
||||
@ -79,7 +80,7 @@ define([
|
||||
};
|
||||
|
||||
eventMgr.addListener("onReady", function() {
|
||||
if(viewerMode === false) {
|
||||
if(window.viewerMode === false) {
|
||||
return;
|
||||
}
|
||||
// Check parameters to see if we have to download a shared document
|
||||
|
@ -4,7 +4,7 @@ define([
|
||||
"settings",
|
||||
"utils",
|
||||
"text!html/settingsShortcutEntry.html",
|
||||
], function(_, eventMgr, settings, utils, settingsShortcutEntryHTML) {
|
||||
], function(_, eventMgr, settings, utils, settingsShortcutEntryHTML) {
|
||||
|
||||
var shortcutMgr = {};
|
||||
|
||||
|
@ -1,13 +1,23 @@
|
||||
// Setup an empty localStorage or upgrade an existing one
|
||||
define([
|
||||
"underscore",
|
||||
"utils"
|
||||
], function(_, utils) {
|
||||
"underscore"
|
||||
], function(_) {
|
||||
|
||||
var fileIndexList = utils.retrieveIndexArray("file.list");
|
||||
function retrieveIndexArray(storeIndex) {
|
||||
try {
|
||||
return _.compact(localStorage[storeIndex].split(";"));
|
||||
}
|
||||
catch(e) {
|
||||
localStorage[storeIndex] = ";";
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
var fileIndexList = retrieveIndexArray("file.list");
|
||||
var currentFileIndex, settings;
|
||||
|
||||
// localStorage versioning
|
||||
var version = localStorage["version"];
|
||||
var version = localStorage.version;
|
||||
|
||||
// Upgrade from v0 to v1
|
||||
if(version === undefined) {
|
||||
@ -19,7 +29,7 @@ define([
|
||||
|
||||
_.each(fileIndexList, function(fileIndex) {
|
||||
localStorage[fileIndex + ".publish"] = ";";
|
||||
var syncIndexList = utils.retrieveIndexArray(fileIndex + ".sync");
|
||||
var syncIndexList = retrieveIndexArray(fileIndex + ".sync");
|
||||
_.each(syncIndexList, function(syncIndex) {
|
||||
localStorage[syncIndex + ".contentCRC"] = "0";
|
||||
// We store title CRC only for Google Drive synchronization
|
||||
@ -49,7 +59,7 @@ define([
|
||||
var SYNC_PROVIDER_GDRIVE = "sync." + PROVIDER_GDRIVE + ".";
|
||||
var SYNC_PROVIDER_DROPBOX = "sync." + PROVIDER_DROPBOX + ".";
|
||||
_.each(fileIndexList, function(fileIndex) {
|
||||
var syncIndexList = utils.retrieveIndexArray(fileIndex + ".sync");
|
||||
var syncIndexList = retrieveIndexArray(fileIndex + ".sync");
|
||||
_.each(syncIndexList, function(syncIndex) {
|
||||
var syncAttributes = {};
|
||||
if(syncIndex.indexOf(SYNC_PROVIDER_GDRIVE) === 0) {
|
||||
@ -82,7 +92,7 @@ define([
|
||||
localStorage.removeItem(fileIndex + ".title");
|
||||
localStorage.removeItem(fileIndex + ".publish");
|
||||
localStorage.removeItem(fileIndex + ".content");
|
||||
utils.removeIndexFromArray("file.list", fileIndex);
|
||||
localStorage["file.list"].replace(";" + fileIndex + ";", ";");
|
||||
}
|
||||
});
|
||||
version = "v3";
|
||||
@ -90,7 +100,7 @@ define([
|
||||
|
||||
// Upgrade from v3 to v4
|
||||
if(version == "v3") {
|
||||
var currentFileIndex = localStorage["file.current"];
|
||||
currentFileIndex = localStorage["file.current"];
|
||||
if(currentFileIndex !== undefined && localStorage["file.list"].indexOf(";" + currentFileIndex + ";") === -1) {
|
||||
localStorage.removeItem("file.current");
|
||||
}
|
||||
@ -107,7 +117,7 @@ define([
|
||||
// Upgrade from v5 to v6
|
||||
if(version == "v5") {
|
||||
_.each(fileIndexList, function(fileIndex) {
|
||||
var publishIndexList = utils.retrieveIndexArray(fileIndex + ".publish");
|
||||
var publishIndexList = retrieveIndexArray(fileIndex + ".publish");
|
||||
_.each(publishIndexList, function(publishIndex) {
|
||||
var publishAttributes = JSON.parse(localStorage[publishIndex]);
|
||||
if(publishAttributes.provider == "gdrive") {
|
||||
@ -123,7 +133,7 @@ define([
|
||||
|
||||
// Upgrade from v6 to v7
|
||||
if(version == "v6") {
|
||||
var currentFileIndex = localStorage["file.current"];
|
||||
currentFileIndex = localStorage["file.current"];
|
||||
if(currentFileIndex !== undefined) {
|
||||
localStorage[currentFileIndex + ".selectTime"] = new Date().getTime();
|
||||
localStorage.removeItem("file.current");
|
||||
@ -158,7 +168,7 @@ define([
|
||||
// Upgrade from v9 to v10
|
||||
if(version == "v9") {
|
||||
if(_.has(localStorage, 'settings')) {
|
||||
var settings = JSON.parse(localStorage.settings);
|
||||
settings = JSON.parse(localStorage.settings);
|
||||
delete settings.editorFontFamily;
|
||||
delete settings.editorFontSize;
|
||||
settings.template && (settings.template = settings.template.replace('http://benweet.github.io/stackedit/css/main-min.css', 'http://benweet.github.io/stackedit/res-min/themes/default.css'));
|
||||
@ -170,7 +180,7 @@ define([
|
||||
// Upgrade from v10 to v11
|
||||
if(version == "v10") {
|
||||
if(_.has(localStorage, 'settings')) {
|
||||
var settings = JSON.parse(localStorage.settings);
|
||||
settings = JSON.parse(localStorage.settings);
|
||||
((settings.extensionSettings || {}).markdownExtra || {}).extensions && settings.extensionSettings.markdownExtra.extensions.push('smartypants');
|
||||
settings.sshProxy == 'http://stackedit-ssh-proxy.herokuapp.com/' && (settings.sshProxy = 'https://stackedit-ssh-proxy.herokuapp.com/');
|
||||
settings.template && (settings.template = settings.template.replace('http://benweet.github.io/stackedit/lib/', 'https://stackedit.io/libs/'));
|
||||
@ -184,5 +194,6 @@ define([
|
||||
version = "v11";
|
||||
}
|
||||
|
||||
localStorage["version"] = version;
|
||||
localStorage.version = version;
|
||||
return localStorage;
|
||||
});
|
@ -2,13 +2,14 @@ define([
|
||||
"jquery",
|
||||
"underscore",
|
||||
"utils",
|
||||
"storage",
|
||||
"eventMgr",
|
||||
"fileSystem",
|
||||
"fileMgr",
|
||||
"classes/Provider",
|
||||
"providers/dropboxProvider",
|
||||
"providers/gdriveProvider"
|
||||
], function($, _, utils, eventMgr, fileSystem, fileMgr, Provider) {
|
||||
], function($, _, utils, storage, eventMgr, fileSystem, fileMgr, Provider) {
|
||||
|
||||
var synchronizer = {};
|
||||
|
||||
@ -20,11 +21,11 @@ define([
|
||||
];
|
||||
}).compact().object().value();
|
||||
|
||||
// Retrieve sync locations from localStorage
|
||||
// Retrieve sync locations from storage
|
||||
_.each(fileSystem, function(fileDesc) {
|
||||
_.each(utils.retrieveIndexArray(fileDesc.fileIndex + ".sync"), function(syncIndex) {
|
||||
try {
|
||||
var syncAttributes = JSON.parse(localStorage[syncIndex]);
|
||||
var syncAttributes = JSON.parse(storage[syncIndex]);
|
||||
// Store syncIndex
|
||||
syncAttributes.syncIndex = syncIndex;
|
||||
// Replace provider ID by provider module in attributes
|
||||
@ -36,11 +37,11 @@ define([
|
||||
fileDesc.syncLocations[syncIndex] = syncAttributes;
|
||||
}
|
||||
catch(e) {
|
||||
// localStorage can be corrupted
|
||||
// storage can be corrupted
|
||||
eventMgr.onError(e);
|
||||
// Remove sync location
|
||||
utils.removeIndexFromArray(fileDesc.fileIndex + ".sync", syncIndex);
|
||||
localStorage.removeItem(syncIndex);
|
||||
storage.removeItem(syncIndex);
|
||||
}
|
||||
});
|
||||
});
|
||||
@ -60,10 +61,10 @@ define([
|
||||
|
||||
// Recursive function to upload a single file on multiple locations
|
||||
var uploadSyncAttributesList = [];
|
||||
var uploadContent = undefined;
|
||||
var uploadContentCRC = undefined;
|
||||
var uploadTitle = undefined;
|
||||
var uploadTitleCRC = undefined;
|
||||
var uploadContent;
|
||||
var uploadContentCRC;
|
||||
var uploadTitle;
|
||||
var uploadTitleCRC;
|
||||
function locationUp(callback) {
|
||||
|
||||
// No more synchronized location for this document
|
||||
@ -92,7 +93,7 @@ define([
|
||||
return;
|
||||
}
|
||||
if(uploadFlag) {
|
||||
// Update syncAttributes in localStorage
|
||||
// Update syncAttributes in storage
|
||||
utils.storeAttributes(syncAttributes);
|
||||
}
|
||||
locationUp(callback);
|
||||
@ -216,8 +217,8 @@ define([
|
||||
* Realtime synchronization
|
||||
**************************************************************************/
|
||||
|
||||
var realtimeFileDesc = undefined;
|
||||
var realtimeSyncAttributes = undefined;
|
||||
var realtimeFileDesc;
|
||||
var realtimeSyncAttributes;
|
||||
var isOnline = true;
|
||||
|
||||
// Determines if open file has real time sync location and tries to start
|
||||
@ -259,7 +260,7 @@ define([
|
||||
};
|
||||
|
||||
// Triggers realtime synchronization from eventMgr events
|
||||
if(viewerMode === false) {
|
||||
if(window.viewerMode === false) {
|
||||
eventMgr.addListener("onFileOpen", onFileOpen);
|
||||
eventMgr.addListener("onFileClosed", synchronizer.tryStopRealtimeSync);
|
||||
eventMgr.addListener("onOfflineChanged", onOfflineChanged);
|
||||
@ -355,7 +356,7 @@ define([
|
||||
exportPreferences[inputId] = inputElt.value;
|
||||
}
|
||||
});
|
||||
localStorage[provider.providerId + ".exportPreferences"] = JSON.stringify(exportPreferences);
|
||||
storage[provider.providerId + ".exportPreferences"] = JSON.stringify(exportPreferences);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -1,11 +1,12 @@
|
||||
define([
|
||||
"jquery",
|
||||
"underscore",
|
||||
"storage",
|
||||
"crel",
|
||||
"xregexp",
|
||||
"FileSaver",
|
||||
"stacktrace",
|
||||
], function($, _, crel, XRegExp) {
|
||||
"FileSaver",
|
||||
], function($, _, storage, crel, XRegExp, printStackTrace, saveAs) {
|
||||
|
||||
var utils = {};
|
||||
|
||||
@ -106,7 +107,9 @@ define([
|
||||
return undefined;
|
||||
}
|
||||
try {
|
||||
/*jshint evil:true */
|
||||
eval("var test=" + value);
|
||||
/*jshint evil:false */
|
||||
}
|
||||
catch(e) {
|
||||
inputError(element, event);
|
||||
@ -241,41 +244,41 @@ define([
|
||||
};
|
||||
utils.updateCurrentTime();
|
||||
|
||||
// Serialize sync/publish attributes and store it in the localStorage
|
||||
// Serialize sync/publish attributes and store it in the storage
|
||||
utils.storeAttributes = function(attributes) {
|
||||
var storeIndex = attributes.syncIndex || attributes.publishIndex;
|
||||
// Don't store sync/publish index
|
||||
var storedAttributes = _.omit(attributes, "syncIndex", "publishIndex", "provider");
|
||||
// Store providerId instead of provider
|
||||
storedAttributes.provider = attributes.provider.providerId;
|
||||
localStorage[storeIndex] = JSON.stringify(storedAttributes);
|
||||
storage[storeIndex] = JSON.stringify(storedAttributes);
|
||||
};
|
||||
|
||||
// Retrieve/parse an index array from localStorage
|
||||
// Retrieve/parse an index array from storage
|
||||
utils.retrieveIndexArray = function(storeIndex) {
|
||||
try {
|
||||
return _.compact(localStorage[storeIndex].split(";"));
|
||||
return _.compact(storage[storeIndex].split(";"));
|
||||
}
|
||||
catch(e) {
|
||||
localStorage[storeIndex] = ";";
|
||||
storage[storeIndex] = ";";
|
||||
return [];
|
||||
}
|
||||
};
|
||||
|
||||
// Append an index to an array in localStorage
|
||||
// Append an index to an array in storage
|
||||
utils.appendIndexToArray = function(storeIndex, index) {
|
||||
localStorage[storeIndex] += index + ";";
|
||||
storage[storeIndex] += index + ";";
|
||||
};
|
||||
|
||||
// Remove an index from an array in localStorage
|
||||
// Remove an index from an array in storage
|
||||
utils.removeIndexFromArray = function(storeIndex, index) {
|
||||
localStorage[storeIndex] = localStorage[storeIndex].replace(";" + index + ";", ";");
|
||||
storage[storeIndex] = storage[storeIndex].replace(";" + index + ";", ";");
|
||||
};
|
||||
|
||||
// Retrieve/parse an object from localStorage. Returns undefined if error.
|
||||
// Retrieve/parse an object from storage. Returns undefined if error.
|
||||
utils.retrieveIgnoreError = function(storeIndex) {
|
||||
try {
|
||||
return JSON.parse(localStorage[storeIndex]);
|
||||
return JSON.parse(storage[storeIndex]);
|
||||
}
|
||||
catch(e) {
|
||||
return undefined;
|
||||
|
@ -1,4 +1,7 @@
|
||||
var isConfigured = false
|
||||
/*jshint worker:true */
|
||||
var isConfigured = false;
|
||||
|
||||
/*jshint evil:true, unused:false */
|
||||
self.onmessage = function(e) {
|
||||
if(isConfigured === false) {
|
||||
eval(e.data);
|
||||
@ -10,3 +13,4 @@ self.onmessage = function(e) {
|
||||
self[functionName].apply(this, data);
|
||||
}
|
||||
};
|
||||
/*jshint evil:false, unused:true */
|
||||
|
@ -1,5 +1,7 @@
|
||||
var dictionary = undefined;
|
||||
/*jshint worker:true */
|
||||
var dictionary;
|
||||
|
||||
/*jshint evil:true, unused:false */
|
||||
self.init = function(typoJS, LZString, lang, aff, dic) {
|
||||
eval([
|
||||
typoJS,
|
||||
@ -9,8 +11,9 @@ self.init = function(typoJS, LZString, lang, aff, dic) {
|
||||
'dictionary = new Typo(lang, aff, dic);'
|
||||
].join('\n'));
|
||||
};
|
||||
/*jshint evil:false, unused:true */
|
||||
|
||||
var timeoutId = undefined;
|
||||
var timeoutId;
|
||||
self.check = function(words) {
|
||||
// Check function has priority over Suggest function
|
||||
// This prevents Suggest to run if called just before Check
|
||||
@ -22,7 +25,7 @@ self.check = function(words) {
|
||||
postMessage(JSON.stringify(['check', words]));
|
||||
};
|
||||
|
||||
var word = undefined;
|
||||
var word;
|
||||
|
||||
function delayedSuggest() {
|
||||
timeoutId = undefined;
|
||||
|
@ -13,12 +13,12 @@
|
||||
/>
|
||||
<script>
|
||||
// Use ?debug to serve original JavaScript files instead of minified
|
||||
var baseDir = 'res';
|
||||
window.baseDir = 'res';
|
||||
if (!/(\?|&)debug($|&)/.test(location.search)) {
|
||||
baseDir += '-min';
|
||||
window.baseDir += '-min';
|
||||
}
|
||||
var require = {
|
||||
baseUrl: baseDir,
|
||||
window.require = {
|
||||
baseUrl: window.baseDir,
|
||||
deps: ['main']
|
||||
};
|
||||
</script>
|
||||
|
Loading…
Reference in New Issue
Block a user