Skip to content

Commit e88a884

Browse files
committed
minor general cleanup of the Judaism JS assets
1 parent 199d24a commit e88a884

1 file changed

Lines changed: 44 additions & 25 deletions

File tree

public/assets/community/judaism.js

Lines changed: 44 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ THE SOFTWARE.
5454

5555
/** @type {JQuery<HTMLTextAreaElement | HTMLInputElement>} */
5656
let currentTextfield = $('textarea, input[type=text]');
57-
$(document).ready(function(){
58-
$(document).on('focus', 'textarea, input[type=text]', function(){
57+
$(document).ready(function () {
58+
$(document).on('focus', 'textarea, input[type=text]', function () {
5959
currentTextfield = $(this);
6060
});
6161

@@ -87,11 +87,11 @@ THE SOFTWARE.
8787

8888
function createKeyboard() {
8989
const stand = "קראטוןםפשדגכעיחלךףזסבהנמצתץ",
90-
alpha = "חזוהדגבאסןנםמלךכיטתשרקץצףפע",
91-
nek = ["שׁ", "שׂ", "וְ", "וֱ", "וֲ", "וֳ", "וִ", "וֵ", "וֶ", "וַ", "וָ", "וֹ", "וֻ", "וּ"],
92-
x = 50,
93-
y = 50,
94-
kb = $('<div class="hbkeyboard"></div>').appendTo($("body"));
90+
alpha = "חזוהדגבאסןנםמלךכיטתשרקץצףפע",
91+
nek = ["שׁ", "שׂ", "וְ", "וֱ", "וֲ", "וֳ", "וִ", "וֵ", "וֶ", "וַ", "וָ", "וֹ", "וֻ", "וּ"],
92+
x = 50,
93+
y = 50,
94+
kb = $('<div class="hbkeyboard"></div>').appendTo($("body"));
9595

9696
$.each(alpha.split('').concat(nek), function (i, letter) {
9797
kb.append('<button type="button" class="hbkey" data-t="' + letter.slice(-1) + '">' + letter + '</button>');
@@ -225,7 +225,7 @@ THE SOFTWARE.
225225
kb.fadeToggle('medium');
226226
});
227227

228-
$('#keylayout').change(function(){
228+
$('#keylayout').change(function () {
229229
const layout = $(this).prop('checked') ? stand : alpha;
230230
$('.hbkey').slice(0, 27).each(function (index) {
231231
$(this).data('t', layout[index]).text(layout[index]);
@@ -242,8 +242,6 @@ THE SOFTWARE.
242242
return kb;
243243
}
244244

245-
246-
247245
//Draggability
248246
const drag = {
249247
elem: null,
@@ -255,15 +253,18 @@ THE SOFTWARE.
255253
x: 0,
256254
y: 0
257255
};
256+
258257
$(document).on('mousedown', '.hbkeyboard', function (e) {
259258
if (!drag.state) {
260259
drag.elem = this;
261260
drag.x = e.pageX;
262261
drag.y = e.pageY;
263262
drag.state = true;
264263
}
264+
265265
return false;
266266
});
267+
267268
$(document).mousemove(function (e) {
268269
if (drag.state) {
269270
delta.x = e.pageX - drag.x;
@@ -279,6 +280,7 @@ THE SOFTWARE.
279280
drag.y = e.pageY;
280281
}
281282
});
283+
282284
$(document).mouseup(function () {
283285
drag.state && (drag.state = false);
284286
});
@@ -316,6 +318,7 @@ $(() => {
316318
}, 1000);
317319
});
318320
});
321+
319322
document.body.appendChild(el);
320323
});
321324

@@ -324,12 +327,19 @@ $(() => {
324327

325328

326329
$(() => {
330+
/**
331+
* @param {string} term
332+
* @returns {Promise<string[]>}
333+
*/
327334
const getSuggestions = async (term) => {
328335
const resp = await fetch(`https://sefaria.org/api/name/${term}`);
329336
const data = await resp.json();
330337
return data.completions;
331338
};
332339

340+
/**
341+
* @param {JQuery.ClickEvent} ev
342+
*/
333343
const doReplacement = (ev) => {
334344
ev.preventDefault();
335345

@@ -341,6 +351,9 @@ $(() => {
341351
$field.trigger('markdown');
342352
};
343353

354+
/**
355+
* @param {string[]} suggestions
356+
*/
344357
const createPopup = (suggestions) => {
345358
const $itemTemplate = $(`<a class="item" href="#"></a>`);
346359
return suggestions.map((s) => {
@@ -363,26 +376,32 @@ $(() => {
363376
});
364377
});
365378

379+
366380
// ============================================================================================== //
367-
/**
381+
382+
383+
/**
368384
* Calendar script, added 2021-04-01 by @luap42
369385
*/
370386

371-
// Use *local* time for ISO string (Date.toISOString() uses UTC).
372-
// We only need the date here, so punting on time.
373-
function toIsoDate(date) {
374-
/**
375-
* @param {number} num
376-
* @returns {string}
377-
*/
378-
const pad = function(num) {
379-
const norm = Math.floor(Math.abs(num));
380-
return (norm < 10 ? '0' : '') + norm;
381-
};
382-
387+
/**
388+
* @param {number} num
389+
* @returns {string}
390+
*/
391+
const pad = (num) => {
392+
const norm = Math.floor(Math.abs(num));
393+
return (norm < 10 ? '0' : '') + norm;
394+
};
395+
396+
/**
397+
* Use *local* time when converting to ISO string (Date.toISOString() uses UTC).
398+
* @param {Date} date
399+
* @returns {string}
400+
*/
401+
const toIsoDate = (date) => {
383402
return date.getFullYear() +
384-
'-' + pad(date.getMonth() + 1) +
385-
'-' + pad(date.getDate());
403+
'-' + pad(date.getMonth() + 1) +
404+
'-' + pad(date.getDate());
386405
}
387406

388407

0 commit comments

Comments
 (0)