Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 49 additions & 45 deletions app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,57 +130,61 @@ app.directive('spChallenge', function($compile, UserFactory) {
// Set up an iframe to run code in
var iframe = $('<iframe>');
$('body').append(iframe);
iframe.contents().find('body').append(assignment.html);
var frameWindow = iframe[0].contentWindow;

if(assignment.prepare) {
assignment.prepare(frameWindow);
}
var interval = setInterval(() => {
if(frameWindow.document.readyState === 'complete') {
clearInterval(interval);

// Load jQuery
if(assignment.jquery) {
var jquerySource = '';
var f = $.ajax('static/js/jquery.js', {
async: false,
cache: true,
success: function(data) {
jquerySource = data;
}
});
frameWindow.eval(jquerySource);
}
iframe.contents().find('body').append(assignment.html);

try {

// Run the code!
frameWindow.eval(user_code);

// Test the return value
var returnValue = frameWindow.eval(assignment.return);
assignment.tester(returnValue, user_code);

// No error, complete the assignment!
UserFactory.completeAssignment(assignment.id, assignment.points);

$scope.completed = true;
$scope.element.find('.live_assignment').addClass('completed');
$scope.element.find('.complete')
.slideDown()
.delay(1000)
.slideUp();

} catch(e) {
// Show error to user
$scope.element.find('.error').html("Error: " + e)
.slideDown()
.delay(3000)
.slideUp();
} finally {
iframe.remove();
}
}
if(assignment.prepare) {
assignment.prepare(frameWindow);
}

// Load jQuery
if(assignment.jquery) {
var jquerySource = '';
var f = $.ajax('static/js/jquery.js', {
async: false,
cache: true,
success: function(data) {
jquerySource = data;
}
});
frameWindow.eval(jquerySource);
}

try {
// Run the code!
frameWindow.eval(user_code);

// Test the return value
var returnValue = frameWindow.eval(assignment.return);
assignment.tester(returnValue, user_code);

// No error, complete the assignment!
UserFactory.completeAssignment(assignment.id, assignment.points);

$scope.completed = true;
$scope.element.find('.live_assignment').addClass('completed');
$scope.element.find('.complete')
.slideDown()
.delay(1000)
.slideUp();

} catch(e) {
// Show error to user
$scope.element.find('.error').html("Error: " + e)
.slideDown()
.delay(3000)
.slideUp();
} finally {
iframe.remove();
}
}
}, 50);
}
}
};
});
Expand Down
2 changes: 0 additions & 2 deletions jquery/opdrachten.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ <h1>Opdrachten week 2</h1>

<p>Welkom terug bij week 2! Deze week gaan we oefenen met jQuery, één van de meest populaire JavaScript libraries. In de presentatie van deze week en vorige week staan alle voorbeelden die je nodig hebt om de opdrachten te maken.</p>

<p><em>Onderstaande challenges kan je helaas niet maken met Firefox</em></p>

<sp-challenge assignment="jquery_changecolor"></sp-challenge>
<sp-challenge assignment="jquery_hide"></sp-challenge>
<sp-challenge assignment="jquery_delegated"></sp-challenge>
Expand Down