diff options
author | Nicolas LÅ“uillet <nicolas@loeuillet.org> | 2015-09-13 21:07:27 +0200 |
---|---|---|
committer | Nicolas LÅ“uillet <nicolas@loeuillet.org> | 2015-09-13 21:07:27 +0200 |
commit | b004a236ba0cc96bf530801a55cdddf9ec809d13 (patch) | |
tree | 9cd57b48d5a4c5ec7952ba02736c8209f1c95c69 /src/Wallabag/CoreBundle/Resources/views/themes/baggy/public/js | |
parent | 4d5fd9be812825c480589cdcfcec281ffb5aa66a (diff) | |
parent | 1a5f7e2d88284419654057fda71e2b0be9b5439a (diff) | |
download | wallabag-b004a236ba0cc96bf530801a55cdddf9ec809d13.tar.gz wallabag-b004a236ba0cc96bf530801a55cdddf9ec809d13.tar.zst wallabag-b004a236ba0cc96bf530801a55cdddf9ec809d13.zip |
Merge pull request #1401 from wallabag/v2-baggy-themes
Cleanup baggy
Diffstat (limited to 'src/Wallabag/CoreBundle/Resources/views/themes/baggy/public/js')
5 files changed, 262 insertions, 0 deletions
diff --git a/src/Wallabag/CoreBundle/Resources/views/themes/baggy/public/js/autoClose.js b/src/Wallabag/CoreBundle/Resources/views/themes/baggy/public/js/autoClose.js new file mode 100644 index 00000000..e9145b7e --- /dev/null +++ b/src/Wallabag/CoreBundle/Resources/views/themes/baggy/public/js/autoClose.js | |||
@@ -0,0 +1,6 @@ | |||
1 | $(document).ready(function() { | ||
2 | current_url = window.location.href | ||
3 | if (current_url.match("&closewin=true")) { | ||
4 | window.close(); | ||
5 | } | ||
6 | }); | ||
diff --git a/src/Wallabag/CoreBundle/Resources/views/themes/baggy/public/js/autoCompleteTags.js b/src/Wallabag/CoreBundle/Resources/views/themes/baggy/public/js/autoCompleteTags.js new file mode 100755 index 00000000..90bc982c --- /dev/null +++ b/src/Wallabag/CoreBundle/Resources/views/themes/baggy/public/js/autoCompleteTags.js | |||
@@ -0,0 +1,47 @@ | |||
1 | jQuery(function($) { | ||
2 | |||
3 | function split( val ) { | ||
4 | return val.split( /,\s*/ ); | ||
5 | } | ||
6 | function extractLast( term ) { | ||
7 | return split( term ).pop(); | ||
8 | } | ||
9 | |||
10 | |||
11 | $("#value").bind("keydown", function(event) { | ||
12 | if (event.keyCode === $.ui.keyCode.TAB && $(this).data("ui-autocomplete").menu.active) { | ||
13 | event.preventDefault(); | ||
14 | } | ||
15 | }).autocomplete({ | ||
16 | source : function(request, response) { | ||
17 | $.getJSON("./?view=tags", { | ||
18 | term : extractLast(request.term), | ||
19 | //id: $(':hidden#entry_id').val() | ||
20 | }, response); | ||
21 | }, | ||
22 | search : function() { | ||
23 | // custom minLength | ||
24 | var term = extractLast(this.value); | ||
25 | if (term.length < 1) { | ||
26 | return false; | ||
27 | } | ||
28 | }, | ||
29 | focus : function() { | ||
30 | // prevent value inserted on focus | ||
31 | return false; | ||
32 | }, | ||
33 | select : function(event, ui) { | ||
34 | var terms = split(this.value); | ||
35 | // remove the current input | ||
36 | terms.pop(); | ||
37 | // add the selected item | ||
38 | terms.push(ui.item.value); | ||
39 | // add placeholder to get the comma-and-space at the end | ||
40 | terms.push(""); | ||
41 | this.value = terms.join(", "); | ||
42 | return false; | ||
43 | } | ||
44 | }); | ||
45 | |||
46 | |||
47 | }); | ||
diff --git a/src/Wallabag/CoreBundle/Resources/views/themes/baggy/public/js/closeMessage.js b/src/Wallabag/CoreBundle/Resources/views/themes/baggy/public/js/closeMessage.js new file mode 100644 index 00000000..527719d5 --- /dev/null +++ b/src/Wallabag/CoreBundle/Resources/views/themes/baggy/public/js/closeMessage.js | |||
@@ -0,0 +1,17 @@ | |||
1 | $(function(){ | ||
2 | //--------------------------------------------------------------------------- | ||
3 | // Show the close icon when the user hover over a message | ||
4 | //--------------------------------------------------------------------------- | ||
5 | // $('.messages').on('mouseenter', function(){ | ||
6 | // $(this).find('a.closeMessage').stop(true, true).show(); | ||
7 | // }).on('mouseleave', function(){ | ||
8 | // $(this).find('a.closeMessage').stop(true, true).hide(); | ||
9 | // }); | ||
10 | //--------------------------------------------------------------------------- | ||
11 | // Close the message box when the user clicks the close icon | ||
12 | //--------------------------------------------------------------------------- | ||
13 | $('a.closeMessage').on('click', function(){ | ||
14 | $(this).parents('div.messages').slideUp(300, function(){ $(this).remove(); }); | ||
15 | return false; | ||
16 | }); | ||
17 | }); \ No newline at end of file | ||
diff --git a/src/Wallabag/CoreBundle/Resources/views/themes/baggy/public/js/popupForm.js b/src/Wallabag/CoreBundle/Resources/views/themes/baggy/public/js/popupForm.js new file mode 100644 index 00000000..b933acd1 --- /dev/null +++ b/src/Wallabag/CoreBundle/Resources/views/themes/baggy/public/js/popupForm.js | |||
@@ -0,0 +1,83 @@ | |||
1 | $(document).ready(function() { | ||
2 | |||
3 | $("#search-form").hide(); | ||
4 | $("#bagit-form").hide(); | ||
5 | $("#filter-form").hide(); | ||
6 | |||
7 | //--------------------------------------------------------------------------- | ||
8 | // Toggle the "Search" popup in the sidebar | ||
9 | //--------------------------------------------------------------------------- | ||
10 | function toggleSearch() { | ||
11 | $("#search-form").toggle(); | ||
12 | $("#search").toggleClass("current"); | ||
13 | $("#search").toggleClass("active-current"); | ||
14 | $("#search-arrow").toggleClass("arrow-down"); | ||
15 | if ($("#search").hasClass("current")) { | ||
16 | $("#content").addClass("opacity03"); | ||
17 | } else { | ||
18 | $("#content").removeClass("opacity03"); | ||
19 | } | ||
20 | } | ||
21 | |||
22 | //--------------------------------------------------------------------------- | ||
23 | // Toggle the "Filter" popup on entries list | ||
24 | //--------------------------------------------------------------------------- | ||
25 | function toggleFilter() { | ||
26 | $("#filter-form").toggle(); | ||
27 | } | ||
28 | |||
29 | //--------------------------------------------------------------------------- | ||
30 | // Toggle the "Save a Link" popup in the sidebar | ||
31 | //--------------------------------------------------------------------------- | ||
32 | function toggleBagit() { | ||
33 | $("#bagit-form").toggle(); | ||
34 | $("#bagit").toggleClass("current"); | ||
35 | $("#bagit").toggleClass("active-current"); | ||
36 | $("#bagit-arrow").toggleClass("arrow-down"); | ||
37 | if ($("#bagit").hasClass("current")) { | ||
38 | $("#content").addClass("opacity03"); | ||
39 | } else { | ||
40 | $("#content").removeClass("opacity03"); | ||
41 | } | ||
42 | } | ||
43 | |||
44 | //--------------------------------------------------------------------------- | ||
45 | // Close all #links popups in the sidebar | ||
46 | //--------------------------------------------------------------------------- | ||
47 | function closePopups() { | ||
48 | $("#links .messages").hide(); | ||
49 | $("#links > li > a").removeClass("active-current"); | ||
50 | $("#links > li > a").removeClass("current"); | ||
51 | $("[id$=-arrow]").removeClass("arrow-down"); | ||
52 | $("#content").removeClass("opacity03"); | ||
53 | } | ||
54 | |||
55 | $("#search").click(function(){ | ||
56 | closePopups(); | ||
57 | toggleSearch(); | ||
58 | $("#searchfield").focus(); | ||
59 | }); | ||
60 | |||
61 | $("#filter").click(function(){ | ||
62 | closePopups(); | ||
63 | toggleFilter(); | ||
64 | }); | ||
65 | |||
66 | $("#bagit").click(function(){ | ||
67 | closePopups(); | ||
68 | toggleBagit(); | ||
69 | $("#plainurl").focus(); | ||
70 | }); | ||
71 | |||
72 | $("#search-form-close").click(function(){ | ||
73 | toggleSearch(); | ||
74 | }); | ||
75 | |||
76 | $("#filter-form-close").click(function(){ | ||
77 | toggleFilter(); | ||
78 | }); | ||
79 | |||
80 | $("#bagit-form-close").click(function(){ | ||
81 | toggleBagit(); | ||
82 | }); | ||
83 | }); | ||
diff --git a/src/Wallabag/CoreBundle/Resources/views/themes/baggy/public/js/saveLink.js b/src/Wallabag/CoreBundle/Resources/views/themes/baggy/public/js/saveLink.js new file mode 100755 index 00000000..a7acd84c --- /dev/null +++ b/src/Wallabag/CoreBundle/Resources/views/themes/baggy/public/js/saveLink.js | |||
@@ -0,0 +1,109 @@ | |||
1 | $.fn.ready(function() { | ||
2 | |||
3 | var $bagit = $('#bagit'), | ||
4 | $bagitForm = $('#bagit-form'), | ||
5 | $bagitFormForm = $('#bagit-form-form'); | ||
6 | |||
7 | /* ========================================================================== | ||
8 | bag it link and close button | ||
9 | ========================================================================== */ | ||
10 | |||
11 | function toggleSaveLinkForm(url, event) { | ||
12 | $("#add-link-result").empty(); | ||
13 | |||
14 | $bagit.toggleClass("active-current"); | ||
15 | |||
16 | //only if bag-it link is not presented on page | ||
17 | if ( $bagit.length === 0 ) { | ||
18 | if ( event !== 'undefined' && event ) { | ||
19 | $bagitForm.css( {position:"absolute", top:event.pageY, left:event.pageX-200}); | ||
20 | } | ||
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 | //--------------------------------------------------------------------------- | ||
40 | // These two functions are now taken care of in popupForm.js | ||
41 | //--------------------------------------------------------------------------- | ||
42 | |||
43 | // $bagit.click(function(){ | ||
44 | // $bagit.toggleClass("current"); | ||
45 | // $("#bagit-arrow").toggleClass("arrow-down"); | ||
46 | // toggleSaveLinkForm(); | ||
47 | // }); | ||
48 | |||
49 | // $("#bagit-form-close").click(function(){ | ||
50 | // $bagit.removeClass("current"); | ||
51 | // $("#bagit-arrow").removeClass("arrow-down"); | ||
52 | // toggleSaveLinkForm(); | ||
53 | // }); | ||
54 | |||
55 | |||
56 | //send "bag it link" form request via ajax | ||
57 | $bagitFormForm.submit( function(event) { | ||
58 | $("body").css("cursor", "wait"); | ||
59 | $("#add-link-result").empty(); | ||
60 | |||
61 | $.ajax({ | ||
62 | type: $bagitFormForm.attr('method'), | ||
63 | url: $bagitFormForm.attr('action'), | ||
64 | data: $bagitFormForm.serialize(), | ||
65 | success: function(data) { | ||
66 | $('#add-link-result').html("Done!"); | ||
67 | $('#plainurl').val(''); | ||
68 | $('#plainurl').blur(''); | ||
69 | $("body").css("cursor", "auto"); | ||
70 | //setTimeout( function() { toggleSaveLinkForm(); }, 1000); //close form after 1000 delay | ||
71 | }, | ||
72 | error: function(data) { | ||
73 | $('#add-link-result').html("Failed!"); | ||
74 | $("body").css("cursor", "auto"); | ||
75 | } | ||
76 | }); | ||
77 | |||
78 | event.preventDefault(); | ||
79 | }); | ||
80 | |||
81 | /* ========================================================================== | ||
82 | Keyboard gestion | ||
83 | ========================================================================== */ | ||
84 | |||
85 | $(window).keydown(function(e){ | ||
86 | if ( ( e.target.tagName.toLowerCase() !== 'input' && e.keyCode == 83 ) || (e.keyCode == 27 && $bagitForm.is(':visible') ) ) { | ||
87 | $bagit.removeClass("current"); | ||
88 | $("#bagit-arrow").removeClass("arrow-down"); | ||
89 | toggleSaveLinkForm(); | ||
90 | return false; | ||
91 | } | ||
92 | }); | ||
93 | |||
94 | /* ========================================================================== | ||
95 | Process all links inside an article | ||
96 | ========================================================================== */ | ||
97 | |||
98 | $("article a[href^='http']").after(function() { | ||
99 | return " <a href=\"" + $(this).attr('href') + "\" class=\"add-to-wallabag-link-after\" alt=\"add to wallabag\" title=\"add to wallabag\"></a> "; | ||
100 | }); | ||
101 | |||
102 | $(".add-to-wallabag-link-after").click(function(event){ | ||
103 | toggleSaveLinkForm($(this).attr('href'), event); | ||
104 | event.preventDefault(); | ||
105 | }); | ||
106 | |||
107 | }); | ||
108 | |||
109 | |||