-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
💥 Make template slots behave more like vanilla custom element slots
- Loading branch information
Showing
7 changed files
with
30 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2247,25 +2247,25 @@ defStat(function appendChildren(target, new_children) { | |
* | ||
* @author Jelle De Loecker <[email protected]> | ||
* @since 2.0.0 | ||
* @version 2.0.0 | ||
* @version 2.4.0 | ||
* | ||
* @param {HTMLElement} element | ||
* @param {String} name | ||
* @param {String} names | ||
* @param {String} value | ||
* | ||
* @return {Array} | ||
*/ | ||
defStat(function getElementsByAttribute(element, name, value) { | ||
defStat(function getElementsByAttribute(element, names, value) { | ||
var check_value = arguments.length > 2; | ||
return _getElementsByAttribute([], check_value, element, name, value); | ||
return _getElementsByAttribute([], check_value, element, names, value); | ||
}); | ||
|
||
/** | ||
* Get elements by attribute name/value | ||
* | ||
* @author Jelle De Loecker <[email protected]> | ||
* @since 2.0.0 | ||
* @version 2.0.0 | ||
* @version 2.4.0 | ||
* | ||
* @param {Array} result | ||
* @param {HTMLElement} element | ||
|
@@ -2274,7 +2274,7 @@ defStat(function getElementsByAttribute(element, name, value) { | |
* | ||
* @return {Array} | ||
*/ | ||
function _getElementsByAttribute(result, check_value, element, name, value) { | ||
function _getElementsByAttribute(result, check_value, element, names, value) { | ||
|
||
if (typeof element == 'string' || element.nodeType != 1) { | ||
return; | ||
|
@@ -2290,20 +2290,25 @@ function _getElementsByAttribute(result, check_value, element, name, value) { | |
children = element.children; | ||
} | ||
|
||
names = Array.cast(names); | ||
|
||
for (i = 0; i < children.length; i++) { | ||
child = children[i]; | ||
|
||
if (!child || !child.hasAttribute) { | ||
continue; | ||
} | ||
|
||
if (child.hasAttribute(name)) { | ||
if (!check_value || child.getAttribute(name) == value) { | ||
result.push(child); | ||
for (let name of names) { | ||
if (child.hasAttribute(name)) { | ||
if (!check_value || child.getAttribute(name) == value) { | ||
result.push(child); | ||
break; | ||
} | ||
} | ||
} | ||
|
||
_getElementsByAttribute(result, check_value, child, name, value); | ||
_getElementsByAttribute(result, check_value, child, names, value); | ||
} | ||
|
||
return result; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2623,7 +2623,7 @@ Element.setMethod(function afterRender(callback) { | |
* | ||
* @author Jelle De Loecker <[email protected]> | ||
* @since 2.1.3 | ||
* @version 2.3.17 | ||
* @version 2.4.0 | ||
* | ||
* @param {boolean} clear_content | ||
* @param {boolean} re_render | ||
|
@@ -2671,11 +2671,11 @@ function _extractSlotData(clear_content, re_render) { | |
// If this element is being re-rendered, the slots have already been used. | ||
// We need to extract them from the children | ||
if (re_render) { | ||
let slot_elements = this.querySelectorAll('[data-he-slot]'); | ||
let slot_elements = this.querySelectorAll('[data-he-slot],[slot]'); | ||
|
||
for (i = 0; i < slot_elements.length; i++) { | ||
child = slot_elements[i]; | ||
slot_name = child.getAttribute('data-he-slot'); | ||
slot_name = child.getAttribute('data-he-slot') || child.getAttribute('slot'); | ||
|
||
if (!slots) { | ||
slots = {}; | ||
|
@@ -2721,7 +2721,7 @@ function _extractSlotData(clear_content, re_render) { | |
* | ||
* @author Jelle De Loecker <[email protected]> | ||
* @since 2.1.3 | ||
* @version 2.1.3 | ||
* @version 2.4.0 | ||
* | ||
* @param {Object} slot_data | ||
*/ | ||
|
@@ -2731,17 +2731,17 @@ function _insertSlotData(slot_data) { | |
return; | ||
} | ||
|
||
let slots = Hawkejs.getElementsByAttribute(this, 'data-he-slot'), | ||
let slots = this.querySelectorAll('slot'), | ||
slot, | ||
name, | ||
i; | ||
|
||
for (i = 0; i < slots.length; i++) { | ||
slot = slots[i]; | ||
name = slot.dataset.heSlot; | ||
name = slot.getAttribute('name'); | ||
|
||
if (slot_data.slots[name]) { | ||
Hawkejs.replaceChildren(slot, slot_data.slots[name].childNodes); | ||
Hawkejs.replaceChildren(slot, [slot_data.slots[name]]); | ||
} | ||
} | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
<div data-he-slot="main">Default main slot</div> | ||
<slot name="main">Default main slot</slot> |