Skip to content

Commit

Permalink
keep values of url params if given invalid args
Browse files Browse the repository at this point in the history
this is particularly important after the split
because of the else branch in versligilumi.
  • Loading branch information
noureddin committed Nov 6, 2023
1 parent 15a132e commit 1075bc2
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 88 deletions.
88 changes: 44 additions & 44 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1648,26 +1648,26 @@ <h2 class="help-part">ملاحظات متفرقة</h2>
//.reduce((obj, cur, i) => { i == 0? {} : (obj[cur[0]] = cur[1], obj), {})
.forEach((e, i) => {
const is_of = (...params) => params.includes(e[0])
if (is_of('dark', 'd')) { dark = true }
else if (is_of('light', 'l')) { dark = false }
else if (is_of('color', 'c')) { color = parse_color(e[1]) }
else if (is_of('mvbtns', 'mv', 'm')) { mv = parse_mv(e[1]) }
else if (is_of('quizmode', 'qz', 'q')) { quizmode = parse_quizmode(e[1]) }
else if (is_of('txt')) { quizmode = parse_quizmode('imlaai') }
else if (is_of('byword')) { byword = true }
else if (is_of('byletter')) { byword = false }
else if (is_of( 'linebreaks')) { nolinebreaks = false }
else if (is_of('nolinebreaks')) { nolinebreaks = true }
else if (is_of('t', 'teach', 'teacher')) { teacher = true }
else if (is_of('n', 'noteach', 'noteacher')) { teacher = false }
else if (is_of('dt', 'disableteacher')) { disableteacher = true }
else if (is_of('dq', 'disablequizmode')) { disablequizmode = true }
else if (is_of('hc', 'highcontrast')) { highcontrast = true }
else if (is_of('emu', 'emulate', 'emulation')) { emulate = e[1] }
else if (is_of('qari')) { qari = e[1] }
else if (is_of('qariurl')) { qariurl = e[1] }
else if (is_of('cn')) { cn = true }
else if (is_of('zz')) { zz = true }
if (is_of('dark', 'd')) { dark = true }
else if (is_of('light', 'l')) { dark = false }
else if (is_of('color', 'c')) { color = parse_color(e[1]) || color }
else if (is_of('mvbtns', 'mv', 'm')) { mv = parse_mv(e[1]) || mv }
else if (is_of('quizmode', 'qz', 'q')) { quizmode = parse_quizmode(e[1]) || quizmode }
else if (is_of('txt')) { quizmode = parse_quizmode('imlaai') }
else if (is_of('byword')) { byword = true }
else if (is_of('byletter')) { byword = false }
else if (is_of( 'linebreaks')) { nolinebreaks = false }
else if (is_of('nolinebreaks')) { nolinebreaks = true }
else if (is_of('t', 'teach', 'teacher')) { teacher = true }
else if (is_of('n', 'noteach', 'noteacher')) { teacher = false }
else if (is_of('dt', 'disableteacher')) { disableteacher = true }
else if (is_of('dq', 'disablequizmode')) { disablequizmode = true }
else if (is_of('hc', 'highcontrast')) { highcontrast = true }
else if (is_of('emu', 'emulate', 'emulation')) { emulate = e[1] }
else if (is_of('qari')) { qari = e[1] }
else if (is_of('qariurl')) { qariurl = e[1] }
else if (is_of('cn')) { cn = true }
else if (is_of('zz')) { zz = true }
})
let opts = {
dark,
Expand Down Expand Up @@ -1805,11 +1805,11 @@ <h2 class="help-part">ملاحظات متفرقة</h2>
function suras_to_ayat (stsura, ensura) { // each is 1-114
if (stsura === '') { stsura = '1' }
if (ensura === '') { ensura = '114' }
if (!is_number(stsura) || !is_number(ensura)) { return [null, null] }
if (!is_number(stsura) || !is_number(ensura)) { return }
stsura = +stsura || 1
ensura = +ensura || MAX_SURA
if (stsura < 1 || ensura < 1 ) { return [null, null] }
if (stsura > MAX_SURA || ensura > MAX_SURA) { return [null, null] }
if (stsura < 1 || ensura < 1 ) { return }
if (stsura > MAX_SURA || ensura > MAX_SURA) { return }
const st = start_(stsura - 1) + 1
const en = start_(ensura - 1) + suar_length[ensura - 1]
return [st, en]
Expand Down Expand Up @@ -1837,10 +1837,10 @@ <h2 class="help-part">ملاحظات متفرقة</h2>
}

function ayat_to_ayat (staya, enaya) { // each is 1-6236 or 1/7 (sura/aya)
if (!staya) { return [null, null] }
if (!staya) { return }
let st = _aya2idx(staya)
let en = _aya2idx(enaya)
if (st == null || en == null) { return [null, null] }
if (st == null || en == null) { return }
st = +st || 1; en = +en || MAX_AYA
return [st, en]
}
Expand Down Expand Up @@ -1873,27 +1873,27 @@ <h2 class="help-part">ملاحظات متفرقة</h2>
}

