Created
August 31, 2011 04:12
-
-
Save e7h4n/1182812 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 currentEditObj = null; | |
function findParent(obj, filter){ | |
while (obj.nodeType !== Node.DOCUMENT_NODE) { | |
if (filter(obj)) { | |
return obj; | |
} | |
obj = obj.parentNode; | |
} | |
return null; | |
} | |
function edit(obj) { | |
currentEditObj = obj; | |
var content = currentEditObj.nodeValue; | |
console.log(content); | |
window.Htmlout.editContent(content); | |
} | |
function editDone(value) { | |
currentEditObj.nodeValue = value; | |
} | |
document.addEventListener('click', function(evt) { | |
var range = document.caretRangeFromPoint(evt.clientX, evt.clientY); | |
if (range && range.collapsed) { | |
var text = range.commonAncestorContainer; | |
if (text.nodeType === Node.TEXT_NODE && findParent(text, function(obj) { | |
return obj.nodeType === Node.ELEMENT_NODE && (obj.getAttribute('contenteditable') === false || obj.getAttribute('contenteditable') === 'false'); | |
}) === null) { | |
edit(text); | |
} | |
} | |
}); | |
/* | |
vim:ft=javascript | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment