Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0;">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">

<link rel="stylesheet" type="text/css" href="css/site.css">
<link href='http://fonts.googleapis.com/css?family=Source+Sans+Pro' rel='stylesheet' type='text/css'>
Expand All @@ -27,7 +27,7 @@
<section>
<h1 data-content="name" class="name"></h1>
<h2 data-content="title"></h2>
<section id="contact">
<section id="contact" data-content="contact">
</section>
</section>

Expand Down Expand Up @@ -196,7 +196,8 @@ <h1>Education</h1>
<li><a href="${link}" target="_blank">${name}</a></li>
</script>

<script type="text/javascript" src="js/jsonme.min.js"></script>
<script src="js/snack-sizzle.min.js"></script>
<script src="js/app.js"></script>
<script type="text/javascript">
snack.ready( function( ) {
window.app.loadData( );
Expand Down
84 changes: 58 additions & 26 deletions js/app.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,55 @@
window.app = ( function( window, $, snack ){
'use strict';

//From Handlebars.Utils.escapeExpression
var escape = {
'&': '&amp;',
'<': '&lt;',
'>': '&gt;',
'"': '&quot;',
'\'': '&#x27;',
'`': '&#x60;'
};
var badChars = /[&<>"'`]/g;
var possible = /[&<>"'`]/;

var escapeChar = function(chr) {
return escape[chr] || chr;
};
var escapeStr = function(string) {
if (!possible.test(string)) {
return string;
}
return string.replace(badChars, escapeChar);
};

var navHeight = 0;
var format = function(str, context) {
return str.replace(/\$\{([^{}]+)\}/g, function(match, key) {
if (context.hasOwnProperty(key)) {
return escapeStr(context[key]);
} else {
return '';
}
});
};

var remove = function(ele) {
ele.parentNode.removeChild(ele);
return ele;
};

var parseData = function( data ) {

var json = snack.parseJSON( data ),
key = null,
ele = null,
val = null,
sections = $('[data-content]'),
section = null;
var json = snack.parseJSON(data),
ele = null,
sections = $('[data-content]');

document.title = 'Resumé for ' + json.name;

$( '#contact' )[0].innerHTML = json.contact;
// $( '#contact' )[0].innerHTML = json.contact;

for( key in json ){

val = json[ key ];
ele = $( '[data-content=' + key + ']' )[ 0 ];
snack.each(json, function(val, key) {
ele = $('[data-content=' + key + ']')[0];

if( ele ){
//standard keys just populate the section
Expand All @@ -37,12 +67,10 @@ window.app = ( function( window, $, snack ){

//template found, key is a string
if( template && typeof item === 'string' ){

frag = frag + template.replace('${' + key + '}', item );
frag += template.replace(new RegExp('\\$\\{' + key + '\\}', 'g'), item);
}
else if( template && typeof item === 'object' ){

var cur = template;
var cur = format(template, item);

for( var innerKey in item ){
cur = cur.replace('${' + innerKey + '}', item[ innerKey ] );
Expand All @@ -52,23 +80,27 @@ window.app = ( function( window, $, snack ){
cur = cur.replace('<li>','<li class="last">');
}

frag = frag + cur;
frag += cur;
}
});

ele.innerHTML = frag;

//remove unused fields
snack.each($('li .content', ele), function(child) {
if (!/\w/.test(child.innerHTML)) {
remove(child.parentNode);
}
});
}
}
}
});

for( var i = 0; i < sections.length; i++ ){
section = sections[ i ];

if( !section.innerHTML.match( /\w/ ) ){

section.parentNode.style.display = 'none';
}
}
snack.each(sections, function(section) {
if (!/\w/.test(section.innerHTML)) {
remove(section.parentNode);
}
});
};

return {
Expand Down
Empty file removed js/jsonme.js
Empty file.
8 changes: 0 additions & 8 deletions js/jsonme.min.js

This file was deleted.

Loading