markdown-xblock 2.4.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- markdown_xblock/__init__.py +2 -0
- markdown_xblock/html.py +335 -0
- markdown_xblock/public/plugins/codemirror/LICENSE +21 -0
- markdown_xblock/public/plugins/codemirror/codemirror-4.8/addon/dialog/dialog.css +32 -0
- markdown_xblock/public/plugins/codemirror/codemirror-4.8/addon/dialog/dialog.js +155 -0
- markdown_xblock/public/plugins/codemirror/codemirror-4.8/addon/display/fullscreen.css +6 -0
- markdown_xblock/public/plugins/codemirror/codemirror-4.8/addon/display/fullscreen.js +41 -0
- markdown_xblock/public/plugins/codemirror/codemirror-4.8/addon/edit/matchbrackets.js +120 -0
- markdown_xblock/public/plugins/codemirror/codemirror-4.8/addon/search/search.js +159 -0
- markdown_xblock/public/plugins/codemirror/codemirror-4.8/addon/search/searchcursor.js +189 -0
- markdown_xblock/public/plugins/codemirror/codemirror-4.8/addon/selection/active-line.js +71 -0
- markdown_xblock/public/plugins/codemirror/codemirror-4.8/lib/codemirror.css +319 -0
- markdown_xblock/public/plugins/codemirror/codemirror-4.8/lib/codemirror.js +7923 -0
- markdown_xblock/public/plugins/codemirror/codemirror-4.8/mode/css/css.js +717 -0
- markdown_xblock/public/plugins/codemirror/codemirror-4.8/mode/htmlmixed/htmlmixed.js +121 -0
- markdown_xblock/public/plugins/codemirror/codemirror-4.8/mode/javascript/javascript.js +684 -0
- markdown_xblock/public/plugins/codemirror/codemirror-4.8/mode/markdown/markdown.js +883 -0
- markdown_xblock/public/plugins/codemirror/codemirror-4.8/mode/xml/xml.js +384 -0
- markdown_xblock/public/plugins/codemirror/langs/en.js +8 -0
- markdown_xblock/public/plugins/codemirror/plugin.min.js +1 -0
- markdown_xblock/public/plugins/codemirror/source.html +270 -0
- markdown_xblock/public/plugins/codesample/css/prism.css +141 -0
- markdown_xblock/public/plugins/codesample/js/prism.js +15 -0
- markdown_xblock/public/plugins/codesample/plugin.min.js +1 -0
- markdown_xblock/public/plugins/image/plugin.min.js +1 -0
- markdown_xblock/public/plugins/link/plugin.min.js +1 -0
- markdown_xblock/public/plugins/lists/plugin.min.js +1 -0
- markdown_xblock/public/plugins/textcolor/plugin.min.js +1 -0
- markdown_xblock/public/skin/content.inline.min.css +1 -0
- markdown_xblock/public/skin/content.min.css +2 -0
- markdown_xblock/public/skin/fonts/icomoon-small.eot +0 -0
- markdown_xblock/public/skin/fonts/icomoon-small.svg +175 -0
- markdown_xblock/public/skin/fonts/icomoon-small.ttf +0 -0
- markdown_xblock/public/skin/fonts/icomoon-small.woff +0 -0
- markdown_xblock/public/skin/fonts/icomoon.eot +0 -0
- markdown_xblock/public/skin/fonts/icomoon.svg +153 -0
- markdown_xblock/public/skin/fonts/icomoon.ttf +0 -0
- markdown_xblock/public/skin/fonts/icomoon.woff +0 -0
- markdown_xblock/public/skin/fonts/readme.md +1 -0
- markdown_xblock/public/skin/img/anchor.gif +0 -0
- markdown_xblock/public/skin/img/loader.gif +0 -0
- markdown_xblock/public/skin/img/object.gif +0 -0
- markdown_xblock/public/skin/img/trans.gif +0 -0
- markdown_xblock/public/skin/img/wline.gif +0 -0
- markdown_xblock/public/skin/skin.ie7.min.css +1 -0
- markdown_xblock/public/skin/skin.json +51 -0
- markdown_xblock/public/skin/skin.min.css +1 -0
- markdown_xblock/static/css/html.css +15 -0
- markdown_xblock/static/css/pygments.css +61 -0
- markdown_xblock/static/html/lms.html +1 -0
- markdown_xblock/static/html/studio.html +29 -0
- markdown_xblock/static/js/html.js +233 -0
- markdown_xblock/static/js/tinymce/themes/modern/theme.min.js +1 -0
- markdown_xblock/static/js/tinymce/tinymce.js +26801 -0
- markdown_xblock/static/js/tinymce/tinymce.min.js +2 -0
- markdown_xblock/translations/README.txt +4 -0
- markdown_xblock/utils.py +11 -0
- markdown_xblock-2.4.0.dist-info/METADATA +158 -0
- markdown_xblock-2.4.0.dist-info/RECORD +83 -0
- markdown_xblock-2.4.0.dist-info/WHEEL +5 -0
- markdown_xblock-2.4.0.dist-info/entry_points.txt +2 -0
- markdown_xblock-2.4.0.dist-info/licenses/LICENSE +671 -0
- markdown_xblock-2.4.0.dist-info/top_level.txt +5 -0
- releasenotes/notes/add-default-css-for-tables-3a53e02e8a350253.yaml +5 -0
- releasenotes/notes/add_public_view-d24763b7941dc2b0.yaml +4 -0
- releasenotes/notes/custom-css-classes-7984a9c95147d39c.yaml +5 -0
- releasenotes/notes/export-md-to-file-ab1528b4c28cb2f0.yaml +5 -0
- releasenotes/notes/fix-course-export-b35c78a22be0c6b5.yaml +6 -0
- releasenotes/notes/missing-codemirror-files-d64ccb15d0faf640.yaml +6 -0
- releasenotes/notes/pypi-release-3e4d5ceb7b6e252a.yaml +7 -0
- releasenotes/notes/python-3.12-support-dac839f8d01ac6b9.yaml +4 -0
- releasenotes/notes/refactor-ci-36abda8c15250d06.yaml +6 -0
- releasenotes/notes/refactor-export-import-49bbf0e8a364f139.yaml +8 -0
- releasenotes/notes/remove_py35-0b265861449b1753.yaml +9 -0
- releasenotes/notes/safe_mode_replace_escape-40fdb78ec8aa5eff.yaml +7 -0
- releasenotes/notes/show_in_read_only_mode-3af39459d5d56b33.yaml +7 -0
- requirements/base.txt +9 -0
- requirements/dev.txt +2 -0
- requirements/reno.txt +1 -0
- requirements/test.txt +9 -0
- tests/__init__.py +1 -0
- tests/test_basics.py +280 -0
- var/.placeholder +2 -0
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
.markdown_xblock table {
|
|
2
|
+
width: 100%;
|
|
3
|
+
margin: 20px 0;
|
|
4
|
+
border-collapse: collapse;
|
|
5
|
+
font-size: 16px;
|
|
6
|
+
}
|
|
7
|
+
.markdown_xblock th, td {
|
|
8
|
+
padding: 10px;
|
|
9
|
+
border: 1px solid #c8c8c8;
|
|
10
|
+
font-size: 14px;
|
|
11
|
+
}
|
|
12
|
+
.markdown_xblock th {
|
|
13
|
+
background: #eee;
|
|
14
|
+
font-weight: bold;
|
|
15
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
.markdown_xblock .codehilite .hll { background-color: #ffffcc }
|
|
2
|
+
.markdown_xblock .codehilite .c { color: #999988; font-style: italic } /* Comment */
|
|
3
|
+
.markdown_xblock .codehilite .err { color: #a61717; background-color: #e3d2d2 } /* Error */
|
|
4
|
+
.markdown_xblock .codehilite .k { color: #000000; font-weight: bold } /* Keyword */
|
|
5
|
+
.markdown_xblock .codehilite .o { color: #000000; font-weight: bold } /* Operator */
|
|
6
|
+
.markdown_xblock .codehilite .cm { color: #999988; font-style: italic } /* Comment.Multiline */
|
|
7
|
+
.markdown_xblock .codehilite .cp { color: #999999; font-weight: bold; font-style: italic } /* Comment.Preproc */
|
|
8
|
+
.markdown_xblock .codehilite .c1 { color: #999988; font-style: italic } /* Comment.Single */
|
|
9
|
+
.markdown_xblock .codehilite .cs { color: #999999; font-weight: bold; font-style: italic } /* Comment.Special */
|
|
10
|
+
.markdown_xblock .codehilite .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */
|
|
11
|
+
.markdown_xblock .codehilite .ge { color: #000000; font-style: italic } /* Generic.Emph */
|
|
12
|
+
.markdown_xblock .codehilite .gr { color: #aa0000 } /* Generic.Error */
|
|
13
|
+
.markdown_xblock .codehilite .gh { color: #999999 } /* Generic.Heading */
|
|
14
|
+
.markdown_xblock .codehilite .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */
|
|
15
|
+
.markdown_xblock .codehilite .go { color: #888888 } /* Generic.Output */
|
|
16
|
+
.markdown_xblock .codehilite .gp { color: #555555 } /* Generic.Prompt */
|
|
17
|
+
.markdown_xblock .codehilite .gs { font-weight: bold } /* Generic.Strong */
|
|
18
|
+
.markdown_xblock .codehilite .gu { color: #aaaaaa } /* Generic.Subheading */
|
|
19
|
+
.markdown_xblock .codehilite .gt { color: #aa0000 } /* Generic.Traceback */
|
|
20
|
+
.markdown_xblock .codehilite .kc { color: #000000; font-weight: bold } /* Keyword.Constant */
|
|
21
|
+
.markdown_xblock .codehilite .kd { color: #000000; font-weight: bold } /* Keyword.Declaration */
|
|
22
|
+
.markdown_xblock .codehilite .kn { color: #000000; font-weight: bold } /* Keyword.Namespace */
|
|
23
|
+
.markdown_xblock .codehilite .kp { color: #000000; font-weight: bold } /* Keyword.Pseudo */
|
|
24
|
+
.markdown_xblock .codehilite .kr { color: #000000; font-weight: bold } /* Keyword.Reserved */
|
|
25
|
+
.markdown_xblock .codehilite .kt { color: #445588; font-weight: bold } /* Keyword.Type */
|
|
26
|
+
.markdown_xblock .codehilite .m { color: #009999 } /* Literal.Number */
|
|
27
|
+
.markdown_xblock .codehilite .s { color: #d01040 } /* Literal.String */
|
|
28
|
+
.markdown_xblock .codehilite .na { color: #008080 } /* Name.Attribute */
|
|
29
|
+
.markdown_xblock .codehilite .nb { color: #0086B3 } /* Name.Builtin */
|
|
30
|
+
.markdown_xblock .codehilite .nc { color: #445588; font-weight: bold } /* Name.Class */
|
|
31
|
+
.markdown_xblock .codehilite .no { color: #008080 } /* Name.Constant */
|
|
32
|
+
.markdown_xblock .codehilite .nd { color: #3c5d5d; font-weight: bold } /* Name.Decorator */
|
|
33
|
+
.markdown_xblock .codehilite .ni { color: #800080 } /* Name.Entity */
|
|
34
|
+
.markdown_xblock .codehilite .ne { color: #990000; font-weight: bold } /* Name.Exception */
|
|
35
|
+
.markdown_xblock .codehilite .nf { color: #990000; font-weight: bold } /* Name.Function */
|
|
36
|
+
.markdown_xblock .codehilite .nl { color: #990000; font-weight: bold } /* Name.Label */
|
|
37
|
+
.markdown_xblock .codehilite .nn { color: #555555 } /* Name.Namespace */
|
|
38
|
+
.markdown_xblock .codehilite .nt { color: #000080 } /* Name.Tag */
|
|
39
|
+
.markdown_xblock .codehilite .nv { color: #008080 } /* Name.Variable */
|
|
40
|
+
.markdown_xblock .codehilite .ow { color: #000000; font-weight: bold } /* Operator.Word */
|
|
41
|
+
.markdown_xblock .codehilite .w { color: #bbbbbb } /* Text.Whitespace */
|
|
42
|
+
.markdown_xblock .codehilite .mf { color: #009999 } /* Literal.Number.Float */
|
|
43
|
+
.markdown_xblock .codehilite .mh { color: #009999 } /* Literal.Number.Hex */
|
|
44
|
+
.markdown_xblock .codehilite .mi { color: #009999 } /* Literal.Number.Integer */
|
|
45
|
+
.markdown_xblock .codehilite .mo { color: #009999 } /* Literal.Number.Oct */
|
|
46
|
+
.markdown_xblock .codehilite .sb { color: #d01040 } /* Literal.String.Backtick */
|
|
47
|
+
.markdown_xblock .codehilite .sc { color: #d01040 } /* Literal.String.Char */
|
|
48
|
+
.markdown_xblock .codehilite .sd { color: #d01040 } /* Literal.String.Doc */
|
|
49
|
+
.markdown_xblock .codehilite .s2 { color: #d01040 } /* Literal.String.Double */
|
|
50
|
+
.markdown_xblock .codehilite .se { color: #d01040 } /* Literal.String.Escape */
|
|
51
|
+
.markdown_xblock .codehilite .sh { color: #d01040 } /* Literal.String.Heredoc */
|
|
52
|
+
.markdown_xblock .codehilite .si { color: #d01040 } /* Literal.String.Interpol */
|
|
53
|
+
.markdown_xblock .codehilite .sx { color: #d01040 } /* Literal.String.Other */
|
|
54
|
+
.markdown_xblock .codehilite .sr { color: #009926 } /* Literal.String.Regex */
|
|
55
|
+
.markdown_xblock .codehilite .s1 { color: #d01040 } /* Literal.String.Single */
|
|
56
|
+
.markdown_xblock .codehilite .ss { color: #990073 } /* Literal.String.Symbol */
|
|
57
|
+
.markdown_xblock .codehilite .bp { color: #999999 } /* Name.Builtin.Pseudo */
|
|
58
|
+
.markdown_xblock .codehilite .vc { color: #008080 } /* Name.Variable.Class */
|
|
59
|
+
.markdown_xblock .codehilite .vg { color: #008080 } /* Name.Variable.Global */
|
|
60
|
+
.markdown_xblock .codehilite .vi { color: #008080 } /* Name.Variable.Instance */
|
|
61
|
+
.markdown_xblock .codehilite .il { color: #009999 } /* Literal.Number.Integer.Long */
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<div class="markdown_xblock{% if self.classes %} {{ self.classes | join:' ' }}{% endif %}">{{ self.html | safe }}</div>
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
<div class="wrapper-comp-editor editor-with-buttons" id="editor-tab" data-editor="{self.editor}">
|
|
2
|
+
<div class="tab">
|
|
3
|
+
<button class="tablinks" aria-selected="true" onclick="openTab(event, 'editor')" id="default-tab" >Editor</button>
|
|
4
|
+
<button class="tablinks" aria-selected="false" onclick="openTab(event, 'settings')">Settings</button>
|
|
5
|
+
</div>
|
|
6
|
+
|
|
7
|
+
<div id="editor" class="tabcontent">
|
|
8
|
+
<div class="markdown-editor editor">
|
|
9
|
+
<div class="row">
|
|
10
|
+
<textarea id="markdown-textarea">{{ self.data }}</textarea>
|
|
11
|
+
</div>
|
|
12
|
+
</div>
|
|
13
|
+
<div class="xblock-actions">
|
|
14
|
+
<span class="xblock-editor-error-message"></span>
|
|
15
|
+
<ul>
|
|
16
|
+
<li class="action-item">
|
|
17
|
+
<a href="#" class="button action-primary save-button">Save</a>
|
|
18
|
+
</li>
|
|
19
|
+
<li class="action-item">
|
|
20
|
+
<a href="#" class="button cancel-button">Cancel</a>
|
|
21
|
+
</li>
|
|
22
|
+
</ul>
|
|
23
|
+
</div>
|
|
24
|
+
</div>
|
|
25
|
+
|
|
26
|
+
<div id="settings" class="tabcontent">
|
|
27
|
+
{{ settings_page | safe }}
|
|
28
|
+
</div>
|
|
29
|
+
</div>
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
/* Javascript for HTMLXBlock. */
|
|
2
|
+
|
|
3
|
+
const CUSTOM_FONTS = "Default='Open Sans', Verdana, Arial, Helvetica, sans-serif;";
|
|
4
|
+
const STANDARD_FONTS = "Andale Mono=andale mono,times;" + "Arial=arial,helvetica,sans-serif;" + "Arial Black=arial black,avant garde;" + "Book Antiqua=book antiqua,palatino;" + "Comic Sans MS=comic sans ms,sans-serif;" + "Courier New=courier new,courier;" + "Georgia=georgia,palatino;" + "Helvetica=helvetica;" + "Impact=impact,chicago;" + "Symbol=symbol;" + "Tahoma=tahoma,arial,helvetica,sans-serif;" + "Terminal=terminal,monaco;" + "Times New Roman=times new roman,times;" + "Trebuchet MS=trebuchet ms,geneva;" + "Verdana=verdana,geneva;" + "Webdings=webdings;" + "Wingdings=wingdings,zapf dingbats";
|
|
5
|
+
const FONTS = CUSTOM_FONTS + STANDARD_FONTS;
|
|
6
|
+
|
|
7
|
+
function openTab(evt, tabName) {
|
|
8
|
+
/**
|
|
9
|
+
* This method has been adopted as found in https://www.w3schools.com/howto/howto_js_tabs.asp
|
|
10
|
+
*/
|
|
11
|
+
var i, tabcontent, tablinks;
|
|
12
|
+
tabcontent = document.getElementsByClassName("tabcontent");
|
|
13
|
+
for (i = 0; i < tabcontent.length; i++) {
|
|
14
|
+
tabcontent[i].style.display = "none";
|
|
15
|
+
}
|
|
16
|
+
tablinks = document.getElementsByClassName("tablinks");
|
|
17
|
+
for (i = 0; i < tablinks.length; i++) {
|
|
18
|
+
tablinks[i].className = tablinks[i].className.replace(" active", "");
|
|
19
|
+
tablinks[i].setAttribute("aria-selected", false);
|
|
20
|
+
}
|
|
21
|
+
document.getElementById(tabName).style.display = "block";
|
|
22
|
+
evt.currentTarget.className += " active";
|
|
23
|
+
evt.currentTarget.setAttribute("aria-selected", true);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function configureTheEditor(data) {
|
|
27
|
+
const contentSelector = "textarea#markdown-textarea";
|
|
28
|
+
const languageWrapper = document.querySelectorAll(".wrapper-view, .window-wrap");
|
|
29
|
+
const directionality = (languageWrapper.length > 0) ? languageWrapper.dir : "ltr";
|
|
30
|
+
var editor;
|
|
31
|
+
|
|
32
|
+
editor = CodeMirror.fromTextArea(document.querySelectorAll(contentSelector)[0], {
|
|
33
|
+
mode: "markdown",
|
|
34
|
+
lineNumbers: true,
|
|
35
|
+
matchBrackets: true,
|
|
36
|
+
lineWrapping: true,
|
|
37
|
+
theme: "default"
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
return editor;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function getSettingsValues(fields) {
|
|
44
|
+
var values = {};
|
|
45
|
+
var notSet = []; // List of field names that should be set to default values
|
|
46
|
+
for (var i in fields) {
|
|
47
|
+
var field = fields[i];
|
|
48
|
+
if (field.isSet()) {
|
|
49
|
+
values[field.name] = field.val();
|
|
50
|
+
} else {
|
|
51
|
+
notSet.push(field.name);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return {
|
|
56
|
+
values: values,
|
|
57
|
+
defaults: notSet
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function extractXBlockFields() {
|
|
62
|
+
/**
|
|
63
|
+
* The content of this function is as found in xblockutils#studio_edit.js
|
|
64
|
+
*/
|
|
65
|
+
var elements;
|
|
66
|
+
var fields = [];
|
|
67
|
+
|
|
68
|
+
elements = document.querySelectorAll(".field-data-control");
|
|
69
|
+
Array.prototype.forEach.call(elements, function (item) {
|
|
70
|
+
var $field = $(item);
|
|
71
|
+
var $wrapper = $field.closest('li');
|
|
72
|
+
var $resetButton = $wrapper.find('button.setting-clear');
|
|
73
|
+
var type = $wrapper.data('cast');
|
|
74
|
+
|
|
75
|
+
fields.push({
|
|
76
|
+
name: $wrapper.data('field-name'),
|
|
77
|
+
isSet: function () {
|
|
78
|
+
return $wrapper.hasClass('is-set');
|
|
79
|
+
},
|
|
80
|
+
val: function () {
|
|
81
|
+
var val = $field.val();
|
|
82
|
+
// Cast values to the appropriate type so that we send nice clean JSON over the wire:
|
|
83
|
+
if (type == 'boolean')
|
|
84
|
+
return (val == 'true' || val == '1');
|
|
85
|
+
if (type == "integer")
|
|
86
|
+
return parseInt(val, 10);
|
|
87
|
+
if (type == "float")
|
|
88
|
+
return parseFloat(val);
|
|
89
|
+
if (type == "generic" || type == "list" || type == "set") {
|
|
90
|
+
val = val.trim();
|
|
91
|
+
if (val === "")
|
|
92
|
+
val = null;
|
|
93
|
+
else
|
|
94
|
+
val = JSON.parse(val);
|
|
95
|
+
}
|
|
96
|
+
return val;
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
var fieldChanged = function () {
|
|
100
|
+
// Field value has been modified:
|
|
101
|
+
$wrapper.addClass('is-set');
|
|
102
|
+
$resetButton.removeClass('inactive').addClass('active');
|
|
103
|
+
};
|
|
104
|
+
$field.bind("change input paste", fieldChanged);
|
|
105
|
+
$resetButton.click(function () {
|
|
106
|
+
$field.val($wrapper.attr('data-default')); // Use attr instead of data to force treating the default value as a string
|
|
107
|
+
$wrapper.removeClass('is-set');
|
|
108
|
+
$resetButton.removeClass('active').addClass('inactive');
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
var datepickerAvailable = (typeof $.fn.datepicker !== 'undefined'); // Studio includes datepicker jQuery plugin
|
|
112
|
+
if (type == 'datepicker' && datepickerAvailable) {
|
|
113
|
+
$field.datepicker('destroy');
|
|
114
|
+
$field.datepicker({dateFormat: "m/d/yy"});
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
elements = document.querySelectorAll(".wrapper-list-settings .list-set");
|
|
119
|
+
Array.prototype.forEach.call(elements, function (item) {
|
|
120
|
+
var $optionList = $(item);
|
|
121
|
+
var $checkboxes = $(item).find('input');
|
|
122
|
+
var $wrapper = $optionList.closest('li');
|
|
123
|
+
var $resetButton = $wrapper.find('button.setting-clear');
|
|
124
|
+
|
|
125
|
+
fields.push({
|
|
126
|
+
name: $wrapper.data('field-name'),
|
|
127
|
+
isSet: function () {
|
|
128
|
+
return $wrapper.hasClass('is-set');
|
|
129
|
+
},
|
|
130
|
+
val: function () {
|
|
131
|
+
var val = [];
|
|
132
|
+
$checkboxes.each(function () {
|
|
133
|
+
if ($(item).is(':checked')) {
|
|
134
|
+
val.push(JSON.parse($(item).val()));
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
return val;
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
var fieldChanged = function () {
|
|
142
|
+
// Field value has been modified:
|
|
143
|
+
$wrapper.addClass('is-set');
|
|
144
|
+
$resetButton.removeClass('inactive').addClass('active');
|
|
145
|
+
};
|
|
146
|
+
$checkboxes.bind("change input", fieldChanged);
|
|
147
|
+
|
|
148
|
+
$resetButton.click(function () {
|
|
149
|
+
var defaults = JSON.parse($wrapper.attr('data-default'));
|
|
150
|
+
$checkboxes.each(function () {
|
|
151
|
+
var val = JSON.parse($(item).val());
|
|
152
|
+
$(item).prop('checked', defaults.indexOf(val) > -1);
|
|
153
|
+
});
|
|
154
|
+
$wrapper.removeClass('is-set');
|
|
155
|
+
$resetButton.removeClass('active').addClass('inactive');
|
|
156
|
+
});
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
return fields;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
function MarkdownXBlock(runtime, element, data) {
|
|
163
|
+
document.getElementById("default-tab").click(); // Will open the XBlock by showing the default tab
|
|
164
|
+
|
|
165
|
+
const editor = configureTheEditor(data);
|
|
166
|
+
var fields = extractXBlockFields();
|
|
167
|
+
var elements;
|
|
168
|
+
|
|
169
|
+
function studioSubmit() {
|
|
170
|
+
const ContentHandlerUrl = runtime.handlerUrl(element, "update_content");
|
|
171
|
+
const SettingsHandlerUrl = runtime.handlerUrl(element, "submit_studio_edits");
|
|
172
|
+
const content = editor.getValue();
|
|
173
|
+
const fields_data = getSettingsValues(fields);
|
|
174
|
+
var errorMessage = "This may be happening because of an error with our server or your internet connection. Try refreshing the page or making sure you are online.";
|
|
175
|
+
|
|
176
|
+
runtime.notify('save', {state: 'start', message: "Saving"});
|
|
177
|
+
$.ajax({
|
|
178
|
+
type: "POST",
|
|
179
|
+
url: SettingsHandlerUrl,
|
|
180
|
+
data: JSON.stringify(fields_data),
|
|
181
|
+
dataType: "json",
|
|
182
|
+
global: false, // Disable Studio's error handling that conflicts with studio's notify('save') and notify('cancel') :-/
|
|
183
|
+
success: function (response) {
|
|
184
|
+
$.ajax({
|
|
185
|
+
type: "POST",
|
|
186
|
+
url: ContentHandlerUrl,
|
|
187
|
+
data: JSON.stringify({"content": content}),
|
|
188
|
+
dataType: "json",
|
|
189
|
+
global: false, // Disable Studio's error handling that conflicts with studio's notify('save') and notify('cancel') :-/
|
|
190
|
+
success: function (response) {
|
|
191
|
+
runtime.notify('save', {state: 'end'});
|
|
192
|
+
}
|
|
193
|
+
}).fail(function (jqXHR) {
|
|
194
|
+
runtime.notify('error', {title: "Unable to update content", message: errorMessage});
|
|
195
|
+
})
|
|
196
|
+
}
|
|
197
|
+
}).fail(function (jqXHR) {
|
|
198
|
+
if (jqXHR.responseText) { // Is there a more specific error message we can show?
|
|
199
|
+
try {
|
|
200
|
+
errorMessage = JSON.parse(jqXHR.responseText).error;
|
|
201
|
+
if (typeof errorMessage === "object" && errorMessage.messages) {
|
|
202
|
+
// e.g. {"error": {"messages": [{"text": "Unknown user 'bob'!", "type": "error"}, ...]}} etc.
|
|
203
|
+
errorMessage = $.map(errorMessage.messages, function (msg) {
|
|
204
|
+
return msg.text;
|
|
205
|
+
}).join(", ");
|
|
206
|
+
}
|
|
207
|
+
} catch (error) {
|
|
208
|
+
errorMessage = jqXHR.responseText.substr(0, 300);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
runtime.notify('error', {title: "Unable to update settings", message: errorMessage});
|
|
212
|
+
})
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
element = typeof element[0] === 'undefined' ? element : element[0]; // Fix: sometimes edX passes a jQuery
|
|
216
|
+
// element, other times a DOM element
|
|
217
|
+
|
|
218
|
+
const addClickFn = function (el, fn) {
|
|
219
|
+
el.addEventListener("click", function (event) {
|
|
220
|
+
event.preventDefault();
|
|
221
|
+
fn(event);
|
|
222
|
+
});
|
|
223
|
+
};
|
|
224
|
+
|
|
225
|
+
element.querySelectorAll('.save-button').forEach(button => {
|
|
226
|
+
addClickFn(button, studioSubmit);
|
|
227
|
+
});
|
|
228
|
+
element.querySelectorAll('.cancel-button').forEach(button => {
|
|
229
|
+
addClickFn(button, function () {
|
|
230
|
+
runtime.notify('cancel', {});
|
|
231
|
+
});
|
|
232
|
+
});
|
|
233
|
+
}
|