Example #1
0
 return Chain.mapper(function (parents: Element[]) {
   const names = Arr.map(parents, Node.name);
   Assertions.assertEq('Should be expected names', expectedNames, names);
   return {};
 });
Example #2
0
const normalizeEntries = (entries: Entry[]): void => {
  Arr.foldl(entries, (outline: Array<Option<Entry>>, entry) => {
    return entry.depth > outline.length ? normalizeDeep(outline, entry) : normalizeShallow(outline, entry);
  }, []);
};
Example #3
0
UnitTest.asynctest('browser.tinymce.core.dom.EventUtilsTest', function (success, failure) {
  const suite = LegacyUnit.createSuite();
  const eventUtils = EventUtils.Event;

  suite.test('unbind all', function () {
    let result;

    eventUtils.bind(window, 'click', function () {
      result.click = true;
    });

    eventUtils.bind(window, 'keydown', function () {
      result.keydown1 = true;
    });

    eventUtils.bind(window, 'keydown', function () {
      result.keydown2 = true;
    });

    result = {};
    eventUtils.fire(window, 'click');
    eventUtils.fire(window, 'keydown');
    LegacyUnit.deepEqual(result, { click: true, keydown1: true, keydown2: true });

    eventUtils.unbind(window);
    result = {};
    eventUtils.fire(window, 'click');
    eventUtils.fire(window, 'keydown');
    LegacyUnit.deepEqual(result, {});
  });

  suite.test('unbind event', function () {
    let result;

    eventUtils.bind(window, 'click', function () {
      result.click = true;
    });

    eventUtils.bind(window, 'keydown', function () {
      result.keydown1 = true;
    });

    eventUtils.bind(window, 'keydown', function () {
      result.keydown2 = true;
    });

    result = {};
    eventUtils.fire(window, 'click');
    eventUtils.fire(window, 'keydown');
    LegacyUnit.deepEqual(result, { click: true, keydown1: true, keydown2: true });

    eventUtils.unbind(window, 'click');
    result = {};
    eventUtils.fire(window, 'click');
    eventUtils.fire(window, 'keydown');
    LegacyUnit.deepEqual(result, { keydown1: true, keydown2: true });
  });

  suite.test('unbind event non existing', function () {
    eventUtils.unbind(window, 'noevent');
    LegacyUnit.equal(true, true, 'No exception');
  });

  suite.test('unbind callback', function () {
    let result;

    eventUtils.bind(window, 'click', function () {
      result.click = true;
    });

    eventUtils.bind(window, 'keydown', function () {
      result.keydown1 = true;
    });

    const callback2 = function () {
      result.keydown2 = true;
    };

    eventUtils.bind(window, 'keydown', callback2);

    result = {};
    eventUtils.fire(window, 'click');
    eventUtils.fire(window, 'keydown');
    LegacyUnit.deepEqual(result, { click: true, keydown1: true, keydown2: true });

    eventUtils.unbind(window, 'keydown', callback2);
    result = {};
    eventUtils.fire(window, 'click');
    eventUtils.fire(window, 'keydown');
    LegacyUnit.deepEqual(result, { click: true, keydown1: true });
  });

  suite.test('unbind multiple', function () {
    let result;

    eventUtils.bind(window, 'mouseup mousedown click', function (e) {
      result[e.type] = true;
    });

    eventUtils.unbind(window, 'mouseup mousedown');

    result = {};
    eventUtils.fire(window, 'mouseup');
    eventUtils.fire(window, 'mousedown');
    eventUtils.fire(window, 'click');
    LegacyUnit.deepEqual(result, { click: true });
  });

  suite.test('bind multiple', function () {
    let result;

    eventUtils.bind(window, 'mouseup mousedown', function (e) {
      result[e.type] = true;
    });

    result = {};
    eventUtils.fire(window, 'mouseup');
    eventUtils.fire(window, 'mousedown');
    eventUtils.fire(window, 'click');
    LegacyUnit.deepEqual(result, { mouseup: true, mousedown: true });
  });

  suite.test('bind/fire bubbling', function () {
    let result;

    eventUtils.bind(window, 'click', function () {
      result.window = true;
    });

    eventUtils.bind(document, 'click', function () {
      result.document = true;
    });

    eventUtils.bind(document.body, 'click', function () {
      result.body = true;
    });

    eventUtils.bind(document.getElementById('content'), 'click', function () {
      result.content = true;
    });

    eventUtils.bind(document.getElementById('inner'), 'click', function () {
      result.inner = true;
    });

    result = {};
    eventUtils.fire(window, 'click');
    LegacyUnit.deepEqual(result, { window: true });

    result = {};
    eventUtils.fire(document, 'click');
    LegacyUnit.deepEqual(result, { document: true, window: true });

    result = {};
    eventUtils.fire(document.body, 'click');
    LegacyUnit.deepEqual(result, { body: true, document: true, window: true });

    result = {};
    eventUtils.fire(document.getElementById('content'), 'click');
    LegacyUnit.deepEqual(result, { content: true, body: true, document: true, window: true });

    result = {};
    eventUtils.fire(document.getElementById('inner'), 'click');
    LegacyUnit.deepEqual(result, { inner: true, content: true, body: true, document: true, window: true });
  });

  suite.test('bind/fire stopImmediatePropagation', function () {
    let result;

    eventUtils.bind(window, 'click', function () {
      result.click1 = true;
    });

    eventUtils.bind(window, 'click', function (e) {
      result.click2 = true;
      e.stopImmediatePropagation();
    });

    eventUtils.bind(window, 'click', function () {
      result.click3 = true;
    });

    result = {};
    eventUtils.fire(window, 'click');
    LegacyUnit.deepEqual(result, { click1: true, click2: true });
  });

  suite.test('bind/fire stopPropagation', function () {
    let result;

    eventUtils.bind(window, 'click', function () {
      result.click1 = true;
    });

    eventUtils.bind(document.body, 'click', function () {
      result.click2 = true;
    });

    eventUtils.bind(document.getElementById('inner'), 'click', function (e) {
      result.click3 = true;
      e.stopPropagation();
    });

    result = {};
    eventUtils.fire(document.getElementById('inner'), 'click');
    LegacyUnit.deepEqual(result, { click3: true });
  });

  suite.test('clean window', function () {
    let result;

    eventUtils.bind(window, 'click', function () {
      result.click1 = true;
    });

    eventUtils.bind(document.body, 'click', function () {
      result.click2 = true;
    });

    eventUtils.bind(document.getElementById('content'), 'click', function () {
      result.click3 = true;
    });

    eventUtils.bind(document.getElementById('inner'), 'click', function () {
      result.click4 = true;
    });

    result = {};
    eventUtils.fire(document.getElementById('inner'), 'click');
    LegacyUnit.deepEqual(result, { click1: true, click2: true, click3: true, click4: true });

    eventUtils.clean(window);
    result = {};
    eventUtils.fire(document.getElementById('inner'), 'click');
    LegacyUnit.deepEqual(result, {});
  });

  suite.test('clean document', function () {
    let result;

    eventUtils.bind(window, 'click', function () {
      result.click1 = true;
    });

    eventUtils.bind(document, 'click', function () {
      result.click2 = true;
    });

    eventUtils.bind(document.body, 'click', function () {
      result.click3 = true;
    });

    eventUtils.bind(document.getElementById('content'), 'click', function () {
      result.click4 = true;
    });

    eventUtils.bind(document.getElementById('inner'), 'click', function () {
      result.click5 = true;
    });

    result = {};
    eventUtils.fire(document.getElementById('inner'), 'click');
    LegacyUnit.deepEqual(result, { click1: true, click2: true, click3: true, click4: true, click5: true });

    eventUtils.clean(document);
    result = {};
    eventUtils.fire(document.getElementById('inner'), 'click');
    LegacyUnit.deepEqual(result, { click1: true });
  });

  suite.test('clean element', function () {
    let result;

    eventUtils.bind(window, 'click', function () {
      result.click1 = true;
    });

    eventUtils.bind(document.body, 'click', function () {
      result.click2 = true;
    });

    eventUtils.bind(document.getElementById('content'), 'click', function () {
      result.click3 = true;
    });

    eventUtils.bind(document.getElementById('inner'), 'click', function () {
      result.click4 = true;
    });

    result = {};
    eventUtils.fire(document.getElementById('inner'), 'click');
    LegacyUnit.deepEqual(result, { click1: true, click2: true, click3: true, click4: true });

    eventUtils.clean(document.getElementById('content'));
    result = {};
    eventUtils.fire(document.getElementById('inner'), 'click');
    LegacyUnit.deepEqual(result, { click1: true, click2: true });
  });

  suite.test('mouseenter/mouseleave bind/unbind', function () {
    let result = {};

    eventUtils.bind(document.body, 'mouseenter mouseleave', function (e) {
      result[e.type] = true;
    });

    eventUtils.fire(document.body, 'mouseenter');
    eventUtils.fire(document.body, 'mouseleave');

    LegacyUnit.deepEqual(result, { mouseenter: true, mouseleave: true });

    result = {};
    eventUtils.clean(document.body);
    eventUtils.fire(document.body, 'mouseenter');
    eventUtils.fire(document.body, 'mouseleave');
    LegacyUnit.deepEqual(result, {});
  });

  /*
  asyncTest("focusin/focusout bind/unbind", function() {
    var result = {};

    window.setTimeout(function() {
      eventUtils.bind(document.body, 'focusin focusout', function(e) {
        // IE will fire a focusout on the parent element if you focus an element within not a big deal so lets detect it in the test
        if (e.type == "focusout" && e.target.contains(document.activeElement)) {
          return;
        }

        result[e.type] = result[e.type] ? ++result[e.type] : 1;
      });

      start();
      document.getElementById('content').focus();
      document.getElementById('inner').focus();

      LegacyUnit.deepEqual(result, {focusin: 2, focusout: 1});
    }, 0);
  });
  */

  suite.test('bind unbind fire clean on null', function () {
    eventUtils.bind(null, 'click', function () {});
    eventUtils.unbind(null, 'click', function () {});
    eventUtils.fire(null, 'click', {});
    eventUtils.clean(null);
    LegacyUnit.equal(true, true, 'No exception');
  });

  suite.test('bind ready when page is loaded', function () {
    let ready;

    eventUtils.bind(window, 'ready', function () {
      ready = true;
    });

    LegacyUnit.equal(true, eventUtils.domLoaded, 'DomLoaded state true');
    LegacyUnit.equal(true, ready, 'Window is ready.');
  });

  suite.test('event states when event object is fired twice', function () {
    const result = {};

    eventUtils.bind(window, 'keydown', function (e) {
      result[e.type] = true; e.preventDefault(); e.stopPropagation();
    });
    eventUtils.bind(window, 'keyup', function (e) {
      result[e.type] = true; e.stopImmediatePropagation();
    });

    const event: any = {};
    eventUtils.fire(window, 'keydown', event);
    eventUtils.fire(window, 'keyup', event);

    LegacyUnit.equal(true, event.isDefaultPrevented(), 'Default is prevented.');
    LegacyUnit.equal(true, event.isPropagationStopped(), 'Propagation is stopped.');
    LegacyUnit.equal(true, event.isImmediatePropagationStopped(), 'Immediate propagation is stopped.');

    LegacyUnit.deepEqual(result, { keydown: true, keyup: true });
  });

  suite.test('unbind inside callback', function () {
    let data;

    const append = function (value) {
      return function () {
        data += value;
      };
    };

    const callback = function () {
      eventUtils.unbind(window, 'click', callback);
      data += 'b';
    };

    data = '';
    eventUtils.bind(window, 'click', append('a'));
    eventUtils.bind(window, 'click', callback);
    eventUtils.bind(window, 'click', append('c'));

    eventUtils.fire(window, 'click', {});
    LegacyUnit.equal(data, 'abc');

    data = '';
    eventUtils.fire(window, 'click', {});
    LegacyUnit.equal(data, 'ac');
  });

  suite.test('ready/DOMContentLoaded (domLoaded = true)', function () {
    let evt;

    eventUtils.bind(window, 'ready', function (e) {
      evt = e;
    });
    LegacyUnit.equal(evt.type, 'ready');
  });

  suite.test('ready/DOMContentLoaded (document.readyState check)', function () {
    let evt;

    try {
      document.readyState = 'loading';
    } catch (e) {
      LegacyUnit.equal(true, true, 'IE doesn\'t allow us to set document.readyState');
      return;
    }

    eventUtils.domLoaded = false;
    document.readyState = 'loading';
    eventUtils.bind(window, 'ready', function (e) {
      evt = e;
    });
    LegacyUnit.equal(true, typeof (evt) !== 'undefined');

    eventUtils.domLoaded = false;
    document.readyState = 'complete';
    eventUtils.bind(window, 'ready', function (e) {
      evt = e;
    });
    LegacyUnit.equal(evt.type, 'ready');
  });

  suite.test('isDefaultPrevented', function () {
    const testObj: any = {};
    const testCallback = function () {
      return 'hello';
    };
    testObj.isDefaultPrevented = testCallback;
    eventUtils.fire(window, 'testEvent', testObj);

    LegacyUnit.equal(testObj.isDefaultPrevented !== testCallback, true, 'Is overwritten by our isDefaultPrevented');
    LegacyUnit.equal(typeof testObj.isPropagationStopped, 'function', 'Has our isPropagationStopped');
    LegacyUnit.equal(typeof testObj.isImmediatePropagationStopped, 'function', 'Has our isImmediatePropagationStopped');
  });

  const sAddTestDiv = Step.sync(function () {
    const testDiv = document.createElement('div');
    testDiv.id = 'testDiv';
    testDiv.innerHTML = (
      '<div id="content" tabindex="0">' +
      '<div id="inner" tabindex="0"></div>' +
      '</div>'
    );

    document.body.appendChild(testDiv);
  });

  const sRemoveTestDiv = Step.sync(function () {
    const testDiv = document.querySelector('#testDiv');
    testDiv.parentNode.removeChild(testDiv);
  });

  let steps = Arr.bind(suite.toSteps({}), function (step) {
    return [
      step,
      Step.sync(function () {
        eventUtils.clean(window);
      })
    ];
  });

  steps = [sAddTestDiv].concat(steps).concat(sRemoveTestDiv);

  Pipeline.async({}, steps, function () {
    success();
  }, failure);
});
Example #4
0
 parser.addNodeFilter('p', (nodes) => {
   Arr.each(nodes, (node) => {
     node.attr('class', 'x');
   });
 });
 const update = function () {
   clear();
   const rectangles = Rectangles.getRectangles(win);
   const spans = Arr.map(rectangles, make);
   InsertAll.append(container, spans);
 };
