[Mobile] Merge

Fix Conflicts.
This commit is contained in:
Shivam Dave
2015-07-27 15:21:59 -07:00
40 changed files with 1561 additions and 141 deletions

View File

@@ -24,6 +24,7 @@
"implementation": "gestures/InfoGesture.js",
"depends": [
"$timeout",
"queryService",
"infoService",
"INFO_HOVER_DELAY"
]

View File

@@ -38,17 +38,26 @@ define(
* @param {DomainObject} domainObject the domain object for which to
* show information
*/
function InfoGesture($timeout, infoService, DELAY, element, domainObject) {
function InfoGesture($timeout, queryService, infoService, DELAY, element, domainObject) {
var dismissBubble,
pendingBubble,
mousePosition,
scopeOff;
touchPosition,
scopeOff,
touchDELAY = 500;
function trackPosition(event) {
// Record mouse position, so bubble can be shown at latest
// mouse position (not just where the mouse entered)
mousePosition = [ event.clientX, event.clientY ];
}
function trackTouchPosition(event) {
var tEvent = event.changedTouches[0];
// Record mouse position, so bubble can be shown at latest
// mouse position (not just where the mouse entered)
touchPosition = [ tEvent.clientX + 44, tEvent.clientY ];
}
function hideBubble() {
// If a bubble is showing, dismiss it
@@ -67,11 +76,12 @@ define(
// Also clear mouse position so we don't have a ton of tiny
// arrays allocated while user mouses over things
mousePosition = undefined;
touchPosition = undefined;
}
function showBubble(event) {
trackPosition(event);
// Also need to track position during hover
element.on('mousemove', trackPosition);
@@ -85,14 +95,39 @@ define(
mousePosition
);
element.off('mousemove', trackPosition);
pendingBubble = undefined;
}, DELAY);
element.on('mouseleave', hideBubble);
}
function showTouchBubble(event) {
// Makes sure user is only touching one place
if (event.touches.length < 2) {
trackTouchPosition(event);
pendingBubble = $timeout(function () {
dismissBubble = infoService.display(
"info-table",
domainObject.getModel().name,
domainObject.useCapability('metadata'),
touchPosition
);
}, touchDELAY);
// Show bubble (on a timeout) on mouse over
element.on('mouseenter', showBubble);
element.on('touchend', hideBubble);
}
}
// Checks if you are on a mobile device, if the device is
// not mobile (queryService.isMobile() = false), then
// the pendingBubble and therefore hovering is allowed
if (!queryService.isMobile(navigator.userAgent)) {
// Show bubble (on a timeout) on mouse over
element.on('mouseenter', showBubble);
} else if (queryService.isMobile(navigator.userAgent)) {
element.on('touchstart', showTouchBubble);
}
// Also make sure we dismiss bubble if representation is destroyed
// before the mouse actually leaves it

View File

@@ -28,6 +28,7 @@ define(
describe("The info gesture", function () {
var mockTimeout,
mockQueryService,
mockInfoService,
testDelay = 12321,
mockElement,
@@ -50,6 +51,7 @@ define(
beforeEach(function () {
mockTimeout = jasmine.createSpy('$timeout');
mockTimeout.cancel = jasmine.createSpy('cancel');
mockQueryService = jasmine.createSpyObj('queryService', ['isMobile']);
mockInfoService = jasmine.createSpyObj(
'infoService',
[ 'display' ]
@@ -79,6 +81,7 @@ define(
gesture = new InfoGesture(
mockTimeout,
mockQueryService,
mockInfoService,
testDelay,
mockElement,