Skip to content

Commit

Permalink
Fix: Update deprecated references (fixes #87)
Browse files Browse the repository at this point in the history
  • Loading branch information
swashbuck authored May 21, 2024
1 parent 880b784 commit e8b2ffe
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 30 deletions.
10 changes: 5 additions & 5 deletions js/adapt-devtools.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ class DevtoolsView extends Backbone.View {
/*************************************************/

_checkCompletePageVisibility () {
const currentModel = data.findById(Adapt.location._currentId);
const currentModel = data.findById(location._currentId);
if (currentModel.get('_type') !== 'page') {
this.$('.complete-page').addClass('u-display-none');
return;
Expand All @@ -283,7 +283,7 @@ class DevtoolsView extends Backbone.View {
}

onCompletePage (e) {
const currentModel = data.findById(Adapt.location._currentId);
const currentModel = data.findById(location._currentId);
if (Adapt.devtools.get('_trickleEnabled')) Adapt.trigger('trickle:kill');
const incomplete = currentModel.findDescendantModels('components', { where: { _isInteractionComplete: false } });
incomplete.forEach(component => {
Expand All @@ -306,7 +306,7 @@ class DevtoolsView extends Backbone.View {
/*************************************************/

_checkCompleteMenuVisibility () {
const currentModel = data.findById(Adapt.location._currentId);
const currentModel = data.findById(location._currentId);
if (currentModel.get('_type') !== 'menu' && currentModel.get('_type') !== 'course') {
this.$('.complete-menu').addClass('u-display-none');
return;
Expand All @@ -316,7 +316,7 @@ class DevtoolsView extends Backbone.View {
}

onCompleteMenu (e) {
const currentModel = Adapt.findById(Adapt.location._currentId);
const currentModel = data.findById(location._currentId);
if (Adapt.devtools.get('_trickleEnabled')) Adapt.trigger('trickle:kill');
const incomplete = currentModel.findDescendantModels('components', { where: { _isComplete: false } });
_.invoke(incomplete, 'set', '_isComplete', true);
Expand All @@ -328,7 +328,7 @@ class DevtoolsView extends Backbone.View {
/************************************************************/

_checkPassHalfFailVisibility () {
const currentModel = data.findById(Adapt.location._currentId);
const currentModel = data.findById(location._currentId);
if (currentModel.get('_type') !== 'page') {
this.$('.pass, .half, .fail').addClass('u-display-none');
return;
Expand Down
5 changes: 3 additions & 2 deletions js/enable.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Adapt from 'core/js/adapt';
import Router from 'core/js/router';
import location from 'core/js/location';

let buffer = '';
let isMouseDown = false;
Expand Down Expand Up @@ -42,8 +43,8 @@ function enable() {
Adapt.trigger('devtools:enable');

// reload the menu/page
if (Adapt.location._currentId === Adapt.course.get('_id')) Router.handleRoute ? Router.handleRoute() : Router.handleCourse();
else Router.handleId(Adapt.location._currentId);
if (location._currentId === Adapt.course.get('_id')) Router.handleRoute ? Router.handleRoute() : Router.handleCourse();
else Router.handleId(location._currentId);
}

function addHooks() {
Expand Down
11 changes: 6 additions & 5 deletions js/map.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Backbone from 'backbone';
import Adapt from 'core/js/adapt';
import data from 'core/js/data';
import location from 'core/js/location';
import Router from 'core/js/router';

class MapView extends Backbone.View {
Expand Down Expand Up @@ -105,8 +106,8 @@ class MapView extends Backbone.View {
* affected article(s)|block(s).
*/
navigateAndDisableTrickleUpTo (id) {
const model = Adapt.findById(id);
const pageModel = Adapt.findById(Adapt.location._currentId);
const model = data.findById(id);
const pageModel = data.findById(location._currentId);
// first ensure page incomplete prompt won't activate
this._disablePageIncompletePrompt(pageModel);
// now navigate
Expand All @@ -133,8 +134,8 @@ class MapView extends Backbone.View {
this.checkVisibility(id);
});
});
if (Adapt.location._currentId === Adapt.course.get('_id')) Router.handleRoute ? Router.handleRoute() : Router.handleCourse();
else Router.handleId(Adapt.location._currentId);
if (location._currentId === Adapt.course.get('_id')) Router.handleRoute ? Router.handleRoute() : Router.handleCourse();
else Router.handleId(location._currentId);
} else {
this.listenToOnce(Adapt, 'pageView:ready', () => {
_.defer(() => {
Expand Down Expand Up @@ -196,7 +197,7 @@ class MapView extends Backbone.View {
}

checkVisibility (id) {
let model = Adapt.findById(id);
let model = data.findById(id);
if ($('.' + id).is(':visible') || model === Adapt.course) return;
while (!$('.' + id).is(':visible') && model !== Adapt.course) {
model = model.getParent();
Expand Down
2 changes: 1 addition & 1 deletion js/toggle-banking.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class ToggleBanking extends Backbone.Controller {
}

getBankedAssessmentsInCurrentPage() {
const pageModel = data.findById(Adapt.location._currentId);
const pageModel = data.findById(location._currentId);
const f = m => {
const config = this.getConfig(m);
if (!config._assessmentBankDisabled &&
Expand Down
20 changes: 3 additions & 17 deletions js/utils.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Adapt from 'core/js/adapt';
import AdaptModel from 'core/js/models/adaptModel';
import QuestionView from 'core/js/views/questionView';
import data from 'core/js/data';
import drawer from 'core/js/drawer';

let mouseTarget = null;
Expand Down Expand Up @@ -33,30 +34,15 @@ function onDrawerOpened() {
}

function getAdaptCoreVersion() {
try {
if (Adapt.build && Adapt.build.has('package')) return Adapt.build.get('package').version || '>=v3.0.0';
// v2.2.4-v2.2.5 not possible to distinguish
if (typeof AdaptModel.prototype.checkCompletionStatusFor === 'function') return '>=v2.2.3';
if (typeof AdaptModel.prototype.setCompletionStatus === 'function') return '>=v2.0.10';
if (typeof AdaptModel.prototype.checkLocking === 'function') return 'v2.0.9';
if (typeof Adapt.checkingCompletion === 'function') return 'v2.0.8';
if (typeof AdaptModel.prototype.getParents === 'function') return 'v2.0.7';
if ($.a11y && Object.prototype.hasOwnProperty.call($.a11y.options, 'isIOSFixesEnabled')) return 'v2.0.5-v2.0.6';
if (Adapt instanceof Backbone.Model) return 'v2.0.4';
if (typeof QuestionView.prototype.recordInteraction === 'function') return 'v2.0.2-v2.0.3';
if (typeof Adapt.findById === 'function') return 'v2.0.0-v2.0.1';
return 'v1.x';
} catch (e) {
return 'unknown version';
}
return Adapt.build?.get?.('package')?.version ?? 'unknown version';
}

const Utils = {
getModelForElement: element => {
const $target = $(element);
if ($target.length === 0) return false;
const id = $target.parents('[data-adapt-id]').data('adapt-id');
return !id ? false : Adapt.findById(id);
return !id ? false : data.findById(id);
}
};

Expand Down

0 comments on commit e8b2ffe

Please sign in to comment.