dolibarr  13.0.2
lib_foot.js.php
Go to the documentation of this file.
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 <https://www.gnu.org/licenses/>.
16  * or see https://www.gnu.org/
17  */
18 
24 if (!defined('NOREQUIRESOC')) define('NOREQUIRESOC', '1');
25 if (!defined('NOCSRFCHECK')) define('NOCSRFCHECK', 1);
26 if (!defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL', 1);
27 if (!defined('NOLOGIN')) define('NOLOGIN', 1);
28 if (!defined('NOREQUIREMENU')) define('NOREQUIREMENU', 1);
29 if (!defined('NOREQUIREHTML')) define('NOREQUIREHTML', 1);
30 if (!defined('NOREQUIREAJAX')) define('NOREQUIREAJAX', '1');
31 
32 session_cache_limiter('public');
33 
34 require_once '../../main.inc.php';
35 
36 // Define javascript type
37 top_httphead('text/javascript; charset=UTF-8');
38 // Important: Following code is to avoid page request by browser and PHP CPU at each Dolibarr page access.
39 if (empty($dolibarr_nocache)) header('Cache-Control: max-age=10800, public, must-revalidate');
40 else header('Cache-Control: no-cache');
41 
42 //var_dump($conf);
43 
44 
45 // Wrapper to show tooltips (html or onclick popup)
46 print "\n/* JS CODE TO ENABLE Tooltips on all object with class classfortooltip */\n";
47 print "jQuery(document).ready(function () {\n";
48 
49 if (empty($conf->dol_no_mouse_hover))
50 {
51  print 'jQuery(".classfortooltip").tooltip({
52  show: { collision: "flipfit", effect:\'toggle\', delay:50 },
53  hide: { delay: 250 },
54  tooltipClass: "mytooltip",
55  content: function () {
56  console.log("Return title for popup");
57  return $(this).prop(\'title\'); /* To force to get title as is */
58  }
59  });'."\n";
60 }
61 
62 print '
63 jQuery(".classfortooltiponclicktext").dialog(
64  { closeOnEscape: true, classes: { "ui-dialog": "highlight" },
65  maxHeight: window.innerHeight-60, width: '.($conf->browser->layout == 'phone' ? max($_SESSION['dol_screenwidth'] - 20, 320) : 700).',
66  modal: true,
67  autoOpen: false }).css("z-index: 5000");
68 jQuery(".classfortooltiponclick").click(function () {
69  console.log("We click on tooltip for element with dolid="+$(this).attr(\'dolid\'));
70  if ($(this).attr(\'dolid\'))
71  {
72  obj=$("#idfortooltiponclick_"+$(this).attr(\'dolid\')); /* obj is a div component */
73  obj.dialog("open");
74  return false;
75  }
76 });'."\n";
77 
78 print "});\n";
79 
80 
81 // Wrapper to manage dropdown
82 if (!defined('JS_JQUERY_DISABLE_DROPDOWN'))
83 {
84  print "\n/* JS CODE TO ENABLE dropdown (hamburger, linkto, ...) */\n";
85  print '
86  jQuery(document).ready(function () {
87  var lastopendropdown = null;
88 
89  // Click onto the link "link to" or "hamburger", toggle dropdown
90  $(".dropdown dt a").on(\'click\', function () {
91  console.log("toggle dropdown dt a");
92 
93  //$(this).parent().parent().find(\'dd ul\').slideToggle(\'fast\');
94  $(this).parent().parent().find(\'dd ul\').toggleClass("open");
95 
96  if ($(this).parent().parent().find(\'dd ul\').hasClass("open")) {
97  lastopendropdown = $(this).parent().parent().find(\'dd ul\');
98  //console.log(lastopendropdown);
99  } else {
100  // We closed the dropdown for hamburger selectfields
101  if ($("input:hidden[name=formfilteraction]").val() == "listafterchangingselectedfields") {
102  console.log("resubmit the form saved into lastopendropdown after clicking on hamburger");
103  //$(".dropdown dt a").parents(\'form:first\').submit();
104  //$(".dropdown dt a").closest("form").submit();
105  lastopendropdown.closest("form").submit();
106  }
107  }
108 
109  // Note: Did not find a way to get exact height (value is update at exit) so i calculate a generic from nb of lines
110  heigthofcontent = 21 * $(this).parent().parent().find(\'dd div ul li\').length;
111  if (heigthofcontent > 300) heigthofcontent = 300; // limited by max-height on css .dropdown dd ul
112  posbottom = $(this).parent().parent().find(\'dd\').offset().top + heigthofcontent + 8;
113  var scrollBottom = $(window).scrollTop() + $(window).height();
114  diffoutsidebottom = (posbottom - scrollBottom);
115  console.log("heigthofcontent="+heigthofcontent+", diffoutsidebottom (posbottom="+posbottom+" - scrollBottom="+scrollBottom+") = "+diffoutsidebottom);
116  if (diffoutsidebottom > 0)
117  {
118  pix = "-"+(diffoutsidebottom+8)+"px";
119  console.log("We reposition top by "+pix);
120  $(this).parent().parent().find(\'dd\').css("top", pix);
121  }
122  });
123 
124  // Click on a link into the popup "link to" or other dropdown that ask to close drop down on element click, so close dropdown
125  $(".dropdowncloseonclick").on(\'click\', function () {
126  console.log("Link has class dropdowncloseonclick, so we close/hide the popup ul");
127  //$(this).parent().parent().hide(); // $(this).parent().parent() is ul
128  $(this).parent().parent().removeClass("open"); // $(this).parent().parent() is ul
129  });
130 
131  // Click outside of any dropdown
132  $(document).bind(\'click\', function (e) {
133  var $clicked = $(e.target); // This is element we click on
134  if (!$clicked.parents().hasClass("dropdown")) {
135  //console.log("close dropdown dd ul - we click outside");
136  //$(".dropdown dd ul").hide();
137  $(".dropdown dd ul").removeClass("open");
138 
139  if ($("input:hidden[name=formfilteraction]").val() == "listafterchangingselectedfields") {
140  console.log("resubmit form saved into lastopendropdown after clicking outside of dropdown and having change selectlist from selectlist field of hamburger dropdown");
141  //$(".dropdown dt a").parents(\'form:first\').submit();
142  //$(".dropdown dt a").closest("form").submit();
143  lastopendropdown.closest("form").submit();
144  }
145  }
146  });
147  });
148  ';
149 }
150 
151 // Wrapper to manage document_preview
152 if ($conf->browser->layout != 'phone')
153 {
154  print "\n/* JS CODE TO ENABLE document_preview */\n"; // Function document_preview is into header
155  print '
156  jQuery(document).ready(function () {
157  jQuery(".documentpreview").click(function () {
158  console.log("We click on preview for element with href="+$(this).attr(\'href\')+" mime="+$(this).attr(\'mime\'));
159  document_preview($(this).attr(\'href\'), $(this).attr(\'mime\'), \''.dol_escape_js($langs->transnoentities("Preview")).'\');
160  return false;
161  });
162  });
163  ' . "\n";
164 }
165 
166 // Code to manage reposition
167 print "\n/* JS CODE TO ENABLE reposition management (does not work if a redirect is done after action of submission) */\n";
168 print '
169  jQuery(document).ready(function() {
170  /* If page_y set, we set scollbar with it */
171  page_y=getParameterByName(\'page_y\', 0); /* search in GET parameter */
172  if (page_y == 0) page_y = jQuery("#page_y").text(); /* search in POST parameter that is filed at bottom of page */
173  if (page_y > 0)
174  {
175  console.log("page_y found is "+page_y);
176  $(\'html, body\').scrollTop(page_y);
177  }
178 
179  /* Set handler to add page_y param on output (click on href links or submit button) */
180  jQuery(".reposition").click(function() {
181  var page_y = $(document).scrollTop();
182 
183  if (page_y > 0)
184  {
185  if (this.href)
186  {
187  var hrefarray = this.href.split("#", 2);
188  this.href=hrefarray[0]+\'&page_y=\'+page_y;
189  console.log("We click on tag with .reposition class. this.ref is now "+this.href);
190  }
191  else
192  {
193  console.log("We click on tag with .reposition class but element is not an <a> html tag, so we try to update input form field with name=page_y with value "+page_y);
194  jQuery("input[type=hidden][name=page_y]").val(page_y);
195  }
196  }
197  });
198  });'."\n";
if(!defined('NOREQUIREMENU')) if(!function_exists("llxHeader")) top_httphead($contenttype= 'text/html', $forcenocache=0)
Show HTTP header.
Definition: main.inc.php:1214
print
Draft customers invoices.
Definition: index.php:89
getParameterByName(name, valueifnotfound)