oxjs/demos/mouse/js/mouse.js

65 lines
2.1 KiB
JavaScript
Raw Normal View History

2011-05-05 18:02:56 +00:00
Ox.load('UI', {
debug: true
}, function() {
2011-04-20 17:00:56 +00:00
var $target = Ox.Element()
.css({
position: 'absolute',
width: '256px',
top: 0,
bottom: 0,
background: 'rgb(255, 0, 0)'
})
.html('Click here')
.appendTo(Ox.UI.$body),
$clear = Ox.Element()
.css({
position: 'absolute',
left: '256px',
right: 0,
height: '16px',
background: 'rgb(192, 192, 192)'
})
.html('Clear log')
.click(function() {
$log.empty();
})
.appendTo(Ox.UI.$body);
$log = Ox.Element()
.css({
position: 'absolute',
left: '256px',
right: 0,
top: '16px',
bottom: 0,
overflowY: 'auto'
})
.appendTo(Ox.UI.$body);
[
'anyclick', 'singleclick', 'doubleclick', 'mousedown', 'mouserepeat',
2011-09-03 23:04:18 +00:00
'dragstart', 'drag', 'dragenter', 'dragleave', 'dragpause', 'dragend'
2011-04-20 17:00:56 +00:00
].forEach(function(event) {
2011-05-05 18:02:56 +00:00
$target.bindEvent(event, function(e) {
2011-04-20 17:00:56 +00:00
var date = new Date();
$('<div>')
.html(
Ox.formatDate(date, '%H:%M:%S') + '.' + (Ox.pad(date % 1000, 3)) +
' <span style="font-weight: bold">' + event + '</span> ' +
JSON.stringify(
Ox.extend(e.clientX ? {
clientX: e.clientX,
clientY: e.clientY,
} : {}, e.clientDX ? {
clientDX: e.clientDX,
clientDY: e.clientDY
} : {})
)
.replace(/"/g, '')
.replace(/:/g, ': ')
.replace(/,/g, ', ')
2011-04-20 17:00:56 +00:00
)
.prependTo($log.$element);
2011-04-20 17:40:09 +00:00
event == 'anyclick' && Ox.print(e);
2011-04-20 17:00:56 +00:00
});
});
2011-04-22 23:07:55 +00:00
});