<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
</body>
</html>
function onMouseDown(event) {
event.preventDefault();
container.addEventListener('mousemove', onMouseMove, false);
container.addEventListener('mouseup', onMouseUp);
// clear previous path
clearPathPoints();
if (event.shiftKey) {
container.style.cursor = 'move';
selecting = true;
startMouse.x = event.clientX;
startMouse.y = event.clientY;
addPathPoints(startMouse.x, startMouse.y);
var x1 = startMouse.x;
var x2 = x1 + 1;
var y1 = startMouse.y;
var y2 = y1 + 1;
selectionDiv.style.left = x1 + "px";
selectionDiv.style.top = y1 + "px";
selectionDiv.style.width = (x2 - x1) + "px";
selectionDiv.style.height = (y2 - y1) + "px";
selectionDiv.style.visibility = "hidden";
} else {
// irrelevant
}
}
function onMouseMove(event) {
if (event.shiftKey) {
selectionFlag = true;
selectionDiv.style.visibility = "visible";
mouse.x = event.clientX;
mouse.y = event.clientY;
var x1 = startMouse.x;
var x2 = mouse.x;
var y1 = startMouse.y;
var y2 = mouse.y;
if (x1 > x2) {
var tmp1 = x1;
x1 = x2;
x2 = tmp1;
}
if (y1 > y2) {
var tmp2 = y1;
y1 = y2;
y2 = tmp2;
}
selectionDiv.style.left = x1 + "px";
selectionDiv.style.top = y1 + "px";
selectionDiv.style.width = (x2 - x1) + "px";
selectionDiv.style.height = (y2 - y1) + "px";
addPathPoints(x2,y2);
} else if (moving) {
// irrelevant
}
}
function onMouseUp(event) {
container.removeEventListener('mousemove', onMouseMove, false);
container.style.cursor = 'auto';
selectionDiv.style.visibility = "hidden";
selecting = false;
moving = false;
if (selectionFlag) {
var shape = getPlaneGeometry(getPathPoints());
var selections = getSelectionsFromShape(shape);
if (selections.length !== 0) {
for (var i in selections) {
highlightSelected(selections[i]);
}
}
}
}
function getPlaneGeometry(points) {
// FIXME it selects BUT seems like not fully correct.
console.log(points);
var startX = points[0].x;
var startY = points[0].y;
var endX = points[points.length-1].x;
var endY = points[points.length-1].y;
var rx1 = (startX / window.innerWidth) * 2 - 1;
var rx2 = (endX / window.innerWidth) * 2 - 1;
var ry1 = -(startY / window.innerHeight) * 2 + 1;
var ry2 = -(endY / window.innerHeight) * 2 + 1;
console.log(rx1+"-"+rx2+"-"+ry1+"-"+ry2);
var projectionMatrix = new THREE.Matrix4();
projectionMatrix.makePerspective( rx1, rx2, ry1, ry2, camera.near, camera.far );
camera.updateMatrix(); // make sure camera's local matrix is updated
camera.updateMatrixWorld(); // make sure plane's world matrix is updated
camera.matrixWorldInverse.getInverse( camera.matrixWorld );
var viewProjectionMatrix = new THREE.Matrix4();
viewProjectionMatrix.multiplyMatrices( projectionMatrix, camera.matrixWorldInverse );
var frustum = new THREE.Frustum();
frustum.setFromMatrix(viewProjectionMatrix);
return frustum;
}
function getSelectionsFromShape(frustum) {
var meshes = [];
for ( var i in globeBars) {
var mesh = globeBars[i];
if (frustum.intersectsObject(mesh)) {
meshes.push(mesh);
}
}
return meshes;
}
Output
You can jump to the latest bin by adding /latest
to your URL
Keyboard Shortcuts
Shortcut | Action |
---|---|
ctrl + [num] | Toggle nth panel |
ctrl + 0 | Close focused panel |
ctrl + enter | Re-render output. If console visible: run JS in console |
Ctrl + l | Clear the console |
ctrl + / | Toggle comment on selected lines |
ctrl + ] | Indents selected lines |
ctrl + [ | Unindents selected lines |
tab | Code complete & Emmet expand |
ctrl + shift + L | Beautify code in active panel |
ctrl + s | Save & lock current Bin from further changes |
ctrl + shift + s | Open the share options |
ctrl + y | Archive Bin |
Complete list of JS Bin shortcuts |
JS Bin URLs
URL | Action |
---|---|
/ | Show the full rendered output. This content will update in real time as it's updated from the /edit url. |
/edit | Edit the current bin |
/watch | Follow a Code Casting session |
/embed | Create an embeddable version of the bin |
/latest | Load the very latest bin (/latest goes in place of the revision) |
/[username]/last | View the last edited bin for this user |
/[username]/last/edit | Edit the last edited bin for this user |
/[username]/last/watch | Follow the Code Casting session for the latest bin for this user |
/quiet | Remove analytics and edit button from rendered output |
.js | Load only the JavaScript for a bin |
.css | Load only the CSS for a bin |
Except for username prefixed urls, the url may start with http://jsbin.com/abc and the url fragments can be added to the url to view it differently. |