tag and
// process that instead.
if (pre.tagName.toLowerCase() !== 'pre') {
pre = pre.parentNode;
}
// Verify there is not already a codePen Button and that we are in a .
if (pre.getElementsByTagName('form').length > 0 ||
pre.tagName.toLowerCase() !== 'pre') {
continue;
}
// Extract ');
var styleBlock = code.substring(startIndex + 7, endIndex).trim();
var styleBlockLines = styleBlock.split('\n').map(
function(elem) {
return elem.trim();
});
styleLines = styleLines.concat(styleBlockLines);
code = code.substr(endIndex + 8);
}
// Create the CodePen Form and add it to the block.
var form = document.createElement('form');
form.classList.add('codepen-button');
form.setAttribute('action', 'http://codepen.io/pen/define');
form.setAttribute('method', 'POST');
form.addEventListener('click', this.clickHandler(form));
var input = document.createElement('input');
input.setAttribute('type', 'hidden');
input.setAttribute('name', 'data');
input.setAttribute('value', JSON.stringify(
{html: '\n \n ' +
mdlLibs.join('\n ') +
'\n \n \n ' +
code.split('\n').join('\n ').trim() +
'\n \n',
css: styleLines.join('\n')}));
form.appendChild(input);
pre.appendChild(form);
}
};
/**
* Click handler for CodePEn buttons. Simply submits the form to CodePen.
*/
CodeBlockCodePen.prototype.clickHandler = function(form) {
'use strict';
return function() {
form.submit();
};
};
window.addEventListener('load', function() {
'use strict';
new CodeBlockCodePen();
});