From f9d37d1d906152c851ae62a4cb51857ec2ba4cf6 Mon Sep 17 00:00:00 2001 From: Eric Allen Date: Sat, 17 Oct 2009 00:03:12 -0400 Subject: [PATCH] Simplify some stuff thanks to live() --- app/views/todos/create.js.rjs | 1 - app/views/todos/toggle_check.js.rjs | 2 -- app/views/todos/update.js.rjs | 2 -- public/javascripts/application.js | 13 ++++--------- 4 files changed, 4 insertions(+), 14 deletions(-) diff --git a/app/views/todos/create.js.rjs b/app/views/todos/create.js.rjs index 5f826699..b63b6168 100644 --- a/app/views/todos/create.js.rjs +++ b/app/views/todos/create.js.rjs @@ -22,7 +22,6 @@ if @saved page[empty_container_msg_div_id].hide unless empty_container_msg_div_id.nil? end # make sure the behavior of the new/updated todo is enabled - page << "TodoBehavior.enableToggleNotes()" page['tickler-empty-nd'].hide if source_view_is :deferred end else diff --git a/app/views/todos/toggle_check.js.rjs b/app/views/todos/toggle_check.js.rjs index c491172c..5f9e2734 100644 --- a/app/views/todos/toggle_check.js.rjs +++ b/app/views/todos/toggle_check.js.rjs @@ -54,5 +54,3 @@ if @saved else page.replace_html "status", content_tag("div", content_tag("h2", "#{pluralize(@todo.errors.count, "error")} prohibited this action from being saved") + content_tag("p", "There were problems with the following fields:") + content_tag("ul", @todo.errors.each_full { |msg| content_tag("li", msg) }), "id" => "errorExplanation", "class" => "errorExplanation") end -# make sure the behavior of the new/updated todo is enabled -page << "TodoBehavior.enableToggleNotes()" diff --git a/app/views/todos/update.js.rjs b/app/views/todos/update.js.rjs index 714eb8b7..8a535028 100644 --- a/app/views/todos/update.js.rjs +++ b/app/views/todos/update.js.rjs @@ -135,8 +135,6 @@ if @saved else logger.error "unexpected source_view '#{params[:_source_view]}'" end - # make sure the behavior of the new/updated todo is enabled - page << "TodoBehavior.enableToggleNotes()" else page.show 'error_status' page.replace_html 'error_status', "#{error_messages_for('todo')}" diff --git a/public/javascripts/application.js b/public/javascripts/application.js index 1a8ffc77..2eff7134 100644 --- a/public/javascripts/application.js +++ b/public/javascripts/application.js @@ -86,14 +86,6 @@ var TracksForm = { } } -var TodoBehavior = { - enableToggleNotes: function() { - $(".show_notes").unbind('click').bind('click', function () { - $(this).next().toggle("fast"); return false; - }); - } -} - $.fn.clearForm = function() { return this.each(function() { var type = this.type, tag = this.tagName.toLowerCase(); @@ -316,8 +308,11 @@ $(document).ready(function() { /* for toggle notes link in mininav */ $("#toggle-notes-nav").click(function () { jQuery(".todo_notes").toggle(); }); + /* show the notes of a todo */ - TodoBehavior.enableToggleNotes(); + $(".show_notes").live('click', function () { + $(this).next().toggle("fast"); return false; + }); /* fade flashes and alerts in automatically */ $(".alert").fadeOut(8000);