Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor jQuery wrappers with local alias #998

Merged
merged 2 commits into from
Apr 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2,295 changes: 1,147 additions & 1,148 deletions admin/js/core/qtranslatex.js

Large diffs are not rendered by default.

65 changes: 32 additions & 33 deletions admin/js/edit-tags-exec.js
Original file line number Diff line number Diff line change
@@ -1,44 +1,43 @@
/* executed for
/wp-admin/edit-tags.php (without action=edit)
*/
const $ = jQuery;

(function ($) {
$(function () {
const qtx = qTranslateConfig.js.get_qtx();
$(function () {
const qtx = qTranslateConfig.js.get_qtx();

const addDisplayHook = function (i, o) {
qtx.addDisplayHook(o);
};
const addDisplayHook = function (i, o) {
qtx.addDisplayHook(o);
};

const updateRow = function (r) {
const j = $(r);
j.find('.row-title, .description').each(addDisplayHook);
j.find('td.name span.inline').css('display', 'none');
};
const updateRow = function (r) {
const j = $(r);
j.find('.row-title, .description').each(addDisplayHook);
j.find('td.name span.inline').css('display', 'none');
};

const the_list = $('#the-list');
let rcnt = $('#the-list > tr').length;
const the_list = $('#the-list');
let rcnt = $('#the-list > tr').length;

const onRowAdd = function () {
const trs = the_list.children();
if (rcnt === trs.length)
return false;
const ok = rcnt > trs.length;
rcnt = trs.length;
if (ok)
return false;
for (let i = 0; i < trs.length; ++i) {
const r = trs[i];
updateRow(r);
}
const onRowAdd = function () {
const trs = the_list.children();
if (rcnt === trs.length)
return false;
};

the_list.each(function (i, o) {
$(o).bind("DOMSubtreeModified", onRowAdd);
});
const ok = rcnt > trs.length;
rcnt = trs.length;
if (ok)
return false;
for (let i = 0; i < trs.length; ++i) {
const r = trs[i];
updateRow(r);
}
return false;
};

// remove "Quick Edit" links for now
$('#the-list > tr > td.name span.inline').css('display', 'none');
the_list.each(function (i, o) {
$(o).bind("DOMSubtreeModified", onRowAdd);
});
})(jQuery);

// remove "Quick Edit" links for now
$('#the-list > tr > td.name span.inline').css('display', 'none');
});
88 changes: 44 additions & 44 deletions admin/js/nav-menus-exec.js
Original file line number Diff line number Diff line change
@@ -1,56 +1,56 @@
/* executed for
/wp-admin/nav-menus.php
*/
(function ($) {
$(function () {
const qtx = qTranslateConfig.js.get_qtx();
const $ = jQuery;

const addMenuItemHooks = function (li) {
qtx.addContentHooksByClass('edit-menu-item-title', li);
qtx.addContentHooksByClass('edit-menu-item-attr-title', li);
qtx.addContentHooksByClass('[edit-menu-item-description', li); // must use '[:]' separator style
$(function () {
const qtx = qTranslateConfig.js.get_qtx();

qtx.addDisplayHooksByClass('menu-item-title', li);
qtx.addDisplayHooksByTagInClass('link-to-original', 'A', li);
};
const addMenuItemHooks = function (li) {
qtx.addContentHooksByClass('edit-menu-item-title', li);
qtx.addContentHooksByClass('edit-menu-item-attr-title', li);
qtx.addContentHooksByClass('[edit-menu-item-description', li); // must use '[:]' separator style

const onAddMenuItem = function (menuMarkup) {
const rx = /id="menu-item-(\d+)"/gi;
while ((matches = rx.exec(menuMarkup))) {
const id = 'menu-item-' + matches[1];
const li = document.getElementById(id);
if (li) addMenuItemHooks(li);
}
};
qtx.addDisplayHooksByClass('menu-item-title', li);
qtx.addDisplayHooksByTagInClass('link-to-original', 'A', li);
};

const onAddMenuItem = function (menuMarkup) {
const rx = /id="menu-item-(\d+)"/gi;
while ((matches = rx.exec(menuMarkup))) {
const id = 'menu-item-' + matches[1];
const li = document.getElementById(id);
if (li) addMenuItemHooks(li);
}
};

if (wpNavMenu) {
const wp_addMenuItemToBottom = wpNavMenu.addMenuItemToBottom;
if (typeof wp_addMenuItemToBottom == 'function') {
wpNavMenu.addMenuItemToBottom = function (menuMarkup, req) {
wp_addMenuItemToBottom(menuMarkup, req);
onAddMenuItem(menuMarkup);
};
}
if (typeof wp_addMenuItemToTop == 'function') {
wpNavMenu.addMenuItemToTop = function (menuMarkup) {
wp_addMenuItemToTop(menuMarkup);
onAddMenuItem(menuMarkup);
};
}
}

const onLanguageSwitchAfter = function (lang) {
if (wpNavMenu) {
const wp_addMenuItemToBottom = wpNavMenu.addMenuItemToBottom;
if (typeof wp_addMenuItemToBottom == 'function') {
wpNavMenu.addMenuItemToBottom = function (menuMarkup, req) {
wp_addMenuItemToBottom(menuMarkup, req);
onAddMenuItem(menuMarkup);
};
if (typeof wpNavMenu.refreshKeyboardAccessibility == 'function') {
wpNavMenu.refreshKeyboardAccessibility();
}
if (typeof wp_addMenuItemToTop == 'function') {
wpNavMenu.addMenuItemToTop = function (menuMarkup) {
wp_addMenuItemToTop(menuMarkup);
onAddMenuItem(menuMarkup);
};
if (typeof wpNavMenu.refreshAdvancedAccessibility == 'function') {
wpNavMenu.refreshAdvancedAccessibility();
}
}
};
onLanguageSwitchAfter();

const onLanguageSwitchAfter = function (lang) {
if (wpNavMenu) {
if (typeof wpNavMenu.refreshKeyboardAccessibility == 'function') {
wpNavMenu.refreshKeyboardAccessibility();
}
if (typeof wpNavMenu.refreshAdvancedAccessibility == 'function') {
wpNavMenu.refreshAdvancedAccessibility();
}
}
};
onLanguageSwitchAfter();

qtx.addLanguageSwitchAfterListener(onLanguageSwitchAfter);
});
})(jQuery);
qtx.addLanguageSwitchAfterListener(onLanguageSwitchAfter);
});
52 changes: 26 additions & 26 deletions admin/js/notices.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
(function ($) {
$(function () {
$('.notice-dismiss, .qtranxs-notice-dismiss').each(
function () {
const q = $(this);
const d = q.closest('div.is-dismissible');
if (!d.length)
const $ = jQuery;

$(function () {
$('.notice-dismiss, .qtranxs-notice-dismiss').each(
function () {
const q = $(this);
const d = q.closest('div.is-dismissible');
if (!d.length)
return;
if (!q.hasClass('qtranxs-notice-dismiss')) {
const f = d.find('.qtranxs-notice-dismiss');
if (!f.length)
return;
if (!q.hasClass('qtranxs-notice-dismiss')) {
const f = d.find('.qtranxs-notice-dismiss');
if (!f.length)
return;
}
let id = d.attr('id');
if (!id)
return;
id = id.replace('qtranxs-', '');
const action = d.attr('action');
q.on('click',
function () {
d.css('display', 'none');
$.post(ajaxurl, {action: 'qtranslate_admin_notice', notice_id: id, notice_action: action});
}
);
}
);
});
}(jQuery));
let id = d.attr('id');
if (!id)
return;
id = id.replace('qtranxs-', '');
const action = d.attr('action');
q.on('click',
function () {
d.css('display', 'none');
$.post(ajaxurl, {action: 'qtranslate_admin_notice', notice_id: id, notice_action: action});
}
);
}
);
});
Loading