it('enhances with narrow scope context', () => {
    let elements = [];
    let data = [];
    let $parent = {};
    let viewResources = {};
    let spy = spyOn(sut, 'enhanceView');

    elements.push(DOM.createElement('div'));
    data.push({dataItem: {id: 15}});

    elements.push(DOM.createElement('div'));
    data.push({aggregate: {id: 30}});

    elements.push(DOM.createElement('div'));
    data.push({something: 45});

    // sometimes Kendo calls the callback with an undefined dataItem
    elements.push(DOM.createElement('div'));
    data.push(undefined);

    sut.compile($parent, elements, data, viewResources);


    expect(spy.calls.argsFor(0)[2].id).toBe(15);
    expect(spy.calls.argsFor(1)[2].id).toBe(30);
    expect(spy.calls.argsFor(2)[2].something).toBe(45);
    expect(spy.calls.argsFor(3)[2]).toBe(undefined);
  });
  LikeButton.prototype.attached = function attached() {
    var id = 'facebook-jssdk';
    if (_aureliaPal.DOM.getElementById(id)) return;

    var js = _aureliaPal.DOM.createElement('script');
    js.id = id;
    js.src = '//connect.facebook.net/en_US/sdk.js#xfbml=1&version=v2.0';
    _aureliaPal.DOM.appendNode(js, _aureliaPal.DOM.body);
  };
 relevantErrors.forEach(error => {
   if (node.parentElement.textContent.indexOf(error.message) === -1) {
     let errorMessageHelper = DOM.createElement('span');
     let errorMessageNode = DOM.createTextNode(error.message);
     errorMessageHelper.appendChild(errorMessageNode);
     errorMessageHelper.classList.add('help-block');
     node.parentElement.appendChild(errorMessageHelper);
   }
 });
 createBottomBufferElement(element: Element): Element {
   let tr = DOM.createElement('tr');
   tr.setAttribute('style', this.tableCssReset);
   let buffer = DOM.createElement('td');
   buffer.setAttribute('style', this.tableCssReset);
   tr.appendChild(buffer);
   element.parentNode.insertBefore(tr, element.nextSibling);
   return buffer;
 }
        return aurelia.start().then(a => {
          let host = DOM.createElement('div');
          host.innerHTML = this._html;

          DOM.querySelectorAll('body')[0].appendChild(host);
          aurelia.enhance(this._bindingContext, host);

          this.element = host.firstElementChild;
        });
 TableStrategy.prototype.createBottomBufferElement = function createBottomBufferElement(element) {
   var tr = _aureliaPal.DOM.createElement('tr');
   tr.setAttribute('style', this.tableCssReset);
   var buffer = _aureliaPal.DOM.createElement('td');
   buffer.setAttribute('style', this.tableCssReset);
   tr.appendChild(buffer);
   element.parentNode.insertBefore(tr, element.nextSibling);
   return buffer;
 };
Example #7
0
function makeRequestFlushFromMutationObserver(flush) {
  let toggle = 1;
  let observer = DOM.createMutationObserver(flush);
  let node = DOM.createTextNode('');
  observer.observe(node, {characterData: true});
  return function requestFlush() {
    toggle = -toggle;
    node.data = toggle;
  };
}
Example #8
0
 beforeEach(() => {
   container = new Container();
   parent = DOM.createElement('div');
   comment = DOM.createComment('testing');
   element = DOM.createElement('div');
   parent.appendChild(element);
   viewSlot = new ViewSlot(element, false);
   container.registerInstance(DOM.Element, element);
   templatingEngine = container.get(TemplatingEngine);
 });
function makeRequestFlushFromMutationObserver(flush) {
  var toggle = 1;
  var observer = _aureliaPal.DOM.createMutationObserver(flush);
  var node = _aureliaPal.DOM.createTextNode('');
  observer.observe(node, { characterData: true });
  return function requestFlush() {
    toggle = -toggle;
    node.data = toggle;
  };
}
    return new Promise((resolve, reject) => {
      let frag = DOM.createDocumentFragment();
      let link = DOM.createElement('link');

      link.rel = 'import';
      link.href = this.linkHrefPrefix + entry.address;
      frag.appendChild(link);

      this._importElements(frag, link, () => resolve(link.import));
    });
