Skip to content

Commit

Permalink
fix #19
Browse files Browse the repository at this point in the history
  • Loading branch information
James Padolsey committed Mar 11, 2014
1 parent f740612 commit 707a33b
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
1 change: 1 addition & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ finder.revert();

### Changelog

* 0.4.1 (11 Mar 2014): Fix portionMode:first phantom nodes (see [issue #19](https://github.com/padolsey/findAndReplaceDOMText/issues/19))
* 0.4.0 (6 Oct 2013): Major API overhaul, including a new arg signature (`findAndReplaceDOMText(node, options)`, plus the ability to replace a match with text or wrap it with a DOM Node.
* 0.3.0: Switch to semver, add node-filtering feature (as requested in [Issue #11](https://github.com/padolsey/findAndReplaceDOMText/issues/11)
* 0.2: Fix case where regular expression contains word bounderies and add support for specifying a capture group to replace as the fourth argument to `findAndReplaceDOMText()` (see [issue #5](https://github.com/padolsey/findAndReplaceDOMText/issues/5))
Expand Down
6 changes: 5 additions & 1 deletion src/findAndReplaceDOMText.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* findAndReplaceDOMText v 0.4.0
* findAndReplaceDOMText v 0.4.1
* @author James Padolsey http://james.padolsey.com
* @license http://unlicense.org/UNLICENSE
*
Expand Down Expand Up @@ -389,6 +389,10 @@ window.findAndReplaceDOMText = (function() {
)
);

if (!replacement.data) {
return replacement;
}

if (!el) {
return replacement;
}
Expand Down
24 changes: 24 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -318,4 +318,28 @@ test('Deprecated argument signature', function() {
});
htmlEqual(d.innerHTML, '<x>foo</x>bar <x>foo</x>bar <style>foobar{}</style>');

});

module('portionMode');

test('portionMode:first', function() {
var d = document.createElement('div');
d.innerHTML = 'Testing 123 HE<em>LLO there</em>';
findAndReplaceDOMText(d, {
find: /hello/i,
wrap: 'span',
portionMode: 'first'
});
htmlEqual(d.innerHTML, 'Testing 123 <span>HELLO</span><em> there</em>');
});

test('portionMode:retain', function() {
var d = document.createElement('div');
d.innerHTML = 'Testing 123 HE<em>LLO there</em>';
findAndReplaceDOMText(d, {
find: /hello/i,
wrap: 'span',
portionMode: 'retain'
});
htmlEqual(d.innerHTML, 'Testing 123 <span>HE</span><em><span>LLO</span> there</em>');
});

0 comments on commit 707a33b

Please sign in to comment.