]>
git.immae.eu Git - github/wallabag/wallabag.git/blob - app/Resources/static/themes/baggy/index.js
1 import $ from 'jquery';
4 import '../_global/index';
7 import './js/shortcuts/main';
8 import './js/shortcuts/entry';
11 import toggleSaveLinkForm
from './js/uiTools';
12 import {savePercent
, retrievePercent
, throttle
} from '../_global/js/tools';
17 import './css/index.scss';
19 $(document
).ready(() => {
20 /* ==========================================================================
22 ========================================================================== */
24 $('#menu').click(() => {
25 $('#links').toggleClass('menu--open');
26 const content
= $('#content');
27 if (content
.hasClass('opacity03')) {
28 content
.removeClass('opacity03');
32 /* ==========================================================================
34 ========================================================================== */
36 $('#nav-btn-add-tag').on('click', () => {
37 $('.baggy-add-tag').toggle(100);
38 $('.nav-panel-menu').addClass('hidden');
39 $('#tag_label').focus();
46 // no display if filters not available
47 if ($('div').is('#filters')) {
48 $('#button_filters').show();
49 $('#clear_form_filters').on('click', () => {
50 $('#filters input').val('');
51 $('#filters :checked').removeAttr('checked');
56 /* ==========================================================================
57 Annotations & Remember position
58 ========================================================================== */
60 if ($('article').length
) {
61 const app
= new annotator
.App();
63 app
.include(annotator
.ui
.main
, {
64 element: document
.querySelector('article'),
67 const x
= JSON
.parse($('#annotationroutes').html());
68 app
.include(annotator
.storage
.http
, x
);
70 app
.start().then(() => {
71 app
.annotations
.load({ entry: x
.entryId
});
74 window
.addEventListener('unload', () => {
75 const scrollTop
= $(window
).scrollTop();
76 const docHeight
= $(document
).height();
77 const scrollPercent
= (scrollTop
) / (docHeight
);
78 const scrollPercentRounded
= Math
.round(scrollPercent
* 100) / 100;
79 savePercent(x
.entryId
, scrollPercentRounded
);
82 retrievePercent(x
.entryId
);
84 $(window
).resize(() => {
85 retrievePercent(x
.entryId
);
90 * Close window after adding entry if popup
92 const currentUrl
= window
.location
.href
;
93 if (currentUrl
.match('&closewin=true')) {
98 if ($('article').size() > 0) {
99 const waypoint = new Waypoint({
100 element: $('.wallabag-title').get(0),
101 handler: (direction) => {
102 console.log(direction);
103 if (direction === 'down') {
104 $('aside.tags').fadeIn('slow');
106 $('aside.tags').fadeOut('slow');
121 $('#value').bind('keydown', (event) => {
122 if (event.keyCode === $.ui.keyCode.TAB && $(this).data('ui-autocomplete').menu.active) {
123 event.preventDefault();
126 source: function source(request, response) {
127 $.getJSON('./?view=tags', {
128 term: extractLast(request.term),
129 //id: $(':hidden#entry_id').val()
132 search: function search() {
134 const term = extractLast(this.value);
135 return term.length >= 1;
137 focus: function focus() {
138 // prevent value inserted on focus
141 select: function select(event, ui) {
142 const terms = split(this.value);
143 // remove the current input
145 // add the selected item
146 terms.push(ui.item.value);
147 // add placeholder to get the comma-and-space at the end
149 this.value = terms.join(', ');
155 //---------------------------------------------------------------------------
156 // Close the message box when the user clicks the close icon
157 //---------------------------------------------------------------------------
158 $('a.closeMessage').on('click', () => {
159 $(this).parents('div.messages').slideUp(300, () => { $(this).remove(); });
163 $('#search-form').hide();
164 $('#bagit-form').hide();
165 $('#filters').hide();
166 $('#download-form').hide();
168 //---------------------------------------------------------------------------
169 // Toggle the 'Search' popup in the sidebar
170 //---------------------------------------------------------------------------
171 function toggleSearch() {
172 $('#search-form').toggle();
173 $('#search').toggleClass('current');
174 $('#search').toggleClass('active-current');
175 $('#search-arrow').toggleClass('arrow-down');
176 if ($('#search').hasClass('current')) {
177 $('#content').addClass('opacity03');
179 $('#content').removeClass('opacity03');
183 //---------------------------------------------------------------------------
184 // Toggle the 'Filter' popup on entries list
185 //---------------------------------------------------------------------------
186 function toggleFilter() {
187 $('#filters').toggle();
190 //---------------------------------------------------------------------------
191 // Toggle the 'Download' popup on entries list
192 //---------------------------------------------------------------------------
193 function toggleDownload() {
194 $('#download-form').toggle();
197 //---------------------------------------------------------------------------
198 // Toggle the 'Save a Link' popup in the sidebar
199 //---------------------------------------------------------------------------
200 function toggleBagit() {
201 $('#bagit-form').toggle();
202 $('#bagit').toggleClass('current');
203 $('#bagit').toggleClass('active-current');
204 $('#bagit-arrow').toggleClass('arrow-down');
205 if ($('#bagit').hasClass('current')) {
206 $('#content').addClass('opacity03');
208 $('#content').removeClass('opacity03');
212 //---------------------------------------------------------------------------
213 // Close all #links popups in the sidebar
214 //---------------------------------------------------------------------------
215 function closePopups() {
216 $('#links .messages').hide();
217 $('#links > li > a').removeClass('active-current');
218 $('#links > li > a').removeClass('current');
219 $('[id$=-arrow]').removeClass('arrow-down');
220 $('#content').removeClass('opacity03');
223 $('#search').click(() => {
226 $('#searchfield').focus();
229 $('.filter-btn').click(() => {
234 $('.download-btn').click(() => {
239 $('#bagit').click(() => {
242 $('#plainurl').focus();
245 $('#search-form-close').click(() => {
249 $('#filter-form-close').click(() => {
253 $('#download-form-close').click(() => {
257 $('#bagit-form-close').click(() => {
261 const bagitFormForm
= $('#bagit-form-form');
263 /* ==========================================================================
264 bag it link and close button
265 ========================================================================== */
267 // send 'bag it link' form request via ajax
268 bagitFormForm
.submit((event
) => {
269 $('body').css('cursor', 'wait');
270 $('#add-link-result').empty();
273 type: bagitFormForm
.attr('method'),
274 url: bagitFormForm
.attr('action'),
275 data: bagitFormForm
.serialize(),
276 success: function success() {
277 $('#add-link-result').html('Done!');
278 $('#plainurl').val('').blur('');
279 $('body').css('cursor', 'auto');
281 error: function error() {
282 $('#add-link-result').html('Failed!');
283 $('body').css('cursor', 'auto');
287 event
.preventDefault();
290 /* ==========================================================================
291 Process all links inside an article
292 ========================================================================== */
294 $('article a[href^="http"]').after(
295 () => `<a href="${$(this).attr('href')}" class="add-to-wallabag-link-after" title="add to wallabag"></a>`,
298 $('.add-to-wallabag-link-after').click((event
) => {
299 toggleSaveLinkForm($(this).attr('href'), event
);
300 event
.preventDefault();