RichText/Archived/Rooster/Rooster.gcomp/Support/node_modules/roosterjs/dist/rooster-amd.js
/**
 * Toggle header at selection
 * @param editor The editor instance
 * @param level The header level, can be a number from 0 to 6, in which 1 ~ 6 refers to
 * the HTML header element &lt;H1&gt; to &lt;H6&gt;, 0 means no header
 * if passed in param is outside the range, will be rounded to nearest number in the range
 */
Toggle header at selection
@param editor The editor instance
@param level The header level, can be a number from 0 to 6, in which 1 ~ 6 refers to
the HTML header element <H1> to <H6>, 0 means no header
if passed in param is outside the range, will be rounded to nearest number in the range
Toggle header at selection @param editor The editor instance @param level The header level can be a number from 0 to 6 in which 1 ~ 6 refers to the HTML header element <H1 > to <H6 > 0 means no header if passed in param is outside the range will be rounded to nearest number in the range
function toggleHeader(editor, level) {
    level = Math.min(Math.max(Math.round(level), 0), 6);
    editor.addUndoSnapshot(function () {
        editor.focus();
        var wrapped = false;
        editor.queryElements('H1,H2,H3,H4,H5,H6', 1 , function (header) {
            if (!wrapped) {
                editor.getDocument().execCommand("formatBlock" , false, '<DIV>');
                wrapped = true;
            }
            var div = editor.getDocument().createElement('div');
            while (header.firstChild) {
                div.appendChild(header.firstChild);
            }
            editor.replaceNode(header, div);
        });
        if (level > 0) {
            var traverser = editor.getSelectionTraverser();
            var inlineElement = traverser ? traverser.currentInlineElement : null;
            while (inlineElement) {
                var element = roosterjs_editor_dom_1.findClosestElementAncestor(inlineElement.getContainerNode());
                if (element) {
                    element.style.fontSize = '';
                }
                inlineElement = traverser.getNextInlineElement();
            }
            editor.getDocument().execCommand("formatBlock" , false, "<H" + level + ">");
        }
    }, "Format" );
}
function toggleHeader ( editor , level ) { level = Math . min ( Math . max ( Math . round ( level ) , 0 ) , 6 ) ; editor . addUndoSnapshot ( function ( ) { editor . focus ( ) ; var wrapped = false ; editor . queryElements ( 'H1,H2,H3,H4,H5,H6' , 1 , function ( header ) { if ( ! wrapped ) { editor . getDocument ( ) . execCommand ( "formatBlock" , false , '<DIV>' ) ; wrapped = true ; } var div = editor . getDocument ( ) . createElement ( 'div' ) ; while ( header . firstChild ) { div . appendChild ( header . firstChild ) ; } editor . replaceNode ( header , div ) ; } ) ; if ( level > 0 ) { var traverser = editor . getSelectionTraverser ( ) ; var inlineElement = traverser ? traverser . currentInlineElement : null ; while ( inlineElement ) { var element = roosterjs_editor_dom_1 . findClosestElementAncestor ( inlineElement . getContainerNode ( ) ) ; if ( element ) { element . style . fontSize = '' ; } inlineElement = traverser . getNextInlineElement ( ) ; } editor . getDocument ( ) . execCommand ( "formatBlock" , false , "<H" + level + ">" ) ; } } , "Format" ) ; }
Toggle header at selection
 @param editor The editor instance
 @param level The header level, can be a number from 0 to 6, in which 1 ~ 6 refers to
 the HTML header element &lt;H1&gt; to &lt;H6&gt;, 0 means no header
 if passed in param is outside the range, will be rounded to nearest number in the range
Toggle header at selection @param editor The editor instance @param level The header level can be a number from 0 to 6 in which 1 ~ 6 refers to the HTML header element &lt ; H1&gt ; to &lt ; H6&gt ; 0 means no header if passed in param is outside the range will be rounded to nearest number in the range
/* OnSelection */ /* FormatBlock */ /* FormatBlock */ /* Format */