-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1426 from laws-africa/search
search for selection in document v iew
- Loading branch information
Showing
8 changed files
with
90 additions
and
16 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
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
34 changes: 34 additions & 0 deletions
34
peachjam/js/components/DocumentContent/selection-search.ts
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,34 @@ | ||
import { IRangeTarget } from '@lawsafrica/indigo-akn/dist/ranges'; | ||
import { GutterEnrichmentManager, IGutterEnrichmentProvider } from '@lawsafrica/indigo-akn/dist/enrichments'; | ||
import peachJam from '../../peachjam'; | ||
import i18next from 'i18next'; | ||
|
||
/** | ||
* Adds a popup to search the site based on selected document text. | ||
*/ | ||
export default class SelectionSearch implements IGutterEnrichmentProvider { | ||
protected manager: GutterEnrichmentManager; | ||
|
||
constructor (manager: GutterEnrichmentManager) { | ||
this.manager = manager; | ||
this.manager.addProvider(this); | ||
} | ||
|
||
getButton (target: IRangeTarget): HTMLButtonElement | null { | ||
const btn = document.createElement('button'); | ||
btn.className = 'btn btn-outline-secondary'; | ||
btn.type = 'button'; | ||
btn.innerText = i18next.t('Search {{appName}}...', { appName: peachJam.config.appName }); | ||
return btn; | ||
} | ||
|
||
addEnrichment (target: IRangeTarget): void { | ||
if (target.selectors) { | ||
// get the selected text | ||
const quoteSelector = target.selectors.find((x) => x.type === 'TextQuoteSelector'); | ||
if (quoteSelector && quoteSelector.exact) { | ||
document.location = '/search/?q=' + encodeURIComponent(quoteSelector.exact); | ||
} | ||
} | ||
} | ||
} |
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
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