Faris Ansari | 019bfd39 | 2018-08-26 20:08:40 +0530 | [diff] [blame] | 1 | import Vue from 'vue/dist/vue.js'; |
Prateeksha Singh | d0a952b | 2018-08-27 10:12:45 +0530 | [diff] [blame] | 2 | |
| 3 | // Global components |
| 4 | import ItemCardsContainer from './components/ItemCardsContainer.vue'; |
| 5 | import SectionHeader from './components/SectionHeader.vue'; |
| 6 | import SearchInput from './components/SearchInput.vue'; |
| 7 | import DetailView from './components/DetailView.vue'; |
| 8 | import DetailHeaderItem from './components/DetailHeaderItem.vue'; |
| 9 | import EmptyState from './components/EmptyState.vue'; |
Faris Ansari | 9fb5e1c | 2018-09-07 23:17:29 +0530 | [diff] [blame] | 10 | import Image from './components/Image.vue'; |
Prateeksha Singh | d0a952b | 2018-08-27 10:12:45 +0530 | [diff] [blame] | 11 | |
Faris Ansari | 019bfd39 | 2018-08-26 20:08:40 +0530 | [diff] [blame] | 12 | Vue.prototype.__ = window.__; |
| 13 | Vue.prototype.frappe = window.frappe; |
| 14 | |
Prateeksha Singh | d0a952b | 2018-08-27 10:12:45 +0530 | [diff] [blame] | 15 | Vue.component('item-cards-container', ItemCardsContainer); |
| 16 | Vue.component('section-header', SectionHeader); |
| 17 | Vue.component('search-input', SearchInput); |
| 18 | Vue.component('detail-view', DetailView); |
| 19 | Vue.component('detail-header-item', DetailHeaderItem); |
| 20 | Vue.component('empty-state', EmptyState); |
Faris Ansari | 9fb5e1c | 2018-09-07 23:17:29 +0530 | [diff] [blame] | 21 | Vue.component('base-image', Image); |
Prateeksha Singh | d0a952b | 2018-08-27 10:12:45 +0530 | [diff] [blame] | 22 | |
Faris Ansari | 019bfd39 | 2018-08-26 20:08:40 +0530 | [diff] [blame] | 23 | Vue.directive('route', { |
| 24 | bind(el, binding) { |
| 25 | const route = binding.value; |
Faris Ansari | f089dad | 2018-08-26 22:20:16 +0530 | [diff] [blame] | 26 | if (!route) return; |
Faris Ansari | 019bfd39 | 2018-08-26 20:08:40 +0530 | [diff] [blame] | 27 | el.classList.add('cursor-pointer'); |
Faris Ansari | f089dad | 2018-08-26 22:20:16 +0530 | [diff] [blame] | 28 | el.dataset.route = route; |
Faris Ansari | 019bfd39 | 2018-08-26 20:08:40 +0530 | [diff] [blame] | 29 | el.addEventListener('click', () => frappe.set_route(route)); |
| 30 | }, |
| 31 | unbind(el) { |
| 32 | el.classList.remove('cursor-pointer'); |
| 33 | } |
| 34 | }); |
| 35 | |
| 36 | const handleImage = (el, src) => { |
| 37 | let img = new Image(); |
| 38 | // add loading class |
| 39 | el.src = ''; |
| 40 | el.classList.add('img-loading'); |
| 41 | |
| 42 | img.onload = () => { |
| 43 | // image loaded, remove loading class |
| 44 | el.classList.remove('img-loading'); |
| 45 | // set src |
| 46 | el.src = src; |
| 47 | } |
| 48 | img.onerror = () => { |
| 49 | el.classList.remove('img-loading'); |
| 50 | el.classList.add('no-image'); |
| 51 | el.src = null; |
| 52 | } |
| 53 | img.src = src; |
| 54 | } |
| 55 | |
Suraj Shetty | 49c37d5 | 2018-08-27 20:31:29 +0530 | [diff] [blame] | 56 | Vue.filter('striphtml', function (text) { |
Faris Ansari | ad0be6a | 2018-09-03 15:42:00 +0530 | [diff] [blame] | 57 | return strip_html(text || ''); |
Suraj Shetty | 49c37d5 | 2018-08-27 20:31:29 +0530 | [diff] [blame] | 58 | }); |