Example #6
0
 Arr.each(SelectorFilter.descendants(tableElm, 'tr'), function (tr, y) {
   Arr.each(SelectorFilter.descendants(tr, 'td,th'), function (td, x) {
     fillout(table, skipCellsX(table, x, y), y, tr, td);
   });
 });
Example #7
0
 const join = function (items) {
   return Arr.foldl(items, function (a, b) {
     const bothEmpty = a.length === 0 || b.length === 0;
     return bothEmpty ? a.concat(b) : a.concat(separator, b);
   }, []);
 };
Example #8
0
const getParentCell = function (rootElm, elm) {
  return Arr.find(Parents.parentsAndSelf(elm, rootElm), ElementType.isTableCell);
};
Example #9
0
const getParentCaption = function (rootElm, elm) {
  return Arr.find(Parents.parentsAndSelf(elm, rootElm), function (elm) {
    return Node.name(elm) === 'caption';
  });
};
 const isRoot = function (element) {
   const name = Node.name(element);
   return Compare.eq(element, body) || Arr.contains(rootElements, name);
 };
Example #11
0
const emptyCells = function (editor, cells) {
  Arr.each(cells, PaddingBr.fillWithPaddingBr);
  editor.selection.setCursorLocation(cells[0].dom(), 0);

  return true;
};
Example #12
0
 const appendTeardown = function (editor, steps) {
   return Arr.bind(steps, function (step) {
     return [step, sTeardown(editor)];
   });
 };