function rukus_to_ayat (struku, enruku) { // each is 1/1 (sura/ruku)
if (struku == null) { return [null, null] }
if (struku == null) { return }
let stpair = _ruku2idx(struku)
let enpair = _ruku2idx(enruku)
if (stpair == null || enpair == null) { return [null, null] }
if (stpair == null || enpair == null) { return }
return [stpair[0], enpair[1]]
}

function pages_to_ayat (stpage, enpage) { // each is 1-604
if (stpage == null) { return [null, null] }
if (stpage == null) { return }
stpage = +stpage || 1; enpage = +enpage || MAX_PAGE
if (stpage > MAX_PAGE || enpage > MAX_PAGE) { return [null, null] }
if (stpage > MAX_PAGE || enpage > MAX_PAGE) { return }
let st = pages[+stpage - 1] + 1
let en = pages[+enpage]
return [st, en]
}

function juzs_to_ayat (stjuz, enjuz) { // each is 1-30
if (stjuz == null) { return [null, null] }
if (stjuz == null) { return }
stjuz = +stjuz || 1
enjuz = +enjuz || MAX_JUZ
if (stjuz > MAX_JUZ || enjuz > MAX_JUZ) { return [null, null] }
if (stjuz > MAX_JUZ || enjuz > MAX_JUZ) { return }
// we multiply by 8, as we have only data for rubs.
const ratio = MAX_RUB / MAX_JUZ // 8
let st = rubs[((stjuz || 1) - 1) * ratio] + 1
Expand Down Expand Up @@ -1922,10 +1922,10 @@ <h2 class="help-part">ملاحظات متفرقة</h2>
}

function rubs_to_ayat (strub, enrub) { // each is 1-240 or 1/1-60/4 or 1//1-30//8.
if (strub == null) { return [null, null] }
if (strub == null) { return }
const stidx = _rub2idx(strub)
const enidx = _rub2idx(enrub)
if (stidx == null || enidx == null) { return [null, null] }
if (stidx == null || enidx == null) { return }
let st = rubs[(stidx || 1) - 1] + 1
let en = rubs[ enidx || 240 ]
return [st, en]
Expand All @@ -1943,10 +1943,10 @@ <h2 class="help-part">ملاحظات متفرقة</h2>
}

