Merge branch 'translation-mode'

This commit is contained in:
Toks
2013-05-25 17:06:53 -04:00
3 changed files with 40 additions and 23 deletions

View File

@@ -131,8 +131,7 @@ Danbooru.Note = {
if (is_hidden) { if (is_hidden) {
$note_container.css('visibility', 'visible'); $note_container.css('visibility', 'visible');
} } else {
else {
$note_container.css('visibility', 'hidden'); $note_container.css('visibility', 'hidden');
} }
} }
@@ -446,6 +445,14 @@ Danbooru.Note = {
TranslationMode: { TranslationMode: {
active: false, active: false,
toggle: function(e) {
if (Danbooru.Note.TranslationMode.active) {
Danbooru.Note.TranslationMode.stop(e);
} else {
Danbooru.Note.TranslationMode.start(e);
}
},
start: function(e) { start: function(e) {
e.preventDefault(); e.preventDefault();
@@ -454,18 +461,24 @@ Danbooru.Note = {
} }
Danbooru.Note.TranslationMode.active = true; Danbooru.Note.TranslationMode.active = true;
$(document.body).addClass("mode-translation");
$("#original-file-link").click(); $("#original-file-link").click();
$("#image").one("mousedown", Danbooru.Note.TranslationMode.Drag.start); $("#image").bind("mousedown", Danbooru.Note.TranslationMode.Drag.start);
$(window).bind("mouseup", Danbooru.Note.TranslationMode.Drag.stop); $(window).bind("mouseup", Danbooru.Note.TranslationMode.Drag.stop);
Danbooru.notice('Click or drag on the image to create a note (shortcut is <span class="key">n</span>)');
Danbooru.notice('Translation mode is on. Click or drag on the image to create notes. <a href="#">Turn translation mode off</a> (shortcut is <span class="key">n</span>).');
$("#notice a:contains(Turn translation mode off)").click(Danbooru.Note.TranslationMode.stop);
}, },
stop: function() { stop: function() {
Danbooru.Note.TranslationMode.active = false; Danbooru.Note.TranslationMode.active = false;
$("#image").unbind("mousedown", Danbooru.Note.TranslationMode.Drag.start);
$(window).unbind("mouseup", Danbooru.Note.TranslationMode.Drag.stop);
$(document.body).removeClass("mode-translation");
$("#close-notice-link").click();
}, },
create_note: function(e,dragged,x,y,w,h) { create_note: function(e,dragged,x,y,w,h) {
Danbooru.Note.TranslationMode.active = false;
var offset = $("#image").offset(); var offset = $("#image").offset();
if (dragged) { if (dragged) {
@@ -480,7 +493,7 @@ Danbooru.Note = {
} else { } else {
Danbooru.Note.new(e.pageX - offset.left, e.pageY - offset.top); Danbooru.Note.new(e.pageX - offset.left, e.pageY - offset.top);
} }
Danbooru.Note.TranslationMode.stop();
$("#note-container").css('visibility', 'visible'); $("#note-container").css('visibility', 'visible');
e.stopPropagation(); e.stopPropagation();
e.preventDefault(); e.preventDefault();
@@ -518,15 +531,15 @@ Danbooru.Note = {
var limitY1 = $image.height()- Danbooru.Note.TranslationMode.Drag.dragStartY + offset.top - 1; var limitY1 = $image.height()- Danbooru.Note.TranslationMode.Drag.dragStartY + offset.top - 1;
var limitY2 = offset.top - Danbooru.Note.TranslationMode.Drag.dragStartY; var limitY2 = offset.top - Danbooru.Note.TranslationMode.Drag.dragStartY;
if(Danbooru.Note.TranslationMode.Drag.dragDistanceX > limitX1) { if (Danbooru.Note.TranslationMode.Drag.dragDistanceX > limitX1) {
Danbooru.Note.TranslationMode.Drag.dragDistanceX = limitX1; Danbooru.Note.TranslationMode.Drag.dragDistanceX = limitX1;
} else if(Danbooru.Note.TranslationMode.Drag.dragDistanceX < limitX2) { } else if (Danbooru.Note.TranslationMode.Drag.dragDistanceX < limitX2) {
Danbooru.Note.TranslationMode.Drag.dragDistanceX = limitX2; Danbooru.Note.TranslationMode.Drag.dragDistanceX = limitX2;
} }
if(Danbooru.Note.TranslationMode.Drag.dragDistanceY > limitY1) { if (Danbooru.Note.TranslationMode.Drag.dragDistanceY > limitY1) {
Danbooru.Note.TranslationMode.Drag.dragDistanceY = limitY1; Danbooru.Note.TranslationMode.Drag.dragDistanceY = limitY1;
} else if(Danbooru.Note.TranslationMode.Drag.dragDistanceY < limitY2) { } else if (Danbooru.Note.TranslationMode.Drag.dragDistanceY < limitY2) {
Danbooru.Note.TranslationMode.Drag.dragDistanceY = limitY2; Danbooru.Note.TranslationMode.Drag.dragDistanceY = limitY2;
} }
@@ -561,19 +574,19 @@ Danbooru.Note = {
}, },
stop: function (e) { stop: function (e) {
if(Danbooru.Note.TranslationMode.Drag.dragStartX === 0) { if (Danbooru.Note.TranslationMode.Drag.dragStartX === 0) {
return; /* 'stop' is bound to window, don't create note if start wasn't triggered */ return; /* 'stop' is bound to window, don't create note if start wasn't triggered */
} }
$(window).unbind("mousemove"); $(window).unbind("mousemove");
if(Danbooru.Note.TranslationMode.Drag.dragging) { if (Danbooru.Note.TranslationMode.Drag.dragging) {
$('#note-preview').css({display:'none'}); $('#note-preview').css({display:'none'});
Danbooru.Note.TranslationMode.create_note(e, true, Danbooru.Note.TranslationMode.Drag.x, Danbooru.Note.TranslationMode.Drag.y, Danbooru.Note.TranslationMode.Drag.w-1, Danbooru.Note.TranslationMode.Drag.h-1); Danbooru.Note.TranslationMode.create_note(e, true, Danbooru.Note.TranslationMode.Drag.x, Danbooru.Note.TranslationMode.Drag.y, Danbooru.Note.TranslationMode.Drag.w-1, Danbooru.Note.TranslationMode.Drag.h-1);
Danbooru.Note.TranslationMode.Drag.dragging = false; /* border of the note is pixel-perfect on the preview border */ Danbooru.Note.TranslationMode.Drag.dragging = false; /* border of the note is pixel-perfect on the preview border */
} else { /* no dragging -> create a normal note */ } else { /* no dragging -> create a normal note */
Danbooru.Note.TranslationMode.create_note(e); Danbooru.Note.TranslationMode.create_note(e);
} }
$(window).unbind("mouseup", Danbooru.Note.TranslationMode.Drag.stop);
Danbooru.Note.TranslationMode.Drag.dragStartX = 0; Danbooru.Note.TranslationMode.Drag.dragStartX = 0;
Danbooru.Note.TranslationMode.Drag.dragStartY = 0; Danbooru.Note.TranslationMode.Drag.dragStartY = 0;
} }
@@ -648,8 +661,8 @@ Danbooru.Note = {
$(function() { $(function() {
if ($("#c-posts").length && $("#a-show").length && $("#image").length) { if ($("#c-posts").length && $("#a-show").length && $("#image").length) {
if ($("#note-locked-notice").length == 0) { if ($("#note-locked-notice").length == 0) {
$("#translate").bind("click", Danbooru.Note.TranslationMode.start); $("#translate").bind("click", Danbooru.Note.TranslationMode.toggle);
$(document).bind("keydown.n", Danbooru.Note.TranslationMode.start); $(document).bind("keydown.n", Danbooru.Note.TranslationMode.toggle);
} }
Danbooru.Note.load_all(); Danbooru.Note.load_all();
$("#image").click(Danbooru.Note.Box.toggle_all); $("#image").click(Danbooru.Note.Box.toggle_all);

View File

@@ -57,3 +57,7 @@ body.mode-add-to-pool {
body.mode-tag-script { body.mode-tag-script {
background-color: #A3A; background-color: #A3A;
} }
body.mode-translation {
background-color: #5CD;
}

View File

@@ -7,7 +7,7 @@
<% if post.is_note_locked? %> <% if post.is_note_locked? %>
<li><span id="note-locked-notice">Note locked</span></li> <li><span id="note-locked-notice">Note locked</span></li>
<% else %> <% else %>
<li><%= link_to "Add note", "#", :id => "translate", :title => "Shortcut is N" %></li> <li><%= link_to "Add notes", "#", :id => "translate", :title => "Shortcut is N" %></li>
<% end %> <% end %>
<% if CurrentUser.is_builder? %> <% if CurrentUser.is_builder? %>
<li><%= link_to "Copy all notes", "#", :id => "copy-notes" %></li> <li><%= link_to "Copy all notes", "#", :id => "copy-notes" %></li>