Class: CommonComponent

Defined in: component.coffee
Inherits: share.CommonComponentBase

Overview

A base class for components with additional methods for various useful features.

In addition to methods/template helpers available when using this class as a base class, insertDOMElement, moveDOMElement, and removeDOMElement have been configured to call corresponding methods in mixins, if they exist, as it is described in Blaze Components documentation. This allows you to use mixins which add animations to your components.

Property Summary

(String) DEFAULT_DATETIME_FORMAT
Default localized date-time format. Example: Thu, Sep 4 1986 8:30 PM.
(String) DEFAULT_DATE_FORMAT
Default localized date format. Example: Sep 4 1986.
(String) DEFAULT_TIME_FORMAT
Default localized time format. Example: 8:30 PM.

Instance Method Summary

Inherited Method Summary

Methods inherited from share.CommonComponentBase

#subscribe #ancestorComponent #ancestorComponentWith #callAncestorWith

Instance Method Details

# (String) pathFor(pathName, kwargs)

Template helper which resolves Flow Router path definition and arguments to URL paths using FlowRouter.path. It works when Flow Router package is available.

Examples:

{{pathFor 'Post.edit' params=data}}

Parameters:

  • pathName ( String ) Path name or path definition.
  • kwargs ( Object )

Options Hash: (kwargs):

  • params ( Object ) Parameters to resolve variables in the path.
  • query ( Object ) Query string values to be added to the URL path.

Returns:

  • String

# (String) currentUserId()

Returns the Meteor.userId() value. Use it instead of currentUser template helper when you want to check only if user is logged in or not.

Examples:

{{#if currentUserId}}
  ...
{{/if}}

Returns:

  • String

# (Object) currentUser(userId, fields)

Extended version of currentUser template helper which can optionally limit fields returned in the user object. This limits template helper's reactivity as well. It works when peerlibrary:user-extra package is available and falls back to old behavior if it is not.

Parameters:

Returns:

  • Object

# (Boolean) $or(args...)

Returns true if any of the arguments is true.

Examples:

{{#if $or isAdmin isModerator}}
  ...
{{/if}}

Returns:

  • Boolean

# (Boolean) $and(args...)

Returns true if all of the arguments are true.

Examples:

{{#if $and currentUserId subscriptionReady}}
  ...
{{/if}}

Returns:

  • Boolean

# (Boolean) $not(args...)

Returns true if the first argument is false, false otherwise.

Examples:

{{#if $not isRobot}}
  ...
{{/if}}

Returns:

  • Boolean

# (String) $join(delimiter, args...)

Joins arguments using the delimiter.

Examples:

{{> EditorComponent args id=($join '-' 'edit-body' _id)}}

Parameters:

  • delimiter ( String )

Returns:

  • String

# (String) formatDate(date, format)

Format a datetime using provided format string.

Examples:

{{formatDate createdAt DEFAULT_DATETIME_FORMAT}}

Parameters:

  • date ( Date )
  • format ( String )

Returns:

  • String

# (String) fromNow(date, withoutSuffix)

Reactively format a datetime into a relative from now and localized string. As times progresses, string is automatically updated. Strings are made using moment.js fromNow function.

Example output: 3 months ago.

Examples:

<span class="timestamp" title="{{formatDate createdAt DEFAULT_DATETIME_FORMAT}}">{{fromNow createdAt}}</span>

Parameters:

  • date ( Date )
  • withoutSuffix ( Boolean ) Should ago suffix be omitted, default is false.

Returns:

  • String

# (String) calendarDate(date)

Format a datetime into a relative from now and localized string using friendly day names. Strings are made using moment.js calendar function.

Example output: last Sunday at 2:30 AM.

Examples:

<span title="{{formatDate playStart DEFAULT_DATETIME_FORMAT}}">{{calendarDate playStart}}</span>

Parameters:

  • date ( Date )

Returns:

  • String

# (String) formatDuration(from, to, size)

TODO: Support localization.

Similar to moment.js humanize function it returns a friendly string representing the duration.

It is build from size number of units. For example, for size equals 2, the string could be 2 days 1 hour. For size equals 3, 2 days 1 hour 44 minutes. If you omit size, full precision is used.

If from or to are null, the output is reactive.

Examples:

<span title="{{formatDuration startedAt endedAt}}">{{formatDuration startedAt endedAt 2}}</span>

<span title="{{formatDuration startedAt null}}">{{formatDuration startedAt null 3}}</span>

Parameters:

  • from ( Date ) If null, current time is used.
  • to ( Date ) If null, current time is used.
  • size ( Number ) Duration description precision: from how many units it should be build.

Returns:

  • String

# (String) cssPrefix()

Returns the CSS prefix used by the current browser.

Returns:

  • String

# (Date) constructDatetime(date, time)

Construct a Date object from inputs of HTML5 form fields of type date and time.

Examples:

this.constructDatetime(this.$('[name="start-date"]').val(), this.$('[name="start-time"]').val())

Parameters:

  • date ( String )
  • time ( String )

Returns:

  • Date

    Quickly fuzzy find classes, mixins, methods, file:

    Control the navigation frame:

    You can focus and blur the search input: