@@ -7,6 +7,8 @@ var $stream = null,
77 shares = 0 ,
88 ajax_loading = false ;
99
10+ if ( ! NodeList . prototype . forEach ) { NodeList . prototype . forEach = Array . prototype . forEach ; } //IE11
11+
1012function redirect ( url , new_tab ) {
1113 if ( url ) {
1214 if ( new_tab ) {
@@ -89,7 +91,7 @@ function incUnreadsFeed(article, feed_id, nb) {
8991 }
9092
9193 //Update unread: favourites
92- if ( article && article . closest ( 'div' ) . hasClass ( 'favorite' ) ) {
94+ if ( article && $ ( article ) . closest ( 'div' ) . hasClass ( 'favorite' ) ) {
9395 elem = $ ( '#aside_feed .favorites .title' ) . get ( 0 ) ;
9496 if ( elem ) {
9597 feed_unreads = elem ? str2int ( elem . getAttribute ( 'data-unread' ) ) : 0 ;
@@ -115,7 +117,7 @@ function incUnreadsFeed(article, feed_id, nb) {
115117}
116118
117119function incUnreadsTag ( tag_id , nb ) {
118- var $t = $ ( '#t_ ' + tag_id ) ;
120+ var $t = $ ( '#' + tag_id ) ;
119121 var unreads = str2int ( $t . attr ( 'data-unread' ) ) ;
120122 $t . attr ( 'data-unread' , unreads + nb )
121123 . children ( '.item-title' ) . attr ( 'data-unread' , numberFormat ( unreads + nb ) ) ;
@@ -126,20 +128,20 @@ function incUnreadsTag(tag_id, nb) {
126128}
127129
128130var pending_entries = { } ;
129- function mark_read ( active , only_not_read ) {
130- if ( ( active . length === 0 ) || ( ! active . attr ( 'id' ) ) ||
131- context . anonymous ||
132- ( only_not_read && ! active . hasClass ( " not_read" ) ) ) {
131+ function mark_read ( $ active, only_not_read ) {
132+ let div = $active ? $ active[ 0 ] : null ;
133+ if ( ! div || ! div . id || context . anonymous ||
134+ ( only_not_read && ! div . classList . contains ( ' not_read' ) ) ) {
133135 return false ;
134136 }
135137
136- if ( pending_entries [ active . attr ( 'id' ) ] ) {
138+ if ( pending_entries [ div . id ] ) {
137139 return false ;
138140 }
139- pending_entries [ active . attr ( 'id' ) ] = true ;
141+ pending_entries [ div . id ] = true ;
140142
141- var url = '.?c=entry&a=read&id=' + active . attr ( 'id' ) . replace ( / ^ f l u x _ / , '' ) +
142- ( active . hasClass ( 'not_read' ) ? '' : '&is_read=0' ) ;
143+ let url = '.?c=entry&a=read&id=' + div . id . replace ( / ^ f l u x _ / , '' ) +
144+ ( div . classList . contains ( 'not_read' ) ? '' : '&is_read=0' ) ;
143145
144146 $ . ajax ( {
145147 type : 'POST' ,
@@ -149,35 +151,39 @@ function mark_read(active, only_not_read) {
149151 _csrf : context . csrf ,
150152 } ,
151153 } ) . done ( function ( data ) {
152- var $r = active . find ( "a.read" ) . attr ( "href" , data . url ) ,
153- inc = 0 ;
154- if ( active . hasClass ( "not_read" ) ) {
155- active . removeClass ( "not_read" ) ;
154+ let inc = 0 ;
155+ if ( div . classList . contains ( 'not_read' ) ) {
156+ div . classList . remove ( 'not_read' ) ;
157+ div . querySelectorAll ( 'a.read' ) . forEach ( function ( a ) { a . setAttribute ( 'href' , a . getAttribute ( 'href' ) . replace ( '&is_read=0' , '' ) + '&is_read=1' ) ; } ) ;
158+ div . querySelectorAll ( 'a.read > .icon' ) . forEach ( function ( img ) { img . outerHTML = icons . read ; } ) ;
156159 inc -- ;
157160 } else {
158- active . addClass ( "not_read" ) ;
159- active . addClass ( "keep_unread" ) ;
161+ div . classList . add ( 'not_read' , 'keep_unread' ) ;
162+ div . querySelectorAll ( 'a.read' ) . forEach ( function ( a ) { a . setAttribute ( 'href' , a . getAttribute ( 'href' ) . replace ( '&is_read=1' , '' ) ) ; } ) ;
163+ div . querySelectorAll ( 'a.read > .icon' ) . forEach ( function ( img ) { img . outerHTML = icons . unread ; } ) ;
160164 inc ++ ;
161165 }
162- $r . find ( '.icon' ) . replaceWith ( data . icon ) ;
163166
164- var feed_url = active . find ( ".website>a" ) . attr ( "href" ) ;
165- if ( feed_url ) {
166- var feed_id = feed_url . substr ( feed_url . lastIndexOf ( 'f_' ) ) ;
167- incUnreadsFeed ( active , feed_id , inc ) ;
167+ let feed_link = div . querySelector ( '.website > a' ) ;
168+ if ( feed_link ) {
169+ let feed_url = feed_link . getAttribute ( 'href' ) ;
170+ let feed_id = feed_url . substr ( feed_url . lastIndexOf ( 'f_' ) ) ;
171+ incUnreadsFeed ( div , feed_id , inc ) ;
168172 }
169173 faviconNbUnread ( ) ;
170174
171175 if ( data . tags ) {
172- for ( var i = data . tags . length - 1 ; i >= 0 ; i -- ) {
173- incUnreadsTag ( data . tags [ i ] , inc ) ;
176+ let tagIds = Object . keys ( data . tags ) ;
177+ for ( let i = tagIds . length - 1 ; i >= 0 ; i -- ) {
178+ let tagId = tagIds [ i ] ;
179+ incUnreadsTag ( tagId , inc * data . tags [ tagId ] . length ) ;
174180 }
175181 }
176182
177- delete pending_entries [ active . attr ( 'id' ) ] ;
183+ delete pending_entries [ div . id ] ;
178184 } ) . fail ( function ( data ) {
179185 openNotification ( i18n . notif_request_failed , 'bad' ) ;
180- delete pending_entries [ active . attr ( 'id' ) ] ;
186+ delete pending_entries [ div . id ] ;
181187 } ) ;
182188}
183189
@@ -911,7 +917,7 @@ function init_dynamic_tags() {
911917 } )
912918 . done ( function ( ) {
913919 if ( $entry . hasClass ( 'not_read' ) ) {
914- incUnreadsTag ( tagId , isChecked ? 1 : - 1 ) ;
920+ incUnreadsTag ( 't_' + tagId , isChecked ? 1 : - 1 ) ;
915921 }
916922 } )
917923 . fail ( function ( ) {
@@ -1079,7 +1085,7 @@ function notifs_html5_show(nb) {
10791085 var notification = new window . Notification ( i18n . notif_title_articles , {
10801086 icon : "../themes/icons/favicon-256.png" ,
10811087 body : i18n . notif_body_articles . replace ( '%d' , nb ) ,
1082- tag : " freshRssNewArticles"
1088+ tag : ' freshRssNewArticles' ,
10831089 } ) ;
10841090
10851091 notification . onclick = function ( ) {
@@ -1491,6 +1497,8 @@ function parseJsonVars() {
14911497 window . url = json . url ;
14921498 window . i18n = json . i18n ;
14931499 window . icons = json . icons ;
1500+ icons . read = decodeURIComponent ( icons . read ) ;
1501+ icons . unread = decodeURIComponent ( icons . unread ) ;
14941502}
14951503
14961504function init_normal ( ) {
0 commit comments