var currently_dragging = null; // if this is null, we have nothing being dragged. if it's not null, then it will represent the glyph object (as goes in the glyphs array) which is currently being dragged
const selection_thresh = 10;
var major_radius;
const glyphs = [];
var embed;
$(document).ready(function() {
svg = $('svg#arena')[0];
major_radius = parseFloat($('circle').attr('r'));
//$.each(glyphs, function(idx, glyph) {
// glyph.element.appendTo($(svg));
//})
$(document).on("mouseup", on_mouse_up);
$("#place_group").on("mousedown", omd_consonant);
$("#vowel_place_group").on("mousedown", omd_vowel);
// handle changing the consonants
$('#consonant_form input').on('change', function(event) {
let glyph = $("#consonant_form input[name='glyphs']:checked").val(); // checked value for the glyph should be here
let radical = $("#consonant_form input[name='radicals']:checked").val(); // checked value for the radical should be here
add_class($('svg #glyph-' + glyph + '-' + radical), 'chosen');
$('#place_group image.radical').attr("href", radical);
$('#place_group image.glyph').attr("href", glyph);
});
$('td > svg').on("click", function(event) {
let receptacle = $("#consonant_put_it_in_here");
let selected = $(this);
receptacle.html(selected.html());
})
// handle changing the vowels
$('.vowel-example > svg').on("click", function(event) {
let receptacle = $('#vowel_put_it_in_here');
let selected = $(this);
receptacle.html(selected.html());
});
var t = $("#testbed");
var glyphs = split_megaglyph(t.find(".angle-1"));
$.each(glyphs, function(idx, glyph) {
glyph.attr("transform", `translate(${100 + idx*100}, 0)`);
t.append(glyph);
});
populate_consonant_grid();
});
function populate_consonant_grid() {
// this function expects that there's a #consonant-grid table, where each row corresponds to a glyph set
// the cells of the row need to be filled with the various possible configurations of that glyph
// so like, the
in a given row should contain a .megaglyph svg group, which contains the base glyph plus all possible radicals.
// then we use the split_megaglyph function to generate the five possible configurations out of that megaglyph
// and insert the five configured glyphs into their corresponding (td) cells of the table
$("#consonant-grid tbody tr").each(function (asdf, row) { // iterate over the rows in the table
// row will now be something like
// that is, a tr containing one th on either end plus a td for each consonant in this row
var head = $(row).find("th:first-child svg"); // this is the header for the row, which should contain the .megaglyph object
var megaglyph = head.find(".megaglyph");
var glyphs = split_megaglyph(megaglyph); // now this is a list of the configured consonant symbols
$(row).find("td").each(function(idx, cell) { // iterate over the cells in the row
// cell will now be a
cell which contains the IPA for that cell's consonants, plus the