]> git.immae.eu Git - github/wallabag/wallabag.git/blame - app/Resources/static/themes/baggy/js/init.js
clean & lint stuff
[github/wallabag/wallabag.git] / app / Resources / static / themes / baggy / js / init.js
CommitLineData
5ecdfcd0
TC
1var $ = global.jquery = require('jquery');
2require('jquery.cookie');
3require('jquery-ui');
4var annotator = require('annotator');
5
6
0743287f
TC
7$.fn.ready(function () {
8 var $listmode = $('#listmode');
9 var $listentries = $('#list-entries');
19f2f11e
NL
10
11 /* ==========================================================================
12 Menu
13 ========================================================================== */
14
0743287f
TC
15 $('#menu').click(function () {
16 $('#links').toggleClass('menu--open');
19f2f11e 17 if ($('#content').hasClass('opacity03')) {
0743287f 18 $('#content').removeClass('opacity03');
19f2f11e
NL
19 }
20 });
21
22 /* ==========================================================================
23 List mode or Table Mode
24 ========================================================================== */
25
0743287f
TC
26 $listmode.click(function () {
27 if (jquery.cookie('listmode') === 1) {
19f2f11e 28 // Cookie
0743287f 29 $.removeCookie('listmode');
19f2f11e 30
0743287f
TC
31 $listentries.removeClass('listmode');
32 $listmode.removeClass('tablemode');
33 $listmode.addClass('listmode');
34 } else {
19f2f11e 35 // Cookie
0743287f 36 jquery.cookie('listmode', 1, { expires: 365 });
19f2f11e 37
0743287f
TC
38 $listentries.addClass('listmode');
39 $listmode.removeClass('listmode');
40 $listmode.addClass('tablemode');
19f2f11e 41 }
19f2f11e
NL
42 });
43
44 /* ==========================================================================
45 Cookie listmode
46 ========================================================================== */
47
0743287f
TC
48 if (jquery.cookie('listmode') === 1) {
49 $listentries.addClass('listmode');
50 $listmode.removeClass('listmode');
51 $listmode.addClass('tablemode');
19f2f11e
NL
52 }
53
56349e47
TC
54 /* ==========================================================================
55 Add tag panel
56 ========================================================================== */
57
58
0743287f
TC
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 });
56349e47 65
5ecdfcd0
TC
66 /* ==========================================================================
67 Annotations & Remember position
68 ========================================================================== */
69
0743287f
TC
70 if ($('article').length) {
71 var app = new annotator.App();
5ecdfcd0 72
0743287f
TC
73 app.include(annotator.ui.main, {
74 element: document.querySelector('article'),
75 });
5ecdfcd0 76
0743287f
TC
77 var x = JSON.parse($('#annotationroutes').html());
78 app.include(annotator.storage.http, x);
5ecdfcd0 79
0743287f
TC
80 app.start().then(function () {
81 app.annotations.load({ entry: x.entryId });
82 });
5ecdfcd0 83
0743287f
TC
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 });
5ecdfcd0 91
0743287f 92 retrievePercent(x.entryId);
5ecdfcd0 93
0743287f
TC
94 $(window).resize(function () {
95 retrievePercent(x.entryId);
96 });
5ecdfcd0 97 }
19f2f11e 98});