diff options
Diffstat (limited to 'app/Resources/static/themes/baggy/js/init.js')
-rwxr-xr-x | app/Resources/static/themes/baggy/js/init.js | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/app/Resources/static/themes/baggy/js/init.js b/app/Resources/static/themes/baggy/js/init.js new file mode 100755 index 00000000..d7d4b166 --- /dev/null +++ b/app/Resources/static/themes/baggy/js/init.js | |||
@@ -0,0 +1,98 @@ | |||
1 | var $ = global.jquery = require('jquery'); | ||
2 | require('jquery.cookie'); | ||
3 | require('jquery-ui'); | ||
4 | var annotator = require('annotator'); | ||
5 | |||
6 | |||
7 | $.fn.ready(function () { | ||
8 | var $listmode = $('#listmode'); | ||
9 | var $listentries = $('#list-entries'); | ||
10 | |||
11 | /* ========================================================================== | ||
12 | Menu | ||
13 | ========================================================================== */ | ||
14 | |||
15 | $('#menu').click(function () { | ||
16 | $('#links').toggleClass('menu--open'); | ||
17 | if ($('#content').hasClass('opacity03')) { | ||
18 | $('#content').removeClass('opacity03'); | ||
19 | } | ||
20 | }); | ||
21 | |||
22 | /* ========================================================================== | ||
23 | List mode or Table Mode | ||
24 | ========================================================================== */ | ||
25 | |||
26 | $listmode.click(function () { | ||
27 | if (jquery.cookie('listmode') === 1) { | ||
28 | // Cookie | ||
29 | $.removeCookie('listmode'); | ||
30 | |||
31 | $listentries.removeClass('listmode'); | ||
32 | $listmode.removeClass('tablemode'); | ||
33 | $listmode.addClass('listmode'); | ||
34 | } else { | ||
35 | // Cookie | ||
36 | jquery.cookie('listmode', 1, { expires: 365 }); | ||
37 | |||
38 | $listentries.addClass('listmode'); | ||
39 | $listmode.removeClass('listmode'); | ||
40 | $listmode.addClass('tablemode'); | ||
41 | } | ||
42 | }); | ||
43 | |||
44 | /* ========================================================================== | ||
45 | Cookie listmode | ||
46 | ========================================================================== */ | ||
47 | |||
48 | if (jquery.cookie('listmode') === 1) { | ||
49 | $listentries.addClass('listmode'); | ||
50 | $listmode.removeClass('listmode'); | ||
51 | $listmode.addClass('tablemode'); | ||
52 | } | ||
53 | |||
54 | /* ========================================================================== | ||
55 | Add tag panel | ||
56 | ========================================================================== */ | ||
57 | |||
58 | |||
59 | $('#nav-btn-add-tag').on('click', function () { | ||
60 | $('.nav-panel-add-tag').toggle(100); | ||
61 | $('.nav-panel-menu').addClass('hidden'); | ||
62 | $('#tag_label').focus(); | ||
63 | return false; | ||
64 | }); | ||
65 | |||
66 | /* ========================================================================== | ||
67 | Annotations & Remember position | ||
68 | ========================================================================== */ | ||
69 | |||
70 | if ($('article').length) { | ||
71 | var app = new annotator.App(); | ||
72 | |||
73 | app.include(annotator.ui.main, { | ||
74 | element: document.querySelector('article'), | ||
75 | }); | ||
76 | |||
77 | var x = JSON.parse($('#annotationroutes').html()); | ||
78 | app.include(annotator.storage.http, x); | ||
79 | |||
80 | app.start().then(function () { | ||
81 | app.annotations.load({ entry: x.entryId }); | ||
82 | }); | ||
83 | |||
84 | $(window).scroll(function (e) { | ||
85 | var scrollTop = $(window).scrollTop(); | ||
86 | var docHeight = $(document).height(); | ||
87 | var scrollPercent = (scrollTop) / (docHeight); | ||
88 | var scrollPercentRounded = Math.round(scrollPercent * 100) / 100; | ||
89 | savePercent(x.entryId, scrollPercentRounded); | ||
90 | }); | ||
91 | |||
92 | retrievePercent(x.entryId); | ||
93 | |||
94 | $(window).resize(function () { | ||
95 | retrievePercent(x.entryId); | ||
96 | }); | ||
97 | } | ||
98 | }); | ||