-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcodiNewsfeed-0.1.js
More file actions
executable file
·152 lines (130 loc) · 4.21 KB
/
codiNewsfeed-0.1.js
File metadata and controls
executable file
·152 lines (130 loc) · 4.21 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
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/*!
* codiNewsfeed jQuery plugin v0.1
* http://codilabs.com
*
*
* Copyright 2013 codiLabs Indonesia, Inc. and jQuery Library
* Released not under any license
* http://codilabs.com/jplugin/codiNewsfeed
*
* Date: 2013-02-13
*/
(function($){
$.fn.codiNewsfeed=function(settings){
settings = $.extend({}, $.fn.codiNewsfeed.defaults, settings);
return this.each(function() {
//detect if url is empty
if(settings.url=='') {
alert("You haven't url parameter, please set it first \n \n $(elem).codiNewsfeed({ \n \t url : target.json.asp \n });");
return false;
}
//rename .....
var $this = $(this);
//initializing for new size of element
/*----------------------------------*/
var thisOuterHeight = $this.outerHeight()
var thisHeight = $this.height();
var thisOuterWidth = $this.outerWidth();
var thisWidth = $this.width();
var parentHeight = $this.parent().height();
var parentWidth = $this.parent().width();
/*----------------------------------*/
//resize element to a new size
$this.css({
height: parentHeight-(thisOuterHeight-thisHeight)+'px',
width: parentWidth-(thisOuterWidth-thisWidth)+'px',
overflow: 'hidden'
});
//set new elem's values
var new_content = '';
//get elem's value
var myhtml = $this.html().replace(/\s+$/,"");
//id for new elem childrens
var elemid = 0;
//generating new elem's values
if(myhtml=='') {
//if elem haven't some text or other elem child, it'll be return to textIfEmpty parameter
new_content = settings.textIfEmpty;
} else {
//reconstructing elem's value
$this.find("list").each(function(index, elem){
new_content += '<div class="codiNewsfeedBox" id="codiNewsfeedBox_'+elemid+'">'+
'<span id="codiNewsfeedContent_'+elemid+'">'+
$(this).html()+
'</span>'+
'</div>';
elemid++;
});
}
//if not found any span content, it'll be return to textIfEmpty parameter
if(new_content=='') {
new_content = settings.textIfEmpty;
}
//last id from parameter
var lastId = settings.lastId;
//revariabling streamInterval
var interval = settings.streamInt;
//start stream for first time
setTimeout(function() { getStream(lastId, elemid); }, interval);
//reset elem's value
$this.html(new_content);
//Start to getting new stream datas
/*----------------------------------*/
//preparing transition speed
var transition = settings.speedMove;
var slideDown = (transition/3)*2;
var fadeIn = transition/2;
/*---- start of stream -----*/
//sorry, we're unavailable to write some comments for all proccess below
function getStream(lastId, elemid) {
$.ajax({
type: "GET", url: settings.url, data: 'id='+lastId, cache: false,
success: function(result){
var timeforrestream = 0;
if(result!='') {
if($this.html()==settings.textIfEmpty) {
$this.html('');
}
var res = jQuery.parseJSON(result);
var res_temp = new Array();
for(var i=0; i<res.length; i++) {
lastId = res[i].id;
var content = res[i].text;
$this.prepend('<div class="codiNewsfeedBox" id="codiNewsfeedBox_'+elemid+'">'+
'<span id="codiNewsfeedContent_'+elemid+'">'+
content+
'</span>'+
'</div>');
$('#codiNewsfeedBox_'+elemid).hide();
$('#codiNewsfeedContent_'+elemid).css({opacity:0});
res_temp[i] = [elemid, timeforrestream];
timeforrestream += interval+transition;
elemid++;
}
for(var n=0; n<res_temp.length; n++) {
showNewTicker(res_temp[n]);
}
}
setTimeout(function() { getStream(lastId, elemid); }, interval+timeforrestream);
}
});
};
function showNewTicker(res_tmp) {
setTimeout(function() {
$('#codiNewsfeedBox_'+res_tmp[0]).slideDown(slideDown);
setTimeout(function() {
$('#codiNewsfeedContent_'+res_tmp[0]).animate({opacity:1}, transition);
}, slideDown);
}, res_tmp[1]);
}
/*---- end of stream -----*/
});
}
$.fn.codiNewsfeed.defaults = {
streamInt : 4000,
speedMove : 1000,
url : '',
lastId : 0,
textIfEmpty : 'You haven\'t data',
};
})(jQuery);