]>
git.immae.eu Git - github/wallabag/wallabag.git/blob - app/Resources/static/themes/baggy/js/init.js
2 import $ from 'jquery';
4 /* eslint-disable no-unused-vars */
5 /* jquery has default scope */
6 import cookie
from 'jquery.cookie';
7 import ui
from 'jquery-ui-browserify';
8 /* eslint-enable no-unused-vars */
11 import annotator
from 'annotator';
14 import './shortcuts/main';
15 import './shortcuts/entry';
16 import '../../_global/js/shortcuts/main';
17 import '../../_global/js/shortcuts/entry';
20 import { savePercent
, retrievePercent
} from '../../_global/js/tools';
21 import toggleSaveLinkForm
from './uiTools';
26 const $listmode
= $('#listmode');
27 const $listentries
= $('#list-entries');
29 /* ==========================================================================
31 ========================================================================== */
33 $('#menu').click(() => {
34 $('#links').toggleClass('menu--open');
35 const content
= $('#content');
36 if (content
.hasClass('opacity03')) {
37 content
.removeClass('opacity03');
41 /* ==========================================================================
42 List mode or Table Mode
43 ========================================================================== */
45 $listmode
.click(() => {
46 if ($.cookie('listmode') === 1) {
48 $.removeCookie('listmode');
50 $listentries
.removeClass('listmode');
51 $listmode
.removeClass('tablemode');
52 $listmode
.addClass('listmode');
55 $.cookie('listmode', 1, { expires: 365 });
57 $listentries
.addClass('listmode');
58 $listmode
.removeClass('listmode');
59 $listmode
.addClass('tablemode');
63 /* ==========================================================================
65 ========================================================================== */
67 if ($.cookie('listmode') === 1) {
68 $listentries
.addClass('listmode');
69 $listmode
.removeClass('listmode');
70 $listmode
.addClass('tablemode');
73 /* ==========================================================================
75 ========================================================================== */
78 $('#nav-btn-add-tag').on('click', () => {
79 $('.nav-panel-add-tag').toggle(100);
80 $('.nav-panel-menu').addClass('hidden');
81 $('#tag_label').focus();
88 // no display if filters not available
89 if ($('div').is('#filters')) {
90 $('#button_filters').show();
91 $('#clear_form_filters').on('click', () => {
92 $('#filters input').val('');
93 $('#filters :checked').removeAttr('checked');
98 /* ==========================================================================
99 Annotations & Remember position
100 ========================================================================== */
102 if ($('article').length
) {
103 const app
= new annotator
.App();
105 app
.include(annotator
.ui
.main
, {
106 element: document
.querySelector('article'),
109 const x
= JSON
.parse($('#annotationroutes').html());
110 app
.include(annotator
.storage
.http
, x
);
112 app
.start().then(() => {
113 app
.annotations
.load({ entry: x
.entryId
});
116 $(window
).scroll(() => {
117 const scrollTop
= $(window
).scrollTop();
118 const docHeight
= $(document
).height();
119 const scrollPercent
= (scrollTop
) / (docHeight
);
120 const scrollPercentRounded
= Math
.round(scrollPercent
* 100) / 100;
121 savePercent(x
.entryId
, scrollPercentRounded
);
124 retrievePercent(x
.entryId
);
126 $(window
).resize(() => {
127 retrievePercent(x
.entryId
);
132 * Close window after adding entry if popup
134 const currentUrl
= window
.location
.href
;
135 if (currentUrl
.match('&closewin=true')) {
146 $('#value').bind('keydown', (event) => {
147 if (event.keyCode === $.ui.keyCode.TAB && $(this).data('ui-autocomplete').menu.active) {
148 event.preventDefault();
151 source: function source(request, response) {
152 $.getJSON('./?view=tags', {
153 term: extractLast(request.term),
154 //id: $(':hidden#entry_id').val()
157 search: function search() {
159 const term = extractLast(this.value);
160 return term.length >= 1;
162 focus: function focus() {
163 // prevent value inserted on focus
166 select: function select(event, ui) {
167 const terms = split(this.value);
168 // remove the current input
170 // add the selected item
171 terms.push(ui.item.value);
172 // add placeholder to get the comma-and-space at the end
174 this.value = terms.join(', ');
180 //---------------------------------------------------------------------------
181 // Close the message box when the user clicks the close icon
182 //---------------------------------------------------------------------------
183 $('a.closeMessage').on('click', () => {
184 $(this).parents('div.messages').slideUp(300, () => { $(this).remove(); });
188 $('#search-form').hide();
189 $('#bagit-form').hide();
190 $('#filters').hide();
191 $('#download-form').hide();
193 //---------------------------------------------------------------------------
194 // Toggle the 'Search' popup in the sidebar
195 //---------------------------------------------------------------------------
196 function toggleSearch() {
197 $('#search-form').toggle();
198 $('#search').toggleClass('current');
199 $('#search').toggleClass('active-current');
200 $('#search-arrow').toggleClass('arrow-down');
201 if ($('#search').hasClass('current')) {
202 $('#content').addClass('opacity03');
204 $('#content').removeClass('opacity03');
208 //---------------------------------------------------------------------------
209 // Toggle the 'Filter' popup on entries list
210 //---------------------------------------------------------------------------
211 function toggleFilter() {
212 $('#filters').toggle();
215 //---------------------------------------------------------------------------
216 // Toggle the 'Download' popup on entries list
217 //---------------------------------------------------------------------------
218 function toggleDownload() {
219 $('#download-form').toggle();
222 //---------------------------------------------------------------------------
223 // Toggle the 'Save a Link' popup in the sidebar
224 //---------------------------------------------------------------------------
225 function toggleBagit() {
226 $('#bagit-form').toggle();
227 $('#bagit').toggleClass('current');
228 $('#bagit').toggleClass('active-current');
229 $('#bagit-arrow').toggleClass('arrow-down');
230 if ($('#bagit').hasClass('current')) {
231 $('#content').addClass('opacity03');
233 $('#content').removeClass('opacity03');
237 //---------------------------------------------------------------------------
238 // Close all #links popups in the sidebar
239 //---------------------------------------------------------------------------
240 function closePopups() {
241 $('#links .messages').hide();
242 $('#links > li > a').removeClass('active-current');
243 $('#links > li > a').removeClass('current');
244 $('[id$=-arrow]').removeClass('arrow-down');
245 $('#content').removeClass('opacity03');
248 $('#search').click(() => {
251 $('#searchfield').focus();
254 $('.filter-btn').click(() => {
259 $('.download-btn').click(() => {
264 $('#bagit').click(() => {
267 $('#plainurl').focus();
270 $('#search-form-close').click(() => {
274 $('#filter-form-close').click(() => {
278 $('#download-form-close').click(() => {
282 $('#bagit-form-close').click(() => {
286 const $bagitFormForm
= $('#bagit-form-form');
288 /* ==========================================================================
289 bag it link and close button
290 ========================================================================== */
292 // send 'bag it link' form request via ajax
293 $bagitFormForm
.submit((event
) => {
294 $('body').css('cursor', 'wait');
295 $('#add-link-result').empty();
298 type: $bagitFormForm
.attr('method'),
299 url: $bagitFormForm
.attr('action'),
300 data: $bagitFormForm
.serialize(),
301 success: function success() {
302 $('#add-link-result').html('Done!');
303 $('#plainurl').val('');
304 $('#plainurl').blur('');
305 $('body').css('cursor', 'auto');
307 error: function error() {
308 $('#add-link-result').html('Failed!');
309 $('body').css('cursor', 'auto');
313 event
.preventDefault();
316 /* ==========================================================================
317 Process all links inside an article
318 ========================================================================== */
320 $('article a[href^="http"]').after(
321 () => `<a href="${$(this).attr('href')}" class="add-to-wallabag-link-after" ` +
322 'alt="add to wallabag" title="add to wallabag"></a>'
325 $('.add-to-wallabag-link-after').click((event
) => {
326 toggleSaveLinkForm($(this).attr('href'), event
);
327 event
.preventDefault();