photomix/public/javascripts/balder.js

100 lines
3.8 KiB
JavaScript
Raw Normal View History

2009-05-25 21:39:43 +02:00
jQuery(function($) {
2009-06-03 21:30:09 +02:00
if ( $('.tag_list').length ) {
$('.tag_list').tagSuggest({
2009-05-25 21:39:43 +02:00
tags: $('#all_tags').val().split('\'')
})
}
2009-07-21 11:31:53 +02:00
var map, latlng
if ( $('#map_canvas').length && $('#album_latitude').val() > '' && $('#album_longitude').val() > '' ) {
2009-07-21 11:31:53 +02:00
latlng = new google.maps.LatLng($('#album_latitude').val(), $('#album_longitude').val());
2009-07-06 15:41:19 +02:00
mapInitialize()
$('#map_canvas').show()
2009-07-06 15:41:19 +02:00
}
2009-07-21 11:31:53 +02:00
if ( $('#map_canvas').length && $('#photo_latitude').val() > '' && $('#photo_longitude').val() > '' ) {
latlng = new google.maps.LatLng($('#photo_latitude').val(), $('#photo_longitude').val());
mapInitialize()
$('#map_canvas').show()
}
$('#collection_albums .delete').livequery('click', function() {
$(this).parent('span').fadeOut('slow', function() { $(this).remove() })
})
$("#available_albums").change( function() {
if ( this.value == '' ) {
return false
}
else if ( $('#collection_album_list_' + this.value).length ) {
$('#collection_album_list_' + this.value).parent('span').fadeTo('slow', 0.33, function () {
$(this).fadeTo('slow', 1)
})
return false
}
$.getJSON("/albums/" + this.value + '/photos',
function(data){
html = '<span style="display:none;"><img src="/images/delete-24x24.png" border="" class="delete" />'
html += '<img alt="' + $("#available_albums :selected").val() + '_collection" src="/thumbs/' + $("#available_albums :selected").text() + '/' + data[0].photo.id + '_album.jpg" />'
html += '<input id="collection_album_list_' + $("#available_albums :selected").val() + '" name="collection[album_list][' + $("#available_albums :selected").val() + ']" type="hidden" />'
html += '</span>'
$('#collection_albums').append(html)
$('#collection_album_list_' + $('#available_albums :selected').val() ).parent('span').fadeIn('slow')
})
}
)
2009-07-21 11:31:53 +02:00
2009-07-08 16:52:21 +02:00
$("#album_address").change( function() {
2009-07-21 11:31:53 +02:00
if( !map ) {
mapInitialize()
$('#map_canvas').show()
}
2009-07-08 16:52:21 +02:00
var geocoder = new google.maps.Geocoder()
var address = this.value
if (geocoder) {
geocoder.geocode( { 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
if (status != google.maps.GeocoderStatus.ZERO_RESULTS) {
map.set_center(results[0].geometry.location)
mapCreateMarker( {
title: $('#album_title').val(),
address: results[0].formatted_address,
position: results[0].geometry.location
}
)
} else {
2009-07-21 11:31:53 +02:00
//alert("No results found")
2009-07-08 16:52:21 +02:00
}
} else {
2009-07-21 11:31:53 +02:00
//alert("Geocode was not successful for the following reason: " + status)
2009-07-08 16:52:21 +02:00
}
});
2009-07-06 15:41:19 +02:00
}
2009-07-08 16:52:21 +02:00
})
function mapInitialize() {
var myOptions = {
zoom: 13,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
2009-07-06 15:41:19 +02:00
}
2009-07-08 16:52:21 +02:00
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions)
}
2009-07-06 15:41:19 +02:00
function mapCreateMarker(location) {
2009-07-08 16:52:21 +02:00
var marker = new google.maps.Marker({
map: map,
position: location.position,
title: location.title
})
var infowindow = new google.maps.InfoWindow({
content: '<b>' + location.title + '</b><br/>' + location.address
})
2009-05-25 21:39:43 +02:00
2009-07-08 16:52:21 +02:00
google.maps.event.addListener(marker, 'click', function() {
infowindow.open(map,marker)
})
}
})