gun/examples/social/index.html
2014-09-09 02:05:13 -06:00

135 lines
3.9 KiB
HTML

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<h1>Social Network</h1>
<form name="sign">
<input name="email" placeholder="email">
<input name="password" type="password" placeholder="password">
<input type="submit" name="it" value="sign in or up">
</form>
<script src="../../deps/jquery.js"></script>
<script src="../../../as/as.js"></script>
<script src="../../gun.js"></script>
<script>
$(function(){
$.as($.as('sign'));
var social = {};
social.server = 'http://localhost:8888/';
gun = Gun(social.server + 'gun');
$.as('sign.email').on('keyup', function(e){
e.val = $(this).val();
if(!e || !e.val || $(this).data('val') == e.val){ return }
$(this).data('val', e.val);
$.post(social.server + 'sign', JSON.stringify({email: e.val}), function(reply){
console.log(reply);
if(!reply){ return }
$.as('sign.it').val(reply.err || reply.ok);
},'json');
});
$('form').on('submit', function(e){
e.preventDefault(); e.stopPropagation();
var auth = {
email: $.as('sign.email').val()
,password: $.as('sign.password').val()
}
if(!auth.email){
return $.as('sign.email').val("No email!");
}
if(!auth.password){
return $.as('sign.password').val("No password!");
}
$.post(social.server + 'sign', JSON.stringify(auth), function(reply){
if(!reply){ return }
$.as('sign.it').val(reply.err || reply.ok);
},'json');
return false;
});
});
</script>
<script>
var load = function(b,c){
var d = document,
j = "script",
s = d.createElement(j)
;
var e = 2166136261,
g = b.length,
h = c,
i = /=\?/,
w = window.setTimeout,
x,
y,
a = function(z){
document.body && (z=z||x) && s && document.body[z]? document.body[y=z](s) : w(a,0);
};
if(i.test(b)){
for(;g--;) e = e * 16777619 ^ b.charCodeAt(g);
window[j+=e<0?-e:e] = function(){
h.apply(h,arguments);
delete window[j]};
b = b.replace(i,"="+j);
c = 0
};
s.onload = s.onreadystatechange = function(){
if(y&&/de|m/.test(s.readyState||"m")){
c&&c();a(x='removeChild');try{for(c in s)delete s[c]}catch(b){}
}
};
s.src = b; c && a(x='appendChild');
}
</script>
<script>
function send(url, data){
var $ = function(t){ return document.createElement(t) },
frame = $('iframe'),
form = $('form'),
input = $("input");
form.method = "POST";
form.target = 'cb';
form.enctype = 'multipart/form-data';
form.action = url;
form.style = "display:none";
form.style.display = "none";
input.name = "d";
input.value = JSON.stringify(data);
input.type = "hidden";
form.appendChild(input);
frame.name = 'cb';
frame.src = 'javascript:false;';
frame.onload = function(){
frame.onload = function(){
console.log(frame);
return;
var doc = this.contentWindow ? this.contentWindow.document :(this.contentDocument ? this.contentDocument : this.document),
root = doc.documentElement ? doc.documentElement : doc.body,
textarea = root.getElementsByTagName("textarea")[0],
type = textarea && textarea.getAttribute("data-type") || null,
status = textarea && textarea.getAttribute("data-status") || 200,
statusText = textarea && textarea.getAttribute("data-statusText") || "OK",
content = {
html: root.innerHTML,
text: type ?
textarea.value :
root ? (root.textContent || root.innerText) : null
};
console.log(doc, root, textarea, type, status, statusText, content);
return;
cleanUp();
completeCallback(status, statusText, content, type ?("Content-Type: " + type) : null);
}
form.submit();
}
form.appendChild(frame);
document.body.appendChild(form);
}
</script>
</body>
</html>