-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjquery.tumblr-ajax-notes.js
43 lines (33 loc) · 1.18 KB
/
jquery.tumblr-ajax-notes.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/* Tumblr Ajax Notes plugin by Matthew Buchanan v1.0g
Requires jQuery 1.2.6 or higher
See https://github.com/matthewbuchanan/tumblr-ajax-notes for installation guide */
;(function ( $, window, undefined ) {
$.fn.doTumblrAjaxNotes = function() {
return this.each(function() {
var $me = $(this);
var noteCount = $me.html();
if (noteCount.indexOf(" ") != -1) {
noteCount = parseInt(noteCount.substring(0,noteCount.indexOf(" ")));
} else {
noteCount = parseInt(noteCount);
}
if (noteCount > 0) $me.show();
if (noteCount > 14) $me.addClass("fave");
$me.click(function(ev) {
ev.preventDefault();
var $node = $("#notes-"+$(this).attr("rel"));
$("#notes-"+$(this).attr("rel")).slideToggle();
$.ajax({ url: $(this).attr("href"), success: function(data){
$node.find(".loading").hide();
$node.find(".notes-loader").html(data).slideDown();
$node.find(".notes-loader").append("<p><a href='#' class='notes-hide'>Hide Notes</a></p>");
$node.find(".notes-hide").click(function(ev) {
ev.preventDefault();
$node.slideToggle();
});
} });
});
});
};
}(jQuery, window));
$("a.notes-button").doTumblrAjaxNotes();