From b942e29829d73834fd728ade933369d838cb455a Mon Sep 17 00:00:00 2001 From: Andrew Miner Date: Thu, 11 Jun 2015 15:13:55 -0700 Subject: [PATCH] Fix two bugs * Make sure no elements of the markdown section are displayed when they shouldn't be by taking advantage of the jQuery animation queue * Don't crash when the user cancels selecting a file --- .../markdown_image_controller.coffee | 15 ++++++----- .../markdown_section_controller.coffee | 15 ++++++----- src/jade/templates/markdown_section.jade | 26 +++++++++---------- 3 files changed, 30 insertions(+), 26 deletions(-) diff --git a/src/coffee/controllers/markdown_image_controller.coffee b/src/coffee/controllers/markdown_image_controller.coffee index 504437f81..8d65ba82d 100644 --- a/src/coffee/controllers/markdown_image_controller.coffee +++ b/src/coffee/controllers/markdown_image_controller.coffee @@ -35,6 +35,7 @@ module.exports = class MarkdownImageController extends BaseController if @_reader? then @_reader.abort = true file = @$input.prop('files')[0] + return unless file? if file.size > MAX_FILE_SIZE logger.warning "The choosen file, #{file.name}, is too large: #{file.size}" @@ -123,20 +124,20 @@ module.exports = class MarkdownImageController extends BaseController @$button.html 'Choose' if @model.status is MarkdownImage.Status.checking - @$loaded.hide duration:Duration.normal - @$loading.show duration:Duration.normal, queue:true + @$loaded.fadeOut duration:Duration.normal + @$loading.fadeIn duration:Duration.normal, queue:true else - @$loading.hide duration:Duration.normal - @$loaded.show duration:Duration.normal, queue:true + @$loading.fadeOut duration:Duration.normal + @$loaded.fadeIn duration:Duration.normal, queue:true if @model.status is MarkdownImage.Status.empty @$errorMessage.html 'please choose an image' - @$errorContainer.show duration:Duration.normal + @$errorContainer.fadeIn duration:Duration.normal else if @errorMessage? @$errorMessage.html @errorMessage - @$errorContainer.show duration:Duration.normal + @$errorContainer.fadeIn duration:Duration.normal else - @$errorContainer.hide duration:Duration.normal + @$errorContainer.fadeOut duration:Duration.normal super diff --git a/src/coffee/controllers/markdown_section_controller.coffee b/src/coffee/controllers/markdown_section_controller.coffee index ed52526f9..8c659e69d 100644 --- a/src/coffee/controllers/markdown_section_controller.coffee +++ b/src/coffee/controllers/markdown_section_controller.coffee @@ -8,6 +8,7 @@ All rights reserved. _ = require 'underscore' BaseController = require './base_controller' convertMarkdown = require 'marked' +{Duration} = require '../constants' {Event} = require '../constants' MarkdownImageListController = require './markdown_image_list_controller' {Url} = require '../constants' @@ -244,6 +245,8 @@ module.exports = class MarkdownSectionController extends BaseController return if @_lastUpdatedState is @state @_lastUpdatedState = @state + logger.verbose => "Updating markdown section visibility for state: #{@state}" + elements = appologizingPanel: @$('.appologizing') buttonPanel: @$('.buttons') @@ -283,13 +286,13 @@ module.exports = class MarkdownSectionController extends BaseController toHide = ($el for name, $el of elements when not visible[name]) toShow = ($el for name, $el of elements when visible[name]) + $el.clearQueue() for name, $el of elements + if toHide.length > 0 - @hide $el for $el in toHide - if toShow.length > 0 - @once Event.animate.hide.finish, => - @show $el for $el in toShow - else if toShow.length > 0 - @show $el for $el in toShow + $el.fadeOut(duration:Duration.normal) for $el in toHide + $el.delay(Duration.normal) for $el in toShow + + $el.fadeIn(duration:Duration.normal) for $el in toShow if @state is State.editing @once Event.animate.show.finish, => diff --git a/src/jade/templates/markdown_section.jade b/src/jade/templates/markdown_section.jade index 9c1c2b337..ce2d25f29 100644 --- a/src/jade/templates/markdown_section.jade +++ b/src/jade/templates/markdown_section.jade @@ -8,11 +8,11 @@ .view__markdown_section.section h2 .panel - .waiting.hideable: img(src='/images/wait.gif') - .markdown.hideable.hidden - .creating.hideable.hidden + .waiting: img(src='/images/wait.gif') + .markdown + .creating p Please help by adding a description! - .editor.hideable.hidden + .editor .instructions p. Edit using GitHub @@ -21,16 +21,16 @@ textarea .sizer .image_list - .buttons.hideable.hidden - .error.hideable.hidden: p - button.return.hideable.hidden return - button.cancel.hideable.hidden cancel - button.preview.hideable.hidden preview - button.save.hideable.hidden save - button.edit.hideable edit - .confirming.hideable.hidden + .buttons + .error: p + button.return return + button.cancel cancel + button.preview preview + button.save save + button.edit edit + .confirming p Thanks for your help! p Your changes will appear on the site in a few minutes. - .appologizing.hideable.hidden + .appologizing p Sorry, but something went wrong. p Please try again after a few moments. \ No newline at end of file