Subversion-Projekte lars-tiefland.prado

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
var currentCommentID;
2
 
3
function show_comment_list()
4
{
5
	$('comment-list').show();
6
	$('add-comment').hide();
7
	$('show-comment-link').addClassName("active");
8
	$('add-comment-link').removeClassName("active");
9
	$('all-comments-link').removeClassName("active");
10
	show_comments_in_list(currentCommentID);
11
}
12
 
13
function show_all_comments()
14
{
15
	$('comment-list').show();
16
	$('add-comment').hide();
17
	$('show-comment-link').removeClassName("active");
18
	$('add-comment-link').removeClassName("active");
19
	$('all-comments-link').addClassName("active");
20
	show_comments_in_list();
21
}
22
 
23
 
24
function show_add_comment()
25
{
26
	$('comment-list').hide();
27
	$('add-comment').show();
28
	$('show-comment-link').removeClassName("active");
29
	$('add-comment-link').addClassName("active");
30
	$('all-comments-link').removeClassName("active");
31
}
32
 
33
function hide_add_comment()
34
{
35
	$('user-comments').hide();
36
	$('modal-background').hide();
37
	$(content_textare_id).value = '';
38
	$(currentCommentID).style.zIndex = 0;
39
}
40
 
41
function show_comments_in_list(id)
42
{
43
	var list = $('comment-list');
44
	var count=0;
45
	for(var i=0, k=list.childNodes.length; i < k; i++)
46
	{
47
		var node = list.childNodes[i];
48
		if(node.nodeType == 1) //an element node
49
		{
50
			if(typeof(id) == "undefined" || node.className.indexOf(id) >= 0)
51
			{
52
				node.style.display="block"
53
				count++;
54
			}
55
			else
56
				node.style.display="none";
57
		}
58
	}
59
	return count;
60
}
61
 
62
function show_comments(block)
63
{
64
	var id = block.id
65
	currentCommentID = id;
66
	$(hidden_block_id).value = id;
67
	var commentBlock = $('user-comments');
68
	var pos = Position.cumulativeOffset(block);
69
	var top = pos[1] + block.offsetHeight;
70
	commentBlock.style.top = top+"px";
71
	commentBlock.style.width = (block.offsetWidth-22)+"px";
72
 
73
	commentBlock.show();
74
 
75
	var count = show_comments_in_list(id);
76
 
77
	$('comment-list').show();
78
	if(count > 0)
79
		show_comment_list();
80
	else
81
		show_add_comment();
82
 
83
	var background = $('modal-background');
84
	background.style.top="0px";
85
	background.style.left="0px";
86
	background.style.opacity="0.5";
87
	background.style.width = document.body.offsetWidth+"px";
88
	background.style.height = document.body.offsetHeight+"px";
89
	background.show();
90
	block.style.zIndex = 100;
91
	block.style.paddingRight="9px";
92
	block.style.marginRight="-9px";
93
 
94
}
95
 
96
function show_block(block)
97
{
98
	while(block && (!block.className || block.className.indexOf("block-content") < 0))
99
		block = block.parentNode;
100
	if(block && block.className.indexOf("block-content") >= 0)
101
	{
102
		block.addClassName('block-hover');
103
		var tag = $('tag-'+block.id);
104
//		if(tag.className.indexOf("tag-shown")<=0)
105
			tag.firstChild.style.visibility="visible"
106
	}
107
}
108
 
109
function hide_block(block)
110
{
111
	while(block && (!block.className || block.className.indexOf("block-content") < 0))
112
		block = block.parentNode;
113
	if(block && block.className.indexOf("block-hover") >= 0)
114
	{
115
		block.removeClassName('block-hover');
116
		var tag = $('tag-'+block.id);
117
		if(tag.className.indexOf("tag-shown")<=0)
118
			tag.firstChild.style.visibility="hidden"
119
	}
120
}
121
 
122
function add_comment_tag(el)
123
{
124
	var dim = Element.getDimensions(el);
125
	var comments = get_comment_count(el.id);
126
	var style = "height:"+(dim.height > 35 ? dim.height : 35)+"px;";
127
	var cssClass = dim.height ? "block-comment-tag" : "block-comment-tag-ie";
128
	var title = "View "+comments+" comments"
129
	var innerStyle="";
130
	if(comments <= 0)
131
	{
132
		innerStyle = " visibility:hidden;";
133
		comments = "add";
134
		title = "Add new comment";
135
	}
136
	else
137
		cssClass += " tag-shown";
138
	var id = "tag-"+el.id;
139
	var tag = "<div id='"+id+"' class='"+cssClass+"' style='"+style+"'><div style='"+innerStyle+"' title='"+title+"'>"+comments+"</div>&nbsp;</div>";
140
	new Insertion.Before(el, tag);
141
	var tag_div = $(id);
142
	Event.observe(tag_div, "mouseover", function(e){ if(typeof(show_block)!="undefined") show_block(el); });
143
	Event.observe(tag_div, "mouseout", function(e){ if(typeof(hide_block) !="undefined") hide_block(el); });
144
	Event.observe(tag_div, "click", function(e) { if(typeof(show_comments) !="undefined") show_comments(el); Event.stop(e); });
145
}
146
 
147
function increment_count_tag(id)
148
{
149
	var tag = $('tag-'+id);
150
	if(tag && tag.firstChild)
151
	{
152
		if(tag.className.indexOf("tag-shown") >= 0)
153
		{
154
			var count = Number(tag.firstChild.innerHTML);
155
			tag.firstChild.innerHTML = (++count)+"";
156
			tag.firstChild.style.visibility="visible";
157
		}
158
		else
159
		{
160
			tag.firstChild.innerHTML = "1";
161
			tag.addClassName("tag-shown");
162
			tag.firstChild.style.visibility="visible";
163
		}
164
	}
165
}
166
 
167
function get_comment_count(id)
168
{
169
	return comment_count[id] ? comment_count[id] : 0;
170
}
171
 
172
//initialize the comment js
173
 
174
if(!Prado.Browser.ie) //not IE 4,5,6
175
{
176
	(function()
177
	{
178
		var userComments = $('user-comments');
179
		userComments.style.position="absolute";
180
		userComments.style.marginRight="80px";
181
		var commentList = $('comment-list');
182
		commentList.style.height="320px";
183
		$('add-comment').style.height="320px";
184
		commentList.style.overflow="auto";
185
		$('show-comment-link').style.display="";
186
		$('to-top').hide();
187
		$('close-comments').show();
188
		$('all-comments-link').show();
189
		userComments.hide();
190
		$('comments-header').hide();
191
 
192
		$$('#comment-list .source-link').each(function(el){ el.hide(); });
193
 
194
		$$('#content .block-content').each(function(el)
195
		{
196
			Event.observe(el, 'mouseover', function(e){ if(typeof(show_block)!="undefined") show_block(Event.element(e)); });
197
			Event.observe(el, 'mouseout', function(e){ if(typeof(hide_block)!="undefined") hide_block(Event.element(e)); });
198
			add_comment_tag(el);
199
		});
200
 
201
		Event.observe($('show-comment-link'), "click", function(e) { show_comment_list(); Event.stop(e); });
202
		Event.observe($('add-comment-link'), "click", function(e) { show_add_comment();	Event.stop(e); });
203
		Event.observe($('all-comments-link'), "click", function(e) { show_all_comments();	Event.stop(e); });
204
		Event.observe($('close-comments'), "click", function(e) { hide_add_comment(); Event.stop(e); });
205
 
206
	})();
207
}