% throw_content :for_stylesheet do -%> #photo_block { z-index: 0; border: 1px solid black; padding: 0px; width: <%= @width -%>px; height: <%= @height -%>px; <% if @photo.exist? -%> background-image: url('/photos/screen/<%= @photo.id -%>'); <% else -%> background-image: url('/images/image-missing.png'); <% end -%> background-repeat: no-repeat; } #photo_block_container { margin: 10px <%= (600 - @width) / 2 -%>px 20px <%= (600 - @width) / 2 -%>px; } #photo_tag_box { position: relative; z-index: 2; width: 100px; height: 100px; border: 7px solid #6f9bdc; left: 0; top: 0; display: none; } #inner_photo_tag_box { border: 2px solid black; width: 96px; height: 96px; } #photo_tag_editor { margin-bottom: 10px; } <% end -%> <% throw_content :for_javascript do -%> function show_tag_at(x, y) { $('photo_tag_box').style.top = (y - 50) + 'px'; $('photo_tag_box').style.left = (x - 50) + 'px'; $('photo_tag_box').style.display = 'block'; } function hide_tag_box() { $('photo_tag_box').style.display = 'none'; } function set_coordinates(x, y) { $('cartesian_x').innerHTML = x; $('cartesian_y').innerHTML = y; $('photo_tag[x]').value = x; $('photo_tag[y]').value = y; show_tag_at(x, y); } var block_box = true; function set_coordinates_from_event(event) { if(block_box) return; var xcoord = (event.offsetX ? event.offsetX : (event.pageX - $('photo_block').offsetLeft)); var ycoord = (event.offsetY ? event.offsetY : (event.pageY - $('photo_block').offsetTop)); if(xcoord < 0) xcoord = 0; if(xcoord > <%= @width -%>) xcoord = <%= @width -%>; if(ycoord < 0) ycoord = 0; if(ycoord > <%= @height -%>) ycoord = <%= @height -%>; set_coordinates(xcoord, ycoord); } function update_tag_selection(tag_name) { var new_tag = tag_name.innerHTML.gsub(/\<[^>]+\>/, ''); var existing_tags = $('tags').value.gsub(/( |^)[^ ]+$/, ''); var plus_space = (existing_tags.length == 0 ? '' : ' '); $('tags').value = existing_tags + plus_space + new_tag; $('tags').focus(); } function photo_tag_effect() { new Effect.Highlight('photo_tags', {duration: 2.0}); } function save_new_tags() { $('save').disabled = true; $('indicator').show(); new Ajax.Updater( { success: 'photo_tags', failure: 'photo_tag_errors' }, '<%= url(:photo_tag) -%>', { parameters: Form.serialize($('photo_tag_fields')), asynchronous: false, onSuccess: function() { set_coordinates(0, 0); hide_tag_box(); $('tags').value = ''; photo_tag_effect(); } } ); $('indicator').hide(); $('save').disabled = false; } function destroy_photo_tag(tag_id) { $('indicator').show(); new Ajax.Updater( { success: 'photo_tags', failure: 'photo_tag_errors' }, '/photo_tags/' + tag_id, { method: 'delete', onSuccess: function() { photo_tag_effect(); }, onComplete: function() { $('indicator').hide(); } } ); } function toggle_photo_tag_editor(direction) { if(direction) { // swap buttons $('hide_photo_tag_editor').show(); $('show_photo_tag_editor').hide(); block_box = false; // update tags to editable mode new Ajax.Updater( 'photo_tags', '/photo_tags/<%= @photo.id -%>?editable=true', { method: 'get', onSuccess: function() { photo_tag_effect(); } } ); // transition editor and navigation new Effect.Fade('pagination_links'); new Effect.Appear('photo_tag_editor'); } else { // remove box if shown hide_tag_box(); // toggle buttons $('show_photo_tag_editor').show(); $('hide_photo_tag_editor').hide(); block_box = true; // transition out editable blocks and navigation new Effect.Fade('photo_tag_editor'); new Effect.Appear('pagination_links'); // update tags to read only new Ajax.Updater( 'photo_tags', '/photo_tags/<%= @photo.id -%>', { method: 'get', onSuccess: function() { photo_tag_effect(); } } ); } } function highlight_tag(tag_id) { } var last_x = 0; var last_y = 0; function check_for_tag_mouseovers(event) { // skip this if you are editing if(!block_box) return; // figure out the real coordinates var xcoord = (event.offsetX ? event.offsetX : (event.pageX - $('photo_block').offsetLeft)); var ycoord = (event.offsetY ? event.offsetY : (event.pageY - $('photo_block').offsetTop)); // save coordinates for cop-out later if(xcoord == last_x && ycoord == last_y) return; last_x = xcoord; last_y = ycoord; // figure out the box area here var min_x = xcoord - 50; if(min_x < 0) min_x = 0 var max_x = xcoord + 50; if(max_x > <%= @width -%>) max_x = <%= @width -%>; var min_y = ycoord - 50; if(min_y < 0) min_y = 0; var max_y = ycoord + 50; if(max_y > <%= @height -%>) max_y = <%= @height -%>; // remove the box, in case there is no match... hide_tag_box(); // remove tag highlighting unhighlight_tags(); // find all in the area, show the box then highlight the tags tag_array.select(function(entry){ return entry[0] >= min_x && entry[0] <= max_x && entry[1] >= min_y && entry[1] <= max_y; }).each(function(entry){ show_tag_at(entry[0], entry[1]); // show which tag, too highlight_tag(entry[2]); }); } function unhighlight_tags() { $$('.photo_tags_for_mouseover').each(function(entry){ entry.style.fontWeight = 'normal'; }); } function unhighlight_tag(tag_id) { $('photo_tag_' + tag_id).style.fontWeight = 'normal'; } function highlight_tag(tag_id) { $('photo_tag_' + tag_id).style.fontWeight = 'bold'; } <% end -%>
<% if @current_index and @max_index and @photo.album -%>