Fixes line endings
This commit is contained in:
parent
9855ba6fe7
commit
02d32ae902
2 changed files with 178 additions and 178 deletions
156
SecretSanta.js
156
SecretSanta.js
|
@ -1,78 +1,78 @@
|
||||||
var SecretSanta = function () {
|
var SecretSanta = function () {
|
||||||
|
|
||||||
this.names = [];
|
this.names = [];
|
||||||
|
|
||||||
this.blacklists = Object.create( null );
|
this.blacklists = Object.create( null );
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
SecretSanta.prototype.add = function ( name ) {
|
SecretSanta.prototype.add = function ( name ) {
|
||||||
|
|
||||||
if ( this.names.indexOf( name ) !== -1 )
|
if ( this.names.indexOf( name ) !== -1 )
|
||||||
throw new Error( 'Cannot redefine ' + name );
|
throw new Error( 'Cannot redefine ' + name );
|
||||||
|
|
||||||
this.names.push( name );
|
this.names.push( name );
|
||||||
|
|
||||||
var subapi = { };
|
var subapi = { };
|
||||||
|
|
||||||
subapi.blacklist = function ( other ) {
|
subapi.blacklist = function ( other ) {
|
||||||
|
|
||||||
if ( ! Object.prototype.hasOwnProperty.call( this.blacklists, name ) )
|
if ( ! Object.prototype.hasOwnProperty.call( this.blacklists, name ) )
|
||||||
this.blacklists[ name ] = [];
|
this.blacklists[ name ] = [];
|
||||||
|
|
||||||
if ( this.blacklists[ name ].indexOf( other ) === -1 )
|
if ( this.blacklists[ name ].indexOf( other ) === -1 )
|
||||||
this.blacklists[ name ].push( other );
|
this.blacklists[ name ].push( other );
|
||||||
|
|
||||||
return subapi;
|
return subapi;
|
||||||
|
|
||||||
}.bind( this );
|
}.bind( this );
|
||||||
|
|
||||||
return subapi;
|
return subapi;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
SecretSanta.prototype.generate = function () {
|
SecretSanta.prototype.generate = function () {
|
||||||
|
|
||||||
var pairings = Object.create( null );
|
var pairings = Object.create( null );
|
||||||
var candidatePairings = Object.create( null );
|
var candidatePairings = Object.create( null );
|
||||||
|
|
||||||
this.names.forEach( function ( name ) {
|
this.names.forEach( function ( name ) {
|
||||||
|
|
||||||
var candidates = _.difference( this.names, name );
|
var candidates = _.difference( this.names, name );
|
||||||
|
|
||||||
if ( Object.prototype.hasOwnProperty.call( this.blacklists, name ) )
|
if ( Object.prototype.hasOwnProperty.call( this.blacklists, name ) )
|
||||||
candidates = _.difference( candidates, this.blacklists[ name ] );
|
candidates = _.difference( candidates, this.blacklists[ name ] );
|
||||||
|
|
||||||
candidatePairings[ name ] = candidates;
|
candidatePairings[ name ] = candidates;
|
||||||
|
|
||||||
}, this );
|
}, this );
|
||||||
|
|
||||||
var findNextGifter = function () {
|
var findNextGifter = function () {
|
||||||
|
|
||||||
var names = Object.keys( candidatePairings );
|
var names = Object.keys( candidatePairings );
|
||||||
|
|
||||||
var minCandidateCount = _.min( names.map( function ( name ) { return candidatePairings[ name ].length; } ) );
|
var minCandidateCount = _.min( names.map( function ( name ) { return candidatePairings[ name ].length; } ) );
|
||||||
var potentialGifters = names.filter( function ( name ) { return candidatePairings[ name ].length === minCandidateCount; } );
|
var potentialGifters = names.filter( function ( name ) { return candidatePairings[ name ].length === minCandidateCount; } );
|
||||||
|
|
||||||
return _.sample( potentialGifters );
|
return _.sample( potentialGifters );
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
while ( Object.keys( candidatePairings ).length > 0 ) {
|
while ( Object.keys( candidatePairings ).length > 0 ) {
|
||||||
|
|
||||||
var name = findNextGifter();
|
var name = findNextGifter();
|
||||||
|
|
||||||
var pairing = _.sample( candidatePairings[ name ] );
|
var pairing = _.sample( candidatePairings[ name ] );
|
||||||
delete candidatePairings[ name ];
|
delete candidatePairings[ name ];
|
||||||
|
|
||||||
Object.keys( candidatePairings ).forEach( function ( name ) {
|
Object.keys( candidatePairings ).forEach( function ( name ) {
|
||||||
candidatePairings[ name ] = _.without( candidatePairings[ name ], pairing );
|
candidatePairings[ name ] = _.without( candidatePairings[ name ], pairing );
|
||||||
} );
|
} );
|
||||||
|
|
||||||
pairings[ name ] = pairing;
|
pairings[ name ] = pairing;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return pairings;
|
return pairings;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
200
pairing.html
200
pairing.html
|
@ -1,100 +1,100 @@
|
||||||
<!doctype html>
|
<!doctype html>
|
||||||
<html>
|
<html>
|
||||||
|
|
||||||
<head>
|
<head>
|
||||||
|
|
||||||
<meta charset="utf-8" />
|
<meta charset="utf-8" />
|
||||||
<title>Secret Santa Pairing</title>
|
<title>Secret Santa Pairing</title>
|
||||||
|
|
||||||
<script src="vendors/Lodash-3.10.1.js"></script>
|
<script src="vendors/Lodash-3.10.1.js"></script>
|
||||||
<script src="vendors/Cryptojs.aes-3.1.2.js"></script>
|
<script src="vendors/Cryptojs.aes-3.1.2.js"></script>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
|
|
||||||
* {
|
* {
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
}
|
}
|
||||||
|
|
||||||
html, body, .main {
|
html, body, .main {
|
||||||
margin: 0;
|
margin: 0;
|
||||||
|
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
|
|
||||||
padding: 0;
|
padding: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
body {
|
body {
|
||||||
background-image: url(assets/santa.png);
|
background-image: url(assets/santa.png);
|
||||||
background-position: bottom right;
|
background-position: bottom right;
|
||||||
background-repeat: no-repeat;
|
background-repeat: no-repeat;
|
||||||
|
|
||||||
font-family: 'Comic Sans MS';
|
font-family: 'Comic Sans MS';
|
||||||
}
|
}
|
||||||
|
|
||||||
.main {
|
.main {
|
||||||
display: flex;
|
display: flex;
|
||||||
}
|
}
|
||||||
|
|
||||||
.content {
|
.content {
|
||||||
margin: auto;
|
margin: auto;
|
||||||
|
|
||||||
text-align: center;
|
text-align: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
.title {
|
.title {
|
||||||
font-size: 30px;
|
font-size: 30px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.pairing {
|
.pairing {
|
||||||
font-size: 90px;
|
font-size: 90px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.affiliate {
|
.affiliate {
|
||||||
display: block;
|
display: block;
|
||||||
box-sizing: content-box;
|
box-sizing: content-box;
|
||||||
|
|
||||||
margin-top: 70px;
|
margin-top: 70px;
|
||||||
|
|
||||||
border: 10px solid #0CB50C;
|
border: 10px solid #0CB50C;
|
||||||
border-radius: 10px;
|
border-radius: 10px;
|
||||||
|
|
||||||
background: rgba(255, 255, 255, .7);
|
background: rgba(255, 255, 255, .7);
|
||||||
}
|
}
|
||||||
|
|
||||||
.affiliate + .affiliate {
|
.affiliate + .affiliate {
|
||||||
margin-top: 40px;
|
margin-top: 40px;
|
||||||
}
|
}
|
||||||
|
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<script>1
|
<script>1
|
||||||
|
|
||||||
var queryString = _.chain( location.search.slice( 1 ).split( /&/g ) )
|
var queryString = _.chain( location.search.slice( 1 ).split( /&/g ) )
|
||||||
.map( function ( item ) { if ( item ) return item.split( /=/ ).map( function ( str ) { return decodeURIComponent( str ); } ); } )
|
.map( function ( item ) { if ( item ) return item.split( /=/ ).map( function ( str ) { return decodeURIComponent( str ); } ); } )
|
||||||
.compact().object().value();
|
.compact().object().value();
|
||||||
|
|
||||||
var name = queryString.name;
|
var name = queryString.name;
|
||||||
var pairing = CryptoJS.AES.decrypt( queryString.pairing, queryString.key ).toString(CryptoJS.enc.Utf8);
|
var pairing = CryptoJS.AES.decrypt( queryString.pairing, queryString.key ).toString(CryptoJS.enc.Utf8);
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
<div class="main">
|
<div class="main">
|
||||||
|
|
||||||
<div class="content">
|
<div class="content">
|
||||||
<h3 class="title">Hi <script>document.write(name)</script>! You've been paired with</h3>
|
<h3 class="title">Hi <script>document.write(name)</script>! You've been paired with</h3>
|
||||||
<h1 class="pairing"><script>document.write(pairing)</script></h1>
|
<h1 class="pairing"><script>document.write(pairing)</script></h1>
|
||||||
<h3 class="title">Good luck!</h3>
|
<h3 class="title">Good luck!</h3>
|
||||||
<iframe class="affiliate" src="http://rcm-eu.amazon-adsystem.com/e/cm?t=secrsant02e-21&o=8&p=48&l=ur1&category=jeuxetjouets&banner=0HS03ACZ89HPK7F4F5G2&f=ifr" width="728" height="90" scrolling="no" border="0" marginwidth="0" frameborder="0"></iframe>
|
<iframe class="affiliate" src="http://rcm-eu.amazon-adsystem.com/e/cm?t=secrsant02e-21&o=8&p=48&l=ur1&category=jeuxetjouets&banner=0HS03ACZ89HPK7F4F5G2&f=ifr" width="728" height="90" scrolling="no" border="0" marginwidth="0" frameborder="0"></iframe>
|
||||||
<iframe class="affiliate" src="http://rcm-eu.amazon-adsystem.com/e/cm?t=secrsant02e-21&o=8&p=48&l=ur1&category=books&banner=10DQAXJ7D1D2VTXMR682&f=ifr" width="728" height="90" scrolling="no" border="0" marginwidth="0" frameborder="0"></iframe>
|
<iframe class="affiliate" src="http://rcm-eu.amazon-adsystem.com/e/cm?t=secrsant02e-21&o=8&p=48&l=ur1&category=books&banner=10DQAXJ7D1D2VTXMR682&f=ifr" width="728" height="90" scrolling="no" border="0" marginwidth="0" frameborder="0"></iframe>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
|
|
Loading…
Reference in a new issue