Import files from disk
This commit is contained in:
parent
e5cc6e907b
commit
835ec4da5a
@ -635,6 +635,12 @@ input[type="file"] {
|
||||
color: #bbb;
|
||||
}
|
||||
|
||||
#modal-import-harddrive-html textarea {
|
||||
width: 500px;
|
||||
max-width: 500px;
|
||||
height: 100px;
|
||||
}
|
||||
|
||||
#md-section-helper {
|
||||
position: absolute;
|
||||
top: -100px;
|
||||
|
36
index.html
36
index.html
@ -71,11 +71,12 @@
|
||||
class="icon-hdd"></i> Open from...</a>
|
||||
<ul class="dropdown-menu">
|
||||
<li><a data-toggle="modal"
|
||||
data-target="#modal-import-harddrive-markdown" class="action-reset-input"
|
||||
href="#">Import from hard drive</a></li>
|
||||
data-target="#modal-import-harddrive-markdown"
|
||||
class="action-reset-input" href="#">Import from hard drive</a></li>
|
||||
<li><a data-toggle="modal"
|
||||
data-target="#modal-import-harddrive-html" class="action-reset-input"
|
||||
href="#">Convert HTML to Markdown</a></li>
|
||||
data-target="#modal-import-harddrive-html"
|
||||
class="action-reset-input" href="#">Convert HTML to
|
||||
Markdown</a></li>
|
||||
</ul></li>
|
||||
<li class="dropdown-submenu"><a href="#"><i
|
||||
class="icon-hdd"></i> Save as...</a>
|
||||
@ -244,10 +245,12 @@
|
||||
<h3>Import from hard drive</h3>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<p>Please select the Markdown files to import:</p>
|
||||
<p><input type="file" id="input-file-import-harddrive-markdown" multiple /></p>
|
||||
<p>Or drag and drop the Markdown files here:</p>
|
||||
<div id="dropzone-import-harddrive-markdown" class="drop-zone">Drop zone</div>
|
||||
<p>Please select your Markdown files here:</p>
|
||||
<p><input type="file" id="input-file-import-harddrive-markdown"
|
||||
multiple /></p>
|
||||
<p>Or drag and drop your Markdown files here:</p>
|
||||
<p id="dropzone-import-harddrive-markdown" class="drop-zone">Drop
|
||||
files here</p>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<a href="#" class="btn btn-primary" data-dismiss="modal">Close</a>
|
||||
@ -258,16 +261,21 @@
|
||||
<div class="modal-header">
|
||||
<button type="button" class="close" data-dismiss="modal"
|
||||
aria-hidden="true">×</button>
|
||||
<h3>Import from hard drive</h3>
|
||||
<h3>Convert HTML to Markdown</h3>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<p>Please select the HTML files to import:</p>
|
||||
<p><input type="file" id="input-file-import-harddrive-html" multiple /></p>
|
||||
<p>Or drag and drop the HTML files here:</p>
|
||||
<div id="dropzone-import-harddrive-html" class="drop-zone">Drop zone</div>
|
||||
<p>Please select your HTML files here:</p>
|
||||
<p><input type="file" id="input-file-import-harddrive-html"
|
||||
multiple /></p>
|
||||
<p>Or drag and drop your HTML files here:</p>
|
||||
<p id="dropzone-import-harddrive-html" class="drop-zone">Drop
|
||||
files here</p>
|
||||
<p>Or insert your HTML code here:</p> <textarea id="input-convert-html"></textarea>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<a href="#" class="btn btn-primary" data-dismiss="modal">Close</a>
|
||||
<a href="#" class="btn" data-dismiss="modal">Close</a> <a
|
||||
href="#" class="btn btn-primary action-convert-html"
|
||||
data-dismiss="modal">OK</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
@ -13,7 +13,6 @@ define([
|
||||
this.finished = false;
|
||||
this.timeout = ASYNC_TASK_DEFAULT_TIMEOUT;
|
||||
this.retryCounter = 0;
|
||||
this.callPath = [];
|
||||
this.runCallbacks = [];
|
||||
this.successCallbacks = [];
|
||||
this.errorCallbacks = [];
|
||||
@ -50,7 +49,7 @@ define([
|
||||
* onRun callback during execution, bypassing the onRun queue.
|
||||
*/
|
||||
AsyncTask.prototype.chain = function(callback) {
|
||||
this.callPath.unshift(printStackTrace()[5]);
|
||||
utils.logStackTrace();
|
||||
if(this.finished === true) {
|
||||
return;
|
||||
}
|
||||
@ -80,11 +79,11 @@ define([
|
||||
* ends the task by throwing an exception.
|
||||
*/
|
||||
AsyncTask.prototype.error = function(error) {
|
||||
this.callPath.unshift(printStackTrace()[5]);
|
||||
utils.logStackTrace();
|
||||
if(this.finished === true) {
|
||||
return;
|
||||
}
|
||||
error = error || new Error("Unknown error|\n" + this.callPath.join("\n"));
|
||||
error = error || new Error("Unknown error");
|
||||
if(error.message) {
|
||||
extensionMgr.onError(error);
|
||||
}
|
||||
@ -110,7 +109,6 @@ define([
|
||||
var delay = Math.pow(2, this.retryCounter++) * 1000;
|
||||
currentTaskStartTime = utils.currentTime + delay;
|
||||
currentTaskRunning = false;
|
||||
this.callPath = [];
|
||||
runTask();
|
||||
};
|
||||
|
||||
@ -136,7 +134,7 @@ define([
|
||||
if(currentTaskRunning === true) {
|
||||
// If the current task takes too long
|
||||
if(currentTaskStartTime + currentTask.timeout < utils.currentTime) {
|
||||
currentTask.error(new Error("A timeout occurred.|\n" + currentTask.callPath.join("\n")));
|
||||
currentTask.error(new Error("A timeout occurred."));
|
||||
}
|
||||
return;
|
||||
}
|
||||
@ -163,7 +161,8 @@ define([
|
||||
}
|
||||
});
|
||||
}
|
||||
// Run runTask function periodically
|
||||
|
||||
// Call runTask function periodically
|
||||
core.addPeriodicCallback(runTask);
|
||||
|
||||
function runSafe(task, callbacks, param) {
|
||||
|
@ -27,6 +27,7 @@ define([
|
||||
"Prettify": "https://code.google.com/p/google-code-prettify/",
|
||||
"RequireJS": "http://requirejs.org/",
|
||||
"stacktrace.js": "http://stacktracejs.com/",
|
||||
"to-markdown": "https://github.com/domchristie/to-markdown",
|
||||
"UI Layout": "http://layout.jquery-dev.net/",
|
||||
"Underscore.js": "http://underscorejs.org/",
|
||||
"waitForImages": "https://github.com/alexanderdickson/waitForImages"
|
||||
|
@ -43,7 +43,7 @@ define([
|
||||
}));
|
||||
lineElement.append($(removeButtonTemplate).click(function() {
|
||||
fileDesc.removePublishLocation(publishAttributes);
|
||||
extensionMgr.onPublishRemoved(publishFileDesc, publishAttributes);
|
||||
extensionMgr.onPublishRemoved(fileDesc, publishAttributes);
|
||||
}));
|
||||
publishList.append(lineElement);
|
||||
});
|
||||
|
@ -1,14 +1,15 @@
|
||||
define([
|
||||
"jquery",
|
||||
"underscore",
|
||||
"utils",
|
||||
"toMarkdown",
|
||||
"config",
|
||||
], function($, _, toMarkdown) {
|
||||
], function($, _, utils, toMarkdown) {
|
||||
|
||||
var dialogOpenHarddrive = {
|
||||
extensionId: "dialogOpenHarddrive",
|
||||
extensionName: 'Dialog "Open from"',
|
||||
settingsBloc: '<p>Handles the "Open from hard drive" and the "Convert HTML to Markdown" dialog boxes.</p>'
|
||||
settingsBloc: '<p>Handles the "Import from hard drive" and the "Convert HTML to Markdown" dialog boxes.</p>'
|
||||
};
|
||||
|
||||
var fileMgr = undefined;
|
||||
@ -87,6 +88,19 @@ define([
|
||||
this.addEventListener('dragover', handleDragOver, false);
|
||||
this.addEventListener('drop', handleHtmlImport, false);
|
||||
});
|
||||
$(".action-convert-html").click(function(e) {
|
||||
var content = utils.getInputTextValue("#input-convert-html", e);
|
||||
if(content === undefined) {
|
||||
return;
|
||||
}
|
||||
content = converter.makeMd(content);
|
||||
if(content === undefined) {
|
||||
extensionMgr.onError(importedFile.name + " is not a valid HTML file.");
|
||||
return;
|
||||
}
|
||||
var fileDesc = fileMgr.createFile(undefined, content);
|
||||
fileMgr.selectFile(fileDesc);
|
||||
});
|
||||
};
|
||||
|
||||
return dialogOpenHarddrive;
|
||||
|
@ -1,9 +1,10 @@
|
||||
define([
|
||||
"jquery",
|
||||
"underscore",
|
||||
"utils",
|
||||
"settings",
|
||||
"config",
|
||||
], function($, _, settings) {
|
||||
], function($, _, utils, settings) {
|
||||
|
||||
var googleAnalytics = {
|
||||
extensionId: "googleAnalytics",
|
||||
@ -31,6 +32,19 @@ define([
|
||||
}
|
||||
};
|
||||
|
||||
var lastPageView = 0;
|
||||
function trackPageView() {
|
||||
if(utils.currentTime - lastPageView > 180000) {
|
||||
_gaq.push([
|
||||
'_trackPageview'
|
||||
]);
|
||||
lastPageView = utils.currentTime;
|
||||
}
|
||||
}
|
||||
googleAnalytics.onPeriodicRun = function() {
|
||||
trackPageView();
|
||||
};
|
||||
|
||||
googleAnalytics.onReady = function() {
|
||||
|
||||
// First configure GA
|
||||
@ -38,9 +52,7 @@ define([
|
||||
'_setAccount',
|
||||
GOOGLE_ANALYTICS_ACCOUNT_ID
|
||||
]);
|
||||
_gaq.push([
|
||||
'_trackPageview'
|
||||
]);
|
||||
trackPageView();
|
||||
|
||||
// Collect informations about user settings
|
||||
_gaq.push([
|
||||
@ -96,8 +108,8 @@ define([
|
||||
_gaq.push([
|
||||
"_trackEvent",
|
||||
"Error",
|
||||
url,
|
||||
message + " (" + line + ")"
|
||||
message,
|
||||
url + ":" + line + utils.formatEventList()
|
||||
]);
|
||||
};
|
||||
|
||||
@ -195,7 +207,7 @@ define([
|
||||
'_trackEvent',
|
||||
"Error",
|
||||
"message",
|
||||
error.message
|
||||
error.message + utils.formatEventList()
|
||||
]);
|
||||
};
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
<blockquote>StackEdit is a free, open-source Markdown
|
||||
editor based on PageDown, the Markdown library used by Stack Overflow
|
||||
and the other Stack Exchange sites.</blockquote>
|
||||
<p>StackEdit is a free, open-source Markdown editor based on
|
||||
PageDown, the Markdown library used by Stack Overflow and the other
|
||||
Stack Exchange sites.</p>
|
||||
|
||||
<dl>
|
||||
<dt>About:</dt>
|
||||
|
@ -61,6 +61,8 @@ define([
|
||||
|
||||
// Dequeue a synchronized location
|
||||
var syncAttributes = uploadSyncAttributesList.pop();
|
||||
utils.logValue(syncAttributes.syncIndex + localStorage[syncAttributes.syncIndex]);
|
||||
|
||||
// Use the specified provider to perform the upload
|
||||
syncAttributes.provider.syncUp(uploadContent, uploadContentCRC, uploadTitle, uploadTitleCRC, syncAttributes, function(error, uploadFlag) {
|
||||
if(uploadFlag === true) {
|
||||
|
33
js/utils.js
33
js/utils.js
@ -1,7 +1,8 @@
|
||||
define([
|
||||
"jquery",
|
||||
"underscore",
|
||||
"libs/FileSaver"
|
||||
"libs/FileSaver",
|
||||
"libs/stacktrace",
|
||||
], function($, _) {
|
||||
|
||||
var utils = {};
|
||||
@ -118,7 +119,7 @@ define([
|
||||
|
||||
// Reset input control in all modals
|
||||
utils.resetModalInputs = function() {
|
||||
$(".modal input[type=text]:not([disabled]), .modal input[type=password]").val("");
|
||||
$(".modal input[type=text]:not([disabled]), .modal input[type=password], .modal textarea").val("");
|
||||
};
|
||||
|
||||
// Basic trim function
|
||||
@ -237,6 +238,34 @@ define([
|
||||
}
|
||||
};
|
||||
|
||||
var eventList = [];
|
||||
utils.logValue = function(value) {
|
||||
eventList.unshift(value);
|
||||
if(eventList.length > 5) {
|
||||
eventList.pop();
|
||||
}
|
||||
};
|
||||
utils.logStackTrace = function() {
|
||||
eventList.unshift(printStackTrace());
|
||||
if(eventList.length > 5) {
|
||||
eventList.pop();
|
||||
}
|
||||
};
|
||||
utils.formatEventList = function() {
|
||||
var result = [];
|
||||
_.each(eventList, function(event) {
|
||||
result.push("\n");
|
||||
if(_.isString(event)) {
|
||||
result.push(event);
|
||||
}
|
||||
else if(_.isArray(event)) {
|
||||
result.push(event[5] || "");
|
||||
result.push(event[6] || "");
|
||||
}
|
||||
});
|
||||
return result.join("");
|
||||
};
|
||||
|
||||
// Base64 conversion
|
||||
utils.encodeBase64 = function(str) {
|
||||
if(str.length === 0) {
|
||||
|
Loading…
Reference in New Issue
Block a user