This repository has been archived by the owner on Mar 30, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 259
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move thumbs up/down JS+CSS fix into style-specific files (fixes #95)
- Loading branch information
Showing
4 changed files
with
111 additions
and
47 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
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,54 @@ | ||
/* | ||
* js/styles/cocoa.js | ||
* | ||
* This script contains code needed for the Cocoa style. | ||
* | ||
* Subject to terms and conditions in LICENSE.md. | ||
* | ||
*/ | ||
|
||
if (typeof window.Styles.Cocoa === 'undefined') { | ||
window.Styles.Cocoa = true; | ||
|
||
// Thumbs up and down styles. | ||
(function() { | ||
// Create dummy elements to get the computed styles for these elements. | ||
var td = document.createElement('td'); | ||
td.dataset.col = 'rating'; | ||
|
||
var el = document.createElement('div'); | ||
el.className = 'song-row'; | ||
el.appendChild(td); | ||
el.style.display = 'none'; | ||
document.body.appendChild(el); | ||
|
||
// Get the background-position for thumbs up. | ||
td.dataset.rating = '5'; | ||
var thumbsUpStyle = document.defaultView.getComputedStyle(td, null); | ||
var thumbsUpBackX = parseInt(thumbsUpStyle.backgroundPositionX); | ||
var thumbsUpBackY = parseInt(thumbsUpStyle.backgroundPositionY); | ||
|
||
// Get the background-position for thumbs down. | ||
td.dataset.rating = '1'; | ||
var thumbsDownStyle = document.defaultView.getComputedStyle(td, null); | ||
var thumbsDownBackX = parseInt(thumbsDownStyle.backgroundPositionX); | ||
var thumbsDownBackY = parseInt(thumbsDownStyle.backgroundPositionY); | ||
|
||
// Remove the element. | ||
document.body.removeChild(el); | ||
|
||
// Apply a new stylesheet for the new thumbs up and down positions. | ||
thumbsUpBackY -= 9; | ||
thumbsDownBackY -= 7; | ||
|
||
var thumbsUpPosition = thumbsUpBackX + 'px ' + thumbsUpBackY + 'px'; | ||
var thumbsDownPosition = thumbsDownBackX + 'px ' + thumbsDownBackY + 'px'; | ||
|
||
window.Styles.applyStyle('thumbsUpDown', | ||
'.song-row [data-col="rating"][data-rating="5"]:not(.stars) { background-position: ' + thumbsUpPosition + ' !important; } ' + | ||
|
||
'.song-row [data-col="rating"][data-rating="1"]:not(.stars), ' + | ||
'.song-row [data-col="rating"][data-rating="2"]:not(.stars) { background-position: ' + thumbsDownPosition + ' !important; } ' | ||
); | ||
})(); | ||
} |
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,54 @@ | ||
/* | ||
* js/styles/cocoa.js | ||
* | ||
* This script contains code needed for the Cocoa style. | ||
* | ||
* Subject to terms and conditions in LICENSE.md. | ||
* | ||
*/ | ||
|
||
if (typeof window.Styles.Dark === 'undefined') { | ||
window.Styles.Dark = true; | ||
|
||
// Thumbs up and down styles. | ||
(function() { | ||
// Create dummy elements to get the computed styles for these elements. | ||
var td = document.createElement('td'); | ||
td.dataset.col = 'rating'; | ||
|
||
var el = document.createElement('div'); | ||
el.className = 'song-row'; | ||
el.appendChild(td); | ||
el.style.display = 'none'; | ||
document.body.appendChild(el); | ||
|
||
// Get the background-position for thumbs up. | ||
td.dataset.rating = '5'; | ||
var thumbsUpStyle = document.defaultView.getComputedStyle(td, null); | ||
var thumbsUpBackX = parseInt(thumbsUpStyle.backgroundPositionX); | ||
var thumbsUpBackY = parseInt(thumbsUpStyle.backgroundPositionY); | ||
|
||
// Get the background-position for thumbs down. | ||
td.dataset.rating = '1'; | ||
var thumbsDownStyle = document.defaultView.getComputedStyle(td, null); | ||
var thumbsDownBackX = parseInt(thumbsDownStyle.backgroundPositionX); | ||
var thumbsDownBackY = parseInt(thumbsDownStyle.backgroundPositionY); | ||
|
||
// Remove the element. | ||
document.body.removeChild(el); | ||
|
||
// Apply a new stylesheet for the new thumbs up and down positions. | ||
thumbsUpBackY -= 9; | ||
thumbsDownBackY -= 7; | ||
|
||
var thumbsUpPosition = thumbsUpBackX + 'px ' + thumbsUpBackY + 'px'; | ||
var thumbsDownPosition = thumbsDownBackX + 'px ' + thumbsDownBackY + 'px'; | ||
|
||
window.Styles.applyStyle('thumbsUpDown', | ||
'.song-row [data-col="rating"][data-rating="5"]:not(.stars) { background-position: ' + thumbsUpPosition + ' !important; } ' + | ||
|
||
'.song-row [data-col="rating"][data-rating="1"]:not(.stars), ' + | ||
'.song-row [data-col="rating"][data-rating="2"]:not(.stars) { background-position: ' + thumbsDownPosition + ' !important; } ' | ||
); | ||
})(); | ||
} |