3dflipbook.min.js
1 year ago
default-book-view.js
2 years ago
html2canvas.min.js
2 years ago
pdf.min.js
2 years ago
pdf.worker.js
2 years ago
three.min.js
2 years ago
default-book-view.js
117 lines
| 1 | /* |
| 2 | This file is part of 3D Flip book. |
| 3 | |
| 4 | Copyright (c) 2024 3D Flip book. |
| 5 | |
| 6 | This program is free software: you can redistribute it and/or modify |
| 7 | it under the terms of the GNU General Public License as published by |
| 8 | the Free Software Foundation, either version 3 of the License, or |
| 9 | (at your option) any later version. |
| 10 | |
| 11 | This program is distributed in the hope that it will be useful, |
| 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | GNU General Public License for more details. |
| 15 | |
| 16 | You should have received a copy of the GNU General Public License |
| 17 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 18 | */ |
| 19 | |
| 20 | function init(container) { |
| 21 | var instance; |
| 22 | if(window.jQuery) { |
| 23 | var $ = window.jQuery; |
| 24 | instance = { |
| 25 | floatWnd: container.find('.float-wnd'), |
| 26 | binds: { |
| 27 | showDropMenu: function(e) { |
| 28 | e.preventDefault(); |
| 29 | var el = $(e.target); |
| 30 | while(!el.hasClass('toggle')) { |
| 31 | el = $(el[0].parentNode); |
| 32 | } |
| 33 | var menu = el.find('.menu'); |
| 34 | if(menu.hasClass('hidden')) { |
| 35 | container.find('.ctrl .fnavbar .menu').addClass('hidden'); |
| 36 | menu.removeClass('hidden'); |
| 37 | e.stopPropagation(); |
| 38 | } |
| 39 | }, |
| 40 | hideDropMenu: function() { |
| 41 | container.find('.ctrl .fnavbar .menu').addClass('hidden'); |
| 42 | }, |
| 43 | pickFloatWnd: function(e) { |
| 44 | if(instance.pos) { |
| 45 | instance.binds.dropFloatWnd(); |
| 46 | } |
| 47 | else { |
| 48 | instance.pos = { |
| 49 | x: e.pageX, |
| 50 | y: e.pageY |
| 51 | }; |
| 52 | } |
| 53 | }, |
| 54 | moveFloatWnd: function(e) { |
| 55 | if(instance.pos) { |
| 56 | var dv = { |
| 57 | x: e.pageX-instance.pos.x, |
| 58 | y: e.pageY-instance.pos.y |
| 59 | }, old = { |
| 60 | x: parseInt(instance.floatWnd.css('left')), |
| 61 | y: parseInt(instance.floatWnd.css('top')) |
| 62 | }; |
| 63 | instance.floatWnd.css('left', old.x+dv.x+'px').css('top', old.y+dv.y+'px'); |
| 64 | instance.pos = { |
| 65 | x: e.pageX, |
| 66 | y: e.pageY |
| 67 | }; |
| 68 | } |
| 69 | }, |
| 70 | dropFloatWnd: function() { |
| 71 | delete instance.pos; |
| 72 | }, |
| 73 | jsCenter: function() { |
| 74 | var ns = container.find('.js-center'); |
| 75 | for(var i=0; i<ns.length; ++i) { |
| 76 | var n = $(ns[i]), parentWidth = $(ns[i].parentNode).width(), width = n.width(); |
| 77 | n.css('left', 0.5*(parentWidth-width)+'px'); |
| 78 | } |
| 79 | } |
| 80 | }, |
| 81 | appLoaded: function() { |
| 82 | instance.binds.jsCenter(); |
| 83 | }, |
| 84 | linkLoaded: function(link) { |
| 85 | instance.binds.jsCenter(); |
| 86 | }, |
| 87 | dispose: function() { |
| 88 | container.find('.ctrl .fnavbar .fnav .toggle').off('click', instance.binds.showDropMenu); |
| 89 | $(container[0].ownerDocument).off('click', instance.binds.hideDropMenu); |
| 90 | |
| 91 | $(container[0].ownerDocument).off('mousemove', instance.binds.moveFloatWnd); |
| 92 | $(container[0].ownerDocument).off('mouseup', instance.binds.dropFloatWnd); |
| 93 | instance.floatWnd.find('.header').off('mousedown', instance.binds.pickFloatWnd); |
| 94 | |
| 95 | $(container[0].ownerDocument.defaultView).off('resize', instance.binds.jsCenter); |
| 96 | } |
| 97 | }; |
| 98 | container.find('.ctrl .fnavbar .fnav .toggle').on('click', instance.binds.showDropMenu); |
| 99 | $(container[0].ownerDocument).on('click', instance.binds.hideDropMenu); |
| 100 | |
| 101 | $(container[0].ownerDocument).on('mousemove', instance.binds.moveFloatWnd); |
| 102 | $(container[0].ownerDocument).on('mouseup', instance.binds.dropFloatWnd); |
| 103 | instance.floatWnd.find('.header').on('mousedown', instance.binds.pickFloatWnd); |
| 104 | |
| 105 | $(container[0].ownerDocument.defaultView).on('resize', instance.binds.jsCenter); |
| 106 | instance.binds.jsCenter(); |
| 107 | } |
| 108 | else { |
| 109 | instance = { |
| 110 | dispose: function() { |
| 111 | } |
| 112 | }; |
| 113 | console.error('jQuery is not found'); |
| 114 | } |
| 115 | return instance; |
| 116 | } init |
| 117 |