var jsonContainer = document.getElementById("jsoneditor");
var jsonEditor = new JSONEditor(jsonContainer, {
change: function() {
mdEditor.$data.front_matter = jsonEditor.get();
}
});
function ValidURL(str) {
var pattern = new RegExp('^(https?:\/\/)?$') // protocol
if(!pattern.test(str)) {
return false;
} else {
return true;
}
}
var mdEditor = new Vue({
el: "#editor",
data: {
input: '# hello',
boldText: '',
italicText: '',
listItems: [],
listItem: '',
link: {},
video: {},
photos: [],
selectedText: '',
front_matter: {
title: ''
},
slug: ''
},
filters: {
marked: marked
},
created: function () {
var that = this;
$(document).ready(function() {
Dropzone.autoDiscover = false;
var mediaDropzone;
mediaDropzone = new Dropzone("#media-dropzone", { addRemoveLinks: false });
mediaDropzone.on("success", function(file, responseText) {
$.ajax({
url: '/statixite/sites/' + responseText.media.site_id + '/media',
data: {
format: 'json'
},
success: function(response) {
that.photos = response;
$.getScript('/statixite/sites/' + response[0].site_id + '/media');
}
});
//that.photos.unshift(responseText.media);
this.removeFile(file);
that.input += "\n\n";
that.input += "\n";
that.input += "\n";
});
});
$(document).on('click', '.pagination a', {}, function() {
var link = this;
$.ajax({
url: link.href,
data: {
format: 'json'
},
success: function(response) {
that.photos = response;
}
});
});
},
methods: {
addBoldText: function() {
this.input = this.input + " **" + this.boldText + "**";
this.boldText = '';
$('#boldText').modal('hide');
},
addItalicText: function() {
this.input = this.input + " *" + this.italicText + "*";
this.italicText = '';
$('#italicText').modal('hide');
},
addListItem: function() {
this.listItems.push(this.listItem);
this.listItem = '';
},
addList: function() {
this.input = this.input + "\n";
for ( i in this.listItems ) {
this.input += "* " + this.listItems[i] + "\n"
}
this.listItems = [];
$('#listModal').modal('hide');
},
addLink: function() {
var text = mdEditor.getSelectedText;
this.input += " [" + this.link.text + "](" + this.link.url +")";
this.link = {};
$('#linkModal').modal('hide');
},
addVideo: function() {
var videoEmbed;
var divStyle = 'height: 0; margin-bottom: 0.88889rem; overflow: hidden; padding-bottom: 67.5%; padding-top: 1.38889rem; position: relative;';
var iframeStyle = 'height: 100%; position: absolute; top: 0; width: 100%; left: 0;';
switch(mdEditor.domain) {
case 'youtu.be':
var videoArray = this.video.url.split('/');
var videoId = videoArray[videoArray.length - 1];
videoEmbed = '