├── Resources ├── img │ ├── img_0001_pageinfo.txt │ ├── img_0002_pageinfo.txt │ ├── img_0001_links.txt │ ├── img_0001.jpg │ ├── img_0002.jpg │ ├── img_0002_links.txt │ ├── img_0003.jpg │ ├── img_0004.jpg │ └── img_0005.jpg ├── flipbook │ ├── pgn.png │ ├── bright.png │ ├── shadow.png │ ├── btn_first.png │ ├── btn_last.png │ ├── btn_next.png │ ├── btn_prev.png │ └── flipbook.js ├── iphone │ ├── Default.png │ └── appicon.png └── app.js ├── README.md ├── scripts └── prepare_catalogue.sh └── LICENSE /Resources/img/img_0001_pageinfo.txt: -------------------------------------------------------------------------------- 1 | /MediaBox [0 0 595.273 841.887] 2 | -------------------------------------------------------------------------------- /Resources/img/img_0002_pageinfo.txt: -------------------------------------------------------------------------------- 1 | /MediaBox [0 0 595.273 841.887] 2 | -------------------------------------------------------------------------------- /Resources/img/img_0001_links.txt: -------------------------------------------------------------------------------- 1 | /URI (mailto:lee@quru.com) 2 | /Rect [380.454 427.199 470.998 487.199] 3 | -------------------------------------------------------------------------------- /Resources/flipbook/pgn.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leebourne/FlipBook-Titanium/HEAD/Resources/flipbook/pgn.png -------------------------------------------------------------------------------- /Resources/img/img_0001.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leebourne/FlipBook-Titanium/HEAD/Resources/img/img_0001.jpg -------------------------------------------------------------------------------- /Resources/img/img_0002.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leebourne/FlipBook-Titanium/HEAD/Resources/img/img_0002.jpg -------------------------------------------------------------------------------- /Resources/img/img_0002_links.txt: -------------------------------------------------------------------------------- 1 | /URI (http://www.quru.com/appcelerator) 2 | /Rect [90 403.614 273.27 413.614] 3 | -------------------------------------------------------------------------------- /Resources/img/img_0003.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leebourne/FlipBook-Titanium/HEAD/Resources/img/img_0003.jpg -------------------------------------------------------------------------------- /Resources/img/img_0004.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leebourne/FlipBook-Titanium/HEAD/Resources/img/img_0004.jpg -------------------------------------------------------------------------------- /Resources/img/img_0005.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leebourne/FlipBook-Titanium/HEAD/Resources/img/img_0005.jpg -------------------------------------------------------------------------------- /Resources/flipbook/bright.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leebourne/FlipBook-Titanium/HEAD/Resources/flipbook/bright.png -------------------------------------------------------------------------------- /Resources/flipbook/shadow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leebourne/FlipBook-Titanium/HEAD/Resources/flipbook/shadow.png -------------------------------------------------------------------------------- /Resources/iphone/Default.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leebourne/FlipBook-Titanium/HEAD/Resources/iphone/Default.png -------------------------------------------------------------------------------- /Resources/iphone/appicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leebourne/FlipBook-Titanium/HEAD/Resources/iphone/appicon.png -------------------------------------------------------------------------------- /Resources/flipbook/btn_first.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leebourne/FlipBook-Titanium/HEAD/Resources/flipbook/btn_first.png -------------------------------------------------------------------------------- /Resources/flipbook/btn_last.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leebourne/FlipBook-Titanium/HEAD/Resources/flipbook/btn_last.png -------------------------------------------------------------------------------- /Resources/flipbook/btn_next.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leebourne/FlipBook-Titanium/HEAD/Resources/flipbook/btn_next.png -------------------------------------------------------------------------------- /Resources/flipbook/btn_prev.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leebourne/FlipBook-Titanium/HEAD/Resources/flipbook/btn_prev.png -------------------------------------------------------------------------------- /Resources/app.js: -------------------------------------------------------------------------------- 1 | // Sample app to use the flipbook component 2 | // - modify pdfName and numPages accordingly 3 | // - name images with suffixes _0001.jpg, _0002.jpg ... _000n.jpg 4 | // 5 | // Released under a Creative Commons License: 6 | // visit http://www.quru.com/appcelerator 7 | 8 | // Your Window 9 | var win = Ti.UI.createWindow({ 10 | backgroundColor:'#666666' 11 | }); 12 | win.open(); 13 | 14 | 15 | // Add Flipbook Library 16 | Ti.include('flipbook/flipbook.js'); 17 | 18 | function pad(number, length) { 19 | 20 | var str = '' + number; 21 | while (str.length < length) { 22 | str = '0' + str; 23 | } 24 | 25 | return str; 26 | } 27 | 28 | var pageArray = []; 29 | var numPages = 5; 30 | var pdfName = "img"; // Your pdf name (without the .jpg extension) 31 | var imgType = "jpg"; 32 | for (curPage = 1; curPage <= numPages; curPage++) 33 | { 34 | pageArray.push(pdfName + "/" + pdfName + "_" + pad(curPage, 4) + "." + imgType); 35 | } 36 | 37 | // Create Flipbook Object 38 | flipbook.create({ 39 | pages:pageArray, 40 | top:0, 41 | left:0, 42 | right:0, 43 | bottom:0, 44 | pagesDir:Ti.Filesystem.resourcesDirectory, 45 | //showButtons:false, 46 | //showPagination:false, 47 | attachTo:win // ATTENTION, USE this to add object to you window instead of 'win.add(blabla);' 48 | }); 49 | 50 | flipbook.showPagination(false); 51 | flipbook.showButtons(true); 52 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # FlipBook-Titanium 2 | FlipBook for Titanium 3 | 4 | This is a component to create a Flipbook to iPad. 5 | This initial release uses images for pages. 6 | 7 | 8 | ## Add this to you project 9 | 10 | Copy the 'flipbook' folder inside your 'Resource' project folder. 11 | 12 | ## Basic Usage 13 | 14 | To add on a window: 15 | 16 | ``` 17 | // Add Flipbook Library 18 | Ti.include('flipbook/flipbook.js'); 19 | 20 | 21 | // Create Flipbook Object 22 | flipbook.create({ 23 | pages:['img/1.jpg','img/2.jpg','img/3.jpg','img/4.jpg','img/5.jpg'], // Add your Image Pages 24 | top:0, 25 | left:0, 26 | width:768, 27 | height:1004, 28 | pagesDir:Ti.Filesystem.resourcesDirectory, 29 | attachTo:win // ATTENTION, USE this to add object to you window instead of 'win.add(blabla);' 30 | }); 31 | ``` 32 | 33 | 34 | That's pretty much it! Any edits/improvements are appreciated. 35 | 36 | ## Starting with a PDF 37 | * Install PDFTK from 38 | * Install ImageMagick from 39 | * Take a PDF and run the scripts prepare_catalogue.sh in the scripts directory against it. 40 | * e.g. ``` scripts/prepare_catalogue.sh .pdf Resources/``` 41 | * Hyperlinks must be annotated correctly in the PDF, see . 42 | * If you need to you can experiment with the image quality settings in the script. Be careful about changing the size though as the iPad is pretty slow at resizing images on the fly. 43 | * Modify Resources/app.js and complete the values for variables 'pdfName' and 'numPages' 44 | -------------------------------------------------------------------------------- /scripts/prepare_catalogue.sh: -------------------------------------------------------------------------------- 1 | # Script to extract the page info and links from a PDF (or multiple PDFs) 2 | # 3 | # Released under a Creative Commons License: 4 | # visit http://www.quru.com/appcelerator 5 | # 6 | # Syntax: 7 | # ./prepare_catalogue.sh [target_dir] 8 | # 9 | # Requirements: 10 | # PDFTK is installed (http://www.pdflabs.com/tools/pdftk-the-pdf-toolkit/) 11 | # ImageMagick is installed (http://www.imagemagick.org/) 12 | 13 | # Globals used by ImageMagick's convert utility 14 | QUALITY=90 15 | DENSITY=132x132 16 | SIZE=768x1024 # iPad size 17 | IMG_TYPE=jpg 18 | 19 | # Either suppress logging with /dev/null or specify a log file 20 | LOGFILE=/dev/null 21 | 22 | if [ -z "$1" ] 23 | then 24 | echo You must supply a pdf filename 25 | exit 1 26 | fi 27 | 28 | if [ -z "$2" ] 29 | then 30 | TARGET_DIR="." 31 | else 32 | TARGET_DIR=$2 33 | mkdir -p $TARGET_DIR 34 | fi 35 | 36 | # Split the multi-page pdf into single pages 37 | short=${1%\.*} 38 | printf "Extracting pages from %s \r" $1 39 | pdftk "$1" burst output "$short"_%04d.pdf 40 | rm doc_data.txt 41 | echo pdftk "$1" burst output "$short"_%04d.pdf 42 | 43 | # Work on each of the separate pdf pages 44 | for pdf in "$short"_*.pdf 45 | do 46 | printf "Processing %s \r" $pdf 47 | stripped=${pdf%\.*} 48 | stripped=${stripped##*/} 49 | 50 | # Convert the pdf to a jpeg 51 | convert -resize $SIZE -quality $QUALITY -density $DENSITY "$pdf" "$TARGET_DIR/$stripped.$IMG_TYPE" >> $LOGFILE 2>&1 52 | 53 | # Extract the links (http and mailto) 54 | dest="$TARGET_DIR/$stripped"_links.txt 55 | egrep -a -A 5 "^/URI" $pdf | egrep "^/URI|^/Rect" > $dest 56 | if [ -s $dest ] 57 | then 58 | # Extract the page size information 59 | egrep -a -B 5 -A 5 "^/Type /Page" "$pdf" | egrep "^/MediaBox|ArtBox|^/UserUnit" > "$TARGET_DIR/$stripped"_pageinfo.txt 60 | else 61 | # If the PDF doesn't have any links we don't need the info 62 | rm $dest 63 | fi 64 | 65 | # Clean up the pdfs that we don't need 66 | # rm $pdf 67 | done 68 | echo "Done " 69 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /Resources/flipbook/flipbook.js: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////// 2 | // 3 | // 23/12/2010 - FlipBook 0.7 By Adriano 4 | // 21/01/2011 - Extended by Lee Khan-Bourne (Quru) 5 | // Extended to cater for hyperlinks 6 | // Added first and last page buttons 7 | // Disabled pagination 8 | // Added option of pagesDir to allow pages to be 9 | // moved to the data dir in the future 10 | // 11 | // Released under a Creative Commons License: 12 | // visit http://www.quru.com/appcelerator 13 | // 14 | ///////////////////////////////////////////////////////////////////////////// 15 | 16 | 17 | // TODO: 18 | // 19 | // -Animation to direct 'GotoPage' 20 | // -Landscape Mode with 2 pages 21 | // -Transform to a 3D flip 22 | // 23 | 24 | // Maybe TODO: 25 | // 26 | // -Convert this to a Titanium module (Objective-C) 27 | // 28 | 29 | 30 | // Variables 31 | var flipbook_actualPage; 32 | var flipbook_pages=[]; 33 | var flipbook_fingers; 34 | var flipbook_pgRear; 35 | var flipbook_pgBright; 36 | var flipbook_pgShadow; 37 | var flipbook_pgShadow2; 38 | var flipbook_imgBottom; 39 | var flipbook_pgBottom; 40 | var flipbook_imgRear; 41 | var flipbook_pgTop; 42 | var flipbook_btn_first; 43 | var flipbook_btn_prev; 44 | var flipbook_btn_next; 45 | var flipbook_btn_last; 46 | var flipbook_pgn; 47 | var flipbook_dots=[]; 48 | var flipbook_options=[]; 49 | var flipbook_container; 50 | var flipbook_containerProxy; 51 | var flipbook_overlay; 52 | var flipbook_startDrag; 53 | var flipbook_hotspots=[]; // Quru 54 | 55 | 56 | // Main Class 57 | var flipbook = { 58 | showPagination: function(b){ 59 | flipbook_pgn.visible=b; 60 | }, 61 | showButtons: function(b){ 62 | flipbook_btn_first.visible=b; // Quru 63 | flipbook_btn_prev.visible=b; 64 | flipbook_btn_next.visible=b; 65 | flipbook_btn_last.visible=b; // Quru 66 | }, 67 | setPagination: function(pg){ 68 | flipbook.showHotspots(pg); // Quru 69 | /* 70 | // Set current page in Dots 71 | for(var i=0;i 0 && flipbook_options.pagesDir[flipbook_options.pagesDir.length - 1] != Titanium.Filesystem.separator) { 126 | flipbook_options.pagesDir += Titanium.Filesystem.separator; 127 | } 128 | // Load Pages 129 | for(i=0;i1){ 338 | flipbook_overlay.image = flipbook_pages[flipbook_actualPage-1]; 339 | flipbook_overlay.visible = true; 340 | 341 | flipbook.move(0); 342 | 343 | 344 | flipbook_imgBottom.image=flipbook_pages[flipbook_actualPage-1]; 345 | flipbook_imgRear.image=flipbook_pages[flipbook_actualPage-2]; 346 | flipbook_pgTop.image=flipbook_pages[flipbook_actualPage-2]; 347 | 348 | flipbook_overlay.visible = false; 349 | 350 | flipbook.animate(e.x,200); 351 | flipbook_startDrag=1; 352 | } 353 | }else{ 354 | 355 | if(flipbook_actualPage0){ 376 | flipbook.move(e.x); 377 | } 378 | }); 379 | flipbook_fingers.addEventListener('touchend', function(e) { 380 | if(flipbook_startDrag>0){ 381 | if(e.x<(flipbook_container.width/2)){ 382 | flipbook.animate(0); 383 | if(flipbook_startDrag==2){ 384 | flipbook_actualPage++; 385 | } 386 | }else{ 387 | flipbook.animate(flipbook_container.width); 388 | if(flipbook_startDrag==1){ 389 | flipbook_actualPage--; 390 | } 391 | } 392 | flipbook.setPagination(flipbook_actualPage); 393 | flipbook_startDrag=0; 394 | } 395 | }); 396 | 397 | 398 | 399 | 400 | 401 | // Create Pagination 402 | flipbook.createPagination(flipbook_pages.length); 403 | 404 | 405 | // Goto Page 1 without animation 406 | flipbook.gotoPage(1,0); 407 | 408 | 409 | // Get Button's Click 410 | flipbook_btn_first.addEventListener('click', function(e) { // Quru 411 | // Check if isn't the first page 412 | if(flipbook_actualPage>1){ 413 | // goto first page 414 | flipbook.gotoPage(1,0); 415 | } 416 | }); 417 | flipbook_btn_prev.addEventListener('click', function(e) { 418 | // Check if isn't the first page 419 | if(flipbook_actualPage>1){ 420 | // goto previous page 421 | flipbook.gotoPage('prev',800); 422 | } 423 | }); 424 | flipbook_btn_next.addEventListener('click', function(e) { 425 | // Check if isn't the last page 426 | if(flipbook_actualPage1){op=1;} 490 | flipbook_pgShadow.opacity=op; 491 | flipbook_pgBright.opacity=op; 492 | 493 | 494 | op2 = x/(flipbook_container.width/8); 495 | if(op2>1){op2=1;} 496 | if(op2<0){op2=0;} 497 | flipbook_pgShadow2.opacity=op2; 498 | 499 | 500 | xo = parseInt(x,10); 501 | flipbook_imgBottom.left=-xo; 502 | flipbook_pgBottom.left=xo; 503 | 504 | }, 505 | animate: function(x,v){ 506 | if(v==null){v=300;} 507 | flipbook_pgRear.animate({left:(x*2)-flipbook_container.width,duration:v}); 508 | flipbook_pgShadow.animate({left:((x*2)-flipbook_container.width)-90,duration:v}); 509 | flipbook_pgBright.animate({left:x-100,duration:v}); 510 | 511 | op = -(x-flipbook_container.width)/(flipbook_container.width/8); 512 | if(op>1){op=1;} 513 | flipbook_pgShadow.animate({opacity:op,duration:v}); 514 | flipbook_pgBright.animate({opacity:op,duration:v}); 515 | 516 | 517 | op2 = x/(flipbook_container.width/8); 518 | if(op2>1){op2=1;} 519 | if(op2<0){op2=0;} 520 | flipbook_pgShadow2.animate({opacity:op2,duration:v}); 521 | 522 | 523 | xo = parseInt(x,10); 524 | flipbook_imgBottom.animate({left:-xo,duration:v}); 525 | flipbook_pgBottom.animate({left:xo,duration:v}); 526 | 527 | }, // Quru 528 | createHotspot: function (pageSize, link, hotspot){ 529 | flipbook_overlay.width = 'auto'; // This allows the real image size to be discovered 530 | flipbook_overlay.height = 'auto'; // Unfortunately it slows the whole thing down 531 | 532 | var ratioImage = flipbook_overlay.size.height / flipbook_overlay.size.width; 533 | var ratioContainer = flipbook_containerProxy.size.height / flipbook_containerProxy.size.width; 534 | var imageWidth = flipbook_containerProxy.width; 535 | var imageHeight = flipbook_containerProxy.height; 536 | var offsetX = 0; 537 | var offsetY = 0; 538 | 539 | // If the image aspect ratio doesn't match the screen aspect ratio 540 | // work out if there is any offset to add to the hotspot position 541 | if (ratioImage > ratioContainer) { 542 | imageWidth = imageWidth / (ratioImage / ratioContainer); 543 | offsetX = (flipbook_containerProxy.size.width - imageWidth) / 2; 544 | } 545 | else { 546 | imageHeight = imageHeight / (ratioContainer / ratioImage); 547 | offsetY = (flipbook_containerProxy.size.height - imageHeight) / 2; 548 | } 549 | 550 | flipbook_overlay.width = flipbook_container.width; // Put the width/height back otherwise when you flip pages 551 | flipbook_overlay.height = flipbook_container.height; // the image visibly resizes as it turns 552 | 553 | var ratioX = imageWidth / pageSize[2]; 554 | var ratioY = imageHeight / pageSize[3]; 555 | 556 | flipbook_hotspots.push(Ti.UI.createImageView({ 557 | borderWidth:1, 558 | borderColor:'#f00', 559 | height:Math.round((hotspot[3] - hotspot[1]) * ratioY), 560 | width:Math.round((hotspot[2] - hotspot[0]) * ratioX), 561 | bottom:Math.round(hotspot[1] * ratioY), 562 | left:Math.round(hotspot[0] * ratioX) + offsetX, 563 | zIndex:7, 564 | visible:true 565 | })); 566 | flipbook_containerProxy.add(flipbook_hotspots[flipbook_hotspots.length - 1]); 567 | flipbook_hotspots[flipbook_hotspots.length - 1].addEventListener('click', (function(link) { 568 | return function (e) { 569 | if (link.substr(0, 7) == "mailto:") { 570 | var emailDialog = Titanium.UI.createEmailDialog(); 571 | // emailDialog.subject = "Contact From App"; 572 | emailDialog.toRecipients = [link.substr(7)]; 573 | // emailDialog.messageBody = 'Please enter a message'; 574 | 575 | emailDialog.open(); 576 | } 577 | else { 578 | // Goto the url using a browser 579 | Ti.Platform.openURL(link); 580 | } 581 | }; 582 | })(link)); 583 | }, 584 | showHotspots: function(pg){ 585 | Ti.API.debug("showHotspots for page " + pg); 586 | // Remove the current hotspots 587 | while (flipbook_hotspots.length > 0) { 588 | flipbook_containerProxy.remove(flipbook_hotspots[flipbook_hotspots.length - 1]); 589 | flipbook_hotspots.pop(); 590 | } 591 | 592 | // Are there any hotspots for this page? 593 | Ti.API.debug(flipbook_options.pagesDir); 594 | Ti.API.debug(flipbook_pages[pg - 1]); 595 | 596 | var filePrefix = flipbook_pages[pg - 1].substr(flipbook_options.pagesDir.length, flipbook_pages[pg - 1].lastIndexOf(".") - flipbook_options.pagesDir.length); 597 | var hotspots = Ti.Filesystem.getFile(flipbook_options.pagesDir, filePrefix + "_links.txt"); 598 | var pageinfo = Ti.Filesystem.getFile(flipbook_options.pagesDir, filePrefix + "_pageinfo.txt"); 599 | if (!hotspots.exists() || !pageinfo.exists()) { 600 | return; 601 | } 602 | 603 | // Get the page size 604 | var linesBlob = pageinfo.read().text; 605 | if (linesBlob.length < 1) { 606 | return; 607 | } 608 | 609 | var linesArray = linesBlob.split("\n"); 610 | var pageSize; 611 | for (i=0; i