forked from openedx/edx-platform
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Load XBlocks with webpack rather than RequireJS
- Loading branch information
1 parent
9455790
commit d08e199
Showing
67 changed files
with
597 additions
and
324 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* eslint-env node */ | ||
|
||
// Karma config for cms suite. | ||
// Docs and troubleshooting tips in common/static/common/js/karma.common.conf.js | ||
|
||
'use strict'; | ||
var path = require('path'); | ||
var configModule = require(path.join(__dirname, '../../common/static/common/js/karma.common.conf.js')); | ||
|
||
var options = { | ||
|
||
includeCommonFiles: true, | ||
|
||
libraryFiles: [], | ||
|
||
libraryFilesToInclude: [ | ||
], | ||
|
||
// Make sure the patterns in sourceFiles and specFiles do not match the same file. | ||
// Otherwise Istanbul which is used for coverage tracking will cause tests to not run. | ||
sourceFiles: [], | ||
// {pattern: 'js/factories/login.js', webpack: true}, | ||
// {pattern: 'js/factories/xblock_validation.js', webpack: true}, | ||
// {pattern: 'js/factories/container.js', webpack: true}, | ||
// {pattern: 'js/factories/context_course.js', webpack: true}, | ||
// {pattern: 'js/factories/edit_tabs.js', webpack: true}, | ||
// {pattern: 'js/factories/library.js', webpack: true}, | ||
// {pattern: 'js/factories/textbooks.js', webpack: true}, | ||
// ], | ||
|
||
// All spec files should be imported in main_webpack.js, rather than being listed here | ||
specFiles: [], | ||
|
||
fixtureFiles: [ | ||
{pattern: '../templates/js/**/*.underscore'}, | ||
{pattern: 'templates/**/*.underscore'} | ||
], | ||
|
||
runFiles: [ | ||
{pattern: 'cms/js/spec/main_webpack.js', webpack: true}, | ||
{pattern: 'jasmine.cms.conf.js', included: true} | ||
], | ||
|
||
preprocessors: {} | ||
}; | ||
|
||
options.runFiles | ||
.filter(function(file) { return file.webpack; }) | ||
.forEach(function(file) { | ||
options.preprocessors[file.pattern] = ['webpack']; | ||
}); | ||
|
||
module.exports = function(config) { | ||
configModule.configure(config, options); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 48 additions & 50 deletions
98
common/lib/xmodule/xmodule/assets/vertical/public/js/vertical_student_view.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,70 +1,68 @@ | ||
/* JavaScript for Vertical Student View. */ | ||
|
||
/* global Set:false */ // false means do not assign to Set | ||
/* global ViewedEventTracker:false */ | ||
|
||
// The vertical marks blocks complete if they are completable by viewing. The | ||
// global variable SEEN_COMPLETABLES tracks blocks between separate loads of | ||
// the same vertical (when a learner goes from one tab to the next, and then | ||
// navigates back within a given sequential) to protect against duplicate calls | ||
// to the server. | ||
|
||
import BookmarkButton from 'course_bookmarks/js/views/bookmark_button'; | ||
import {ViewedEventTracker} from '../../../../../../../../lms/static/completion/js/ViewedEvent.js'; | ||
|
||
var SEEN_COMPLETABLES = new Set(); | ||
|
||
window.VerticalStudentView = function(runtime, element) { | ||
'use strict'; | ||
RequireJS.require(['course_bookmarks/js/views/bookmark_button'], function(BookmarkButton) { | ||
var $element = $(element); | ||
var $bookmarkButtonElement = $element.find('.bookmark-button'); | ||
return new BookmarkButton({ | ||
el: $bookmarkButtonElement, | ||
bookmarkId: $bookmarkButtonElement.data('bookmarkId'), | ||
usageId: $element.data('usageId'), | ||
bookmarked: $element.parent('#seq_content').data('bookmarked'), | ||
apiUrl: $bookmarkButtonElement.data('bookmarksApiUrl') | ||
}); | ||
var $element = $(element); | ||
var $bookmarkButtonElement = $element.find('.bookmark-button'); | ||
return new BookmarkButton({ | ||
el: $bookmarkButtonElement, | ||
bookmarkId: $bookmarkButtonElement.data('bookmarkId'), | ||
usageId: $element.data('usageId'), | ||
bookmarked: $element.parent('#seq_content').data('bookmarked'), | ||
apiUrl: $bookmarkButtonElement.data('bookmarksApiUrl') | ||
}); | ||
RequireJS.require(['bundles/ViewedEvent'], function() { | ||
var tracker, vertical, viewedAfter; | ||
var completableBlocks = []; | ||
var vertModDivs = element.getElementsByClassName('vert-mod'); | ||
if (vertModDivs.length === 0) { | ||
return; | ||
} | ||
vertical = vertModDivs[0]; | ||
$(element).find('.vert').each(function(idx, block) { | ||
if (block.dataset.completableByViewing !== undefined) { | ||
completableBlocks.push(block); | ||
} | ||
}); | ||
if (completableBlocks.length > 0) { | ||
viewedAfter = parseInt(vertical.dataset.completionDelayMs, 10); | ||
if (!(viewedAfter >= 0)) { | ||
// parseInt will return NaN if it fails to parse, which is not >= 0. | ||
viewedAfter = 5000; | ||
} | ||
tracker = new ViewedEventTracker(completableBlocks, viewedAfter); | ||
tracker.addHandler(function(block, event) { | ||
var blockKey = block.dataset.id; | ||
|
||
if (blockKey && !SEEN_COMPLETABLES.has(blockKey)) { | ||
if (event.elementHasBeenViewed) { | ||
$.ajax({ | ||
type: 'POST', | ||
url: runtime.handlerUrl(element, 'publish_completion'), | ||
data: JSON.stringify({ | ||
block_key: blockKey, | ||
completion: 1.0 | ||
}) | ||
}).then( | ||
function() { | ||
SEEN_COMPLETABLES.add(blockKey); | ||
} | ||
); | ||
} | ||
} | ||
}); | ||
var tracker, vertical, viewedAfter; | ||
var completableBlocks = []; | ||
var vertModDivs = element.getElementsByClassName('vert-mod'); | ||
if (vertModDivs.length === 0) { | ||
return; | ||
} | ||
vertical = vertModDivs[0]; | ||
$(element).find('.vert').each(function(idx, block) { | ||
if (block.dataset.completableByViewing !== undefined) { | ||
completableBlocks.push(block); | ||
} | ||
}); | ||
if (completableBlocks.length > 0) { | ||
viewedAfter = parseInt(vertical.dataset.completionDelayMs, 10); | ||
if (!(viewedAfter >= 0)) { | ||
// parseInt will return NaN if it fails to parse, which is not >= 0. | ||
viewedAfter = 5000; | ||
} | ||
tracker = new ViewedEventTracker(completableBlocks, viewedAfter); | ||
tracker.addHandler(function(block, event) { | ||
var blockKey = block.dataset.id; | ||
|
||
if (blockKey && !SEEN_COMPLETABLES.has(blockKey)) { | ||
if (event.elementHasBeenViewed) { | ||
$.ajax({ | ||
type: 'POST', | ||
url: runtime.handlerUrl(element, 'publish_completion'), | ||
data: JSON.stringify({ | ||
block_key: blockKey, | ||
completion: 1.0 | ||
}) | ||
}).then( | ||
function() { | ||
SEEN_COMPLETABLES.add(blockKey); | ||
} | ||
); | ||
} | ||
} | ||
}); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.