Skip to content

Commit

Permalink
supports download missing image button on first image while coding
Browse files Browse the repository at this point in the history
  • Loading branch information
rahulbot committed May 14, 2013
1 parent fdced18 commit 36f610c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
12 changes: 10 additions & 2 deletions app/assets/javascripts/coding.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,16 @@ $(document).ready(function () {
renderHighlightedAreas();

// after we slide for the next image, we normally initialize the imgAreaSelect for the new image, but before that, we also check if the user have a premonition
$('#downloadImageAlert').hide();
if (pageData.allowedToCode) {
// is the image was not found, it will not initialize the imgAreaSelect, and this not working in the heroku deployed version
if ( (current_img.attr("alt") == "404") || (current_img.attr('data-missing')=='true') ) {
$('#images_section div.active img').imgAreaSelect({handles: true,onSelectEnd: highlightingArea, disable:true});
$('#missing_image_id').val(current_img.attr('data-id'));
$('#downloadImageAlert').show();
}else{
$('#images_section div.active img').imgAreaSelect({handles: true,onSelectEnd: highlightingArea});
}
}
setMissingImageInfoFromImg(current_img);

// update the sidebar meta-data about the image
var source_url = $("#images_section div.active img").attr('url');
Expand Down Expand Up @@ -99,6 +98,15 @@ $(document).ready(function () {

});

function setMissingImageInfoFromImg(imgElem){
if(imgElem.attr('data-missing')=='true'){
$('#missing_image_id').val(imgElem.attr('data-id'));
$('#downloadImageAlert').show();
} else {
$('#downloadImageAlert').hide();
}
}

function markAsNothingToCode(){
var current_img = getCurrentImage();
// Clear existing areas
Expand Down
12 changes: 7 additions & 5 deletions app/views/coding/process_images.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -227,19 +227,21 @@ $(function() {
$("#coding").css("color","#fff")
$("#coding").attr("class", "btn btn-info");

// hide alerts
$('#youHaveLoopedAlert').hide();
$('#downloadImageAlert').hide();

// support auto-starting on the image the user clicked in the display view
if (pageData.startImageName.length != 0) {
$("#images_section div.active img").parent().attr("class", "item")
$("#images_section div img[name='"+pageData.startImageName+"']").parent().attr("class", "active item")
var startImage = $("#images_section div img[name='"+pageData.startImageName+"']");
startImage.parent().attr("class", "active item");
setMissingImageInfoFromImg(startImage);
};

// when the user click save, it will set the status to "0", to allow the form to be submitted
$(".save").click(function (e) { setModified(0) })

// hide alerts
$('#youHaveLoopedAlert').hide();
$('#downloadImageAlert').hide();

$(document).bind('keydown', 'left', function(){ $('#carouselPrevLink').click() });
$(document).bind('keydown', 'right', function(){ $('#carouselNextLink').click() });
$(document).bind('keydown', 'n', markAsNothingToCode);
Expand Down

0 comments on commit 36f610c

Please sign in to comment.