1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184
|
;(function($) {
$.fn.extend({
imBookFlip: function(options) {
opts = $.extend({}, $.bookFlip.defaults, options);
return this.each(function() {
new $.bookFlip(this, opts);
});
}
});
$.bookFlip = function(obj, opts) {
var $this = $(obj);
var numPages = 0;
var leftStart=0,rightStart=1;
var autoPage = 0;
var page, book, bW, pageW, pageH, bookOpenW = '';
if (opts.sound_manager) {
loadAudio();
}
if (opts.iframe.src) {
loadIFrame();
} else {
page = $('.'+opts.page_class)[0];
init();
}
function loadIFrame() {
var iframe = $this.append($('<iframe src="'+opts.iframe.src+'" id="bookFlipIframe" name="bookFlipIframe"></iframe>').css({"width":$this.width(), "height": $this.height(), "border": "0px", "overflow":"hidden"}));
$('#bookFlipIframe').load(function() {
book = $('#bookFlipIframe').contents().find('#'+opts.iframe.book);
page = $('#bookFlipIframe').contents().find('.'+opts.page_class)[0];
init();
});
};
function init() {
bW = parseInt($(page).css('borderLeftWidth')) + parseInt($(page).css('borderRightWidth'));
pageW = parseInt($(page).css('width')) + bW;
pageH = parseInt($(page).css('height')) + bW;
bookOpenW = pageW*2;
//var showBinder=false; //change to false for no binder
//var binderImage = "parchmentring2.gif"; //location of center binder
//var binderWidth = 20; //width of center binder image
if(opts.numPixels>100){opts.numPixels=100;};
createPages();
};
function loadAudio() {
var ld = (opts.autoFlip != 'click');
var dbg = false;
if (opts.sound_manager.debug) {
dbg = opts.sound_manager.debug;
}
soundManager.url = opts.sound_manager.swf_loc;
soundManager.debugMode = dbg;
soundManager.onload = function() {
// soundManager is initialised, ready to use. Create a sound for this demo page.
soundManager.createSound({
id: 'bookAudio',
url: opts.sound_manager.audio_loc,
autoLoad: true,
autoPlay: ld
});
}
};
function createPages() {
var pages;
if (opts.iframe.src) {
$this = $(book);
pages = $this.find(' > div');
} else {
var bk = $this.attr('id');
pages = $('#'+bk + ' > div');
}
$this.css({'width': (bookOpenW + 'px'), 'height': pageH+'px', 'zIndex':0});
$(pages).each(function(i) {
numPages++;
var orig = $(this).clone();
var div = $('<div></div>').attr({'id': 'pageNum'+i, 'class': opts.page_class}).css({'zIndex':20-i, 'border': 'none', 'left': pageW+'px', 'width': pageW+'px', 'height': pageH+'px'});
$(this).replaceWith(div);
$(orig).attr('id', 'pageFlip'+i);
/*if(!number_check(i)){
if(document.all){
$(orig).css('filter', 'progid:DXImageTransform.Microsoft.Alpha(Opacity=100, FinishOpacity=30, Style=1, StartX=80, FinishX=100, StartY=0, FinishY=0)');
}else{
var pngDiv = $('<div></div>').css({'position': 'absolute', 'left':pWidth-80+'px', 'top':'0px', 'width':80+'px', 'height': pHeight+'px', 'background': 'transparent url(bookflip/black_gradient.png) top right repeat-y'}).appendTo($(orig));
}
}*/
$(div).append($(orig));
if(opts.allowPageClick){
$(orig).click(function() {
if(number_check(i)){
soundCheck();
nextPage();
} else {
prevPage();
}
});
}
});
$this.css('display', 'block');
if (opts.autoFlip == 'auto') {
doAutoFlip();
}
};
function doAutoFlip() {
if (rightStart < numPages) {
autoPage = setTimeout(nextPage, opts.autoFlipSpeed);
} else {
clearTimeout(autoPage);
}
};
function soundCheck() {
if ((opts.sound_manager) && (rightStart == 1)) {
if (opts.autoFlip == 'click') {
soundManager.play('bookAudio');
}
}
};
function number_check(value) {
// returns true if value is even, false if value is odd
return ( 1 - (value%2) );
};
function nextPage(){
var page = (opts.iframe.src) ? $this.find("#pageNum"+rightStart) : $("#pageNum"+rightStart);
var lpage = (opts.iframe.src) ? $this.find("#pageNum"+leftStart) : $("#pageNum"+leftStart);
$(page).css({'width': '0px', 'left': bookOpenW +'px', 'zIndex': 99});
$(page).animate({'left': 2+'px', 'width': pageW+'px'}, 'slow', function() {
$(lpage).css({'width': '0px'});
var z = $(this).css('zIndex');
$(this).css({'left': '0px', 'width': pageW+'px', 'zIndex': z-99});
$(lpage).css({'left': '', 'right': '0px'});
$(this).css({'left': '', 'right': '0px'});
leftStart=leftStart+2;
rightStart=rightStart+2;
if (opts.autoFlip != 'off') {
doAutoFlip();
}
});
};
function prevPage(){
leftStart=leftStart-2;
rightStart=rightStart-2;
var page = (opts.iframe.src) ? $this.find("#pageNum"+leftStart) : $("#pageNum"+leftStart);
var rpage = (opts.iframe.src) ? $this.find("#pageNum"+rightStart) : $("#pageNum"+rightStart);
var pFlipL = (opts.iframe.src) ? $this.find("#pageFlip"+leftStart) : $("#pageFlip"+leftStart);
var pFlipR = (opts.iframe.src) ? $this.find("#pageFlip"+rightStart) : $("#pageFlip"+rightStart);
$(page).css({'width': '0px', 'left': '0px'});
$(pFlipR).css({'left': '', 'right': '0px'});
$(page).animate({'left': pageW+'px', 'width': pageW+'px'}, 'slow', function() {
$(rpage).css({'width': '0px'});
$(pFlipR).css({'left': '0px'});
$(pFlipL).css({'left': '0px'});
});
};
};
$.bookFlip.defaults = {
allowPageClick: true,
autoFlip: 'off', //auto, click
autoFlipSpeed: 8000,
numPixels: 20, //number of pixels to move per frame, more is faster but less smooth
pSpeed: '20', //page speed, 20 is best for Opera browser. Less is faster
page_class: '',
sound_manager: '', // {swf_loc: 'soundmanager/soundmanager2.swf', audio_loc: '', debug: false}
iframe: '' //{src: 'test_bookflip3_iframe.html', book: 'myBook'}
};
})(jQuery); |
Partager