summaryrefslogtreecommitdiff
path: root/public/js/index.js
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--public/js/index.js45
1 files changed, 45 insertions, 0 deletions
diff --git a/public/js/index.js b/public/js/index.js
index 0b10c9e0..17516169 100644
--- a/public/js/index.js
+++ b/public/js/index.js
@@ -1136,6 +1136,8 @@ ui.toolbar.export.googleDrive.click(function (e) {
});
//export to gist
ui.toolbar.export.gist.attr("href", noteurl + "/gist");
+//export to snippet
+ui.toolbar.export.snippet.attr("href", noteurl + "/snippet");
//import from dropbox
ui.toolbar.import.dropbox.click(function () {
var options = {
@@ -1188,6 +1190,10 @@ function buildImportFromGoogleDrive() {
ui.toolbar.import.gist.click(function () {
//na
});
+//import from snippet
+ui.toolbar.import.snippet.click(function () {
+ //na
+});
//import from clipboard
ui.toolbar.import.clipboard.click(function () {
//na
@@ -1355,6 +1361,45 @@ $("#gistImportModalConfirm").click(function () {
}
});
+// snippet import modal
+$("#snippetImportModalClear").click(function () {
+ $("#snippetImportModalContent").val('');
+});
+$("#snippetImportModalConfirm").click(function () {
+ var snippeturl = $("#snippetImportModalContent").val();
+ if (!snippeturl) return;
+ $('#snippetImportModal').modal('hide');
+ $("#snippetImportModalContent").val('');
+ if (!isValidURL(snippeturl)) {
+ showMessageModal('<i class="fa fa-gitlab"></i> Import from Snippet', 'Not a valid URL :(', '', '', false);
+ return;
+ } else {
+ // TODO: Validate against config.gitlab.baseURL
+ ui.spinner.show();
+ $.get(snippeturl)
+ .success(function (data) {
+ if (data.files) {
+ var contents = "";
+ Object.keys(data.files).forEach(function (key) {
+ contents += key;
+ contents += '\n---\n';
+ contents += data.files[key].content;
+ contents += '\n\n';
+ });
+ replaceAll(contents);
+ } else {
+ showMessageModal('<i class="fa fa-gitlab"></i> Import from Snippet', 'Unable to fetch snippet files :(', '', '', false);
+ }
+ })
+ .error(function (data) {
+ showMessageModal('<i class="fa fa-gitlab"></i> Import from Snippet', 'Not a valid Snippet URL :(', '', JSON.stringify(data), false);
+ })
+ .complete(function () {
+ ui.spinner.hide();
+ });
+ }
+});
+
function parseToEditor(data) {
var parsed = toMarkdown(data);
if (parsed)