summaryrefslogtreecommitdiffstats
path: root/js
diff options
context:
space:
mode:
authorBernhard Posselt <nukeawhale@gmail.com>2012-09-03 15:39:46 +0200
committerBernhard Posselt <nukeawhale@gmail.com>2012-09-03 15:40:02 +0200
commit29c878f4400dbb508e44bc5f40f558d40906bc67 (patch)
tree67b090e34e108cc59cb936946c04ccfa994b2dae /js
parenteba4082bc9653eb24b14a8eb90cc243512e1f26a (diff)
set a timeout for scroll event to only trigger once every 100 milisecs
Diffstat (limited to 'js')
-rw-r--r--js/items.js36
-rw-r--r--js/menu.js4
-rw-r--r--js/news.js1
3 files changed, 25 insertions, 16 deletions
diff --git a/js/items.js b/js/items.js
index cc09ac104..8a082f8ef 100644
--- a/js/items.js
+++ b/js/items.js
@@ -40,20 +40,29 @@ var t = t || function(app, string){ return string; }; // mock translation for lo
// mark items whose title was hid under the top edge as read
// when the bottom is reached, mark all items as read
+ this._scrollTimeoutMiliSecs = 100;
+ this._markReadTimeoutMiliSecs = 1000;
+ this._isScrolling = false;
this._$articleList.scroll(function(){
- var boxHeight = $(this).height();
- var scrollHeight = $(this).prop('scrollHeight');
- var scrolled = $(this).scrollTop() + boxHeight;
- $(this).children('ul').children('.feed_item:not(.read)').each(function(){
- var item = this;
- var itemOffset = $(this).position().top;
- if(itemOffset <= 0){
- // wait and check if the item is still under the top edge
- setTimeout(function(){ self._markItemAsReadTimeout(item);}, 1000);
- }
- });
- // mark item with current class
- self._markCurrentlyViewed();
+ // prevent too many scroll requests;
+ if(!self._isScrolling){
+ self._isScrolling = true;
+ setTimeout(function(){
+ self._isScrolling = false;
+ }, self._scrollTimeoutMiliSecs);
+
+ $(this).children('ul').children('.feed_item:not(.read)').each(function(){
+ var item = this;
+ var itemOffset = $(item).position().top;
+ if(itemOffset <= 0){
+ setTimeout(function(){
+ self._markItemAsReadTimeout(item);
+ }, self._markReadTimeoutMiliSecs);
+ }
+ });
+ // mark item with current class
+ self._markCurrentlyViewed();
+ }
});
this._itemCache.populate(this._$articleList.children('ul'));
@@ -123,7 +132,6 @@ var t = t || function(app, string){ return string; }; // mock translation for lo
var notFound = true;
$('.feed_item').each(function(){
var visiblePx = Math.ceil($(this).position().top + $(this).outerHeight());
- console.log(visiblePx);
if(notFound && visiblePx > 2){
$(this).addClass('viewed');
notFound = false;
diff --git a/js/menu.js b/js/menu.js
index 0591fa828..2a2b930b6 100644
--- a/js/menu.js
+++ b/js/menu.js
@@ -179,7 +179,9 @@ var News = News || {};
id = parseInt(id);
if(data.title !== undefined){
- $node.children('.title').html(data.title);
+ // prevent xss
+ var title = $('<div>').text(data.title).html();
+ $node.children('.title').html(title);
}
if(data.undreadCount !== undefined){
diff --git a/js/news.js b/js/news.js
index 483888005..22baf7f67 100644
--- a/js/news.js
+++ b/js/news.js
@@ -70,7 +70,6 @@ News = {
$.post(url, data, function(jsonData){
if(jsonData.status == 'success'){
- folderName = $('<div>').text(folderName).html();
News.Objects.Menu.updateNode(News.MenuNodeType.Folder, folderId, {title: folderName});
$('#changefolder_dialog').dialog('close');
} else {