forked from episerver/musicfestival-vue-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathepiEdit.js
30 lines (26 loc) · 1.03 KB
/
epiEdit.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/**
* The directive `v-epi-edit` is used similarly to @Html.EditAttributes() in
* Razor views. It enables On-Page Editing on elements using the `data-epi-edit`
* property (introduced in Episerver CMS UI 11.X.0) and disables the DOM
* updating from the CMS so that Vue can keep the responsibility over the DOM.
*
* It's enabled by the `isEditable` value that is stored in the Vuex store, but
* can be overwritten by a component having a property named
* `epiDisableEditing` being true.
*
* Usage can be found on most Vue components, such as ArtistDetailsPage.vue.
*/
import store from '@/Scripts/store';
function toggleEditAttributes(el, binding, vnode) {
const siteIsEditable = store.state.epiContext.isEditable;
const componentIsEditable = !vnode.context.epiDisableEditing;
if (siteIsEditable && componentIsEditable) {
el.setAttribute('data-epi-edit', binding.value);
} else {
el.removeAttribute('data-epi-edit');
}
}
export default {
bind: toggleEditAttributes,
update: toggleEditAttributes
};