Browse Source

New JavaScript function: locator()

Kandrashin Denis 12 years ago
parent
commit
518364c7b9
2 changed files with 16 additions and 0 deletions
  1. 1 0
      source/js/get_status.js
  2. 15 0
      source/js/location.js

+ 1 - 0
source/js/get_status.js

@@ -1,3 +1,4 @@
+logger.trace(locator(document.getSelection().baseNode));
 var baseNode = document.getSelection().baseNode;
 if (baseNode === null) ''; else {
 	(f = function(node){

+ 15 - 0
source/js/location.js

@@ -9,3 +9,18 @@ var f=function(){
 };
 return h.map(f).get().join(",");
 };
+
+function locator(node){
+if (node === undefined) return "undefined";
+return (f = function(node){
+	if (node.tagName === "HTML") return "$('html')";
+	var child = $(node);
+	var parent = child.parent();
+    var prefix = f(node.parentNode);
+	if (node.nodeName === "#text") {
+        return prefix + ".contents()" + ".eq(" + parent.contents().index(node) + ")";
+	} else {
+        return prefix + ".children()" + ".eq(" + parent.children().index(node) + ")";
+	}
+})(node) + ".first()";
+};