From d1e935eff5e2a3508ff8577707ea8c95b26acef0 Mon Sep 17 00:00:00 2001 From: Meezaan-ud-Din Abdu Dhil-Jalali Wal-Ikram Date: Sat, 12 Jun 2021 11:33:44 +0400 Subject: [PATCH] Remove Quran object from client side to fix memory issues --- html/public/js/jquery.quran.js | 25 +++++++++++++++++++------ views/quran.php | 6 +++--- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/html/public/js/jquery.quran.js b/html/public/js/jquery.quran.js index daea3a8..90cce95 100644 --- a/html/public/js/jquery.quran.js +++ b/html/public/js/jquery.quran.js @@ -5,30 +5,43 @@ jQuery( document ).ready( function( $ ) { editions: function(element, reference) { this.monitorEditions(element, reference); }, - surahs: function(element, player, quran) { + surahs: function(element, player) { var w = this; $(element).on('change', function() { w._surah = ($(this).val()); $('.displayedSurah' + w._surah).removeClass('hide').siblings().addClass('hide'); // Set audio player to play the first file in this surah. - w.getFirstAyahOfSurah(w._surah, player, quran); + w.getFirstAyahOfSurah(w._surah, player); }); }, - getFirstAyahOfSurah: function(surahid, player, quran) { + getFirstAyahOfSurah: function(surahid, player) { var w = this; - var ayahNumber = quran.surahs[Number(surahid - 1)].ayahs[0].number; - w.setPlayerToAyah(surahid, ayahNumber, player); + var ayahNumber; + $.ajax({ + type: "GET", + url: "https://api.alquran.cloud/ayah/" + (surahid) + ':' + 1, + cache: false, + success: function(data) { + // Update timings + if (data.code == 200) { + ayahNumber = data.data.number; + w.setPlayerToAyah(surahid, ayahNumber, player); + } + } + }); + //var ayahNumber = quran.surahs[Number(surahid - 1)].ayahs[0].number; + //w.setPlayerToAyah(surahid, ayahNumber, player); }, setPlayerToAyah: function(surah, ayah, player) { const sleep = (milliseconds) => { return new Promise(resolve => setTimeout(resolve, milliseconds)) } if (surah !=1 && surah !=9) { + player.pause(); // First play bismillah var bUrl = 'https://cdn.islamic.network/quran/audio/128/ar.alafasy/1.mp3'; $('#activeAyah').attr('src', bUrl) - player.pause(); if (player.paused) { player.load(); player.oncanplaythrough = player.play(); diff --git a/views/quran.php b/views/quran.php index df0dcfe..8458410 100644 --- a/views/quran.php +++ b/views/quran.php @@ -81,15 +81,15 @@ - +