2010-09-24 01:08:03 -04:00
NEWSBLUR . ReaderFeedchooser = function ( options ) {
2014-11-17 12:50:54 -08:00
options = options || { } ;
2013-04-25 17:57:33 -07:00
var defaults = {
2014-11-17 12:50:54 -08:00
'width' : options . premium _only || options . chooser _only ? 460 : 900 ,
2016-02-03 14:14:30 -08:00
'height' : 750 ,
2014-06-08 20:42:45 -07:00
'premium_only' : false ,
2014-11-17 12:50:54 -08:00
'chooser_only' : false ,
'onOpen' : _ . bind ( function ( ) {
this . resize _modal ( ) ;
} , this ) ,
'onClose' : _ . bind ( function ( ) {
if ( ! this . flags [ 'has_saved' ] && ! this . model . flags [ 'has_chosen_feeds' ] ) {
NEWSBLUR . reader . show _feed _chooser _button ( ) ;
}
dialog . data . hide ( ) . empty ( ) . remove ( ) ;
dialog . container . hide ( ) . empty ( ) . remove ( ) ;
dialog . overlay . fadeOut ( 200 , function ( ) {
dialog . overlay . empty ( ) . remove ( ) ;
$ . modal . close ( callback ) ;
} ) ;
$ ( '.NB-modal-holder' ) . empty ( ) . remove ( ) ;
} , this )
2013-04-25 17:57:33 -07:00
} ;
2010-10-15 18:38:49 -04:00
2010-09-24 01:08:03 -04:00
this . options = $ . extend ( { } , defaults , options ) ;
2012-05-17 18:40:46 -07:00
this . model = NEWSBLUR . assets ;
2010-09-24 01:08:03 -04:00
this . runner ( ) ;
} ;
2014-11-17 12:50:54 -08:00
NEWSBLUR . ReaderFeedchooser . prototype = new NEWSBLUR . Modal ;
NEWSBLUR . ReaderFeedchooser . prototype . constructor = NEWSBLUR . ReaderFeedchooser ;
_ . extend ( NEWSBLUR . ReaderFeedchooser . prototype , {
2010-09-24 01:08:03 -04:00
runner : function ( ) {
2014-10-09 20:58:03 -07:00
var self = this ;
2010-09-29 09:49:34 -04:00
this . start = new Date ( ) ;
2013-03-17 10:28:26 -07:00
this . MAX _FEEDS = 64 ;
2014-10-09 20:58:03 -07:00
NEWSBLUR . assets . feeds . each ( function ( feed ) {
self . add _feed _to _decline ( feed ) ;
} ) ;
2010-09-24 01:08:03 -04:00
this . make _modal ( ) ;
2010-10-16 18:52:52 -04:00
this . make _paypal _button ( ) ;
2014-11-17 12:50:54 -08:00
2013-04-25 17:57:33 -07:00
if ( ! this . options . premium _only ) {
2013-09-06 12:56:18 -07:00
this . initial _load _feeds ( ) ;
2012-12-05 11:56:55 -08:00
}
2014-10-09 20:58:03 -07:00
_ . defer ( _ . bind ( function ( ) { this . update _counts ( true ) ; } , this ) ) ;
2010-10-14 09:51:56 -04:00
this . flags = {
'has_saved' : false
} ;
2014-11-17 12:50:54 -08:00
this . open _modal ( ) ;
2010-10-14 09:51:56 -04:00
2013-04-25 17:57:33 -07:00
this . $modal . bind ( 'mousedown' , $ . rescope ( this . handle _mousedown , this ) ) ;
this . $modal . bind ( 'change' , $ . rescope ( this . handle _change , this ) ) ;
2010-09-24 01:08:03 -04:00
} ,
make _modal : function ( ) {
var self = this ;
2014-06-08 20:42:45 -07:00
this . $modal = $ . make ( 'div' , { className : 'NB-modal-feedchooser NB-modal ' + ( this . options . premium _only ? "NB-feedchooser-premium" : this . options . chooser _only ? "NB-feedchooser-chooser-only" : "NB-feedchooser-standard" ) } , [
2012-03-12 12:33:54 -07:00
// $.make('h2', { className: 'NB-modal-title' }, 'Choose Your '+this.MAX_FEEDS),
2014-06-08 20:42:45 -07:00
( ! this . options . chooser _only && $ . make ( 'div' , { className : 'NB-feedchooser-type NB-right' } , [
2013-04-25 17:57:33 -07:00
( ! this . options . premium _only && $ . make ( 'div' , { className : 'NB-feedchooser-porpoise' } , 'OR' ) ) ,
2012-12-05 11:56:55 -08:00
( NEWSBLUR . Globals . is _premium && $ . make ( 'div' , { className : 'NB-feedchooser-info' } , [
$ . make ( 'div' , { className : 'NB-feedchooser-info-type' } , [
$ . make ( 'span' , { className : 'NB-feedchooser-subtitle-type-prefix' } , 'Thank you' ) ,
' for going premium!'
] ) ,
$ . make ( 'h2' , { className : 'NB-modal-subtitle' } , [
2015-06-14 23:13:08 -07:00
'Your premium account is paid until:' ,
2012-12-05 11:56:55 -08:00
$ . make ( 'br' ) ,
$ . make ( 'b' , { style : 'display: block; margin: 8px 0' } , [
$ . make ( 'span' , { className : 'NB-raquo' } , '»' ) ,
' ' ,
2016-03-20 17:57:06 -07:00
NEWSBLUR . Globals . premium _expire && NEWSBLUR . utils . format _date ( NEWSBLUR . Globals . premium _expire ) ,
( ! NEWSBLUR . Globals . premium _expire && $ . make ( 'b' , "Never gonna expire. Congrats!" ) )
2012-12-05 11:56:55 -08:00
] ) ,
2014-06-10 12:14:22 -07:00
'You can change your payment method and card details. ' ,
( NEWSBLUR . Globals . premium _expire < new Date ) ?
'This will charge your card immediately.' :
'You won\'t be charged until this date.'
2012-12-05 11:56:55 -08:00
] )
] ) ) ,
( ! NEWSBLUR . Globals . is _premium && $ . make ( 'div' , { className : 'NB-feedchooser-info' } , [
2010-10-02 17:05:55 -04:00
$ . make ( 'div' , { className : 'NB-feedchooser-info-type' } , [
2018-07-24 10:49:45 -04:00
$ . make ( 'span' , { className : 'NB-feedchooser-subtitle-type-prefix' } , 'Unlimited' ) ,
2010-10-06 09:42:59 -04:00
' Premium Account'
2010-10-02 17:05:55 -04:00
] )
2012-12-05 11:56:55 -08:00
] ) ) ,
2010-10-02 17:05:55 -04:00
$ . make ( 'ul' , { className : 'NB-feedchooser-premium-bullets' } , [
2010-10-05 19:05:01 -04:00
$ . make ( 'li' , { className : 'NB-1' } , [
$ . make ( 'div' , { className : 'NB-feedchooser-premium-bullet-image' } ) ,
2012-07-11 00:43:53 -07:00
'Enable every site by going premium'
2010-10-02 17:05:55 -04:00
] ) ,
2010-10-05 19:05:01 -04:00
$ . make ( 'li' , { className : 'NB-2' } , [
$ . make ( 'div' , { className : 'NB-feedchooser-premium-bullet-image' } ) ,
2012-07-11 00:43:53 -07:00
'Sites updated up to 10x more often'
2010-10-05 19:05:01 -04:00
] ) ,
$ . make ( 'li' , { className : 'NB-3' } , [
2010-10-06 09:42:59 -04:00
$ . make ( 'div' , { className : 'NB-feedchooser-premium-bullet-image' } ) ,
2012-06-15 14:49:59 -07:00
'River of News (reading by folder)'
2010-10-06 09:42:59 -04:00
] ) ,
$ . make ( 'li' , { className : 'NB-4' } , [
2011-02-22 22:00:32 -05:00
$ . make ( 'div' , { className : 'NB-feedchooser-premium-bullet-image' } ) ,
2015-02-19 11:49:26 -08:00
'Search sites and folders'
2011-02-22 22:00:32 -05:00
] ) ,
$ . make ( 'li' , { className : 'NB-5' } , [
2010-10-05 19:05:01 -04:00
$ . make ( 'div' , { className : 'NB-feedchooser-premium-bullet-image' } ) ,
2015-02-19 11:49:26 -08:00
'Save stories with searchable tags'
2010-10-05 19:05:01 -04:00
] ) ,
2011-02-22 22:00:32 -05:00
$ . make ( 'li' , { className : 'NB-6' } , [
2015-02-19 11:49:26 -08:00
$ . make ( 'div' , { className : 'NB-feedchooser-premium-bullet-image' } ) ,
'Privacy options for your blurblog'
] ) ,
$ . make ( 'li' , { className : 'NB-7' } , [
$ . make ( 'div' , { className : 'NB-feedchooser-premium-bullet-image' } ) ,
2015-08-24 13:23:57 -07:00
'Custom RSS feeds for folders and saved stories'
2015-02-19 11:49:26 -08:00
] ) ,
$ . make ( 'li' , { className : 'NB-8' } , [
2015-08-24 13:23:57 -07:00
$ . make ( 'div' , { className : 'NB-feedchooser-premium-bullet-image' } ) ,
'Text view conveniently extracts the story'
] ) ,
$ . make ( 'li' , { className : 'NB-9' } , [
2010-10-23 12:13:27 -04:00
$ . make ( 'div' , { className : 'NB-feedchooser-premium-bullet-image' } ) ,
2020-11-12 20:28:03 -05:00
'You feed Lyric, my poor, hungry dog, for ' ,
2013-01-09 15:36:35 -08:00
$ . make ( 'span' , { className : 'NB-feedchooser-hungry-dog' } , '6 days' ) ,
2020-11-12 20:28:03 -05:00
$ . make ( 'img' , { className : 'NB-feedchooser-premium-poor-hungry-dog' , src : NEWSBLUR . Globals . MEDIA _URL + '/img/reader/lyric.jpg' } )
2010-09-24 01:08:03 -04:00
] )
2010-10-02 17:05:55 -04:00
] ) ,
2010-12-31 10:34:31 -05:00
$ . make ( 'div' , { className : 'NB-modal-submit NB-modal-submit-paypal' } , [
2017-11-10 15:43:25 -08:00
// $.make('div', { className: 'NB-feedchooser-payextra' }, [
// $.make('input', { type: 'checkbox', name: 'payextra', id: 'NB-feedchooser-payextra-checkbox' }),
// $.make('label', { 'for': 'NB-feedchooser-payextra-checkbox' }, 'I\'m feeling generous')
// ]),
2010-12-31 10:34:31 -05:00
$ . make ( 'div' , { className : 'NB-feedchooser-dollar' } , [
2017-11-10 15:43:25 -08:00
// $.make('div', { className: 'NB-feedchooser-dollar-value NB-2' }, [
// $.make('div', { className: 'NB-feedchooser-dollar-month' }, [
// $.make('div', { className: 'NB-feedchooser-dollar-image' }, [
// $.make('img', { src: NEWSBLUR.Globals.MEDIA_URL + '/img/icons/circular/g_icn_coffeecup_gold16.png', style: "position: absolute; left: -56px;top: 15px;width: 16px;" }),
// $.make('img', { src: NEWSBLUR.Globals.MEDIA_URL + '/img/icons/circular/g_icn_coffeecup_gold24.png', style: "position: absolute; left: -31px;top: 10px; width: 24px;" }),
// $.make('img', { src: NEWSBLUR.Globals.MEDIA_URL + '/img/icons/circular/g_icn_coffeecup_gold32.png', style: "position: absolute; left: 0; top: 6px; width: 32px" })
// ]),
// '$24/year'
// ]),
// $.make('div', { className: 'NB-feedchooser-dollar-year' }, '($2/month)')
// ]),
2011-03-02 17:58:12 -05:00
$ . make ( 'div' , { className : 'NB-feedchooser-dollar-value NB-3' } , [
2012-02-29 12:15:01 -08:00
$ . make ( 'div' , { className : 'NB-feedchooser-dollar-month' } , [
2012-07-20 19:43:28 -07:00
$ . make ( 'div' , { className : 'NB-feedchooser-dollar-image' } , [
2013-04-25 17:57:33 -07:00
$ . make ( 'img' , { src : NEWSBLUR . Globals . MEDIA _URL + '/img/icons/circular/g_icn_coffeecup_gold24.png' , style : "position: absolute; left: -68px;top: 11px;width: 24px;" } ) ,
$ . make ( 'img' , { src : NEWSBLUR . Globals . MEDIA _URL + '/img/icons/circular/g_icn_coffeecup_gold32.png' , style : "position: absolute; left: -42px;top: 7px; width: 32px;" } ) ,
$ . make ( 'img' , { src : NEWSBLUR . Globals . MEDIA _URL + '/img/icons/circular/g_icn_coffeecup_gold40.png' , style : "position: absolute; left: -8px; top: 4px; width: 40px" } )
2012-07-20 19:43:28 -07:00
] ) ,
2012-02-29 12:15:01 -08:00
'$36/year'
] ) ,
2011-09-30 18:02:48 -07:00
$ . make ( 'div' , { className : 'NB-feedchooser-dollar-year' } , '($3/month)' )
2011-02-07 23:41:25 -05:00
] )
2012-02-29 12:15:01 -08:00
] ) ,
$ . make ( 'div' , { className : 'NB-feedchooser-processor' } , [
$ . make ( 'div' , { className : 'NB-feedchooser-paypal' } , [
$ . make ( 'img' , { src : NEWSBLUR . Globals . MEDIA _URL + '/img/reader/logo-paypal.png' , height : 30 } ) ,
$ . make ( 'div' , { className : 'NB-feedchooser-paypal-form' } )
] ) ,
$ . make ( 'div' , { className : 'NB-feedchooser-stripe' } , [
$ . make ( 'div' , { className : 'NB-creditcards' } , [
2013-04-19 09:51:30 -07:00
$ . make ( 'img' , { src : NEWSBLUR . Globals . MEDIA _URL + "/img/reader/cc_visa.png" } ) ,
$ . make ( 'img' , { src : NEWSBLUR . Globals . MEDIA _URL + "/img/reader/cc_mastercard.png" } ) ,
$ . make ( 'img' , { src : NEWSBLUR . Globals . MEDIA _URL + "/img/reader/cc_amex.png" } ) ,
$ . make ( 'img' , { src : NEWSBLUR . Globals . MEDIA _URL + "/img/reader/cc_discover.png" } )
2012-02-29 12:15:01 -08:00
] ) ,
$ . make ( 'div' , {
className : "NB-stripe-button NB-modal-submit-button NB-modal-submit-green"
} , [
2018-05-03 15:38:59 -07:00
( this . options . renew ? "Renew by" : "Pay by" ) ,
2012-02-29 12:15:01 -08:00
$ . make ( 'br' ) ,
"Credit Card"
] )
2011-02-07 23:41:25 -05:00
] )
2010-12-31 10:34:31 -05:00
] )
2010-10-02 17:05:55 -04:00
] )
2014-06-08 20:42:45 -07:00
] ) ) ,
2013-04-25 17:57:33 -07:00
( ! this . options . premium _only && $ . make ( 'div' , { className : 'NB-feedchooser-type NB-feedchooser-left' } , [
2014-06-08 20:42:45 -07:00
( ! NEWSBLUR . Globals . is _premium && $ . make ( 'div' , { className : 'NB-feedchooser-info' } , [
2013-04-25 17:57:33 -07:00
$ . make ( 'div' , { className : 'NB-feedchooser-info-type' } , [
$ . make ( 'span' , { className : 'NB-feedchooser-subtitle-type-prefix' } , 'Free' ) ,
' Standard Account'
] ) ,
$ . make ( 'h2' , { className : 'NB-modal-subtitle' } , [
$ . make ( 'b' , [
'You can follow up to ' + this . MAX _FEEDS + ' sites.'
] ) ,
$ . make ( 'br' ) ,
'You can always change these.'
] ) ,
$ . make ( 'div' , { className : 'NB-feedchooser-info-counts' } ) ,
$ . make ( 'div' , { className : 'NB-feedchooser-info-sort' } , 'Auto-Selected By Popularity' ) ,
$ . make ( 'div' , { className : 'NB-feedchooser-info-reset NB-splash-link' } , 'Reset to popular sites' )
2014-06-08 20:42:45 -07:00
] ) ) ,
( this . options . chooser _only && $ . make ( 'div' , { className : 'NB-feedchooser-info' } , [
$ . make ( 'h2' , { className : 'NB-modal-title' } , [
$ . make ( 'div' , { className : 'NB-icon' } ) ,
2016-02-03 10:38:54 -08:00
'Mute sites' ,
2014-06-08 20:42:45 -07:00
$ . make ( 'div' , { className : 'NB-icon-dropdown' } )
] ) ,
$ . make ( 'div' , { className : 'NB-feedchooser-info-reset NB-splash-link' } , 'Turn every site on' ) ,
$ . make ( 'div' , { className : 'NB-feedchooser-info-counts' } )
] ) ) ,
2013-04-25 17:57:33 -07:00
this . make _feeds ( ) ,
$ . make ( 'form' , { className : 'NB-feedchooser-form' } , [
$ . make ( 'div' , { className : 'NB-modal-submit' } , [
// $.make('div', { className: 'NB-modal-submit-or' }, 'or'),
$ . make ( 'input' , { type : 'submit' , disabled : 'true' , className : 'NB-disabled NB-modal-submit-button NB-modal-submit-save NB-modal-submit-green' , value : 'Check what you like above...' } ) ,
$ . make ( 'input' , { type : 'submit' , className : 'NB-modal-submit-add NB-modal-submit-button NB-modal-submit-green' , value : 'First, add sites' } )
] )
] ) . bind ( 'submit' , function ( e ) {
e . preventDefault ( ) ;
return false ;
} )
] ) )
2010-09-24 01:08:03 -04:00
] ) ;
} ,
2010-10-16 18:52:52 -04:00
make _paypal _button : function ( ) {
2011-02-07 23:41:25 -05:00
var self = this ;
2012-02-29 12:15:01 -08:00
var $paypal = $ ( '.NB-feedchooser-paypal-form' , this . $modal ) ;
2011-02-07 23:41:25 -05:00
$ . get ( '/profile/paypal_form' , function ( response ) {
$paypal . html ( response ) ;
2017-11-10 15:43:25 -08:00
self . choose _dollar _amount ( 3 ) ;
2011-02-07 23:41:25 -05:00
} ) ;
2010-10-16 18:52:52 -04:00
} ,
make _google _button : function ( ) {
var checkout = '<script type="text/javascript" src="https://images-na.ssl-images-amazon.com/images/G/01/cba/js/widget/widget.js"></script><form method=POST action="https://payments.amazon.com/checkout/A215TOHXICT770"><input type="hidden" name="order-input" value="type:cba-signed-order/sha1-hmac/1;order:PD94bWwgdmVyc2lvbj0nMS4wJyBlbmNvZGluZz0nVVRGLTgnPz48T3JkZXIgeG1sbnM9J2h0dHA6Ly9wYXltZW50cy5hbWF6b24uY29tL2NoZWNrb3V0LzIwMDgtMTEtMzAvJz48Q2FydD48SXRlbXM+PEl0ZW0+PE1lcmNoYW50SWQ+QTIxNVRPSFhJQ1Q3NzA8L01lcmNoYW50SWQ+PFRpdGxlPk5ld3NCbHVyIFByZW1pdW0gLSAxIFllYXI8L1RpdGxlPjxEZXNjcmlwdGlvbj5UaGFuayB5b3UsIHRoYW5rIHlvdSwgdGhhbmsgeW91ITwvRGVzY3JpcHRpb24+PFByaWNlPjxBbW91bnQ+MTI8L0Ftb3VudD48Q3VycmVuY3lDb2RlPlVTRDwvQ3VycmVuY3lDb2RlPjwvUHJpY2U+PFF1YW50aXR5PjE8L1F1YW50aXR5PjxGdWxmaWxsbWVudE5ldHdvcms+TUVSQ0hBTlQ8L0Z1bGZpbGxtZW50TmV0d29yaz48L0l0ZW0+PC9JdGVtcz48L0NhcnQ+PC9PcmRlcj4=;signature:Zfg83JluKTIhItevtaGpspjdbfQ="><input alt="Checkout with Amazon Payments" src="https://payments.amazon.com/gp/cba/button?ie=UTF8&color=tan&background=white&cartOwnerId=A215TOHXICT770&size=large" type="image"></form>' ;
2010-10-05 19:05:01 -04:00
var $checkout = $ ( checkout ) ;
return $checkout ;
} ,
2010-09-24 01:08:03 -04:00
make _feeds : function ( ) {
var feeds = this . model . feeds ;
2017-01-09 14:19:19 -08:00
this . feed _count = _ . unique ( NEWSBLUR . assets . folders . feed _ids _in _folder ( { include _inactive : true } ) ) . length ;
2012-06-15 14:49:59 -07:00
2014-10-09 20:58:03 -07:00
this . feedlist = new NEWSBLUR . Views . FeedList ( {
feed _chooser : true ,
sorting : this . options . sorting
} ) . make _feeds ( ) ;
var $feeds = this . feedlist . $el ;
if ( this . options . resize ) {
$feeds . css ( { 'max-height' : this . options . resize } ) ;
}
2011-04-24 20:42:42 -04:00
if ( $feeds . data ( 'sortable' ) ) $feeds . data ( 'sortable' ) . disable ( ) ;
2010-09-24 01:08:03 -04:00
2010-09-28 18:53:57 -04:00
// Expand collapsed folders
2012-06-15 14:49:59 -07:00
$ ( '.NB-folder-collapsed' , $feeds ) . css ( {
2010-09-28 18:53:57 -04:00
'display' : 'block' ,
'opacity' : 1
2012-06-15 14:49:59 -07:00
} ) . removeClass ( 'NB-folder-collapsed' ) ;
2010-09-28 18:53:57 -04:00
2010-10-02 17:05:55 -04:00
// Pretend unfetched feeds are fine
$ ( '.NB-feed-unfetched' , $feeds ) . removeClass ( 'NB-feed-unfetched' ) ;
2014-05-21 23:41:44 +01:00
// Make sure all folders are visible
$ ( '.NB-folder.NB-hidden' , $feeds ) . removeClass ( 'NB-hidden' ) ;
2014-10-09 20:58:03 -07:00
NEWSBLUR . assets . folders . sort ( ) ;
NEWSBLUR . assets . feeds . off ( 'change:highlighted' )
. on ( 'change:highlighted' , _ . bind ( this . change _selection , this ) ) ;
2010-10-02 17:05:55 -04:00
2010-09-28 18:53:57 -04:00
2010-09-24 01:08:03 -04:00
return $feeds ;
} ,
2012-06-15 14:49:59 -07:00
2010-10-02 17:05:55 -04:00
resize _modal : function ( previous _height ) {
2012-10-26 18:10:23 -07:00
var content _height = $ ( '.NB-feedchooser-left' , this . $modal ) . height ( ) + 32 ;
var container _height = this . $modal . parent ( ) . height ( ) ;
if ( content _height > container _height && previous _height != content _height ) {
2010-10-02 17:05:55 -04:00
var chooser _height = $ ( '#NB-feedchooser-feeds' ) . height ( ) ;
2012-10-26 18:10:23 -07:00
var diff = Math . max ( 4 , content _height - container _height ) ;
2010-10-02 17:05:55 -04:00
$ ( '#NB-feedchooser-feeds' ) . css ( { 'max-height' : chooser _height - diff } ) ;
2012-10-26 18:10:23 -07:00
_ . defer ( _ . bind ( function ( ) { this . resize _modal ( content _height ) ; } , this ) , 1 ) ;
2010-10-02 17:05:55 -04:00
}
} ,
2014-11-17 16:42:24 -08:00
add _feed _to _decline : function ( feed , update ) {
2014-11-17 16:41:37 -08:00
feed . highlight _in _all _folders ( false , true , { silent : ! update } ) ;
2012-07-26 18:24:41 -07:00
2010-09-29 09:49:34 -04:00
if ( update ) {
this . update _counts ( ) ;
}
2010-09-24 01:08:03 -04:00
} ,
2014-10-14 17:35:08 -07:00
add _feed _to _approve : function ( feed , update ) {
2014-10-09 20:58:03 -07:00
feed . highlight _in _all _folders ( true , false , { silent : false } ) ;
2010-10-02 17:05:55 -04:00
if ( update ) {
this . update _counts ( ) ;
2010-09-24 01:08:03 -04:00
}
} ,
2010-10-16 19:43:18 -04:00
2014-10-09 20:58:03 -07:00
change _selection : function ( update ) {
this . update _counts ( ) ;
2010-09-24 01:08:03 -04:00
} ,
2014-10-09 20:58:03 -07:00
2012-06-15 15:14:16 -07:00
update _counts : function ( initial _load ) {
2016-12-08 16:32:59 -08:00
if ( this . options . premium _only ) return ;
2010-09-24 01:08:03 -04:00
var $count = $ ( '.NB-feedchooser-info-counts' ) ;
2014-10-09 20:58:03 -07:00
var approved = this . feedlist . folder _view . highlighted _count ( ) ;
2010-09-27 11:43:08 -04:00
var $submit = $ ( '.NB-modal-submit-save' , this . $modal ) ;
var difference = approved - this . MAX _FEEDS ;
2014-06-08 20:42:45 -07:00
var muted = this . feed _count - approved ;
2010-09-24 01:08:03 -04:00
2011-08-26 19:58:06 -07:00
$count . text ( approved + '/' + Inflector . commas ( this . feed _count ) ) ;
2014-06-08 20:42:45 -07:00
if ( NEWSBLUR . Globals . is _premium ) {
$submit . removeClass ( 'NB-disabled' ) . removeClass ( 'NB-modal-submit-grey' ) . attr ( 'disabled' , false ) ;
if ( muted == 0 ) {
$submit . val ( 'Enable all ' + Inflector . pluralize ( 'site' , this . feed _count , true ) ) ;
} else {
$submit . val ( 'Mute ' + Inflector . pluralize ( 'site' , muted , true ) ) ;
}
$count . toggleClass ( 'NB-full' , muted == 0 ) ;
2010-09-27 11:43:08 -04:00
} else {
2014-06-08 20:42:45 -07:00
$count . toggleClass ( 'NB-full' , approved == this . MAX _FEEDS ) ;
$count . toggleClass ( 'NB-error' , approved > this . MAX _FEEDS ) ;
if ( ! initial _load ) {
this . hide _autoselected _label ( ) ;
}
if ( approved > this . MAX _FEEDS ) {
$submit . addClass ( 'NB-disabled' ) . addClass ( 'NB-modal-submit-grey' ) . attr ( 'disabled' , true ) . val ( 'Too many sites! Deselect ' + (
difference == 1 ?
'1 site...' :
difference + ' sites...'
) ) ;
} else {
$submit . removeClass ( 'NB-disabled' ) . removeClass ( 'NB-modal-submit-grey' ) . attr ( 'disabled' , false ) . val ( 'Turn on these ' + approved + ' sites, please' ) ;
}
2010-09-27 11:43:08 -04:00
}
2010-09-24 01:08:03 -04:00
} ,
2012-06-15 15:14:16 -07:00
initial _load _feeds : function ( reset ) {
2010-09-29 09:49:34 -04:00
var start = new Date ( ) ;
2010-09-24 01:08:03 -04:00
var self = this ;
2010-09-28 18:53:57 -04:00
var feeds = this . model . get _feeds ( ) ;
2014-10-09 20:58:03 -07:00
var approved = 0 ; // this.feedlist.folder_view.highlighted_count();
2012-06-15 14:49:59 -07:00
if ( ! feeds . size ( ) ) {
2010-12-23 14:18:40 -05:00
_ . defer ( _ . bind ( function ( ) {
var $info = $ ( '.NB-feedchooser-info' , this . $modal ) ;
$ ( '.NB-feedchooser-info-counts' , $info ) . hide ( ) ;
$ ( '.NB-feedchooser-info-sort' , $info ) . hide ( ) ;
2012-06-15 15:14:16 -07:00
$ ( '.NB-feedchooser-info-reset' , $info ) . hide ( ) ;
2010-12-23 14:18:40 -05:00
$ ( '#NB-feedchooser-feeds' ) . hide ( ) ;
$ ( '.NB-modal-submit-save' ) . hide ( ) ;
$ ( '.NB-modal-submit-add' ) . show ( ) ;
} , this ) ) ;
return ;
}
2014-10-09 20:58:03 -07:00
if ( reset ) {
feeds . each ( function ( feed ) {
2014-10-14 17:35:08 -07:00
self . add _feed _to _decline ( feed , true ) ;
2014-10-09 20:58:03 -07:00
} ) ;
}
2012-05-21 20:08:27 -07:00
var active _feeds = feeds . any ( function ( feed ) { return feed . get ( 'active' ) ; } ) ;
2012-06-15 15:14:16 -07:00
if ( ! active _feeds || reset ) {
2012-06-15 14:49:59 -07:00
// Get feed subscribers bottom cut-off
2010-09-28 18:53:57 -04:00
var min _subscribers = _ . last (
_ . first (
2012-06-15 14:49:59 -07:00
_ . map ( feeds . select ( function ( f ) { return ! f . has _exception ; } ) , function ( f ) { return f . get ( 'subs' ) ; } ) . sort ( function ( a , b ) {
2010-09-28 18:53:57 -04:00
return b - a ;
} ) ,
this . MAX _FEEDS
)
) ;
2010-09-24 18:22:12 -04:00
2010-09-28 18:53:57 -04:00
// Decline everything
2010-09-29 09:49:34 -04:00
var approve _feeds = [ ] ;
2012-06-15 14:49:59 -07:00
feeds . each ( function ( feed ) {
2014-10-14 17:35:08 -07:00
// self.add_feed_to_decline(feed);
2010-09-24 18:22:12 -04:00
2012-05-21 20:08:27 -07:00
if ( feed . get ( 'subs' ) >= min _subscribers ) {
2014-10-14 17:35:08 -07:00
approve _feeds . push ( feed ) ;
2010-09-28 18:53:57 -04:00
}
} ) ;
2010-09-24 18:22:12 -04:00
2010-09-28 18:53:57 -04:00
// Approve feeds in subs
2014-10-14 17:35:08 -07:00
_ . each ( approve _feeds , function ( feed ) {
if ( feed . get ( 'subs' ) > min _subscribers &&
2014-10-09 20:58:03 -07:00
approved < self . MAX _FEEDS &&
2014-10-14 17:35:08 -07:00
! feed . get ( 'has_exception' ) ) {
2014-10-09 20:58:03 -07:00
approved ++ ;
2014-10-14 17:35:08 -07:00
self . add _feed _to _approve ( feed ) ;
2010-09-28 18:53:57 -04:00
}
} ) ;
2014-10-14 17:35:08 -07:00
_ . each ( approve _feeds , function ( feed ) {
if ( feed . get ( 'subs' ) == min _subscribers &&
2014-10-09 20:58:03 -07:00
approved < self . MAX _FEEDS ) {
approved ++ ;
2014-10-14 17:35:08 -07:00
self . add _feed _to _approve ( feed ) ;
2010-09-28 18:53:57 -04:00
}
} ) ;
2012-06-15 15:14:16 -07:00
this . show _autoselected _label ( ) ;
2010-09-28 18:53:57 -04:00
} else {
// Get active feeds
2014-10-14 17:35:08 -07:00
var active _feeds = feeds . select ( function ( feed ) {
2012-05-21 20:08:27 -07:00
return feed . get ( 'active' ) ;
2014-10-14 17:35:08 -07:00
} ) ;
2010-09-28 18:53:57 -04:00
// Approve or decline
2014-10-14 17:35:08 -07:00
_ . each ( active _feeds , function ( feed ) {
self . add _feed _to _approve ( feed ) ;
2010-09-28 18:53:57 -04:00
} ) ;
2012-06-15 15:14:16 -07:00
_ . defer ( _ . bind ( function ( ) { this . hide _autoselected _label ( ) ; } , this ) ) ;
2010-09-28 18:53:57 -04:00
}
2012-06-15 15:14:16 -07:00
_ . defer ( _ . bind ( function ( ) { this . update _counts ( true ) ; } , this ) ) ;
} ,
show _autoselected _label : function ( ) {
$ ( '.NB-feedchooser-info-reset' , this . $modal ) . fadeOut ( 500 , _ . bind ( function ( ) {
$ ( '.NB-feedchooser-info-sort' , this . $modal ) . fadeIn ( 500 ) ;
} , this ) ) ;
} ,
hide _autoselected _label : function ( ) {
$ ( '.NB-feedchooser-info-sort' , this . $modal ) . fadeOut ( 500 , _ . bind ( function ( ) {
$ ( '.NB-feedchooser-info-sort' , this . $modal ) . hide ( ) ;
$ ( '.NB-feedchooser-info-reset' , this . $modal ) . fadeIn ( 500 ) ;
} , this ) ) ;
2010-09-28 18:53:57 -04:00
} ,
save : function ( ) {
2010-10-14 09:51:56 -04:00
var self = this ;
2010-09-28 18:53:57 -04:00
var $submit = $ ( '.NB-modal-submit-save' , this . $modal ) ;
2012-03-19 19:18:19 -07:00
$submit . addClass ( 'NB-disabled' ) . removeClass ( 'NB-modal-submit-green' ) . val ( 'Saving...' ) ;
2014-10-09 20:58:03 -07:00
var approve _list = _ . pluck ( NEWSBLUR . assets . feeds . filter ( function ( feed ) {
return feed . get ( 'highlighted' ) ;
} ) , 'id' ) ;
console . log ( [ "Saving" , approve _list ] ) ;
2013-09-13 16:35:48 -07:00
NEWSBLUR . reader . flags [ 'reloading_feeds' ] = true ;
2010-10-02 17:05:55 -04:00
this . model . save _feed _chooser ( approve _list , function ( ) {
2010-10-14 09:51:56 -04:00
self . flags [ 'has_saved' ] = true ;
2013-09-13 16:35:48 -07:00
NEWSBLUR . reader . flags [ 'reloading_feeds' ] = false ;
2010-10-02 17:05:55 -04:00
NEWSBLUR . reader . hide _feed _chooser _button ( ) ;
2012-06-15 14:49:59 -07:00
NEWSBLUR . assets . load _feeds ( ) ;
2010-09-28 18:53:57 -04:00
$ . modal . close ( ) ;
2010-09-24 01:08:03 -04:00
} ) ;
} ,
2010-12-23 14:18:40 -05:00
close _and _add : function ( ) {
$ . modal . close ( function ( ) {
NEWSBLUR . add _feed = new NEWSBLUR . ReaderAddFeed ( ) ;
} ) ;
} ,
2012-02-29 12:15:01 -08:00
open _stripe _form : function ( ) {
2018-05-03 15:38:59 -07:00
var renew = ( this . options . renew ? "&renew=true" : "" ) ;
2021-03-25 16:24:57 -04:00
window . location . href = "/profile/stripe_form?plan=" + this . plan + renew ;
2012-02-29 12:15:01 -08:00
} ,
choose _dollar _amount : function ( plan ) {
2011-03-02 17:58:12 -05:00
var $value = $ ( '.NB-feedchooser-dollar-value' , this . $modal ) ;
2011-02-07 23:41:25 -05:00
var $input = $ ( 'input[name=a3]' ) ;
2012-06-15 14:49:59 -07:00
var $days = $ ( '.NB-feedchooser-hungry-dog' , this . $modal ) ;
2012-02-29 12:15:01 -08:00
this . plan = plan ;
2011-03-02 17:58:12 -05:00
$value . removeClass ( 'NB-selected' ) ;
2012-02-29 12:15:01 -08:00
$value . filter ( '.NB-' + plan ) . addClass ( 'NB-selected' ) ;
if ( plan == 1 ) {
2011-02-07 23:41:25 -05:00
$input . val ( 12 ) ;
2012-06-15 14:49:59 -07:00
$days . text ( '6 days' ) ;
2012-02-29 12:15:01 -08:00
} else if ( plan == 2 ) {
2011-03-02 17:58:12 -05:00
$input . val ( 24 ) ;
2012-06-15 14:49:59 -07:00
$days . text ( '12 days' ) ;
2012-02-29 12:15:01 -08:00
} else if ( plan == 3 ) {
2011-03-02 17:58:12 -05:00
$input . val ( 36 ) ;
2012-06-15 14:49:59 -07:00
$days . text ( '18 days' ) ;
2011-02-07 23:41:25 -05:00
}
} ,
2013-04-25 17:57:33 -07:00
switch _payextra : function ( ) {
var $payextra = $ ( "input[name=payextra]" , this . $modal ) ;
var selected = $payextra . is ( ':checked' ) ;
if ( selected ) {
this . choose _dollar _amount ( 3 ) ;
} else {
this . choose _dollar _amount ( 2 ) ;
}
} ,
2010-09-24 01:08:03 -04:00
// ===========
// = Actions =
// ===========
2013-04-25 17:57:33 -07:00
handle _mousedown : function ( elem , e ) {
2010-09-24 01:08:03 -04:00
var self = this ;
2010-09-27 11:43:08 -04:00
$ . targetIs ( e , { tagSelector : '.NB-modal-submit-save' } , _ . bind ( function ( $t , $p ) {
e . preventDefault ( ) ;
2010-09-28 18:53:57 -04:00
this . save ( ) ;
2010-09-27 11:43:08 -04:00
} , this ) ) ;
2011-03-02 17:58:12 -05:00
2010-12-23 14:18:40 -05:00
$ . targetIs ( e , { tagSelector : '.NB-modal-submit-add' } , _ . bind ( function ( $t , $p ) {
e . preventDefault ( ) ;
this . close _and _add ( ) ;
} , this ) ) ;
2011-03-02 17:58:12 -05:00
2012-02-29 12:15:01 -08:00
$ . targetIs ( e , { tagSelector : '.NB-stripe-button' } , _ . bind ( function ( $t , $p ) {
e . preventDefault ( ) ;
this . open _stripe _form ( ) ;
} , this ) ) ;
2012-06-15 15:14:16 -07:00
$ . targetIs ( e , { tagSelector : '.NB-feedchooser-info-reset' } , _ . bind ( function ( $t , $p ) {
e . preventDefault ( ) ;
this . initial _load _feeds ( true ) ;
} , this ) ) ;
2011-03-02 17:58:12 -05:00
$ . targetIs ( e , { tagSelector : '.NB-feedchooser-dollar-value' } , _ . bind ( function ( $t , $p ) {
e . preventDefault ( ) ;
var step ;
if ( $t . hasClass ( 'NB-1' ) ) {
step = 1 ;
} else if ( $t . hasClass ( 'NB-2' ) ) {
step = 2 ;
} else if ( $t . hasClass ( 'NB-3' ) ) {
step = 3 ;
}
this . choose _dollar _amount ( step ) ;
} , this ) ) ;
2010-09-24 01:08:03 -04:00
} ,
2013-04-25 17:57:33 -07:00
handle _change : function ( elem , e ) {
$ . targetIs ( e , { tagSelector : 'input[name=payextra]' } , _ . bind ( function ( $t , $p ) {
e . preventDefault ( ) ;
this . switch _payextra ( ) ;
} , this ) ) ;
} ,
2010-09-24 01:08:03 -04:00
handle _cancel : function ( ) {
var $cancel = $ ( '.NB-modal-cancel' , this . $modal ) ;
$cancel . click ( function ( e ) {
e . preventDefault ( ) ;
$ . modal . close ( ) ;
} ) ;
}
2014-11-17 12:50:54 -08:00
} ) ;