Calibre Remote - JS/jQuery


/ Published in: jQuery
Save to your folder(s)

forms part of our Calibre Remote. an alternate gui for calibre ebooks content-server.


Copy this code and paste it in your HTML
  1. $(document).ready( function() {
  2.  
  3. var _content = $('#content'),
  4. _url = "calibre.php";
  5.  
  6. hover();
  7.  
  8. $('#header section a.qs-link').live("click", function(event) {
  9. event.preventDefault();
  10. var _this = $(this);
  11. _this.parents("section").find("a").removeClass("active").end().end().addClass("active");
  12. var qs = get_query_string();
  13. empty_content(_content);
  14. $.get(_url + qs, function(response) {
  15. load_content(_content, response);
  16. });
  17. });
  18.  
  19. $('#search input').live("focus", function(event) {
  20. $(this).val("");
  21. });
  22.  
  23. $('#search a.button').live("click", function(event) {
  24. event.preventDefault();
  25. var _search = $(this).siblings("input").val();
  26. if(_search == this.defaultValue || _search.length < 1)
  27. return false;
  28. var qs = get_query_string();
  29. empty_content(_content);
  30. $.get(_url + qs, function(response) {
  31. load_content(_content, response);
  32. });
  33. });
  34.  
  35. $('a.define.server').live("click", function(event) {
  36. event.preventDefault();
  37. $('article.error').hide(0);
  38. $('.server.config input').each( function() {
  39. $(this).val(this.defaultValue);
  40. });
  41. $('.server.config').show(0);
  42. });
  43.  
  44. $('a.save.server').live("click", function(event) {
  45. event.preventDefault();
  46. $('.server.config input').each( function() {
  47. var attrib = $(this).attr("name");
  48. $('#server #'+ attrib).text($(this).val());
  49. });
  50. $('.server.config').hide(0);
  51. var qs = get_query_string();
  52. empty_content(_content);
  53. $.get(_url + qs, function(response) {
  54. load_content(_content, response);
  55. });
  56. });
  57.  
  58. $('.paginate a').live("click", function(event) {
  59. event.preventDefault();
  60. var href = $(this).attr("href").split("/");
  61. var qs = get_query_string();
  62. empty_content(_content);
  63. $.get(_url + qs +"&start="+ href[1], function(response) {
  64. load_content(_content, response);
  65. });
  66. });
  67.  
  68. $('.paginate select.paginate').live("change", function() {
  69. var page = $(this).find(":selected").val();
  70. var qs = get_query_string();
  71. empty_content(_content);
  72. $.get(_url + qs +"&start="+ page, function(response) {
  73. load_content(_content, response);
  74. });
  75. });
  76.  
  77. $('article.book img').live("click", function() {
  78. $(this).toggleClass("large").parents("article.book").toggleClass("active");
  79. });
  80.  
  81. });
  82.  
  83. function get_query_string() {
  84. var qs = [];
  85. $('a.qs-link.active').each( function(i) {
  86. var hr = $(this).attr("href").split("/");
  87. qs[i] = hr[0] +"="+ hr[1];
  88. });
  89. return "?"+ qs.join("&") +"&"+ get_server_config();
  90. };
  91.  
  92. function get_server_config() {
  93. var sc = [];
  94. $('#server div').each( function(i) {
  95. sc[i] = $(this).attr("id") +"="+ $(this).text();
  96. });
  97. return sc.join("&") + get_search_terms();
  98. };
  99.  
  100. function get_search_terms() {
  101. var server ="&search=";
  102. if($('input.search').val().length > 0)
  103. server += $('input.search').val();
  104. return server;
  105. };
  106.  
  107. function empty_content(_content) {
  108. _content.addClass("loading").find(".book, .error, .paginate").remove();
  109. _content.find(".server.config").hide(0);
  110. };
  111.  
  112. function load_content(_content, response) {
  113. _content.removeClass("loading").find(".book, .error, .paginate").remove();
  114. _content.append(response);
  115. };
  116.  
  117. function hover() {
  118. $('.hover_off').hover(
  119. function() {
  120. $(this).addClass("hover_on").removeClass("hover_off");
  121. },
  122. function() {
  123. $(this).addClass("hover_off").removeClass("hover_on");
  124. }
  125. );
  126. };

URL: http://www.pixaweb.co.uk/calibre/

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.