Skip to content

Commit

Permalink
Extract a few inline statements
Browse files Browse the repository at this point in the history
  • Loading branch information
matthiask committed Sep 11, 2024
1 parent 64c2af9 commit 42abe34
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions content_editor/static/content_editor/content_editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,21 @@
const LS = safeStorage(localStorage)
const SS = safeStorage(sessionStorage)

const prepareContentEditorObject = () => {
Object.assign(ContentEditor, JSON.parse(_contentEditorContext))
Object.assign(ContentEditor, {
pluginsByPrefix: Object.fromEntries(
ContentEditor.plugins.map((plugin) => [plugin.prefix, plugin]),
),
regionsByKey: Object.fromEntries(
ContentEditor.regions.map((region) => [region.key, region]),
),
hasSections: ContentEditor.plugins.some(
(plugin) => plugin.sections,
),
})
}

django.jQuery(($) => {
window.ContentEditor = {
addContent: function addContent(prefix) {
Expand Down Expand Up @@ -71,17 +86,7 @@
},
}

$.extend(window.ContentEditor, JSON.parse(_contentEditorContext))

ContentEditor.pluginsByPrefix = Object.fromEntries(
ContentEditor.plugins.map((plugin) => [plugin.prefix, plugin]),
)
ContentEditor.regionsByKey = Object.fromEntries(
ContentEditor.regions.map((region) => [region.key, region]),
)
ContentEditor.hasSections = ContentEditor.plugins.some(
(plugin) => plugin.sections,
)
prepareContentEditorObject()

// Add basic structure. There is always at least one inline group if
// we even have any plugins.
Expand Down

0 comments on commit 42abe34

Please sign in to comment.