jQuery -> $('#my-forum-photo').ajaxForm() $('input[id = forum-user-button]').click -> manageUserAction(event.target) $('#forum-comment-span').click -> event.stopPropagation() $('input[id=photo_file]').change -> unless $('input[id=photo_file]').val() == '' document.getElementById('forum-comment-span').dataset.needs_photo = true $('#forum-add-photo').click -> $('input[id=photo_file]').click() event.stopPropagation() $('#forum-create-hyperlink').click -> addHotLlink() $('#forum-add-hyperlink').click -> showHyperlinkInput() #------------------------------------- this needs to be last binding ------------------------# $('#forum-senate').click -> checkPost() event.stopPropagation() $('button[id = forum-vote]').click -> doForumVoting(event.target) doForumVoting = (which)-> switch(which.parentNode.name) when 'up' voteUp() when 'down' voteDown() else manageUserAction = (which)-> switch(which.name) when 'forum-edit-comment' editComment() when 'forum-accept-comment' setCommentState('accept') when 'forum-reject-rest' setStateRest('reject') when 'forum-accept-rest' setStateRest('accept') when 'forum-reject-comment' setCommentState('reject') when 'forum-cancel-comment' cancelComment() when 'forum-post-it' setComment() when 'forum-subscribe' subscribe(true) when 'forum-unsubscribe' subscribe(false) when 'add-forum-translation' setTranslationState() when 'add-forum-voting' $.post('xforum/forum_ajax', {function: 'add voting', topic: getTopic()}, setUpVoting) when 'forum-add-suggestion-submit' sendNewThing() when 'forum-restrict-comment' checkRestriction(which) when 'forum-invite-comment' showMe({id: 'forum-invitation-span'}) when 'forum-invite-list-save' saveInviteList() else checkRestriction = (which)-> comment_span = document.getElementById('forum-comment-span') if comment_span.dataset.restricted == 'false' which.value = which.dataset.unrestrict comment_span.dataset.restricted = true else which.value = which.dataset.restrict comment_span.dataset.restricted = false setStateRest = (new_state)-> spans = $('span[data-state = new]') for i in [0...spans.length] setTheState([spans[i]], new_state) $.post('xforum/forum_ajax', {function: 'set_the_rest', topic: getTopic(), state: new_state}) clearSenate() setCategory(0) setTopic(0) subscribe = (subscribed)-> setSubscriber(subscribed) $.post('xforum/forum_ajax', {function: 'subscribe', topic: getTopic()}) voteUp = -> $.post('xforum/forum_ajax', {function: 'vote', vote: 1, topic: getTopic()}, refreshVote) voteIt(1) window.setCommentSpan=-> if $('#comment-maybe')? && $('#comment-maybe').length == 1 id = parseInt($('#comment-maybe').get()[0].dataset.parent) span = $("span[data-id = #{id}]").get()[0] comment_span = document.getElementById('forum-comment-span') if span.dataset.owner == 'true' || isAdmin() comment_span.dataset.editing = true comment_span.dataset.edit=true comment_span.dataset.target = id comment_span.dataset.restricted = span.dataset.restricted if span.dataset.already_has_photo=='true' comment_span.dataset.already_has_photo=true if span.dataset.restricted == 'true' $('[name = forum-restrict-comment]').val($('[name = forum-restrict-comment]').get()[0].dataset.unrestrict) else $('[name = forum-restrict-comment]').val($('[name = forum-restrict-comment]').get()[0].dataset.restrict) comment_data = span.childNodes[0].innerHTML.split(' setCommentSpan() voteDown = -> $.post('xforum/forum_ajax', {function: 'vote', vote: -1, topic: getTopic()}, refreshVote) voteIt(-1) voteIt = (vote)-> votes = parseInt(document.getElementById('forum-vote-count').innerHTML.split(' = ')[1]) document.getElementById('forum-vote-count').innerHTML = 'Vote = ' + (votes + vote) refreshVote = (params)-> document.getElementById('forum-vote-count').innerHTML = 'Vote = ' + (params.votes) window.setUpVoting = (params)-> if params.vote showMe({id: 'forum-voting-booth'}) refreshVote({votes: params.votes}) else hideMe({id: 'forum-voting-booth'}) setCommentState = (new_state)-> span = $('#comment-maybe').get()[0] unless span == undefined id = parseInt($('#comment-maybe').get()[0].dataset.parent) setTheState($("span[data-id = #{id}]"), new_state) resolution = getMyValue('forum-comment') setMyValue('forum-comment', '') hideMe({id: 'comment-span'}) $('#comment-maybe').remove() $.post('xforum/forum_ajax', {function: new_state, id: id, resolution: resolution}) setTheState = (span, new_state)-> baby_span = span[0].children[0] switch new_state when 'accept' baby_span.className = 'forum-comment' when 'reject' baby_span.className = 'comment-reject' else baby_span.parentNode.dataset.comment_state = new_state window.cancelComment = -> $('#forum-comment').val('') $('#comment-maybe').remove() $('#forum-comment-span')[0].dataset.translating = false hideMe({id:'forum-translation-span'}) hideMe({id: 'forum-comment-span'}) checkPost = -> unless getSelectedId().id == undefined page = document.getElementById('forum-senate') if $('#comment-maybe')? $('#comment-maybe').remove() id = parseInt(getSelectedId().id) if id? offset = setNewComment(id) if page.dataset.language showMe({id: 'add-forum-translation'}) else hideMe({id: 'add-forum-translation'}) if isModerator() moderatorOnOff(true) else moderatorOnOff(false) placeCommentSpan(offset, id) window.isModerator =-> document.getElementById('forum-senate').dataset.moderator == 'true' window.isAdmin =-> document.getElementById('forum-senate').dataset.admin == 'true' setNewComment = (id)-> $('#forum-comment').val('') $('#forum-comment-translation').val('') $('[name=translation-suggestion]').remove page = document.getElementById('forum-senate') span = document.createElement('span') span.classList.add('forum-comment-new') span.id = 'comment-maybe' parent_span = $("span[data-id = #{id}]").get()[0] span.dataset.parent = id span.innerHTML = "

