aboutsummaryrefslogtreecommitdiffhomepage
path: root/app/Resources/static/themes/material/js/init.js
blob: d6a87941ee1baf89171731034869e5bf63793f05 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
var $ = require('jquery');
require('materialize');
var annotator = require('annotator');

function initFilters() {
  // no display if filters not aviable
  if ($('div').is('#filters')) {
    $('#button_filters').show();
    $('.button-collapse-right').sideNav({ edge: 'right' });
    $('#clear_form_filters').on('click', function () {
      $('#filters input').val('');
      $('#filters :checked').removeAttr('checked');
      return false;
    });
  }
}

function initExport() {
  // no display if export not aviable
  if ($('div').is('#export')) {
    $('#button_export').show();
    $('.button-collapse-right').sideNav({ edge: 'right' });
  }
}

$(document).ready(function () {
  // sideNav
  $('.button-collapse').sideNav();
  $('select').material_select();
  $('.collapsible').collapsible({
    accordion: false,
  });
  $('.datepicker').pickadate({
    selectMonths: true,
    selectYears: 15,
    formatSubmit: 'dd/mm/yyyy',
    hiddenName: true,
    format: 'dd/mm/yyyy',
  });
  initFilters();
  initExport();

  $('#nav-btn-add-tag').on('click', function () {
    $('.nav-panel-add-tag').toggle(100);
    $('.nav-panel-menu').addClass('hidden');
    $('#tag_label').focus();
    return false;
  });
  $('#nav-btn-add').on('click', function () {
    $('.nav-panel-buttom').hide(100);
    $('.nav-panel-add').show(100);
    $('.nav-panels .action').hide(100);
    $('.nav-panel-menu').addClass('hidden');
    $('.nav-panels').css('background', 'white');
    $('#entry_url').focus();
    return false;
  });
  $('#nav-btn-search').on('click', function () {
    $('.nav-panel-buttom').hide(100);
    $('.nav-panel-search').show(100);
    $('.nav-panels .action').hide(100);
    $('.nav-panel-menu').addClass('hidden');
    $('.nav-panels').css('background', 'white');
    $('#searchfield').focus();
    return false;
  });
  $('.close').on('click', function () {
    $('.nav-panel-add').hide(100);
    $('.nav-panel-search').hide(100);
    $('.nav-panel-buttom').show(100);
    $('.nav-panels .action').show(100);
    $('.nav-panel-menu').removeClass('hidden');
    $('.nav-panels').css('background', 'transparent');
    return false;
  });
  $(window).scroll(function () {
    var s = $(window).scrollTop();
    var d = $(document).height();
    var c = $(window).height();
    var scrollPercent = (s / (d - c)) * 100;
    $('.progress .determinate').css('width', scrollPercent + '%');
  });

/* ==========================================================================
   Annotations & Remember position
   ========================================================================== */

  if ($('article').length) {
    var app = new annotator.App();
    var x = JSON.parse($('#annotationroutes').html());


    app.include(annotator.ui.main, {
      element: document.querySelector('article'),
    });

    app.include(annotator.storage.http, x);

    app.start().then(function () {
      app.annotations.load({ entry: x.entryId });
    });

    $(window).scroll(function (e) {
      var scrollTop = $(window).scrollTop();
      var docHeight = $(document).height();
      var scrollPercent = (scrollTop) / (docHeight);
      var scrollPercentRounded = Math.round(scrollPercent * 100) / 100;
      savePercent(x.entryId, scrollPercentRounded);
    });

    retrievePercent(x.entryId);

    $(window).resize(function () {
      retrievePercent(x.entryId);
    });
  }
});