Commit bcab4bb5 authored by Jose Ivan Vargas's avatar Jose Ivan Vargas

Changed the javascript class from using the global scope to exporting it via webpack

Also improved accesibility and change the id from user_callouts to a class
parent 19a21107
...@@ -36,6 +36,7 @@ ...@@ -36,6 +36,7 @@
/* global Shortcuts */ /* global Shortcuts */
const ShortcutsBlob = require('./shortcuts_blob'); const ShortcutsBlob = require('./shortcuts_blob');
const UserCallout = require('./user_callout');
(function() { (function() {
var Dispatcher; var Dispatcher;
...@@ -277,6 +278,9 @@ const ShortcutsBlob = require('./shortcuts_blob'); ...@@ -277,6 +278,9 @@ const ShortcutsBlob = require('./shortcuts_blob');
case 'ci:lints:show': case 'ci:lints:show':
new gl.CILintEditor(); new gl.CILintEditor();
break; break;
case 'users:show':
new UserCallout();
break;
} }
switch (path.first()) { switch (path.first()) {
case 'sessions': case 'sessions':
...@@ -313,6 +317,7 @@ const ShortcutsBlob = require('./shortcuts_blob'); ...@@ -313,6 +317,7 @@ const ShortcutsBlob = require('./shortcuts_blob');
case 'dashboard': case 'dashboard':
case 'root': case 'root':
shortcut_handler = new ShortcutsDashboardNavigation(); shortcut_handler = new ShortcutsDashboardNavigation();
new UserCallout();
break; break;
case 'profiles': case 'profiles':
new NotificationsForm(); new NotificationsForm();
......
/* eslint-disable arrow-parens, class-methods-use-this, no-param-reassign */ /* eslint-disable arrow-parens, class-methods-use-this, no-param-reassign */
/* global Cookies */ /* global Cookies */
((global) => { const userCalloutElementName = '.user-callout';
const userCalloutElementName = '#user-callout'; const dismissIcon = '.dismiss-icon';
const dismissIcon = '.dismiss-icon'; const userCalloutBtn = '.user-callout-btn';
const userCalloutBtn = '.user-callout-btn';
const USER_CALLOUT_COOKIE = 'user_callout_dismissed'; const USER_CALLOUT_COOKIE = 'user_callout_dismissed';
class UserCallout { class UserCallout {
constructor() { constructor() {
this.isCalloutDismissed = Cookies.get(USER_CALLOUT_COOKIE); this.isCalloutDismissed = Cookies.get(USER_CALLOUT_COOKIE);
this.init(); this.init();
this.isUserCalloutDismissed();
} }
init() { init() {
$(document) $(document)
.on('click', dismissIcon, () => this.closeAndDismissCallout()) .on('click', dismissIcon, () => this.closeAndDismissCallout())
.on('click', userCalloutBtn, () => this.closeAndDismissCallout()) .on('click', userCalloutBtn, () => this.closeAndDismissCallout());
.on('DOMContentLoaded', () => this.isUserCalloutDismissed());
} }
closeAndDismissCallout() { closeAndDismissCallout() {
...@@ -31,7 +30,6 @@ ...@@ -31,7 +30,6 @@
$(userCalloutElementName).show(); $(userCalloutElementName).show();
} }
} }
} }
global.UserCallout = UserCallout; module.exports = UserCallout;
})(window.gl || (window.gl = {}));
...@@ -278,7 +278,7 @@ table.u2f-registrations { ...@@ -278,7 +278,7 @@ table.u2f-registrations {
} }
} }
#user-callout { .user-callout {
display: none; display: none;
margin: 24px auto 0; margin: 24px auto 0;
...@@ -289,11 +289,13 @@ table.u2f-registrations { ...@@ -289,11 +289,13 @@ table.u2f-registrations {
.landing { .landing {
margin-bottom: $gl-padding; margin-bottom: $gl-padding;
overflow: hidden;
.close {
margin-right: 20px;
}
.dismiss-icon { .dismiss-icon {
float: right; float: right;
margin-right: 20px;
cursor: pointer; cursor: pointer;
color: $cycle-analytics-dismiss-icon-color; color: $cycle-analytics-dismiss-icon-color;
} }
......
...@@ -17,6 +17,3 @@ ...@@ -17,6 +17,3 @@
= render 'projects' = render 'projects'
- else - else
= render "zero_authorized_projects" = render "zero_authorized_projects"
:javascript
var userCallout = new gl.UserCallout();
#user-callout .user-callout
.bordered-box.landing.content-block .bordered-box.landing.content-block
%button.btn.btn-default.close{ type: "button" }
= icon("times", class: "dismiss-icon") = icon("times", class: "dismiss-icon")
.row .row
.col-sm-3.col-xs-12.svg-container .col-sm-3.col-xs-12.svg-container
......
...@@ -129,11 +129,8 @@ ...@@ -129,11 +129,8 @@
= spinner = spinner
:javascript :javascript
var userProfile, userCallout; var userProfile;
userProfile = new gl.User({ userProfile = new gl.User({
action: "#{controller.action_name}" action: "#{controller.action_name}"
}); });
userCallout = new gl.UserCallout();
...@@ -18,18 +18,18 @@ describe 'User Callouts', js: true do ...@@ -18,18 +18,18 @@ describe 'User Callouts', js: true do
describe 'user callout should appear in two routes' do describe 'user callout should appear in two routes' do
it 'shows up on the user profile' do it 'shows up on the user profile' do
visit user_path(user) visit user_path(user)
expect(find('#user-callout')).to have_content 'Customize your experience' expect(find('.user-callout')).to have_content 'Customize your experience'
end end
it 'shows up on the dashboard projects' do it 'shows up on the dashboard projects' do
visit dashboard_projects_path visit dashboard_projects_path
expect(find('#user-callout')).to have_content 'Customize your experience' expect(find('.user-callout')).to have_content 'Customize your experience'
end end
end end
it 'hides the user callout when click on the dismiss icon' do it 'hides the user callout when click on the dismiss icon' do
visit user_path(user) visit user_path(user)
within('#user-callout') do within('.user-callout') do
find('.dismiss-icon').click find('.dismiss-icon').click
end end
expect(page).not_to have_selector('#user-callout') expect(page).not_to have_selector('#user-callout')
......
#user-callout .user-callout
.bordered-box.landing.content-block .bordered-box.landing.content-block
%button.btn.btn-default.close{ type: "button" }
%i.fa.fa-times.dismiss-icon %i.fa.fa-times.dismiss-icon
.row .row
.col-sm-3.col-xs-12.svg-container .col-sm-3.col-xs-12.svg-container
......
/* esint-disable space-before-function-paren, arrow-body-style */ /* esint-disable space-before-function-paren, arrow-body-style */
require('~/user_callout'); const UserCallout = require('~/user_callout');
((global) => { const USER_CALLOUT_COOKIE = 'user_callout_dismissed';
const USER_CALLOUT_COOKIE = 'user_callout_dismissed'; const Cookie = window.Cookies;
const Cookie = window.Cookies;
describe('UserCallout', function () { describe('UserCallout', function () {
const fixtureName = 'static/user_callout.html.raw'; const fixtureName = 'static/user_callout.html.raw';
preloadFixtures(fixtureName); preloadFixtures(fixtureName);
it('should be defined in the global scope', () => {
expect(global.UserCallout).toBeDefined();
});
beforeEach(() => { beforeEach(() => {
loadFixtures(fixtureName); loadFixtures(fixtureName);
this.userCallout = new global.UserCallout(); this.userCallout = new UserCallout();
this.dismissIcon = $('.dismiss-icon'); this.dismissIcon = $('.dismiss-icon');
this.userCalloutContainer = $('#user-callout'); this.userCalloutContainer = $('.user-callout');
this.userCalloutBtn = $('.user-callout-btn'); this.userCalloutBtn = $('.user-callout-btn');
Cookie.set(USER_CALLOUT_COOKIE, 0); Cookie.set(USER_CALLOUT_COOKIE, 0);
}); });
...@@ -38,5 +33,4 @@ require('~/user_callout'); ...@@ -38,5 +33,4 @@ require('~/user_callout');
expect(this.userCalloutContainer.is(':visible')).toBe(false); expect(this.userCalloutContainer.is(':visible')).toBe(false);
expect(Cookie.get(USER_CALLOUT_COOKIE)).toBe('1'); expect(Cookie.get(USER_CALLOUT_COOKIE)).toBe('1');
}); });
}); });
})(window.gl || (window.gl = {}));
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment