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

Refactored Code in public/src/admin/extend/widgets.js #590

Open
wants to merge 5 commits into
base: f24
Choose a base branch
from
Open
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
29 changes: 16 additions & 13 deletions public/src/admin/extend/widgets.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,11 +253,23 @@ define('admin/extend/widgets', [
});
}

function setupCloneButton() {
const clone = $('[component="clone"]');
function clone(location, template) {
console.log('Dhanya Shah');
const widgets = $('#active-widgets .tab-pane[data-template="' + template + '"] [data-location="' + location + '"] [data-widget]');
widgets.each(function () {
const widget = $(this).clone(true);
appendClonedWidget(widget, location);
});
}
function appendClonedWidget(widget, location) {
$('#active-widgets .active.tab-pane[data-template]:not([data-template="global"]) [data-location="' + location + '"] .widget-area').append(widget);
}

function setupCloneButton() { // all correct
const cloneContainer = $('[component="clone"]');
const cloneBtn = $('[component="clone/button"]');

clone.find('.dropdown-menu li').on('click', function () {
cloneContainer.find('.dropdown-menu li').on('click', function () {
const template = $(this).find('a').text();
cloneBtn.translateHtml('[[admin/extend/widgets:clone-from]] <strong>' + template + '</strong>');
cloneBtn.attr('data-template', template);
Expand All @@ -281,18 +293,9 @@ define('admin/extend/widgets', [
return currentAreas.indexOf(location) !== -1 ? location : undefined;
}).get().filter(function (i) { return i; });

function clone(location) {
$('#active-widgets .tab-pane[data-template="' + template + '"] [data-location="' + location + '"]').each(function () {
$(this).find('[data-widget]').each(function () {
const widget = $(this).clone(true);
$('#active-widgets .active.tab-pane[data-template]:not([data-template="global"]) [data-location="' + location + '"] .widget-area').append(widget);
});
});
}

for (let i = 0, ii = areasToClone.length; i < ii; i++) {
const location = areasToClone[i];
clone(location);
clone(location, template);
}

alerts.success('[[admin/extend/widgets:alert.clone-success]]');
Expand Down