main.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. import Vue from 'vue'
  2. import store from 'vuejs/store'
  3. import router from 'vuejs/route'
  4. // import autofocus from 'vue-autofocus-directive';
  5. // Vue.directive('autofocus', autofocus);
  6. import VUserBlock from 'vuejs/components/Block/UserBlock'
  7. import VMainContent from 'vuejs/components/Content/MainContent'
  8. import VSearchBlock from 'vuejs/components/Block/SearchBlock'
  9. import { mapState } from 'vuex'
  10. // require('theme/assets/styles/main.scss');
  11. import 'theme/assets/styles/main.scss'
  12. (function(Drupal, drupalSettings) {
  13. var MaterioTheme = function(){
  14. var _v_sitebranding_block, _v_user_block, _v_main_content, _v_search_block;
  15. var _is_front = drupalSettings.path.isFront;
  16. console.log('drupalSettings', drupalSettings);
  17. // ___ _ _
  18. // |_ _|_ _ (_) |_
  19. // | || ' \| | _|
  20. // |___|_||_|_|\__|
  21. function init(){
  22. console.log("MaterioTheme init()")
  23. initVues()
  24. }
  25. function initVues(){
  26. initVSiteBrandingBlock()
  27. initVUserBlock()
  28. initVMainContent()
  29. initVSearchBlock()
  30. }
  31. function initVSiteBrandingBlock(){
  32. _v_sitebranding_block = new Vue({
  33. store,
  34. router,
  35. el: '#block-sitebranding',
  36. methods: {
  37. onclick(event){
  38. // console.log("Clicked on logo event", event);
  39. let href = event.target.getAttribute('href');
  40. // console.log("Clicked on logo href", href);
  41. this.$router.push(href)
  42. }
  43. }
  44. })
  45. }
  46. function initVUserBlock(){
  47. let mount_point = drupalSettings.user.uid !== 0 ? 'block-userblock' : 'block-userlogin';
  48. let props = {
  49. title: "",
  50. loginblock:""
  51. };
  52. switch (mount_point) {
  53. case 'block-userlogin':
  54. let $block = document.getElementById(mount_point);
  55. console.log('initVUserBlock login form html', $block);
  56. props.loginblock = $block.outerHTML.trim()
  57. break;
  58. case 'block-userblock':
  59. default:
  60. break;
  61. }
  62. _v_user_block = new Vue({
  63. store,
  64. // computed: {
  65. // ...mapState({
  66. // isloggedin: state => state.User.isloggedin
  67. // })
  68. // },
  69. created () {
  70. // if already loggedin, call store.user to get the user infos
  71. if(drupalSettings.user.uid !== 0){
  72. this.$store.commit('User/setUid', drupalSettings.user.uid)
  73. this.$store.dispatch('User/getUser')
  74. }
  75. },
  76. render: h => h(VUserBlock, {props:props})
  77. }).$mount('#'+mount_point)
  78. // console.log('initVUserBlock', _v_user_block);
  79. }
  80. function initVMainContent(){
  81. let id = "main-content"
  82. let $main_content = document.querySelector('#'+id)
  83. // console.log('main-content', $main_content);
  84. let main_html = $main_content.innerHTML
  85. _v_main_content = new Vue({
  86. store,
  87. render: h => h(VMainContent, {props:{id:id, html:main_html, isfront:drupalSettings.path.isFront}})
  88. }).$mount('#'+id)
  89. // console.log('initTestVContent', v_test_content);
  90. }
  91. function initVSearchBlock(){
  92. // console.log('initVSearchBlock');
  93. let id = "block-materiosapisearchblock"
  94. let $search_block = document.getElementById(id)
  95. var formhtml = null
  96. if($search_block){
  97. // get the search form html to pass it as template to the vue
  98. // we gain display speed vs async downloaded data
  99. formhtml = $search_block.innerHTML
  100. }else{
  101. // else create the empty block to fill it later with async data
  102. $search_block = document.createElement('div')
  103. $search_block.setAttribute('id', id)
  104. let $region = document.getElementById('content-top');
  105. $region.appendChild($search_block);
  106. }
  107. // in any case create the vue
  108. _v_search_block = new Vue({
  109. store,
  110. render: h => h(VSearchBlock, {props:{blockid:id, formhtml:formhtml}})
  111. }).$mount('#'+id)
  112. }
  113. init()
  114. } // end MaterioTheme()
  115. var materiotheme = new MaterioTheme();
  116. })(Drupal, drupalSettings);