+// Global Event System
+class EventManager {
+ constructor() {
+ this.listeners = {};
+ }
+
+ emit(eventName, eventData) {
+ if (typeof this.listeners[eventName] === 'undefined') return this;
+ let eventsToStart = this.listeners[eventName];
+ for (let i = 0; i < eventsToStart.length; i++) {
+ let event = eventsToStart[i];
+ event(eventData);
+ }
+ return this;
+ }
+
+ listen(eventName, callback) {
+ if (typeof this.listeners[eventName] === 'undefined') this.listeners[eventName] = [];
+ this.listeners[eventName].push(callback);
+ return this;
+ }
+}
+
+window.Events = new EventManager();
+
+// Load in angular specific items
+import Services from './services';
+import Directives from './directives';
+import Controllers from './controllers';
+Services(ngApp, window.Events);
+Directives(ngApp, window.Events);
+Controllers(ngApp, window.Events);
+
+//Global jQuery Config & Extensions
+
+// Smooth scrolling
+jQuery.fn.smoothScrollTo = function () {
+ if (this.length === 0) return;
+ let scrollElem = document.documentElement.scrollTop === 0 ? document.body : document.documentElement;
+ $(scrollElem).animate({
+ scrollTop: this.offset().top - 60 // Adjust to change final scroll position top margin
+ }, 800); // Adjust to change animations speed (ms)
+ return this;
+};
+
+// Making contains text expression not worry about casing
+jQuery.expr[":"].contains = $.expr.createPseudo(function (arg) {
+ return function (elem) {
+ return $(elem).text().toUpperCase().indexOf(arg.toUpperCase()) >= 0;
+ };
+});
+
+// Global jQuery Elements
+let notifications = $('.notification');
+let successNotification = notifications.filter('.pos');
+let errorNotification = notifications.filter('.neg');
+let warningNotification = notifications.filter('.warning');
+// Notification Events
+window.Events.listen('success', function (text) {
+ successNotification.hide();
+ successNotification.find('span').text(text);
+ setTimeout(() => {
+ successNotification.show();
+ }, 1);
+});
+window.Events.listen('warning', function (text) {
+ warningNotification.find('span').text(text);
+ warningNotification.show();
+});
+window.Events.listen('error', function (text) {
+ errorNotification.find('span').text(text);
+ errorNotification.show();