Skip to content

Commit

Permalink
Simplify event detachment
Browse files Browse the repository at this point in the history
  • Loading branch information
lqez committed Mar 11, 2019
1 parent 823d62c commit 3d3c246
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
6 changes: 3 additions & 3 deletions src/js/base/module/ImageDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,9 @@ export default class ImageDialog {
});

this.ui.onDialogHidden(this.$dialog, () => {
$imageInput.off('change');
$imageUrl.off('input propertychange keypress');
$imageBtn.off('click');
$imageInput.off();
$imageUrl.off();
$imageBtn.off();

if (deferred.state() === 'pending') {
deferred.reject();
Expand Down
12 changes: 8 additions & 4 deletions src/js/base/module/LinkDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,17 +87,21 @@ export default class LinkDialog {
this.ui.onDialogShown(this.$dialog, () => {
this.context.triggerEvent('dialog.shown');

// if no url was given and given text is valid URL then copy that into URL Field
// If no url was given and given text is valid URL then copy that into URL Field
if (!linkInfo.url && func.isValidUrl(linkInfo.text)) {
linkInfo.url = linkInfo.text;
}

$linkText.on('input paste propertychange', () => {
// If linktext was modified by input events,
// cloning text from linkUrl will be stopped.
linkInfo.text = $linkText.val();
this.toggleLinkBtn($linkBtn, $linkText, $linkUrl);
}).val(linkInfo.text);

$linkUrl.on('input paste propertychange', () => {
// Display same text on `Text to display` as default
// when linktext has no text
if (!linkInfo.text) {
$linkText.val($linkUrl.val());
}
Expand Down Expand Up @@ -132,9 +136,9 @@ export default class LinkDialog {

this.ui.onDialogHidden(this.$dialog, () => {
// detach events
$linkText.off('input paste keypress');
$linkUrl.off('input paste keypress');
$linkBtn.off('click');
$linkText.off();
$linkUrl.off();
$linkBtn.off();

if (deferred.state() === 'pending') {
deferred.reject();
Expand Down
4 changes: 2 additions & 2 deletions src/js/base/module/VideoDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,8 @@ export default class VideoDialog {
});

this.ui.onDialogHidden(this.$dialog, () => {
$videoUrl.off('input propertychange keypress');
$videoBtn.off('click');
$videoUrl.off();
$videoBtn.off();

if (deferred.state() === 'pending') {
deferred.reject();
Expand Down

0 comments on commit 3d3c246

Please sign in to comment.