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) {
|
module.exports = function(grunt) {
|
||||||
|
|
||||||
|
grunt.loadNpmTasks('grunt-contrib-jshint');
|
||||||
grunt.loadNpmTasks('grunt-contrib-requirejs');
|
grunt.loadNpmTasks('grunt-contrib-requirejs');
|
||||||
grunt.loadNpmTasks('grunt-contrib-less');
|
grunt.loadNpmTasks('grunt-contrib-less');
|
||||||
grunt.loadNpmTasks('grunt-string-replace');
|
grunt.loadNpmTasks('grunt-string-replace');
|
||||||
@ -12,6 +13,30 @@ module.exports = function(grunt) {
|
|||||||
*/
|
*/
|
||||||
grunt.initConfig({
|
grunt.initConfig({
|
||||||
pkg: grunt.file.readJSON('package.json'),
|
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: {
|
requirejs: {
|
||||||
compile: {
|
compile: {
|
||||||
options: {
|
options: {
|
||||||
@ -100,8 +125,8 @@ module.exports = function(grunt) {
|
|||||||
options: {
|
options: {
|
||||||
replacements: [
|
replacements: [
|
||||||
{
|
{
|
||||||
pattern: /(var VERSION = ).*/,
|
pattern: /(constants\.VERSION = ).*/,
|
||||||
replacement: 'var VERSION = "<%= pkg.version %>";'
|
replacement: 'constants.VERSION = "<%= pkg.version %>";'
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,8 @@
|
|||||||
"bower": "~1.2.5",
|
"bower": "~1.2.5",
|
||||||
"grunt-bower-requirejs": "~0.7.1",
|
"grunt-bower-requirejs": "~0.7.1",
|
||||||
"grunt-bower-task": "~0.3.1",
|
"grunt-bower-task": "~0.3.1",
|
||||||
"grunt-bump": "0.0.11"
|
"grunt-bump": "0.0.11",
|
||||||
|
"grunt-contrib-jshint": "~0.7.1"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "echo \"Error: no test specified\" && exit 1"
|
"test": "echo \"Error: no test specified\" && exit 1"
|
||||||
|
@ -13,12 +13,12 @@
|
|||||||
/>
|
/>
|
||||||
<script>
|
<script>
|
||||||
// Use ?debug to serve original JavaScript files instead of minified
|
// Use ?debug to serve original JavaScript files instead of minified
|
||||||
var baseDir = 'res';
|
window.baseDir = 'res';
|
||||||
if (!/(\?|&)debug($|&)/.test(location.search)) {
|
if (!/(\?|&)debug($|&)/.test(location.search)) {
|
||||||
baseDir += '-min';
|
window.baseDir += '-min';
|
||||||
}
|
}
|
||||||
var require = {
|
window.require = {
|
||||||
baseUrl: baseDir,
|
baseUrl: window.baseDir,
|
||||||
deps: ['main']
|
deps: ['main']
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
@ -10,10 +10,10 @@
|
|||||||
<link rel="stylesheet" type="text/css" href="res-min/themes/default.css">
|
<link rel="stylesheet" type="text/css" href="res-min/themes/default.css">
|
||||||
<script>
|
<script>
|
||||||
// Use http://.../?debug to serve original JavaScript files instead of minified
|
// Use http://.../?debug to serve original JavaScript files instead of minified
|
||||||
var baseDir = 'res-min';
|
window.baseDir = 'res-min';
|
||||||
var noStart = true;
|
window.noStart = true;
|
||||||
var require = {
|
window.require = {
|
||||||
baseUrl: baseDir,
|
baseUrl: window.baseDir,
|
||||||
deps: ['main']
|
deps: ['main']
|
||||||
};
|
};
|
||||||
setTimeout(function() {
|
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([
|
define([
|
||||||
"underscore",
|
"underscore",
|
||||||
|
"constants",
|
||||||
"utils",
|
"utils",
|
||||||
"eventMgr",
|
"eventMgr",
|
||||||
"config"
|
"config"
|
||||||
], function(_, utils, eventMgr) {
|
], function(_, constants, utils, eventMgr) {
|
||||||
|
|
||||||
var taskQueue = [];
|
var taskQueue = [];
|
||||||
|
|
||||||
function AsyncTask(force) {
|
function AsyncTask(force) {
|
||||||
this.finished = false;
|
this.finished = false;
|
||||||
this.timeout = ASYNC_TASK_DEFAULT_TIMEOUT;
|
this.timeout = constants.ASYNC_TASK_DEFAULT_TIMEOUT;
|
||||||
this.retryCounter = 0;
|
this.retryCounter = 0;
|
||||||
this.runCallbacks = [];
|
this.runCallbacks = [];
|
||||||
this.successCallbacks = [];
|
this.successCallbacks = [];
|
||||||
@ -123,7 +124,7 @@ define([
|
|||||||
};
|
};
|
||||||
|
|
||||||
var asyncRunning = false;
|
var asyncRunning = false;
|
||||||
var currentTask = undefined;
|
var currentTask;
|
||||||
|
|
||||||
// Determine if user is real by listening to his activity
|
// Determine if user is real by listening to his activity
|
||||||
var isUserReal = false;
|
var isUserReal = false;
|
||||||
|
@ -1,17 +1,18 @@
|
|||||||
define([
|
define([
|
||||||
"underscore",
|
"underscore",
|
||||||
"utils",
|
"utils",
|
||||||
|
"storage",
|
||||||
"ace/range"
|
"ace/range"
|
||||||
], function(_, utils, range) {
|
], function(_, utils, storage, range) {
|
||||||
var Range = range.Range;
|
var Range = range.Range;
|
||||||
|
|
||||||
function FileDescriptor(fileIndex, title, syncLocations, publishLocations) {
|
function FileDescriptor(fileIndex, title, syncLocations, publishLocations) {
|
||||||
this.fileIndex = fileIndex;
|
this.fileIndex = fileIndex;
|
||||||
this._title = title || localStorage[fileIndex + ".title"];
|
this._title = title || storage[fileIndex + ".title"];
|
||||||
this._editorScrollTop = parseInt(localStorage[fileIndex + ".editorScrollTop"]) || 0;
|
this._editorScrollTop = parseInt(storage[fileIndex + ".editorScrollTop"]) || 0;
|
||||||
this._editorSelectRange = (function() {
|
this._editorSelectRange = (function() {
|
||||||
try {
|
try {
|
||||||
var rangeComponents = localStorage[fileIndex + ".editorSelectRange"].split(';');
|
var rangeComponents = storage[fileIndex + ".editorSelectRange"].split(';');
|
||||||
rangeComponents = _.map(rangeComponents, function(component) {
|
rangeComponents = _.map(rangeComponents, function(component) {
|
||||||
return parseInt(component);
|
return parseInt(component);
|
||||||
});
|
});
|
||||||
@ -21,9 +22,9 @@ define([
|
|||||||
return new Range(0, 0, 0, 0);
|
return new Range(0, 0, 0, 0);
|
||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
this._editorEnd = parseInt(localStorage[fileIndex + ".editorEnd"]) || 0;
|
this._editorEnd = parseInt(storage[fileIndex + ".editorEnd"]) || 0;
|
||||||
this._previewScrollTop = parseInt(localStorage[fileIndex + ".previewScrollTop"]) || 0;
|
this._previewScrollTop = parseInt(storage[fileIndex + ".previewScrollTop"]) || 0;
|
||||||
this._selectTime = parseInt(localStorage[fileIndex + ".selectTime"]) || 0;
|
this._selectTime = parseInt(storage[fileIndex + ".selectTime"]) || 0;
|
||||||
this.syncLocations = syncLocations || {};
|
this.syncLocations = syncLocations || {};
|
||||||
this.publishLocations = publishLocations || {};
|
this.publishLocations = publishLocations || {};
|
||||||
Object.defineProperty(this, 'title', {
|
Object.defineProperty(this, 'title', {
|
||||||
@ -32,15 +33,15 @@ define([
|
|||||||
},
|
},
|
||||||
set: function(title) {
|
set: function(title) {
|
||||||
this._title = title;
|
this._title = title;
|
||||||
localStorage[this.fileIndex + ".title"] = title;
|
storage[this.fileIndex + ".title"] = title;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
Object.defineProperty(this, 'content', {
|
Object.defineProperty(this, 'content', {
|
||||||
get: function() {
|
get: function() {
|
||||||
return localStorage[this.fileIndex + ".content"];
|
return storage[this.fileIndex + ".content"];
|
||||||
},
|
},
|
||||||
set: function(content) {
|
set: function(content) {
|
||||||
localStorage[this.fileIndex + ".content"] = content;
|
storage[this.fileIndex + ".content"] = content;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
Object.defineProperty(this, 'editorScrollTop', {
|
Object.defineProperty(this, 'editorScrollTop', {
|
||||||
@ -49,7 +50,7 @@ define([
|
|||||||
},
|
},
|
||||||
set: function(editorScrollTop) {
|
set: function(editorScrollTop) {
|
||||||
this._editorScrollTop = editorScrollTop;
|
this._editorScrollTop = editorScrollTop;
|
||||||
localStorage[this.fileIndex + ".editorScrollTop"] = editorScrollTop;
|
storage[this.fileIndex + ".editorScrollTop"] = editorScrollTop;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
Object.defineProperty(this, 'editorSelectRange', {
|
Object.defineProperty(this, 'editorSelectRange', {
|
||||||
@ -58,7 +59,7 @@ define([
|
|||||||
},
|
},
|
||||||
set: function(range) {
|
set: function(range) {
|
||||||
this._editorSelectRange = range;
|
this._editorSelectRange = range;
|
||||||
localStorage[this.fileIndex + ".editorSelectRange"] = [
|
storage[this.fileIndex + ".editorSelectRange"] = [
|
||||||
range.start.row,
|
range.start.row,
|
||||||
range.start.column,
|
range.start.column,
|
||||||
range.end.row,
|
range.end.row,
|
||||||
@ -72,7 +73,7 @@ define([
|
|||||||
},
|
},
|
||||||
set: function(previewScrollTop) {
|
set: function(previewScrollTop) {
|
||||||
this._previewScrollTop = previewScrollTop;
|
this._previewScrollTop = previewScrollTop;
|
||||||
localStorage[this.fileIndex + ".previewScrollTop"] = previewScrollTop;
|
storage[this.fileIndex + ".previewScrollTop"] = previewScrollTop;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
Object.defineProperty(this, 'selectTime', {
|
Object.defineProperty(this, 'selectTime', {
|
||||||
@ -81,7 +82,7 @@ define([
|
|||||||
},
|
},
|
||||||
set: function(selectTime) {
|
set: function(selectTime) {
|
||||||
this._selectTime = selectTime;
|
this._selectTime = selectTime;
|
||||||
localStorage[this.fileIndex + ".selectTime"] = selectTime;
|
storage[this.fileIndex + ".selectTime"] = selectTime;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -95,7 +96,7 @@ define([
|
|||||||
FileDescriptor.prototype.removeSyncLocation = function(syncAttributes) {
|
FileDescriptor.prototype.removeSyncLocation = function(syncAttributes) {
|
||||||
utils.removeIndexFromArray(this.fileIndex + ".sync", syncAttributes.syncIndex);
|
utils.removeIndexFromArray(this.fileIndex + ".sync", syncAttributes.syncIndex);
|
||||||
delete this.syncLocations[syncAttributes.syncIndex];
|
delete this.syncLocations[syncAttributes.syncIndex];
|
||||||
localStorage.removeItem(syncAttributes.syncIndex);
|
storage.removeItem(syncAttributes.syncIndex);
|
||||||
};
|
};
|
||||||
|
|
||||||
FileDescriptor.prototype.addPublishLocation = function(publishAttributes) {
|
FileDescriptor.prototype.addPublishLocation = function(publishAttributes) {
|
||||||
@ -107,7 +108,7 @@ define([
|
|||||||
FileDescriptor.prototype.removePublishLocation = function(publishAttributes) {
|
FileDescriptor.prototype.removePublishLocation = function(publishAttributes) {
|
||||||
utils.removeIndexFromArray(this.fileIndex + ".publish", publishAttributes.publishIndex);
|
utils.removeIndexFromArray(this.fileIndex + ".publish", publishAttributes.publishIndex);
|
||||||
delete this.publishLocations[publishAttributes.publishIndex];
|
delete this.publishLocations[publishAttributes.publishIndex];
|
||||||
localStorage.removeItem(publishAttributes.publishIndex);
|
storage.removeItem(publishAttributes.publishIndex);
|
||||||
};
|
};
|
||||||
|
|
||||||
FileDescriptor.prototype.composeTitle = function() {
|
FileDescriptor.prototype.composeTitle = function() {
|
||||||
|
@ -1,13 +1,14 @@
|
|||||||
define([
|
define([
|
||||||
"underscore",
|
"underscore",
|
||||||
"utils",
|
"utils",
|
||||||
|
"storage",
|
||||||
"fileSystem"
|
"fileSystem"
|
||||||
], function(_, utils, fileSystem) {
|
], function(_, utils, storage, fileSystem) {
|
||||||
|
|
||||||
function FolderDescriptor(folderIndex, name, fileList) {
|
function FolderDescriptor(folderIndex, name, fileList) {
|
||||||
this.folderIndex = folderIndex;
|
this.folderIndex = folderIndex;
|
||||||
this._name = name || localStorage[folderIndex + ".name"];
|
this._name = name || storage[folderIndex + ".name"];
|
||||||
// Retrieve file list from localStorage
|
// Retrieve file list from storage
|
||||||
this.fileList = {};
|
this.fileList = {};
|
||||||
_.each(utils.retrieveIndexArray(folderIndex + ".files"), function(fileIndex) {
|
_.each(utils.retrieveIndexArray(folderIndex + ".files"), function(fileIndex) {
|
||||||
try {
|
try {
|
||||||
@ -16,7 +17,7 @@ define([
|
|||||||
this.fileList[fileIndex] = fileDesc;
|
this.fileList[fileIndex] = fileDesc;
|
||||||
}
|
}
|
||||||
catch(e) {
|
catch(e) {
|
||||||
// localStorage can be corrupted
|
// storage can be corrupted
|
||||||
// Remove file from folder
|
// Remove file from folder
|
||||||
utils.removeIndexFromArray(folderIndex + ".files", fileIndex);
|
utils.removeIndexFromArray(folderIndex + ".files", fileIndex);
|
||||||
}
|
}
|
||||||
@ -27,7 +28,7 @@ define([
|
|||||||
},
|
},
|
||||||
set: function(name) {
|
set: function(name) {
|
||||||
this._name = 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/";
|
constants.MAIN_URL = "https://stackedit.io/";
|
||||||
var GOOGLE_ANALYTICS_ACCOUNT_ID = "UA-39556145-1";
|
constants.GOOGLE_ANALYTICS_ACCOUNT_ID = "UA-39556145-1";
|
||||||
var GOOGLE_API_KEY = "AIzaSyAeCU8CGcSkn0z9js6iocHuPBX4f_mMWkw";
|
constants.GOOGLE_API_KEY = "AIzaSyAeCU8CGcSkn0z9js6iocHuPBX4f_mMWkw";
|
||||||
var GOOGLE_DRIVE_APP_ID = "241271498917";
|
constants.GOOGLE_DRIVE_APP_ID = "241271498917";
|
||||||
var DROPBOX_APP_KEY = "lq6mwopab8wskas";
|
constants.DROPBOX_APP_KEY = "lq6mwopab8wskas";
|
||||||
var DROPBOX_APP_SECRET = "851fgnucpezy84t";
|
constants.DROPBOX_APP_SECRET = "851fgnucpezy84t";
|
||||||
var BITLY_ACCESS_TOKEN = "317e033bfd48cf31155a68a536b1860013b09c4c";
|
constants.BITLY_ACCESS_TOKEN = "317e033bfd48cf31155a68a536b1860013b09c4c";
|
||||||
var DEFAULT_FILE_TITLE = "Title";
|
constants.DEFAULT_FILE_TITLE = "Title";
|
||||||
var DEFAULT_FOLDER_NAME = "New folder";
|
constants.DEFAULT_FOLDER_NAME = "New folder";
|
||||||
var GDRIVE_DEFAULT_FILE_TITLE = "New Markdown document";
|
constants.GDRIVE_DEFAULT_FILE_TITLE = "New Markdown document";
|
||||||
var EDITOR_DEFAULT_PADDING = 15;
|
constants.EDITOR_DEFAULT_PADDING = 15;
|
||||||
var CHECK_ONLINE_PERIOD = 120000;
|
constants.CHECK_ONLINE_PERIOD = 120000;
|
||||||
var AJAX_TIMEOUT = 30000;
|
constants.AJAX_TIMEOUT = 30000;
|
||||||
var ASYNC_TASK_DEFAULT_TIMEOUT = 60000;
|
constants.ASYNC_TASK_DEFAULT_TIMEOUT = 60000;
|
||||||
var ASYNC_TASK_LONG_TIMEOUT = 180000;
|
constants.ASYNC_TASK_LONG_TIMEOUT = 180000;
|
||||||
var SYNC_PERIOD = 180000;
|
constants.USER_IDLE_THRESHOLD = 300000;
|
||||||
var USER_IDLE_THRESHOLD = 300000;
|
constants.IMPORT_FILE_MAX_CONTENT_SIZE = 100000;
|
||||||
var IMPORT_FILE_MAX_CONTENT_SIZE = 100000;
|
constants.IMPORT_IMG_MAX_CONTENT_SIZE = 10000000;
|
||||||
var IMPORT_IMG_MAX_CONTENT_SIZE = 10000000;
|
constants.TEMPORARY_FILE_INDEX = "file.tempIndex";
|
||||||
var TEMPORARY_FILE_INDEX = "file.tempIndex";
|
constants.WELCOME_DOCUMENT_TITLE = "Welcome document";
|
||||||
var WELCOME_DOCUMENT_TITLE = "Welcome document";
|
constants.DOWNLOAD_PROXY_URL = "https://stackedit-download-proxy.herokuapp.com/";
|
||||||
var DOWNLOAD_PROXY_URL = "https://stackedit-download-proxy.herokuapp.com/";
|
constants.PICASA_PROXY_URL = "https://stackedit-picasa-proxy.herokuapp.com/";
|
||||||
var PICASA_PROXY_URL = "https://stackedit-picasa-proxy.herokuapp.com/";
|
constants.SSH_PROXY_URL = "https://stackedit-ssh-proxy.herokuapp.com/";
|
||||||
var SSH_PROXY_URL = "https://stackedit-ssh-proxy.herokuapp.com/";
|
constants.HTMLTOPDF_URL = "https://stackedit-htmltopdf.herokuapp.com/";
|
||||||
var HTMLTOPDF_URL = "https://stackedit-htmltopdf.herokuapp.com/";
|
|
||||||
|
|
||||||
// Use by Google's client.js
|
// Use by Google's client.js
|
||||||
var delayedFunction = undefined;
|
window.delayedFunction = undefined;
|
||||||
function runDelayedFunction() {
|
function runDelayedFunction() {
|
||||||
if(delayedFunction !== undefined) {
|
if(window.delayedFunction !== undefined) {
|
||||||
delayedFunction();
|
window.delayedFunction();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Site dependent
|
// Site dependent
|
||||||
var BASE_URL = "http://localhost/";
|
constants.BASE_URL = "http://localhost/";
|
||||||
var GOOGLE_CLIENT_ID = '241271498917-lev37kef013q85avc91am1gccg5g8lrb.apps.googleusercontent.com';
|
constants.GOOGLE_CLIENT_ID = '241271498917-lev37kef013q85avc91am1gccg5g8lrb.apps.googleusercontent.com';
|
||||||
var GITHUB_CLIENT_ID = 'e47fef6055344579799d';
|
constants.GITHUB_CLIENT_ID = 'e47fef6055344579799d';
|
||||||
var GATEKEEPER_URL = "https://stackedit-gatekeeper-localhost.herokuapp.com/";
|
constants.GATEKEEPER_URL = "https://stackedit-gatekeeper-localhost.herokuapp.com/";
|
||||||
var TUMBLR_PROXY_URL = "https://stackedit-tumblr-proxy-local.herokuapp.com/";
|
constants.TUMBLR_PROXY_URL = "https://stackedit-tumblr-proxy-local.herokuapp.com/";
|
||||||
var WORDPRESS_CLIENT_ID = '23361';
|
constants.WORDPRESS_CLIENT_ID = '23361';
|
||||||
var WORDPRESS_PROXY_URL = "https://stackedit-io-wordpress-proxy.herokuapp.com/";
|
constants.WORDPRESS_PROXY_URL = "https://stackedit-io-wordpress-proxy.herokuapp.com/";
|
||||||
|
|
||||||
if(location.hostname.indexOf("stackedit.io") === 0) {
|
if(location.hostname.indexOf("stackedit.io") === 0) {
|
||||||
BASE_URL = MAIN_URL;
|
constants.BASE_URL = constants.MAIN_URL;
|
||||||
GOOGLE_CLIENT_ID = '241271498917-t4t7d07qis7oc0ahaskbif3ft6tk63cd.apps.googleusercontent.com';
|
constants.GOOGLE_CLIENT_ID = '241271498917-t4t7d07qis7oc0ahaskbif3ft6tk63cd.apps.googleusercontent.com';
|
||||||
GITHUB_CLIENT_ID = '710fc67886ab1ae8fee6';
|
constants.GITHUB_CLIENT_ID = '710fc67886ab1ae8fee6';
|
||||||
GATEKEEPER_URL = "https://stackedit-io-gatekeeper.herokuapp.com/";
|
constants.GATEKEEPER_URL = "https://stackedit-io-gatekeeper.herokuapp.com/";
|
||||||
TUMBLR_PROXY_URL = "https://stackedit-io-tumblr-proxy.herokuapp.com/";
|
constants.TUMBLR_PROXY_URL = "https://stackedit-io-tumblr-proxy.herokuapp.com/";
|
||||||
}
|
}
|
||||||
|
|
||||||
if(location.hostname.indexOf("benweet.github.io") === 0) {
|
if(location.hostname.indexOf("benweet.github.io") === 0) {
|
||||||
BASE_URL = 'http://benweet.github.io/stackedit/';
|
constants.BASE_URL = 'http://benweet.github.io/stackedit/';
|
||||||
GOOGLE_CLIENT_ID = '241271498917-jpto9lls9fqnem1e4h6ppds9uob8rpvu.apps.googleusercontent.com';
|
constants.GOOGLE_CLIENT_ID = '241271498917-jpto9lls9fqnem1e4h6ppds9uob8rpvu.apps.googleusercontent.com';
|
||||||
GITHUB_CLIENT_ID = 'fa0d09514da8377ee32e';
|
constants.GITHUB_CLIENT_ID = 'fa0d09514da8377ee32e';
|
||||||
GATEKEEPER_URL = "https://stackedit-gatekeeper.herokuapp.com/";
|
constants.GATEKEEPER_URL = "https://stackedit-gatekeeper.herokuapp.com/";
|
||||||
TUMBLR_PROXY_URL = "https://stackedit-tumblr-proxy.herokuapp.com/";
|
constants.TUMBLR_PROXY_URL = "https://stackedit-tumblr-proxy.herokuapp.com/";
|
||||||
WORDPRESS_CLIENT_ID = '3185';
|
constants.WORDPRESS_CLIENT_ID = '3185';
|
||||||
WORDPRESS_PROXY_URL = "https://stackedit-wordpress-proxy.herokuapp.com/";
|
constants.WORDPRESS_PROXY_URL = "https://stackedit-wordpress-proxy.herokuapp.com/";
|
||||||
}
|
}
|
||||||
|
|
||||||
if(location.hostname.indexOf("benweet.insomnia247.nl") === 0) {
|
if(location.hostname.indexOf("benweet.insomnia247.nl") === 0) {
|
||||||
BASE_URL = "http://benweet.insomnia247.nl/stackedit/";
|
constants.BASE_URL = "http://benweet.insomnia247.nl/stackedit/";
|
||||||
GOOGLE_CLIENT_ID = '241271498917-52hae7a08hv7ltenv7km8h7lghno9sk3.apps.googleusercontent.com';
|
constants.GOOGLE_CLIENT_ID = '241271498917-52hae7a08hv7ltenv7km8h7lghno9sk3.apps.googleusercontent.com';
|
||||||
GITHUB_CLIENT_ID = 'd2943d6074b2d9c4a830';
|
constants.GITHUB_CLIENT_ID = 'd2943d6074b2d9c4a830';
|
||||||
GATEKEEPER_URL = "https://stackedit-gatekeeper-insomnia.herokuapp.com/";
|
constants.GATEKEEPER_URL = "https://stackedit-gatekeeper-insomnia.herokuapp.com/";
|
||||||
TUMBLR_PROXY_URL = "https://stackedit-tumblr-proxy-beta.herokuapp.com/";
|
constants.TUMBLR_PROXY_URL = "https://stackedit-tumblr-proxy-beta.herokuapp.com/";
|
||||||
}
|
}
|
||||||
|
|
||||||
var THEME_LIST = {
|
constants.THEME_LIST = {
|
||||||
"default": "Default",
|
"default": "Default",
|
||||||
"blue-gray": "Blue-Gray",
|
"blue-gray": "Blue-Gray",
|
||||||
"night": "Night",
|
"night": "Night",
|
||||||
"school": "School",
|
"school": "School",
|
||||||
};
|
};
|
||||||
|
});
|
||||||
|
@ -3,7 +3,9 @@ define([
|
|||||||
"underscore",
|
"underscore",
|
||||||
"crel",
|
"crel",
|
||||||
"ace",
|
"ace",
|
||||||
|
"constants",
|
||||||
"utils",
|
"utils",
|
||||||
|
"storage",
|
||||||
"settings",
|
"settings",
|
||||||
"eventMgr",
|
"eventMgr",
|
||||||
"shortcutMgr",
|
"shortcutMgr",
|
||||||
@ -22,7 +24,7 @@ define([
|
|||||||
'ace/ext/spellcheck',
|
'ace/ext/spellcheck',
|
||||||
'ace/ext/searchbox'
|
'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 = {};
|
var core = {};
|
||||||
|
|
||||||
@ -45,7 +47,7 @@ define([
|
|||||||
}
|
}
|
||||||
|
|
||||||
function isUserActive() {
|
function isUserActive() {
|
||||||
if(utils.currentTime - userLastActivity > USER_IDLE_THRESHOLD) {
|
if(utils.currentTime - userLastActivity > constants.USER_IDLE_THRESHOLD) {
|
||||||
userActive = false;
|
userActive = false;
|
||||||
}
|
}
|
||||||
return userActive && windowUnique;
|
return userActive && windowUnique;
|
||||||
@ -59,9 +61,9 @@ define([
|
|||||||
}
|
}
|
||||||
if(windowId === undefined) {
|
if(windowId === undefined) {
|
||||||
windowId = utils.randomString();
|
windowId = utils.randomString();
|
||||||
localStorage.frontWindowId = windowId;
|
storage.frontWindowId = windowId;
|
||||||
}
|
}
|
||||||
var frontWindowId = localStorage.frontWindowId;
|
var frontWindowId = storage.frontWindowId;
|
||||||
if(frontWindowId != windowId) {
|
if(frontWindowId != windowId) {
|
||||||
windowUnique = false;
|
windowUnique = false;
|
||||||
if(intervalId !== undefined) {
|
if(intervalId !== undefined) {
|
||||||
@ -90,12 +92,12 @@ define([
|
|||||||
}
|
}
|
||||||
function checkOnline() {
|
function checkOnline() {
|
||||||
// Try to reconnect if we are offline but we have some network
|
// 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;
|
offlineTime = utils.currentTime;
|
||||||
// Try to download anything to test the connection
|
// Try to download anything to test the connection
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: "//www.google.com/jsapi",
|
url: "//www.google.com/jsapi",
|
||||||
timeout: AJAX_TIMEOUT,
|
timeout: constants.AJAX_TIMEOUT,
|
||||||
dataType: "script"
|
dataType: "script"
|
||||||
}).done(function() {
|
}).done(function() {
|
||||||
setOnline();
|
setOnline();
|
||||||
@ -182,8 +184,8 @@ define([
|
|||||||
|
|
||||||
if(!event.isPropagationStopped()) {
|
if(!event.isPropagationStopped()) {
|
||||||
$.extend(settings, newSettings);
|
$.extend(settings, newSettings);
|
||||||
localStorage.settings = JSON.stringify(settings);
|
storage.settings = JSON.stringify(settings);
|
||||||
localStorage.theme = theme;
|
storage.theme = theme;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -220,7 +222,7 @@ define([
|
|||||||
aceEditor.setOption("spellcheck", true);
|
aceEditor.setOption("spellcheck", true);
|
||||||
aceEditor.renderer.setShowGutter(false);
|
aceEditor.renderer.setShowGutter(false);
|
||||||
aceEditor.renderer.setPrintMarginColumn(false);
|
aceEditor.renderer.setPrintMarginColumn(false);
|
||||||
aceEditor.renderer.setPadding(EDITOR_DEFAULT_PADDING);
|
aceEditor.renderer.setPadding(constants.EDITOR_DEFAULT_PADDING);
|
||||||
aceEditor.session.setUseWrapMode(true);
|
aceEditor.session.setUseWrapMode(true);
|
||||||
aceEditor.session.setNewLineMode("unix");
|
aceEditor.session.setNewLineMode("unix");
|
||||||
aceEditor.session.setMode("libs/ace_mode");
|
aceEditor.session.setMode("libs/ace_mode");
|
||||||
@ -334,8 +336,8 @@ define([
|
|||||||
aceEditor.renderer.setScrollMargin(0, bottomMargin, 0, 0);
|
aceEditor.renderer.setScrollMargin(0, bottomMargin, 0, 0);
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
var padding = (aceEditor.renderer.$size.scrollerWidth - settings.maxWidth) / 2;
|
var padding = (aceEditor.renderer.$size.scrollerWidth - settings.maxWidth) / 2;
|
||||||
if(padding < EDITOR_DEFAULT_PADDING) {
|
if(padding < constants.EDITOR_DEFAULT_PADDING) {
|
||||||
padding = EDITOR_DEFAULT_PADDING;
|
padding = constants.EDITOR_DEFAULT_PADDING;
|
||||||
}
|
}
|
||||||
if(padding !== aceEditor.renderer.$padding) {
|
if(padding !== aceEditor.renderer.$padding) {
|
||||||
aceEditor.renderer.setPadding(padding);
|
aceEditor.renderer.setPadding(padding);
|
||||||
@ -747,7 +749,7 @@ define([
|
|||||||
isModalShown = false;
|
isModalShown = false;
|
||||||
(aceEditor && aceEditor.focus()) || $editorElt.focus();
|
(aceEditor && aceEditor.focus()) || $editorElt.focus();
|
||||||
// Revert to current theme when settings modal is closed
|
// Revert to current theme when settings modal is closed
|
||||||
applyTheme(localStorage.theme);
|
applyTheme(storage.theme);
|
||||||
}).keyup(function(e) {
|
}).keyup(function(e) {
|
||||||
// Handle enter key in modals
|
// Handle enter key in modals
|
||||||
if(e.which == 13 && !$(e.target).is("textarea")) {
|
if(e.which == 13 && !$(e.target).is("textarea")) {
|
||||||
@ -827,7 +829,7 @@ define([
|
|||||||
$(".action-import-docs-settings").click(function(e) {
|
$(".action-import-docs-settings").click(function(e) {
|
||||||
$("#input-file-import-docs-settings").click();
|
$("#input-file-import-docs-settings").click();
|
||||||
});
|
});
|
||||||
var newLocalStorage = undefined;
|
var newstorage = undefined;
|
||||||
$("#input-file-import-docs-settings").change(function(evt) {
|
$("#input-file-import-docs-settings").change(function(evt) {
|
||||||
var files = (evt.dataTransfer || evt.target).files;
|
var files = (evt.dataTransfer || evt.target).files;
|
||||||
$(".modal-settings").modal("hide");
|
$(".modal-settings").modal("hide");
|
||||||
@ -836,12 +838,12 @@ define([
|
|||||||
reader.onload = (function(importedFile) {
|
reader.onload = (function(importedFile) {
|
||||||
return function(e) {
|
return function(e) {
|
||||||
try {
|
try {
|
||||||
newLocalStorage = JSON.parse(e.target.result);
|
newstorage = JSON.parse(e.target.result);
|
||||||
// Compare localStorage version
|
// Compare storage version
|
||||||
var newVersion = parseInt(newLocalStorage.version.match(/^v(\d+)$/)[1], 10);
|
var newVersion = parseInt(newstorage.version.match(/^v(\d+)$/)[1], 10);
|
||||||
var currentVersion = parseInt(localStorage.version.match(/^v(\d+)$/)[1], 10);
|
var currentVersion = parseInt(storage.version.match(/^v(\d+)$/)[1], 10);
|
||||||
if(newVersion > currentVersion) {
|
if(newVersion > currentVersion) {
|
||||||
// We manage localStorage upgrade, not downgrade
|
// We manage storage upgrade, not downgrade
|
||||||
eventMgr.onError("Incompatible version. Please upgrade StackEdit.");
|
eventMgr.onError("Incompatible version. Please upgrade StackEdit.");
|
||||||
} else {
|
} else {
|
||||||
$('.modal-import-docs-settings').modal('show');
|
$('.modal-import-docs-settings').modal('show');
|
||||||
@ -857,28 +859,28 @@ define([
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
$(".action-import-docs-settings-confirm").click(function(e) {
|
$(".action-import-docs-settings-confirm").click(function(e) {
|
||||||
localStorage.clear();
|
storage.clear();
|
||||||
var allowedKeys = /^file\.|^focusMode$|^folder\.|^publish\.|^settings$|^sync\.|^theme$|^version$|^welcomeTour$/;
|
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)) {
|
if(allowedKeys.test(key)) {
|
||||||
localStorage[key] = value;
|
storage[key] = value;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
window.location.reload();
|
window.location.reload();
|
||||||
});
|
});
|
||||||
// Export settings
|
// Export settings
|
||||||
$(".action-export-docs-settings").click(function(e) {
|
$(".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() {
|
$(".action-default-settings").click(function() {
|
||||||
localStorage.removeItem("settings");
|
storage.removeItem("settings");
|
||||||
localStorage.removeItem("theme");
|
storage.removeItem("theme");
|
||||||
window.location.reload();
|
window.location.reload();
|
||||||
});
|
});
|
||||||
|
|
||||||
$(".action-app-reset").click(function() {
|
$(".action-app-reset").click(function() {
|
||||||
localStorage.clear();
|
storage.clear();
|
||||||
window.location.reload();
|
window.location.reload();
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -974,7 +976,7 @@ define([
|
|||||||
|
|
||||||
if(viewerMode === false) {
|
if(viewerMode === false) {
|
||||||
// Load theme list
|
// 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>';
|
return themeOptions + '<option value="' + value + '">' + name + '</option>';
|
||||||
}, '');
|
}, '');
|
||||||
document.getElementById('input-settings-theme').innerHTML = themeOptions;
|
document.getElementById('input-settings-theme').innerHTML = themeOptions;
|
||||||
|
@ -2,8 +2,9 @@ define([
|
|||||||
"jquery",
|
"jquery",
|
||||||
"underscore",
|
"underscore",
|
||||||
"crel",
|
"crel",
|
||||||
|
"storage",
|
||||||
"classes/Extension"
|
"classes/Extension"
|
||||||
], function($, _, crel, Extension) {
|
], function($, _, crel, storage, Extension) {
|
||||||
|
|
||||||
var buttonFocusMode = new Extension("buttonFocusMode", 'Button "Focus Mode"', true, true, true);
|
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.";
|
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() {
|
aceEditor.container.addEventListener('mousedown', function() {
|
||||||
isMouseActive = true;
|
isMouseActive = true;
|
||||||
}, true);
|
}, true);
|
||||||
if(localStorage.focusMode == 'on') {
|
if(storage.focusMode == 'on') {
|
||||||
$button.click();
|
$button.click();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -47,7 +48,7 @@ define([
|
|||||||
$button.click(function() {
|
$button.click(function() {
|
||||||
_.defer(function() {
|
_.defer(function() {
|
||||||
isFocusModeOn = $button.is('.active');
|
isFocusModeOn = $button.is('.active');
|
||||||
localStorage.focusMode = isFocusModeOn ? 'on' : 'off';
|
storage.focusMode = isFocusModeOn ? 'on' : 'off';
|
||||||
isMouseActive = false;
|
isMouseActive = false;
|
||||||
aceEditor.focus();
|
aceEditor.focus();
|
||||||
doFocusMode();
|
doFocusMode();
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
define([
|
define([
|
||||||
"underscore",
|
"underscore",
|
||||||
|
"constants",
|
||||||
"utils",
|
"utils",
|
||||||
"classes/Extension",
|
"classes/Extension",
|
||||||
"text!html/dialogAbout.html",
|
"text!html/dialogAbout.html",
|
||||||
"config"
|
"config"
|
||||||
], function(_, utils, Extension, dialogAboutHTML) {
|
], function(_, constants, utils, Extension, dialogAboutHTML) {
|
||||||
|
|
||||||
var dialogAbout = new Extension("dialogAbout", 'Dialog "About"');
|
var dialogAbout = new Extension("dialogAbout", 'Dialog "About"');
|
||||||
|
|
||||||
@ -54,7 +55,7 @@ define([
|
|||||||
utils.addModal('modal-about', _.template(dialogAboutHTML, {
|
utils.addModal('modal-about', _.template(dialogAboutHTML, {
|
||||||
libraries: libraries,
|
libraries: libraries,
|
||||||
projects: projects,
|
projects: projects,
|
||||||
version: VERSION
|
version: constants.VERSION
|
||||||
}));
|
}));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1,11 +1,12 @@
|
|||||||
define([
|
define([
|
||||||
"jquery",
|
"jquery",
|
||||||
"underscore",
|
"underscore",
|
||||||
|
"constants",
|
||||||
"utils",
|
"utils",
|
||||||
"classes/Extension",
|
"classes/Extension",
|
||||||
"toMarkdown",
|
"toMarkdown",
|
||||||
"config",
|
"config",
|
||||||
], function($, _, utils, Extension, toMarkdown) {
|
], function($, _, constants, utils, Extension, toMarkdown) {
|
||||||
|
|
||||||
var dialogOpenHarddrive = new Extension("dialogOpenHarddrive", 'Dialog "Open from"');
|
var dialogOpenHarddrive = new Extension("dialogOpenHarddrive", 'Dialog "Open from"');
|
||||||
|
|
||||||
@ -53,7 +54,7 @@ define([
|
|||||||
fileMgr.selectFile(fileDesc);
|
fileMgr.selectFile(fileDesc);
|
||||||
};
|
};
|
||||||
})(file);
|
})(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);
|
reader.readAsText(blob);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -1,13 +1,15 @@
|
|||||||
define([
|
define([
|
||||||
"jquery",
|
"jquery",
|
||||||
"underscore",
|
"underscore",
|
||||||
|
"constants",
|
||||||
"utils",
|
"utils",
|
||||||
|
"storage",
|
||||||
"classes/Extension",
|
"classes/Extension",
|
||||||
"classes/FolderDescriptor",
|
"classes/FolderDescriptor",
|
||||||
"folderList",
|
"folderList",
|
||||||
"fileSystem",
|
"fileSystem",
|
||||||
"config"
|
"config"
|
||||||
], function($, _, utils, Extension, FolderDescriptor, folderList, fileSystem) {
|
], function($, _, constants, utils, storage, Extension, FolderDescriptor, folderList, fileSystem) {
|
||||||
|
|
||||||
var documentManager = new Extension("documentManager", 'Document Manager', false, true);
|
var documentManager = new Extension("documentManager", 'Document Manager', false, true);
|
||||||
|
|
||||||
@ -105,8 +107,8 @@ define([
|
|||||||
// Delete folders
|
// Delete folders
|
||||||
_.each(selectedFolderList, function(folderDesc) {
|
_.each(selectedFolderList, function(folderDesc) {
|
||||||
utils.removeIndexFromArray("folder.list", folderDesc.folderIndex);
|
utils.removeIndexFromArray("folder.list", folderDesc.folderIndex);
|
||||||
localStorage.removeItem(folderDesc.folderIndex + ".name");
|
storage.removeItem(folderDesc.folderIndex + ".name");
|
||||||
localStorage.removeItem(folderDesc.folderIndex + ".files");
|
storage.removeItem(folderDesc.folderIndex + ".files");
|
||||||
delete folderList[folderDesc.folderIndex];
|
delete folderList[folderDesc.folderIndex];
|
||||||
});
|
});
|
||||||
eventMgr.onFoldersChanged();
|
eventMgr.onFoldersChanged();
|
||||||
@ -314,10 +316,10 @@ define([
|
|||||||
folderIndex = "folder." + utils.randomString();
|
folderIndex = "folder." + utils.randomString();
|
||||||
} while (_.has(folderList, folderIndex));
|
} while (_.has(folderList, folderIndex));
|
||||||
|
|
||||||
localStorage[folderIndex + ".name"] = DEFAULT_FOLDER_NAME;
|
storage[folderIndex + ".name"] = constants.DEFAULT_FOLDER_NAME;
|
||||||
|
|
||||||
// Create the folder descriptor
|
// 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
|
// Add the index to the folder list
|
||||||
utils.appendIndexToArray("folder.list", folderIndex);
|
utils.appendIndexToArray("folder.list", folderIndex);
|
||||||
|
@ -1,11 +1,12 @@
|
|||||||
define([
|
define([
|
||||||
"jquery",
|
"jquery",
|
||||||
"underscore",
|
"underscore",
|
||||||
|
"constants",
|
||||||
"utils",
|
"utils",
|
||||||
"classes/Extension",
|
"classes/Extension",
|
||||||
"settings",
|
"settings",
|
||||||
"config",
|
"config",
|
||||||
], function($, _, utils, Extension, settings) {
|
], function($, _, constants, utils, Extension, settings) {
|
||||||
|
|
||||||
var googleAnalytics = new Extension("googleAnalytics", "Google Analytics", true);
|
var googleAnalytics = new Extension("googleAnalytics", "Google Analytics", true);
|
||||||
googleAnalytics.settingsBlock = '<p>Sends anonymous statistics about usage and errors to help improve StackEdit.</p>';
|
googleAnalytics.settingsBlock = '<p>Sends anonymous statistics about usage and errors to help improve StackEdit.</p>';
|
||||||
@ -47,7 +48,7 @@ define([
|
|||||||
// First configure GA
|
// First configure GA
|
||||||
_gaq.push([
|
_gaq.push([
|
||||||
'_setAccount',
|
'_setAccount',
|
||||||
GOOGLE_ANALYTICS_ACCOUNT_ID
|
constants.GOOGLE_ANALYTICS_ACCOUNT_ID
|
||||||
]);
|
]);
|
||||||
trackPageView();
|
trackPageView();
|
||||||
|
|
||||||
@ -56,7 +57,7 @@ define([
|
|||||||
'_trackEvent',
|
'_trackEvent',
|
||||||
"About",
|
"About",
|
||||||
'version',
|
'version',
|
||||||
VERSION
|
constants.VERSION
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// Collect informations about user settings
|
// Collect informations about user settings
|
||||||
@ -95,20 +96,20 @@ define([
|
|||||||
'_trackEvent',
|
'_trackEvent',
|
||||||
"Settings",
|
"Settings",
|
||||||
'defaultContent backlink',
|
'defaultContent backlink',
|
||||||
"" + (settings.defaultContent.indexOf(MAIN_URL) !== -1)
|
"" + (settings.defaultContent.indexOf(constants.MAIN_URL) !== -1)
|
||||||
]);
|
]);
|
||||||
_gaq.push([
|
_gaq.push([
|
||||||
'_trackEvent',
|
'_trackEvent',
|
||||||
"Settings",
|
"Settings",
|
||||||
'commitMsg backlink',
|
'commitMsg backlink',
|
||||||
"" + (settings.commitMsg.indexOf(MAIN_URL) !== -1)
|
"" + (settings.commitMsg.indexOf(constants.MAIN_URL) !== -1)
|
||||||
]);
|
]);
|
||||||
// Check if user has changed sshProxy
|
// Check if user has changed sshProxy
|
||||||
_gaq.push([
|
_gaq.push([
|
||||||
'_trackEvent',
|
'_trackEvent',
|
||||||
"Settings",
|
"Settings",
|
||||||
'sshProxy unchanged',
|
'sshProxy unchanged',
|
||||||
"" + (settings.sshProxy == SSH_PROXY_URL)
|
"" + (settings.sshProxy == constants.SSH_PROXY_URL)
|
||||||
]);
|
]);
|
||||||
// Check if extensions have been disabled
|
// Check if extensions have been disabled
|
||||||
_.each(settings.extensionSettings, function(config, extensionId) {
|
_.each(settings.extensionSettings, function(config, extensionId) {
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
define([
|
define([
|
||||||
'underscore',
|
'underscore',
|
||||||
'jquery',
|
'jquery',
|
||||||
|
'storage',
|
||||||
'classes/Extension',
|
'classes/Extension',
|
||||||
'bootstrap-tour'
|
'bootstrap-tour'
|
||||||
], function(_, $, Extension) {
|
], function(_, $, storage, Extension) {
|
||||||
|
|
||||||
var welcomeTour = new Extension('welcomeTour', 'Welcome tour', false, true);
|
var welcomeTour = new Extension('welcomeTour', 'Welcome tour', false, true);
|
||||||
|
|
||||||
@ -19,7 +20,7 @@ define([
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
onEnd: function(tour) {
|
onEnd: function(tour) {
|
||||||
localStorage.welcomeTour = 'done';
|
storage.welcomeTour = 'done';
|
||||||
},
|
},
|
||||||
template: [
|
template: [
|
||||||
'<div class="popover tour">',
|
'<div class="popover tour">',
|
||||||
@ -86,7 +87,7 @@ define([
|
|||||||
reflex: true,
|
reflex: true,
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
if(!_.has(localStorage, 'welcomeTour')) {
|
if(!_.has(storage, 'welcomeTour')) {
|
||||||
tour.start();
|
tour.start();
|
||||||
}
|
}
|
||||||
$('.action-welcome-tour').click(function() {
|
$('.action-welcome-tour').click(function() {
|
||||||
|
@ -1,14 +1,16 @@
|
|||||||
define([
|
define([
|
||||||
"jquery",
|
"jquery",
|
||||||
"underscore",
|
"underscore",
|
||||||
|
"constants",
|
||||||
"core",
|
"core",
|
||||||
"utils",
|
"utils",
|
||||||
|
"storage",
|
||||||
"settings",
|
"settings",
|
||||||
"eventMgr",
|
"eventMgr",
|
||||||
"fileSystem",
|
"fileSystem",
|
||||||
"classes/FileDescriptor",
|
"classes/FileDescriptor",
|
||||||
"text!WELCOME.md"
|
"text!WELCOME.md"
|
||||||
], function($, _, core, utils, settings, eventMgr, fileSystem, FileDescriptor, welcomeContent) {
|
], function($, _, constants, core, utils, storage, settings, eventMgr, fileSystem, FileDescriptor, welcomeContent) {
|
||||||
|
|
||||||
var fileMgr = {};
|
var fileMgr = {};
|
||||||
|
|
||||||
@ -23,7 +25,7 @@ define([
|
|||||||
var fileSystemSize = _.size(fileSystem);
|
var fileSystemSize = _.size(fileSystem);
|
||||||
if(fileSystemSize === 0) {
|
if(fileSystemSize === 0) {
|
||||||
// If fileSystem empty create one file
|
// If fileSystem empty create one file
|
||||||
fileDesc = fileMgr.createFile(WELCOME_DOCUMENT_TITLE, welcomeContent);
|
fileDesc = fileMgr.createFile(constants.WELCOME_DOCUMENT_TITLE, welcomeContent);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// Select the last selected file
|
// Select the last selected file
|
||||||
@ -41,7 +43,7 @@ define([
|
|||||||
eventMgr.onFileSelected(fileDesc);
|
eventMgr.onFileSelected(fileDesc);
|
||||||
|
|
||||||
// Hide the viewer pencil button
|
// 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)
|
// Refresh the editor (even if it's the same file)
|
||||||
@ -52,17 +54,18 @@ define([
|
|||||||
content = content !== undefined ? content : settings.defaultContent;
|
content = content !== undefined ? content : settings.defaultContent;
|
||||||
if(!title) {
|
if(!title) {
|
||||||
// Create a file title
|
// Create a file title
|
||||||
title = DEFAULT_FILE_TITLE;
|
title = constants.DEFAULT_FILE_TITLE;
|
||||||
var indicator = 2;
|
var indicator = 2;
|
||||||
while (_.some(fileSystem, function(fileDesc) {
|
var checkTitle = function (fileDesc) {
|
||||||
return fileDesc.title == title;
|
return fileDesc.title == title;
|
||||||
})) {
|
};
|
||||||
title = DEFAULT_FILE_TITLE + indicator++;
|
while (_.some(fileSystem, checkTitle)) {
|
||||||
|
title = constants.DEFAULT_FILE_TITLE + indicator++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generate a unique fileIndex
|
// Generate a unique fileIndex
|
||||||
var fileIndex = TEMPORARY_FILE_INDEX;
|
var fileIndex = constants.TEMPORARY_FILE_INDEX;
|
||||||
if(!isTemporary) {
|
if(!isTemporary) {
|
||||||
do {
|
do {
|
||||||
fileIndex = "file." + utils.randomString();
|
fileIndex = "file." + utils.randomString();
|
||||||
@ -76,10 +79,10 @@ define([
|
|||||||
return sync + syncAttributes.syncIndex + ";";
|
return sync + syncAttributes.syncIndex + ";";
|
||||||
}, ";");
|
}, ";");
|
||||||
|
|
||||||
localStorage[fileIndex + ".title"] = title;
|
storage[fileIndex + ".title"] = title;
|
||||||
localStorage[fileIndex + ".content"] = content;
|
storage[fileIndex + ".content"] = content;
|
||||||
localStorage[fileIndex + ".sync"] = sync;
|
storage[fileIndex + ".sync"] = sync;
|
||||||
localStorage[fileIndex + ".publish"] = ";";
|
storage[fileIndex + ".publish"] = ";";
|
||||||
|
|
||||||
// Create the file descriptor
|
// Create the file descriptor
|
||||||
var fileDesc = new FileDescriptor(fileIndex, title, syncLocations);
|
var fileDesc = new FileDescriptor(fileIndex, title, syncLocations);
|
||||||
@ -107,25 +110,25 @@ define([
|
|||||||
fileMgr.selectFile();
|
fileMgr.selectFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove synchronized locations from localStorage
|
// Remove synchronized locations from storage
|
||||||
_.each(fileDesc.syncLocations, function(syncAttributes) {
|
_.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) {
|
_.each(fileDesc.publishLocations, function(publishAttributes) {
|
||||||
localStorage.removeItem(publishAttributes.publishIndex);
|
storage.removeItem(publishAttributes.publishIndex);
|
||||||
});
|
});
|
||||||
|
|
||||||
localStorage.removeItem(fileDesc.fileIndex + ".title");
|
storage.removeItem(fileDesc.fileIndex + ".title");
|
||||||
localStorage.removeItem(fileDesc.fileIndex + ".content");
|
storage.removeItem(fileDesc.fileIndex + ".content");
|
||||||
localStorage.removeItem(fileDesc.fileIndex + ".sync");
|
storage.removeItem(fileDesc.fileIndex + ".sync");
|
||||||
localStorage.removeItem(fileDesc.fileIndex + ".publish");
|
storage.removeItem(fileDesc.fileIndex + ".publish");
|
||||||
localStorage.removeItem(fileDesc.fileIndex + ".selectTime");
|
storage.removeItem(fileDesc.fileIndex + ".selectTime");
|
||||||
localStorage.removeItem(fileDesc.fileIndex + ".editorStart");
|
storage.removeItem(fileDesc.fileIndex + ".editorStart");
|
||||||
localStorage.removeItem(fileDesc.fileIndex + ".editorEnd");
|
storage.removeItem(fileDesc.fileIndex + ".editorEnd");
|
||||||
localStorage.removeItem(fileDesc.fileIndex + ".editorScrollTop");
|
storage.removeItem(fileDesc.fileIndex + ".editorScrollTop");
|
||||||
localStorage.removeItem(fileDesc.fileIndex + ".previewScrollTop");
|
storage.removeItem(fileDesc.fileIndex + ".previewScrollTop");
|
||||||
|
|
||||||
eventMgr.onFileDeleted(fileDesc);
|
eventMgr.onFileDeleted(fileDesc);
|
||||||
};
|
};
|
||||||
@ -150,13 +153,13 @@ define([
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
var aceEditor = undefined;
|
var aceEditor;
|
||||||
eventMgr.addListener('onAceCreated', function(aceEditorParam) {
|
eventMgr.addListener('onAceCreated', function(aceEditorParam) {
|
||||||
aceEditor = aceEditorParam;
|
aceEditor = aceEditorParam;
|
||||||
});
|
});
|
||||||
|
|
||||||
eventMgr.addListener("onReady", function() {
|
eventMgr.addListener("onReady", function() {
|
||||||
$editorElt = $("#wmd-input")
|
var $editorElt = $("#wmd-input");
|
||||||
fileMgr.selectFile();
|
fileMgr.selectFile();
|
||||||
|
|
||||||
var $fileTitleElt = $('.file-title-navbar');
|
var $fileTitleElt = $('.file-title-navbar');
|
||||||
@ -170,7 +173,7 @@ define([
|
|||||||
fileMgr.deleteFile();
|
fileMgr.deleteFile();
|
||||||
});
|
});
|
||||||
$fileTitleElt.click(function() {
|
$fileTitleElt.click(function() {
|
||||||
if(viewerMode === true) {
|
if(window.viewerMode === true) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$fileTitleElt.addClass('hide');
|
$fileTitleElt.addClass('hide');
|
||||||
@ -216,7 +219,7 @@ define([
|
|||||||
window.location.href = ".";
|
window.location.href = ".";
|
||||||
});
|
});
|
||||||
$(".action-welcome-file").click(function() {
|
$(".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);
|
fileMgr.selectFile(fileDesc);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -1,13 +1,17 @@
|
|||||||
|
/*global Dropbox */
|
||||||
define([
|
define([
|
||||||
"jquery",
|
"jquery",
|
||||||
"underscore",
|
"underscore",
|
||||||
|
"constants",
|
||||||
"core",
|
"core",
|
||||||
|
"storage",
|
||||||
|
"logger",
|
||||||
"eventMgr",
|
"eventMgr",
|
||||||
"classes/AsyncTask",
|
"classes/AsyncTask",
|
||||||
"config",
|
"config",
|
||||||
], function($, _, core, eventMgr, AsyncTask) {
|
], function($, _, constants, core, storage, logger, eventMgr, AsyncTask) {
|
||||||
|
|
||||||
var client = undefined;
|
var client;
|
||||||
var authenticated = false;
|
var authenticated = false;
|
||||||
|
|
||||||
var dropboxHelper = {};
|
var dropboxHelper = {};
|
||||||
@ -33,14 +37,14 @@ define([
|
|||||||
$.ajax({
|
$.ajax({
|
||||||
url: "libs/dropbox.min.js",
|
url: "libs/dropbox.min.js",
|
||||||
dataType: "script",
|
dataType: "script",
|
||||||
timeout: AJAX_TIMEOUT
|
timeout: constants.AJAX_TIMEOUT
|
||||||
}).done(function() {
|
}).done(function() {
|
||||||
client = new Dropbox.Client({
|
client = new Dropbox.Client({
|
||||||
key: DROPBOX_APP_KEY,
|
key: constants.DROPBOX_APP_KEY,
|
||||||
secret: DROPBOX_APP_SECRET
|
secret: constants.DROPBOX_APP_SECRET
|
||||||
});
|
});
|
||||||
client.authDriver(new Dropbox.AuthDriver.Popup({
|
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
|
rememberUser: true
|
||||||
}));
|
}));
|
||||||
task.chain();
|
task.chain();
|
||||||
@ -73,7 +77,7 @@ define([
|
|||||||
if(immediate === false) {
|
if(immediate === false) {
|
||||||
// If not immediate we add time for user to enter his
|
// If not immediate we add time for user to enter his
|
||||||
// credentials
|
// credentials
|
||||||
task.timeout = ASYNC_TASK_LONG_TIMEOUT;
|
task.timeout = constants.ASYNC_TASK_LONG_TIMEOUT;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
client.reset();
|
client.reset();
|
||||||
@ -102,7 +106,7 @@ define([
|
|||||||
}
|
}
|
||||||
|
|
||||||
dropboxHelper.upload = function(path, content, callback) {
|
dropboxHelper.upload = function(path, content, callback) {
|
||||||
var result = undefined;
|
var result;
|
||||||
var task = new AsyncTask();
|
var task = new AsyncTask();
|
||||||
connect(task);
|
connect(task);
|
||||||
authenticate(task);
|
authenticate(task);
|
||||||
@ -212,7 +216,7 @@ define([
|
|||||||
}
|
}
|
||||||
var object = objects[0];
|
var object = objects[0];
|
||||||
result.push(object);
|
result.push(object);
|
||||||
var file = undefined;
|
var file;
|
||||||
// object may be a file
|
// object may be a file
|
||||||
if(object.isFile === true) {
|
if(object.isFile === true) {
|
||||||
file = object;
|
file = object;
|
||||||
@ -266,11 +270,11 @@ define([
|
|||||||
}
|
}
|
||||||
else if(error.status === 400 && error.responseText.indexOf("oauth_nonce") !== -1) {
|
else if(error.status === 400 && error.responseText.indexOf("oauth_nonce") !== -1) {
|
||||||
// A bug I guess...
|
// A bug I guess...
|
||||||
_.each(_.keys(localStorage), function(key) {
|
_.each(_.keys(storage), function(key) {
|
||||||
// We have to remove the Oauth cache from the
|
// We have to remove the Oauth cache from the
|
||||||
// localStorage
|
// storage
|
||||||
if(key.indexOf("dropbox-auth") === 0) {
|
if(key.indexOf("dropbox-auth") === 0) {
|
||||||
localStorage.removeItem(key);
|
storage.removeItem(key);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
authenticated = false;
|
authenticated = false;
|
||||||
@ -305,7 +309,7 @@ define([
|
|||||||
$.ajax({
|
$.ajax({
|
||||||
url: "https://www.dropbox.com/static/api/1/dropbox.js",
|
url: "https://www.dropbox.com/static/api/1/dropbox.js",
|
||||||
dataType: "script",
|
dataType: "script",
|
||||||
timeout: AJAX_TIMEOUT
|
timeout: constants.AJAX_TIMEOUT
|
||||||
}).done(function() {
|
}).done(function() {
|
||||||
pickerLoaded = true;
|
pickerLoaded = true;
|
||||||
task.chain(chooserRedirect);
|
task.chain(chooserRedirect);
|
||||||
@ -323,7 +327,7 @@ define([
|
|||||||
var paths = [];
|
var paths = [];
|
||||||
var task = new AsyncTask();
|
var task = new AsyncTask();
|
||||||
// Add some time for user to choose his files
|
// Add some time for user to choose his files
|
||||||
task.timeout = ASYNC_TASK_LONG_TIMEOUT;
|
task.timeout = constants.ASYNC_TASK_LONG_TIMEOUT;
|
||||||
connect(task);
|
connect(task);
|
||||||
loadPicker(task);
|
loadPicker(task);
|
||||||
task.onRun(function() {
|
task.onRun(function() {
|
||||||
|
@ -1,14 +1,18 @@
|
|||||||
|
/*global Github */
|
||||||
define([
|
define([
|
||||||
"jquery",
|
"jquery",
|
||||||
|
"constants",
|
||||||
"core",
|
"core",
|
||||||
"utils",
|
"utils",
|
||||||
|
"storage",
|
||||||
|
"logger",
|
||||||
"eventMgr",
|
"eventMgr",
|
||||||
"classes/AsyncTask",
|
"classes/AsyncTask",
|
||||||
"config"
|
"config"
|
||||||
], function($, core, utils, eventMgr, AsyncTask) {
|
], function($, constants, core, utils, storage, logger, eventMgr, AsyncTask) {
|
||||||
|
|
||||||
var connected = undefined;
|
var connected;
|
||||||
var github = undefined;
|
var github;
|
||||||
|
|
||||||
var githubHelper = {};
|
var githubHelper = {};
|
||||||
|
|
||||||
@ -33,7 +37,7 @@ define([
|
|||||||
$.ajax({
|
$.ajax({
|
||||||
url: "libs/github.js",
|
url: "libs/github.js",
|
||||||
dataType: "script",
|
dataType: "script",
|
||||||
timeout: AJAX_TIMEOUT
|
timeout: constants.AJAX_TIMEOUT
|
||||||
}).done(function() {
|
}).done(function() {
|
||||||
connected = true;
|
connected = true;
|
||||||
task.chain();
|
task.chain();
|
||||||
@ -49,14 +53,14 @@ define([
|
|||||||
|
|
||||||
// Try to authenticate with Oauth
|
// Try to authenticate with Oauth
|
||||||
function authenticate(task) {
|
function authenticate(task) {
|
||||||
var authWindow = undefined;
|
var authWindow;
|
||||||
var intervalId = undefined;
|
var intervalId;
|
||||||
task.onRun(function() {
|
task.onRun(function() {
|
||||||
if(github !== undefined) {
|
if(github !== undefined) {
|
||||||
task.chain();
|
task.chain();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var token = localStorage.githubToken;
|
var token = storage.githubToken;
|
||||||
if(token !== undefined) {
|
if(token !== undefined) {
|
||||||
github = new Github({
|
github = new Github({
|
||||||
token: token,
|
token: token,
|
||||||
@ -67,8 +71,8 @@ define([
|
|||||||
}
|
}
|
||||||
var errorMsg = "Failed to retrieve a token from GitHub.";
|
var errorMsg = "Failed to retrieve a token from GitHub.";
|
||||||
// We add time for user to enter his credentials
|
// We add time for user to enter his credentials
|
||||||
task.timeout = ASYNC_TASK_LONG_TIMEOUT;
|
task.timeout = constants.ASYNC_TASK_LONG_TIMEOUT;
|
||||||
var code = undefined;
|
var code;
|
||||||
function oauthRedirect() {
|
function oauthRedirect() {
|
||||||
core.redirectConfirm('You are being redirected to <strong>GitHub</strong> authorization page.', function() {
|
core.redirectConfirm('You are being redirected to <strong>GitHub</strong> authorization page.', function() {
|
||||||
task.chain(getCode);
|
task.chain(getCode);
|
||||||
@ -77,29 +81,29 @@ define([
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
function getCode() {
|
function getCode() {
|
||||||
localStorage.removeItem("githubCode");
|
storage.removeItem("githubCode");
|
||||||
authWindow = utils.popupWindow('html/github-oauth-client.html?client_id=' + GITHUB_CLIENT_ID, 'stackedit-github-oauth', 960, 600);
|
authWindow = utils.popupWindow('html/github-oauth-client.html?client_id=' + constants.GITHUB_CLIENT_ID, 'stackedit-github-oauth', 960, 600);
|
||||||
authWindow.focus();
|
authWindow.focus();
|
||||||
intervalId = setInterval(function() {
|
intervalId = setInterval(function() {
|
||||||
if(authWindow.closed === true) {
|
if(authWindow.closed === true) {
|
||||||
clearInterval(intervalId);
|
clearInterval(intervalId);
|
||||||
authWindow = undefined;
|
authWindow = undefined;
|
||||||
intervalId = undefined;
|
intervalId = undefined;
|
||||||
code = localStorage.githubCode;
|
code = storage.githubCode;
|
||||||
if(code === undefined) {
|
if(code === undefined) {
|
||||||
task.error(new Error(errorMsg));
|
task.error(new Error(errorMsg));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
localStorage.removeItem("githubCode");
|
storage.removeItem("githubCode");
|
||||||
task.chain(getToken);
|
task.chain(getToken);
|
||||||
}
|
}
|
||||||
}, 500);
|
}, 500);
|
||||||
}
|
}
|
||||||
function getToken() {
|
function getToken() {
|
||||||
$.getJSON(GATEKEEPER_URL + "authenticate/" + code, function(data) {
|
$.getJSON(constants.GATEKEEPER_URL + "authenticate/" + code, function(data) {
|
||||||
if(data.token !== undefined) {
|
if(data.token !== undefined) {
|
||||||
token = data.token;
|
token = data.token;
|
||||||
localStorage.githubToken = token;
|
storage.githubToken = token;
|
||||||
github = new Github({
|
github = new Github({
|
||||||
token: token,
|
token: token,
|
||||||
auth: "oauth"
|
auth: "oauth"
|
||||||
@ -175,7 +179,7 @@ define([
|
|||||||
files[filename] = {
|
files[filename] = {
|
||||||
content: content
|
content: content
|
||||||
};
|
};
|
||||||
githubFunction = gist.update;
|
var githubFunction = gist.update;
|
||||||
if(gistId === undefined) {
|
if(gistId === undefined) {
|
||||||
githubFunction = gist.create;
|
githubFunction = gist.create;
|
||||||
}
|
}
|
||||||
@ -209,8 +213,8 @@ define([
|
|||||||
var task = new AsyncTask(true);
|
var task = new AsyncTask(true);
|
||||||
connect(task);
|
connect(task);
|
||||||
// No need for authentication
|
// No need for authentication
|
||||||
var title = undefined;
|
var title;
|
||||||
var content = undefined;
|
var content;
|
||||||
task.onRun(function() {
|
task.onRun(function() {
|
||||||
var github = new Github({});
|
var github = new Github({});
|
||||||
var gist = github.getGist(gistId);
|
var gist = github.getGist(gistId);
|
||||||
@ -240,7 +244,7 @@ define([
|
|||||||
};
|
};
|
||||||
|
|
||||||
function handleError(error, task) {
|
function handleError(error, task) {
|
||||||
var errorMsg = undefined;
|
var errorMsg;
|
||||||
if(error) {
|
if(error) {
|
||||||
logger.error(error);
|
logger.error(error);
|
||||||
// Try to analyze the error
|
// Try to analyze the error
|
||||||
@ -251,7 +255,7 @@ define([
|
|||||||
errorMsg = "Could not publish on GitHub.";
|
errorMsg = "Could not publish on GitHub.";
|
||||||
if(error.error === 401 || error.error === 403) {
|
if(error.error === 401 || error.error === 403) {
|
||||||
github = undefined;
|
github = undefined;
|
||||||
localStorage.removeItem("githubToken");
|
storage.removeItem("githubToken");
|
||||||
errorMsg = "Access to GitHub account is not authorized.";
|
errorMsg = "Access to GitHub account is not authorized.";
|
||||||
task.retry(new Error(errorMsg), 1);
|
task.retry(new Error(errorMsg), 1);
|
||||||
return;
|
return;
|
||||||
|
@ -1,20 +1,24 @@
|
|||||||
|
/*global gapi, google */
|
||||||
define([
|
define([
|
||||||
"underscore",
|
"underscore",
|
||||||
"jquery",
|
"jquery",
|
||||||
|
"constants",
|
||||||
"core",
|
"core",
|
||||||
"utils",
|
"utils",
|
||||||
|
"storage",
|
||||||
|
"logger",
|
||||||
"settings",
|
"settings",
|
||||||
"eventMgr",
|
"eventMgr",
|
||||||
"classes/AsyncTask",
|
"classes/AsyncTask",
|
||||||
"config"
|
"config"
|
||||||
], function(_, $, core, utils, settings, eventMgr, AsyncTask) {
|
], function(_, $, constants, core, utils, storage, logger, settings, eventMgr, AsyncTask) {
|
||||||
|
|
||||||
var connected = false;
|
var connected = false;
|
||||||
var authorizationMgr = {};
|
var authorizationMgr = {};
|
||||||
(function() {
|
(function() {
|
||||||
var permissionList = {};
|
var permissionList = {};
|
||||||
var isAuthorized = false;
|
var isAuthorized = false;
|
||||||
_.each((localStorage.gdrivePermissions || '').split(';'), function(permission) {
|
_.each((storage.gdrivePermissions || '').split(';'), function(permission) {
|
||||||
permission && (permissionList[permission] = true);
|
permission && (permissionList[permission] = true);
|
||||||
});
|
});
|
||||||
authorizationMgr.reset = function() {
|
authorizationMgr.reset = function() {
|
||||||
@ -25,7 +29,7 @@ define([
|
|||||||
};
|
};
|
||||||
authorizationMgr.add = function(permission) {
|
authorizationMgr.add = function(permission) {
|
||||||
permissionList[permission] = true;
|
permissionList[permission] = true;
|
||||||
localStorage.gdrivePermissions = _.keys(permissionList).join(';');
|
storage.gdrivePermissions = _.keys(permissionList).join(';');
|
||||||
isAuthorized = true;
|
isAuthorized = true;
|
||||||
};
|
};
|
||||||
authorizationMgr.getListWithNew = function(permission) {
|
authorizationMgr.getListWithNew = function(permission) {
|
||||||
@ -57,7 +61,7 @@ define([
|
|||||||
task.chain();
|
task.chain();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
delayedFunction = function() {
|
window.delayedFunction = function() {
|
||||||
gapi.load("client,drive-realtime", function() {
|
gapi.load("client,drive-realtime", function() {
|
||||||
connected = true;
|
connected = true;
|
||||||
task.chain();
|
task.chain();
|
||||||
@ -66,7 +70,7 @@ define([
|
|||||||
$.ajax({
|
$.ajax({
|
||||||
url: "https://apis.google.com/js/api.js?onload=runDelayedFunction",
|
url: "https://apis.google.com/js/api.js?onload=runDelayedFunction",
|
||||||
dataType: "script",
|
dataType: "script",
|
||||||
timeout: AJAX_TIMEOUT
|
timeout: constants.AJAX_TIMEOUT
|
||||||
}).fail(function(jqXHR) {
|
}).fail(function(jqXHR) {
|
||||||
var error = {
|
var error = {
|
||||||
code: jqXHR.status,
|
code: jqXHR.status,
|
||||||
@ -106,11 +110,11 @@ define([
|
|||||||
}
|
}
|
||||||
function localAuthenticate() {
|
function localAuthenticate() {
|
||||||
if(immediate === false) {
|
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();
|
var scopeList = _.chain(scopeMap).pick(authorizationMgr.getListWithNew(permission)).flatten().value();
|
||||||
gapi.auth.authorize({
|
gapi.auth.authorize({
|
||||||
'client_id': GOOGLE_CLIENT_ID,
|
'client_id': constants.GOOGLE_CLIENT_ID,
|
||||||
'scope': scopeList,
|
'scope': scopeList,
|
||||||
'immediate': immediate
|
'immediate': immediate
|
||||||
}, function(authResult) {
|
}, function(authResult) {
|
||||||
@ -144,7 +148,7 @@ define([
|
|||||||
};
|
};
|
||||||
|
|
||||||
googleHelper.upload = function(fileId, parentId, title, content, contentType, etag, callback) {
|
googleHelper.upload = function(fileId, parentId, title, content, contentType, etag, callback) {
|
||||||
var result = undefined;
|
var result;
|
||||||
var task = new AsyncTask();
|
var task = new AsyncTask();
|
||||||
connect(task);
|
connect(task);
|
||||||
authenticate(task, 'gdrive');
|
authenticate(task, 'gdrive');
|
||||||
@ -222,7 +226,7 @@ define([
|
|||||||
}
|
}
|
||||||
else if(error.code === 412) {
|
else if(error.code === 412) {
|
||||||
// We may have missed a file update
|
// 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.';
|
error = 'Conflict on file ID "' + fileId + '". Please restart the synchronization.';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -239,7 +243,7 @@ define([
|
|||||||
};
|
};
|
||||||
|
|
||||||
googleHelper.rename = function(fileId, title, callback) {
|
googleHelper.rename = function(fileId, title, callback) {
|
||||||
var result = undefined;
|
var result;
|
||||||
var task = new AsyncTask();
|
var task = new AsyncTask();
|
||||||
connect(task);
|
connect(task);
|
||||||
authenticate(task, 'gdrive');
|
authenticate(task, 'gdrive');
|
||||||
@ -276,7 +280,7 @@ define([
|
|||||||
};
|
};
|
||||||
|
|
||||||
googleHelper.createRealtimeFile = function(parentId, title, callback) {
|
googleHelper.createRealtimeFile = function(parentId, title, callback) {
|
||||||
var result = undefined;
|
var result;
|
||||||
var task = new AsyncTask();
|
var task = new AsyncTask();
|
||||||
connect(task);
|
connect(task);
|
||||||
authenticate(task, 'gdrive');
|
authenticate(task, 'gdrive');
|
||||||
@ -317,7 +321,7 @@ define([
|
|||||||
};
|
};
|
||||||
|
|
||||||
googleHelper.uploadImg = function(name, content, albumId, callback) {
|
googleHelper.uploadImg = function(name, content, albumId, callback) {
|
||||||
var result = undefined;
|
var result;
|
||||||
var task = new AsyncTask();
|
var task = new AsyncTask();
|
||||||
connect(task);
|
connect(task);
|
||||||
authenticate(task, 'picasa');
|
authenticate(task, 'picasa');
|
||||||
@ -340,14 +344,14 @@ define([
|
|||||||
}
|
}
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: PICASA_PROXY_URL + "upload/" + albumId,
|
url: constants.PICASA_PROXY_URL + "upload/" + albumId,
|
||||||
headers: headers,
|
headers: headers,
|
||||||
data: content,
|
data: content,
|
||||||
processData: false,
|
processData: false,
|
||||||
dataType: "xml",
|
dataType: "xml",
|
||||||
timeout: AJAX_TIMEOUT,
|
timeout: constants.AJAX_TIMEOUT,
|
||||||
type: "POST"
|
type: "POST"
|
||||||
}).done(function(data, textStatus, jqXHR) {
|
}).done(function(data) {
|
||||||
result = data;
|
result = data;
|
||||||
task.chain();
|
task.chain();
|
||||||
}).fail(function(jqXHR) {
|
}).fail(function(jqXHR) {
|
||||||
@ -377,9 +381,9 @@ define([
|
|||||||
connect(task);
|
connect(task);
|
||||||
authenticate(task, 'gdrive');
|
authenticate(task, 'gdrive');
|
||||||
task.onRun(function() {
|
task.onRun(function() {
|
||||||
var nextPageToken = undefined;
|
var nextPageToken;
|
||||||
function retrievePageOfChanges() {
|
function retrievePageOfChanges() {
|
||||||
var request = undefined;
|
var request;
|
||||||
if(nextPageToken === undefined) {
|
if(nextPageToken === undefined) {
|
||||||
request = gapi.client.drive.changes.list({
|
request = gapi.client.drive.changes.list({
|
||||||
'startChangeId': newChangeId + 1
|
'startChangeId': newChangeId + 1
|
||||||
@ -445,11 +449,11 @@ define([
|
|||||||
url: "https://www.googleapis.com/drive/v2/files/" + id,
|
url: "https://www.googleapis.com/drive/v2/files/" + id,
|
||||||
headers: headers,
|
headers: headers,
|
||||||
data: {
|
data: {
|
||||||
key: GOOGLE_API_KEY
|
key: constants.GOOGLE_API_KEY
|
||||||
},
|
},
|
||||||
dataType: "json",
|
dataType: "json",
|
||||||
timeout: AJAX_TIMEOUT
|
timeout: constants.AJAX_TIMEOUT
|
||||||
}).done(function(data, textStatus, jqXHR) {
|
}).done(function(data) {
|
||||||
result.push(data);
|
result.push(data);
|
||||||
ids.shift();
|
ids.shift();
|
||||||
task.chain(recursiveDownloadMetadata);
|
task.chain(recursiveDownloadMetadata);
|
||||||
@ -480,7 +484,7 @@ define([
|
|||||||
var result = [];
|
var result = [];
|
||||||
var task = new AsyncTask();
|
var task = new AsyncTask();
|
||||||
// Add some time for user to choose his files
|
// Add some time for user to choose his files
|
||||||
task.timeout = ASYNC_TASK_LONG_TIMEOUT;
|
task.timeout = constants.ASYNC_TASK_LONG_TIMEOUT;
|
||||||
connect(task);
|
connect(task);
|
||||||
if(!skipAuth) {
|
if(!skipAuth) {
|
||||||
authenticate(task, 'gdrive');
|
authenticate(task, 'gdrive');
|
||||||
@ -493,7 +497,7 @@ define([
|
|||||||
}
|
}
|
||||||
var object = objects[0];
|
var object = objects[0];
|
||||||
result.push(object);
|
result.push(object);
|
||||||
var file = undefined;
|
var file;
|
||||||
// object may be a file
|
// object may be a file
|
||||||
if(object.kind == "drive#file") {
|
if(object.kind == "drive#file") {
|
||||||
file = object;
|
file = object;
|
||||||
@ -524,11 +528,11 @@ define([
|
|||||||
url: file.downloadUrl,
|
url: file.downloadUrl,
|
||||||
headers: headers,
|
headers: headers,
|
||||||
data: {
|
data: {
|
||||||
key: GOOGLE_API_KEY
|
key: constants.GOOGLE_API_KEY
|
||||||
},
|
},
|
||||||
dataType: "text",
|
dataType: "text",
|
||||||
timeout: AJAX_TIMEOUT
|
timeout: constants.AJAX_TIMEOUT
|
||||||
}).done(function(data, textStatus, jqXHR) {
|
}).done(function(data) {
|
||||||
file.content = data;
|
file.content = data;
|
||||||
objects.shift();
|
objects.shift();
|
||||||
task.chain(recursiveDownloadContent);
|
task.chain(recursiveDownloadContent);
|
||||||
@ -553,7 +557,7 @@ define([
|
|||||||
};
|
};
|
||||||
|
|
||||||
googleHelper.loadRealtime = function(fileId, content, callback, errorCallback) {
|
googleHelper.loadRealtime = function(fileId, content, callback, errorCallback) {
|
||||||
var doc = undefined;
|
var doc;
|
||||||
var task = new AsyncTask();
|
var task = new AsyncTask();
|
||||||
connect(task);
|
connect(task);
|
||||||
authenticate(task, 'gdrive');
|
authenticate(task, 'gdrive');
|
||||||
@ -581,7 +585,7 @@ define([
|
|||||||
};
|
};
|
||||||
|
|
||||||
function handleError(error, task) {
|
function handleError(error, task) {
|
||||||
var errorMsg = undefined;
|
var errorMsg;
|
||||||
if(error) {
|
if(error) {
|
||||||
logger.error(error);
|
logger.error(error);
|
||||||
// Try to analyze the error
|
// Try to analyze the error
|
||||||
@ -622,10 +626,10 @@ define([
|
|||||||
$.ajax({
|
$.ajax({
|
||||||
url: "//www.google.com/jsapi",
|
url: "//www.google.com/jsapi",
|
||||||
data: {
|
data: {
|
||||||
key: GOOGLE_API_KEY
|
key: constants.GOOGLE_API_KEY
|
||||||
},
|
},
|
||||||
dataType: "script",
|
dataType: "script",
|
||||||
timeout: AJAX_TIMEOUT
|
timeout: constants.AJAX_TIMEOUT
|
||||||
}).done(function() {
|
}).done(function() {
|
||||||
google.load('picker', '1', {
|
google.load('picker', '1', {
|
||||||
callback: function() {
|
callback: function() {
|
||||||
@ -645,7 +649,7 @@ define([
|
|||||||
|
|
||||||
googleHelper.picker = function(callback, pickerType) {
|
googleHelper.picker = function(callback, pickerType) {
|
||||||
var docs = [];
|
var docs = [];
|
||||||
var picker = undefined;
|
var picker;
|
||||||
function hidePicker() {
|
function hidePicker() {
|
||||||
if(picker !== undefined) {
|
if(picker !== undefined) {
|
||||||
picker.setVisible(false);
|
picker.setVisible(false);
|
||||||
@ -654,27 +658,28 @@ define([
|
|||||||
}
|
}
|
||||||
var task = new AsyncTask();
|
var task = new AsyncTask();
|
||||||
// Add some time for user to choose his files
|
// Add some time for user to choose his files
|
||||||
task.timeout = ASYNC_TASK_LONG_TIMEOUT;
|
task.timeout = constants.ASYNC_TASK_LONG_TIMEOUT;
|
||||||
connect(task);
|
connect(task);
|
||||||
loadPicker(task);
|
loadPicker(task);
|
||||||
task.onRun(function() {
|
task.onRun(function() {
|
||||||
var pickerBuilder = new google.picker.PickerBuilder();
|
var pickerBuilder = new google.picker.PickerBuilder();
|
||||||
pickerBuilder.setAppId(GOOGLE_DRIVE_APP_ID);
|
pickerBuilder.setAppId(constants.GOOGLE_DRIVE_APP_ID);
|
||||||
|
var view;
|
||||||
if(pickerType == 'doc') {
|
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.setIncludeFolders(true);
|
||||||
view.setMimeTypes([
|
view.setMimeTypes([
|
||||||
"text/x-markdown",
|
"text/x-markdown",
|
||||||
"text/plain",
|
"text/plain",
|
||||||
"application/octet-stream",
|
"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(","));
|
].join(","));
|
||||||
pickerBuilder.enableFeature(google.picker.Feature.NAV_HIDDEN);
|
pickerBuilder.enableFeature(google.picker.Feature.NAV_HIDDEN);
|
||||||
pickerBuilder.enableFeature(google.picker.Feature.MULTISELECT_ENABLED);
|
pickerBuilder.enableFeature(google.picker.Feature.MULTISELECT_ENABLED);
|
||||||
pickerBuilder.addView(view);
|
pickerBuilder.addView(view);
|
||||||
}
|
}
|
||||||
else if(pickerType == 'folder') {
|
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.setIncludeFolders(true);
|
||||||
view.setSelectFolderEnabled(true);
|
view.setSelectFolderEnabled(true);
|
||||||
view.setMimeTypes('application/vnd.google-apps.folder');
|
view.setMimeTypes('application/vnd.google-apps.folder');
|
||||||
@ -746,8 +751,8 @@ define([
|
|||||||
type: type,
|
type: type,
|
||||||
contentType: "application/json",
|
contentType: "application/json",
|
||||||
dataType: "json",
|
dataType: "json",
|
||||||
timeout: AJAX_TIMEOUT
|
timeout: constants.AJAX_TIMEOUT
|
||||||
}).done(function(post, textStatus, jqXHR) {
|
}).done(function(post) {
|
||||||
postId = post.id;
|
postId = post.id;
|
||||||
task.chain();
|
task.chain();
|
||||||
}).fail(function(jqXHR) {
|
}).fail(function(jqXHR) {
|
||||||
@ -774,8 +779,8 @@ define([
|
|||||||
},
|
},
|
||||||
headers: headers,
|
headers: headers,
|
||||||
dataType: "json",
|
dataType: "json",
|
||||||
timeout: AJAX_TIMEOUT
|
timeout: constants.AJAX_TIMEOUT
|
||||||
}).done(function(blog, textStatus, jqXHR) {
|
}).done(function(blog) {
|
||||||
blogId = blog.id;
|
blogId = blog.id;
|
||||||
task.chain(publish);
|
task.chain(publish);
|
||||||
}).fail(function(jqXHR) {
|
}).fail(function(jqXHR) {
|
||||||
|
@ -1,10 +1,12 @@
|
|||||||
define([
|
define([
|
||||||
"jquery",
|
"jquery",
|
||||||
|
"constants",
|
||||||
"core",
|
"core",
|
||||||
|
"logger",
|
||||||
"eventMgr",
|
"eventMgr",
|
||||||
"settings",
|
"settings",
|
||||||
"classes/AsyncTask"
|
"classes/AsyncTask"
|
||||||
], function($, core, eventMgr, settings, AsyncTask) {
|
], function($, constants, core, logger, eventMgr, settings, AsyncTask) {
|
||||||
|
|
||||||
var sshHelper = {};
|
var sshHelper = {};
|
||||||
|
|
||||||
@ -44,8 +46,8 @@ define([
|
|||||||
data: data,
|
data: data,
|
||||||
type: "POST",
|
type: "POST",
|
||||||
dataType: "json",
|
dataType: "json",
|
||||||
timeout: AJAX_TIMEOUT
|
timeout: constants.AJAX_TIMEOUT
|
||||||
}).done(function(response, textStatus, jqXHR) {
|
}).done(function(response) {
|
||||||
if(response.error === undefined) {
|
if(response.error === undefined) {
|
||||||
task.chain();
|
task.chain();
|
||||||
return;
|
return;
|
||||||
@ -69,7 +71,7 @@ define([
|
|||||||
};
|
};
|
||||||
|
|
||||||
function handleError(error, task) {
|
function handleError(error, task) {
|
||||||
var errorMsg = undefined;
|
var errorMsg;
|
||||||
if(error) {
|
if(error) {
|
||||||
logger.error(error);
|
logger.error(error);
|
||||||
// Try to analyze the error
|
// Try to analyze the error
|
||||||
|
@ -1,12 +1,15 @@
|
|||||||
define([
|
define([
|
||||||
"jquery",
|
"jquery",
|
||||||
|
"constants",
|
||||||
"core",
|
"core",
|
||||||
"utils",
|
"utils",
|
||||||
|
"storage",
|
||||||
|
"logger",
|
||||||
"eventMgr",
|
"eventMgr",
|
||||||
"classes/AsyncTask"
|
"classes/AsyncTask"
|
||||||
], function($, core, utils, eventMgr, AsyncTask) {
|
], function($, constants, core, utils, storage, logger, eventMgr, AsyncTask) {
|
||||||
|
|
||||||
var oauthParams = undefined;
|
var oauthParams;
|
||||||
|
|
||||||
var tumblrHelper = {};
|
var tumblrHelper = {};
|
||||||
|
|
||||||
@ -29,14 +32,14 @@ define([
|
|||||||
|
|
||||||
// Try to authenticate with OAuth
|
// Try to authenticate with OAuth
|
||||||
function authenticate(task) {
|
function authenticate(task) {
|
||||||
var authWindow = undefined;
|
var authWindow;
|
||||||
var intervalId = undefined;
|
var intervalId;
|
||||||
task.onRun(function() {
|
task.onRun(function() {
|
||||||
if(oauthParams !== undefined) {
|
if(oauthParams !== undefined) {
|
||||||
task.chain();
|
task.chain();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var serializedOauthParams = localStorage.tumblrOauthParams;
|
var serializedOauthParams = storage.tumblrOauthParams;
|
||||||
if(serializedOauthParams !== undefined) {
|
if(serializedOauthParams !== undefined) {
|
||||||
oauthParams = JSON.parse(serializedOauthParams);
|
oauthParams = JSON.parse(serializedOauthParams);
|
||||||
task.chain();
|
task.chain();
|
||||||
@ -44,10 +47,10 @@ define([
|
|||||||
}
|
}
|
||||||
var errorMsg = "Failed to retrieve a token from Tumblr.";
|
var errorMsg = "Failed to retrieve a token from Tumblr.";
|
||||||
// We add time for user to enter his credentials
|
// We add time for user to enter his credentials
|
||||||
task.timeout = ASYNC_TASK_LONG_TIMEOUT;
|
task.timeout = constants.ASYNC_TASK_LONG_TIMEOUT;
|
||||||
var oauth_object = undefined;
|
var oauth_object;
|
||||||
function getOauthToken() {
|
function getOauthToken() {
|
||||||
$.getJSON(TUMBLR_PROXY_URL + "request_token", function(data) {
|
$.getJSON(constants.TUMBLR_PROXY_URL + "request_token", function(data) {
|
||||||
if(data.oauth_token !== undefined) {
|
if(data.oauth_token !== undefined) {
|
||||||
oauth_object = data;
|
oauth_object = data;
|
||||||
task.chain(oauthRedirect);
|
task.chain(oauthRedirect);
|
||||||
@ -65,7 +68,7 @@ define([
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
function getVerifier() {
|
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 = utils.popupWindow('html/tumblr-oauth-client.html?oauth_token=' + oauth_object.oauth_token, 'stackedit-tumblr-oauth', 800, 600);
|
||||||
authWindow.focus();
|
authWindow.focus();
|
||||||
intervalId = setInterval(function() {
|
intervalId = setInterval(function() {
|
||||||
@ -73,20 +76,20 @@ define([
|
|||||||
clearInterval(intervalId);
|
clearInterval(intervalId);
|
||||||
authWindow = undefined;
|
authWindow = undefined;
|
||||||
intervalId = undefined;
|
intervalId = undefined;
|
||||||
oauth_object.oauth_verifier = localStorage.tumblrVerifier;
|
oauth_object.oauth_verifier = storage.tumblrVerifier;
|
||||||
if(oauth_object.oauth_verifier === undefined) {
|
if(oauth_object.oauth_verifier === undefined) {
|
||||||
task.error(new Error(errorMsg));
|
task.error(new Error(errorMsg));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
localStorage.removeItem("tumblrVerifier");
|
storage.removeItem("tumblrVerifier");
|
||||||
task.chain(getAccessToken);
|
task.chain(getAccessToken);
|
||||||
}
|
}
|
||||||
}, 500);
|
}, 500);
|
||||||
}
|
}
|
||||||
function getAccessToken() {
|
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) {
|
if(data.access_token !== undefined && data.access_token_secret !== undefined) {
|
||||||
localStorage.tumblrOauthParams = JSON.stringify(data);
|
storage.tumblrOauthParams = JSON.stringify(data);
|
||||||
oauthParams = data;
|
oauthParams = data;
|
||||||
task.chain();
|
task.chain();
|
||||||
}
|
}
|
||||||
@ -121,12 +124,12 @@ define([
|
|||||||
content: content
|
content: content
|
||||||
}, oauthParams);
|
}, oauthParams);
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: TUMBLR_PROXY_URL + "post",
|
url: constants.TUMBLR_PROXY_URL + "post",
|
||||||
data: data,
|
data: data,
|
||||||
type: "POST",
|
type: "POST",
|
||||||
dataType: "json",
|
dataType: "json",
|
||||||
timeout: AJAX_TIMEOUT
|
timeout: constants.AJAX_TIMEOUT
|
||||||
}).done(function(post, textStatus, jqXHR) {
|
}).done(function(post) {
|
||||||
postId = post.id;
|
postId = post.id;
|
||||||
task.chain();
|
task.chain();
|
||||||
}).fail(function(jqXHR) {
|
}).fail(function(jqXHR) {
|
||||||
@ -151,7 +154,7 @@ define([
|
|||||||
};
|
};
|
||||||
|
|
||||||
function handleError(error, task) {
|
function handleError(error, task) {
|
||||||
var errorMsg = undefined;
|
var errorMsg;
|
||||||
if(error) {
|
if(error) {
|
||||||
logger.error(error);
|
logger.error(error);
|
||||||
// Try to analyze the error
|
// Try to analyze the error
|
||||||
@ -162,7 +165,7 @@ define([
|
|||||||
errorMsg = "Could not publish on Tumblr.";
|
errorMsg = "Could not publish on Tumblr.";
|
||||||
if(error.code === 401 || error.code === 403) {
|
if(error.code === 401 || error.code === 403) {
|
||||||
oauthParams = undefined;
|
oauthParams = undefined;
|
||||||
localStorage.removeItem("tumblrOauthParams");
|
storage.removeItem("tumblrOauthParams");
|
||||||
errorMsg = "Access to Tumblr account is not authorized.";
|
errorMsg = "Access to Tumblr account is not authorized.";
|
||||||
task.retry(new Error(errorMsg), 1);
|
task.retry(new Error(errorMsg), 1);
|
||||||
return;
|
return;
|
||||||
|
@ -1,12 +1,15 @@
|
|||||||
define([
|
define([
|
||||||
"jquery",
|
"jquery",
|
||||||
|
"constants",
|
||||||
"core",
|
"core",
|
||||||
"utils",
|
"utils",
|
||||||
|
"storage",
|
||||||
|
"logger",
|
||||||
"eventMgr",
|
"eventMgr",
|
||||||
"classes/AsyncTask"
|
"classes/AsyncTask"
|
||||||
], function($, core, utils, eventMgr, AsyncTask) {
|
], function($, constants, core, utils, storage, logger, eventMgr, AsyncTask) {
|
||||||
|
|
||||||
var token = undefined;
|
var token;
|
||||||
|
|
||||||
var wordpressHelper = {};
|
var wordpressHelper = {};
|
||||||
|
|
||||||
@ -29,18 +32,18 @@ define([
|
|||||||
|
|
||||||
// Try to authenticate with OAuth
|
// Try to authenticate with OAuth
|
||||||
function authenticate(task) {
|
function authenticate(task) {
|
||||||
var authWindow = undefined;
|
var authWindow;
|
||||||
var intervalId = undefined;
|
var intervalId;
|
||||||
task.onRun(function() {
|
task.onRun(function() {
|
||||||
token = localStorage.wordpressToken;
|
token = storage.wordpressToken;
|
||||||
if(token !== undefined) {
|
if(token !== undefined) {
|
||||||
task.chain();
|
task.chain();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var errorMsg = "Failed to retrieve a token from Wordpress.";
|
var errorMsg = "Failed to retrieve a token from Wordpress.";
|
||||||
// We add time for user to enter his credentials
|
// We add time for user to enter his credentials
|
||||||
task.timeout = ASYNC_TASK_LONG_TIMEOUT;
|
task.timeout = constants.ASYNC_TASK_LONG_TIMEOUT;
|
||||||
var code = undefined;
|
var code;
|
||||||
function oauthRedirect() {
|
function oauthRedirect() {
|
||||||
core.redirectConfirm('You are being redirected to <strong>WordPress</strong> authorization page.', function() {
|
core.redirectConfirm('You are being redirected to <strong>WordPress</strong> authorization page.', function() {
|
||||||
task.chain(getCode);
|
task.chain(getCode);
|
||||||
@ -49,29 +52,29 @@ define([
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
function getCode() {
|
function getCode() {
|
||||||
localStorage.removeItem("wordpressCode");
|
storage.removeItem("wordpressCode");
|
||||||
authWindow = utils.popupWindow('html/wordpress-oauth-client.html?client_id=' + WORDPRESS_CLIENT_ID, 'stackedit-wordpress-oauth', 960, 600);
|
authWindow = utils.popupWindow('html/wordpress-oauth-client.html?client_id=' + constants.WORDPRESS_CLIENT_ID, 'stackedit-wordpress-oauth', 960, 600);
|
||||||
authWindow.focus();
|
authWindow.focus();
|
||||||
intervalId = setInterval(function() {
|
intervalId = setInterval(function() {
|
||||||
if(authWindow.closed === true) {
|
if(authWindow.closed === true) {
|
||||||
clearInterval(intervalId);
|
clearInterval(intervalId);
|
||||||
authWindow = undefined;
|
authWindow = undefined;
|
||||||
intervalId = undefined;
|
intervalId = undefined;
|
||||||
code = localStorage.wordpressCode;
|
code = storage.wordpressCode;
|
||||||
if(code === undefined) {
|
if(code === undefined) {
|
||||||
task.error(new Error(errorMsg));
|
task.error(new Error(errorMsg));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
localStorage.removeItem("wordpressCode");
|
storage.removeItem("wordpressCode");
|
||||||
task.chain(getToken);
|
task.chain(getToken);
|
||||||
}
|
}
|
||||||
}, 500);
|
}, 500);
|
||||||
}
|
}
|
||||||
function getToken() {
|
function getToken() {
|
||||||
$.getJSON(WORDPRESS_PROXY_URL + "authenticate/" + code, function(data) {
|
$.getJSON(constants.WORDPRESS_PROXY_URL + "authenticate/" + code, function(data) {
|
||||||
if(data.token !== undefined) {
|
if(data.token !== undefined) {
|
||||||
token = data.token;
|
token = data.token;
|
||||||
localStorage.wordpressToken = token;
|
storage.wordpressToken = token;
|
||||||
task.chain();
|
task.chain();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -96,7 +99,7 @@ define([
|
|||||||
connect(task);
|
connect(task);
|
||||||
authenticate(task);
|
authenticate(task);
|
||||||
task.onRun(function() {
|
task.onRun(function() {
|
||||||
var url = WORDPRESS_PROXY_URL + "post";
|
var url = constants.WORDPRESS_PROXY_URL + "post";
|
||||||
var data = {
|
var data = {
|
||||||
token: token,
|
token: token,
|
||||||
site: site,
|
site: site,
|
||||||
@ -110,8 +113,8 @@ define([
|
|||||||
data: data,
|
data: data,
|
||||||
type: "POST",
|
type: "POST",
|
||||||
dataType: "json",
|
dataType: "json",
|
||||||
timeout: AJAX_TIMEOUT
|
timeout: constants.AJAX_TIMEOUT
|
||||||
}).done(function(response, textStatus, jqXHR) {
|
}).done(function(response) {
|
||||||
if(response.body.ID) {
|
if(response.body.ID) {
|
||||||
postId = response.body.ID;
|
postId = response.body.ID;
|
||||||
task.chain();
|
task.chain();
|
||||||
@ -149,7 +152,7 @@ define([
|
|||||||
};
|
};
|
||||||
|
|
||||||
function handleError(error, task) {
|
function handleError(error, task) {
|
||||||
var errorMsg = undefined;
|
var errorMsg;
|
||||||
if(error) {
|
if(error) {
|
||||||
logger.error(error);
|
logger.error(error);
|
||||||
// Try to analyze the error
|
// Try to analyze the error
|
||||||
@ -159,7 +162,7 @@ define([
|
|||||||
else {
|
else {
|
||||||
errorMsg = "Could not publish on WordPress.";
|
errorMsg = "Could not publish on WordPress.";
|
||||||
if((error.code === 400 && error.message == "invalid_token") || error.code === 401 || error.code === 403) {
|
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.";
|
errorMsg = "Access to WordPress account is not authorized.";
|
||||||
task.retry(new Error(errorMsg), 1);
|
task.retry(new Error(errorMsg), 1);
|
||||||
return;
|
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
|
// RequireJS configuration
|
||||||
|
/*global requirejs */
|
||||||
requirejs.config({
|
requirejs.config({
|
||||||
waitSeconds: 0,
|
waitSeconds: 0,
|
||||||
packages: [{
|
packages: [{
|
||||||
@ -75,6 +76,12 @@ requirejs.config({
|
|||||||
deps: ['jquery'],
|
deps: ['jquery'],
|
||||||
exports: 'toMarkdown'
|
exports: 'toMarkdown'
|
||||||
},
|
},
|
||||||
|
stacktrace: {
|
||||||
|
exports: 'printStackTrace'
|
||||||
|
},
|
||||||
|
FileSaver: {
|
||||||
|
exports: 'saveAs'
|
||||||
|
},
|
||||||
'bootstrap-tour': ['bootstrap'],
|
'bootstrap-tour': ['bootstrap'],
|
||||||
bootstrap: ['jquery'],
|
bootstrap: ['jquery'],
|
||||||
'jquery-waitforimages': ['jquery'],
|
'jquery-waitforimages': ['jquery'],
|
||||||
@ -107,30 +114,20 @@ catch (e) {
|
|||||||
throw 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
|
// 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
|
// Light mode is for mobile or viewer
|
||||||
var lightMode = viewerMode || /(\?|&)light($|&)/.test(location.search) || (function(a) {
|
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;
|
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);
|
})(navigator.userAgent || navigator.vendor || window.opera);
|
||||||
|
|
||||||
// Keep the theme in a global variable
|
// Keep the theme in a global variable
|
||||||
var theme = localStorage.theme || 'default';
|
var theme = localStorage.theme || 'default';
|
||||||
var themeModule = "less!themes/" + theme;
|
var themeModule = "less!themes/" + theme;
|
||||||
if (baseDir.indexOf('-min') !== -1) {
|
if (window.baseDir.indexOf('-min') !== -1) {
|
||||||
themeModule = "css!themes/" + theme;
|
themeModule = "css!themes/" + theme;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -139,7 +136,7 @@ if (baseDir.indexOf('-min') !== -1) {
|
|||||||
require(["jquery", "core", "eventMgr", "synchronizer", "publisher", "mediaImporter", "css",
|
require(["jquery", "core", "eventMgr", "synchronizer", "publisher", "mediaImporter", "css",
|
||||||
themeModule, ], function($, core, eventMgr) {
|
themeModule, ], function($, core, eventMgr) {
|
||||||
|
|
||||||
if(typeof(noStart) !== 'undefined' && noStart) {
|
if(window.noStart) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -150,7 +147,7 @@ themeModule, ], function($, core, eventMgr) {
|
|||||||
|
|
||||||
// If browser has detected a new application cache.
|
// If browser has detected a new application cache.
|
||||||
if (window.applicationCache) {
|
if (window.applicationCache) {
|
||||||
window.applicationCache.addEventListener('updateready', function(e) {
|
window.applicationCache.addEventListener('updateready', function() {
|
||||||
if (window.applicationCache.status === window.applicationCache.UPDATEREADY) {
|
if (window.applicationCache.status === window.applicationCache.UPDATEREADY) {
|
||||||
window.applicationCache.swapCache();
|
window.applicationCache.swapCache();
|
||||||
eventMgr.onMessage('New version available!\nJust refresh the page to upgrade.');
|
eventMgr.onMessage('New version available!\nJust refresh the page to upgrade.');
|
||||||
|
@ -1,11 +1,12 @@
|
|||||||
define([
|
define([
|
||||||
"jquery",
|
"jquery",
|
||||||
"underscore",
|
"underscore",
|
||||||
|
"constants",
|
||||||
"classes/Provider",
|
"classes/Provider",
|
||||||
"core",
|
"core",
|
||||||
"eventMgr",
|
"eventMgr",
|
||||||
"providers/gplusProvider"
|
"providers/gplusProvider"
|
||||||
], function($, _, Provider, core, eventMgr) {
|
], function($, _, constants, Provider, core, eventMgr) {
|
||||||
|
|
||||||
var mediaImporter = {};
|
var mediaImporter = {};
|
||||||
|
|
||||||
@ -45,7 +46,7 @@ define([
|
|||||||
reader.onload = (function(importedFile) {
|
reader.onload = (function(importedFile) {
|
||||||
return function(e) {
|
return function(e) {
|
||||||
var content = new Uint8Array(e.target.result);
|
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) {
|
if(error) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -62,7 +63,7 @@ define([
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
})(file);
|
})(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);
|
reader.readAsArrayBuffer(blob);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,12 @@
|
|||||||
define([
|
define([
|
||||||
"jquery",
|
"jquery",
|
||||||
|
"constants",
|
||||||
"eventMgr",
|
"eventMgr",
|
||||||
"utils",
|
"utils",
|
||||||
"fileMgr",
|
"fileMgr",
|
||||||
"classes/Provider",
|
"classes/Provider",
|
||||||
"classes/AsyncTask"
|
"classes/AsyncTask"
|
||||||
], function($, eventMgr, utils, fileMgr, Provider, AsyncTask) {
|
], function($, constants, eventMgr, utils, fileMgr, Provider, AsyncTask) {
|
||||||
|
|
||||||
var downloadProvider = new Provider("download");
|
var downloadProvider = new Provider("download");
|
||||||
downloadProvider.sharingAttributes = [
|
downloadProvider.sharingAttributes = [
|
||||||
@ -13,8 +14,8 @@ define([
|
|||||||
];
|
];
|
||||||
|
|
||||||
downloadProvider.importPublic = function(importParameters, callback) {
|
downloadProvider.importPublic = function(importParameters, callback) {
|
||||||
var title = undefined;
|
var title;
|
||||||
var content = undefined;
|
var content;
|
||||||
var task = new AsyncTask(true);
|
var task = new AsyncTask(true);
|
||||||
task.onRun(function() {
|
task.onRun(function() {
|
||||||
var url = importParameters.url;
|
var url = importParameters.url;
|
||||||
@ -25,14 +26,14 @@ define([
|
|||||||
}
|
}
|
||||||
title = url.substring(slashUrl + 1);
|
title = url.substring(slashUrl + 1);
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: DOWNLOAD_PROXY_URL + "download?url=" + url,
|
url: constants.DOWNLOAD_PROXY_URL + "download?url=" + url,
|
||||||
type: "GET",
|
type: "GET",
|
||||||
dataType: "text",
|
dataType: "text",
|
||||||
timeout: AJAX_TIMEOUT
|
timeout: constants.AJAX_TIMEOUT
|
||||||
}).done(function(result, textStatus, jqXHR) {
|
}).done(function(result) {
|
||||||
content = result;
|
content = result;
|
||||||
task.chain();
|
task.chain();
|
||||||
}).fail(function(jqXHR) {
|
}).fail(function() {
|
||||||
task.error(new Error("Unable to access URL " + url));
|
task.error(new Error("Unable to access URL " + url));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -1,11 +1,12 @@
|
|||||||
define([
|
define([
|
||||||
"underscore",
|
"underscore",
|
||||||
"utils",
|
"utils",
|
||||||
|
"storage",
|
||||||
"classes/Provider",
|
"classes/Provider",
|
||||||
"eventMgr",
|
"eventMgr",
|
||||||
"fileMgr",
|
"fileMgr",
|
||||||
"helpers/dropboxHelper"
|
"helpers/dropboxHelper"
|
||||||
], function(_, utils, Provider, eventMgr, fileMgr, dropboxHelper) {
|
], function(_, utils, storage, Provider, eventMgr, fileMgr, dropboxHelper) {
|
||||||
|
|
||||||
var PROVIDER_DROPBOX = "dropbox";
|
var PROVIDER_DROPBOX = "dropbox";
|
||||||
|
|
||||||
@ -129,7 +130,7 @@ define([
|
|||||||
};
|
};
|
||||||
|
|
||||||
dropboxProvider.syncDown = function(callback) {
|
dropboxProvider.syncDown = function(callback) {
|
||||||
var lastChangeId = localStorage[PROVIDER_DROPBOX + ".lastChangeId"];
|
var lastChangeId = storage[PROVIDER_DROPBOX + ".lastChangeId"];
|
||||||
dropboxHelper.checkChanges(lastChangeId, function(error, changes, newChangeId) {
|
dropboxHelper.checkChanges(lastChangeId, function(error, changes, newChangeId) {
|
||||||
if(error) {
|
if(error) {
|
||||||
callback(error);
|
callback(error);
|
||||||
@ -201,7 +202,7 @@ define([
|
|||||||
syncAttributes.contentCRC = remoteContentCRC;
|
syncAttributes.contentCRC = remoteContentCRC;
|
||||||
utils.storeAttributes(syncAttributes);
|
utils.storeAttributes(syncAttributes);
|
||||||
});
|
});
|
||||||
localStorage[PROVIDER_DROPBOX + ".lastChangeId"] = newChangeId;
|
storage[PROVIDER_DROPBOX + ".lastChangeId"] = newChangeId;
|
||||||
callback();
|
callback();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -1,12 +1,17 @@
|
|||||||
|
/*global gapi */
|
||||||
define([
|
define([
|
||||||
|
"jquery",
|
||||||
"underscore",
|
"underscore",
|
||||||
|
"constants",
|
||||||
"utils",
|
"utils",
|
||||||
|
"storage",
|
||||||
|
"logger",
|
||||||
"classes/Provider",
|
"classes/Provider",
|
||||||
"settings",
|
"settings",
|
||||||
"eventMgr",
|
"eventMgr",
|
||||||
"fileMgr",
|
"fileMgr",
|
||||||
"helpers/googleHelper"
|
"helpers/googleHelper"
|
||||||
], function(_, utils, Provider, settings, eventMgr, fileMgr, googleHelper) {
|
], function($, _, constants, utils, storage, logger, Provider, settings, eventMgr, fileMgr, googleHelper) {
|
||||||
|
|
||||||
var PROVIDER_GDRIVE = "gdrive";
|
var PROVIDER_GDRIVE = "gdrive";
|
||||||
|
|
||||||
@ -42,7 +47,7 @@ define([
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var fileDescList = [];
|
var fileDescList = [];
|
||||||
var fileDesc = undefined;
|
var fileDesc;
|
||||||
_.each(result, function(file) {
|
_.each(result, function(file) {
|
||||||
var syncAttributes = createSyncAttributes(file.id, file.etag, file.content, file.title);
|
var syncAttributes = createSyncAttributes(file.id, file.etag, file.content, file.title);
|
||||||
syncAttributes.isRealtime = file.isRealtime;
|
syncAttributes.isRealtime = file.isRealtime;
|
||||||
@ -150,7 +155,7 @@ define([
|
|||||||
};
|
};
|
||||||
|
|
||||||
gdriveProvider.syncDown = function(callback) {
|
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) {
|
googleHelper.checkChanges(lastChangeId, function(error, changes, newChangeId) {
|
||||||
if(error) {
|
if(error) {
|
||||||
callback(error);
|
callback(error);
|
||||||
@ -238,7 +243,7 @@ define([
|
|||||||
syncAttributes.titleCRC = remoteTitleCRC;
|
syncAttributes.titleCRC = remoteTitleCRC;
|
||||||
utils.storeAttributes(syncAttributes);
|
utils.storeAttributes(syncAttributes);
|
||||||
});
|
});
|
||||||
localStorage[PROVIDER_GDRIVE + ".lastChangeId"] = newChangeId;
|
storage[PROVIDER_GDRIVE + ".lastChangeId"] = newChangeId;
|
||||||
callback();
|
callback();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -267,22 +272,22 @@ define([
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Keep a link to the Pagedown editor
|
// Keep a link to the Pagedown editor
|
||||||
var pagedownEditor = undefined;
|
var pagedownEditor;
|
||||||
var undoExecute = undefined;
|
var undoExecute;
|
||||||
var redoExecute = undefined;
|
var redoExecute;
|
||||||
var setUndoRedoButtonStates = undefined;
|
var setUndoRedoButtonStates;
|
||||||
eventMgr.addListener("onPagedownConfigure", function(pagedownEditorParam) {
|
eventMgr.addListener("onPagedownConfigure", function(pagedownEditorParam) {
|
||||||
pagedownEditor = pagedownEditorParam;
|
pagedownEditor = pagedownEditorParam;
|
||||||
});
|
});
|
||||||
|
|
||||||
// Keep a link to the ACE editor
|
// Keep a link to the ACE editor
|
||||||
var realtimeContext = undefined;
|
var realtimeContext;
|
||||||
var aceEditor = undefined;
|
var aceEditor;
|
||||||
var isAceUpToDate = true;
|
var isAceUpToDate = true;
|
||||||
eventMgr.addListener('onAceCreated', function(aceEditorParam) {
|
eventMgr.addListener('onAceCreated', function(aceEditorParam) {
|
||||||
aceEditor = aceEditorParam;
|
aceEditor = aceEditorParam;
|
||||||
// Listen to editor's changes
|
// Listen to editor's changes
|
||||||
aceEditor.session.on('change', function(e) {
|
aceEditor.session.on('change', function() {
|
||||||
// Update the real time model if any
|
// Update the real time model if any
|
||||||
realtimeContext && realtimeContext.string && realtimeContext.string.setText(aceEditor.getValue());
|
realtimeContext && realtimeContext.string && realtimeContext.string.setText(aceEditor.getValue());
|
||||||
});
|
});
|
||||||
@ -492,9 +497,9 @@ define([
|
|||||||
if(state === undefined) {
|
if(state === undefined) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
localStorage.removeItem(PROVIDER_GDRIVE + ".state");
|
storage.removeItem(PROVIDER_GDRIVE + ".state");
|
||||||
if(state.action == "create") {
|
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) {
|
if(error) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1,17 +1,19 @@
|
|||||||
define([
|
define([
|
||||||
|
"jquery",
|
||||||
"underscore",
|
"underscore",
|
||||||
"utils",
|
"utils",
|
||||||
|
"storage",
|
||||||
"classes/Provider",
|
"classes/Provider",
|
||||||
"eventMgr",
|
"eventMgr",
|
||||||
"helpers/googleHelper"
|
"helpers/googleHelper"
|
||||||
], function(_, utils, Provider, eventMgr, googleHelper) {
|
], function($, _, utils, storage, Provider, eventMgr, googleHelper) {
|
||||||
|
|
||||||
var PROVIDER_GPLUS = "gplus";
|
var PROVIDER_GPLUS = "gplus";
|
||||||
|
|
||||||
var gplusProvider = new Provider(PROVIDER_GPLUS, "Google+");
|
var gplusProvider = new Provider(PROVIDER_GPLUS, "Google+");
|
||||||
|
|
||||||
function getThumbnailUrl(doc, size) {
|
function getThumbnailUrl(doc, size) {
|
||||||
var result = undefined;
|
var result;
|
||||||
_.find(doc.thumbnails, function(thumbnail) {
|
_.find(doc.thumbnails, function(thumbnail) {
|
||||||
var found = false;
|
var found = false;
|
||||||
thumbnail.url.replace(/(.*\/s)\d.*?(\/[^\/]+)/, function(match, sub1, sub2) {
|
thumbnail.url.replace(/(.*\/s)\d.*?(\/[^\/]+)/, function(match, sub1, sub2) {
|
||||||
@ -23,12 +25,13 @@ define([
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
var imageDoc = undefined;
|
var imageDoc;
|
||||||
var importImagePreferences = utils.retrieveIgnoreError(PROVIDER_GPLUS + ".importImagePreferences");
|
var importImagePreferences = utils.retrieveIgnoreError(PROVIDER_GPLUS + ".importImagePreferences");
|
||||||
|
var importImageCallback;
|
||||||
function showImportImgDialog() {
|
function showImportImgDialog() {
|
||||||
if(!imageDoc.thumbnails) {
|
if(!imageDoc.thumbnails) {
|
||||||
eventMgr.onError("Image " + imageDoc.name + " is not accessible.");
|
eventMgr.onError("Image " + imageDoc.name + " is not accessible.");
|
||||||
callback(true);
|
importImageCallback(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
utils.resetModalInputs();
|
utils.resetModalInputs();
|
||||||
@ -43,7 +46,6 @@ define([
|
|||||||
$(".modal-import-image").modal();
|
$(".modal-import-image").modal();
|
||||||
}
|
}
|
||||||
|
|
||||||
var importImageCallback = undefined;
|
|
||||||
gplusProvider.importImage = function(callback) {
|
gplusProvider.importImage = function(callback) {
|
||||||
importImageCallback = callback;
|
importImageCallback = callback;
|
||||||
googleHelper.picker(function(error, docs) {
|
googleHelper.picker(function(error, docs) {
|
||||||
@ -77,7 +79,7 @@ define([
|
|||||||
};
|
};
|
||||||
|
|
||||||
eventMgr.addListener("onReady", function() {
|
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 size = utils.getInputIntValue("#input-import-image-size", undefined, 0) || 0;
|
||||||
var title = utils.getInputTextValue("#input-import-image-title");
|
var title = utils.getInputTextValue("#input-import-image-title");
|
||||||
var image = getThumbnailUrl(imageDoc, size);
|
var image = getThumbnailUrl(imageDoc, size);
|
||||||
@ -91,7 +93,7 @@ define([
|
|||||||
if(size) {
|
if(size) {
|
||||||
importImagePreferences.size = size;
|
importImagePreferences.size = size;
|
||||||
}
|
}
|
||||||
localStorage[PROVIDER_GPLUS + ".importImagePreferences"] = JSON.stringify(importImagePreferences);
|
storage[PROVIDER_GPLUS + ".importImagePreferences"] = JSON.stringify(importImagePreferences);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
define([
|
define([
|
||||||
"jquery",
|
"jquery",
|
||||||
"underscore",
|
"underscore",
|
||||||
|
"constants",
|
||||||
"utils",
|
"utils",
|
||||||
|
"storage",
|
||||||
"settings",
|
"settings",
|
||||||
"eventMgr",
|
"eventMgr",
|
||||||
"fileSystem",
|
"fileSystem",
|
||||||
@ -18,7 +20,7 @@ define([
|
|||||||
"providers/sshProvider",
|
"providers/sshProvider",
|
||||||
"providers/tumblrProvider",
|
"providers/tumblrProvider",
|
||||||
"providers/wordpressProvider"
|
"providers/wordpressProvider"
|
||||||
], function($, _, utils, settings, eventMgr, fileSystem, fileMgr, sharing, Provider, AsyncTask) {
|
], function($, _, constants, utils, storage, settings, eventMgr, fileSystem, fileMgr, sharing, Provider, AsyncTask) {
|
||||||
|
|
||||||
var publisher = {};
|
var publisher = {};
|
||||||
|
|
||||||
@ -30,11 +32,11 @@ define([
|
|||||||
];
|
];
|
||||||
}).compact().object().value();
|
}).compact().object().value();
|
||||||
|
|
||||||
// Retrieve publish locations from localStorage
|
// Retrieve publish locations from storage
|
||||||
_.each(fileSystem, function(fileDesc) {
|
_.each(fileSystem, function(fileDesc) {
|
||||||
_.each(utils.retrieveIndexArray(fileDesc.fileIndex + ".publish"), function(publishIndex) {
|
_.each(utils.retrieveIndexArray(fileDesc.fileIndex + ".publish"), function(publishIndex) {
|
||||||
try {
|
try {
|
||||||
var publishAttributes = JSON.parse(localStorage[publishIndex]);
|
var publishAttributes = JSON.parse(storage[publishIndex]);
|
||||||
// Store publishIndex
|
// Store publishIndex
|
||||||
publishAttributes.publishIndex = publishIndex;
|
publishAttributes.publishIndex = publishIndex;
|
||||||
// Replace provider ID by provider module in attributes
|
// Replace provider ID by provider module in attributes
|
||||||
@ -46,11 +48,11 @@ define([
|
|||||||
fileDesc.publishLocations[publishIndex] = publishAttributes;
|
fileDesc.publishLocations[publishIndex] = publishAttributes;
|
||||||
}
|
}
|
||||||
catch(e) {
|
catch(e) {
|
||||||
// localStorage can be corrupted
|
// storage can be corrupted
|
||||||
eventMgr.onError(e);
|
eventMgr.onError(e);
|
||||||
// Remove publish location
|
// Remove publish location
|
||||||
utils.removeIndexFromArray(fileDesc.fileIndex + ".publish", publishIndex);
|
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
|
// Recursive function to publish a file on multiple locations
|
||||||
var publishAttributesList = [];
|
var publishAttributesList = [];
|
||||||
var publishFileDesc = undefined;
|
var publishFileDesc;
|
||||||
var publishHTML = undefined;
|
var publishHTML;
|
||||||
function publishLocation(callback, errorFlag) {
|
function publishLocation(callback, errorFlag) {
|
||||||
|
|
||||||
// No more publish location for this document
|
// No more publish location for this document
|
||||||
@ -130,7 +132,7 @@ define([
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get the html from the onPreviewFinished callback
|
// Get the html from the onPreviewFinished callback
|
||||||
var previewHtml = undefined;
|
var previewHtml;
|
||||||
eventMgr.addListener("onPreviewFinished", function(html) {
|
eventMgr.addListener("onPreviewFinished", function(html) {
|
||||||
previewHtml = html;
|
previewHtml = html;
|
||||||
});
|
});
|
||||||
@ -164,17 +166,17 @@ define([
|
|||||||
|
|
||||||
// Generate a publishIndex associated to a file and store publishAttributes
|
// Generate a publishIndex associated to a file and store publishAttributes
|
||||||
function createPublishIndex(fileDesc, publishAttributes) {
|
function createPublishIndex(fileDesc, publishAttributes) {
|
||||||
var publishIndex = undefined;
|
var publishIndex;
|
||||||
do {
|
do {
|
||||||
publishIndex = "publish." + utils.randomString();
|
publishIndex = "publish." + utils.randomString();
|
||||||
} while (_.has(localStorage, publishIndex));
|
} while (_.has(storage, publishIndex));
|
||||||
publishAttributes.publishIndex = publishIndex;
|
publishAttributes.publishIndex = publishIndex;
|
||||||
fileDesc.addPublishLocation(publishAttributes);
|
fileDesc.addPublishLocation(publishAttributes);
|
||||||
eventMgr.onNewPublishSuccess(fileDesc, publishAttributes);
|
eventMgr.onNewPublishSuccess(fileDesc, publishAttributes);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize the "New publication" dialog
|
// Initialize the "New publication" dialog
|
||||||
var newLocationProvider = undefined;
|
var newLocationProvider;
|
||||||
function initNewLocation(provider) {
|
function initNewLocation(provider) {
|
||||||
var defaultPublishFormat = provider.defaultPublishFormat || "markdown";
|
var defaultPublishFormat = provider.defaultPublishFormat || "markdown";
|
||||||
newLocationProvider = provider;
|
newLocationProvider = provider;
|
||||||
@ -246,15 +248,9 @@ define([
|
|||||||
});
|
});
|
||||||
publishPreferences.format = publishAttributes.format;
|
publishPreferences.format = publishAttributes.format;
|
||||||
publishPreferences.customTmpl = publishAttributes.customTmpl;
|
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 = [
|
var initPublishButtonTmpl = [
|
||||||
'<li>',
|
'<li>',
|
||||||
' <a href="#"',
|
' <a href="#"',
|
||||||
@ -264,7 +260,7 @@ define([
|
|||||||
'</li>'
|
'</li>'
|
||||||
].join('');
|
].join('');
|
||||||
eventMgr.addListener("onReady", function() {
|
eventMgr.addListener("onReady", function() {
|
||||||
if(viewerMode === false) {
|
if(window.viewerMode === false) {
|
||||||
// Add every provider in the panel menu
|
// Add every provider in the panel menu
|
||||||
var publishMenuElt = document.querySelector('.menu-panel .collapse-publish-on .nav');
|
var publishMenuElt = document.querySelector('.menu-panel .collapse-publish-on .nav');
|
||||||
var publishMenuHtml = _.reduce(providerMap, function(result, provider) {
|
var publishMenuHtml = _.reduce(providerMap, function(result, provider) {
|
||||||
@ -326,7 +322,7 @@ define([
|
|||||||
customTmpl: settings.pdfTemplate
|
customTmpl: settings.pdfTemplate
|
||||||
}, previewHtml);
|
}, previewHtml);
|
||||||
var task = new AsyncTask();
|
var task = new AsyncTask();
|
||||||
var pdf = undefined;
|
var pdf;
|
||||||
task.onRun(function() {
|
task.onRun(function() {
|
||||||
if(isOffline === true) {
|
if(isOffline === true) {
|
||||||
eventMgr.onError("Operation not available in offline mode.");
|
eventMgr.onError("Operation not available in offline mode.");
|
||||||
@ -334,7 +330,7 @@ define([
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var xhr = new XMLHttpRequest();
|
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('Content-type', 'application/x-www-form-urlencoded');
|
||||||
xhr.setRequestHeader('page-size', settings.pdfPageSize);
|
xhr.setRequestHeader('page-size', settings.pdfPageSize);
|
||||||
xhr.responseType = 'blob';
|
xhr.responseType = 'blob';
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
define([
|
define([
|
||||||
"underscore",
|
"underscore",
|
||||||
|
"constants",
|
||||||
|
"storage",
|
||||||
"config",
|
"config",
|
||||||
"storage"
|
], function (_, constants, storage) {
|
||||||
], function(_) {
|
|
||||||
|
|
||||||
var settings = {
|
var settings = {
|
||||||
layoutOrientation: "horizontal",
|
layoutOrientation: "horizontal",
|
||||||
@ -10,8 +11,8 @@ define([
|
|||||||
editorFontFamily: 'Menlo, Consolas, "Courier New", Courier, monospace',
|
editorFontFamily: 'Menlo, Consolas, "Courier New", Courier, monospace',
|
||||||
editorFontSize: 12,
|
editorFontSize: 12,
|
||||||
maxWidth: 960,
|
maxWidth: 960,
|
||||||
defaultContent: "\n\n\n> Written with [StackEdit](" + MAIN_URL + ").",
|
defaultContent: "\n\n\n> Written with [StackEdit](" + constants.MAIN_URL + ").",
|
||||||
commitMsg: "Published with " + MAIN_URL,
|
commitMsg: "Published with " + constants.MAIN_URL,
|
||||||
gdriveFullAccess: true,
|
gdriveFullAccess: true,
|
||||||
template: [
|
template: [
|
||||||
'<!DOCTYPE html>\n',
|
'<!DOCTYPE html>\n',
|
||||||
@ -20,10 +21,10 @@ define([
|
|||||||
'<meta charset="utf-8">\n',
|
'<meta charset="utf-8">\n',
|
||||||
'<title><%= documentTitle %></title>\n',
|
'<title><%= documentTitle %></title>\n',
|
||||||
'<link rel="stylesheet" href="',
|
'<link rel="stylesheet" href="',
|
||||||
MAIN_URL,
|
constants.MAIN_URL,
|
||||||
'res-min/themes/default.css" />\n',
|
'res-min/themes/default.css" />\n',
|
||||||
'<script type="text/javascript" src="',
|
'<script type="text/javascript" src="',
|
||||||
MAIN_URL,
|
constants.MAIN_URL,
|
||||||
'libs/MathJax/MathJax.js?config=TeX-AMS_HTML"></script>\n',
|
'libs/MathJax/MathJax.js?config=TeX-AMS_HTML"></script>\n',
|
||||||
'</head>\n',
|
'</head>\n',
|
||||||
'<body><div class="container"><%= documentHTML %></div></body>\n',
|
'<body><div class="container"><%= documentHTML %></div></body>\n',
|
||||||
@ -36,28 +37,28 @@ define([
|
|||||||
'<meta charset="utf-8">\n',
|
'<meta charset="utf-8">\n',
|
||||||
'<title><%= documentTitle %></title>\n',
|
'<title><%= documentTitle %></title>\n',
|
||||||
'<link rel="stylesheet" href="',
|
'<link rel="stylesheet" href="',
|
||||||
MAIN_URL,
|
constants.MAIN_URL,
|
||||||
'res-min/themes/default.css" />\n',
|
'res-min/themes/default.css" />\n',
|
||||||
'<script type="text/x-mathjax-config">\n',
|
'<script type="text/x-mathjax-config">\n',
|
||||||
'MathJax.Hub.Config({ messageStyle: "none" });\n',
|
'MathJax.Hub.Config({ messageStyle: "none" });\n',
|
||||||
'</script>\n',
|
'</script>\n',
|
||||||
'<script type="text/javascript" src="',
|
'<script type="text/javascript" src="',
|
||||||
MAIN_URL,
|
constants.MAIN_URL,
|
||||||
'libs/MathJax/MathJax.js?config=TeX-AMS_HTML"></script>\n',
|
'libs/MathJax/MathJax.js?config=TeX-AMS_HTML"></script>\n',
|
||||||
'</head>\n',
|
'</head>\n',
|
||||||
'<body class="pdf"><%= documentHTML %></body>\n',
|
'<body class="pdf"><%= documentHTML %></body>\n',
|
||||||
'</html>'
|
'</html>'
|
||||||
].join(""),
|
].join(""),
|
||||||
pdfPageSize: 'A4',
|
pdfPageSize: 'A4',
|
||||||
sshProxy: SSH_PROXY_URL,
|
sshProxy: constants.SSH_PROXY_URL,
|
||||||
shortcuts: {},
|
shortcuts: {},
|
||||||
extensionSettings: {}
|
extensionSettings: {}
|
||||||
};
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
_.extend(settings, JSON.parse(localStorage.settings));
|
_.extend(settings, JSON.parse(storage.settings));
|
||||||
}
|
}
|
||||||
catch(e) {
|
catch (e) {
|
||||||
// Ignore parsing error
|
// Ignore parsing error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
define([
|
define([
|
||||||
"jquery",
|
"jquery",
|
||||||
"underscore",
|
"underscore",
|
||||||
|
"constants",
|
||||||
"utils",
|
"utils",
|
||||||
"eventMgr",
|
"eventMgr",
|
||||||
"fileMgr",
|
"fileMgr",
|
||||||
@ -8,7 +9,7 @@ define([
|
|||||||
"classes/Provider",
|
"classes/Provider",
|
||||||
"providers/downloadProvider",
|
"providers/downloadProvider",
|
||||||
"providers/gistProvider"
|
"providers/gistProvider"
|
||||||
], function($, _, utils, eventMgr, fileMgr, AsyncTask, Provider) {
|
], function($, _, constants, utils, eventMgr, fileMgr, AsyncTask, Provider) {
|
||||||
|
|
||||||
var sharing = {};
|
var sharing = {};
|
||||||
|
|
||||||
@ -30,21 +31,21 @@ define([
|
|||||||
var provider = providerMap[attributes.provider.providerId];
|
var provider = providerMap[attributes.provider.providerId];
|
||||||
// Don't create link if link already exists or provider is not
|
// Don't create link if link already exists or provider is not
|
||||||
// compatible for sharing
|
// compatible for sharing
|
||||||
if(attributes.sharingLink !== undefined || provider === undefined
|
if(attributes.sharingLink !== undefined || provider === undefined ||
|
||||||
// Or document is not published in markdown format
|
// Or document is not published in markdown format
|
||||||
|| attributes.format != "markdown") {
|
attributes.format != "markdown") {
|
||||||
callback();
|
callback();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var task = new AsyncTask();
|
var task = new AsyncTask();
|
||||||
var shortUrl = undefined;
|
var shortUrl;
|
||||||
task.onRun(function() {
|
task.onRun(function() {
|
||||||
if(isOffline === true) {
|
if(isOffline === true) {
|
||||||
task.chain();
|
task.chain();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var url = [
|
var url = [
|
||||||
MAIN_URL,
|
constants.MAIN_URL,
|
||||||
'viewer#!provider=',
|
'viewer#!provider=',
|
||||||
provider.providerId
|
provider.providerId
|
||||||
];
|
];
|
||||||
@ -56,7 +57,7 @@ define([
|
|||||||
});
|
});
|
||||||
url = url.join("");
|
url = url.join("");
|
||||||
$.getJSON("https://api-ssl.bitly.com/v3/shorten", {
|
$.getJSON("https://api-ssl.bitly.com/v3/shorten", {
|
||||||
"access_token": BITLY_ACCESS_TOKEN,
|
"access_token": constants.BITLY_ACCESS_TOKEN,
|
||||||
"longUrl": url
|
"longUrl": url
|
||||||
}, function(response) {
|
}, function(response) {
|
||||||
if(response.data) {
|
if(response.data) {
|
||||||
@ -79,7 +80,7 @@ define([
|
|||||||
};
|
};
|
||||||
|
|
||||||
eventMgr.addListener("onReady", function() {
|
eventMgr.addListener("onReady", function() {
|
||||||
if(viewerMode === false) {
|
if(window.viewerMode === false) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Check parameters to see if we have to download a shared document
|
// Check parameters to see if we have to download a shared document
|
||||||
|
@ -4,7 +4,7 @@ define([
|
|||||||
"settings",
|
"settings",
|
||||||
"utils",
|
"utils",
|
||||||
"text!html/settingsShortcutEntry.html",
|
"text!html/settingsShortcutEntry.html",
|
||||||
], function(_, eventMgr, settings, utils, settingsShortcutEntryHTML) {
|
], function(_, eventMgr, settings, utils, settingsShortcutEntryHTML) {
|
||||||
|
|
||||||
var shortcutMgr = {};
|
var shortcutMgr = {};
|
||||||
|
|
||||||
|
@ -1,13 +1,23 @@
|
|||||||
// Setup an empty localStorage or upgrade an existing one
|
// Setup an empty localStorage or upgrade an existing one
|
||||||
define([
|
define([
|
||||||
"underscore",
|
"underscore"
|
||||||
"utils"
|
], function(_) {
|
||||||
], function(_, utils) {
|
|
||||||
|
|
||||||
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
|
// localStorage versioning
|
||||||
var version = localStorage["version"];
|
var version = localStorage.version;
|
||||||
|
|
||||||
// Upgrade from v0 to v1
|
// Upgrade from v0 to v1
|
||||||
if(version === undefined) {
|
if(version === undefined) {
|
||||||
@ -19,7 +29,7 @@ define([
|
|||||||
|
|
||||||
_.each(fileIndexList, function(fileIndex) {
|
_.each(fileIndexList, function(fileIndex) {
|
||||||
localStorage[fileIndex + ".publish"] = ";";
|
localStorage[fileIndex + ".publish"] = ";";
|
||||||
var syncIndexList = utils.retrieveIndexArray(fileIndex + ".sync");
|
var syncIndexList = retrieveIndexArray(fileIndex + ".sync");
|
||||||
_.each(syncIndexList, function(syncIndex) {
|
_.each(syncIndexList, function(syncIndex) {
|
||||||
localStorage[syncIndex + ".contentCRC"] = "0";
|
localStorage[syncIndex + ".contentCRC"] = "0";
|
||||||
// We store title CRC only for Google Drive synchronization
|
// We store title CRC only for Google Drive synchronization
|
||||||
@ -49,7 +59,7 @@ define([
|
|||||||
var SYNC_PROVIDER_GDRIVE = "sync." + PROVIDER_GDRIVE + ".";
|
var SYNC_PROVIDER_GDRIVE = "sync." + PROVIDER_GDRIVE + ".";
|
||||||
var SYNC_PROVIDER_DROPBOX = "sync." + PROVIDER_DROPBOX + ".";
|
var SYNC_PROVIDER_DROPBOX = "sync." + PROVIDER_DROPBOX + ".";
|
||||||
_.each(fileIndexList, function(fileIndex) {
|
_.each(fileIndexList, function(fileIndex) {
|
||||||
var syncIndexList = utils.retrieveIndexArray(fileIndex + ".sync");
|
var syncIndexList = retrieveIndexArray(fileIndex + ".sync");
|
||||||
_.each(syncIndexList, function(syncIndex) {
|
_.each(syncIndexList, function(syncIndex) {
|
||||||
var syncAttributes = {};
|
var syncAttributes = {};
|
||||||
if(syncIndex.indexOf(SYNC_PROVIDER_GDRIVE) === 0) {
|
if(syncIndex.indexOf(SYNC_PROVIDER_GDRIVE) === 0) {
|
||||||
@ -82,7 +92,7 @@ define([
|
|||||||
localStorage.removeItem(fileIndex + ".title");
|
localStorage.removeItem(fileIndex + ".title");
|
||||||
localStorage.removeItem(fileIndex + ".publish");
|
localStorage.removeItem(fileIndex + ".publish");
|
||||||
localStorage.removeItem(fileIndex + ".content");
|
localStorage.removeItem(fileIndex + ".content");
|
||||||
utils.removeIndexFromArray("file.list", fileIndex);
|
localStorage["file.list"].replace(";" + fileIndex + ";", ";");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
version = "v3";
|
version = "v3";
|
||||||
@ -90,7 +100,7 @@ define([
|
|||||||
|
|
||||||
// Upgrade from v3 to v4
|
// Upgrade from v3 to v4
|
||||||
if(version == "v3") {
|
if(version == "v3") {
|
||||||
var currentFileIndex = localStorage["file.current"];
|
currentFileIndex = localStorage["file.current"];
|
||||||
if(currentFileIndex !== undefined && localStorage["file.list"].indexOf(";" + currentFileIndex + ";") === -1) {
|
if(currentFileIndex !== undefined && localStorage["file.list"].indexOf(";" + currentFileIndex + ";") === -1) {
|
||||||
localStorage.removeItem("file.current");
|
localStorage.removeItem("file.current");
|
||||||
}
|
}
|
||||||
@ -107,7 +117,7 @@ define([
|
|||||||
// Upgrade from v5 to v6
|
// Upgrade from v5 to v6
|
||||||
if(version == "v5") {
|
if(version == "v5") {
|
||||||
_.each(fileIndexList, function(fileIndex) {
|
_.each(fileIndexList, function(fileIndex) {
|
||||||
var publishIndexList = utils.retrieveIndexArray(fileIndex + ".publish");
|
var publishIndexList = retrieveIndexArray(fileIndex + ".publish");
|
||||||
_.each(publishIndexList, function(publishIndex) {
|
_.each(publishIndexList, function(publishIndex) {
|
||||||
var publishAttributes = JSON.parse(localStorage[publishIndex]);
|
var publishAttributes = JSON.parse(localStorage[publishIndex]);
|
||||||
if(publishAttributes.provider == "gdrive") {
|
if(publishAttributes.provider == "gdrive") {
|
||||||
@ -123,7 +133,7 @@ define([
|
|||||||
|
|
||||||
// Upgrade from v6 to v7
|
// Upgrade from v6 to v7
|
||||||
if(version == "v6") {
|
if(version == "v6") {
|
||||||
var currentFileIndex = localStorage["file.current"];
|
currentFileIndex = localStorage["file.current"];
|
||||||
if(currentFileIndex !== undefined) {
|
if(currentFileIndex !== undefined) {
|
||||||
localStorage[currentFileIndex + ".selectTime"] = new Date().getTime();
|
localStorage[currentFileIndex + ".selectTime"] = new Date().getTime();
|
||||||
localStorage.removeItem("file.current");
|
localStorage.removeItem("file.current");
|
||||||
@ -158,7 +168,7 @@ define([
|
|||||||
// Upgrade from v9 to v10
|
// Upgrade from v9 to v10
|
||||||
if(version == "v9") {
|
if(version == "v9") {
|
||||||
if(_.has(localStorage, 'settings')) {
|
if(_.has(localStorage, 'settings')) {
|
||||||
var settings = JSON.parse(localStorage.settings);
|
settings = JSON.parse(localStorage.settings);
|
||||||
delete settings.editorFontFamily;
|
delete settings.editorFontFamily;
|
||||||
delete settings.editorFontSize;
|
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'));
|
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
|
// Upgrade from v10 to v11
|
||||||
if(version == "v10") {
|
if(version == "v10") {
|
||||||
if(_.has(localStorage, 'settings')) {
|
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.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.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/'));
|
settings.template && (settings.template = settings.template.replace('http://benweet.github.io/stackedit/lib/', 'https://stackedit.io/libs/'));
|
||||||
@ -184,5 +194,6 @@ define([
|
|||||||
version = "v11";
|
version = "v11";
|
||||||
}
|
}
|
||||||
|
|
||||||
localStorage["version"] = version;
|
localStorage.version = version;
|
||||||
|
return localStorage;
|
||||||
});
|
});
|
@ -2,13 +2,14 @@ define([
|
|||||||
"jquery",
|
"jquery",
|
||||||
"underscore",
|
"underscore",
|
||||||
"utils",
|
"utils",
|
||||||
|
"storage",
|
||||||
"eventMgr",
|
"eventMgr",
|
||||||
"fileSystem",
|
"fileSystem",
|
||||||
"fileMgr",
|
"fileMgr",
|
||||||
"classes/Provider",
|
"classes/Provider",
|
||||||
"providers/dropboxProvider",
|
"providers/dropboxProvider",
|
||||||
"providers/gdriveProvider"
|
"providers/gdriveProvider"
|
||||||
], function($, _, utils, eventMgr, fileSystem, fileMgr, Provider) {
|
], function($, _, utils, storage, eventMgr, fileSystem, fileMgr, Provider) {
|
||||||
|
|
||||||
var synchronizer = {};
|
var synchronizer = {};
|
||||||
|
|
||||||
@ -20,11 +21,11 @@ define([
|
|||||||
];
|
];
|
||||||
}).compact().object().value();
|
}).compact().object().value();
|
||||||
|
|
||||||
// Retrieve sync locations from localStorage
|
// Retrieve sync locations from storage
|
||||||
_.each(fileSystem, function(fileDesc) {
|
_.each(fileSystem, function(fileDesc) {
|
||||||
_.each(utils.retrieveIndexArray(fileDesc.fileIndex + ".sync"), function(syncIndex) {
|
_.each(utils.retrieveIndexArray(fileDesc.fileIndex + ".sync"), function(syncIndex) {
|
||||||
try {
|
try {
|
||||||
var syncAttributes = JSON.parse(localStorage[syncIndex]);
|
var syncAttributes = JSON.parse(storage[syncIndex]);
|
||||||
// Store syncIndex
|
// Store syncIndex
|
||||||
syncAttributes.syncIndex = syncIndex;
|
syncAttributes.syncIndex = syncIndex;
|
||||||
// Replace provider ID by provider module in attributes
|
// Replace provider ID by provider module in attributes
|
||||||
@ -36,11 +37,11 @@ define([
|
|||||||
fileDesc.syncLocations[syncIndex] = syncAttributes;
|
fileDesc.syncLocations[syncIndex] = syncAttributes;
|
||||||
}
|
}
|
||||||
catch(e) {
|
catch(e) {
|
||||||
// localStorage can be corrupted
|
// storage can be corrupted
|
||||||
eventMgr.onError(e);
|
eventMgr.onError(e);
|
||||||
// Remove sync location
|
// Remove sync location
|
||||||
utils.removeIndexFromArray(fileDesc.fileIndex + ".sync", syncIndex);
|
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
|
// Recursive function to upload a single file on multiple locations
|
||||||
var uploadSyncAttributesList = [];
|
var uploadSyncAttributesList = [];
|
||||||
var uploadContent = undefined;
|
var uploadContent;
|
||||||
var uploadContentCRC = undefined;
|
var uploadContentCRC;
|
||||||
var uploadTitle = undefined;
|
var uploadTitle;
|
||||||
var uploadTitleCRC = undefined;
|
var uploadTitleCRC;
|
||||||
function locationUp(callback) {
|
function locationUp(callback) {
|
||||||
|
|
||||||
// No more synchronized location for this document
|
// No more synchronized location for this document
|
||||||
@ -92,7 +93,7 @@ define([
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(uploadFlag) {
|
if(uploadFlag) {
|
||||||
// Update syncAttributes in localStorage
|
// Update syncAttributes in storage
|
||||||
utils.storeAttributes(syncAttributes);
|
utils.storeAttributes(syncAttributes);
|
||||||
}
|
}
|
||||||
locationUp(callback);
|
locationUp(callback);
|
||||||
@ -216,8 +217,8 @@ define([
|
|||||||
* Realtime synchronization
|
* Realtime synchronization
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
var realtimeFileDesc = undefined;
|
var realtimeFileDesc;
|
||||||
var realtimeSyncAttributes = undefined;
|
var realtimeSyncAttributes;
|
||||||
var isOnline = true;
|
var isOnline = true;
|
||||||
|
|
||||||
// Determines if open file has real time sync location and tries to start
|
// Determines if open file has real time sync location and tries to start
|
||||||
@ -259,7 +260,7 @@ define([
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Triggers realtime synchronization from eventMgr events
|
// Triggers realtime synchronization from eventMgr events
|
||||||
if(viewerMode === false) {
|
if(window.viewerMode === false) {
|
||||||
eventMgr.addListener("onFileOpen", onFileOpen);
|
eventMgr.addListener("onFileOpen", onFileOpen);
|
||||||
eventMgr.addListener("onFileClosed", synchronizer.tryStopRealtimeSync);
|
eventMgr.addListener("onFileClosed", synchronizer.tryStopRealtimeSync);
|
||||||
eventMgr.addListener("onOfflineChanged", onOfflineChanged);
|
eventMgr.addListener("onOfflineChanged", onOfflineChanged);
|
||||||
@ -355,7 +356,7 @@ define([
|
|||||||
exportPreferences[inputId] = inputElt.value;
|
exportPreferences[inputId] = inputElt.value;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
localStorage[provider.providerId + ".exportPreferences"] = JSON.stringify(exportPreferences);
|
storage[provider.providerId + ".exportPreferences"] = JSON.stringify(exportPreferences);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -1,11 +1,12 @@
|
|||||||
define([
|
define([
|
||||||
"jquery",
|
"jquery",
|
||||||
"underscore",
|
"underscore",
|
||||||
|
"storage",
|
||||||
"crel",
|
"crel",
|
||||||
"xregexp",
|
"xregexp",
|
||||||
"FileSaver",
|
|
||||||
"stacktrace",
|
"stacktrace",
|
||||||
], function($, _, crel, XRegExp) {
|
"FileSaver",
|
||||||
|
], function($, _, storage, crel, XRegExp, printStackTrace, saveAs) {
|
||||||
|
|
||||||
var utils = {};
|
var utils = {};
|
||||||
|
|
||||||
@ -106,7 +107,9 @@ define([
|
|||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
/*jshint evil:true */
|
||||||
eval("var test=" + value);
|
eval("var test=" + value);
|
||||||
|
/*jshint evil:false */
|
||||||
}
|
}
|
||||||
catch(e) {
|
catch(e) {
|
||||||
inputError(element, event);
|
inputError(element, event);
|
||||||
@ -241,41 +244,41 @@ define([
|
|||||||
};
|
};
|
||||||
utils.updateCurrentTime();
|
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) {
|
utils.storeAttributes = function(attributes) {
|
||||||
var storeIndex = attributes.syncIndex || attributes.publishIndex;
|
var storeIndex = attributes.syncIndex || attributes.publishIndex;
|
||||||
// Don't store sync/publish index
|
// Don't store sync/publish index
|
||||||
var storedAttributes = _.omit(attributes, "syncIndex", "publishIndex", "provider");
|
var storedAttributes = _.omit(attributes, "syncIndex", "publishIndex", "provider");
|
||||||
// Store providerId instead of provider
|
// Store providerId instead of provider
|
||||||
storedAttributes.provider = attributes.provider.providerId;
|
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) {
|
utils.retrieveIndexArray = function(storeIndex) {
|
||||||
try {
|
try {
|
||||||
return _.compact(localStorage[storeIndex].split(";"));
|
return _.compact(storage[storeIndex].split(";"));
|
||||||
}
|
}
|
||||||
catch(e) {
|
catch(e) {
|
||||||
localStorage[storeIndex] = ";";
|
storage[storeIndex] = ";";
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Append an index to an array in localStorage
|
// Append an index to an array in storage
|
||||||
utils.appendIndexToArray = function(storeIndex, index) {
|
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) {
|
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) {
|
utils.retrieveIgnoreError = function(storeIndex) {
|
||||||
try {
|
try {
|
||||||
return JSON.parse(localStorage[storeIndex]);
|
return JSON.parse(storage[storeIndex]);
|
||||||
}
|
}
|
||||||
catch(e) {
|
catch(e) {
|
||||||
return undefined;
|
return undefined;
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
var isConfigured = false
|
/*jshint worker:true */
|
||||||
|
var isConfigured = false;
|
||||||
|
|
||||||
|
/*jshint evil:true, unused:false */
|
||||||
self.onmessage = function(e) {
|
self.onmessage = function(e) {
|
||||||
if(isConfigured === false) {
|
if(isConfigured === false) {
|
||||||
eval(e.data);
|
eval(e.data);
|
||||||
@ -10,3 +13,4 @@ self.onmessage = function(e) {
|
|||||||
self[functionName].apply(this, data);
|
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) {
|
self.init = function(typoJS, LZString, lang, aff, dic) {
|
||||||
eval([
|
eval([
|
||||||
typoJS,
|
typoJS,
|
||||||
@ -9,8 +11,9 @@ self.init = function(typoJS, LZString, lang, aff, dic) {
|
|||||||
'dictionary = new Typo(lang, aff, dic);'
|
'dictionary = new Typo(lang, aff, dic);'
|
||||||
].join('\n'));
|
].join('\n'));
|
||||||
};
|
};
|
||||||
|
/*jshint evil:false, unused:true */
|
||||||
|
|
||||||
var timeoutId = undefined;
|
var timeoutId;
|
||||||
self.check = function(words) {
|
self.check = function(words) {
|
||||||
// Check function has priority over Suggest function
|
// Check function has priority over Suggest function
|
||||||
// This prevents Suggest to run if called just before Check
|
// This prevents Suggest to run if called just before Check
|
||||||
@ -22,7 +25,7 @@ self.check = function(words) {
|
|||||||
postMessage(JSON.stringify(['check', words]));
|
postMessage(JSON.stringify(['check', words]));
|
||||||
};
|
};
|
||||||
|
|
||||||
var word = undefined;
|
var word;
|
||||||
|
|
||||||
function delayedSuggest() {
|
function delayedSuggest() {
|
||||||
timeoutId = undefined;
|
timeoutId = undefined;
|
||||||
|
@ -13,12 +13,12 @@
|
|||||||
/>
|
/>
|
||||||
<script>
|
<script>
|
||||||
// Use ?debug to serve original JavaScript files instead of minified
|
// Use ?debug to serve original JavaScript files instead of minified
|
||||||
var baseDir = 'res';
|
window.baseDir = 'res';
|
||||||
if (!/(\?|&)debug($|&)/.test(location.search)) {
|
if (!/(\?|&)debug($|&)/.test(location.search)) {
|
||||||
baseDir += '-min';
|
window.baseDir += '-min';
|
||||||
}
|
}
|
||||||
var require = {
|
window.require = {
|
||||||
baseUrl: baseDir,
|
baseUrl: window.baseDir,
|
||||||
deps: ['main']
|
deps: ['main']
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
Loading…
Reference in New Issue
Block a user