Skip to content

Instantly share code, notes, and snippets.

@onefriendaday
Created August 23, 2022 12:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save onefriendaday/cd04556e38c7238da99b837235b9f4b9 to your computer and use it in GitHub Desktop.
Save onefriendaday/cd04556e38c7238da99b837235b9f4b9 to your computer and use it in GitHub Desktop.
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