Skip to content

Commit

Permalink
Fixed an issue of utils.watchElement function (#51)
Browse files Browse the repository at this point in the history
* Fixed an issue of utils.watchElement
  • Loading branch information
allmywant authored Feb 18, 2020
1 parent d9f6e9c commit 9f83f1d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
9 changes: 3 additions & 6 deletions lib/mojito.js
Original file line number Diff line number Diff line change
Expand Up @@ -883,11 +883,8 @@ Mojito = (function ()
}
}

if (!this.domWatcher)
{
var MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver;
this.domWatcher = new MutationObserver(callback);
}
var MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver;
var domWatcher = new MutationObserver(callback);

if (!watchOptions)
{
Expand All @@ -911,7 +908,7 @@ Mojito = (function ()

for (var i=0;i<elements.length;i++)
{
this.domWatcher.observe(elements[i], watchOptions);
domWatcher.observe(elements[i], watchOptions);
}
},
/**
Expand Down
25 changes: 23 additions & 2 deletions tests/test_suite.html
Original file line number Diff line number Diff line change
Expand Up @@ -838,16 +838,37 @@
});

it('WatchElement changes', function (done) {
testDiv = document.createElement('div');
var testDiv = document.createElement('div');
testDiv.className = 'watch-changes';
document.body.appendChild(testDiv);

var testDiv2 = document.createElement('div');
testDiv2.className = 'watch-changes2';
document.body.appendChild(testDiv2);

var testDivChanged = false,
testDiv2Changed = false;

Mojito.utils.watchElement('.watch-changes', function (mutationsList)
{
done();
testDivChanged = true;
if (testDivChanged&&testDiv2Changed)
{
done();
}
});

Mojito.utils.watchElement('.watch-changes2', function (mutationsList)
{
testDiv2Changed = true;
if (testDivChanged&&testDiv2Changed)
{
done();
}
});

testDiv.innerHTML = 'changed';
testDiv2.innerHTML = 'changed';
});

});
Expand Down

0 comments on commit 9f83f1d

Please sign in to comment.