diff options
author | Paulino Michelazzo <paulino@michelazzo.com.br> | 2016-10-18 22:48:23 +0200 |
---|---|---|
committer | Paulino Michelazzo <paulino@michelazzo.com.br> | 2016-10-18 22:48:23 +0200 |
commit | 99731f0bb1f6fd2815eeb9af504ce86df927657b (patch) | |
tree | b080efc608d2bbd52b77a4a0067402007f50c5a8 /app/Resources/static/themes/_global/js/tools.js | |
parent | 3a3c6b866b52721431bed22426d9abfcd0d2dfe0 (diff) | |
parent | 7180aaed45dce62e40620a9e4b202526ebd6a3bb (diff) | |
download | wallabag-99731f0bb1f6fd2815eeb9af504ce86df927657b.tar.gz wallabag-99731f0bb1f6fd2815eeb9af504ce86df927657b.tar.zst wallabag-99731f0bb1f6fd2815eeb9af504ce86df927657b.zip |
Merge remote-tracking branch 'wallabag/master'
Diffstat (limited to 'app/Resources/static/themes/_global/js/tools.js')
-rw-r--r-- | app/Resources/static/themes/_global/js/tools.js | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/app/Resources/static/themes/_global/js/tools.js b/app/Resources/static/themes/_global/js/tools.js new file mode 100644 index 00000000..ab30deb1 --- /dev/null +++ b/app/Resources/static/themes/_global/js/tools.js | |||
@@ -0,0 +1,50 @@ | |||
1 | const $ = require('jquery'); | ||
2 | |||
3 | function supportsLocalStorage() { | ||
4 | try { | ||
5 | return 'localStorage' in window && window.localStorage !== null; | ||
6 | } catch (e) { | ||
7 | return false; | ||
8 | } | ||
9 | } | ||
10 | |||
11 | function savePercent(id, percent) { | ||
12 | if (!supportsLocalStorage()) { return false; } | ||
13 | localStorage[`wallabag.article.${id}.percent`] = percent; | ||
14 | return true; | ||
15 | } | ||
16 | |||
17 | function retrievePercent(id) { | ||
18 | if (!supportsLocalStorage()) { return false; } | ||
19 | |||
20 | const bheight = $(document).height(); | ||
21 | const percent = localStorage[`wallabag.article.${id}.percent`]; | ||
22 | const scroll = bheight * percent; | ||
23 | |||
24 | $('html,body').animate({ scrollTop: scroll }, 'fast'); | ||
25 | |||
26 | return true; | ||
27 | } | ||
28 | |||
29 | function initFilters() { | ||
30 | // no display if filters not available | ||
31 | if ($('div').is('#filters')) { | ||
32 | $('#button_filters').show(); | ||
33 | $('.button-collapse-right').sideNav({ edge: 'right' }); | ||
34 | $('#clear_form_filters').on('click', () => { | ||
35 | $('#filters input').val(''); | ||
36 | $('#filters :checked').removeAttr('checked'); | ||
37 | return false; | ||
38 | }); | ||
39 | } | ||
40 | } | ||
41 | |||
42 | function initExport() { | ||
43 | // no display if export not available | ||
44 | if ($('div').is('#export')) { | ||
45 | $('#button_export').show(); | ||
46 | $('.button-collapse-right').sideNav({ edge: 'right' }); | ||
47 | } | ||
48 | } | ||
49 | |||
50 | export { savePercent, retrievePercent, initFilters, initExport }; | ||