link include styles to extract css

This commit is contained in:
alexadam 2017-06-12 22:12:44 +03:00
parent 475ea4c158
commit 3c626ac2bc

View file

@ -325,63 +325,38 @@ function jsonToCss(jsonObj) {
} }
function extractCss(callback) { function extractCss(callback) {
// getIncludeStyle(function (result) { getIncludeStyle(function (result) {
// if (result) { if (result) {
// $('body').find('*').each(function (i, pre) { $('body').find('*').each(function (i, pre) {
// if (!$(pre).is(':visible')) { if (!$(pre).is(':visible')) {
// $(pre).replaceWith(''); $(pre).replaceWith('');
// } else { } else {
// var classNames = pre.getAttribute('class'); var classNames = pre.getAttribute('class');
// var tmpName = cssClassesToTmpIds[classNames]; if (!classNames) {
// var tmpNewCss = tmpIdsToNewCss[tmpName]; return;
// if (!tmpName) { }
// tmpName = 'class-' + Math.floor(Math.random()*100000); var tmpName = cssClassesToTmpIds[classNames];
// cssClassesToTmpIds[classNames] = tmpName; var tmpNewCss = tmpIdsToNewCss[tmpName];
// tmpIdsToNewCss[tmpName] = {}; if (!tmpName) {
// } tmpName = 'class-' + Math.floor(Math.random()*100000);
// if (!tmpNewCss) { cssClassesToTmpIds[classNames] = tmpName;
// var style = window.getComputedStyle(pre); }
// tmpNewCss = {}; if (!tmpNewCss) {
// for (var cssTagName of supportedCss) { var style = window.getComputedStyle(pre);
// tmpNewCss[cssTagName] = style.getPropertyValue(cssTagName); tmpNewCss = {};
// } for (var cssTagName of supportedCss) {
// tmpIdsToNewCss[tmpName] = tmpNewCss; tmpNewCss[cssTagName] = style.getPropertyValue(cssTagName);
// } }
// pre.setAttribute('data-class', tmpName); tmpIdsToNewCss[tmpName] = tmpNewCss;
// } }
// }); pre.setAttribute('data-class', tmpName);
// callback(jsonToCss(tmpIdsToNewCss));
// } else {
// callback();
// }
// });
$('body').find('*').each(function (i, pre) {
if (!$(pre).is(':visible')) {
$(pre).replaceWith('');
} else {
var classNames = pre.getAttribute('class');
if (!classNames) {
return;
}
var tmpName = cssClassesToTmpIds[classNames];
var tmpNewCss = tmpIdsToNewCss[tmpName];
if (!tmpName) {
tmpName = 'class-' + Math.floor(Math.random()*100000);
cssClassesToTmpIds[classNames] = tmpName;
}
if (!tmpNewCss) {
var style = window.getComputedStyle(pre);
tmpNewCss = {};
for (var cssTagName of supportedCss) {
tmpNewCss[cssTagName] = style.getPropertyValue(cssTagName);
} }
tmpIdsToNewCss[tmpName] = tmpNewCss; });
} callback(jsonToCss(tmpIdsToNewCss));
pre.setAttribute('data-class', tmpName); } else {
callback();
} }
}); });
callback(jsonToCss(tmpIdsToNewCss));
} }
///// /////