2010-07-25 23:13:27 -04:00
NEWSBLUR . ReaderStatistics = function ( feed _id , options ) {
var defaults = { } ;
this . options = $ . extend ( { } , defaults , options ) ;
this . model = NEWSBLUR . AssetModel . reader ( ) ;
this . google _favicon _url = 'http://www.google.com/s2/favicons?domain_url=' ;
this . feed _id = feed _id ;
this . feed = this . model . get _feed ( feed _id ) ;
this . runner ( ) ;
} ;
NEWSBLUR . ReaderStatistics . prototype = {
runner : function ( ) {
this . make _modal ( ) ;
this . open _modal ( ) ;
this . get _stats ( ) ;
} ,
make _modal : function ( ) {
var self = this ;
this . $modal = $ . make ( 'div' , { className : 'NB-modal-statistics NB-modal' } , [
$ . make ( 'h2' , { className : 'NB-modal-title' } , 'Statistics & History' ) ,
$ . make ( 'h2' , { className : 'NB-modal-subtitle' } , [
$ . make ( 'img' , { className : 'NB-modal-statistics-feed-image feed_favicon' , src : this . google _favicon _url + this . feed . feed _link } ) ,
$ . make ( 'span' , { className : 'NB-modal-statistics-feed-title' } , this . feed . feed _title )
2010-07-26 22:21:58 -04:00
] ) ,
$ . make ( 'div' , { className : 'NB-modal-statistics-info' } )
2010-07-25 23:13:27 -04:00
] ) ;
} ,
open _modal : function ( ) {
var self = this ;
var $holder = $ . make ( 'div' , { className : 'NB-modal-holder' } ) . append ( this . $modal ) . appendTo ( 'body' ) . css ( { 'visibility' : 'hidden' , 'display' : 'block' , 'width' : 600 } ) ;
var height = $ ( '.NB-add' , $holder ) . outerHeight ( true ) ;
$holder . css ( { 'visibility' : 'visible' , 'display' : 'none' } ) ;
this . $modal . modal ( {
'minWidth' : 600 ,
'maxHeight' : height ,
2010-07-26 22:21:58 -04:00
'minHeight' : 340 ,
2010-07-25 23:13:27 -04:00
'overlayClose' : true ,
'onOpen' : function ( dialog ) {
dialog . overlay . fadeIn ( 200 , function ( ) {
dialog . container . fadeIn ( 200 ) ;
dialog . data . fadeIn ( 200 ) ;
} ) ;
} ,
'onShow' : function ( dialog ) {
2010-07-26 22:21:58 -04:00
$ ( '#simplemodal-container' ) . corner ( '6px' ) ;
2010-07-25 23:13:27 -04:00
$ . modal . impl . setPosition ( ) ;
} ,
'onClose' : function ( dialog ) {
dialog . data . hide ( ) . empty ( ) . remove ( ) ;
dialog . container . hide ( ) . empty ( ) . remove ( ) ;
dialog . overlay . fadeOut ( 200 , function ( ) {
dialog . overlay . empty ( ) . remove ( ) ;
$ . modal . close ( ) ;
} ) ;
$ ( '.NB-modal-holder' ) . empty ( ) . remove ( ) ;
}
} ) ;
} ,
get _stats : function ( ) {
this . model . get _feed _statistics ( this . feed _id , $ . rescope ( this . populate _stats , this ) ) ;
} ,
populate _stats : function ( s , data ) {
NEWSBLUR . log ( [ 'Stats' , data ] ) ;
2010-07-28 01:14:25 -04:00
var interval _start = data [ 'update_interval_minutes' ] ;
var interval _end = data [ 'update_interval_minutes' ] * 1.25 ;
var interval = '' ;
if ( interval _start < 60 ) {
interval = interval _start + ' to ' + interval _end + ' minutes' ;
} else {
var interval _start _hours = parseInt ( interval _start / 60 , 10 ) ;
var interval _end _hours = parseInt ( interval _end / 60 , 10 ) ;
var dec _start = interval _start % 60 ;
var dec _end = interval _end % 60 ;
interval = interval _start _hours + ( dec _start >= 30 ? '.5' : '' ) + ' to ' + interval _end _hours + ( dec _end >= 30 || interval _start _hours == interval _end _hours ? '.5' : '' ) + ' hours' ;
}
2010-07-26 22:21:58 -04:00
var $stats = $ . make ( 'div' , { className : 'NB-modal-statistics-info' } , [
2010-07-28 01:14:25 -04:00
$ . make ( 'div' , { className : 'NB-statistics-stat NB-statistics-updates' } , [
$ . make ( 'div' , { className : 'NB-statistics-update' } , [
$ . make ( 'div' , { className : 'NB-statistics-update-label' } , 'Last Update' ) ,
2010-07-28 18:18:01 -04:00
$ . make ( 'div' , { className : 'NB-statistics-update-count' } , data [ 'last_update' ] + ' ago' )
2010-07-28 01:14:25 -04:00
] ) ,
$ . make ( 'div' , { className : 'NB-statistics-update' } , [
2010-07-28 18:18:01 -04:00
$ . make ( 'div' , { className : 'NB-statistics-update-label' } , 'Every' ) ,
$ . make ( 'div' , { className : 'NB-statistics-update-count' } , interval )
2010-07-28 01:14:25 -04:00
] ) ,
$ . make ( 'div' , { className : 'NB-statistics-update' } , [
$ . make ( 'div' , { className : 'NB-statistics-update-label' } , 'Next Update' ) ,
2010-07-28 18:18:01 -04:00
$ . make ( 'div' , { className : 'NB-statistics-update-count' } , 'in ' + data [ 'next_update' ] )
2010-07-28 01:14:25 -04:00
] )
] ) ,
2010-07-26 22:21:58 -04:00
$ . make ( 'div' , { className : 'NB-statistics-stat' } , [
$ . make ( 'div' , { className : 'NB-statistics-count' } , '' + data [ 'subscriber_count' ] ) ,
$ . make ( 'div' , { className : 'NB-statistics-label' } , 'subscribers' )
] ) ,
$ . make ( 'div' , { className : 'NB-statistics-stat' } , [
$ . make ( 'div' , { className : 'NB-statistics-count' } , '' + data [ 'average_stories_per_month' ] ) ,
$ . make ( 'div' , { className : 'NB-statistics-label' } , ' stories per month' )
] )
] ) ;
$ ( '.NB-modal-statistics-info' , this . $modal ) . replaceWith ( $stats ) ;
setTimeout ( function ( ) {
$ . modal . impl . setPosition ( ) ;
} , 10 ) ;
2010-07-25 23:13:27 -04:00
}
} ;