2010-08-01 19:12:42 -04:00
|
|
|
NEWSBLUR.ReaderClassifierTrainer = function(options) {
|
|
|
|
var defaults = {
|
|
|
|
'score': 1,
|
|
|
|
'training': true
|
|
|
|
};
|
|
|
|
|
|
|
|
this.flags = {
|
|
|
|
'publisher': true,
|
|
|
|
'story': false
|
|
|
|
};
|
|
|
|
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.google_favicon_url = 'http://www.google.com/s2/favicons?domain_url=';
|
|
|
|
this.runner_trainer();
|
|
|
|
};
|
|
|
|
|
|
|
|
NEWSBLUR.ReaderClassifierFeed = function(feed_id, options) {
|
|
|
|
var defaults = {
|
|
|
|
'score': 1,
|
|
|
|
'training': false
|
|
|
|
};
|
2010-06-08 11:19:41 -04:00
|
|
|
|
|
|
|
this.flags = {
|
|
|
|
'publisher': true,
|
|
|
|
'story': false
|
|
|
|
};
|
|
|
|
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.google_favicon_url = 'http://www.google.com/s2/favicons?domain_url=';
|
|
|
|
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,
|
|
|
|
'story': true
|
|
|
|
};
|
|
|
|
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.google_favicon_url = 'http://www.google.com/s2/favicons?domain_url=';
|
|
|
|
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
|
|
|
this.user_classifiers = this.model.classifiers;
|
|
|
|
|
2010-06-08 11:19:41 -04:00
|
|
|
this.find_story_and_feed();
|
|
|
|
this.make_modal_feed();
|
|
|
|
this.make_modal_title();
|
|
|
|
this.make_modal_intelligence_slider();
|
|
|
|
this.handle_select_checkboxes();
|
|
|
|
this.handle_cancel();
|
|
|
|
this.handle_select_title();
|
|
|
|
this.open_modal();
|
|
|
|
},
|
|
|
|
|
|
|
|
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-08-01 19:12:42 -04:00
|
|
|
load_next_feed_in_trainer: function(backwards) {
|
|
|
|
if (backwards) {
|
2010-08-01 23:47:40 -04:00
|
|
|
this.trainer_iterator = this.trainer_iterator - 1;
|
|
|
|
if (this.trainer_iterator < 1) {
|
|
|
|
this.make_trainer_intro();
|
|
|
|
this.load_feeds_trainer(null, this.trainer_data);
|
|
|
|
}
|
2010-08-01 19:12:42 -04:00
|
|
|
} else {
|
|
|
|
this.trainer_iterator = Math.min(this.trainer_data.length, this.trainer_iterator + 1);
|
|
|
|
}
|
|
|
|
|
2010-08-01 23:47:40 -04:00
|
|
|
// Show only feeds, not the trainer intro if going backwards.
|
|
|
|
if (this.trainer_iterator > 0) {
|
|
|
|
var trainer_data = this.trainer_data[this.trainer_iterator-1];
|
|
|
|
this.feed_id = trainer_data['feed_id'];
|
|
|
|
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'];
|
|
|
|
|
|
|
|
this.make_modal_feed();
|
|
|
|
this.make_modal_title();
|
|
|
|
this.make_modal_trainer_count();
|
|
|
|
|
|
|
|
if (backwards || this.feed_id in this.cache) {
|
|
|
|
this.$modal = this.cache[this.feed_id];
|
|
|
|
}
|
|
|
|
}
|
2010-08-01 19:12:42 -04:00
|
|
|
|
2010-08-01 23:47:40 -04:00
|
|
|
$('.NB-modal').replaceWith(this.$modal);
|
2010-08-01 19:12:42 -04:00
|
|
|
$.modal.impl.resize(this.$modal);
|
|
|
|
},
|
|
|
|
|
|
|
|
get_feeds_trainer: function() {
|
|
|
|
this.model.get_feeds_trainer($.rescope(this.load_feeds_trainer, this));
|
|
|
|
},
|
|
|
|
|
|
|
|
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')
|
|
|
|
.addClass('NB-modal-submit-save')
|
|
|
|
.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);
|
|
|
|
}
|
|
|
|
this.feed = this.model.get_feed(this.feed_id);
|
|
|
|
this.feed_tags = this.model.get_feed_tags();
|
|
|
|
this.feed_authors = this.model.get_feed_authors();
|
2010-08-01 19:12:42 -04:00
|
|
|
|
|
|
|
$('.NB-modal-subtitle .NB-modal-feed-image', this.$modal).attr('src', this.google_favicon_url + this.feed['feed_link']);
|
|
|
|
$('.NB-modal-subtitle .NB-modal-feed-title', this.$modal).html(this.feed['feed_title']);
|
|
|
|
},
|
|
|
|
|
|
|
|
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.'),
|
|
|
|
' Check the features you want to see in stories. If you check too many options, you won\'t filter the good stories from the neutral stories.'
|
|
|
|
]),
|
|
|
|
$.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.'),
|
|
|
|
' You can always come back to this trainer.'
|
|
|
|
]),
|
|
|
|
$.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 }),
|
|
|
|
' buttons next to stories as you read them.'
|
|
|
|
])
|
|
|
|
]),
|
2010-08-01 19:12:42 -04:00
|
|
|
$.make('div', { className: 'NB-modal-submit' }, [
|
|
|
|
$.make('a', { href: '#', className: 'NB-modal-submit-save NB-modal-submit-begin NB-modal-submit-button NB-disabled' }, 'Loading Training...')
|
|
|
|
])
|
|
|
|
]);
|
|
|
|
|
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-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-06-08 11:19:41 -04:00
|
|
|
$.make('h2', { className: 'NB-modal-title' }),
|
2010-08-01 19:12:42 -04:00
|
|
|
$.make('h2', { className: 'NB-modal-subtitle' }, [
|
|
|
|
$.make('img', { className: 'NB-modal-feed-image feed_favicon', src: this.google_favicon_url + this.feed.feed_link }),
|
|
|
|
$.make('span', { className: 'NB-modal-feed-title' }, this.feed.feed_title)
|
|
|
|
]),
|
2010-06-08 11:19:41 -04:00
|
|
|
$.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)
|
|
|
|
)
|
|
|
|
]),
|
2010-08-01 19:12:42 -04:00
|
|
|
(this.options['training'] && $.make('div', { className: 'NB-modal-submit' }, [
|
2010-06-08 11:19:41 -04:00
|
|
|
$.make('input', { name: 'score', value: this.score, type: 'hidden' }),
|
|
|
|
$.make('input', { name: 'feed_id', value: this.feed_id, type: 'hidden' }),
|
2010-08-01 19:12:42 -04:00
|
|
|
$.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-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' }),
|
2010-06-08 11:19:41 -04:00
|
|
|
$.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' }),
|
|
|
|
$.make('input', { type: 'submit', disabled: 'true', className: 'NB-modal-submit-save 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')
|
2010-08-01 19:12:42 -04:00
|
|
|
]))
|
2010-08-01 23:59:22 -04:00
|
|
|
]).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' }),
|
|
|
|
$.make('input', { type: 'submit', disabled: 'true', className: 'NB-modal-submit-save 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-01 19:12:42 -04:00
|
|
|
if (this.feed.feed_link in this.user_classifiers.feeds
|
|
|
|
&& this.user_classifiers.feeds[this.feed.feed_link].score == 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' }, [
|
|
|
|
$.make('img', { className: 'feed_favicon', src: this.google_favicon_url + publisher.feed_link }),
|
|
|
|
$.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;
|
|
|
|
|
|
|
|
var $holder = $.make('div', { className: 'NB-modal-holder' })
|
2010-08-01 19:12:42 -04:00
|
|
|
.append(this.$modal)
|
2010-06-08 11:19:41 -04:00
|
|
|
.appendTo('body')
|
|
|
|
.css({'visibility': 'hidden', 'display': 'block', 'width': 600});
|
|
|
|
var height = $('.NB-classifier', $holder).outerHeight(true);
|
|
|
|
$holder.css({'visibility': 'visible', 'display': 'none'});
|
2010-06-30 12:17:22 -04:00
|
|
|
var w = $.modal.impl.getDimensions();
|
|
|
|
if (height > w[0] - 70) {
|
|
|
|
height = w[0] - 70;
|
|
|
|
}
|
2010-06-08 11:19:41 -04:00
|
|
|
|
2010-08-01 19:12:42 -04:00
|
|
|
this.$modal.modal({
|
2010-06-08 11:19:41 -04:00
|
|
|
'minWidth': 600,
|
|
|
|
'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-06-08 11:19:41 -04:00
|
|
|
},
|
|
|
|
'onShow': function(dialog) {
|
|
|
|
$('#simplemodal-container').corner('6px').css({'width': 600, 'height': height});
|
2010-08-01 19:12:42 -04:00
|
|
|
$('.NB-classifier', self.$modal).corner('14px');
|
2010-07-25 15:34:50 -04:00
|
|
|
$.modal.impl.setPosition();
|
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();
|
|
|
|
self.load_next_feed_in_trainer(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
$.targetIs(e, { tagSelector: '.NB-modal-submit-close' }, function($t, $p){
|
|
|
|
e.preventDefault();
|
|
|
|
self.save_publisher();
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
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) {
|
|
|
|
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
|
|
|
|
2010-08-01 19:12:42 -04:00
|
|
|
if (this.options['training']) {
|
|
|
|
this.cache[this.feed_id] = this.$modal.clone();
|
|
|
|
}
|
2010-06-08 11:19:41 -04:00
|
|
|
$save.text('Saving...').addClass('NB-disabled').attr('disabled', true);
|
|
|
|
this.model.save_classifier_publisher(data, function() {
|
2010-08-01 19:12:42 -04:00
|
|
|
if (!keep_modal_open) {
|
|
|
|
NEWSBLUR.reader.force_feed_refresh();
|
|
|
|
$.modal.close();
|
|
|
|
}
|
2010-06-08 11:19:41 -04:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
save_story: function() {
|
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() {
|
|
|
|
NEWSBLUR.reader.force_feed_refresh();
|
|
|
|
$.modal.close();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
NEWSBLUR.ReaderClassifierStory.prototype = classifier;
|
|
|
|
NEWSBLUR.ReaderClassifierFeed.prototype = classifier;
|
2010-08-01 19:12:42 -04:00
|
|
|
NEWSBLUR.ReaderClassifierTrainer.prototype = classifier;
|