forked from moodle/moodle
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
dongsheng
committed
Jul 24, 2009
1 parent
3209773
commit 1bcb7eb
Showing
22 changed files
with
1,484 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
YAHOO.util.Event.onDOMReady(init); | ||
function init() { | ||
var select_all = document.getElementById('comment_select_all'); | ||
select_all.onclick = function() { | ||
var comments = document.getElementsByName('comments'); | ||
var checked = false; | ||
for (var i in comments) { | ||
if (comments[i].checked) { | ||
checked=true; | ||
} | ||
} | ||
for (var i in comments) { | ||
comments[i].checked = !checked; | ||
} | ||
this.checked = !checked; | ||
} | ||
var comments_delete = document.getElementById('comments_delete'); | ||
comments_delete.onclick = function() { | ||
delete_comments(); | ||
} | ||
} | ||
function delete_comments() { | ||
var url = moodle_cfg.wwwroot + '/comment/index.php'; | ||
var cb = { | ||
success:function(o) { | ||
if (o.responseText == 'yes') { | ||
location.reload(); | ||
} | ||
} | ||
} | ||
var comments = document.getElementsByName('comments'); | ||
var list = ''; | ||
for (var i in comments) { | ||
if (comments[i].checked) { | ||
list += (comments[i].value + '-'); | ||
} | ||
} | ||
var data = { | ||
'commentids': list, | ||
'sesskey': moodle_cfg.sesskey | ||
} | ||
var trans = YAHOO.util.Connect.asyncRequest('POST', | ||
url+'?action=delete', cb, build_querystring(data)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,206 @@ | ||
/** | ||
* Javascript for comments 2.0 | ||
*/ | ||
|
||
function cmt_replace(client_id,list,newcmt) { | ||
var ret = {}; | ||
ret.ids = []; | ||
var template = document.getElementById('cmt-tmpl'); | ||
var html = ''; | ||
for(var i in list) { | ||
var htmlid = 'comment-'+list[i].id+'-'+client_id; | ||
var val = template.innerHTML; | ||
val = val.replace('___name___', list[i].username); | ||
if (list[i]['delete']||newcmt) { | ||
list[i].time += ' <a href="###" title="'+mstr.moodle.delete+'" onclick="delete_comment(\''+client_id+'\',\''+list[i].id+'\')"><img src="'+moodle_cfg.wwwroot+'/pix/t/delete.gif" /></a>'; | ||
} | ||
val = val.replace('___time___', list[i].time); | ||
val = val.replace('___picture___', list[i].avatar); | ||
val = val.replace('___content___', list[i].content); | ||
val = '<li id="'+htmlid+'">'+val+'</li>'; | ||
ret.ids.push(htmlid); | ||
html = (val+html); | ||
} | ||
ret.html = html; | ||
return ret; | ||
} | ||
function cmt_load(cid) { | ||
var container = document.getElementById('comment-list-'+cid); | ||
container.innerHTML = '<div style="text-align:center"><img src="'+moodle_cfg.wwwroot+'/pix/i/loading.gif'+'" /></div>'; | ||
} | ||
function get_comments(client_id, area, itemid, page) { | ||
var url = moodle_cfg.wwwroot + '/comment/comment_ajax.php'; | ||
var data = { | ||
'courseid': comment_params.courseid, | ||
'contextid': comment_params.contextid, | ||
'area': area, | ||
'itemid': itemid, | ||
'page': page, | ||
'client_id': client_id, | ||
'sesskey': moodle_cfg.sesskey | ||
} | ||
this.cb = { | ||
success: function(o) { | ||
try { | ||
var ret = YAHOO.lang.JSON.parse(o.responseText); | ||
} catch(e) { | ||
alert("JSON ERROR: "+o.responseText); | ||
} | ||
if (!comment_check_response(ret)) { | ||
return; | ||
} | ||
var container = document.getElementById('comment-list-'+ret.client_id); | ||
var pagination = document.getElementById('comment-pagination-'+ret.client_id); | ||
if (ret.pagination) { | ||
pagination.innerHTML = ret.pagination; | ||
} else { | ||
//empty paging bar | ||
pagination.innerHTML = ''; | ||
} | ||
var result = cmt_replace(ret.client_id, ret.list); | ||
container.innerHTML = result.html; | ||
} | ||
} | ||
cmt_load(client_id); | ||
var trans = YAHOO.util.Connect.asyncRequest('POST', | ||
url+'?action=get', this.cb, build_querystring(data)); | ||
} | ||
function post_comment(cid) { | ||
this.cb = { | ||
success: function(o) { | ||
try { | ||
var resp = YAHOO.lang.JSON.parse(o.responseText); | ||
} catch(e) { | ||
alert("JSON ERROR: "+o.responseText); | ||
} | ||
if (!comment_check_response(resp)) { | ||
return; | ||
} | ||
if(resp) { | ||
var cid = resp.client_id; | ||
var ta = document.getElementById('dlg-content-'+cid); | ||
ta.value = ''; | ||
var container = document.getElementById('comment-list-'+cid); | ||
var result = cmt_replace(cid,[resp], true); | ||
container.innerHTML += result.html; | ||
var ids = result.ids; | ||
for(var i in ids) { | ||
var attributes = { | ||
color: { to: '#06e' }, | ||
backgroundColor: { to: '#FFE390' } | ||
}; | ||
var anim = new YAHOO.util.ColorAnim(ids[i], attributes); | ||
anim.animate(); | ||
} | ||
} | ||
} | ||
} | ||
var ta = document.getElementById('dlg-content-'+cid); | ||
if (ta.value && ta.value != mstr.moodle.addcomment) { | ||
var url = moodle_cfg.wwwroot + '/comment/comment_ajax.php'; | ||
var formObject = document.getElementById('comment-form-'+cid); | ||
YAHOO.util.Connect.setForm(formObject); | ||
var trans = YAHOO.util.Connect.asyncRequest('POST', url+'?action=add', this.cb); | ||
} else { | ||
var attributes = { | ||
backgroundColor: { from: '#FFE390', to:'#FFFFFF' } | ||
}; | ||
var anim = new YAHOO.util.ColorAnim('dlg-content-'+cid, attributes); | ||
anim.animate(); | ||
} | ||
} | ||
function delete_comment(client_id, comment_id) { | ||
var url = moodle_cfg.wwwroot + '/comment/comment_ajax.php'; | ||
var data = { | ||
'courseid': comment_params.courseid, | ||
'contextid': comment_params.contextid, | ||
'commentid': comment_id, | ||
'client_id': client_id, | ||
'sesskey': moodle_cfg.sesskey | ||
} | ||
this.cb = { | ||
success: function(o) { | ||
try { | ||
var resp = YAHOO.lang.JSON.parse(o.responseText); | ||
} catch(e) { | ||
alert("JSON ERROR: "+o.responseText); | ||
} | ||
if (!comment_check_response(resp)) { | ||
return; | ||
} | ||
var htmlid= 'comment-'+resp.commentid+'-'+resp.client_id; | ||
this.el = document.getElementById(htmlid); | ||
this.el.style.overflow = 'hidden'; | ||
var attributes = { | ||
width:{to:0}, | ||
height:{to:0} | ||
}; | ||
var anim = new YAHOO.util.Anim(htmlid, attributes, 1, YAHOO.util.Easing.easeOut); | ||
anim.onComplete.subscribe(this.remove_dom, [], this); | ||
anim.animate(); | ||
}, | ||
remove_dom: function() { | ||
this.el.parentNode.removeChild(this.el); | ||
} | ||
} | ||
var trans = YAHOO.util.Connect.asyncRequest('POST', | ||
url+'?action=delete', this.cb, build_querystring(data)); | ||
} | ||
function view_comments(client_id, area, itemid, page) { | ||
var container = document.getElementById('comment-ctrl-'+client_id); | ||
var ta = document.getElementById('dlg-content-'+client_id); | ||
var img = document.getElementById('comment-img-'+client_id); | ||
if (container.style.display=='none'||container.style.display=='') { | ||
// show | ||
get_comments(client_id, area, itemid, page); | ||
container.style.display = 'block'; | ||
img.src=moodle_cfg.wwwroot+'/pix/t/expanded.png'; | ||
} else { | ||
// hide | ||
container.style.display = 'none'; | ||
img.src=moodle_cfg.wwwroot+'/pix/t/collapsed.png'; | ||
ta.value = ''; | ||
} | ||
toggle_textarea.apply(ta, [false]); | ||
// reset textarea size | ||
ta.onclick = function() { | ||
toggle_textarea.apply(this, [true]); | ||
} | ||
ta.onkeypress = function() { | ||
if (this.scrollHeight > this.clientHeight && !window.opera) | ||
this.rows += 1; | ||
} | ||
ta.onblur = function() { | ||
toggle_textarea.apply(this, [false]); | ||
} | ||
return false; | ||
} | ||
function comment_hide_link(cid) { | ||
var link = document.getElementById('comment-link-'+cid); | ||
if(link){ | ||
link.style.display='none'; | ||
} else { | ||
alert('wront'); | ||
} | ||
} | ||
function toggle_textarea(focus) { | ||
if (focus) { | ||
if (this.value == mstr.moodle.addcomment) { | ||
this.value = ''; | ||
this.style.color = 'black'; | ||
} | ||
}else{ | ||
if (this.value == '') { | ||
this.value = mstr.moodle.addcomment; | ||
this.style.color = 'grey'; | ||
this.rows = 1; | ||
} | ||
} | ||
} | ||
function comment_check_response(data) { | ||
if (data.error) { | ||
alert(data.error); | ||
return false; | ||
} | ||
return true; | ||
} |
Oops, something went wrong.