mami/src/mami.js/ui/view.js

96 lines
3.1 KiB
JavaScript
Raw Normal View History

2024-01-18 19:50:37 +00:00
#include themes.js
#include ui/elems.js
Umi.UI.View = (function() {
const accentColours = {
'dark': 'Dark',
'light': 'Light',
'blue': 'Blue',
'purple': 'Purple',
'archaic': 'Archaic'
};
const getPosition = function(end) {
return Umi.UI.Elements.MessageInput[end ? 'selectionEnd' : 'selectionStart'];
};
const setPosition = function(pos, end) {
Umi.UI.Elements.MessageInput[end ? 'selectionEnd' : 'selectionStart'] = pos;
};
const getText = function() {
return Umi.UI.Elements.MessageInput.value;
};
const setText = function(text) {
Umi.UI.Elements.MessageInput.value = text;
};
return {
AccentColours: accentColours,
AccentReload: function() {
2024-01-22 21:45:39 +00:00
const settings = mami.getSettings(),
available = Object.keys(accentColours),
name = settings.get('style'),
2024-01-18 19:50:37 +00:00
compact = 'chat--compact',
classes = ['umi'];
if(available.indexOf(name) < 0)
return;
// should probably be moved elsewhere eventually
// the entire AccentReload function should probably be axed
UmiThemeApply(name);
2024-01-22 21:45:39 +00:00
if(!settings.get('tmpDisableOldThemeSys'))
2024-01-18 19:50:37 +00:00
classes.push('umi--' + name);
if(Umi.UI.Elements.Chat.className.indexOf('hidden') >= 0)
classes.push('hidden');
Umi.UI.Elements.Chat.className = '';
Umi.UI.Elements.Chat.classList.add.apply(Umi.UI.Elements.Chat.classList, classes);
2024-01-22 21:45:39 +00:00
if(settings.get('compactView')) {
2024-01-18 19:50:37 +00:00
if(Umi.UI.Elements.Chat.className.indexOf(compact) < 0)
Umi.UI.Elements.Messages.classList.add(compact);
} else
Umi.UI.Elements.Messages.classList.remove(compact);
2024-01-22 21:45:39 +00:00
if(settings.get('autoScroll'))
2024-01-18 19:50:37 +00:00
Umi.UI.Elements.Messages.scrollTop = Umi.UI.Elements.Messages.scrollHeight;
},
Focus: function() {
Umi.UI.Elements.MessageInput.focus();
},
SetPosition: setPosition,
GetPosition: getPosition,
GoToStart: function() {
setPosition(0);
},
GoToEnd: function() {
setPosition(Umi.UI.Elements.MessageInput.value.length);
},
GetSelectionLength: function() {
let length = getPosition(true) - getPosition();
if(length < 0)
length = getPosition() - getPosition(true);
return length;
},
EnterAtCursor: function(text, overwrite) {
const value = getText(),
current = getPosition();
let out = '';
out += value.slice(0, current);
out += text;
out += value.slice(current + (overwrite ? text.length : 0));
setText(out);
setPosition(current);
},
GetSelectedText: function() {
return getText().slice(getPosition(), getPosition(true));
},
GetText: getText,
SetText: setText,
};
})();