PageRenderTime 12ms CodeModel.GetById 1ms app.highlight 5ms RepoModel.GetById 2ms app.codeStats 0ms

/library/platform/DOMMozilla.py

http://pyjamas.googlecode.com/
Python | 100 lines | 100 code | 0 blank | 0 comment | 0 complexity | b7ee33d601b5c9c321339a6c8300bf81 MD5 | raw file
  1def compare(elem1, elem2):
  2    JS("""
  3    if (!elem1 && !elem2) {
  4        return true;
  5    } else if (!elem1 || !elem2) {
  6        return false;
  7    }
  8    return (elem1.isSameNode(elem2));
  9    """)
 10
 11def eventGetButton(evt):
 12    JS("""
 13    var button = evt.button;
 14    if(button == 0) {
 15        return 1;
 16    } else if (button == 1) {
 17        return 4;
 18    } else {
 19        return button;
 20    }
 21    """)
 22
 23def getAbsoluteLeft(elem):
 24    JS("""
 25    var left = 0;
 26    var parent = elem;
 27
 28    while (parent) {
 29        if (parent.scrollLeft > 0) {
 30            left = left -  parent.scrollLeft;
 31        }
 32        parent = parent.parentNode;
 33    }
 34    while (elem) {
 35        left = left + elem.offsetLeft;
 36        elem = elem.offsetParent;
 37    }
 38
 39    return left + $doc.body.scrollLeft + $doc.documentElement.scrollLeft;
 40    """)
 41
 42def getAbsoluteTop(elem):
 43    JS("""
 44    var top = 0;
 45    var parent = elem;
 46    while (parent) {
 47        if (parent.scrollTop > 0) {
 48            top -= parent.scrollTop;
 49        }
 50        parent = parent.parentNode;
 51    }
 52
 53    while (elem) {
 54        top += elem.offsetTop;
 55        elem = elem.offsetParent;
 56    }
 57    return top + $doc.body.scrollTop + $doc.documentElement.scrollTop;
 58    """)
 59
 60def getChildIndex(parent, child):
 61    JS("""
 62    var count = 0, current = parent.firstChild;
 63    while (current) {
 64        if (current.isSameNode(child)) {
 65            return count;
 66        }
 67        if (current.nodeType == 1) {
 68            ++count;
 69        }
 70        current = current.nextSibling;
 71    }
 72    return -1;
 73    """)
 74
 75def isOrHasChild(parent, child):
 76    JS("""
 77    while (child) {
 78        if (parent.isSameNode(child)) {
 79            return true;
 80        }
 81        child = child.parentNode;
 82        if (child.nodeType != 1) {
 83            child = null;
 84        }
 85    }
 86    return false;
 87    """)
 88
 89def releaseCapture(elem):
 90    JS("""
 91    if ((DOM_sCaptureElem != null) && DOM_compare(elem, DOM_sCaptureElem))
 92        DOM_sCaptureElem = null;
 93    
 94    if (elem.isSameNode($wnd.__captureElem)) {
 95        $wnd.__captureElem = null;
 96    }
 97    """)
 98
 99
100