Skip to content

Commit

Permalink
XWIKI-14928: Upgrade to jQuery 3.6.0
Browse files Browse the repository at this point in the history
* Replace more deprecated APIs
  • Loading branch information
mflorea committed Feb 16, 2022
1 parent 1693a6f commit 05f0ba0
Show file tree
Hide file tree
Showing 31 changed files with 81 additions and 81 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -749,7 +749,7 @@ require(['jquery'], function($) {
var panelGroup = $(this).closest('.panel-group');
var text = $(this).val().toLowerCase();
// Schedule a new filter operation.
timeoutId = setTimeout($.proxy(filterPanelGroup, panelGroup, text), 500);
timeoutId = setTimeout(filterPanelGroup.bind(panelGroup, text), 500);

// Finally, enable the search input.
}).prop('disabled', false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -557,8 +557,8 @@ require(['jquery', 'xwiki-meta', 'xwiki-livetable-modal', 'xwiki-events-bridge']
actionTrigger.removeClass('pending');
});
};
$('#userstable').on('click', 'a.actionenable', $.proxy(onToggleUser, null, 'enable'));
$('#userstable').on('click', 'a.actiondisable', $.proxy(onToggleUser, null, 'disable'));
$('#userstable').on('click', 'a.actionenable', onToggleUser.bind(null, 'enable'));
$('#userstable').on('click', 'a.actiondisable', onToggleUser.bind(null, 'disable'));
})();

