Last active
October 27, 2024 17:05
-
-
Save mf81bln/f5433c13b8378e4da873 to your computer and use it in GitHub Desktop.
tribbles - a little jQuery extension for displaying long content of text fields as tooltip (using jQuery UI) --> demo: https://jsfiddle.net/5v1snbkm/
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
<!DOCTYPE html> | |
<html> | |
<head lang="en"> | |
<meta charset="UTF-8"> | |
<title>tribbles demo</title> | |
<link rel="stylesheet" href="http://code.jquery.com/ui/1.11.2/themes/smoothness/jquery-ui.css"> | |
<link rel="stylesheet" href="/styles.css"> | |
<script src="http://code.jquery.com/jquery-1.10.2.js"></script> | |
<script src="http://code.jquery.com/ui/1.11.2/jquery-ui.js"></script> | |
<script src="/tribbles.js"></script> | |
</head> | |
<body> | |
<div class="container"> | |
<p class="longText"> | |
Lorem ipsum dolor sit amet, consectetur adipisici elit, sed eiusmod tempor incidunt ut labore et dolore magna aliqua. | |
</p> | |
<span class="longText">And just for fun - a little bit more text!</span> | |
</div> | |
<script type="application/javascript"> | |
$('.longText').tribbles(); | |
</script> | |
</body> | |
</html> |
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
body * { | |
box-sizing: border-box; | |
} | |
.container { | |
border: solid 1px #4b5faa; | |
width: 150px; | |
padding: 3px; | |
} | |
.container * { | |
/* just to render all elements by same style */ | |
margin: 0; | |
padding: 0; | |
display: block; | |
/* next three lines does the ... magic */ | |
white-space: nowrap; | |
overflow: hidden; | |
text-overflow: ellipsis; | |
} | |
.longText { | |
cursor: help; | |
} |
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
(function($) { | |
$.fn.extend({ | |
tribbles: function() { | |
$.each(this, function() { | |
var elem = $(this); | |
if(elem[0].scrollWidth > elem[0].offsetWidth) { | |
elem.tooltip({ | |
items: "*", | |
content: elem.html() | |
}) | |
} | |
}) | |
} | |
}) | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment