Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
F
foresight
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
libraries
foresight
Commits
02efffc0
Commit
02efffc0
authored
Aug 02, 2018
by
James Ooi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make config parameter optional
parent
41505fa1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
7 deletions
+8
-7
foresight.ts
src/foresight.ts
+8
-7
No files found.
src/foresight.ts
View file @
02efffc0
...
@@ -22,10 +22,10 @@ interface ForesightConfig {
...
@@ -22,10 +22,10 @@ interface ForesightConfig {
/** Configure the intersection observer. */
/** Configure the intersection observer. */
observerOptions
?:
IntersectionObserverInit
observerOptions
?:
IntersectionObserverInit
/** Treat clicks as an interactive event. Defaults to
true
. */
/** Treat clicks as an interactive event. Defaults to
`true`
. */
clicksAreInteractions
?:
boolean
clicksAreInteractions
?:
boolean
/** Treat views as an interactive event. Defaults to
false
. */
/** Treat views as an interactive event. Defaults to
`false`
. */
viewsAreInteractions
?:
boolean
viewsAreInteractions
?:
boolean
}
}
...
@@ -53,9 +53,9 @@ class Foresight {
...
@@ -53,9 +53,9 @@ class Foresight {
*/
*/
static
defaultOptions
:
Partial
<
ForesightConfig
>
=
{
static
defaultOptions
:
Partial
<
ForesightConfig
>
=
{
defer
:
false
,
defer
:
false
,
observerOptions
:
{},
clicksAreInteractions
:
true
,
clicksAreInteractions
:
true
,
viewsAreInteractions
:
false
,
viewsAreInteractions
:
false
,
observerOptions
:
{},
}
}
/**
/**
...
@@ -80,7 +80,7 @@ class Foresight {
...
@@ -80,7 +80,7 @@ class Foresight {
/**
/**
* @constructor
* @constructor
*/
*/
constructor
(
config
:
ForesightConfig
)
{
constructor
(
config
:
ForesightConfig
=
{}
)
{
this
.
options
=
{
...
Foresight
.
defaultOptions
,
...
config
};
this
.
options
=
{
...
Foresight
.
defaultOptions
,
...
config
};
// Initialise IntersectionObserver
// Initialise IntersectionObserver
...
@@ -100,7 +100,8 @@ class Foresight {
...
@@ -100,7 +100,8 @@ class Foresight {
}
}
/**
/**
* Start event tracking for all DOM elements with event tracking attributes.
* Start tracking all elements with tracking attributes for events.
* @param {Element} root The container to scan for elements. Defaults to `body`.
*/
*/
start
(
root
:
Element
=
document
.
body
)
{
start
(
root
:
Element
=
document
.
body
)
{
if
(
gtag
===
undefined
)
{
if
(
gtag
===
undefined
)
{
...
@@ -113,7 +114,7 @@ class Foresight {
...
@@ -113,7 +114,7 @@ class Foresight {
}
}
/**
/**
*
Enables event tracking for a DOM element with event tracking attribute
.
*
Start tracking an element for events
.
*/
*/
track
(
element
:
Element
)
{
track
(
element
:
Element
)
{
if
(
!
this
.
_untrackFns
.
has
(
element
))
{
if
(
!
this
.
_untrackFns
.
has
(
element
))
{
...
@@ -140,7 +141,7 @@ class Foresight {
...
@@ -140,7 +141,7 @@ class Foresight {
}
}
/**
/**
*
Disable event tracking for a DOM element
.
*
Stop tracking an element for events
.
*/
*/
untrack
(
element
:
Element
)
{
untrack
(
element
:
Element
)
{
const
untrackFn
=
this
.
_untrackFns
.
get
(
element
);
const
untrackFn
=
this
.
_untrackFns
.
get
(
element
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment