Skip to content

Commit

Permalink
Merge branch 'MDL-74766-400' of https://github.com/JBThong/moodle int…
Browse files Browse the repository at this point in the history
…o MOODLE_400_STABLE
  • Loading branch information
snake committed Aug 4, 2022
2 parents 1cc0b48 + abb6bc9 commit f5342a2
Show file tree
Hide file tree
Showing 11 changed files with 143 additions and 6 deletions.
19 changes: 19 additions & 0 deletions lib/editor/atto/plugins/html/tests/behat/html.feature
Expand Up @@ -10,3 +10,22 @@ Feature: Atto edit HTML
And I click on "Show more buttons" "button"
And I click on "HTML" "button"
Then the field "Description" matches value "<p style=\"color: blue;\">Smurf</p>"

@javascript
Scenario: Validation of empty string when the form is submitted with HTML source mode.
Given the following "courses" exist:
| fullname | shortname | format |
| Course 1 | C1 | weeks |
And the following "question categories" exist:
| contextlevel | reference | name |
| Course | C1 | Test questions |
And the following "questions" exist:
| questioncategory | qtype | name | questiontext |
| Test questions | essay | Essay 01 new | Write about whatever you want |
And I am on the "Essay 01 new" "core_question > edit" page logged in as admin
And I click on "Show more buttons" "button" in the "Question text" "form_row"
And I click on "HTML" "button" in the "Question text" "form_row"
And I press the shift + end key
And I press the delete key
When I press "id_submitbutton"
Then I should see "You must supply a value here." in the "Question text" "form_row"
Expand Up @@ -132,6 +132,10 @@ Y.namespace('M.atto_html').Button = Y.Base.create('button', Y.M.editor_atto.Edit
_hideCodeMirror: function() {
var host = this.get('host');

// Disable placeholder for empty content.
// This will prevent the editor to copy and submit the empty placeholder.
host.disablePlaceholderForEmptyContent();

// Enable all plugins.
host.enablePlugins();

Expand Down Expand Up @@ -164,6 +168,9 @@ Y.namespace('M.atto_html').Button = Y.Base.create('button', Y.M.editor_atto.Edit

// And re-mark everything as updated.
this.markUpdated();

// Enable placeholder for empty content.
host.enablePlaceholderForEmptyContent();
}
}, {
ATTRS: {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Expand Up @@ -132,6 +132,10 @@ Y.namespace('M.atto_html').Button = Y.Base.create('button', Y.M.editor_atto.Edit
_hideCodeMirror: function() {
var host = this.get('host');

// Disable placeholder for empty content.
// This will prevent the editor to copy and submit the empty placeholder.
host.disablePlaceholderForEmptyContent();

// Enable all plugins.
host.enablePlugins();

Expand Down Expand Up @@ -164,6 +168,9 @@ Y.namespace('M.atto_html').Button = Y.Base.create('button', Y.M.editor_atto.Edit

// And re-mark everything as updated.
this.markUpdated();

// Enable placeholder for empty content.
host.enablePlaceholderForEmptyContent();
}
}, {
ATTRS: {
Expand Down
7 changes: 7 additions & 0 deletions lib/editor/atto/plugins/html/yui/src/button/js/button.js
Expand Up @@ -130,6 +130,10 @@ Y.namespace('M.atto_html').Button = Y.Base.create('button', Y.M.editor_atto.Edit
_hideCodeMirror: function() {
var host = this.get('host');

// Disable placeholder for empty content.
// This will prevent the editor to copy and submit the empty placeholder.
host.disablePlaceholderForEmptyContent();

// Enable all plugins.
host.enablePlugins();

Expand Down Expand Up @@ -162,6 +166,9 @@ Y.namespace('M.atto_html').Button = Y.Base.create('button', Y.M.editor_atto.Edit

// And re-mark everything as updated.
this.markUpdated();

// Enable placeholder for empty content.
host.enablePlaceholderForEmptyContent();
}
}, {
ATTRS: {
Expand Down
10 changes: 10 additions & 0 deletions lib/editor/atto/upgrade.txt
@@ -1,5 +1,15 @@
This files describes API changes in the editor_atto code.

=== 4.0 ===

* Two new helper functions have been added to lib/editor/atto
to handle enable/disable the empty placeholder for empty content in the HTML source view:
- enablePlaceholderForEmptyContent() - Handle to enable the empty placeholder for empty content
- disablePlaceholderForEmptyContent() - Handle to disable the empty placeholder for empty content.

* One property have been added to lib/editor/atto to handle the state of the empty placeholder content.
- enableAppropriateEmptyContent - Enable/disable the empty placeholder content.

=== 3.4 ===

* The following functions, previously used (exclusively) by upgrade steps are not available
Expand Down
Expand Up @@ -158,6 +158,14 @@ Y.extend(Editor, Y.Base, {
*/
coreDirection: null,

/**
* Enable/disable the empty placeholder content.
*
* @property enableAppropriateEmptyContent
* @type Boolean
*/
enableAppropriateEmptyContent: null,

/**
* Event Handles to clear on editor destruction.
*
Expand Down Expand Up @@ -210,6 +218,9 @@ Y.extend(Editor, Y.Base, {
// Set diretcion according to current page language.
this.coreDirection = Y.one('body').hasClass('dir-rtl') ? 'rtl' : 'ltr';

// Enable the placeholder for empty content.
this.enablePlaceholderForEmptyContent();

// Add everything to the wrapper.
this.setupToolbar();

Expand Down Expand Up @@ -423,6 +434,20 @@ Y.extend(Editor, Y.Base, {
}
},

/**
* Enable the empty placeholder for empty content.
*/
enablePlaceholderForEmptyContent: function() {
this.enableAppropriateEmptyContent = true;
},

/**
* Disable the empty placeholder for empty content.
*/
disablePlaceholderForEmptyContent: function() {
this.enableAppropriateEmptyContent = false;
},

/**
* Register an event handle for disposal in the destructor.
*
Expand Down Expand Up @@ -695,6 +720,10 @@ EditorTextArea.prototype = {
* @private
*/
_getEmptyContent: function() {
if (!this.enableAppropriateEmptyContent) {
// Return the empty string if we do not enable the empty placeholder. Ex: HTML mode.
return '';
}
var alignment;
if (this.coreDirection === 'rtl') {
alignment = 'style="text-align: right;"';
Expand Down

0 comments on commit f5342a2

Please sign in to comment.