Created
August 23, 2022 12:30
-
-
Save onefriendaday/cd04556e38c7238da99b837235b9f4b9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Fieldtype = { | |
mixins: [window.Storyblok.plugin], | |
template: `<div><label class="toggle" v-for="script in scriptsList" v-bind:key="script"> | |
<input | |
type="checkbox" | |
v-on:click="toggleScript(script)" | |
checked="checked" | |
/> | |
{{ script }} | |
</label></div>`, | |
data() { | |
return { | |
scriptsList: [], | |
}; | |
}, | |
methods: { | |
initWith() { | |
return { | |
plugin: "script-manager-alex", | |
scripts: {}, | |
} | |
}, | |
pluginCreated() { | |
this.getScripts(); | |
console.log('plugin:created') | |
}, | |
toggleScript(scriptName) { | |
const stateObj = this.model.scripts; | |
stateObj[scriptName] = !stateObj[scriptName]; | |
this.model.scripts = stateObj; | |
}, | |
getScripts() { | |
this.api.get("cdn/stories/global").then((res) => { | |
const { content } = res.data.story; | |
const scripts = content.headScripts.concat(content.bodyScripts); | |
const scriptsList = []; | |
const scriptsState = {}; | |
for (var i in scripts) { | |
scriptsState[scripts[i].scriptName] = true; | |
scriptsList.push(scripts[i].scriptName); | |
} | |
this.scriptsList = scriptsList; | |
this.model.scripts = scriptsState; | |
}); | |
}, | |
}, | |
watch: { | |
'model': { | |
handler: function (value) { | |
this.$emit('changed-model', value); | |
}, | |
deep: true | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment