]> git.immae.eu Git - github/wallabag/wallabag.git/blame - app/Resources/static/themes/baggy/js/init.js
manage assets through npm
[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
19f2f11e
NL
7$.fn.ready(function() {
8
9 var $listmode = $('#listmode'),
10 $listentries = $("#list-entries");
11
12 /* ==========================================================================
13 Menu
14 ========================================================================== */
15
16 $("#menu").click(function(){
17 $("#links").toggleClass('menu--open');
18 if ($('#content').hasClass('opacity03')) {
19 $('#content').removeClass('opacity03');
20 }
21 });
22
23 /* ==========================================================================
24 List mode or Table Mode
25 ========================================================================== */
26
27 $listmode.click(function(){
5ecdfcd0 28 if ( jquery.cookie("listmode") == 1 ) {
19f2f11e
NL
29 // Cookie
30 $.removeCookie("listmode");
31
32 $listentries.removeClass("listmode");
33 $listmode.removeClass("tablemode");
34 $listmode.addClass("listmode");
35 }
36 else {
37 // Cookie
5ecdfcd0 38 jquery.cookie("listmode", 1, {expires: 365});
19f2f11e
NL
39
40 $listentries.addClass("listmode");
41 $listmode.removeClass("listmode");
42 $listmode.addClass("tablemode");
43 }
44
45 });
46
47 /* ==========================================================================
48 Cookie listmode
49 ========================================================================== */
50
5ecdfcd0 51 if ( jquery.cookie("listmode") == 1 ) {
19f2f11e
NL
52 $listentries.addClass("listmode");
53 $listmode.removeClass("listmode");
54 $listmode.addClass("tablemode");
55 }
56
56349e47
TC
57 /* ==========================================================================
58 Add tag panel
59 ========================================================================== */
60
61
62 $('#nav-btn-add-tag').on('click', function(){
63 $(".nav-panel-add-tag").toggle(100);
64 $(".nav-panel-menu").addClass('hidden');
65 $("#tag_label").focus();
66 return false;
67 });
68
5ecdfcd0
TC
69 /* ==========================================================================
70 Annotations & Remember position
71 ========================================================================== */
72
73 if ($("article").length) {
74 var app = new annotator.App();
75
76 app.include(annotator.ui.main, {
77 element: document.querySelector('article')
78 });
79
80 var x = JSON.parse($('#annotationroutes').html());
81 app.include(annotator.storage.http, x);
82
83 app.start().then(function () {
84 app.annotations.load({entry: x.entryId});
85 });
86
87 $(window).scroll(function(e){
88 var scrollTop = $(window).scrollTop();
89 var docHeight = $(document).height();
90 var scrollPercent = (scrollTop) / (docHeight);
91 var scrollPercentRounded = Math.round(scrollPercent*100)/100;
92 savePercent(x.entryId, scrollPercentRounded);
93 });
94
95 retrievePercent(x.entryId);
96
97 $(window).resize(function(){
98 retrievePercent(x.entryId);
99 });
100 }
19f2f11e 101});