//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ require(['jquery', 'bootstrap'], function($) {
$.ajax({
type: 'HEAD',
url: newAppHomePage.getURL()
}).then($.proxy(endValidation, null, pageExistsError), response => {
}).then(endValidation.bind(null, pageExistsError), response => {
if (response.status === 404) {
$.ajax({
type: 'HEAD',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@
$('.jcaptcha .engine.' + this.value).removeClass('hidden');

// Check the first option for the new type.
$('.jcaptcha .engine:visible:first input').prop('checked', true);
$('.jcaptcha .engine:visible').first().find('input').prop('checked', true);

// Clear the custom value since it will not match the new type.
$('.customEngine').val('');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ define('editInPlace', [
if (xwikiDocument.lockConfirmation) {
var confirmation = xwikiDocument.lockConfirmation;
delete xwikiDocument.lockConfirmation;
return maybeForceLock(confirmation).then($.proxy(xwikiDocument, 'lock', 'edit', true), function() {
return maybeForceLock(confirmation).then(xwikiDocument.lock.bind(xwikiDocument, 'edit', true), function() {
// Cancel the edit action.
return Promise.reject(xwikiDocument);
});
Expand Down Expand Up @@ -543,7 +543,7 @@ define('editInPlace', [
return Promise.reject(xwikiDocument);
// Render the document for edit, in order to have the annotated content HTML. The annotations are used to protect
// the rendering transformations (e.g. macros) when editing the content.
}).then($.proxy(render, null, false));
}).then(render.bind(null, false));
};

/**
Expand Down Expand Up @@ -598,7 +598,7 @@ define('editInPlace', [
// its content doesn't match the saved content).
reload,
// No need to reload the editor because either the action was Save & View or there was no merge on save.
$.proxy(maybeContinueEditing, null, data['continue'])
maybeContinueEditing.bind(null, data['continue'])
);
// Save failed. Continue editing because we may have unsaved content.
}, maybeSave);
Expand All @@ -612,8 +612,8 @@ define('editInPlace', [
// once it was resolved or rejected. So the first event that fires will resolve/reject the promise and the
// remaining event won't be able to change that. The remaining event listener could be called later but it won't
// have any effect.
$(document).one('xwiki:document:saved', '.xcontent.form', $.proxy(resolve, null, xwikiDocument));
$(document).one('xwiki:document:saveFailed', '.xcontent.form', $.proxy(reject, null, xwikiDocument));
$(document).one('xwiki:document:saved', '.xcontent.form', resolve.bind(null, xwikiDocument));
$(document).one('xwiki:document:saveFailed', '.xcontent.form', reject.bind(null, xwikiDocument));
});
};

Expand All @@ -635,9 +635,9 @@ define('editInPlace', [

// Reload the document JSON data (to have the new version) and render the document for view. We need the view HTML
// both if we stop editing now and if we continue but cancel the edit later.
return xwikiDocument.reload().then($.proxy(render, null, true)).then(
$.proxy(afterReloadAndRender, null, /* success: */ true),
$.proxy(afterReloadAndRender, null, /* success: */ false)
return xwikiDocument.reload().then(render.bind(null, true)).then(
afterReloadAndRender.bind(null, /* success: */ true),
afterReloadAndRender.bind(null, /* success: */ false)
);
};

Expand All @@ -656,7 +656,7 @@ define('editInPlace', [
};

// Make sure we unlock the document when the user navigates to another page.
$(window).on('unload pagehide', $.proxy(unlock, null, currentXWikiDocument));
$(window).on('unload pagehide', unlock.bind(null, currentXWikiDocument));

var shouldReload = function(xwikiDocument) {
var reloadEventFired = false;
Expand Down Expand Up @@ -1063,7 +1063,7 @@ require(['jquery'], function($) {
editButton.removeClass('disabled');
});
// Fallback on the standalone edit mode if we fail to load the required modules.
}, $.proxy(disableInPlaceEditing, event.target));
}, disableInPlaceEditing.bind(event.target));
};

var disableInPlaceEditing = function() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
var container = $((data && data.elements) || document);
container.find('input.datetime').each(function() {
var dateTimeInput = $(this);
maybeLoadLocale(dateTimeInput.data('locale')).then($.proxy(createDateTimePicker, null, dateTimeInput));
maybeLoadLocale(dateTimeInput.data('locale')).then(createDateTimePicker.bind(null, dateTimeInput));
});
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ define('xwiki-locale-picker', ['jquery', 'bootstrap-select'], function($) {
});

$.fn.localePicker = function(settings) {
return this.each($.proxy(init, null, settings));
return this.each(init.bind(null, settings));
};

var defaultSettings = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ require(['jquery', 'xwiki-syntax-converter', 'bootstrap'], function($, syntaxCon
});
syntaxPicker.prop('disabled', true).trigger('xwiki:document:syntaxChange', data);
// Re-enable the syntax picker after the UI has been updated.
data.promise.finally($.proxy(syntaxPicker, 'prop', 'disabled', false));
data.promise.finally(syntaxPicker.prop.bind(syntaxPicker, 'disabled', false));
// Update the previous syntax.
syntaxPicker.data('previousSyntax', data.syntax);
};
Expand Down Expand Up @@ -351,7 +351,8 @@ require(['jquery'], function($) {
// the user can change the syntax multiple times before saving. Note that this check works as long as the document
// content doesn't have unsaved changes, which is true because we are only viewing the content in this case.
if (data.convertSyntax && data.syntax.id !== data.savedSyntax.id) {
return data.syntaxConverter.convert(data.syntax).then($.proxy(data.syntaxConverter, 'render', data.syntax));
return data.syntaxConverter.convert(data.syntax)
.then(data.syntaxConverter.render.bind(data.syntaxConverter, data.syntax));
} else {
return data.syntaxConverter.render(data.syntax);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,8 @@
}).on('load', function() {
// We need to refresh just after LESS is loaded because the fist rendering does not handle the variables of the
// flamingo theme. Unfortunately, it means that the preview is rendered twice at the loading of the page.
initPreview(iframe).then(refreshPreview).then($.proxy(deferred, 'resolve')).catch($.proxy(deferred, 'reject'));
initPreview(iframe).then(refreshPreview).then(deferred.resolve.bind(deferred))
.catch(deferred.reject.bind(deferred));
}).insertBefore('#preview-curtain');

// Update the preview curtain size and position.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ define(['jquery'], function($) {
return promise;
};

var onFailure = $.proxy(promise.reject, promise);
var onFailure = promise.reject.bind(promise);

var refresh = function(job) {
var request = config.createStatusRequest(job.id);
Expand All @@ -43,7 +43,7 @@ define(['jquery'], function($) {
var onProgress = function(job) {
if (job && job.id && job.state && job.progress) {
if (job.state == 'WAITING') {
promise.notify(job, $.proxy(answerJobQuestion, job));
promise.notify(job, answerJobQuestion.bind(job));

// Restart the progress if the question timeout is reached
var timeout = job.questionTimeLeft;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ define('xwiki-l10n', ['module', 'jquery'], function(module, $) {
locale: specs.locale || document.documentElement.getAttribute('lang'),
prefix: specs.prefix,
key: specs.keys
}, true))).then($.proxy(toTranslationsMap, null, specs.prefix || ''));
}, true))).then(toTranslationsMap.bind(null, specs.prefix || ''));
};

