2012-06-11 18:56:19 -07:00
|
|
|
NEWSBLUR.Views.StoryTabView = Backbone.View.extend({
|
2014-10-29 16:16:50 -07:00
|
|
|
|
|
|
|
flags: {},
|
2012-06-11 18:56:19 -07:00
|
|
|
|
|
|
|
initialize: function() {
|
2013-07-04 01:10:38 -07:00
|
|
|
this.setElement(NEWSBLUR.reader.$s.$story_view);
|
|
|
|
this.$iframe = NEWSBLUR.reader.$s.$story_iframe;
|
2012-06-11 18:56:19 -07:00
|
|
|
this.collection.bind('change:selected', this.select_story, this);
|
2014-10-29 16:16:50 -07:00
|
|
|
this.$iframe.on('load', _.bind(function() {
|
|
|
|
this.ensure_proxied_story();
|
|
|
|
}, this));
|
2012-06-11 18:56:19 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
// ===========
|
|
|
|
// = Actions =
|
|
|
|
// ===========
|
|
|
|
|
2014-10-29 16:16:50 -07:00
|
|
|
prepare_story: function(story, is_temporary) {
|
2012-06-11 18:56:19 -07:00
|
|
|
if (!story) story = NEWSBLUR.reader.active_story;
|
2012-08-02 14:01:16 -07:00
|
|
|
if (!story) return;
|
2012-06-11 18:56:19 -07:00
|
|
|
var feed = NEWSBLUR.assets.get_feed(story.get('story_feed_id'));
|
|
|
|
|
|
|
|
if ((feed && feed.get('disabled_page')) ||
|
|
|
|
NEWSBLUR.utils.is_url_iframe_buster(story.get('story_permalink'))) {
|
|
|
|
if (!is_temporary) {
|
2014-10-29 16:16:50 -07:00
|
|
|
NEWSBLUR.reader.switch_taskbar_view('text', {skip_save_type: 'story'});
|
|
|
|
NEWSBLUR.app.taskbar_info.show_stories_error({}, "Sorry, the original story<br />could not be proxied.");
|
2012-06-11 18:56:19 -07:00
|
|
|
}
|
|
|
|
} else {
|
2012-07-23 16:51:27 -07:00
|
|
|
NEWSBLUR.reader.switch_taskbar_view('story', {skip_save_type: is_temporary ? 'story' : false});
|
2014-10-29 16:16:50 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
open_story: function(story) {
|
|
|
|
if (!story) story = NEWSBLUR.reader.active_story;
|
|
|
|
if (!story) return;
|
|
|
|
|
|
|
|
var permalink = story.get('story_permalink');
|
2019-01-18 16:47:24 -05:00
|
|
|
// if (window.location.protocol == 'https:' && !_.string.startsWith(permalink, 'https')) {
|
2014-10-29 16:16:50 -07:00
|
|
|
this.flags.proxied_https = true;
|
|
|
|
this.load_original_story_page(story);
|
2019-01-18 16:47:24 -05:00
|
|
|
// } else {
|
|
|
|
// this.flags.proxied_https = false;
|
|
|
|
// this.load_story_iframe(story);
|
|
|
|
// }
|
2012-06-11 18:56:19 -07:00
|
|
|
},
|
|
|
|
|
2014-10-29 16:16:50 -07:00
|
|
|
load_original_story_page: function(story) {
|
|
|
|
this.$(".NB-story-list-empty").remove();
|
|
|
|
this.show_loading();
|
|
|
|
var url = '/rss_feeds/original_story?story_hash='+story.get('story_hash');
|
|
|
|
console.log(['url', url]);
|
|
|
|
if (!_.string.contains(this.$iframe.attr('src'), url)) {
|
|
|
|
this.unload_story_iframe();
|
|
|
|
|
|
|
|
NEWSBLUR.reader.flags.iframe_scroll_snap_back_prepared = true;
|
|
|
|
this.$iframe.removeAttr('src').attr({src: url});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2012-06-11 18:56:19 -07:00
|
|
|
load_story_iframe: function(story) {
|
|
|
|
story = story || NEWSBLUR.reader.active_story;
|
|
|
|
if (!story) return;
|
|
|
|
|
2013-07-04 01:10:38 -07:00
|
|
|
this.$(".NB-story-list-empty").remove();
|
|
|
|
if (this.$iframe.attr('src') != story.get('story_permalink')) {
|
2012-06-11 18:56:19 -07:00
|
|
|
this.unload_story_iframe();
|
|
|
|
|
|
|
|
NEWSBLUR.reader.flags.iframe_scroll_snap_back_prepared = true;
|
2013-07-04 01:10:38 -07:00
|
|
|
this.$iframe.removeAttr('src').attr({src: story.get('story_permalink')});
|
2012-06-11 18:56:19 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
unload_story_iframe: function() {
|
2014-10-29 16:16:50 -07:00
|
|
|
NEWSBLUR.app.taskbar_info.hide_stories_error();
|
|
|
|
|
2013-07-04 01:10:38 -07:00
|
|
|
this.$iframe.empty();
|
2016-11-21 13:02:13 -08:00
|
|
|
this.$iframe.removeAttr('src');//.attr({src: 'about:blank'});
|
2013-07-04 01:10:38 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
show_explainer_single_story_mode: function() {
|
|
|
|
var $empty = $.make("div", { className: "NB-story-list-empty" }, [
|
2013-07-11 15:09:00 -07:00
|
|
|
$.make('div', { className: 'NB-world' }),
|
2013-07-04 01:10:38 -07:00
|
|
|
'Select a story to read'
|
|
|
|
]);
|
|
|
|
|
|
|
|
this.$(".NB-story-list-empty").remove();
|
|
|
|
this.$el.append($empty);
|
2012-06-11 18:56:19 -07:00
|
|
|
},
|
2014-10-29 16:16:50 -07:00
|
|
|
|
|
|
|
show_loading: function() {
|
|
|
|
NEWSBLUR.app.taskbar_info.hide_stories_error();
|
|
|
|
NEWSBLUR.app.taskbar_info.show_stories_progress_bar(10, "Fetching story");
|
|
|
|
},
|
2012-06-11 18:56:19 -07:00
|
|
|
|
2014-10-29 16:16:50 -07:00
|
|
|
ensure_proxied_story: function() {
|
|
|
|
NEWSBLUR.app.taskbar_info.hide_stories_progress_bar();
|
|
|
|
if (this.$iframe.attr('src') == 'about:blank') {
|
|
|
|
console.log(['Blank iframe, ignoring']);
|
|
|
|
NEWSBLUR.app.taskbar_info.hide_stories_error();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
var correct = this.$iframe.contents().find('body').children().length;
|
|
|
|
console.log(['correct?', this.$iframe.contents(), this.$iframe.contents().find('body').children().length]);
|
|
|
|
if (correct && this.flags.proxied_https) {
|
2020-12-06 10:30:21 -05:00
|
|
|
// NEWSBLUR.app.taskbar_info.show_stories_error({
|
|
|
|
// proxied_https: true
|
|
|
|
// }, "Imperfect proxy due<br />to http over https");
|
2014-10-29 16:16:50 -07:00
|
|
|
} else if (!correct && this.flags.proxied_https) {
|
2022-01-19 16:28:18 -05:00
|
|
|
// NEWSBLUR.reader.switch_taskbar_view('text', {skip_save_type: 'story'});
|
|
|
|
// NEWSBLUR.app.taskbar_info.show_stories_error({}, "Sorry, the original story<br />could not be proxied.");
|
2014-10-29 16:16:50 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2012-06-11 18:56:19 -07:00
|
|
|
// ==========
|
|
|
|
// = Events =
|
|
|
|
// ==========
|
|
|
|
|
|
|
|
select_story: function(story, selected) {
|
|
|
|
if (selected && NEWSBLUR.reader.story_view == 'story') {
|
2014-10-29 16:16:50 -07:00
|
|
|
this.prepare_story(story);
|
2012-06-11 18:56:19 -07:00
|
|
|
this.open_story(story);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-06 10:30:21 -05:00
|
|
|
});
|