lib_foot.js.php 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. <?php
  2. /* Copyright (C) 2017 Laurent Destailleur <eldy@users.sourceforge.net>
  3. *
  4. * This program 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; either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. * or see http://www.gnu.org/
  17. */
  18. /**
  19. * \file htdocs/core/js/lib_foot.js.php
  20. * \brief File that include javascript functions (included if option use_javascript activated)
  21. */
  22. if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC','1');
  23. if (! defined('NOCSRFCHECK')) define('NOCSRFCHECK',1);
  24. if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL',1);
  25. if (! defined('NOLOGIN')) define('NOLOGIN',1);
  26. if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU',1);
  27. if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML',1);
  28. if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX','1');
  29. session_cache_limiter('public');
  30. require_once '../../main.inc.php';
  31. // Define javascript type
  32. top_httphead('text/javascript; charset=UTF-8');
  33. // Important: Following code is to avoid page request by browser and PHP CPU at each Dolibarr page access.
  34. if (empty($dolibarr_nocache)) header('Cache-Control: max-age=10800, public, must-revalidate');
  35. else header('Cache-Control: no-cache');
  36. //var_dump($conf);
  37. // Wrapper to show tooltips (html or onclick popup)
  38. if (empty($conf->dol_no_mouse_hover))
  39. {
  40. print "\n/* JS CODE TO ENABLE Tooltips on all object with class classfortooltip */\n";
  41. print '
  42. jQuery(document).ready(function () {
  43. jQuery(".classfortooltip").tooltip({
  44. show: { collision: "flipfit", effect:\'toggle\', delay:50 },
  45. hide: { delay: 50 },
  46. tooltipClass: "mytooltip",
  47. content: function () {
  48. return $(this).prop(\'title\'); /* To force to get title as is */
  49. }
  50. });
  51. jQuery(".classfortooltiponclicktext").dialog(
  52. { closeOnEscape: true, classes: { "ui-dialog": "highlight" },
  53. maxHeight: window.innerHeight-60, width: '.($conf->browser->layout == 'phone' ? 400 : 700).',
  54. modal: true,
  55. autoOpen: false }).css("z-index: 5000");
  56. jQuery(".classfortooltiponclick").click(function () {
  57. console.log("We click on tooltip for element with dolid="+$(this).attr(\'dolid\'));
  58. if ($(this).attr(\'dolid\'))
  59. {
  60. obj=$("#idfortooltiponclick_"+$(this).attr(\'dolid\')); /* obj is a div component */
  61. obj.dialog("open");
  62. return false;
  63. }
  64. });
  65. });
  66. ' . "\n";
  67. }
  68. // Wrapper to manage dropdown
  69. if (! defined('JS_JQUERY_DISABLE_DROPDOWN'))
  70. {
  71. print "\n/* JS CODE TO ENABLE dropdown */\n";
  72. print '
  73. jQuery(document).ready(function () {
  74. $(".dropdown dt a").on(\'click\', function () {
  75. console.log("We click on dropdown");
  76. //console.log($(this).parent().parent().find(\'dd ul\'));
  77. $(this).parent().parent().find(\'dd ul\').slideToggle(\'fast\');
  78. // Note: Did not find a way to get exact height (value is update at exit) so i calculate a generic from nb of lines
  79. heigthofcontent = 21 * $(this).parent().parent().find(\'dd div ul li\').length;
  80. if (heigthofcontent > 300) heigthofcontent = 300; // limited by max-height on css .dropdown dd ul
  81. posbottom = $(this).parent().parent().find(\'dd\').offset().top + heigthofcontent + 8;
  82. var scrollBottom = $(window).scrollTop() + $(window).height();
  83. diffoutsidebottom = (posbottom - scrollBottom);
  84. console.log("heigthofcontent="+heigthofcontent+", diffoutsidebottom (posbottom="+posbottom+" - scrollBottom="+scrollBottom+") = "+diffoutsidebottom);
  85. if (diffoutsidebottom > 0)
  86. {
  87. pix = "-"+(diffoutsidebottom+8)+"px";
  88. console.log("We reposition top by "+pix);
  89. $(this).parent().parent().find(\'dd\').css("top", pix);
  90. }
  91. // $(".dropdown dd ul").slideToggle(\'fast\');
  92. });
  93. $(".dropdowncloseonclick").on(\'click\', function () {
  94. console.log("Link has class dropdowncloseonclick, so we close/hide the popup ul");
  95. $(this).parent().parent().hide();
  96. });
  97. $(document).bind(\'click\', function (e) {
  98. //console.log("We click outside of dropdown, so we close it.");
  99. var $clicked = $(e.target);
  100. if (!$clicked.parents().hasClass("dropdown")) $(".dropdown dd ul").hide();
  101. });
  102. });
  103. ';
  104. }
  105. // Wrapper to manage document_preview
  106. if ($conf->browser->layout != 'phone')
  107. {
  108. print "\n/* JS CODE TO ENABLE document_preview */\n"; // Function document_preview is into header
  109. print '
  110. jQuery(document).ready(function () {
  111. jQuery(".documentpreview").click(function () {
  112. console.log("We click on preview for element with href="+$(this).attr(\'href\')+" mime="+$(this).attr(\'mime\'));
  113. document_preview($(this).attr(\'href\'), $(this).attr(\'mime\'), \''.dol_escape_js($langs->transnoentities("Preview")).'\');
  114. return false;
  115. });
  116. });
  117. ' . "\n";
  118. }
  119. // Code to manage reposition
  120. print "\n/* JS CODE TO ENABLE reposition management (does not work if a redirect is done after action of submission) */\n";
  121. print '
  122. jQuery(document).ready(function() {
  123. /* If page_y set, we set scollbar with it */
  124. page_y=getParameterByName(\'page_y\', 0); /* search in GET parameter */
  125. if (page_y == 0) page_y = jQuery("#page_y").text(); /* search in POST parameter that is filed at bottom of page */
  126. if (page_y > 0)
  127. {
  128. console.log("page_y found is "+page_y);
  129. $(\'html, body\').scrollTop(page_y);
  130. }
  131. /* Set handler to add page_y param on output (click on href links or submit button) */
  132. jQuery(".reposition").click(function() {
  133. var page_y = $(document).scrollTop();
  134. if (page_y > 0)
  135. {
  136. if (this.href)
  137. {
  138. this.href=this.href+\'&page_y=\'+page_y;
  139. console.log("We click on tag with .reposition class. this.ref is now "+this.href);
  140. }
  141. else
  142. {
  143. console.log("We click on tag with .reposition class but element is not an <a> html tag, so we try to update form field page_y with value "+page_y);
  144. jQuery("input[type=hidden][name=page_y]").val(page_y);
  145. }
  146. }
  147. });
  148. });'."\n";