parent
18744975b3
commit
ede8ae6742
|
@ -5,6 +5,8 @@
|
||||||
* Douban Books api document: https://developers.douban.com/wiki/?title=book_v2 (Chinese Only)
|
* Douban Books api document: https://developers.douban.com/wiki/?title=book_v2 (Chinese Only)
|
||||||
*/
|
*/
|
||||||
/* global i18nMsg */
|
/* global i18nMsg */
|
||||||
|
var dbResults = [];
|
||||||
|
var ggResults = [];
|
||||||
|
|
||||||
$(document).ready(function () {
|
$(document).ready(function () {
|
||||||
var msg = i18nMsg;
|
var msg = i18nMsg;
|
||||||
|
@ -19,8 +21,6 @@ $(document).ready(function () {
|
||||||
// var gg_get_info = "/books/v1/volumes/";
|
// var gg_get_info = "/books/v1/volumes/";
|
||||||
var ggDone = false;
|
var ggDone = false;
|
||||||
|
|
||||||
var dbResults = [];
|
|
||||||
var ggResults = [];
|
|
||||||
var showFlag = 0;
|
var showFlag = 0;
|
||||||
String.prototype.replaceAll = function (s1, s2) {
|
String.prototype.replaceAll = function (s1, s2) {
|
||||||
return this.replace(new RegExp(s1, "gm"), s2);
|
return this.replace(new RegExp(s1, "gm"), s2);
|
||||||
|
@ -32,11 +32,11 @@ $(document).ready(function () {
|
||||||
var bookHtml;
|
var bookHtml;
|
||||||
showFlag++;
|
showFlag++;
|
||||||
if (showFlag === 1) {
|
if (showFlag === 1) {
|
||||||
$("#meta-info").html("<ul id=\"book-list\" class=\"media-list\"></ul>");
|
$("#metaModal #meta-info").html("<ul id=\"book-list\" class=\"media-list\"></ul>");
|
||||||
}
|
}
|
||||||
if (ggDone && dbDone) {
|
if (ggDone && dbDone) {
|
||||||
if (!ggResults && !dbResults) {
|
if (!ggResults && !dbResults) {
|
||||||
$("#meta-info").html("<p class=\"text-danger\">"+ msg.no_result +"</p>");
|
$("#metaModal #meta-info").html("<p class=\"text-danger\">"+ msg.no_result +"</p>");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -51,8 +51,8 @@ $(document).ready(function () {
|
||||||
}
|
}
|
||||||
bookHtml = "<li class=\"media\">" +
|
bookHtml = "<li class=\"media\">" +
|
||||||
"<img class=\"pull-left img-responsive\" data-toggle=\"modal\" data-target=\"#metaModal\" src=\"" +
|
"<img class=\"pull-left img-responsive\" data-toggle=\"modal\" data-target=\"#metaModal\" src=\"" +
|
||||||
bookCover + "\" alt=\"Cover\" style=\"width:100px;height:150px\" onclick='javascript:getMeta(\"google\"," +
|
bookCover + "\" alt=\"Cover\" style=\"width:100px;height:150px\" onclick='getMeta(\"google\"," +
|
||||||
i + ")\\>\"" +
|
i + ")'>" +
|
||||||
"<div class=\"media-body\">" +
|
"<div class=\"media-body\">" +
|
||||||
"<h4 class=\"media-heading\"><a href=\"https://books.google.com/books?id=" +
|
"<h4 class=\"media-heading\"><a href=\"https://books.google.com/books?id=" +
|
||||||
book.id + "\" target=\"_blank\">" + book.volumeInfo.title + "</a></h4>" +
|
book.id + "\" target=\"_blank\">" + book.volumeInfo.title + "</a></h4>" +
|
||||||
|
@ -62,7 +62,7 @@ $(document).ready(function () {
|
||||||
"<p>"+ msg.source + ":<a href=\"https://books.google.com\" target=\"_blank\">Google Books</a></p>" +
|
"<p>"+ msg.source + ":<a href=\"https://books.google.com\" target=\"_blank\">Google Books</a></p>" +
|
||||||
"</div>" +
|
"</div>" +
|
||||||
"</li>";
|
"</li>";
|
||||||
$("#book-list").append(bookHtml);
|
$("#metaModal #book-list").append(bookHtml);
|
||||||
}
|
}
|
||||||
ggDone = false;
|
ggDone = false;
|
||||||
}
|
}
|
||||||
|
@ -71,8 +71,8 @@ $(document).ready(function () {
|
||||||
book = dbResults[i];
|
book = dbResults[i];
|
||||||
bookHtml = "<li class=\"media\">" +
|
bookHtml = "<li class=\"media\">" +
|
||||||
"<img class=\"pull-left img-responsive\" data-toggle=\"modal\" data-target=\"#metaModal\" src=\"" +
|
"<img class=\"pull-left img-responsive\" data-toggle=\"modal\" data-target=\"#metaModal\" src=\"" +
|
||||||
book.image + "\" alt=\"Cover\" style=\"width:100px;height: 150px\" onclick='javascript:getMeta(\"douban\"," +
|
book.image + "\" alt=\"Cover\" style=\"width:100px;height: 150px\" onclick='getMeta(\"douban\"," +
|
||||||
i + ")\\'>" +
|
i + ")'>" +
|
||||||
"<div class=\"media-body\">" +
|
"<div class=\"media-body\">" +
|
||||||
"<h4 class=\"media-heading\"><a href=\"https://book.douban.com/subject/" +
|
"<h4 class=\"media-heading\"><a href=\"https://book.douban.com/subject/" +
|
||||||
book.id + "\" target=\"_blank\">" + book.title + "</a></h4>" +
|
book.id + "\" target=\"_blank\">" + book.title + "</a></h4>" +
|
||||||
|
@ -82,7 +82,7 @@ $(document).ready(function () {
|
||||||
"<p>" + msg.source + ":<a href=\"https://book.douban.com\" target=\"_blank\">Douban Books</a></p>" +
|
"<p>" + msg.source + ":<a href=\"https://book.douban.com\" target=\"_blank\">Douban Books</a></p>" +
|
||||||
"</div>" +
|
"</div>" +
|
||||||
"</li>";
|
"</li>";
|
||||||
$("#book-list").append(bookHtml);
|
$("#metaModal #book-list").append(bookHtml);
|
||||||
}
|
}
|
||||||
dbDone = false;
|
dbDone = false;
|
||||||
}
|
}
|
||||||
|
@ -106,6 +106,53 @@ $(document).ready(function () {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function dbSearchBook (title) {
|
||||||
|
var url = douban + dbSearch + "?q=" + title + "&fields=all&count=10";
|
||||||
|
$.ajax({
|
||||||
|
url,
|
||||||
|
type: "GET",
|
||||||
|
dataType: "jsonp",
|
||||||
|
jsonp: "callback",
|
||||||
|
success (data) {
|
||||||
|
dbResults = data.books;
|
||||||
|
},
|
||||||
|
error () {
|
||||||
|
$("#metaModal #meta-info").html("<p class=\"text-danger\">"+ msg.search_error+"!</p>");
|
||||||
|
},
|
||||||
|
complete () {
|
||||||
|
dbDone = true;
|
||||||
|
showResult();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function doSearch (keyword) {
|
||||||
|
showFlag = 0;
|
||||||
|
$("#metaModal #meta-info").text(msg.loading);
|
||||||
|
// var keyword = $("#keyword").val();
|
||||||
|
if (keyword) {
|
||||||
|
dbSearchBook(keyword);
|
||||||
|
ggSearchBook(keyword);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$("#do-search").click(function () {
|
||||||
|
var keyword = $("#keyword").val();
|
||||||
|
if (keyword) {
|
||||||
|
doSearch(keyword);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
$("#get_meta").click(function () {
|
||||||
|
var bookTitle = $("#book_title").val();
|
||||||
|
if (bookTitle) {
|
||||||
|
$("#keyword").val(bookTitle);
|
||||||
|
doSearch(bookTitle);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
function getMeta (source, id) {
|
function getMeta (source, id) {
|
||||||
var meta;
|
var meta;
|
||||||
var tags;
|
var tags;
|
||||||
|
@ -137,50 +184,3 @@ $(document).ready(function () {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function dbSearchBook (title) {
|
|
||||||
var url = douban + dbSearch + "?q=" + title + "&fields=all&count=10";
|
|
||||||
$.ajax({
|
|
||||||
url,
|
|
||||||
type: "GET",
|
|
||||||
dataType: "jsonp",
|
|
||||||
jsonp: "callback",
|
|
||||||
success (data) {
|
|
||||||
dbResults = data.books;
|
|
||||||
},
|
|
||||||
error () {
|
|
||||||
$("#meta-info").html("<p class=\"text-danger\">"+ msg.search_error+"!</p>");
|
|
||||||
},
|
|
||||||
complete () {
|
|
||||||
dbDone = true;
|
|
||||||
showResult();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function doSearch (keyword) {
|
|
||||||
showFlag = 0;
|
|
||||||
$("#meta-info").text(msg.loading);
|
|
||||||
// var keyword = $("#keyword").val();
|
|
||||||
if (keyword) {
|
|
||||||
dbSearchBook(keyword);
|
|
||||||
ggSearchBook(keyword);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$("#do-search").click(function () {
|
|
||||||
var keyword = $("#keyword").val();
|
|
||||||
if (keyword) {
|
|
||||||
doSearch(keyword);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
$("#get_meta").click(function () {
|
|
||||||
var bookTitle = $("#book_title").val();
|
|
||||||
if (bookTitle) {
|
|
||||||
$("#keyword").val(bookTitle);
|
|
||||||
doSearch(bookTitle);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
|
|
@ -117,6 +117,9 @@
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block modal %}
|
||||||
{% if g.user.role_delete_books() %}
|
{% if g.user.role_delete_books() %}
|
||||||
<div class="modal fade" id="deleteModal" role="dialog" aria-labelledby="metaDeleteLabel">
|
<div class="modal fade" id="deleteModal" role="dialog" aria-labelledby="metaDeleteLabel">
|
||||||
<div class="modal-dialog">
|
<div class="modal-dialog">
|
||||||
|
|
|
@ -188,6 +188,7 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
{% block modal %}{% endblock %}
|
||||||
{% block js %}{% endblock %}
|
{% block js %}{% endblock %}
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user