Remove unnecessary conditions

The code won't do anything if there are no elements, so there's no need
to check that condition.
This commit is contained in:
Javi Martín
2019-06-30 01:50:35 +02:00
parent 1cc3324468
commit 4d7c124188
4 changed files with 10 additions and 19 deletions

View File

@@ -9,8 +9,7 @@ App.Imageable =
$("#new_image_link").removeClass("hide") $("#new_image_link").removeClass("hide")
$("#nested-image").on "cocoon:before-insert", -> $("#nested-image").on "cocoon:before-insert", ->
if $(".js-image-attachment").length > 0 $(".js-image-attachment").closest(".image").remove()
$(".js-image-attachment").closest(".image").remove()
$("#nested-image").on "cocoon:after-insert", (e, nested_image) -> $("#nested-image").on "cocoon:after-insert", (e, nested_image) ->
$("#new_image_link").addClass("hide") $("#new_image_link").addClass("hide")

View File

@@ -1,9 +1,7 @@
App.RegistrationForm = App.RegistrationForm =
initialize: -> initialize: ->
usernameInput = $("form#new_user[action=\"/users\"] input#user_username")
registrationForm = $("form#new_user[action=\"/users\"]")
usernameInput = $("input#user_username")
clearUsernameMessage = -> clearUsernameMessage = ->
$("small").remove() $("small").remove()
@@ -18,8 +16,7 @@ App.RegistrationForm =
showUsernameMessage(response) showUsernameMessage(response)
if registrationForm.length > 0 usernameInput.on "focusout", ->
usernameInput.on "focusout", -> clearUsernameMessage()
clearUsernameMessage() username = usernameInput.val()
username = usernameInput.val() validateUsername(username) if username != ""
validateUsername(username) if username != ""

View File

@@ -2,9 +2,6 @@ App.TreeNavigator =
setNodes: (nodes) -> setNodes: (nodes) ->
children = nodes.children("ul") children = nodes.children("ul")
if(children.length == 0)
return
children.each -> children.each ->
link = $(this).prev("a") link = $(this).prev("a")
$('<span class="open"></span>').insertBefore(link) $('<span class="open"></span>').insertBefore(link)
@@ -30,7 +27,6 @@ App.TreeNavigator =
elem.siblings("ul").show() elem.siblings("ul").show()
if anchor = $(location).attr("hash") if anchor = $(location).attr("hash")
if link = elem.find("a[href='#{anchor}']") elem.find("a[href='#{anchor}']").parents("ul").each ->
link.parents("ul").each -> $(this).show()
$(this).show() $(this).siblings("span").removeClass("closed").addClass("open")
$(this).siblings("span").removeClass("closed").addClass("open")

View File

@@ -3,8 +3,7 @@ App.WatchFormChanges =
return $("form[data-watch-changes]") return $("form[data-watch-changes]")
msg: -> msg: ->
if($("[data-watch-form-message]").length) return $("[data-watch-form-message]").data("watch-form-message")
return $("[data-watch-form-message]").data("watch-form-message")
hasChanged: -> hasChanged: ->
App.WatchFormChanges.forms().is -> App.WatchFormChanges.forms().is ->