flowpaper_handlers.js 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. /**
  2. █▒▓▒░ The FlowPaper Project
  3. This file is part of FlowPaper.
  4. FlowPaper is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation, version 3 of the License.
  7. FlowPaper is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with FlowPaper. If not, see <http://www.gnu.org/licenses/>.
  13. For more information on FlowPaper please see the FlowPaper project
  14. home page: https://flowpaper.com
  15. */
  16. jQuery(function() {
  17. /**
  18. * Handles the event of external links getting clicked in the document.
  19. *
  20. * @example onExternalLinkClicked("http://www.google.com")
  21. *
  22. * @param String link
  23. */
  24. jQuery('#documentViewer').bind('onExternalLinkClicked',function(e,link){
  25. if(link.indexOf('mailto:')==0){
  26. window.parent.location.href = link;
  27. }else if(!FLOWPAPER.LinkTarget || (FLOWPAPER.LinkTarget && FLOWPAPER.LinkTarget == 'New window')){
  28. if (window.eb && window.eb.platform && window.eb.platform.touchonlydevice) {
  29. if (window != window.top) { // in a iframe
  30. window.parent.location.href = link;
  31. } else { // loaded as parent
  32. document.location.href = link;
  33. }
  34. } else {
  35. var newWindow = window.open(link, '_flowpaper_exturl_'+new Date().getTime());
  36. if (FLOWPAPER.blockedNewWindow(newWindow)) {
  37. document.location.href = link;
  38. }
  39. }
  40. }else if(FLOWPAPER.LinkTarget){
  41. if(FLOWPAPER.LinkTarget == 'Full window'){
  42. window.parent.location.href = link;
  43. }
  44. if(FLOWPAPER.LinkTarget == 'Same window'){
  45. window.location.href = link;
  46. }
  47. }
  48. // record the Google Analytics event
  49. TrackFlowPaperEvent(jQuery(this).data('TrackingNumber'),jQuery(this).data('TrackingDocument'),'External Link Clicked',link,null);
  50. });
  51. /**
  52. * Handles the event of videos being played in the document.
  53. *
  54. * @example onVideoStarted("http://youtube.com/abc")
  55. *
  56. * @param String video url
  57. */
  58. jQuery('#documentViewer').bind('onVideoStarted',function(e,videoProps){
  59. // record the Google Analytics event
  60. TrackFlowPaperEvent(jQuery(this).data('TrackingNumber'),jQuery(this).data('TrackingDocument'),'Video Started',videoProps.VideoUrl,videoProps.PageNumber);
  61. });
  62. /**
  63. * Handles the event of audios being played in the document.
  64. *
  65. * @example onAudioStarted("http://url/mp3")
  66. *
  67. * @param String audio url
  68. */
  69. jQuery('#documentViewer').bind('onAudioStarted',function(e,audioProps){
  70. // record the Google Analytics event
  71. TrackFlowPaperEvent(jQuery(this).data('TrackingNumber'),jQuery(this).data('TrackingDocument'),'Audio Started',audioProps.AudioUrl,audioProps.PageNumber);
  72. });
  73. /**
  74. * Handles the event of the original document being downloaded.
  75. *
  76. * @example onDownloadDocument("https://mydomain.com/abc.pdf")
  77. *
  78. * @param String pdf url
  79. */
  80. jQuery('#documentViewer').bind('onDownloadDocument',function(e,pdfUrl){
  81. // record the Google Analytics event
  82. TrackFlowPaperEvent(jQuery(this).data('TrackingNumber'),jQuery(this).data('TrackingDocument'),'Document Downloaded',pdfUrl,null);
  83. });
  84. /**
  85. * Recieves progress information about the document being loaded
  86. *
  87. * @example onProgress( 100,10000 );
  88. *
  89. * @param int loaded
  90. * @param int total
  91. */
  92. jQuery('#documentViewer').bind('onProgress',function(e,loadedBytes,totalBytes){
  93. });
  94. /**
  95. * Handles the event of a document is in progress of loading
  96. *
  97. */
  98. jQuery('#documentViewer').bind('onDocumentLoading',function(e){
  99. });
  100. /**
  101. * Handles the event of a document is in progress of loading
  102. *
  103. */
  104. jQuery('#documentViewer').bind('onPageLoading',function(e,pageNumber){
  105. });
  106. /**
  107. * Receives messages about the current page being changed
  108. *
  109. * @example onCurrentPageChanged( 10 );
  110. *
  111. * @param int pagenum
  112. */
  113. jQuery('#documentViewer').bind('onCurrentPageChanged',function(e,pagenum){
  114. // if GANumber is supplied then lets track this as a Google Analytics event.
  115. if(jQuery(this).data('TrackingNumber')){
  116. var trackingDoc = jQuery(this).data('TrackingDocument');
  117. var pagelocation = (document.location.pathname.indexOf('.html')>-1?document.location.pathname.substr(0,document.location.pathname.lastIndexOf('.html'))+'/':document.location.pathname)+'#page='+pagenum;
  118. if(jQuery(this).data('TrackingNumber').indexOf('G-')==0){
  119. (function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
  120. new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
  121. j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
  122. 'https://www.googletagmanager.com/gtag/js?id='+i+dl;f.parentNode.insertBefore(j,f);
  123. })(window,document,'script','dataLayer',jQuery(this).data('TrackingNumber'));
  124. window.dataLayer = window.dataLayer || [];
  125. function gtag(){dataLayer.push(arguments);}
  126. gtag('js', new Date());
  127. gtag('event', 'page_view', { 'send_to': jQuery(this).data('TrackingNumber') });
  128. }else{
  129. (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
  130. (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
  131. m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  132. })(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
  133. ga('create', jQuery(this).data('TrackingNumber'), 'auto', 'FlowPaperEventTracker');
  134. ga('FlowPaperEventTracker.set', 'page', pagelocation);
  135. ga('FlowPaperEventTracker.send', 'pageview');
  136. }
  137. }
  138. });
  139. /**
  140. * Receives messages about the document being loaded
  141. *
  142. * @example onDocumentLoaded( 20 );
  143. *
  144. * @param int totalPages
  145. */
  146. jQuery('#documentViewer').bind('onDocumentLoaded',function(e,totalPages){
  147. });
  148. /**
  149. * Receives messages about the page loaded
  150. *
  151. * @example onPageLoaded( 1 );
  152. *
  153. * @param int pageNumber
  154. */
  155. jQuery('#documentViewer').bind('onPageLoaded',function(e,pageNumber){
  156. });
  157. /**
  158. * Receives messages about the page loaded
  159. *
  160. * @example onErrorLoadingPage( 1 );
  161. *
  162. * @param int pageNumber
  163. */
  164. jQuery('#documentViewer').bind('onErrorLoadingPage',function(e,pageNumber){
  165. });
  166. /**
  167. * Receives error messages when a document is not loading properly
  168. *
  169. * @example onDocumentLoadedError( "Network error" );
  170. *
  171. * @param String errorMessage
  172. */
  173. jQuery('#documentViewer').bind('onDocumentLoadedError',function(e,errMessage){
  174. });
  175. /**
  176. * Receives error messages when a document has finished printed
  177. *
  178. * @example onDocumentPrinted();
  179. *
  180. */
  181. jQuery('#documentViewer').bind('onDocumentPrinted',function(e,numPages){
  182. });
  183. /**
  184. * Handles the event of a pdf requiring a password
  185. *
  186. * @example onPasswordNeeded(updatePassword,reason)
  187. *
  188. * @param updatePassword callback function for setting the password
  189. */
  190. jQuery('#documentViewer').bind('onPasswordNeeded',function(e,updatePassword){
  191. });
  192. });