re-enabliing ajaxifyAttachHref for some CSRF & XSS lessons. Some cleanup along the way
This commit is contained in:
parent
a36697bf0d
commit
6307f102f0
@ -40,59 +40,13 @@ define(['jquery',
|
|||||||
// returning anything other than false will allow the form submit to continue
|
// returning anything other than false will allow the form submit to continue
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
// post-submit callback
|
|
||||||
showResponse: function(responseText, statusText, xhr, $form) {
|
|
||||||
// for normal html responses, the first argument to the success callback
|
|
||||||
// is the XMLHttpRequest object's responseText property
|
|
||||||
|
|
||||||
// if the ajaxForm method was passed an Options Object with the dataType
|
|
||||||
// property set to 'xml' then the first argument to the success callback
|
|
||||||
// is the XMLHttpRequest object's responseXML property
|
|
||||||
|
|
||||||
// if the ajaxForm method was passed an Options Object with the dataType
|
|
||||||
// property set to 'json' then the first argument to the success callback
|
|
||||||
// is the json data object returned by the server
|
|
||||||
if (GoatUtils.debugFormSubmission) {
|
|
||||||
alert('status: ' + statusText + '\n\nresponseText: \n' + responseText +
|
|
||||||
'\n\nThe output div should have already been updated with the responseText.');
|
|
||||||
}
|
|
||||||
// update lesson cookies and params
|
|
||||||
// make any embedded forms ajaxy
|
|
||||||
GoatUtils.showLessonCookiesAndParams();
|
|
||||||
// forms and links are now hooked with each standard lesson render (see Java class Screen.getContent())
|
|
||||||
// but these are safe to call twice
|
|
||||||
GoatUtils.makeFormsAjax();
|
|
||||||
GoatUtils.ajaxifyAttackHref(); //TODO find some way to hook scope for current menu. Likely needs larger refactor which is already started/stashed
|
|
||||||
//refresh menu
|
|
||||||
angular.element($('#leftside-navigation')).scope().renderMenu();
|
|
||||||
},
|
|
||||||
makeFormsAjax: function() {
|
|
||||||
// make all forms ajax forms
|
|
||||||
var options = {
|
|
||||||
target: '#lesson_content', // target element(s) to be updated with server response
|
|
||||||
beforeSubmit: GoatUtils.showRequest, // pre-submit callback, comment out after debugging
|
|
||||||
success: GoatUtils.showResponse // post-submit callback, comment out after debugging
|
|
||||||
|
|
||||||
// other available options:
|
|
||||||
//url: url // override for form's 'action' attribute
|
|
||||||
//type: type // 'get' or 'post', override for form's 'method' attribute
|
|
||||||
//dataType: null // 'xml', 'script', or 'json' (expected server response type)
|
|
||||||
//clearForm: true // clear all form fields after successful submit
|
|
||||||
//resetForm: true // reset the form after successful submit
|
|
||||||
|
|
||||||
// $.ajax options can be used here too, for example:
|
|
||||||
//timeout: 3000
|
|
||||||
};
|
|
||||||
//console.log("Hooking any lesson forms to make them ajax");
|
|
||||||
$("form").ajaxForm(options);
|
|
||||||
},
|
|
||||||
displayButton: function(id, show) {
|
displayButton: function(id, show) {
|
||||||
if ($('#' + id)) {
|
if ($('#' + id)) {
|
||||||
if (show) {
|
if (show) {
|
||||||
$('#' + id).show();
|
$('#' + id).show();
|
||||||
} else {
|
} else {
|
||||||
$('#' + id).hide();
|
a }
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -128,19 +82,6 @@ define(['jquery',
|
|||||||
$('#' + id).parent().addClass(goatConstants.selectedMenuClass);
|
$('#' + id).parent().addClass(goatConstants.selectedMenuClass);
|
||||||
},
|
},
|
||||||
|
|
||||||
ajaxifyAttackHref: function() { // rewrite any links with hrefs point to relative attack URLs
|
|
||||||
$.each($('a[href^="attack?"]'),
|
|
||||||
function(i,el) {
|
|
||||||
var url = $(el).attr('href');
|
|
||||||
$(el).unbind('click').attr('href','#').attr('link',url);
|
|
||||||
//TODO pull currentMenuId
|
|
||||||
$(el).click(function() {
|
|
||||||
event.preventDefault();
|
|
||||||
var _url = $(el).attr('link');
|
|
||||||
$.get(_url, {success:showResponse});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return goatUtils;
|
return goatUtils;
|
||||||
|
@ -13,13 +13,11 @@ function($,_,Backbone,JQueryForm,LessonData) {
|
|||||||
render: function() {
|
render: function() {
|
||||||
this.$el.html(this.model.get('content'));
|
this.$el.html(this.model.get('content'));
|
||||||
this.makeFormsAjax();
|
this.makeFormsAjax();
|
||||||
|
this.ajaxifyAttackHref();
|
||||||
},
|
},
|
||||||
//TODO: reimplement this in custom fashion maybe?
|
//TODO: reimplement this in custom fashion maybe?
|
||||||
makeFormsAjax: function () {
|
makeFormsAjax: function () {
|
||||||
var options = {
|
var options = {
|
||||||
//target: '#lesson_content', // target element(s) to be updated with server response
|
|
||||||
//beforeSubmit: GoatUtils.showRequest, // pre-submit callback, comment out after debugging
|
|
||||||
//success: GoatUtils.showResponse // post-submit callback, comment out after debugging
|
|
||||||
success:this.reLoadView.bind(this),
|
success:this.reLoadView.bind(this),
|
||||||
url:'attack?Screen=' + this.model.get('screenParam') + '&menu=' + this.model.get('menuParam'),
|
url:'attack?Screen=' + this.model.get('screenParam') + '&menu=' + this.model.get('menuParam'),
|
||||||
type:'GET'
|
type:'GET'
|
||||||
@ -29,6 +27,21 @@ function($,_,Backbone,JQueryForm,LessonData) {
|
|||||||
//hook forms //TODO: clarify form selectors later
|
//hook forms //TODO: clarify form selectors later
|
||||||
$("form").ajaxForm(options);
|
$("form").ajaxForm(options);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
ajaxifyAttackHref: function() { // rewrite any links with hrefs point to relative attack URLs
|
||||||
|
var self = this;
|
||||||
|
$.each($('a[href^="attack?"]'),function(i,el) {
|
||||||
|
var url = $(el).attr('href');
|
||||||
|
$(el).unbind('click').attr('href','#').attr('link',url);
|
||||||
|
//TODO pull currentMenuId
|
||||||
|
$(el).click(function() {
|
||||||
|
event.preventDefault();
|
||||||
|
var _url = $(el).attr('link');
|
||||||
|
$.get(_url, {success:self.reloadView.bind(self)});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
reLoadView: function(content) {
|
reLoadView: function(content) {
|
||||||
this.model.setContent(content);
|
this.model.setContent(content);
|
||||||
this.render();
|
this.render();
|
||||||
|
@ -1,35 +0,0 @@
|
|||||||
//goatConstants
|
|
||||||
|
|
||||||
var goatConstants = {
|
|
||||||
CATEGORYCLASS:'fa-angle-right pull-right',
|
|
||||||
lessonCompleteClass:'glyphicon glyphicon-check lessonComplete',
|
|
||||||
selectedMenuClass:'selected',
|
|
||||||
keepOpenClass:'keepOpen',
|
|
||||||
menuPrefix : [
|
|
||||||
{
|
|
||||||
name:'LESSONS',
|
|
||||||
type:'STATIC',
|
|
||||||
complete:false,
|
|
||||||
link:'',
|
|
||||||
children:null,
|
|
||||||
class:'fa-bars static'
|
|
||||||
}],
|
|
||||||
//services
|
|
||||||
lessonService: 'service/lessonmenu.mvc',
|
|
||||||
cookieService: 'service/cookie.mvc', //cookies_widget.mvc
|
|
||||||
hintService:'service/hint.mvc',
|
|
||||||
sourceService:'service/source.mvc',
|
|
||||||
solutionService:'service/solution.mvc',
|
|
||||||
lessonPlanService:'service/lessonplan.mvc',
|
|
||||||
menuService: 'service/lessonmenu.mvc',
|
|
||||||
lessonTitleService: 'service/lessontitle.mvc',
|
|
||||||
restartLessonService: 'service/restartlesson.mvc',
|
|
||||||
|
|
||||||
// literal messages
|
|
||||||
notFound: 'Could not find',
|
|
||||||
noHints: 'There are no hints defined.',
|
|
||||||
noSourcePulled: 'No source was retrieved for this lesson'
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
@ -1,265 +0,0 @@
|
|||||||
//main goat application file
|
|
||||||
//TODO: reorg
|
|
||||||
|
|
||||||
/* ### GOAT CONTROLLERS ### */
|
|
||||||
|
|
||||||
/* menu controller */
|
|
||||||
var goatMenu = function($scope, $http, $modal, $log, $templateCache) {
|
|
||||||
$scope.cookies = [];
|
|
||||||
$scope.params = [];
|
|
||||||
$scope.renderMenu = function() {
|
|
||||||
goat.data.loadMenu($http).then(//$http({method: 'GET', url: goatConstants.lessonService})
|
|
||||||
function(menuData) {
|
|
||||||
var menuItems = goat.utils.addMenuClasses(goatConstants.menuPrefix.concat(menuData.data));
|
|
||||||
//top-tier 'categories'
|
|
||||||
for (var i = 0; i < menuItems.length; i++) {
|
|
||||||
menuItems[i].id = goat.utils.makeId(menuItems[i].name);//TODO move the replace routine into util function
|
|
||||||
menuItems[i].displayClass = ($scope.openMenu === menuItems[i].id) ? goatConstants.keepOpenClass : '';
|
|
||||||
if (menuItems[i].children) {
|
|
||||||
for (var j = 0; j < menuItems[i].children.length; j++) {
|
|
||||||
menuItems[i].children[j].id = goat.utils.makeId(menuItems[i].children[j].name);
|
|
||||||
//handle selected Menu state
|
|
||||||
if (menuItems[i].children[j].id === $scope.curMenuItemSelected) {
|
|
||||||
menuItems[i].children[j].selectedClass = goatConstants.selectedMenuClass;
|
|
||||||
menuItems[i].selectedClass = goatConstants.selectedMenuClass;
|
|
||||||
}
|
|
||||||
//handle complete state
|
|
||||||
if (menuItems[i].children[j].complete) {
|
|
||||||
menuItems[i].children[j].completeClass = goatConstants.lessonCompleteClass;
|
|
||||||
} else {
|
|
||||||
menuItems[i].children[j].completeClass = '';
|
|
||||||
}
|
|
||||||
if (menuItems[i].children[j].children) {
|
|
||||||
for (var k = 0; k < menuItems[i].children[j].children.length; k++) {
|
|
||||||
//TODO make utility function for name >> id
|
|
||||||
menuItems[i].children[j].children[k].id = goat.utils.makeId(menuItems[i].children[j].children[k].name);
|
|
||||||
//menuItems[i].children[j].children[k].id = menuItems[i].children[j].children[k].name.replace(/\s|\(|\)/g,'');
|
|
||||||
//handle selected Menu state
|
|
||||||
if (menuItems[i].children[j].children[k].id === $scope.curMenuItemSelected) {
|
|
||||||
menuItems[i].children[j].children[k].selectedClass = goatConstants.selectedMenuClass;
|
|
||||||
menuItems[i].children[j].selectedClass = goatConstants.selectedMenuClass;
|
|
||||||
}
|
|
||||||
//handle complete state
|
|
||||||
if (menuItems[i].children[j].children[k].complete) {
|
|
||||||
menuItems[i].children[j].children[k].completeClass = goatConstants.lessonCompleteClass;
|
|
||||||
} else {
|
|
||||||
menuItems[i].children[j].children[k].completeClass = ''
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$scope.menuTopics = menuItems;
|
|
||||||
//
|
|
||||||
if ($scope.openMenu) {
|
|
||||||
$('ul' + $scope.openMenu).show();
|
|
||||||
}
|
|
||||||
|
|
||||||
},
|
|
||||||
function(error) {
|
|
||||||
// TODO - handle this some way other than an alert
|
|
||||||
console.error("Error rendering menu: " + error);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
$scope.renderLesson = function(id, url, showControls) {//TODO convert to single object parameter
|
|
||||||
$scope.hintIndex = 0;
|
|
||||||
var curScope = $scope;
|
|
||||||
$('.lessonHelp').hide();
|
|
||||||
// clean up menus, mark selected
|
|
||||||
$scope.curMenuItemSelected = id;
|
|
||||||
goat.utils.highlightCurrentLessonMenu(id);
|
|
||||||
curScope.parameters = goat.utils.scrapeParams(url);
|
|
||||||
// lesson content
|
|
||||||
goat.data.loadLessonContent($http, url).then(
|
|
||||||
function(reply) {
|
|
||||||
goat.data.loadLessonTitle($http).then(
|
|
||||||
function(reply) {
|
|
||||||
$("#lessonTitle").text(reply.data);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
//TODO encode html or get angular js portion working
|
|
||||||
$("#lesson_content").html(reply.data);
|
|
||||||
//hook forms and links (safe to call twice)
|
|
||||||
// links are hooked with each lesson now (see Java class Screen.getContent())
|
|
||||||
goat.utils.makeFormsAjax();// inject form?
|
|
||||||
goat.utils.ajaxifyAttackHref();
|
|
||||||
$('#leftside-navigation').height($('#main-content').height() + 15)//TODO: get ride of fixed value (15)here
|
|
||||||
//notifies goatLesson Controller of the less change
|
|
||||||
$scope.$emit('lessonUpdate', {params: curScope.parameters, 'showControls': showControls});
|
|
||||||
}
|
|
||||||
)
|
|
||||||
$scope.renderMenu();
|
|
||||||
};
|
|
||||||
$scope.accordionMenu = function(id) {
|
|
||||||
if ($('ul#' + id).attr('isOpen') == 0) {
|
|
||||||
$scope.expandMe = true;
|
|
||||||
} else {
|
|
||||||
$('ul#' + id).slideUp(300).attr('isOpen', 0);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
$scope.openMenu = id;
|
|
||||||
$('.lessonsAndStages').not('ul#' + id).slideUp(300).attr('isOpen', 0);
|
|
||||||
if ($scope.expandMe) {
|
|
||||||
$('ul#' + id).slideDown(300).attr('isOpen', 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$scope.renderMenu();
|
|
||||||
// runs on first loadcan be augmented later to '
|
|
||||||
// resume' for a given user ... currently kluged to start at fixed lesson
|
|
||||||
var url = 'attack?Screen=32&menu=5';
|
|
||||||
angular.element($('#leftside-navigation')).scope().renderLesson(null, url);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* lesson controller */
|
|
||||||
var goatLesson = function($scope, $http, $log) {
|
|
||||||
|
|
||||||
$('#hintsView').hide();
|
|
||||||
// adjust menu to lessonContent size if necssary
|
|
||||||
//cookies
|
|
||||||
|
|
||||||
$scope.$on('lessonUpdate', function(params) {
|
|
||||||
$scope.parameters = arguments[1].params;
|
|
||||||
$scope.showHints = (arguments[1].showControls && arguments[1].showControls.showHints);
|
|
||||||
$scope.showSource = (arguments[1].showControls && arguments[1].showControls.showSource);
|
|
||||||
curScope = $scope; //TODO .. update below, this curScope is probably not needed
|
|
||||||
goat.data.loadCookies($http).then(
|
|
||||||
function(resp) {
|
|
||||||
curScope.cookies = resp.data;
|
|
||||||
}
|
|
||||||
);
|
|
||||||
//hints
|
|
||||||
curScope.hintIndex = 0;
|
|
||||||
if ($scope.showHints) {
|
|
||||||
goat.data.loadHints($http).then(
|
|
||||||
function(resp) {
|
|
||||||
curScope.hints = resp.data;
|
|
||||||
if (curScope.hints.length > 0 && curScope.hints[0].hint.indexOf(goatConstants.noHints) === -1) {
|
|
||||||
goat.utils.displayButton('showHintsBtn', true);
|
|
||||||
} else {
|
|
||||||
goat.utils.displayButton('showHintsBtn', false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
$scope.hints = null;
|
|
||||||
goat.utils.displayButton('showHintsBtn', false);
|
|
||||||
}
|
|
||||||
//source
|
|
||||||
if ($scope.showSource) {
|
|
||||||
goat.data.loadSource($http).then(
|
|
||||||
function(resp) {
|
|
||||||
curScope.source = resp.data;
|
|
||||||
}
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
$scope.source = goatConstants.noSourcePulled;
|
|
||||||
}
|
|
||||||
|
|
||||||
//plan
|
|
||||||
goat.data.loadPlan($http).then(
|
|
||||||
function(resp) {
|
|
||||||
curScope.plan = resp.data;
|
|
||||||
}
|
|
||||||
);
|
|
||||||
//solution
|
|
||||||
goat.data.loadSolution($http).then(
|
|
||||||
function(resp) {
|
|
||||||
curScope.solution = resp.data;
|
|
||||||
}
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
//goat.utils.scrollToTop();
|
|
||||||
|
|
||||||
|
|
||||||
$scope.showLessonSource = function() {
|
|
||||||
$('.lessonHelp').hide();
|
|
||||||
$('#lesson_source_row').show();
|
|
||||||
goat.utils.scrollToHelp();
|
|
||||||
}
|
|
||||||
|
|
||||||
$scope.showLessonPlan = function() {
|
|
||||||
$('.lessonHelp').hide();
|
|
||||||
$("#lesson_plan").html($scope.plan);
|
|
||||||
$('#lesson_plan_row').show();
|
|
||||||
goat.utils.scrollToHelp();
|
|
||||||
}
|
|
||||||
|
|
||||||
$scope.showLessonSolution = function() {
|
|
||||||
$('.lessonHelp').hide();
|
|
||||||
$("#lesson_solution").html($scope.solution);
|
|
||||||
$('#lesson_solution_row').show();
|
|
||||||
goat.utils.scrollToHelp();
|
|
||||||
}
|
|
||||||
|
|
||||||
$scope.manageHintButtons = function() {
|
|
||||||
if ($scope.hintIndex === $scope.hints.length - 1) {
|
|
||||||
$('#showNextHintBtn').css('visibility', 'hidden');
|
|
||||||
} else if ($scope.hintIndex < $scope.hints.length - 1) {
|
|
||||||
$('#showNextHintBtn').css('visibility', 'visible');
|
|
||||||
}
|
|
||||||
//
|
|
||||||
if ($scope.hintIndex === 0) {
|
|
||||||
$('#showPrevHintBtn').css('visibility', 'hidden');
|
|
||||||
} else if ($scope.hintIndex > 0) {
|
|
||||||
$('#showPrevHintBtn').css('visibility', 'visible');
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
$scope.viewHints = function() {
|
|
||||||
if (!$scope.hints) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$('.lessonHelp').hide();
|
|
||||||
$('#lesson_hint_row').show();
|
|
||||||
//goat.utils.scrollToHelp();
|
|
||||||
//TODO
|
|
||||||
$scope.curHint = $scope.hints[$scope.hintIndex].hint;
|
|
||||||
//$scope.curHint = $sce.trustAsHtml($scope.hints[$scope.hintIndex].hint);
|
|
||||||
//TODO get html binding workin in the UI ... in the meantime ...
|
|
||||||
//$scope.renderCurHint();
|
|
||||||
$scope.manageHintButtons();
|
|
||||||
};
|
|
||||||
|
|
||||||
$scope.viewNextHint = function() {
|
|
||||||
$scope.hintIndex++;
|
|
||||||
$scope.curHint = $scope.hints[$scope.hintIndex].hint;
|
|
||||||
$scope.renderCurHint();
|
|
||||||
$scope.manageHintButtons();
|
|
||||||
};
|
|
||||||
|
|
||||||
$scope.viewPrevHint = function() {
|
|
||||||
$scope.hintIndex--;
|
|
||||||
$scope.curHint = $scope.hints[$scope.hintIndex].hint;
|
|
||||||
$scope.renderCurHint();
|
|
||||||
$scope.manageHintButtons();
|
|
||||||
};
|
|
||||||
|
|
||||||
$scope.renderCurHint = function() {
|
|
||||||
$('#curHintContainer').html($scope.curHint);
|
|
||||||
}
|
|
||||||
|
|
||||||
$scope.hideHints = function() {
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
$scope.restartLesson = function() {
|
|
||||||
goat.data.loadRestart($http).then(
|
|
||||||
function(resp) {
|
|
||||||
angular.element($('#leftside-navigation')).scope().renderLesson(null, resp.data, {showSource: $scope.showSource, showHints: $scope.showHints});
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
$scope.showAbout = function() {
|
|
||||||
$('#aboutModal').modal({
|
|
||||||
//remote: 'about.mvc'
|
|
||||||
});
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
@ -1,44 +0,0 @@
|
|||||||
/* ### GOAT DATA/PROMISES ### */
|
|
||||||
|
|
||||||
goat.data = {
|
|
||||||
/**** jQuery loads ... ****/
|
|
||||||
loadLessonContent: function ($http,_url) {
|
|
||||||
//TODO: switch to $http (angular) later
|
|
||||||
return $http({method:'GET', url: _url});
|
|
||||||
//return $.get(_url, {}, null, "html");
|
|
||||||
},
|
|
||||||
loadCookies: function($http) {
|
|
||||||
return $http({method: 'GET', url: goatConstants.cookieService});
|
|
||||||
//return $.get(goatConstants.cookieService, {});
|
|
||||||
},
|
|
||||||
loadHints: function ($http) {
|
|
||||||
return $http({method: 'GET', url: goatConstants.hintService});
|
|
||||||
//return $.get(goatConstants.hintService, {});
|
|
||||||
},
|
|
||||||
loadSource: function($http) {
|
|
||||||
return $http({method: 'GET', url: goatConstants.sourceService});
|
|
||||||
//return $.get(goatConstants.sourceService, {});
|
|
||||||
},
|
|
||||||
loadSolution: function ($http) {
|
|
||||||
return $http({method: 'GET', url: goatConstants.solutionService});
|
|
||||||
//return $.get(goatConstants.solutionService, {});
|
|
||||||
},
|
|
||||||
loadPlan: function ($http) {
|
|
||||||
return $http({method: 'GET', url: goatConstants.lessonPlanService});
|
|
||||||
//return $.get(goatConstants.lessonPlanService, {});
|
|
||||||
},
|
|
||||||
loadParams: function($http) {
|
|
||||||
return $http({method: 'GET', url: goatConstants.paramsService});
|
|
||||||
//return $.get(goatConstants.paramsService,{});
|
|
||||||
},
|
|
||||||
loadMenu: function($http) {
|
|
||||||
return $http({method: 'GET', url: goatConstants.lessonService});
|
|
||||||
},
|
|
||||||
loadLessonTitle: function ($http) {
|
|
||||||
return $http({method: 'GET', url: goatConstants.lessonTitleService});
|
|
||||||
},
|
|
||||||
loadRestart: function ($http) {
|
|
||||||
return $http({method: 'GET', url:goatConstants.restartLessonService})
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
@ -1,110 +0,0 @@
|
|||||||
// goat.lesson name space
|
|
||||||
goat.lesson = {
|
|
||||||
CurLesson: function(_lessonUrl) {
|
|
||||||
return {
|
|
||||||
hints:[],
|
|
||||||
hintIndex:0,
|
|
||||||
solution:null,
|
|
||||||
plan:null,
|
|
||||||
cookiesAndParams:[],
|
|
||||||
params:[],
|
|
||||||
source:null,
|
|
||||||
lessonUrl:(_lessonUrl || null),
|
|
||||||
clearInfo: function() {
|
|
||||||
this.hints = null;
|
|
||||||
this.solution = null;
|
|
||||||
this.plan = null;
|
|
||||||
this.cookies = null;
|
|
||||||
this.source = null;
|
|
||||||
this.params = null;
|
|
||||||
},
|
|
||||||
loadInfo: function() {
|
|
||||||
this.getHints();
|
|
||||||
this.getPlan();
|
|
||||||
this.getSolution();
|
|
||||||
this.getCookies();
|
|
||||||
this.getSource();
|
|
||||||
this.getParams();
|
|
||||||
},
|
|
||||||
getHints:function() {
|
|
||||||
var scope = this;
|
|
||||||
goat.data.loadHints().then(
|
|
||||||
function(resp) {
|
|
||||||
scope.hints = resp.data;
|
|
||||||
if (scope.hints.length > 0 && scope.hints[0].hint.indexOf(goatConstants.noHints) === -1) {
|
|
||||||
goat.utils.displayButton('showHintsBtn',true);
|
|
||||||
} else {
|
|
||||||
goat.utils.displayButton('showHintsBtn',false);
|
|
||||||
}
|
|
||||||
return scope;
|
|
||||||
},
|
|
||||||
function(err){
|
|
||||||
goat.utils.displayButton('showHintsBtn',false);
|
|
||||||
//TODO handle errors
|
|
||||||
}
|
|
||||||
);
|
|
||||||
},
|
|
||||||
getSolution:function() {
|
|
||||||
var scope = this;
|
|
||||||
goat.data.loadSolution().then(
|
|
||||||
function(resp) {
|
|
||||||
scope.solution = resp.data;
|
|
||||||
goat.utils.displayButton('showSolutionBtn',true);
|
|
||||||
$('#showSolutionBtn').unbind().click(goat.utils.showLessonSolution);
|
|
||||||
return scope;
|
|
||||||
},
|
|
||||||
function(err){
|
|
||||||
scope.solution = null;
|
|
||||||
goat.utils.displayButton('showSolutionBtn',false);
|
|
||||||
//TODO handle errors
|
|
||||||
}
|
|
||||||
);
|
|
||||||
},
|
|
||||||
getPlan: function() {
|
|
||||||
var scope = this;
|
|
||||||
goat.data.loadPlan().then(
|
|
||||||
function(resp) {
|
|
||||||
scope.plan = resp.data;
|
|
||||||
goat.utils.displayButton('showPlanBtn',true);
|
|
||||||
$('#showPlanBtn').unbind().click(goat.utils.showLessonPlan);
|
|
||||||
return scope;
|
|
||||||
},
|
|
||||||
function(err){
|
|
||||||
goat.utils.displayButton('showPlanBtn',false);
|
|
||||||
//TODO handle errors
|
|
||||||
}
|
|
||||||
);
|
|
||||||
},
|
|
||||||
getSource: function() {
|
|
||||||
var scope = this;
|
|
||||||
goat.data.loadSource().then(
|
|
||||||
function(resp) {
|
|
||||||
scope.source = resp.data;
|
|
||||||
goat.utils.displayButton('showSourceBtn',true);
|
|
||||||
$('#showSourceBtn').unbind().click(goat.utils.showLessonSource);
|
|
||||||
return scope;
|
|
||||||
},
|
|
||||||
function(err){
|
|
||||||
goat.utils.displayButton('showSourceBtn',false);
|
|
||||||
//TODO handle errors
|
|
||||||
}
|
|
||||||
);
|
|
||||||
},
|
|
||||||
getCookies: function() {
|
|
||||||
var scope = this;
|
|
||||||
goat.data.loadCookies().then(
|
|
||||||
function(resp) {
|
|
||||||
scope.cookies = resp.data;
|
|
||||||
return scope;
|
|
||||||
},
|
|
||||||
function(err){
|
|
||||||
//TODO handle errors
|
|
||||||
}
|
|
||||||
);
|
|
||||||
},
|
|
||||||
getParams: function() {
|
|
||||||
this.params = goat.utils.scrapeParams(this.lessonUrl);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
@ -1,59 +0,0 @@
|
|||||||
// Logout and Help Swap Image
|
|
||||||
|
|
||||||
function MM_reloadPage(init) { //reloads the window if Nav4 resized
|
|
||||||
if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
|
|
||||||
document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
|
|
||||||
else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
|
|
||||||
}
|
|
||||||
MM_reloadPage(true);
|
|
||||||
|
|
||||||
function MM_swapImgRestore() { //v3.0
|
|
||||||
var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
|
|
||||||
}
|
|
||||||
|
|
||||||
function MM_swapImage() { //v3.0
|
|
||||||
var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
|
|
||||||
if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Lesson Nav bar image swapping
|
|
||||||
|
|
||||||
function MM_preloadImages() { //v3.0
|
|
||||||
var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
|
|
||||||
var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
|
|
||||||
if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
|
|
||||||
}
|
|
||||||
|
|
||||||
function MM_nbGroup(event, grpName) { //v6.0
|
|
||||||
var i,img,nbArr,args=MM_nbGroup.arguments;
|
|
||||||
if (event == "init" && args.length > 2) {
|
|
||||||
if ((img = MM_findObj(args[2])) != null && !img.MM_init) {
|
|
||||||
img.MM_init = true; img.MM_up = args[3]; img.MM_dn = img.src;
|
|
||||||
if ((nbArr = document[grpName]) == null) nbArr = document[grpName] = new Array();
|
|
||||||
nbArr[nbArr.length] = img;
|
|
||||||
for (i=4; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
|
|
||||||
if (!img.MM_up) img.MM_up = img.src;
|
|
||||||
img.src = img.MM_dn = args[i+1];
|
|
||||||
nbArr[nbArr.length] = img;
|
|
||||||
} }
|
|
||||||
} else if (event == "over") {
|
|
||||||
document.MM_nbOver = nbArr = new Array();
|
|
||||||
for (i=1; i < args.length-1; i+=3) if ((img = MM_findObj(args[i])) != null) {
|
|
||||||
if (!img.MM_up) img.MM_up = img.src;
|
|
||||||
img.src = (img.MM_dn && args[i+2]) ? args[i+2] : ((args[i+1])? args[i+1] : img.MM_up);
|
|
||||||
nbArr[nbArr.length] = img;
|
|
||||||
}
|
|
||||||
} else if (event == "out" ) {
|
|
||||||
for (i=0; i < document.MM_nbOver.length; i++) {
|
|
||||||
img = document.MM_nbOver[i]; img.src = (img.MM_dn) ? img.MM_dn : img.MM_up; }
|
|
||||||
} else if (event == "down") {
|
|
||||||
nbArr = document[grpName];
|
|
||||||
if (nbArr)
|
|
||||||
for (i=0; i < nbArr.length; i++) { img=nbArr[i]; img.src = img.MM_up; img.MM_dn = 0; }
|
|
||||||
document[grpName] = nbArr = new Array();
|
|
||||||
for (i=2; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
|
|
||||||
if (!img.MM_up) img.MM_up = img.src;
|
|
||||||
img.src = img.MM_dn = (args[i+1])? args[i+1] : img.MM_up;
|
|
||||||
nbArr[nbArr.length] = img;
|
|
||||||
} }
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user