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