Created
August 7, 2014 14:39
-
-
Save A-gambit/4389c75571113cd9a8b5 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
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <meta charset="utf-8"> | |
| <title>Book</title> | |
| <style type="text/css" media="screen"> | |
| .result-google{ | |
| width: 50%; | |
| } | |
| .result-word-cat{ | |
| left: 50%; | |
| position: absolute; | |
| top: 10%; | |
| } | |
| .find{ | |
| display: block; | |
| width: 100%; | |
| } | |
| </style> | |
| </head> | |
| <script src="http://code.jquery.com/jquery-git2.js"></script> | |
| <body> | |
| <div class="find"> | |
| <input type="text" name="text" value="" class="text"> | |
| </div> | |
| <div class="result-google"></div> | |
| <div class="result-word-cat"></div> | |
| <script type="text/javascript"> | |
| var wordCatObj = [], | |
| isbnObj = []; | |
| function printWordCat(){ | |
| var el = $(".result-word-cat") | |
| el.html(""); | |
| $.each(wordCatObj, function(index, val) { | |
| var i = "<span>" + (index+1) + "</span>", | |
| authors = "<span>" + val.author + "</span>", | |
| title = "<span>" + val.title + "</span>", | |
| elDiv = "<div class='item-word'>" + i + " " + authors + " " + title + "</div>" | |
| el.append(elDiv) | |
| }) | |
| } | |
| function addToBib(list){ | |
| wordCatObj.push(list) | |
| printWordCat() | |
| } | |
| function findWordCat(obj){ | |
| console.log(isbnObj) | |
| getObjWordCat(obj.isbn) | |
| /*$.each(obj, function(index, val) { | |
| getObjWordCat(val.isbn) | |
| })*/ | |
| function getObjWordCat(isbn){ | |
| var config = { | |
| wskey: "isbvGOWBKcHL1Td6E87jL2QDLodVpBabo4xnviUIAIbGEy9KKhyIvuI3jxh7Bd4xUzjg4Mad72TX2QN0", | |
| q: isbn, | |
| url:"", | |
| dataType: 'jsonp' | |
| } | |
| config.url = "http://xisbn.worldcat.org/webservices/xid/isbn/"+config.q+"?method=getMetadata&format=json&fl=*" | |
| $.ajax(config) | |
| .done(function(data){ | |
| console.log(data) | |
| if(data.stat == "ok") addToBib(data.list[0]) | |
| }) | |
| } | |
| } | |
| function getForBibl(){ | |
| $(".item").click(function() { | |
| console.log(this) | |
| var num = parseInt(this.children[0].textContent) | |
| findWordCat(isbnObj[num]) | |
| }) | |
| } | |
| function printGoogle(isbnObj){ | |
| var el = $(".result-google") | |
| el.html(""); | |
| $.each(isbnObj, function(index, val) { | |
| var i = "<span>" + (index+1) + "</span>", | |
| authors = "<span>" + val.authors + "</span>", | |
| title = "<span>" + val.title + "</span>", | |
| elDiv = "<div class='item'>" + i + " " + authors + " " + title + "</div>" | |
| el.append(elDiv) | |
| }) | |
| getForBibl() | |
| } | |
| function getISBN(list){ | |
| isbnObj = []; | |
| $.each(list, function(index, val) { | |
| identify(val) | |
| }) | |
| function identify(val){ | |
| var inf = val.volumeInfo, | |
| authors = inf.authors, | |
| index = inf.industryIdentifiers; | |
| book = { | |
| authors: "", | |
| title: inf.title, | |
| isbn: "" | |
| } | |
| if(authors){ | |
| for (var i = 0; i < authors.length; i++){ | |
| if(authors[i]) book.authors = book.authors + authors[i] | |
| book.authors = (i!=authors.length-1) ? book.authors + ", " : book.authors | |
| } | |
| } else book.authors = "No Authors" | |
| if(index) | |
| book.isbn = index[0].identifier ? index[0].identifier : ""; | |
| isbnObj.push(book) | |
| } | |
| //findWordCat(isbnObj); | |
| printGoogle(isbnObj); | |
| } | |
| function findBook(word){ | |
| var config = { | |
| q: "", | |
| dataType: "jsonp", | |
| url: "", | |
| key: "AIzaSyDZAfYZSNJL9Ay2RngwN_0XtWDkSMfp4lk" | |
| } | |
| config.q = word | |
| config.url= "https://www.googleapis.com/books/v1/volumes?q="+config.q+"&langRestrict=en&maxResults=40&key="+config.key | |
| $.ajax(config) | |
| .done(function(list){ | |
| console.log(list) | |
| getISBN(list.items) | |
| }) | |
| } | |
| $(".find").click(function(){ | |
| var text = $(".text").val() | |
| findBook(text) | |
| }); | |
| $(".text").change(function(){ | |
| var text = $(this).val() | |
| findBook(text) | |
| }); | |
| </script> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment