Skip to content

Commit 127b151

Browse files
authored
Merge branch 'WordPress:trunk' into trunk
2 parents 5c5c375 + 60f7663 commit 127b151

8 files changed

Lines changed: 135 additions & 16 deletions

File tree

src/js/media/models/attachments.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,6 @@ var Attachments = Backbone.Collection.extend(/** @lends wp.media.model.Attachmen
212212
this.observers.push( attachments );
213213

214214
attachments.on( 'add change remove', this._validateHandler, this );
215-
attachments.on( 'add', this._addToTotalAttachments, this );
216-
attachments.on( 'remove', this._removeFromTotalAttachments, this );
217215
attachments.on( 'reset', this._validateAllHandler, this );
218216
this.validateAll( attachments );
219217
return this;
@@ -310,6 +308,12 @@ var Attachments = Backbone.Collection.extend(/** @lends wp.media.model.Attachmen
310308
this.reset( [], { silent: true } );
311309
this.observe( attachments );
312310

311+
// Bind total attachment count tracking only to the mirrored query
312+
// collection, not to additional observed collections (e.g. selection).
313+
// See Trac #65053.
314+
attachments.on( 'add', this._addToTotalAttachments, this );
315+
attachments.on( 'remove', this._removeFromTotalAttachments, this );
316+
313317
// Used for the search results.
314318
this.trigger( 'attachments:received', this );
315319
return this;

src/wp-admin/css/themes.css

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1748,6 +1748,7 @@ body.full-overlay-active {
17481748
background: transparent;
17491749
border: none;
17501750
height: 45px;
1751+
min-width: 50px;
17511752
padding: 0 3px;
17521753
margin: 0 0 0 -4px;
17531754
box-shadow: none;
@@ -1767,9 +1768,9 @@ body.full-overlay-active {
17671768
.wp-full-overlay-footer .devices button:before {
17681769
display: inline-block;
17691770
-webkit-font-smoothing: antialiased;
1770-
font: normal 20px/30px "dashicons";
1771+
font: normal 20px/20px "dashicons";
17711772
vertical-align: top;
1772-
margin: 3px 0;
1773+
margin: 0 0 -2px;
17731774
padding: 4px 8px;
17741775
color: #646970;
17751776
}
@@ -1812,6 +1813,12 @@ body.full-overlay-active {
18121813
content: "\f470" / '';
18131814
}
18141815

1816+
.wp-full-overlay-footer .devices .devices__preview-label {
1817+
display: block;
1818+
font-size: 10px;
1819+
line-height: 1;
1820+
}
1821+
18151822
@media screen and (max-width: 1024px) {
18161823
.wp-full-overlay-footer .devices {
18171824
display: none;

src/wp-admin/customize.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@
275275
</button>
276276
<?php $previewable_devices = $wp_customize->get_previewable_devices(); ?>
277277
<?php if ( ! empty( $previewable_devices ) ) : ?>
278-
<div class="devices-wrapper">
278+
<div class="devices-wrapper" role="group" aria-label="<?php echo esc_attr_x( 'Responsive Views', 'label for responsive previews group' ); ?>">
279279
<div class="devices">
280280
<?php foreach ( (array) $previewable_devices as $device => $settings ) : ?>
281281
<?php
@@ -289,7 +289,7 @@
289289
}
290290
?>
291291
<button type="button" class="<?php echo esc_attr( $class ); ?>" aria-pressed="<?php echo esc_attr( $active ); ?>" data-device="<?php echo esc_attr( $device ); ?>">
292-
<span class="screen-reader-text"><?php echo esc_html( $settings['label'] ); ?></span>
292+
<span class="devices__preview-label"><?php echo esc_html( $settings['label'] ); ?></span>
293293
</button>
294294
<?php endforeach; ?>
295295
</div>

src/wp-includes/class-wp-customize-manager.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5044,14 +5044,14 @@ public function customize_pane_settings() {
50445044
public function get_previewable_devices() {
50455045
$devices = array(
50465046
'desktop' => array(
5047-
'label' => __( 'Enter desktop preview mode' ),
5047+
'label' => __( 'Desktop' ),
50485048
'default' => true,
50495049
),
50505050
'tablet' => array(
5051-
'label' => __( 'Enter tablet preview mode' ),
5051+
'label' => __( 'Tablet' ),
50525052
),
50535053
'mobile' => array(
5054-
'label' => __( 'Enter mobile preview mode' ),
5054+
'label' => __( 'Mobile' ),
50555055
),
50565056
);
50575057

tests/phpunit/tests/customize/manager.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3519,14 +3519,14 @@ public function test_get_previewable_devices() {
35193519
// The default devices list.
35203520
$default_devices = array(
35213521
'desktop' => array(
3522-
'label' => __( 'Enter desktop preview mode' ),
3522+
'label' => __( 'Desktop' ),
35233523
'default' => true,
35243524
),
35253525
'tablet' => array(
3526-
'label' => __( 'Enter tablet preview mode' ),
3526+
'label' => __( 'Tablet' ),
35273527
),
35283528
'mobile' => array(
3529-
'label' => __( 'Enter mobile preview mode' ),
3529+
'label' => __( 'Mobile' ),
35303530
),
35313531
);
35323532

@@ -3551,7 +3551,7 @@ public function test_get_previewable_devices() {
35513551
private function filtered_device_list() {
35523552
return array(
35533553
'custom-device' => array(
3554-
'label' => __( 'Enter custom-device preview mode' ),
3554+
'label' => __( 'Custom device' ),
35553555
'default' => true,
35563556
),
35573557
);

tests/qunit/fixtures/customize-settings.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,14 +146,14 @@ window._wpCustomizeSettings = {
146146
},
147147
'previewableDevices': {
148148
'desktop': {
149-
'label': 'Enter desktop preview mode',
149+
'label': 'Desktop',
150150
'default': true
151151
},
152152
'tablet': {
153-
'label': 'Enter tablet preview mode'
153+
'label': 'Tablet'
154154
},
155155
'mobile': {
156-
'label': 'Enter mobile preview mode'
156+
'label': 'Mobile'
157157
}
158158
},
159159
initialClientTimestamp: 1506510531595,

tests/qunit/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@
166166
<script src="wp-admin/js/widgets/test-media-image-widget.js"></script>
167167
<script src="wp-admin/js/widgets/test-media-gallery-widget.js"></script>
168168
<script src="wp-admin/js/widgets/test-media-video-widget.js"></script>
169+
<script src="wp-includes/js/media/test-models.js"></script>
169170

170171
<!-- Customizer templates for sections -->
171172
<script type="text/html" id="tmpl-customize-section-default">
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
/* globals wp */
2+
/* jshint qunit: true */
3+
/* eslint-env qunit */
4+
5+
( function () {
6+
'use strict';
7+
8+
QUnit.module( 'wp.media.model.Attachments' );
9+
10+
/*
11+
* Trac #65053: opening the media modal via "Set featured image" or
12+
* an Image block reported an incorrect "Showing X of Y" total because
13+
* Attachments#observe() bound the totalAttachments trackers to every
14+
* observed collection, including the Selection. Selection mutations
15+
* therefore mutated the mirrored Query's totalAttachments.
16+
*
17+
* The library mirrors a Query (which owns totalAttachments) AND
18+
* additionally observes a Selection (so a pre-existing featured image
19+
* stays visible in the grid). Only the Query should drive the count.
20+
*/
21+
QUnit.test(
22+
'observing a selection does not corrupt totalAttachments (Trac #65053)',
23+
function ( assert ) {
24+
var Attachments = wp.media.model.Attachments,
25+
Selection = wp.media.model.Selection,
26+
Attachment = wp.media.model.Attachment,
27+
query,
28+
library,
29+
selection;
30+
31+
// Stand-in for a Query collection: the source of truth for totalAttachments.
32+
query = new Attachments();
33+
query.totalAttachments = 8;
34+
35+
// The library is what AttachmentsBrowser renders. It mirrors the query.
36+
library = new Attachments();
37+
library.mirror( query );
38+
39+
assert.strictEqual(
40+
library.getTotalAttachments(),
41+
8,
42+
'precondition: getTotalAttachments() reflects the mirrored query total'
43+
);
44+
45+
// FeaturedImage / ReplaceImage controllers additionally observe the selection.
46+
selection = new Selection( [], { multiple: false } );
47+
library.observe( selection );
48+
49+
// Adding to the selection must not mutate the mirrored query's total.
50+
selection.add( new Attachment( { id: 42 } ) );
51+
assert.strictEqual(
52+
library.getTotalAttachments(),
53+
8,
54+
'add to observed selection leaves totalAttachments untouched'
55+
);
56+
57+
// Single-select swap: Selection#add internally remove()s prior models
58+
// before adding the new one. Both events must be ignored by the count.
59+
selection.add( new Attachment( { id: 99 } ) );
60+
assert.strictEqual(
61+
library.getTotalAttachments(),
62+
8,
63+
'single-select swap on observed selection leaves totalAttachments untouched'
64+
);
65+
66+
// Removing from the selection must also leave the total alone.
67+
selection.remove( selection.models );
68+
assert.strictEqual(
69+
library.getTotalAttachments(),
70+
8,
71+
'remove from observed selection leaves totalAttachments untouched'
72+
);
73+
}
74+
);
75+
76+
QUnit.test(
77+
'mirrored query add/remove still drives totalAttachments',
78+
function ( assert ) {
79+
var Attachments = wp.media.model.Attachments,
80+
Attachment = wp.media.model.Attachment,
81+
query,
82+
library,
83+
attachment;
84+
85+
query = new Attachments();
86+
query.totalAttachments = 5;
87+
88+
library = new Attachments();
89+
library.mirror( query );
90+
91+
attachment = new Attachment( { id: 1 } );
92+
query.add( attachment );
93+
assert.strictEqual(
94+
library.getTotalAttachments(),
95+
6,
96+
'adding to the mirrored query increments totalAttachments'
97+
);
98+
99+
query.remove( attachment );
100+
assert.strictEqual(
101+
library.getTotalAttachments(),
102+
5,
103+
'removing from the mirrored query decrements totalAttachments'
104+
);
105+
}
106+
);
107+
} )();

0 commit comments

Comments
 (0)