-
Notifications
You must be signed in to change notification settings - Fork 436
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14120 from ncounter/collapsible-text
BugFix: collapsible text for request beta
- Loading branch information
Showing
6 changed files
with
33 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,25 @@ | ||
$(document).ready(function() { | ||
setCollapsible(); | ||
}); | ||
function setCollapsible() { // jshint ignore:line | ||
$('.obs-collapsible-textbox').each(function() { | ||
var container = $(this); | ||
var textBox = container.find('.obs-collapsible-text'); | ||
var showButton = container.find('.show-content'); | ||
|
||
function setCollapsible() { | ||
$('.obs-collapsible-textbox').on('click', function() { | ||
var selectedText = document.getSelection().toString(); | ||
if(!selectedText) { | ||
$(this).find('.obs-collapsible-text').toggleClass('expanded'); | ||
$(this).find('.show-content').toggleClass('more less'); | ||
// Add the event if it wasn't already added | ||
if (container.hasClass('vanilla-textbox-to-collapse')) { | ||
container.on('click', function() { | ||
if(!document.getSelection().toString()) { | ||
textBox.toggleClass('expanded'); | ||
showButton.toggleClass('more less'); | ||
} | ||
}); | ||
// Make sure to not add the event twice by removing the target class | ||
container.removeClass('vanilla-textbox-to-collapse'); | ||
} | ||
}); | ||
|
||
$('.obs-collapsible-text').each(function(_index, element){ | ||
if (element.scrollHeight > element.offsetHeight) { | ||
var $link = $('<a href="javascript:void(0)" class="show-content more"><i class="fa"></i></a>'); | ||
$(element).after($link); | ||
// Make sure to not add the button twice and only if it makes sense to | ||
if (showButton.length === 0 && textBox.prop('scrollHeight') > textBox.prop('offsetHeight')) { | ||
showButton = $('<a href="javascript:void(0)" class="show-content more"><i class="fa"></i></a>'); | ||
textBox.after(showButton); | ||
} | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -170,4 +170,6 @@ | |
}); | ||
}); | ||
|
||
setCollapsible(); | ||
|
||
-# haml-lint:enable ViewLength |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
-# NOTE: look into app/assets/stylesheets/webui/collapsible-text.scss | ||
- if text.present? | ||
.obs-collapsible-textbox{ class: "#{extra_css_classes if defined?(extra_css_classes)}" } | ||
.obs-collapsible-textbox.vanilla-textbox-to-collapse{ class: "#{extra_css_classes if defined?(extra_css_classes)}" } | ||
.obs-collapsible-text | ||
= sanitize(simple_format(text), tags: %w[br p]) | ||
|
||
:javascript | ||
setCollapsible(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters