-
Notifications
You must be signed in to change notification settings - Fork 0
/
activitylogs.js
139 lines (117 loc) · 3.35 KB
/
activitylogs.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
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
(function ($) {
/**
* Move a block in the blocks table from one region to another via select list.
*
* This behavior is dependent on the tableDrag behavior, since it uses the
* objects initialized in that behavior to update the row.
*/
Drupal.behaviors.activitylogs = {
attach: function (context, settings) {
}
};
})(jQuery);
(function($){
$.fn.loaddata = function(options) {// Settings
url = location.href;
parts = url.split("/");
//type
if(parts[3] != null) {
activity_name = parts[3];
}
else {
activity_name = '';
}
if(activity_name == 'node') {
//type
if(parts[6] != null) {
activity_type = parts[6];
}
else {
activity_type = '';
}
//nid
if(parts[4] != null) {
activity_nid = parts[4];
}
else {
activity_nid = 0;
}
//uid
if(parts[7] != null) {
activity_uid = parts[7];
}
else {
activity_uid = 0;
}
}
else if(activity_name == 'activitylogs') {
//type
if(parts[4] != null) {
activity_type = parts[4];
}
else {
activity_type = '';
}
//nid
if(parts[5] != null) {
activity_nid = parts[5];
}
else {
activity_nid = 0;
}
//uid
if(parts[6] != null) {
activity_uid = parts[6];
}
else {
activity_uid = 0;
}
}
else {
activity_type = '';
activity_nid = 0;
activity_uid = 0;
}
//console.log(url);
var settings = $.extend({
loading_gif_url : "/loader.gif", //url to loading gif
end_record_text : 'No activity records found!', //no more records to load
data_url : '/activitylogs/timelines/load/'+activity_type+'/'+activity_nid+'/'+activity_uid, //url
start_page : 1 //initial page
}, options);
var el = this;
//console.log(el);
loading = false;
end_record = false;
contents(el, settings); //initial data load
$(window).scroll(function() { //detact scroll
if($(window).scrollTop() + $(window).height() >= $(document).height()){ //scrolled to bottom of the page
contents(el, settings); //load content chunk
}
});
};
//Ajax load function
function contents(el, settings){
var load_img = $('<img/>').attr('src',settings.loading_gif_url).addClass('loading-image'); //create load image
//var record_end_txt = $('<div/>').text(settings.end_record_text).addClass('end-record-info'); //end record text
var record_end_txt = '<div class="cd-timeline__block js-cd-block"><div class="cd-timeline__img cd-timeline__img--picture js-cd-img"> </div><!-- cd-timeline__img --><div class="cd-timeline__content js-cd-content"><p>'+settings.end_record_text+'</p></div> <!-- cd-timeline__content --></div>';
if(loading == false && end_record == false){
loading = true; //set loading flag on
el.append(load_img); //append loading image
$.post( settings.data_url, {'page': settings.start_page}, function(data){ //jQuery Ajax post
//console.log(data);
if(data.trim().length == 0){ //no more records
el.append(record_end_txt); //show end record text
load_img.remove(); //remove loading img
end_record = true; //set end record flag on
return; //exit
}
loading = false; //set loading flag off
load_img.remove(); //remove loading img
el.append(data); //append content
settings.start_page ++; //page increment
})
}
}
jQuery("#activitylogs-timelines").loaddata(); //load the results into element
})(jQuery);