import {GlobalStore} from './lib/gstore-es6' window.gstore = new GlobalStore(); // Header gstore.add('header_title', 'ndli1718'); gstore.add('info', { active: false, type: 'warning', message: 'Warning! blabla' }); gstore.add('notif', { emergency: { class: 'emergency', data: [], count: 0 }, event: { class: 'event', data: [], count: 0 }, inbox: { class: 'message', data: [], count: 0 }, dashboard: { class: 'menu', data: [], count: 0 } }) // Menu gstore.add('menu_item', { dashboard: { label: 'Accueil', theme: 'dashboard' }, emergency: { label: 'Urgences', theme: 'emergency' }, event: { label: 'Signalements', theme: 'event' }, inbox: { label: 'Messagerie', theme: 'inbox' } }); gstore.add('URI', document.URL.replace(/^(?:\/\/|[^\/]+)*/, '')); gstore.add('is_local', document.URL.replace(/^http:\/\/([^\/]+).*$/, '$1') == 'ndli1718'); gstore.add('min_menu', false); // Proccess current page from url if( /^\/(\w+)(?:\/?.*)$/.test(gstore.data.URI) ){ var mi_keys = Object.keys( gstore.data.menu_item ); // if current page exists if( !!~mi_keys.indexOf(RegExp.$1) ) gstore.add('menu_item_active', RegExp.$1); else gstore.add('menu_item_active', 'dashboard'); }else gstore.add('menu_item_active', 'dashboard'); // Functions gstore.add('func', { nav: function(router, uri){ // {1} Update view (vue-router) // if( typeof uri == 'string' ) router.push('/'+uri); // {2} if no @uri -> Extract route from @router // else if( /^\/([^\/]+).*$/.test( router.app.$route.path ) ) uri = RegExp.$1; // {3} If no @uri -> exit // else return; // {4} Activate current menu_item // gstore.data.menu_item_active = uri; // {5} Manage notifications // for( var id in gstore.data.notif ) if( id == uri ) // if notif links to current page gstore.data.notif[id].count = 0; }, toggleMenuSize: function(){ gstore.data.min_menu=!gstore.data.min_menu; }, bbcode: function(msg){ /* (1) Escape HTML ---------------------------------------------------------*/ msg = msg.replace(/&/g, '&'); msg = msg.replace(//g, '>'); /* (2) Manage text format ---------------------------------------------------------*/ /* (1) Manage bold */ msg = msg.replace(/\*([^\*]+)\*/g, "$1"); /* (2) italic */ msg = msg.replace(/_([^_]+)_/g, "$1"); /* (3) underline */ msg = msg.replace(/\[([^\]]+)\]/g, "$1"); /* (4) Code */ msg = msg.replace(/`([^`]+)`/g, "$1"); /* (3) Manage emojis ---------------------------------------------------------*/ /* (1) Smileys */ msg = msg.replace(/:D/g, "😃"); msg = msg.replace(/:\)/g, "🙂"); msg = msg.replace(/:B/g, "😎"); msg = msg.replace(/:3/g, "😗"); msg = msg.replace(/;\)/g, "😉"); msg = msg.replace(/:P/g, "😋"); msg = msg.replace(/;P/g, "😜"); msg = msg.replace(/xD/g, "😆"); msg = msg.replace(/:O/ig, "😲"); msg = msg.replace(/:S/g, "😖"); msg = msg.replace(/\^\^/g, "😊"); /* (2) Emojis */ msg = msg.replace(/:poop:/g, "💩"); msg = msg.replace(/:fuck:/g, "🖕"); msg = msg.replace(/\+1/g, "👍"); msg = msg.replace(/-1/g, "👎"); return msg; } }); // new-message container gstore.add('new_msg', { inbox: '', emergency: '', event: '' }); // if message loader gstore.add('msg_pending', { inbox: true, emergency: true, event: true }); // true when message send pending // notification stack visibility gstore.add('nstack', false);