Reformat notes JS
This commit is contained in:
parent
d9b15fc17d
commit
fac4e3f2e5
1 changed files with 167 additions and 179 deletions
|
@ -9,8 +9,7 @@ var NoteList = {
|
||||||
loading_more_disabled: false,
|
loading_more_disabled: false,
|
||||||
reversed: false,
|
reversed: false,
|
||||||
|
|
||||||
init:
|
init: function(tid, tt, path) {
|
||||||
function(tid, tt, path) {
|
|
||||||
this.notes_path = path + ".js";
|
this.notes_path = path + ".js";
|
||||||
this.target_id = tid;
|
this.target_id = tid;
|
||||||
this.target_type = tt;
|
this.target_type = tt;
|
||||||
|
@ -232,8 +231,7 @@ var NoteList = {
|
||||||
/**
|
/**
|
||||||
* Gets an inital set of notes.
|
* Gets an inital set of notes.
|
||||||
*/
|
*/
|
||||||
getContent:
|
getContent: function() {
|
||||||
function() {
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: this.notes_path,
|
url: this.notes_path,
|
||||||
data: this.target_params,
|
data: this.target_params,
|
||||||
|
@ -247,8 +245,7 @@ var NoteList = {
|
||||||
* Called in response to getContent().
|
* Called in response to getContent().
|
||||||
* Replaces the content of #notes-list with the given html.
|
* Replaces the content of #notes-list with the given html.
|
||||||
*/
|
*/
|
||||||
setContent:
|
setContent: function(newNoteIds, html) {
|
||||||
function(newNoteIds, html) {
|
|
||||||
this.top_id = newNoteIds.first();
|
this.top_id = newNoteIds.first();
|
||||||
this.bottom_id = newNoteIds.last();
|
this.bottom_id = newNoteIds.last();
|
||||||
$("#notes-list").html(html);
|
$("#notes-list").html(html);
|
||||||
|
@ -274,8 +271,7 @@ var NoteList = {
|
||||||
/**
|
/**
|
||||||
* Initializes loading more notes when scrolling to the bottom of the page.
|
* Initializes loading more notes when scrolling to the bottom of the page.
|
||||||
*/
|
*/
|
||||||
initLoadMore:
|
initLoadMore: function() {
|
||||||
function() {
|
|
||||||
$(document).endlessScroll({
|
$(document).endlessScroll({
|
||||||
bottomPixels: 400,
|
bottomPixels: 400,
|
||||||
fireDelay: 1000,
|
fireDelay: 1000,
|
||||||
|
@ -292,8 +288,7 @@ var NoteList = {
|
||||||
/**
|
/**
|
||||||
* Gets an additional set of notes.
|
* Gets an additional set of notes.
|
||||||
*/
|
*/
|
||||||
getMore:
|
getMore: function() {
|
||||||
function() {
|
|
||||||
// only load more notes if there are no "new" notes
|
// only load more notes if there are no "new" notes
|
||||||
$('.loading').show();
|
$('.loading').show();
|
||||||
$.ajax({
|
$.ajax({
|
||||||
|
@ -309,8 +304,7 @@ var NoteList = {
|
||||||
* Called in response to getMore().
|
* Called in response to getMore().
|
||||||
* Append notes to #notes-list.
|
* Append notes to #notes-list.
|
||||||
*/
|
*/
|
||||||
appendMoreNotes:
|
appendMoreNotes: function(newNoteIds, html) {
|
||||||
function(newNoteIds, html) {
|
|
||||||
var lastNewNoteId = newNoteIds.last();
|
var lastNewNoteId = newNoteIds.last();
|
||||||
if(lastNewNoteId != this.bottom_id) {
|
if(lastNewNoteId != this.bottom_id) {
|
||||||
this.bottom_id = lastNewNoteId;
|
this.bottom_id = lastNewNoteId;
|
||||||
|
@ -323,8 +317,7 @@ var NoteList = {
|
||||||
* Disables loading more notes when scrolling to the bottom of the page.
|
* Disables loading more notes when scrolling to the bottom of the page.
|
||||||
* Initalizes refreshing new notes.
|
* Initalizes refreshing new notes.
|
||||||
*/
|
*/
|
||||||
finishedLoadingMore:
|
finishedLoadingMore: function() {
|
||||||
function() {
|
|
||||||
this.loading_more_disabled = true;
|
this.loading_more_disabled = true;
|
||||||
|
|
||||||
// from now on only get new notes
|
// from now on only get new notes
|
||||||
|
@ -348,16 +341,14 @@ var NoteList = {
|
||||||
/**
|
/**
|
||||||
* Initializes getting new notes every n seconds.
|
* Initializes getting new notes every n seconds.
|
||||||
*/
|
*/
|
||||||
initRefreshNew:
|
initRefreshNew: function() {
|
||||||
function() {
|
|
||||||
setInterval("NoteList.getNew()", 10000);
|
setInterval("NoteList.getNew()", 10000);
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the new set of notes.
|
* Gets the new set of notes.
|
||||||
*/
|
*/
|
||||||
getNew:
|
getNew: function() {
|
||||||
function() {
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: this.notes_path,
|
url: this.notes_path,
|
||||||
data: this.target_params + "&loading_new=1&after_id=" + (this.reversed ? this.top_id : this.bottom_id),
|
data: this.target_params + "&loading_new=1&after_id=" + (this.reversed ? this.top_id : this.bottom_id),
|
||||||
|
@ -369,8 +360,7 @@ var NoteList = {
|
||||||
* Called in response to getNew().
|
* Called in response to getNew().
|
||||||
* Replaces the content of #new-notes-list with the given html.
|
* Replaces the content of #new-notes-list with the given html.
|
||||||
*/
|
*/
|
||||||
replaceNewNotes:
|
replaceNewNotes: function(newNoteIds, html) {
|
||||||
function(newNoteIds, html) {
|
|
||||||
$("#new-notes-list").html(html);
|
$("#new-notes-list").html(html);
|
||||||
this.updateVotes();
|
this.updateVotes();
|
||||||
},
|
},
|
||||||
|
@ -378,8 +368,7 @@ var NoteList = {
|
||||||
/**
|
/**
|
||||||
* Adds a single note to #new-notes-list.
|
* Adds a single note to #new-notes-list.
|
||||||
*/
|
*/
|
||||||
appendNewNote:
|
appendNewNote: function(id, html) {
|
||||||
function(id, html) {
|
|
||||||
if (this.reversed) {
|
if (this.reversed) {
|
||||||
$("#notes-list").prepend(html);
|
$("#notes-list").prepend(html);
|
||||||
} else {
|
} else {
|
||||||
|
@ -396,10 +385,9 @@ var NoteList = {
|
||||||
* Might produce inaccurate results when not all notes have been loaded and a
|
* Might produce inaccurate results when not all notes have been loaded and a
|
||||||
* recalculation is triggered (e.g. when deleting a note).
|
* recalculation is triggered (e.g. when deleting a note).
|
||||||
*/
|
*/
|
||||||
updateVotes:
|
updateVotes: function() {
|
||||||
function() {
|
|
||||||
var votes = $("#votes .votes");
|
var votes = $("#votes .votes");
|
||||||
var notes = $("#notes-list, #new-notes-list").find(".note .vote");
|
var notes = $("#notes-list").find(".note .vote");
|
||||||
|
|
||||||
// only update if there is a vote display
|
// only update if there is a vote display
|
||||||
if (votes.size()) {
|
if (votes.size()) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue