2010-08-01 19:12:42 -04:00
NEWSBLUR . ReaderClassifierTrainer = function ( options ) {
var defaults = {
'training' : true
} ;
this . flags = {
'publisher' : true ,
2010-09-21 09:18:58 -04:00
'story' : false ,
'modal_loading' : false ,
'modal_loaded' : false
2010-08-01 19:12:42 -04:00
} ;
this . cache = { } ;
2010-10-21 13:37:36 -04:00
this . trainer _iterator = - 1 ;
2010-08-01 19:12:42 -04:00
this . feed _id = null ;
this . options = $ . extend ( { } , defaults , options ) ;
2012-05-17 18:40:46 -07:00
this . model = NEWSBLUR . assets ;
2010-08-01 19:12:42 -04:00
this . runner _trainer ( ) ;
} ;
NEWSBLUR . ReaderClassifierFeed = function ( feed _id , options ) {
var defaults = {
2010-09-17 12:40:42 -04:00
'training' : false ,
'feed_loaded' : true
2010-08-01 19:12:42 -04:00
} ;
2010-06-08 11:19:41 -04:00
this . flags = {
'publisher' : true ,
2010-09-21 09:18:58 -04:00
'story' : false ,
'modal_loading' : false ,
'modal_loaded' : false
2010-06-08 11:19:41 -04:00
} ;
2010-09-17 12:40:42 -04:00
this . cache = { } ;
2010-06-08 11:19:41 -04:00
this . feed _id = feed _id ;
2010-10-21 13:37:36 -04:00
this . trainer _iterator = - 1 ;
2010-06-08 11:19:41 -04:00
this . options = $ . extend ( { } , defaults , options ) ;
2012-05-17 18:40:46 -07:00
this . model = NEWSBLUR . assets ;
2010-06-08 11:19:41 -04:00
this . runner _feed ( ) ;
} ;
2010-08-01 19:12:42 -04:00
NEWSBLUR . ReaderClassifierStory = function ( story _id , feed _id , options ) {
var defaults = {
2010-12-04 16:42:51 -05:00
'feed_loaded' : true
2010-08-01 19:12:42 -04:00
} ;
2010-06-08 11:19:41 -04:00
this . flags = {
'publisher' : false ,
2010-09-21 09:18:58 -04:00
'story' : true ,
'modal_loading' : false ,
'modal_loaded' : false
2010-06-08 11:19:41 -04:00
} ;
2010-12-04 16:42:51 -05:00
this . cache = { } ;
2010-06-08 11:19:41 -04:00
this . story _id = story _id ;
this . feed _id = feed _id ;
2010-12-04 16:42:51 -05:00
this . trainer _iterator = - 1 ;
2010-06-08 11:19:41 -04:00
this . options = $ . extend ( { } , defaults , options ) ;
2012-05-17 18:40:46 -07:00
this . model = NEWSBLUR . assets ;
2010-06-08 11:19:41 -04:00
this . runner _story ( ) ;
} ;
2010-10-19 20:57:25 -04:00
var classifier _prototype = {
2010-06-08 11:19:41 -04:00
2010-10-29 11:34:33 -04:00
runner _trainer : function ( reload ) {
if ( ! reload ) {
this . user _classifiers = { } ;
}
2010-08-01 19:12:42 -04:00
this . make _trainer _intro ( ) ;
this . get _feeds _trainer ( ) ;
this . handle _cancel ( ) ;
this . open _modal ( ) ;
this . $modal . parent ( ) . bind ( 'click.reader_classifer' , $ . rescope ( this . handle _clicks , this ) ) ;
} ,
2010-06-08 11:19:41 -04:00
runner _feed : function ( ) {
2012-02-13 11:07:32 -08:00
this . options . social _feed = _ . string . include ( this . feed _id , 'social:' ) ;
2011-10-24 08:55:28 -07:00
if ( ! this . model . classifiers [ this . feed _id ] ) {
this . model . classifiers [ this . feed _id ] = _ . extend ( { } , this . model . defaults [ 'classifiers' ] ) ;
}
2010-08-01 19:12:42 -04:00
2010-09-17 12:40:42 -04:00
if ( this . options . feed _loaded ) {
2011-10-24 08:55:28 -07:00
this . user _classifiers = this . model . classifiers [ this . feed _id ] ;
2010-09-17 12:40:42 -04:00
} else {
this . user _classifiers = { } ;
}
2010-09-21 09:18:58 -04:00
this . find _story _and _feed ( ) ;
this . make _modal _feed ( ) ;
this . make _modal _title ( ) ;
2010-06-08 11:19:41 -04:00
this . handle _cancel ( ) ;
this . open _modal ( ) ;
2010-10-19 22:41:30 -04:00
this . $modal . parent ( ) . bind ( 'click.reader_classifer' , $ . rescope ( this . handle _clicks , this ) ) ;
2010-09-21 09:18:58 -04:00
if ( ! this . options . feed _loaded ) {
_ . defer ( _ . bind ( function ( ) {
this . load _single _feed _trainer ( ) ;
} , this ) ) ;
}
2010-06-08 11:19:41 -04:00
} ,
runner _story : function ( ) {
2011-10-24 08:55:28 -07:00
if ( ! this . model . classifiers [ this . feed _id ] ) {
this . model . classifiers [ this . feed _id ] = _ . extend ( { } , this . model . defaults [ 'classifiers' ] ) ;
}
2010-12-04 16:42:51 -05:00
if ( this . options . feed _loaded ) {
2011-10-24 08:55:28 -07:00
this . user _classifiers = this . model . classifiers [ this . feed _id ] ;
2010-12-04 16:42:51 -05:00
} else {
this . user _classifiers = { } ;
}
2010-08-01 19:12:42 -04:00
2010-06-08 11:19:41 -04:00
this . find _story _and _feed ( ) ;
this . make _modal _story ( ) ;
this . handle _text _highlight ( ) ;
2010-11-09 22:06:08 -05:00
this . make _modal _title ( ) ;
2010-06-08 11:19:41 -04:00
this . handle _cancel ( ) ;
this . open _modal ( ) ;
2010-10-19 22:41:30 -04:00
this . $modal . parent ( ) . bind ( 'click.reader_classifer' , $ . rescope ( this . handle _clicks , this ) ) ;
2010-12-04 16:42:51 -05:00
if ( ! this . options . feed _loaded ) {
_ . defer ( _ . bind ( function ( ) {
this . load _single _feed _trainer ( ) ;
} , this ) ) ;
}
2010-06-08 11:19:41 -04:00
} ,
2010-09-17 12:40:42 -04:00
load _previous _feed _in _trainer : function ( ) {
2010-10-18 18:14:47 -04:00
var trainer _data _length = this . trainer _data . length ;
2010-09-17 12:40:42 -04:00
this . trainer _iterator = this . trainer _iterator - 1 ;
2010-10-21 13:37:36 -04:00
var trainer _data = this . trainer _data [ this . trainer _iterator ] ;
2010-10-29 11:34:33 -04:00
// NEWSBLUR.log(['load_previous_feed_in_trainer', this.trainer_iterator, trainer_data]);
2010-10-21 13:37:36 -04:00
if ( ! trainer _data || this . trainer _iterator < 0 ) {
2010-09-17 12:40:42 -04:00
this . make _trainer _intro ( ) ;
2010-10-17 23:34:14 -04:00
this . reload _modal ( ) ;
2010-10-21 13:37:36 -04:00
} else {
this . feed _id = trainer _data [ 'feed_id' ] ;
2010-09-17 12:40:42 -04:00
this . load _feed ( trainer _data ) ;
}
} ,
2010-10-29 11:34:33 -04:00
load _next _feed _in _trainer : function ( ) {
2010-10-18 18:14:47 -04:00
var trainer _data _length = this . trainer _data . length ;
2012-01-03 10:05:43 -08:00
this . trainer _iterator += 1 ;
2010-10-21 13:37:36 -04:00
var trainer _data = this . trainer _data [ this . trainer _iterator ] ;
2010-10-29 11:34:33 -04:00
// NEWSBLUR.log(['load_next_feed_in_trainer', this.trainer_iterator, trainer_data]);
2010-10-21 13:37:36 -04:00
if ( ! trainer _data || this . trainer _iterator >= trainer _data _length ) {
2010-09-17 12:40:42 -04:00
this . make _trainer _outro ( ) ;
2010-10-17 23:34:14 -04:00
this . reload _modal ( ) ;
2010-09-17 12:40:42 -04:00
this . load _feeds _trainer ( null , this . trainer _data ) ;
2010-10-17 23:34:14 -04:00
} else {
2010-10-21 13:37:36 -04:00
this . feed _id = trainer _data [ 'feed_id' ] ;
2012-01-03 10:05:43 -08:00
if ( this . model . get _feed ( this . feed _id ) ) {
this . load _feed ( trainer _data ) ;
} else {
this . load _next _feed _in _trainer ( ) ;
}
2010-09-17 12:40:42 -04:00
}
} ,
load _feed : function ( trainer _data ) {
2012-02-13 11:07:32 -08:00
this . feed _id = trainer _data [ 'feed_id' ] || trainer _data [ 'id' ] ;
2010-09-17 12:40:42 -04:00
this . feed = this . model . get _feed ( this . feed _id ) ;
this . feed _tags = trainer _data [ 'feed_tags' ] ;
this . feed _authors = trainer _data [ 'feed_authors' ] ;
this . user _classifiers = trainer _data [ 'classifiers' ] ;
2012-05-24 13:31:23 -07:00
this . feed _publishers = new Backbone . Collection ( trainer _data [ 'popular_publishers' ] ) ;
2012-05-21 20:08:27 -07:00
this . feed . set ( 'num_subscribers' , trainer _data [ 'num_subscribers' ] , { silent : true } ) ;
2010-09-20 18:20:22 -04:00
this . options . feed _loaded = true ;
2011-10-24 08:55:28 -07:00
if ( ! this . model . classifiers [ this . feed _id ] ) {
this . model . classifiers [ this . feed _id ] = _ . extend ( { } , this . model . defaults [ 'classifiers' ] ) ;
}
2010-09-17 12:40:42 -04:00
if ( this . feed _id in this . cache ) {
this . $modal = this . cache [ this . feed _id ] ;
2010-10-18 18:14:47 -04:00
} else {
2010-12-04 16:42:51 -05:00
if ( this . flags [ 'story' ] ) {
this . make _modal _story ( ) ;
this . handle _text _highlight ( ) ;
} else if ( this . flags [ 'publisher' ] ) {
this . make _modal _feed ( ) ;
this . make _modal _trainer _count ( ) ;
}
2010-10-18 18:14:47 -04:00
this . make _modal _title ( ) ;
2010-08-01 23:47:40 -04:00
}
2010-08-01 19:12:42 -04:00
2010-10-17 23:34:14 -04:00
this . reload _modal ( ) ;
} ,
2010-10-29 11:34:33 -04:00
reload _modal : function ( callback ) {
2010-09-21 09:18:58 -04:00
this . flags . modal _loading = setInterval ( _ . bind ( function ( ) {
if ( this . flags . modal _loaded ) {
clearInterval ( this . flags . modal _loading ) ;
$ ( '.NB-modal' ) . empty ( ) . append ( this . $modal . children ( ) ) ;
this . $modal = $ ( '.NB-modal' ) ; // This is bonkers. I shouldn't have to reattach like this
$ ( window ) . trigger ( 'resize.simplemodal' ) ;
this . handle _cancel ( ) ;
2010-10-23 11:05:43 -04:00
this . $modal . parent ( ) . scrollTop ( 0 ) ;
2010-10-29 11:34:33 -04:00
callback && callback ( ) ;
2010-09-21 09:18:58 -04:00
}
} , this ) , 125 ) ;
2010-08-01 19:12:42 -04:00
} ,
get _feeds _trainer : function ( ) {
2010-09-17 12:40:42 -04:00
this . model . get _feeds _trainer ( null , $ . rescope ( this . load _feeds _trainer , this ) ) ;
2010-08-01 19:12:42 -04:00
} ,
load _feeds _trainer : function ( e , data ) {
var $begin = $ ( '.NB-modal-submit-begin' , this . $modal ) ;
this . trainer _data = data ;
2010-10-21 13:37:36 -04:00
if ( ! data || ! data . length ) {
this . make _trainer _outro ( ) ;
this . reload _modal ( ) ;
} else {
$begin . text ( 'Begin Training' )
. addClass ( 'NB-modal-submit-green' )
2012-07-02 10:15:17 -07:00
. removeClass ( 'NB-modal-submit-grey' )
2010-10-21 13:37:36 -04:00
. removeClass ( 'NB-disabled' ) ;
}
2010-08-01 19:12:42 -04:00
} ,
2010-10-29 11:34:33 -04:00
retrain _all _sites : function ( ) {
$ ( '.NB-modal-submit-reset' , this . $modal ) . text ( 'Rewinding...' ) . attr ( 'disabled' , true ) . addClass ( 'NB-disabled' ) ;
this . model . retrain _all _sites ( _ . bind ( function ( data ) {
this . load _feeds _trainer ( null , data ) ;
this . load _next _feed _in _trainer ( ) ;
} , this ) ) ;
} ,
2010-06-08 11:19:41 -04:00
find _story _and _feed : function ( ) {
if ( this . story _id ) {
this . story = this . model . get _story ( this . story _id ) ;
}
2010-09-17 12:40:42 -04:00
2010-06-08 11:19:41 -04:00
this . feed = this . model . get _feed ( this . feed _id ) ;
2010-09-20 18:20:22 -04:00
2011-02-27 16:13:22 -05:00
if ( this . options . feed _loaded && this . feed ) {
2010-09-20 18:20:22 -04:00
this . feed _tags = this . model . get _feed _tags ( ) ;
this . feed _authors = this . model . get _feed _authors ( ) ;
2012-01-26 18:59:40 -08:00
$ ( '.NB-modal-subtitle .NB-modal-feed-image' , this . $modal ) . attr ( 'src' , $ . favicon ( this . feed ) ) ;
2012-05-21 20:08:27 -07:00
$ ( '.NB-modal-subtitle .NB-modal-feed-title' , this . $modal ) . html ( this . feed . get ( 'feed_title' ) ) ;
$ ( '.NB-modal-subtitle .NB-modal-feed-subscribers' , this . $modal ) . html ( Inflector . pluralize ( ' subscriber' , this . feed . get ( 'num_subscribers' ) , true ) ) ;
2010-09-20 18:20:22 -04:00
}
2010-08-01 19:12:42 -04:00
} ,
2010-09-17 12:40:42 -04:00
load _single _feed _trainer : function ( ) {
var self = this ;
var $loading = $ ( '.NB-modal-loading' , this . $modal ) ;
$loading . addClass ( 'NB-active' ) ;
2012-02-13 11:07:32 -08:00
var get _trainer _fn = this . model . get _feeds _trainer ;
if ( this . options . social _feed ) {
get _trainer _fn = this . model . get _social _trainer ;
}
get _trainer _fn . call ( this . model , this . feed _id , function ( data ) {
2010-09-17 12:40:42 -04:00
self . trainer _data = data ;
2010-09-20 18:20:22 -04:00
if ( data && data . length ) {
// Should only be one feed
self . load _feed ( data [ 0 ] ) ;
}
2010-09-17 12:40:42 -04:00
} ) ;
} ,
2010-08-01 19:12:42 -04:00
make _trainer _intro : function ( ) {
var self = this ;
2010-10-21 13:37:36 -04:00
this . $modal = $ . make ( 'div' , { className : 'NB-modal-classifiers NB-modal NB-modal-trainer' } , [
2010-08-01 19:12:42 -04:00
$ . make ( 'h2' , { className : 'NB-modal-title' } , 'Intelligence Trainer' ) ,
2010-08-01 23:47:40 -04:00
$ . make ( 'h3' , { className : 'NB-modal-subtitle' } , 'Here\'s what to do:' ) ,
$ . make ( 'ol' , { className : 'NB-trainer-points' } , [
$ . make ( 'li' , [
2010-12-07 09:52:14 -05:00
$ . make ( 'img' , { src : NEWSBLUR . Globals . MEDIA _URL + '/img/reader/sample_classifier_tag.png' , style : 'float: right;margin-top: 4px;' , width : 155 , height : 17 } ) ,
2010-08-01 23:47:40 -04:00
$ . make ( 'b' , 'You will see a bunch of tags and authors.' ) ,
2011-07-27 22:17:34 -07:00
' Sites will be ordered by popularity. Click on what you like and don\'t like.'
2010-08-01 23:47:40 -04:00
] ) ,
$ . make ( 'li' , [
2011-04-21 10:44:50 -04:00
$ . make ( 'img' , { src : NEWSBLUR . Globals . MEDIA _URL + '/img/reader/intelligence_slider_all.png' , style : 'float: right' , width : 127 , height : 92 } ) ,
2010-12-07 09:52:14 -05:00
$ . make ( 'b' , 'The intelligence slider filters stories.' ) ,
$ . make ( 'img' , { className : 'NB-trainer-bullet' , src : NEWSBLUR . Globals . MEDIA _URL + '/img/icons/silk/bullet_green.png' } ) ,
' are stories you like' ,
2010-08-01 23:47:40 -04:00
$ . make ( 'br' ) ,
$ . make ( 'img' , { className : 'NB-trainer-bullet' , src : NEWSBLUR . Globals . MEDIA _URL + '/img/icons/silk/bullet_yellow.png' } ) ,
' are stories you have not yet rated' ,
$ . make ( 'br' ) ,
2010-12-07 09:52:14 -05:00
$ . make ( 'img' , { className : 'NB-trainer-bullet' , src : NEWSBLUR . Globals . MEDIA _URL + '/img/icons/silk/bullet_red.png' } ) ,
' are stories you don\'t like'
2010-08-01 23:47:40 -04:00
] ) ,
$ . make ( 'li' , [
2010-12-07 09:52:14 -05:00
// $.make('img', { src: NEWSBLUR.Globals.MEDIA_URL + '/img/reader/sample_menu.png', style: 'float: right', width: 176, height: 118 }),
2011-07-27 22:17:34 -07:00
$ . make ( 'b' , 'Stop any time you like.' ) ,
' You can always come back to this trainer.'
2010-08-01 23:47:40 -04:00
] ) ,
$ . make ( 'li' , [
$ . make ( 'b' , 'Don\'t worry if you don\'t know what you like right now.' ) ,
2011-07-27 22:17:34 -07:00
' Just skip the site. You can train directly in the Feed view.'
2010-08-01 23:47:40 -04:00
] )
] ) ,
2010-08-02 09:28:56 -04:00
( ! NEWSBLUR . Globals . is _authenticated && $ . make ( 'div' , { className : 'NB-trainer-not-authenticated' } , 'Please create an account and add sites you read. Then you can train them.' ) ) ,
2010-08-01 19:12:42 -04:00
$ . make ( 'div' , { className : 'NB-modal-submit' } , [
2010-08-02 09:28:56 -04:00
( ! NEWSBLUR . Globals . is _authenticated && $ . make ( 'a' , { href : '#' , className : 'NB-modal-submit-close NB-modal-submit-button' } , 'Close' ) ) ,
2012-07-02 10:15:17 -07:00
( NEWSBLUR . Globals . is _authenticated && $ . make ( 'a' , { href : '#' , className : 'NB-modal-submit-begin NB-modal-submit-button NB-modal-submit-grey NB-disabled' } , 'Loading Training...' ) )
2010-08-02 09:28:56 -04:00
] )
] ) ;
} ,
make _trainer _outro : function ( ) {
var self = this ;
2010-10-21 13:37:36 -04:00
this . $modal = $ . make ( 'div' , { className : 'NB-modal-classifiers NB-modal NB-modal-trainer' } , [
2010-08-02 09:28:56 -04:00
$ . make ( 'h2' , { className : 'NB-modal-title' } , 'Congratulations! You\'re done.' ) ,
$ . make ( 'h3' , { className : 'NB-modal-subtitle' } , 'Here\'s what happens next:' ) ,
$ . make ( 'ol' , { className : 'NB-trainer-points' } , [
$ . make ( 'li' , [
$ . make ( 'img' , { src : NEWSBLUR . Globals . MEDIA _URL + '/img/reader/sample_classifier_tag.png' , style : 'float: right' , width : 135 , height : 20 } ) ,
$ . make ( 'b' , 'You can change your opinions.' ) ,
' You can click the ' ,
2010-10-22 00:25:02 -04:00
$ . make ( 'img' , { src : NEWSBLUR . Globals . MEDIA _URL + '/img/reader/thumbs_up.png' , style : 'vertical-align: middle;padding: 0 8px 0 2px' , width : 14 , height : 20 } ) ,
$ . make ( 'img' , { src : NEWSBLUR . Globals . MEDIA _URL + '/img/reader/thumbs_down.png' , style : 'vertical-align: top; padding: 0' , width : 14 , height : 20 } ) ,
2010-08-02 09:28:56 -04:00
' buttons next to stories as you read them.'
] ) ,
$ . make ( 'li' , [
$ . make ( 'img' , { src : NEWSBLUR . Globals . MEDIA _URL + '/img/reader/intelligence_slider_positive.png' , style : 'float: right' , width : 114 , height : 29 } ) ,
$ . make ( 'b' , 'As a reminder, use the intelligence slider to select a filter:' ) ,
$ . make ( 'img' , { className : 'NB-trainer-bullet' , src : NEWSBLUR . Globals . MEDIA _URL + '/img/icons/silk/bullet_red.png' } ) ,
' are stories you don\'t like' ,
$ . make ( 'br' ) ,
$ . make ( 'img' , { className : 'NB-trainer-bullet' , src : NEWSBLUR . Globals . MEDIA _URL + '/img/icons/silk/bullet_yellow.png' } ) ,
' are stories you have not yet rated' ,
$ . make ( 'br' ) ,
$ . make ( 'img' , { className : 'NB-trainer-bullet' , src : NEWSBLUR . Globals . MEDIA _URL + '/img/icons/silk/bullet_green.png' } ) ,
' are stories you like'
] ) ,
$ . make ( 'li' , [
$ . make ( 'b' , 'You can also filter out stories you don\'t want to read.' ) ,
' As great as finding good stuff is, you can just as easily ignore the stories you do not like.'
] )
] ) ,
$ . make ( 'div' , { className : 'NB-modal-submit' } , [
2010-10-29 11:34:33 -04:00
$ . make ( 'a' , { href : '#' , className : 'NB-modal-submit-button NB-modal-submit-reset' } , $ . entity ( '«' ) + ' Retrain all sites' ) ,
2010-08-02 09:28:56 -04:00
$ . make ( 'a' , { href : '#' , className : 'NB-modal-submit-end NB-modal-submit-button' } , 'Close Training and Start Reading' )
2010-08-01 19:12:42 -04:00
] )
] ) ;
2010-06-08 11:19:41 -04:00
} ,
make _modal _feed : function ( ) {
var self = this ;
var feed = this . feed ;
2010-10-22 09:56:06 -04:00
2010-08-01 19:12:42 -04:00
// NEWSBLUR.log(['Make feed', feed, this.feed_authors, this.feed_tags]);
2010-06-08 11:19:41 -04:00
2010-10-21 13:37:36 -04:00
this . $modal = $ . make ( 'div' , { className : 'NB-modal-classifiers NB-modal ' + ( this . options [ 'training' ] && 'NB-modal-trainer' ) } , [
2010-08-01 19:12:42 -04:00
$ . make ( 'div' , { className : 'NB-modal-loading' } ) ,
2010-09-20 19:51:57 -04:00
$ . make ( 'h2' , { className : 'NB-modal-title' } , '' ) ,
2010-08-01 19:12:42 -04:00
$ . make ( 'h2' , { className : 'NB-modal-subtitle' } , [
2010-10-21 13:37:36 -04:00
( this . options [ 'training' ] && $ . make ( 'div' , { className : 'NB-classifier-trainer-counts' } ) ) ,
2012-01-26 18:59:40 -08:00
$ . make ( 'img' , { className : 'NB-modal-feed-image feed_favicon' , src : $ . favicon ( this . feed ) } ) ,
2011-07-27 22:17:34 -07:00
$ . make ( 'div' , { className : 'NB-modal-feed-heading' } , [
2012-05-21 20:08:27 -07:00
$ . make ( 'span' , { className : 'NB-modal-feed-title' } , this . feed . get ( 'feed_title' ) ) ,
$ . make ( 'span' , { className : 'NB-modal-feed-subscribers' } , Inflector . pluralize ( ' subscriber' , this . feed . get ( 'num_subscribers' ) , true ) )
2011-07-27 22:17:34 -07:00
] )
2010-08-01 19:12:42 -04:00
] ) ,
2010-09-20 18:20:22 -04:00
( this . options [ 'feed_loaded' ] &&
$ . make ( 'form' , { method : 'post' , className : 'NB-publisher' } , [
2010-10-21 23:32:07 -04:00
( ! _ . isEmpty ( this . user _classifiers . titles ) && $ . make ( 'div' , { className : 'NB-modal-field NB-fieldset NB-classifiers' } , [
$ . make ( 'h5' , 'Titles and Phrases' ) ,
$ . make ( 'div' , { className : 'NB-classifier-titles NB-fieldset-fields NB-classifiers' } ,
this . make _user _titles ( )
)
] ) ) ,
2010-09-20 18:20:22 -04:00
( this . feed _authors . length && $ . make ( 'div' , { className : 'NB-modal-field NB-fieldset NB-classifiers' } , [
$ . make ( 'h5' , 'Authors' ) ,
$ . make ( 'div' , { className : 'NB-classifier-authors NB-fieldset-fields NB-classifiers' } ,
2010-10-21 23:32:07 -04:00
this . make _authors ( this . feed _authors ) . concat ( this . make _user _authors ( ) )
2010-09-20 18:20:22 -04:00
)
] ) ) ,
( this . feed _tags . length && $ . make ( 'div' , { className : 'NB-modal-field NB-fieldset NB-classifiers' } , [
$ . make ( 'h5' , 'Categories & Tags' ) ,
$ . make ( 'div' , { className : 'NB-classifier-tags NB-fieldset-fields NB-classifiers' } ,
2010-10-21 23:32:07 -04:00
this . make _tags ( this . feed _tags ) . concat ( this . make _user _tags ( ) )
2010-09-20 18:20:22 -04:00
)
] ) ) ,
2012-02-15 18:00:10 -08:00
( this . feed _publishers && this . feed _publishers . length && $ . make ( 'div' , { className : 'NB-modal-field NB-fieldset NB-publishers' } , [
2012-02-13 11:07:32 -08:00
$ . make ( 'h5' , 'Sharing Stories From These Sites' ) ,
$ . make ( 'div' , { className : 'NB-classifier-publishers NB-fieldset-fields NB-classifiers' } ,
this . make _publishers ( this . feed _publishers )
)
] ) ) ,
2010-09-20 18:20:22 -04:00
$ . make ( 'div' , { className : 'NB-modal-field NB-fieldset NB-classifiers' } , [
$ . make ( 'h5' , 'Everything by This Publisher' ) ,
$ . make ( 'div' , { className : 'NB-fieldset-fields NB-classifiers' } ,
2010-10-21 23:32:07 -04:00
this . make _publisher ( feed )
2010-09-20 18:20:22 -04:00
)
] ) ,
( this . options [ 'training' ] && $ . make ( 'div' , { className : 'NB-modal-submit' } , [
$ . make ( 'input' , { name : 'feed_id' , value : this . feed _id , type : 'hidden' } ) ,
$ . make ( 'a' , { href : '#' , className : 'NB-modal-submit-button NB-modal-submit-back' } , $ . entity ( '«' ) + ' Back' ) ,
2010-10-21 13:37:36 -04:00
$ . make ( 'a' , { href : '#' , className : 'NB-modal-submit-button NB-modal-submit-green NB-modal-submit-next NB-modal-submit-save' } , 'Save & Next ' + $ . entity ( '»' ) ) ,
2010-09-20 18:20:22 -04:00
$ . make ( 'a' , { href : '#' , className : 'NB-modal-submit-button NB-modal-submit-close' } , 'Close' )
] ) ) ,
( ! this . options [ 'training' ] && $ . make ( 'div' , { className : 'NB-modal-submit' } , [
$ . make ( 'input' , { name : 'story_id' , value : this . story _id , type : 'hidden' } ) ,
$ . make ( 'input' , { name : 'feed_id' , value : this . feed _id , type : 'hidden' } ) ,
$ . make ( 'input' , { type : 'submit' , disabled : 'true' , className : 'NB-modal-submit-save NB-modal-submit-green NB-disabled' , value : 'Check what you like above...' } ) ,
' or ' ,
$ . make ( 'a' , { href : '#' , className : 'NB-modal-cancel' } , 'cancel' )
] ) )
2010-10-21 13:37:36 -04:00
] )
2010-09-20 18:20:22 -04:00
)
2010-06-08 11:19:41 -04:00
] ) ;
} ,
make _modal _story : function ( ) {
var self = this ;
var story = this . story ;
var feed = this . feed ;
2010-11-09 22:06:08 -05:00
// NEWSBLUR.log(['Make Story', story, feed]);
2010-06-08 11:19:41 -04:00
// HTML entities decoding.
2012-05-25 22:13:50 -07:00
story _title = _ . string . trim ( $ ( '<div/>' ) . html ( story . get ( 'story_title' ) ) . text ( ) ) ;
2010-06-08 11:19:41 -04:00
2010-10-22 00:16:34 -04:00
this . $modal = $ . make ( 'div' , { className : 'NB-modal-classifiers NB-modal' } , [
2010-06-08 11:19:41 -04:00
$ . make ( 'h2' , { className : 'NB-modal-title' } ) ,
2010-12-04 16:42:51 -05:00
( this . options [ 'feed_loaded' ] &&
$ . make ( 'form' , { method : 'post' } , [
2012-05-25 22:13:50 -07:00
( story _title && $ . make ( 'div' , { className : 'NB-modal-field NB-fieldset' } , [
2010-12-04 16:42:51 -05:00
$ . make ( 'h5' , 'Story Title' ) ,
$ . make ( 'div' , { className : 'NB-fieldset-fields NB-classifiers' } , [
2012-05-25 22:13:50 -07:00
$ . make ( 'input' , { type : 'text' , value : story _title , className : 'NB-classifier-title-highlight' } ) ,
2010-12-04 16:42:51 -05:00
this . make _classifier ( '<span class="NB-classifier-title-placeholder">Highlight phrases to look for in future stories</span>' , '' , 'title' ) ,
$ . make ( 'span' ,
2012-05-25 22:13:50 -07:00
this . make _user _titles ( story _title )
2010-12-04 16:42:51 -05:00
)
] )
] ) ) ,
2012-05-25 22:13:50 -07:00
( story . get ( 'story_authors' ) && $ . make ( 'div' , { className : 'NB-modal-field NB-fieldset' } , [
2010-12-04 16:42:51 -05:00
$ . make ( 'h5' , 'Story Author' ) ,
$ . make ( 'div' , { className : 'NB-fieldset-fields NB-classifiers' } ,
2012-05-25 22:13:50 -07:00
this . make _authors ( [ story . get ( 'story_authors' ) ] )
2010-11-09 22:06:08 -05:00
)
2010-12-04 16:42:51 -05:00
] ) ) ,
2012-05-25 22:13:50 -07:00
( story . get ( 'story_tags' ) . length && $ . make ( 'div' , { className : 'NB-modal-field NB-fieldset' } , [
2010-12-04 16:42:51 -05:00
$ . make ( 'h5' , 'Story Categories & Tags' ) ,
$ . make ( 'div' , { className : 'NB-classifier-tags NB-fieldset-fields NB-classifiers' } ,
2012-05-25 22:13:50 -07:00
this . make _tags ( story . get ( 'story_tags' ) )
2010-12-04 16:42:51 -05:00
)
] ) ) ,
$ . make ( 'div' , { className : 'NB-modal-field NB-fieldset' } , [
$ . make ( 'h5' , 'Everything by This Publisher' ) ,
$ . make ( 'div' , { className : 'NB-fieldset-fields NB-classifiers' } ,
2011-03-06 21:33:06 -05:00
this . make _publisher ( feed )
2010-12-04 16:42:51 -05:00
)
] ) ,
$ . make ( 'div' , { className : 'NB-modal-submit' } , [
$ . make ( 'input' , { name : 'story_id' , value : this . story _id , type : 'hidden' } ) ,
$ . make ( 'input' , { name : 'feed_id' , value : this . feed _id , type : 'hidden' } ) ,
$ . make ( 'input' , { type : 'submit' , disabled : 'true' , className : 'NB-modal-submit-save NB-modal-submit-green NB-disabled' , value : 'Check what you like above...' } ) ,
' or ' ,
$ . make ( 'a' , { href : '#' , className : 'NB-modal-cancel' } , 'cancel' )
2010-06-08 11:19:41 -04:00
] )
2011-03-06 21:33:06 -05:00
] )
2010-12-04 16:42:51 -05:00
)
2010-06-08 11:19:41 -04:00
] ) ;
} ,
make _modal _title : function ( ) {
2010-08-01 19:12:42 -04:00
var $modal _title = $ ( '.NB-modal-title' , this . $modal ) ;
2010-06-08 11:19:41 -04:00
2010-10-21 13:37:36 -04:00
var $title = $ . make ( 'div' , [
'What do you ' ,
$ . make ( 'b' , { className : 'NB-classifier-title-like' } , 'like' ) ,
' and ' ,
$ . make ( 'b' , { className : 'NB-classifier-title-dislike' } , 'dislike' ) ,
' about this ' ,
( this . flags [ 'publisher' ] && 'site' ) ,
( this . flags [ 'story' ] && 'story' ) ,
'?'
] ) ;
$modal _title . html ( $title ) ;
2010-06-08 11:19:41 -04:00
} ,
2010-08-01 19:12:42 -04:00
make _modal _trainer _count : function ( ) {
var $count = $ ( '.NB-classifier-trainer-counts' , this . $modal ) ;
2010-10-21 13:37:36 -04:00
var count = this . trainer _iterator + 1 ;
2010-08-01 19:12:42 -04:00
var total = this . trainer _data . length ;
$count . html ( count + '/' + total ) ;
} ,
2010-11-09 22:06:08 -05:00
make _user _titles : function ( existing _title ) {
2010-10-21 23:32:07 -04:00
var $titles = [ ] ;
var titles = _ . keys ( this . user _classifiers . titles ) ;
2010-06-08 11:19:41 -04:00
2010-10-21 23:32:07 -04:00
_ . each ( titles , _ . bind ( function ( title ) {
2010-11-09 22:06:08 -05:00
if ( ! existing _title || existing _title . indexOf ( title ) != - 1 ) {
var $title = this . make _classifier ( title , title , 'title' ) ;
$titles . push ( $title ) ;
}
2010-10-21 23:32:07 -04:00
} , this ) ) ;
2010-06-08 11:19:41 -04:00
2010-10-21 23:32:07 -04:00
return $titles ;
2010-06-08 11:19:41 -04:00
} ,
2011-03-06 21:33:06 -05:00
make _authors : function ( authors ) {
2010-06-08 11:19:41 -04:00
var $authors = [ ] ;
for ( var a in authors ) {
var author _obj = authors [ a ] ;
if ( typeof author _obj == 'string' ) {
var author = author _obj ;
var author _count ;
} else {
var author = author _obj [ 0 ] ;
var author _count = author _obj [ 1 ] ;
}
if ( ! author ) continue ;
2010-10-19 22:41:30 -04:00
var $author = this . make _classifier ( author , author , 'author' , author _count ) ;
2010-06-08 11:19:41 -04:00
$authors . push ( $author ) ;
}
return $authors ;
} ,
2010-10-21 23:32:07 -04:00
make _user _authors : function ( ) {
var $authors = [ ] ;
var user _authors = _ . keys ( this . user _classifiers . authors ) ;
var feed _authors = _ . map ( this . feed _authors , function ( author ) { return author [ 0 ] ; } ) ;
var authors = _ . reduce ( user _authors , function ( memo , author , i ) {
if ( ! _ . contains ( feed _authors , author ) ) return memo . concat ( author ) ;
return memo ;
} , [ ] ) ;
return this . make _authors ( authors ) ;
} ,
make _tags : function ( tags ) {
2010-06-08 11:19:41 -04:00
var $tags = [ ] ;
for ( var t in tags ) {
var tag _obj = tags [ t ] ;
if ( typeof tag _obj == 'string' ) {
var tag = tag _obj ;
var tag _count ;
} else {
var tag = tag _obj [ 0 ] ;
var tag _count = tag _obj [ 1 ] ;
}
if ( ! tag ) continue ;
2010-10-19 20:57:25 -04:00
var $tag = this . make _classifier ( tag , tag , 'tag' , tag _count ) ;
2010-06-08 11:19:41 -04:00
$tags . push ( $tag ) ;
}
return $tags ;
} ,
2010-10-19 20:57:25 -04:00
2010-10-21 23:32:07 -04:00
make _user _tags : function ( ) {
var $tags = [ ] ;
var user _tags = _ . keys ( this . user _classifiers . tags ) ;
var feed _tags = _ . map ( this . feed _tags , function ( tag ) { return tag [ 0 ] ; } ) ;
var tags = _ . reduce ( user _tags , function ( memo , tag , i ) {
if ( ! _ . contains ( feed _tags , tag ) ) return memo . concat ( tag ) ;
return memo ;
} , [ ] ) ;
2010-06-08 11:19:41 -04:00
2010-10-21 23:32:07 -04:00
return this . make _tags ( tags ) ;
} ,
2012-02-13 11:07:32 -08:00
make _publishers : function ( publishers ) {
2012-05-24 13:31:23 -07:00
var $publishers = publishers . map ( _ . bind ( function ( publisher ) {
2012-02-13 11:07:32 -08:00
return this . make _publisher ( publisher ) ;
} , this ) ) ;
return $publishers ;
} ,
2011-03-06 21:33:06 -05:00
make _publisher : function ( publisher ) {
2012-05-24 13:31:23 -07:00
var $publisher = this . make _classifier ( _ . string . truncate ( publisher . get ( 'feed_title' ) , 50 ) ,
publisher . id , 'feed' , publisher . get ( 'story_count' ) , publisher ) ;
2010-10-19 22:41:30 -04:00
return $publisher ;
} ,
2012-02-13 11:07:32 -08:00
make _classifier : function ( classifier _title , classifier _value , classifier _type , classifier _count , classifier ) {
2010-10-19 20:57:25 -04:00
var score = 0 ;
2010-10-21 23:32:07 -04:00
// NEWSBLUR.log(['classifiers', this.user_classifiers, classifier_value, this.user_classifiers[classifier_type+'s']]);
2010-10-19 20:57:25 -04:00
if ( classifier _value in this . user _classifiers [ classifier _type + 's' ] ) {
score = this . user _classifiers [ classifier _type + 's' ] [ classifier _value ] ;
2010-06-08 11:19:41 -04:00
}
2010-10-19 20:57:25 -04:00
var classifier _type _title = Inflector . capitalize ( classifier _type == 'feed' ?
2012-02-13 11:07:32 -08:00
'site' :
2010-10-19 20:57:25 -04:00
classifier _type ) ;
var $classifier = $ . make ( 'span' , { className : 'NB-classifier-container' } , [
$ . make ( 'span' , { className : 'NB-classifier NB-classifier-' + classifier _type } , [
$ . make ( 'input' , {
type : 'checkbox' ,
className : 'NB-classifier-input-like' ,
name : 'like_' + classifier _type ,
2010-10-21 13:37:36 -04:00
value : classifier _value
2010-10-19 20:57:25 -04:00
} ) ,
$ . make ( 'input' , {
type : 'checkbox' ,
className : 'NB-classifier-input-dislike' ,
name : 'dislike_' + classifier _type ,
value : classifier _value
} ) ,
$ . make ( 'div' , { className : 'NB-classifier-icon-like' } ) ,
$ . make ( 'div' , { className : 'NB-classifier-icon-dislike' } , [
$ . make ( 'div' , { className : 'NB-classifier-icon-dislike-inner' } )
] ) ,
$ . make ( 'label' , [
( classifier _type == 'feed' &&
$ . make ( 'img' , {
className : 'feed_favicon' ,
2012-02-13 11:07:32 -08:00
src : $ . favicon ( classifier )
2010-10-19 20:57:25 -04:00
} ) ) ,
$ . make ( 'b' , classifier _type _title + ': ' ) ,
$ . make ( 'span' , classifier _title )
2010-06-08 11:19:41 -04:00
] )
2010-10-19 20:57:25 -04:00
] ) ,
( classifier _count && $ . make ( 'span' , { className : 'NB-classifier-count' } , [
'× ' ,
classifier _count
] ) )
2010-06-08 11:19:41 -04:00
] ) ;
2010-10-19 20:57:25 -04:00
if ( score > 0 ) {
2010-10-21 13:37:36 -04:00
$ ( '.NB-classifier' , $classifier ) . addClass ( 'NB-classifier-like' ) ;
2010-10-19 20:57:25 -04:00
$ ( '.NB-classifier-input-like' , $classifier ) . attr ( 'checked' , true ) ;
} else if ( score < 0 ) {
2010-10-21 13:37:36 -04:00
$ ( '.NB-classifier' , $classifier ) . addClass ( 'NB-classifier-dislike' ) ;
2010-10-19 20:57:25 -04:00
$ ( '.NB-classifier-input-dislike' , $classifier ) . attr ( 'checked' , true ) ;
}
2010-10-21 19:36:03 -04:00
$ ( '.NB-classifier' , $classifier ) . bind ( 'mouseenter' , function ( e ) {
2010-10-19 20:57:25 -04:00
$ ( e . currentTarget ) . addClass ( 'NB-classifier-hover-like' ) ;
2010-10-21 19:36:03 -04:00
} ) . bind ( 'mouseleave' , function ( e ) {
2010-10-19 20:57:25 -04:00
$ ( e . currentTarget ) . removeClass ( 'NB-classifier-hover-like' ) ;
} ) ;
2010-10-21 19:36:03 -04:00
$ ( '.NB-classifier-icon-dislike' , $classifier ) . bind ( 'mouseenter' , function ( e ) {
2010-10-19 20:57:25 -04:00
$ ( '.NB-classifier' , $classifier ) . addClass ( 'NB-classifier-hover-dislike' ) ;
2010-10-21 19:36:03 -04:00
} ) . bind ( 'mouseleave' , function ( e ) {
2010-10-19 20:57:25 -04:00
$ ( '.NB-classifier' , $classifier ) . removeClass ( 'NB-classifier-hover-dislike' ) ;
} ) ;
return $classifier ;
2010-06-08 11:19:41 -04:00
} ,
2010-10-19 20:57:25 -04:00
2010-10-19 22:41:30 -04:00
change _classifier : function ( $classifier , classifier _opinion ) {
var $like = $ ( '.NB-classifier-input-like' , $classifier ) ;
var $dislike = $ ( '.NB-classifier-input-dislike' , $classifier ) ;
2010-10-21 13:37:36 -04:00
var $save = $ ( '.NB-modal-submit-save' , this . $modal ) ;
var $close = $ ( '.NB-modal-submit-close' , this . $modal ) ;
var $back = $ ( '.NB-modal-submit-back' , this . $modal ) ;
2010-10-19 22:41:30 -04:00
if ( classifier _opinion == 'like' ) {
if ( $classifier . is ( '.NB-classifier-like' ) ) {
$classifier . removeClass ( 'NB-classifier-like' ) ;
2010-10-21 13:37:36 -04:00
$dislike . attr ( 'checked' , false ) ;
$like . attr ( 'checked' , false ) ;
2010-10-19 22:41:30 -04:00
} else {
$classifier . removeClass ( 'NB-classifier-dislike' ) ;
$classifier . addClass ( 'NB-classifier-like' ) ;
2010-10-21 13:37:36 -04:00
$dislike . attr ( 'checked' , false ) ;
$like . attr ( 'checked' , true ) ;
2010-10-19 22:41:30 -04:00
}
} else if ( classifier _opinion == 'dislike' ) {
if ( $classifier . is ( '.NB-classifier-dislike' ) ) {
$classifier . removeClass ( 'NB-classifier-dislike' ) ;
2010-10-21 13:37:36 -04:00
$like . attr ( 'checked' , false ) ;
$dislike . attr ( 'checked' , false ) ;
2010-10-19 22:41:30 -04:00
} else {
$classifier . removeClass ( 'NB-classifier-like' ) ;
$classifier . addClass ( 'NB-classifier-dislike' ) ;
2010-10-21 13:37:36 -04:00
$like . attr ( 'checked' , false ) ;
$dislike . attr ( 'checked' , true ) ;
2010-10-19 22:41:30 -04:00
}
}
2010-10-21 13:37:36 -04:00
if ( this . options [ 'training' ] ) {
$close . val ( 'Save & Close' ) ;
} else {
$save . removeClass ( "NB-disabled" ) . removeAttr ( 'disabled' ) . attr ( 'value' , 'Save' ) ;
}
2010-10-21 23:32:07 -04:00
// NEWSBLUR.log(['change_classifier', classifier_opinion, $classifier, $like.is(':checked'), $dislike.is(':checked')]);
2010-06-08 11:19:41 -04:00
} ,
open _modal : function ( ) {
var self = this ;
2010-08-01 19:12:42 -04:00
this . $modal . modal ( {
2010-06-08 11:19:41 -04:00
'minWidth' : 600 ,
2010-08-03 23:41:02 -04:00
'maxWidth' : 600 ,
2010-06-08 11:19:41 -04:00
'overlayClose' : true ,
2010-07-25 15:34:50 -04:00
'autoResize' : true ,
2010-08-01 23:47:40 -04:00
'position' : [ this . options [ 'training' ] ? 40 : 0 , 0 ] ,
2010-06-08 11:19:41 -04:00
'onOpen' : function ( dialog ) {
2010-06-13 18:57:20 -04:00
dialog . overlay . fadeIn ( 200 , function ( ) {
dialog . container . fadeIn ( 200 ) ;
dialog . data . fadeIn ( 200 ) ;
2010-09-21 09:18:58 -04:00
setTimeout ( function ( ) {
self . flags . modal _loaded = true ;
2011-04-30 23:33:36 -04:00
$ ( window ) . trigger ( 'resize.simplemodal' ) ;
2010-10-17 17:25:10 -04:00
} ) ;
2010-06-13 18:57:20 -04:00
} ) ;
2010-06-08 11:19:41 -04:00
} ,
'onShow' : function ( dialog ) {
2010-08-03 23:41:02 -04:00
$ ( '#simplemodal-container' ) . corner ( '6px' ) ;
2010-08-01 19:12:42 -04:00
$ ( '.NB-classifier' , self . $modal ) . corner ( '14px' ) ;
2010-06-08 11:19:41 -04:00
} ,
'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 ( ) ;
}
} ) ;
} ,
2010-10-18 19:21:02 -04:00
update _homepage _counts : function ( ) {
var $count = $ ( '.NB-module-account-trainer-count' ) ;
$count . text ( _ . size ( this . model . get _feeds ( ) ) - ( this . trainer _data . length - this . trainer _iterator ) - 1 ) ;
} ,
end : function ( ) {
2012-03-19 19:18:19 -07:00
this . model . preference ( 'has_trained_intelligence' , true ) ;
NEWSBLUR . reader . check _hide _getting _started ( ) ;
$ . modal . close ( ) ;
2010-10-18 19:21:02 -04:00
} ,
// ==========
// = Events =
// ==========
2010-06-08 11:19:41 -04:00
handle _text _highlight : function ( ) {
2010-10-22 00:16:34 -04:00
var self = this ;
2010-08-01 19:12:42 -04:00
var $title _highlight = $ ( '.NB-classifier-title-highlight' , this . $modal ) ;
2010-11-09 22:06:08 -05:00
var $title _placeholder = $ ( '.NB-classifier-title-placeholder' , this . $modal ) ;
var $title _classifier = $title _placeholder . parents ( '.NB-classifier' ) . eq ( 0 ) ;
2010-10-22 00:16:34 -04:00
var $title _checkboxs = $ ( '.NB-classifier-input-like, .NB-classifier-input-dislike' , $title _classifier ) ;
2010-06-08 11:19:41 -04:00
var update = function ( ) {
var text = $ . trim ( $ ( this ) . getSelection ( ) . text ) ;
2010-11-09 22:06:08 -05:00
if ( text . length && $title _placeholder . text ( ) != text ) {
$title _placeholder . text ( text ) ;
2010-10-22 00:16:34 -04:00
$title _checkboxs . val ( text ) ;
if ( ! $title _classifier . is ( '.NB-classifier-like,.NB-classifier-dislike' ) ) {
2010-11-09 22:06:08 -05:00
self . change _classifier ( $title _classifier , 'like' ) ;
2010-10-22 00:16:34 -04:00
}
2010-06-08 11:19:41 -04:00
}
} ;
$title _highlight
. keydown ( update ) . keyup ( update )
. mousedown ( update ) . mouseup ( update ) . mousemove ( update ) ;
2010-11-09 22:06:08 -05:00
$title _checkboxs . val ( $title _highlight . val ( ) ) ;
$title _placeholder . parents ( '.NB-classifier' ) . bind ( 'click' , function ( ) {
2010-11-25 11:00:57 -05:00
if ( $title _highlight . val ( ) == $title _checkboxs . val ( ) ) {
$title _placeholder . text ( $title _highlight . val ( ) ) ;
}
2010-11-09 22:06:08 -05:00
} ) ;
2010-06-08 11:19:41 -04:00
} ,
handle _cancel : function ( ) {
2010-08-01 19:12:42 -04:00
var $cancel = $ ( '.NB-modal-cancel' , this . $modal ) ;
2010-06-08 11:19:41 -04:00
$cancel . click ( function ( e ) {
e . preventDefault ( ) ;
$ . modal . close ( ) ;
} ) ;
} ,
2010-08-01 19:12:42 -04:00
handle _clicks : function ( elem , e ) {
var self = this ;
2010-10-21 13:37:36 -04:00
if ( this . options [ 'training' ] ) {
$ . targetIs ( e , { tagSelector : '.NB-modal-submit-begin' } , function ( $t , $p ) {
e . preventDefault ( ) ;
2012-03-19 14:15:38 -07:00
self . model . preference ( 'has_trained_intelligence' , true ) ;
NEWSBLUR . reader . check _hide _getting _started ( ) ;
2010-10-21 13:37:36 -04:00
self . load _next _feed _in _trainer ( ) ;
} ) ;
$ . targetIs ( e , { tagSelector : '.NB-modal-submit-save.NB-modal-submit-next' } , function ( $t , $p ) {
e . preventDefault ( ) ;
2011-03-08 10:06:55 -05:00
self . save ( true ) ;
2010-10-21 13:37:36 -04:00
self . load _next _feed _in _trainer ( ) ;
2010-10-22 09:56:06 -04:00
self . update _homepage _counts ( ) ;
2010-10-21 13:37:36 -04:00
} ) ;
2010-08-01 19:12:42 -04:00
2010-10-21 13:37:36 -04:00
$ . targetIs ( e , { tagSelector : '.NB-modal-submit-back' } , function ( $t , $p ) {
e . preventDefault ( ) ;
self . load _previous _feed _in _trainer ( ) ;
} ) ;
2010-10-29 11:34:33 -04:00
$ . targetIs ( e , { tagSelector : '.NB-modal-submit-reset' } , function ( $t , $p ) {
e . preventDefault ( ) ;
self . retrain _all _sites ( ) ;
} ) ;
2010-08-01 19:12:42 -04:00
2010-10-21 13:37:36 -04:00
$ . targetIs ( e , { tagSelector : '.NB-modal-submit-close' } , function ( $t , $p ) {
e . preventDefault ( ) ;
2011-03-08 10:06:55 -05:00
self . save ( ) ;
2010-10-21 13:37:36 -04:00
} ) ;
2010-08-01 19:12:42 -04:00
2010-10-21 13:37:36 -04:00
$ . targetIs ( e , { tagSelector : '.NB-modal-submit-end' } , function ( $t , $p ) {
e . preventDefault ( ) ;
2010-12-24 11:00:30 -05:00
NEWSBLUR . reader . force _feed _refresh ( ) ;
2010-10-23 11:05:43 -04:00
self . end ( ) ;
2010-10-21 13:37:36 -04:00
// NEWSBLUR.reader.open_feed(self.feed_id, true);
// TODO: Update counts in active feed.
} ) ;
} else {
$ . targetIs ( e , { tagSelector : '.NB-modal-submit-save:not(.NB-modal-submit-next)' } , function ( $t , $p ) {
e . preventDefault ( ) ;
2011-03-08 10:06:55 -05:00
self . save ( ) ;
2010-10-21 13:37:36 -04:00
return false ;
} ) ;
}
2010-10-19 22:41:30 -04:00
var stop = false ;
$ . targetIs ( e , { tagSelector : '.NB-classifier-icon-dislike' } , function ( $t , $p ) {
2010-08-01 19:12:42 -04:00
e . preventDefault ( ) ;
2010-10-19 22:41:30 -04:00
stop = true ;
2010-11-25 11:00:57 -05:00
self . change _classifier ( $t . closest ( '.NB-classifier' ) , 'dislike' ) ;
2010-08-01 19:12:42 -04:00
} ) ;
2010-10-19 22:41:30 -04:00
if ( stop ) return ;
$ . targetIs ( e , { tagSelector : '.NB-classifier' } , function ( $t , $p ) {
2010-08-02 09:28:56 -04:00
e . preventDefault ( ) ;
2010-10-19 22:41:30 -04:00
self . change _classifier ( $t , 'like' ) ;
2010-08-02 09:28:56 -04:00
} ) ;
2010-08-01 19:12:42 -04:00
} ,
2010-06-08 11:19:41 -04:00
serialize _classifier : function ( ) {
2011-03-02 19:59:31 -05:00
var data = { } ;
2010-10-21 13:37:36 -04:00
$ ( '.NB-classifier' , this . $modal ) . each ( function ( ) {
2012-05-25 22:13:50 -07:00
var value = _ . string . trim ( $ ( '.NB-classifier-input-like' , this ) . val ( ) ) ;
2010-10-21 13:37:36 -04:00
if ( $ ( '.NB-classifier-input-like, .NB-classifier-input-dislike' , this ) . is ( ':checked' ) ) {
2011-03-02 19:59:31 -05:00
var name = $ ( 'input:checked' , this ) . attr ( 'name' ) ;
if ( ! data [ name ] ) data [ name ] = [ ] ;
data [ name ] . push ( value ) ;
2010-10-21 13:37:36 -04:00
} else {
2011-03-02 19:59:31 -05:00
var name = 'remove_' + $ ( '.NB-classifier-input-like' , this ) . attr ( 'name' ) ;
if ( ! data [ name ] ) data [ name ] = [ ] ;
data [ name ] . push ( value ) ;
2010-10-21 13:37:36 -04:00
}
2010-06-08 11:19:41 -04:00
} ) ;
2011-03-02 19:59:31 -05:00
data [ 'feed_id' ] = this . feed _id ;
2010-10-21 13:37:36 -04:00
if ( this . story _id ) {
2011-03-02 19:59:31 -05:00
data [ 'story_id' ] = this . story _id ;
2010-10-21 13:37:36 -04:00
}
2010-06-08 11:19:41 -04:00
return data ;
} ,
2011-03-06 21:33:06 -05:00
save : function ( keep _modal _open ) {
2010-10-10 23:33:56 -04:00
var self = this ;
2010-08-01 19:12:42 -04:00
var $save = $ ( '.NB-modal-submit-save' , this . $modal ) ;
2010-06-08 11:19:41 -04:00
var data = this . serialize _classifier ( ) ;
2011-02-27 19:42:22 -05:00
var feed _id = this . feed _id ;
2010-06-08 11:19:41 -04:00
2010-08-01 19:12:42 -04:00
if ( this . options [ 'training' ] ) {
this . cache [ this . feed _id ] = this . $modal . clone ( ) ;
2010-08-02 00:15:20 -04:00
$save . text ( 'Saving...' ) ;
} else {
$save . val ( 'Saving...' ) ;
2010-08-01 19:12:42 -04:00
}
2010-08-02 00:15:20 -04:00
$save . addClass ( 'NB-disabled' ) . attr ( 'disabled' , true ) ;
2011-03-06 21:33:06 -05:00
this . update _opinions ( ) ;
2012-05-25 22:13:50 -07:00
NEWSBLUR . assets . recalculate _story _scores ( feed _id ) ;
2011-04-24 01:52:44 -04:00
this . model . save _classifier ( data , function ( ) {
2010-08-01 19:12:42 -04:00
if ( ! keep _modal _open ) {
2011-02-27 16:13:22 -05:00
NEWSBLUR . reader . force _feeds _refresh ( null , true ) ;
// NEWSBLUR.reader.force_feed_refresh();
2010-10-21 13:37:36 -04:00
// NEWSBLUR.reader.open_feed(self.feed_id, true);
// TODO: Update counts in active feed.
2010-08-01 19:12:42 -04:00
$ . modal . close ( ) ;
}
2010-06-08 11:19:41 -04:00
} ) ;
} ,
2011-03-06 21:33:06 -05:00
update _opinions : function ( ) {
2010-10-10 23:33:56 -04:00
var self = this ;
2011-02-27 19:42:22 -05:00
var feed _id = this . feed _id ;
2010-06-08 11:19:41 -04:00
2011-03-06 21:33:06 -05:00
$ ( 'input[type=checkbox]' , this . $modal ) . each ( function ( ) {
var $this = $ ( this ) ;
var name = $this . attr ( 'name' ) . replace ( /^(dis)?like_/ , '' ) ;
var score = /^dislike/ . test ( $this . attr ( 'name' ) ) ? - 1 : 1 ;
var value = $this . val ( ) ;
var checked = $this . attr ( 'checked' ) ;
if ( checked ) {
if ( name == 'tag' ) {
2011-10-24 08:55:28 -07:00
self . model . classifiers [ feed _id ] . tags [ value ] = score ;
2011-03-06 21:33:06 -05:00
} else if ( name == 'title' ) {
2011-10-24 08:55:28 -07:00
self . model . classifiers [ feed _id ] . titles [ value ] = score ;
2011-03-06 21:33:06 -05:00
} else if ( name == 'author' ) {
2011-10-24 08:55:28 -07:00
self . model . classifiers [ feed _id ] . authors [ value ] = score ;
2011-03-06 21:33:06 -05:00
} else if ( name == 'feed' ) {
2011-10-24 08:55:28 -07:00
self . model . classifiers [ feed _id ] . feeds [ feed _id ] = score ;
2011-03-06 21:33:06 -05:00
}
} else {
2011-10-24 08:55:28 -07:00
if ( name == 'tag' && self . model . classifiers [ feed _id ] . tags [ value ] == score ) {
delete self . model . classifiers [ feed _id ] . tags [ value ] ;
} else if ( name == 'title' && self . model . classifiers [ feed _id ] . titles [ value ] == score ) {
delete self . model . classifiers [ feed _id ] . titles [ value ] ;
} else if ( name == 'author' && self . model . classifiers [ feed _id ] . authors [ value ] == score ) {
delete self . model . classifiers [ feed _id ] . authors [ value ] ;
} else if ( name == 'feed' && self . model . classifiers [ feed _id ] . feeds [ feed _id ] == score ) {
delete self . model . classifiers [ feed _id ] . feeds [ feed _id ] ;
2011-03-06 21:33:06 -05:00
}
}
2010-06-08 11:19:41 -04:00
} ) ;
}
} ;
2010-10-19 20:57:25 -04:00
NEWSBLUR . ReaderClassifierStory . prototype = classifier _prototype ;
NEWSBLUR . ReaderClassifierFeed . prototype = classifier _prototype ;
NEWSBLUR . ReaderClassifierTrainer . prototype = classifier _prototype ;