From 70161498b690336f882d40aa41309d61c201650d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Hanol?= Date: Sun, 12 Jan 2014 19:38:46 +0100 Subject: [PATCH] BUGFIX: spoiler tag on lightboxed images wasn't working --- .../javascripts/discourse/dialects/bbcode_dialect.js | 11 ++++++++--- app/assets/javascripts/discourse/dialects/dialect.js | 2 +- app/assets/javascripts/discourse/lib/lightbox.js | 6 +++++- spec/components/pretty_text_spec.rb | 2 +- test/javascripts/lib/bbcode_test.js | 6 +++++- 5 files changed, 20 insertions(+), 7 deletions(-) diff --git a/app/assets/javascripts/discourse/dialects/bbcode_dialect.js b/app/assets/javascripts/discourse/dialects/bbcode_dialect.js index ba6f4b5b303..3222747ca9e 100644 --- a/app/assets/javascripts/discourse/dialects/bbcode_dialect.js +++ b/app/assets/javascripts/discourse/dialects/bbcode_dialect.js @@ -57,8 +57,6 @@ replaceBBCode('ul', function(contents) { return ['ul'].concat(contents); }); replaceBBCode('ol', function(contents) { return ['ol'].concat(contents); }); replaceBBCode('li', function(contents) { return ['li'].concat(contents); }); -replaceBBCode('spoiler', function(contents) { return ['span', {'class': 'spoiler'}].concat(contents); }); - Discourse.Dialect.inlineBetween({ start: '[img]', stop: '[/img]', @@ -80,7 +78,6 @@ Discourse.Dialect.inlineBetween({ emitter: function(contents) { return ['a', {href: contents, 'data-bbcode': true}, contents]; } }); - replaceBBCodeParamsRaw("url", function(param, contents) { return ['a', {href: param, 'data-bbcode': true}, contents]; }); @@ -103,3 +100,11 @@ Discourse.Dialect.replaceBlock({ } }); +Discourse.Dialect.replaceBlock({ + start: /(\[spoiler\])([\s\S]*)/igm, + stop: '[/spoiler]', + + emitter: function(blockContents) { + return ['p', ['div', { 'class': 'spoiler' }, blockContents.join("\n")]]; + } +}); diff --git a/app/assets/javascripts/discourse/dialects/dialect.js b/app/assets/javascripts/discourse/dialects/dialect.js index 0b877870ac6..cf12fc64d1d 100644 --- a/app/assets/javascripts/discourse/dialects/dialect.js +++ b/app/assets/javascripts/discourse/dialects/dialect.js @@ -213,7 +213,7 @@ Discourse.Dialect = { @param {String} [opts.start] The starting token we want to find @param {String} [opts.matcher] The regular expression to match @param {Boolean} [opts.wordBoundary] If true, the match must be on a word boundary - @param {Boolean} [opts.spaceBoundary] If true, the match must be on a sppace boundary + @param {Boolean} [opts.spaceBoundary] If true, the match must be on a space boundary **/ inlineRegexp: function(args) { this.registerInline(args.start, function(text, match, prev) { diff --git a/app/assets/javascripts/discourse/lib/lightbox.js b/app/assets/javascripts/discourse/lib/lightbox.js index bdef16a111e..bf0f865d24e 100644 --- a/app/assets/javascripts/discourse/lib/lightbox.js +++ b/app/assets/javascripts/discourse/lib/lightbox.js @@ -9,7 +9,11 @@ Discourse.Lightbox = { apply: function($elem) { $LAB.script("/javascripts/jquery.magnific-popup-min.js").wait(function() { $("a.lightbox", $elem).each(function(i, e) { - $(e).magnificPopup({ + var $e = $(e); + // do not lightbox spoiled images + if ($e.parents(".spoiler").length > 0 || $e.parents(".spoiled").length > 0) { return; } + + $e.magnificPopup({ type: "image", closeOnContentClick: false, diff --git a/spec/components/pretty_text_spec.rb b/spec/components/pretty_text_spec.rb index 1398937d0db..5f70dbe1455 100644 --- a/spec/components/pretty_text_spec.rb +++ b/spec/components/pretty_text_spec.rb @@ -41,7 +41,7 @@ describe PrettyText do end it 'should add spoiler tags' do - PrettyText.cook("[spoiler]hello[/spoiler]").should match_html "

hello

" + PrettyText.cook("[spoiler]hello[/spoiler]").should match_html "

hello

" end end diff --git a/test/javascripts/lib/bbcode_test.js b/test/javascripts/lib/bbcode_test.js index 88160015477..70cda0b6e21 100644 --- a/test/javascripts/lib/bbcode_test.js +++ b/test/javascripts/lib/bbcode_test.js @@ -10,7 +10,6 @@ test('basic bbcode', function() { format("[i]emphasis[/i]", "emphasis", "italics text"); format("[u]underlined[/u]", "underlined", "underlines text"); format("[s]strikethrough[/s]", "strikethrough", "strikes-through text"); - format("[spoiler]it's a sled[/spoiler]", "it's a sled", "supports spoiler tags"); format("[img]http://eviltrout.com/eviltrout.png[/img]", "", "links images"); format("[url]http://bettercallsaul.com[/url]", "http://bettercallsaul.com", "supports [url] without a title"); format("[email]eviltrout@mailinator.com[/email]", "eviltrout@mailinator.com", "supports [email] without a title"); @@ -30,6 +29,11 @@ test('code', function() { format("[code]abc\n#def\n[/code]", '
abc\n#def
', 'it handles headings in a [code] block'); }); +test('spoiler', function() { + format("[spoiler]it's a sled[/spoiler]", "
it's a sled
", "supports spoiler tags on text"); + format("[spoiler][/spoiler]", "
", "supports spoiler tags on images"); +}); + test('lists', function() { format("[ul][li]option one[/li][/ul]", "", "creates an ul"); format("[ol][li]option one[/li][/ol]", "
  1. option one
", "creates an ol");