Created
December 19, 2013 12:59
-
-
Save vic/8038748 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
<html> | |
<head> | |
<script type='text/javascript'> | |
+(function(undefined){ | |
var Acute = function(){ | |
} | |
var TEXT_PLACEHOLDER_RE = /\{\{[\w\.]+\}\}/ | |
var TEXT_PLACEHOLDER_FINAL = /^\{\{[\w\.]+\}\}$/ | |
var bindTextTemplate = function(node, binding) { | |
console.log("BOUND ", node, " TO ", binding) | |
} | |
var compileTextNode = function(node, target){ | |
if(TEXT_PLACEHOLDER_FINAL.test(node.data)) { | |
return bindTextTemplate(node, node.data) | |
} | |
var lastIdx = 0, text = node.data.substring(lastIdx), offset = text.search(TEXT_PLACEHOLDER_RE) | |
node.data.replace(TEXT_PLACEHOLDER_RE, function(binding){ | |
var plain = node.data.substring(lastIdx, offset) | |
if(plain.length > 0) { target.insertBefore(document.createTextNode(plain), node) } | |
var bound = document.createTextNode(binding) | |
target.insertBefore(bound, node) | |
lastIdx += offset + binding.length | |
text = node.data.substring(lastIdx) | |
offset = text.search(TEXT_PLACEHOLDER_RE) | |
if(offset < 0){ target.insertBefore(document.createTextNode(text), node) } | |
}) | |
target.removeChild(node) | |
} | |
var compile = function(node, target){ | |
if(node.nodeName === "#text" && TEXT_PLACEHOLDER_RE.test(node.data)) { | |
return compileTextNode(node, target) | |
} | |
var css = window.getComputedStyle(node) | |
console.log(node, css) | |
} | |
var mutated = function(mutations, observer){ | |
for (var n = mutations.length, i = 0, mutation; mutation = mutations[i], i < n; i++) { | |
for (var a = mutation.addedNodes.length, j = 0, node; node = mutation.addedNodes[j], j < a; j++) { | |
compile(node, mutation.target) | |
} | |
for (var a = mutation.removedNodes.length, j = 0, node; node = mutation.removedNodes[j], j < a; j++) { | |
} | |
console.log(mutation.type, mutation) | |
} | |
} | |
mutated.options = { | |
childList: true, | |
attributes: true, | |
characterData: true, | |
subtree: true, | |
attributeOldValue: true, | |
characterDataOldValue: true | |
} | |
new MutationObserver(mutated).observe(document, mutated.options) | |
Acute("owner:nodeame", function(el){ | |
}) | |
})(); | |
</script> | |
</head> | |
<body> | |
<h1 class="hey">Hey</h1> | |
Hello {{name}} Que pex | |
<input type="text" placeholder="name" /> | |
<ul> | |
<li>{{age}}</li> | |
</ul> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment