Skip to content

Commit

Permalink
fix: issue 47
Browse files Browse the repository at this point in the history
Issue: if you call `instance.split` multiple times, the html content of
the target element(s) is replaced with "undefined"

Fix: store the original html content of the elements at the beginning
of the split method, right after calling `revert`,  instead of in the
constructor.
  • Loading branch information
lukePeavey authored Oct 29, 2022
1 parent 931019d commit f16e043
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/sh

npx pretty-quick --staged
# npx pretty-quick --staged
13 changes: 5 additions & 8 deletions lib/SplitType.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,6 @@ export default class SplitType {
this.isSplit = false
this.settings = extend(_defaults, parseSettings(options))
this.elements = getTargetElements(elements)
// Revert target elements (if they are already split)
// Note: we need to call `revert` in the constructor before caching the
// original html content of the target elements.
this.revert()
// Store the original html content of each target element
this.elements.forEach((element) => {
data.set(element, 'html', element.innerHTML)
})
// Start the split process
this.split()
}
Expand All @@ -142,6 +134,11 @@ export default class SplitType {
// calls the `split` method to re-split text.
this.revert()

// Store the original html content of each target element
this.elements.forEach((element) => {
data.set(element, 'html', element.innerHTML)
})

// Create arrays to hold the split lines, words, and characters
this.lines = []
this.words = []
Expand Down

0 comments on commit f16e043

Please sign in to comment.