Skip to content

Commit be4c5ee

Browse files
committed
Working multiple console challenges, each with their own editor
1 parent df6390d commit be4c5ee

39 files changed

Lines changed: 32436 additions & 31480 deletions

bower.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
"codemirror": "~3.16.0",
2222
"abecedary": "~0.0.5",
2323
"mocha": "~2.2.1",
24-
"lodash": "~3.5.0"
24+
"lodash": "~3.5.0",
25+
"angular-resource": "~1.3.15",
26+
"marked": "~0.3.3"
2527
}
2628
}

client/javascriptcom/app.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1-
angular.module('javascriptcom', []);
1+
angular.module('javascriptcom', ['ngResource'])
2+
.config(['$httpProvider', function config($httpProvider) {
3+
$httpProvider.defaults.cache = true;
4+
}]);
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
angular.module('javascriptcom').directive('jsChallenge', [function() {
2+
return {
3+
templateUrl: 'javascripts/javascriptcom/templates/challenge.html',
4+
replace: true,
5+
scope: {
6+
challenge: '='
7+
},
8+
bindToController: true,
9+
controllerAs: 'ctrl',
10+
controller: function jsChallengeController() {
11+
this.isActive = function() {
12+
return this.challenge.active;
13+
}
14+
}
15+
};
16+
}]);
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
angular.module('javascriptcom').directive('jsConsole', ['CSConsole', 'jsCommand', 'jsChallengeProgress', function(CSConsole, jsCommand, jsChallengeProgress) {
2+
return {
3+
templateUrl: 'javascripts/javascriptcom/templates/console.html',
4+
replace: true,
5+
scope: {
6+
challenge: '='
7+
},
8+
bindToController: true,
9+
controllerAs: 'ctrl',
10+
link: function(scope, element) {
11+
function onConsoleSuccess() {
12+
scope.challenge.completed = true;
13+
jsChallengeProgress.next();
14+
}
15+
function onConsoleError() { }
16+
17+
var el = $(element).find('.console-ui')[0];
18+
var command = new jsCommand(scope.challenge, onConsoleSuccess, onConsoleError);
19+
20+
var console = new CSConsole(el, {
21+
prompt: '> ',
22+
syntax: 'javascript',
23+
autoFocus: true,
24+
welcomeMessage: 'Type `help` to see the help menu',
25+
commandValidate: command.validate,
26+
commandHandle: command.handler
27+
});
28+
}
29+
};
30+
}]);
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
angular.module('javascriptcom').directive('jsCourse', ['_', 'jsCourseChallengeResource', 'jsChallengeProgress', function(_, jsCourseChallengeResource, jsChallengeProgress) {
2+
return {
3+
replace: true,
4+
templateUrl: 'javascripts/javascriptcom/templates/course.html',
5+
scope: {
6+
course: '@'
7+
},
8+
bindToController: true,
9+
controllerAs: 'ctrl',
10+
controller: function jsChallengeResourceController(jsCourseChallengeResource) {
11+
this.challenges = jsCourseChallengeResource.query({ course: this.course });
12+
jsChallengeProgress.setChallenges(this.challenges);
13+
}
14+
};
15+
}]);
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
angular.module('javascriptcom').directive('jsInstructions', function() {
2+
return {
3+
templateUrl: 'javascripts/javascriptcom/templates/instructions.html',
4+
replace: true,
5+
scope: {
6+
challenge: '='
7+
},
8+
bindToController: true,
9+
controllerAs: 'ctrl',
10+
controller: function() {}
11+
};
12+
});

client/javascriptcom/directives/jsConsole.js

Lines changed: 0 additions & 19 deletions
This file was deleted.

client/javascriptcom/directives/jsCourse.js

Lines changed: 0 additions & 14 deletions
This file was deleted.

client/javascriptcom/directives/jsInstructions.js

Lines changed: 0 additions & 9 deletions
This file was deleted.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
angular.module('javascriptcom').directive('jsSafeHtml', ['$sce', function SafeHtmlDirective($sce) {
2+
return {
3+
restrict: 'A',
4+
scope: {
5+
jsSafeHtml: "@"
6+
},
7+
template: "<div ng-bind-html='safeHtml'></div>",
8+
link: function(scope, element, attrs) {
9+
var unregister = scope.$watch('jsSafeHtml', setHtml);
10+
11+
function setHtml(value) {
12+
if(!value) { return; }
13+
scope.safeHtml = $sce.trustAsHtml(value.replace(/^\s+|\s+$/g, ''));
14+
unregister();
15+
}
16+
}
17+
};
18+
}]);

0 commit comments

Comments
 (0)