Use document fragment when loading notes
This commit is contained in:
@@ -89,13 +89,13 @@ Danbooru.Note = {
|
|||||||
|
|
||||||
scale: function($note_box) {
|
scale: function($note_box) {
|
||||||
var $image = $("#image");
|
var $image = $("#image");
|
||||||
var ratio = $image.width() / parseFloat($("#image").data("original-width"));
|
var ratio = $image.width() / parseFloat($image.data("original-width"));
|
||||||
var $note = $("#notes > article[data-id=" + $note_box.data("id") + "]");
|
var MIN_SIZE = 5;
|
||||||
$note_box.css({
|
$note_box.css({
|
||||||
top: Math.ceil(parseFloat($note.data("y")) * ratio),
|
top: Math.ceil(parseFloat($note_box.data("y")) * ratio),
|
||||||
left: Math.ceil(parseFloat($note.data("x")) * ratio),
|
left: Math.ceil(parseFloat($note_box.data("x")) * ratio),
|
||||||
width: Math.ceil(parseFloat($note.data("width")) * ratio),
|
width: Math.max(MIN_SIZE, Math.ceil(parseFloat($note_box.data("width")) * ratio)),
|
||||||
height: Math.ceil(parseFloat($note.data("height")) * ratio)
|
height: Math.max(MIN_SIZE, Math.ceil(parseFloat($note_box.data("height")) * ratio))
|
||||||
});
|
});
|
||||||
Danbooru.Note.Box.resize_inner_border($note_box);
|
Danbooru.Note.Box.resize_inner_border($note_box);
|
||||||
},
|
},
|
||||||
@@ -139,6 +139,10 @@ Danbooru.Note = {
|
|||||||
top: $note_box.position().top + $note_box.height() + 5,
|
top: $note_box.position().top + $note_box.height() + 5,
|
||||||
left: $note_box.position().left
|
left: $note_box.position().left
|
||||||
});
|
});
|
||||||
|
if (!$note_body.data('resized')) {
|
||||||
|
Danbooru.Note.Body.resize($note_body);
|
||||||
|
$note_body.data('resized', 'true');
|
||||||
|
}
|
||||||
Danbooru.Note.Body.bound_position($note_body);
|
Danbooru.Note.Body.bound_position($note_body);
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -169,8 +173,8 @@ Danbooru.Note = {
|
|||||||
Danbooru.Note.Body.hide_all();
|
Danbooru.Note.Body.hide_all();
|
||||||
Danbooru.Note.clear_timeouts();
|
Danbooru.Note.clear_timeouts();
|
||||||
var $note_body = Danbooru.Note.Body.find(id);
|
var $note_body = Danbooru.Note.Body.find(id);
|
||||||
$note_body.show();
|
|
||||||
Danbooru.Note.Body.initialize($note_body);
|
Danbooru.Note.Body.initialize($note_body);
|
||||||
|
$note_body.show();
|
||||||
},
|
},
|
||||||
|
|
||||||
find: function(id) {
|
find: function(id) {
|
||||||
@@ -223,7 +227,7 @@ Danbooru.Note = {
|
|||||||
}
|
}
|
||||||
} while ((hi - lo) > 4)
|
} while ((hi - lo) > 4)
|
||||||
if ($note_body.height() > h) {
|
if ($note_body.height() > h) {
|
||||||
$note_body.css("minWidth", hi);
|
$note_body.css("min-width", hi);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -557,23 +561,19 @@ Danbooru.Note = {
|
|||||||
pending: {},
|
pending: {},
|
||||||
ignore_click_until: 0,
|
ignore_click_until: 0,
|
||||||
|
|
||||||
add: function(id, x, y, w, h, text) {
|
add: function(container, id, x, y, w, h, text) {
|
||||||
var $note_box = Danbooru.Note.Box.create(id);
|
var $note_box = Danbooru.Note.Box.create(id);
|
||||||
var $note_body = Danbooru.Note.Body.create(id);
|
var $note_body = Danbooru.Note.Body.create(id);
|
||||||
|
|
||||||
$note_box.css({
|
$note_box.data('x', x);
|
||||||
left: x,
|
$note_box.data('y', y);
|
||||||
top: y,
|
$note_box.data('width', w);
|
||||||
width: w,
|
$note_box.data('height', h);
|
||||||
height: h,
|
container.appendChild($note_box[0]);
|
||||||
display: 'none'
|
container.appendChild($note_body[0]);
|
||||||
});
|
|
||||||
|
|
||||||
$("#note-container").append($note_box);
|
|
||||||
$("#note-container").append($note_body);
|
|
||||||
$note_body.data("original-body", text);
|
$note_body.data("original-body", text);
|
||||||
Danbooru.Note.Box.scale($note_box);
|
Danbooru.Note.Box.scale($note_box);
|
||||||
Danbooru.Note.Body.set_text($note_body, text);
|
Danbooru.Note.Body.display_text($note_body, text);
|
||||||
},
|
},
|
||||||
|
|
||||||
new: function(x, y, w, h) {
|
new: function(x, y, w, h) {
|
||||||
@@ -603,9 +603,11 @@ Danbooru.Note = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
load_all: function() {
|
load_all: function() {
|
||||||
|
var fragment = document.createDocumentFragment();
|
||||||
$.each($("#notes article"), function(i, article) {
|
$.each($("#notes article"), function(i, article) {
|
||||||
var $article = $(article);
|
var $article = $(article);
|
||||||
Danbooru.Note.add(
|
Danbooru.Note.add(
|
||||||
|
fragment,
|
||||||
$article.data("id"),
|
$article.data("id"),
|
||||||
$article.data("x"),
|
$article.data("x"),
|
||||||
$article.data("y"),
|
$article.data("y"),
|
||||||
@@ -614,12 +616,7 @@ Danbooru.Note = {
|
|||||||
$article.html()
|
$article.html()
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
$("#note-container").append(fragment);
|
||||||
$('#note-container').css('display','none');
|
|
||||||
$('.note-box').each(function(i, v) {
|
|
||||||
$(v).css('display','block')
|
|
||||||
});
|
|
||||||
$('#note-container').css('display','block');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user