导致我使用带角度的ckEditor的braindamage。 当我在用户点击答案按钮后尝试将ckEditor设为可编程时,ckEditor没有焦点。
我试过了:
ck.focus()
和
var focusManager = new CKEDITOR.focusManager(ck);
focusManager.focus();
无。在调用此方法之后,ckEditor仍然没有关注self。
angular指令(参见范围。$ on function):
angular.module('ck', []).directive('ckEditor', function() {
return {
require: '?ngModel',
link: function(scope, elm, attr, ngModel) {
var isReady = false;
var data = [];
var ck = CKEDITOR.replace(elm[0], {
customConfig: 'lite_config.js',
height: attr.height || 200
});
function setData() {
if (!data.length) {
return;
}
var d = data.splice(0, 1);
ck.setData(d[0] || '<span></span>', function() {
setData();
isReady = true;
});
}
ck.on('instanceReady', function(e) {
if (ngModel) {
setData();
}
});
elm.bind('$destroy', function() {
ck.destroy(false);
});
scope.$on('$focus', function() {
ck.focus();
var focusManager = new CKEDITOR.focusManager(ck);
focusManager.focus();
});
var onChange = function() {
scope.$apply(function() {
var data = ck.getData();
if (data == '<span></span>') {
data = null;
}
ngModel.$setViewValue(data);
});
};
if (ngModel) {
ck.on('change', function() {
onChange();
});
ck.on('paste', function() {
onChange();
});
ngModel.$render = function(value) {
if (ngModel.$viewValue === undefined) {
ngModel.$setViewValue(null);
ngModel.$viewValue = null;
}
data.push(ngModel.$viewValue);
if (isReady) {
isReady = false;
setData();
}
};
}
}
};
});
这就是我在角度控制器方法中的方法:
$scope.answer = function(parentComment) {
resetForking();
$scope.newComment = '';
$scope.answering = true;
parentCommentId = parentComment.comment.id;
answerContentId = parentComment.comment.initiativeContentId;
$scope.answerTo = parentComment.author.userName;
$scope.$broadcast('$focus');
utils.scrollDown();
};
答案 0 :(得分:0)
试试这个
CKEDITOR.replace('editor1',
{
on :
{
instanceReady : function( ev )
{
CKEDITOR.instances.editor1.focus();
}
}
} );