diff options
author | Riyad Preukschas <riyad@informatik.uni-bremen.de> | 2012-09-14 17:01:34 +0200 |
---|---|---|
committer | Riyad Preukschas <riyad@informatik.uni-bremen.de> | 2012-09-14 21:41:57 +0200 |
commit | 07eec9c66a910b5a808852f498e1dc9c88b701d2 (patch) | |
tree | c2861d2d33484599ba022271e85e8c936bc9d95f /app/assets/javascripts/notes.js | |
parent | 7563abbe49fc16280877be89342d552e0609d57c (diff) | |
download | gitlab-ce-07eec9c66a910b5a808852f498e1dc9c88b701d2.tar.gz |
Update Notes JS for reversed notes
Diffstat (limited to 'app/assets/javascripts/notes.js')
-rw-r--r-- | app/assets/javascripts/notes.js | 27 |
1 files changed, 20 insertions, 7 deletions
diff --git a/app/assets/javascripts/notes.js b/app/assets/javascripts/notes.js index 7cbf44b98bf..81bb1d6d1b0 100644 --- a/app/assets/javascripts/notes.js +++ b/app/assets/javascripts/notes.js @@ -4,14 +4,17 @@ var NoteList = { target_params: null, target_id: 0, target_type: null, + top_id: 0, bottom_id: 0, loading_more_disabled: false, + reversed: false, init: function(tid, tt, path) { this.notes_path = path + ".js"; this.target_id = tid; this.target_type = tt; + this.reversed = $("#notes-list").hasClass("reversed"); this.target_params = "&target_type=" + this.target_type + "&target_id=" + this.target_id; // get initial set of notes @@ -69,12 +72,18 @@ var NoteList = { * Replaces the content of #notes-list with the given html. */ setContent: - function(last_id, html) { + function(first_id, last_id, html) { + this.top_id = first_id; this.bottom_id = last_id; $("#notes-list").html(html); - // Init infinite scrolling + // init infinite scrolling this.initLoadMore(); + + // init getting new notes + if (this.reversed) { + this.initRefreshNew(); + } }, @@ -114,7 +123,7 @@ var NoteList = { $.ajax({ type: "GET", url: this.notes_path, - data: "loading_more=1&after_id=" + this.bottom_id + this.target_params, + data: "loading_more=1&" + (this.reversed ? "before_id" : "after_id") + "=" + this.bottom_id + this.target_params, complete: function(){ $('.notes-status').removeClass("loading")}, beforeSend: function() { $('.notes-status').addClass("loading") }, dataType: "script"}); @@ -142,7 +151,9 @@ var NoteList = { this.loading_more_disabled = true; // from now on only get new notes - this.initRefreshNew(); + if (!this.reversed) { + this.initRefreshNew(); + } }, @@ -164,14 +175,14 @@ var NoteList = { }, /** - * Gets the new set of notes (i.e. all notes after ). + * Gets the new set of notes. */ getNew: function() { $.ajax({ type: "GET", url: this.notes_path, - data: "loading_new=1&after_id=" + this.bottom_id + this.target_params, + data: "loading_new=1&after_id=" + (this.reversed ? this.top_id : this.bottom_id) + this.target_params, dataType: "script"}); }, @@ -189,7 +200,9 @@ var NoteList = { */ appendNewNote: function(id, html) { - if(id != this.bottom_id) { + if (this.reversed) { + $("#new-notes-list").prepend(html); + } else { $("#new-notes-list").append(html); } } |