Skip to content
Browse files

Generate code that's compatible with google closure advanced optimali…

…sations
  • Loading branch information...
1 parent f1d2a37 commit 62bf5c19cbceebcaf873081af17d29e889286e2d @keesbos keesbos committed Jun 20, 2012
Showing with 3,615 additions and 3,588 deletions.
  1. 0 examples/employeeadmin/download.sh
  2. +2 −1 examples/libtest/ClassTest.py
  3. +2 −0 examples/libtest/NoInlineCodeTest.py
  4. +4 −4 library/dynamic.py
  5. +9 −9 library/pygwt.browser.py
  6. +1 −1 library/pygwt.py
  7. +3 −3 library/pyjamas/Canvas/GWTCanvasImplIE6.py
  8. +7 −7 library/pyjamas/Canvas/ImageLoaderhulahop.py
  9. +31 −31 library/pyjamas/Canvas2D.browser.py
  10. +12 −12 library/pyjamas/Cookies.browser.py
  11. +129 −128 library/pyjamas/DOM.browser.py
  12. +69 −69 library/pyjamas/DOM.ie6.py
  13. +48 −48 library/pyjamas/DOM.mozilla.py
  14. +31 −31 library/pyjamas/DOM.oldmoz.py
  15. +17 −17 library/pyjamas/DOM.opera.py
  16. +28 −28 library/pyjamas/DOM.safari.py
  17. +3 −3 library/pyjamas/HTTPRequest.browser.py
  18. +1 −1 library/pyjamas/HTTPRequest.ie6.py
  19. +17 −17 library/pyjamas/History.browser.py
  20. +26 −26 library/pyjamas/History.ie6.py
  21. +1 −1 library/pyjamas/History.py
  22. +21 −21 library/pyjamas/History.safari.py
  23. +3 −3 library/pyjamas/Location.browser.py
  24. +2 −2 library/pyjamas/Location.ie6.py
  25. +2 −2 library/pyjamas/Location.opera.py
  26. +4 −4 library/pyjamas/PyExternalMod.py
  27. +4 −4 library/pyjamas/Timer.browser.py
  28. +10 −10 library/pyjamas/Window.browser.py
  29. +4 −4 library/pyjamas/Window.safari.py
  30. +4 −4 library/pyjamas/XMLDoc.browser.py
  31. +16 −16 library/pyjamas/gears/Factory.py
  32. +7 −7 library/pyjamas/gears/database/Database.py
  33. +8 −8 library/pyjamas/gmaps/Base.py
  34. +2 −2 library/pyjamas/gmaps/DirectionsRenderer.py
  35. +4 −4 library/pyjamas/gmaps/DirectionsService.py
  36. +3 −3 library/pyjamas/gmaps/Geocoder.py
  37. +1 −1 library/pyjamas/gmaps/InfoWindow.py
  38. +2 −2 library/pyjamas/gmaps/Interfaces.py
  39. +8 −8 library/pyjamas/gmaps/Map.py
  40. +2 −2 library/pyjamas/gmaps/Marker.py
  41. +5 −5 library/pyjamas/gmaps/Polygon.py
  42. +1 −1 library/pyjamas/gmaps/Polyline.py
  43. +13 −13 library/pyjamas/gmaps/Utils.py
  44. +5 −5 library/pyjamas/logging/handlers.py
  45. +5 −5 library/pyjamas/media/Media.py
  46. +3 −3 library/pyjamas/media/MediaElement.py
  47. +1 −1 library/pyjamas/media/MediaError.py
  48. +3 −3 library/pyjamas/media/TimeRanges.py
  49. +8 −8 library/pyjamas/media/VideoElement.py
  50. +57 −57 library/pyjamas/raphael/raphael.py
  51. +15 −15 library/pyjamas/selection/Range.ie6.py
  52. +10 −10 library/pyjamas/selection/RangeEndPoint.py
  53. +2 −2 library/pyjamas/ui/Focus.ie6.py
  54. +20 −20 library/pyjamas/ui/Focus.mozilla.py
  55. +20 −20 library/pyjamas/ui/Focus.oldmoz.py
  56. +21 −20 library/pyjamas/ui/Focus.opera.py
  57. +22 −21 library/pyjamas/ui/Focus.safari.py
  58. +12 −12 library/pyjamas/ui/FormPanel.browser.py
  59. +11 −11 library/pyjamas/ui/FormPanel.ie6.py
  60. +2 −2 library/pyjamas/ui/FormPanel.opera.py
  61. +16 −16 library/pyjamas/ui/PopupPanel.ie6.py
  62. +23 −23 library/pyjamas/ui/RichTextAreaImplStandard.browser.py
  63. +6 −6 library/pyjamas/ui/TextArea.ie6.py
  64. +14 −14 library/pyjamas/ui/TextBoxBase.ie6.py
  65. +1 −1 library/pyjamas/ui/__init__.py
  66. +1 −1 library/pyjamas/ui/horizsplitpanel.ie6.py
  67. +341 −341 library/pyjslib.PyJS.py
  68. +79 −79 library/pyjslib.PyV8.py
  69. +1 −1 library/pyjslib.pysm.py
  70. +47 −40 pyjs/src/pyjs/boilerplate/all.cache.html
  71. +3 −3 pyjs/src/pyjs/browser.py
  72. +225 −225 pyjs/src/pyjs/builtin/public/_pyjs.js
  73. +1,708 −1,707 pyjs/src/pyjs/builtin/pyjslib.py
  74. +5 −5 pyjs/src/pyjs/lib/_random.py
  75. +8 −8 pyjs/src/pyjs/lib/datetime.py
  76. +4 −4 pyjs/src/pyjs/lib/imp.py
  77. +39 −39 pyjs/src/pyjs/lib/json.py
  78. +1 −1 pyjs/src/pyjs/lib/logging/__init__.py
  79. +19 −19 pyjs/src/pyjs/lib/math.py
  80. +9 −9 pyjs/src/pyjs/lib/md5.py
  81. +23 −23 pyjs/src/pyjs/lib/sets.py
  82. +23 −23 pyjs/src/pyjs/lib/sys.py
  83. +2 −2 pyjs/src/pyjs/lib/test/UnitTest.py
  84. +3 −3 pyjs/src/pyjs/lib/test/write.py
  85. +37 −37 pyjs/src/pyjs/lib/time.py
  86. +193 −180 pyjs/src/pyjs/translator_proto.py
