diff options
Diffstat (limited to 'view/tpl/jot-header.tpl')
-rw-r--r-- | view/tpl/jot-header.tpl | 430 |
1 files changed, 262 insertions, 168 deletions
diff --git a/view/tpl/jot-header.tpl b/view/tpl/jot-header.tpl index 2c60b7c22..b9b8b3012 100644 --- a/view/tpl/jot-header.tpl +++ b/view/tpl/jot-header.tpl @@ -1,54 +1,56 @@ -<script language="javascript" type="text/javascript"> +<script src="vendor/blueimp/jquery-file-upload/js/vendor/jquery.ui.widget.js"></script> +<script src="vendor/blueimp/jquery-file-upload/js/jquery.iframe-transport.js"></script> +<script src="vendor/blueimp/jquery-file-upload/js/jquery.fileupload.js"></script> -var editor = false; -var plaintext = '{{$editselect}}'; -var pretext = '{{$pretext}}'; +<script> -function initEditor(cb){ - if(editor == false){ - $("#profile-jot-text-loading").show(); - $("#profile-jot-tools").removeClass('d-none'); - {{$geotag}} - if(plaintext == 'none') { - $("#profile-jot-text-loading").hide(); - $(".jothidden").show(); - $("#profile-jot-text").addClass('jot-expanded'); - {{if $bbco_autocomplete}} - $("#profile-jot-text").bbco_autocomplete('{{$bbco_autocomplete}}'); // autocomplete bbcode - {{/if}} - {{if $editor_autocomplete}} - if(typeof channelId === 'undefined') - $("#profile-jot-text").editor_autocomplete(baseurl+"/acl"); - else - $("#profile-jot-text").editor_autocomplete(baseurl+"/acl",[channelId]); // Also gives suggestions from current channel's connections - {{/if}} - editor = true; + var editor = false; + var plaintext = '{{$editselect}}'; + var pretext = '{{$pretext}}'; + + var activeCommentID = 0; + var activeCommentText = ''; + + var isModalAction = false; + + var postSaveTimer = null; + + function initEditor(cb){ + if(editor == false){ + $("#profile-jot-text-loading").show(); + $("#profile-jot-tools").removeClass('d-none'); + {{$geotag}} + if(plaintext == 'none') { + $("#profile-jot-text-loading").hide(); + $(".jothidden").show(); + $("#profile-jot-text").addClass('jot-expanded'); + {{if $bbco_autocomplete}} + $("#profile-jot-text").bbco_autocomplete('{{$bbco_autocomplete}}'); // autocomplete bbcode + {{/if}} + {{if $editor_autocomplete}} + if(typeof channelId === 'undefined') + $("#profile-jot-text").editor_autocomplete(baseurl+"/acl"); + else + $("#profile-jot-text").editor_autocomplete(baseurl+"/acl",[channelId]); // Also gives suggestions from current channel's connections + {{/if}} + editor = true; + if (typeof cb!="undefined") cb(); + if(pretext.length) + addeditortext(pretext); + return; + } + editor = true; + } else { if (typeof cb!="undefined") cb(); - if(pretext.length) - addeditortext(pretext); - return; } - editor = true; - } else { - if (typeof cb!="undefined") cb(); } -} - -function enableOnUser(){ - if(editor) - return; - - initEditor(); -} -</script> -<script src="vendor/blueimp/jquery-file-upload/js/vendor/jquery.ui.widget.js"></script> -<script src="vendor/blueimp/jquery-file-upload/js/jquery.iframe-transport.js"></script> -<script src="vendor/blueimp/jquery-file-upload/js/jquery.fileupload.js"></script> + function enableOnUser(){ + if(editor) + return; -<script> -var activeCommentID = 0; -var activeCommentText = ''; + initEditor(); + } $(document).ready(function() { @@ -152,28 +154,28 @@ var activeCommentText = ''; } function jotGetLink() { - textarea = document.getElementById('profile-jot-text'); - if (textarea.selectionStart || textarea.selectionStart == "0") { - var start = textarea.selectionStart; - var end = textarea.selectionEnd; - if (end > start) { - reply = prompt("{{$linkurl}}"); - if(reply && reply.length) { - textarea.value = textarea.value.substring(0, start) + "[url=" + reply + "]" + textarea.value.substring(start, end) + "[/url]" + textarea.value.substring(end, textarea.value.length); - } - } else { - reply = prompt("{{$linkurl}}"); - if(reply && reply.length) { - reply = bin2hex(reply); - $('#profile-rotator').show(); - $.get('{{$baseurl}}/linkinfo?f=&binurl=' + reply, function(data) { - addeditortext(data); + textarea = document.getElementById('profile-jot-text'); + if (textarea.selectionStart || textarea.selectionStart == "0") { + var start = textarea.selectionStart; + var end = textarea.selectionEnd; + if (end > start) { + reply = prompt("{{$linkurl}}"); + if(reply && reply.length) { + textarea.value = textarea.value.substring(0, start) + "[url=" + reply + "]" + textarea.value.substring(start, end) + "[/url]" + textarea.value.substring(end, textarea.value.length); + } + } else { + reply = prompt("{{$linkurl}}"); + if(reply && reply.length) { + reply = bin2hex(reply); + $('#profile-rotator').show(); + $.get('{{$baseurl}}/linkinfo?f=&binurl=' + reply, function(data) { + addeditortext(data); preview_post(); - $('#profile-rotator').hide(); - }); - } - } - } + $('#profile-rotator').hide(); + }); + } + } + } } function jotGetLocation() { @@ -199,6 +201,7 @@ var activeCommentText = ''; $('#created-modal-OKButton').on('click', function() { reply=$('#created-date').val(); if(reply && reply.length) { + $('#jot-delayed').val(1); $('#jot-created').val(reply); $('#createdModal').modal('hide'); } @@ -210,6 +213,7 @@ var activeCommentText = ''; $.get('{{$baseurl}}/share/' + id, function(data) { $('#like-rotator-' + id).hide(); updateInit(); + close_modal(); }); } @@ -402,88 +406,186 @@ var activeCommentText = ''; } - var initializeEmbedPhotoDialog = function () { - $('.embed-photo-selected-photo').each(function (index) { - $(this).removeClass('embed-photo-selected-photo'); - }); - getPhotoAlbumList(); - $('#embedPhotoModalBodyAlbumDialog').off('click'); - $('#embedPhotoModal').modal('show'); - }; - - var choosePhotoFromAlbum = function (album) { - $.post("embedphotos/album", {name: album}, - function(data) { - if (data['status']) { - $('#embedPhotoModalLabel').html("{{$modalchooseimages}}"); - $('#embedPhotoModalBodyAlbumDialog').html('\ - <div><div class="nav nav-pills flex-column">\n\ - <li class="nav-item"><a class="nav-link" href="#" onclick="initializeEmbedPhotoDialog();return false;">\n\ - <i class="bi bi-chevron-left"></i> \n\ - {{$modaldiffalbum}}\n\ - </a>\n\ - </li>\n\ - </div><br></div>') - $('#embedPhotoModalBodyAlbumDialog').append(data['content']); - $('#embedPhotoModalBodyAlbumDialog').click(function (evt) { - evt.preventDefault(); - var image = document.getElementById(evt.target.id); - if (typeof($(image).parent()[0]) !== 'undefined') { - var imageparent = document.getElementById($(image).parent()[0].id); - $(imageparent).toggleClass('embed-photo-selected-photo'); - var href = $(imageparent).attr('href'); - $.post( - "embedphotos/photolink", - {href: href}, - function(ddata) { - if (ddata['status']) { - addeditortext(ddata['photolink']); - preview_post(); - } else { - window.console.log("{{$modalerrorlink}}" + ':' + ddata['errormsg']); - } - return false; - }, - 'json' - ); - } - }); - $('#embedPhotoModalBodyAlbumListDialog').addClass('d-none'); - $('#embedPhotoModalBodyAlbumDialog').removeClass('d-none'); - } else { - window.console.log("{{$modalerroralbum}} " + JSON.stringify(album) + ':' + data['errormsg']); - } - return false; - }, - 'json'); - }; - - var getPhotoAlbumList = function () { - $.post("embedphotos/albumlist", {}, - function(data) { - if (data['status']) { - var albums = data['albumlist']; //JSON.parse(data['albumlist']); - $('#embedPhotoModalLabel').html("{{$modalchoosealbum}}"); - $('#embedPhotoModalBodyAlbumList').html('<ul class="nav nav-pills flex-column"></ul>'); - for(var i=0; i<albums.length; i++) { - var albumName = albums[i].text; - var jsAlbumName = albums[i].jstext; - var albumLink = '<li class="nav-item">'; - albumLink += '<a class="nav-link" href="#" onclick="choosePhotoFromAlbum(\'' + jsAlbumName + '\'); return false;">' + albumName + '</a>'; - albumLink += '</li>'; - $('#embedPhotoModalBodyAlbumList').find('ul').append(albumLink); - } - $('#embedPhotoModalBodyAlbumDialog').addClass('d-none'); - $('#embedPhotoModalBodyAlbumListDialog').removeClass('d-none'); - } else { - window.console.log("{{$modalerrorlist}}" + ':' + data['errormsg']); - } - return false; - }, - 'json'); - }; - - // + const initializeEmbedPhotoDialog = () => { + // Remove the 'embed-photo-selected-photo' class from all selected photos + const selectedPhotos = document.querySelectorAll('.embed-photo-selected-photo'); + selectedPhotos.forEach(photo => { + photo.classList.remove('embed-photo-selected-photo'); + }); + + // Fetch the photo album list + getPhotoAlbumList(); + + if (activeCommentID) { + const modalEl = document.getElementById('reactions'); + isModalAction = modalEl.classList.contains('show'); + } + + if (isModalAction) { + // Remove any existing click event listeners on the modal body + const modalBodyAlbumDialog = document.getElementById('reactions_extra_middle'); + modalBodyAlbumDialog.replaceWith(modalBodyAlbumDialog.cloneNode(true)); // This effectively removes all event listeners + + const modalEl = document.getElementById('reactions'); + + // Reset activeCommentID when the modal is closed + modalEl.addEventListener('hide.bs.modal', event => { + activeCommentID = 0; + isModalAction = false; + document.getElementById('reactions_extra_middle').innerHTML = ''; + document.getElementById('reactions_extra_top').innerHTML = ''; + }); + } + else { + // Remove any existing click event listeners on the modal body + const modalBodyAlbumDialog = document.getElementById('embedPhotoModalBodyAlbumDialog'); + modalBodyAlbumDialog.replaceWith(modalBodyAlbumDialog.cloneNode(true)); // This effectively removes all event listeners + + // Show the modal + const modalEl = document.getElementById('embedPhotoModal'); + const modal = new bootstrap.Modal(modalEl); + modal.show(); + + // Reset activeCommentID when the modal is closed + modalEl.addEventListener('hide.bs.modal', event => { + activeCommentID = 0; + }); + } + }; + + const choosePhotoFromAlbum = (album) => { + + const params = new URLSearchParams(); + params.append('name', album); + + fetch('embedphotos/album', { + method: 'POST', + body: params + }) + .then(response => response.json()) + .then(data => { + if (data.status) { + + const modalLabel = isModalAction ? document.getElementById('reactions_extra_top') : document.getElementById('embedPhotoModalLabel'); + const modalBody = isModalAction ? document.getElementById('reactions_extra_middle') : document.getElementById('embedPhotoModalBodyAlbumDialog'); + + modalLabel.innerHTML = '<h3>{{$modalchooseimages}}</h3>'; + modalBody.innerHTML = '<div><div class="nav nav-pills flex-column"><li class="nav-item"><a class="nav-link" href="#" onclick="initializeEmbedPhotoDialog(); return false;"><i class="bi bi-chevron-left"></i> {{$modaldiffalbum}}</a></li></div><br></div>'; + modalBody.innerHTML += data.content; + + // Make sure the loaded script is executed + const scripts = modalBody.querySelectorAll('script'); + + scripts.forEach(script => { + const scriptContent = script.textContent || script.innerText; + eval(scriptContent); // Execute the script + }); + + modalBody.addEventListener('click', (evt) => { + evt.preventDefault(); + const image = document.getElementById(evt.target.id); + if (image && image.parentElement) { + const imageParent = image.parentElement; + imageParent.classList.toggle('embed-photo-selected-photo'); + const href = imageParent.getAttribute('href'); + + const params = new URLSearchParams(); + params.append('href', href); + + fetch('embedphotos/photolink', { + method: 'POST', + body: params + }) + .then(response => response.json()) + .then(ddata => { + if (ddata.status) { + addActiveEditorText(ddata.photolink); + } else { + console.error("{{$modalerrorlink}}: " + ddata.errormsg); + } + }); + } + }); + + document.getElementById('embedPhotoModalBodyAlbumListDialog').classList.add('d-none'); + modalBody.classList.remove('d-none'); + } else { + console.error("{{$modalerroralbum}} " + JSON.stringify(album) + ': ' + data.errormsg); + } + }) + .catch(error => { + console.error("Error fetching album:", error); + }); + }; + + const getPhotoAlbumList = () => { + fetch('embedphotos/albumlist', { + method: 'POST', + }) + .then(response => response.json()) + .then(data => { + if (data.status) { + const albums = data.albumlist; + const modalLabel = isModalAction ? document.getElementById('reactions_extra_top') : document.getElementById('embedPhotoModalLabel'); + const modalBodyList = isModalAction ? document.getElementById('reactions_extra_middle') : document.getElementById('embedPhotoModalBodyAlbumList'); + + modalLabel.innerHTML = '<h3>{{$modalchoosealbum}}</h3>'; + modalBodyList.innerHTML = '<ul class="nav nav-pills flex-column"></ul>'; + + albums.forEach(album => { + const albumName = album.text; + const jsAlbumName = album.jstext; + const albumLink = '<li class="nav-item"><a class="nav-link" href="#" onclick="choosePhotoFromAlbum(\'' + jsAlbumName + '\'); return false;">' + albumName + '</a></li>'; + modalBodyList.querySelector('ul').innerHTML += albumLink; + }); + + document.getElementById('embedPhotoModalBodyAlbumDialog').classList.add('d-none'); + document.getElementById('embedPhotoModalBodyAlbumListDialog').classList.remove('d-none'); + } else { + console.error("{{$modalerrorlist}}: " + data.errormsg); + } + }) + .catch(error => { + console.error("Error fetching album list:", error); + }); + }; + + function addeditortext(data) { + if(plaintext == 'none') { + var currentText = $("#profile-jot-text").val(); + $("#profile-jot-text").val(currentText + data); + } + } + + // Add text to active comment region if set, otherwise add to main editor + function addActiveEditorText(data) { + if (activeCommentID) { + const textarea = document.getElementById('comment-edit-text-' + activeCommentID); + + if (textarea) { + let currentText = textarea.value; + + // Clear the textarea if it matches the active comment text + if (currentText === activeCommentText) { + currentText = ''; + } + + textarea.classList.add('expanded'); + openMenu('comment-tools-' + activeCommentID); + textarea.value = currentText + data; + textarea.focus(); + textarea.click(); + if (!isModalAction) { + preview_comment(activeCommentID); + } + } + } else { + addeditortext(data); + preview_post(); + } + } + + // initialize drag-drop function DragDropUploadInit() { @@ -530,28 +632,21 @@ var activeCommentText = ''; $(this).closest('.jot-poll-option').remove(); } -</script> - -<script> -$( document ).on( "click", ".wall-item-delete-link,.page-delete-link,.layout-delete-link,.block-delete-link", function(e) { - var link = $(this).attr("href"); // "get" the intended link in a var - - if (typeof(eval($.fn.modal)) === 'function'){ - e.preventDefault(); - bootbox.confirm("<h4>{{$confirmdelete}}</h4>",function(result) { - if (result) { - document.location.href = link; - } - }); - } else { - return confirm("{{$confirmdelete}}"); - } -}); -</script> + $( document ).on( "click", ".wall-item-delete-link,.page-delete-link,.layout-delete-link,.block-delete-link", function(e) { + var link = $(this).attr("href"); // "get" the intended link in a var -<script> - var postSaveTimer = null; + if (typeof(eval($.fn.modal)) === 'function'){ + e.preventDefault(); + bootbox.confirm("<h4>{{$confirmdelete}}</h4>",function(result) { + if (result) { + document.location.href = link; + } + }); + } else { + return confirm("{{$confirmdelete}}"); + } + }); function postSaveChanges(action) { if({{$auto_save_draft}}) { @@ -591,7 +686,6 @@ $( document ).on( "click", ".wall-item-delete-link,.page-delete-link,.layout-del } $(document).ready(function() { - var cleaned = false; if({{$auto_save_draft}}) { |