Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the onKeyDown event back to codemark form autocomplete box. #38

Merged
merged 1 commit into from Apr 17, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
31 changes: 26 additions & 5 deletions app/assets/javascripts/codemark_form.coffee
@@ -1,6 +1,30 @@
window.CodemarkForm =
handleNewTopics: ->
$("#link_form_topic_autocomplete").keydown (event) ->
if (event.keyCode == 13)
if($("#link_form_topic_count").val() == '0')
event.preventDefault()

newTopic = $("#link_form_topic_autocomplete").val()
existingCheckbox = $("#topic_chb_#{newTopic}")
if (existingCheckbox.length == 0)
newListItem = CodemarkForm.buildTopicListItem(newTopic)
$("#topic_tags").append(newListItem)
else
existingCheckbox.closest("li").effect("highlight", {}, 2000)

$("#fetch").removeAttr("disabled")
$("#link_form_topic_autocomplete").val("")
$("#link_form_topic_slug").val("")

buildTopicListItem: (newTopic) ->
listItem = $("<li class='alert-message warning'></li>")
listItem.append("<input checked='checked' id='topic_chb_#{newTopic}' name='topic_ids[#{newTopic}]' type='hidden' value='#{newTopic}'>")
listItem.append("<div class='title'>#{newTopic}</div>")
listItem.append("<div class='delete'><a href='#'>X</a></div>")
listItem.append("<div class='clear'></div>")

prepareDeletes: ->
console.log $('#topic_tags')
$('#topic_tags').delegate('.delete', 'click', (event) ->
event.preventDefault()

Expand All @@ -13,20 +37,17 @@ window.CodemarkForm =

bindEnter: ->
$("#codemark_form").keyup (event) ->
console.log(event.keyCode)

if (event.keyCode == 13)
console.log 'Enter hit'
event.stopPropagation()
event.preventDefault()

bootstrap: ->
console.log 'here'
CodemarkForm.prepareDeletes()
CodemarkForm.bindEnter()
CodemarkForm.topics_count = $("#topic_tags li").length

Codemarks.prepareAutocompletes()
CodemarkForm.handleNewTopics()

if(CodemarkForm.topics_count == 0)
$("#codemark_form input[type=submit]").attr('disabled', 'disabled')
3 changes: 1 addition & 2 deletions app/views/links/new_topic_checkbox.js.erb
@@ -1,13 +1,12 @@
console.log 'wooooo'
var chb = $("#topic_chb_<%= @topic_title %>");
$("#save_codemark").removeAttr('disabled');
$("#fetch").removeAttr("disabled");

if (chb.length == 0) {
$("#topic_tags").append("<%= escape_javascript(render '/codemarks/new_topic_tag_item', :topic_title => @topic_title) %>");
} else {
chb.closest("li").effect("highlight", {}, 2000);
}
$("#fetch").removeAttr("disabled");
$("#link_form_topic_autocomplete").val("");
$("#link_form_topic_slug").val("");
prepareTagDeletes();