当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript dom-globals.DocumentFragment类代码示例

本文整理汇总了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);
});
开发者ID:tinymce,项目名称:tinymce,代码行数:45,代码来源:InsertListTest.ts

示例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);
});
开发者ID:danielpunkass,项目名称:tinymce,代码行数:84,代码来源:RangeInsertNodeTest.ts

示例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);
  }
};
开发者ID:danielpunkass,项目名称:tinymce,代码行数:9,代码来源:Fragments.ts

示例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);
  }, {
开发者ID:danielpunkass,项目名称:tinymce,代码行数:67,代码来源:RangeInsertNodeTest.ts

示例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);
  });
开发者ID:tinymce,项目名称:tinymce,代码行数:6,代码来源:InsertListTest.ts


注:本文中的@ephox/dom-globals.DocumentFragment类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。