Merge branch 'embedded-notes'

This commit is contained in:
r888888888
2015-02-02 13:34:10 -08:00
8 changed files with 171 additions and 107 deletions

View File

@@ -4,8 +4,15 @@ Danbooru.Note = {
var $inner_border = $('<div/>');
$inner_border.addClass("note-box-inner-border");
var opacity = 0;
if (Danbooru.Note.embed) {
opacity = 0.95
} else {
opacity = 0.5
}
$inner_border.css({
opacity: 0.5,
opacity: opacity,
"-ms-filter": "progid:DXImageTransform.Microsoft.Alpha(Opacity=50)",
"filter": "alpha(opacity=50)",
zoom: 1
@@ -13,6 +20,11 @@ Danbooru.Note = {
var $note_box = $('<div/>');
$note_box.addClass("note-box");
if (Danbooru.Note.embed) {
$note_box.addClass("embedded");
}
$note_box.data("id", String(id));
$note_box.attr("data-id", String(id));
$note_box.draggable({
@@ -267,8 +279,11 @@ Danbooru.Note = {
}
},
set_text: function($note_body, text) {
set_text: function($note_body, $note_box, text) {
Danbooru.Note.Body.display_text($note_body, text);
if (Danbooru.Note.embed) {
Danbooru.Note.Body.display_text($note_box.children("div"), text);
}
Danbooru.Note.Body.resize($note_body);
Danbooru.Note.Body.bound_position($note_body);
},
@@ -321,6 +336,10 @@ Danbooru.Note = {
$(".note-box").resizable("disable");
$(".note-box").draggable("disable");
if (Danbooru.Note.embed) {
$(".note-box").css("opacity", "0.5");
}
$textarea = $('<textarea></textarea>');
$textarea.css({
width: "97%",
@@ -362,6 +381,10 @@ Danbooru.Note = {
Danbooru.Note.editing = false;
$(".note-box").resizable("enable");
$(".note-box").draggable("enable");
if (Danbooru.Note.embed) {
$(".note-box").css("opacity", "0.95");
}
});
$textarea.selectEnd();
@@ -416,9 +439,9 @@ Danbooru.Note = {
var $note_box = Danbooru.Note.Box.find(id);
var text = $textarea.val();
$note_body.data("original-body", text);
Danbooru.Note.Body.set_text($note_body, "Loading...");
Danbooru.Note.Body.set_text($note_body, $note_box, "Loading...");
$.get("/note_previews.json", {body: text}).success(function(data) {
Danbooru.Note.Body.set_text($note_body, data.body);
Danbooru.Note.Body.set_text($note_body, $note_box, data.body);
$note_body.show();
});
$this.dialog("close");
@@ -448,9 +471,9 @@ Danbooru.Note = {
var text = $textarea.val();
var $note_box = Danbooru.Note.Box.find(id);
$note_box.find(".note-box-inner-border").addClass("unsaved");
Danbooru.Note.Body.set_text($note_body, "Loading...");
Danbooru.Note.Body.set_text($note_body, $note_box, "Loading...");
$.get("/note_previews.json", {body: text}).success(function(data) {
Danbooru.Note.Body.set_text($note_body, data.body);
Danbooru.Note.Body.set_text($note_body, $note_box, data.body);
$note_body.show();
});
},
@@ -662,6 +685,9 @@ Danbooru.Note = {
$note_body.data("original-body", text);
Danbooru.Note.Box.scale($note_box);
Danbooru.Note.Body.display_text($note_body, text);
if (Danbooru.Note.embed) {
Danbooru.Note.Body.display_text($note_box.children("div"), text);
}
},
create: function(x, y, w, h) {
@@ -713,6 +739,7 @@ $(function() {
$("#translate").bind("click", Danbooru.Note.TranslationMode.toggle);
$(document).bind("keypress", "n", Danbooru.Note.TranslationMode.toggle);
}
Danbooru.Note.embed = (Danbooru.meta("post-has-embedded-notes") === "true");
Danbooru.Note.load_all();
$("#image").bind("click", Danbooru.Note.Box.toggle_all);
}

View File

@@ -71,6 +71,11 @@ div#note-container {
border: 1px solid red;
}
}
div.note-box.embedded div.note-box-inner-border {
text-align: center;
word-wrap: break-word;
}
}
div#note-preview {

View File

@@ -3,6 +3,10 @@ class Post < ActiveRecord::Base
class DisapprovalError < Exception ; end
class SearchError < Exception ; end
BOOLEAN_ATTRIBUTES = {
:has_embedded_notes => 0x0001
}
attr_accessor :old_tag_string, :old_parent_id, :old_source, :old_rating, :has_constraints, :disable_versioning
after_destroy :delete_files
after_destroy :delete_remote_files
@@ -38,7 +42,7 @@ class Post < ActiveRecord::Base
has_many :favorites, :dependent => :destroy
validates_uniqueness_of :md5
validate :post_is_not_its_own_parent
attr_accessible :source, :rating, :tag_string, :old_tag_string, :old_parent_id, :old_source, :old_rating, :last_noted_at, :parent_id, :as => [:member, :builder, :gold, :platinum, :contributor, :janitor, :moderator, :admin, :default]
attr_accessible :source, :rating, :tag_string, :old_tag_string, :old_parent_id, :old_source, :old_rating, :last_noted_at, :parent_id, :has_embedded_notes, :as => [:member, :builder, :gold, :platinum, :contributor, :janitor, :moderator, :admin, :default]
attr_accessible :is_rating_locked, :is_note_locked, :as => [:builder, :contributor, :janitor, :moderator, :admin]
attr_accessible :is_status_locked, :as => [:admin]
@@ -1486,6 +1490,24 @@ class Post < ActiveRecord::Base
include PixivMethods
include IqdbMethods
BOOLEAN_ATTRIBUTES.each do |boolean_attribute, bit_flag|
define_method(boolean_attribute) do
bit_flags & bit_flag > 0
end
define_method("#{boolean_attribute}?") do
bit_flags & bit_flag > 0
end
define_method("#{boolean_attribute}=") do |val|
if val.to_s =~ /t|1|y/
self.bit_flags |= bit_flag
else
self.bit_flags &= ~bit_flag
end
end
end
def visible?
return false if !Danbooru.config.can_user_see_post?(CurrentUser.user, self)
return false if CurrentUser.safe_mode? && rating != "s"

View File

@@ -33,6 +33,11 @@
<% end %>
</div>
<div class="input">
<%= f.label :has_embedded_notes, "Embed notes" %>
<%= f.check_box :has_embedded_notes %>
</div>
<% if CurrentUser.is_builder? %>
<div class="input">
<%= f.label :blank, "Lock" %>

View File

@@ -120,6 +120,7 @@
<meta name="post-is-deleted" content="<%= @post.is_deleted? %>">
<meta name="post-is-flagged" content="<%= @post.is_flagged? %>">
<meta name="config-large-width" content="<%= Danbooru.config.large_image_width %>">
<meta name="post-has-embedded-notes" content="<%= @post.has_embedded_notes? %>">
<meta name="always-resize-images" content="<%= CurrentUser.user.always_resize_images? %>">
<meta property="og:title" content="<%= @post.presenter.humanized_essential_tag_string %> - <%= Danbooru.config.app_name %>">
<meta property="og:description" content="<%= @post.presenter.humanized_tag_string %>">