< span class="cnblogs_code_copy">
Copy code');
}
function loadEncoderJs() {
var encoderJs = document.createElement('script');
encoderJs.type = 'text/javascript';
encoderJs.src = 'http: //common.cnblogs.com/script/encoder.js';
var node = document.getElementsByTagName('script')[0];
node.parentNode.insertBefore(encoderJs, node);
}
function copyCnblogsCode(element) {
var codeContainer = getCnblogsCodeContainer(element);
var cbCode = getCnblogsCodeText(codeContainer);
var textarea = document.createElement('textarea');
$(textarea).val(cbCode).select();
$(textarea).css("width", $(codeContainer).css("width"));
$(textarea ).css("height", $(codeContainer).css("height"));
$(textarea).css("font-family", "Courier New");
$(textarea) .css("font-size", "12px");
$(textarea).css("line-height", "1.5");
$(codeContainer).parent().html(textarea );
$(textarea).select();
$("
Press Ctrl C to copy the code
").insertAfter($(textarea));
}
function getCnblogsCodeContainer(element) {
var codeContainer = $(element).parent().parent().parent().find("pre");
if (codeContainer.length = = 0) {
codeContainer = $(element).parent().parent().parent().find("div").first();
}
return codeContainer;
}
function getCnblogsCodeText(codeContainer) {
var cbCode = 'n' $(codeContainer).html()
.replace(/ /g, ' ')
.replace(/
/ig, 'n')
.replace(/<[^>]*>/g, '');
cbCode = cbCode.replace(/n (s*d )/ig, 'n');
cbCode = cbCode.replace(/n/g, 'rn');
if (typeof Encoder != undefined) {
cbCode = Encoder .htmlDecode(cbCode);
}
cbCode = $.trim(cbCode);
return cbCode;
}
function showRunCode(element) {
var codeCopyDiv = $(element).find("div.cnblogs_code_toolbar");
if (codeCopyDiv.length) {
$(codeCopyDiv).append('Run code');
}
}
function runJsCode (element) {
var codeContainer = getCnblogsCodeContainer(element);
var cbCode = getCnblogsCodeText(codeContainer);
var newwin = window.open('', "_blank", '');
newwin.document.open('text/html', 'replace');
newwin.opener = null;
newwin.document.write(cbCode);
newwin.document.close();
}
//#endregion