Skip to content
This repository has been archived by the owner on Mar 30, 2021. It is now read-only.

Commit

Permalink
Move thumbs up/down JS+CSS fix into style-specific files (fixes #95)
Browse files Browse the repository at this point in the history
  • Loading branch information
kbhomes committed Mar 26, 2014
1 parent b972f47 commit b21c9bf
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 47 deletions.
6 changes: 3 additions & 3 deletions google-music-mac/Styles/ApplicationStyle.m
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ + (NSString *)cssNamed:(NSString *)name

+ (NSString *)jsNamed:(NSString *)name
{
NSString *file = [NSString stringWithFormat:@"js/%@", name];
NSString *file = [NSString stringWithFormat:@"js/styles/%@", name];
NSString *path = [[NSBundle mainBundle] pathForResource:file ofType:@"js"];
NSString *js = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:NULL];

Expand All @@ -58,7 +58,7 @@ + (NSMutableDictionary *)styles
[cocoa setDescription:@"An application style to match Mac OS X."];
[cocoa setWindowColor:[NSColor colorWithSRGBRed:0.898f green:0.898f blue:0.898f alpha:1.0f]];
[cocoa setCss:[ApplicationStyle cssNamed:@"cocoa"]];
[cocoa setJs:nil];
[cocoa setJs:[ApplicationStyle jsNamed:@"cocoa"]];

// Create the Dark style.
ApplicationStyle *dark = [[ApplicationStyle alloc] init];
Expand All @@ -67,7 +67,7 @@ + (NSMutableDictionary *)styles
[dark setDescription:@"A dark style similar to Spotify."];
[dark setWindowColor:[NSColor colorWithSRGBRed:0.768f green:0.768f blue:0.768f alpha:1.0f]];
[dark setCss:[ApplicationStyle cssNamed:@"dark"]];
[dark setJs:nil];
[dark setJs:[ApplicationStyle jsNamed:@"dark"]];

NSMutableDictionary *dictionary = [NSMutableDictionary dictionary];
[dictionary setObject:cocoa forKey:[cocoa name]];
Expand Down
44 changes: 0 additions & 44 deletions google-music-mac/js/styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,48 +35,4 @@ if (typeof window.Styles === 'undefined') {
}
}
};

// Here, apply styles that cannot be calculated in CSS alone.

// 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; } '
);
})();
}
54 changes: 54 additions & 0 deletions google-music-mac/js/styles/cocoa.js
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; } '
);
})();
}
54 changes: 54 additions & 0 deletions google-music-mac/js/styles/dark.js
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; } '
);
})();
}

0 comments on commit b21c9bf

Please sign in to comment.