dolibarr  9.0.0
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 <http://www.gnu.org/licenses/>.
16  * or see http://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 if (empty($conf->dol_no_mouse_hover))
47 {
48  print "\n/* JS CODE TO ENABLE Tooltips on all object with class classfortooltip */\n";
49  print '
50  jQuery(document).ready(function () {
51  jQuery(".classfortooltip").tooltip({
52  show: { collision: "flipfit", effect:\'toggle\', delay:50 },
53  hide: { delay: 50 },
54  tooltipClass: "mytooltip",
55  content: function () {
56  return $(this).prop(\'title\'); /* To force to get title as is */
57  }
58  });
59  jQuery(".classfortooltiponclicktext").dialog(
60  { closeOnEscape: true, classes: { "ui-dialog": "highlight" },
61  maxHeight: window.innerHeight-60, width: '.($conf->browser->layout == 'phone' ? 400 : 700).',
62  modal: true,
63  autoOpen: false }).css("z-index: 5000");
64  jQuery(".classfortooltiponclick").click(function () {
65  console.log("We click on tooltip for element with dolid="+$(this).attr(\'dolid\'));
66  if ($(this).attr(\'dolid\'))
67  {
68  obj=$("#idfortooltiponclick_"+$(this).attr(\'dolid\')); /* obj is a div component */
69  obj.dialog("open");
70  return false;
71  }
72  });
73  });
74  ' . "\n";
75 }
76 
77 // Wrapper to manage dropdown
78 if (! defined('JS_JQUERY_DISABLE_DROPDOWN'))
79 {
80  print "\n/* JS CODE TO ENABLE dropdown */\n";
81  print '
82  jQuery(document).ready(function () {
83  $(".dropdown dt a").on(\'click\', function () {
84  console.log("We click on dropdown");
85  //console.log($(this).parent().parent().find(\'dd ul\'));
86  $(this).parent().parent().find(\'dd ul\').slideToggle(\'fast\');
87  // Note: Did not find a way to get exact height (value is update at exit) so i calculate a generic from nb of lines
88  heigthofcontent = 21 * $(this).parent().parent().find(\'dd div ul li\').length;
89  if (heigthofcontent > 300) heigthofcontent = 300; // limited by max-height on css .dropdown dd ul
90  posbottom = $(this).parent().parent().find(\'dd\').offset().top + heigthofcontent + 8;
91  var scrollBottom = $(window).scrollTop() + $(window).height();
92  diffoutsidebottom = (posbottom - scrollBottom);
93  console.log("heigthofcontent="+heigthofcontent+", diffoutsidebottom (posbottom="+posbottom+" - scrollBottom="+scrollBottom+") = "+diffoutsidebottom);
94  if (diffoutsidebottom > 0)
95  {
96  pix = "-"+(diffoutsidebottom+8)+"px";
97  console.log("We reposition top by "+pix);
98  $(this).parent().parent().find(\'dd\').css("top", pix);
99  }
100  // $(".dropdown dd ul").slideToggle(\'fast\');
101  });
102  $(".dropdowncloseonclick").on(\'click\', function () {
103  console.log("Link has class dropdowncloseonclick, so we close/hide the popup ul");
104  $(this).parent().parent().hide();
105  });
106 
107  $(document).bind(\'click\', function (e) {
108  //console.log("We click outside of dropdown, so we close it.");
109  var $clicked = $(e.target);
110  if (!$clicked.parents().hasClass("dropdown")) $(".dropdown dd ul").hide();
111  });
112  });
113  ';
114 }
115 
116 // Wrapper to manage document_preview
117 if ($conf->browser->layout != 'phone')
118 {
119  print "\n/* JS CODE TO ENABLE document_preview */\n"; // Function document_preview is into header
120  print '
121  jQuery(document).ready(function () {
122  jQuery(".documentpreview").click(function () {
123  console.log("We click on preview for element with href="+$(this).attr(\'href\')+" mime="+$(this).attr(\'mime\'));
124  document_preview($(this).attr(\'href\'), $(this).attr(\'mime\'), \''.dol_escape_js($langs->transnoentities("Preview")).'\');
125  return false;
126  });
127  });
128  ' . "\n";
129 }
130 
131 // Code to manage reposition
132 print "\n/* JS CODE TO ENABLE reposition management (does not work if a redirect is done after action of submission) */\n";
133 print '
134  jQuery(document).ready(function() {
135  /* If page_y set, we set scollbar with it */
136  page_y=getParameterByName(\'page_y\', 0); /* search in GET parameter */
137  if (page_y == 0) page_y = jQuery("#page_y").text(); /* search in POST parameter that is filed at bottom of page */
138  if (page_y > 0)
139  {
140  console.log("page_y found is "+page_y);
141  $(\'html, body\').scrollTop(page_y);
142  }
143 
144  /* Set handler to add page_y param on output (click on href links or submit button) */
145  jQuery(".reposition").click(function() {
146  var page_y = $(document).scrollTop();
147  if (page_y > 0)
148  {
149  if (this.href)
150  {
151  this.href=this.href+\'&page_y=\'+page_y;
152  console.log("We click on tag with .reposition class. this.ref is now "+this.href);
153  }
154  else
155  {
156  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);
157  jQuery("input[type=hidden][name=page_y]").val(page_y);
158  }
159  }
160  });
161  });'."\n";
162 
print
Draft customers invoices.
Definition: index.php:91
if(! defined('NOREQUIREMENU')) if(! function_exists("llxHeader")) top_httphead($contenttype='text/html', $forcenocache=0)
Show HTTP header.
Definition: main.inc.php:1107
getParameterByName(name, valueifnotfound)