merge expandable branch; fixes #1638

This commit is contained in:
Toks
2013-06-14 12:43:40 -04:00
3 changed files with 64 additions and 2 deletions

View File

@@ -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();
});

View File

@@ -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 {

View File

@@ -134,6 +134,8 @@ class DText
str.gsub!(/\[spoilers?\]\s+/m, "\n\n[spoiler]\n\n")
str.gsub!(/\s+\[\/spoilers?\]/m, "\n\n[/spoiler]\n\n")
str.gsub!(/^(h[1-6]\.\s*.+)$/, "\n\n\\1\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")
@@ -195,6 +197,20 @@ class DText
flags[:code] = false
'</pre>'
when /\[expand(?:\=([^\]]*))?\](?!\])/
stack << "expandable"
expand_html = '<div class="expandable"><div class="expandable-header">'
expand_html << "<span>#{h($1)}</span>" if $1.present?
expand_html << '<div class="expandable-button">Show</div></div>'
expand_html << '<div class="expandable-content">'
expand_html
when /\[\/expand\](?!\])/
if stack.last == "expandable"
stack.pop
'</div></div>'
end
else
if flags[:code]
CGI.escape_html(block) + "\n\n"
@@ -213,6 +229,8 @@ class DText
html << "</pre>"
elsif tag == "spoiler"
html << "</div>"
elsif tag == "expandable"
html << "</div></div>"
end
end