Replace javascript by jQuery

This commit is contained in:
Laurent Destailleur
2010-08-29 17:52:06 +00:00
parent 4547233095
commit c326e2697a

View File

@@ -29,32 +29,34 @@ function autofilltownfromzip_PopupPostalCode(url_root, postalcode,objecttown,obj
} }
/*================================================================= /*
Purpose: Pour la saisie des dates par calendrier * =================================================================
Input: base "/theme/eldy" * Purpose:
dateFieldID "dateo" Nom du champ * Pour la saisie des dates par calendrier Input: base "/theme/eldy" dateFieldID
format "dd/MM/yyyy" Format issu de Dolibarr de SimpleDateFormat a utiliser pour retour * "dateo" Nom du champ format "dd/MM/yyyy" Format issu de Dolibarr de
==================================================================*/ * SimpleDateFormat a utiliser pour retour
* ==================================================================
*/
function showDP(base,dateFieldID,format,codelang) function showDP(base,dateFieldID,format,codelang)
{ {
//check to see if another box is already showing // check to see if another box is already showing
var alreadybox=getObjectFromID("DPCancel"); var alreadybox=getObjectFromID("DPCancel");
if (alreadybox) closeDPBox(); // This erase value of showDP.datefieldID if (alreadybox) closeDPBox(); // This erase value of showDP.datefieldID
//alert("showDP "+codelang); // alert("showDP "+codelang);
showDP.datefieldID=dateFieldID; // Must be after the close showDP.datefieldID=dateFieldID; // Must be after the close
var dateField=getObjectFromID(dateFieldID); var dateField=getObjectFromID(dateFieldID);
//get positioning // get positioning
var thetop=getTop(dateField)+dateField.offsetHeight; var thetop=getTop(dateField)+dateField.offsetHeight;
// var xxx=getObjectFromID('bottompage'); // var xxx=getObjectFromID('bottompage');
//alert(xxx.style.pixelTop); // alert(xxx.style.pixelTop);
//alert(document.body.clientHeight); // alert(document.body.clientHeight);
//alert(document.body.style.offsetTop); // alert(document.body.style.offsetTop);
//alert(thetop); // alert(thetop);
//alert(window.innerHeight); // alert(window.innerHeight);
if (thetop+160 > window.innerHeight) if (thetop+160 > window.innerHeight)
thetop=thetop-160-20; thetop=thetop-160-20;
var theleft=getLeft(dateField); var theleft=getLeft(dateField);
@@ -117,8 +119,8 @@ function resetDP(base,dateFieldID,format,codelang)
function loadMonth(base,month,year,ymd,codelang) function loadMonth(base,month,year,ymd,codelang)
{ {
/*showDP.box.innerHTML="Loading...";*/ /* showDP.box.innerHTML="Loading..."; */
//alert(codelang); // alert(codelang);
var theURL=base+"datepicker.php?cm=shw&lang="+codelang; var theURL=base+"datepicker.php?cm=shw&lang="+codelang;
theURL+="&m="+encodeURIComponent(month); theURL+="&m="+encodeURIComponent(month);
theURL+="&y="+encodeURIComponent(year); theURL+="&y="+encodeURIComponent(year);
@@ -131,7 +133,8 @@ function loadMonth(base,month,year,ymd,codelang)
req=loadXMLDoc(theURL,null,false); req=loadXMLDoc(theURL,null,false);
if (req.responseText == '') alert('Failed to get URL '.theURL); if (req.responseText == '') alert('Failed to get URL '.theURL);
//alert(theURL+' - '+req.responseText); // L'url doit avoir la meme racine que la pages et elements sinon pb de securite. // alert(theURL+' - '+req.responseText); // L'url doit avoir la meme racine
// que la pages et elements sinon pb de securite.
showDP.box.innerHTML=req.responseText; showDP.box.innerHTML=req.responseText;
} }
@@ -201,7 +204,7 @@ function dpHighlightDay(year,month,day,tradMonths){
displayinfo.innerHTML=months[month-1]+" "+day+", "+year; displayinfo.innerHTML=months[month-1]+" "+day+", "+year;
} }
//Returns an object given an id // Returns an object given an id
function getObjectFromID(id){ function getObjectFromID(id){
var theObject; var theObject;
if(document.getElementById) if(document.getElementById)
@@ -296,7 +299,8 @@ function loadXMLDoc(url,readyStateFunction,async)
return req; return req;
} }
// To hide/show select Boxes with IE6 (and only IE6 because IE6 has a bug and not put popup completely on the front) // To hide/show select Boxes with IE6 (and only IE6 because IE6 has a bug and
// not put popup completely on the front)
function hideSelectBoxes() { function hideSelectBoxes() {
var brsVersion = parseInt(window.navigator.appVersion.charAt(0), 10); var brsVersion = parseInt(window.navigator.appVersion.charAt(0), 10);
if (brsVersion <= 6 && window.navigator.userAgent.indexOf("MSIE 6") > -1) if (brsVersion <= 6 && window.navigator.userAgent.indexOf("MSIE 6") > -1)
@@ -324,26 +328,22 @@ function displaySelectBoxes() {
/*================================================================= /*
Function: formatDate (javascript object Date(), format) * =================================================================
Purpose: Returns a date in the output format specified. * Function:
The format string can use the following tags: * formatDate (javascript object Date(), format) Purpose: Returns a date in the
Field | Tags * output format specified. The format string can use the following tags: Field |
-------------+------------------------------- * Tags -------------+------------------------------- Year | yyyy (4 digits), yy
Year | yyyy (4 digits), yy (2 digits) * (2 digits) Month | MM (2 digits) Day of Month | dd (2 digits) Hour (1-12) |
Month | MM (2 digits) * hh (2 digits) Hour (0-23) | HH (2 digits) Minute | mm (2 digits) Second | ss
Day of Month | dd (2 digits) * (2 digits) Author: Laurent Destailleur Author: Matelli (see
Hour (1-12) | hh (2 digits) * http://matelli.fr/showcases/patchs-dolibarr/update-date-input-in-action-form.html)
Hour (0-23) | HH (2 digits) * Licence: GPL
Minute | mm (2 digits) * ==================================================================
Second | ss (2 digits) */
Author: Laurent Destailleur
Author: Matelli (see http://matelli.fr/showcases/patchs-dolibarr/update-date-input-in-action-form.html)
Licence: GPL
==================================================================*/
function formatDate(date,format) function formatDate(date,format)
{ {
//alert('formatDate date='+date+' format='+format); // alert('formatDate date='+date+' format='+format);
// Force parametres en chaine // Force parametres en chaine
format=format+""; format=format+"";
@@ -363,12 +363,14 @@ function formatDate(date,format)
c=format.charAt(i); // Recupere char du format c=format.charAt(i); // Recupere char du format
substr=""; substr="";
j=i; j=i;
while ((format.charAt(j)==c) && (j < format.length)) // Recupere char successif identiques while ((format.charAt(j)==c) && (j < format.length)) // Recupere char
// successif
// identiques
{ {
substr += format.charAt(j++); substr += format.charAt(j++);
} }
//alert('substr='+substr); // alert('substr='+substr);
if (substr == 'yyyy') { result=result+year; } if (substr == 'yyyy') { result=result+year; }
else if (substr == 'yy') { result=result+year.substring(2,4); } else if (substr == 'yy') { result=result+year.substring(2,4); }
else if (substr == 'M') { result=result+month; } else if (substr == 'M') { result=result+month; }
@@ -384,33 +386,27 @@ function formatDate(date,format)
i+=substr.length; i+=substr.length;
} }
//alert(result); // alert(result);
return result; return result;
} }
/*================================================================= /*
Function: getDateFromFormat(date_string, format_string) * =================================================================
Purpose: This function takes a date string and a format string. * Function:
It parses the date string with format and it returns * getDateFromFormat(date_string, format_string) Purpose: This function takes a
the date as a javascript Date() object. * date string and a format string. It parses the date string with format and it
If date does not match format, it returns 0. * returns the date as a javascript Date() object. If date does not match
The format string can use the following tags: * format, it returns 0. The format string can use the following tags: Field |
Field | Tags * Tags -------------+------------------------------- Year | yyyy (4 digits), yy
-------------+------------------------------- * (2 digits) Month | MM (2 digits) Day of Month | dd (2 digits) Hour (1-12) |
Year | yyyy (4 digits), yy (2 digits) * hh (2 digits) Hour (0-23) | HH (2 digits) Minute | mm (2 digits) Second | ss
Month | MM (2 digits) * (2 digits) Author: Laurent Destailleur Licence: GPL
Day of Month | dd (2 digits) * ==================================================================
Hour (1-12) | hh (2 digits) */
Hour (0-23) | HH (2 digits)
Minute | mm (2 digits)
Second | ss (2 digits)
Author: Laurent Destailleur
Licence: GPL
==================================================================*/
function getDateFromFormat(val,format) function getDateFromFormat(val,format)
{ {
//alert('getDateFromFormat val='+val+' format='+format); // alert('getDateFromFormat val='+val+' format='+format);
// Force parametres en chaine // Force parametres en chaine
val=val+""; val=val+"";
@@ -425,19 +421,22 @@ function getDateFromFormat(val,format)
var seconde=now.getSeconds(); var seconde=now.getSeconds();
var i=0; var i=0;
var d=0; // -d- follows the date string while -i- follows the format string var d=0; // -d- follows the date string while -i- follows the format
// string
while (i < format.length) while (i < format.length)
{ {
c=format.charAt(i); // Recupere char du format c=format.charAt(i); // Recupere char du format
substr=""; substr="";
j=i; j=i;
while ((format.charAt(j)==c) && (j < format.length)) // Recupere char successif identiques while ((format.charAt(j)==c) && (j < format.length)) // Recupere char
// successif
// identiques
{ {
substr += format.charAt(j++); substr += format.charAt(j++);
} }
//alert('substr='+substr); // alert('substr='+substr);
if (substr == "yyyy") year=getIntegerInString(val,d,4,4); if (substr == "yyyy") year=getIntegerInString(val,d,4,4);
if (substr == "yy") year=""+(getIntegerInString(val,d,2,2)-0+1900); if (substr == "yy") year=""+(getIntegerInString(val,d,2,2)-0+1900);
if (substr == "MM" ||substr == "M") if (substr == "MM" ||substr == "M")
@@ -477,16 +476,18 @@ function getDateFromFormat(val,format)
if (minute==null||(minute<0)||(minute>60)) { return 0; } if (minute==null||(minute<0)||(minute>60)) { return 0; }
if (seconde==null||(seconde<0)||(seconde>60)) { return 0; } if (seconde==null||(seconde<0)||(seconde>60)) { return 0; }
//alert(year+' '+month+' '+day+' '+hour+' '+minute+' '+seconde); // alert(year+' '+month+' '+day+' '+hour+' '+minute+' '+seconde);
var newdate=new Date(year,month-1,day,hour,minute,seconde); var newdate=new Date(year,month-1,day,hour,minute,seconde);
return newdate; return newdate;
} }
/*================================================================= /*
Function: stringIsInteger(string) * =================================================================
Purpose: Return true if string is an integer * Function:
==================================================================*/ * stringIsInteger(string) Purpose: Return true if string is an integer
* ==================================================================
*/
function stringIsInteger(str) function stringIsInteger(str)
{ {
var digits="1234567890"; var digits="1234567890";
@@ -500,10 +501,13 @@ function stringIsInteger(str)
return true; return true;
} }
/*================================================================= /*
Function: getIntegerInString(string,pos,minlength,maxlength) * =================================================================
Purpose: Return part of string from position i that is integer * Function:
==================================================================*/ * getIntegerInString(string,pos,minlength,maxlength) Purpose: Return part of
* string from position i that is integer
* ==================================================================
*/
function getIntegerInString(str,i,minlength,maxlength) function getIntegerInString(str,i,minlength,maxlength)
{ {
for (var x=maxlength; x>=minlength; x--) for (var x=maxlength; x>=minlength; x--)
@@ -516,50 +520,54 @@ function getIntegerInString(str,i,minlength,maxlength)
} }
/*================================================================= /*
Purpose: Clean string to have it url encoded * =================================================================
Input: s * Purpose:
Author: Laurent Destailleur * Clean string to have it url encoded Input: s Author: Laurent Destailleur
Licence: GPL * Licence: GPL
==================================================================*/ * ==================================================================
*/
function urlencode(s) { function urlencode(s) {
return s.replace(/\+/gi,'%2B'); return s.replace(/\+/gi,'%2B');
} }
/*================================================================= /*
Purpose: Show a popup HTML page. * =================================================================
Input: url,title * Purpose:
Author: Laurent Destailleur * Show a popup HTML page. Input: url,title Author: Laurent Destailleur Licence:
Licence: GPL * GPL ==================================================================
==================================================================*/ */
function newpopup(url,title) { function newpopup(url,title) {
var argv = newpopup.arguments; var argv = newpopup.arguments;
var argc = newpopup.arguments.length; var argc = newpopup.arguments.length;
tmp=url; tmp=url;
var l = (argc > 2) ? argv[2] : 600; var l = (argc > 2) ? argv[2] : 600;
var h = (argc > 3) ? argv[3] : 400; var h = (argc > 3) ? argv[3] : 400;
var wfeatures="directories=0,menubar=0,status=0,resizable=0,scrollbars=1,toolbar=0,width="+l+",height="+h+",left=" + eval("(screen.width - l)/2") + ",top=" + eval("(screen.height - h)/2"); var wfeatures="directories=0,menubar=0,status=0,resizable=0,scrollbars=1,toolbar=0,width="+l+",height="+h+",left=" + eval("(screen.width - l)/2") + ",top=" + eval("(screen.height - h)/2");
fen=window.open(tmp,title,wfeatures); fen=window.open(tmp,title,wfeatures);
return false; return false;
} }
/*================================================================= /*
Purpose: Fonction pour champ saisie en mode ajax. Used for autocompletion of products. * =================================================================
Author: Laurent Destailleur * Purpose:
Licence: GPL * Fonction pour champ saisie en mode ajax. Used for autocompletion of products.
==================================================================*/ * Author: Laurent Destailleur Licence: GPL
* ==================================================================
*/
function publish_selvalue(obj) { $(obj.name).value = obj.options[obj.selectedIndex].value; } function publish_selvalue(obj) { $(obj.name).value = obj.options[obj.selectedIndex].value; }
/*================================================================= /*
Purpose: Set value of a field after return of Ajax call. Used for autocompletion. * =================================================================
Input: HTML field name, val * Purpose:
Author: Regis Houssin * Set value of a field after return of Ajax call. Used for autocompletion.
Licence: GPL * Input: HTML field name, val Author: Regis Houssin Licence: GPL
==================================================================*/ * ==================================================================
*/
function ac_return(field, val){ function ac_return(field, val){
/* alert('field.name='+field.name+'-'+val.innerHTML); */ /* alert('field.name='+field.name+'-'+val.innerHTML); */
/* on met en place l'expression reguliere */ /* on met en place l'expression reguliere */
@@ -574,25 +582,26 @@ function ac_return(field, val){
$(field.name+'_id').value = id; $(field.name+'_id').value = id;
} }
/*================================================================= /*
Purpose: Applique un delai avant execution. Used for autocompletion of companies. * =================================================================
Input: funct, delay * Purpose:
Author: Regis Houssin * Applique un delai avant execution. Used for autocompletion of companies.
Licence: GPL * Input: funct, delay Author: Regis Houssin Licence: GPL
==================================================================*/ * ==================================================================
*/
function ac_delay(funct,delay) { function ac_delay(funct,delay) {
// delay before start of action // delay before start of action
setTimeout(funct,delay); setTimeout(funct,delay);
} }
/*================================================================= /*
Purpose: Clean values of a "Sortable.serialize". * =================================================================
Used by drag and drop. Works for Scriptaculous and jQuery. * Purpose:
Input: expr * Clean values of a "Sortable.serialize". Used by drag and drop. Works for
Author: Regis Houssin * Scriptaculous and jQuery. Input: expr Author: Regis Houssin Licence: GPL
Licence: GPL * ==================================================================
==================================================================*/ */
function cleanSerialize(expr) { function cleanSerialize(expr) {
var reg = new RegExp("(&)", "g"); var reg = new RegExp("(&)", "g");
var reg2 = new RegExp("[^A-Z0-9,]", "g"); var reg2 = new RegExp("[^A-Z0-9,]", "g");
@@ -602,13 +611,13 @@ function cleanSerialize(expr) {
} }
/*================================================================= /*
Purpose: Display a temporary message in input text fields (For showing help message on input field). * =================================================================
Input: fieldId * Purpose:
Input: message * Display a temporary message in input text fields (For showing help message on
Author: Regis Houssin * input field). Input: fieldId Input: message Author: Regis Houssin Licence:
Licence: GPL * GPL ==================================================================
==================================================================*/ */
function displayMessage(fieldId,message) { function displayMessage(fieldId,message) {
var textbox = document.getElementById(fieldId); var textbox = document.getElementById(fieldId);
if (textbox.value == '') { if (textbox.value == '') {
@@ -617,25 +626,27 @@ function displayMessage(fieldId,message) {
} }
} }
/*================================================================= /*
Purpose: Hide a temporary message in input text fields (For showing help message on input field). * =================================================================
Input: fiedId * Purpose:
Input: message * Hide a temporary message in input text fields (For showing help message on
Author: Regis Houssin * input field). Input: fiedId Input: message Author: Regis Houssin Licence: GPL
Licence: GPL * ==================================================================
==================================================================*/ */
function hideMessage(fieldId,message) { function hideMessage(fieldId,message) {
var textbox = document.getElementById(fieldId); var textbox = document.getElementById(fieldId);
textbox.style.color = 'black'; textbox.style.color = 'black';
if (textbox.value == message) textbox.value = ''; if (textbox.value == message) textbox.value = '';
} }
/*=================================================================
Purpose: To show an element (To support multiselect of checkboxes in some pages) /*
Input: fieldId * =================================================================
Author: Regis Houssin * Purpose: To
Licence: GPL * show an element (To support multiselect of checkboxes in some pages) Input:
==================================================================*/ * fieldId Author: Regis Houssin Licence: GPL
* ==================================================================
*/
function displayElement(fieldId) { function displayElement(fieldId) {
var elementId = document.getElementById(fieldId); var elementId = document.getElementById(fieldId);
if (elementId.style.visibility == 'hidden') { if (elementId.style.visibility == 'hidden') {
@@ -643,12 +654,13 @@ function displayElement(fieldId) {
} }
} }
/*================================================================= /*
Purpose: To hide an element (To support multiselect of checkboxes in some pages) * =================================================================
Input: fieldId * Purpose: To
Author: Regis Houssin * hide an element (To support multiselect of checkboxes in some pages) Input:
Licence: GPL * fieldId Author: Regis Houssin Licence: GPL
==================================================================*/ * ==================================================================
*/
function hideElement(fieldId) { function hideElement(fieldId) {
var elementId = document.getElementById(fieldId); var elementId = document.getElementById(fieldId);
if (elementId.style.visibility == 'visible') { if (elementId.style.visibility == 'visible') {
@@ -656,12 +668,13 @@ function hideElement(fieldId) {
} }
} }
/*================================================================= /*
Purpose: To check a checkbox (To support multiselect of checkboxes in some pages) * =================================================================
Input: fieldId * Purpose: To
Author: Regis Houssin * check a checkbox (To support multiselect of checkboxes in some pages) Input:
Licence: GPL * fieldId Author: Regis Houssin Licence: GPL
==================================================================*/ * ==================================================================
*/
function checkBox(boxId) { function checkBox(boxId) {
var elementId = document.getElementById(boxId); var elementId = document.getElementById(boxId);
if (elementId.checked == false) { if (elementId.checked == false) {
@@ -669,12 +682,13 @@ function checkBox(boxId) {
} }
} }
/*================================================================= /*
Purpose: To uncheck a checkbox (To support multiselect of checkboxes in some pages) * =================================================================
Input: fieldId * Purpose: To
Author: Regis Houssin * uncheck a checkbox (To support multiselect of checkboxes in some pages)
Licence: GPL * Input: fieldId Author: Regis Houssin Licence: GPL
==================================================================*/ * ==================================================================
*/
function uncheckBox(boxId) { function uncheckBox(boxId) {
var elementId = document.getElementById(boxId); var elementId = document.getElementById(boxId);
if (elementId.checked == true) { if (elementId.checked == true) {
@@ -682,4 +696,3 @@ function uncheckBox(boxId) {
} }
} }