2019-04-09 00:21:00 +02:00
|
|
|
import Vue from 'vue'
|
2019-05-31 15:01:54 +02:00
|
|
|
|
2019-06-12 12:16:15 +02:00
|
|
|
import InfiniteLoading from 'vue-infinite-loading';
|
|
|
|
Vue.use(InfiniteLoading, {
|
|
|
|
props: {
|
|
|
|
spinner: 'spiral',
|
|
|
|
// slots.noMore: ''
|
|
|
|
},
|
|
|
|
// system: {
|
|
|
|
// throttleLimit: 50,
|
|
|
|
// /* other settings need to configure */
|
|
|
|
// }
|
|
|
|
});
|
|
|
|
|
2019-04-09 00:21:00 +02:00
|
|
|
import store from 'vuejs/store'
|
2019-06-03 13:06:44 +02:00
|
|
|
import router from 'vuejs/route'
|
2019-05-31 15:01:54 +02:00
|
|
|
|
|
|
|
import VUserBlock from 'vuejs/components/Block/UserBlock'
|
2019-05-23 18:11:06 +02:00
|
|
|
import VMainContent from 'vuejs/components/Content/MainContent'
|
2019-05-31 15:01:54 +02:00
|
|
|
import VSearchBlock from 'vuejs/components/Block/SearchBlock'
|
2019-04-11 00:12:23 +02:00
|
|
|
|
|
|
|
import { mapState } from 'vuex'
|
2019-03-25 18:27:56 +01:00
|
|
|
|
2019-04-09 00:21:00 +02:00
|
|
|
// require('theme/assets/styles/main.scss');
|
|
|
|
import 'theme/assets/styles/main.scss'
|
|
|
|
|
|
|
|
(function(Drupal, drupalSettings) {
|
|
|
|
|
|
|
|
var MaterioTheme = function(){
|
2019-04-11 00:12:23 +02:00
|
|
|
|
2019-07-12 22:15:09 +02:00
|
|
|
var _v_sitebranding_block, _v_user_block, _v_header_menu
|
|
|
|
, _v_pagetitle_block, _v_search_block
|
|
|
|
, _v_main_content;
|
2019-05-31 15:01:54 +02:00
|
|
|
var _is_front = drupalSettings.path.isFront;
|
2019-04-11 00:12:23 +02:00
|
|
|
|
|
|
|
console.log('drupalSettings', drupalSettings);
|
|
|
|
|
2019-03-25 18:27:56 +01:00
|
|
|
// ___ _ _
|
|
|
|
// |_ _|_ _ (_) |_
|
|
|
|
// | || ' \| | _|
|
|
|
|
// |___|_||_|_|\__|
|
|
|
|
function init(){
|
2019-04-11 00:12:23 +02:00
|
|
|
console.log("MaterioTheme init()")
|
|
|
|
initVues()
|
|
|
|
}
|
|
|
|
|
|
|
|
function initVues(){
|
2019-07-12 22:15:09 +02:00
|
|
|
initVRouter();
|
2019-06-03 13:06:44 +02:00
|
|
|
initVSiteBrandingBlock()
|
2019-06-22 16:13:47 +02:00
|
|
|
initVPagetitleBlock()
|
2019-05-31 23:05:37 +02:00
|
|
|
initVUserBlock()
|
2019-07-12 22:15:09 +02:00
|
|
|
initVHeaderMenu()
|
2019-05-23 18:11:06 +02:00
|
|
|
initVMainContent()
|
2019-05-31 15:01:54 +02:00
|
|
|
initVSearchBlock()
|
2019-04-11 00:12:23 +02:00
|
|
|
}
|
2019-03-25 18:27:56 +01:00
|
|
|
|
2019-07-12 22:15:09 +02:00
|
|
|
function initVRouter(){
|
2019-07-24 17:20:44 +02:00
|
|
|
// we need this to update the title and body classes while using history nav
|
2019-07-12 22:15:09 +02:00
|
|
|
router.beforeEach((to, from, next) => {
|
2019-07-24 17:20:44 +02:00
|
|
|
// console.log('router beforeEach to ', to);
|
|
|
|
// commit new title to store
|
2019-07-25 21:23:23 +02:00
|
|
|
let title = null;
|
|
|
|
switch (to.name) {
|
|
|
|
case 'home':
|
|
|
|
title = null
|
|
|
|
break;
|
|
|
|
case 'article':
|
|
|
|
title = false
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
title = to.name
|
|
|
|
}
|
|
|
|
if (title !== false) {
|
|
|
|
store.commit('Common/setPagetitle', title)
|
|
|
|
}
|
2019-07-24 17:20:44 +02:00
|
|
|
|
|
|
|
// remove all path related body classes
|
|
|
|
let body_classes = document.querySelector('body').classList;
|
|
|
|
let classes_to_rm = [];
|
|
|
|
for (var i = 0; i < body_classes.length; i++) {
|
|
|
|
if(body_classes[i].startsWith('path-')){
|
|
|
|
classes_to_rm.push(body_classes[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
document.querySelector('body').classList.remove(...classes_to_rm);
|
|
|
|
// add new path classes to body
|
|
|
|
let classes = [];
|
|
|
|
if(to.path == '/'){
|
|
|
|
classes.push('path-home');
|
|
|
|
}else{
|
|
|
|
let path_parts = to.path.replace(/^\//, '').split('/');
|
|
|
|
for (var i = 0; i < path_parts.length; i++) {
|
|
|
|
if(i == 0){
|
|
|
|
var c = "path-" + path_parts[i];
|
|
|
|
}else if (path_parts[i] !== ''){
|
|
|
|
var c = classes[i-1] +'-'+ path_parts[i];
|
|
|
|
}
|
|
|
|
classes.push(c)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
document.querySelector('body').classList.add(...classes);
|
|
|
|
|
|
|
|
// trigger router
|
2019-07-12 22:15:09 +02:00
|
|
|
next();
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-06-03 13:06:44 +02:00
|
|
|
function initVSiteBrandingBlock(){
|
|
|
|
_v_sitebranding_block = new Vue({
|
|
|
|
store,
|
|
|
|
router,
|
|
|
|
el: '#block-sitebranding',
|
|
|
|
methods: {
|
2019-06-06 17:37:43 +02:00
|
|
|
onclick(event){
|
|
|
|
// console.log("Clicked on logo event", event);
|
|
|
|
let href = event.target.getAttribute('href');
|
|
|
|
// console.log("Clicked on logo href", href);
|
|
|
|
this.$router.push(href)
|
2019-07-12 22:15:09 +02:00
|
|
|
// replaced by router.beforeEach
|
|
|
|
// this.$store.commit('Common/setPagetitle', null)
|
2019-06-03 13:06:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-06-22 16:13:47 +02:00
|
|
|
function initVPagetitleBlock(){
|
|
|
|
let $blk = document.querySelector('#block-pagetitle')
|
|
|
|
let $h2 = $blk.querySelector('h2')
|
|
|
|
// get the loaded pagetitle
|
|
|
|
let title = $h2.innerText
|
|
|
|
// if not front recorde the loaded pagetitle in store
|
|
|
|
if (!_is_front) {
|
|
|
|
store.commit('Common/setPagetitle', title)
|
|
|
|
}
|
|
|
|
// replace in template the pagetitle by vue binding
|
|
|
|
$h2.innerText = '{{ pagetitle }}'
|
|
|
|
// create the vue
|
|
|
|
_v_pagetitle_block = new Vue({
|
|
|
|
store,
|
|
|
|
router,
|
|
|
|
el: $blk,
|
|
|
|
computed: {
|
|
|
|
...mapState({
|
|
|
|
pagetitle: state => state.Common.pagetitle
|
|
|
|
})
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-05-31 23:05:37 +02:00
|
|
|
function initVUserBlock(){
|
|
|
|
let mount_point = drupalSettings.user.uid !== 0 ? 'block-userblock' : 'block-userlogin';
|
2019-05-21 14:56:34 +02:00
|
|
|
let props = {
|
2019-05-31 15:01:54 +02:00
|
|
|
title: "",
|
2019-05-31 23:05:37 +02:00
|
|
|
loginblock:""
|
2019-05-21 14:56:34 +02:00
|
|
|
};
|
|
|
|
switch (mount_point) {
|
2019-05-31 23:05:37 +02:00
|
|
|
case 'block-userlogin':
|
|
|
|
let $block = document.getElementById(mount_point);
|
|
|
|
console.log('initVUserBlock login form html', $block);
|
|
|
|
props.loginblock = $block.outerHTML.trim()
|
2019-05-21 14:56:34 +02:00
|
|
|
break;
|
2019-05-31 23:05:37 +02:00
|
|
|
case 'block-userblock':
|
2019-05-21 14:56:34 +02:00
|
|
|
default:
|
2019-05-23 17:52:46 +02:00
|
|
|
break;
|
2019-05-21 14:56:34 +02:00
|
|
|
}
|
2019-05-23 17:52:46 +02:00
|
|
|
|
2019-05-31 15:01:54 +02:00
|
|
|
_v_user_block = new Vue({
|
2019-04-11 00:12:23 +02:00
|
|
|
store,
|
2019-05-31 15:01:54 +02:00
|
|
|
// computed: {
|
|
|
|
// ...mapState({
|
|
|
|
// isloggedin: state => state.User.isloggedin
|
|
|
|
// })
|
|
|
|
// },
|
2019-04-11 00:12:23 +02:00
|
|
|
created () {
|
2019-05-31 23:05:37 +02:00
|
|
|
// if already loggedin, call store.user to get the user infos
|
2019-04-11 00:12:23 +02:00
|
|
|
if(drupalSettings.user.uid !== 0){
|
|
|
|
this.$store.commit('User/setUid', drupalSettings.user.uid)
|
|
|
|
this.$store.dispatch('User/getUser')
|
|
|
|
}
|
|
|
|
},
|
2019-05-21 14:56:34 +02:00
|
|
|
render: h => h(VUserBlock, {props:props})
|
2019-05-31 23:05:37 +02:00
|
|
|
}).$mount('#'+mount_point)
|
|
|
|
// console.log('initVUserBlock', _v_user_block);
|
2019-04-11 00:12:23 +02:00
|
|
|
}
|
2019-03-25 18:27:56 +01:00
|
|
|
|
2019-07-12 22:15:09 +02:00
|
|
|
function initVHeaderMenu(){
|
|
|
|
// console.log('initVHeaderMenu');
|
|
|
|
// adding vuejs attributes has it wont work on twig template (see menu--header.html.twig)
|
|
|
|
// not working : String contains an invalid character
|
|
|
|
// document.querySelectorAll(`#block-header a`).forEach(link => {
|
|
|
|
// console.log(link);
|
|
|
|
// link.setAttribute('@click.prevent', 'onclick')
|
|
|
|
// });
|
|
|
|
|
|
|
|
_v_header_menu = new Vue({
|
|
|
|
store,
|
|
|
|
router,
|
|
|
|
el: `#block-header`,
|
|
|
|
methods: {
|
|
|
|
onclick(event){
|
|
|
|
// console.log("Clicked on header menu link", event);
|
|
|
|
let href = event.target.getAttribute('href');
|
2019-07-24 17:20:44 +02:00
|
|
|
// let title = event.target.innerText;
|
2019-07-12 22:15:09 +02:00
|
|
|
// console.log("Clicked on header menu link : href", href);
|
|
|
|
this.$router.push(href)
|
|
|
|
// replaced by router.beforeEach
|
|
|
|
// this.$store.commit('Common/setPagetitle', title)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-05-23 18:11:06 +02:00
|
|
|
function initVMainContent(){
|
2019-06-03 13:06:44 +02:00
|
|
|
let id = "main-content"
|
|
|
|
let $main_content = document.querySelector('#'+id)
|
2019-05-31 15:01:54 +02:00
|
|
|
// console.log('main-content', $main_content);
|
2019-05-23 18:11:06 +02:00
|
|
|
let main_html = $main_content.innerHTML
|
2019-05-31 15:01:54 +02:00
|
|
|
_v_main_content = new Vue({
|
2019-04-11 00:12:23 +02:00
|
|
|
store,
|
2019-06-04 22:38:44 +02:00
|
|
|
render: h => h(VMainContent, {props:{id:id, html:main_html, isfront:drupalSettings.path.isFront}})
|
2019-06-03 13:06:44 +02:00
|
|
|
}).$mount('#'+id)
|
2019-04-11 00:12:23 +02:00
|
|
|
}
|
2019-03-25 18:27:56 +01:00
|
|
|
|
2019-05-31 15:01:54 +02:00
|
|
|
function initVSearchBlock(){
|
|
|
|
// console.log('initVSearchBlock');
|
|
|
|
let id = "block-materiosapisearchblock"
|
|
|
|
let $search_block = document.getElementById(id)
|
|
|
|
var formhtml = null
|
|
|
|
if($search_block){
|
|
|
|
// get the search form html to pass it as template to the vue
|
|
|
|
// we gain display speed vs async downloaded data
|
|
|
|
formhtml = $search_block.innerHTML
|
|
|
|
}else{
|
|
|
|
// else create the empty block to fill it later with async data
|
|
|
|
$search_block = document.createElement('div')
|
|
|
|
$search_block.setAttribute('id', id)
|
2019-06-22 16:13:47 +02:00
|
|
|
// TODO: get region by REST
|
|
|
|
let $region = document.getElementById('header-bottom');
|
2019-05-31 15:01:54 +02:00
|
|
|
$region.appendChild($search_block);
|
|
|
|
}
|
|
|
|
|
|
|
|
// in any case create the vue
|
|
|
|
_v_search_block = new Vue({
|
|
|
|
store,
|
|
|
|
render: h => h(VSearchBlock, {props:{blockid:id, formhtml:formhtml}})
|
|
|
|
}).$mount('#'+id)
|
|
|
|
}
|
|
|
|
|
2019-04-11 00:12:23 +02:00
|
|
|
init()
|
2019-03-25 18:27:56 +01:00
|
|
|
} // end MaterioTheme()
|
|
|
|
|
2019-04-11 00:12:23 +02:00
|
|
|
var materiotheme = new MaterioTheme();
|
2019-03-25 18:27:56 +01:00
|
|
|
|
2019-04-09 00:21:00 +02:00
|
|
|
})(Drupal, drupalSettings);
|