Compact/Loose text + prettyprint
Jquery/CSS snippet to maintain prettyprinted text content in one line and to expand on click
by David Gonzalez
HTML
<script src="https://cdn.rawgit.com/google/code-prettify/master/loader/run_prettify.js"></script>
<pre class="prettyprint lang-js compact-overflow">
{
"name": ["json.human"],
"description": "Convert\n JSON to human readable\r HTML",
"author": "Mariano Guerra <[email protected]>",
"tags": ["DOM", "HTML", "JSON", "Pretty Print"],
"version": "0.1.0",
"main": "json.human.js",
"license" : "MIT",
"dependencies": {
"crel": "1.0.0"
},
"repository": {
"type": "git",
"url": "git://github.com/marianoguerra/json.human.js.git"
},
"bugs": {
"url": "http://github.com/marianoguerra/json.human.js/issues"
},
"contributors": [],
"config": {
"what?": "this object is just to show some extra stuff",
"how?": ["add json.human.js", "add json.human.css", "???", "profit!"],
"customization?": ["customize the css prefix", "change the css file"],
"integer": 42,
"float": 12.3,
"bool": true,
"emptyString": "",
"emptyArray": [],
"emptyObject": {},
"htmlEntities": " <- trailing <em> & </em> and some html "
}
}
</pre>
<!-- does not work on buttons-->
CSS
.compact-overflow {
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
cursor: zoom-in;
}
.loose-overflow {
text-overflow: unset;
white-space: normal;
word-wrap: break-word;
-ms-hyphens: auto;
-moz-hyphens: auto;
-webkit-hyphens: auto;
hyphens: auto;
cursor: zoom-out;
}
pre.prettyprint{
border: none;
margin: 0;
padding: 0;
}
JavaScript
$(".compact-overflow").click( function(){
$(this).toggleClass("compact-overflow");
$(this).toggleClass("loose-overflow");
});