]> git.immae.eu Git - github/wallabag/wallabag.git/blame - app/Resources/static/themes/baggy/index.js
Release wallabag 2.3.2
[github/wallabag/wallabag.git] / app / Resources / static / themes / baggy / index.js
CommitLineData
af61cb80
TC
1import $ from 'jquery';
2
64f81bc3
TC
3/* Global imports */
4import '../_global/index';
af61cb80 5
5637a26e 6/* Shortcuts */
64f81bc3
TC
7import './js/shortcuts/main';
8import './js/shortcuts/entry';
5637a26e
TC
9
10/* Tools */
64f81bc3 11import toggleSaveLinkForm from './js/uiTools';
5ecdfcd0 12
64f81bc3
TC
13/* Theme style */
14import './css/index.scss';
19f2f11e 15
64f81bc3 16$(document).ready(() => {
19f2f11e
NL
17 /* ==========================================================================
18 Menu
19 ========================================================================== */
20
c146f694 21 $('#menu').click(() => {
0743287f 22 $('#links').toggleClass('menu--open');
c146f694
TC
23 const content = $('#content');
24 if (content.hasClass('opacity03')) {
25 content.removeClass('opacity03');
19f2f11e
NL
26 }
27 });
28
56349e47
TC
29 /* ==========================================================================
30 Add tag panel
31 ========================================================================== */
32
c146f694 33 $('#nav-btn-add-tag').on('click', () => {
64f81bc3 34 $('.baggy-add-tag').toggle(100);
0743287f
TC
35 $('.nav-panel-menu').addClass('hidden');
36 $('#tag_label').focus();
37 return false;
38 });
56349e47 39
c146f694
TC
40 /**
41 * Filters & Export
42 */
43 // no display if filters not available
44 if ($('div').is('#filters')) {
45 $('#button_filters').show();
46 $('#clear_form_filters').on('click', () => {
47 $('#filters input').val('');
48 $('#filters :checked').removeAttr('checked');
49 return false;
50 });
51 }
52
c146f694
TC
53 /**
54 * Close window after adding entry if popup
55 */
56 const currentUrl = window.location.href;
57 if (currentUrl.match('&closewin=true')) {
58 window.close();
59 }
60
64f81bc3
TC
61 /**
62 if ($('article').size() > 0) {
63 const waypoint = new Waypoint({
64 element: $('.wallabag-title').get(0),
65 handler: (direction) => {
66 console.log(direction);
67 if (direction === 'down') {
68 $('aside.tags').fadeIn('slow');
69 } else {
70 $('aside.tags').fadeOut('slow');
71 }
72 },
73 offset: 250,
74 });
75 }
76 */
77
c146f694
TC
78 /**
79 * Tags autocomplete
80 */
8f234d01
TC
81 /**
82 * Not working on v2
83 *
84
c146f694
TC
85 $('#value').bind('keydown', (event) => {
86 if (event.keyCode === $.ui.keyCode.TAB && $(this).data('ui-autocomplete').menu.active) {
87 event.preventDefault();
88 }
89 }).autocomplete({
90 source: function source(request, response) {
91 $.getJSON('./?view=tags', {
92 term: extractLast(request.term),
93 //id: $(':hidden#entry_id').val()
94 }, response);
95 },
96 search: function search() {
97 // custom minLength
98 const term = extractLast(this.value);
99 return term.length >= 1;
100 },
101 focus: function focus() {
102 // prevent value inserted on focus
103 return false;
104 },
105 select: function select(event, ui) {
106 const terms = split(this.value);
107 // remove the current input
108 terms.pop();
109 // add the selected item
110 terms.push(ui.item.value);
111 // add placeholder to get the comma-and-space at the end
112 terms.push('');
113 this.value = terms.join(', ');
114 return false;
115 },
116 });
8f234d01 117 */
c146f694
TC
118
119 //---------------------------------------------------------------------------
120 // Close the message box when the user clicks the close icon
121 //---------------------------------------------------------------------------
122 $('a.closeMessage').on('click', () => {
123 $(this).parents('div.messages').slideUp(300, () => { $(this).remove(); });
124 return false;
125 });
126
127 $('#search-form').hide();
128 $('#bagit-form').hide();
129 $('#filters').hide();
130 $('#download-form').hide();
5ecdfcd0 131
c146f694
TC
132 //---------------------------------------------------------------------------
133 // Toggle the 'Search' popup in the sidebar
134 //---------------------------------------------------------------------------
135 function toggleSearch() {
136 $('#search-form').toggle();
137 $('#search').toggleClass('current');
138 $('#search').toggleClass('active-current');
139 $('#search-arrow').toggleClass('arrow-down');
140 if ($('#search').hasClass('current')) {
141 $('#content').addClass('opacity03');
142 } else {
143 $('#content').removeClass('opacity03');
144 }
145 }
146
147 //---------------------------------------------------------------------------
148 // Toggle the 'Filter' popup on entries list
149 //---------------------------------------------------------------------------
150 function toggleFilter() {
151 $('#filters').toggle();
152 }
153
154 //---------------------------------------------------------------------------
155 // Toggle the 'Download' popup on entries list
156 //---------------------------------------------------------------------------
157 function toggleDownload() {
158 $('#download-form').toggle();
159 }
160
161 //---------------------------------------------------------------------------
162 // Toggle the 'Save a Link' popup in the sidebar
163 //---------------------------------------------------------------------------
164 function toggleBagit() {
165 $('#bagit-form').toggle();
166 $('#bagit').toggleClass('current');
167 $('#bagit').toggleClass('active-current');
168 $('#bagit-arrow').toggleClass('arrow-down');
169 if ($('#bagit').hasClass('current')) {
170 $('#content').addClass('opacity03');
171 } else {
172 $('#content').removeClass('opacity03');
5ecdfcd0 173 }
c146f694
TC
174 }
175
176 //---------------------------------------------------------------------------
177 // Close all #links popups in the sidebar
178 //---------------------------------------------------------------------------
179 function closePopups() {
180 $('#links .messages').hide();
181 $('#links > li > a').removeClass('active-current');
182 $('#links > li > a').removeClass('current');
183 $('[id$=-arrow]').removeClass('arrow-down');
184 $('#content').removeClass('opacity03');
185 }
186
187 $('#search').click(() => {
188 closePopups();
189 toggleSearch();
190 $('#searchfield').focus();
191 });
192
193 $('.filter-btn').click(() => {
194 closePopups();
195 toggleFilter();
196 });
197
198 $('.download-btn').click(() => {
199 closePopups();
200 toggleDownload();
201 });
202
203 $('#bagit').click(() => {
204 closePopups();
205 toggleBagit();
206 $('#plainurl').focus();
207 });
208
209 $('#search-form-close').click(() => {
210 toggleSearch();
211 });
212
213 $('#filter-form-close').click(() => {
214 toggleFilter();
215 });
216
217 $('#download-form-close').click(() => {
218 toggleDownload();
219 });
220
221 $('#bagit-form-close').click(() => {
222 toggleBagit();
223 });
224
64f81bc3 225 const bagitFormForm = $('#bagit-form-form');
c146f694
TC
226
227 /* ==========================================================================
228 bag it link and close button
229 ========================================================================== */
230
231 // send 'bag it link' form request via ajax
64f81bc3 232 bagitFormForm.submit((event) => {
c146f694
TC
233 $('body').css('cursor', 'wait');
234 $('#add-link-result').empty();
235
236 $.ajax({
64f81bc3
TC
237 type: bagitFormForm.attr('method'),
238 url: bagitFormForm.attr('action'),
239 data: bagitFormForm.serialize(),
c146f694
TC
240 success: function success() {
241 $('#add-link-result').html('Done!');
64f81bc3 242 $('#plainurl').val('').blur('');
c146f694
TC
243 $('body').css('cursor', 'auto');
244 },
245 error: function error() {
246 $('#add-link-result').html('Failed!');
247 $('body').css('cursor', 'auto');
248 },
249 });
250
251 event.preventDefault();
252 });
253
254 /* ==========================================================================
255 Process all links inside an article
256 ========================================================================== */
257
258 $('article a[href^="http"]').after(
f99ebec0 259 () => `<a href="${$(this).attr('href')}" class="add-to-wallabag-link-after" title="add to wallabag"></a>`,
c146f694
TC
260 );
261
262 $('.add-to-wallabag-link-after').click((event) => {
263 toggleSaveLinkForm($(this).attr('href'), event);
264 event.preventDefault();
265 });
19f2f11e 266});