Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

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

Merged
merged 1 commit into from

2 participants

@gmassanek
Owner

[27964339] [27964339]

@jeanbahnik jeanbahnik merged commit df173f9 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 17, 2012
This page is out of date. Refresh to see the latest.
View
31 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()
@@ -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')
View
3  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();
Something went wrong with that request. Please try again.