remove duplicate code

This commit is contained in:
daria 2024-03-08 17:37:17 +02:00
parent c6bcfc1321
commit 923cb9690b
8 changed files with 64 additions and 209 deletions

View File

@ -123,14 +123,15 @@ define([
window.print();
framework.feedback('PRINT_CODE');
});
var $print = UIElements.createDropdownEntry({
tag: 'a',
attributes: { 'class': $printButton.attr('class') },
content: h('span', $printButton.text()),
action: function () {
$printButton.click();
}
});
// var $print = UIElements.createDropdownEntry({
// tag: 'a',
// attributes: { 'class': $printButton.attr('class') },
// content: h('span', $printButton.text()),
// action: function () {
// $printButton.click();
// }
// });
var $print = UIElements.getEntryFromButton($printButton);
framework._.toolbar.$drawer.append($print);
};
var mkMarkdownTb = function (editor, framework) {

View File

@ -576,6 +576,25 @@ define([
});
};
UIElements.getEntryFromButton = function ($button) {
// If the button contains an icon, clone it and re-use it
let $icon = $button.find('> i');
let icon = $icon.length ? $icon.clone() : undefined;
return UIElements.createDropdownEntry({
tag: 'a',
attributes: {'class': $button.attr('class')},
content: [
icon,
h('span', $button.text())
],
action: function () {
$button.click();
return true;
}
});
};
UIElements.createButton = function (common, type, rightside, data, callback) {
var AppConfig = common.getAppConfig();
var button;

View File

@ -2763,7 +2763,6 @@ Uncaught TypeError: Cannot read property 'calculatedType' of null
$historyButton.click();
}
});
$historyDropdown.appendTo(toolbar.$drawer);
// Snapshots
@ -2772,27 +2771,13 @@ Uncaught TypeError: Cannot read property 'calculatedType' of null
make: makeSnapshot,
load: loadSnapshot
});
var $snapshot = UIElements.createDropdownEntry({
tag: 'a',
attributes: { 'class': $snapshotButton.attr('class') },
content: h('span', $snapshotButton.text()),
action: function () {
$snapshotButton.click();
}
});
var $snapshot = UIElements.getEntryFromButton($snapshotButton);
toolbar.$drawer.append($snapshot);
// Import template
var $templateButton = common.createButton('importtemplate', true, {}, openTemplatePicker);
if ($templateButton && typeof($templateButton.appendTo) === 'function') {
var $template = UIElements.createDropdownEntry({
tag: 'a',
attributes: { 'class': $templateButton.attr('class') },
content: h('span', $templateButton.text()),
action: function () {
openTemplatePicker();
}
});
var $template = UIElements.getEntryFromButton($templateButton);
$template.appendTo(toolbar.$drawer);
}
@ -2816,14 +2801,7 @@ Uncaught TypeError: Cannot read property 'calculatedType' of null
}
};
var $templateButton = common.createButton('template', true, templateObj);
var $template = UIElements.createDropdownEntry({
tag: 'a',
attributes: { 'class': $templateButton.attr('class') },
content: h('span', $templateButton.text()),
action: function () {
$templateButton.click();
}
});
var $template = UIElements.getEntryFromButton($templateButton);
toolbar.$drawer.append($template);
}
})();
@ -2849,14 +2827,7 @@ Uncaught TypeError: Cannot read property 'calculatedType' of null
}
var $exportXLSXButton = common.createButton('export', true, {}, exportXLSXFile);
var $exportXLSX = UIElements.createDropdownEntry({
tag: 'a',
attributes: { 'class': $exportXLSXButton.attr('class') },
content: h('span', $exportXLSXButton.text()),
action: function () {
exportXLSXFile();
}
});
var $exportXLSX = UIElements.getEntryFromButton($exportXLSXButton);
$exportXLSX.appendTo(toolbar.$drawer);
var type = privateData.ooType;
@ -2889,24 +2860,10 @@ Uncaught TypeError: Cannot read property 'calculatedType' of null
binary: ["ods", "xlsx", "odt", "docx", "odp", "pptx"],
first: first,
}, importXLSXFile);
var $importXLSX = UIElements.createDropdownEntry({
tag: 'a',
attributes: { 'class': $importXLSXButton.attr('class') },
content: h('span', $importXLSXButton.text()),
action: function () {
importXLSXFile();
}
});
var $importXLSX = UIElements.getEntryFromButton($importXLSXButton);
// tag button
var $hashtagButton = common.createButton('hashtag', true);
var $hashtag = UIElements.createDropdownEntry({
tag: 'a',
attributes: { 'class': $hashtagButton.attr('class') },
content: h('span', $hashtagButton.text()),
action: function () {
$hashtagButton.click();
}
});
var $hashtag = UIElements.getEntryFromButton($hashtagButton);
$importXLSX.appendTo(toolbar.$drawer);
$hashtag.appendTo(toolbar.$drawer);
}
@ -2919,14 +2876,7 @@ Uncaught TypeError: Cannot read property 'calculatedType' of null
if (err) { return; }
setEditable(false);
});
var $forget = UIElements.createDropdownEntry({
tag: 'a',
attributes: { 'class': $forgetButton.attr('class') },
content: h('span', $forgetButton.text()),
action: function () {
$forgetButton.click();
}
});
var $forget = UIElements.getEntryFromButton($forgetButton);
toolbar.$drawer.append($forget);
if (!privateData.isEmbed) {
@ -2948,25 +2898,11 @@ Uncaught TypeError: Cannot read property 'calculatedType' of null
}
var $propertiesButton = common.createButton('properties', true);
var $properties = UIElements.createDropdownEntry({
tag: 'a',
attributes: { 'class': $propertiesButton.attr('class') },
content: h('span', $propertiesButton.text()),
action: function () {
$propertiesButton.click();
}
});
var $properties = UIElements.getEntryFromButton($propertiesButton);
toolbar.$drawer.append($properties);
var $copyButton = common.createButton('copy', true);
var $copy = UIElements.createDropdownEntry({
tag: 'a',
attributes: { 'class': $copyButton.attr('class') },
content: h('span', $copyButton.text()),
action: function () {
$copyButton.click();
}
});
var $copy = UIElements.getEntryFromButton($copyButton);
toolbar.$drawer.append($copy);
};

