-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Minor refactoring and bump version to 0.1.4
- Loading branch information
1 parent
fddf76e
commit 813ea5f
Showing
5 changed files
with
50 additions
and
53 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
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,35 +1,34 @@ | ||
(function(root, factory) { | ||
root.TemplateTemplate = factory(); | ||
}(this, function() { | ||
root.TemplateTemplate = factory(root.document); | ||
}(this, function(document) { | ||
return function(template, insertions) { | ||
template = template instanceof HTMLElement ? template : document.querySelector(template); | ||
insertions = insertions || {}; | ||
|
||
if (template instanceof HTMLTemplateElement) { | ||
var importedNode = document.importNode(template.content, true); | ||
if (template === null) { | ||
throw new TypeError(template + ' is not an HTMLTemplateElement'); | ||
} | ||
|
||
Object.entries(insertions).forEach(function(insertionArray) { | ||
var currentNode = importedNode.querySelector(insertionArray[0]), | ||
insertionValue = insertionArray[1]; | ||
var importedNode = document.importNode(template.content, true); | ||
|
||
if (insertionValue instanceof Array) { | ||
Object.entries(insertionValue[1]).forEach(function(attributesArray) { | ||
currentNode.setAttribute(attributesArray[0], attributesArray[1]); | ||
}); | ||
Object.entries(insertions || {}).forEach(function(insertionArray) { | ||
var currentNode = importedNode.querySelector(insertionArray[0]), | ||
insertionValue = insertionArray[1]; | ||
|
||
insertionValue = insertionValue[0]; | ||
} | ||
if (insertionValue instanceof Array) { | ||
Object.entries(insertionValue[1]).forEach(function(attributesArray) { | ||
currentNode.setAttribute(attributesArray[0], attributesArray[1]); | ||
}); | ||
|
||
if (insertionValue instanceof DocumentFragment || insertionValue instanceof HTMLElement) { | ||
currentNode.appendChild(insertionValue); | ||
} else { | ||
currentNode.textContent = insertionValue; | ||
} | ||
}); | ||
insertionValue = insertionValue[0]; | ||
} | ||
|
||
return importedNode; | ||
} else { | ||
throw new TypeError(template.constructor.name + ' is not an HTMLTemplateElement.'); | ||
} | ||
if (insertionValue instanceof DocumentFragment || insertionValue instanceof HTMLElement) { | ||
currentNode.appendChild(insertionValue); | ||
} else { | ||
currentNode.textContent = insertionValue; | ||
} | ||
}); | ||
|
||
return importedNode; | ||
}; | ||
})); |