dolibarr  7.0.0-beta
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('NOREQUIREUSER')) define('NOREQUIREUSER','1'); // Not disabled cause need to load personalized language
25 //if (! defined('NOREQUIREDB')) define('NOREQUIREDB','1');
26 if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC','1');
27 //if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN','1'); // Not disabled cause need to do translations
28 if (! defined('NOCSRFCHECK')) define('NOCSRFCHECK',1);
29 if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL',1);
30 if (! defined('NOLOGIN')) define('NOLOGIN',1);
31 if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU',1);
32 if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML',1);
33 if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX','1');
34 
35 session_cache_limiter(FALSE);
36 
37 require_once '../../main.inc.php';
38 
39 // Define javascript type
40 top_httphead('text/javascript; charset=UTF-8');
41 // Important: Following code is to avoid page request by browser and PHP CPU at each Dolibarr page access.
42 if (empty($dolibarr_nocache)) header('Cache-Control: max-age=3600, public, must-revalidate');
43 else header('Cache-Control: no-cache');
44 
45 //var_dump($conf);
46 
47 
48 // Wrapper to show tooltips (html or onclick popup)
49 if (empty($conf->dol_no_mouse_hover))
50 {
51  print "\n/* JS CODE TO ENABLE Tooltips on all object with class classfortooltip */\n";
52  print '
53  jQuery(document).ready(function () {
54  jQuery(".classfortooltip").tooltip({
55  show: { collision: "flipfit", effect:\'toggle\', delay:50 },
56  hide: { delay: 50 },
57  tooltipClass: "mytooltip",
58  content: function () {
59  return $(this).prop(\'title\'); /* To force to get title as is */
60  }
61  });
62  jQuery(".classfortooltiponclicktext").dialog(
63  { closeOnEscape: true, classes: { "ui-dialog": "highlight" },
64  maxHeight: window.innerHeight-60, width: '.($conf->browser->layout == 'phone' ? 400 : 700).',
65  modal: true,
66  autoOpen: false }).css("z-index: 5000");
67  jQuery(".classfortooltiponclick").click(function () {
68  console.log("We click on tooltip for element with dolid="+$(this).attr(\'dolid\'));
69  if ($(this).attr(\'dolid\'))
70  {
71  obj=$("#idfortooltiponclick_"+$(this).attr(\'dolid\')); /* obj is a div component */
72  obj.dialog("open");
73  return false;
74  }
75  });
76  });
77  ' . "\n";
78 }
79 
80 // Wrapper to manage dropdown
81 if (! defined('JS_JQUERY_DISABLE_DROPDOWN'))
82 {
83  print "\n/* JS CODE TO ENABLE dropdown */\n";
84  print '
85  jQuery(document).ready(function () {
86  $(".dropdown dt a").on(\'click\', function () {
87  console.log("We click on dropdown");
88  //console.log($(this).parent().parent().find(\'dd ul\'));
89  $(this).parent().parent().find(\'dd ul\').slideToggle(\'fast\');
90  // Note: Did not find a way to get exact height (value is update at exit) so i calculate a generic from nb of lines
91  heigthofcontent = 21 * $(this).parent().parent().find(\'dd div ul li\').length;
92  if (heigthofcontent > 300) heigthofcontent = 300; // limited by max-height on css .dropdown dd ul
93  posbottom = $(this).parent().parent().find(\'dd\').offset().top + heigthofcontent + 8;
94  var scrollBottom = $(window).scrollTop() + $(window).height();
95  diffoutsidebottom = (posbottom - scrollBottom);
96  console.log("heigthofcontent="+heigthofcontent+", diffoutsidebottom (posbottom="+posbottom+" - scrollBottom="+scrollBottom+") = "+diffoutsidebottom);
97  if (diffoutsidebottom > 0)
98  {
99  pix = "-"+(diffoutsidebottom+8)+"px";
100  console.log("We reposition top by "+pix);
101  $(this).parent().parent().find(\'dd\').css("top", pix);
102  }
103  // $(".dropdown dd ul").slideToggle(\'fast\');
104  });
105  $(".dropdowncloseonclick").on(\'click\', function () {
106  console.log("Link has class dropdowncloseonclick, so we close/hide the popup ul");
107  $(this).parent().parent().hide();
108  });
109 
110  $(document).bind(\'click\', function (e) {
111  //console.log("We click outside of dropdown, so we close it.");
112  var $clicked = $(e.target);
113  if (!$clicked.parents().hasClass("dropdown")) $(".dropdown dd ul").hide();
114  });
115  });
116  ';
117 }
118 
119 // Wrapper to manage document_preview
120 if ($conf->browser->layout != 'phone')
121 {
122  print "\n/* JS CODE TO ENABLE document_preview */\n"; // Function document_preview is into header
123  print '
124  jQuery(document).ready(function () {
125  jQuery(".documentpreview").click(function () {
126  console.log("We click on preview for element with href="+$(this).attr(\'href\')+" mime="+$(this).attr(\'mime\'));
127  document_preview($(this).attr(\'href\'), $(this).attr(\'mime\'), \''.dol_escape_js($langs->transnoentities("Preview")).'\');
128  return false;
129  });
130  });
131  ' . "\n";
132 }
133 
134 print "\n/* JS CODE TO ENABLE reposition management (does not work if a redirect is done after action of submission) */\n";
135 print '
136  jQuery(document).ready(function() {
137  /* If page_y set, we set scollbar with it */
138  page_y=getParameterByName(\'page_y\', 0); if (page_y > 0) $(\'html, body\').scrollTop(page_y);
139  /* Set handler to add page_y param on some a href links */
140  jQuery(".reposition").click(function() {
141  var page_y = $(document).scrollTop();
142  this.href=this.href+\'&page_y=\'+page_y;
143  console.log("We click on tag with .reposition class. this.ref is now "+this.href)
144  });
145  });'."\n";
146 
print
Draft customers invoices.
Definition: index.php:91
getParameterByName(name, valueifnotfound)
if(!defined('NOREQUIREMENU')) if(!function_exists("llxHeader")) top_httphead($contenttype='text/html')
Show HTTP header.
Definition: main.inc.php:1052