main.js 4.1 KB

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