blob: 6e6a7cb5989deda8e365e8c9b149b822a9602a87 [file] [log] [blame]
Faris Ansari019bfd392018-08-26 20:08:40 +05301import Vue from 'vue/dist/vue.js';
Prateeksha Singhd0a952b2018-08-27 10:12:45 +05302
3// Global components
4import ItemCardsContainer from './components/ItemCardsContainer.vue';
5import SectionHeader from './components/SectionHeader.vue';
6import SearchInput from './components/SearchInput.vue';
7import DetailView from './components/DetailView.vue';
8import DetailHeaderItem from './components/DetailHeaderItem.vue';
9import EmptyState from './components/EmptyState.vue';
Faris Ansari9fb5e1c2018-09-07 23:17:29 +053010import Image from './components/Image.vue';
Prateeksha Singhd0a952b2018-08-27 10:12:45 +053011
Faris Ansari019bfd392018-08-26 20:08:40 +053012Vue.prototype.__ = window.__;
13Vue.prototype.frappe = window.frappe;
14
Prateeksha Singhd0a952b2018-08-27 10:12:45 +053015Vue.component('item-cards-container', ItemCardsContainer);
16Vue.component('section-header', SectionHeader);
17Vue.component('search-input', SearchInput);
18Vue.component('detail-view', DetailView);
19Vue.component('detail-header-item', DetailHeaderItem);
20Vue.component('empty-state', EmptyState);
Faris Ansari9fb5e1c2018-09-07 23:17:29 +053021Vue.component('base-image', Image);
Prateeksha Singhd0a952b2018-08-27 10:12:45 +053022
Faris Ansari019bfd392018-08-26 20:08:40 +053023Vue.directive('route', {
24 bind(el, binding) {
25 const route = binding.value;
Faris Ansarif089dad2018-08-26 22:20:16 +053026 if (!route) return;
Faris Ansari019bfd392018-08-26 20:08:40 +053027 el.classList.add('cursor-pointer');
Faris Ansarif089dad2018-08-26 22:20:16 +053028 el.dataset.route = route;
Faris Ansari019bfd392018-08-26 20:08:40 +053029 el.addEventListener('click', () => frappe.set_route(route));
30 },
31 unbind(el) {
32 el.classList.remove('cursor-pointer');
33 }
34});
35
36const 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 Shetty49c37d52018-08-27 20:31:29 +053056Vue.filter('striphtml', function (text) {
Faris Ansariad0be6a2018-09-03 15:42:00 +053057 return strip_html(text || '');
Suraj Shetty49c37d52018-08-27 20:31:29 +053058});