Skip to content

Commit

Permalink
Localize ckeditor
Browse files Browse the repository at this point in the history
  • Loading branch information
mbohal committed Jun 24, 2016
1 parent 657269b commit fd47a0d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
6 changes: 6 additions & 0 deletions src/js/ckeditor-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@
// and thus it would make it impossible to test this part of the code.
$(window).load(function () {
$('[data-onload-ckeditor]').each(function () {
var language = $('html').attr('lang');
var confObj = {};
var $this = $(this);
var confValue = $this.data('onload-ckeditor');

if (confValue) {
if (typeof confValue === 'object') {
confObj = confValue;
Expand All @@ -20,6 +22,10 @@
}
}

if (language) {
confObj.language = language;
}

$this.ckeditor(confObj);
});
});
Expand Down
15 changes: 15 additions & 0 deletions src/js/tests/unit/ckeditor-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,19 @@ $(function () {
);
});

QUnit.test('should init ckeditor on page load with correct language settings', function () {
var $textarea = $('<textarea data-onload-ckeditor></textarea>');
$('#qunit-fixture').append($textarea);

sinon.spy(jQuery.fn, 'ckeditor');
$('html').attr('lang', 'cs');
$(window).trigger('load');

QUnit.ok(jQuery.fn.ckeditor.calledOnce, 'Should init the ckeditor');
QUnit.ok(
jQuery.fn.ckeditor.calledWithExactly({ language: 'cs' }),
'Should init the ckeditor with proper config object'
);
});

});
4 changes: 2 additions & 2 deletions src/less/components/javascript/ckeditor-loader.less
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ options.
### Usage
This loader only calls the jQuery plugin defined in CKEditor jQuery adapter with appropriate arguments. Id does nothing
else.
This loader only calls the jQuery plugin defined in CKEditor jQuery adapter with appropriate arguments.
If the `lang` attribute is set on the `<html>` element the CKEditor is localized accordingly.
#### Data-API
Expand Down

0 comments on commit fd47a0d

Please sign in to comment.