Skip to content

Instantly share code, notes, and snippets.

@akagomez
Created March 17, 2015 18:35
Show Gist options
  • Save akagomez/47e7bbac3ecf53dd5e8e to your computer and use it in GitHub Desktop.
Save akagomez/47e7bbac3ecf53dd5e8e to your computer and use it in GitHub Desktop.
Clickable tiles in node-webkit
<html>
<head>
<style type="text/css">
body { margin: 0; padding: 0; }
div { float: left; background: #f00; }
</style>
</head>
<body>
<script type="text/javascript">
var gui = require('nw.gui');
process.on('uncaughtException', function(err) {
return false;
});
gui.Window.get().showDevTools();
var win = window.win = gui.Window.get(window);
win.on('focus', function () {
console.log('The window is focused.');
})
var w = win.width;
var h = win.height;
var d = 10;
var cw = w / d;
var ch = h / d;
for (var r = 0; r < d; r++) {
for (var c = 0; c < d; c++) {
var div = document.createElement('div');
div.style.width = cw + 'px';
div.style.height = ch + 'px';
div.id = r + 'x' + c;
div.onclick = function () {
this.style.backgroundColor = 'transparent';
}
document.getElementsByTagName('body')[0].appendChild(div);
}
}
</script>
</script>
</body>
</html>
@akagomez
Copy link
Author

This is the test used for this issue: nwjs/nw.js#3255

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment