function FluidbookNotes(fluidbook) {
this.fluidbook = fluidbook;
this.enabled = !!this.fluidbook.settings.notes;
+ this.allNotes = null;
if (this.enabled) {
this.init();
}
setTimeout(function () {
$this.resize();
$this.initNotesFromStorage();
- }, 1000);
+ }, 150);
});
$(document).on('click', '.notes-toggle', function () {
initNotesFromStorage: function () {
this.clearNotes();
- var pages = [this.fluidbook.currentPage];
- if (!this.fluidbook.displayOnePage) {
- if (this.currentPage === 1) {
- pages.unshift(0);
- } else {
- pages.push(this.fluidbook.currentPage + 1);
- }
- }
- var notes = this.getAllNotes();
+
+ var notes = this.getNotesOfPageFromStorage();
+
var $this = this;
$.each(notes, function (k, v) {
- if (pages.indexOf(v.p) === -1) {
- return;
- }
v.y = Math.max(0, Math.min(1, v.y));
v.x = Math.max(0, Math.min(1, v.x));
var w = $this.fluidbook.resize.fluidbookrect.width;
this.initNotes();
},
+ getNotesOfPageFromStorage: function (page) {
+ if (page === undefined) {
+ page = this.fluidbook.currentPage;
+ }
+ var pages = [page];
+ if (!this.fluidbook.displayOnePage) {
+ if (this.currentPage === 1) {
+ pages.unshift(0);
+ } else {
+ pages.push(this.fluidbook.currentPage + 1);
+ }
+ }
+ var notes = this.getAllNotes();
+ var res = {};
+ $.each(notes, function (k, v) {
+ if (pages.indexOf(v.p) === -1) {
+ return;
+ }
+ res[k] = v;
+ });
+ return res;
+ },
+
openMenu: function (callback) {
this.fluidbook.menu.viewWrap(this.getView(this.fluidbook.l10n.__('all notes')), 'notes');
var index = '<div class="' + contentClass + '"><div class="indexView notesView"><div class="indexViewHolder">';
$.each(this.getPagesWithNotes(), function (k, page) {
- index += $this.fluidbook.menu.index.getPage(page, $this.fluidbook.displayOnePage, 300, true, false, $this.fluidbook.mobilefirst.enabled, '');
+ var thumb_notes = '<div class="notes">';
+ $.each($this.getNotesOfPageFromStorage(page), function (id, n) {
+ if (!$this.fluidbook.displayOnePage) {
+ n.x /= 2;
+ if (n.p % 2 === 1) {
+ n.x += 1;
+ }
+ }
+ var x = n.x * 100;
+ var y = n.y * 100;
+ thumb_notes += '<a href="#/page/' + (n.p) + '" class="note" style="top:' + y + '%;left:' + x + '%;" data-tooltip-hide-on-click data-tooltip="' + escapeHtml(n.c) + '"></a>';
+ });
+ thumb_notes += '</div>';
+ index += $this.fluidbook.menu.index.getPage(page, $this.fluidbook.displayOnePage, 300, true, false, $this.fluidbook.mobilefirst.enabled, thumb_notes);
});
index += '</div></div>';
})
},
updateNote: function (id) {
+ this.fluidbook.resize.updateFluidbookRect();
var n = this._getNote(id);
var e = $("#" + id);
var t = $(e).find('textarea');
},
getAllNotes: function () {
- return this.fluidbook.cache.find('note_');
+ if (this.allNotes === null) {
+ this.allNotes = this.fluidbook.cache.find('note_');
+ }
+ return this.allNotes;
},
createNote: function (id) {
return {x: 0, y: 0, w: 0, h: 0, p: -1, c: ''};
},
_setNote: function (id, val) {
+ this.allNotes = null;
this.fluidbook.cache.set(id, val);
},
_getNote: function (id) {
return this.fluidbook.cache.get(id, this._defaultNote());
},
_unsetNote: function (id) {
+ this.allNotes = null;
this.fluidbook.cache.unset(id);
}