mirror of
https://github.com/Esri/offline-editor-js.git
synced 2025-12-15 15:20:05 +00:00
39 lines
1.4 KiB
JavaScript
39 lines
1.4 KiB
JavaScript
define([],function(){
|
|
return {
|
|
|
|
/**
|
|
* Activates the orientation listener and listens for native events.
|
|
* Handle orientation events to allow for resizing the map and working around
|
|
* jQuery mobile bugs related to how and when the view settles after such an event
|
|
*/
|
|
setOrientationListener: function(callback){
|
|
var supportsOrientationChange = "onorientationchange" in window,
|
|
orientationEvent = supportsOrientationChange ? "orientationchange" : "resize";
|
|
|
|
window.addEventListener(orientationEvent, this.debounceMap(function(){
|
|
callback();
|
|
},this.DEBOUNCE_DELAY).bind(this), false);
|
|
},
|
|
|
|
/**
|
|
* Minimize the number of times window readjustment fires a function
|
|
* http://davidwalsh.name/javascript-debounce-function
|
|
* @param func
|
|
* @param wait
|
|
* @param immediate
|
|
* @returns {Function}
|
|
*/
|
|
debounceMap: function (func, wait, immediate) {
|
|
var timeout;
|
|
return function() {
|
|
var context = this, args = arguments;
|
|
clearTimeout(timeout);
|
|
timeout = setTimeout(function() {
|
|
timeout = null;
|
|
if (!immediate) func.apply(context, args);
|
|
}, wait);
|
|
if (immediate && !timeout) func.apply(context, args);
|
|
};
|
|
}
|
|
}
|
|
}) |