app.js 1.49 KB
Newer Older
1
'use strict'
2

NGPixel's avatar
NGPixel committed
3 4
/* global alertsData */

5
import $ from 'jquery'
NGPixel's avatar
NGPixel committed
6 7 8
import _ from 'lodash'
import io from 'socket.io-client'
import Alerts from './components/alerts.js'
9
import 'jquery-smooth-scroll'
10
import 'jquery-sticky'
11

12
$(() => {
13 14 15
  // ====================================
  // Scroll
  // ====================================
NGPixel's avatar
NGPixel committed
16

17
  $('a').smoothScroll({
18 19
    speed: 500,
    offset: -50
20
  })
21

22
  $('.stickyscroll').sticky({ topSpacing: 15, bottomSpacing: 75 })
23

24 25 26
  // ====================================
  // Notifications
  // ====================================
27

28 29 30 31 32 33 34 35
  $(window).bind('beforeunload', () => {
    $('#notifload').addClass('active')
  })
  $(document).ajaxSend(() => {
    $('#notifload').addClass('active')
  }).ajaxComplete(() => {
    $('#notifload').removeClass('active')
  })
NGPixel's avatar
NGPixel committed
36

37 38 39 40 41 42
  var alerts = new Alerts()
  if (alertsData) {
    _.forEach(alertsData, (alertRow) => {
      alerts.push(alertRow)
    })
  }
43

44 45 46
  // ====================================
  // Establish WebSocket connection
  // ====================================
47

48
  var socket = io(window.location.origin)
49

50
  require('./components/search.js')(socket)
51

52 53 54
  // ====================================
  // Pages logic
  // ====================================
55

56
  require('./pages/view.js')(alerts)
57
  require('./pages/all.js')(alerts, socket)
58
  require('./pages/create.js')(alerts, socket)
59 60
  require('./pages/edit.js')(alerts, socket)
  require('./pages/source.js')(alerts)
61
  require('./pages/history.js')(alerts)
62
  require('./pages/admin.js')(alerts)
63
})