Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass DOM element, not jQuery object to XBlock initialisation. #11433

Merged
merged 1 commit into from
Feb 15, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cms/static/js/views/xblock.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ define(["jquery", "underscore", "common/js/components/utils/view_utils", "js/vie
fragmentsRendered.always(function() {
xblockElement = self.$('.xblock').first();
try {
xblock = XBlock.initializeBlock(xblockElement);
xblock = XBlock.initializeBlock(xblockElement.get(0));
self.xblock = xblock;
self.xblockReady(xblock);
if (successCallback) {
Expand Down
17 changes: 9 additions & 8 deletions cms/static/js/xblock/authoring.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
'use strict';

function VisibilityEditorView(runtime, element) {
var $element = $(element);
this.getGroupAccess = function() {
var groupAccess = {},
checkboxValues,
Expand All @@ -15,12 +16,12 @@
// defined by VerificationPartitionScheme on the backend!
ALLOW_GROUP_ID = 1;

if (element.find('.visibility-level-all').prop('checked')) {
if ($element.find('.visibility-level-all').prop('checked')) {
return {};
}

// Cohort partitions (user is allowed to select more than one)
element.find('.field-visibility-content-group input:checked').each(function(index, input) {
$element.find('.field-visibility-content-group input:checked').each(function(index, input) {
checkboxValues = $(input).val().split("-");
partitionId = parseInt(checkboxValues[0], 10);
groupId = parseInt(checkboxValues[1], 10);
Expand All @@ -33,7 +34,7 @@
});

// Verification partitions (user can select exactly one)
if (element.find('#verification-access-checkbox').prop('checked')) {
if ($element.find('#verification-access-checkbox').prop('checked')) {
partitionId = parseInt($('#verification-access-dropdown').val(), 10);
groupAccess[partitionId] = [ALLOW_GROUP_ID];
}
Expand All @@ -42,19 +43,19 @@
};

// When selecting "all students and staff", uncheck the specific groups
element.find('.field-visibility-level input').change(function(event) {
$element.find('.field-visibility-level input').change(function(event) {
if ($(event.target).hasClass('visibility-level-all')) {
element.find('.field-visibility-content-group input, .field-visibility-verification input')
$element.find('.field-visibility-content-group input, .field-visibility-verification input')
.prop('checked', false);
}
});

// When selecting a specific group, deselect "all students and staff" and
// select "specific content groups" instead.`
element.find('.field-visibility-content-group input, .field-visibility-verification input')
$element.find('.field-visibility-content-group input, .field-visibility-verification input')
.change(function() {
element.find('.visibility-level-all').prop('checked', false);
element.find('.visibility-level-specific').prop('checked', true);
$element.find('.visibility-level-all').prop('checked', false);
$element.find('.visibility-level-specific').prop('checked', true);
});
}

Expand Down
2 changes: 1 addition & 1 deletion common/lib/xmodule/xmodule/js/src/html/edit.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class @HTMLEditingDescriptor
CUSTOM_FONTS + STANDARD_FONTS

constructor: (element) ->
@element = element
@element = $(element)
@base_asset_url = @element.find("#editor-tab").data('base-asset-url')
@editor_choice = @element.find("#editor-tab").data('editor')
if @base_asset_url == undefined
Expand Down
2 changes: 1 addition & 1 deletion common/lib/xmodule/xmodule/js/src/problem/edit.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class @MarkdownEditingDescriptor extends XModule.Descriptor
@explanationTemplate: "[explanation]\n#{gettext 'Short explanation'}\n[explanation]\n"

constructor: (element) ->
@element = element
@element = $(element)

if $(".markdown-box", @element).length != 0
@markdown_editor = CodeMirror.fromTextArea($(".markdown-box", element)[0], {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ class @TabsEditingDescriptor
@isInactiveClass : "is-inactive"

constructor: (element) ->
@element = element;
@element = $(element)
###
Not tested on syncing of multiple editors of same type in tabs
(Like many CodeMirrors).
Expand Down
2 changes: 1 addition & 1 deletion common/static/js/xblock/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
} else {
block = {};
}
block.element = element;
block.element = $element;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line has caused a regression: https://openedx.atlassian.net/browse/TNL-4161

What was the rationale for this specific change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bradenmacdonald The rationale was that all XBlocks inside edx-platform I looked at required the element attribute to be a jQuery object. This was the only way I managed to get it working at all.

Thinking about it, it seems inconsitent to pass a DOM element to the initialisation function and use a jQuery object here, so this line should probably be reverted. However, this will require a large number of changes in other places, but it's probably what we need to do.

block.name = $element.data('name');
block.type = $element.data('block-type');
$element.trigger('xblock-initialized');
Expand Down