Example #11
0
 CSSViewEngineHooks.prototype.beforeCompile = function beforeCompile(content, resources, instruction) {
   if (instruction.targetShadowDOM) {
     DOM.injectStyles(this.css, content, true);
   } else if (FEATURE.scopedCSS) {
     var styleNode = DOM.injectStyles(this.css, content, true);
     styleNode.setAttribute('scoped', 'scoped');
   } else if (!this.owner._alreadyGloballyInjected) {
     DOM.injectStyles(this.css);
     this.owner._alreadyGloballyInjected = true;
   }
 };
    return new Promise(function (resolve, reject) {
      var frag = _aureliaPal.DOM.createDocumentFragment();
      var link = _aureliaPal.DOM.createElement('link');

      link.rel = 'import';
      link.href = _this4.linkHrefPrefix + entry.address;
      frag.appendChild(link);

      _this4._importElements(frag, link, function () {
        return resolve(link.import);
      });
    });
Example #13
0
function makeRequestFlushFromMutationObserver(flush) {
  let observer = DOM.createMutationObserver(flush);
  let val = 'a';
  let node = DOM.createTextNode('a');
  let values = Object.create(null);
  values.a = 'b';
  values.b = 'a';
  observer.observe(node, {characterData: true});
  return function requestFlush() {
    node.data = val = values[val];
  };
}
    return this.use.apply().then(function () {
      preventActionlessFormSubmit();

      if (!_this5.container.hasResolver(_aureliaTemplating.BindingLanguage)) {
        var message = 'You must configure Aurelia with a BindingLanguage implementation.';
        _this5.logger.error(message);
        throw new Error(message);
      }

      _this5.logger.info('Aurelia Started');
      var evt = _aureliaPal.DOM.createCustomEvent('aurelia-started', { bubbles: true, cancelable: true });
      _aureliaPal.DOM.dispatchEvent(evt);
      return _this5;
    });
    return this._started = this.use.apply().then(() => {
      preventActionlessFormSubmit();

      if (!this.container.hasResolver(BindingLanguage)) {
        let message = 'You must configure Aurelia with a BindingLanguage implementation.';
        this.logger.error(message);
        throw new Error(message);
      }

      this.logger.info('Aurelia Started');
      let evt = DOM.createCustomEvent('aurelia-started', { bubbles: true, cancelable: true });
      DOM.dispatchEvent(evt);
      return this;
    });
Example #16
0
  addUnit(binding, options) {
    if (!binding.target.label || !options.symbol)
      return;

    binding.label = binding.target.label;
    binding.target.label += ' (' + options.symbol + ')';

    return; // TODO: handle no component case

    let unitHelper = binding.label = DOM.createElement('span');
    let unitHelperNode = DOM.createTextNode(' (' + options.symbol + ')');

    unitHelper.appendChild(unitHelperNode);
    binding.target.labelElement.appendChild(unitHelper);
  }
Example #17
0
    dialogController.showDialog = () => {
      if (!this.dialogControllers.length) {
        DOM.addEventListener('keyup', this.escapeKeyEvent);
      }

      this.dialogControllers.push(dialogController);

      dialogController.slot.attached();

      if (typeof settings.position === 'function') {
        settings.position(modalContainer, modalOverlay);
      } else {
        dialogController.centerDialog();
      }

      modalContainer.addEventListener('click', closeModalClick);
      anchor.addEventListener('click', stopPropagation);

      return new Promise(resolve => {
        modalContainer.addEventListener(transitionEvent(), onTransitionEnd);

        function onTransitionEnd(e) {
          if (e.target !== modalContainer) {
            return;
          }
          modalContainer.removeEventListener(transitionEvent(), onTransitionEnd);
          resolve();
        }

        modalOverlay.classList.add('active');
        modalContainer.classList.add('active');
        body.classList.add('ai-dialog-open');
      });
    };
