本文整理汇总了TypeScript中@ephox/dom-globals.DocumentFragment类的典型用法代码示例。如果您正苦于以下问题:TypeScript DocumentFragment类的具体用法?TypeScript DocumentFragment怎么用?TypeScript DocumentFragment使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DocumentFragment类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: Schema
UnitTest.asynctest('browser.tinymce.core.content.InsertListTest', (success, failure) => {
const suite = LegacyUnit.createSuite();
const schema = Schema({});
const createFragment = function (html) {
const parser = DomParser({ validate: false });
const fragment = parser.parse(html);
return fragment;
};
const createDomFragment = function (html): DocumentFragment {
return DOMUtils.DOM.createFragment(html);
};
suite.test('isListFragment', function () {
LegacyUnit.equal(InsertList.isListFragment(schema, createFragment('<ul><li>x</li></ul>')), true);
LegacyUnit.equal(InsertList.isListFragment(schema, createFragment('<ol><li>x</li></ol>')), true);
LegacyUnit.equal(InsertList.isListFragment(schema, createFragment('<meta><ul><li>x</li></ul>')), true);
LegacyUnit.equal(InsertList.isListFragment(schema, createFragment('<ul><li>x</li></ul><span id="mce_marker"></span>')), true);
LegacyUnit.equal(InsertList.isListFragment(schema, createFragment('<ul><li>x</li></ul><p><br></p>')), true);
LegacyUnit.equal(InsertList.isListFragment(schema, createFragment('<ul><li>x</li></ul><p></p>')), true);
LegacyUnit.equal(InsertList.isListFragment(schema, createFragment('<ul><li>x</li></ul><p>\u00a0</p>')), true);
LegacyUnit.equal(InsertList.isListFragment(schema, createFragment('<ul><li>x</li></ul><p>x</p>')), false);
LegacyUnit.equal(InsertList.isListFragment(schema, createFragment('<div></div>')), false);
});
suite.test('listItems', function () {
const list = createDomFragment('<ul><li>a</li><li>b</li><li>c</li></ul>').firstChild as HTMLUListElement;
LegacyUnit.equal(InsertList.listItems(list).length, 3);
LegacyUnit.equal(InsertList.listItems(list)[0].nodeName, 'LI');
});
suite.test('trimListItems', function () {
const list = createDomFragment('<ul><li>a</li><li>b</li><li></li></ul>').firstChild as HTMLUListElement;
LegacyUnit.equal(InsertList.listItems(list).length, 3);
LegacyUnit.equal(InsertList.trimListItems(InsertList.listItems(list)).length, 2);
});
Pipeline.async({}, suite.toSteps({}), function () {
success();
}, failure);
});
示例2: Theme
UnitTest.asynctest('browser.tinymce.core.selection.RangeInsertNode', (success, failure) => {
Theme();
const sRangeInsertNode = (editor: Editor, node: Node | DocumentFragment) => {
return Step.sync(() => {
rangeInsertNode(editor.dom, editor.selection.getRng(), node);
});
};
const fragmentFromHtml = (html: string, scope: Document): DocumentFragment => {
return Fragment.fromElements(Elements.fromHtml(html, scope), scope).dom();
};
TinyLoader.setup((editor: Editor, onSuccess, onFailure) => {
const tinyApis = TinyApis(editor);
const doc = editor.getDoc();
Pipeline.async({}, [
Logger.t('Insert node at start of text', GeneralSteps.sequence([
tinyApis.sFocus,
tinyApis.sSetRawContent('<p>a</p>'),
tinyApis.sSetCursor([0, 0], 0),
sRangeInsertNode(editor, doc.createTextNode('X')),
tinyApis.sAssertContentStructure(
ApproxStructure.build((s, str, arr) => {
return s.element('body', {
children: [
s.element('p', {
children: [
s.text(str.is('X')),
s.text(str.is('a'))
]
})
]
});
})
)
])),
Logger.t('Insert node at end of text', GeneralSteps.sequence([
tinyApis.sFocus,
tinyApis.sSetRawContent('<p>a</p>'),
tinyApis.sSetCursor([0, 0], 1),
sRangeInsertNode(editor, doc.createTextNode('X')),
tinyApis.sAssertContentStructure(
ApproxStructure.build((s, str, arr) => {
return s.element('body', {
children: [
s.element('p', {
children: [
s.text(str.is('a')),
s.text(str.is('X'))
]
})
]
});
})
)
])),
Logger.t('Insert document fragment at start of text', GeneralSteps.sequence([
tinyApis.sFocus,
tinyApis.sSetRawContent('<p>a</p>'),
tinyApis.sSetCursor([0, 0], 0),
sRangeInsertNode(editor, fragmentFromHtml('X', doc)),
tinyApis.sAssertContentStructure(
ApproxStructure.build((s, str, arr) => {
return s.element('body', {
children: [
s.element('p', {
children: [
s.text(str.is('X')),
s.text(str.is('a'))
]
})
]
});
})
)
])),
], onSuccess, onFailure);
}, {
indent: false,
skin_url: '/project/js/tinymce/skins/lightgray'
}, success, failure);
});
示例3: function
const insertAt = function (elm: Element, html: string, index: number) {
const fragment = createFragment(html);
if (elm.hasChildNodes() && index < elm.childNodes.length) {
const target = elm.childNodes[index];
target.parentNode.insertBefore(fragment, target);
} else {
elm.appendChild(fragment);
}
};
示例4: TinyApis
TinyLoader.setup((editor: Editor, onSuccess, onFailure) => {
const tinyApis = TinyApis(editor);
const doc = editor.getDoc();
Pipeline.async({}, [
Logger.t('Insert node at start of text', GeneralSteps.sequence([
tinyApis.sFocus,
tinyApis.sSetRawContent('<p>a</p>'),
tinyApis.sSetCursor([0, 0], 0),
sRangeInsertNode(editor, doc.createTextNode('X')),
tinyApis.sAssertContentStructure(
ApproxStructure.build((s, str, arr) => {
return s.element('body', {
children: [
s.element('p', {
children: [
s.text(str.is('X')),
s.text(str.is('a'))
]
})
]
});
})
)
])),
Logger.t('Insert node at end of text', GeneralSteps.sequence([
tinyApis.sFocus,
tinyApis.sSetRawContent('<p>a</p>'),
tinyApis.sSetCursor([0, 0], 1),
sRangeInsertNode(editor, doc.createTextNode('X')),
tinyApis.sAssertContentStructure(
ApproxStructure.build((s, str, arr) => {
return s.element('body', {
children: [
s.element('p', {
children: [
s.text(str.is('a')),
s.text(str.is('X'))
]
})
]
});
})
)
])),
Logger.t('Insert document fragment at start of text', GeneralSteps.sequence([
tinyApis.sFocus,
tinyApis.sSetRawContent('<p>a</p>'),
tinyApis.sSetCursor([0, 0], 0),
sRangeInsertNode(editor, fragmentFromHtml('X', doc)),
tinyApis.sAssertContentStructure(
ApproxStructure.build((s, str, arr) => {
return s.element('body', {
children: [
s.element('p', {
children: [
s.text(str.is('X')),
s.text(str.is('a'))
]
})
]
});
})
)
])),
], onSuccess, onFailure);
}, {
示例5: function
suite.test('trimListItems', function () {
const list = createDomFragment('<ul><li>a</li><li>b</li><li></li></ul>').firstChild as HTMLUListElement;
LegacyUnit.equal(InsertList.listItems(list).length, 3);
LegacyUnit.equal(InsertList.trimListItems(InsertList.listItems(list)).length, 2);
});