diff --git a/media/js/newsblur/models/stories.js b/media/js/newsblur/models/stories.js index b17d47ed3..c132ecfff 100644 --- a/media/js/newsblur/models/stories.js +++ b/media/js/newsblur/models/stories.js @@ -82,7 +82,7 @@ NEWSBLUR.Models.Story = Backbone.Model.extend({ if (window.location.protocol == 'https:') { _.each(this.get('secure_image_urls'), function(secure_url, url) { if (_.str.startsWith(url, "http://")) { - console.log(['Securing image url', url, secure_url]); + // console.log(['Securing image url', url, secure_url]); content = content.split(url).join(secure_url); } }); diff --git a/media/js/newsblur/views/story_detail_view.js b/media/js/newsblur/views/story_detail_view.js index 24e56580e..8d5866ed5 100644 --- a/media/js/newsblur/views/story_detail_view.js +++ b/media/js/newsblur/views/story_detail_view.js @@ -719,7 +719,7 @@ NEWSBLUR.Views.StoryDetailView = Backbone.View.extend({ mouseup_check_selection: function(e) { var $doc = this.$(".NB-feed-story-content"); - console.log(['mouseup_check_selection', e, $(e.target)]); + // console.log(['mouseup_check_selection', e, $(e.target)]); if ($(e.target).hasClass("NB-highlight")) { this.show_unhighlight_tooltip($(e.target)); return; @@ -728,15 +728,17 @@ NEWSBLUR.Views.StoryDetailView = Backbone.View.extend({ this.$(".NB-starred-story-selection-highlight,[data-tippy]").contents().unwrap(); $doc.attr('id', 'NB-highlighting'); - var text = ""; + var selection; if (window.getSelection) { + selection = window.getSelection(); text = window.getSelection().toString(); } else if (document.selection && document.selection.type != "Control") { + selection = document.selection.createRange(); text = document.selection.createRange().text; } this.serialized_highlight = text; - console.log(['mouseup_check_selection 1', this.serialized_highlight]); + // console.log(['mouseup_check_selection 1', this.serialized_highlight]); if (this.tooltip && this.tooltip.tooltips && this.tooltip.tooltips.length) { this.tooltip.tooltips[0].hide(); @@ -746,14 +748,22 @@ NEWSBLUR.Views.StoryDetailView = Backbone.View.extend({ this.apply_starred_story_selections(); return; } - + $doc.mark(this.serialized_highlight, { "className": "NB-starred-story-selection-highlight", "separateWordSearch": false, "acrossElements": true, + "filter": function(node, term, total_counter, counter) { + if (!selection.containsNode(node)) return false; + // Highlighting the second 'baz' will fail, and the entire 'baz quz baz' will be highlighted instead. + // foo bar baz quz baz bar foo + // console.log(['filter', node, term, total_counter, counter, selection.anchorNode, selection.anchorOffset, selection.focusNode, selection.focusOffset, selection.anchorNode == node, selection.containsNode(node), node.textContent.indexOf(term)]); + // if (node.textContent.indexOf(term) != selection.anchorOffset) return false; + return true; + }, "done": _.bind(function() { var $selection = $(".NB-starred-story-selection-highlight", $doc); - console.log(['$selection', $selection]); + console.log(['$selection', $selection, $selection.first().get(0), $selection.last().get(0)]); $selection.attr('title', "