/* jshint esversion: 6 */
/* jshint scripturl:true */
// #############################################################################
(function()
{
"use strict";
// #########################################################################
WK_Keisei.prototype.addNavItem = function(event)
{
const $keisei_li = $(`
`)
.attr(`data-dropdown`, ``)
.addClass(`dropdown phonetic`)
.insertAfter(`li.dropdown.vocabulary`);
const $drop_a = $(``)
.attr(`href`, `#`)
.attr(`data-toggle`, `dropdown`)
.addClass(`dropdown-toggle`)
.appendTo($keisei_li)
.html(`声符Phonetics
`);
const $drop_menu = $(``)
.addClass(`dropdown-menu`)
.appendTo($keisei_li)
.append(``)
.append(`
Phonetic Marks
`)
.append(`
Compounds
`)
.append(``)
.append(`
Settings
`)
.append(`
About
`);
if (!$(`#keisei_modal_settings`).length)
this.injectModals();
$(`#keisei_nav_btn_compounds`).on(`click`, this.handleNavCompounds.bind(this));
$(`#keisei_nav_btn_phonetics`).on(`click`, this.handleNavPhonetics.bind(this));
};
// #########################################################################
// #########################################################################
WK_Keisei.prototype.handleNavPhonetics = function(event)
{
$(`#keisei_summary_top_div`).remove();
const $top = $(``)
.attr(`id`, `keisei_summary_top_div`)
.addClass(`${GM_info.script.namespace} container`);
$(`.container:eq(2)`).hide().after($top);
$(`#progress`).hide();
const content = this.kdb.getPhoneticsByCompCount();
this.createPhoneticSummary($top, content);
this.populatePhoneticSummary(content);
$(`.keisei_kanji_link`).attr(`target`, `_blank`);
};
// #########################################################################
// #########################################################################
WK_Keisei.prototype.createPhoneticSummary = function(parent, content)
{
const $page = parent;
$(`List Of Phonetic Marks
`)
.appendTo($page);
const $outer = $(``)
.appendTo($page);
content.forEach(
(phons, count) => {
const $section = $(``)
.attr(`id`, `level-keisei_tm_by_comp_count`)
.appendTo($outer);
const $header = $(``)
.append(`Phonetic Marks with ${count} Compounds
`)
.appendTo($section);
const $ul = $(``)
.attr(`id`, `keisei_grid_tm_by_comp_count_${count}`)
.addClass(`single-character-grid`)
.appendTo($section);
}
);
};
// #########################################################################
// #########################################################################
WK_Keisei.prototype.populatePhoneticSummary = function(content)
{
content.forEach(
(phons, count) => {
_.forEach(phons,
(phon) => {
let li_item_data = {};
if (this.kdb.checkRadical(phon))
li_item_data = {
"kanji": phon,
"readings": this.kdb.getKReadings(phon),
"meanings": [this.kdb.getWKRadicalPP(phon)],
"href": `/radicals/${this.kdb.getWKRadical(phon)}`,
"kanji_id": `radical-${phon}`
};
else
li_item_data = {
"kanji": phon,
"readings": this.kdb.getKReadings(phon),
"meanings": this.kdb.getWKKMeanings(phon),
"notInWK": this.kdb.isKanjiInWK(phon) ? `` : `notInWK`,
"href": this.kdb.isKanjiInWK(phon) ?
`/kanji/${phon}` :
`https://jisho.org/search/${phon}%20%23kanji`,
"kanji_id": `kanji-${phon}`,
"rnd_style": this.kdb.isFirstReadingInWK(phon) ?
`` :
`keisei_style_reading_notInWK`
};
$(`#keisei_grid_tm_by_comp_count_${count}`).append(
this.gen_item_chargrid(li_item_data));
}
);
}
);
};
// #########################################################################
// #########################################################################
WK_Keisei.prototype.handleNavCompounds = function (event)
{
$(`#keisei_summary_top_div`).remove();
const $top = $(``)
.attr(`id`, `keisei_summary_top_div`)
.addClass(`${GM_info.script.namespace} container`);
$(`.container:eq(2)`).hide().after($top);
$(`#progress`).hide();
const content = this.kdb.getPhoneticsByHeader();
this.createCompoundSummary($top, content);
this.populateCompoundSummary(content);
$(`.keisei_kanji_link`).attr(`target`, `_blank`);
};
// #########################################################################
// #########################################################################
WK_Keisei.prototype.createCompoundSummary = function(parent, content)
{
const $page = parent;
$(`List Of Phonetic Compounds
`)
.appendTo($page);
const $section = $(``)
.attr(`id`, `keisei_summary_section`)
.addClass(``)
.appendTo($page);
// this.createAccordion(`#keisei_summary_section`, `top`, content, ``);
this.createTabs(`#keisei_summary_section`,
`top`,
`Column`,
content);
$(`#keisei_tab_container_top`)
.addClass(`boxed parentTabs`);
$(`ul.nav-tabs a`).click(function(e) {
e.preventDefault();
const target = this.getAttribute(`href`);
if (target === `#`)
return;
$(this).parent().siblings().removeClass(`active`);
$(this).parent().addClass(`active`);
$(target).siblings(`.tab-pane`).removeClass(`in active`);
$(target).addClass(`in active`);
});
};
// #########################################################################
// #########################################################################
WK_Keisei.prototype.createTabs = function(parent, id_suffix, name, content)
{
const $container_o = $(``)
.attr(`id`, `keisei_tab_container_${id_suffix}`)
.addClass(`tabbable`)
.appendTo(parent);
const $tab_nav_o = $(``)
.attr(`data-tabs`, `tabs`)
.addClass(`nav nav-tabs`)
.appendTo($container_o);
const $tab_content_o = $(``)
.addClass(`tab-content`)
.appendTo($container_o);
$tab_nav_o.append(`${name}`);
let has_active = false;
let idx = 0;
content.forEach(
(h_map, header) => {
const $li_nav_o = $(``)
.appendTo($tab_nav_o);
const $a_nav_o = $(``)
.attr(`data-toggle`, `tab`)
.attr(`href`, `#keisei_tab_${id_suffix}_${idx}`)
.text(header)
.appendTo($li_nav_o);
const $pane_i = $(``)
.addClass(`tab-pane fade`)
.attr(`id`, `keisei_tab_${id_suffix}_${idx}`)
.appendTo($tab_content_o);
if (!has_active)
{
$li_nav_o.addClass(`active`);
$pane_i.addClass(`active in`);
has_active = true;
}
if (h_map instanceof Map)
this.createTabs($pane_i,
`${id_suffix}_${idx}`,
`Initial`,
h_map);
idx += 1;
}
);
};
// #########################################################################
// #########################################################################
WK_Keisei.prototype.populateCompoundSummary = function(content)
{
let h_idx = 0;
content.forEach(
(h_map, header) => {
let s_idx = 0;
h_map.forEach(
(phons, subheader) => {
_.forEach(phons,
(phon) => {
const tab_i = `#keisei_tab_top_${h_idx}_${s_idx}`;
const selector = `keisei_phonetic_grid_${phon}`;
const $grid = $(``)
.attr(`id`, selector)
.addClass(`single-character-grid keisei_spaced_chargrid`)
.appendTo(tab_i);
this.populateCharGrid(`#${selector}`, {"phon": phon});
}
);
s_idx += 1;
}
);
h_idx += 1;
}
);
};
// #########################################################################
// #########################################################################
WK_Keisei.prototype.createAccordion = function(parent, id_suffix, headers, heading)
{
const $accord = $(``)
.attr(`id`, `keisei_accordion_${id_suffix}`)
.addClass(`accordion`)
.appendTo(parent);
_.forEach(headers,
(header, idx) => {
const $group = $(``)
.addClass(`accordion-group`)
.appendTo($accord);
const $head = $(``)
.addClass(`accordion-heading`)
.appendTo($group);
const $heading = $(heading)
.appendTo($head);
const collapse_id = `keisei_collapse_${id_suffix}_${header}`;
const $a = $(``)
.addClass(`accordion-toggle`)
.attr(`data-toggle`, `collapse`)
.attr(`data-parent`, parent)
.attr(`href`, `#${collapse_id}`)
.text(`Column ${header}`)
.appendTo($heading);
const $collapse = $(``)
.attr(`id`, collapse_id)
.addClass(`accordion-body collapse`)
.appendTo($group);
const $body = $(``)
.attr(`id`, `keisei_accordion_inner_${id_suffix}_${header}`)
.addClass(`accordion-inner`)
.appendTo($collapse);
}
);
};
// #########################################################################
// #########################################################################
WK_Keisei.prototype.populateCompoundSummary_acc = function(content)
{
content.forEach(
(h_map, header) => {
this.createAccordion(`#keisei_accordion_inner_top_${header}`,
header,
[...h_map.keys()],
``);
h_map.forEach(
(phons, subheader) => {
_.forEach(phons,
(phon) => {
const accord_inner = `#keisei_accordion_inner_${header}_${subheader}`;
const selector = `keisei_phonetic_grid_${phon}`;
const $grid = $(``)
.attr(`id`, selector)
.addClass(`single-character-grid`)
.appendTo(accord_inner);
this.populateCharGrid(`#${selector}`, {"phon": phon});
}
);
}
);
}
);
};
// #########################################################################
}
)();
// #############################################################################