<html ng-app="app">
<head>
<meta charset="utf-8" />
<title>AngularJS Plunker</title>
<script>document.write('<base href="' + document.location + '" />');</script>
<link rel="stylesheet" href="style.css" />
<script src="https://code.angularjs.org/1.3.2/angular.js"></script>
</head>
<body>
<div ng-init="d1.click = 0" on-deselect="d1.click = d1.click + 1">
<h1>DIV 1 <i>(clicks outside: {{ d1.click }})</i></h1>
<button>Click</button>
</div>
<div ng-init="d2.click = 0" on-deselect="d2.click = d2.click + 1">
<h1>DIV 2 <i>(clicks outside: {{ d2.click }})</i></h1>
<button>click</button>
</div>
</body>
</html>
body {
text-align: center;
}
button {
padding: 5px;
font-size: 20px;
}
div {
padding: 20px;
margin: 20px;
outline: 4px solid gray;
}
div:nth-child(1) {
color: red;
background-color: lightgreen;
}
div:nth-child(2) {
color: white;
background-color: red
}
var app = angular.module('app', []);
app.directive('onDeselect', [ '$document', function($document) {
return {
scope: { onDeselect: '&' },
link: function(scope, element, attrs) {
var clickHandler = function(e) {
var target = e.target;
while (target) {
if (element[0] === target) return;
target = target.parentElement;
}
scope.$apply(function() {
scope.onDeselect({$event:e});
});
};
$document.on('click', clickHandler);
// clean handler on destroy
scope.$on('$destroy', function() {
$document.off('click', clickHandler);
});
}
};
}]);
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. |