Skip to content

Instantly share code, notes, and snippets.

@holgersindbaek
Created November 29, 2014 21:53
Show Gist options
  • Save holgersindbaek/546f92a61c0e30e74cab to your computer and use it in GitHub Desktop.
Save holgersindbaek/546f92a61c0e30e74cab to your computer and use it in GitHub Desktop.
var $button = $("<div id='source-button' class='btn btn-primary btn-xs'>&lt; &gt;</div>").click(function() {
var html = $(this).parent().html();
html = cleanSource(html);
$("#source-modal pre").text(html);
$("#source-modal").modal();
});
$('[data-toggle="popover"]').popover();
$('[data-toggle="tooltip"]').tooltip();
$(".demo-component").hover(function() {
$(this).append($button);
$button.show();
}, function() {
$button.hide();
});
function cleanSource(html) {
var lines = html.split(/\n/);
lines.shift();
lines.splice(-1, 1);
var indentSize = lines[0].length - lines[0].trim().length,
re = new RegExp(" {" + indentSize + "}");
lines = lines.map(function(line) {
if (line.match(re)) {
line = line.substring(indentSize);
}
return line;
});
lines = lines.join("\n");
return lines;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment