Skip to content

Commit

Permalink
custom js events fix (#407)
Browse files Browse the repository at this point in the history
* custom js events fix

* build new scripts
  • Loading branch information
Harvel218 authored Dec 9, 2021
1 parent cc62e53 commit 6a1b664
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 9 deletions.
8 changes: 4 additions & 4 deletions src/Resources/assets/admin/js/bitbag/bitbag-cms-preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,22 +70,22 @@ export class HandlePreview {
};

try {
triggerCustomEvent(this.mediaContainer, 'cms.create.preview.start');
triggerCustomEvent(this.modal, 'cms.create.preview.start');
const req = await fetch(`${path}?_channel_code=${channelCode}&_locale=${localeCode}`, settings);
const res = await req.text();

const blob = new Blob([res], {type: 'text/html', charset: 'utf-8'});
const blobUrl = window.URL.createObjectURL(blob);

this.modal.querySelector('iframe').src = blobUrl;
triggerCustomEvent(this.mediaContainer, 'cms.create.preview.completed', res);
triggerCustomEvent(this.modal, 'cms.create.preview.completed', res);
} catch (error) {
console.error(`BitBag CMS Plugin - HandlePreview class error : ${error}`);
triggerCustomEvent(this.mediaContainer, 'cms.create.preview.error', error);
triggerCustomEvent(this.modal, 'cms.create.preview.error', error);
} finally {
this.modal.querySelector('.ui.loadable').classList.remove('loading');
this.modal.disabled = false;
triggerCustomEvent(this.mediaContainer, 'cms.create.preview.end');
triggerCustomEvent(this.modal, 'cms.create.preview.end');
}
}
}
Expand Down
6 changes: 2 additions & 4 deletions src/Resources/assets/admin/js/bitbag/bitbag-page-slug.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,22 +70,20 @@ export class HandleSlugUpdate {
}

async _updateSlug(slugField, value) {
triggerCustomEvent(this.mediaContainer, 'cms.slug.update.start');
triggerCustomEvent(slugField, 'cms.slug.update.start');
slugField.parentNode.classList.add('loading');
slugField.value = await this._getValidSlug(slugField.dataset.url, value);
slugField.parentNode.classList.remove('loading');
triggerCustomEvent(this.mediaContainer, 'cms.slug.update.end');
triggerCustomEvent(slugField, 'cms.slug.update.end');
}

async _getValidSlug(url, value) {
try {
const request = await fetch(`${url}?name=${value}`);
const response = await request.json();
triggerCustomEvent(this.mediaContainer, 'cms.slug.update.completed', response);
return response.slug;
} catch (error) {
console.error(`BitBag CMS Plugin - HandleSlugUpdate class error : ${error}`);
triggerCustomEvent(this.mediaContainer, 'cms.slug.update.error', error);
}
}

Expand Down
Loading

0 comments on commit 6a1b664

Please sign in to comment.