Fixed videos not embedding in the posting preview.
This commit is contained in:
parent
d5bb0bb475
commit
58edc5c5dc
2 changed files with 122 additions and 116 deletions
|
@ -1,6 +1,4 @@
|
||||||
var Misuzu = function() {
|
var Misuzu = function() {
|
||||||
const UIHARU_API = location.protocol + '//uiharu.' + location.host;
|
|
||||||
|
|
||||||
timeago.render($qa('time'));
|
timeago.render($qa('time'));
|
||||||
hljs.initHighlighting();
|
hljs.initHighlighting();
|
||||||
|
|
||||||
|
@ -8,6 +6,124 @@ var Misuzu = function() {
|
||||||
Misuzu.Forum.Editor.init();
|
Misuzu.Forum.Editor.init();
|
||||||
Misuzu.Events.dispatch();
|
Misuzu.Events.dispatch();
|
||||||
Misuzu.initLoginPage();
|
Misuzu.initLoginPage();
|
||||||
|
Misuzu.handleEmbeds();
|
||||||
|
};
|
||||||
|
Misuzu.showMessageBox = function(text, title, buttons) {
|
||||||
|
if($q('.messagebox'))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
text = text || '';
|
||||||
|
title = title || '';
|
||||||
|
buttons = buttons || [];
|
||||||
|
|
||||||
|
var element = document.createElement('div');
|
||||||
|
element.className = 'messagebox';
|
||||||
|
|
||||||
|
var container = element.appendChild(document.createElement('div'));
|
||||||
|
container.className = 'container messagebox__container';
|
||||||
|
|
||||||
|
var titleElement = container.appendChild(document.createElement('div')),
|
||||||
|
titleBackground = titleElement.appendChild(document.createElement('div')),
|
||||||
|
titleText = titleElement.appendChild(document.createElement('div'));
|
||||||
|
|
||||||
|
titleElement.className = 'container__title';
|
||||||
|
titleBackground.className = 'container__title__background';
|
||||||
|
titleText.className = 'container__title__text';
|
||||||
|
titleText.textContent = title || 'Information';
|
||||||
|
|
||||||
|
var textElement = container.appendChild(document.createElement('div'));
|
||||||
|
textElement.className = 'container__content';
|
||||||
|
textElement.textContent = text;
|
||||||
|
|
||||||
|
var buttonsContainer = container.appendChild(document.createElement('div'));
|
||||||
|
buttonsContainer.className = 'messagebox__buttons';
|
||||||
|
|
||||||
|
var firstButton = null;
|
||||||
|
|
||||||
|
if(buttons.length < 1) {
|
||||||
|
firstButton = buttonsContainer.appendChild(document.createElement('button'));
|
||||||
|
firstButton.className = 'input__button';
|
||||||
|
firstButton.textContent = 'OK';
|
||||||
|
firstButton.addEventListener('click', function() { element.remove(); });
|
||||||
|
} else {
|
||||||
|
for(var i = 0; i < buttons.length; i++) {
|
||||||
|
var button = buttonsContainer.appendChild(document.createElement('button'));
|
||||||
|
button.className = 'input__button';
|
||||||
|
button.textContent = buttons[i].text;
|
||||||
|
button.addEventListener('click', function() {
|
||||||
|
element.remove();
|
||||||
|
buttons[i].callback();
|
||||||
|
});
|
||||||
|
|
||||||
|
if(firstButton === null)
|
||||||
|
firstButton = button;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
document.body.appendChild(element);
|
||||||
|
firstButton.focus();
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
Misuzu.initLoginPage = function() {
|
||||||
|
var updateForm = function(avatarElem, usernameElem) {
|
||||||
|
var xhr = new XMLHttpRequest;
|
||||||
|
xhr.addEventListener('readystatechange', function() {
|
||||||
|
if(xhr.readyState !== 4)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var json = JSON.parse(xhr.responseText);
|
||||||
|
if(!json)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if(json.name)
|
||||||
|
usernameElem.value = json.name;
|
||||||
|
avatarElem.src = json.avatar;
|
||||||
|
});
|
||||||
|
// need to figure out a url registry system again, current one is too much overhead so lets just do this for now
|
||||||
|
xhr.open('GET', '/auth/login.php?resolve=1&name=' + encodeURIComponent(usernameElem.value));
|
||||||
|
xhr.send();
|
||||||
|
};
|
||||||
|
|
||||||
|
var loginForms = $c('js-login-form');
|
||||||
|
|
||||||
|
for(var i = 0; i < loginForms.length; ++i)
|
||||||
|
(function(form) {
|
||||||
|
var loginTimeOut = 0,
|
||||||
|
loginAvatar = form.querySelector('.js-login-avatar'),
|
||||||
|
loginUsername = form.querySelector('.js-login-username');
|
||||||
|
|
||||||
|
updateForm(loginAvatar, loginUsername);
|
||||||
|
loginUsername.addEventListener('keyup', function() {
|
||||||
|
if(loginTimeOut)
|
||||||
|
return;
|
||||||
|
loginTimeOut = setTimeout(function() {
|
||||||
|
updateForm(loginAvatar, loginUsername);
|
||||||
|
clearTimeout(loginTimeOut);
|
||||||
|
loginTimeOut = 0;
|
||||||
|
}, 750);
|
||||||
|
});
|
||||||
|
})(loginForms[i]);
|
||||||
|
};
|
||||||
|
Misuzu.initQuickSubmit = function() {
|
||||||
|
var ctrlSubmit = Array.from($qa('.js-quick-submit, .js-ctrl-enter-submit'));
|
||||||
|
if(!ctrlSubmit)
|
||||||
|
return;
|
||||||
|
|
||||||
|
for(var i = 0; i < ctrlSubmit.length; ++i)
|
||||||
|
ctrlSubmit[i].addEventListener('keydown', function(ev) {
|
||||||
|
if((ev.code === 'Enter' || ev.code === 'NumpadEnter') // i hate this fucking language so much
|
||||||
|
&& ev.ctrlKey && !ev.altKey && !ev.shiftKey && !ev.metaKey) {
|
||||||
|
// hack: prevent forum editor from screaming when using this keycombo
|
||||||
|
// can probably be done in a less stupid manner
|
||||||
|
Misuzu.Forum.Editor.allowWindowClose = true;
|
||||||
|
|
||||||
|
this.form.submit();
|
||||||
|
ev.preventDefault();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
Misuzu.handleEmbeds = function() {
|
||||||
|
const UIHARU_API = location.protocol + '//uiharu.' + location.host;
|
||||||
|
|
||||||
const embeds = Array.from($qa('.js-msz-embed-media'));
|
const embeds = Array.from($qa('.js-msz-embed-media'));
|
||||||
if(embeds.length > 0) {
|
if(embeds.length > 0) {
|
||||||
|
@ -271,117 +387,3 @@ var Misuzu = function() {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
Misuzu.showMessageBox = function(text, title, buttons) {
|
|
||||||
if($q('.messagebox'))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
text = text || '';
|
|
||||||
title = title || '';
|
|
||||||
buttons = buttons || [];
|
|
||||||
|
|
||||||
var element = document.createElement('div');
|
|
||||||
element.className = 'messagebox';
|
|
||||||
|
|
||||||
var container = element.appendChild(document.createElement('div'));
|
|
||||||
container.className = 'container messagebox__container';
|
|
||||||
|
|
||||||
var titleElement = container.appendChild(document.createElement('div')),
|
|
||||||
titleBackground = titleElement.appendChild(document.createElement('div')),
|
|
||||||
titleText = titleElement.appendChild(document.createElement('div'));
|
|
||||||
|
|
||||||
titleElement.className = 'container__title';
|
|
||||||
titleBackground.className = 'container__title__background';
|
|
||||||
titleText.className = 'container__title__text';
|
|
||||||
titleText.textContent = title || 'Information';
|
|
||||||
|
|
||||||
var textElement = container.appendChild(document.createElement('div'));
|
|
||||||
textElement.className = 'container__content';
|
|
||||||
textElement.textContent = text;
|
|
||||||
|
|
||||||
var buttonsContainer = container.appendChild(document.createElement('div'));
|
|
||||||
buttonsContainer.className = 'messagebox__buttons';
|
|
||||||
|
|
||||||
var firstButton = null;
|
|
||||||
|
|
||||||
if(buttons.length < 1) {
|
|
||||||
firstButton = buttonsContainer.appendChild(document.createElement('button'));
|
|
||||||
firstButton.className = 'input__button';
|
|
||||||
firstButton.textContent = 'OK';
|
|
||||||
firstButton.addEventListener('click', function() { element.remove(); });
|
|
||||||
} else {
|
|
||||||
for(var i = 0; i < buttons.length; i++) {
|
|
||||||
var button = buttonsContainer.appendChild(document.createElement('button'));
|
|
||||||
button.className = 'input__button';
|
|
||||||
button.textContent = buttons[i].text;
|
|
||||||
button.addEventListener('click', function() {
|
|
||||||
element.remove();
|
|
||||||
buttons[i].callback();
|
|
||||||
});
|
|
||||||
|
|
||||||
if(firstButton === null)
|
|
||||||
firstButton = button;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
document.body.appendChild(element);
|
|
||||||
firstButton.focus();
|
|
||||||
return true;
|
|
||||||
};
|
|
||||||
Misuzu.initLoginPage = function() {
|
|
||||||
var updateForm = function(avatarElem, usernameElem) {
|
|
||||||
var xhr = new XMLHttpRequest;
|
|
||||||
xhr.addEventListener('readystatechange', function() {
|
|
||||||
if(xhr.readyState !== 4)
|
|
||||||
return;
|
|
||||||
|
|
||||||
var json = JSON.parse(xhr.responseText);
|
|
||||||
if(!json)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if(json.name)
|
|
||||||
usernameElem.value = json.name;
|
|
||||||
avatarElem.src = json.avatar;
|
|
||||||
});
|
|
||||||
// need to figure out a url registry system again, current one is too much overhead so lets just do this for now
|
|
||||||
xhr.open('GET', '/auth/login.php?resolve=1&name=' + encodeURIComponent(usernameElem.value));
|
|
||||||
xhr.send();
|
|
||||||
};
|
|
||||||
|
|
||||||
var loginForms = $c('js-login-form');
|
|
||||||
|
|
||||||
for(var i = 0; i < loginForms.length; ++i)
|
|
||||||
(function(form) {
|
|
||||||
var loginTimeOut = 0,
|
|
||||||
loginAvatar = form.querySelector('.js-login-avatar'),
|
|
||||||
loginUsername = form.querySelector('.js-login-username');
|
|
||||||
|
|
||||||
updateForm(loginAvatar, loginUsername);
|
|
||||||
loginUsername.addEventListener('keyup', function() {
|
|
||||||
if(loginTimeOut)
|
|
||||||
return;
|
|
||||||
loginTimeOut = setTimeout(function() {
|
|
||||||
updateForm(loginAvatar, loginUsername);
|
|
||||||
clearTimeout(loginTimeOut);
|
|
||||||
loginTimeOut = 0;
|
|
||||||
}, 750);
|
|
||||||
});
|
|
||||||
})(loginForms[i]);
|
|
||||||
};
|
|
||||||
Misuzu.initQuickSubmit = function() {
|
|
||||||
var ctrlSubmit = Array.from($qa('.js-quick-submit, .js-ctrl-enter-submit'));
|
|
||||||
if(!ctrlSubmit)
|
|
||||||
return;
|
|
||||||
|
|
||||||
for(var i = 0; i < ctrlSubmit.length; ++i)
|
|
||||||
ctrlSubmit[i].addEventListener('keydown', function(ev) {
|
|
||||||
if((ev.code === 'Enter' || ev.code === 'NumpadEnter') // i hate this fucking language so much
|
|
||||||
&& ev.ctrlKey && !ev.altKey && !ev.shiftKey && !ev.metaKey) {
|
|
||||||
// hack: prevent forum editor from screaming when using this keycombo
|
|
||||||
// can probably be done in a less stupid manner
|
|
||||||
Misuzu.Forum.Editor.allowWindowClose = true;
|
|
||||||
|
|
||||||
this.form.submit();
|
|
||||||
ev.preventDefault();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
|
@ -64,6 +64,8 @@ Misuzu.Forum.Editor.init = function() {
|
||||||
|
|
||||||
lastPostParser = postParser;
|
lastPostParser = postParser;
|
||||||
postingPreview.innerHTML = text;
|
postingPreview.innerHTML = text;
|
||||||
|
Misuzu.handleEmbeds();
|
||||||
|
|
||||||
previewButton.removeAttribute('disabled');
|
previewButton.removeAttribute('disabled');
|
||||||
postingParser.removeAttribute('disabled');
|
postingParser.removeAttribute('disabled');
|
||||||
previewButton.classList.remove('input__button--busy');
|
previewButton.classList.remove('input__button--busy');
|
||||||
|
@ -111,6 +113,8 @@ Misuzu.Forum.Editor.init = function() {
|
||||||
lastPostText = postText;
|
lastPostText = postText;
|
||||||
lastPostParser = postParser;
|
lastPostParser = postParser;
|
||||||
postingPreview.innerHTML = text;
|
postingPreview.innerHTML = text;
|
||||||
|
Misuzu.handleEmbeds();
|
||||||
|
|
||||||
postingPreview.removeAttribute('hidden');
|
postingPreview.removeAttribute('hidden');
|
||||||
postingText.setAttribute('hidden', 'hidden');
|
postingText.setAttribute('hidden', 'hidden');
|
||||||
previewButton.value = 'back';
|
previewButton.value = 'back';
|
||||||
|
|
Loading…
Reference in a new issue