Skip to content

Instantly share code, notes, and snippets.

@shama
Created February 2, 2012 00:01
Show Gist options
  • Save shama/1720264 to your computer and use it in GitHub Desktop.
Save shama/1720264 to your computer and use it in GitHub Desktop.
jmpress.js zoom in and out with + or -
/**
* Viewport Key Zoom In & Out
* Press + and - to zoom the viewport in and out.
*/
(function() {
'use strict';
$.jmpress("defaults").viewPort.keyZoomAmount = 100;
$.extend(true, $.jmpress('defaults').keyboard.keys, {
187: 'zoomin' // plus
,189: 'zoomout' // minus
});
$.jmpress("register", "zoomin", function() {
var settings = $(this).jmpress('settings');
if ( settings.viewPort.width ) {
settings.viewPort.width += settings.viewPort.keyZoomAmount;
}
if ( settings.viewPort.height ) {
settings.viewPort.height += settings.viewPort.keyZoomAmount;
}
$(this).jmpress("select", $(this).jmpress("active"), "resize");
});
$.jmpress("register", "zoomout", function() {
var settings = $(this).jmpress('settings');
if ( settings.viewPort.width ) {
settings.viewPort.width -= settings.viewPort.keyZoomAmount;
}
if ( settings.viewPort.height ) {
settings.viewPort.height -= settings.viewPort.keyZoomAmount;
}
$(this).jmpress("select", $(this).jmpress("active"), "resize");
});
})();
@sokra
Copy link

sokra commented Feb 2, 2012

check if the viewPort values are set. if not do not use 0. do not set them at all. leave them undefined.

@sokra
Copy link

sokra commented Feb 2, 2012

if(settings.viewPort.width)
  settings.viewPort.width = ...;
if(settings.viewPort.height)
  settings.viewPort.height = ...;

settings.viewPort is ever set.
width and heigt may be false, which means window scale should not be considered in this dimension. It must stay false even when zooming

@shama
Copy link
Author

shama commented Feb 2, 2012

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment