Created
July 20, 2009 17:30
-
-
Save jasonong/150463 to your computer and use it in GitHub Desktop.
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
//General function for retrieving verses | |
function verseQuery ( apiParams, callback) { | |
var apiUrl = "http://www.esvapi.org/v2/rest/passageQuery?"; | |
jQuery.ajax({ | |
type: "GET", | |
url: apiUrl, | |
dataType: "html", | |
data: apiParams, | |
error: function() { | |
callback ( "Error searching the ESV Bible." ); | |
}, | |
success: function(responseData) { | |
callback ( responseData ); | |
} | |
}); | |
}; | |
//General function for previewing verses | |
function versePreview (previewBlock, inputObject, myVerseQuery, myNoInputMessage) { | |
if (inputObject.text.length < 1) { | |
previewBlock.innerHTML = myNoInputMessage; | |
return; | |
} | |
previewBlock.innerHTML = "Searching for ESV Bible passages matching " + inputObject.summary + "..."; | |
var originalInput = inputObject.text; | |
myVerseQuery( inputObject.text, function( verse ) { | |
if (inputObject.text == originalInput) { | |
previewBlock.innerHTML = verse; | |
} | |
}); | |
}; | |
//General function for inserting verses | |
function verseInsert (inputObject, myVerseQuery) { | |
if (inputObject.text.length < 1) { | |
displayMessage("Please enter a verse reference."); | |
return; | |
} | |
myVerseQuery( inputObject.text , function( verse ) { | |
CmdUtils.setSelection( verse, "text" ); | |
}); | |
}; | |
//Main function for rich-text esv-insert command | |
CmdUtils.CreateCommand({ | |
name: "esv-insert", | |
synonyms: [ "insert-esv", "esvinsert" ], | |
homepage: "http://www.duncanandmeg.org/projects/ubiquity-esv-insert.php", | |
author: { name: "Duncan Johnson", email: "[email protected]" }, | |
license: "GPL", | |
takes: { "verse reference": noun_arb_text }, | |
icon: "http://www.esv.org/favicon.ico", | |
description: "Inserts a passage from the ESV Bible in rich-text format. Also responds to \"insert-esv\" and \"esvinsert\".", | |
help: "Best for inserting ESV text when rich-text editing is supported. Try selecting a Bible reference and then issuing \"esv-insert this\". You can also insert a verse by issuing \"esv-insert\" and then typing your reference into the command window. ESV footnotes and section headings \<b\>are\</b\> inserted. \<h3\>Sample output:\</h3\>\<div class=\"esv\"\>\<h2\>Mark 1:1\</h2\>\<div class=\"esv-text\"\>\<h3 id=\"p41001001.01-1\"\>John the Baptist Prepares the Way\</h3\>\<p class=\"chapter-first\" id=\"p41001001.07-1\"\>\<span class=\"chapter-num\" id=\"v41001001-1\"\>1:1 \</span\>The beginning of the gospel of Jesus Christ, the Son of God.\<span class=\"footnote\"\> \<a href=\"#f1\" id=\"b1\" title=\"Some manuscripts omit 'the Son of God'\"\>[1]\</a\>\</span\> (\<a href=\"http://www.esv.org/\" class=\"copyright\"\>ESV\</a\>)\</p\>\</div\>\<div class=\"footnotes\"\>\<h3\>Footnotes\</h3\>\<p\>\<span class=\"footnote\"\>\<a href=\"#b1\" id=\"f1\"\>[1]\</a\>\</span\> \<span class=\"footnote-ref\"\>1:1\</span\> Some manuscripts omit \<i\>the Son of God\</i\>\</p\>\</div\>\</div\>", | |
_getVerse: function ( inputText, callback ) { | |
var apiParams = { | |
key: "IP", | |
"link-url": "http://www.gnpcb.org/esv/search/", | |
"include-audio-link": "false", | |
"passage": inputText | |
}; | |
verseQuery(apiParams, callback); | |
}, | |
preview: function(previewBlock, inputObject) { | |
versePreview(previewBlock, inputObject, this._getVerse, this.description); | |
}, | |
execute: function(inputObject) { | |
verseInsert(inputObject, this._getVerse); | |
} | |
}); | |
//Main function for plain-text esv-insert-plain command | |
CmdUtils.CreateCommand({ | |
name: "esv-insert-plain", | |
synonyms: [ "insert-plain-esv", "esvinsertplain", "esvplaininsert", "plainesv" ], | |
homepage: "http://www.duncanandmeg.org/projects/ubiquity-esv-insert.php", | |
author: { name: "Duncan Johnson", email: "[email protected]" }, | |
license: "GPL", | |
takes: { "verse reference": noun_arb_text }, | |
icon: "http://www.esv.org/favicon.ico", | |
description: "Inserts a passage from the ESV Bible in plain-text format. Also responds to \"insert-plain-esv\", \"esvinsertplain\", \"esvplaininsert\", or \"plainesv\".", | |
help: "Best for inserting ESV text when rich-text editing is not supported. Try selecting a Bible reference and then issuing \"esv-insert-plain this\". You can also insert a verse by issuing \"esv-insert-plain\" and then typing your reference into the command window. ESV footnotes and section headings are \<b\>not\</b\> inserted. \<h3\>Sample output:\</h3\>Mark 1:1 The beginning of the gospel of Jesus Christ, the Son of God. (ESV)", | |
_getVerse: function ( inputText, callback ) { | |
var apiParams = { | |
key: "IP", | |
"output-format": "plain-text", | |
"include-passage-horizontal-lines": "false", | |
"include-heading-horizontal-lines": "false", | |
"include-headings": "false", | |
"include-subheadings": "false", | |
"include-footnotes": "false", | |
"include-first-verse-numbers": "false", | |
"passage": inputText | |
}; | |
verseQuery(apiParams, callback); | |
}, | |
preview: function(previewBlock, inputObject) { | |
versePreview(previewBlock, inputObject, this._getVerse, this.description); | |
}, | |
execute: function(inputObject) { | |
verseInsert(inputObject, this._getVerse); | |
} | |
}); | |
//Main function for esv-search command | |
CmdUtils.makeSearchCommand({ | |
name: "esv-search", | |
synonyms: [ "esvsearch", "search-esv", "searchesv" ], | |
url: "http://www.gnpcb.org/esv/search/?q={QUERY}", | |
homepage: "http://www.duncanandmeg.org/projects/ubiquity-esv-insert.php", | |
author: { name: "Duncan Johnson", email: "[email protected]" }, | |
license: "GPL", | |
takes: { "verse reference": noun_arb_text }, | |
icon: "http://www.esv.org/favicon.ico", | |
description: "Searches the ESV Bible by verse reference or keyword. Also responds to \"esvsearch\", \"search-esv\", or \"searchesv\".", | |
help: "Try selecting a Bible reference or phrase and then issuing \"esv-search this\". You can also search by issuing \"esv-search\" and then typing your reference into the command window. Press ENTER to open the ESV search results in your browser window.", | |
_getVerse: function ( inputText, callback ) { | |
var apiParams = { | |
key: "IP", | |
"link-url": "http://www.gnpcb.org/esv/search/", | |
"include-audio-link": "false", | |
q: inputText | |
}; | |
verseQuery(apiParams, callback); | |
}, | |
preview: function(previewBlock, inputObject) { | |
versePreview(previewBlock, inputObject, this._getVerse, this.description); | |
}, | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment