Skip to content

Commit

Permalink
Fix snippet issue when field has more that one %
Browse files Browse the repository at this point in the history
  • Loading branch information
Tam committed Aug 13, 2024
1 parent 3d0b463 commit 323d43e
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 22 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 5.0.0-rc5 - 2024-07-13
### Fixed
- Fix snippet issue when field has more that one %

## 5.0.0-rc4 - 2024-06-06
### Fixed
- Fix incorrect live preview URL used in keyword analysis
Expand Down
40 changes: 20 additions & 20 deletions resources/js/field/Snippet.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export default class Snippet {
.trim()
.replace(/[\r\n\t]/g, ' ')
.replace(/\s{2,}/g, ' ')
.replace('%', '%25')
.replace(/%/g, '%25')
);
}

Expand All @@ -51,15 +51,15 @@ export default class Snippet {
slug: this.slugField,
desc: this.descField,
};

this.title();
this.slugField && SEO.options.hasPreview && this.slug();
this.desc();
}

// Initializers
// =========================================================================

/**
* Sync up the main title input with the SEO one
* (if it's a new entry, or we don't have a title)
Expand Down Expand Up @@ -87,31 +87,31 @@ export default class Snippet {
this._observeMainForm();
this._observeAllInputs();
}

/**
* Sync up the SEO slug with crafts
*/
slug () {
const mainSlugField = document.getElementById('slug');

// Skip if we don't have a slug field (i.e. the homepage)
if (!mainSlugField) return;

const onSlugChange = () => {
this.slugField.textContent = mainSlugField.value;
};

mainSlugField.addEventListener('input', onSlugChange);

// Slug generation has a debounce that we need to account for to keep
// the slugs in sync
const title = document.getElementById('title');
title && title.addEventListener('input', debounce(onSlugChange, 500));

// Sync straight away (see above in title() as to why)
onSlugChange();
}

/**
* Adjust the height of the description TextArea to ensure it never scrolls,
* and handle descriptions that are longer than the recommended length.
Expand All @@ -123,44 +123,44 @@ export default class Snippet {
this.descField.style.height = this.descField.scrollHeight + 'px';
}, 1);
};

// Prevent line breaks
this.descField.addEventListener('keydown', e => {
if (e.keyCode === 13) e.preventDefault();
});

// Cleanse line breaks & check length
this.descField.addEventListener('input', () => {
this.descField.value =
this.descField.value.replace(/(\r\n|\r|\n)/gm, ' ');

if (this.descField.value.length > 313)
this.descField.classList.add('invalid');
else
this.descField.classList.remove('invalid');

adjustHeight();
});

// Adjust height TextArea size changes

// On tab change
if (document.getElementById('tabs')) {
const tabs = document.querySelectorAll('#tabs a.tab');
for (let i = 0; i < tabs.length; i++) {
tabs[i].addEventListener('click', adjustHeight);
}
}

// On open / close live preview
if (Craft.livePreview) {
Craft.livePreview.on('enter', adjustHeight);
Craft.livePreview.on('exit', adjustHeight);
}

// On window resize
window.addEventListener('resize', adjustHeight);

// Set initial height (extra delay to fix FF bug)
setTimeout(() => {
adjustHeight();
Expand Down Expand Up @@ -389,5 +389,5 @@ export default class Snippet {
);
}
}

}
2 changes: 1 addition & 1 deletion src/web/assets/js/SeoField.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/web/assets/js/SeoField.min.js.map

Large diffs are not rendered by default.

0 comments on commit 323d43e

Please sign in to comment.