1/* Flipbook Plugin for jQuery 2 * Author : Jon Raasch 3 * Website : http://jonraasch.com/blog/jquery-flipbook-movies 4 * Contact : [email protected] 5 * Version : 0.1 6 * 7 * Copyright (c)2008 Jon Raasch. All rights reserved. 8 * Released under FreeBSD License, see readme.txt 9 * Do not remove the above copyright notice or text 10 * 11 * 12 * Usage : 13 * 14 * Place this HTML anywhere on your page: 15 16 <div id="flipbook"> 17 Loading ...<br /> 18 <a href="http://jonraasch.com/blog/jquery-flipbook-movies"> 19 jQuery Flipbook</a> 20 </div> 21 22 * 23 * Then include this bit of Javascript to pull images from the directory 24 * "images/": 25 26 <script type="text/javascript"> 27 $(function() { 28 Flipbook.init( 'images/' ); 29 }); 30 </script> 31 32 * 33 */ 34 35 36var Flipbook = { 37 obj : {}, 38 frameRate : 2, 39 fadeSpeed : 0, 40 ajaxPhp : 'flipbook.php', 41 frames : $('<div></div>'), 42 imageCount : 0, 43 loadedImages : 0, 44 isBuilt : 0, 45 loadingAjax : 0, 46 47 init : function( source ) { 48 Flipbook.obj.wrapper = $('#flipbook, #flipbook2'); 49 50 if ( typeof( source ) == 'undefined' ) Flipbook.startFlipping(); 51 else { 52 Flipbook.processSource( source ); 53 54 Flipbook.isBuilt = 1; 55 56 // if the images loaded faster than we were able to set the isBuilt variable, we make sure to start the flipbook here...just a failsafe 57 if ( Flipbook.imageCount == Flipbook.loadedImages && !Flipbook.loadingAjax ) Flipbook.startFlipping(); 58 } 59 }, 60 61 processSource : function( source ) { 62 if ( typeof( source ) == 'string' ) source = [ source ]; 63 for ( var i = 0; i < source.length; i++ ) { 64 if ( !Flipbook.isImage( source[i] ) ) Flipbook.addDirectory( source[i] ); 65 } 66 }, 67 68 isImage : function( source ) { 69 var theExt = source.substr( source.length - 4 ); 70 if ( theExt == '.jpg' || theExt == '.png' || theExt == '.gif' || theExt == '.bmp' ) { 71 Flipbook.imageCount++; 72 73 // append an image with this source, adding to the loaded images variable once the image is loaded in the browser 74 75 var img = new Image(); 76 $img = $(img); 77 if ( Flipbook.imageCount == 1 ) $img.addClass('active bananas'); 78 79 $img.load( function() { 80 Flipbook.loadedImages++; 81 82 // if all images are processed and imageCount == loadedImages and not currently loading any AJAX, start Flipping 83 if ( Flipbook.isBuilt && Flipbook.imageCount == Flipbook.loadedImages && !Flipbook.loadingAjax) Flipbook.startFlipping(); 84 85 }) . attr('src', source ) . appendTo( Flipbook.frames ); 86 87 88 89 return 1; 90 } 91 else return 0; 92 }, 93 94 addDirectory : function( dir ) { 95 Flipbook.loadingAjax++; 96 $.ajax({ 97 type : 'POST', 98 url : Flipbook.ajaxPhp, 99 data : 'dir=' + dir, 100 cache : false, 101 success : function(html) { 102 if ( html ) { 103 Flipbook.loadingAjax--; 104 105 if ( html != 'empty.dir' ) { 106 var newSource = html.split(','); 107 Flipbook.processSource( newSource ); 108 } 109 } 110 } 111 }); 112 }, 113 114 startFlipping : function() { 115 // if the flipbook built dynamically, set the flipbook html here, otherwise leave what was on page 116 var framesHTML = Flipbook.frames.html(); 117 if ( framesHTML.length ) Flipbook.obj.wrapper.html( framesHTML ); 118 119 Flipbook.obj.theFirst = $(':first', Flipbook.obj.wrapper); 120 121 $active = $('.active', Flipbook.obj.wrapper); 122 if ( !$active.length ) $active = $(':last', Flipbook.obj.wrapper); 123 124 Flipbook.obj.active = $active; 125 126 Flipbook.play = setInterval( "Flipbook.slideSwitch()", Math.floor( 1000 / Flipbook.frameRate ) ); 127 }, 128 129 slideSwitch : function() { 130 var $active = Flipbook.obj.active; 131 132 var $next = $active.next().length ? $active.next() 133 : Flipbook.obj.theFirst; 134 135 if ( Flipbook.fadeSpeed ) { 136 $active.addClass('last-active'); 137 138 $next.css({opacity: 0.0}) 139 .addClass('active') 140 .animate({opacity: 1.0}, Flipbook.fadeSpeed, function() { 141 $active.removeClass('active last-active'); 142 }); 143 } 144 else { 145 $next.addClass('active'); 146 $active.removeClass('active'); 147 } 148 149 Flipbook.obj.active = $next; 150 } 151 152}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.