Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Monster
Manage
Activity
Members
Plan
Jira
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Analyze
Contributor analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
OSS
Libraries
Javascript
Monster
Commits
1cdf3809
Verified
Commit
1cdf3809
authored
Apr 3, 2023
by
Volker Schukai
Browse files
Options
Downloads
Patches
Plain Diff
feat: attribure observer
parent
49ed6f78
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
application/source/dom/customelement.mjs
+58
-24
58 additions, 24 deletions
application/source/dom/customelement.mjs
with
58 additions
and
24 deletions
application/source/dom/customelement.mjs
+
58
−
24
View file @
1cdf3809
...
...
@@ -203,6 +203,7 @@ class CustomElement extends HTMLElement {
this
[
internalSymbol
]
=
new
ProxyObserver
({
options
:
initOptionsFromAttributes
(
this
,
extend
({},
this
.
defaults
)),
});
initAttributeChangeMutationObserver
.
call
(
this
);
initOptionObserver
.
call
(
this
);
this
[
initMethodSymbol
]();
}
...
...
@@ -217,7 +218,9 @@ class CustomElement extends HTMLElement {
}
/**
* This method determines which attributes are to be monitored by `attributeChangedCallback()`.
* This method determines which attributes are to be
* monitored by `attributeChangedCallback()`. Unfortunately, this method is static.
* Therefore, the `observedAttributes` property cannot be changed during runtime.
*
* @return {string[]}
* @since 1.15.0
...
...
@@ -421,7 +424,8 @@ class CustomElement extends HTMLElement {
try
{
value
=
new
Pathfinder
(
this
[
internalSymbol
].
getRealSubject
()[
"
options
"
]).
getVia
(
path
);
}
catch
(
e
)
{}
}
catch
(
e
)
{
}
if
(
value
===
undefined
)
return
defaultValue
;
return
value
;
...
...
@@ -491,7 +495,8 @@ class CustomElement extends HTMLElement {
try
{
initShadowRoot
.
call
(
self
);
elements
=
self
.
shadowRoot
.
childNodes
;
}
catch
(
e
)
{}
}
catch
(
e
)
{
}
try
{
initCSSStylesheet
.
call
(
this
);
...
...
@@ -542,7 +547,8 @@ class CustomElement extends HTMLElement {
* @return {void}
* @since 1.7.0
*/
disconnectedCallback
()
{}
disconnectedCallback
()
{
}
/**
* The custom element has been moved into a new document (e.g. someone called document.adoptNode(el)).
...
...
@@ -550,7 +556,8 @@ class CustomElement extends HTMLElement {
* @return {void}
* @since 1.7.0
*/
adoptedCallback
()
{}
adoptedCallback
()
{
}
/**
* Called when an observed attribute has been added, removed, updated, or replaced. Also called for initial
...
...
@@ -595,6 +602,32 @@ class CustomElement extends HTMLElement {
}
}
/**
* This method is called when the element is first created.
*
* @private
* @this CustomElement
*/
function
initAttributeChangeMutationObserver
()
{
const
self
=
this
;
if
(
self
[
attributeObserverSymbol
]
===
undefined
)
{
self
[
attributeObserverSymbol
]
=
{};
}
new
MutationObserver
(
function
(
mutations
)
{
for
(
const
mutation
of
mutations
)
{
if
(
mutation
.
type
===
"
attributes
"
)
{
self
.
attributeChangedCallback
(
mutation
.
attributeName
,
mutation
.
oldValue
,
mutation
.
target
.
getAttribute
(
mutation
.
attributeName
));
}
}
}).
observe
(
self
,
{
attributes
:
true
,
attributeOldValue
:
true
,
attributeFilter
:
Object
.
keys
(
self
[
attributeObserverSymbol
]),
});
}
/**
* @this CustomElement
* @private
...
...
@@ -787,7 +820,8 @@ function parseOptionsJSON(data) {
try
{
let
dataUrl
=
parseDataURL
(
data
);
data
=
dataUrl
.
content
;
}
catch
(
e
)
{}
}
catch
(
e
)
{
}
try
{
obj
=
JSON
.
parse
(
data
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment