X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=view%2Ftheme%2Ffrio%2Fjs%2Fmodal.js;h=c13b0682b581fbd2523478dd69c46e8c92544bc4;hb=8536b313a1eb1c3e11f9ba5317fdcef33118bcb8;hp=56df75d7b68269fa5ea9ced61d7ad80b0e1998eb;hpb=c118c03a70ad783a5cc75c1be80d594eae6ca954;p=friendica.git diff --git a/view/theme/frio/js/modal.js b/view/theme/frio/js/modal.js index 56df75d7b6..c13b0682b5 100644 --- a/view/theme/frio/js/modal.js +++ b/view/theme/frio/js/modal.js @@ -12,7 +12,7 @@ $(document).ready(function(){ // with AjaxUpload. $(".fbrowser").remove(); // Remove the AjaxUpload element. - $("[name=userfile]").parent().remove(); + $(".ajaxbutton-wrapper").remove(); }); // Clear bs modal on close. @@ -22,6 +22,10 @@ $(document).ready(function(){ $("#jot-content").append(jotcache); // Clear the jotcache. jotcache = ''; + // Destroy the attachment linkPreviw for Jot. + if (typeof linkPreview === 'object') { + linkPreview.destroy(); + } }); // Add Colorbox for viewing Network page images. @@ -89,6 +93,21 @@ $(document).ready(function(){ input.val(img); }); + + // Generic delegated event to open an anchor URL in a modal. + // Used in the hovercard. + document.getElementsByTagName('body')[0].addEventListener('click', function(e) { + var target = e.target; + while (target) { + if (target.matches && target.matches('a.add-to-modal')) { + addToModal(target.href); + e.preventDefault(); + return false; + } + + target = target.parentNode || null; + } + }); }); // Overwrite Dialog.show from main js to load the filebrowser into a bs modal. @@ -116,7 +135,7 @@ Dialog.show = function(url, title) { Dialog._get_url = function(type, name, id) { var hash = name; if (id !== undefined) hash = hash + "-" + id; - return "fbrowser/"+type+"/?mode=none#"+hash; + return "fbrowser/"+type+"/?mode=none&theme=frio#"+hash; }; // Does load the filebrowser into the jot modal. @@ -140,20 +159,19 @@ Dialog.showJot = function() { // Init the filebrowser after page load. Dialog._load = function(url) { // Get nickname & filebrowser type from the modal content. - var nickname = $("#fb-nickname").attr("value"); - var type = $("#fb-type").attr("value"); + let filebrowser = document.getElementById('filebrowser'); // Try to fetch the hash form the url. - var match = url.match(/fbrowser\/[a-z]+\/\?mode=none(.*)/); - if (match===null) return; //not fbrowser - var hash = match[1]; + let match = url.match(/fbrowser\/[a-z]+\/.*(#.*)/); + if (!filebrowser || match === null) { + return; //not fbrowser + } // Initialize the filebrowser. - var jsbrowser = function() { - FileBrowser.init(nickname, type, hash); - }; loadScript("view/js/ajaxupload.js"); - loadScript("view/theme/frio/js/filebrowser.js", jsbrowser); + loadScript("view/theme/frio/js/filebrowser.js", function() { + FileBrowser.init(filebrowser.dataset.nickname, filebrowser.dataset.type, match[1]); + }); }; /** @@ -188,14 +206,25 @@ function loadModalTitle() { } } -// This function loads html content from a friendica page -// into a modal. -function addToModal(url) { + +/** + * This function loads html content from a friendica page into a modal. + * + * @param {string} url The url with html content. + * @param {string} id The ID of a html element (can be undefined). + * @returns {void} + */ +function addToModal(url, id) { var char = qOrAmp(url); url = url + char + 'mode=none'; var modal = $('#modal').modal(); + // Only search for an element if we have an ID. + if (typeof id !== "undefined") { + url = url + " div#" + id; + } + modal .find('#modal-body') .load(url, function (responseText, textStatus) { @@ -207,11 +236,15 @@ function addToModal(url) { //Get first element with the class "heading" //and use it as title. loadModalTitle(); + + // We need to initialize autosize again for new + // modal conent. + autosize($('.modal .text-autosize')); } }); } -// Add a element (by it's id) to a bootstrap modal. +// Add an element (by its id) to a bootstrap modal. function addElmToModal(id) { var elm = $(id).html(); var modal = $('#modal').modal(); @@ -243,7 +276,6 @@ function editpost(url) { var modal = $('#jot-modal').modal(); url = url + " #jot-sections"; - //var rand_num = random_digits(12); $(".jot-nav .jot-perms-lnk").parent("li").addClass("hidden"); // For editpost we load the modal html of "jot-sections" of the edit page. So we would have two jot forms in @@ -277,6 +309,7 @@ function editpost(url) { modal.show(); $("#jot-popup").show(); + linkPreview = $('#profile-jot-text').linkPreview(); } }); } @@ -291,14 +324,6 @@ function jotreset() { $("#profile-jot-form #jot-title-wrap").show(); $("#profile-jot-form #jot-category-wrap").show(); - // the following was commented out because it is needed anymore - // because we changed the behavior at an other place. - // var rand_num = random_digits(12); - // $('#jot-title, #jot-category, #profile-jot-text').val(""); - // $( "#profile-jot-form input[name='type']" ).val("wall"); - // $( "#profile-jot-form input[name='post_id']" ).val(""); - // $( "#profile-jot-form input[name='post_id_random']" ).val(rand_num); - // Remove the "edit-jot" class so we can the standard behavior on close. $("#jot-modal.edit-jot").removeClass("edit-jot"); $("#jot-modal-content").empty(); @@ -318,16 +343,18 @@ function toggleJotNav (elm) { // Minimize all tab content wrapper and activate only the selected // tab panel. - $('#jot-modal [role=tabpanel]').addClass("minimize").attr("aria-hidden" ,"true"); - $('#jot-modal #' + tabpanel).removeClass("minimize").attr("aria-hidden" ,"false"); + $('#profile-jot-form > [role=tabpanel]').addClass("minimize").attr("aria-hidden" ,"true"); + $('#' + tabpanel).removeClass("minimize").attr("aria-hidden" ,"false"); // Set the aria-selected states - $("#jot-modal .nav-tabs .jot-nav-lnk").attr("aria-selected", "false"); + $("#jot-modal .modal-header .nav-tabs .jot-nav-lnk").attr("aria-selected", "false"); elm.setAttribute("aria-selected", "true"); // For some some tab panels we need to execute other js functions. if (tabpanel === "jot-preview-content") { preview_post(); + // Make Share button visivle in preview + $('#jot-preview-share').removeClass("minimize").attr("aria-hidden" ,"false"); } else if (tabpanel === "jot-fbrowser-wrapper") { $(function() { Dialog.showJot();