View File

@ -774,14 +774,7 @@ define([
});
$select.find('button').addClass('btn');
});
var $export = UIElements.createDropdownEntry({
tag: 'a',
attributes: { 'class': $exportButton.attr('class') },
content: h('span', $exportButton.text()),
action: function () {
$exportButton.click();
}
});
var $export = UIElements.getEntryFromButton($exportButton);
toolbar.$drawer.append($export);
};
@ -812,14 +805,7 @@ define([
});
};
var $importButton = common.createButton('import', true, options, fileImporter);
var $import = UIElements.createDropdownEntry({
tag: 'a',
attributes: { 'class': $importButton.attr('class') },
content: h('span', $importButton.text()),
action: function () {
$importButton.click();
},
});
var $import = UIElements.getEntryFromButton($importButton);
toolbar.$drawer.append($import);
};
@ -1014,14 +1000,7 @@ define([
$toolbar: $(toolbarContainer)
};
var $histButton = common.createButton('history', true, {histConfig: histConfig});
var $hist = UIElements.createDropdownEntry({
tag: 'a',
attributes: {'class': $histButton.attr('class')},
content: h('span', $histButton.text()),
action: function () {
$histButton.click();
},
});
var $hist = UIElements.getEntryFromButton($histButton);
toolbar.$drawer.append($hist);
var $snapshotButton = common.createButton('snapshots', true, {
@ -1029,38 +1008,17 @@ define([
make: makeSnapshot,
load: loadSnapshot
});
var $snapshot = UIElements.createDropdownEntry({
tag: 'a',
attributes: { 'class': $snapshotButton.attr('class') },
content: h('span', $snapshotButton.text()),
action: function () {
$snapshotButton.click();
}
});
var $snapshot = UIElements.getEntryFromButton($snapshotButton);
toolbar.$drawer.append($snapshot);
var $copyButton = common.createButton('copy', true);
var $copy = UIElements.createDropdownEntry({
tag: 'a',
attributes: { 'class': $copyButton.attr('class') },
content: h('span', $copyButton.text()),
action: function () {
$copyButton.click();
}
});
var $copy = UIElements.getEntryFromButton($copyButton);
toolbar.$drawer.append($copy);
var $store = common.createButton('storeindrive', true);
var $storeEntry = UIElements.createDropdownEntry({
tag: 'a',
attributes: { 'class': $store.attr('class') },
content: h('span', $store.text()),
action: function () {
$store.click();
}
});
toolbar.$drawer.append($storeEntry);
var $storeButton = UIElements.getEntryFromButton($store);
toolbar.$drawer.append($storeButton);
if (!cpNfInner.metadataMgr.getPrivateData().isTemplate) {
var templateObj = {
@ -1068,28 +1026,14 @@ define([
getTitle: function () { return cpNfInner.metadataMgr.getMetadata().title; }
};
var $templateButton = common.createButton('template', true, templateObj);
var $template = UIElements.createDropdownEntry({
tag: 'a',
attributes: { 'class': $templateButton.attr('class') },
content: h('span', $templateButton.text()),
action: function () {
$templateButton.click();
}
});
var $template = UIElements.getEntryFromButton($templateButton);
toolbar.$drawer.append($template);
}
var $importTemplateButton = common.createButton('importtemplate', true);
if (!readOnly) {
var $importTemplate = UIElements.createDropdownEntry({
tag: 'a',
attributes: { 'class': $importTemplateButton.attr('class') },
content: h('span', $importTemplateButton.text()),
action: function () {
$importTemplateButton.click();
}
});
var $importTemplate = UIElements.getEntryFromButton($importTemplateButton);
toolbar.$drawer.append($importTemplate);
}
@ -1098,41 +1042,18 @@ define([
if (err) { return; }
stateChange(STATE.FORGOTTEN);
});
var $forget = UIElements.createDropdownEntry({
tag: 'a',
attributes: { 'class': $forgetButton.attr('class') },
content: h('span', $forgetButton.text()),
action: function () {
$forgetButton.click();
}
});
var $forget = UIElements.getEntryFromButton($forgetButton);
toolbar.$drawer.append($forget);
if (common.isLoggedIn()) {
var $tagsButton = common.createButton('hashtag', true);
var $tags = UIElements.createDropdownEntry({
tag: 'a',
attributes: { 'class': $tagsButton.attr('class') },
content: h('span', $tagsButton.text()),
action: function () {
$tagsButton.click();
}
});
var $tags = UIElements.getEntryFromButton($tagsButton);
toolbar.$drawer.append($tags);
}
var $propertiesButton = common.createButton('properties', true);
var $properties = UIElements.createDropdownEntry({
tag: 'a',
attributes: { 'class': $propertiesButton.attr('class') },
content: h('span', $propertiesButton.text()),
action: function () {
$propertiesButton.click();
}
});
var $properties = UIElements.getEntryFromButton($propertiesButton);
toolbar.$drawer.append($properties);
createFilePicker();

View File

@ -479,7 +479,6 @@ define([
$block.find('button').click();
},
});
// $blockButton.append($block.find('ul'));
$drawer.append($blockButton);
}
if (cb) { cb(); }

View File

@ -1008,14 +1008,7 @@ MessengerUI, Messages, Pages) {
var createNewPad = function (toolbar) {
var $button = Common.createButton('newpad', true);
var $newPad = UIElements.createDropdownEntry({
tag: 'a',
attributes: { 'class': $button.attr('class') },
content: h('span', $button.text()),
action: function () {
$button.click();
}
});
var $newPad = UIElements.getEntryFromButton($button);
toolbar.$drawer.append($newPad);
return $newPad;
};

View File

@ -646,23 +646,8 @@ define([
var mkPrintButton = function (framework, editor) {
var $printButton = framework._.sfCommon.createButton('print', true);
var $print = UIElements.createDropdownEntry({
tag: 'a',
attributes: { 'class': $printButton.attr('class') },
content: h('span', $printButton.text()),
action: function () {
/*
// NOTE: alternative print system in case we keep having more issues on Firefox
var $iframe = $('html').find('iframe');
var iframe = $iframe[0].contentWindow;
iframe.print();
*/
editor.execCommand('print');
framework.feedback('PRINT_PAD');
}
});
var $print = UIElements.getEntryFromButton($printButton);
framework._.toolbar.$drawer.append($print);
};
var andThen2 = function(editor, Ckeditor, framework) {

View File

@ -122,18 +122,19 @@ define([
var mkPrintButton = function (framework, editor, $content, $print) {
var $printButton = framework._.sfCommon.createButton('print', true);
var $print = UIElements.createDropdownEntry({
tag: 'a',
attributes: { 'class': $printButton.attr('class') },
content: h('span', $printButton.text()),
action: function () {
Slide.update(editor.getValue(), true);
$print.html($content.html());
window.focus();
window.print();
framework.feedback('PRINT_SLIDES');
}
});
// var $print = UIElements.createDropdownEntry({
// tag: 'a',
// attributes: { 'class': $printButton.attr('class') },
// content: h('span', $printButton.text()),
// action: function () {
// Slide.update(editor.getValue(), true);
// $print.html($content.html());
// window.focus();
// window.print();
// framework.feedback('PRINT_SLIDES');
// }
// });
var $print = UIElements.getEntryFromButton($printButton);
framework._.toolbar.$drawer.append($print);
};