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
-
#
(String)
pathFor(pathName, kwargs)
Template helper which resolves Flow Router path definition and arguments to URL paths using
FlowRouter.path
. -
#
(String)
currentUserId()
Returns the
Meteor.userId()
value. -
#
(Object)
currentUser(userId, fields)
Extended version of
currentUser
template helper which can optionally limit fields returned in the user object. -
#
(Boolean)
$or(args...)
Returns
true
if any of the arguments is true. -
#
(Boolean)
$and(args...)
Returns
true
if all of the arguments are true. -
#
(Boolean)
$not(args...)
Returns
true
if the first argument is false,false
otherwise. -
#
(String)
$join(delimiter, args...)
Joins arguments using the
delimiter
. -
#
(String)
formatDate(date, format)
Format a datetime using provided
format
string. - # (String) fromNow(date, withoutSuffix) Reactively format a datetime into a relative from now and localized string.
- # (String) calendarDate(date) Format a datetime into a relative from now and localized string using friendly day names.
-
#
(String)
formatDuration(from, to, size)
Similar to moment.js
humanize
function it returns a friendly string representing the duration. - # (String) cssPrefix() Returns the CSS prefix used by the current browser.
-
#
(Date)
constructDatetime(date, time)
Construct a
Date
object from inputs of HTML5 form fields of typedate
andtime
.
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}}
#
(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}}
#
(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.
#
(Boolean)
$or(args...)
Returns true
if any of the arguments is true.
Examples:
{{#if $or isAdmin isModerator}}
...
{{/if}}
#
(Boolean)
$and(args...)
Returns true
if all of the arguments are true.
Examples:
{{#if $and currentUserId subscriptionReady}}
...
{{/if}}
#
(Boolean)
$not(args...)
Returns true
if the first argument is false, false
otherwise.
Examples:
{{#if $not isRobot}}
...
{{/if}}
#
(String)
$join(delimiter, args...)
Joins arguments using the delimiter
.
Examples:
{{> EditorComponent args id=($join '-' 'edit-body' _id)}}
#
(String)
formatDate(date, format)
Format a datetime using provided format
string.
Examples:
{{formatDate createdAt DEFAULT_DATETIME_FORMAT}}
#
(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>
#
(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>
#
(String)
formatDuration(from, to, size)
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>
#
(String)
cssPrefix()
Returns the CSS prefix used by the current browser.
#
(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())