2024-01-18 19:50:37 +00:00
|
|
|
#include themes.js
|
2024-02-09 00:56:27 +00:00
|
|
|
#include utility.js
|
2024-01-18 19:50:37 +00:00
|
|
|
|
|
|
|
Umi.UI.View = (function() {
|
|
|
|
const accentColours = {
|
|
|
|
'dark': 'Dark',
|
|
|
|
'light': 'Light',
|
|
|
|
'blue': 'Blue',
|
|
|
|
'purple': 'Purple',
|
|
|
|
'archaic': 'Archaic'
|
|
|
|
};
|
|
|
|
|
|
|
|
const getPosition = function(end) {
|
2024-02-09 00:56:27 +00:00
|
|
|
return $i('umi-msg-text')[end ? 'selectionEnd' : 'selectionStart'];
|
2024-01-18 19:50:37 +00:00
|
|
|
};
|
|
|
|
const setPosition = function(pos, end) {
|
2024-02-09 00:56:27 +00:00
|
|
|
$i('umi-msg-text')[end ? 'selectionEnd' : 'selectionStart'] = pos;
|
2024-01-18 19:50:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const getText = function() {
|
2024-02-09 00:56:27 +00:00
|
|
|
return $i('umi-msg-text').value;
|
2024-01-18 19:50:37 +00:00
|
|
|
};
|
|
|
|
const setText = function(text) {
|
2024-02-09 00:56:27 +00:00
|
|
|
$i('umi-msg-text').value = text;
|
2024-01-18 19:50:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
return {
|
|
|
|
AccentColours: accentColours,
|
|
|
|
AccentReload: function() {
|
2024-02-09 00:56:27 +00:00
|
|
|
const settings = mami.getSettings()
|
|
|
|
const style = settings.get('style');
|
2024-01-18 19:50:37 +00:00
|
|
|
|
2024-02-09 00:56:27 +00:00
|
|
|
if(!accentColours.hasOwnProperty(style))
|
2024-01-18 19:50:37 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
// should probably be moved elsewhere eventually
|
|
|
|
// the entire AccentReload function should probably be axed
|
2024-02-09 00:56:27 +00:00
|
|
|
UmiThemeApply(style);
|
2024-01-18 19:50:37 +00:00
|
|
|
|
2024-02-09 00:56:27 +00:00
|
|
|
const chat = $i('umi-chat');
|
|
|
|
if(chat instanceof Element) {
|
|
|
|
const compactView = settings.get('compactView');
|
|
|
|
chat.classList.toggle('chat--compact', compactView);
|
|
|
|
$i('umi-messages').classList.toggle('chat--compact', compactView);
|
2024-01-18 19:50:37 +00:00
|
|
|
|
2024-02-09 00:56:27 +00:00
|
|
|
const forceOldOff = settings.get('tmpDisableOldThemeSys');
|
|
|
|
for(const name in accentColours)
|
|
|
|
if(accentColours.hasOwnProperty(name))
|
|
|
|
chat.classList.toggle(`umi--${name}`, !forceOldOff && name === style);
|
|
|
|
}
|
2024-01-18 19:50:37 +00:00
|
|
|
},
|
|
|
|
Focus: function() {
|
2024-02-09 00:56:27 +00:00
|
|
|
$i('umi-msg-text').focus();
|
2024-01-18 19:50:37 +00:00
|
|
|
},
|
|
|
|
SetPosition: setPosition,
|
|
|
|
GetPosition: getPosition,
|
|
|
|
GoToStart: function() {
|
|
|
|
setPosition(0);
|
|
|
|
},
|
|
|
|
GoToEnd: function() {
|
2024-02-09 00:56:27 +00:00
|
|
|
setPosition($i('umi-msg-text').value.length);
|
2024-01-18 19:50:37 +00:00
|
|
|
},
|
|
|
|
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,
|
|
|
|
};
|
|
|
|
})();
|