Skip to content

Commit

Permalink
Adjustements for jquery update
Browse files Browse the repository at this point in the history
- Replaced .click(function) by .on('click', function)
- Replaced .click() by .trigger('click')
- Replaced .live(event, function) by .on(event, function)
- Replaced $(document).ready(function) by $(function)
- Replaced .bind/.unbind by .on/.off
- Replaced keypress events by keydown events, so that up/down keys get
supported again.

Thanks to the jquery-migrate project.
  • Loading branch information
nirgal authored and xzilla committed Oct 7, 2020
1 parent f28e894 commit bf0572a
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 40 deletions.
10 changes: 5 additions & 5 deletions classes/Misc.php
Expand Up @@ -545,7 +545,7 @@ function printHeader($title = '', $script = null, $frameset = false) {
echo "<link rel=\"icon\" type=\"image/png\" href=\"images/themes/{$conf['theme']}/Introduction.png\" />\n";
echo "<script type=\"text/javascript\" src=\"libraries/js/jquery.js\"></script>";
echo "<script type=\"text/javascript\">// <!-- \n";
echo "$(document).ready(function() { \n";
echo "$(function() { \n";
echo " if (window.parent.frames.length > 1)\n";
echo " $('#csstheme', window.parent.frames[0].document).attr('href','themes/{$conf['theme']}/global.css');\n";
echo "}); // --></script>\n";
Expand Down Expand Up @@ -1416,25 +1416,25 @@ function printTopbar() {
$history_window_id = htmlentities('history:'.$_REQUEST['server']);

echo "<script type=\"text/javascript\">
$('#toplink_sql').click(function() {
$('#toplink_sql').on('click', function() {
window.open($(this).attr('href'),'{$sql_window_id}','toolbar=no,width=700,height=500,resizable=yes,scrollbars=yes').focus();
return false;
});
$('#toplink_history').click(function() {
$('#toplink_history').on('click', function() {
window.open($(this).attr('href'),'{$history_window_id}','toolbar=no,width=700,height=500,resizable=yes,scrollbars=yes').focus();
return false;
});
$('#toplink_find').click(function() {
$('#toplink_find').on('click', function() {
window.open($(this).attr('href'),'{$sql_window_id}','toolbar=no,width=700,height=500,resizable=yes,scrollbars=yes').focus();
return false;
});
";

if (isset($_SESSION['sharedUsername'])) {
printf("
$('#toplink_logout').click(function() {
$('#toplink_logout').on('click', function() {
return confirm('%s');
});", str_replace("'", "\'", $lang['strconfdropcred']));
}
Expand Down
47 changes: 22 additions & 25 deletions js/ac_insert_row.js
Expand Up @@ -14,15 +14,15 @@ function hideAc() {
function triggerAc(ac) {
if (ac) {
jQuery.ppa.attrs
.bind('keyup.ac_action', autocomplete)
.bind('focus.ac_action', autocomplete)
.bind('keypress.ac_action', move)
.on('keyup.ac_action', autocomplete)
.on('focus.ac_action', autocomplete)
.on('keydown.ac_action', move)
.addClass('ac_field');
}
else {
jQuery.ppa.attrs
.removeClass('ac_field')
.unbind('.ac_action');
.off('.ac_action');
}
}

Expand Down Expand Up @@ -90,6 +90,7 @@ function openlist(e) {
show();
jQuery.ppa.numrow = find('tr').length;
}

}
});
}
Expand Down Expand Up @@ -135,7 +136,7 @@ function autocomplete(event) {
/* if pressing enter, fire a click on the selected line */
if (event.keyCode == 13) {
if (jQuery.ppa.i > 0) {
jQuery.ppa.fklist.find('tr').eq(jQuery.ppa.i).click();
jQuery.ppa.fklist.find('tr').eq(jQuery.ppa.i).trigger('click');
}
return false;
}
Expand Down Expand Up @@ -166,39 +167,35 @@ function autocomplete(event) {
return true;
}

/* bind actions on values lines: hover for style change, click for select */
with(jQuery('tr.acline')) {
live('mouseover', function () {
selectVal(jQuery('table.ac_values tr').index(this));
});

live('click', function () {
var a = jQuery(this).find('td > a.fkval');
$(document).on('mouseover', 'tr.acline', function() {
selectVal(jQuery('table.ac_values tr').index(this));
});

for (i=0; i < a.length; i++) {
jQuery('input[name="values['+ a[i].name +']"]').val(jQuery(a[i]).text());
}
hideAc();
});
}
$(document).on('click', 'tr.acline', function() {
var a = jQuery(this).find('td > a.fkval');
for (i=0; i < a.length; i++) {
jQuery('input[name="values['+ a[i].name +']"]').val(jQuery(a[i]).text());
}
hideAc();
});

jQuery('#fkprev').live('click', function () {
$(document).on('click', '#fkprev', function () {
jQuery.ppa.o -= 11;
/* get the field that is the previous html elt from the #fklist
* and trigger its focus to refresh the list AND actually
* focus back on the field */
jQuery('#fklist').prev().focus();
});

jQuery('#fknext').live('click', function () {
$(document).on('click', '#fknext', function () {
jQuery.ppa.o += 11;
/* get the field that is the previous html elt from the #fklist
* and trigger its focus to refresh the list AND actually
* focus back on the field*/
jQuery('#fklist').prev().focus();
});

jQuery(document).ready(function () {
jQuery(function () {
/* register some global value in the ppa namespace */
jQuery.ppa = {
fklist: jQuery('#fklist'),
Expand All @@ -209,20 +206,20 @@ jQuery(document).ready(function () {
};

/* close the list when clicking outside of it */
jQuery.ppa.fkbg.click(function (e) {
jQuery.ppa.fkbg.on('click', function (e) {
hideAc();
});

/* do not submit the form when selecting a value by pressing enter */
jQuery.ppa.attrs
.keydown(function (e) {
.on('keydown', function (e) {
if (e.keyCode == 13 && jQuery.ppa.fklist[0].style.display == 'block')
return false;
});

/* enable/disable auto-complete according to the checkbox */
triggerAc(
jQuery('#no_ac').click(function () {
jQuery('#no_ac').on('click', function () {
triggerAc(this.checked);
})[0].checked
);
Expand Down
15 changes: 8 additions & 7 deletions js/database.js
@@ -1,4 +1,4 @@
$(document).ready(function() {
$(function() {

var timeid = query = null;
var controlLink = $('#control');
Expand Down Expand Up @@ -34,24 +34,25 @@ $(document).ready(function() {
}
}

controlLink.toggle(
function() {
controlLink.on('click', function() {
if (!timeid) {
$(errmsg).hide();
timeid = window.setTimeout(refreshTable, Database.ajax_time_refresh);
controlLink.html('<img src="'+ Database.str_stop.icon +'" alt="" />&nbsp;'
+ Database.str_stop.text + '&nbsp;&nbsp;&nbsp;'
);
},
function() {
} else {
$(errmsg).hide();
$(loading).hide();
window.clearInterval(timeid);
timeid = null;
if (query) query.abort();
controlLink.html('<img src="'+ Database.str_start.icon +'" alt="" />&nbsp;'
+ Database.str_start.text
);
}
);
return false; /* disable event propagation */
});

/* preload images */
$('#control img').hide()
Expand All @@ -60,5 +61,5 @@ $(document).ready(function() {
.show();

/* start refreshing */
controlLink.click();
controlLink.trigger('click');
});
6 changes: 3 additions & 3 deletions js/display.js
@@ -1,4 +1,4 @@
$(document).ready(function() {
$(function() {

/* init some needed tags and values */

Expand All @@ -9,7 +9,7 @@ $(document).ready(function() {
root: $('#root')
};

$("a.fk").live('click', function (event) {
$("a.fk").on('click', function (event) {
/* make the cursor being a waiting cursor */
$('body').css('cursor','wait');

Expand Down Expand Up @@ -80,7 +80,7 @@ $(document).ready(function() {
return false; // do not refresh the page
});

$(".fk_delete").live('click', function (event) {
$(document).on('click', '.fk_delete', function (event) {
with($(this).closest('div')) {
data('ref').closest('tr').find('a.'+data('refclass')).closest('div').removeClass('highlight');
remove();
Expand Down

0 comments on commit bf0572a

Please sign in to comment.