Skip to content

Commit a356e01

Browse files
committed
Merge pull request #219 from nasa/open213
[Mobile] Don't move DOM nodes
2 parents a20bbd9 + d1bc93c commit a356e01

File tree

2 files changed

+26
-21
lines changed

2 files changed

+26
-21
lines changed

platform/commonUI/mobile/src/MCTDevice.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ define(
8585
function link(scope, element, attrs, ctrl, transclude) {
8686
if (deviceMatches(attrs.mctDevice)) {
8787
transclude(function (clone) {
88-
element.parent().append(clone);
88+
element.replaceWith(clone);
8989
});
9090
}
9191
}

platform/commonUI/mobile/test/MCTDeviceSpec.js

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,12 @@ define(
2626
function (MCTDevice) {
2727
"use strict";
2828

29-
var JQLITE_METHODS = [ 'parent', 'append' ];
29+
var JQLITE_METHODS = [ 'replaceWith' ];
3030

3131
describe("The mct-device directive", function () {
3232
var mockAgentService,
3333
mockTransclude,
3434
mockElement,
35-
mockParent,
3635
mockClone,
3736
testAttrs,
3837
directive;
@@ -48,11 +47,8 @@ define(
4847
);
4948
mockTransclude = jasmine.createSpy("$transclude");
5049
mockElement = jasmine.createSpyObj(name, JQLITE_METHODS);
51-
mockParent = jasmine.createSpyObj(name, JQLITE_METHODS);
5250
mockClone = jasmine.createSpyObj(name, JQLITE_METHODS);
5351

54-
mockElement.parent.andReturn(mockParent);
55-
5652
mockTransclude.andCallFake(function (fn) {
5753
fn(mockClone);
5854
});
@@ -65,6 +61,15 @@ define(
6561
directive = new MCTDevice(mockAgentService);
6662
});
6763

64+
function expectInclusion() {
65+
expect(mockElement.replaceWith)
66+
.toHaveBeenCalledWith(mockClone);
67+
}
68+
69+
function expectExclusion() {
70+
expect(mockElement.replaceWith).not.toHaveBeenCalled();
71+
}
72+
6873
it("is applicable at the attribute level", function () {
6974
expect(directive.restrict).toEqual("A");
7075
});
@@ -80,66 +85,66 @@ define(
8085
it("restricts element inclusion for mobile devices", function () {
8186
testAttrs.mctDevice = "mobile";
8287
link();
83-
expect(mockParent.append).not.toHaveBeenCalled();
88+
expectExclusion();
8489

8590
mockAgentService.isMobile.andReturn(true);
8691
link();
87-
expect(mockParent.append).toHaveBeenCalledWith(mockClone);
92+
expectInclusion();
8893
});
8994

9095
it("restricts element inclusion for tablet devices", function () {
9196
testAttrs.mctDevice = "tablet";
9297
mockAgentService.isMobile.andReturn(true);
9398
link();
94-
expect(mockParent.append).not.toHaveBeenCalled();
99+
expectExclusion();
95100

96101
mockAgentService.isTablet.andReturn(true);
97102
link();
98-
expect(mockParent.append).toHaveBeenCalledWith(mockClone);
103+
expectInclusion();
99104
});
100105

101106
it("restricts element inclusion for phone devices", function () {
102107
testAttrs.mctDevice = "phone";
103108
mockAgentService.isMobile.andReturn(true);
104109
link();
105-
expect(mockParent.append).not.toHaveBeenCalled();
110+
expectExclusion();
106111

107112
mockAgentService.isPhone.andReturn(true);
108113
link();
109-
expect(mockParent.append).toHaveBeenCalledWith(mockClone);
114+
expectInclusion();
110115
});
111116

112117
it("restricts element inclusion for desktop devices", function () {
113118
testAttrs.mctDevice = "desktop";
114119
mockAgentService.isMobile.andReturn(true);
115120
link();
116-
expect(mockParent.append).not.toHaveBeenCalled();
121+
expectExclusion();
117122

118123
mockAgentService.isMobile.andReturn(false);
119124
link();
120-
expect(mockParent.append).toHaveBeenCalledWith(mockClone);
125+
expectInclusion();
121126
});
122127

123128
it("restricts element inclusion for portrait orientation", function () {
124129
testAttrs.mctDevice = "portrait";
125130
link();
126-
expect(mockParent.append).not.toHaveBeenCalled();
131+
expectExclusion();
127132

128133
mockAgentService.isPortrait.andReturn(true);
129134
link();
130-
expect(mockParent.append).toHaveBeenCalledWith(mockClone);
135+
expectInclusion();
131136
});
132137

133138
it("restricts element inclusion for landscape orientation", function () {
134139
testAttrs.mctDevice = "landscape";
135140
mockAgentService.isLandscape.andReturn(false);
136141
mockAgentService.isPortrait.andReturn(true);
137142
link();
138-
expect(mockParent.append).not.toHaveBeenCalled();
143+
expectExclusion();
139144

140145
mockAgentService.isLandscape.andReturn(true);
141146
link();
142-
expect(mockParent.append).toHaveBeenCalledWith(mockClone);
147+
expectInclusion();
143148
});
144149

145150
it("allows multiple device characteristics to be requested", function () {
@@ -148,17 +153,17 @@ define(
148153
testAttrs.mctDevice = "portrait mobile";
149154
link();
150155
// Neither portrait nor mobile, not called
151-
expect(mockParent.append).not.toHaveBeenCalled();
156+
expectExclusion();
152157

153158
mockAgentService.isPortrait.andReturn(true);
154159
link();
155160

156161
// Was portrait, but not mobile, so no
157-
expect(mockParent.append).not.toHaveBeenCalled();
162+
expectExclusion();
158163

159164
mockAgentService.isMobile.andReturn(true);
160165
link();
161-
expect(mockParent.append).toHaveBeenCalledWith(mockClone);
166+
expectInclusion();
162167
});
163168
});
164169
}

0 commit comments

Comments
 (0)