diff options
Diffstat (limited to 'themes/baggy/js/init.js')
-rwxr-xr-x | themes/baggy/js/init.js | 120 |
1 files changed, 105 insertions, 15 deletions
diff --git a/themes/baggy/js/init.js b/themes/baggy/js/init.js index 4a843548..da644fbe 100755 --- a/themes/baggy/js/init.js +++ b/themes/baggy/js/init.js | |||
@@ -1,36 +1,126 @@ | |||
1 | $(document).ready(function() { | 1 | $.fn.ready(function() { |
2 | |||
3 | var $listmode = $('#listmode'), | ||
4 | $listentries = $("#list-entries"), | ||
5 | $bagit = $('#bagit'), | ||
6 | $bagitForm = $('#bagit-form'); | ||
7 | $bagitFormForm = $('#bagit-form-form'); | ||
8 | |||
9 | /* ========================================================================== | ||
10 | Menu | ||
11 | ========================================================================== */ | ||
2 | 12 | ||
3 | $("#menu").click(function(){ | 13 | $("#menu").click(function(){ |
4 | $("#links").toggle(); | 14 | $("#links").toggle(); |
5 | }); | 15 | }); |
6 | 16 | ||
17 | /* ========================================================================== | ||
18 | List mode or Table Mode | ||
19 | ========================================================================== */ | ||
7 | 20 | ||
8 | $("#listmode").click(function(){ | 21 | $listmode.click(function(){ |
9 | if ( $.cookie("listmode") == 1 ) { | 22 | if ( $.cookie("listmode") == 1 ) { |
10 | $(".entrie").css("width", ""); | 23 | // Cookie |
11 | $(".entrie").css("margin-left", ""); | ||
12 | |||
13 | $.removeCookie("listmode"); | 24 | $.removeCookie("listmode"); |
14 | $("#listmode").removeClass("tablemode"); | 25 | |
15 | $("#listmode").addClass("listmode"); | 26 | $listentries.removeClass("listmode"); |
27 | $listmode.removeClass("tablemode"); | ||
28 | $listmode.addClass("listmode"); | ||
16 | } | 29 | } |
17 | else { | 30 | else { |
31 | // Cookie | ||
18 | $.cookie("listmode", 1, {expires: 365}); | 32 | $.cookie("listmode", 1, {expires: 365}); |
19 | 33 | ||
20 | $(".entrie").css("width", "100%"); | 34 | $listentries.addClass("listmode"); |
21 | $(".entrie").css("margin-left", "0"); | 35 | $listmode.removeClass("listmode"); |
22 | $("#listmode").removeClass("listmode"); | 36 | $listmode.addClass("tablemode"); |
23 | $("#listmode").addClass("tablemode"); | ||
24 | } | 37 | } |
25 | 38 | ||
26 | }); | 39 | }); |
27 | 40 | ||
41 | /* ========================================================================== | ||
42 | Cookie listmode | ||
43 | ========================================================================== */ | ||
44 | |||
28 | if ( $.cookie("listmode") == 1 ) { | 45 | if ( $.cookie("listmode") == 1 ) { |
29 | $(".entrie").css("width", "100%"); | 46 | $listentries.addClass("listmode"); |
30 | $(".entrie").css("margin-left", "0"); | 47 | $listmode.removeClass("listmode"); |
31 | $("#listmode").removeClass("listmode"); | 48 | $listmode.addClass("tablemode"); |
32 | $("#listmode").addClass("tablemode"); | ||
33 | } | 49 | } |
34 | 50 | ||
51 | /* ========================================================================== | ||
52 | bag it link and close button | ||
53 | ========================================================================== */ | ||
54 | |||
55 | function toggleSaveLinkForm(url) { | ||
56 | $bagit.toggleClass("active-current"); | ||
57 | $bagitForm.toggle(); | ||
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 | |||
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(); | ||
97 | }); | ||
98 | |||
99 | /* ========================================================================== | ||
100 | Keyboard gestion | ||
101 | ========================================================================== */ | ||
102 | |||
103 | $(window).keydown(function(e){ | ||
104 | if ( ( e.target.tagName.toLowerCase() !== 'input' && e.keyCode == 83 ) || e.keyCode == 27 ) { | ||
105 | toggleSaveLinkForm(); | ||
106 | return false; | ||
107 | } | ||
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){ | ||
119 | toggleSaveLinkForm($(this).attr('href')); | ||
120 | event.preventDefault(); | ||
121 | }); | ||
122 | |||
123 | |||
124 | |||
35 | 125 | ||
36 | }); | 126 | }); |