2010-08-01 19:12:42 -04:00
NEWSBLUR . ReaderClassifierTrainer = function ( options ) {
var defaults = {
'score' : 1 ,
'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 = { } ;
this . trainer _iterator = 0 ;
this . feed _id = null ;
this . options = $ . extend ( { } , defaults , options ) ;
this . score = this . options [ 'score' ] ;
this . model = NEWSBLUR . AssetModel . reader ( ) ;
this . runner _trainer ( ) ;
} ;
NEWSBLUR . ReaderClassifierFeed = function ( feed _id , options ) {
var defaults = {
'score' : 1 ,
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-09-17 12:40:42 -04:00
this . trainer _iterator = 0 ;
2010-06-08 11:19:41 -04:00
this . options = $ . extend ( { } , defaults , options ) ;
2010-08-01 19:12:42 -04:00
this . score = this . options [ 'score' ] ;
2010-06-08 11:19:41 -04:00
this . model = NEWSBLUR . AssetModel . reader ( ) ;
this . runner _feed ( ) ;
} ;
2010-08-01 19:12:42 -04:00
NEWSBLUR . ReaderClassifierStory = function ( story _id , feed _id , options ) {
var defaults = {
'score' : 1
} ;
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
} ;
this . story _id = story _id ;
this . feed _id = feed _id ;
this . options = $ . extend ( { } , defaults , options ) ;
2010-08-01 19:12:42 -04:00
this . score = this . options [ 'score' ] ;
2010-06-08 11:19:41 -04:00
this . model = NEWSBLUR . AssetModel . reader ( ) ;
this . runner _story ( ) ;
} ;
var classifier = {
2010-08-01 19:12:42 -04:00
runner _trainer : function ( ) {
this . user _classifiers = { } ;
this . make _trainer _intro ( ) ;
this . get _feeds _trainer ( ) ;
this . handle _select _checkboxes ( ) ;
this . handle _cancel ( ) ;
this . handle _select _title ( ) ;
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 ( ) {
2010-08-01 19:12:42 -04:00
2010-09-17 12:40:42 -04:00
if ( this . options . feed _loaded ) {
this . user _classifiers = this . model . classifiers ;
} 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 ( ) ;
this . make _modal _intelligence _slider ( ) ;
2010-06-08 11:19:41 -04:00
this . handle _select _checkboxes ( ) ;
this . handle _cancel ( ) ;
this . handle _select _title ( ) ;
this . open _modal ( ) ;
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 ( ) {
2010-08-01 19:12:42 -04:00
this . user _classifiers = this . model . classifiers ;
2010-06-08 11:19:41 -04:00
this . find _story _and _feed ( ) ;
this . make _modal _story ( ) ;
this . make _modal _title ( ) ;
this . handle _text _highlight ( ) ;
this . handle _select _checkboxes ( ) ;
this . handle _cancel ( ) ;
this . handle _select _title ( ) ;
this . open _modal ( ) ;
} ,
2010-09-17 12:40:42 -04:00
load _previous _feed _in _trainer : function ( ) {
this . trainer _iterator = this . trainer _iterator - 1 ;
2010-10-18 18:14:47 -04:00
var trainer _data _length = this . trainer _data . length ;
2010-09-17 12:40:42 -04:00
if ( this . trainer _iterator < 1 ) {
2010-10-18 18:14:47 -04:00
NEWSBLUR . log ( [ 'intro' , this . trainer _iterator ] ) ;
2010-09-17 12:40:42 -04:00
this . make _trainer _intro ( ) ;
this . load _feeds _trainer ( null , this . trainer _data ) ;
2010-10-17 23:34:14 -04:00
this . reload _modal ( ) ;
2010-10-18 18:14:47 -04:00
} else if ( this . trainer _iterator > 0 && this . trainer _iterator <= trainer _data _length ) {
var trainer _data = this . trainer _data [ this . trainer _iterator - 1 ] ;
NEWSBLUR . log ( [ 'previous' , trainer _data _length , this . trainer _iterator - 1 , trainer _data ] ) ;
2010-09-17 12:40:42 -04:00
this . load _feed ( trainer _data ) ;
}
} ,
load _next _feed _in _trainer : function ( backwards ) {
2010-10-18 18:14:47 -04:00
this . trainer _iterator = this . trainer _iterator + 1 ;
2010-08-01 23:47:40 -04:00
2010-10-18 18:14:47 -04:00
var trainer _data _length = this . trainer _data . length ;
if ( this . trainer _iterator > trainer _data _length ) {
NEWSBLUR . log ( [ 'outro' , this . trainer _iterator , trainer _data _length ] ) ;
2010-09-17 12:40:42 -04:00
this . make _trainer _outro ( ) ;
this . load _feeds _trainer ( null , this . trainer _data ) ;
2010-10-17 23:34:14 -04:00
this . reload _modal ( ) ;
} else {
2010-10-18 18:14:47 -04:00
var trainer _data = this . trainer _data [ this . trainer _iterator - 1 ] ;
NEWSBLUR . log ( [ 'next' , trainer _data _length , this . trainer _iterator - 1 , trainer _data ] ) ;
this . load _feed ( trainer _data ) ;
2010-09-17 12:40:42 -04:00
}
} ,
load _feed : function ( trainer _data ) {
2010-10-18 18:14:47 -04:00
this . feed _id = trainer _data [ 'feed_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' ] ;
2010-09-20 18:20:22 -04:00
this . options . feed _loaded = true ;
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 {
this . make _modal _feed ( ) ;
this . make _modal _title ( ) ;
this . make _modal _trainer _count ( ) ;
2010-08-01 23:47:40 -04:00
}
2010-10-18 18:14:47 -04:00
2010-08-01 19:12:42 -04:00
2010-10-17 23:34:14 -04:00
this . reload _modal ( ) ;
} ,
reload _modal : function ( ) {
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 _select _checkboxes ( ) ;
this . handle _cancel ( ) ;
}
} , 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 ) ;
NEWSBLUR . log ( [ 'data' , data ] ) ;
this . trainer _data = data ;
$begin . text ( 'Begin Training' )
2010-08-30 22:42:44 -04:00
. addClass ( 'NB-modal-submit-green' )
2010-10-14 09:51:56 -04:00
. removeClass ( 'NB-modal-submit-close' )
2010-08-01 19:12:42 -04:00
. removeClass ( 'NB-disabled' ) ;
} ,
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
if ( this . options . feed _loaded ) {
this . feed _tags = this . model . get _feed _tags ( ) ;
this . feed _authors = this . model . get _feed _authors ( ) ;
2010-10-05 19:05:01 -04:00
$ ( '.NB-modal-subtitle .NB-modal-feed-image' , this . $modal ) . attr ( 'src' , NEWSBLUR . Globals . google _favicon _url + this . feed [ 'feed_link' ] ) ;
2010-09-20 18:20:22 -04:00
$ ( '.NB-modal-subtitle .NB-modal-feed-title' , this . $modal ) . html ( this . feed [ 'feed_title' ] ) ;
}
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' ) ;
this . model . get _feeds _trainer ( this . feed _id , function ( data ) {
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-08-01 23:47:40 -04:00
this . $modal = $ . make ( 'div' , { className : 'NB-classifier 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' , [
$ . make ( 'img' , { src : NEWSBLUR . Globals . MEDIA _URL + '/img/reader/sample_classifier_tag.png' , style : 'float: right' , width : 135 , height : 20 } ) ,
$ . make ( 'b' , 'You will see a bunch of tags and authors.' ) ,
2010-10-17 17:25:10 -04:00
' Check the features you want to see in stories. If you check too many options, you won\'t find the good among the neutral.'
2010-08-01 23:47:40 -04:00
] ) ,
$ . make ( 'li' , [
$ . make ( 'img' , { src : NEWSBLUR . Globals . MEDIA _URL + '/img/reader/intelligence_slider_positive.png' , style : 'float: right' , width : 114 , height : 29 } ) ,
$ . make ( 'b' , 'What you select now will show when you use the intelligence slider.' ) ,
$ . 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 ( 'img' , { src : NEWSBLUR . Globals . MEDIA _URL + '/img/reader/sample_menu.png' , style : 'float: right' , width : 176 , height : 118 } ) ,
$ . make ( 'b' , 'Stop at any time you like.' ) ,
2010-10-17 17:25:10 -04:00
' You can always come back to this.'
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.' ) ,
' Just skip the site. You can click the ' ,
$ . 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-10-17 17:25:10 -04:00
' buttons as you read stories.'
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' ) ) ,
2010-10-14 09:51:56 -04:00
( NEWSBLUR . Globals . is _authenticated && $ . make ( 'a' , { href : '#' , className : 'NB-modal-submit-begin NB-modal-submit-button NB-modal-submit-close NB-disabled' } , 'Loading Training...' ) )
2010-08-02 09:28:56 -04:00
] )
] ) ;
} ,
make _trainer _outro : function ( ) {
var self = this ;
this . $modal = $ . make ( 'div' , { className : 'NB-classifier NB-modal NB-modal-trainer' } , [
$ . 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 ' ,
$ . 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 } ) ,
' 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' } , [
$ . 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 ;
var opinion = ( this . score == 1 ? 'like_' : 'dislike_' ) ;
2010-10-17 23:34:14 -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-08-01 23:47:40 -04:00
this . $modal = $ . make ( 'div' , { className : 'NB-classifier NB-modal ' + ( this . options [ 'training' ] && 'NB-modal-trainer' ) } , [
2010-08-01 19:12:42 -04:00
$ . make ( 'div' , { className : 'NB-modal-loading' } ) ,
( ! this . options [ 'training' ] && this . make _modal _intelligence _slider ( ) ) ,
( this . options [ 'training' ] && $ . make ( 'div' , { className : 'NB-classifier-trainer-counts' } ) ) ,
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-05 19:05:01 -04:00
$ . make ( 'img' , { className : 'NB-modal-feed-image feed_favicon' , src : NEWSBLUR . Globals . google _favicon _url + this . feed . feed _link } ) ,
2010-08-01 19:12:42 -04:00
$ . make ( 'span' , { className : 'NB-modal-feed-title' } , this . feed . feed _title )
] ) ,
2010-09-20 18:20:22 -04:00
( this . options [ 'feed_loaded' ] &&
$ . make ( 'form' , { method : 'post' , className : 'NB-publisher' } , [
( 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' } ,
this . make _authors ( this . feed _authors , opinion )
)
] ) ) ,
( 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' } ,
this . make _tags ( this . feed _tags , opinion )
)
] ) ) ,
$ . make ( 'div' , { className : 'NB-modal-field NB-fieldset NB-classifiers' } , [
$ . make ( 'h5' , 'Everything by This Publisher' ) ,
$ . make ( 'div' , { className : 'NB-fieldset-fields NB-classifiers' } ,
this . make _publisher ( feed , opinion )
)
] ) ,
( this . options [ 'training' ] && $ . make ( 'div' , { className : 'NB-modal-submit' } , [
$ . make ( 'input' , { name : 'score' , value : this . score , type : 'hidden' } ) ,
$ . 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' ) ,
$ . make ( 'a' , { href : '#' , className : 'NB-modal-submit-button NB-modal-submit-green NB-modal-submit-save' } , 'Save & Next ' + $ . entity ( '»' ) ) ,
$ . 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 : 'score' , value : this . score , type : 'hidden' } ) ,
$ . 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' )
] ) )
] ) . bind ( 'submit' , function ( e ) {
e . preventDefault ( ) ;
self . save _publisher ( ) ;
return false ;
} )
)
2010-06-08 11:19:41 -04:00
] ) ;
} ,
make _modal _story : function ( ) {
var self = this ;
var story = this . story ;
var feed = this . feed ;
var opinion = ( this . score == 1 ? 'like_' : 'dislike_' ) ;
NEWSBLUR . log ( [ 'Make Story' , story , feed ] ) ;
// HTML entities decoding.
story . story _title = $ ( '<div/>' ) . html ( story . story _title ) . text ( ) ;
2010-08-01 19:12:42 -04:00
this . $modal = $ . make ( 'div' , { className : 'NB-classifier NB-modal' } , [
2010-06-08 11:19:41 -04:00
this . make _modal _intelligence _slider ( ) ,
$ . make ( 'h2' , { className : 'NB-modal-title' } ) ,
$ . make ( 'form' , { method : 'post' } , [
( story . story _title && $ . make ( 'div' , { className : 'NB-modal-field NB-fieldset' } , [
$ . make ( 'h5' , 'Story Title' ) ,
$ . make ( 'div' , { className : 'NB-fieldset-fields NB-classifiers' } , [
$ . make ( 'input' , { type : 'text' , value : story . story _title , className : 'NB-classifier-title-highlight' } ) ,
$ . make ( 'div' , { className : 'NB-classifier NB-classifier-title NB-classifier-facet-disabled' } , [
$ . make ( 'input' , { type : 'checkbox' , name : opinion + 'title' , value : '' , id : 'classifier_title' } ) ,
$ . make ( 'label' , { 'for' : 'classifier_title' } , [
$ . make ( 'b' , 'Look for: ' ) ,
$ . make ( 'span' , { className : 'NB-classifier-title-text' } , 'Highlight phrases to look for in future stories' )
] )
] )
] )
] ) ) ,
( story . story _authors && $ . make ( 'div' , { className : 'NB-modal-field NB-fieldset' } , [
$ . make ( 'h5' , 'Story Author' ) ,
$ . make ( 'div' , { className : 'NB-fieldset-fields NB-classifiers' } ,
this . make _authors ( [ story . story _authors ] , opinion )
)
] ) ) ,
( story . story _tags . length && $ . make ( 'div' , { className : 'NB-modal-field NB-fieldset' } , [
$ . make ( 'h5' , 'Story Categories & Tags' ) ,
$ . make ( 'div' , { className : 'NB-classifier-tags NB-fieldset-fields NB-classifiers' } ,
this . make _tags ( story . story _tags , opinion )
)
] ) ) ,
$ . make ( 'div' , { className : 'NB-modal-field NB-fieldset' } , [
$ . make ( 'h5' , 'Everything by This Publisher' ) ,
$ . make ( 'div' , { className : 'NB-fieldset-fields NB-classifiers' } ,
this . make _publisher ( feed , opinion )
)
] ) ,
$ . make ( 'div' , { className : 'NB-modal-submit' } , [
$ . make ( 'input' , { name : 'score' , value : this . score , type : 'hidden' } ) ,
$ . make ( 'input' , { name : 'story_id' , value : this . story _id , type : 'hidden' } ) ,
2010-08-01 19:12:42 -04:00
$ . make ( 'input' , { name : 'feed_id' , value : this . feed _id , type : 'hidden' } ) ,
2010-08-30 22:42:44 -04:00
$ . make ( 'input' , { type : 'submit' , disabled : 'true' , className : 'NB-modal-submit-save NB-modal-submit-green NB-disabled' , value : 'Check what you like above...' } ) ,
2010-06-08 11:19:41 -04:00
' or ' ,
$ . make ( 'a' , { href : '#' , className : 'NB-modal-cancel' } , 'cancel' )
] )
] ) . bind ( 'submit' , function ( e ) {
e . preventDefault ( ) ;
self . save _story ( ) ;
return false ;
} )
] ) ;
} ,
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
if ( this . flags [ 'publisher' ] ) {
if ( this . score == 1 ) {
2010-07-30 20:04:02 -04:00
$modal _title . html ( 'What do you <b class="NB-classifier-like">like</b> about this site?' ) ;
2010-06-08 11:19:41 -04:00
} else if ( this . score == - 1 ) {
2010-07-30 20:04:02 -04:00
$modal _title . html ( 'What do you <b class="NB-classifier-dislike">dislike</b> about this site?' ) ;
2010-06-08 11:19:41 -04:00
}
} else if ( this . flags [ 'story' ] ) {
if ( this . score == 1 ) {
$modal _title . html ( 'What do you <b class="NB-classifier-like">like</b> about this story?' ) ;
} else if ( this . score == - 1 ) {
$modal _title . html ( 'What do you <b class="NB-classifier-dislike">dislike</b> about this story?' ) ;
}
}
} ,
2010-08-01 19:12:42 -04:00
make _modal _trainer _count : function ( ) {
var $count = $ ( '.NB-classifier-trainer-counts' , this . $modal ) ;
var count = this . trainer _iterator ;
var total = this . trainer _data . length ;
$count . html ( count + '/' + total ) ;
} ,
2010-06-08 11:19:41 -04:00
make _modal _intelligence _slider : function ( ) {
var self = this ;
var $slider = $ . make ( 'div' , { className : 'NB-taskbar-intelligence NB-modal-slider' } , [
$ . make ( 'div' , { className : 'NB-taskbar-intelligence-indicator NB-taskbar-intelligence-negative' } ) ,
$ . make ( 'div' , { className : 'NB-taskbar-intelligence-indicator NB-taskbar-intelligence-neutral' } ) ,
$ . make ( 'div' , { className : 'NB-taskbar-intelligence-indicator NB-taskbar-intelligence-positive' } ) ,
$ . make ( 'div' , { className : 'NB-intelligence-slider' } )
] ) ;
$ ( '.NB-intelligence-slider' , $slider ) . slider ( {
range : 'max' ,
2010-07-25 15:34:50 -04:00
min : 0 ,
max : 2 ,
2010-06-08 11:19:41 -04:00
step : 2 ,
2010-07-25 15:34:50 -04:00
value : this . score + 1 ,
2010-06-08 11:19:41 -04:00
slide : function ( e , ui ) {
// self.switch_feed_view_unread_view(ui.value);
2010-07-25 15:34:50 -04:00
self . score = ui . value - 1 ;
2010-06-08 11:19:41 -04:00
self . make _modal _title ( ) ;
2010-08-01 19:12:42 -04:00
$ ( 'input[name^=like],input[name^=dislike]' , self . $modal ) . attr ( 'name' , function ( i , current _name ) {
2010-06-08 11:19:41 -04:00
if ( self . score == - 1 ) {
return 'dis' + current _name . substr ( current _name . indexOf ( 'like_' ) ) ;
} else if ( self . score == 1 ) {
return current _name . substr ( current _name . indexOf ( 'like_' ) ) ;
}
} ) ;
2010-08-01 19:12:42 -04:00
var $submit = $ ( 'input[type=submit]' , self . $modal ) ;
2010-07-25 15:34:50 -04:00
$submit . removeClass ( "NB-disabled" ) . removeAttr ( 'disabled' ) . attr ( 'value' , 'Save' ) ;
2010-06-08 11:19:41 -04:00
}
} ) ;
return $slider ;
} ,
make _authors : function ( authors , opinion ) {
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 ;
var input _attrs = {
type : 'checkbox' ,
name : opinion + 'author' ,
value : author ,
id : 'classifier_author_' + a
} ;
2010-08-01 19:12:42 -04:00
if ( author in this . user _classifiers . authors
&& this . user _classifiers . authors [ author ] == this . score ) {
2010-06-08 11:19:41 -04:00
input _attrs [ 'checked' ] = 'checked' ;
}
var $author = $ . make ( 'span' , { className : 'NB-classifier-container NB-classifier-author-container' } , [
$ . make ( 'span' , { className : 'NB-classifier NB-classifier-author' } , [
$ . make ( 'input' , input _attrs ) ,
$ . make ( 'label' , { 'for' : 'classifier_author_' + a } , [
$ . make ( 'b' , 'Author: ' ) ,
$ . make ( 'span' , author )
] )
] ) ,
( author _count && $ . make ( 'span' , { className : 'NB-classifier-tag-count' } , [
'× ' ,
author _count
] ) )
] ) ;
$authors . push ( $author ) ;
}
return $authors ;
} ,
make _tags : function ( tags , opinion ) {
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 ;
var input _attrs = {
type : 'checkbox' ,
name : opinion + 'tag' ,
value : tag ,
id : 'classifier_tag_' + t
} ;
2010-08-01 19:12:42 -04:00
if ( tag in this . user _classifiers . tags && this . user _classifiers . tags [ tag ] == this . score ) {
2010-06-08 11:19:41 -04:00
input _attrs [ 'checked' ] = 'checked' ;
}
var $tag = $ . make ( 'span' , { className : 'NB-classifier-container NB-classifier-tag-container' } , [
$ . make ( 'span' , { className : 'NB-classifier NB-classifier-tag' } , [
$ . make ( 'input' , input _attrs ) ,
$ . make ( 'label' , { 'for' : 'classifier_tag_' + t } , [
$ . make ( 'b' , 'Tag: ' ) ,
$ . make ( 'span' , tag )
] )
] ) ,
( tag _count && $ . make ( 'span' , { className : 'NB-classifier-tag-count' } , [
'× ' ,
tag _count
] ) )
] ) ;
$tags . push ( $tag ) ;
}
return $tags ;
} ,
make _publisher : function ( publisher , opinion ) {
var input _attrs = {
type : 'checkbox' ,
name : opinion + 'publisher' ,
value : this . feed _id ,
id : 'classifier_publisher' ,
checked : false
} ;
2010-08-22 18:34:40 -04:00
if ( this . user _classifiers . feeds [ this . feed _id ] == this . score ) {
2010-06-08 11:19:41 -04:00
input _attrs [ 'checked' ] = true ;
}
var $publisher = $ . make ( 'div' , { className : 'NB-classifier NB-classifier-publisher' } , [
$ . make ( 'input' , input _attrs ) ,
$ . make ( 'label' , { 'for' : 'classifier_publisher' } , [
2010-10-05 19:05:01 -04:00
$ . make ( 'img' , { className : 'feed_favicon' , src : NEWSBLUR . Globals . google _favicon _url + publisher . feed _link } ) ,
2010-06-08 11:19:41 -04:00
$ . make ( 'span' , { className : 'feed_title' } , [
$ . make ( 'b' , 'Publisher: ' ) ,
$ . make ( 'span' , publisher . feed _title )
] )
] )
] ) ;
return $publisher ;
} ,
make _title : function ( title , t , opinion ) {
var $title = $ . make ( 'div' , { className : 'NB-classifier NB-classifier-title' } , [
$ . make ( 'input' , { type : 'checkbox' , name : opinion + 'title' , value : title , id : 'classifier_title_' + t , checked : 'checked' } ) ,
$ . make ( 'label' , { 'for' : 'classifier_title_' + t } , [
$ . make ( 'b' , 'Title: ' ) ,
$ . make ( 'span' , title )
] )
] ) ;
return $title ;
} ,
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 ;
2010-10-14 09:51:56 -04:00
$ ( window ) . resize ( ) ;
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 ( ) ;
}
} ) ;
} ,
handle _text _highlight : function ( ) {
2010-08-01 19:12:42 -04:00
var $title _highlight = $ ( '.NB-classifier-title-highlight' , this . $modal ) ;
var $title = $ ( '.NB-classifier-title-text' , this . $modal ) ;
var $title _checkbox = $ ( '#classifier_title' , this . $modal ) ;
2010-06-08 11:19:41 -04:00
var update = function ( ) {
var text = $ . trim ( $ ( this ) . getSelection ( ) . text ) ;
if ( $title . text ( ) != text && text . length ) {
$title _checkbox . attr ( 'checked' , 'checked' ) . change ( ) ;
$title . text ( text ) ;
$title _checkbox . parents ( '.NB-classifier-facet-disabled' )
. removeClass ( 'NB-classifier-facet-disabled' ) ;
$title _checkbox . val ( text ) ;
}
} ;
$title _highlight
. keydown ( update ) . keyup ( update )
. mousedown ( update ) . mouseup ( update ) . mousemove ( update ) ;
} ,
handle _select _title : function ( ) {
2010-08-01 19:12:42 -04:00
var $title _checkbox = $ ( '#classifier_title' , this . $modal ) ;
var $title = $ ( '.NB-classifier-title-text' , this . $modal ) ;
var $title _highlight = $ ( '.NB-classifier-title-highlight' , this . $modal ) ;
2010-06-08 11:19:41 -04:00
$title _checkbox . change ( function ( ) { ;
if ( $title . parents ( '.NB-classifier-facet-disabled' ) . length ) {
var text = $title _highlight . val ( ) ;
$title . text ( text ) ;
$title _checkbox . parents ( '.NB-classifier-facet-disabled' )
. removeClass ( 'NB-classifier-facet-disabled' ) ;
$title _checkbox . val ( text ) ;
}
} ) ;
} ,
handle _select _checkboxes : function ( ) {
var self = this ;
2010-08-01 19:12:42 -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-06-08 11:19:41 -04:00
2010-08-01 19:12:42 -04:00
$ ( 'input' , this . $modal ) . change ( function ( ) {
// var count = $('input:checked', self.$modal).length;
if ( self . options [ 'training' ] ) {
$close . val ( 'Save & Close' ) ;
} else {
2010-08-01 23:47:40 -04:00
$save . removeClass ( "NB-disabled" ) . removeAttr ( 'disabled' ) . attr ( 'value' , 'Save' ) ;
2010-08-01 19:12:42 -04: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 ;
$ . targetIs ( e , { tagSelector : '.NB-modal-submit-begin' } , function ( $t , $p ) {
e . preventDefault ( ) ;
self . load _next _feed _in _trainer ( ) ;
} ) ;
$ . targetIs ( e , { tagSelector : '.NB-modal-submit-save:not(.NB-modal-submit-begin)' } , function ( $t , $p ) {
e . preventDefault ( ) ;
self . save _publisher ( true ) ;
self . load _next _feed _in _trainer ( ) ;
} ) ;
$ . targetIs ( e , { tagSelector : '.NB-modal-submit-back' } , function ( $t , $p ) {
e . preventDefault ( ) ;
2010-09-17 12:40:42 -04:00
self . load _previous _feed _in _trainer ( ) ;
2010-08-01 19:12:42 -04:00
} ) ;
$ . targetIs ( e , { tagSelector : '.NB-modal-submit-close' } , function ( $t , $p ) {
e . preventDefault ( ) ;
self . save _publisher ( ) ;
} ) ;
2010-08-02 09:28:56 -04:00
$ . targetIs ( e , { tagSelector : '.NB-modal-submit-end' } , function ( $t , $p ) {
e . preventDefault ( ) ;
2010-10-17 23:34:14 -04:00
$ . modal . close ( ) ;
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 ( ) {
2010-08-01 19:12:42 -04:00
var checked _data = $ ( 'input' , this . $modal ) . serialize ( ) ;
2010-06-08 11:19:41 -04:00
2010-08-01 19:12:42 -04:00
var $unchecked = $ ( 'input[type=checkbox]:not(:checked)' , this . $modal ) ;
2010-06-08 11:19:41 -04:00
$unchecked . attr ( 'checked' , true ) ;
$unchecked . each ( function ( ) {
$ ( this ) . attr ( 'name' , 'remove_' + $ ( this ) . attr ( 'name' ) ) ;
} ) ;
var unchecked _data = $unchecked . serialize ( ) ;
$unchecked . each ( function ( ) {
$ ( this ) . attr ( 'name' , $ ( this ) . attr ( 'name' ) . replace ( /^remove_/ , '' ) ) ;
} ) ;
$unchecked . attr ( 'checked' , false ) ;
var data = [ checked _data , unchecked _data ] . join ( '&' ) ;
return data ;
} ,
2010-08-01 19:12:42 -04:00
save _publisher : 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 ( ) ;
2010-08-01 19:12:42 -04:00
NEWSBLUR . reader . update _opinions ( this . $modal , 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 ) ;
2010-06-08 11:19:41 -04:00
this . model . save _classifier _publisher ( data , function ( ) {
2010-08-01 19:12:42 -04:00
if ( ! keep _modal _open ) {
2010-10-10 23:33:56 -04:00
NEWSBLUR . reader . force _feeds _refresh ( ) ;
2010-10-15 19:02:19 -04:00
if ( self . feed _id == NEWSBLUR . reader . active _feed ) {
NEWSBLUR . reader . load _feed ( self . feed _id , null , true ) ;
}
2010-08-01 19:12:42 -04:00
$ . modal . close ( ) ;
}
2010-06-08 11:19:41 -04:00
} ) ;
} ,
save _story : function ( ) {
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 story _id = this . story _id ;
var data = this . serialize _classifier ( ) ;
2010-08-01 19:12:42 -04:00
NEWSBLUR . reader . update _opinions ( this . $modal , this . feed _id ) ;
2010-06-08 11:19:41 -04:00
$save . text ( 'Saving...' ) . addClass ( 'NB-disabled' ) . attr ( 'disabled' , true ) ;
this . model . save _classifier _story ( story _id , data , function ( ) {
2010-10-10 23:33:56 -04:00
NEWSBLUR . reader . force _feeds _refresh ( ) ;
2010-10-11 12:07:32 -04:00
NEWSBLUR . reader . open _feed ( self . feed _id , true ) ;
2010-06-08 11:19:41 -04:00
$ . modal . close ( ) ;
} ) ;
}
} ;
NEWSBLUR . ReaderClassifierStory . prototype = classifier ;
NEWSBLUR . ReaderClassifierFeed . prototype = classifier ;
2010-08-01 19:12:42 -04:00
NEWSBLUR . ReaderClassifierTrainer . prototype = classifier ;