2017-11-09 01:00:43 +01:00
< ? php
/* Copyright ( C ) 2017 Laurent Destailleur < eldy @ users . sourceforge . net >
*
* This program is free software ; you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation ; either version 3 of the License , or
* ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
2019-09-23 21:55:30 +02:00
* along with this program . If not , see < https :// www . gnu . org / licenses />.
* or see https :// www . gnu . org /
2017-11-09 01:00:43 +01:00
*/
/**
* \file htdocs / core / js / lib_foot . js . php
* \brief File that include javascript functions ( included if option use_javascript activated )
*/
2019-03-02 10:16:13 +01:00
if ( ! defined ( 'NOREQUIRESOC' )) define ( 'NOREQUIRESOC' , '1' );
if ( ! defined ( 'NOCSRFCHECK' )) define ( 'NOCSRFCHECK' , 1 );
if ( ! defined ( 'NOTOKENRENEWAL' )) define ( 'NOTOKENRENEWAL' , 1 );
if ( ! defined ( 'NOLOGIN' )) define ( 'NOLOGIN' , 1 );
if ( ! defined ( 'NOREQUIREMENU' )) define ( 'NOREQUIREMENU' , 1 );
if ( ! defined ( 'NOREQUIREHTML' )) define ( 'NOREQUIREHTML' , 1 );
if ( ! defined ( 'NOREQUIREAJAX' )) define ( 'NOREQUIREAJAX' , '1' );
2017-11-09 01:00:43 +01:00
2018-12-18 15:06:00 +01:00
session_cache_limiter ( 'public' );
2017-11-09 01:00:43 +01:00
require_once '../../main.inc.php' ;
// Define javascript type
top_httphead ( 'text/javascript; charset=UTF-8' );
// Important: Following code is to avoid page request by browser and PHP CPU at each Dolibarr page access.
2018-12-18 15:06:00 +01:00
if ( empty ( $dolibarr_nocache )) header ( 'Cache-Control: max-age=10800, public, must-revalidate' );
2017-11-09 01:00:43 +01:00
else header ( 'Cache-Control: no-cache' );
//var_dump($conf);
2017-11-19 12:22:01 +01:00
2017-11-09 01:00:43 +01:00
// Wrapper to show tooltips (html or onclick popup)
2019-03-09 18:37:07 +01:00
print " \n /* JS CODE TO ENABLE Tooltips on all object with class classfortooltip */ \n " ;
print " jQuery(document).ready(function () { \n " ;
2017-11-09 01:00:43 +01:00
if ( empty ( $conf -> dol_no_mouse_hover ))
{
2019-03-09 18:37:07 +01:00
print ' jQuery ( " .classfortooltip " ) . tooltip ({
show : { collision : " flipfit " , effect : \ ' toggle\ ' , delay : 50 },
2019-10-04 16:53:58 +02:00
hide : { delay : 250 },
2019-03-09 18:37:07 +01:00
tooltipClass : " mytooltip " ,
content : function () {
2019-03-27 17:50:23 +01:00
console . log ( " Return title for popup " );
2019-03-09 18:37:07 +01:00
return $ ( this ) . prop ( \ ' title\ ' ); /* To force to get title as is */
}
}); ' . " \n " ;
2017-11-09 01:00:43 +01:00
}
2019-03-09 18:37:07 +01:00
print '
jQuery ( " .classfortooltiponclicktext " ) . dialog (
{ closeOnEscape : true , classes : { " ui-dialog " : " highlight " },
maxHeight : window . innerHeight - 60 , width : '.($conf->browser->layout == ' phone ' ? max($_SESSION[' dol_screenwidth ']-20, 320) : 700).' ,
modal : true ,
autoOpen : false }) . css ( " z-index: 5000 " );
jQuery ( " .classfortooltiponclick " ) . click ( function () {
console . log ( " We click on tooltip for element with dolid= " + $ ( this ) . attr ( \ ' dolid\ ' ));
if ( $ ( this ) . attr ( \ ' dolid\ ' ))
{
obj = $ ( " #idfortooltiponclick_ " + $ ( this ) . attr ( \ ' dolid\ ' )); /* obj is a div component */
obj . dialog ( " open " );
return false ;
}
}); ' . " \n " ;
print " }); \n " ;
2017-11-09 01:00:43 +01:00
// Wrapper to manage dropdown
if ( ! defined ( 'JS_JQUERY_DISABLE_DROPDOWN' ))
{
print " \n /* JS CODE TO ENABLE dropdown */ \n " ;
print '
jQuery ( document ) . ready ( function () {
$ ( " .dropdown dt a " ) . on ( \ ' click\ ' , function () {
2017-11-09 18:50:15 +01:00
console . log ( " We click on dropdown " );
2017-11-09 01:00:43 +01:00
//console.log($(this).parent().parent().find(\'dd ul\'));
$ ( this ) . parent () . parent () . find ( \ ' dd ul\ ' ) . slideToggle ( \ ' fast\ ' );
// Note: Did not find a way to get exact height (value is update at exit) so i calculate a generic from nb of lines
heigthofcontent = 21 * $ ( this ) . parent () . parent () . find ( \ ' dd div ul li\ ' ) . length ;
if ( heigthofcontent > 300 ) heigthofcontent = 300 ; // limited by max-height on css .dropdown dd ul
posbottom = $ ( this ) . parent () . parent () . find ( \ ' dd\ ' ) . offset () . top + heigthofcontent + 8 ;
var scrollBottom = $ ( window ) . scrollTop () + $ ( window ) . height ();
diffoutsidebottom = ( posbottom - scrollBottom );
console . log ( " heigthofcontent= " + heigthofcontent + " , diffoutsidebottom (posbottom= " + posbottom + " - scrollBottom= " + scrollBottom + " ) = " + diffoutsidebottom );
if ( diffoutsidebottom > 0 )
{
pix = " - " + ( diffoutsidebottom + 8 ) + " px " ;
console . log ( " We reposition top by " + pix );
$ ( this ) . parent () . parent () . find ( \ ' dd\ ' ) . css ( " top " , pix );
}
// $(".dropdown dd ul").slideToggle(\'fast\');
});
$ ( " .dropdowncloseonclick " ) . on ( \ ' click\ ' , function () {
console . log ( " Link has class dropdowncloseonclick, so we close/hide the popup ul " );
$ ( this ) . parent () . parent () . hide ();
});
$ ( document ) . bind ( \ ' click\ ' , function ( e ) {
2017-11-18 12:35:25 +01:00
//console.log("We click outside of dropdown, so we close it.");
2017-11-09 01:00:43 +01:00
var $clicked = $ ( e . target );
if ( ! $clicked . parents () . hasClass ( " dropdown " )) $ ( " .dropdown dd ul " ) . hide ();
});
});
' ;
}
// Wrapper to manage document_preview
if ( $conf -> browser -> layout != 'phone' )
{
2018-01-08 00:05:26 +01:00
print " \n /* JS CODE TO ENABLE document_preview */ \n " ; // Function document_preview is into header
2017-11-09 01:00:43 +01:00
print '
jQuery ( document ) . ready ( function () {
jQuery ( " .documentpreview " ) . click ( function () {
console . log ( " We click on preview for element with href= " + $ ( this ) . attr ( \ ' href\ ' ) + " mime= " + $ ( this ) . attr ( \ ' mime\ ' ));
document_preview ( $ ( this ) . attr ( \ 'href\'), $(this).attr(\'mime\'), \'' . dol_escape_js ( $langs -> transnoentities ( " Preview " )) . ' \ ' );
return false ;
});
});
' . " \n " ;
}
2018-04-19 13:59:20 +02:00
// Code to manage reposition
2017-11-09 09:50:55 +01:00
print " \n /* JS CODE TO ENABLE reposition management (does not work if a redirect is done after action of submission) */ \n " ;
print '
jQuery ( document ) . ready ( function () {
/* If page_y set, we set scollbar with it */
2018-04-19 13:59:20 +02:00
page_y = getParameterByName ( \ ' page_y\ ' , 0 ); /* search in GET parameter */
if ( page_y == 0 ) page_y = jQuery ( " #page_y " ) . text (); /* search in POST parameter that is filed at bottom of page */
2018-04-30 10:33:36 +02:00
if ( page_y > 0 )
{
console . log ( " page_y found is " + page_y );
$ ( \ ' html , body\ ' ) . scrollTop ( page_y );
}
2018-04-19 13:59:20 +02:00
/* Set handler to add page_y param on output (click on href links or submit button) */
2017-11-09 09:50:55 +01:00
jQuery ( " .reposition " ) . click ( function () {
2018-04-19 21:33:26 +02:00
var page_y = $ ( document ) . scrollTop ();
2019-08-01 15:42:44 +02:00
2018-04-28 19:54:41 +02:00
if ( page_y > 0 )
2018-04-19 13:59:20 +02:00
{
2018-04-28 19:54:41 +02:00
if ( this . href )
{
this . href = this . href + \ ' & page_y = \ ' + page_y ;
console . log ( " We click on tag with .reposition class. this.ref is now " + this . href );
}
else
{
2020-01-17 11:34:31 +01:00
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 );
2018-04-28 19:54:41 +02:00
jQuery ( " input[type=hidden][name=page_y] " ) . val ( page_y );
}
2018-04-19 13:59:20 +02:00
}
2018-04-19 21:33:26 +02:00
});
2017-11-09 09:50:55 +01:00
}); ' . " \n " ;