Skip to content

Commit f324f1d

Browse files
committed
MOBILE-1701 assign: Fix word count in onlinetext
1 parent ac5e333 commit f324f1d

File tree

3 files changed

+22
-5
lines changed

3 files changed

+22
-5
lines changed

www/addons/mod/assign/submission/onlinetext/directive.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,17 @@ angular.module('mm.addons.mod_assign')
9090
// Text changed in first render.
9191
scope.firstRender = function() {
9292
scope.plugin.rteInitialText = scope.model.text;
93+
94+
// Calculate words.
95+
if (scope.configs.wordlimitenabled) {
96+
scope.words = $mmText.countWords(scope.model.text);
97+
}
9398
};
99+
100+
// Rte not enabled, calculate words since firstRender won't be called.
101+
if (!rteEnabled && scope.configs.wordlimitenabled) {
102+
scope.words = $mmText.countWords(scope.model.text);
103+
}
94104
});
95105
}
96106
};

www/core/directives/richtexteditor.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ angular.module('mm.core')
4444
* @param {String} [name] Name to set to the hidden textarea.
4545
* @param {Function} [textChange] Function to call when the editor text changes.
4646
* @param {Function} [firstRender] Function to call when the editor text is first rendered. Only called with rich text editor.
47-
* This function will only be called if the editor changes the text when rendering it.
4847
* @param {String} [component] The component to link the files to.
4948
* @param {Mixed} [componentId] An ID to use in conjunction with the component.
5049
*/
@@ -352,6 +351,16 @@ angular.module('mm.core')
352351
});
353352
}
354353

354+
// If text isn't changed we won't throw firstRender, so throw it manually.
355+
if (scope.richTextEditor && scope.firstRender) {
356+
$timeout(function() {
357+
if (firstChange) {
358+
scope.firstRender();
359+
firstChange = false;
360+
}
361+
}, 1000);
362+
}
363+
355364
// Get editor controller.
356365
editorController = getCKEditorController(element);
357366

@@ -389,9 +398,7 @@ angular.module('mm.core')
389398
// Text changed.
390399
scope.onChange = function() {
391400
if (scope.richTextEditor && firstChange && scope.firstRender && new Date().getTime() - renderTime < 1000) {
392-
// On change triggered by first rendering. Store the value as the initial text.
393-
// This is because rich text editor performs some minor changes (like new lines),
394-
// and we don't want to detect those as real user changes.
401+
// On change triggered by first rendering, call firstRender.
395402
scope.firstRender();
396403
}
397404
firstChange = false;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<div ng-if="richTextEditor === true || richTextEditor === false" ng-class="{'mm-rich-text-editor-container': richTextEditor}" data-tap-disabled="{{richTextEditor}}">
22
<!-- This textarea won't be seen, but we set {{model.text}} inside it so it can be retrieved via plain JS. -->
33
<textarea ng-if="richTextEditor" ckeditor="editorOptions" ng-model="model.text" ready="editorReady()" placeholder="{{ placeholder }}" name="{{name}}" ng-change="onChange()">{{model.text}}</textarea>
4-
<textarea ng-if="!richTextEditor" class="mm-textarea" placeholder="{{ placeholder }}" name="{{name}}" ng-model="model.text" aria-multiline="true"></textarea>
4+
<textarea ng-if="!richTextEditor" class="mm-textarea" placeholder="{{ placeholder }}" name="{{name}}" ng-model="model.text" aria-multiline="true" ng-change="onChange()"></textarea>
55
</div>

0 commit comments

Comments
 (0)