ami/src/ami.js/colourpick.js

50 lines
1.3 KiB
JavaScript

#include utility.js
var AmiColourPicker = function(parent) {
var container = $e({ attrs: { id: 'pickerNew', className: 'hidden' } }),
callback = undefined;
parent.appendChild(container);
var picker = new FwColourPicker(
function(picker, result) {
if(result === null)
return;
callback.call(picker, {
raw: result,
hex: FwColourPicker.hexFormat(result),
});
callback = undefined;
},
{
presets: futami.get('colours'),
},
null,
function() {
callback = undefined;
container.classList.add('hidden');
return true;
}
);
picker.appendTo(container);
var showAt = function(x, y, cb) {
if(typeof cb !== 'function')
throw 'missing callback';
callback = cb;
picker.setPosition(x, y);
container.classList.remove('hidden');
};
return {
show: function(ev, cb) {
var pos = typeof ev === 'object' ? picker.suggestPosition(ev) : { x: 10, y: 10 };
showAt(pos.x, pos.y, cb);
},
showAt: showAt,
hide: function() {
picker.close();
},
};
};