當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。