]>
git.immae.eu Git - github/wallabag/wallabag.git/blob - app/Resources/static/themes/baggy/js/init.js
1 const $ = global
.jquery
= require('jquery');
2 require('jquery.cookie');
3 require('jquery-ui-browserify');
4 const annotator
= require('annotator');
5 import { savePercent
, retrievePercent
} from '../../_global/js/tools.js';
6 import { toggleSaveLinkForm
} from './uiTools.js';
10 const $listmode
= $('#listmode');
11 const $listentries
= $('#list-entries');
13 /* ==========================================================================
15 ========================================================================== */
17 $('#menu').click(() => {
18 $('#links').toggleClass('menu--open');
19 const content
= $('#content');
20 if (content
.hasClass('opacity03')) {
21 content
.removeClass('opacity03');
25 /* ==========================================================================
26 List mode or Table Mode
27 ========================================================================== */
29 $listmode
.click(() => {
30 if ($.cookie('listmode') === 1) {
32 $.removeCookie('listmode');
34 $listentries
.removeClass('listmode');
35 $listmode
.removeClass('tablemode');
36 $listmode
.addClass('listmode');
39 $.cookie('listmode', 1, { expires: 365 });
41 $listentries
.addClass('listmode');
42 $listmode
.removeClass('listmode');
43 $listmode
.addClass('tablemode');
47 /* ==========================================================================
49 ========================================================================== */
51 if ($.cookie('listmode') === 1) {
52 $listentries
.addClass('listmode');
53 $listmode
.removeClass('listmode');
54 $listmode
.addClass('tablemode');
57 /* ==========================================================================
59 ========================================================================== */
62 $('#nav-btn-add-tag').on('click', () => {
63 $('.nav-panel-add-tag').toggle(100);
64 $('.nav-panel-menu').addClass('hidden');
65 $('#tag_label').focus();
72 // no display if filters not available
73 if ($('div').is('#filters')) {
74 $('#button_filters').show();
75 $('#clear_form_filters').on('click', () => {
76 $('#filters input').val('');
77 $('#filters :checked').removeAttr('checked');
82 /* ==========================================================================
83 Annotations & Remember position
84 ========================================================================== */
86 if ($('article').length
) {
87 const app
= new annotator
.App();
89 app
.include(annotator
.ui
.main
, {
90 element: document
.querySelector('article'),
93 const x
= JSON
.parse($('#annotationroutes').html());
94 app
.include(annotator
.storage
.http
, x
);
96 app
.start().then(() => {
97 app
.annotations
.load({ entry: x
.entryId
});
100 $(window
).scroll(() => {
101 const scrollTop
= $(window
).scrollTop();
102 const docHeight
= $(document
).height();
103 const scrollPercent
= (scrollTop
) / (docHeight
);
104 const scrollPercentRounded
= Math
.round(scrollPercent
* 100) / 100;
105 savePercent(x
.entryId
, scrollPercentRounded
);
108 retrievePercent(x
.entryId
);
110 $(window
).resize(() => {
111 retrievePercent(x
.entryId
);
116 * Close window after adding entry if popup
118 const currentUrl
= window
.location
.href
;
119 if (currentUrl
.match('&closewin=true')) {
130 $('#value').bind('keydown', (event) => {
131 if (event.keyCode === $.ui.keyCode.TAB && $(this).data('ui-autocomplete').menu.active) {
132 event.preventDefault();
135 source: function source(request, response) {
136 $.getJSON('./?view=tags', {
137 term: extractLast(request.term),
138 //id: $(':hidden#entry_id').val()
141 search: function search() {
143 const term = extractLast(this.value);
144 return term.length >= 1;
146 focus: function focus() {
147 // prevent value inserted on focus
150 select: function select(event, ui) {
151 const terms = split(this.value);
152 // remove the current input
154 // add the selected item
155 terms.push(ui.item.value);
156 // add placeholder to get the comma-and-space at the end
158 this.value = terms.join(', ');
164 //---------------------------------------------------------------------------
165 // Close the message box when the user clicks the close icon
166 //---------------------------------------------------------------------------
167 $('a.closeMessage').on('click', () => {
168 $(this).parents('div.messages').slideUp(300, () => { $(this).remove(); });
172 $('#search-form').hide();
173 $('#bagit-form').hide();
174 $('#filters').hide();
175 $('#download-form').hide();
177 //---------------------------------------------------------------------------
178 // Toggle the 'Search' popup in the sidebar
179 //---------------------------------------------------------------------------
180 function toggleSearch() {
181 $('#search-form').toggle();
182 $('#search').toggleClass('current');
183 $('#search').toggleClass('active-current');
184 $('#search-arrow').toggleClass('arrow-down');
185 if ($('#search').hasClass('current')) {
186 $('#content').addClass('opacity03');
188 $('#content').removeClass('opacity03');
192 //---------------------------------------------------------------------------
193 // Toggle the 'Filter' popup on entries list
194 //---------------------------------------------------------------------------
195 function toggleFilter() {
196 $('#filters').toggle();
199 //---------------------------------------------------------------------------
200 // Toggle the 'Download' popup on entries list
201 //---------------------------------------------------------------------------
202 function toggleDownload() {
203 $('#download-form').toggle();
206 //---------------------------------------------------------------------------
207 // Toggle the 'Save a Link' popup in the sidebar
208 //---------------------------------------------------------------------------
209 function toggleBagit() {
210 $('#bagit-form').toggle();
211 $('#bagit').toggleClass('current');
212 $('#bagit').toggleClass('active-current');
213 $('#bagit-arrow').toggleClass('arrow-down');
214 if ($('#bagit').hasClass('current')) {
215 $('#content').addClass('opacity03');
217 $('#content').removeClass('opacity03');
221 //---------------------------------------------------------------------------
222 // Close all #links popups in the sidebar
223 //---------------------------------------------------------------------------
224 function closePopups() {
225 $('#links .messages').hide();
226 $('#links > li > a').removeClass('active-current');
227 $('#links > li > a').removeClass('current');
228 $('[id$=-arrow]').removeClass('arrow-down');
229 $('#content').removeClass('opacity03');
232 $('#search').click(() => {
235 $('#searchfield').focus();
238 $('.filter-btn').click(() => {
243 $('.download-btn').click(() => {
248 $('#bagit').click(() => {
251 $('#plainurl').focus();
254 $('#search-form-close').click(() => {
258 $('#filter-form-close').click(() => {
262 $('#download-form-close').click(() => {
266 $('#bagit-form-close').click(() => {
270 const $bagitFormForm
= $('#bagit-form-form');
272 /* ==========================================================================
273 bag it link and close button
274 ========================================================================== */
276 // send 'bag it link' form request via ajax
277 $bagitFormForm
.submit((event
) => {
278 $('body').css('cursor', 'wait');
279 $('#add-link-result').empty();
282 type: $bagitFormForm
.attr('method'),
283 url: $bagitFormForm
.attr('action'),
284 data: $bagitFormForm
.serialize(),
285 success: function success() {
286 $('#add-link-result').html('Done!');
287 $('#plainurl').val('');
288 $('#plainurl').blur('');
289 $('body').css('cursor', 'auto');
291 error: function error() {
292 $('#add-link-result').html('Failed!');
293 $('body').css('cursor', 'auto');
297 event
.preventDefault();
300 /* ==========================================================================
301 Process all links inside an article
302 ========================================================================== */
304 $('article a[href^="http"]').after(
305 () => `<a href="${$(this).attr('href')}" class="add-to-wallabag-link-after" ` +
306 'alt="add to wallabag" title="add to wallabag"></a>'
309 $('.add-to-wallabag-link-after').click((event
) => {
310 toggleSaveLinkForm($(this).attr('href'), event
);
311 event
.preventDefault();