diff options
Diffstat (limited to 'app/Resources/static/themes/baggy/index.js')
-rwxr-xr-x | app/Resources/static/themes/baggy/index.js | 267 |
1 files changed, 267 insertions, 0 deletions
diff --git a/app/Resources/static/themes/baggy/index.js b/app/Resources/static/themes/baggy/index.js new file mode 100755 index 00000000..5d448018 --- /dev/null +++ b/app/Resources/static/themes/baggy/index.js | |||
@@ -0,0 +1,267 @@ | |||
1 | import $ from 'jquery'; | ||
2 | |||
3 | /* Global imports */ | ||
4 | import '../_global/index'; | ||
5 | |||
6 | /* Shortcuts */ | ||
7 | import './js/shortcuts/main'; | ||
8 | import './js/shortcuts/entry'; | ||
9 | |||
10 | /* Tools */ | ||
11 | import toggleSaveLinkForm from './js/uiTools'; | ||
12 | |||
13 | /* Theme style */ | ||
14 | import './css/index.scss'; | ||
15 | |||
16 | $(document).ready(() => { | ||
17 | /* ========================================================================== | ||
18 | Menu | ||
19 | ========================================================================== */ | ||
20 | |||
21 | $('#menu').click(() => { | ||
22 | $('#links').toggleClass('menu--open'); | ||
23 | const content = $('#content'); | ||
24 | if (content.hasClass('opacity03')) { | ||
25 | content.removeClass('opacity03'); | ||
26 | } | ||
27 | }); | ||
28 | |||
29 | /* ========================================================================== | ||
30 | Add tag panel | ||
31 | ========================================================================== */ | ||
32 | |||
33 | $('#nav-btn-add-tag').on('click', () => { | ||
34 | $('.baggy-add-tag').toggle(100); | ||
35 | $('.nav-panel-menu').addClass('hidden'); | ||
36 | $('#tag_label').focus(); | ||
37 | return false; | ||
38 | }); | ||
39 | |||
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 | |||
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 | |||
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 | |||
78 | /** | ||
79 | * Tags autocomplete | ||
80 | */ | ||
81 | /** | ||
82 | * Not working on v2 | ||
83 | * | ||
84 | |||
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 | }); | ||
117 | */ | ||
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(); | ||
131 | |||
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'); | ||
173 | } | ||
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 | |||
225 | const bagitFormForm = $('#bagit-form-form'); | ||
226 | |||
227 | /* ========================================================================== | ||
228 | bag it link and close button | ||
229 | ========================================================================== */ | ||
230 | |||
231 | // send 'bag it link' form request via ajax | ||
232 | bagitFormForm.submit((event) => { | ||
233 | $('body').css('cursor', 'wait'); | ||
234 | $('#add-link-result').empty(); | ||
235 | |||
236 | $.ajax({ | ||
237 | type: bagitFormForm.attr('method'), | ||
238 | url: bagitFormForm.attr('action'), | ||
239 | data: bagitFormForm.serialize(), | ||
240 | success: function success() { | ||
241 | $('#add-link-result').html('Done!'); | ||
242 | $('#plainurl').val('').blur(''); | ||
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( | ||
259 | () => `<a href="${$(this).attr('href')}" class="add-to-wallabag-link-after" ` + | ||
260 | 'title="add to wallabag"></a>', | ||
261 | ); | ||
262 | |||
263 | $('.add-to-wallabag-link-after').click((event) => { | ||
264 | toggleSaveLinkForm($(this).attr('href'), event); | ||
265 | event.preventDefault(); | ||
266 | }); | ||
267 | }); | ||