DOM.py :  » Ajax » pyjamas » src » library » __mozilla__ » pyjamas » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Ajax » pyjamas 
pyjamas » src » library » __mozilla__ » pyjamas » DOM.py
def buttonClick(button):
    JS("""
        var doc = button.ownerDocument;
        if (doc != null) {
            var evt = doc.createEvent('MouseEvents');
            evt.initMouseEvent('click', true, true, null, 0, 0,
                                0, 0, 0, false, false, false, false, 0, null);
            button.dispatchEvent(evt);
        }
    """)

def compare(elem1, elem2):
    JS("""
    if (!elem1 && !elem2) {
        return true;
    } else if (!elem1 || !elem2) {
        return false;
    }
  if (!elem1.isSameNode) {
    return (elem1 == elem2);
  }
    return (elem1.isSameNode(elem2));
    """)

def eventGetButton(evt):
    JS("""
    var button = evt.which;
    if(button == 2) {
        return 4;
    } else if (button == 3) {
        return 2;
    } else {
        return button || 0;
    }
    """)

# This is what is in GWT 1.5 for getAbsoluteLeft.  err...
#"""
#    // We cannot use DOMImpl here because offsetLeft/Top return erroneous
#    // values when overflow is not visible.  We have to difference screenX
#    // here due to a change in getBoxObjectFor which causes inconsistencies
#    // on whether the calculations are inside or outside of the element's
#    // border.
#    try {
#      return $doc.getBoxObjectFor(elem).screenX
#          - $doc.getBoxObjectFor($doc.documentElement).screenX;
#    } catch (e) {
#      // This works around a bug in the FF3 betas. The bug
#      // should be fixed before they release, so this can
#      // be removed at a later date.
#      // https://bugzilla.mozilla.org/show_bug.cgi?id=409111
#      // DOMException.WRONG_DOCUMENT_ERR == 4
#      if (e.code == 4) {
#        return 0;
#      }
#      throw e;
#    }
#"""
def getAbsoluteLeft(elem):
    JS("""
    // Firefox 3 expects getBoundingClientRect
    // getBoundingClientRect can be float: 73.1 instead of 74, see
    // gwt's workaround at user/src/com/google/gwt/dom/client/DOMImplMozilla.java:47
    // Please note, their implementation has 1px offset.
    if (   typeof elem.getBoundingClientRect == 'function'  ) {
        var left = Math.ceil(elem.getBoundingClientRect().left);
        
        return left  + $doc.body.scrollLeft + $doc.documentElement.scrollLeft;
    }
    // Older Firefox can use getBoxObjectFor
    else {
        var left = $doc.getBoxObjectFor(elem).x;
        var parent = elem.parentNode;
        while (parent) {
            if (parent.scrollLeft > 0) {
                left = left -  parent.scrollLeft;
            }
            parent = parent.parentNode;
        }
        
        return left + $doc.body.scrollLeft + $doc.documentElement.scrollLeft;
    }
    """)

# This is what is in GWT 1.5 for getAbsoluteTop.  err...
#"""
#    // We cannot use DOMImpl here because offsetLeft/Top return erroneous
#    // values when overflow is not visible.  We have to difference screenY
#    // here due to a change in getBoxObjectFor which causes inconsistencies
#    // on whether the calculations are inside or outside of the element's
#    // border.
#    try {
#      return $doc.getBoxObjectFor(elem).screenY
#          - $doc.getBoxObjectFor($doc.documentElement).screenY;
#    } catch (e) {
#      // This works around a bug in the FF3 betas. The bug
#      // should be fixed before they release, so this can
#      // be removed at a later date.
#      // https://bugzilla.mozilla.org/show_bug.cgi?id=409111
#      // DOMException.WRONG_DOCUMENT_ERR == 4
#      if (e.code == 4) {
#        return 0;
#      }
#      throw e;
#    }
#"""
def getAbsoluteTop(elem):
    JS("""
    // Firefox 3 expects getBoundingClientRect
    if (   typeof elem.getBoundingClientRect == 'function'  ) {
        var top = Math.ceil(elem.getBoundingClientRect().top);
        return top + $doc.body.scrollTop + $doc.documentElement.scrollTop;
    }
    // Older Firefox can use getBoxObjectFor
    else {
        var top = $doc.getBoxObjectFor(elem).y;
        var parent = elem.parentNode;
        while (parent) {
            if (parent.scrollTop > 0) {
                top -= parent.scrollTop;
            }
            parent = parent.parentNode;
        }
    
        return top + $doc.body.scrollTop + $doc.documentElement.scrollTop;
    }
    """)

def getChildIndex(parent, child):
    JS("""
    var count = 0, current = parent.firstChild;
    while (current) {
    if (! current.isSameNode) {
      if (current == child) {
      return count;
      }
    }
    else if (current.isSameNode(child)) {
            return count;
        }
        if (current.nodeType == 1) {
            ++count;
        }
        current = current.nextSibling;
    }
    return -1;
    """)

def isOrHasChild(parent, child):
    JS("""
    while (child) {
        if ((!parent.isSameNode)) {
      if (parent == child) {
        return true;
      }
    }
    else if (parent.isSameNode(child)) {
            return true;
        }
        try {
            child = child.parentNode;
        } catch(e) {
          // Give up on 'Permission denied to get property
          // HTMLDivElement.parentNode'
          // See https://bugzilla.mozilla.org/show_bug.cgi?id=208427
          return false;
        }
        if (child && (child.nodeType != 1)) {
          child = null;
        }
      }
    return false;
    """)

def releaseCapture(elem):
    JS("""
    if ((DOM.sCaptureElem != null) && DOM.compare(elem, DOM.sCaptureElem))
        DOM.sCaptureElem = null;
    
  if (!elem.isSameNode) {
    if (elem == $wnd.__captureElem) {
      $wnd.__captureElem = null;
    }
  }
  else if (elem.isSameNode($wnd.__captureElem)) {
        $wnd.__captureElem = null;
    }
    """)



www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.