your post

" if page.dataset.review == 'true' $("span[data-id = #{id}]").after(span) else $(lastChild(id)).after(span) paragraph=span.getElementsByTagName('p')[0] paragraph.classList.add('forum-comment-new') paragraph.style.marginLeft = 20 + parseInt(parent_span.style.marginLeft) + 'px' if parent_span.dataset.owner == 'true' || isAdmin() then showMe({name: 'forum-edit-comment'}) else hideMe({name: 'forum-edit-comment'}) if document.getElementById('forum-comment-span').dataset.translating == 'true' editComment() parseInt(span.offsetTop) placeCommentSpan = (offset, id) -> comment = document.getElementById('forum-comment-span') offset=Math.min(400,offset) comment.style.position = 'absolute' comment.style.top = offset + 'px' comment.style.left = '250px' comment.dataset.restricted = false comment.dataset.edit = false comment.dataset.editing = false hideMe({id:'forum-add-hyperlink-span'}) $('[name = forum-restrict-comment]').val($('[name = forum-restrict-comment]').get()[0].dataset.restrict) comment.dataset.owner = $("span[data-id = #{id}]").get()[0].dataset.owner comment.dataset.target=id showMe({obj: comment}) $('#forum-comment').focus() the_span=$("[data-id="+id+']').get()[0] if the_span.dataset.needs_translation =='true' $('[name=add-forum-translation]').get()[0].classList.add('hot') else $('[name=add-forum-translation]').get()[0].classList.remove('hot') moderatorOnOff = (on_off)-> if on_off showMe({name: 'forum-accept-comment'}) showMe({name: 'forum-reject-comment'}) showMe({name: 'add-forum-voting'}) else hideMe({name: 'forum-accept-comment'}) hideMe({name: 'forum-reject-comment'}) hideMe({name: 'add-forum-voting'}) lastChild = (id)-> kids = $("span[data-parent = #{id}]") if kids.length == 0 $("span[data-id = #{id}]") else lastChild(kids[kids.length - 1].dataset.id) setComment = -> request = {function: 'post'} request.comment = $('#forum-comment').val().trim() if request.comment == "" && $('#comment-maybe')? $('#comment-maybe').remove() else if $('#comment-maybe')? sendPost(request) hideMe({id: 'forum-comment-span'}) $('#forum-comment').val('') window.sendPost = (request)-> comment_span = document.getElementById('forum-comment-span') if comment_span.dataset.edit == 'true' || comment_span.dataset.translating == 'true' id = parseInt($('#comment-maybe').get()[0].dataset.parent) span = $("span[data-id = #{id}]").get()[0] request.id = id #id is nil if new comment $('#comment-maybe').remove() else span = document.getElementById('comment-maybe') next_id = parseInt(comment_span.dataset.next_id) comment_span.dataset.next_id = next_id+1 request.tag = next_id span.dataset.id = 'new' + next_id span.dataset.tag=next_id parent=$('[data-id='+span.dataset.parent+']').get()[0] span.dataset.indent= parseInt(parent.dataset.indent ) + 1 request.edit = comment_span.dataset.edit == 'true' request.translation = $('#forum-comment-translation').val().trim() request.language = getTranslationLanguage() request.translating = comment_span.dataset.translating == 'true' request.restricted = span.dataset.restricted request.invitees = $('#forum-invite-list').val() request.parent = span.dataset.parent request.topic = getTopic() request.category = getCategory() request.needs_photo= comment_span.dataset.needs_photo == 'true' request.already_has_photo=comment_span.dataset.already_has_photo request.count=0 link_ref=comment_span.dataset.link_ref unless link_ref == undefined request= addLinks(request,parseInt(link_ref)) request= addLinkTranslations(request) writeParagraph(span,request) if request.needs_photo document.getElementById('photo_data').value= JSON.stringify(request) #goes up in the submit $('#my-forum-photo').submit() document.getElementById('forum-comment-span').dataset.needs_photo =false document.getElementById('photo_data').value='' request.function='get forum photo' $.post('xforum/forum_ajax', request, needAPhoto) $('#photo_file').val('') else $.post('xforum/forum_ajax', request, setMaybeId) window.setMaybeId = (params)-> unless params.edit span = $("[data-tag=#{params.tag}]").get()[0] span.id = 'just-a-comment' span.dataset.id = params.id span.dataset.parent = params.parent writeParagraph=(span,params)-> comment_span = document.getElementById('forum-comment-span') if comment_span.dataset.editing=='true' the_html = span.innerHTML comment_text =span.getElementsByTagName('p')[0].innerHTML.split('' paragraph=span.getElementsByTagName('p')[0] paragraph.classList.add('forum-comment-new') paragraph.style={} paragraph.style.marginLeft = 20 * parseInt(span.dataset.indent) + 'px' span.dataset.restricted = comment_span.dataset.restricted span.dataset.owner = true link_refs=parseInt(comment_span.dataset.link_ref) unless link_refs==undefined for i in [0...link_refs] writeLocalLink(span,i) writeLocalLink=(span,link_ref)-> data= getLinkData(link_ref) writeLink(data,span) window.getLinkData=(link_ref)-> comment_span = document.getElementById('forum-comment-span') data={} data.link_address = comment_span.dataset['link_address-'+link_ref] data.link_text= comment_span.dataset['link_text-'+link_ref] data.link_id = comment_span.dataset['link_id-'+link_ref] data window.writeLink=(data,span)-> link=document.createElement('a') link.href='http://'+data.link_address link.innerHTML=data.link_text link.id=data.link_id link.className='external' space1=document.createElement('span') space1.innerHTML=' ' space2=document.createElement('span') space2.innerHTML=' ' paragraph=span.children[0] paragraph.appendChild((space1)) paragraph.appendChild(link) paragraph.appendChild(space2) sendNewThing = -> $.post('xforum/forum_ajax', {function: 'suggestion', suggestion:$('#forum-suggestion').val(), topic:getTopic(),language:getLanguage(),category: getCategory()}) $('#forum-suggestion').val('') setCategory(0) setTopic(0) hideMe({id: 'forum-add-new-thing-span'}) showMe({id: 'forum-senate'}) window.setSubscriber = (subscribed)-> document.getElementById('forum-senate').dataset.subscribed = subscribed if subscribed hideMe({id: 'subscribe-forum'}) showMe({id: 'unsubscribe-forum'}) else showMe({id: 'subscribe-forum'}) hideMe({id: 'unsubscribe-forum'}) addHotLlink=-> #to span.dataset data={function:'add hot link'} data.link_address= $('[id=forum-hyperlink-address]').val() data.link_text=$('[id=forum-hyperlink-text]').val() link_ref=document.getElementById('forum-comment-span').dataset.link_ref if link_ref == undefined data.link_id = 0 else data.link_id = parseInt(link_ref) sethyperlink(data) clearhyperlink() clearhyperlink=-> $('[id=forum-hyperlink-address]').val('') $('[id=forum-hyperlink-text]').val('') hideMe({id:'forum-hyperlink-span'}) showHyperlinkInput=-> showMe({id:'forum-add-hyperlink-span'}) sethyperlink=(params)-> #push data onto dataset comment_span=document.getElementById('forum-comment-span') link_ref=comment_span.dataset.link_ref if link_ref == undefined then link_ref= 0 link_ref=parseInt(link_ref) comment_span.dataset.link_ref = link_ref + 1 comment_span.dataset['link_address-'+link_ref]=params.link_address comment_span.dataset['link_text-'+link_ref]=params.link_text comment_span.dataset['link_id-'+link_ref]=params.link_id window.addLinks=(request,link_ref)-> request.link_ref=link_ref for i in [0...link_ref] request['link-'+i]= getLinkData(i) request