2011-06-09 22:08:59 -04:00
|
|
|
NEWSBLUR.utils = {
|
|
|
|
|
2011-06-16 23:45:41 -04:00
|
|
|
compute_story_score: function(story) {
|
|
|
|
var score = 0;
|
2012-05-24 17:32:01 -07:00
|
|
|
var intelligence = story.get('intelligence');
|
|
|
|
var score_max = Math.max(intelligence['title'],
|
|
|
|
intelligence['author'],
|
|
|
|
intelligence['tags']);
|
|
|
|
var score_min = Math.min(intelligence['title'],
|
|
|
|
intelligence['author'],
|
|
|
|
intelligence['tags']);
|
2011-06-16 23:45:41 -04:00
|
|
|
if (score_max > 0) score = score_max;
|
|
|
|
else if (score_min < 0) score = score_min;
|
2011-06-09 22:08:59 -04:00
|
|
|
|
2012-05-24 17:32:01 -07:00
|
|
|
if (score == 0) score = intelligence['feed'];
|
2011-06-09 22:08:59 -04:00
|
|
|
|
2011-06-16 23:45:41 -04:00
|
|
|
return score;
|
|
|
|
},
|
2012-05-24 17:32:01 -07:00
|
|
|
|
2012-06-25 11:55:38 -07:00
|
|
|
generate_shadow: _.memoize(function(feed) {
|
|
|
|
if (!feed) return '';
|
|
|
|
var color = feed.get('favicon_color');
|
|
|
|
|
|
|
|
if (!color) {
|
|
|
|
return '0 1px 0 #222';
|
|
|
|
}
|
|
|
|
|
|
|
|
var r = parseInt(color.substr(0, 2), 16);
|
|
|
|
var g = parseInt(color.substr(2, 2), 16);
|
|
|
|
var b = parseInt(color.substr(4, 2), 16);
|
|
|
|
|
|
|
|
if (feed.is_light()) {
|
|
|
|
return [
|
|
|
|
'0 1px 0 ',
|
|
|
|
'rgb(',
|
|
|
|
[r+35, g+35, b+35].join(','),
|
|
|
|
')'
|
|
|
|
].join('');
|
|
|
|
} else {
|
|
|
|
return [
|
|
|
|
'0 1px 0 ',
|
|
|
|
'rgb(',
|
|
|
|
[
|
|
|
|
parseInt(r*(6/8), 10),
|
|
|
|
parseInt(g*(6/8), 10),
|
|
|
|
parseInt(b*(6/8), 10)
|
|
|
|
].join(','),
|
|
|
|
')'
|
|
|
|
].join('');
|
|
|
|
}
|
|
|
|
}, function(feed) {
|
|
|
|
return "" + feed.id;
|
|
|
|
}),
|
|
|
|
|
2012-05-24 17:32:01 -07:00
|
|
|
generate_gradient: _.memoize(function(feed, type) {
|
2011-06-16 23:45:41 -04:00
|
|
|
if (!feed) return '';
|
2012-05-21 14:36:54 -07:00
|
|
|
var color = feed.get('favicon_color');
|
2011-06-16 23:45:41 -04:00
|
|
|
if (!color) return '';
|
|
|
|
|
|
|
|
var r = parseInt(color.substr(0, 2), 16);
|
|
|
|
var g = parseInt(color.substr(2, 2), 16);
|
|
|
|
var b = parseInt(color.substr(4, 2), 16);
|
2012-05-21 14:58:25 -07:00
|
|
|
|
2012-06-25 11:55:38 -07:00
|
|
|
if (type == 'border') {
|
2011-06-16 23:45:41 -04:00
|
|
|
return [
|
2012-05-17 14:42:34 -07:00
|
|
|
(type == 'border' ? '1px solid ' : '') + 'rgb(',
|
2011-06-16 23:45:41 -04:00
|
|
|
[
|
|
|
|
parseInt(r*(6/8), 10),
|
|
|
|
parseInt(g*(6/8), 10),
|
|
|
|
parseInt(b*(6/8), 10)
|
|
|
|
].join(','),
|
|
|
|
')'
|
|
|
|
].join('');
|
|
|
|
} else if (type == 'webkit') {
|
|
|
|
return [
|
|
|
|
'-webkit-gradient(',
|
|
|
|
'linear,',
|
|
|
|
'left bottom,',
|
|
|
|
'left top,',
|
|
|
|
'color-stop(0, rgba(',
|
|
|
|
[
|
|
|
|
r,
|
|
|
|
g,
|
|
|
|
b,
|
|
|
|
255
|
|
|
|
].join(','),
|
|
|
|
')),',
|
|
|
|
'color-stop(1, rgba(',
|
|
|
|
[
|
|
|
|
r+35,
|
|
|
|
g+35,
|
|
|
|
b+35,
|
|
|
|
255
|
|
|
|
].join(','),
|
|
|
|
')))'
|
|
|
|
].join('');
|
|
|
|
} else if (type == 'moz') {
|
|
|
|
return [
|
|
|
|
'-moz-linear-gradient(',
|
|
|
|
'center bottom,',
|
|
|
|
'rgb(',
|
|
|
|
[
|
|
|
|
r,
|
|
|
|
g,
|
|
|
|
b
|
|
|
|
].join(','),
|
|
|
|
') 0%,',
|
|
|
|
'rgb(',
|
|
|
|
[
|
|
|
|
r+35,
|
|
|
|
g+35,
|
|
|
|
b+35
|
|
|
|
].join(','),
|
|
|
|
') 100%)'
|
|
|
|
].join('');
|
|
|
|
}
|
2012-05-24 17:32:01 -07:00
|
|
|
}, function(feed, type) {
|
|
|
|
return "" + feed.id + '-' + type;
|
|
|
|
}),
|
2011-06-16 23:45:41 -04:00
|
|
|
|
2012-02-16 18:36:52 -08:00
|
|
|
is_feed_social: function(feed_id) {
|
|
|
|
return _.string.include(feed_id, 'social:');
|
|
|
|
},
|
|
|
|
|
2012-05-24 11:54:10 -07:00
|
|
|
make_folders: function(model, selected_folder_title) {
|
2011-09-04 15:42:13 -07:00
|
|
|
var folders = model.get_folders();
|
|
|
|
var $options = $.make('select', { className: 'NB-folders'});
|
|
|
|
|
|
|
|
var $option = $.make('option', { value: '' }, "Top Level");
|
|
|
|
$options.append($option);
|
|
|
|
|
2012-05-24 11:54:10 -07:00
|
|
|
$options = this.make_folder_options($options, folders, ' ', selected_folder_title);
|
2011-09-04 15:42:13 -07:00
|
|
|
|
|
|
|
return $options;
|
|
|
|
},
|
|
|
|
|
2012-05-24 11:54:10 -07:00
|
|
|
make_folder_options: function($options, items, depth, selected_folder_title) {
|
2012-05-21 20:08:27 -07:00
|
|
|
var self = this;
|
|
|
|
items.each(function(item) {
|
|
|
|
if (item.is_folder()) {
|
|
|
|
var $option = $.make('option', {
|
|
|
|
value: item.get('folder_title')
|
|
|
|
}, depth + ' ' + item.get('folder_title'));
|
|
|
|
$options.append($option);
|
2012-05-24 11:54:10 -07:00
|
|
|
if (item.get('folder_title') == selected_folder_title) {
|
|
|
|
$option.attr('selected', true);
|
|
|
|
}
|
|
|
|
$options = self.make_folder_options($options, item.folders, depth+' ', selected_folder_title);
|
2011-09-04 15:42:13 -07:00
|
|
|
}
|
2012-05-21 20:08:27 -07:00
|
|
|
});
|
2011-09-04 15:42:13 -07:00
|
|
|
|
|
|
|
return $options;
|
2012-05-09 12:09:23 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
is_url_iframe_buster: function(url) {
|
2012-09-05 11:32:12 -07:00
|
|
|
// Also change in utils/page_importer.py.
|
2012-05-14 15:01:30 -07:00
|
|
|
var BROKEN_URLS = [
|
2012-05-09 12:09:23 -07:00
|
|
|
'nytimes.com',
|
2013-01-02 18:37:15 -08:00
|
|
|
'washingtonpost.com',
|
2012-05-09 12:09:23 -07:00
|
|
|
'stackoverflow.com',
|
2012-05-14 15:01:30 -07:00
|
|
|
'stackexchange.com',
|
2012-08-14 11:10:47 -07:00
|
|
|
'twitter.com',
|
2012-08-14 11:41:10 -07:00
|
|
|
'rankexploits'
|
2012-05-09 12:09:23 -07:00
|
|
|
];
|
|
|
|
return _.any(BROKEN_URLS, function(broken_url) {
|
2012-05-09 12:11:04 -07:00
|
|
|
return _.string.contains(url, broken_url);
|
2012-05-09 12:09:23 -07:00
|
|
|
});
|
2011-06-16 23:45:41 -04:00
|
|
|
}
|
2011-06-09 22:08:59 -04:00
|
|
|
|
|
|
|
};
|