View
0 examples/employeeadmin/download.sh 100644 → 100755
File mode changed.
View
3 examples/libtest/ClassTest.py
@@ -161,7 +161,8 @@ def testClassVars(self):
from __pyjamas__ import JS
try:
x = ExampleClass().fail_a()
- self.assertTrue(JS('pyjslib.isUndefined(@{{x}})'))
+ #self.assertTrue(JS('pyjslib.isUndefined(@{{x}})'))
+ self.assertTrue(JS("$pyjs['loaded_modules']['pyjslib']['isUndefined'](@{{x}})"))
except ValueError:
self.assertTrue(True)
View
2 examples/libtest/NoInlineCodeTest.py
@@ -1,4 +1,6 @@
# Tests for the implementatuion of --no-inline-code
+# Note that the use of int/float/lon as variable
+# is not allowed with google closure compile
import sys
import UnitTest
View
8 library/dynamic.py
@@ -14,13 +14,13 @@ class AjaxError(RuntimeError):
pass
def createHttpRequest():
- if JS("""typeof $wnd.XMLHttpRequest != 'undefined'"""):
+ if JS("""typeof $wnd['XMLHttpRequest'] != 'undefined'"""):
# IE7+, Mozilla, Safari, ...
return JS("""new XMLHttpRequest()""")
# Check for IE6/ActiveX
try:
- res = JS("""new ActiveXObject("Msxml2.XMLHTTP")""")
+ res = JS("""new ActiveXObject("Msxml2['XMLHTTP']")""")
return res
except:
pass
@@ -50,7 +50,7 @@ def onreadystatechange(evnt):
on_load_fn(evnt, req)
# next line is in JS() for IE6
- JS("@{{req}}.onreadystatechange = @{{onreadystatechange}};")
+ JS("@{{req}}['onreadystatechange'] = @{{onreadystatechange}};")
req.open("GET", url , async)
try:
req.send(None)
@@ -72,7 +72,7 @@ def onreadystatechange(evnt):
def inject(values, namespace = None, names=None):
if namespace is None:
from __pyjamas__ import JS
- namespace = JS("$pyjs.global_namespace")
+ namespace = JS("$pyjs['global_namespace']")
values = dict(values)
if names is None:
for k in values:
View
18 library/pygwt.browser.py
@@ -6,7 +6,7 @@ def getNextHashId():
def getHashCode(o):
JS("""
return (@{{o}} == null) ? 0 :
- (@{{o}}.$H ? @{{o}}.$H : (@{{o}}.$H = @{{getNextHashId}}()));
+ (@{{o}}['$H'] ? @{{o}}['$H'] : (@{{o}}['$H'] = @{{getNextHashId}}()));
""")
def getModuleName():
@@ -18,22 +18,22 @@ def getModuleBaseURL():
JS("""
// this is intentionally not using $doc, because we want
// the module's own url
- var s = document.location.href;
+ var s = document['location']['href'];
// Pull off any hash.
- var i = s.indexOf('#');
+ var i = s['indexOf']('#');
if (i != -1)
- s = s.substring(0, i);
+ s = s['substring'](0, i);
// Pull off any query string.
- i = s.indexOf('?');
+ i = s['indexOf']('?');
if (i != -1)
- s = s.substring(0, i);
+ s = s['substring'](0, i);
// Rip off everything after the last slash.
- i = s.lastIndexOf('/');
+ i = s['lastIndexOf']('/');
if (i != -1)
- s = s.substring(0, i);
+ s = s['substring'](0, i);
- return (s.length > 0) ? s + "/" : "";
+ return (s['length'] > 0) ? s + "/" : "";
""")
View
2 library/pygwt.py
@@ -10,7 +10,7 @@ def getNextHashId():
def getHashCode(o):
JS("""
return (@{{o}} == null) ? 0 :
- (@{{o}}.$H ? @{{o}}.$H : (@{{o}}.$H = @{{!pygwt_getNextHashId}}()))
+ (@{{o}}['$H'] ? @{{o}}['$H'] : (@{{o}}['$H'] = @{{!pygwt_getNextHashId}}()))
""")
def getModuleName():
View
6 library/pyjamas/Canvas/GWTCanvasImplIE6.py
@@ -35,9 +35,9 @@
def addNamespace():
JS("""
- if (!$doc.namespaces["v"]) {
- $doc.namespaces.add("v", "urn:schemas-microsoft-com:vml");
- $doc.createStyleSheet().cssText = "v\\:*{behavior:url(#default#VML);}";
+ if (!$doc['namespaces']["v"]) {
+ $doc['namespaces']['add']("v", "urn:schemas-microsoft-com:vml");
+ $doc['createStyleSheet']()['cssText'] = "v\\:*{behavior:url(#default#VML);}";
}
""")
View
14 library/pyjamas/Canvas/ImageLoaderhulahop.py
@@ -123,22 +123,22 @@ def prepareImage(self, url):
var __this = this;
- @{{img}}.onload = function() {
- if(!@{{img}}.__isLoaded) {
+ @{{img}}['onload'] = function() {
+ if(!@{{img}}['__isLoaded']) {
// __isLoaded should be set for the first time here.
// if for some reason img fires a second onload event
// we do not want to execute the following again (hence the guard)
- @{{img}}.__isLoaded = true;
- __this.incrementLoadedImages();
- @{{img}}.onload = null;
+ @{{img}}['__isLoaded'] = true;
+ __this['incrementLoadedImages']();
+ @{{img}}['onload'] = null;
// we call this function each time onload fires
// It will see if we are ready to invoke the callback
- __this.dispatchIfComplete();
+ __this['dispatchIfComplete']();
} else {
// we invoke the callback since we are already loaded
- __this.dispatchIfComplete();
+ __this['dispatchIfComplete']();
}
}
View
62 library/pyjamas/Canvas2D.browser.py
@@ -2,66 +2,66 @@ class Canvas(Widget):
def isEmulation(self):
JS("""
- return (typeof $wnd.G_vmlCanvasManager != "undefined");
+ return (typeof $wnd['G_vmlCanvasManager'] != "undefined");
""")
def init(self):
JS("""
- var el = this.canvas;
- if (typeof $wnd.G_vmlCanvasManager != "undefined") {
- var parent = el.parent;
+ var el = this['canvas'];
+ if (typeof $wnd['G_vmlCanvasManager'] != "undefined") {
+ var parent = el['parent'];
- el = $wnd.G_vmlCanvasManager.fixElement_(el);
- el.getContext = function () {
- if (this.context_) {
- return this.context_;
+ el = $wnd['G_vmlCanvasManager']['fixElement_'](el);
+ el['getContext'] = function () {
+ if (this['context_']) {
+ return this['context_'];
}
- return this.context_ = new $wnd.CanvasRenderingContext2D(el);
+ return this['context_'] = new $wnd['CanvasRenderingContext2D'](el);
};
- el.attachEvent("onpropertychange", function (e) {
+ el['attachEvent']("onpropertychange", function (e) {
// we need to watch changes to width and height
- switch (e.propertyName) {
+ switch (e['propertyName']) {
case "width":
case "height":
// coord size changed?
break;
}
});
- // if style.height is set
+ // if style['height'] is set
- var attrs = el.attributes;
- if (attrs.width && attrs.width.specified) {
+ var attrs = el['attributes'];
+ if (attrs['width'] && attrs['width']['specified']) {
// TODO: use runtimeStyle and coordsize
- // el.getContext().setWidth_(attrs.width.nodeValue);
- el.style.width = attrs.width.nodeValue + "px";
+ // el['getContext']()['setWidth_'](attrs['width']['nodeValue']);
+ el['style']['width'] = attrs['width']['nodeValue'] + "px";
}
- if (attrs.height && attrs.height.specified) {
+ if (attrs['height'] && attrs['height']['specified']) {
// TODO: use runtimeStyle and coordsize
- // el.getContext().setHeight_(attrs.height.nodeValue);
- el.style.height = attrs.height.nodeValue + "px";
+ // el['getContext']()['setHeight_'](attrs['height']['nodeValue']);
+ el['style']['height'] = attrs['height']['nodeValue'] + "px";
}
}
- var ctx = el.getContext("2d");
+ var ctx = el['getContext']("2d");
- ctx._createPattern = ctx.createPattern;
- ctx.createPattern = function(img, rep) {
+ ctx['_createPattern'] = ctx['createPattern'];
+ ctx['createPattern'] = function(img, rep) {
// Next line breaks things for Chrome
- //if (!(img instanceof Image)) img = img.getElement();
- return this._createPattern(img, rep);
+ //if (!(img instanceof Image)) img = img['getElement']();
+ return this['_createPattern'](img, rep);
}
- ctx._drawImage = ctx.drawImage;
- ctx.drawImage = function() {
+ ctx['_drawImage'] = ctx['drawImage'];
+ ctx['drawImage'] = function() {
var a=arguments;
// Next line breaks things for Chrome
- //if (!(a[0] instanceof Image)) a[0] = a[0].getElement();
- if (a.length==9) return this._drawImage(a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8]);
- else if (a.length==5) return this._drawImage(a[0], a[1], a[2], a[3], a[4]);
- return this._drawImage(a[0], a[1], a[2]);
+ //if (!(a[0] instanceof Image)) a[0] = a[0]['getElement']();
+ if (a['length']==9) return this['_drawImage'](a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8]);
+ else if (a['length']==5) return this['_drawImage'](a[0], a[1], a[2], a[3], a[4]);
+ return this['_drawImage'](a[0], a[1], a[2]);
}
- this.context = ctx;
+ this['context'] = ctx;
""")
View
24 library/pyjamas/Cookies.browser.py
@@ -1,6 +1,6 @@
def getCookie(cookie_name):
JS("""
- var results = document.cookie.match ( '(^|;) ?' +
+ var results = document['cookie']['match'] ( '(^|;) ?' +
@{{cookie_name}} + '=([^;]*)(;|$)' );
if ( results )
@@ -13,18 +13,18 @@ def getCookie(cookie_name):
# expires can be int or Date
def setCookie(name, value, expires, domain=None, path=None, secure=False):
JS("""
- if (@{{expires}} instanceof Date) @{{expires}} = @{{expires}}.getTime();
+ if (@{{expires}} instanceof Date) @{{expires}} = @{{expires}}['getTime']();
if (@{{isUndefined}}(@{{domain}})) @{{domain}} = null;
if (@{{isUndefined}}(@{{path}})) @{{path}} = null;
if (@{{isUndefined}}(@{{secure}})) @{{secure}} = false;
var today = new Date();
var expiration = new Date();
if (!@{{expires}}) @{{expires}} = 0;
- expiration.setTime(today.getTime() + @{{expires}});
+ expiration['setTime'](today['getTime']() + @{{expires}});
var c = encodeURIComponent(@{{name}}) + '=' + encodeURIComponent(@{{value}});
- c += ';expires=' + expiration.toGMTString();
+ c += ';expires=' + expiration['toGMTString']();
if (@{{domain}})
c += ';domain=' + @{{domain}};
@@ -33,28 +33,28 @@ def setCookie(name, value, expires, domain=None, path=None, secure=False):
if (@{{secure}})
c += ';secure';
- $doc.cookie = c;
+ $doc['cookie'] = c;
""")
def loadCookies():
JS("""
var cookies = {};
- var docCookie = $doc.cookie;
+ var docCookie = $doc['cookie'];
if (docCookie && docCookie != '') {
- var crumbs = docCookie.split(';');
- for (var i = 0; i < crumbs.length; ++i) {
- alert(crumbs.length);
+ var crumbs = docCookie['split'](';');
+ for (var i = 0; i < crumbs['length']; ++i) {
+ alert(crumbs['length']);
var name, value;
- var eqIdx = crumbs[i].indexOf('=');
+ var eqIdx = crumbs[i]['indexOf']('=');
if (eqIdx == -1) {
name = crumbs[i];
value = '';
} else {
- name = crumbs[i].substring(0, eqIdx);
- value = crumbs[i].substring(eqIdx + 1);
+ name = crumbs[i]['substring'](0, eqIdx);
+ value = crumbs[i]['substring'](eqIdx + 1);
}
alert(name);
View
257 library/pyjamas/DOM.browser.py
@@ -17,84 +17,84 @@ def init():
mousewheel = Event.eventbits[Event.eventmap['mousewheel']][0]
JS("""
// Set up capture event dispatchers.
- $wnd.__dispatchCapturedMouseEvent = function(evt) {
- if ($wnd.__dispatchCapturedEvent(evt)) {
+ $wnd['__dispatchCapturedMouseEvent'] = function(evt) {
+ if ($wnd['__dispatchCapturedEvent'](evt)) {
var cap = @{{getCaptureElement}}();
- if (cap && cap.__listener) {
- @{{dispatchEvent}}(evt, cap, cap.__listener);
- evt.stopPropagation();
+ if (cap && cap['__listener']) {
+ @{{dispatchEvent}}(evt, cap, cap['__listener']);
+ evt['stopPropagation']();
}
}
};
- $wnd.__dispatchCapturedEvent = function(evt) {
- if (!@{{previewEvent}}(evt).valueOf()) {
- evt.stopPropagation();
- evt.preventDefault();
+ $wnd['__dispatchCapturedEvent'] = function(evt) {
+ if (!@{{previewEvent}}(evt)['valueOf']()) {
+ evt['stopPropagation']();
+ evt['preventDefault']();
return false;
}
return true;
};
- $wnd.addEventListener(
+ $wnd['addEventListener'](
'mouseout',
function(evt){
var cap = @{{getCaptureElement}}();
if (cap) {
- if (!evt.relatedTarget) {
+ if (!evt['relatedTarget']) {
// When the mouse leaves the window during capture,
// release capture and synthesize an 'onlosecapture' event.
@{{sCaptureElem}} = null;
- if (cap.__listener) {
- var lcEvent = $doc.createEvent('UIEvent');
- lcEvent.initUIEvent('losecapture', false, false,
+ if (cap['__listener']) {
+ var lcEvent = $doc['createEvent']('UIEvent');
+ lcEvent['initUIEvent']('losecapture', false, false,
$wnd, 0);
- @{{dispatchEvent}}(lcEvent, cap, cap.__listener);
+ @{{dispatchEvent}}(lcEvent, cap, cap['__listener']);
}
}
}
},
true
);
- var dcme = $wnd.__dispatchCapturedMouseEvent;
- var dce = $wnd.__dispatchCapturedEvent;
+ var dcme = $wnd['__dispatchCapturedMouseEvent'];
+ var dce = $wnd['__dispatchCapturedEvent'];
- $wnd.addEventListener('click', dcme, true);
- $wnd.addEventListener('dblclick', dcme, true);
- $wnd.addEventListener('mousedown', dcme, true);
- $wnd.addEventListener('mouseup', dcme, true);
- $wnd.addEventListener('mousemove', dcme, true);
- $wnd.addEventListener('keydown', dce, true);
- $wnd.addEventListener('keyup', dce, true);
- $wnd.addEventListener('keypress', dce, true);
+ $wnd['addEventListener']('click', dcme, true);
+ $wnd['addEventListener']('dblclick', dcme, true);
+ $wnd['addEventListener']('mousedown', dcme, true);
+ $wnd['addEventListener']('mouseup', dcme, true);
+ $wnd['addEventListener']('mousemove', dcme, true);
+ $wnd['addEventListener']('keydown', dce, true);
+ $wnd['addEventListener']('keyup', dce, true);
+ $wnd['addEventListener']('keypress', dce, true);
- $wnd.__dispatchEvent = function(evt) {
+ $wnd['__dispatchEvent'] = function(evt) {
var listener, curElem = this;
- while (curElem && !(listener = curElem.__listener)) {
- curElem = curElem.parentNode;
+ while (curElem && !(listener = curElem['__listener'])) {
+ curElem = curElem['parentNode'];
}
- if (curElem && curElem.nodeType != 1) {
+ if (curElem && curElem['nodeType'] != 1) {
curElem = null;
}
if (listener) {
@{{dispatchEvent}}(evt, curElem, listener);
}
};
- var dcme = $wnd.__dispatchCapturedMouseEvent;
- $wnd.addEventListener(@{{mousewheel}}, dcme, true);
+ var dcme = $wnd['__dispatchCapturedMouseEvent'];
+ $wnd['addEventListener'](@{{mousewheel}}, dcme, true);
""")
def addEventPreview(preview):
sEventPreviewStack.append(preview)
def buttonClick(button):
JS("""
- @{{button}}.click();
+ @{{button}}['click']();
""")
def compare(elem1, elem2):
@@ -104,70 +104,70 @@ def compare(elem1, elem2):
def createElement(tag):
JS("""
- return $doc.createElement(@{{tag}});
+ return $doc['createElement'](@{{tag}});
""")
def createInputElement(elementType):
JS("""
- var e = $doc.createElement("INPUT");
- e.type = @{{elementType}};
+ var e = $doc['createElement']("INPUT");
+ e['type'] = @{{elementType}};
return e;
""")
def createInputRadio(group):
JS("""
- var elem = $doc.createElement("INPUT");
- elem.type = 'radio';
- elem.name = @{{group}};
+ var elem = $doc['createElement']("INPUT");
+ elem['type'] = 'radio';
+ elem['name'] = @{{group}};
return elem;
""")
def eventGetFromElement(evt):
JS("""
- return @{{evt}}.fromElement ? @{{evt}}.fromElement : null;
+ return @{{evt}}['fromElement'] ? @{{evt}}['fromElement'] : null;
""")
def eventGetKeyCode(evt):
JS("""
- return @{{evt}}.which ? @{{evt}}.which :
- (@{{evt}}.keyCode ? @{{evt}}.keyCode : 0);
+ return @{{evt}}['which'] ? @{{evt}}['which'] :
+ (@{{evt}}['keyCode'] ? @{{evt}}['keyCode'] : 0);
""")
def eventGetTarget(event):
JS("""
- return @{{event}}.target ? @{{event}}.target : null;
+ return @{{event}}['target'] ? @{{event}}['target'] : null;
""")
def eventGetToElement(evt):
JS("""
- return @{{evt}}.relatedTarget ? @{{evt}}.relatedTarget : null;
+ return @{{evt}}['relatedTarget'] ? @{{evt}}['relatedTarget'] : null;
""")
def eventToString(evt):
JS("""
- return @{{evt}}.toString();
+ return @{{evt}}['toString']();
""")
def getAbsoluteLeft(_elem):
JS("""
var elem = @{{_elem}};
var left = 0;
while (elem) {
- left += elem.offsetLeft - elem.scrollLeft;
- elem = elem.offsetParent;
+ left += elem['offsetLeft'] - elem['scrollLeft'];
+ elem = elem['offsetParent'];
}
- return left + $doc.body.scrollLeft;
+ return left + $doc['body']['scrollLeft'];
""")
def getAbsoluteTop(_elem):
JS("""
var elem = @{{_elem}};
var top = 0;
while (elem) {
- top += elem.offsetTop - elem.scrollTop;
- elem = elem.offsetParent;
+ top += elem['offsetTop'] - elem['scrollTop'];
+ elem = elem['offsetParent'];
}
- return top + $doc.body.scrollTop;
+ return top + $doc['body']['scrollTop'];
""")
def getAttribute(elem, attr):
@@ -192,10 +192,10 @@ def getChild(elem, index):
Get a child of the DOM element by specifying an index.
"""
JS("""
- var count = 0, child = @{{elem}}.firstChild;
+ var count = 0, child = @{{elem}}['firstChild'];
while (child) {
- var next = child.nextSibling;
- if (child.nodeType == 1) {
+ var next = child['nextSibling'];
+ if (child['nodeType'] == 1) {
if (@{{index}} == count)
return child;
++count;
@@ -212,11 +212,11 @@ def getChildCount(elem):
over all the children of that element and counts them.
"""
JS("""
- var count = 0, child = @{{elem}}.firstChild;
+ var count = 0, child = @{{elem}}['firstChild'];
while (child) {
- if (child.nodeType == 1)
+ if (child['nodeType'] == 1)
++count;
- child = child.nextSibling;
+ child = child['nextSibling'];
}
return count;
""")
@@ -228,13 +228,13 @@ def getChildIndex(parent, toFind):
This performs a linear search.
"""
JS("""
- var count = 0, child = @{{parent}}.firstChild;
+ var count = 0, child = @{{parent}}['firstChild'];
while (child) {
if (child == @{{toFind}})
return count;
- if (child.nodeType == 1)
+ if (child['nodeType'] == 1)
++count;
- child = child.nextSibling;
+ child = child['nextSibling'];
}
return -1;
@@ -245,7 +245,7 @@ def getElementById(id):
Return the element in the document's DOM tree with the given id.
"""
JS("""
- var elem = $doc.getElementById(@{{id}});
+ var elem = $doc['getElementById'](@{{id}});
return elem ? elem : null;
""")
@@ -254,7 +254,7 @@ def getEventListener(element):
See setEventListener for more information.
"""
JS("""
- return @{{element}}.__listener;
+ return @{{element}}['__listener'];
""")
def getEventsSunk(element):
@@ -263,34 +263,34 @@ def getEventsSunk(element):
sinkEvents() for more information.
"""
from __pyjamas__ import INT
- return INT(JS("@{{element}}.__eventBits ? @{{element}}.__eventBits : 0"))
+ return INT(JS("@{{element}}['__eventBits'] ? @{{element}}['__eventBits'] : 0"))
def getFirstChild(elem):
JS("""
- var child = @{{elem}}.firstChild;
- while (child && child.nodeType != 1)
- child = child.nextSibling;
+ var child = @{{elem}}['firstChild'];
+ while (child && child['nodeType'] != 1)
+ child = child['nextSibling'];
return child ? child : null;
""")
def getInnerHTML(element):
JS("""
- var ret = @{{element}}.innerHTML;
+ var ret = @{{element}}['innerHTML'];
return (ret == null) ? null : ret;
""")
def getInnerText(element):
JS("""
// To mimic IE's 'innerText' property in the W3C DOM, we need to recursively
// concatenate all child text nodes (depth first).
- var text = '', child = @{{element}}.firstChild;
+ var text = '', child = @{{element}}['firstChild'];
while (child) {
- if (child.nodeType == 1){ // 1 == Element node
+ if (child['nodeType'] == 1){ // 1 == Element node
text += @{{getInnerText}}(child);
- } else if (child.nodeValue) {
- text += child.nodeValue;
+ } else if (child['nodeValue']) {
+ text += child['nodeValue'];
}
- child = child.nextSibling;
+ child = child['nextSibling'];
}
return text;
""")
@@ -306,7 +306,7 @@ def getIntAttribute(elem, attr):
def getIntStyleAttribute(elem, attr):
JS("""
- var i = parseInt(@{{elem}}.style[@{{attr}}]);
+ var i = parseInt(@{{elem}}['style'][@{{attr}}]);
if (!i) {
return 0;
}
@@ -315,44 +315,44 @@ def getIntStyleAttribute(elem, attr):
def getNextSibling(elem):
JS("""
- var sib = @{{elem}}.nextSibling;
- while (sib && sib.nodeType != 1)
- sib = sib.nextSibling;
+ var sib = @{{elem}}['nextSibling'];
+ while (sib && sib['nodeType'] != 1)
+ sib = sib['nextSibling'];
return sib ? sib : null;
""")
def getParent(elem):
JS("""
- var parent = @{{elem}}.parentNode;
+ var parent = @{{elem}}['parentNode'];
if(parent == null) {
return null;
}
- if (parent.nodeType != 1)
+ if (parent['nodeType'] != 1)
parent = null;
return parent ? parent : null;
""")
def getStyleAttribute(elem, attr):
JS("""
- var ret = @{{elem}}.style[@{{attr}}];
+ var ret = @{{elem}}['style'][@{{attr}}];
return (ret == null) ? null : ret;
""")
def insertChild(parent, toAdd, index):
JS("""
- var count = 0, child = @{{parent}}.firstChild, before = null;
+ var count = 0, child = @{{parent}}['firstChild'], before = null;
while (child) {
- if (child.nodeType == 1) {
+ if (child['nodeType'] == 1) {
if (count == @{{index}}) {
before = child;
break;
}
++count;
}
- child = child.nextSibling;
+ child = child['nextSibling'];
}
- @{{parent}}.insertBefore(@{{toAdd}}, before);
+ @{{parent}}['insertBefore'](@{{toAdd}}, before);
""")
def iterChildren(elem):
@@ -362,7 +362,7 @@ def iterChildren(elem):
"""
JS("""
var parent = @{{elem}};
- var child = @{{elem}}.firstChild;
+ var child = @{{elem}}['firstChild'];
var lastChild = null;
return {
'next': function() {
@@ -374,7 +374,7 @@ def iterChildren(elem):
return lastChild;
},
'remove': function() {
- parent.removeChild(lastChild);
+ parent['removeChild'](lastChild);
},
__iter__: function() {
return this;
@@ -404,23 +404,23 @@ def walkChildren(elem):
var nextSibling = @{{getNextSibling}}(child);
if(firstChild != null) {
if(nextSibling != null) {
- stack.push(nextSibling);
- parentStack.push(parent);
+ stack['push'](nextSibling);
+ parentStack['push'](parent);
}
parent = child;
child = firstChild;
} else if(nextSibling != null) {
child = nextSibling;
- } else if(stack.length > 0) {
- child = stack.pop();
- parent = parentStack.pop();
+ } else if(stack['length'] > 0) {
+ child = stack['pop']();
+ parent = parentStack['pop']();
} else {
child = null;
}
return lastChild;
},
'remove': function() {
- parent.removeChild(lastChild);
+ parent['removeChild'](lastChild);
},
__iter__: function() {
return this;
@@ -433,40 +433,40 @@ def removeEventPreview(preview):
def scrollIntoView(elem):
JS("""
- var left = @{{elem}}.offsetLeft, top = @{{elem}}.offsetTop;
- var width = @{{elem}}.offsetWidth, height = @{{elem}}.offsetHeight;
+ var left = @{{elem}}['offsetLeft'], top = @{{elem}}['offsetTop'];
+ var width = @{{elem}}['offsetWidth'], height = @{{elem}}['offsetHeight'];
- if (@{{elem}}.parentNode != @{{elem}}.offsetParent) {
- left -= @{{elem}}.parentNode.offsetLeft;
- top -= @{{elem}}.parentNode.offsetTop;
+ if (@{{elem}}['parentNode'] != @{{elem}}['offsetParent']) {
+ left -= @{{elem}}['parentNode']['offsetLeft'];
+ top -= @{{elem}}['parentNode']['offsetTop'];
}
- var cur = @{{elem}}.parentNode;
- while (cur && (cur.nodeType == 1)) {
- if ((cur.style.overflow == 'auto') || (cur.style.overflow == 'scroll')) {
- if (left < cur.scrollLeft) {
- cur.scrollLeft = left;
+ var cur = @{{elem}}['parentNode'];
+ while (cur && (cur['nodeType'] == 1)) {
+ if ((cur['style']['overflow'] == 'auto') || (cur['style']['overflow'] == 'scroll')) {
+ if (left < cur['scrollLeft']) {
+ cur['scrollLeft'] = left;
}
- if (left + width > cur.scrollLeft + cur.clientWidth) {
- cur.scrollLeft = (left + width) - cur.clientWidth;
+ if (left + width > cur['scrollLeft'] + cur['clientWidth']) {
+ cur['scrollLeft'] = (left + width) - cur['clientWidth'];
}
- if (top < cur.scrollTop) {
- cur.scrollTop = top;
+ if (top < cur['scrollTop']) {
+ cur['scrollTop'] = top;
}
- if (top + height > cur.scrollTop + cur.clientHeight) {
- cur.scrollTop = (top + height) - cur.clientHeight;
+ if (top + height > cur['scrollTop'] + cur['clientHeight']) {
+ cur['scrollTop'] = (top + height) - cur['clientHeight'];
}
}
- var offsetLeft = cur.offsetLeft, offsetTop = cur.offsetTop;
- if (cur.parentNode != cur.offsetParent) {
- offsetLeft -= cur.parentNode.offsetLeft;
- offsetTop -= cur.parentNode.offsetTop;
+ var offsetLeft = cur['offsetLeft'], offsetTop = cur['offsetTop'];
+ if (cur['parentNode'] != cur['offsetParent']) {
+ offsetLeft -= cur['parentNode']['offsetLeft'];
+ offsetTop -= cur['parentNode']['offsetTop'];
}
- left += offsetLeft - cur.scrollLeft;
- top += offsetTop - cur.scrollTop;
- cur = cur.parentNode;
+ left += offsetLeft - cur['scrollLeft'];
+ top += offsetTop - cur['scrollTop'];
+ cur = cur['parentNode'];
}
""")
@@ -493,30 +493,30 @@ def setEventListener(element, listener):
use sinkEvents().
"""
JS("""
- @{{element}}.__listener = @{{listener}};
+ @{{element}}['__listener'] = @{{listener}};
""")
def setInnerHTML(element, html):
- JS("""@{{element}}.innerHTML = @{{html}} || "";""")
+ JS("""@{{element}}['innerHTML'] = @{{html}} || "";""")
def setInnerText(elem, text):
JS("""
// Remove all children first.
- while (@{{elem}}.firstChild) {
- @{{elem}}.removeChild(@{{elem}}.firstChild);
+ while (@{{elem}}['firstChild']) {
+ @{{elem}}['removeChild'](@{{elem}}['firstChild']);
}
// Add a new text node.
- @{{elem}}.appendChild($doc.createTextNode(@{{text}}));
+ @{{elem}}['appendChild']($doc['createTextNode'](@{{text}}));
""")
def setIntAttribute(elem, attr, value):
JS("""
- @{{elem}}[@{{attr}}] = @{{value}}.valueOf();
+ @{{elem}}[@{{attr}}] = @{{value}}['valueOf']();
""")
def setIntStyleAttribute(elem, attr, value):
JS("""
- @{{elem}}.style[@{{attr}}] = @{{value}}.valueOf();
+ @{{elem}}['style'][@{{attr}}] = @{{value}}['valueOf']();
""")
def setOptionText(select, text, index):
@@ -525,7 +525,7 @@ def setOptionText(select, text, index):
def setStyleAttribute(element, attr, value):
JS("""
- @{{element}}.style[@{{attr}}] = @{{value}};
+ @{{element}}['style'][@{{attr}}] = @{{value}};
""")
def sinkEvents(element, bits):
@@ -535,9 +535,9 @@ def sinkEvents(element, bits):
@param bits: A combination of bits; see ui.Event for bit values
"""
- JS("@{{element}}.__eventBits = @{{bits}};")
+ JS("@{{element}}['__eventBits'] = @{{bits}};")
sinkEventsMozilla(element, bits)
- dispEvnt = JS("$wnd.__dispatchEvent")
+ dispEvnt = JS("$wnd['__dispatchEvent']")
for bit in Event.eventbits:
if (bits & bit):
for event_name in Event.eventbits[bit][1]:
@@ -548,11 +548,11 @@ def sinkEvents(element, bits):
def toString(elem):
JS("""
- var temp = @{{elem}}.cloneNode(true);
- var tempDiv = $doc.createElement("DIV");
- tempDiv.appendChild(temp);
- var outer = tempDiv.innerHTML;
- temp.innerHTML = "";
+ var temp = @{{elem}}['cloneNode'](true);
+ var tempDiv = $doc['createElement']("DIV");
+ tempDiv['appendChild'](temp);
+ var outer = tempDiv['innerHTML'];
+ temp['innerHTML'] = "";
return outer;
""")
@@ -600,3 +600,4 @@ def insertListItem(select, item, value, index):
+
View
138 library/pyjamas/DOM.ie6.py
@@ -5,39 +5,39 @@
def init():
JS("""
// Set up event dispatchers.
- $wnd.__dispatchEvent = function() {
- if ($wnd.event.returnValue == null) {
- $wnd.event.returnValue = true;
- if (!@{{previewEvent}}($wnd.event))
+ $wnd['__dispatchEvent'] = function() {
+ if ($wnd['event']['returnValue'] == null) {
+ $wnd['event']['returnValue'] = true;
+ if (!@{{previewEvent}}($wnd['event']))
return;
}
var listener, curElem = this;
- while (curElem && !(listener = curElem.__listener))
- curElem = curElem.parentElement;
+ while (curElem && !(listener = curElem['__listener']))
+ curElem = curElem['parentElement'];
if (listener)
- @{{dispatchEvent}}($wnd.event, curElem, listener);
+ @{{dispatchEvent}}($wnd['event'], curElem, listener);
};
- $wnd.__dispatchDblClickEvent = function() {
- var newEvent = $doc.createEventObject();
- this.fireEvent('onclick', newEvent);
- if (this.__eventBits & 2)
- $wnd.__dispatchEvent.call(this);
+ $wnd['__dispatchDblClickEvent'] = function() {
+ var newEvent = $doc['createEventObject']();
+ this['fireEvent']('onclick', newEvent);
+ if (this['__eventBits'] & 2)
+ $wnd['__dispatchEvent']['call'](this);
};
- $doc.body.onclick =
- $doc.body.onmousedown =
- $doc.body.onmouseup =
- $doc.body.onmousemove =
- $doc.body.onkeydown =
- $doc.body.onkeypress =
- $doc.body.onkeyup =
- $doc.body.onfocus =
- $doc.body.onblur =
- $doc.body.onselectstart =
- $doc.body.ondblclick = $wnd.__dispatchEvent;
+ $doc['body']['onclick'] =
+ $doc['body']['onmousedown'] =
+ $doc['body']['onmouseup'] =
+ $doc['body']['onmousemove'] =
+ $doc['body']['onkeydown'] =
+ $doc['body']['onkeypress'] =
+ $doc['body']['onkeyup'] =
+ $doc['body']['onfocus'] =
+ $doc['body']['onblur'] =
+ $doc['body']['onselectstart'] =
+ $doc['body']['ondblclick'] = $wnd['__dispatchEvent'];
""")
def compare(elem1, elem2):
@@ -46,20 +46,20 @@ def compare(elem1, elem2):
return true;
else if (!@{{elem1}} || !@{{elem2}})
return false;
- return (@{{elem1}}.uniqueID == @{{elem2}}.uniqueID);
+ return (@{{elem1}}['uniqueID'] == @{{elem2}}['uniqueID']);
""")
def createInputRadio(group):
JS("""
- ua = navigator.userAgent.toLowerCase();
- if (ua.indexOf('msie 9.0') != -1) {
- var elem = $doc.createElement("INPUT");
- elem.type = 'radio';
- elem.name = @{{group}};
+ ua = navigator['userAgent']['toLowerCase']();
+ if (ua['indexOf']('msie 9['0']') != -1) {
+ var elem = $doc['createElement']("INPUT");
+ elem['type'] = 'radio';
+ elem['name'] = @{{group}};
return elem
}
- return $doc.createElement("<INPUT type='RADIO' name='" + @{{group}} + "'>");
+ return $doc['createElement']("<INPUT type='RADIO' name='" + @{{group}} + "'>");
""")
def eventGetType(event):
@@ -73,45 +73,45 @@ def eventGetCurrentTarget(event):
def eventGetTarget(evt):
JS("""
- var elem = @{{evt}}.srcElement;
+ var elem = @{{evt}}['srcElement'];
return elem ? elem : null;
""")
def eventGetToElement(evt):
JS("""
- return @{{evt}}.toElement ? @{{evt}}.toElement : null;
+ return @{{evt}}['toElement'] ? @{{evt}}['toElement'] : null;
""")
def eventPreventDefault(evt):
JS("""
- @{{evt}}.returnValue = false;
+ @{{evt}}['returnValue'] = false;
""")
def eventToString(evt):
JS("""
- if (@{{evt}}.toString) return @{{evt}}.toString();
+ if (@{{evt}}['toString']) return @{{evt}}['toString']();
return "[object Event]";
""")
def getBodyOffsetTop():
JS("""
- return $doc.body.parentElement.clientTop;
+ return $doc['body']['parentElement']['clientTop'];
""")
def getBodyOffsetLeft():
JS("""
- return $doc.body.parentElement.clientLeft;
+ return $doc['body']['parentElement']['clientLeft'];
""")
def getAbsoluteLeft(elem):
JS("""
// getBoundingClientRect() throws a JS exception if the elem is not attached
// to the document, so we wrap it in a try/catch block
- var zoomMultiple = $doc.body.parentElement.offsetWidth /
- $doc.body.offsetWidth;
+ var zoomMultiple = $doc['body']['parentElement']['offsetWidth'] /
+ $doc['body']['offsetWidth'];
try {
- return Math.floor((@{{elem}}.getBoundingClientRect().left / zoomMultiple) +
- $doc.body.parentElement.scrollLeft );
+ return Math['floor']((@{{elem}}['getBoundingClientRect']()['left'] / zoomMultiple) +
+ $doc['body']['parentElement']['scrollLeft'] );
} catch (e) {
return 0;
}
@@ -121,12 +121,12 @@ def getAbsoluteTop(elem):
JS("""
// getBoundingClientRect() throws a JS exception if the elem is not attached
// to the document, so we wrap it in a try/catch block
- var zoomMultiple = $doc.body.parentElement.offsetWidth /
- $doc.body.offsetWidth;
+ var zoomMultiple = $doc['body']['parentElement']['offsetWidth'] /
+ $doc['body']['offsetWidth'];
try {
- var scrollTop = $doc.parent ? $doc.parent.body.scrollTop : 0;
- scrollTop += $doc.body.scrollTop;
- return Math.floor((@{{elem}}.getBoundingClientRect().top / zoomMultiple) +
+ var scrollTop = $doc['parent'] ? $doc['parent']['body']['scrollTop'] : 0;
+ scrollTop += $doc['body']['scrollTop'];
+ return Math['floor']((@{{elem}}['getBoundingClientRect']()['top'] / zoomMultiple) +
scrollTop);
} catch (e) {
return 0;
@@ -136,107 +136,107 @@ def getAbsoluteTop(elem):
def getChild(elem, index):
JS("""
- var child = @{{elem}}.children[@{{index}}];
+ var child = @{{elem}}['children'][@{{index}}];
return child ? child : null;
""")
def getChildCount(elem):
JS("""
- return @{{elem}}.children.length;
+ return @{{elem}}['children']['length'];
""")
def getChildIndex(parent, child):
JS("""
- var count = @{{parent}}.children.length;
+ var count = @{{parent}}['children']['length'];
for (var i = 0; i < count; ++i) {
- if (@{{child}}.uniqueID == @{{parent}}.children[i].uniqueID)
+ if (@{{child}}['uniqueID'] == @{{parent}}['children'][i]['uniqueID'])
return i;
}
return -1;
""")
def getFirstChild(elem):
JS("""
- var child = @{{elem}}.firstChild;
+ var child = @{{elem}}['firstChild'];
return child ? child : null;
""")
def getInnerText(elem):
JS("""
- var ret = @{{elem}}.innerText;
+ var ret = @{{elem}}['innerText'];
return (ret == null) ? null : ret;
""")
def getNextSibling(elem):
JS("""
- var sib = @{{elem}}.nextSibling;
+ var sib = @{{elem}}['nextSibling'];
return sib ? sib : null;
""")
def getParent(elem):
JS("""
- var parent = @{{elem}}.parentElement;
+ var parent = @{{elem}}['parentElement'];
return parent ? parent : null;
""")
def insertChild(parent, child, index):
JS("""
- if (@{{index}} == @{{parent}}.children.length)
- @{{parent}}.appendChild(@{{child}});
+ if (@{{index}} == @{{parent}}['children']['length'])
+ @{{parent}}['appendChild'](@{{child}});
else
- @{{parent}}.insertBefore(@{{child}}, @{{parent}}.children[@{{index}}]);
+ @{{parent}}['insertBefore'](@{{child}}, @{{parent}}['children'][@{{index}}]);
""")
def insertListItem(select, text, value, index):
JS("""
- var newOption = document.createElement("Option");
+ var newOption = document['createElement']("Option");
if(@{{index}}==-1) {
- @{{select}}.add(newOption);
+ @{{select}}['add'](newOption);
} else {
- @{{select}}.add(newOption,@{{index}});
+ @{{select}}['add'](newOption,@{{index}});
}
- newOption.text=@{{text}};
- newOption.value=@{{value}};
+ newOption['text']=@{{text}};
+ newOption['value']=@{{value}};
""")
def isOrHasChild(parent, _child):
JS("""
var child = @{{_child}};
while (child) {
- if (@{{parent}}.uniqueID == child.uniqueID)
+ if (@{{parent}}['uniqueID'] == child['uniqueID'])
return true;
- child = child.parentElement;
+ child = child['parentElement'];
}
return false;
""")
def releaseCapture_impl(elem):
JS("""
- @{{elem}}.releaseCapture();
+ @{{elem}}['releaseCapture']();
""")
def setCapture_impl(elem):
JS("""
- @{{elem}}.setCapture();
+ @{{elem}}['setCapture']();
""")
def setInnerText(elem, text):
JS("""
if (!@{{text}})
- @{{elem}}.innerText = '';
+ @{{elem}}['innerText'] = '';
else
- @{{elem}}.innerText = @{{text}};
+ @{{elem}}['innerText'] = @{{text}};
""")
def toString(elem):
JS("""
- return @{{elem}}.outerHTML;
+ return @{{elem}}['outerHTML'];
""")
def eventStopPropagation(evt):
eventCancelBubble(evt,True)
def eventGetMouseWheelVelocityY(evt):
JS("""
- return Math.round(-@{{evt}}.wheelDelta / 40) || 0;
+ return Math['round'](-@{{evt}}['wheelDelta'] / 40) || 0;
""")
View
96 library/pyjamas/DOM.mozilla.py
@@ -1,11 +1,11 @@
def buttonClick(button):
JS("""
- var doc = @{{button}}.ownerDocument;
+ var doc = @{{button}}['ownerDocument'];
if (doc != null) {
- var evt = doc.createEvent('MouseEvents');
- evt.initMouseEvent('click', true, true, null, 0, 0,
+ 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);
+ @{{button}}['dispatchEvent'](evt);
}
""")
@@ -16,10 +16,10 @@ def compare(elem1, elem2):
} else if (!@{{elem1}} || !@{{elem2}}) {
return false;
}
- if (!@{{elem1}}.isSameNode) {
+ if (!@{{elem1}}['isSameNode']) {
return (@{{elem1}} == @{{elem2}});
}
- return (@{{elem1}}.isSameNode(@{{elem2}}));
+ return (@{{elem1}}['isSameNode'](@{{elem2}}));
""")
def eventGetType(event):
@@ -30,7 +30,7 @@ def eventGetType(event):
def eventGetButton(evt):
JS("""
- var button = @{{evt}}.which;
+ var button = @{{evt}}['which'];
if(button == 2) {
return 4;
} else if (button == 3) {
@@ -65,26 +65,26 @@ def eventGetButton(evt):
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
+ // 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);
+ if ( typeof @{{elem}}['getBoundingClientRect'] == 'function' ) {
+ var left = Math['ceil'](@{{elem}}['getBoundingClientRect']()['left']);
- return left + $doc.body.scrollLeft + $doc.documentElement.scrollLeft;
+ return left + $doc['body']['scrollLeft'] + $doc['documentElement']['scrollLeft'];
}
// Older Firefox can use getBoxObjectFor
else {
- var left = $doc.getBoxObjectFor(@{{elem}}).x;
- var parent = @{{elem}}.parentNode;
+ var left = $doc['getBoxObjectFor'](@{{elem}})['x'];
+ var parent = @{{elem}}['parentNode'];
while (parent) {
- if (parent.scrollLeft > 0) {
- left = left - parent.scrollLeft;
+ if (parent['scrollLeft'] > 0) {
+ left = left - parent['scrollLeft'];
}
- parent = parent.parentNode;
+ parent = parent['parentNode'];
}
- return left + $doc.body.scrollLeft + $doc.documentElement.scrollLeft;
+ return left + $doc['body']['scrollLeft'] + $doc['documentElement']['scrollLeft'];
}
""")
@@ -113,41 +113,41 @@ def getAbsoluteLeft(elem):
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;
+ 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;
+ var top = $doc['getBoxObjectFor'](@{{elem}})['y'];
+ var parent = @{{elem}}['parentNode'];
while (parent) {
- if (parent.scrollTop > 0) {
- top -= parent.scrollTop;
+ if (parent['scrollTop'] > 0) {
+ top -= parent['scrollTop'];
}
- parent = parent.parentNode;
+ parent = parent['parentNode'];
}
- return top + $doc.body.scrollTop + $doc.documentElement.scrollTop;
+ return top + $doc['body']['scrollTop'] + $doc['documentElement']['scrollTop'];
}
""")
def getChildIndex(parent, child):
JS("""
- var count = 0, current = @{{parent}}.firstChild;
+ var count = 0, current = @{{parent}}['firstChild'];
while (current) {
- if (! current.isSameNode) {
+ if (! current['isSameNode']) {
if (current == @{{child}}) {
return count;
}
}
- else if (current.isSameNode(@{{child}})) {
+ else if (current['isSameNode'](@{{child}})) {
return count;
}
- if (current.nodeType == 1) {
+ if (current['nodeType'] == 1) {
++count;
}
- current = current.nextSibling;
+ current = current['nextSibling'];
}
return -1;
""")
@@ -156,23 +156,23 @@ def isOrHasChild(parent, _child):
JS("""
var child = @{{_child}};
while (child) {
- if ((!@{{parent}}.isSameNode)) {
+ if ((!@{{parent}}['isSameNode'])) {
if (@{{parent}} == child) {
return true;
}
}
- else if (@{{parent}}.isSameNode(child)) {
+ else if (@{{parent}}['isSameNode'](child)) {
return true;
}
try {
- child = child.parentNode;
+ 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
+ // HTMLDivElement['parentNode']'
+ // See https://bugzilla['mozilla']['org']/show_bug['cgi']?id=208427
return false;
}
- if (child && (child.nodeType != 1)) {
+ if (child && (child['nodeType'] != 1)) {
child = null;
}
}
@@ -184,35 +184,35 @@ def releaseCapture(elem):
if ((@{{sCaptureElem}} != null) && @{{compare}}(@{{elem}}, @{{sCaptureElem}}))
@{{sCaptureElem}} = null;
- if (!@{{elem}}.isSameNode) {
- if (@{{elem}} == $wnd.__captureElem) {
- $wnd.__captureElem = null;
+ if (!@{{elem}}['isSameNode']) {
+ if (@{{elem}} == $wnd['__captureElem']) {
+ $wnd['__captureElem'] = null;
}
}
- else if (@{{elem}}.isSameNode($wnd.__captureElem)) {
- $wnd.__captureElem = null;
+ else if (@{{elem}}['isSameNode']($wnd['__captureElem'])) {
+ $wnd['__captureElem'] = null;
}
""")
def eventGetMouseWheelVelocityY(evt):
JS("""
- return @{{evt}}.detail || 0;
+ return @{{evt}}['detail'] || 0;
""")
def sinkEventsMozilla(element, bits):
JS("""
if (@{{bits}} & 0x40000) {
- @{{element}}.addEventListener("DOMMouseScroll", $wnd.__dispatchEvent,
+ @{{element}}['addEventListener']("DOMMouseScroll", $wnd['__dispatchEvent'],
false);
} else {
- @{{element}}.removeEventListener("DOMMouseScroll", $wnd.__dispatchEvent,
+ @{{element}}['removeEventListener']("DOMMouseScroll", $wnd['__dispatchEvent'],
false);
}
if (@{{bits}} & 0x80000) {
- @{{element}}.addEventListener("input", $wnd.__dispatchEvent,
+ @{{element}}['addEventListener']("input", $wnd['__dispatchEvent'],
false);
} else {
- @{{element}}.removeEventListener("input", $wnd.__dispatchEvent,
+ @{{element}}['removeEventListener']("input", $wnd['__dispatchEvent'],
false);
}
""")
View
62 library/pyjamas/DOM.oldmoz.py
@@ -5,15 +5,15 @@ def compare(elem1, elem2):
} else if (!@{{elem1}} || !@{{elem2}}) {
return false;
}
- if (!@{{elem1}}.isSameNode) {
+ if (!@{{elem1}}['isSameNode']) {
return (@{{elem1}} == @{{elem2}});
}
- return (@{{elem1}}.isSameNode(@{{elem2}}));
+ return (@{{elem1}}['isSameNode'](@{{elem2}}));
""")
def eventGetButton(evt):
JS("""
- var button = @{{evt}}.button;
+ var button = @{{evt}}['button'];
if(button == 0) {
return 1;
} else if (button == 1) {
@@ -30,17 +30,17 @@ def getAbsoluteLeft(_elem):
var parent = elem;
while (parent) {
- if (parent.scrollLeft > 0) {
- left = left - parent.scrollLeft;
+ if (parent['scrollLeft'] > 0) {
+ left = left - parent['scrollLeft'];
}
- parent = parent.parentNode;
+ parent = parent['parentNode'];
}
while (elem) {
- left = left + elem.offsetLeft;
- elem = elem.offsetParent;
+ left = left + elem['offsetLeft'];
+ elem = elem['offsetParent'];
}
- return left + $doc.body.scrollLeft + $doc.documentElement.scrollLeft;
+ return left + $doc['body']['scrollLeft'] + $doc['documentElement']['scrollLeft'];
""")
def getAbsoluteTop(_elem):
@@ -49,35 +49,35 @@ def getAbsoluteTop(_elem):
var elem = @{{_elem}};
var parent = elem;
while (parent) {
- if (parent.scrollTop > 0) {
- top -= parent.scrollTop;
+ if (parent['scrollTop'] > 0) {
+ top -= parent['scrollTop'];
}
- parent = parent.parentNode;
+ parent = parent['parentNode'];
}
while (elem) {
- top += elem.offsetTop;
- elem = elem.offsetParent;
+ top += elem['offsetTop'];
+ elem = elem['offsetParent'];
}
- return top + $doc.body.scrollTop + $doc.documentElement.scrollTop;
+ return top + $doc['body']['scrollTop'] + $doc['documentElement']['scrollTop'];
""")
def getChildIndex(parent, child):
JS("""
- var count = 0, current = @{{parent}}.firstChild;
+ var count = 0, current = @{{parent}}['firstChild'];
while (current) {
- if (! current.isSameNode) {
+ if (! current['isSameNode']) {
if (current == @{{child}}) {
return count;
}
}
- else if (current.isSameNode(@{{child}})) {
+ else if (current['isSameNode'](@{{child}})) {
return count;
}
- if (current.nodeType == 1) {
+ if (current['nodeType'] == 1) {
++count;
}
- current = current.nextSibling;
+ current = current['nextSibling'];
}
return -1;
""")
@@ -86,23 +86,23 @@ def isOrHasChild(parent, _child):
JS("""
var child = @{{_child}};
while (child) {
- if ((!@{{parent}}.isSameNode)) {
+ if ((!@{{parent}}['isSameNode'])) {
if (@{{parent}} == child) {
return true;
}
}
- else if (@{{parent}}.isSameNode(child)) {
+ else if (@{{parent}}['isSameNode'](child)) {
return true;
}
try {
- child = child.parentNode;
+ 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
+ // HTMLDivElement['parentNode']'
+ // See https://bugzilla['mozilla']['org']/show_bug['cgi']?id=208427
return false;
}
- if (child && (child.nodeType != 1)) {
+ if (child && (child['nodeType'] != 1)) {
child = null;
}
}
@@ -114,12 +114,12 @@ def releaseCapture(elem):
if ((@{{sCaptureElem}} != null) && @{{compare}}(@{{elem}}, @{{sCaptureElem}}))
@{{sCaptureElem}} = null;
- if (!@{{elem}}.isSameNode) {
- if (@{{elem}} == $wnd.__captureElem) {
- $wnd.__captureElem = null;
+ if (!@{{elem}}['isSameNode']) {
+ if (@{{elem}} == $wnd['__captureElem']) {
+ $wnd['__captureElem'] = null;
}
}
- else if (@{{elem}}.isSameNode($wnd.__captureElem)) {
- $wnd.__captureElem = null;
+ else if (@{{elem}}['isSameNode']($wnd['__captureElem'])) {
+ $wnd['__captureElem'] = null;
}
""")
View
34 library/pyjamas/DOM.opera.py
@@ -1,6 +1,6 @@
def eventGetButton(evt):
JS("""
- var button = @{{evt}}.button;
+ var button = @{{evt}}['button'];
if(button == 0){
return 1;
} else {
@@ -11,22 +11,22 @@ def getAbsoluteLeft(_elem):
JS("""
var left = 0;
var elem = @{{_elem}};
- var curr = elem.parentNode;
+ var curr = elem['parentNode'];
// This intentionally excludes body
- while (curr && curr != $doc.body) {
+ while (curr && curr != $doc['body']) {
- // see https://bugs.opera.com/show_bug.cgi?id=249965
+ // see https://bugs['opera']['com']/show_bug['cgi']?id=249965
// The net effect is that TR and TBODY elemnts report the scroll offsets
// of the BODY and HTML elements instead of 0.
- if (curr.tagName != 'TR' && curr.tagName != 'TBODY') {
- left -= curr.scrollLeft;
+ if (curr['tagName'] != 'TR' && curr['tagName'] != 'TBODY') {
+ left -= curr['scrollLeft'];
}
- curr = curr.parentNode;
+ curr = curr['parentNode'];
}
while (elem) {
- left += elem.offsetLeft;
- elem = elem.offsetParent;
+ left += elem['offsetLeft'];
+ elem = elem['offsetParent'];
}
return left;
""")
@@ -37,24 +37,24 @@ def getAbsoluteTop(_elem):
var elem = @{{_elem}};
// This intentionally excludes body
- var curr = elem.parentNode;
- while (curr && curr != $doc.body) {
+ var curr = elem['parentNode'];
+ while (curr && curr != $doc['body']) {
// see getAbsoluteLeft()
- if (curr.tagName != 'TR' && curr.tagName != 'TBODY') {
- top -= curr.scrollTop;
+ if (curr['tagName'] != 'TR' && curr['tagName'] != 'TBODY') {
+ top -= curr['scrollTop'];
}
- curr = curr.parentNode;
+ curr = curr['parentNode'];
}
while (elem) {
- top += elem.offsetTop;
- elem = elem.offsetParent;
+ top += elem['offsetTop'];
+ elem = elem['offsetParent'];
}
return top;
""")
def eventGetMouseWheelVelocityY(evt):
JS("""
- return @{{evt}}.detail * 4 || 0;
+ return @{{evt}}['detail'] * 4 || 0;
""")
View
56 library/pyjamas/DOM.safari.py
@@ -4,11 +4,11 @@ def toString(elem):
# html. just leave it out so far, don't know what this should do
# anyways
JS("""
- var temp = @{{elem}}.cloneNode(true);
- var tempDiv = $doc.createElement("DIV");
- tempDiv.appendChild(temp);
- var outer = tempDiv.innerHTML;
- //temp.innerHTML = " ";
+ var temp = @{{elem}}['cloneNode'](true);
+ var tempDiv = $doc['createElement']("DIV");
+ tempDiv['appendChild'](temp);
+ var outer = tempDiv['innerHTML'];
+ //temp['innerHTML'] = " ";
return outer;
""")
@@ -17,28 +17,28 @@ def getAbsoluteLeft(_elem):
// Unattached elements and elements (or their ancestors) with style
// 'display: none' have no offsetLeft.
var elem = @{{_elem}};
- if (elem.offsetLeft == null) {
+ if (elem['offsetLeft'] == null) {
return 0;
}
var left = 0;
- var curr = elem.parentNode;
+ var curr = elem['parentNode'];
if (curr) {
// This intentionally excludes body which has a null offsetParent.
- while (curr.offsetParent) {
- left -= curr.scrollLeft;
- curr = curr.parentNode;
+ while (curr['offsetParent']) {
+ left -= curr['scrollLeft'];
+ curr = curr['parentNode'];
}
}
while (elem) {
- left += elem.offsetLeft;
+ left += elem['offsetLeft'];
// Safari bug: a top-level absolutely positioned element includes the
// body's offset position already.
- var parent = elem.offsetParent;
- if (parent && (parent.tagName == 'BODY') &&
- (elem.style.position == 'absolute')) {
+ var parent = elem['offsetParent'];
+ if (parent && (parent['tagName'] == 'BODY') &&
+ (elem['style']['position'] == 'absolute')) {
break;
}
@@ -52,28 +52,28 @@ def getAbsoluteTop(_elem):
// Unattached elements and elements (or their ancestors) with style
// 'display: none' have no offsetTop.
var elem = @{{_elem}};
- if (elem.offsetTop == null) {
+ if (elem['offsetTop'] == null) {
return 0;
}
var top = 0;
- var curr = elem.parentNode;
+ var curr = elem['parentNode'];
if (curr) {
// This intentionally excludes body which has a null offsetParent.
- while (curr.offsetParent) {
- top -= curr.scrollTop;
- curr = curr.parentNode;
+ while (curr['offsetParent']) {
+ top -= curr['scrollTop'];
+ curr = curr['parentNode'];
}
}
while (elem) {
- top += elem.offsetTop;
+ top += elem['offsetTop'];
// Safari bug: a top-level absolutely positioned element includes the
// body's offset position already.
- var parent = elem.offsetParent;
- if (parent && (parent.tagName == 'BODY') &&
- (elem.style.position == 'absolute')) {
+ var parent = elem['offsetParent'];
+ if (parent && (parent['tagName'] == 'BODY') &&
+ (elem['style']['position'] == 'absolute')) {
break;
}
@@ -84,7 +84,7 @@ def getAbsoluteTop(_elem):
def eventGetButton(evt):
JS("""
- var button = @{{evt}}.which;
+ var button = @{{evt}}['which'];
if(button == 2) {
return 4;
} else if (button == 3) {
@@ -96,16 +96,16 @@ def eventGetButton(evt):
def buttonClick(elem):
JS("""
- var evt = $doc.createEvent('MouseEvents');
- evt.initMouseEvent('click', true, true, null, 1, 0,
+ var evt = $doc['createEvent']('MouseEvents');
+ evt['initMouseEvent']('click', true, true, null, 1, 0,
0, 0, 0, false, false, false, false, 0, null);
- @{{elem}}.dispatchEvent(evt);
+ @{{elem}}['dispatchEvent'](evt);
""")
def eventGetMouseWheelVelocityY(evt):
JS("""
- return Math.round(-@{{evt}}.wheelDelta / 40) || 0;
+ return Math['round'](-@{{evt}}['wheelDelta'] / 40) || 0;
""")
View
6 library/pyjamas/HTTPRequest.browser.py
@@ -2,7 +2,7 @@
class HTTPRequest(object):
def doCreateXmlHTTPRequest(self):
- if JS("""typeof $wnd.XMLHttpRequest != 'undefined'"""):
+ if JS("""typeof $wnd['XMLHttpRequest'] != 'undefined'"""):
# IE7+, Mozilla, Safari, ...
res = JS("""new XMLHttpRequest()""")
return res
@@ -29,7 +29,7 @@ def onreadystatechange(evnt=None):
global xmlHttp, handler
if xmlHttp.readyState == 4:
# For IE:
- JS("delete @{{xmlHttp}}.onreadystatechange;")
+ JS("delete @{{xmlHttp}}['onreadystatechange'];")
localHandler = handler
status = xmlHttp.status
if returnxml:
@@ -62,7 +62,7 @@ def onprogress(evnt=None):
xmlHttp.send(postData)
except:
# For IE:
- JS("delete @{{xmlHttp}}.onreadystatechange;")
+ JS("delete @{{xmlHttp}}['onreadystatechange'];")
localHandler = handler
handler = None
xmlHttp = None
View
2 library/pyjamas/HTTPRequest.ie6.py
@@ -1,5 +1,5 @@
class HTTPRequest(object):
def doCreateXmlHTTPRequest(self):
- return JS("""new ActiveXObject("Msxml2.XMLHTTP")""")
+ return JS("""new ActiveXObject("Msxml2['XMLHTTP']")""")
View
34 library/pyjamas/History.browser.py
@@ -25,31 +25,31 @@
def init():
JS("""
- $wnd.__historyToken = '';
+ $wnd['__historyToken'] = '';
// Get the initial token from the url's hash component.
- var hash = $wnd.location.hash;
- if (hash.length > 0)
- $wnd.__historyToken = decodeURI(hash.substring(1)).replace('%23','#');
+ var hash = $wnd['location']['hash'];
+ if (hash['length'] > 0)
+ $wnd['__historyToken'] = decodeURI(hash['substring'](1))['replace']('%23','#');
// Create the timer that checks the browser's url hash every 1/4 s.
- $wnd.__checkHistory = function() {
- var token = '', hash = $wnd.location.hash;
- if (hash.length > 0)
- token = decodeURI(hash.substring(1)).replace('%23','#');
+ $wnd['__checkHistory'] = function() {
+ var token = '', hash = $wnd['location']['hash'];
+ if (hash['length'] > 0)
+ token = decodeURI(hash['substring'](1))['replace']('%23','#');
- if (token != $wnd.__historyToken) {
- $wnd.__historyToken = token;