52 lines
1.3 KiB
JavaScript
52 lines
1.3 KiB
JavaScript
#include colour.js
|
|
#include utility.js
|
|
#include colpick/picker.jsx
|
|
|
|
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: AmiColour.hex(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();
|
|
},
|
|
};
|
|
};
|