_.each(this.getQuestionComponents(), function(item, index) { var parent = Adapt.findById(item.get("_parentId")); //make array of questionModels var questionModel = { _quizBankID: parent.get('_quizBankID'), _isCorrect: item.get("_isCorrect"), title: item.get("title"), _id: item.get("_id"), _associatedLearning: _.clone(item.get("_associatedLearning")) }; //convert associatedlearning id array to element data object array if (typeof questionModel._associatedLearning !== "undefined") { for (var al = 0; al < questionModel._associatedLearning.length; al++) { var assoc = Adapt.findById(questionModel._associatedLearning[al]).toJSON(); questionModel._associatedLearning[al] = { _id: assoc._id, title: assoc.title }; } } else questionModel._associatedLearning = []; allQuestions[questionModel._id] = questionModel; if (!allBanks[questionModel._quizBankID]) allBanks[questionModel._quizBankID] = { allQuestions: {}, _quizBankID: questionModel._quizBankID }; allBanks[questionModel._quizBankID].allQuestions[questionModel._id] = questionModel; });
navigateAndDisableTrickleUpTo:function(id) { var model = Adapt.findById(id); var pageModel = Adapt.findById(Adapt.location._currentId); // first ensure page incomplete prompt won't activate this._disablePageIncompletePrompt(pageModel); // now navigate if (model._siblings == 'contentObjects') { Backbone.history.navigate("#/id/"+id, {trigger:true}); } else { var level = model.get('_type') == 'component' ? model.getParent() : model; var siblings = level.getParent().getChildren(), sibling = null; // disable trickle on all preceeding article(s)|block(s) for (var i=0, count=siblings.indexOf(level); i < count; i++) { sibling = siblings.at(i); console.log('disabling trickle on '+sibling.get('_id')); if (sibling.has('_trickle')) { sibling.get('_trickle')._isEnabled = false; } else { sibling.set('_trickle', {_isEnabled:false}); } } // check if already on page if (Adapt.location._currentId == model.findAncestor('contentObjects').get('_id')) { this.listenToOnce(Adapt, 'pageView:ready', function(view) { _.defer(_.bind(function() { Adapt.scrollTo($('.'+id)); this.checkVisibility(id); }, this)); }); if (Adapt.location._currentId == Adapt.course.get('_id')) Router.handleRoute ? Router.handleRoute() : Router.handleCourse(); else Router.handleId(Adapt.location._currentId); } else { this.listenToOnce(Adapt, 'pageView:ready', function() { _.defer(_.bind(function() { this.checkVisibility(id); }, this)); }); Backbone.history.navigate("#/id/"+id, {trigger:true}); } } // restore pageIncompletePrompt config this._restorePageIncompletePrompt(pageModel); this.invalidate(); },
navigateAndDisableTrickle:function(id) { var model = Adapt.findById(id); var pageModel = Adapt.findById(Adapt.location._currentId); // first ensure page incomplete prompt won't activate this._disablePageIncompletePrompt(pageModel); if (model._siblings == 'contentObjects') { Backbone.history.navigate("#/id/"+id, {trigger:true}); } else { // if already on page ensure trickle is disabled if (Adapt.location._currentId == model.findAncestor('contentObjects').get('_id')) { Adapt.devtools.set('_trickleEnabled', false); Adapt.scrollTo($('.'+id)); this.checkVisibility(id); } else { // pick target model to determine trickle config according to trickle version (2.1 or 2.0.x) var targetModel = Adapt.trickle ? model.findAncestor('contentObjects') : Adapt.course; // if necessary disable trickle (until page is ready) if (!targetModel.has('_trickle')) { targetModel.set('_trickle', {_isEnabled:false}); this.listenToOnce(Adapt, 'pageView:ready', function() { _.defer(_.bind(function() { targetModel.get('_trickle')._isEnabled = true; this.checkVisibility(id); }, this)); }); } else if (targetModel.get('_trickle')._isEnabled) { targetModel.get('_trickle')._isEnabled = false; this.listenToOnce(Adapt, 'pageView:ready', function() { _.defer(_.bind(function() { targetModel.get('_trickle')._isEnabled = true; this.checkVisibility(id); }, this)); }); } Backbone.history.navigate("#/id/"+id, {trigger:true}); } } // restore pageIncompletePrompt config this._restorePageIncompletePrompt(pageModel); this.invalidate(); },
handleId: function(id) { var currentModel = Adapt.findById(id); switch (currentModel.get('_type')) { case 'page': case 'menu': this.removeViews(); this.showLoading(); this.setContentObjectToVisited(currentModel); if (currentModel.get('_type') == 'page') { var location = 'page-' + id; this.updateLocation(location, 'page', id); Adapt.trigger('router:page', currentModel); this.$wrapper.append(new PageView({model:currentModel}).$el); } else { var location = 'menu-' + id; this.updateLocation(location, 'menu', id); Adapt.trigger('router:menu', currentModel); } break; default: Adapt.navigateToElement('.' + id); } },
fetchAdaptStructureFlat: function(id, parentFirst) { var model = Adapt.findById(id); if (model === undefined) return undefined; var struct = StructureType.fromString(model.get("_type")); if (struct._level === StructureType.levels) { return [model]; } var children = model.getChildren(); var ret = []; for (var i = 0, l = children.models.length; i < l; i++) { var child = children.models[i]; var struct = StructureType.fromString(child.get("_type")); if (struct._level === StructureType.levels) { ret.push(child); } else { var append = utils.fetchAdaptStructureFlat(child.get("_id"), parentFirst); if (parentFirst !== false) ret.push(child); ret = ret.concat(append); if (parentFirst === false) ret.push(child); } } return ret; },
_.each(_config._events, function(to, key) { var matches = key.split(" "); var eventName = matches.shift(); if (isMatchingScreenSize(_screenSize, matches)) { switch(eventName) { case "adapt:initialize": if (location.hash.substr(0,1) == "#" && location.hash.substr(0,2) == "#/" && location.hash > "#/") return; if (_.isArray(to)) { if (Adapt.findById(to[0]).get('_isComplete')) { console.info(to[0] + ' is complete so navigating to ' + to[1]); to = to[1]; } else { to = to[0]; } } break; } var replaceUrl = eventName == 'adapt:initialize'; _onRouteTo = _.bind(onRouteTo, undefined, Adapt, to, replaceUrl); Adapt.on(eventName, _onRouteTo); _attached.push({ $el: Adapt, eventName: eventName, callback: _onRouteTo }); } });
_.delay(function() { //ENABLED DOCUMENT READING $.a11y_on(true, '#wrapper'); //DO NOT FOCUS IF USER HAS ALREADY INTERACTED if ($.a11y.userInteracted) return; if (Adapt.location._currentId) { //required to stop JAWS from auto reading content in IE var currentModel = Adapt.findById(Adapt.location._currentId); var alertText = " "; switch (currentModel.get("_type")) { case "page": if (Adapt.course.get("_accessibility") && Adapt.course.get("_accessibility")._ariaLabels && Adapt.course.get("_accessibility")._ariaLabels.pageLoaded) { alertText = Adapt.course.get("_accessibility")._ariaLabels.pageLoaded; } break; case "menu": if (Adapt.course.get("_accessibility") && Adapt.course.get("_accessibility")._ariaLabels && Adapt.course.get("_accessibility")._ariaLabels.menuLoaded) { alertText = Adapt.course.get("_accessibility")._ariaLabels.menuLoaded; } break; } $.a11y_alert(alertText); } $.a11y_focus(); }, 1000);
toggleVisibility: function() { var model = Adapt.findById(Adapt.location._currentId); if (model.get('_quiz')) { this.$el.css({display:"block"}); } else { this.$el.css({display:"none"}); } }
var onRouteTo = function (item, to, replaceUrl, event) { if (event) { event.preventDefault(); event.stopPropagation(); } if (to.substr(0,1) == "#") { Adapt.trigger("remove"); Backbone.history.navigate(to, {trigger: true, replace: false}); } else if (to == "") { Adapt.trigger("remove"); Backbone.history.navigate("#/", {trigger: true, replace: false}); } else if (to.substr(0,1) == "@") { var sections = to.substr(1).split(" "); var type = sections[0]; var amount = eval( "0" + sections[1] + ";" ); var currentId = this.model.get("_id"); var currentType = this.model.get("_type"); var currentPage = resolveType(currentId, "page"); switch (type) { case "article": var currentArticle = resolveType(currentId, "article"); var toItem = resolveItem(item, currentPage, currentArticle, amount, "articles"); if (toItem === undefined) return; var next = $("." + toItem.get("_id")); if (next.length === 0) return; $.scrollTo(next.offset()['top'] - $('.navigation').height() - parseInt(next.css("margin-top")), {axis:'y', duration: 1000 }); break; case "block": var currentBlock = resolveType(currentId, "block"); var toItem = resolveItem(item, currentPage, currentBlock, amount, "blocks"); if (toItem === undefined) return; var next = $("." + toItem.get("_id")); if (next.length === 0) return; Adapt.scrollTo(next.offset()['top'] - $('.navigation').height() - parseInt(next.css("margin-top")), {axis:'y', duration: 1000 }); break; case "component": var currentComponent = resolveType(currentId, "component"); var toItem = resolveItem(item, currentPage, currentComponent, amount, "components"); if (toItem === undefined) return; var next = $("." + toItem.get("_id")); if (next.length === 0) return; Adapt.scrollTo(next.offset()['top'] - $('.navigation').height() - parseInt(next.css("margin-top")), {axis:'y', duration: 1000 }); break; } } else { var model = Adapt.findById(to); if (model) { switch (model.get("_type")) { case "page": case "menu": Backbone.history.navigate("#/id/"+to, {trigger: true, replace: replaceUrl}); break; default: Adapt.navigateToElement("." + to); break; } } } }
Adapt.on('componentView:postRender', function(componentView) { var componentId = componentView.model.get('_id'); var blockId = componentView.model.get("_parentId"); var articleId = Adapt.findById(blockId).get("_parentId"); var article = Adapt.findById(articleId); if (!article.get("_assessment") && article.get("_assessment")._isEnable !== true) return; if (!article.get("_assessment")._singleSubmit && article.get("_assessment")._singleSubmit._isEnable !== true) return; if (SingleSubmit.components.findWhere({ _id: componentId }) === undefined) return; SingleSubmit.componentViews[componentId] = componentView; //SETUP SUB COMPONENT INTERACTION LISTENERS componentView.$el.on("inview", { _id: componentId }, SingleSubmit.onInteraction); componentView.$el.on("click", { _id: componentId }, SingleSubmit.onInteraction); });
getParent: function () { if (this.get("_parent")) return this.get("_parent"); if (this._parent === "course") { return Adapt.course; } var parent = Adapt.findById(this.get("_parentId")); this.set("_parent", parent); // returns a parent model return parent; },
checkVisibility:function(id) { var model = Adapt.findById(id); if ($('.'+id).is(':visible') || model == Adapt.course) return; while (!$('.'+id).is(':visible') && model != Adapt.course) { model = model.getParent(); id = model.get('_id'); } console.log('adapt-devtools::checkVisibility scrolling to ancestor '+id); Adapt.scrollTo($('.'+id)); }
var resolveType = function(_id, type) { var current = Adapt.findById(_id) var i = 0; while (i < 10) { if (current.get("_type") == type) { return current; } current = current.getParent(); i++; } throw new Error(type + " not found!"); }
_.each(associatedLearningIDs, function(id) { var model = Adapt.findById(id); //console.log("model",model) if (model && model.has('title')) { var title = model.get('title'); //console.log("title: " + title); if (!_.contains(associatedLearning, title)) { associatedLearning.push({id: id, type: model._siblings, title: title}); } } }, this);
Adapt.on("learnerassistant:takeQuiz", function() { var id = LearnerAssistant.views['assessment'].model.get("_id"); var element = Adapt.findById(id) var typeNameConversion = { "component": "components", "article": "articles", "block": "blocks", "menu": "contentObject", "page": "contentObject" }; Adapt.navigateToElement(id, typeNameConversion[element.get("_type")] ); });
shouldLock: function(child) { var lockedBy = child.get("_lockedBy"); if (!lockedBy) return false; for (var i = lockedBy.length - 1; i >= 0; i--) { var id = lockedBy[i]; try { if (!Adapt.findById(id).get("_isComplete")) return true; } catch (e) { console.warn("AdaptModel.shouldLock: unknown _lockedBy ID \"" + id + "\" found on " + child.get("_id")); } } return false; },
onNextClick: function(event) { var assoc = _.findWhere(this.model.get('associatedLearning'), { _interactions: 0 }); event.preventDefault(); $currentTarget = $(event.currentTarget); var element = Adapt.findById(assoc._id) var typeNameConversion = { "component": "components", "article": "articles", "block": "blocks", "menu": "contentObject", "page": "contentObject" }; Adapt.navigateToElement(assoc._id, typeNameConversion[element.get("_type")] ); this.parent.results.hide(); this.render(); }
onLinkClicked:function(e) { var $target = $(e.currentTarget); var id = $target.attr("href").slice(1); var model = Adapt.findById(id); e.preventDefault(); if (e.ctrlKey && this.el.defaultView) { id = id.replace(/-/g, ''); this.el.defaultView[id] = model; this.el.defaultView.console.log('devtools: add property window.'+id+':'); this.el.defaultView.console.log(model); } else if (e.shiftKey) { this.navigateAndDisableTrickle(id); } else { this.navigateAndDisableTrickleUpTo(id); } },
_.each(options.questions, function(question) { LearnerAssistant.listenTo( Adapt.findById(question._id), "change:_isInteractionsComplete", LearnerAssistant.pagelevelprogress.onQuestionInteraction); });
_.each(options.questions, function(question) { LearnerAssistant.stopListening( Adapt.findById(question._id), "change:_isInteractionsComplete"); });