Beispiel #1
0
    let isVisible = this.isVisible.value();

    if (isVisible !== false) {
      return value;
    } else if (!value && value !== 0) {
      return SAFE_DISPLAY_NONE;
    } else {
      let style = value + ' ' + DISPLAY_NONE;
      return isHTMLSafe(value) ? htmlSafe(style) : style;
    }
  }
}

export const IsVisibleBinding = {
  install(element, component, operations) {
    operations.addDynamicAttribute(element, 'style', map(referenceForKey(component, 'isVisible'), this.mapStyleValue));
  },

  mapStyleValue(isVisible) {
    return isVisible === false ? SAFE_DISPLAY_NONE : null;
  }
};

export const ClassNameBinding = {
  install(element, component, microsyntax, operations) {
    let [ prop, truthy, falsy ] = microsyntax.split(':');
    let isPath = prop.indexOf('.') > -1;
    let parts = isPath && prop.split('.');
    let value = isPath ? referenceForParts(component, parts) : referenceForKey(component, prop);
    let ref;
Beispiel #2
0
      return [prop, attribute, false];
    }
  },

  apply(component, parsed, operations) {
    let [prop, attribute, isSimple] = parsed;
    let isPath = prop.indexOf('.') > -1;
    let value = isPath ? referenceForParts(component, prop.split('.')) : referenceForKey(component, prop);
    let reference;

    assert(`Illegal attributeBinding: '${prop}' is not a valid attribute name.`, !(isSimple && isPath));

    if (attribute === 'style') {
      reference = new StyleBindingReference(value, referenceForKey(component, 'isVisible'));
    } else {
      reference = map(value, this.mapAttributeValue);
    }

    operations.addAttribute(attribute, reference);
  },

  mapAttributeValue(value) {
    if (value === null || value === undefined || value === false) {
      return null;
    } else if (value === true) {
      // Note:
      // This is here to mimic functionality in HTMLBars for properties.
      // For instance when a property like "disable" is set all of these
      // forms are valid and have the same disabled functionality:
      //
      // <input disabled />