xonecas.io
1361
Xc

xonecas.com / commit 6811fee

new, and always more new

sean2012-02-06 6811fee92a03b6a909661cd06c19714f13068368 parent 2b6df60

7 files changed

htdocs/css/style.css+7−63
@@ -161,79 +161,23 @@ html, body {
161161 font-family: Helvetica, "Helvetica Neue", Arial, "DejaVu Sans", sans-serif;
162162 }
163163
164-small {
165- color: #666;
166-}
167-
168-pre, code {
164+pre {
169165 font-size: smaller;
170166 padding: 4px;
171- background: #efefef;
172- -webkit-border-radius: 6px; /* Saf3-4, iOS 1-3.2, Android ≤1.6 */
173- -moz-border-radius: 6px; /* FF1-3.6 */
174- border-radius: 6px; /* Opera 10.5, IE9, Saf5, Chrome, FF4, iOS 4, Android 2.1+ */
167+ border-left: 5px solid #eff6ff;
175168 }
176169
177170 a {
178- color: #323230;
179- background: #f0db4e;
180- padding: 2px;
181- -webkit-border-radius: 4px; /* Saf3-4, iOS 1-3.2, Android ≤1.6 */
182- -moz-border-radius: 4px; /* FF1-3.6 */
183- border-radius: 4px; /* Opera 10.5, IE9, Saf5, Chrome, FF4, iOS 4, Android 2.1+ */
171+ color: #91ceed;
184172 text-decoration: none;
185173 }
186174 a:active, a:visited {
187- color: #666;
175+ color: #6caee8;
188176 }
189177 a:hover {
190- color: #000;
178+ color: #2072d6;
191179 }
192180
193-.name {
194- color: #fff;
195- margin: 0;
196- padding: 20px;
197-}
198-
199-.header-background {
200- height: 60px;
201- margin-bottom: 20px;
202-
203- background-color: #333333;
204- background-image: -webkit-gradient(linear, left top, left bottom, from(#333333), to()); /* Saf4+, Chrome */
205- background-image: -webkit-linear-gradient(top, #333333, #000000); /* Chrome 10+, Saf5.1+, iOS 5+ */
206- background-image: -moz-linear-gradient(top, #333333, #000000); /* FF3.6 */
207- background-image: -ms-linear-gradient(top, #333333, #000000); /* IE10 */
208- background-image: -o-linear-gradient(top, #333333, #000000); /* Opera 11.10+ */
209- background-image: linear-gradient(to bottom, #333333, #000000);
210-
211- -webkit-box-shadow: 0 4px 2px #ccc; /* Saf3-4, iOS 4.0.2 - 4.2, Android 2.3+ */
212- -moz-box-shadow: 0 4px 2px #ccc; /* FF3.5 - 3.6 */
213- box-shadow: 0 4px 2px #ccc; /* Opera 10.5, IE9, FF4+, Chrome 6+, iOS 5 */
214-}
215-
216-.title {
217- text-transform: uppercase;
218- margin-top: 0;
219- margin-bottom: 20px;
220-}
221-
222-.banner {
223- padding: 20px;
224- margin: 40px 0;
225- background: #efefef;
226-
227- -webkit-border-radius: 12px; /* Saf3-4, iOS 1-3.2, Android ≤1.6 */
228- -moz-border-radius: 12px; /* FF1-3.6 */
229- border-radius: 12px; /* Opera 10.5, IE9, Saf5, Chrome, FF4, iOS 4, Android 2.1+ */
230-}
231-
232-.preview > div {
233- margin-bottom: 20px;
234-}
235-
236-.timestamp {
237- color: #666;
238- font-size: smaller;
181+.container {
182+ padding: 40px;
239183 }
htdocs/index.html+20−29
@@ -10,44 +10,35 @@
1010 <link rel="stylesheet" href="css/style.css">
1111 </head>
1212 <body>
13-
14- <header class="header-background">
15- <h3 class="name">Sean Caetano Martin <small>xonecas</small></h3>
16- </header>
17-
18- <section id="main" class="container">
19- <div class="banner">
20- </div>
21-
22- <div class="previews row">
23- </div>
24- </section>
25-
26- <!--[if lt IE 9]> <script src="js/html5shiv.js"></script> <![endif]-->
13+ <!-- vendor stuff -->
2714 <script src="js/underscore.js"></script>
2815 <script src="js/jquery.js"></script>
16+ <script src="js/jquery.noisy.js"></script>
17+ <script src="js/parallax.js"></script>
18+
19+ <!-- my modules -->
2920 <script src="js/tumblr-api.js"></script>
3021 <script src="js/view.js"></script>
22+
23+ <!-- startup -->
3124 <script src="js/index.js"></script>
3225
33- <script id="banner-tmpl" type="text/template">
34- <h1 class="title"><%= title %></h1>
35- <h2><%= description %></h2>
26+ <script id="index-tmpl" type="text/template">
27+ <h1><%= title %></h1>
28+ <h3><%= description %></h3>
29+ <ul>
30+ <% _.each(posts, function (post, idx) { %>
31+ <li><a href="#" id="<%= post.id %>" class="navigation">
32+ <%= post.title %> &rarr;
33+ </a></li>
34+ <% }); %>
35+ </ul>
3636 </script>
3737
38- <script id="preview-tmpl" type="text/template">
39- <h3><a href="#" class="preview-title" data-id="<%= id %>"><%= title %></a></h3>
38+ <script id="page-tmpl" type="text/template">
39+ <h1><%= title %></h1>
4040 <div><%= body %></div>
41- <time class="timestamp"><%= date %></time>
42- </script>
43-
44- <script id="post-tmpl" type="text/template">
45- <a href="#" class="back push-right">Back</a>
46- <h2><%= title %></h2>
47- <div><%= body %></div>
48- <time class="timestamp"><%= date %></time>
49-
50- <p><a href="#" class="back">Back</a></p>
41+ <a href="#" class="back">&larr; Back</a>
5142 </script>
5243
5344 </body>
htdocs/js/html5shiv.js+0−82
@@ -1,82 +0,0 @@
1-/*! HTML5 Shiv v3 | @jon_neal @afarkas @rem | MIT/GPL2 Licensed */
2-(function (win, doc) {
3- // feature detection: whether the browser supports unknown elements
4- var supportsUnknownElements = (function (a) {
5- a.innerHTML = '<x-element></x-element>';
6- return a.childNodes.length === 1;
7- })(doc.createElement('a'));
8-
9- // feature detection: whether the browser supports default html5 styles
10- var supportsHtml5Styles = (function (nav, docEl, compStyle) {
11- docEl.appendChild(nav);
12- return (compStyle = (compStyle ? compStyle(nav) : nav.currentStyle).display) && docEl.removeChild(nav) && compStyle === 'block';
13- })(doc.createElement('nav'), doc.documentElement, win.getComputedStyle);
14-
15- // html5 global so that more elements can be shived and also so that existing shiving can be detected on iframes
16- // more elements can be added and shived with the following code: html5.elements.push('element-name'); shivDocument(document);
17- var html5 = {
18- // a list of html5 elements
19- elements: 'abbr article aside audio bdi canvas data datalist details figcaption figure footer header hgroup mark meter nav output progress section summary time video'.split(' '),
20-
21- // the shiv function
22- shivDocument: function (scopeDocument) {
23- scopeDocument = scopeDocument || doc;
24-
25- // test if the document has already been shived
26- if (scopeDocument.documentShived) {
27- return;
28- }
29- scopeDocument.documentShived = true;
30-
31- // set local variables
32- var
33- documentCreateElement = scopeDocument.createElement,
34- documentCreateDocumentFragment = scopeDocument.createDocumentFragment,
35- documentHead = scopeDocument.getElementsByTagName('head')[0],
36- documentCreateElementReplaceFunction = function (m) {
37- documentCreateElement(m);
38- };
39-
40- // shiv for unknown elements
41- if (!supportsUnknownElements) {
42- // shiv the document
43- html5.elements.join(' ').replace(/\w+/g, documentCreateElementReplaceFunction);
44-
45- // shiv document create element function
46- scopeDocument.createElement = function (nodeName) {
47- var element = documentCreateElement(nodeName);
48- if (element.canHaveChildren){
49- html5.shivDocument(element.document);
50- }
51- return element;
52- };
53-
54- // shiv document create element function
55- scopeDocument.createDocumentFragment = function () {
56- return html5.shivDocument(documentCreateDocumentFragment());
57- };
58- }
59-
60- // shiv for default html5 styles
61- if (!supportsHtml5Styles && documentHead) {
62- var div = documentCreateElement('div');
63- div.innerHTML = ['x<style>',
64- 'article,aside,details,figcaption,figure,footer,header,hgroup,nav,section{display:block}', // Corrects block display not defined in IE6/7/8/9
65- 'audio{display:none}', // Corrects audio display not defined in IE6/7/8/9
66- 'canvas,video{display:inline-block;*display:inline;*zoom:1}', // Corrects canvas and video display not defined in IE6/7/8/9 (audio[controls] in IE7)
67- '[hidden]{display:none}audio[controls]{display:inline-block;*display:inline;*zoom:1}', // Corrects 'hidden' attribute and audio[controls] display not present in IE7/8/9
68- 'mark{background:#FF0;color:#000}', // Addresses styling not present in IE6/7/8/9
69- '</style>'].join('');
70- documentHead.insertBefore(div.lastChild, documentHead.firstChild);
71- }
72-
73- // return document (for potential chaining)
74- return scopeDocument;
75- }
76- };
77-
78- // shiv the document
79- html5.shivDocument(doc);
80-
81- win.html5 = html5;
82-})(this, document);
htdocs/js/index.js+36−76
@@ -1,87 +1,47 @@
1-/*global Tumblr:true, _:true, $:true, View:true */
1+/*global Tumblr:true, _:true, $:true, View:true, parallax: true */
22 $(function () {
33 'use strict';
44
5- var
6- // data source
7- tumblr,
8- // views
9- body,
10- banner,
11- previews,
12- post;
5+ var tumblr = new Tumblr('xonecas', 'IM11cPEsi3jxTeSNwF8BB9Z08UItXcYKiEDLTLvl5RYn6MBcMD');
6+ $('body').hide();
137
14-
15- // init
16- tumblr = new Tumblr('xonecas', 'IM11cPEsi3jxTeSNwF8BB9Z08UItXcYKiEDLTLvl5RYn6MBcMD');
17-
18- body = new View({ el: $('body') });
19- banner = new View({
20- el: $('.banner').first(),
21- template: _.template($('#banner-tmpl').html())
22- });
23- previews = new View({ el: $('.previews').first() });
24- post = new View({
25- el: $('<section id="secondary" class="container"></div>').appendTo('body'),
26- template: _.template($('#post-tmpl').html())
27- });
28-
29- // events
30- body.on('.back', 'click', function (ev) {
31- $('#secondary').fadeOut('fast', function () {
32- $('#main').fadeIn('fast');
33- });
34-
35- ev.preventDefault();
36- return false;
37- });
38-
39- previews.on('.preview-title', 'click', function (ev) {
40- tumblr.getpost(""+ $(ev.target).data('id'), { success: function (data) {
41- post.el.hide();
42- post.toHTML(data.response.posts[0]);
43- $('#main').fadeOut('fast', function () {
44- post.el.fadeIn('fast');
45- });
46- }});
47-
48- ev.preventDefault();
49- return false;
50- });
51-
52- // xhr init
53- tumblr.getinfo({
54- success: function (data) {
55- banner.toHTML(data.response.blog);
56- tumblr.getavatar({
57- size: 96,
58- success: function (avatarurl) {
59- banner.el.prepend('<img class="push-right" src="'+ avatarurl +'">');
60- }
61- });
62- }
63- });
64-
65- tumblr.getpost(12, {
8+ tumblr.getpost(20, {
669 type: 'text',
6710 success: function (data) {
68- var posts = data.response.posts.reverse(),
69- len = posts.length,
70- post, prev;
71-
72- previews.items = [];
73-
74- while (len--) {
75- post = posts[len];
11+ var _posts = data.response.posts,
12+ info = data.response.blog,
13+ pageTemplate = _.template($('#page-tmpl').html()),
14+ index;
15+
16+ index = new View({
17+ el: $('<section id="index" class="container"></section>')
18+ .prependTo('body'),
19+ template: _.template($('#index-tmpl').html())
20+ }).toHTML(_.extend(info, { posts: _posts }));
21+ parallax.add(index.el);
22+ index.on('.navigation', 'click', function (ev) {
23+ parallax[ev.target.id].right();
24+ ev.preventDefault();
25+ return false;
26+ });
7627
77- prev = $('<div></div>').html(post.body);
78- post.body = prev.children().slice(0, 3).html() +' ... ';
28+ _.each(_posts, function (post, idx) {
29+ var page = new View({
30+ el: $('<section class="container"></section>').prependTo('body'),
31+ template: pageTemplate
32+ }).toHTML(post);
33+
34+ page.el.attr('id', post.id);
35+ parallax.add(page.el);
36+ page.on('.back', 'click', function (ev) {
37+ parallax.index.left();
38+ ev.preventDefault();
39+ return false;
40+ });
41+ });
7942
80- previews.items.push(new View({
81- el: $('<div class="preview span-one-third"></div>').appendTo('.previews'),
82- template: _.template($('#preview-tmpl').html())
83- }).toHTML(post));
84- }
43+ $('body').noisy().css('background-color', '#eff6ff').show();
44+ parallax.index.show();
8545 }
8646 });
8747
htdocs/js/jquery.noisy.js+90−0
@@ -0,0 +1,90 @@
1+(function($){
2+ // This function adds noise to the background-image attribute of a given element
3+ $.fn.noisy = function(options) {
4+ options = $.extend({}, $.fn.noisy.defaults, options);
5+ var uri, localStorageSupported, cachedUri = false;
6+
7+ try {
8+ localStorageSupported = 'localStorage' in window && window['localStorage'] !== null;
9+ } catch (err) {
10+ localStorageSupported = false;
11+ }
12+
13+ if (window.JSON && localStorageSupported) {
14+ cachedUri = localStorage.getItem(window.JSON.stringify(options));
15+ }
16+
17+ // Use localStorage cache if these options have been used before
18+ if (cachedUri) {
19+ uri = cachedUri;
20+ }
21+ else {
22+ var canvas = document.createElement('canvas');
23+
24+ // Use fallback image if canvas isn't supported
25+ if (!canvas.getContext) {
26+ uri = options.fallback;
27+ }
28+ else {
29+ canvas.width = canvas.height = options.size;
30+
31+ var ctx = canvas.getContext('2d'),
32+ imgData = ctx.createImageData(canvas.width, canvas.height),
33+ numPixels = options.intensity * Math.pow(options.size, 2),
34+ maxAlpha = 255 * options.opacity;
35+
36+ // Add color to random pixels in the canvas
37+ while (numPixels--) { // Read about the double bitwise NOT trick here: goo.gl/6DPpt
38+ var x = ~~(Math.random()*canvas.width),
39+ y = ~~(Math.random()*canvas.height),
40+ index = (x + y * imgData.width) * 4;
41+
42+ var colorChannel = numPixels % 255; // This will look random enough
43+ imgData.data[index ] = colorChannel; // red
44+ imgData.data[index+1] = options.monochrome ? colorChannel : ~~(Math.random()*255); // green
45+ imgData.data[index+2] = options.monochrome ? colorChannel : ~~(Math.random()*255); // blue
46+ imgData.data[index+3] = ~~(Math.random()*maxAlpha); // alpha
47+ }
48+
49+ ctx.putImageData(imgData, 0, 0);
50+ uri = canvas.toDataURL('image/png');
51+
52+ // In IE < 9 Data URI's are only displayed if they are < 32KB
53+ // Though IE < 9 doesn't officially support the canvas element,
54+ // certain scripts like excanvas.js will enable it and if the URI is > 32KB it won't be displayed
55+ if (uri.indexOf('data:image/png') != 0 || // toDataURL doesn't return anything in Android 2.2
56+ $.browser.msie &&
57+ $.browser.version.substr(0,1) < 9 &&
58+ uri.length > 32768) {
59+ uri = options.fallback;
60+ }
61+ }
62+
63+ if (window.JSON && localStorageSupported) {
64+ localStorage.setItem(window.JSON.stringify(options), uri);
65+ }
66+ }
67+
68+ return this.each(function() {
69+ $(this).css('background-image', "url('" + uri + "')," + $(this).css('background-image'));
70+ });
71+ };
72+ $.fn.noisy.defaults = {
73+ // How many percent of the image that is filled with noise,
74+ // represented by a number between 0 and 1 inclusive
75+ intensity: 0.9,
76+
77+ // The width and height of the image in pixels
78+ size: 200,
79+
80+ // The maximum noise particle opacity,
81+ // represented by a number between 0 and 1 inclusive
82+ opacity: 0.08,
83+
84+ // A string linking to the image used if there's no canvas support
85+ fallback: '',
86+
87+ // Specifies wheter the particles are grayscale or colorful
88+ monochrome: false
89+ };
90+})(jQuery);
htdocs/js/parallax.js+167−0
@@ -0,0 +1,167 @@
1+window.onload = function(){
2+ if (typeof jQuery === 'undefined') {
3+ alert("ERROR: parallax.js requires jQuery.");
4+ } else {
5+ var updateparallax = function(){
6+ parallax.width = window.innerWidth;
7+ parallax.height = window.innerHeight;
8+ }
9+ updateparallax();
10+ $(window).resize(function(){updateparallax();});
11+ }
12+}
13+
14+var parallaxPage = function(name, htmlObject){
15+ return{
16+ key: name,
17+ page : htmlObject,
18+
19+ right : function(callback){return this.transition({left:parallax.width,top:0} ,{left:-parallax.width,top:0} ,callback);},
20+ left : function(callback){return this.transition({left:-parallax.width,top:0} ,{left:parallax.width,top:0} ,callback);},
21+ top : function(callback){return this.transition({left:0,top:-parallax.height},{left:0,top:parallax.height} ,callback);},
22+ bottom : function(callback){return this.transition({left:0,top:parallax.height} ,{left:0,top:-parallax.height},callback);},
23+
24+ transition : function(locationNew, locationOld, callback){
25+ if(!parallax.sliding){
26+ parallax.sliding = true;
27+ var thisPage = this;
28+ if(parallax.current !== this){
29+ this.hide(locationNew);
30+ if(typeof parallax.preload === 'function'){ parallax.preload(); }
31+ if(typeof this.preload === 'function'){ this.preload(); }
32+ this.slide({left:0,top:0}, function(){
33+ thisPage.makeCurrent();
34+ if(typeof callback === 'function'){ callback(); }
35+ });
36+ if(typeof parallax.current !== 'undefined'){
37+ parallax.current.slide(
38+ locationOld,
39+ function(){parallax.sliding = false;}
40+ );
41+ }
42+ parallax.slideBackground(locationNew);
43+ }
44+ }
45+ return this;
46+ },
47+
48+ slide : function(css, callback){
49+ this.page.css("display", "block");
50+ this.page.stop().animate(css, parallax.speed, parallax.easing,
51+ function(){if(typeof callback === "function"){callback();}
52+ });
53+ },
54+
55+ hide : function(newLocation){
56+ newLocation = newLocation || {left:parallax.width,top:0}; //defaults left off screen
57+ this.page.css("display", "none");
58+ this.page.css(newLocation);
59+ return this;
60+ },
61+
62+ show : function(newLocation){
63+ newLocation = newLocation || {left:0,top:0}; //defaults on screen
64+ if(typeof parallax.current !== 'undefined'){
65+ parallax.current.hide();
66+ }
67+ this.makeCurrent();
68+ this.page.css("display", "block");
69+ this.page.css(newLocation);
70+ return this;
71+ },
72+
73+ makeCurrent : function(){
74+ if(this === parallax.current){
75+ return false;
76+ }else{
77+ if(typeof parallax.current !== 'undefined'){
78+ parallax.current.hide();
79+ parallax.last = parallax.current;
80+ }
81+ if(parallax.updateUrl === true){ this.updateUrl(); }
82+ if(typeof parallax.onload == 'function'){ parallax.onload();}
83+ if(typeof this.onload === 'function'){ this.onload();}
84+ parallax.current = this;
85+ }
86+ return true;
87+ },
88+
89+ updateUrl : function(){
90+ var url = document.URL;
91+ url = (url.lastIndexOf("#") === -1)? url : url.substring(0, url.lastIndexOf("#"));
92+ window.location.href = url + "#" + this.key;
93+ },
94+
95+ ackbar : function(){ alert(this.key + " thinks it's a trap!"); return this;},
96+ };
97+};
98+
99+
100+var parallax = {
101+
102+ speed : 800,
103+ easing : 'swing',
104+ sliding : false,
105+ unusableNames : ["last", "current", "background","onload","updateUrl", "preload"],
106+ scaling : 0.15,
107+
108+ add : function(key,object) {
109+ var check = true;
110+ if(typeof key === 'object'){
111+ try{
112+ object = key
113+ key = key.attr('id');
114+ } catch(err){
115+ check = false;
116+ alert("ERROR:Page object lacks an id");
117+ }
118+ }else if(typeof key !== 'string'){
119+ check = false;
120+ alert("ERROR:undefined key");
121+ }
122+
123+ if(typeof object !== 'object'){
124+ check = false;
125+ alert("ERROR:undefined page");
126+ }
127+
128+ if(check){
129+ validKeyName = true;
130+ for(propName in this){
131+ if(propName === key) {
132+ validKeyName = false;
133+ }
134+ }
135+ if($.inArray(key, this.unusableNames) !== -1){
136+ validKeyName = false;
137+ }
138+ if(validKeyName){
139+ this[key] = parallaxPage(key,object);
140+ this[key].hide();
141+ this[key].page.css("position","absolute");
142+ }else{
143+ alert("ERROR:'"+key+"' cannot be used as a page identifier");
144+ }
145+ }
146+ return this;
147+ },
148+
149+ fromUrl : function(){
150+ var temp = document.URL.lastIndexOf("#")
151+ if(temp !== -1){
152+ pageName = document.URL.substring(temp + 1, document.URL.length);
153+ if(parallax.hasOwnProperty(pageName)){
154+ return parallax[pageName];
155+ }
156+ }
157+ },
158+
159+ slideBackground : function(newLocation){
160+ if(typeof this.background !== 'undefined' && typeof newLocation !== 'undefined'){
161+ $(this.background).animate({
162+ 'background-position-x': '+=' + -newLocation.left * parallax.scaling + 'px',
163+ 'background-position-y': '+=' + -newLocation.top * parallax.scaling + 'px',
164+ }, parallax.speed, parallax.easing);
165+ }
166+ },
167+};
htdocs/js/tumblr-api.js+0−5
@@ -100,11 +100,6 @@ var Tumblr = (function (win, doc, undefined) {
100100 }
101101 };
102102
103- if (typeof define === 'function') {
104- // it depends on jquery and underscore, not quite sure how to reflect this atm.
105- define('Tumblr', [], function () { return Tumblr; });
106- }
107-
108103 return (win.Tumblr = Tumblr);
109104
110105 }) (this, document);