/ Published in: jQuery
forms part of our Calibre Remote. an alternate gui for calibre ebooks content-server.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
$(document).ready( function() { var _content = $('#content'), _url = "calibre.php"; hover(); $('#header section a.qs-link').live("click", function(event) { event.preventDefault(); var _this = $(this); _this.parents("section").find("a").removeClass("active").end().end().addClass("active"); var qs = get_query_string(); empty_content(_content); $.get(_url + qs, function(response) { load_content(_content, response); }); }); $('#search input').live("focus", function(event) { $(this).val(""); }); $('#search a.button').live("click", function(event) { event.preventDefault(); var _search = $(this).siblings("input").val(); if(_search == this.defaultValue || _search.length < 1) return false; var qs = get_query_string(); empty_content(_content); $.get(_url + qs, function(response) { load_content(_content, response); }); }); $('a.define.server').live("click", function(event) { event.preventDefault(); $('article.error').hide(0); $('.server.config input').each( function() { $(this).val(this.defaultValue); }); $('.server.config').show(0); }); $('a.save.server').live("click", function(event) { event.preventDefault(); $('.server.config input').each( function() { var attrib = $(this).attr("name"); $('#server #'+ attrib).text($(this).val()); }); $('.server.config').hide(0); var qs = get_query_string(); empty_content(_content); $.get(_url + qs, function(response) { load_content(_content, response); }); }); $('.paginate a').live("click", function(event) { event.preventDefault(); var href = $(this).attr("href").split("/"); var qs = get_query_string(); empty_content(_content); $.get(_url + qs +"&start="+ href[1], function(response) { load_content(_content, response); }); }); $('.paginate select.paginate').live("change", function() { var page = $(this).find(":selected").val(); var qs = get_query_string(); empty_content(_content); $.get(_url + qs +"&start="+ page, function(response) { load_content(_content, response); }); }); $('article.book img').live("click", function() { $(this).toggleClass("large").parents("article.book").toggleClass("active"); }); }); function get_query_string() { var qs = []; $('a.qs-link.active').each( function(i) { var hr = $(this).attr("href").split("/"); qs[i] = hr[0] +"="+ hr[1]; }); return "?"+ qs.join("&") +"&"+ get_server_config(); }; function get_server_config() { var sc = []; $('#server div').each( function(i) { sc[i] = $(this).attr("id") +"="+ $(this).text(); }); return sc.join("&") + get_search_terms(); }; function get_search_terms() { var server ="&search="; if($('input.search').val().length > 0) server += $('input.search').val(); return server; }; function empty_content(_content) { _content.addClass("loading").find(".book, .error, .paginate").remove(); _content.find(".server.config").hide(0); }; function load_content(_content, response) { _content.removeClass("loading").find(".book, .error, .paginate").remove(); _content.append(response); }; function hover() { $('.hover_off').hover( function() { $(this).addClass("hover_on").removeClass("hover_off"); }, function() { $(this).addClass("hover_off").removeClass("hover_on"); } ); };
URL: http://www.pixaweb.co.uk/calibre/