(js) Improve ckEditor directive

The directive will now consider the following attributes:

- ck-options: a JSON object of options
- ck-locale: the locale code to be used as the language and the speller
  language
feature/saveSortContacts
Francis Lachapelle 2015-08-06 16:04:39 -04:00
parent 8690cee221
commit ae017b50bc
1 changed files with 18 additions and 5 deletions

View File

@ -4,7 +4,8 @@
(function() {
'use strict';
angular.module('ck', []).directive('ckEditor', function() {
ckEditor.$inject = ['$parse'];
function ckEditor($parse) {
var calledEarly, loaded;
loaded = false;
calledEarly = false;
@ -39,7 +40,7 @@
},
link: function($scope, elm, attr, ngModel) {
var ck;
var ck, options = {}, locale;
if (!ngModel) {
return;
}
@ -49,7 +50,16 @@
}
loaded = false;
ck = CKEDITOR.replace(elm[0]);
if (attr.ckOptions)
options = angular.fromJson(attr.ckOptions.replace(/'/g, "\""));
if (attr.ckLocale) {
locale = $parse(attr.ckLocale)($scope);
options.language = locale;
options.scayt_sLang = locale;
}
ck = CKEDITOR.replace(elm[0], options);
ck.on('pasteState', function() {
$scope.$apply(function() {
ngModel.$setViewValue(ck.getData());
@ -61,6 +71,9 @@
};
}
};
});
}
angular
.module('ck', [])
.directive('ckEditor', ckEditor);
})();