var toTranslationsMap = function(prefix, responseJSON) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@
<code>require(['jquery'], function ($) {
var form = $('#realtime\\ editors_XWiki\\.Realtime\\.Configuration');
if (XWiki.mainWiki === XWiki.currentWiki) {
form.find('dt:first').hide();
form.find('dt').first().hide();
return;
}
var onChange = function () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ define('xwiki-realtime-document', [
// Reload failed. Continue using the current data.
return this;
}
}).then($.proxy(this, 'update'));
}).then(this.update.bind(this));
},

update: function(data) {
Expand Down Expand Up @@ -94,7 +94,7 @@ define('xwiki-realtime-document', [
editingVersionDate: this.modified,
minorEdit: 1,
ajax: true
}, data), true)).then($.proxy(this, 'reload'));
}, data), true)).then(this.reload.bind(this));
},

getChannels: function(params) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ define('xwiki-realtime-loader', [
userAvatarURL: realtimeConfig.user.avatarURL,
isAdvancedUser: realtimeConfig.user.advanced,
network: allRt.network,
abort: $.proxy(module, 'onRealtimeAbort'),
onKeysChanged: $.proxy(module, 'onKeysChanged'),
displayDisableModal: $.proxy(module, 'displayDisableModal'),
abort: module.onRealtimeAbort.bind(module),
onKeysChanged: module.onKeysChanged.bind(module),
displayDisableModal: module.displayDisableModal.bind(module),
};
},

