User:Bernanke's Crossbow/ModifiedIME.js: Difference between revisions

Content deleted Content added
Tweaks
refactor some ifs
 
(3 intermediate revisions by the same user not shown)
Line 77:
makeDiv(id) {
const div = document.createElement('div');
if (id) div.id = id || "";
return div;
},
Line 137:
areas.updateSelection = function () {
this.selection.children().remove();
for (const {[i, area}] of this.entries()) {
const title =
(area.title || area.link || '') +
Line 169:
// Remove element from this array
this.splice(this.currentlyEditing, 1);
if ( this.currentlyEditing >= Math.min(this.currentlyEditing, this.length - 1);
this.currentlyEditing = this.length - 1;
this.update();
if (this.currentlyEditing >= 0)
Line 178 ⟶ 177:
function markPoint(point, color) {
if (point) {
ime.context.beginPath();
const arm = 8 / ime.scale;
ime.context.beginPath();
ime.context.moveTo(point.x + arm, point.y);
ime.context.lineTo(point.x - arm, point.y);
Line 201 ⟶ 200:
ime.context.canvas.width / ime.scale,
ime.context.canvas.height / ime.scale);
for (const {[ind, area}] of this.entries()) {
const current = (ind == this.currentlyEditing);
ime.context.fillStyle =
current ? 'rgba(255,' + (current ? '255,0,0.4)' : 'rgba(255,0') + ',0,0.4)';
const coords = area.coords;
ime.context.beginPath();
Line 450 ⟶ 449:
function updateResult() {
const
arr = Array.from(document.ime.imageDescriptionPos;),
imageDescriptionPos =
(arr.find(elt => elt.checked) || arr[0]).value;
Line 469 ⟶ 468:
 
const preResult = document.getElementById('imeResult');
while (preResult.lastChild)
preResult.removeChild(preResult.lastChild);
 
Line 481 ⟶ 480:
function updateInputs(fromAreas) {
function updateShape(selectors, coords) {
for (const {[index, selector}] of selectors.entries())
$(selector).val(coords && coords[index] || '');
}
Line 515 ⟶ 514:
 
function attachTemplate() {
{const
clicks = {
'.ime_t_rect': () => areas.make('rect'),
'.ime_t_circle': () => areas.make('circle'),
'.ime_t_poly': () => areas.make('poly'),
'.ime_t_deletearea': areas.remove.bind(areas),
'#imeImportShow': ime.imports.show.bind(ime.imports),
'#imeImportHide': ime.imports.hide.bind(ime.imports),
'.ime_t_import': ime.imports.make.bind(ime.imports),
'.ime_t_deletecoordinates': () => {
areas.current().coords = [];
mouse.currentClicks = {};
ime.store();
}
};, changes = {
'#ime_areaselector': function (e) {
for (const {id, click} of Object.entries(clicks))
areas.edit($(this).prop('selectedIndex'));
},
'.ime_saveonchange': ime.store.bind(ime),
'.ime-updateresultsonchange': updateResult,
'#ime_areaLink': function () {
areas.current().link = $(this).val(); updateResult();
},
'#ime_areaTitle': function () {
areas.current().title = $(this).val(); updateResult();
}
};
for (const {[id, click}] of Object.entries(clicks))
$(id).click(util.std_handler(click));
for (const {[id, change}] of Object.entries(changes))
const changes = {
'#ime_areaselector': function (e) {
areas.edit($(this).prop('selectedIndex'));
},
'.ime_saveonchange': ime.store.bind(ime),
'.ime-updateresultsonchange': updateResult,
'#ime_areaLink': function () {
areas.current().link = $(this).val(); updateResult();
},
'#ime_areaTitle': function () {
areas.current().title = $(this).val(); updateResult();
}
};
for (const {id, change} of Object.entries(changes))
$(id).change(change);
}
areas.selection = $('#ime_areaselector');
$('.ime-saveonchange').focusout(function () {