Created
November 29, 2014 21:53
-
-
Save holgersindbaek/546f92a61c0e30e74cab to your computer and use it in GitHub Desktop.
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
var $button = $("<div id='source-button' class='btn btn-primary btn-xs'>< ></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