TypeScript tinymce-plugins-fullpage-Plugin.default类(方法)实例源码

TypeScript
阅读 40 收藏 0 点赞 0 评论 0

项目: 作者:
作者:howardjin    项目:tinymc   
export default function () {
  AdvListPlugin();
  AnchorPlugin();
  AutoLinkPlugin();
  AutoResizePlugin();
  AutoSavePlugin();
  BbCodePlugin();
  CharMapPlugin();
  CodePlugin();
  CodeSamplePlugin();
  ColorPickerPlugin();
  ContextMenuPlugin();
  DirectionalityPlugin();
  EmoticonsPlugin();
  FullPagePlugin();
  FullScreenPlugin();
  HrPlugin();
  ImagePlugin();
  ImageToolsPlugin();
  ImportCssPlugin();
  InsertDatetimePlugin();
  LegacyOutputPlugin();
  LinkPlugin();
  ListsPlugin();
  MediaPlugin();
  NonBreakingPlugin();
  NonEditablePlugin();
  PageBreakPlugin();
  PastePlugin();
  PreviewPlugin();
  PrintPlugin();
  SavePlugin();
  SearchReplacePlugin();
  SpellCheckerPlugin();
  TabFocusPlugin();
  TablePlugin();
  TemplatePlugin();
  TextColorPlugin();
  TextPatternPlugin();
  TocPlugin();
  VisualBlocksPlugin();
  VisualCharsPlugin();
  WordCountPlugin();
  ModernTheme();
  MobileTheme();
  HelpPlugin();

  PluginManager.urls.emoticons = '../../../../js/tinymce/plugins/emoticons';

  const settings = {
    skin_url: '../../../../js/tinymce/skins/lightgray',
    codesample_content_css: '../../../../js/tinymce/plugins/codesample/css/prism.css',
    visualblocks_content_css: '../../../../js/tinymce/plugins/visualblocks/css/visualblocks.css',
    images_upload_url: 'd',
    selector: 'textarea',
    // rtl_ui: true,
    link_list: [
      { title: 'My page 1', value: 'http://www.tinymce.com' },
      { title: 'My page 2', value: 'http://www.moxiecode.com' }
    ],
    image_list: [
      { title: 'My page 1', value: 'http://www.tinymce.com' },
      { title: 'My page 2', value: 'http://www.moxiecode.com' }
    ],
    image_class_list: [
      { title: 'None', value: '' },
      { title: 'Some class', value: 'class-name' }
    ],
    importcss_append: true,
    height: 400,
    file_picker_callback (callback, value, meta) {
      // Provide file and text for the link dialog
      if (meta.filetype === 'file') {
        callback('https://www.google.com/logos/google.jpg', { text: 'My text' });
      }

      // Provide image and alt text for the image dialog
      if (meta.filetype === 'image') {
        callback('https://www.google.com/logos/google.jpg', { alt: 'My alt text' });
      }

      // Provide alternative source and posted for the media dialog
      if (meta.filetype === 'media') {
        callback('movie.mp4', { source2: 'alt.ogg', poster: 'https://www.google.com/logos/google.jpg' });
      }
    },
    spellchecker_callback (method, text, success, failure) {
      const words = text.match(this.getWordCharPattern());

      if (method === 'spellcheck') {
        const suggestions = {};

        for (let i = 0; i < words.length; i++) {
          suggestions[words[i]] = ['First', 'Second'];
        }

        success(suggestions);
      }

      if (method === 'addToDictionary') {
//.........这里部分代码省略.........

作者:howardjin    项目:tinymc   
export default function () {
  AdvListPlugin();
  AnchorPlugin();
  AutoLinkPlugin();
  AutoResizePlugin();
  AutoSavePlugin();
  BbCodePlugin();
  CharMapPlugin();
  CodePlugin();
  CodeSamplePlugin();
  ColorPickerPlugin();
  ContextMenuPlugin();
  DirectionalityPlugin();
  EmoticonsPlugin();
  FullPagePlugin();
  FullScreenPlugin();
  HrPlugin();
  ImagePlugin();
  ImageToolsPlugin();
  ImportCssPlugin();
  InsertDatetimePlugin();
  LegacyOutputPlugin();
  LinkPlugin();
  ListsPlugin();
  MediaPlugin();
  NonBreakingPlugin();
  NonEditablePlugin();
  PageBreakPlugin();
  PastePlugin();
  PreviewPlugin();
  PrintPlugin();
  SavePlugin();
  SearchReplacePlugin();
  SpellCheckerPlugin();
  TabFocusPlugin();
  TablePlugin();
  TemplatePlugin();
  TextColorPlugin();
  TextPatternPlugin();
  TocPlugin();
  VisualBlocksPlugin();
  VisualCharsPlugin();
  WordCountPlugin();
  ModernTheme();

  const cmd = function (command, value?) {
    return { command, value };
  };

  const commands = [
    cmd('Bold'),
    cmd('Italic'),
    cmd('Underline'),
    cmd('Strikethrough'),
    cmd('Superscript'),
    cmd('Subscript'),
    cmd('Cut'),
    cmd('Copy'),
    cmd('Paste'),
    cmd('Unlink'),
    cmd('JustifyLeft'),
    cmd('JustifyCenter'),
    cmd('JustifyRight'),
    cmd('JustifyFull'),
    cmd('JustifyNone'),
    cmd('InsertUnorderedList'),
    cmd('InsertOrderedList'),
    cmd('ForeColor', 'red'),
    cmd('HiliteColor', 'green'),
    cmd('FontName', 'Arial'),
    cmd('FontSize', 7),
    cmd('RemoveFormat'),
    cmd('mceBlockQuote'),
    cmd('FormatBlock', 'h1'),
    cmd('mceInsertContent', 'abc'),
    cmd('mceToggleFormat', 'bold'),
    cmd('mceSetContent', 'abc'),
    cmd('Indent'),
    cmd('Outdent'),
    cmd('InsertHorizontalRule'),
    cmd('mceToggleVisualAid'),
    cmd('mceInsertLink', 'url'),
    cmd('selectAll'),
    cmd('delete'),
    cmd('mceNewDocument'),
    cmd('Undo'),
    cmd('Redo'),
    cmd('mceAutoResize'),
    cmd('mceShowCharmap'),
    cmd('mceCodeEditor'),
    cmd('mceDirectionLTR'),
    cmd('mceDirectionRTL'),
    cmd('mceFullPageProperties'),
    cmd('mceFullscreen'),
    cmd('mceImage'),
    cmd('mceInsertDate'),
    cmd('mceInsertTime'),
    cmd('InsertDefinitionList'),
    cmd('mceNonBreaking'),
    cmd('mcePageBreak'),
//.........这里部分代码省略.........

作者:tinymc    项目:tinymc   
//.........这里部分代码省略.........
                      })
                    ]
                  }),
                  s.element('div', {
                    classes: [ arr.has('tox-dialog__footer') ]
                  })
                ]
              });
            }),
            dialog
          );
        })
      ]),
    ])
  );

  const sOpenDialog = (editor) => {
    return Logger.t('Open dialog', Step.sync(function () {
      editor.execCommand('mceFullPageProperties');
    }));
  };

  const cGetInput = (selector: string) => Chain.control(
    Chain.fromChains([
      Chain.inject(Body.body()),
      UiFinder.cFindIn(selector)
    ]),
    Guard.addLogging('Get input')
  );

  const sCheckInputValue = (Label, selector, expected) => {
    return Logger.t(Label,
      Chain.asStep({}, [
        cGetInput(selector),
        Chain.op((element) => {
          Assertions.assertEq(`The input value for ${Label} should be: `, expected, Value.get(element));
        })
      ]),
    );
  };

  TinyLoader.setup(function (editor, onSuccess, onFailure) {
    const doc = Element.fromDom(document);
    Pipeline.async({},
      Log.steps('TBA', 'FullPage: Test initial data, set new input values, open dialog, verify that the dialog data matches the input values', [

        sInitialState(editor),
        sCheckInputValue('Title', selectors.titleInput, 'Fullpage Dialog Test Title'),
        sCheckInputValue('Keywords', selectors.keywordsInput, ''),
        sCheckInputValue('Description', selectors.descriptionInput, ''),
        sCheckInputValue('Robots', selectors.robotsInput, ''),
        sCheckInputValue('Author', selectors.authorInput, ''),
        sCheckInputValue('Encoding', selectors.encodingInput, 'ISO-8859-1'),

        FocusTools.sTryOnSelector(
          'Focus should start on first input',
          doc,
          selectors.titleInput
        ),
        FocusTools.sSetActiveValue(doc, 'the nu title'),
        Keyboard.sKeydown(doc, Keys.tab(), { }),
        FocusTools.sSetActiveValue(doc, 'the nu keywords'),
        Keyboard.sKeydown(doc, Keys.tab(), { }),
        FocusTools.sSetActiveValue(doc, 'the nu description'),
        Keyboard.sKeydown(doc, Keys.tab(), { }),
        FocusTools.sSetActiveValue(doc, 'the nu robots'),
        Keyboard.sKeydown(doc, Keys.tab(), { }),
        FocusTools.sSetActiveValue(doc, 'the nu author'),
        Keyboard.sKeydown(doc, Keys.tab(), { }),
        FocusTools.sSetActiveValue(doc, 'the nu encoding'),
        FocusTools.sIsOnSelector('last', doc, selectors.encodingInput),

        Keyboard.sKeydown(doc, Keys.tab(), { }),
        FocusTools.sIsOnSelector('The cancel button should be focused', doc, 'button:contains("Cancel")'),
        Keyboard.sKeydown(doc, Keys.tab(), { }),
        FocusTools.sIsOnSelector('The save button should be focused', doc, 'button:contains("Save")'),
        Keyboard.sKeydown(doc, Keys.enter(), { }),
        UiFinder.sNotExists(Body.body(), 'div.tox-dialog'),

        sOpenDialog(editor),
        sCheckInputValue('Title', selectors.titleInput, 'the nu title'),
        sCheckInputValue('Keywords', selectors.keywordsInput, 'the nu keywords'),
        sCheckInputValue('Description', selectors.descriptionInput, 'the nu description'),
        sCheckInputValue('Robots', selectors.robotsInput, 'the nu robots'),
        sCheckInputValue('Author', selectors.authorInput, 'the nu author'),
        sCheckInputValue('Encoding', selectors.encodingInput, 'the nu encoding'),
    ]), onSuccess, onFailure);

  }, {
    plugins: 'fullpage',
    base_url: '/project/tinymce/js/tinymce',
    indent: false,
    theme: 'silver',
    fullpage_default_title: 'Fullpage Dialog Test Title',
    fullpage_default_langcode: 'en-US',
    fullpage_default_xml_pi: true,
    fullpage_default_text_color: 'blue',
    fullpage_default_font_family: '"Times New Roman", Georgia, Serif'
  }, success, failure);
});

