@@ -2,11 +2,71 @@
22 /*global $: true */
33 (function () {
44 'use strict';
5+ function rrange(min, max, noFloor) {
6+ var result = Math.random() * (max - min) + min;
7+ return noFloor ? result : Math.floor(result);
8+ }
9+ function loadStyle(url, fn) {
10+ var style = document.createElement('style'),
11+ fi;
12+ style.textContent = '@import "' + url + '"';
13+ fi = setInterval(function () {
14+ try {
15+ style.sheet.cssRules; // <--- MAGIC: only populated when file is loaded
16+ fn(style);
17+ clearInterval(fi);
18+ } catch (e) {}
19+ }, 10);
20+ $('head').prepend(style);
21+ }
22+ function setNavActive() {
23+ var items = $('.nav-main li'),
24+ page = location.pathname.match(/\/[a-zA-Z0-9\.\-]+$/);
25+ if (page) {
26+ page = page[0];
27+ if (page === '/work.html') {
28+ items.last().addClass('active');
29+ } else {
30+ items.first().addClass('active');
31+ }
32+ }
33+ }
34+ function setRandomTitle() {
35+ var nouns = [ 'Functions', 'Loops', 'Bugs', 'Monkeys', 'Duck', 'String', 'Integers' ],
36+ adjs = [ 'Flying', 'Sleeping', 'Typing', 'Parsing', 'Lost', 'Delicious', 'Forgotten' ],
37+ x = rrange(1, nouns.length) - 1,
38+ y = rrange(1, adjs.length) - 1,
39+ prefix = Math.random() > 0.5 ? 'The ' : '',
40+ middle = Math.random() > 0.66666 ? ' of ' : ' ',
41+ title = Math.random() > 0.5 ?
42+ prefix + adjs[y] + ' ' + nouns[x] :
43+ prefix + nouns[x] + middle + adjs[y];
44+ $('#random-title').text(title);
45+ }
46+ function setLightSwitch(fn) {
47+ var saved = window.localStorage ? window.localStorage.getItem('colorscheme') : 'light',
48+ style = saved || 'light';
49+ function color(done) {
50+ var url = '/css/bootstrap.' + style + '.min.css';
51+ $('#colorscheme').remove();
52+ loadStyle(url, function (node) {
53+ node.id = 'colorscheme';
54+ if (done) { done(); }
55+ });
56+ }
57+ color(fn);
58+ $('#light-switch').click(function (ev) {
59+ ev.preventDefault();
60+ style = style === 'light' ? 'dark' : 'light';
61+ if (window.localStorage) { window.localStorage.setItem('colorscheme', style); }
62+ color();
63+ });
64+ }
565 // google web font, no flash of unstyled text
666 window.WebFontConfig = {
7- google: { families: ['Quantico:400,400italic,700,700italic:latin'] },
67+ google: { families: ['Quantico:400,400italic,700,700italic:latin', 'Racing+Sans+One::latin'] },
868 active: function () {
9- // font is ready, assume jquery
69+ // font is ready, dom is ready, init and display
1070 $(function () {
1171 // on your css make sure you make all the elements that us this font visibility: hidden;
1272 $('h1, .custom-font').css({ visibility: 'visible' });
@@ -22,36 +82,16 @@
2282 s = document.getElementsByTagName('script')[0];
2383 s.parentNode.insertBefore(wf, s);
2484 }());
25- function setNavActive() {
26- var items = $('.navbar .nav li'),
27- page = location.pathname.match(/\/[a-zA-Z0-9\.\-]+$/);
28- if (page) {
29- page = page[0];
30- if (page === '/work.html') {
31- items.last().addClass('active');
32- } else {
33- items.first().addClass('active');
34- }
35- }
36- }
3785 $(function () {
38- $('body').show();
39- setNavActive();
86+ setLightSwitch(function () {
87+ setNavActive();
88+ setRandomTitle();
89+ $('body').show();
90+ $('.tipped').tooltip({ placement: 'left', animation: true });
91+ $('#reload-title').click(function (ev) {
92+ ev.preventDefault();
93+ setRandomTitle();
94+ });
95+ });
4096 });
41- /* save for later
42- function loadStyle(url, fn) {
43- var style = document.createElement('style'),
44- fi;
45- style.textContent = '@import "' + url + '"';
46- fi = setInterval(function () {
47- try {
48- style.sheet.cssRules; // <--- MAGIC: only populated when file is loaded
49- fn();
50- clearInterval(fi);
51- } catch (e) {}
52- }, 10);
53-
54- $('head').prepend(style);
55- }
56- */
5797 }());