2019-03-21 22:59:41 +00:00
|
|
|
"use strict";
|
2018-03-08 03:59:47 +00:00
|
|
|
|
2019-03-21 22:59:41 +00:00
|
|
|
(() => {
|
2020-03-09 21:41:17 +00:00
|
|
|
function newElement(etype, eclass) {
|
|
|
|
let element = document.createElement(etype);
|
|
|
|
element.className = eclass;
|
|
|
|
return element;
|
|
|
|
}
|
|
|
|
|
2019-04-28 22:27:58 +00:00
|
|
|
function moveAlerts() {
|
|
|
|
// Move the alerts under the first header
|
|
|
|
let colSel = $(".colstack_right .colstack_head:first");
|
|
|
|
let colSelAlt = $(".colstack_right .colstack_item:first");
|
|
|
|
let colSelAltAlt = $(".colstack_right .coldyn_block:first");
|
|
|
|
if(colSel.length > 0) $('.alert').insertAfter(colSel);
|
|
|
|
else if (colSelAlt.length > 0) $('.alert').insertBefore(colSelAlt);
|
|
|
|
else if (colSelAltAlt.length > 0) $('.alert').insertBefore(colSelAltAlt);
|
|
|
|
else $('.alert').insertAfter(".rowhead:first");
|
|
|
|
}
|
|
|
|
|
2019-03-21 22:59:41 +00:00
|
|
|
addInitHook("end_init", () => {
|
2020-03-22 23:14:08 +00:00
|
|
|
let loggedIn = document.head.querySelector("[property='x-mem']")!=null;
|
2019-03-21 22:59:41 +00:00
|
|
|
if(loggedIn) {
|
2020-03-22 23:14:08 +00:00
|
|
|
if(navigator.userAgent.indexOf("Firefox")!=-1) $.trumbowyg.svgPath = "/s/trumbowyg/ui/icons.svg";
|
2019-03-25 03:30:56 +00:00
|
|
|
|
2019-03-21 22:59:41 +00:00
|
|
|
// Is there we way we can append instead? Maybe, an editor plugin?
|
|
|
|
attachItemCallback = function(attachItem) {
|
|
|
|
let currentContent = $('#input_content').trumbowyg('html');
|
|
|
|
$('#input_content').trumbowyg('html', currentContent);
|
|
|
|
}
|
2019-03-25 03:30:56 +00:00
|
|
|
quoteItemCallback = function() {
|
|
|
|
let currentContent = $('#input_content').trumbowyg('html');
|
|
|
|
$('#input_content').trumbowyg('html', currentContent);
|
|
|
|
}
|
2019-03-21 22:59:41 +00:00
|
|
|
|
2020-03-09 21:41:17 +00:00
|
|
|
$(".topic_name_row").click(() => {
|
2019-03-21 22:59:41 +00:00
|
|
|
$(".topic_create_form").addClass("selectedInput");
|
|
|
|
});
|
2017-12-19 03:53:13 +00:00
|
|
|
|
2019-03-21 22:59:41 +00:00
|
|
|
// TODO: Bind this to the viewport resize event
|
|
|
|
var btnlist = [];
|
|
|
|
if(document.documentElement.clientWidth > 550) {
|
|
|
|
btnlist = [['viewHTML'],['undo','redo'],['formatting'],['strong','em','del'],['link'],['insertImage'],['unorderedList','orderedList'],['removeformat']];
|
|
|
|
} else {
|
|
|
|
btnlist = [['viewHTML'],['strong','em','del'],['link'],['insertImage'],['unorderedList','orderedList'],['removeformat']];
|
|
|
|
}
|
|
|
|
|
|
|
|
$('.topic_create_form #input_content').trumbowyg({
|
|
|
|
btns: btnlist,
|
|
|
|
});
|
|
|
|
$('.topic_reply_form #input_content').trumbowyg({
|
2019-03-04 07:47:38 +00:00
|
|
|
btns: btnlist,
|
|
|
|
autogrow: true,
|
|
|
|
});
|
2019-03-21 22:59:41 +00:00
|
|
|
$('#profile_comments_form .topic_reply_form .input_content').trumbowyg({
|
|
|
|
btns: [['viewHTML'],['strong','em','del'],['link'],['insertImage'],['removeformat']],
|
|
|
|
autogrow: true,
|
|
|
|
});
|
|
|
|
addHook("edit_item_pre_bind", () => {
|
|
|
|
$('.user_content textarea').trumbowyg({
|
|
|
|
btns: btnlist,
|
|
|
|
autogrow: true,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
2017-12-19 03:53:13 +00:00
|
|
|
|
2019-03-21 22:59:41 +00:00
|
|
|
// TODO: Refactor this to use `each` less
|
|
|
|
$('.button_menu').click(function(){
|
2020-07-23 04:02:16 +00:00
|
|
|
log(".button_menu");
|
2019-03-21 22:59:41 +00:00
|
|
|
// The outer container
|
|
|
|
let buttonPane = newElement("div","button_menu_pane");
|
|
|
|
let postItem = $(this).parents('.post_item');
|
2017-12-19 03:53:13 +00:00
|
|
|
|
2019-03-21 22:59:41 +00:00
|
|
|
// Create the userinfo row in the pane
|
|
|
|
let userInfo = newElement("div","userinfo");
|
|
|
|
postItem.find('.avatar_item').each(function(){
|
|
|
|
userInfo.appendChild(this);
|
|
|
|
});
|
2017-12-19 03:53:13 +00:00
|
|
|
|
2019-03-21 22:59:41 +00:00
|
|
|
let userText = newElement("div","userText");
|
|
|
|
postItem.find('.userinfo:not(.avatar_item)').children().each(function(){
|
|
|
|
userText.appendChild(this);
|
|
|
|
});
|
|
|
|
userInfo.appendChild(userText);
|
|
|
|
buttonPane.appendChild(userInfo);
|
2017-12-19 03:53:13 +00:00
|
|
|
|
2019-03-21 22:59:41 +00:00
|
|
|
// Copy a short preview of the post contents into the pane
|
|
|
|
postItem.find('.user_content').each(function(){
|
|
|
|
// TODO: Truncate an excessive number of lines to 5 or so
|
|
|
|
let contents = this.innerHTML;
|
|
|
|
if(contents.length > 45) this.innerHTML = contents.substring(0,45) + "...";
|
|
|
|
buttonPane.appendChild(this);
|
|
|
|
});
|
2017-12-19 03:53:13 +00:00
|
|
|
|
2019-03-21 22:59:41 +00:00
|
|
|
// Copy the buttons from the post to the pane
|
|
|
|
let buttonGrid = newElement("div","buttonGrid");
|
|
|
|
let gridElementCount = 0;
|
|
|
|
$(this).parent().children('a:not(.button_menu)').each(function(){
|
|
|
|
buttonGrid.appendChild(this);
|
|
|
|
gridElementCount++;
|
|
|
|
});
|
|
|
|
|
2017-12-19 03:53:13 +00:00
|
|
|
|
2019-03-21 22:59:41 +00:00
|
|
|
// Fill in the placeholder grid nodes
|
|
|
|
let rowCount = 4;
|
2020-07-23 04:02:16 +00:00
|
|
|
log("rowCount",rowCount);
|
|
|
|
log("gridElementCount",gridElementCount);
|
2019-03-21 22:59:41 +00:00
|
|
|
if(gridElementCount%rowCount != 0) {
|
|
|
|
let fillerNodes = (rowCount - (gridElementCount%rowCount));
|
2020-07-23 04:02:16 +00:00
|
|
|
log("fillerNodes",fillerNodes);
|
2019-03-21 22:59:41 +00:00
|
|
|
for(let i = 0; i < fillerNodes;i++ ) {
|
2020-07-23 04:02:16 +00:00
|
|
|
log("added a gridFiller");
|
2019-03-21 22:59:41 +00:00
|
|
|
buttonGrid.appendChild(newElement("div","gridFiller"));
|
|
|
|
}
|
2017-12-19 03:53:13 +00:00
|
|
|
}
|
2019-03-21 22:59:41 +00:00
|
|
|
buttonPane.appendChild(buttonGrid);
|
2017-12-19 03:53:13 +00:00
|
|
|
|
2019-03-21 22:59:41 +00:00
|
|
|
document.getElementById("back").appendChild(buttonPane);
|
|
|
|
});
|
2018-03-08 03:59:47 +00:00
|
|
|
|
2019-04-28 22:27:58 +00:00
|
|
|
moveAlerts();
|
2019-03-21 22:59:41 +00:00
|
|
|
});
|
2019-04-28 22:27:58 +00:00
|
|
|
|
|
|
|
addInitHook("after_notice", moveAlerts);
|
2020-03-09 21:41:17 +00:00
|
|
|
})()
|