Skip to content

Commit 99cd7c9

Browse files
change: preview-block-id to data-preview-block-id
1 parent e756bd9 commit 99cd7c9

File tree

6 files changed

+21
-16
lines changed

6 files changed

+21
-16
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
44

55
The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/).
66

7+
## 4.0.0 - 2024-11-13
8+
### Breaking Changes
9+
- Changed the attribute name for tracking preview blocks from `preview-block-id` to `data-preview-block-id`. Update your template code accordingly.
10+
- `craft.previewMate.previewBlock` twig variable now returns the HTML attribute with `data-` prefixed to match the new `data-preview-block-id` attribute.
11+
712
## 3.0.2 - 2024-11-13
813
### Updated
914
- `craft.previewMate.previewBlock` twig variable now uses `Craft::$app->request->isPreview` internally to check if the current request is a preview request.

README.md

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# PreviewMate v3
1+
# PreviewMate v4
22

33
Find live preview matrix blocks with ease.
44

@@ -20,9 +20,9 @@ To install the plugin, follow these instructions.
2020

2121
## How to use
2222

23-
![PreviewMate v3 Demo](./resources/img/PreviewMate_v3_Demo.gif)
23+
![PreviewMate v4 Demo](./resources/img/PreviewMate_v4_Demo.gif)
2424

25-
Preview blocks will be tracked in live preview when adding the `preview-block-id` attribute to the entry's HTML element.
25+
Preview blocks will be tracked in live preview by adding `data-preview-block-id` attribute to the entry's HTML element.
2626

2727
```twig
2828
{# option 1 (recommended) - only rendered in live preview #}
@@ -31,10 +31,10 @@ Preview blocks will be tracked in live preview when adding the `preview-block-id
3131
or
3232
```twig
3333
{# option 2 - manually set the preview block id #}
34-
preview-block-id="{{ entry.id }}"
34+
data-preview-block-id="{{ entry.id }}"
3535
```
3636

37-
That element will now be tracked in the live preview. Clicking on it in the preview will scroll you to the element in the editor. Hovering over it will highlight both the editor and preview elements.
37+
Clicking a preview block will now scroll to and highlight the editor block.
3838

3939
## Usage example
4040

@@ -50,14 +50,14 @@ That element will now be tracked in the live preview. Clicking on it in the prev
5050
{% endfor %}
5151
```
5252

53-
It's recommended to add styles for preview blocks using `preview-block-id`.
54-
The hovering style will only be toggled during live preview.
53+
It's recommended to add styles for preview blocks using `data-preview-block-id`.
54+
Adding the following styles will highlight the preview block on hover.
5555

5656
```css
57-
[preview-block-id] {
57+
[data-preview-block-id] {
5858
position: relative;
5959
}
60-
[preview-block-id]::after {
60+
[data-preview-block-id]::after {
6161
content: '';
6262
position: absolute;
6363
top: 0;
@@ -69,7 +69,7 @@ The hovering style will only be toggled during live preview.
6969
opacity: 0;
7070
transition: opacity 300ms ease;
7171
}
72-
[preview-block-id].preview-block-hover::after {
72+
[data-preview-block-id].preview-block-hover::after {
7373
opacity: 1;
7474
}
7575
```

example/templates/_page-builder/index.twig

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88

99
{# css to highlight the preview block in live preview when hovering #}
1010
{% css %}
11-
[preview-block-id] {
11+
[data-preview-block-id] {
1212
position: relative;
1313
}
14-
[preview-block-id]::after {
14+
[data-preview-block-id]::after {
1515
content: '';
1616
position: absolute;
1717
top: 0;
@@ -23,7 +23,7 @@
2323
opacity: 0;
2424
transition: opacity 300ms ease;
2525
}
26-
[preview-block-id].preview-block-hover::after {
26+
[data-preview-block-id].preview-block-hover::after {
2727
opacity: 1;
2828
}
2929
{% endcss %}

resources/img/PreviewMate_v4_Demo.gif

3.16 MB
Loading

src/assetbundles/previewmate/dist/js/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,11 @@
8181
},
8282

8383
attatchPreviewBlockEventListeners(iframe) {
84-
const previewBlocks = iframe.contentWindow.document.body.querySelectorAll('[preview-block-id]');
84+
const previewBlocks = iframe.contentWindow.document.body.querySelectorAll('[data-preview-block-id]');
8585

8686
previewBlocks.forEach(function (previewBlock) {
8787

88-
const editorBlock = Craft.PreviewMate.lpEditorContainer.querySelector(`[data-id="${previewBlock.getAttribute('preview-block-id')}"]`);
88+
const editorBlock = Craft.PreviewMate.lpEditorContainer.querySelector(`[data-id="${previewBlock.dataset.previewBlockId}"]`);
8989
if (!editorBlock) return;
9090

9191
previewBlock.addEventListener('click', function () {

src/variables/PreviewMateVariable.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ public function previewBlock(Entry $entry) {
1515
$isPreview = Craft::$app->request->isPreview ?? false;
1616
}
1717

18-
return $isPreview ? Template::raw("preview-block-id=\"" . $entry->id . "\"") : '';
18+
return $isPreview ? Template::raw("data-preview-block-id=\"" . $entry->id . "\"") : '';
1919
}
2020
}

0 commit comments

Comments
 (0)