Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from LearnBoost/add/example
Fix profile route
- Loading branch information
Showing
11 changed files
with
217 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,5 @@ | ||
build/ | ||
components/ | ||
node_modules | ||
test/build | ||
test/components |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
|
||
test: | ||
cd test && make | ||
|
||
.PHONY: test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
|
||
build: index.js components | ||
@component build | ||
|
||
components: | ||
@component install | ||
|
||
clean: | ||
rm -fr build components | ||
|
||
all: | ||
clear | ||
make clean | ||
make build | ||
|
||
.PHONY: clean |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"name": "gravatar-test", | ||
"repo": "learnboost/gravatar-test", | ||
"description": "Component Gravatar Testing", | ||
"version": "0.1.0", | ||
"dependencies": { | ||
"component/jquery": "*", | ||
"learnboost/gravatar-component": "1.0.6" | ||
}, | ||
"scripts": ["index.js"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
<!DOCTYPE 5> | ||
<html> | ||
<head> | ||
<title>Gravatar component</title> | ||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> | ||
<style> | ||
body { | ||
font-family: tahoma; | ||
color: #333; | ||
} | ||
|
||
input { | ||
height: 30px; | ||
line-height: 20px; | ||
min-width: 300px; | ||
border: 1px solid #aaa; | ||
padding: 5px; | ||
} | ||
|
||
label { | ||
width: 80px; | ||
text-align: right; | ||
margin-right: 20px; | ||
display: inline-block; | ||
} | ||
|
||
body.loading input { | ||
opacity: 0.3; | ||
} | ||
|
||
.profile-placeholder, | ||
.image-placeholder { | ||
display: inline-block; | ||
vertical-align: top; | ||
background-color: #f2f2f2; | ||
width: 400px; | ||
height: 400px; | ||
border: 1px solid #eee; | ||
padding: 10px; | ||
margin: 10px; | ||
font-size: 12px; | ||
} | ||
|
||
.profile-placeholder strong { | ||
width: 320px; | ||
display: inline-block; | ||
vertical-align: top; | ||
white-space: nowrap; | ||
overflow: hidden; | ||
text-overflow: ellipsis; | ||
} | ||
|
||
body.loading .image-placeholder img { | ||
display: none; | ||
} | ||
|
||
</style> | ||
</head> | ||
<body> | ||
<h2>Gravatar component</h2> | ||
<script src="build/build.js"></script> | ||
|
||
<p> | ||
<label>Email: </label> | ||
<input name="email" type="email" value="a@gmail.com" /> | ||
</p> | ||
|
||
<p> | ||
<label>Size: </label> | ||
<input name="size" type="number" value="400" /> | ||
</p> | ||
|
||
<div class="blocks"> | ||
<div class="image-placeholder"><img scr="#" /></div> | ||
<div class="profile-placeholder"></div> | ||
</div> | ||
|
||
<script> | ||
require('gravatar-test'); | ||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
|
||
/** | ||
* Load Components | ||
*/ | ||
|
||
var o = require('jquery'); | ||
var Grt = require('gravatar'); | ||
|
||
/** | ||
* DOM elements | ||
*/ | ||
|
||
var body = o('body'); | ||
var img_ph = o('.image-placeholder'); | ||
var profile_ph = o('.profile-placeholder'); | ||
var email = o('input[name=email]').focus(); | ||
var size = o('input[name=size]'); | ||
var img; | ||
|
||
/** | ||
* Print the gratar image appending | ||
* an img element | ||
* | ||
* @param {String} email | ||
* @param {Number} s | ||
* @api private | ||
*/ | ||
|
||
function printAvatar(email, s){ | ||
if (img) img.remove(); | ||
body.addClass('loading'); | ||
|
||
img = o(Grt.img(email, { s: s || 100 })) | ||
.appendTo(img_ph) | ||
.on('load', function(){ | ||
body.removeClass('loading'); | ||
}); | ||
|
||
profile_ph.empty(); | ||
var profile = Grt.profile(email, function(err, data){ | ||
var prts = [ | ||
'displayName', | ||
'profileUrl', | ||
'id', | ||
'hash', | ||
'requestHash', | ||
'thumbnailUrl' | ||
]; | ||
|
||
for (var i = 0; i < prts.length; i++) { | ||
if (data[prts[i]]) { | ||
profile_ph.append(o('<p>').append( | ||
o('<span>', { text: prts[i] + ': ' }), | ||
o('<strong>', { text: data[prts[i]] }) | ||
)); | ||
} | ||
} | ||
}); | ||
} | ||
|
||
// input keypress event | ||
|
||
o('input') | ||
.on('keypress', function(e){ | ||
if (body.hasClass('loading')) return; | ||
if (e.keyCode == 13) printAvatar(email.val(), size.val()); | ||
}); | ||
|
||
// get initial avatar | ||
printAvatar('a@gmail.com', 400); |