Skip to content

Commit

Permalink
fix: make sure all Typeahead demos check to make sure the demo select…
Browse files Browse the repository at this point in the history
…or exists
  • Loading branch information
sghoweri committed Sep 12, 2019
1 parent 92b6214 commit b623357
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 50 deletions.
Expand Up @@ -4,7 +4,7 @@ const dynamicTypeaheadDemo = document.querySelector(
);

if (dynamicTypeaheadDemo) {
document.body.addEventListener('ready', function(e) {
dynamicTypeaheadDemo.addEventListener('ready', function(e) {
if (e.detail.name === 'bolt-typeahead') {
// note: make sure to let Typeahead know when the data fetched is ready
dynamicTypeaheadDemo.on('getSuggestions', async value => {
Expand Down
Expand Up @@ -20,35 +20,37 @@ const typeaheadDemoItems = [
},
];

typeaheadDemo.addEventListener('ready', function(e) {
if (e.detail.name === 'bolt-typeahead') {
typeaheadDemo.items = typeaheadDemoItems;
if (typeaheadDemo) {
typeaheadDemo.addEventListener('ready', function(e) {
if (e.detail.name === 'bolt-typeahead') {
typeaheadDemo.items = typeaheadDemoItems;

typeaheadDemo.on('onSelected', (element, event, suggestion) => {
const exactMatch = element.items.filter(
item => item.label === suggestion.suggestionValue,
)[0];
typeaheadDemo.on('onSelected', (element, event, suggestion) => {
const exactMatch = element.items.filter(
item => item.label === suggestion.suggestionValue,
)[0];

function navigateTo(url) {
if (window.location !== window.parent.location) {
const win = window.open(url, '_blank');
win.focus();
} else {
window.location = url;
function navigateTo(url) {
if (window.location !== window.parent.location) {
const win = window.open(url, '_blank');
win.focus();
} else {
window.location = url;
}
}
}

if (exactMatch && exactMatch.url) {
if (exactMatch.url) {
navigateTo(exactMatch.url);
} else {
navigateTo(`https://www.pega.com/search?q=${itemSelected.label}`);
if (exactMatch && exactMatch.url) {
if (exactMatch.url) {
navigateTo(exactMatch.url);
} else {
navigateTo(`https://www.pega.com/search?q=${itemSelected.label}`);
}
} else if (suggestion.suggestionValue !== '') {
navigateTo(
`https://www.pega.com/search?q=${suggestion.suggestionValue}`,
);
}
} else if (suggestion.suggestionValue !== '') {
navigateTo(
`https://www.pega.com/search?q=${suggestion.suggestionValue}`,
);
}
});
}
});
});
}
});
}
Expand Up @@ -56,28 +56,30 @@ const items = [
},
];

typeahead.addEventListener('ready', function(e) {
if (e.detail.name === 'bolt-typeahead') {
typeahead.items = items;
typeahead.on('onSelected', (element, event, suggestion) => {
const itemSelected = element.items.filter(
item => item.label === suggestion.suggestionValue,
)[0];
if (typeahead) {
typeahead.addEventListener('ready', function(e) {
if (e.detail.name === 'bolt-typeahead') {
typeahead.items = items;
typeahead.on('onSelected', (element, event, suggestion) => {
const itemSelected = element.items.filter(
item => item.label === suggestion.suggestionValue,
)[0];

if (itemSelected) {
if (itemSelected.label) {
if (window.location !== window.parent.location) {
// const win = window.open(`${itemSelected.url}`, '_blank');
const win = window.open(
`https://www.pega.com/search?q=${itemSelected.label}`,
'_blank',
);
win.focus();
} else {
window.location = `https://www.pega.com/search?q=${itemSelected.label}`;
if (itemSelected) {
if (itemSelected.label) {
if (window.location !== window.parent.location) {
// const win = window.open(`${itemSelected.url}`, '_blank');
const win = window.open(
`https://www.pega.com/search?q=${itemSelected.label}`,
'_blank',
);
win.focus();
} else {
window.location = `https://www.pega.com/search?q=${itemSelected.label}`;
}
}
}
}
});
}
});
});
}
});
}

0 comments on commit b623357

Please sign in to comment.