From 9c3ef26741621285c6e1a2b29e36ed1812320a6e Mon Sep 17 00:00:00 2001
From: Aaron Parecki <aaron@parecki.com>
Date: Sat, 6 Aug 2016 16:13:16 +0000
Subject: add manual photo URL field

---
 views/new-post.php | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

(limited to 'views/new-post.php')

diff --git a/views/new-post.php b/views/new-post.php
index 0d79767..8128c4a 100644
--- a/views/new-post.php
+++ b/views/new-post.php
@@ -27,6 +27,7 @@
         <div class="form-group">
           <label for="note_photo"><code>photo</code></label>
           <input type="file" name="note_photo" id="note_photo" accept="image/*">
+          <a href="javascript:switchToManualPhotoURL();" id="note_manual_photo">enter photo url</a>
           <br>
           <div id="photo_preview_container" class="hidden">
             <img src="" id="photo_preview" style="max-width: 300px; max-height: 300px;">
@@ -185,6 +186,17 @@ function replacePhotoWithPhotoURL(url) {
   $("#note_photo").remove();  
   $("#photo_preview").attr("src", url);
   $("#photo_preview_container").removeClass("hidden");
+  $("#note_manual_photo").addClass("hidden");
+}
+
+function switchToManualPhotoURL() {
+  $("#note_photo").after('<input type="url" name="note_photo_url" id="note_photo_url" value="" class="form-control">');
+  $("#note_photo").remove();  
+  $("#note_photo_url").change(function(){
+    $("#photo_preview").attr("src", $(this).val());
+    $("#photo_preview_container").removeClass("hidden");
+  });
+  $("#note_manual_photo").addClass("hidden");
 }
 
 $(function(){
@@ -193,7 +205,7 @@ $(function(){
 
   var hasMediaEndpoint = <?= $this->media_endpoint ? 'true' : 'false' ?>;
 
-  $("#note_content, #note_category, #note_in_reply_to, #note_slug").on('keyup change', function(e){
+  $("#note_content, #note_category, #note_in_reply_to, #note_slug, #note_photo_url").on('keyup change', function(e){
     saveNoteState();
   })
 
@@ -233,8 +245,10 @@ $(function(){
   });
   $("#remove_photo").on("click", function(){
     $("#note_photo").val("");
+    $("#note_photo_url").val("");
     $("#photo_preview").attr("src", "" );
     $("#photo_preview_container").addClass("hidden");
+    saveNoteState();
   });
 
   $("#note_content").on('change keyup', function(e){
-- 
cgit v1.2.3