FIX: Fixed behat text selection rule, which broke some tests.

The behat rule for text selection wasn't working due to the JavaScript not executing properly. I have
also updated the code to traverse all childNodes, which is important if you have text like this:

<p>text1 <b>text2</b> text3</p>

And you are trying to select 'text3'
This commit is contained in:
Sam Minnee 2014-02-13 17:36:46 +13:00
parent 5e29249593
commit 4f7c6ebcff
1 changed files with 14 additions and 7 deletions

View File

@ -184,17 +184,24 @@ var editor = jQuery('#$inputFieldId').entwine('ss').getEditor(),
sel = editor.getInstance().selection,
rng = document.createRange(),
matched = false;
jQuery(doc).find('body *').each(function() {
if(!matched && this.firstChild && this.firstChild.nodeValue && this.firstChild.nodeValue.match('$text')) {
rng.setStart(this.firstChild, this.firstChild.nodeValue.indexOf('$text'));
rng.setEnd(this.firstChild, this.firstChild.nodeValue.indexOf('$text') + '$text'.length);
sel.setRng(rng);
editor.getInstance().nodeChanged();
matched = true;
if(!matched) {
for(var i=0;i<this.childNodes.length;i++) {
if(!matched && this.childNodes[i].nodeValue && this.childNodes[i].nodeValue.match('$text')) {
rng.setStart(this.childNodes[i], this.childNodes[i].nodeValue.indexOf('$text'));
rng.setEnd(this.childNodes[i], this.childNodes[i].nodeValue.indexOf('$text') + '$text'.length);
sel.setRng(rng);
editor.getInstance().nodeChanged();
matched = true;
break;
}
}
}
});
JS;
$this->getSession()->evaluateScript($js);
$this->getSession()->executeScript($js);
}
/**