Skip to content
Browse files

Fixes to get ie7 working (hopefully ie6 as well)

  • Loading branch information...
1 parent 02d9e4e commit 46d31aea8ef68bb462ae5f3989b40aaa856b1b13 @pyronicide committed Jan 19, 2011
Showing with 23 additions and 16 deletions.
  1. +20 −14 lib/janky.post.js
  2. +3 −2 python/janky_post/gae.py
View
34 lib/janky.post.js
@@ -23,16 +23,22 @@
opts.data = extend({}, opts.data, {
_origin: location.href
});
- janky._input(form, opts.data);
- iframe.onload = iframe.onreadystatechange = function() {
- // This is for IE (only IE implements readyState)
- if (typeof(iframe.readyState) != 'undefined' &&
- iframe.readyState != 'complete') return
+ janky._input(iframe, form, opts.data);
+ var _response = function(resp) {
+ window.detachEvent && window.detachEvent('onmessage', _response);
+ window.removeEventListener && window.removeEventListener('message',
+ _response);
setTimeout(function() { document.body.removeChild(iframe) }, 1);
- if (!iframe.contentDocument.location.href)
- return opts.error && opts.error();
- var resp = iframe.contentWindow.name;
- opts.success && opts.success(JSON.parse(resp));
+ opts.success && opts.success(JSON.parse(resp.data));
+ };
+ window.attachEvent && window.attachEvent('onmessage', _response);
+ window.addEventListener && window.addEventListener(
+ "message", _response, false);
+ // IE<8 must use window.name
+ iframe.onreadystatechange = function() {
+ if (typeof(window.postMessage) != 'undefined' ||
+ iframe.readyState != 'complete') return
+ _response({ data: iframe.contentWindow.name });
};
form.submit();
});
@@ -42,10 +48,10 @@
var iframe = document.createElement("iframe");
document.body.appendChild(iframe);
iframe.style.display = "none";
- var form = document.createElement("form");
- // This is because IE creates the document only after yielding
+ // IE creates the document only after yielding
setTimeout(function() {
- iframe.contentDocument.body.appendChild(form);
+ var form = iframe.contentWindow.document.createElement("form");
+ iframe.contentWindow.document.body.appendChild(form);
cb(iframe, form);
}, 0);
};
@@ -55,12 +61,12 @@
this.janky.is_string = function(obj) {
return !!(obj === '' || (obj && obj.charCodeAt && obj.substr))
};
- this.janky._input = function(form, data) {
+ this.janky._input = function(iframe, form, data) {
for (var k in data) {
var val = data[k];
if (!janky.is_string(val))
val = JSON.stringify(val);
- var inp = document.createElement("input");
+ var inp = iframe.contentWindow.document.createElement("input");
inp.setAttribute("type", "hidden");
inp.setAttribute("name", k);
inp.value = val;
View
5 python/janky_post/gae.py
@@ -35,7 +35,8 @@ class JankyMiddleware(object):
tmpl = """<html><head></head><body>
<script type="text/javascript">
window.name = %(resp)s;
- location.href = %(origin)s;
+ window.parent.postMessage ? window.parent.postMessage(%(resp)s, "*") :
+ location.href = %(origin)s;
</script>
</body></html>
"""
@@ -54,7 +55,7 @@ def my_write(body):
'resp': json.dumps(body),
'origin': json.dumps(urlparse.urljoin(
webapp.Request(environ).get('_origin'),
- '/janky'))
+ '/janky.html'))
}
write(body)
return my_write

0 comments on commit 46d31ae

Please sign in to comment.
Something went wrong with that request. Please try again.