Last active
October 25, 2016 19:58
-
-
Save marat-chardymov/cf0c1f01aa7938765d4aa944edff4dc5 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 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); | |
} | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
blocksModule.buildBlockGraph($('#my_bootstrap_container'));