]> git.immae.eu Git - github/wallabag/wallabag.git/blame - themes/baggy/js/init.js
saving link form now sends ajax request, article view is now justified
[github/wallabag/wallabag.git] / themes / baggy / js / init.js
CommitLineData
4744cb0e
TL
1$.fn.ready(function() {
2
3 var $listmode = $('#listmode'),
4 $listentries = $("#list-entries"),
5 $bagit = $('#bagit'),
6 $bagitForm = $('#bagit-form');
3ee27ee6 7 $bagitFormForm = $('#bagit-form-form');
4744cb0e
TL
8
9 /* ==========================================================================
10 Menu
11 ========================================================================== */
36a733af
MR
12
13 $("#menu").click(function(){
14 $("#links").toggle();
15 });
16
4744cb0e
TL
17 /* ==========================================================================
18 List mode or Table Mode
19 ========================================================================== */
36a733af 20
4744cb0e 21 $listmode.click(function(){
36a733af 22 if ( $.cookie("listmode") == 1 ) {
4744cb0e 23 // Cookie
36a733af 24 $.removeCookie("listmode");
4744cb0e
TL
25
26 $listentries.removeClass("listmode");
27 $listmode.removeClass("tablemode");
28 $listmode.addClass("listmode");
943ac3c7 29 }
36a733af 30 else {
4744cb0e 31 // Cookie
36a733af
MR
32 $.cookie("listmode", 1, {expires: 365});
33
4744cb0e
TL
34 $listentries.addClass("listmode");
35 $listmode.removeClass("listmode");
36 $listmode.addClass("tablemode");
36a733af
MR
37 }
38
943ac3c7 39 });
36a733af 40
4744cb0e
TL
41 /* ==========================================================================
42 Cookie listmode
43 ========================================================================== */
44
36a733af 45 if ( $.cookie("listmode") == 1 ) {
4744cb0e
TL
46 $listentries.addClass("listmode");
47 $listmode.removeClass("listmode");
48 $listmode.addClass("tablemode");
36a733af
MR
49 }
50
4744cb0e 51 /* ==========================================================================
6775da70
MR
52 bag it link and close button
53 ========================================================================== */
4744cb0e 54
6775da70
MR
55 function toggleSaveLinkForm(url) {
56 $bagit.toggleClass("active-current");
4744cb0e 57 $bagitForm.toggle();
6775da70
MR
58 $('#content').toggleClass("opacity03");
59 if (url !== 'undefined' && url) {
60 $('#plainurl').val(url);
61 }
62 $('#plainurl').focus();
63 }
64
65 $bagit.click(function(){
66 toggleSaveLinkForm();
67 });
68
69 $("#bagit-form-close").click(function(){
70 toggleSaveLinkForm();
71 });
72
3ee27ee6
MR
73
74 //send "bag it link" form request via ajax
75 $bagitFormForm.submit( function(event) {
76 $bagitFormForm.css("cursor", "wait");
77 $("#add-link-result").empty();
78
79 $.ajax({
80 type: $bagitFormForm.attr('method'),
81 url: $bagitFormForm.attr('action'),
82 data: $bagitFormForm.serialize(),
83 success: function(data) {
84 $('#add-link-result').html("Done!");
85 $('#plainurl').val('');
86 $('#plainurl').blur('');
87 $bagitFormForm.css("cursor", "auto");
88 //setTimeout( function() { toggleSaveLinkForm(); }, 1000); //close form after 1000 delay
89 },
90 error: function(data) {
91 $('#add-link-result').html("Failed!");
92 $bagitFormForm.css("cursor", "auto");
93 }
94 });
95
96 event.preventDefault();
4744cb0e
TL
97 });
98
99 /* ==========================================================================
6775da70
MR
100 Keyboard gestion
101 ========================================================================== */
4744cb0e
TL
102
103 $(window).keydown(function(e){
6775da70
MR
104 if ( ( e.target.tagName.toLowerCase() !== 'input' && e.keyCode == 83 ) || e.keyCode == 27 ) {
105 toggleSaveLinkForm();
106 return false;
4744cb0e 107 }
6775da70
MR
108 });
109
110 /* ==========================================================================
111 Process all links inside an article
112 ========================================================================== */
113
114 $("article a[href^='http']").after(function() {
115 return " <a href=\"" + $(this).attr('href') + "\" class=\"add-to-wallabag-link-after\" alt=\"add to wallabag\" title=\"add to wallabag\">w</a> ";
116 });
117
118 $(".add-to-wallabag-link-after").click(function(event){
6775da70 119 toggleSaveLinkForm($(this).attr('href'));
3ee27ee6 120 event.preventDefault();
6775da70
MR
121 });
122
123
4744cb0e 124
36a733af 125
7339b0b0 126});