main.js 4.1 KB

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