Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • adi-ia/enrollment-profile
  • SABERG3/enrollment-profile
2 results
Show changes
Commits on Source (35)
# myuw-profile versions
## 1.3.2
### Fixed
* Check for valid references before messing with DOM elements/variables
## 1.3.0
### Added
* Component listens for a CustomEvent called "myuw-login" and sets up its appearance accordingly. See the README usage guide.
## 1.2.2
### Added
* Polyfills included in demo page
### Fixed
* Fixed appearance in Firefox
## 1.2.1
### Changed
* Set standard top-bar button margin on containing element
* Removed left-only margin to better support usage outside of myuw-app-bar
* Add use of a CSS variable for menu link color (myuw-menu-color)
* Adjust circle button appearance to be centered better
* Add font weight CSS variable
\ No newline at end of file
......@@ -9,35 +9,78 @@ Add the following import to your page's `<head>`:
<script nomodule src="https://unpkg.com/@myuw-web-components/myuw-profile@^1"></script>
```
*Note: You may want to specify a specific version of the component to ensure stability. See [the change log](CHANGELOG.md) or the [npm entry](https://www.npmjs.com/package/@myuw-web-components/myuw-profile) for version information.*
Use the component's HTML tag wherever you want:
```HTML
<myuw-profile
login-url=""
logout-url=""
session-endpoint=""
background-color=""
open-right
>
</myuw-profile>
```
#### Configurable properties
### Displaying the component
Because it has multiple states depending on whether there is an active session, all elements of the profile component are hidden by default. The component listens for a CustomEvent called "myuw-login" and its state is dependent on the data you pass when you dispatch that event:
```js
/*
Notes about configuring the event:
- The event MUST contain a "detail" object. The contents of the detail object determine what the component will display:
- An empty "detail" object ( detail: {} ) will result in the login button being displayed
- An empty "person" object ( person: {} ) will result in a generic session being displayed (using the person icon). This should only be used when the session doesn't provide a user's name, username, email, etc.
- A person object containing a "firstName" ( person: {firstName: "Name"} ) will result in the full session display
- The "bubbles" property is optional unless you're dispatching the event from an element/scope other than "document"
*/
var customEvent = new CustomEvent('myuw-login', {
bubbles: true, // optional
detail: { // required always
person: { // required for generic session display
"firstName": "User" // required for full session display
}
}
});
// Dispatch the event
document.dispatchEvent(customEvent);
```
#### Initial page load
If you want the component to show something on the initial page load (and not be hidden), make sure to dispatch the "myuw-login" event **after** all web components are loaded and upgraded (i.e. ready to be interacted with). The webcomponentsjs polyfill provides and event you can hook into:
```js
document.addEventListener('WebComponentsReady', function() {
var customEvent = new CustomEvent('myuw-login', {
// Configure the event data to display what you want
});
// Dispatch the event
document.dispatchEvent(customEvent);
});
```
### Configurable properties
- **Login URL (login-url):** The URL to redirect users to on login
- **Logout URL (logout-url):** The Logout URL to redirect users to on logout
- **Session Endpoint (session-endpoint):** The endpoint URL for session info
- **Background color (background-color):** Use this to dynamically set the background color of the profile menu button
- **Open Menu Right (open-right):** Include this attribute if you would like the profile menu to open to the right, instead of left
#### Slots
### Slots
- **Profile Navigation Item (nav-item):** Add a custom item to the profile button's navigation menu, this slot expects an `<a>` tag
#### CSS Variables
### CSS Variables
- `--myuw-profile-font`: Set the font stack for this component
- `--myuw-profile-login-color`: Set the font color of the "Login" button
- `--myuw-profile-background-color`: Set the background color of the circular menu button
- `--myuw-menu-color`: The text color of links/buttons in the profile menu
For more information about CSS variables and how they work with MyUW Web Components, [reference the styles component](https://github.com/myuw-web-components/myuw-app-styles "reference the styles component")
Cross-browser testing provided by:<br/>
<a href="https://www.browserstack.com/"><img width="160" src="https://myuw-web-components.github.io/img/Browserstack-logo.svg" alt="BrowserStack"/></a>
......@@ -48,6 +48,14 @@
cursor: pointer;
}
</style>
<script src="https://unpkg.com/css-vars-ponyfill@1"></script>
<script>
cssVars({shadowDOM: true,watch: true});
</script>
<!-- Web component polyfill loader -->
<script src="https://unpkg.com/@webcomponents/webcomponentsjs@2.1.3/webcomponents-loader.js"></script>
<script type="module" src="https://unpkg.com/@myuw-web-components/myuw-app-styles@^1?module"></script>
<script nomodule src="https://unpkg.com/@myuw-web-components/myuw-app-styles@^1"></script>
......@@ -56,25 +64,22 @@
<script type="module" src="./dist/myuw-profile.mjs"></script>
<script nomodule src="./dist/myuw-profile.mjs"></script>
</head>
<body>
<!-- App bar with profile button -->
<myuw-app-bar
theme-name="MyUW"
theme-url=""
app-name="Profile Demo"
app-url=""
background="rgb(197, 5, 12)"
color="white">
<myuw-profile
slot="myuw-profile"
login-url="https://wisc.edu/"
logout-url="https://wisc.edu/"
session-endpoint="./test/session.json">
<a href="#" slot="nav-item">UW Madison Home</a>
<a href="#" slot="nav-item">STAR</a>
</myuw-profile>
<myuw-profile
slot="myuw-profile"
login-url="https://wisc.edu/"
logout-url="https://wisc.edu/">
<a href="#" slot="nav-item">UW Madison Home</a>
<a href="#" slot="nav-item">STAR</a>
</myuw-profile>
</myuw-app-bar>
<!-- Demo content -->
......@@ -88,47 +93,102 @@
<button aria-label="set profile button color" onclick="setColor(newColor.value)">Set profile color</button>
</div>
<div class="demo-item">
<button aria-label="set no session" onclick="setSession('jargon')">No session</button>
<button aria-label="set no session" onclick="logout()">No session</button>
</div>
<div class="demo-item">
<button aria-label="restore demo session" onclick="setSession('./test/session.json')">Restore demo session</button>
<button aria-label="restore demo session" onclick="setPortalSession()">Set portal session</button>
</div>
<div class="demo-item">
<button aria-label="set missing session-endpoint" onclick="setSession(null)">Set missing session endpoint</button>
<button aria-label="set a session without user info" onclick="setNonstandardSession()">Set session without person info</button>
</div>
<div class="demo-item">
<button aria-label="log in with other data" onclick="customLogin()">Set custom session</button>
</div>
</div>
<!-- Functions for demo content -->
<script>
// Add event listener to profile component
function customLogin(event) {
var customEvent = new CustomEvent('myuw-login', {
bubbles: true,
detail: {
person: {
"firstName": "Shibboleth"
}
}
});
document.dispatchEvent(customEvent);
};
function logout() {
var customEvent = new CustomEvent('myuw-login', {
bubbles: true,
detail: {
person: null
}
});
document.dispatchEvent(customEvent);
}
function setNonstandardSession() {
var customEvent = new CustomEvent('myuw-login', {
bubbles: true,
detail: {
person: {
"someOtherAttribute": "What is this"
}
}
});
document.dispatchEvent(customEvent);
}
function setPortalSession() {
fetch('./test/session.json')
.then(res => {
// Check if the request was valid
if(res.status === 200){
res.json()
.then( data => {
// If data.person is not set, return.
if(!data.person) { return; }
// Set user data to the component
var customEvent = new CustomEvent('myuw-login', {
bubbles: true,
detail: {
person: data.person
}
});
document.dispatchEvent(customEvent);
})
} else {
var customEvent = new CustomEvent('myuw-login', {
bubbles: true,
detail: {
person: null
}
});
document.dispatchEvent(customEvent);
}
})
.catch( e => {
var customEvent = new CustomEvent('myuw-login', {
bubbles: true,
detail: {
person: null
}
});
document.dispatchEvent(customEvent);
} );
}
function setColor(newColor) {
if (newColor.indexOf('#') < 0) {
newColor = '#' + newColor;
}
document.getElementsByTagName('myuw-profile')[0].setAttribute('background-color', newColor);
}
function setSession(session) {
// Remove profile from DOM
document.getElementsByTagName('myuw-profile')[0].remove();
// Construct new profile template
var newProfileTemplate = document.createElement('myuw-profile');
newProfileTemplate.setAttribute('slot', 'myuw-profile');
newProfileTemplate.setAttribute('login-url', 'https://wisc.edu/');
newProfileTemplate.setAttribute('logout-url', 'https://wisc.edu/');
newProfileTemplate.setAttribute('color', '#fb686d');
newProfileTemplate.innerHTML = `
<a href="https://wisc.edu" slot="nav-item">UW Madison Home</a>
<a href="https://wisc.edu" slot="nav-item">STAR</a>
`;
if (session) {
newProfileTemplate.setAttribute('session-endpoint', session);
}
// Reinsert into DOM
document.getElementsByTagName('myuw-app-bar')[0].appendChild(newProfileTemplate);
}
</script>
<!-- Accessibility tester -->
<script src="./node_modules/tota11y/build/tota11y.min.js"></script>
</body>
</html>
This diff is collapsed.
{
"name": "@myuw-web-components/myuw-profile",
"version": "1.1.0",
"name": "enrollment-profile",
"version": "1.3.1",
"description": "Web component that provides an avatar button and profile menu",
"module": "dist/myuw-profile.min.mjs",
"browser": "dist/myuw-profile.min.js",
"scripts": {
"build": "rollup -c",
"watch": "rollup -c -w",
"serve": "live-server",
"serve": "live-server --port=4200",
"start": "run-p watch serve",
"prepare": "npm run build",
"pages": "mkdir -p demo && cp -r dist demo/dist && cp index.html demo/index.html && gh-pages -d demo",
"pages": "rm -rf demo && mkdir -p demo && cp -r dist demo/ && cp -r test demo/ && cp index.html demo/ && gh-pages -d demo --repo git@github.com:myuw-web-components/myuw-profile.git",
"postpublish": "npm run pages"
},
"repository": {
"type": "git",
"url": "git+https://github.com/myuw-web-components/myuw-profile.git"
"url": "git+https://git.doit.wisc.edu/adi-ia/enrollment-profile.git"
},
"author": "",
"license": "Apache-2.0",
"bugs": {
"url": "https://github.com/myuw-web-components/myuw-profile/issues"
},
"homepage": "https://github.com/myuw-web-components/myuw-profile#readme",
"devDependencies": {
"rollup": "^0.63.4",
"rollup-plugin-html": "^0.2.1",
"rollup-plugin-minify-es": "^1.1.1",
"@babel/core": "^7.1.2",
"@babel/preset-env": "^7.1.0",
"gh-pages": "^1.2.0",
"live-server": "^1.2.0",
"npm-run-all": "^4.1.3",
"rollup": "^0.63.4",
"rollup-plugin-babel": "^4.0.3",
"rollup-plugin-html": "^0.2.1",
"rollup-plugin-minify-es": "^1.1.1",
"tota11y": "^0.1.6"
},
"files": [
......
import { rollup } from 'rollup';
import html from 'rollup-plugin-html';
import minify from 'rollup-plugin-minify-es';
import babel from 'rollup-plugin-babel';
let fileName = 'myuw-profile';
let objName = 'MyUWProfile';
......@@ -38,7 +39,7 @@ let plugins = {
export default [
{
input: `src/${fileName}.js`,
plugins: plugins.full,
plugins: plugins.full.concat([babel({exclude: 'node_modules/**'})]),
output: {
file: `dist/${fileName}.js`,
name: objName,
......@@ -47,7 +48,7 @@ export default [
},
{
input: `src/${fileName}.js`,
plugins: plugins.min,
plugins: plugins.min.concat([babel({exclude: 'node_modules/**'})]),
output: {
file: `dist/${fileName}.min.js`,
name: objName,
......
{
"presets": [
["@babel/env", {
"modules": false
}]
],
}
<style>
@import url(https://fonts.googleapis.com/icon?family=Material+Icons);
:host([hidden]) {
display: none;
}
......@@ -9,7 +11,7 @@
text-decoration: none;
color: var( --myuw-profile-login-color, var(--myuw-primary-color, white) );
padding: 10px 13px;
font-weight: bold;
font-weight: var(--myuw-profile-font-weight, 600);
letter-spacing: 0px;
font-size: 14px;
position: relative;
......@@ -22,14 +24,16 @@
}
#myuw-profile-circle {
display: inline-block;
display: flex;
justify-content: center;
align-items: center;
align-content: center;
align-self: center;
outline: none;
border-radius: 50%;
height: 42px;
width: 42px;
min-width: initial;
margin-left: 8px;
padding: 4px;
text-transform: uppercase;
text-align: center;
background: transparent;
......@@ -44,30 +48,34 @@
}
#myuw-profile-circle-initial {
display: flex;
justify-content: center;
align-items: center;
align-content: center;
align-self: center;
padding: 0;
margin: 0;
font-weight: 500;
font-weight: var(--myuw-profile-font-weight, 300);
font-size: 18px;
font-family: var( --myuw-profile-font, var(--myuw-font, 'Montserrat', 'Roboto', Arial, sans-serif) );
font-family: var( --myuw-profile-font, var(--myuw-font, 'Roboto', Arial, sans-serif) );
background-color: var( --myuw-profile-background-color, #fb686d);
user-select: none;
color: white;
text-transform: capitalize;
border-radius: 50%;
display: block;
margin: 0;
overflow: hidden;
position: relative;
height: 33px;
width: 33px;
line-height: 33px;
height: 34px;
width: 34px;
min-width: 34px;
font-size: 18px;
font-weight: 400;
}
#myuw-profile-wrapper {
position: relative;
display: inline-block;
margin: 0 6px;
}
#myuw-profile-wrapper.hidden {
......@@ -97,12 +105,6 @@
box-shadow: 0 2px 4px -1px rgba(0,0,0,0.2), 0 4px 5px 0 rgba(0,0,0,0.14), 0 1px 10px 0 rgba(0,0,0,0.12);
}
#myuw-profile-nav.open-right {
left: 0;
right: inherit;
transform-origin: top left;
}
#myuw-profile-nav.visible {
transform: scale(1);
opacity: 1;
......@@ -114,35 +116,66 @@
margin: 0;
}
#myuw-profile-nav a,
#myuw-profile-nav p,
::slotted(a),
::slotted(p) {
transition: all .3s ease;
position: relative;
font-size: 15px;
font-family: var( --myuw-profile-font, var(--myuw-font, 'Montserrat', 'Roboto', Arial, sans-serif) );
padding: 3px 16px;
color: rgba(0,0,0,0.87);
text-decoration: none;
background-color: #f5f5f5;
border-bottom: 1px solid #e5e5e5;
user-select: none;
outline: none;
display: flex;
-webkit-box-orient: horizontal;
-webkit-box-direction: normal;
-webkit-flex-direction: row;
flex-direction: row;
min-height: 48px;
height: 48px;
-webkit-align-content: center;
align-content: center;
-webkit-align-items: center;
align-items: center;
-webkit-box-pack: start;
-webkit-justify-content: flex-start;
justify-content: flex-start;
transition: all .3s ease;
position: relative;
font-size: 15px;
font-family: var( --myuw-profile-font, var(--myuw-font, 'Montserrat', 'Roboto', Arial, sans-serif) );
padding: 3px 16px;
color: var(--myuw-menu-color, rgba(0,0,0,0.87));
text-decoration: none;
background-color: #f5f5f5;
border-bottom: 1px solid #e5e5e5;
user-select: none;
outline: none;
display: flex;
-webkit-box-orient: horizontal;
-webkit-box-direction: normal;
-webkit-flex-direction: row;
flex-direction: row;
min-height: 48px;
height: 48px;
-webkit-align-content: center;
align-content: center;
-webkit-align-items: center;
align-items: center;
-webkit-box-pack: start;
-webkit-justify-content: flex-start;
justify-content: flex-start;
}
/*
Styles need to be duplicated separate from ::slotted in order for
Firefox to do it's job
*/
#myuw-profile-nav a,
#myuw-profile-nav p {
transition: all .3s ease;
position: relative;
font-size: 15px;
font-family: var( --myuw-profile-font, var(--myuw-font, 'Montserrat', 'Roboto', Arial, sans-serif) );
padding: 3px 16px;
color: var(--myuw-menu-color, rgba(0,0,0,0.87));
text-decoration: none;
background-color: #f5f5f5;
border-bottom: 1px solid #e5e5e5;
user-select: none;
outline: none;
display: flex;
-webkit-box-orient: horizontal;
-webkit-box-direction: normal;
-webkit-flex-direction: row;
flex-direction: row;
min-height: 48px;
height: 48px;
-webkit-align-content: center;
align-content: center;
-webkit-align-items: center;
align-items: center;
-webkit-box-pack: start;
-webkit-justify-content: flex-start;
justify-content: flex-start;
}
#myuw-profile-nav #myuw-profile-nav-user {
......@@ -152,20 +185,27 @@
border-bottom: none;
}
#myuw-profile-nav #myuw-profile-nav-user.hidden {
display: none;
}
#myuw-profile-nav #myuw-profile-nav-user:hover {
background-color: rgb(255,255,255);
}
#myuw-profile-nav a:hover,
#myuw-profile-nav a:focus,
#myuw-profile-nav p:hover,
#myuw-profile-nav p:focus,
::slotted(a:hover),
::slotted(a:focus),
::slotted(p:hover),
::slotted(p:focus) {
background-color: #ececec;
}
#myuw-profile-nav a:hover,
#myuw-profile-nav a:focus,
#myuw-profile-nav p:hover,
#myuw-profile-nav p:focus {
background-color: #ececec;
}
</style>
<a href="#" id="myuw-profile-login" class="hidden">Login</a>
......@@ -176,7 +216,7 @@
aria-haspopup="true"
aria-controls="myuw-profile-nav"
aria-expanded="false">
<p id="myuw-profile-circle-initial">B</p>
<p id="myuw-profile-circle-initial"><i class="material-icons">person</i></p>
</button>
<ul id="myuw-profile-nav"
......
......@@ -4,8 +4,6 @@ class MyUWProfile extends HTMLElement {
constructor() {
super();
this['open-right'] = false;
// Create a shadowroot for this element
this.attachShadow({mode: 'open'});
......@@ -17,60 +15,50 @@ class MyUWProfile extends HTMLElement {
return [
'login-url',
'logout-url',
'open-right',
'background-color'
];
}
attributeChangedCallback(name, oldValue, newValue){
attributeChangedCallback(name, oldValue, newValue) {
if (typeof this.$circle !== 'undefined') {
// Update the attribute internally
this[name] = newValue;
// Update the component with new att value
this.updateAttribute(name);
}
}
connectedCallback(){
// Get all attributes
this['login-url'] = this.getAttribute('login-url');
this['logout-url'] = this.getAttribute('logout-url');
this['session-endpoint'] = this.getAttribute('session-endpoint');
this['background-color'] = this.getAttribute('background-color');
this['user'] = false;
if (this.getAttribute('open-right') !== null) {
this['open-right'] = true;
}
// If the session endpoint is set, fetch session info
if (this['session-endpoint']) {
fetch(this['session-endpoint'])
.then(res => {
// Check if the request was valid
if(res.status === 200){
res.json()
.then( data => {
// If data.person is not set, return.
if(!data.person){ return; }
// Set user data to the component
this.user = data.person;
this.componentReady();
})
} else {
this.componentReady();
}
})
.catch( e => {
console.log(e);
// Show login button if we couldn't get session info
this.componentReady();
} );
} else {
throw Error('No session endpoint has been defiend. Please set the "session-endpoint" attribute URL into the myuw-profile element!');
}
this.$login = this.shadowRoot.getElementById('myuw-profile-login');
this.$logout = this.shadowRoot.getElementById('myuw-profile-logout');
this.$button = this.shadowRoot.getElementById('myuw-profile-circle');
this.$circle = this.shadowRoot.getElementById('myuw-profile-circle-initial');
this.$nav = this.shadowRoot.getElementById('myuw-profile-nav');
this.$displayName = this.shadowRoot.getElementById('myuw-profile-nav-user');
this.$wrapper = this.shadowRoot.getElementById('myuw-profile-wrapper');
/**
* @typedef {Object} person
* @property {String} firstName
*/
/**
* Listen for custom event to receive session information
* @param {CustomEvent} event Event that should pass "person" information to display
*/
document.addEventListener('myuw-login', (event) => {
// Process data passed with event
if (event.detail.person) {
this.componentReady(event.detail.person);
} else {
this.componentReady();
}
}, false);
/*
Add an on click event to the window.
......@@ -78,11 +66,9 @@ class MyUWProfile extends HTMLElement {
clicks anywhere but on the menu.
*/
window.addEventListener('click', e => {
let nav = this.shadowRoot.getElementById('myuw-profile-nav');
if (nav.classList.contains('visible')) {
nav.classList.remove('visible');
this.shadowRoot.getElementById('myuw-profile-circle').setAttribute('aria-expanded', 'false');
if (this.$nav.classList.contains('visible')) {
this.$nav.classList.remove('visible');
this.$button.setAttribute('aria-expanded', 'false');
}
});
......@@ -94,7 +80,7 @@ class MyUWProfile extends HTMLElement {
If a user clicks on the nav menu, the window on click
event will not fire, and it will not close the nav menu
*/
this.shadowRoot.getElementById('myuw-profile-nav').addEventListener('click', e => {
this.$nav.addEventListener('click', e => {
e.stopPropagation();
});
......@@ -105,93 +91,82 @@ class MyUWProfile extends HTMLElement {
this event or else the window on click will always fire
and the menu will never open.
*/
this.shadowRoot.getElementById('myuw-profile-circle').addEventListener('click', e => {
// Find menu button and the first nav list item
let nav = this.shadowRoot.getElementById('myuw-profile-nav');
let menuButton = this.shadowRoot.getElementById('myuw-profile-circle');
this.$button.addEventListener('click', e => {
e.stopPropagation();
nav.classList.toggle('visible');
this.$nav.classList.toggle('visible');
// Focus the menu upon opening, blur on close
if (nav.classList.contains('visible')) {
nav.focus();
menuButton.setAttribute('aria-expanded', 'true');
if (this.$nav.classList.contains('visible')) {
this.$nav.focus();
this.$button.setAttribute('aria-expanded', 'true');
} else {
nav.blur();
menuButton.setAttribute('aria-expanded', 'false');
this.$nav.blur();
this.$button.setAttribute('aria-expanded', 'false');
}
});
// this.componentReady();
// Update the component to use the new attributes
this.updateAttribute('login-url');
this.updateAttribute('logout-url');
this.updateAttribute('session-endpoint');
this.updateAttribute('open-right');
this.updateAttribute('background-color');
}
// Update the component with attribute values
updateAttribute(att) {
switch(att){
case 'login-url':
this.shadowRoot.getElementById('myuw-profile-login').setAttribute('href', this['login-url']);
break;
case 'logout-url':
this.shadowRoot.getElementById('myuw-profile-logout').setAttribute('href', this['logout-url']);
break;
case 'open-right':
if(this['open-right']){
this.shadowRoot.getElementById('myuw-profile-nav').classList.add('open-right');
}
break;
case 'background-color':
this.shadowRoot.getElementById('myuw-profile-circle-initial').style.backgroundColor = this['background-color'];
break;
}
switch(att){
case 'login-url':
this.shadowRoot.getElementById('myuw-profile-login').setAttribute('href', this['login-url']);
break;
case 'logout-url':
this.shadowRoot.getElementById('myuw-profile-logout').setAttribute('href', this['logout-url']);
break;
case 'background-color':
this.$circle.style.backgroundColor = this['background-color'];
break;
}
}
/*
Function to run after the session endpoint
has been hit and the component has all the
data that it needs to render.
If user data was returned from the endpoint,
the profile bubble will show.
If not, the login button will show.
/**
* Runs after component detects the 'myuw-login' event and receives
* the required parameter
* @param {*} person
*/
componentReady() {
if (this.user) {
// Add user's name to first menu item
this.shadowRoot.getElementById('myuw-profile-nav-user').innerHTML = this.user.firstName;
// Change the letter in the profile circle
this.shadowRoot.getElementById('myuw-profile-circle-initial').innerHTML = this.user.firstName.substring(0,1);
// Show the profile bubble
this.showProfileBubble();
componentReady(person) {
if (person) {
if (person.firstName) {
// Add user's name to first menu item
this.$displayName.classList.remove('hidden');
this.$displayName.innerHTML = person.firstName;
// Change the letter in the profile circle
this.$circle.innerHTML = person.firstName.substring(0,1);
// Show the profile bubble
this.showProfileBubble();
} else {
if (this['login-url'] !== null) {
this.showLoginButton();
} else {
this.hidden = true;
}
this.$displayName.classList.add('hidden');
this.$circle.innerHTML = '<i class="material-icons">person</i>';
this.showProfileBubble();
}
} else {
this.showLoginButton();
}
}
showLoginButton() {
// Show Login Button
this.shadowRoot.getElementById('myuw-profile-login').classList.remove('hidden');
this.$login.classList.remove('hidden');
// Hide profile Circle
this.shadowRoot.getElementById('myuw-profile-wrapper').classList.add('hidden');
this.$wrapper.classList.add('hidden');
}
showProfileBubble() {
// Hide login button
this.shadowRoot.getElementById('myuw-profile-login').classList.add('hidden');
this.$login.classList.add('hidden');
// Show Profile circle
this.shadowRoot.getElementById('myuw-profile-wrapper').classList.remove('hidden');
this.$wrapper.classList.remove('hidden');
}
}
......@@ -200,4 +175,24 @@ MyUWProfile.template = (function template(src) {
template.innerHTML = src;
return template;
})(tpl);
/**
* Polyfill for supporting the CustomEvent constructor in IE9+
* From: https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent/CustomEvent#Polyfill
*/
(function () {
if (typeof window.CustomEvent === 'function') {
return false;
}
function CustomEvent (event, params) {
params = params || { bubbles: false, cancelable: false, detail: undefined };
var evt = document.createEvent( 'CustomEvent' );
evt.initCustomEvent(event, params.bubbles, params.cancelable, params.detail);
return evt;
}
CustomEvent.prototype = window.Event.prototype;
window.CustomEvent = CustomEvent;
})();
window.customElements.define('myuw-profile', MyUWProfile);