Created
August 10, 2009 08:46
-
-
Save ahmedre/165091 to your computer and use it in GitHub Desktop.
quran plugin for ubiquity 0.5+
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CmdUtils.CreateCommand({ | |
names: ["search quran", "search-quran"], | |
homepage: "http://whatstheplot.com", | |
icon: "http://alpha.quranicrealm.com/images/favicon.ico", | |
arguments: [ {role: 'object', nountype: noun_arb_text, label: 'query'} ], | |
preview: function( pblock, args ) { | |
if (args.object.text.length < 1){ | |
pblock.innerHTML = "will search the quran for the specified text"; | |
return; | |
} | |
var baseUrl = "http://alpha.api.searchquran.net/v1/search"; | |
var params = {q: args.object.text}; | |
jQuery.getJSON(baseUrl, params, function(data){ | |
var matches = 0; | |
var resultText = ""; | |
jQuery.each(data.results, function(i, item){ | |
matches++; | |
if (matches < 4){ | |
resultText += "<b>" + item.sura + ":" + item.ayah + "</b> - "; | |
resultText += "<div style=\"direction:rtl\">" + | |
item.arabic + "</div>"; | |
resultText += "<br>" + item.match + "<br><br>"; | |
} | |
}); | |
if (matches == 0) | |
pblock.innerHTML = "no results found."; | |
else pblock.innerHTML = resultText; | |
}); | |
}, | |
execute: function( args ) { | |
var url = "http://alpha.searchquran.net/search?q={QUERY}"; | |
url = url.replace("{QUERY}", args.object.text); | |
Utils.openUrlInBrowser(url); | |
} | |
}) | |
var quran_type_link = new CmdUtils.NounType("translation or text", | |
["arabic", "arabic [no tashkeel]", "english - yusuf ali", "english - muhsin khan", | |
"english - pickthal", "english - sahih international", "english - dr. ghali", | |
"english - shakir", "transliteration"] | |
); | |
CmdUtils.CreateCommand({ | |
names: ["get ayah", "get-ayah", "ayah"], | |
homepage: "http://whatstheplot.com", | |
icon: "http://alpha.quranicrealm.com/images/favicon.ico", | |
arguments: [ {role: 'object', nountype: /[0-9]+:[0-9]+/, label: 'sura:ayah'}, | |
{role: 'format', nountype: quran_type_link} ], | |
preview: "will insert the specified ayah into the selection", | |
execute: function( args ) { | |
var url = "http://alpha.api.searchquran.net/v1/sura/"; | |
parts = args.object.text.split(':'); | |
url = url + parts[0] + '/' + parts[1]; | |
resultText = ''; | |
lang = 2; | |
if (args.format){ | |
translation = args.format.text.toLowerCase(); | |
// this isn't good - need to fix the api | |
if (translation.indexOf('no tashkeel')!=-1){ lang = 4; } | |
else if (translation.indexOf('arabic')!=-1){ lang = 2; } | |
else if (translation.indexOf('muhsin')!=-1){ lang = 8; } | |
else if (translation.indexOf('yusuf')!=-1){ lang = 16; } | |
else if (translation.indexOf('pickthal')!=-1){ lang = 32; } | |
else if (translation.indexOf('shakir')!=-1){ lang = 64; } | |
else if (translation.indexOf('sahih')!=-1){ lang = 256; } | |
else if (translation.indexOf('ghali')!=-1){ lang = 512; } | |
else if (translation.indexOf('transliteration')!=-1){ lang = 128; } | |
} | |
var params = {langs: lang}; | |
jQuery.getJSON(url, params, function(data){ | |
jQuery.each(data.verses, function(i, item){ | |
resultText += item[lang]; | |
}); | |
CmdUtils.setSelection(resultText); | |
}); | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment