-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Right-align rtl text in title fields (#1261)
* Functionality to get rtl titles aligned properly in index, show and browse pages done * Lint * Export the show_default methods and import where needed. Adds jest test to test the alignRtl method * moved some things around to be better organized * Lint * Reverted to == since we aren't doing a strict match
- Loading branch information
Showing
8 changed files
with
87 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
app/javascript/psulib_blacklight/javascripts/align_rtl_index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
const alignRtl = function () { | ||
// Align rtl text properly | ||
$('article').each(function () { | ||
const titleLink = this.querySelector('.index_title').querySelector('a'); | ||
titleLink.setAttribute('dir', 'auto'); | ||
if (window.getComputedStyle(titleLink).direction === 'rtl') { | ||
titleLink.setAttribute( | ||
'class', | ||
'float-right text-align-start col-sm-11 p-0 pr-4' | ||
); | ||
} | ||
}); | ||
}; | ||
|
||
export default alignRtl; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,8 @@ | |
.documents-list .record-view-only { | ||
display: none; | ||
} | ||
|
||
.text-align-start { | ||
text-align: start; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
<div class="row"> | ||
<div class="col"> | ||
<div class="col text-align-start" dir="auto"> | ||
<%= render_document_heading(@document, tag: :h1) %> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import $ from 'jquery'; | ||
import alignRtl from '../../../app/javascript/psulib_blacklight/javascripts/align_rtl_index'; | ||
|
||
global.$ = $; | ||
global.jQuery = $; | ||
|
||
beforeEach(() => { | ||
document.body.innerHTML = ` | ||
<article data-document-id="123" data-document-counter="4" itemscope="itemscope" itemtype="http://schema.org/Thing" class="blacklight-musical-score document document-position-4"> | ||
<header class="documentHeader row"> | ||
<h3 class="index_title document-title-heading col-sm-9 col-lg-10"> | ||
<span class="document-counter">4.</span> | ||
<a data-context-href="/catalog/123/track?counter=4&document_id=2123&search_id=106" href="/catalog/123">بعض عناوين الأدب</a> | ||
</h3> | ||
</header> | ||
</article> | ||
<article data-document-id="124" data-document-counter="4" itemscope="itemscope" itemtype="http://schema.org/Thing" class="blacklight-musical-score document document-position-5"> | ||
<header class="documentHeader row"> | ||
<h3 class="index_title document-title-heading col-sm-9 col-lg-10"> | ||
<span class="document-counter">5.</span> | ||
<a data-context-href="/catalog/124/track?counter=4&document_id=2124&search_id=107" href="/catalog/124">Some other title</a> | ||
</h3> | ||
</header> | ||
</article> | ||
`; | ||
}); | ||
|
||
describe('when catalog index list contains rtl text titles', () => { | ||
test('Aligns rtl text to the right but does not change ltr text', () => { | ||
const mockComputedStyleRtl = { | ||
direction: 'rtl', | ||
}; | ||
|
||
const mockComputedStyleLtr = { | ||
direction: 'ltr', | ||
}; | ||
|
||
window.getComputedStyle = jest.fn().mockImplementation((element) => { | ||
if (element == 'http://localhost/catalog/123') { | ||
return mockComputedStyleRtl; | ||
} | ||
return mockComputedStyleLtr; | ||
}); | ||
|
||
alignRtl(); | ||
expect($('a')[0].outerHTML).toBe( | ||
'<a data-context-href="/catalog/123/track?counter=4&' + | ||
'document_id=2123&search_id=106" href="/catalog/123' + | ||
'" dir="auto" class="float-right text-align-start col' + | ||
'-sm-11 p-0 pr-4">بعض عناوين الأدب</a>' | ||
); | ||
expect($('a')[1].outerHTML).toBe( | ||
'<a data-context-href="/catalog/124/track?counter=4&' + | ||
'document_id=2124&search_id=107" href="/catalog/124' + | ||
'" dir="auto">Some other title</a>' | ||
); | ||
}); | ||
}); |