From 29c878f4400dbb508e44bc5f40f558d40906bc67 Mon Sep 17 00:00:00 2001 From: Bernhard Posselt Date: Mon, 3 Sep 2012 15:39:46 +0200 Subject: set a timeout for scroll event to only trigger once every 100 milisecs --- js/items.js | 36 ++++++++++++++++++++++-------------- js/menu.js | 4 +++- js/news.js | 1 - 3 files changed, 25 insertions(+), 16 deletions(-) (limited to 'js') 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 = $('
').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 = $('
').text(folderName).html(); News.Objects.Menu.updateNode(News.MenuNodeType.Folder, folderId, {title: folderName}); $('#changefolder_dialog').dialog('close'); } else { -- cgit v1.2.3