summaryrefslogtreecommitdiff
path: root/public/editor/editor.js
diff options
context:
space:
mode:
authorAaron Parecki <aaron@parecki.com>2015-05-10 16:49:22 +0200
committerAaron Parecki <aaron@parecki.com>2015-05-10 16:49:22 +0200
commit3b7d766c31314a3d42d651b8c8f643ff8d6e15bd (patch)
treedec9c9cbed6cb077ada14754f556c21eb51da2c8 /public/editor/editor.js
parent3dc97d7478781550aa1a878120082a871988f02e (diff)
do the micropub post and redirect after it's created!medium
Diffstat (limited to 'public/editor/editor.js')
-rw-r--r--public/editor/editor.js35
1 files changed, 35 insertions, 0 deletions
diff --git a/public/editor/editor.js b/public/editor/editor.js
index 2d99674..17cc24e 100644
--- a/public/editor/editor.js
+++ b/public/editor/editor.js
@@ -29,8 +29,43 @@ $(function () {
$('.editable').focus(function(){
$('.placeholder').removeClass('placeholder');
});
+
+ $.post('/editor/test-login', {}, function(response) {
+ $('#publish_btn').text(response.logged_in ? 'Publish' : 'Sign In');
+ });
+
+ $('#publish_btn').click(function(){
+ if($('#publish_btn').text() == 'Publish') {
+
+ $.post('/editor/publish', {
+ name: $("#post-name").val(),
+ body: editor.serialize().content.value
+ }, function(response) {
+ if(response.location) {
+ reset_page().then(function(){
+ window.location = response.location;
+ });
+ }
+ });
+
+ } else {
+ var url = prompt("Enter your URL");
+ window.location = '/auth/start?me=' + encodeURIComponent(url) + '&redirect=/editor';
+ }
+ });
+
+ $('#new_btn').click(function(){
+ reset_page();
+ });
});
+function reset_page() {
+ $("#post-name").val('');
+ $("#content").html('<p class="placeholder">Write something nice...</p>');
+ $("#draft-status").text("New");
+ return localforage.setItem('currentdraft', {});
+}
+
/* ************************************************ */
/* autosave loop */
var autosaveTimeout = false;