/* * jsQari: JavaScript Quran Recitation widget * http://www.qurantracker.com/jsQari * * Copyright (c) 2011 Ziad Mannan * Dual licensed under the MIT and GPL licenses. * - http://www.opensource.org/licenses/mit-license.php * - http://www.gnu.org/copyleft/gpl.html * * Author: Ziad Mannan * Version: 1.2.1 * Date: 9th May 2012 */ var JSQari = function() { this.jsqariPlayer = $("#jquery_jplayer_1"); this.jsqariBasmalahPlayed = false; this.jsqariSurah; this.jsqariAyah; this.jsqariReciter; this.jsqariMode; this.surahAyahs = [0, 7, 286, 200, 176, 120, 165, 206, 75, 129, 109, 123, 111, 43, 52, 99, 128, 111, 110, 98, 135, 112, 78, 118, 64, 77, 227, 93, 88, 69, 60, 34, 30, 73, 54, 45, 83, 182, 88, 75, 85, 54, 53, 89, 59, 37, 35, 38, 29, 18, 45, 60, 49, 62, 55, 78, 96, 29, 22, 24, 13, 14, 11, 11, 18, 12, 12, 30, 52, 52, 44, 28, 28, 20, 56, 40, 31, 50, 40, 46, 42, 29, 19, 36, 25, 22, 17, 19, 26, 30, 20, 15, 21, 11, 8, 8, 19, 5, 8, 8, 11, 11, 8, 3, 9, 5, 4, 7, 3, 6, 3, 5, 4, 5, 6]; this.uiSurahSelector = $('#jsqari-ui-surah-selector'); this.uiAyahSelector = $('#jsqari-ui-ayah-selector'); this.uiAyahSelector2 = $('#jsqari-ui-ayah-selector2'); this.uiReciterSelector = $('#jsqari-ui-reciter-selector'); this.uiModeSelector = $('#jsqari-ui-mode-selector'); }; JSQari.prototype = { init: function () { var _this = this; this.jsqariSurah = this.uiSurahSelector.val(); this.jsqariAyah = this.uiAyahSelector.val(); this.jsqariReciter = this.uiReciterSelector.val(); this.jsqariMode = this.uiModeSelector.val(); this.jsqariBasmalahPlayed = true; this.jsqariPlayer.jPlayer({ // ready: function () { // $(_this.jsqariPlayer).jPlayer("setMedia", { // mp3: "http://www.server1.quran4u.net/abdelbasit_ayah/001001.mp3" // }); // }, ended: function () { _this.handleJSQariAyahEnd(); }, swfPath: "" }); // set up event handlers this.uiSurahSelector.change(function () { _this.jsqariSurah = $(this).val(); _this.handleSurahChange(); _this.setMediaFile(); }); this.uiAyahSelector.change(function () { _this.jsqariAyah = $(this).val(); _this.setBasmalahStatus(); _this.setMediaFile(); }); this.uiReciterSelector.change(function () { _this.jsqariReciter = $(this).val(); _this.setBasmalahStatus(); _this.setMediaFile(); }); this.uiModeSelector.change(function () { _this.jsqariMode = $(this).val(); _this.setBasmalahStatus(); _this.setMediaFile(); }); this.setMediaFile(); }, // CONTROLLER methods handleSurahChange: function () { document.getElementById("Srurah_img").src = 'Surah_Name_Banner/' + this.pad(this.jsqariSurah, 3) + '.jpg'; document.getElementById("frm_Man").src = "https://archive.org/download/Quran4u_Surah_Maany/w-" + this.jsqariSurah + ".htm"; document.getElementById("frm_Moyassar").src = "https://archive.org/download/Quran4u_Tafsir_Page_Part_Surah_Moyassar/taf-sur" + this.jsqariSurah + ".htm"; this.jsqariAyah = 1; this.setBasmalahStatus(); this.uiAyahSelector.children().remove(); this.uiAyahSelector2.children().remove(); var surahAyahNumber = this.surahAyahs[this.jsqariSurah]; for (i = 1; i <= surahAyahNumber; i++) { this.uiAyahSelector.append(''); this.uiAyahSelector2.append(''); } }, handleJSQariAyahEnd: function (event) { if (this.jsqariMode == 'someayas') { // go to next ayah and play again this.jsqariAyah = parseInt(this.jsqariAyah) + 1; if (this.jsqariAyah > this.surahAyahs[this.jsqariSurah]) { this.jsqariAyah = 1; this.jsqariSurah = parseInt(this.jsqariSurah) + 1; if (this.jsqariSurah > 114) { this.jsqariSurah = 1; } this.handleSurahChange(); } this.setMediaFile(); this.jsqariPlayer.jPlayer("play"); //--------------------------------------------------------------------- if (parseInt(this.jsqariAyah) > this.uiAyahSelector2.val()) { //alert("stop"); this.jsqariPlayer.jPlayer('stop'); } //-------------------------------------------------------------------------------------- } else if (this.jsqariMode == 'continious') { // go to next ayah and play again this.jsqariAyah = parseInt(this.jsqariAyah) + 1; if (this.jsqariAyah > this.surahAyahs[this.jsqariSurah]) { this.jsqariAyah = 1; this.jsqariSurah = parseInt(this.jsqariSurah) + 1; if (this.jsqariSurah > 114) { this.jsqariSurah = 1; } this.handleSurahChange(); } this.setMediaFile(); this.jsqariPlayer.jPlayer("play"); } else if (this.jsqariMode == 'repeatayah') { // play again if (this.jsqariAyah == 0) { this.jsqariAyah = 1; this.setMediaFile(); } this.jsqariPlayer.jPlayer("play"); } else if (this.jsqariMode == 'singleayah') { // play first ayah after basmalah if (this.jsqariAyah == 0) { this.jsqariAyah = 1; this.setMediaFile(); this.jsqariPlayer.jPlayer("play"); } } else if (this.jsqariMode == 'surah') { // play to end of surah if (this.jsqariAyah < this.surahAyahs[this.jsqariSurah]) { this.jsqariAyah = parseInt(this.jsqariAyah) + 1; this.setMediaFile(); this.jsqariPlayer.jPlayer("play"); } } else if (this.jsqariMode == 'repeatsurah') { // play to end of surah if (this.jsqariAyah < this.surahAyahs[this.jsqariSurah]) { this.jsqariAyah = parseInt(this.jsqariAyah) + 1; this.setMediaFile(); this.jsqariPlayer.jPlayer("play"); } else { this.jsqariAyah = 1; this.setBasmalahStatus(); this.setMediaFile(); this.jsqariPlayer.jPlayer("play"); } } this.updateUI(); }, // VIEW functions updateUI: function () { this.uiSurahSelector.val(this.jsqariSurah); this.uiAyahSelector.val(this.jsqariAyah); this.uiModeSelector.val(this.jsqariMode); }, // API functions setPlayMode: function (playMode) { this.jsqariMode = playMode; this.updateUI(); }, playSurah: function (surahNumber) { return this.playSurahAyah(surahNumber, 1); }, playSurahAyah: function (surahNumber, ayahNumber) { // check surah number surahNumberParsed = parseInt(surahNumber); if (isNaN(surahNumberParsed)) { alert('رقم السورة غير صحيح'); return false; } else if (surahNumberParsed > 114 || surahNumberParsed < 1) { alert('رقم السورة غير صحيح'); return false; } // check ayah number ayahNumberParsed = parseInt(ayahNumber); if (isNaN(ayahNumberParsed)) { alert('رقم الآية غير صحيح'); return false; } else if (ayahNumberParsed > this.surahAyahs[surahNumberParsed] || ayahNumberParsed < 1) { alert('رقم الآية غير صحيح'); return false; } if (this.jsqariSurah != surahNumberParsed) { this.jsqariSurah = surahNumberParsed; this.handleSurahChange(); } this.jsqariAyah = ayahNumberParsed; this.setBasmalahStatus(); this.updateUI(); this.setMediaFile(); this.jsqariPlayer.jPlayer("play"); }, // 'PRIVATE' functions setMediaFile: function () { //---------------------------- Gamal ------------------------------------------------------- document.getElementById("surahNumber").value = this.jsqariSurah; document.getElementById("ayahNumber").value = this.jsqariAyah; document.getElementById("Aya-img").src = 'https://archive.org/download/Quran4u_Quran_Ayat/' + this.jsqariSurah + '_' + this.jsqariAyah + '.gif'; // handle basmalah var tempSurah = false; var tempSurahNumber; if (!this.jsqariBasmalahPlayed) { tempSurah = true; tempSurahNumber = this.jsqariSurah; this.jsqariSurah = 1; this.jsqariAyah = 1; this.jsqariBasmalahPlayed = true; } //var base = 'http://www.everyayah.com/data/'; var base = '' var mp3file = base + this.jsqariReciter + this.pad(this.jsqariSurah, 3) + this.pad(this.jsqariAyah, 3) + '.mp3'; //---------------------------------------------------------------------------------------------------------------------------------------------- var surahAyahsss = [0, 7, 286, 200, 176, 120, 165, 206, 75, 129,109, 123, 111, 43, 52, 99, 128, 111, 110, 98, 135, 112, 78, 118, 64, 77, 227, 93, 88, 69, 60, 34, 30, 73, 54, 45, 83, 182, 88, 75, 85, 54, 53, 89, 59, 37, 35, 38, 29, 18, 45, 60, 49, 62, 55, 78, 96, 29, 22, 24, 13, 14, 11, 11, 18, 12, 12, 30, 52, 52, 44, 28, 28, 20, 56, 40, 31, 50, 40, 46, 42, 29, 19, 36, 25, 22, 17, 19, 26, 30, 20, 15, 21, 11, 8, 8, 19, 5, 8, 8, 11, 11, 8, 3, 9, 5, 4, 7, 3, 6, 3, 5, 4, 5, 6]; if (this.jsqariAyah < surahAyahsss[this.jsqariSurah]) { document.getElementById('Prev_Btn').style.width = "60px"; document.getElementById('Prev_Btn0').style.width = "60px"; }; if (this.jsqariAyah >= surahAyahsss[this.jsqariSurah]) { document.getElementById('Prev_Btn').style.width = "0px"; document.getElementById('Prev_Btn0').style.width = "0px"; }; if (this.jsqariAyah < 2) { document.getElementById('Next_Btn').style.width = "0px"; document.getElementById('Next_Btn0').style.width = "0px"; }; if (this.jsqariAyah > 1) { document.getElementById('Next_Btn').style.width = "60px"; document.getElementById('Next_Btn0').style.width = "60px"; }; //---------------------------------------------------------------------------------------------------------------------------------------------- if (tempSurah) { // alert(this.jsqariReciter); this.jsqariSurah = tempSurahNumber; this.jsqariAyah = 0; } this.jsqariPlayer.jPlayer("setMedia", { mp3: mp3file }); if (this.jsqariAyah == 0) { document.getElementById("frm_Taf").src = "https://archive.org/download/Quran4u_Tafsir_Ayah_Jal/" + this.pad(this.jsqariSurah, 3) + '001.html'; }; if (this.jsqariAyah > 0) { document.getElementById("frm_Taf").src = "https://archive.org/download/Quran4u_Tafsir_Ayah_Jal/" + this.pad(this.jsqariSurah, 3) + this.pad(this.jsqariAyah, 3) + '.html'; }; //document.getElementById("frm_Taf").src = "Quran-Ayah-Tafseer2.aspx?Surah=" + this.jsqariSurah + "&Ayah=" + this.jsqariAyah; }, setBasmalahStatus: function () { if (this.jsqariAyah == 1 && (this.jsqariSurah != 1 && this.jsqariSurah != 9)) { this.jsqariBasmalahPlayed = false; } else { this.jsqariBasmalahPlayed = true; } }, pad: function (number, length) { var str = '' + number; while (str.length < length) { str = '0' + str; } return str; } } function Img_border_On(iid) { document.getElementById(iid).border = '1'; } function Img_border_Off(iiid) { document.getElementById(iiid).border = '0'; } function play_next() { //alert (kk.val()) document.getElementById("ayahNumber").value = parseInt(document.getElementById("ayahNumber").value) + 1 jsQari.playSurahAyah($('#surahNumber').val(), $('#ayahNumber').val()); } function PlayAya() { jsQari.playSurahAyah($('#surahNumber').val(), $('#ayahNumber').val()); }; function opentafsir() { var ourayah1 = document.getElementById("ayahNumber").value var oursurah1 = document.getElementById("surahNumber").value var width = 660; var height = 500; var x = (800 - width) / 2; var y = (600 - height) / 2; if (screen) { y = (screen.availHeight - height) / 2; x = (screen.availWidth - width) / 2; } // alert('Quran-Ayah-Tafseer.aspx?Surah=' + oursurah1 + '&Ayah=' + ourayah1) window.open('Quran-Ayah-Tafseer.aspx?Surah=' + oursurah1 + '&Ayah=' + ourayah1, 'newWin', 'width=' + width + ',height=' + height + ',screenX=' + x + ',scrollbars=yes,screenY=' + y + ',top=' + y + ',left=' + x) }; ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// function createCookie(name, value, days) { if (days) { var date = new Date(); date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000)); var expires = "; expires=" + date.toGMTString(); } else var expires = ""; document.cookie = escape(name) + "=" + escape(value) + expires + "; path=/"; } function readCookie(name) { var nameEQ = escape(name) + "="; var ca = document.cookie.split(';'); for (var i = 0; i < ca.length; i++) { var c = ca[i]; while (c.charAt(0) == ' ') c = c.substring(1, c.length); if (c.indexOf(nameEQ) == 0) return unescape(c.substring(nameEQ.length, c.length)); } return null; } function eraseCookie(name) { createCookie(name, "", -1); } //---------------------------------------------------------------------------------------------------------------------- function save_it() { if (are_cookies_enabled() == true) { var finalsurah = document.getElementById('jsqari-ui-surah-selector').selectedIndex + 1; var finalayah = document.getElementById('jsqari-ui-ayah-selector').selectedIndex + 1; var toayah = document.getElementById('jsqari-ui-ayah-selector2').selectedIndex + 1; var finalreciter = document.getElementById('jsqari-ui-reciter-selector').selectedIndex; createCookie('ayah_ayah_lastsurah', finalsurah, '365'); createCookie('ayah_ayah_lastayah', finalayah, '365'); createCookie('ayah_ayah_toayah', toayah, '365'); createCookie('ayah_ayah_reciternum', finalreciter, '365'); } else { alert("المتصفح المستعمل لايقبل الحفظ - Please Allow cookies") } }; //----------------------------------------------------------------- function are_cookies_enabled() { var cookieEnabled = (navigator.cookieEnabled) ? true : false; if (typeof navigator.cookieEnabled == "undefined" && !cookieEnabled) { document.cookie = "testcookie"; cookieEnabled = (document.cookie.indexOf("testcookie") != -1) ? true : false; } return (cookieEnabled); } function del_it() { eraseCookie('ayah_ayah_lastsurah'); eraseCookie('ayah_ayah_lastayah'); eraseCookie('ayah_ayah_reciternum'); }; //--------------------------------------------------------------------------------------------------------------------------------------------------------------- function get_it() { if (document.cookie.indexOf("ayah_ayah_lastsurah") >= 0) { var savedsurah = readCookie('ayah_ayah_lastsurah'); var savedayah = readCookie('ayah_ayah_lastayah'); var savedtoayah = readCookie('ayah_ayah_toayah'); var savedrecieternum = readCookie('ayah_ayah_reciternum'); document.getElementById('jsqari-ui-surah-selector').selectedIndex = savedsurah; document.getElementById('jsqari-ui-ayah-selector').selectedIndex = savedayah; //* document.getElementById('jsqari-ui-reciter-selector').selectedIndex = savedrecieternum; jsQari.jsqariReciter = document.getElementById('jsqari-ui-reciter-selector').value; //* document.getElementById("surahNumber").value = savedsurah; document.getElementById("ayahNumber").value = savedayah; //* jsQari.playSurahAyah(savedsurah, savedayah); jsQari.jsqariPlayer.jPlayer('stop'); document.getElementById('jsqari-ui-ayah-selector2').selectedIndex = savedtoayah - 1; } }