/* * jquery booklet plugin * copyright (c) 2010 w. grauvogel (http://builtbywill.com/) * download by http://www.codefans.net * dual licensed under the mit (http://www.opensource.org/licenses/mit-license.php) * and gpl (http://www.opensource.org/licenses/gpl-license.php) licenses. * * version : 1.1.0 * * originally based on the work of: * 1) charles mangin (http://clickheredammit.com/pageflip/) */ (function (b) { b.fn.booklet = function (c) { var d = b.extend({}, b.fn.booklet.defaults, c); return b(this).each(function () { var j, e, h, k, f, g; if (typeof c == "string") { if (b(this).data("booklet")) { j = c.tolowercase(); h = b.fn.booklet.interfaces[b(this).data("id")]; if (j == "next") { h.next() } else { if (j == "prev") { h.prev() } } } } else { if (typeof c == "number") { if (b(this).data("booklet")) { g = c; h = b.fn.booklet.interfaces[b(this).data("id")]; if (g % 2 != 0) { g -= 1 } h.gotopage(g) } } else { e = b.extend(true, {}, d); k = b.fn.booklet.interfaces.length; for (f = 0; f < k; f++) { if (typeof b.fn.booklet.interfaces[f] == "undefined") { k = f; break } } h = new a(b(this), e, k); b.fn.booklet.interfaces[k] = h } } }) }; function a(ac, ae, g) { var ao, av, s, a, o, l, i, e, o, ad, ah, c, n, aw = new array(), k = new array(), f, ab, z, y, w, u, ay, ag, j, s, c, aq, am, ax, az, t, al, ak, r, aj, ai, m, d, b, af, y, e, d, l, x, q, v, r, an, w, k, u, p, n, au, t, g, ap = '
', at = '
'; ad = false; ah = false; c = n = false; ao = this; ao.options = ae; ao.id = g; ao.hash = ""; av = ao.options; s = ac.addclass("booklet"); a = s.children(".b-load"); h(); s.data("booklet", true); s.data("id", g); s.data("total", a.children().length); if (!av.width) { av.width = s.width() } if (!av.height) { av.height = s.height() } s.width(av.width); s.height(av.height); av.pwidth = av.width / 2; av.pwidthn = "-" + (av.width / 2) + "px"; av.pwidthh = av.width / 4; av.pheight = av.height; av.ptotal = a.children().length; av.speedh = av.speed / 2; if (av.direction == "ltr") { av.curr = 0 } else { if (av.direction == "rtl") { av.curr = av.ptotal - 2 } } if (!isnan(av.startingpage) && av.startingpage <= av.ptotal && av.startingpage > 0) { if ((av.startingpage % 2) != 0) { av.startingpage-- } av.curr = av.startingpage } if (av.name) { document.title = av.name } else { av.name = document.title } if (av.shadows) { av.shadowtopfwdwidth = "-" + av.shadowtopfwdwidth + "px"; av.shadowtopbackwidth = "-" + av.shadowtopbackwidth + "px" } if (av.menu) { l = b(av.menu).addclass("b-menu"); e = av.curr; if (av.pageselector) { q = b('
' + (e + 1) + " - " + (e + 2) + "
").appendto(l); v = b("").appendto(q).empty().css("height", "auto"); for (l = 0; l < av.ptotal; l += 2) { i = l; nums = (i + 1) + "-" + (i + 2); if (av.closed) { i--; if (l == 0) { nums = "1" } else { if (l == av.ptotal - 2) { nums = av.ptotal - 2 } else { nums = (i + 1) + "-" + (i + 2) } } if (av.covers) { i--; if (l == 0) { nums = "" } else { if (l == av.ptotal - 2) { nums = "" } else { nums = (i + 1) + "-" + (i + 2) } } } } if (av.direction == "rtl") { nums = (math.abs(i - av.ptotal) - 1) + " - " + ((math.abs(i - av.ptotal))); if (av.closed) { if (l == av.ptotal - 2) { nums = "1" } else { if (l == 0) { nums = av.ptotal - 2 } else { nums = (math.abs(i - av.ptotal) - 3) + " - " + ((math.abs(i - av.ptotal) - 2)) } } if (av.covers) { if (l == av.ptotal - 2) { nums = "" } else { if (l == 0) { nums = "" } else { nums = (math.abs(i - av.ptotal) - 5) + " - " + ((math.abs(i - av.ptotal) - 4)) } } } } q.find(".b-current").text(nums); an = b('
  • ' + aw[l + 1] + '' + nums + "
  • ").prependto(v) } else { if (l == 0) { q.find(".b-current").text(nums) } an = b('
  • ' + aw[l] + '' + nums + "
  • ").appendto(v) } w = an.find("a"); if (!av.hash) { w.click(function () { if (av.direction == "rtl") { q.find(".b-current").text(b(this).find(".b-num").text()) } k = parseint(b(this).attr("id").replace("selector-page-", "")); ao.gotopage(k); return false }) } } r = v.height(); v.css({ height: 0, "padding-bottom": 0 }); q.unbind("hover").hover(function () { v.stop().animate({ height: r, paddingbottom: 10 }, 500) }, function () { v.stop().animate({ height: 0, paddingbottom: 0 }, 500) }) } if (av.chapterselector) { x = k[av.curr]; if (x == "") { x = k[av.curr + 1] } u = b('
    ' + x + "
    ").appendto(l); p = b("").appendto(u).empty().css("height", "auto"); for (l = 0; l < av.ptotal; l += 1) { if (k[l] != "" && typeof k[l] != "undefined") { if (av.direction == "rtl") { i = l; if (i % 2 != 0) { i-- } u.find(".b-current").text(k[l]); au = b('
  • ' + k[l] + "
  • ").prependto(p) } else { au = b('
  • ' + k[l] + "
  • ").appendto(p) } t = au.find("a"); if (!av.hash) { t.click(function () { if (av.direction == "rtl") { u.find(".b-current").text(b(this).find(".b-text").text()) } g = parseint(b(this).attr("id").replace("selector-page-", "")); ao.gotopage(g); return false }) } } } n = p.height(); p.css({ height: 0, "padding-bottom": 0 }); u.unbind("hover").hover(function () { p.stop().animate({ height: n, paddingbottom: 10 }, 500) }, function () { p.stop().animate({ height: 0, paddingbottom: 0 }, 500) }) } } b.extend(ao, { next: function () { if (!ad) { ao.gotopage(av.curr + 2) } }, prev: function () { if (!ad) { ao.gotopage(av.curr - 2) } }, gotopage: function (i) { if (i > av.curr && i < av.ptotal && i >= 0 && !ad) { $(".book_wrapper").css("backgroundimage", "url(../theme/bg/bg.gif)"); ad = true; o = i - av.curr; av.curr = i; av.before.call(ao, av); ar(); z(); m(av.curr + 1, av); q(o, true, ax); y.stop().animate({ width: 0 }, av.speedh, av.easein); w.stop().animate({ left: av.pwidthh, width: av.pwidthh, paddingleft: av.shadowbtmwidth }, av.speedh, av.easein).animate({ left: 0, width: av.pwidth, paddingleft: 0 }, av.speedh); c.animate({ left: av.shadowbtmwidth }, av.speedh, av.easein).animate({ left: 0 }, av.speedh, av.easeout, function () { h() }); //alert(av.curr); //alert(av.ptotal); if (av.curr == av.ptotal - 2) { $(".book_wrapper").css("backgroundimage", "url(../theme/bg/bg2.gif)"); } } else { if (i < av.curr && i < av.ptotal && i >= 0 && !ad) { ad = true; o = av.curr - i; av.curr = i; av.before.call(ao, av); ar(); z(); m(av.curr + 1, av); q(o, false, az); z.animate({ left: av.pwidth, width: 0 }, av.speed, av.easing); j.animate({ left: av.pwidthn }, av.speed, av.easing); ab.animate({ left: av.pwidthh, width: av.pwidthh }, av.speedh, av.easein).animate({ left: av.pwidth, width: av.pwidth }, av.speedh, av.easeout); ag.animate({ right: av.shadowbtmwidth }, av.speedh, av.easein).animate({ right: 0 }, av.speedh, av.easeout, function () { h() }); if (i === 0) { //alert("yes"); $(".book_wrapper").css("backgroundimage", "url(../theme/bg/bg1.gif)"); } else { //alert("no"); $(".book_wrapper").css("backgroundimage", "url(../theme/bg/bg.gif)"); } } } } }); if (av.next) { af = b(av.next); af.click(function (i) { i.preventdefault(); ao.next() }) } if (av.prev) { y = b(av.prev); y.click(function (i) { i.preventdefault(); ao.prev() }) } if (av.overlays) { ak = b('
    ').appendto(s); al = b('
    ').appendto(s); t = s.find(".b-overlay"); if (b.browser.msie) { t.css({ background: "#fff", filter: "progid:dximagetransform.microsoft.alpha(opacity=0) !important" }) } } if (av.tabs) { ai = b('
    previous
    ').appendto(s); aj = b('
    next
    ').appendto(s); r = s.find(".b-tab"); if (av.tabwidth) { r.width(av.tabwidth) } if (av.tabheight) { r.height(av.tabheight) } r.css({ top: "-" + aj.outerheight() + "px" }); s.css({ margintop: aj.outerheight() }); if (av.direction == "rtl") { aj.html("previous").attr("title", "previous page"); ai.html("next").attr("title", "next page") } } else { s.css({ margintop: 0 }) } if (av.arrows) { b = b('
    previous
    ').appendto(s); d = b('
    next
    ').appendto(s); m = s.find(".b-arrow"); if (av.direction == "rtl") { d.html("
    previous
    ").attr("title", "previous page"); b.html("
    next
    ").attr("title", "next page") } } e = s.find(".b-next"); d = s.find(".b-prev"); e.click(function (i) { i.preventdefault(); ao.next() }); d.click(function (i) { i.preventdefault(); ao.prev() }); if (av.hovers) { e.hover(function () { if (!ad && av.curr + 2 <= av.ptotal - 2) { y.stop().animate({ width: av.pwidth - 40 }, 500, av.easing); w.stop().animate({ left: av.width - 40, width: 20, paddingleft: 10 }, 500, av.easing); c = true } }, function () { if (!ad && av.curr + 2 <= av.ptotal - 2) { y.stop().animate({ width: av.pwidth }, 500, av.easing); w.stop().animate({ left: av.width, width: 0, paddingleft: 0 }, 500, av.easing); c = false } }); d.hover(function () { if (!ad && av.curr - 2 >= 0) { z.stop().animate({ left: 10, width: av.pwidth - 10 }, 400, av.easing); j.stop().animate({ left: "-10px" }, 400, av.easing); ab.stop().animate({ left: 10, width: 40 }, 400, av.easing); ag.stop().animate({ right: 10 }, 400, av.easing); n = true } }, function () { if (!ad && av.curr - 2 >= 0) { z.stop().animate({ left: 0, width: av.pwidth }, 400, av.easing); j.stop().animate({ left: 0 }, 400, av.easing); ab.stop().animate({ left: 0, width: 0 }, 400, av.easing); ag.stop().animate({ right: 0 }, 400, av.easing); n = false } }) } if (av.arrows) { if (b.support.opacity) { e.hover(function () { d.find("div").stop().fadeto("fast", 1) }, function () { d.find("div").stop().fadeto("fast", 0) }); d.hover(function () { b.find("div").stop().fadeto("fast", 1) }, function () { b.find("div").stop().fadeto("fast", 0) }) } else { e.hover(function () { d.find("div").show() }, function () { d.find("div").hide() }); d.hover(function () { b.find("div").show() }, function () { b.find("div").hide() }) } } if (av.keyboard) { b(document).keyup(function (i) { if (i.keycode == 37) { ao.prev() } else { if (i.keycode == 39) { ao.next() } } }) } if (av.hash) { f(); // clearinterval(); setinterval(function () { v() }, 250) } aa(); function h() { if ((a.children().length % 2) != 0) { if (av.closed && av.covers) { a.children().last().before(at) } else { a.children().last().after(at) } } if (av.closed) { b(ap).attr({ title: av.closedfronttitle || "beginning", rel: av.closedfrontchapter || "beginning of book" }).prependto(a); a.children().last().attr({ title: av.closedbacktitle || "end", rel: av.closedbackchapter || "end of book" }); a.append(ap) } if (av.direction == "ltr") { i = 0 } else { i = a.children().length; if (av.closed) { i -= 2 } if (av.covers) { i -= 2 } b(a.children().get().reverse()).each(function () { b(this).appendto(a) }) } a.children().each(function (j) { if (b(this).attr("rel")) { k[j] = b(this).attr("rel") } else { k[j] = "" } aw[j] = b(this).attr("title"); if (b(this).hasclass("b-page-empty")) { b(this).wrap('
    ') } else { if (av.closed && av.covers && (j == 1 || j == a.children().length - 2)) { b(this).wrap('
    ') } else { if (j % 2 != 0) { b(this).wrap('
    ') } else { b(this).wrap('
    ') } } } b(this).parents(".b-page").addclass("b-page-" + j); if (av.pagenumbers && !b(this).hasclass("b-page-empty") && (!av.closed || (av.closed && !av.covers) || (av.closed && av.covers && j != 1 && j != a.children().length - 2))) { if (av.direction == "ltr") { i++ } b(this).parent().append('
    ' + (i) + "
    "); if (av.direction == "rtl") { i-- } } }) } function aa(s) { s.find(".b-page").removeclass("b-pn b-p0 b-p1 b-p2 b-p3 b-p4").hide(); if (ah) { i = av.ptotal - 1; for (l = 0; l < av.ptotal; l++) { s.find(".b-page-" + l).detach().appendto(a) } } if (av.curr - 2 >= 0) { s.find(".b-page-" + (av.curr - 2)).addclass("b-pn").show(); s.find(".b-page-" + (av.curr - 1)).addclass("b-p0").show() } s.find(".b-page-" + (av.curr)).addclass("b-p1").show(); s.find(".b-page-" + (av.curr + 1)).addclass("b-p2").show(); if (av.curr + 3 <= av.ptotal) { s.find(".b-page-" + (av.curr + 2)).addclass("b-p3").show(); s.find(".b-page-" + (av.curr + 3)).addclass("b-p4").show() } f = s.find(".b-pn"); ab = s.find(".b-p0"); z = s.find(".b-p1"); y = s.find(".b-p2"); w = s.find(".b-p3"); u = s.find(".b-p4"); ay = s.find(".b-pn .b-wrap"); ag = s.find(".b-p0 .b-wrap"); j = s.find(".b-p1 .b-wrap"); s = s.find(".b-p2 .b-wrap"); c = s.find(".b-p3 .b-wrap"); aq = s.find(".b-p4 .b-wrap"); am = s.find(".b-wrap"); am.attr("style", ""); am.css({ width: av.pwidth - (av.pagepadding * 2), height: av.pheight - (av.pagepadding * 2), padding: av.pagepadding }); z.css({ left: 0, width: av.pwidth, height: av.pheight }); if (s==true) { y.css({ left: "25%", width: av.pwidth, opacity: 1, height: av.pheight }); } else { y.css({ left: av.pwidth, width: av.pwidth, opacity: 1, height: av.pheight }); } f.css({ left: 0, width: av.pwidth, height: av.pheight }); ab.css({ left: 0, width: 0, height: av.pheight }); w.stop().css({ left: av.pwidth * 2, width: 0, height: av.pheight, paddingleft: 0 }); c.stop().css({ left: 0 }); u.css({ left: av.pwidth , width: av.pwidth, height: av.pheight }); if (av.curr + 3 <= av.ptotal) { w.after(ab.detach()); z.after(u.detach()) } else { ab.detach().appendto(a) } ah = true; ax = az = null; s.find(".b-shadow-b, .b-shadow-f").remove(); if (av.shadows) { ax = b('
    ').appendto(w).css({ right: 0, width: av.pwidth, height: av.pheight }); az = b('
    ').appendto(ab).css({ left: 0, width: av.pwidth, height: av.pheight }) } } function q(j, i, p) { if (i && j > 2) { s.find(".b-p3, .b-p4").removeclass("b-p3 b-p4").hide(); s.find(".b-page-" + av.curr).addclass("b-p3").show().stop().css({ left: av.pwidth * 2, width: 0, height: av.pheight, paddingleft: 0 }); s.find(".b-page-" + (av.curr + 1)).addclass("b-p4").show().css({ left: av.pwidth, width: av.pwidth, height: av.pheight }); s.find(".b-page-" + av.curr + " .b-wrap").show().css({ width: av.pwidth - (av.pagepadding * 2), height: av.pheight - (av.pagepadding * 2), padding: av.pagepadding }); s.find(".b-page-" + (av.curr + 1) + " .b-wrap").show().css({ width: av.pwidth - (av.pagepadding * 2), height: av.pheight - (av.pagepadding * 2), padding: av.pagepadding }); w = s.find(".b-p3"); u = s.find(".b-p4"); c = s.find(".b-p3 .b-wrap"); aq = s.find(".b-p4 .b-wrap"); if (c) { w.css({ left: av.width - 40, width: 20, "padding-left": 10 }) } p.appendto(w); z.after(u.detach()); y.after(w.detach()) } else { if (!i && j > 2) { s.find(".b-pn, .b-p0").removeclass("b-pn b-p0").hide(); s.find(".b-page-" + av.curr).addclass("b-pn").show().css({ left: 0, width: av.pwidth, height: av.pheight }); s.find(".b-page-" + (av.curr + 1)).addclass("b-p0").show().css({ left: 0, width: 0, height: av.pheight }); s.find(".b-page-" + av.curr + " .b-wrap").show().css({ width: av.pwidth - (av.pagepadding * 2), height: av.pheight - (av.pagepadding * 2), padding: av.pagepadding }); s.find(".b-page-" + (av.curr + 1) + " .b-wrap").show().css({ width: av.pwidth - (av.pagepadding * 2), height: av.pheight - (av.pagepadding * 2), padding: av.pagepadding }); f = s.find(".b-pn"); ab = s.find(".b-p0"); ay = s.find(".b-pn .b-wrap"); ag = s.find(".b-p0 .b-wrap"); if (n) { ab.css({ left: 10, width: 40 }); ag.css({ right: 10 }) } p.appendto(ab); ab.detach().appendto(a) } } if (av.closed) { if (!i && av.curr == 0) { f.hide() } else { if (!i) { f.show() } } if (i && av.curr >= av.ptotal - 2) { u.hide() } else { if (i) { u.show() } } } if (av.shadows) { if (b.support.opacity) { p.animate({ opacity: 1 }, av.speedh, av.easein).animate({ opacity: 0 }, av.speedh, av.easeout) } else { if (i) { p.animate({ right: av.shadowtopfwdwidth }, av.speed, av.easein) } else { p.animate({ left: av.shadowtopbackwidth }, av.speed, av.easein) } } } } function h() { aa(); ar(); z(); av.after.call(ao, av); ad = false } function z() { if (av.overlays || av.tabs || av.arrows) { if (av.curr < av.ptotal - 2) { e.fadein("fast").css("cursor", av.cursor) } else { e.fadeout("fast").css("cursor", "default") } if (av.curr >= 2 && av.curr != 0) { d.fadein("fast").css("cursor", av.cursor) } else { d.fadeout("fast").css("cursor", "default") } } } function ar() { if (av.pageselector) { if (av.direction == "rtl") { nums = (math.abs(av.curr - av.ptotal) - 1) + " - " + ((math.abs(av.curr - av.ptotal))); if (av.closed) { if (av.curr == av.ptotal - 2) { nums = "1" } else { if (av.curr == 0) { nums = av.ptotal - 2 } else { nums = (math.abs(av.curr - av.ptotal) - 2) + " - " + ((math.abs(av.curr - av.ptotal) - 1)) } } if (av.covers) { if (av.curr == av.ptotal - 2) { nums = "" } else { if (av.curr == 0) { nums = "" } else { nums = (math.abs(av.curr - av.ptotal) - 3) + " - " + ((math.abs(av.curr - av.ptotal) - 2)) } } } } b(av.menu + " .b-selector-page .b-current").text(nums) } else { nums = (av.curr + 1) + " - " + (av.curr + 2); if (av.closed) { if (av.curr == 0) { nums = "1" } else { if (av.curr == av.ptotal - 2) { nums = av.ptotal - 2 } else { nums = (av.curr) + "-" + (av.curr + 1) } } if (av.covers) { if (av.curr == 0) { nums = "" } else { if (av.curr == av.ptotal - 2) { nums = "" } else { nums = (av.curr - 1) + "-" + (av.curr) } } } } b(av.menu + " .b-selector-page .b-current").text(nums) } } if (av.chapterselector) { if (k[av.curr] != "") { b(av.menu + " .b-selector-chapter .b-current").text(k[av.curr]) } else { if (k[av.curr + 1] != "") { b(av.menu + " .b-selector-chapter .b-current").text(k[av.curr + 1]) } } if (av.direction == "rtl" && k[av.curr + 1] != "") { b(av.menu + " .b-selector-chapter .b-current").text(k[av.curr + 1]) } else { if (k[av.curr] != "") { b(av.menu + " .b-selector-chapter .b-current").text(k[av.curr]) } } } } function f() { o = x(); if (!isnan(o) && o <= av.ptotal - 1 && o >= 0 && o != "") { if ((o % 2) != 0) { o-- } av.curr = o } else { m(av.curr + 1, av) } ao.hash = o } function v() { o = x(); if (!isnan(o) && o <= av.ptotal - 1 && o >= 0) { if (o != av.curr && o.tostring() != ao.hash) { if ((o % 2) != 0) { o-- } document.title = av.name + " - page " + (o + 1); if (!ad) { ao.gotopage(o); ao.hash = o } } } } function x() { var i = window.location.hash.split("/"); if (i.length > 1) { return parseint(i[2]) - 1 } else { return "" } } function m(j, i) { if (i.hash) { window.location.hash = "/page/" + j } } } b.fn.booklet.interfaces = []; b.fn.booklet.defaults = { name: null, width: 600, height: 400, speed: 1000, direction: "ltr", startingpage: 0, easing: "easeinoutquad", easein: "easeinquad", easeout: "easeoutquad", closed: false, closedfronttitle: null, closedfrontchapter: null, closedbacktitle: null, closedbackchapter: null, covers: false, pagepadding: 10, pagenumbers: true, hovers: true, overlays: true, tabs: false, tabwidth: 60, tabheight: 20, arrows: false, cursor: "pointer", hash: false, keyboard: true, next: null, prev: null, menu: null, pageselector: false, chapterselector: false, shadows: true, shadowtopfwdwidth: 166, shadowtopbackwidth: 166, shadowbtmwidth: 50, before: function () { }, after: function () { } } })(jquery);