Skip to content

Commit b0472bb

Browse files
committed
Visible scroll-top button and smooth scroll on privacy-policy page (Cloud-CV#111)
* Removed unnecessary changes Removed build changes and privacy-policy UI changes. * UI change Added z-index value for scroll top button * Added smooth scroll implemented scrollOnTop method to add smooth scroll feature. * Added Linting Linted Privacy-policy component.ts file * Removed unnecessary changes deleted console.logs and commented line form scrollToTop method. * Changed scrollToTop method removed setInterval method and added scrollIntoView to scroll to top with smooth behaviour. * Nav content smooth scroll Added smooth scroll for the right side content on click of nav content. * Fix Cloud-CV#107 Added scroll bar for nav content. max height property has been added in nav container. * Added integration tests. Number of section title elements should be equal to the number of nav elements and should be greater than zero. * Removed unnecessary test component toBe(truthy) removed from the test * Changed section title Made section element title same as nav element title * Added test for section title Test checks the section title to be as same as nav element title or not. * Fixes linting issue fixed linting issues by adding whitespace properly * changes for privacy-policy component tests Made ALL_NAV and ALL_TARGET variable which gets initialized before each test. * Added logs in test logic Added console logs to show title of target and nav element in test-log file * Added grep commands Added grep commands in travis.yml file to show logs from test-log file * Changed xvfb command Added screen size and pixel depth in xvfb command to set specific screen size of virtual display. * Hide Scroll button on Top Added logic to change visibility if 'privacy-policy-title' element gets out of the view.
1 parent 998b85a commit b0472bb

6 files changed

+53
-20
lines changed

.travis.yml

+4-1
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,17 @@ before_install:
1414
- export CHROME_BIN=chromium-browser
1515
- export DISPLAY=:99.0
1616
- export DEPLOY_DOMAIN=https://pr-${TRAVIS_PULL_REQUEST}-evalai.surge.sh
17-
- sh -e /etc/init.d/xvfb start
17+
- /sbin/start-stop-daemon --start --quiet --pidfile /tmp/custom_xvfb_99.pid --make-pidfile --background --exec /usr/bin/Xvfb -- :99 -ac -screen 0 1280x1024x16
1818

1919
before_script:
2020
- npm install -g --silent @angular/cli
2121

2222
script:
2323
- ng lint
2424
- ng test --watch=false --progress=false --code-coverage > test-log
25+
- grep Executed test-log
26+
- grep ERROR test-log
27+
- grep LOGE test-log
2528
- ng e2e
2629
- ng build --prod
2730

src/app/components/nav/footer/footer.component.scss

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
overflow-x: hidden;
1313
background-repeat: no-repeat;
1414
background-size: 100% 100%;
15-
z-index: 10;
15+
z-index: 0;
1616
margin-top:30px;
1717
1818
&.at-home {

src/app/components/privacy-policy/privacy-policy.component.html

+10-10
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,13 @@
7272
</div>
7373
<div class="col-lg-3 col-md-4 col-sm-1 col-xs-1 privacy-empty-container">&nbsp;</div>
7474
<div class="privacy-content col-lg-9 col-md-8 col-sm-12 col-xs-12">
75-
<img class="scroll-to-top" src="assets/images/arrow_scroll.png" (click)="scrollToTop();" />
75+
<img class="scroll-to-top" *ngIf="visible" src="assets/images/arrow_scroll.png" (click)="scrollToTop();" />
7676
<div class="privacy-title" id="privacy-policy-title">Privacy Policy</div>
7777
<div class="privacy-section-content">
7878
This privacy policy has been compiled to better serve those who are concerned with how their 'Personally Identifiable Information' (PII) is being used online. PII, as described in US privacy law and information security, is information that can be used on its own or with other information to identify, contact, or locate a single person, or to identify an individual in context. Please read our privacy policy carefully to get a clear understanding of how we collect, use, protect or otherwise handle your Personally Identifiable Information in accordance with our website.
7979
</div>
8080
<div class="privacy-section-title">
81-
What personal information do we collect from the people that visit our blog, website or app?
81+
What personal information do we collect ?
8282
</div>
8383
<div class="privacy-section-content">
8484
When ordering or registering on our site, as appropriate, you may be asked to enter your name, email address, mailing address or other details to help you with your experience.
@@ -114,7 +114,7 @@
114114
Yes. Cookies are small files that a site or its service provider transfers to your computer's hard drive through your Web browser (if you allow) that enables the site's or service provider's systems to recognize your browser and capture and remember certain information. For instance, we use cookies to help us remember and update the status of the submissions. They are also used to help us understand your preferences based on previous or current site activity, which enables us to provide you with improved services. We also use cookies to help us compile aggregate data about site traffic and site interaction so that we can offer better site experiences and tools in the future.
115115
</div>
116116
<div class="privacy-section-title">
117-
We use cookies to:
117+
Why do we use cookies?
118118
</div>
119119
<div class="privacy-section-content">
120120
<ul>
@@ -123,7 +123,7 @@
123123
You can choose to have your computer warn you each time a cookie is being sent, or you can choose to turn off all cookies. You do this through your browser settings. Since browser is a little different, look at your browser's Help Menu to learn the correct way to modify your cookies.
124124
</div>
125125
<div class="privacy-section-title">
126-
If users disable cookies in their browser:
126+
What happens if users disable cookies in their browser?
127127
</div>
128128
<div class="privacy-section-content">
129129
If you turn cookies off, Some of the features that make your site experience more efficient may not function properly.Some of the features that make your site experience more efficient and may not function properly.
@@ -150,7 +150,7 @@
150150
Google, as a third-party vendor, uses cookies to serve ads on our site. Google's use of the DART cookie enables it to serve ads to our users based on previous visits to our site and other sites on the Internet. Users may opt-out of the use of the DART cookie by visiting the Google Ad and Content Network privacy policy.
151151
</div>
152152
<div class="privacy-section-title">
153-
We have implemented the following:
153+
What have we implemented?
154154
</div>
155155
<div class="privacy-section-content">
156156
<ul>
@@ -159,7 +159,7 @@
159159
We, along with third-party vendors such as Google use first-party cookies (such as the Google Analytics cookies) and third-party cookies (such as the DoubleClick cookie) or other third-party identifiers together to compile data regarding user interactions with ad impressions and other ad service functions as they relate to our website.
160160
</div>
161161
<div class="privacy-section-title">
162-
Opting out:
162+
Opting out
163163
</div>
164164
<div class="privacy-section-content">
165165
Users can set preferences for how Google advertises to you using the Google Ad Settings page. Alternatively, you can opt out by visiting the Network Advertising Initiative Opt Out page or by using the Google Analytics Opt Out Browser add on.
@@ -172,7 +172,7 @@
172172
<a href="http://consumercal.org/california-online-privacy-protection-act-caloppa/#sthash.0FdRbT51.dpuf">http://consumercal.org/california-online-privacy-protection-act-caloppa/#sthash.0FdRbT51.dpuf</a>.
173173
</div>
174174
<div class="privacy-section-title">
175-
According to CalOPPA, we agree to the following:
175+
CalOPPA Terms
176176
</div>
177177
<div class="privacy-section-content">
178178
Users can visit our site anonymously.
@@ -208,7 +208,7 @@
208208
The Fair Information Practices Principles form the backbone of privacy law in the United States and the concepts they include have played a significant role in the development of data protection laws around the globe. Understanding the Fair Information Practice Principles and how they should be implemented is critical to comply with the various privacy laws that protect personal information.
209209
</div>
210210
<div class="privacy-section-title">
211-
In order to be in line with Fair Information Practices we will take the following responsive action, should a data breach occur:
211+
What responsive actions will we take, should a data breach occur?
212212
</div>
213213
<div class="privacy-section-content">
214214
We will notify you via email
@@ -224,15 +224,15 @@
224224
The CAN-SPAM Act is a law that sets the rules for commercial email, establishes requirements for commercial messages, gives recipients the right to have emails stopped from being sent to them, and spells out tough penalties for violations.
225225
</div>
226226
<div class="privacy-section-title">
227-
We collect your email address in order to:
227+
Why do we collect your email address?
228228
</div>
229229
<div class="privacy-section-content">
230230
<ul>
231231
<li>Send information, respond to inquiries, and/or other requests or questions</li>
232232
</ul>
233233
</div>
234234
<div class="privacy-section-title">
235-
To be in accordance with CANSPAM, we agree to the following:
235+
Why do we agree to, for being in accordance with CANSPAM?
236236
</div>
237237
<div class="privacy-section-content">
238238
If at any time you would like to unsubscribe from receiving future emails, you can email us at <a href="mailto:[email protected]">[email protected]</a> and we will promptly remove you from <b>ALL</b> correspondence.

src/app/components/privacy-policy/privacy-policy.component.scss

+2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
position: relative;
1818
position: -webkit-sticky;
1919
position: sticky;
20+
max-height: 65vh;
2021
ul {
2122
list-style-type: none;
2223
padding-left: 0;
@@ -54,6 +55,7 @@
5455
right: 4%;
5556
height: 50px;
5657
cursor: pointer;
58+
z-index: 4 !important;
5759
&:hover {
5860
height: 55px;
5961
}

src/app/components/privacy-policy/privacy-policy.component.spec.ts

+25
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,17 @@ import { HeaderStaticComponent } from '../../components/nav/header-static/header
99
import { ActivatedRoute, Router } from '@angular/router';
1010
import { FooterComponent } from '../../components/nav/footer/footer.component';
1111
import { RouterTestingModule } from '@angular/router/testing';
12+
import { By } from '@angular/platform-browser';
13+
import { DebugElement } from '@angular/core';
1214

1315

1416
describe('PrivacyPolicyComponent', () => {
1517
let component: PrivacyPolicyComponent;
1618
let fixture: ComponentFixture<PrivacyPolicyComponent>;
19+
let de: DebugElement;
20+
let ALL_NAV;
21+
let ALL_TARGET;
22+
1723
const fakeActivatedRoute = {
1824
snapshot: { data: { } }
1925
} as ActivatedRoute;
@@ -35,10 +41,29 @@ describe('PrivacyPolicyComponent', () => {
3541
beforeEach(() => {
3642
fixture = TestBed.createComponent(PrivacyPolicyComponent);
3743
component = fixture.componentInstance;
44+
de = fixture.debugElement;
3845
fixture.detectChanges();
46+
ALL_NAV = de.queryAll(By.css('.privacy-nav'));
47+
ALL_TARGET = de.queryAll(By.css('.privacy-section-title'));
3948
});
4049

4150
it('should create', () => {
4251
expect(component).toBeTruthy();
4352
});
53+
54+
it('should have equal number of section-title elements as nav elements', () => {
55+
56+
expect(ALL_NAV.length).toBeGreaterThan(0);
57+
expect(ALL_TARGET.length).toBeGreaterThan(0);
58+
expect(ALL_TARGET.length).toBe(ALL_NAV.length);
59+
});
60+
61+
it('should have same section title as nav element title', () => {
62+
ALL_NAV.forEach((ele, index) => {
63+
console.log(`LOGE: TARGET: ${ALL_TARGET[index].nativeElement.innerText}`);
64+
console.log(`LOGE: NAV: ${ele.nativeElement.innerText}`);
65+
expect(ALL_TARGET[index].nativeElement.innerText).toBe(ele.nativeElement.innerText);
66+
});
67+
});
68+
4469
});

src/app/components/privacy-policy/privacy-policy.component.ts

+11-8
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ import { GlobalService } from '../../services/global.service';
1212
})
1313
export class PrivacyPolicyComponent implements OnInit {
1414

15-
constructor(@Inject(DOCUMENT) private document: Document, private globalService: GlobalService) { }
15+
visible: boolean;
16+
17+
constructor(@Inject(DOCUMENT) private document: Document, private globalService: GlobalService) {
18+
this.visible = false;
19+
}
1620

1721
/**
1822
* Checks if element is visible (called after scroll event)
@@ -85,6 +89,10 @@ export class PrivacyPolicyComponent implements OnInit {
8589
*/
8690
@HostListener('window:scroll', [])
8791
onWindowScroll(): void {
92+
93+
const el = this.document.getElementById('privacy-policy-title');
94+
this.visible = el.getBoundingClientRect().top < 0;
95+
8896
if (!this.document['manuallyScrolling']) {
8997
const ALL_TARGETS = this.document.getElementsByClassName('privacy-section-title');
9098
const SELF = this;
@@ -119,19 +127,14 @@ export class PrivacyPolicyComponent implements OnInit {
119127

120128
// Removing -nav from the id of the clicked element
121129
const ELEMENT_ID = ID.slice(0, -4);
122-
this.document.getElementById(ELEMENT_ID).scrollIntoView();
130+
this.document.getElementById(ELEMENT_ID).scrollIntoView({behavior: 'smooth'});
123131
this.highlightSectionTitle(ELEMENT_ID);
124-
const SCROLLED_Y = window.scrollY;
125-
if (SCROLLED_Y) {
126-
const HEADER_HEIGHT = this.document.getElementById('header-static').clientHeight;
127-
window.scroll(0, SCROLLED_Y - HEADER_HEIGHT);
128-
}
129132
}
130133

131134
/**
132135
* Scrolls to the top of the page
133136
*/
134137
scrollToTop() {
135-
this.document.body.scrollTop = this.document.documentElement.scrollTop = 0;
138+
this.document.getElementById('privacy-policy-title').scrollIntoView({behavior: 'smooth'});
136139
}
137140
}

0 commit comments

Comments
 (0)