0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-06 22:40:14 -05:00
ghost/core/client/utils/mobile-utils.js
Matt Enlow 77941275ed Fix mobile sidebar menu
Closes #3110
- Created `ApplicationView`
- Added `js-close-sidebar` classes to navbar navigation links
- Clicking on a navigation link in the sidebar will close it
2014-07-07 08:55:22 -06:00

48 lines
1.3 KiB
JavaScript

/*global DocumentTouch,FastClick*/
var hasTouchScreen,
smallScreen,
initFastClick,
responsiveAction;
// Taken from "Responsive design & the Guardian" with thanks to Matt Andrews
// Added !window._phantom so that the functional tests run as though this is not a touch screen.
// In future we can do something more advanced here for testing both touch and non touch
hasTouchScreen = function () {
return !window._phantom &&
(
('ontouchstart' in window) ||
(window.DocumentTouch && document instanceof DocumentTouch)
);
};
smallScreen = function () {
if (window.matchMedia('(max-width: 1000px)').matches) {
return true;
}
return false;
};
initFastClick = function () {
Ember.run.scheduleOnce('afterRender', null, function () {
FastClick.attach(document.body);
});
};
responsiveAction = function responsiveAction(event, mediaCondition, cb) {
if (!window.matchMedia(mediaCondition).matches) {
return;
}
event.preventDefault();
event.stopPropagation();
cb();
};
export { hasTouchScreen, smallScreen, responsiveAction };
export default {
hasTouchScreen: hasTouchScreen,
smallScreen: smallScreen,
initFastClick: initFastClick,
responsiveAction: responsiveAction
};