Example #13
0
const write = function (fragments: string[], elm: Element): Element {
  const currentFragments = Arr.map(Arr.from(elm.childNodes), getOuterHtml);
  applyDiff(Diff.diff(currentFragments, fragments), elm);
  return elm;
};
Example #14
0
const read = function (elm: Element): string[] {
  return Arr.filter(Arr.map(Arr.from(elm.childNodes), getOuterHtml), function (item) {
    return item.length > 0;
  });
};
Example #15
0
 const destroy = function () {
   Arr.each(listeners, function (l) {
     l.unbind();
   });
 };
Example #16
0
 const groups = Arr.map(toolbarGroups, (group) => {
   const items = Arr.bind(group.items, (toolbarItem) => {
     return toolbarItem.trim().length === 0 ? [] : lookupButton(editor, toolbarConfig.buttons, toolbarItem, extras, prefixes).toArray();
   });
   return {
     title: Option.from(editor.translate(group.name)),
     items
   };
 });
Example #17
0
const showTab = (allTabs, comp: AlloyComponent) => {
  Arr.head(allTabs).each((tab) => TabSection.showTab(comp, tab.value));
};
    function (editor, onSuccess, onFailure) {
      const tinyApis = TinyApis(editor);
      const stepsWithTeardown = Arr.bind([
        Logger.t('incorrect service url no api key', GeneralSteps.sequence([
          uploadHandlerState.sResetState,
          tinyApis.sSetSetting('imagetools_proxy', 'http://0.0.0.0.0.0/'),
          tinyApis.sSetSetting('api_key', undefined),
          ImageUtils.sLoadImage(editor, corsUrl),
          tinyApis.sSelect('img', []),
          ImageUtils.sExecCommand(editor, 'mceImageFlipHorizontal'),
          sAssertErrorMessage('ImageProxy HTTP error: Incorrect Image Proxy URL')
        ])),

        Logger.t('incorrect service url with api key', GeneralSteps.sequence([
          uploadHandlerState.sResetState,
          tinyApis.sSetSetting('imagetools_proxy', 'http://0.0.0.0.0.0/'),
          tinyApis.sSetSetting('api_key', 'fake_key'),
          ImageUtils.sLoadImage(editor, corsUrl),
          tinyApis.sSelect('img', []),
          ImageUtils.sExecCommand(editor, 'mceImageFlipHorizontal'),
          sAssertErrorMessage('ImageProxy HTTP error: Incorrect Image Proxy URL')
        ])),

        Logger.t('403 no api key', GeneralSteps.sequence([
          uploadHandlerState.sResetState,
          tinyApis.sSetSetting('imagetools_proxy', '/custom/403'),
          tinyApis.sSetSetting('api_key', undefined),
          ImageUtils.sLoadImage(editor, corsUrl),
          tinyApis.sSelect('img', []),
          ImageUtils.sExecCommand(editor, 'mceImageFlipHorizontal'),
          sAssertErrorMessage('ImageProxy HTTP error: Rejected request')
        ])),

        Logger.t('403 with api key', GeneralSteps.sequence([
          uploadHandlerState.sResetState,
          tinyApis.sSetSetting('imagetools_proxy', '/custom/403'),
          tinyApis.sSetSetting('api_key', 'fake_key'),
          ImageUtils.sLoadImage(editor, corsUrl),
          tinyApis.sSelect('img', []),
          ImageUtils.sExecCommand(editor, 'mceImageFlipHorizontal'),
          sAssertErrorMessage('ImageProxy Service error: Invalid JSON in service error message')
        ])),

        Logger.t('403 with api key and return error data', GeneralSteps.sequence([
          uploadHandlerState.sResetState,
          tinyApis.sSetSetting('imagetools_proxy', '/custom/403data'),
          tinyApis.sSetSetting('api_key', 'fake_key'),
          ImageUtils.sLoadImage(editor, corsUrl),
          tinyApis.sSelect('img', []),
          ImageUtils.sExecCommand(editor, 'mceImageFlipHorizontal'),
          sAssertErrorMessage('ImageProxy Service error: Unknown service error')
        ])),

        Logger.t('404 no api key', GeneralSteps.sequence([
          uploadHandlerState.sResetState,
          tinyApis.sSetSetting('imagetools_proxy', '/custom/404'),
          tinyApis.sSetSetting('api_key', undefined),
          ImageUtils.sLoadImage(editor, corsUrl),
          tinyApis.sSelect('img', []),
          ImageUtils.sExecCommand(editor, 'mceImageFlipHorizontal'),
          sAssertErrorMessage('ImageProxy HTTP error: Could not find Image Proxy')
        ])),

        Logger.t('404 with api key', GeneralSteps.sequence([
          uploadHandlerState.sResetState,
          tinyApis.sSetSetting('imagetools_proxy', '/custom/404'),
          tinyApis.sSetSetting('api_key', 'fake_key'),
          ImageUtils.sLoadImage(editor, corsUrl),
          tinyApis.sSelect('img', []),
          ImageUtils.sExecCommand(editor, 'mceImageFlipHorizontal'),
          sAssertErrorMessage('ImageProxy HTTP error: Could not find Image Proxy')
        ]))
      ], function (step) {
        return [
          step,
          GeneralSteps.sequence([
            sCloseErrorMessage,
            tinyApis.sSetContent('')
          ])
        ];
      });

      Pipeline.async({}, stepsWithTeardown, onSuccess, onFailure);
    },
