-
-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Scryfall links/popups Fixes #94 * Remove service-worker.js * Nonfunctional improvements Remove unused eslint command. Hardcode utm_source for this site. Combine two calls into one. * Update VueTippy and other dependencies Also removes vanilla Tippy * Add "progress" cursor while tippy is loading
- Loading branch information
1 parent
4258f56
commit 979a17e
Showing
8 changed files
with
208 additions
and
316 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
node_modules | ||
service-worker.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
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 |
---|---|---|
@@ -0,0 +1,100 @@ | ||
const tip = Tippy( '.cardname', { | ||
arrow: false, | ||
animateFill: false, | ||
followCursor: true, | ||
html: '#js--card-popup', | ||
placement: 'top', | ||
touchHold: true, | ||
delay: [ 50, 0 ], | ||
animation: 'fade', | ||
duration: 0, | ||
performance: true, | ||
theme: 'scryfall', | ||
onShow() { | ||
const thisPopper = this, | ||
content = thisPopper.querySelector( '.tippy-content' ), | ||
target = thisPopper._reference, | ||
jsonURI = new URL( 'https://api.scryfall.com/cards/named' ); | ||
var rotationClass = 'rotate-0'; | ||
jsonURI.searchParams.set( 'exact', target.dataset.cardName ); | ||
jsonURI.searchParams.set( 'set', typeof target.dataset.cardSet === 'undefined' ? '' : target.dataset.cardSet ); | ||
if ( tip.loading || content.innerHTML !== '' ) { return; } | ||
tip.loading = true; | ||
target.style.cursor = 'progress'; | ||
// Hide the tooltip until we've finished loaded the image | ||
thisPopper.style.display = 'none'; | ||
// fetch() only works on modern browsers | ||
fetch( jsonURI ) | ||
.then( response => { | ||
if ( !response.ok ) { throw Error( response.statusText ); } | ||
{ return response; } | ||
} ) | ||
.then( response => response.json() ) | ||
.then( data => { | ||
const queryURI = new URL( target.href ), | ||
directURI = new URL( data.scryfall_uri ); | ||
directURI.searchParams.set( 'utm_source', 'whatsinstandard' ); | ||
if ( data.hasOwnProperty( 'card_faces' ) ) { | ||
const isSecondface = data.card_faces[ 0 ].name.replace( /[^a-z]/ig, '' ).toUpperCase() !== | ||
decodeURIComponent( target.dataset.cardName ).replace( /[^a-z]/ig, '' ).toUpperCase(); | ||
if ( data.layout === 'transform' || data.layout === 'double_faced_token' ) { | ||
if ( isSecondface ) { | ||
target.href = directURI.href + '&back'; | ||
return data.card_faces[ 1 ].image_uris.normal; | ||
} else { | ||
return data.card_faces[ 0 ].image_uris.normal; | ||
} | ||
} else if ( data.layout === 'split' ) { | ||
if ( data.card_faces[ 1 ].oracle_text.startsWith( 'Aftermath' ) ) { | ||
if ( isSecondface ) { rotationClass = 'rotate-90ccw'; } | ||
} else { rotationClass = 'rotate-90cw'; } | ||
} else if ( data.layout === 'flip' ) { | ||
if ( isSecondface ) { rotationClass = 'rotate-180'; } | ||
} | ||
} | ||
target.href = directURI.href; | ||
if ( data.layout === 'planar' ) { rotationClass = 'rotate-90cw'; } | ||
return data.image_uris.normal; | ||
} ) | ||
.then( imageURI => fetch( imageURI ) ) | ||
.then( response => response.blob() ) | ||
.then( blob => { | ||
const url = URL.createObjectURL( blob ), | ||
img = document.createElement( 'img' ); | ||
img.classList.add( 'cardimage', rotationClass ); | ||
img.src = url; | ||
img.alt = target.text; | ||
img.width = 244; | ||
content.append( img ); | ||
// Show the tooltip by removing display:none | ||
thisPopper.style.removeProperty( 'display' ); | ||
target.style.removeProperty( 'cursor' ); | ||
tip.loading = false; | ||
} ) | ||
.catch( function () { | ||
// TODO: This should be localized | ||
content.innerHTML = 'Preview error'; | ||
content.parentNode.classList.remove( 'scryfall-theme' ); | ||
content.parentNode.classList.add( 'error' ); | ||
// Show the tooltip by removing display:none | ||
thisPopper.style.removeProperty( 'display' ); | ||
target.style.removeProperty( 'cursor' ); | ||
tip.loading = false; | ||
} ); | ||
}, | ||
onHidden() { | ||
const content = this.querySelector( '.tippy-content' ); | ||
content.innerHTML = ''; | ||
}, | ||
// prevent tooltip from displaying over button | ||
popperOptions: { | ||
modifiers: { | ||
preventOverflow: { | ||
enabled: false | ||
}, | ||
hide: { | ||
enabled: false | ||
} | ||
} | ||
} | ||
} ); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.