Skip to content
This repository has been archived by the owner on Sep 24, 2019. It is now read-only.

Commit

Permalink
Changed to smaller number of elements to search, support ancestor dir…
Browse files Browse the repository at this point in the history
…ection.

#72
  • Loading branch information
Kevin Miller committed Jan 4, 2014
1 parent d2c4677 commit 426fe50
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/js/custom/languageDirAttributeIsUsed.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
quail.languageDirAttributeIsUsed = function() {
var currentDirection = (quail.html.attr('dir')) ? quail.html.attr('dir').toLowerCase() : 'ltr';
var oppositeDirection = (currentDirection === 'ltr') ? 'rtl' : 'ltr';
quail.html.find(quail.textSelector).each(function() {
currentDirection = ($(this).attr('dir')) ? $(this).attr('dir').toLowerCase() : currentDirection;
quail.html.find('p, blockquote, aside, h1, h2, h3, h4, h5, h6').each(function() {
if($(this).attr('dir')) {
currentDirection = $(this).attr('dir').toLowerCase();
}
else {
currentDirection = ($(this).parent('[dir]').first().attr('dir')) ? $(this).parent('[dir]').first().attr('dir').toLowerCase() : currentDirection;
}
if(typeof quail.textDirection[currentDirection] === 'undefined') {
currentDirection = 'ltr';
}
oppositeDirection = (currentDirection === 'ltr') ? 'rtl' : 'ltr';
var matches = $(this).text().match(quail.textDirection[currentDirection]);
var matches = $(this).text().match(quail.textDirection[oppositeDirection]);
if(!matches) {
return;
}
matches = matches.length;
$(this).find('[dir=' + oppositeDirection + ']').each(function() {
var childMatches = $(this).text().match(quail.textDirection[currentDirection]);
var childMatches = $(this).text().match(quail.textDirection[oppositeDirection]);
if(childMatches) {
matches = matches - childMatches.length;
}
Expand Down
1 change: 1 addition & 0 deletions test/quail.html
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,7 @@
"testfiles/common/languageDirAttributeIsUsed-fail.html",
"testfiles/common/languageDirAttributeIsUsed-fail-2.html",
"testfiles/common/languageDirAttributeIsUsed-fail-3.html",
"testfiles/common/languageDirAttributeIsUsed-fail-4.html",
"testfiles/common/legendDescribesListOfChoices-fail-2.html",
"testfiles/common/legendDescribesListOfChoices-fail.html",
"testfiles/common/legendTextNotEmpty-fail.html",
Expand Down
33 changes: 33 additions & 0 deletions test/testfiles/common/languageDirAttributeIsUsed-fail-4.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<!doctype html>
<html>

<head>
<title>languageDirAttributeIsUsed-fail-4</title>
<link rel="stylesheet" href="../../../lib/qunit/qunit/qunit.css" media="screen">
</head>

<body>
<div id="quail-scope">
<div dir="rtl">
<blockquote>
וואַכטל זענען זייער קיוט איך טראַכטן.
</blockquote>
<p>
וואַכטל זענען זייער "some english text" קיוט איך טראַכטן.
</p>
</div>
</div>
<script id="qunit-jquery" src="../../../lib/jquery/jquery.js"></script>
<script id="qunit-quail" src="../../../dist/quail.jquery.js"></script>
<script id="qunit-composite" src="../../composite.js"></script>
<script id="qunit-qunit" src="../../../lib/qunit/qunit/qunit.js"></script>
<script id="qunit-script">
test('languageDirAttributeIsUsed', function() {
quailTest.runTest( 'languageDirAttributeIsUsed' );
equal(true, quailTest.confirmIsTag('p'), 'Paragraph has mixed direction');
});
</script>
</body>

</html>

0 comments on commit 426fe50

Please sign in to comment.