function hizbs_to_ayat (sthizb, enhizb) { // each is 1-240 or 1/1-60/4 or 1//1-30//8.
if (sthizb == null) { return [null, null] }
if (sthizb == null) { return }
const stidx = _hizb2idx(sthizb)
const enidx = _hizb2idx(enhizb)
if (stidx == null || enidx == null) { return [null, null] }
if (stidx == null || enidx == null) { return }
// we multiply by 4, as we have only data for rubs.
const ratio = MAX_RUB / MAX_HIZB // 4
let st = rubs[((stidx || 1) - 1) * ratio] + 1
Expand Down Expand Up @@ -1978,15 +1978,15 @@ <h2 class="help-part">ملاحظات متفرقة</h2>
//.reduce((obj, cur, i) => { i == 0? {} : (obj[cur[0]] = cur[1], obj), {})
.forEach((e, i) => {
const is_of = (...params) => params.includes(e[0])
if (is_of('a')) { a = +e[1] }
else if (is_of('b')) { b = +e[1] }
else if (is_of('p')) { [st, en] = pages_to_ayat(...range_to_pair(e[1])) }
else if (is_of('s')) { [st, en] = suras_to_ayat(...range_to_pair(e[1])) }
else if (is_of('r')) { [st, en] = rubs_to_ayat(...range_to_pair(e[1])) }
else if (is_of('h')) { [st, en] = hizbs_to_ayat(...range_to_pair(e[1])) }
else if (is_of('j')) { [st, en] = juzs_to_ayat(...range_to_pair(e[1])) }
else if (is_of('k')) { [st, en] = rukus_to_ayat(...range_to_pair(e[1])) }
else { [st, en] = ayat_to_ayat(...range_to_pair(e[0])) }
if (is_of('a')) { a = isNaN(+e[1]) ? a : +e[1] }
else if (is_of('b')) { b = isNaN(+e[1]) ? b : +e[1] }
else if (is_of('p')) { [st, en] = pages_to_ayat(...range_to_pair(e[1])) || [st, en] }
else if (is_of('s')) { [st, en] = suras_to_ayat(...range_to_pair(e[1])) || [st, en] }
else if (is_of('r')) { [st, en] = rubs_to_ayat(...range_to_pair(e[1])) || [st, en] }
else if (is_of('h')) { [st, en] = hizbs_to_ayat(...range_to_pair(e[1])) || [st, en] }
else if (is_of('j')) { [st, en] = juzs_to_ayat(...range_to_pair(e[1])) || [st, en] }
else if (is_of('k')) { [st, en] = rukus_to_ayat(...range_to_pair(e[1])) || [st, en] }
else { [st, en] = ayat_to_ayat(...range_to_pair(e[0])) || [st, en] }
})
if (st == null || en == null) { return [null, null] }
st -= b; en += a
Expand Down
40 changes: 20 additions & 20 deletions tajlorligilumi.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,26 +52,26 @@ function _tajlorligilumilo (params) {
//.reduce((obj, cur, i) => { i == 0? {} : (obj[cur[0]] = cur[1], obj), {})
.forEach((e, i) => {
const is_of = (...params) => params.includes(e[0])
if (is_of('dark', 'd')) { dark = true }
else if (is_of('light', 'l')) { dark = false }
else if (is_of('color', 'c')) { color = parse_color(e[1]) }
else if (is_of('mvbtns', 'mv', 'm')) { mv = parse_mv(e[1]) }
else if (is_of('quizmode', 'qz', 'q')) { quizmode = parse_quizmode(e[1]) }
else if (is_of('txt')) { quizmode = parse_quizmode('imlaai') }
else if (is_of('byword')) { byword = true }
else if (is_of('byletter')) { byword = false }
else if (is_of( 'linebreaks')) { nolinebreaks = false }
else if (is_of('nolinebreaks')) { nolinebreaks = true }
else if (is_of('t', 'teach', 'teacher')) { teacher = true }
else if (is_of('n', 'noteach', 'noteacher')) { teacher = false }
else if (is_of('dt', 'disableteacher')) { disableteacher = true }
else if (is_of('dq', 'disablequizmode')) { disablequizmode = true }
else if (is_of('hc', 'highcontrast')) { highcontrast = true }
else if (is_of('emu', 'emulate', 'emulation')) { emulate = e[1] }
else if (is_of('qari')) { qari = e[1] }
else if (is_of('qariurl')) { qariurl = e[1] }
else if (is_of('cn')) { cn = true }
else if (is_of('zz')) { zz = true }
if (is_of('dark', 'd')) { dark = true }
else if (is_of('light', 'l')) { dark = false }
else if (is_of('color', 'c')) { color = parse_color(e[1]) || color }
else if (is_of('mvbtns', 'mv', 'm')) { mv = parse_mv(e[1]) || mv }
else if (is_of('quizmode', 'qz', 'q')) { quizmode = parse_quizmode(e[1]) || quizmode }
else if (is_of('txt')) { quizmode = parse_quizmode('imlaai') }
else if (is_of('byword')) { byword = true }
else if (is_of('byletter')) { byword = false }
else if (is_of( 'linebreaks')) { nolinebreaks = false }
else if (is_of('nolinebreaks')) { nolinebreaks = true }
else if (is_of('t', 'teach', 'teacher')) { teacher = true }
else if (is_of('n', 'noteach', 'noteacher')) { teacher = false }
else if (is_of('dt', 'disableteacher')) { disableteacher = true }
else if (is_of('dq', 'disablequizmode')) { disablequizmode = true }
else if (is_of('hc', 'highcontrast')) { highcontrast = true }
else if (is_of('emu', 'emulate', 'emulation')) { emulate = e[1] }
else if (is_of('qari')) { qari = e[1] }
else if (is_of('qariurl')) { qariurl = e[1] }
else if (is_of('cn')) { cn = true }
else if (is_of('zz')) { zz = true }
})
let opts = {
dark,
Expand Down
48 changes: 24 additions & 24 deletions versligilumi.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ function range_to_pair (x) {
function suras_to_ayat (stsura, ensura) { // each is 1-114
if (stsura === '') { stsura = '1' }
if (ensura === '') { ensura = '114' }
if (!is_number(stsura) || !is_number(ensura)) { return [null, null] }
if (!is_number(stsura) || !is_number(ensura)) { return }
stsura = +stsura || 1
ensura = +ensura || MAX_SURA
if (stsura < 1 || ensura < 1 ) { return [null, null] }
if (stsura > MAX_SURA || ensura > MAX_SURA) { return [null, null] }
if (stsura < 1 || ensura < 1 ) { return }
if (stsura > MAX_SURA || ensura > MAX_SURA) { return }
const st = start_(stsura - 1) + 1
const en = start_(ensura - 1) + suar_length[ensura - 1]
return [st, en]
Expand Down Expand Up @@ -66,10 +66,10 @@ function _aya2idx (aya) { // 1-6236 or 1/7
}

function ayat_to_ayat (staya, enaya) { // each is 1-6236 or 1/7 (sura/aya)
if (!staya) { return [null, null] }
if (!staya) { return }
let st = _aya2idx(staya)
let en = _aya2idx(enaya)
if (st == null || en == null) { return [null, null] }
if (st == null || en == null) { return }
st = +st || 1; en = +en || MAX_AYA
return [st, en]
}
Expand Down Expand Up @@ -102,27 +102,27 @@ function _ruku2idx (ruku) { // each is 1/1 (sura/ruku) -- TODO: remove redundan
}

function rukus_to_ayat (struku, enruku) { // each is 1/1 (sura/ruku)
if (struku == null) { return [null, null] }
if (struku == null) { return }
let stpair = _ruku2idx(struku)
let enpair = _ruku2idx(enruku)
if (stpair == null || enpair == null) { return [null, null] }
if (stpair == null || enpair == null) { return }
return [stpair[0], enpair[1]]
}

function pages_to_ayat (stpage, enpage) { // each is 1-604
if (stpage == null) { return [null, null] }
if (stpage == null) { return }
stpage = +stpage || 1; enpage = +enpage || MAX_PAGE
if (stpage > MAX_PAGE || enpage > MAX_PAGE) { return [null, null] }
if (stpage > MAX_PAGE || enpage > MAX_PAGE) { return }
let st = pages[+stpage - 1] + 1
let en = pages[+enpage]
return [st, en]
}

function juzs_to_ayat (stjuz, enjuz) { // each is 1-30
if (stjuz == null) { return [null, null] }
if (stjuz == null) { return }
stjuz = +stjuz || 1
enjuz = +enjuz || MAX_JUZ
if (stjuz > MAX_JUZ || enjuz > MAX_JUZ) { return [null, null] }
if (stjuz > MAX_JUZ || enjuz > MAX_JUZ) { return }
// we multiply by 8, as we have only data for rubs.
const ratio = MAX_RUB / MAX_JUZ // 8
let st = rubs[((stjuz || 1) - 1) * ratio] + 1
Expand Down Expand Up @@ -151,10 +151,10 @@ function _rub2idx (rub) { // 1-240 or 1/1-60/4 or 1//1-30//8.
}

function rubs_to_ayat (strub, enrub) { // each is 1-240 or 1/1-60/4 or 1//1-30//8.
if (strub == null) { return [null, null] }
if (strub == null) { return }
const stidx = _rub2idx(strub)
const enidx = _rub2idx(enrub)
if (stidx == null || enidx == null) { return [null, null] }
if (stidx == null || enidx == null) { return }
let st = rubs[(stidx || 1) - 1] + 1
let en = rubs[ enidx || 240 ]
return [st, en]
Expand All @@ -172,10 +172,10 @@ function _hizb2idx (hizb) { // 1-60 or 1/1-30/2.
}

function hizbs_to_ayat (sthizb, enhizb) { // each is 1-240 or 1/1-60/4 or 1//1-30//8.
if (sthizb == null) { return [null, null] }
if (sthizb == null) { return }
const stidx = _hizb2idx(sthizb)
const enidx = _hizb2idx(enhizb)
if (stidx == null || enidx == null) { return [null, null] }
if (stidx == null || enidx == null) { return }
// we multiply by 4, as we have only data for rubs.
const ratio = MAX_RUB / MAX_HIZB // 4
let st = rubs[((stidx || 1) - 1) * ratio] + 1
Expand Down Expand Up @@ -207,15 +207,15 @@ function _versligilumilo (params) {
//.reduce((obj, cur, i) => { i == 0? {} : (obj[cur[0]] = cur[1], obj), {})
.forEach((e, i) => {
const is_of = (...params) => params.includes(e[0])
if (is_of('a')) { a = +e[1] }
else if (is_of('b')) { b = +e[1] }
else if (is_of('p')) { [st, en] = pages_to_ayat(...range_to_pair(e[1])) }
else if (is_of('s')) { [st, en] = suras_to_ayat(...range_to_pair(e[1])) }
else if (is_of('r')) { [st, en] = rubs_to_ayat(...range_to_pair(e[1])) }
else if (is_of('h')) { [st, en] = hizbs_to_ayat(...range_to_pair(e[1])) }
else if (is_of('j')) { [st, en] = juzs_to_ayat(...range_to_pair(e[1])) }
else if (is_of('k')) { [st, en] = rukus_to_ayat(...range_to_pair(e[1])) }
else { [st, en] = ayat_to_ayat(...range_to_pair(e[0])) }
if (is_of('a')) { a = isNaN(+e[1]) ? a : +e[1] }
else if (is_of('b')) { b = isNaN(+e[1]) ? b : +e[1] }
else if (is_of('p')) { [st, en] = pages_to_ayat(...range_to_pair(e[1])) || [st, en] }
else if (is_of('s')) { [st, en] = suras_to_ayat(...range_to_pair(e[1])) || [st, en] }
else if (is_of('r')) { [st, en] = rubs_to_ayat(...range_to_pair(e[1])) || [st, en] }
else if (is_of('h')) { [st, en] = hizbs_to_ayat(...range_to_pair(e[1])) || [st, en] }
else if (is_of('j')) { [st, en] = juzs_to_ayat(...range_to_pair(e[1])) || [st, en] }
else if (is_of('k')) { [st, en] = rukus_to_ayat(...range_to_pair(e[1])) || [st, en] }
else { [st, en] = ayat_to_ayat(...range_to_pair(e[0])) || [st, en] }
})
if (st == null || en == null) { return [null, null] }
st -= b; en += a
Expand Down

0 comments on commit 1075bc2

Please sign in to comment.