summaryrefslogtreecommitdiff
path: root/views/new-post.php
diff options
context:
space:
mode:
Diffstat (limited to 'views/new-post.php')
-rw-r--r--views/new-post.php40
1 files changed, 33 insertions, 7 deletions
diff --git a/views/new-post.php b/views/new-post.php
index 0d79767..21571ec 100644
--- a/views/new-post.php
+++ b/views/new-post.php
@@ -27,6 +27,8 @@
<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>
+ <a href="javascript:addPhotoURL();" class="hidden" id="add_photo">add photo</a>
<br>
<div id="photo_preview_container" class="hidden">
<img src="" id="photo_preview" style="max-width: 300px; max-height: 300px;">
@@ -180,11 +182,30 @@ function restoreNoteState() {
}
function replacePhotoWithPhotoURL(url) {
- $("#note_photo").after('<input type="url" name="note_photo_url" id="note_photo_url" value="" class="form-control">');
- $("#note_photo_url").val(url);
+ $("#note_photo").after('<input type="url" name="note_photo_url[]" value="" class="note_photo_url form-control">');
+ $(".note_photo_url").val(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[]" value="" class="note_photo_url 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");
+ $("#add_photo").removeClass("hidden");
+}
+
+function addPhotoURL() {
+ $(".note_photo_url:last").after('<input type="url" name="note_photo_url[]" value="" class="note_photo_url form-control" style="margin-top:2px;">');
+ if($(".note_photo_url").length == 4) {
+ $("#add_photo").remove();
+ }
}
$(function(){
@@ -193,7 +214,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 +254,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){
@@ -307,8 +330,12 @@ $(function(){
// Add either the photo as a file, or the photo URL depending on whether the user has a media endpoint
if(document.getElementById("note_photo") && document.getElementById("note_photo").files[0]) {
formData.append("photo", document.getElementById("note_photo").files[0]);
- } else if($("#note_photo_url").val()) {
- formData.append("photo", $("#note_photo_url").val());
+ } else if($(".note_photo_url").val()) {
+ $(".note_photo_url").each(function(){
+ if($(this).val()) {
+ formData.append("photo[]", $(this).val());
+ }
+ });
}
// Need to append a placeholder field because if the file size max is hit, $_POST will
@@ -316,12 +343,11 @@ $(function(){
// This will be stripped by Quill before it's sent to the Micropub endpoint
formData.append("null","null");
-
var request = new XMLHttpRequest();
request.open("POST", "/micropub/multipart");
request.onreadystatechange = function() {
if(request.readyState == XMLHttpRequest.DONE) {
- console.log(request.responseText);
+ // console.log(request.responseText);
try {
var response = JSON.parse(request.responseText);
localforage.removeItem('current-note');