Expand Down Expand Up @@ -189,9 +189,7 @@ define('xwiki-realtime-loader', [
this.showDialog();
},
createContent: function() {
$(content).find('button, input').on('click', $.proxy(function() {
this.closeDialog();
}, this));
$(content).find('button, input').on('click', this.closeDialog.bind(this));
return content;
}
});
Expand Down Expand Up @@ -260,7 +258,7 @@ define('xwiki-realtime-loader', [
getReloadContent = function() {
var content = createModalContent(Messages['reloadDialog.prompt'], Messages['reloadDialog.exit']);
var buttonReload = $('<button class="btn btn-default"></button>').text(Messages['reloadDialog.reload']);
buttonReload.on('click', $.proxy(window.location, 'reload', true)).insertAfter(content.find('button'));
buttonReload.on('click', window.location.reload.bind(window.location, true)).insertAfter(content.find('button'));
return content[0];
},

Expand All @@ -275,17 +273,17 @@ define('xwiki-realtime-loader', [
module.displayDisableModal = function(callback) {
var content = createModalContent(Messages['disableDialog.prompt'], Messages['disableDialog.ok']);

var buttonOK = content.find('button').on('click', $.proxy(callback, null, true));
var buttonOK = content.find('button').on('click', callback.bind(null, true));
$('<button class="btn btn-default"></button>').text(Messages['disableDialog.exit']).insertBefore(buttonOK)
.on('click', $.proxy(callback, null, false));
.on('click', callback.bind(null, false));
return void displayCustomModal(content[0]);
};

var availableRt = {};
module.setAvailableRt = function(info) {
availableRt[info.type] = {
info,
cb: $.proxy(createRt, null, info)
cb: createRt.bind(null, info)
};
};

Expand Down Expand Up @@ -624,7 +622,7 @@ define('xwiki-realtime-loader', [

joinAllUsers = function() {
var config = getConfig();
var getChannels = $.proxy(doc, 'getChannels', {
var getChannels = doc.getChannels.bind(doc, {
path: doc.language + '/events/all',
create: true
});
Expand All @@ -638,7 +636,7 @@ define('xwiki-realtime-loader', [
console.error(error);
};
// Connect to the websocket server.
Netflux.connect(config.WebsocketURL).then($.proxy(onNetfluxConnect, null, config, getChannels, channelKey,
Netflux.connect(config.WebsocketURL).then(onNetfluxConnect.bind(null, config, getChannels, channelKey,
onError), onError);
});
}
Expand Down Expand Up @@ -780,7 +778,7 @@ define('xwiki-realtime-loader', [
doc.language + '/content/',
],
create: true
}).then($.proxy(parseKeyData, module, editorId));
}).then(parseKeyData.bind(module, editorId));
},

requestRt: function(type, callback) {
Expand Down Expand Up @@ -822,7 +820,7 @@ define('xwiki-realtime-loader', [
displayWsWarning(true);
callback(false);
} else {
setTimeout($.proxy(module, 'whenReady', callback), 100);
setTimeout(module.whenReady.bind(module, callback), 100);
}
},

Expand Down Expand Up @@ -854,7 +852,7 @@ define('xwiki-realtime-loader', [
// Let the user choose between joining the existing real-time session (with a different editor) or create
// a new real-time session with the current editor.
console.log('Join the existing realtime session or create a new one.');
this.displayModal(info.type, Object.keys(keys.active), $.proxy(resolve, null, keys), info);
this.displayModal(info.type, Object.keys(keys.active), resolve.bind(null, keys), info);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ define('xwiki-realtime-saver', [
}
// A merge took place.
if (merge.error) {
resolveMergeConflicts(merge).then($.proxy(mergeContinuation, null, merge, andThen));
resolveMergeConflicts(merge).then(mergeContinuation.bind(null, merge, andThen));
} else {
mergedWithoutConflicts(merge, preMergeContent).then(() => {
mergeContinuation(merge, andThen);
Expand All @@ -428,7 +428,7 @@ define('xwiki-realtime-saver', [
// Post your current version to the server to see if it must merge. Remember the current state so you can check if
// it has changed.
var preMergeContent = mainConfig.getTextValue();
ajaxMerge(preMergeContent, $.proxy(mergeCallback, null, preMergeContent, andThen));
ajaxMerge(preMergeContent, mergeCallback.bind(null, preMergeContent, andThen));
},

onMessage = function(data) {
Expand Down Expand Up @@ -802,7 +802,7 @@ define('xwiki-realtime-saver', [
$(document).off('xwiki:document:saved.realtime-saver xwiki:document:saveFailed.realtime-saver');
// Remove our custom click listeners from the save buttons and restore the original click listeners.
$('[name="action_save"], [name="action_saveandcontinue"]').off('click.realtime-saver').each(function() {
$(this).data('prototype.js/clickListeners')?.forEach($.proxy(this, 'observe', 'click'));
$(this).data('prototype.js/clickListeners')?.forEach(this.observe.bind(this, 'click'));
});
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ define('xwiki-realtime-wikiEditor-loader', [
Loader.bootstrap(info).then(keys => {
require(['xwiki-realtime-wikiEditor'], function (RealtimeWikiEditor) {
if (RealtimeWikiEditor && RealtimeWikiEditor.main) {
keys._update = $.proxy(Loader, 'updateKeys', editorId);
keys._update = Loader.updateKeys.bind(Loader, editorId);
var config = Loader.getConfig();
config.rtURL = Loader.getEditorURL(window.location.href, info);
RealtimeWikiEditor.main(config, keys);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ define('xwiki-realtime-wysiwygEditor-loader', [
Loader.bootstrap(info).then(keys => {
require(['xwiki-realtime-wysiwygEditor'], function(RealtimeWysiwygEditor) {
if (RealtimeWysiwygEditor && RealtimeWysiwygEditor.main) {
keys._update = $.proxy(Loader, 'updateKeys', editorId);
keys._update = Loader.updateKeys.bind(Loader, editorId);
var config = Loader.getConfig();
config.rtURL = Loader.getEditorURL(window.location.href, info);
RealtimeWysiwygEditor.main(config, keys, Loader.isRt).then(editor => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ define('xwiki-realtime-wysiwygEditor', [
if (editor.status === 'ready') {
resolve(editor);
} else {
editor.on('instanceReady', $.proxy(resolve, null, editor));
editor.on('instanceReady', resolve.bind(null, editor));
}
} else {
ckeditor.on('instanceReady', function(event) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@

// Toggle the form when the user selects the corresponding option. We pass null to prevent animation.
$(this).find('.itemName').prev('input[type="checkbox"]').removeClass('hidden')
.on('click', $.proxy(form, 'toggle', null));
.on('click', form.toggle.bind(form, null));

// Use the client TimeZone when searching and displaying dates on the server.
// Note that we change the sign because Date#getTimezoneOffset() returns (UTC - local time)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@
checkBox.prop('checked', $(this).hasClass('selected'));
// Add the 'checked' attribute so that it can be easily located with CSS.
checkBox.prop('checked') &amp;&amp; checkBox.attr('checked', 'checked');
checkBox.on('click', $.proxy(this, 'click'));
checkBox.on('click', this.click.bind(this));
// Remove the 'selected' class because the selected state is marked using the check box.
$(this).removeClass('selected').before(checkBox);
};
Expand Down
Loading

0 comments on commit 05f0ba0

Please sign in to comment.