github.com/Azareal/Gosora@v0.0.0-20210729070923-553e66b59003/themes/cosora/public/misc.js (about) 1 "use strict"; 2 3 (() => { 4 function newElement(etype, eclass) { 5 let element = document.createElement(etype); 6 element.className = eclass; 7 return element; 8 } 9 10 function moveAlerts() { 11 // Move the alerts under the first header 12 let colSel = $(".colstack_right .colstack_head:first"); 13 let colSelAlt = $(".colstack_right .colstack_item:first"); 14 let colSelAltAlt = $(".colstack_right .coldyn_block:first"); 15 if(colSel.length > 0) $('.alert').insertAfter(colSel); 16 else if (colSelAlt.length > 0) $('.alert').insertBefore(colSelAlt); 17 else if (colSelAltAlt.length > 0) $('.alert').insertBefore(colSelAltAlt); 18 else $('.alert').insertAfter(".rowhead:first"); 19 } 20 21 addInitHook("end_init", () => { 22 let loggedIn = document.head.querySelector("[property='x-mem']")!=null; 23 if(loggedIn) { 24 if(navigator.userAgent.indexOf("Firefox")!=-1) $.trumbowyg.svgPath = pre+"trumbowyg/ui/icons.svg"; 25 26 // Is there we way we can append instead? Maybe, an editor plugin? 27 attachItemCallback = function(attachItem) { 28 let currentContent = $('#input_content').trumbowyg('html'); 29 $('#input_content').trumbowyg('html',currentContent); 30 } 31 quoteItemCallback = function() { 32 let currentContent = $('#input_content').trumbowyg('html'); 33 $('#input_content').trumbowyg('html',currentContent); 34 } 35 36 $(".topic_name_row").click(() => { 37 $(".topic_create_form").addClass("selectedInput"); 38 }); 39 40 // TODO: Bind this to the viewport resize event 41 var btnlist = []; 42 if(document.documentElement.clientWidth > 550) { 43 btnlist = [['viewHTML'],['undo','redo'],['formatting'],['strong','em','del'],['link'],['insertImage'],['unorderedList','orderedList'],['removeformat']]; 44 } else { 45 btnlist = [['viewHTML'],['strong','em','del'],['link'],['insertImage'],['unorderedList','orderedList'],['removeformat']]; 46 } 47 48 $('.topic_create_form #input_content').trumbowyg({ 49 btns: btnlist, 50 }); 51 $('.topic_reply_form #input_content').trumbowyg({ 52 btns: btnlist, 53 autogrow: true, 54 }); 55 $('#profile_comments_form .topic_reply_form .input_content').trumbowyg({ 56 btns: [['viewHTML'],['strong','em','del'],['link'],['insertImage'],['removeformat']], 57 autogrow: true, 58 }); 59 addHook("edit_item_pre_bind", () => { 60 $('.user_content textarea').trumbowyg({ 61 btns: btnlist, 62 autogrow: true, 63 }); 64 }); 65 } 66 67 // TODO: Refactor this to use `each` less 68 $('.button_menu').click(function(){ 69 log(".button_menu"); 70 // The outer container 71 let buttonPane = newElement("div","button_menu_pane"); 72 let postItem = $(this).parents('.post_item'); 73 74 // Create the userinfo row in the pane 75 let userInfo = newElement("div","userinfo"); 76 postItem.find('.avatar_item').each(function(){ 77 userInfo.appendChild(this); 78 }); 79 80 let userText = newElement("div","userText"); 81 postItem.find('.userinfo:not(.avatar_item)').children().each(function(){ 82 userText.appendChild(this); 83 }); 84 userInfo.appendChild(userText); 85 buttonPane.appendChild(userInfo); 86 87 // Copy a short preview of the post contents into the pane 88 postItem.find('.user_content').each(function(){ 89 // TODO: Truncate an excessive number of lines to 5 or so 90 let contents = this.innerHTML; 91 if(contents.length > 45) this.innerHTML = contents.substring(0,45) + "..."; 92 buttonPane.appendChild(this); 93 }); 94 95 // Copy the buttons from the post to the pane 96 let buttonGrid = newElement("div","buttonGrid"); 97 let gridElementCount = 0; 98 $(this).parent().children('a:not(.button_menu)').each(function(){ 99 buttonGrid.appendChild(this); 100 gridElementCount++; 101 }); 102 103 104 // Fill in the placeholder grid nodes 105 let rowCount = 4; 106 log("rowCount",rowCount); 107 log("gridElementCount",gridElementCount); 108 if(gridElementCount%rowCount != 0) { 109 let fillerNodes = (rowCount - (gridElementCount%rowCount)); 110 log("fillerNodes",fillerNodes); 111 for(let i = 0; i < fillerNodes;i++ ) { 112 log("added a gridFiller"); 113 buttonGrid.appendChild(newElement("div","gridFiller")); 114 } 115 } 116 buttonPane.appendChild(buttonGrid); 117 118 document.getElementById("back").appendChild(buttonPane); 119 }); 120 121 moveAlerts(); 122 }); 123 124 addInitHook("after_notice", moveAlerts); 125 })()