作者:howardjin    项目:tinymc   
/**
 * Demo.js
 *
 * Released under LGPL License.
 * Copyright (c) 1999-2016 Ephox Corp. All rights reserved
 *
 * License: http://www.tinymce.com/license
 * Contributing: http://www.tinymce.com/contributing
 */

import FullPagePlugin from 'tinymce/plugins/fullpage/Plugin';

declare let tinymce: any;

FullPagePlugin();

tinymce.init({
  selector: 'textarea.tinymce',
  theme: 'modern',
  skin_url: '../../../../../js/tinymce/skins/lightgray',
  plugins: 'fullpage code',
  toolbar: 'fullpage code',
  height: 600
});

作者:tinymc    项目:tinymc   
UnitTest.asynctest('browser.tinymce.plugins.fullpage.FullPagePluginTest', function (success, failure) {

  const suite = LegacyUnit.createSuite();

  Plugin();
  Theme();

  const teardown = function (editor) {
    editor.getBody().rtl = '';
  };

  suite.test('TestCase-TBA: FullPage: Keep header/footer intact', function (editor) {
    const normalizeHTML = function (html) {
      return html.replace(/\s/g, '');
    };

    editor.setContent('<html><body><p>Test</p>');
    LegacyUnit.equal(normalizeHTML(editor.getContent()), '<html><body><p>Test</p>', 'Invalid HTML content is still editable.');

    editor.setContent('<html><body><p>Test</p></body></html>');
    LegacyUnit.equal(normalizeHTML(editor.getContent()), '<html><body><p>Test</p></body></html>', 'Header/footer is intact.');
  });

  suite.test('TestCase-TBA: FullPage: Default header/footer', function (editor) {
    editor.setContent('<p>Test</p>');
    LegacyUnit.equal(
      editor.getContent(),
      '<!DOCTYPE html>\n<html>\n<head>\n</head>\n<body>\n<p>Test</p>\n</body>\n</html>',
      'Invalid HTML content is still editable.'
    );
  });

  suite.test('TestCase-TBA: FullPage: Parse body attributes', function (editor) {
    editor.setContent('<html><body><p>Test</p></body></html>');
    LegacyUnit.equal(editor.getBody().style.color, '', 'No color on body.');
    LegacyUnit.equal(editor.getBody().dir, '', 'No dir on body.');
    LegacyUnit.equal(editor.dom.getStyle(editor.getBody().firstChild, 'display', true), 'block', 'No styles added to iframe document');

    editor.setContent('<html><body style="color:#FF0000"><p>Test</p></body></html>');
    LegacyUnit.equal(editor.getBody().style.color.length > 0, true, 'Color added to body');

    editor.setContent('<html><body dir="rtl"><p>Test</p></body></html>');
    LegacyUnit.equal(editor.getBody().dir, 'rtl', 'Dir added to body');

    editor.setContent('<html><body><p>Test</p></body></html>');
    LegacyUnit.equal(editor.getBody().style.color, '', 'No color on body.');
    LegacyUnit.equal(editor.getBody().dir, '', 'No dir on body.');
    LegacyUnit.equal(editor.dom.getStyle(editor.getBody().firstChild, 'display', true), 'block', 'No styles added to iframe document');
  });

  suite.test('TestCase-TBA: FullPage: fullpage_hide_in_source_view: false', function (editor) {
    editor.settings.fullpage_hide_in_source_view = false;
    editor.setContent('<html><body><p>1</p></body></html>');
    LegacyUnit.equal(editor.getContent({ source_view: true }), '<html><body>\n<p>1</p>\n</body></html>');
  });

  suite.test('TestCase-TBA: FullPage: fullpage_hide_in_source_view: false', function (editor) {
    editor.settings.fullpage_hide_in_source_view = true;
    editor.setContent('<html><body><p>1</p></body></html>');
    LegacyUnit.equal(editor.getContent({ source_view: true }), '<p>1</p>');
  });

  suite.test('TestCase-TBA: FullPage: link elements', function (editor) {
    editor.setContent('<html><head><link rel="stylesheet" href="a.css"><link rel="something"></head><body><p>c</p></body></html>');
    LegacyUnit.equal(
      editor.getContent(),
      '<html><head><link rel="stylesheet" href="a.css"><link rel="something"></head><body>\n<p>c</p>\n</body></html>'
    );
  });

  suite.test('TestCase-TBA: FullPage: add/remove stylesheets', function (editor) {
    const hasLink = function hasink(href) {
      const links = editor.getDoc().getElementsByTagName('link');

      for (let i = 0; i < links.length; i++) {
        if (links[i].href.indexOf('/' + href) !== -1) {
          return true;
        }
      }

      return false;
    };

    editor.setContent('<html><head><link rel="stylesheet" href="a.css"></head><body><p>c</p></body></html>');
    LegacyUnit.equal(hasLink('a.css'), true);
    LegacyUnit.equal(hasLink('b.css'), false);
    LegacyUnit.equal(hasLink('c.css'), false);

    editor.setContent(
      '<html><head><link rel="stylesheet" href="a.css"><link rel="stylesheet" href="b.css"></head><body><p>c</p></body></html>'
    );
    LegacyUnit.equal(hasLink('a.css'), true);
    LegacyUnit.equal(hasLink('b.css'), true);
    LegacyUnit.equal(hasLink('c.css'), false);

    editor.setContent(
      '<html><head>' +
      '<link rel="stylesheet" href="a.css">' +
      '<link rel="stylesheet" href="b.css">' +
      '<link rel="stylesheet" href="c.css">' +
//.........这里部分代码省略.........

评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号