1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
| <!DOCTYPE html>
<html lang="fr" dir="ltr">
<head>
<meta http-equiv="cache-control" content="public, max-age=60">
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1.0">
<meta name="author" content="Daniel Hagnoul">
<title>Test</title>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.11.4/themes/sunny/jquery-ui.css">
<style>
.list-group-item { display: block; }
</style>
</head>
<body>
<div class="container">
<div class="list-group"></div>
</div>
<script src="http://code.jquery.com/jquery-2.1.4.min.js"></script>
<script src="http://code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<script>
"use strict";
$( function(){ // forme abrégée de $(document).ready( function( ){
var
data = [
{
"latitude" : 65465,
"longitude" : 98765,
"name" : "Paris",
"_id" : {
"$oid" : "http://www.google.fr"
}
},
{
"latitude" : 65465,
"longitude" : 98765,
"name" : "Bruxelles",
"_id" : {
"$oid" : "http://www.google.fr"
}
},
{
"latitude" : 65465,
"longitude" : 98765,
"name" : "Anvers",
"_id" : {
"$oid" : "http://www.google.fr"
}
}
],
jObjListPoints = $( ".list-group" ),
jObjButtons = $( '<span class="pull-right"></span>' ),
jObjBtnInfo = $( '<button/>', {
"css" : {
"display" : "inline-block",
"margin-left" : "6px"
},
"class" : "btn btn-xs btn-info",
"text" : "Info",
"click" : function( event ){
event.preventDefault()
event.stopPropagation();
// debug, console touche F12
console.log( "btn-info", $( event.target ).parents( ".list-group-item" ).attr( "href" ) );
}
}),
jObjBtnWarning = $( '<button/>', {
"css" : {
"display" : "inline-block",
"margin-left" : "6px"
},
"class" : "btn btn-xs btn-warning",
"text" : "Warning",
"click" : function( event ){
event.preventDefault()
event.stopPropagation();
// debug, console touche F12
console.log( "btn-warning", $( event.target ).parents( ".list-group-item" ).data( "name" ) );
}
});
jObjButtons.append( jObjBtnInfo, jObjBtnWarning );
$.each( data, function( i, item ){
$( '<a/>', {
"class" : "list-group-item",
"href" : item._id.$oid,
"text" : item.name,
"data" : {
'latitude' : item.latitude,
'longitude': item.longitude,
'name' : item.name
}
})
.append( jObjButtons.clone( true, true ) )
.appendTo( jObjListPoints );
});
});
$( window ).load( function(){
});
</script>
</body>
</html> |
Partager