Skip to content

Instantly share code, notes, and snippets.

@marat-chardymov
Last active October 25, 2016 19:58
Show Gist options
  • Save marat-chardymov/cf0c1f01aa7938765d4aa944edff4dc5 to your computer and use it in GitHub Desktop.
Save marat-chardymov/cf0c1f01aa7938765d4aa944edff4dc5 to your computer and use it in GitHub Desktop.
var blocksModule = (function () {
function pushSubNode(node, subNode) {
if (node.subNodes != null) {
node.subNodes.push(subNode);
} else {
node.subNodes = [subNode];
}
}
function buildBlockGraphRecursively(root, result) {
var children = $(root).children();
$(children).each(function (i, entry) {
if ($(entry).is('div[class*="col-"]')) {
var subNode = {type: "col"};
var mdWidth = parseInt(entry.className.match(/col-md-\d+/)[0].match(/\d+/)[0]);
var smWidth = parseInt(entry.className.match(/col-sm-\d+/)[0].match(/\d+/)[0]);
var xsWidth = parseInt(entry.className.match(/col-xs-\d+/)[0].match(/\d+/)[0]);
subNode["mdWidth"] = mdWidth;
subNode["smWidth"] = smWidth;
subNode["xsWidth"] = xsWidth;
subNode["id"] = entry.dataset.id;
pushSubNode(result, subNode)
buildBlockGraphRecursively(entry, subNode);
} else if ($(entry).is('.row')) {
var subNode = {type: "row"}
subNode["id"] = entry.dataset.id;
pushSubNode(result, subNode)
buildBlockGraphRecursively(entry, subNode);
} else {
return;
}
});
return result;
}
return {
buildBlockGraph: function (root) {
var result = {};
buildBlockGraphRecursively(root, result)
return JSON.stringify(result);
}
}
})();
@marat-chardymov
Copy link
Author

blocksModule.buildBlockGraph($('#my_bootstrap_container'));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment