Skip to content
Snippets Groups Projects
Commit 1ce856b5 authored by Jan-Hendrik Willms's avatar Jan-Hendrik Willms
Browse files

fixes #4

parent 6f951545
No related branches found
No related tags found
No related merge requests found
...@@ -57,7 +57,7 @@ class Colorschemepicker extends StudIPPlugin implements SystemPlugin ...@@ -57,7 +57,7 @@ class Colorschemepicker extends StudIPPlugin implements SystemPlugin
$widget = Sidebar::get()->addWidget(new SearchWidget()); $widget = Sidebar::get()->addWidget(new SearchWidget());
$widget->setTitle(_('Farbwert suchen')); $widget->setTitle(_('Farbwert suchen'));
$widget->addNeedle('#abcdef', 'search-color', true, null, null, null, [ $widget->addNeedle('#abcdef', 'search-color', true, null, null, null, [
'pattern' => '#?[a-fA-F0-9]{6}' 'pattern' => '#?(?:[a-fA-F0-9]{3}){1,2}'
]); ]);
$factory = new Flexi_TemplateFactory($this->getPluginPath() . '/templates'); $factory = new Flexi_TemplateFactory($this->getPluginPath() . '/templates');
......
...@@ -5,6 +5,10 @@ ...@@ -5,6 +5,10 @@
hex = hex.slice(1); hex = hex.slice(1);
} }
if (hex.length === 3) {
hex = hex[0] + hex[0] + hex[1] + hex[1] + hex[2] + hex[2];
}
const rgb = { const rgb = {
r: parseInt(hex.slice(0, 2), 16), r: parseInt(hex.slice(0, 2), 16),
g: parseInt(hex.slice(2, 4), 16), g: parseInt(hex.slice(2, 4), 16),
...@@ -125,27 +129,58 @@ ...@@ -125,27 +129,58 @@
return allVars.concat(...colors); return allVars.concat(...colors);
}, []); }, []);
const minibus = {
handlers: {},
trigger(event, ...args) {
if (this.handlers[event] === undefined) {
return;
}
this.handlers[event].forEach(handler => handler(...args));
},
on(event, handler) {
if (this.handlers[event] === undefined) {
this.handlers[event] = [];
}
this.handlers[event].push(handler);
}
}
// Create vue app // Create vue app
const appConfig = { const appConfig = {
el: document.getElementById('color-list'), el: document.getElementById('color-list'),
data: { data() {
return {
colors: colors, colors: colors,
searchColor: false, searchColor: false,
sortByColor: false, sortByColor: false,
};
}, },
methods: { methods: {
copy(event) { copy(event) {
(new Promise((resolve, reject) => {
if (navigator.clipboard) {
navigator.clipboard.writeText(event.target.value).then(resolve, reject);
}
const dummy = document.createElement('textarea'); const dummy = document.createElement('textarea');
dummy.value = event.target.value; dummy.value = event.target.value;
document.body.appendChild(dummy); document.body.appendChild(dummy);
dummy.select(); dummy.select();
if (document.execCommand('copy')) { if (document.execCommand('copy')) {
resolve();
} else {
reject();
}
document.body.removeChild(dummy);
})).then(() => {
console.log('fooooo');
event.target.classList.add('copied-value'); event.target.classList.add('copied-value');
event.target.addEventListener('animationend', () => { event.target.addEventListener('animationend', () => {
event.target.classList.remove('copied-value'); event.target.classList.remove('copied-value');
}); });
} });
document.body.removeChild(dummy);
}, },
toggleSortByColor() { toggleSortByColor() {
if (!this.sortByColor) { if (!this.sortByColor) {
...@@ -196,13 +231,16 @@ ...@@ -196,13 +231,16 @@
} }
return colors; return colors;
} }
},
created() {
minibus.on('search-color', color => this.searchColor = color);
} }
}; };
let promise; let promise;
if (window.Vue) { if (window.Vue !== undefined) {
promise = Promise.resolve(new Vue(appConfig)); promise = Promise.resolve(new Vue(appConfig));
} else if (window.STUDIP.Vue) { } else if (window.STUDIP.Vue !== undefined) {
promise = STUDIP.Vue.load().then(({createApp}) => { promise = STUDIP.Vue.load().then(({createApp}) => {
return createApp(appConfig); return createApp(appConfig);
}) })
...@@ -210,14 +248,15 @@ ...@@ -210,14 +248,15 @@
promise = Promise.reject('No search possible due to missing vue'); promise = Promise.reject('No search possible due to missing vue');
} }
promise.then(app => { promise.then(() => {
// Attach search input from sidebar // Attach search input from sidebar
const search = document.querySelector('.sidebar,#sidebar').querySelector('input[name="search-color"]'); const search = document.querySelector('.sidebar,#sidebar').querySelector('input[name="search-color"]');
console.log('search', search);
search.addEventListener('keyup', event => { search.addEventListener('keyup', event => {
if (search.checkValidity()) { if (search.checkValidity()) {
app.searchColor = Color.fromHexValue(search.value); minibus.trigger('search-color', Color.fromHexValue(search.value));
} else { } else {
app.searchColor = false; minibus.trigger('search-color', false);
} }
}); });
search.closest('form').addEventListener( search.closest('form').addEventListener(
......
pluginname=Colorscheme Picker pluginname=Colorscheme Picker
pluginclassname=Colorschemepicker pluginclassname=Colorschemepicker
origin=UOL origin=UOL
version=2.3.1 version=2.3.2
studipMinVersion=4.5 studipMinVersion=5.0
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment