diff options
Diffstat (limited to 'app/Resources/static/themes/baggy/js')
-rw-r--r-- | app/Resources/static/themes/baggy/js/autoClose.js | 8 | ||||
-rwxr-xr-x | app/Resources/static/themes/baggy/js/autoCompleteTags.js | 46 | ||||
-rw-r--r-- | app/Resources/static/themes/baggy/js/closeMessage.js | 19 | ||||
-rwxr-xr-x | app/Resources/static/themes/baggy/js/init.js | 98 | ||||
-rw-r--r-- | app/Resources/static/themes/baggy/js/popupForm.js | 101 | ||||
-rwxr-xr-x | app/Resources/static/themes/baggy/js/saveLink.js | 75 |
6 files changed, 347 insertions, 0 deletions
diff --git a/app/Resources/static/themes/baggy/js/autoClose.js b/app/Resources/static/themes/baggy/js/autoClose.js new file mode 100644 index 00000000..b0dafab2 --- /dev/null +++ b/app/Resources/static/themes/baggy/js/autoClose.js | |||
@@ -0,0 +1,8 @@ | |||
1 | var $ = global.jquery = require('jquery'); | ||
2 | |||
3 | $(document).ready(function () { | ||
4 | var currentUrl = window.location.href; | ||
5 | if (currentUrl.match('&closewin=true')) { | ||
6 | window.close(); | ||
7 | } | ||
8 | }); | ||
diff --git a/app/Resources/static/themes/baggy/js/autoCompleteTags.js b/app/Resources/static/themes/baggy/js/autoCompleteTags.js new file mode 100755 index 00000000..edd0a421 --- /dev/null +++ b/app/Resources/static/themes/baggy/js/autoCompleteTags.js | |||
@@ -0,0 +1,46 @@ | |||
1 | var $ = global.jquery = require('jquery'); | ||
2 | |||
3 | jQuery(function ($) { | ||
4 | function split(val) { | ||
5 | return val.split(/,\s*/); | ||
6 | } | ||
7 | function extractLast(term) { | ||
8 | return split(term).pop(); | ||
9 | } | ||
10 | |||
11 | |||
12 | $('#value').bind('keydown', function (event) { | ||
13 | if (event.keyCode === $.ui.keyCode.TAB && $(this).data('ui-autocomplete').menu.active) { | ||
14 | event.preventDefault(); | ||
15 | } | ||
16 | }).autocomplete({ | ||
17 | source: function (request, response) { | ||
18 | $.getJSON('./?view=tags', { | ||
19 | term: extractLast(request.term), | ||
20 | //id: $(':hidden#entry_id').val() | ||
21 | }, response); | ||
22 | }, | ||
23 | search: function () { | ||
24 | // custom minLength | ||
25 | var term = extractLast(this.value); | ||
26 | if (term.length < 1) { | ||
27 | return false; | ||
28 | } | ||
29 | }, | ||
30 | focus: function () { | ||
31 | // prevent value inserted on focus | ||
32 | return false; | ||
33 | }, | ||
34 | select: function (event, ui) { | ||
35 | var terms = split(this.value); | ||
36 | // remove the current input | ||
37 | terms.pop(); | ||
38 | // add the selected item | ||
39 | terms.push(ui.item.value); | ||
40 | // add placeholder to get the comma-and-space at the end | ||
41 | terms.push(''); | ||
42 | this.value = terms.join(', '); | ||
43 | return false; | ||
44 | }, | ||
45 | }); | ||
46 | }); | ||
diff --git a/app/Resources/static/themes/baggy/js/closeMessage.js b/app/Resources/static/themes/baggy/js/closeMessage.js new file mode 100644 index 00000000..ae4b1791 --- /dev/null +++ b/app/Resources/static/themes/baggy/js/closeMessage.js | |||
@@ -0,0 +1,19 @@ | |||
1 | var $ = global.jquery = require('jquery'); | ||
2 | |||
3 | $(function () { | ||
4 | //--------------------------------------------------------------------------- | ||
5 | // Show the close icon when the user hover over a message | ||
6 | //--------------------------------------------------------------------------- | ||
7 | // $('.messages').on('mouseenter', function(){ | ||
8 | // $(this).find('a.closeMessage').stop(true, true).show(); | ||
9 | // }).on('mouseleave', function(){ | ||
10 | // $(this).find('a.closeMessage').stop(true, true).hide(); | ||
11 | // }); | ||
12 | //--------------------------------------------------------------------------- | ||
13 | // Close the message box when the user clicks the close icon | ||
14 | //--------------------------------------------------------------------------- | ||
15 | $('a.closeMessage').on('click', function () { | ||
16 | $(this).parents('div.messages').slideUp(300, function () { $(this).remove(); }); | ||
17 | return false; | ||
18 | }); | ||
19 | }); | ||
diff --git a/app/Resources/static/themes/baggy/js/init.js b/app/Resources/static/themes/baggy/js/init.js new file mode 100755 index 00000000..d7d4b166 --- /dev/null +++ b/app/Resources/static/themes/baggy/js/init.js | |||
@@ -0,0 +1,98 @@ | |||
1 | var $ = global.jquery = require('jquery'); | ||
2 | require('jquery.cookie'); | ||
3 | require('jquery-ui'); | ||
4 | var annotator = require('annotator'); | ||
5 | |||
6 | |||
7 | $.fn.ready(function () { | ||
8 | var $listmode = $('#listmode'); | ||
9 | var $listentries = $('#list-entries'); | ||
10 | |||
11 | /* ========================================================================== | ||
12 | Menu | ||
13 | ========================================================================== */ | ||
14 | |||
15 | $('#menu').click(function () { | ||
16 | $('#links').toggleClass('menu--open'); | ||
17 | if ($('#content').hasClass('opacity03')) { | ||
18 | $('#content').removeClass('opacity03'); | ||
19 | } | ||
20 | }); | ||
21 | |||
22 | /* ========================================================================== | ||
23 | List mode or Table Mode | ||
24 | ========================================================================== */ | ||
25 | |||
26 | $listmode.click(function () { | ||
27 | if (jquery.cookie('listmode') === 1) { | ||
28 | // Cookie | ||
29 | $.removeCookie('listmode'); | ||
30 | |||
31 | $listentries.removeClass('listmode'); | ||
32 | $listmode.removeClass('tablemode'); | ||
33 | $listmode.addClass('listmode'); | ||
34 | } else { | ||
35 | // Cookie | ||
36 | jquery.cookie('listmode', 1, { expires: 365 }); | ||
37 | |||
38 | $listentries.addClass('listmode'); | ||
39 | $listmode.removeClass('listmode'); | ||
40 | $listmode.addClass('tablemode'); | ||
41 | } | ||
42 | }); | ||
43 | |||
44 | /* ========================================================================== | ||
45 | Cookie listmode | ||
46 | ========================================================================== */ | ||
47 | |||
48 | if (jquery.cookie('listmode') === 1) { | ||
49 | $listentries.addClass('listmode'); | ||
50 | $listmode.removeClass('listmode'); | ||
51 | $listmode.addClass('tablemode'); | ||
52 | } | ||
53 | |||
54 | /* ========================================================================== | ||
55 | Add tag panel | ||
56 | ========================================================================== */ | ||
57 | |||
58 | |||
59 | $('#nav-btn-add-tag').on('click', function () { | ||
60 | $('.nav-panel-add-tag').toggle(100); | ||
61 | $('.nav-panel-menu').addClass('hidden'); | ||
62 | $('#tag_label').focus(); | ||
63 | return false; | ||
64 | }); | ||
65 | |||
66 | /* ========================================================================== | ||
67 | Annotations & Remember position | ||
68 | ========================================================================== */ | ||
69 | |||
70 | if ($('article').length) { | ||
71 | var app = new annotator.App(); | ||
72 | |||
73 | app.include(annotator.ui.main, { | ||
74 | element: document.querySelector('article'), | ||
75 | }); | ||
76 | |||
77 | var x = JSON.parse($('#annotationroutes').html()); | ||
78 | app.include(annotator.storage.http, x); | ||
79 | |||
80 | app.start().then(function () { | ||
81 | app.annotations.load({ entry: x.entryId }); | ||
82 | }); | ||
83 | |||
84 | $(window).scroll(function (e) { | ||
85 | var scrollTop = $(window).scrollTop(); | ||
86 | var docHeight = $(document).height(); | ||
87 | var scrollPercent = (scrollTop) / (docHeight); | ||
88 | var scrollPercentRounded = Math.round(scrollPercent * 100) / 100; | ||
89 | savePercent(x.entryId, scrollPercentRounded); | ||
90 | }); | ||
91 | |||
92 | retrievePercent(x.entryId); | ||
93 | |||
94 | $(window).resize(function () { | ||
95 | retrievePercent(x.entryId); | ||
96 | }); | ||
97 | } | ||
98 | }); | ||
diff --git a/app/Resources/static/themes/baggy/js/popupForm.js b/app/Resources/static/themes/baggy/js/popupForm.js new file mode 100644 index 00000000..95ba60ee --- /dev/null +++ b/app/Resources/static/themes/baggy/js/popupForm.js | |||
@@ -0,0 +1,101 @@ | |||
1 | var $ = global.jquery = require('jquery'); | ||
2 | |||
3 | $(document).ready(function () { | ||
4 | $('#search-form').hide(); | ||
5 | $('#bagit-form').hide(); | ||
6 | $('#filter-form').hide(); | ||
7 | $('#download-form').hide(); | ||
8 | |||
9 | //--------------------------------------------------------------------------- | ||
10 | // Toggle the 'Search' popup in the sidebar | ||
11 | //--------------------------------------------------------------------------- | ||
12 | function toggleSearch() { | ||
13 | $('#search-form').toggle(); | ||
14 | $('#search').toggleClass('current'); | ||
15 | $('#search').toggleClass('active-current'); | ||
16 | $('#search-arrow').toggleClass('arrow-down'); | ||
17 | if ($('#search').hasClass('current')) { | ||
18 | $('#content').addClass('opacity03'); | ||
19 | } else { | ||
20 | $('#content').removeClass('opacity03'); | ||
21 | } | ||
22 | } | ||
23 | |||
24 | //--------------------------------------------------------------------------- | ||
25 | // Toggle the 'Filter' popup on entries list | ||
26 | //--------------------------------------------------------------------------- | ||
27 | function toggleFilter() { | ||
28 | $('#filter-form').toggle(); | ||
29 | } | ||
30 | |||
31 | //--------------------------------------------------------------------------- | ||
32 | // Toggle the 'Download' popup on entries list | ||
33 | //--------------------------------------------------------------------------- | ||
34 | function toggleDownload() { | ||
35 | $('#download-form').toggle(); | ||
36 | } | ||
37 | |||
38 | //--------------------------------------------------------------------------- | ||
39 | // Toggle the 'Save a Link' popup in the sidebar | ||
40 | //--------------------------------------------------------------------------- | ||
41 | function toggleBagit() { | ||
42 | $('#bagit-form').toggle(); | ||
43 | $('#bagit').toggleClass('current'); | ||
44 | $('#bagit').toggleClass('active-current'); | ||
45 | $('#bagit-arrow').toggleClass('arrow-down'); | ||
46 | if ($('#bagit').hasClass('current')) { | ||
47 | $('#content').addClass('opacity03'); | ||
48 | } else { | ||
49 | $('#content').removeClass('opacity03'); | ||
50 | } | ||
51 | } | ||
52 | |||
53 | //--------------------------------------------------------------------------- | ||
54 | // Close all #links popups in the sidebar | ||
55 | //--------------------------------------------------------------------------- | ||
56 | function closePopups() { | ||
57 | $('#links .messages').hide(); | ||
58 | $('#links > li > a').removeClass('active-current'); | ||
59 | $('#links > li > a').removeClass('current'); | ||
60 | $('[id$=-arrow]').removeClass('arrow-down'); | ||
61 | $('#content').removeClass('opacity03'); | ||
62 | } | ||
63 | |||
64 | $('#search').click(function () { | ||
65 | closePopups(); | ||
66 | toggleSearch(); | ||
67 | $('#searchfield').focus(); | ||
68 | }); | ||
69 | |||
70 | $('.filter-btn').click(function () { | ||
71 | closePopups(); | ||
72 | toggleFilter(); | ||
73 | }); | ||
74 | |||
75 | $('.download-btn').click(function () { | ||
76 | closePopups(); | ||
77 | toggleDownload(); | ||
78 | }); | ||
79 | |||
80 | $('#bagit').click(function () { | ||
81 | closePopups(); | ||
82 | toggleBagit(); | ||
83 | $('#plainurl').focus(); | ||
84 | }); | ||
85 | |||
86 | $('#search-form-close').click(function () { | ||
87 | toggleSearch(); | ||
88 | }); | ||
89 | |||
90 | $('#filter-form-close').click(function () { | ||
91 | toggleFilter(); | ||
92 | }); | ||
93 | |||
94 | $('#download-form-close').click(function () { | ||
95 | toggleDownload(); | ||
96 | }); | ||
97 | |||
98 | $('#bagit-form-close').click(function () { | ||
99 | toggleBagit(); | ||
100 | }); | ||
101 | }); | ||
diff --git a/app/Resources/static/themes/baggy/js/saveLink.js b/app/Resources/static/themes/baggy/js/saveLink.js new file mode 100755 index 00000000..5c720886 --- /dev/null +++ b/app/Resources/static/themes/baggy/js/saveLink.js | |||
@@ -0,0 +1,75 @@ | |||
1 | var $ = global.jquery = require('jquery'); | ||
2 | |||
3 | $.fn.ready(function () { | ||
4 | var $bagit = $('#bagit'); | ||
5 | var $bagitForm = $('#bagit-form'); | ||
6 | var $bagitFormForm = $('#bagit-form-form'); | ||
7 | |||
8 | /* ========================================================================== | ||
9 | bag it link and close button | ||
10 | ========================================================================== */ | ||
11 | |||
12 | function toggleSaveLinkForm(url, event) { | ||
13 | $('#add-link-result').empty(); | ||
14 | |||
15 | $bagit.toggleClass('active-current'); | ||
16 | |||
17 | // only if bag-it link is not presented on page | ||
18 | if ($bagit.length === 0) { | ||
19 | if (event !== 'undefined' && event) { | ||
20 | $bagitForm.css({ position: 'absolute', top: event.pageY, left: event.pageX - 200 }); | ||
21 | } else { | ||
22 | $bagitForm.css({ position: 'relative', top: 'auto', left: 'auto' }); | ||
23 | } | ||
24 | } | ||
25 | |||
26 | if ($('#search-form').length !== 0) { | ||
27 | $('#search').removeClass('current'); | ||
28 | $('#search-arrow').removeClass('arrow-down'); | ||
29 | $('#search-form').hide(); | ||
30 | } | ||
31 | $bagitForm.toggle(); | ||
32 | $('#content').toggleClass('opacity03'); | ||
33 | if (url !== 'undefined' && url) { | ||
34 | $('#plainurl').val(url); | ||
35 | } | ||
36 | $('#plainurl').focus(); | ||
37 | } | ||
38 | |||
39 | // send 'bag it link' form request via ajax | ||
40 | $bagitFormForm.submit(function (event) { | ||
41 | $('body').css('cursor', 'wait'); | ||
42 | $('#add-link-result').empty(); | ||
43 | |||
44 | $.ajax({ | ||
45 | type: $bagitFormForm.attr('method'), | ||
46 | url: $bagitFormForm.attr('action'), | ||
47 | data: $bagitFormForm.serialize(), | ||
48 | success: function (data) { | ||
49 | $('#add-link-result').html('Done!'); | ||
50 | $('#plainurl').val(''); | ||
51 | $('#plainurl').blur(''); | ||
52 | $('body').css('cursor', 'auto'); | ||
53 | }, | ||
54 | error: function (data) { | ||
55 | $('#add-link-result').html('Failed!'); | ||
56 | $('body').css('cursor', 'auto'); | ||
57 | }, | ||
58 | }); | ||
59 | |||
60 | event.preventDefault(); | ||
61 | }); | ||
62 | |||
63 | /* ========================================================================== | ||
64 | Process all links inside an article | ||
65 | ========================================================================== */ | ||
66 | |||
67 | $('article a[href^="http"]').after(function () { | ||
68 | return ' <a href="' + $(this).attr('href') + '" class="add-to-wallabag-link-after" alt="add to wallabag" title="add to wallabag"></a> '; | ||
69 | }); | ||
70 | |||
71 | $('.add-to-wallabag-link-after').click(function (event) { | ||
72 | toggleSaveLinkForm($(this).attr('href'), event); | ||
73 | event.preventDefault(); | ||
74 | }); | ||
75 | }); | ||