From 58a93876b64852b2f510ab7a592618bf0190117a Mon Sep 17 00:00:00 2001 From: Toks Date: Fri, 14 Jun 2013 12:11:50 -0400 Subject: [PATCH] fixes #1638 --- app/assets/javascripts/dtext.js | 14 +++++++- app/assets/stylesheets/common/dtext.css.scss | 34 +++++++++++++++++++- app/logical/d_text.rb | 18 +++++++++++ 3 files changed, 64 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/dtext.js b/app/assets/javascripts/dtext.js index 96e46da4f..a50dadc7c 100644 --- a/app/assets/javascripts/dtext.js +++ b/app/assets/javascripts/dtext.js @@ -1,11 +1,23 @@ (function() { Danbooru.Dtext = {}; + Danbooru.Dtext.initialize_all = function() { + Danbooru.Dtext.initialize_links(); + Danbooru.Dtext.initialize_expandables(); + } + Danbooru.Dtext.initialize_links = function() { $(".simple_form .dtext-preview").hide(); $(".simple_form input[value=Preview]").click(Danbooru.Dtext.click_button); } + Danbooru.Dtext.initialize_expandables = function() { + $(".expandable-content").hide(); + $(".expandable-button").click(function(e) { + $(this).parent().next().fadeToggle("fast"); + }); + } + Danbooru.Dtext.call_preview = function(e, $button, $input, $preview) { $button.val("Edit"); $input.hide(); @@ -44,5 +56,5 @@ })(); $(document).ready(function() { - Danbooru.Dtext.initialize_links(); + Danbooru.Dtext.initialize_all(); }); diff --git a/app/assets/stylesheets/common/dtext.css.scss b/app/assets/stylesheets/common/dtext.css.scss index 3c82ddac4..c067d7c78 100644 --- a/app/assets/stylesheets/common/dtext.css.scss +++ b/app/assets/stylesheets/common/dtext.css.scss @@ -40,9 +40,41 @@ div.prose { font-family: monospace; margin: 1em 0; padding: 1em 2em; - background: #eee; + background: #EEE; white-space: pre-wrap; } + + div.expandable { + margin-bottom: 1em; + border: 1px solid #666; + background: #EEE; + } + + div.expandable-header { + padding: 0.7em; + + span { + margin-right: 1em; + } + } + + div.expandable-button { + padding: 0.3em; + display: inline-block; + border: 1px solid #666; + border-radius: 3px; + background: #CCC; + cursor: pointer; + } + + div.expandable-content { + padding: 0.7em; + border-top: 1px solid #666; + + p:last-child { + margin-bottom: 0; + } + } } div.dtext-preview { diff --git a/app/logical/d_text.rb b/app/logical/d_text.rb index ba353288c..9c80313cb 100644 --- a/app/logical/d_text.rb +++ b/app/logical/d_text.rb @@ -131,6 +131,8 @@ class DText str.gsub!(/\s*\[\/quote\]\s*/m, "\n\n[/quote]\n\n") str.gsub!(/\s*\[code\]\s*/m, "\n\n[code]\n\n") str.gsub!(/\s*\[\/code\]\s*/m, "\n\n[/code]\n\n") + str.gsub!(/\s*\[expand(\=[^\]]*)?\]\s*/m, "\n\n[expand\\1]\n\n") + str.gsub!(/\s*\[\/expand\]\s*/m, "\n\n[/expand]\n\n") end str.gsub!(/(?:\r?\n){3,}/, "\n\n") @@ -180,6 +182,20 @@ class DText flags[:code] = false '' + when /\[expand(?:\=([^\]]*))?\](?!\])/ + stack << "expandable" + expand_html = '' + end + else if flags[:code] CGI.escape_html(block) + "\n\n" @@ -196,6 +212,8 @@ class DText html << "" elsif tag == "pre" html << "" + elsif tag == "expandable" + html << "" end end