| 1 |
define([ |
| 2 |
"dojo/Evented", |
| 3 |
"dojo/on", |
| 4 |
"dojo/domReady", |
| 5 |
"dojo/sniff", |
| 6 |
"dojo/window" |
| 7 |
], function(Evented, on, domReady, has, winUtils){ |
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
var Viewport = new Evented(); |
| 26 |
|
| 27 |
var focusedNode; |
| 28 |
|
| 29 |
domReady(function(){ |
| 30 |
var oldBox = winUtils.getBox(); |
| 31 |
Viewport._rlh = on(window, "resize", function(){ |
| 32 |
var newBox = winUtils.getBox(); |
| 33 |
if(oldBox.h == newBox.h && oldBox.w == newBox.w){ return; } |
| 34 |
oldBox = newBox; |
| 35 |
Viewport.emit("resize"); |
| 36 |
}); |
| 37 |
|
| 38 |
|
| 39 |
if(has("ie") == 8){ |
| 40 |
var deviceXDPI = screen.deviceXDPI; |
| 41 |
setInterval(function(){ |
| 42 |
if(screen.deviceXDPI != deviceXDPI){ |
| 43 |
deviceXDPI = screen.deviceXDPI; |
| 44 |
Viewport.emit("resize"); |
| 45 |
} |
| 46 |
}, 500); |
| 47 |
} |
| 48 |
|
| 49 |
|
| 50 |
if(has("ios")){ |
| 51 |
on(document, "focusin", function(evt){ |
| 52 |
focusedNode = evt.target; |
| 53 |
}); |
| 54 |
on(document, "focusout", function(evt){ |
| 55 |
focusedNode = null; |
| 56 |
}); |
| 57 |
} |
| 58 |
}); |
| 59 |
|
| 60 |
Viewport.getEffectiveBox = function( doc){ |
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
var box = winUtils.getBox(doc); |
| 66 |
|
| 67 |
|
| 68 |
var tag = focusedNode && focusedNode.tagName && focusedNode.tagName.toLowerCase(); |
| 69 |
if(has("ios") && focusedNode && !focusedNode.readOnly && (tag == "textarea" || (tag == "input" && |
| 70 |
/^(color|email|number|password|search|tel|text|url)$/.test(focusedNode.type)))){ |
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
box.h *= (orientation == 0 || orientation == 180 ? 0.66 : 0.40); |
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
var rect = focusedNode.getBoundingClientRect(); |
| 80 |
box.h = Math.max(box.h, rect.top + rect.height); |
| 81 |
} |
| 82 |
|
| 83 |
return box; |
| 84 |
}; |
| 85 |
|
| 86 |
return Viewport; |
| 87 |
}); |