0

ここに興味深い問題があります。ユーザーが複数の要素を選択し、ボタンをクリックして新しいタグを選択できるようにしたいと考えています。私の現在のコードは次のようになります。

sel = editor.getSelection()
ranges = sel.getRanges()
# Iterate through the selection ranges
for range in ranges
    iterator = range.createIterator()
    paragraphs = []
    # Iterate through the blocks in the range
    while (block = iterator.getNextParagraph())
        # Undo the style if it's already applied 
        if (block.getName() == tagName) 
            tagName = 'p'
        paragraphs.push( block )
    if paragraphs.length
        # Create the new element
        bqBlock = editor.document.createElement(tagName)
        bqBlock.insertBefore( paragraphs[0] )
        # Move each child in the selection into the new element
        while ( paragraphs.length > 0 )
            block = paragraphs.shift()
            block.moveChildren(bqBlock)
            block.remove()

これはうまく機能しますが、選択が消去されることを除いて、これはひどくユーザーフレンドリーではありません. 元の選択を維持したいと思います。

これを行う組み込みの方法がある場合は、ckeditorを使用しています。

編集:

Reinmar が答えを見つけてくれました: Set cursor to specific position in CKEditor

4

0 に答える 0