CKEditor
選択した単語を<p>
要素にラップしたかったのです。
から:
<p>This is a paragraph. And this is Selected text.</p>
に:
<p>This is a paragraph. And this is</p>
<p class="myclass">Selected text.</p>
私はいくつかのコードを見つけました:
( function() {
CKEDITOR.plugins.add( 'qna', {
init: function( editor ) {
editor.addCommand( 'insertQnA', {
exec : function( editor ) {
if(CKEDITOR.env.ie) {
editor.getSelection().unlock(true);
var selected_text = editor.getSelection().getNative().createRange().text;
} else {
var selected_text = editor.getSelection().getNative();
}
editor.insertHtml('[before]' + selected_text + '[after]');
}
});
editor.ui.addButton( 'qna', {
label: 'Insert QnA',
command: 'insertQnA',
icon: this.path + 'images/qna.png'
});
}
});
})();
[before]
and[after]
を<p class"myclass">
andに置き換えたかったの</p>
ですが、うまくいきません。
私はJS/Jqueryの初心者です。あなたが私のためにそれに光を当ててくれることを願っています。
編集:Sponの返信から。
( function() {
CKEDITOR.plugins.add( 'qna', {
init: function( editor ) {
editor.addCommand( 'insertQnA', {
exec : function( editor ) {
editor.applyStyle(new CKEDITOR.style({
Element : 'p',
Attributes : { class : 'Myclass' },
Styles : { color : '#ff0000','font-family' : 'Courier'}
}));
}
});
editor.ui.addButton( 'qna', {
label: 'Insert QnA',
command: 'insertQnA',
icon: this.path + 'images/question.png'
});
}
});
})();
上記のコードは、<span>
何らかの理由で選択されたテキスト/単語を要素にラップします。
例:
から...
<p>This is a paragraph. And this is Selected text.</p>
に...
<p>This is a paragraph. And this is <span>Selected text.</span></p>
これは私が望むものではありません。