<html ng-app="APP">
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.0/angular.min.js"></script>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body ng-controller='baseController'>
<hover-select
placeholder="Select a value"
data="myList"
model="selected"
display-field="label"
value-field="value"
on-select="onSelectFromList()"
/>
</body>
</html>
.hover-select {
font-family:Verdana;
}
.hover-select *{
margin:0;
padding:0;
}
.hover-select ul{
list-style-type:none;
/* display:none; */
}
.hover-select .trigger:hover > ul{
display:block;
}
.hover-select .trigger ul li .checkOn {
color: red !important;
width: 80px !important;
display: inline-block;
}
.hover-select .trigger ul li .check {
color: green !important;
width: 80px !important;
display: inline-block;
}
var APP = angular.module('APP' ,[]);
APP.directive('hoverSelect', function($timeout){
return {
restrict: 'E',
scope: {
placeholder: "@",
data: "=",
model: "=",
displayField: "@",
valueField: "@",
onSelect: "&"
},
replace:true,
template: "<div class='hover-select'>" +
"<div class='trigger'>" +
"<h4>{{selectedValue[displayField]}}</h4>" +
"<ul>" +
"<li ng-repeat='item in data' ng-click='selectItem(item)'>" +
"<span class='checkOn' ng-if='item.value == model'>Check </span>" +
"<span class='check' ng-if='item.value != model'>not </span>" +
"{{item[displayField]}}" +
"</li>" +
"</ul>" +
"</div>" +
"</div>",
link:function($scope, $element, $attrs){
$scope.find = function(value){
for(var i=0;i<$scope.data.length;i++){
var rec = $scope.data[i];
if(rec[$scope.valueField] === value){
return rec;
}
}
return false;
};
var found = $scope.find($scope.model);
var placeholderObj = {};
placeholderObj[$scope.displayField] = $scope.placeholder;
$scope.selectedValue = found ? found : placeholderObj;
$scope.selectItem = function(item){
$scope.selectedValue = item;
$scope.model = item[$scope.valueField];
$timeout(function(){
$scope.onSelect();
}, 50);
};
}
};
});
APP.controller('baseController', function($scope, $timeout){
$scope.onSelectFromList = function(){
alert("VALUE TO SAVE: " + $scope.selected);
};
$scope.selected = 3;
$scope.myList = [
{ value: 1,label: "Item 1", year: "year 1" },
{ value: 2,label: "Item 2", year: "year 2" },
{ value: 3,label: "Item 3", year: "year 3" },
{ value: 4,label: "Item 4", year: "year 4" },
{ value: 5,label: "Item 5", year: "year 5" }
];
});
Output
300px
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. |