Skip to content

Commit

Permalink
Merge pull request #1615 from Sefaria/feature/sc-19829/tag-1-to-the-p…
Browse files Browse the repository at this point in the history
…roper-image

feat(Scroll Links): inline links can now be scrollLink or refLink
  • Loading branch information
akiva10b committed Sep 7, 2023
2 parents ee16114 + 4c662e4 commit 58911c6
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 14 deletions.
2 changes: 1 addition & 1 deletion sefaria/constants/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
# structure placement (e.g. page transitions): uses 'data-overlay', 'data-value'
'i': ['data-overlay', 'data-value', 'data-commentator', 'data-order', 'class', 'data-label', 'dir'],
'img': ['src', 'alt'],
'a': ['dir', 'class', 'href', 'data-ref', "data-ven", "data-vhe"],
'a': ['dir', 'class', 'href', 'data-ref', "data-ven", "data-vhe", 'data-scroll-link'],
}
4 changes: 2 additions & 2 deletions static/css/s2.css
Original file line number Diff line number Diff line change
Expand Up @@ -5351,14 +5351,14 @@ But not to use a display block directive that might break continuous mode for ot
.readerPanel.hebrew .segment.enOnly .segmentNumber .he {
display: block;
}
.segment .refLink {
.segment .refLink, .scrollLink {
font-size: .8em;
font-weight: bold;
letter-spacing: 1px;
cursor: pointer;
color: #333;
}
.refLink:hover {
.scrollLink:hover, .refLink:hover {
text-decoration: underline;
}
.segment .namedEntityLink {
Expand Down
6 changes: 4 additions & 2 deletions static/js/ReaderApp.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -1355,9 +1355,11 @@ toggleSignUpModal(modalContentKind = SignUpModalKind.Default) {
currentlyVisibleRef = ref;
highlightedRefs = (panel.mode === "TextAndConnections") ? [ref] : [];
}
let updatePanelObj = {refs: refs, currentlyVisibleRef: currentlyVisibleRef, highlightedRefs: highlightedRefs}
let updatePanelObj = {refs, currentlyVisibleRef, highlightedRefs};
const { dependentPanel } = this._getDependentPanel(n);
Object.assign(dependentPanel, {refs, currentlyVisibleRef, highlightedRefs});
if (dependentPanel) {
Object.assign(dependentPanel, updatePanelObj);
}
Object.assign(panel, updatePanelObj);
this.setState({panels: this.state.panels});
}
Expand Down
1 change: 1 addition & 0 deletions static/js/ReaderPanel.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,7 @@ class ReaderPanel extends Component {
unsetTextHighlight={this.props.unsetTextHighlight}
translationLanguagePreference={this.props.translationLanguagePreference}
updateCurrVersionsToMatchAPIResult={this.updateCurrVersionsToMatchAPIResult}
navigatePanel={this.props.navigatePanel}
key={`${textColumnBookTitle ? textColumnBookTitle : "empty"}-TextColumn`} />
);
}
Expand Down
2 changes: 2 additions & 0 deletions static/js/TextColumn.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,7 @@ class TextColumn extends Component {
panelsOpen={this.props.panelsOpen}
layoutWidth={this.props.layoutWidth}
unsetTextHighlight={this.props.unsetTextHighlight}
navigatePanel={this.props.navigatePanel}
translationLanguagePreference={this.props.translationLanguagePreference}
updateCurrVersionsToMatchAPIResult={this.props.updateCurrVersionsToMatchAPIResult}
key={sref} />);
Expand Down Expand Up @@ -458,6 +459,7 @@ TextColumn.propTypes = {
textHighlights: PropTypes.array,
unsetTextHighlight: PropTypes.func,
translationLanguagePreference: PropTypes.string,
navigatePanel: PropTypes.func,
};


Expand Down
40 changes: 31 additions & 9 deletions static/js/TextRange.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,7 @@ class TextRange extends Component {
formatEnAsPoetry={formatEnAsPoetry}
formatHeAsPoetry={formatHeAsPoetry}
placeSegmentNumbers={this.placeSegmentNumbers}
navigatePanel={this.props.navigatePanel}
/>
</span>
);
Expand Down Expand Up @@ -468,6 +469,7 @@ TextRange.propTypes = {
inlineReference: PropTypes.object,
textHighlights: PropTypes.array,
translationLanguagePreference: PropTypes.string,
navigatePanel: PropTypes.func
};
TextRange.defaultProps = {
currVersions: {en:null,he:null},
Expand All @@ -492,21 +494,40 @@ class TextSegment extends Component {
this.props.unsetTextHighlight();
}
}
handleRefLinkClick(refLink, event) {
event.preventDefault();
let newRef = Sefaria.humanRef(refLink.attr("data-ref"));
const newBook = Sefaria.parseRef(newRef)?.book;
const currBook = Sefaria.parseRef(this.props.sref)?.book;
const isScrollLink = refLink.attr('data-scroll-link');

// two options: in most cases, we open a new panel, but if isScrollLink is 'true', we should navigate in the same panel to the new location
const canNavigatePanel = newBook === currBook && !!this.props.navigatePanel; // navigatePanel only works if we're scrolling to a location in the same book
if (isScrollLink === 'true' && canNavigatePanel) {
this.props.navigatePanel(newRef);
}
else {
const ven = refLink.attr("data-ven") ? refLink.attr("data-ven") : null;
const vhe = refLink.attr("data-vhe") ? refLink.attr("data-vhe") : null;
let currVersions = {"en": ven, "he": vhe};
this.props.onCitationClick(newRef, this.props.sref, true, currVersions);
}

event.stopPropagation();
Sefaria.track.event("Reader", "Citation Link Click", ref);
}
isRefLink (x) {
// 'x' is a jquery element
return x?.attr('data-ref') && x?.prop('tagName') === 'A';
}
handleClick(event) {
// grab refLink from target or parent (sometimes there is an <i> within refLink forcing us to look for the parent)
const refLink = $(event.target).hasClass("refLink") ? $(event.target) : ($(event.target.parentElement).hasClass("refLink") ? $(event.target.parentElement) : null);
const refLink = this.isRefLink($(event.target)) ? $(event.target) : this.isRefLink($(event.target.parentElement)) ? $(event.target.parentElement) : null;
const namedEntityLink = $(event.target).closest("a.namedEntityLink");
const footnoteLink = $(event.target).is("sup") || $(event.target).parents("sup").size();
if (refLink) {
//Click of citation
event.preventDefault();
let ref = Sefaria.humanRef(refLink.attr("data-ref"));
const ven = refLink.attr("data-ven") ? refLink.attr("data-ven") : null;
const vhe = refLink.attr("data-vhe") ? refLink.attr("data-vhe") : null;
let currVersions = {"en": ven, "he": vhe};
this.props.onCitationClick(ref, this.props.sref, true, currVersions);
event.stopPropagation();
Sefaria.track.event("Reader", "Citation Link Click", ref);
this.handleRefLinkClick(refLink, event);
} else if (footnoteLink) {
this.props.onFootnoteClick(event);
event.stopPropagation();
Expand Down Expand Up @@ -663,6 +684,7 @@ TextSegment.propTypes = {
onFootnoteClick: PropTypes.func,
onNamedEntityClick: PropTypes.func,
unsetTextHighlight: PropTypes.func,
navigatePanel: PropTypes.func
};

export default TextRange;

0 comments on commit 58911c6

Please sign in to comment.