Skip to content

Commit

Permalink
demo2
Browse files Browse the repository at this point in the history
  • Loading branch information
andregoncalves committed Dec 4, 2009
1 parent 5557c27 commit a30bf06
Show file tree
Hide file tree
Showing 6 changed files with 143 additions and 0 deletions.
39 changes: 39 additions & 0 deletions assets/javascripts/cymain.js
@@ -0,0 +1,39 @@
var Cyclops = {

init:function() {
this.eventStorage = {};
pubsub.subscribe('/record/start', this, "startRecording");
pubsub.subscribe('/record/stop', this, "stopRecording");
},

startRecording: function(e) {
$(document).bind('mousemove', this.storeEvent);
},

stopRecording: function(e) {
$(document).unbind('mousemove', this.storeEvent);
},

storeEvent: function(e) {
this.eventStorage.push(e);
this.sendEvent(e);
},

sendEvent: function(e) {
ev = this['getEvent_'+e.type](e);

$.post('/publish?id=demo2', ev.serialize(), function(data, textStatus) {
if (textStatus != "success")
console.info("failed posting! " + stextStatus);
});
},

getEvent_mousemove: function(e) {
event = new CyEvent("mousemove", { x:e.pageX, y:e.pageY });
return event;
},

playEvent_mousemove: function(e) {
$("#mouse").css('top', e.x).css('left', e.y);
}
}
13 changes: 13 additions & 0 deletions assets/javascripts/cynotify.js
@@ -0,0 +1,13 @@
var CyNotify = {
subscribe: function(eventname) {
pubsub.subscribe(eventname, this, "notify");
},

unsubscribe: function(eventname) {

},

notify: function(e,msg) {
$.jGrowl(msg);
}
}
52 changes: 52 additions & 0 deletions assets/javascripts/demo2.js
@@ -0,0 +1,52 @@


$(document).ready(function() {
window.pubsub = new PubSub('/record/start', '/record/stop');
CyNotify.subscribe('/record/start');
CyNotify.subscribe('/record/stop');


/*e = new CyEvent("mousemove", { x:10, y:20});
s = e.serialize();
e = JSON.parse(s);*/



});

$(window).load(function() {
Cyclops.init();

$(document).bind('keydown', 'Ctrl+r', function(e) {
pubsub.publish('/record/start', e, 'recording started');
});

$(document).bind('keydown', 'Ctrl+s', function(e) {
pubsub.publish('/record/stop', e, 'recording stopped');
});

/* $('img').click(function(e) {
console.info(e);
console.info("click on image");
})
$("#a").click(function() {
simulateClick();
});
$(document).click(function() {
console.info("click on document");
});*/

});

/*
function simulateClick() {
var evt = document.createEvent("MouseEvents");
evt.initMouseEvent("click", true, true, window,
0, 0, 0, 0, 0, false, false, false, false, 0, null);
var element = document.elementFromPoint(16, 109);
//document.getElementById('body').dispatchEvent(evt);
element.dispatchEvent(evt);
}
*/
9 changes: 9 additions & 0 deletions assets/javascripts/event.js
@@ -0,0 +1,9 @@
function CyEvent(type, data) {
this.type = type;
this.data = data;
}

CyEvent.prototype.serialize = function() {

return JSON.stringify(this);
}
Empty file added assets/stylesheets/master.css
Empty file.
30 changes: 30 additions & 0 deletions demo2/demo2.html
@@ -0,0 +1,30 @@
<!DOCTYPE html>
<html>
<head>
<title>Cyclops Demo 2</title>
<meta name="description" content="" />
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<link rel="stylesheet" href="../assets/stylesheets/master.css" type="text/css" media="screen" charset="utf-8">
<link rel="stylesheet" href="../assets/stylesheets/jquery.jgrowl.css" type="text/css" media="screen" charset="utf-8">
</head>
<body id="body">
<header class="clearfix">
<h1>Proof of Concept 2</h1>
</header>
<div id="main">
<button id="a">Click me</button>
</div>
<footer>
</footer>
<img src="../assets/images/cursor.png" id="mouse" style="position:absolute" />
<script src="../assets/javascripts/jquery.js" type="text/javascript" charset="utf-8"></script>
<script src="../assets/javascripts/demo2.js" type="text/javascript" charset="utf-8"></script>
<script src="../assets/javascripts/json2.js" type="text/javascript" charset="utf-8"></script>
<script src="../assets/javascripts/pubsub.js" type="text/javascript" charset="utf-8"></script>
<script src="../assets/javascripts/event.js" type="text/javascript" charset="utf-8"></script>
<script src="../assets/javascripts/cymain.js" type="text/javascript" charset="utf-8"></script>
<script src="../assets/javascripts/cynotify.js" type="text/javascript" charset="utf-8"></script>
<script src="../assets/javascripts/jquery.hotkeys.js" type="text/javascript" charset="utf-8"></script>
<script src="../assets/javascripts/jquery.jgrowl.js" type="text/javascript" charset="utf-8"></script>
</body>
</html>

0 comments on commit a30bf06

Please sign in to comment.