ノードサイズ制限の問題を解決するための最初のアプローチを提供します。unescapeHtml コードを変更して、Firefox のデータ分割を複数のノードに処理するようにしました。これには、各 childNode を循環し、nodeValues を結果に追加するループを作成します。この関数は、 Matt Thommes の簡潔なすべての子ノードを削除するコードを使用してノードをクリーンアップします。
私のコードは以下のとおりです。
//htmlToCKEditor
// Arguments:
// 1. contentCK - Escaped content (likely HTML) to be inserted into CKEditor. (string)
// 2. targetCK- The ID of the target CKEditor instance. (string)
// Creates a temporary element, inserts the escaped content into the innerHTML,
// loops over every childNode, appends each nodeValue to the result string,
// removes the temporary element's child nodes, sets the data of the CKEditor to the new unescaped value.
function htmlToCKEditor (contentCK,targetCK) {
// Return false if there's no target CKEditor instance
if (!(targetCK.match(/\w+/))){
return false;
}
if (contentCK.match(/\w+/)){
var thisHTML = unescape(contentCK);
var temp = document.createElement("div");
temp.innerHTML = thisHTML;
// Loop over childNodes and append values to result variable.
var result = '';
for (var i=0; i < temp.childNodes.length; i++){
result += temp.childNodes[i].nodeValue;
}
// Cleanup from Matt Thommes
if (temp.hasChildNodes()){
while (temp.childNodes.length >= 1){
temp.removeChild(temp.firstChild);
}
}
// Set CKEditor instance of choice with the newly unescaped result.
CKEDITOR.instances[targetCK].setData(result);
}else{
CKEDITOR.instances[targetCK].setData('');
}
return true;
}
これを達成するために取ることができる代替アプローチがいくつかあるので、質問を洗練し、コードを回答として分割しました。私はCKEditorメソッドに完全に精通しているわけではなく、CKEditorに組み込まれているより簡単なソリューションがあるかもしれないので、この質問に対するより多くの解決策を読みたいと思っています.