Skip to content

Commit 93132ac

Browse files
committed
Rename a function to be clearer, and remove an argument which makes the visibility calculation nonsensical
1 parent 4dec07f commit 93132ac

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

content_editor/admin.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,8 @@ def _content_editor_context(self, request, context):
216216
"selectMultiple": gettext(
217217
"Use Ctrl-Click to select and move multiple items."
218218
),
219+
"clone": gettext("Clone plugins from another region"),
220+
"selectAll": gettext("Select all"),
219221
},
220222
}
221223

content_editor/static/content_editor/content_editor.js

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,11 @@
129129
window.ContentEditor = prepareContentEditorObject(django.jQuery)
130130

131131
django.jQuery(($) => {
132-
ContentEditor.addPluginButton = (prefix, iconHTML) => {
132+
ContentEditor.addPluginButton = (
133+
prefix,
134+
iconHTML,
135+
initializing = false,
136+
) => {
133137
const plugin = ContentEditor.pluginsByPrefix[prefix]
134138
if (!plugin) return
135139

@@ -160,7 +164,9 @@
160164
const unit = qs(".plugin-buttons")
161165
unit.appendChild(button)
162166

163-
hideNotAllowedPluginButtons([button])
167+
if (!initializing) {
168+
updatePluginButtonsVisibility()
169+
}
164170
}
165171

166172
// Add basic structure. There is always at least one inline group if
@@ -487,11 +493,8 @@
487493

488494
// Hide not allowed plugin buttons
489495
// If buttons only checks this buttons, else checks all
490-
function hideNotAllowedPluginButtons(_buttons) {
491-
const buttons = _buttons
492-
? _buttons
493-
: qsa(".plugin-buttons .plugin-button")
494-
496+
function updatePluginButtonsVisibility() {
497+
const buttons = qsa(".plugin-buttons .plugin-button")
495498
let visible = 0
496499

497500
for (const button of buttons) {
@@ -838,9 +841,7 @@
838841
.filter(`[data-region="${ContentEditor.currentRegion}"]`)
839842
.addClass("active")
840843

841-
// Make sure only allowed plugins are in select
842-
hideNotAllowedPluginButtons()
843-
844+
updatePluginButtonsVisibility()
844845
updateSections()
845846
})
846847
})()
@@ -1003,7 +1004,7 @@
10031004
setTimeout(restoreEditorState, 1)
10041005

10051006
for (const plugin of ContentEditor.plugins) {
1006-
ContentEditor.addPluginButton(plugin.prefix, plugin.button)
1007+
ContentEditor.addPluginButton(plugin.prefix, plugin.button, true)
10071008
}
10081009

10091010
if (!ContentEditor.allowChange) {

0 commit comments

Comments
 (0)