forked from AlexP11223/JavaSpringMvcBlog
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommon.js
More file actions
75 lines (66 loc) · 2.17 KB
/
Copy pathcommon.js
File metadata and controls
75 lines (66 loc) · 2.17 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
function getPostId(el) {
return $(el).closest('.post').attr('data-post-id');
}
function getPostTitle(el) {
return $(el).closest('.post').attr('data-post-title');
}
function showErrorDialog(text) {
bootbox.dialog({
message: text,
buttons: {
ok: {
label: 'OK'
}
}
});
}
function scrollToViewIfNotVisible(element){
var offset = element.offset().top;
if(!element.is(":visible")) {
element.css({"visiblity":"hidden"}).show();
offset = element.offset().top;
element.css({"visiblity":"", "display":""});
}
var visible_area_start = $(window).scrollTop();
var visible_area_end = visible_area_start + window.innerHeight;
if(offset < visible_area_start || offset > visible_area_end){
$('html,body').animate({scrollTop: offset - window.innerHeight/3}, 300);
return false;
}
return true;
}
$(document).ready(function() {
var token = $("meta[name='_csrf']").attr("content");
var header = $("meta[name='_csrf_header']").attr("content");
$(document).ajaxSend(function(e, xhr, options) {
xhr.setRequestHeader(header, token);
});
$.ajax({
dataType: "json",
url: window.postsUrl,
success: function (data) {
var items = [];
$.each(data, function(key, val) {
items.push('<li><a href="' + window.postsUrl + '/' + val.id + '">' + val.title + '</a></li>');
});
$("<ul/>", {
class: 'list-no-indent',
html: items.join('')
}).appendTo('#latestPosts div');
}
});
$.ajax({
dataType: "json",
url: window.popularPostsUrl,
success: function (data) {
var items = [];
$.each(data, function(key, val) {
items.push('<li><a href="' + window.postsUrl + '/' + val.id + '">' + val.title + '</a></li>');
});
$("<ul/>", {
class: 'list-no-indent',
html: items.join('')
}).appendTo('#popularPosts div');
}
});
});