function trackRequestStart(client) {
    client.isRequesting = !!(++client.activeRequestCount);
    if (client.isRequesting) {
        var evt_1 = aureliaPal.DOM.createCustomEvent('aurelia-fetch-client-request-started', { bubbles: true, cancelable: true });
        setTimeout(function () { return aureliaPal.DOM.dispatchEvent(evt_1); }, 1);
    }
}
function trackRequestEnd(client) {
    client.isRequesting = !!(--client.activeRequestCount);
    if (!client.isRequesting) {
        var evt_2 = aureliaPal.DOM.createCustomEvent('aurelia-fetch-client-requests-drained', { bubbles: true, cancelable: true });
        setTimeout(function () { return aureliaPal.DOM.dispatchEvent(evt_2); }, 1);
    }
}
  it('createWidget looks at the rootElement for event attributes when a rootElement is supplied', () => {
    // sut.getOptionsFromBindables = jasmine.createSpy().and.returnValue({});
    sut.control('kendoButton')
    .linkViewModel({ options: {} });

    let rootElement = DOM.createElement('div');
    rootElement.setAttribute('k-on-click', 'click');

    let widget = sut.createWidget({
      element: DOM.createElement('div'),
      parentCtx: {},
      rootElement: rootElement
    });

    expect(widget.options.click).toEqual(jasmine.any(Function));
  });
  it('handles value binding and sets initial value', () => {
    let widgetFake = new WidgetFake();
    widgetFake.value.and.returnValue('initialValue');
    spyOn(sut, '_createWidget').and.returnValue(widgetFake);

    sut.control('kendoDropDownList')
    .linkViewModel({})
    .useValueBinding();

    let widget = sut.createWidget({
      element: DOM.createElement('div'),
      parentCtx: {}
    });

    // check if initial kValue is set
    // verify that the change event is registered to
    expect(widgetFake.value).toHaveBeenCalled();
    let args = widgetFake.first.calls.argsFor(0);
    expect(args[0]).toBe('change');
    expect(widgetFake.first).toHaveBeenCalled();
    expect(sut.viewModel.kValue).toBe('initialValue');


    // raise 'change' event, check if kValue changed
    widgetFake.value = jasmine.createSpy().and.returnValue('changedValue');
    args[1]({ sender: widget });
    expect(sut.viewModel.kValue).toBe('changedValue');
  });
 beforeCompile(content, resources, instruction) {
   if (this.mode === 'scoped') {
     if (instruction.targetShadowDOM) {
       DOM.injectStyles(this.css, content, true);
     } else if (FEATURE.scopedCSS) {
       let styleNode = DOM.injectStyles(this.css, content, true);
       styleNode.setAttribute('scoped', 'scoped');
     } else if (!this._alreadyGloballyInjected) {
       DOM.injectStyles(this.css);
       this._alreadyGloballyInjected = true;
     }
   } else if (!this._alreadyGloballyInjected) {
     DOM.injectStyles(this.css);
     this._alreadyGloballyInjected = true;
   }
 }
Example #23
0
  increment() {
    this.count++;

    if (this.count === 1) {
      DOM.addEventListener(this.eventName, handleDelegatedEvent, false);
    }
  }
Example #24
0
  decrement() {
    this.count--;

    if (this.count === 0) {
      DOM.removeEventListener(this.eventName, handleCapturedEvent, true);
    }
  }
Example #25
0
  increment() {
    this.count++;

    if (this.count === 1) {
      DOM.addEventListener(this.eventName, handleCapturedEvent, true);
    }
  }
Example #26
0
  decrement() {
    this.count--;

    if (this.count === 0) {
      DOM.removeEventListener(this.eventName, handleDelegatedEvent, false);
    }
  }
Example #27
0
function centerDialog(modalContainer) {
  var child = modalContainer.children[0];
  var vh = Math.max(_aureliaPal.DOM.querySelectorAll('html')[0].clientHeight, window.innerHeight || 0);

  child.style.marginTop = Math.max((vh - child.offsetHeight) / 2, 30) + 'px';
  child.style.marginBottom = Math.max((vh - child.offsetHeight) / 2, 30) + 'px';
}
Example #28
0
    it('handles textContent and innerHTML properties', () => {
      var element = DOM.createElement('div');

      expect(em.getElementHandler(element, 'textContent')).not.toBeNull();
      expect(em.getElementHandler(element, 'innerHTML')).not.toBeNull();
      expect(em.getElementHandler(element, 'id')).toBeNull();
    });
Example #29
0
    it('handles scrollTop and scrollLeft properties', () => {
      var element = DOM.createElement('div');

      expect(em.getElementHandler(element, 'scrollTop')).not.toBeNull();
      expect(em.getElementHandler(element, 'scrollLeft')).not.toBeNull();
      expect(em.getElementHandler(element, 'id')).toBeNull();
    });
Example #30
0
  FormElement.prototype.attached = function attached() {
    var element = _aureliaPal.DOM.createElement(this.getElementName());

    this.setAttributes(element);
    this.DOMElement.appendChild(element);
    this.templatingEngine.enhance({ element: element, bindingContext: this }).attached();
  };