Example #19
0
const getWidth = function (rows) {
  return Arr.foldl(rows, function (acc, row) {
    return row.cells().length > acc ? row.cells().length : acc;
  }, 0);
};
Example #20
0
const withTeardown = function (steps, teardownStep) {
  return Arr.bind(steps, function (step) {
    return [step, teardownStep];
  });
};
Example #21
0
const findParentListContainer = function (parents) {
  return Arr.find(parents, function (elm) {
    return Node.name(elm) === 'ul' || Node.name(elm) === 'ol';
  });
};
Example #22
0
const sTypeContentAtSelection = function (doc, text) {
  return GeneralSteps.sequence(Arr.map(text.split(''), Fun.curry(sTypeChar, doc)));
};
Example #23
0
 parser.addAttributeFilter('class', (nodes) => {
   Arr.each(nodes, (node) => {
     node.attr('class', 'x');
   });
 });
Example #24
0
 const cAssertApproxRawContent = (expectedHtml) => NamedChain.read('editor', Chain.op((editor) => {
   const elm = Replication.deep(Element.fromDom(editor.getBody()));
   Arr.each(SelectorFilter.descendants(elm, '*[data-mce-bogus="all"]'), Remove.remove);
   const actualHtml = Html.get(elm);
   Assertions.assertHtmlStructure('Should expected structure', `<body>${expectedHtml}</body>`, `<body>${actualHtml}</body>`);
 }));
Example #25
0
const getClientRects = (node: Node[]): NodeClientRect[] => {
  return Arr.foldl(node, function (result, node) {
    return result.concat(getNodeClientRects(node));
  }, []);
};
Example #26
0
const deleteOffscreenSelection = function (rootElement) {
  Arr.each(SelectorFilter.descendants(rootElement, '.mce-offscreen-selection'), Remove.remove);
};
              function (xs) {
                const cellString = Arr.map(xs, Html.getOuter).join('');

                return Result.value(cellString);
              }
Example #28
0
const firstElement = function (nodes) {
  return Arr.find(nodes, Node.isElement);
};
Example #29
0
 const processNodes = (nodes) => {
   const elems = Arr.map(nodes, Element.fromDom);
   processElements(elems);
 };
Example #30
0
const getBlocksToIndent = (editor: Editor) => {
  return Arr.filter(Arr.map(editor.selection.getSelectedBlocks(), Element.fromDom), (el) =>
    !isListComponent(el) && !parentIsListComponent(el) && isEditable(el)
  );
};