postComment = function(){
var form = $(this)
form.find("input[type=submit]").attr('disabled', 'diabled')
var comments = $('div.comments#'+form.attr('id'))
var array = form.serializeArray()
var postData = {}
for (i in array) {
postData[array[i].name] = array[i].value
}
postData['comment'] = tinyMCE.activeEditor.getContent()
progress.show()
$.post(form.attr("action"), postData,
function(result) {
progress.hide()
form.find("input[type=submit]").removeAttr('disabled')
if (result.result == 'OK') {
tinyMCE.activeEditor.setContent('')
pollForComments($([comments]), false)
} else {
handleError(result['message'], $('.messages'))
}
tinyMCE.activeEditor.focus()
},
"json"
)
return false
}
$("form.comment_form").submit(postComment)
function pollForComments(containers, doitagain) {
containers.each(
function(container){
var container = $(containers[container])
var timeout = container.data('timeout')
var name = container.data('name')
var id = container.data('id')
var after = container.find('div.comment').first().attr('id')
var type = container.data('type')
var data = {
method: 'poll_for_comments',
name: name,
id: id,
after: after,
type: type,
}
$.getJSON('/api/', data,
function(result) {
if (result['result'] == 'OK') {
if (result['comments']) {
var newComments = result['comments']
$.each(newComments, function(comment){
var comment = $(newComments[comment]).hide()
comment.prependTo(container).animate({ height: 'toggle', opacity: 'toggle' }, 'slow')
})
}
if (doitagain) {
setTimeout(pollForComments, timeout, containers, true)
}
} else {
handleError(result['message'], container)
}
}
)
}
)
}
pollForComments($("div.comments"), true)
за такой код никто котят не убивает? мне как-то ссыкотно.