2014-12-11 17:24:22 +01:00
|
|
|
/* -*- Mode: javascript; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* JavaScript for CKEditor module */
|
|
|
|
|
|
|
|
(function() {
|
|
|
|
'use strict';
|
|
|
|
|
2015-08-06 22:04:39 +02:00
|
|
|
ckEditor.$inject = ['$parse'];
|
|
|
|
function ckEditor($parse) {
|
2014-12-11 17:24:22 +01:00
|
|
|
var calledEarly, loaded;
|
|
|
|
loaded = false;
|
|
|
|
calledEarly = false;
|
|
|
|
|
|
|
|
return {
|
|
|
|
restrict: 'C',
|
|
|
|
require: '?ngModel',
|
|
|
|
compile: function(element, attributes, transclude) {
|
|
|
|
var loadIt, local;
|
|
|
|
|
|
|
|
local = this;
|
|
|
|
loadIt = function() {
|
|
|
|
return calledEarly = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
element.ready(function() {
|
|
|
|
return loadIt();
|
|
|
|
});
|
|
|
|
|
|
|
|
return {
|
|
|
|
post: function($scope, element, attributes, controller) {
|
|
|
|
if (calledEarly) {
|
|
|
|
return local.link($scope, element, attributes, controller);
|
|
|
|
}
|
|
|
|
loadIt = (function($scope, element, attributes, controller) {
|
|
|
|
return function() {
|
|
|
|
local.link($scope, element, attributes, controller);
|
|
|
|
};
|
|
|
|
})($scope, element, attributes, controller);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
link: function($scope, elm, attr, ngModel) {
|
2015-08-06 22:04:39 +02:00
|
|
|
var ck, options = {}, locale;
|
2014-12-11 17:24:22 +01:00
|
|
|
if (!ngModel) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (calledEarly && !loaded) {
|
|
|
|
return loaded = true;
|
|
|
|
}
|
|
|
|
loaded = false;
|
|
|
|
|
2015-08-06 22:04:39 +02:00
|
|
|
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);
|
2014-12-11 17:24:22 +01:00
|
|
|
ck.on('pasteState', function() {
|
|
|
|
$scope.$apply(function() {
|
|
|
|
ngModel.$setViewValue(ck.getData());
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
ngModel.$render = function(value) {
|
|
|
|
ck.setData(ngModel.$viewValue);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
};
|
2015-08-06 22:04:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
angular
|
|
|
|
.module('ck', [])
|
|
|
|
.directive('ckEditor', ckEditor);
|
2014-12-11 17:24:22 +01:00
|
|
|
})();
|