Media modal/grid: remove thumbnail resizing from JS, only keep setting number of columns. Props avryl, see #27423.

Built from https://develop.svn.wordpress.org/trunk@29376


git-svn-id: http://core.svn.wordpress.org/trunk@29154 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Andrew Ozz 2014-08-05 05:20:18 +00:00
parent e1eab74aa6
commit e6b0d0c9ee
7 changed files with 298 additions and 291 deletions

View File

@ -700,7 +700,7 @@
*/
.attachments {
margin: 0;
padding-left: 16px;
padding: 8px;
-webkit-overflow-scrolling: touch;
}
@ -710,101 +710,74 @@
.attachment {
position: relative;
float: right;
padding: 0;
margin: 0 10px 20px;
padding: 8px;
margin: 0;
color: #464646;
cursor: pointer;
list-style: none;
text-align: center;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
width: 20%;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
.attachment:focus {
-webkit-box-shadow:
0 0 0 1px #5b9dd9,
0 0 2px 2px #5b9dd9;
inset 0 0 0 5px #fff,
inset 0 0 1px 7px #5b9dd9;
box-shadow:
0 0 0 1px #5b9dd9,
0 0 2px 2px #5b9dd9;
inset 0 0 0 5px #fff,
inset 0 0 1px 7px #5b9dd9;
outline: none;
}
.selected.attachment {
-webkit-box-shadow:
0 0 0 1px #fff,
0 0 0 3px #ccc;
inset 0 0 0 5px #fff,
inset 0 0 0 7px #ccc;
box-shadow:
0 0 0 1px #fff,
0 0 0 3px #ccc;
}
.selected.attachment:focus {
-webkit-box-shadow:
0 0 0 1px #fff,
0 0 0 5px #1e8cbe;
box-shadow:
0 0 0 1px #fff,
0 0 0 5px #1e8cbe;
inset 0 0 0 5px #fff,
inset 0 0 0 7px #ccc;
}
.attachment-preview {
position: relative;
width: 199px;
height: 199px;
-webkit-box-shadow:
inset 0 0 15px rgba( 0, 0, 0, 0.1 ),
inset 0 0 0 1px rgba( 0, 0, 0, 0.05 );
box-shadow:
inset 0 0 15px rgba( 0, 0, 0, 0.1 ),
inset 0 0 0 1px rgba( 0, 0, 0, 0.05 );
background: #eee;
cursor: pointer;
}
.attachment-preview:before {
content: '';
display: block;
padding-top: 100%;
}
.attachment .icon {
margin: 0 auto;
overflow: hidden;
padding-top: 20%;
}
.attachment .thumbnail {
display: block;
overflow: hidden;
position: absolute;
top: 0;
left: 0;
bottom: 0;
right: 0;
margin: 0 auto;
overflow: hidden;
}
.attachment .portrait img {
max-width: 100%;
}
.attachment .landscape img {
max-height: 100%;
}
.attachment-preview.type-audio .thumbnail,
.attachment-preview.type-video .thumbnail {
z-index: 1;
margin: 1%;
max-width: 98%;
max-height: 98%;
}
.media-frame-content .attachment-preview.type-audio .icon,
.media-frame-content .attachment-preview.type-video .icon {
z-index: 2;
background: #f1f1f1;
position: relative;
padding: 0;
top: 15%;
right: auto;
left: auto;
}
.attachment-preview.type-audio .filename,
.attachment-preview.type-video .filename {
z-index: 3;
}
.attachment-preview .thumbnail:after {
.attachment .thumbnail:after {
content: '';
display: block;
position: absolute;
@ -831,7 +804,7 @@
width: 100%;
height: 100%;
-webkit-transform: translate( 50%, 50% );
-ms-transform: translate( 50%, 50% );
-ms-transform: translate(50%,50%); /* Fails with spaces?? Weird! */
transform: translate( 50%, 50% );
}
@ -848,7 +821,6 @@
bottom: 0;
overflow: hidden;
max-height: 100%;
word-wrap: break-word;
text-align: center;
font-weight: bold;
@ -861,11 +833,6 @@
padding: 5px 10px;
}
.attachment-preview .thumbnail {
width: 199px;
height: 199px;
}
.attachment .thumbnail img {
position: absolute;
}
@ -907,8 +874,8 @@
width: 24px;
position: absolute;
z-index: 10;
top: -6px;
left: -6px;
top: 0;
left: 0;
outline: none;
background: #eee;
-webkit-box-shadow: 0 0 0 1px #fff, 0 0 0 2px rgba( 0, 0, 0, 0.15 );
@ -930,21 +897,26 @@
display: block;
}
.selected.attachment:focus,
.attachment.details,
.media-frame.mode-grid .selected.attachment {
-webkit-box-shadow: 0 0 0 1px #fff,
0 0 0 5px #1e8cbe;
box-shadow: 0 0 0 1px #fff,
0 0 0 5px #1e8cbe;
-webkit-box-shadow:
inset 0 0 0 3px #fff,
inset 0 0 0 7px #1e8cbe;
box-shadow:
inset 0 0 0 3px #fff,
inset 0 0 0 7px #1e8cbe;
}
.attachment.details .check,
.attachment.selected .check:focus,
.media-frame.mode-grid .attachment.selected .check {
background-color: #1e8cbe;
-webkit-box-shadow: 0 0 0 1px #fff,
-webkit-box-shadow:
0 0 0 1px #fff,
0 0 0 2px #1e8cbe;
box-shadow: 0 0 0 1px #fff,
box-shadow:
0 0 0 1px #fff,
0 0 0 2px #1e8cbe;
}
@ -971,7 +943,7 @@
position: relative;
display: block;
width: 100%;
margin: -1px 0 0;
margin: 0;
padding: 8px;
font-size: 12px;
-webkit-border-radius: 0;
@ -1381,16 +1353,32 @@
.media-selection .attachments {
display: inline-block;
height: 48px;
margin-top: 5px;
margin: 6px;
padding: 0;
overflow: hidden;
vertical-align: top;
}
.media-selection .attachment {
width: 48px;
padding: 0;
margin: 0;
-webkit-box-shadow: none;
box-shadow: none;
}
.media-selection .attachment .thumbnail {
top: 4px;
left: 4px;
bottom: 4px;
right: 4px;
}
.media-selection .attachment .icon {
width: 50%;
}
.attachment.selection.selected {
/*
.attachment.selection.selected .thumbnail {
-webkit-box-shadow: none;
box-shadow: none;
}
@ -1413,8 +1401,8 @@
0 0 0 1px #fff,
0 0 0 4px #1e8cbe;
}
.media-selection .attachment.selection.details {
*/
.media-selection .attachment.selection.details .thumbnail {
-webkit-box-shadow:
0 0 0 1px #fff,
0 0 0 3px #1e8cbe;
@ -2914,3 +2902,51 @@
max-width: none !important;
}
}
.attachments[data-columns="1"] .attachment {
width: 100%;
}
.attachments[data-columns="2"] .attachment {
width: 50%;
}
.attachments[data-columns="3"] .attachment {
width: 33.3%;
}
.attachments[data-columns="4"] .attachment {
width: 25%;
}
.attachments[data-columns="5"] .attachment {
width: 20%;
}
.attachments[data-columns="6"] .attachment {
width: 16.6%;
}
.attachments[data-columns="7"] .attachment {
width: 14.2%;
}
.attachments[data-columns="8"] .attachment {
width: 12.5%;
}
.attachments[data-columns="9"] .attachment {
width: 11.1%;
}
.attachments[data-columns="10"] .attachment {
width: 10%;
}
.attachments[data-columns="11"] .attachment {
width: 9%;
}
.attachments[data-columns="12"] .attachment {
width: 8.3%;
}

File diff suppressed because one or more lines are too long

View File

@ -700,7 +700,7 @@
*/
.attachments {
margin: 0;
padding-right: 16px;
padding: 8px;
-webkit-overflow-scrolling: touch;
}
@ -710,101 +710,74 @@
.attachment {
position: relative;
float: left;
padding: 0;
margin: 0 10px 20px;
padding: 8px;
margin: 0;
color: #464646;
cursor: pointer;
list-style: none;
text-align: center;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
width: 20%;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
.attachment:focus {
-webkit-box-shadow:
0 0 0 1px #5b9dd9,
0 0 2px 2px #5b9dd9;
inset 0 0 0 5px #fff,
inset 0 0 1px 7px #5b9dd9;
box-shadow:
0 0 0 1px #5b9dd9,
0 0 2px 2px #5b9dd9;
inset 0 0 0 5px #fff,
inset 0 0 1px 7px #5b9dd9;
outline: none;
}
.selected.attachment {
-webkit-box-shadow:
0 0 0 1px #fff,
0 0 0 3px #ccc;
inset 0 0 0 5px #fff,
inset 0 0 0 7px #ccc;
box-shadow:
0 0 0 1px #fff,
0 0 0 3px #ccc;
}
.selected.attachment:focus {
-webkit-box-shadow:
0 0 0 1px #fff,
0 0 0 5px #1e8cbe;
box-shadow:
0 0 0 1px #fff,
0 0 0 5px #1e8cbe;
inset 0 0 0 5px #fff,
inset 0 0 0 7px #ccc;
}
.attachment-preview {
position: relative;
width: 199px;
height: 199px;
-webkit-box-shadow:
inset 0 0 15px rgba( 0, 0, 0, 0.1 ),
inset 0 0 0 1px rgba( 0, 0, 0, 0.05 );
box-shadow:
inset 0 0 15px rgba( 0, 0, 0, 0.1 ),
inset 0 0 0 1px rgba( 0, 0, 0, 0.05 );
background: #eee;
cursor: pointer;
}
.attachment-preview:before {
content: '';
display: block;
padding-top: 100%;
}
.attachment .icon {
margin: 0 auto;
overflow: hidden;
padding-top: 20%;
}
.attachment .thumbnail {
display: block;
overflow: hidden;
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
margin: 0 auto;
overflow: hidden;
}
.attachment .portrait img {
max-width: 100%;
}
.attachment .landscape img {
max-height: 100%;
}
.attachment-preview.type-audio .thumbnail,
.attachment-preview.type-video .thumbnail {
z-index: 1;
margin: 1%;
max-width: 98%;
max-height: 98%;
}
.media-frame-content .attachment-preview.type-audio .icon,
.media-frame-content .attachment-preview.type-video .icon {
z-index: 2;
background: #f1f1f1;
position: relative;
padding: 0;
top: 15%;
left: auto;
right: auto;
}
.attachment-preview.type-audio .filename,
.attachment-preview.type-video .filename {
z-index: 3;
}
.attachment-preview .thumbnail:after {
.attachment .thumbnail:after {
content: '';
display: block;
position: absolute;
@ -831,7 +804,7 @@
width: 100%;
height: 100%;
-webkit-transform: translate( 50%, 50% );
-ms-transform: translate( 50%, 50% );
-ms-transform: translate(50%,50%); /* Fails with spaces?? Weird! */
transform: translate( 50%, 50% );
}
@ -848,7 +821,6 @@
bottom: 0;
overflow: hidden;
max-height: 100%;
word-wrap: break-word;
text-align: center;
font-weight: bold;
@ -861,11 +833,6 @@
padding: 5px 10px;
}
.attachment-preview .thumbnail {
width: 199px;
height: 199px;
}
.attachment .thumbnail img {
position: absolute;
}
@ -907,8 +874,8 @@
width: 24px;
position: absolute;
z-index: 10;
top: -6px;
right: -6px;
top: 0;
right: 0;
outline: none;
background: #eee;
-webkit-box-shadow: 0 0 0 1px #fff, 0 0 0 2px rgba( 0, 0, 0, 0.15 );
@ -930,21 +897,26 @@
display: block;
}
.selected.attachment:focus,
.attachment.details,
.media-frame.mode-grid .selected.attachment {
-webkit-box-shadow: 0 0 0 1px #fff,
0 0 0 5px #1e8cbe;
box-shadow: 0 0 0 1px #fff,
0 0 0 5px #1e8cbe;
-webkit-box-shadow:
inset 0 0 0 3px #fff,
inset 0 0 0 7px #1e8cbe;
box-shadow:
inset 0 0 0 3px #fff,
inset 0 0 0 7px #1e8cbe;
}
.attachment.details .check,
.attachment.selected .check:focus,
.media-frame.mode-grid .attachment.selected .check {
background-color: #1e8cbe;
-webkit-box-shadow: 0 0 0 1px #fff,
-webkit-box-shadow:
0 0 0 1px #fff,
0 0 0 2px #1e8cbe;
box-shadow: 0 0 0 1px #fff,
box-shadow:
0 0 0 1px #fff,
0 0 0 2px #1e8cbe;
}
@ -971,7 +943,7 @@
position: relative;
display: block;
width: 100%;
margin: -1px 0 0;
margin: 0;
padding: 8px;
font-size: 12px;
-webkit-border-radius: 0;
@ -1381,16 +1353,32 @@
.media-selection .attachments {
display: inline-block;
height: 48px;
margin-top: 5px;
margin: 6px;
padding: 0;
overflow: hidden;
vertical-align: top;
}
.media-selection .attachment {
width: 48px;
padding: 0;
margin: 0;
-webkit-box-shadow: none;
box-shadow: none;
}
.media-selection .attachment .thumbnail {
top: 4px;
right: 4px;
bottom: 4px;
left: 4px;
}
.media-selection .attachment .icon {
width: 50%;
}
.attachment.selection.selected {
/*
.attachment.selection.selected .thumbnail {
-webkit-box-shadow: none;
box-shadow: none;
}
@ -1413,8 +1401,8 @@
0 0 0 1px #fff,
0 0 0 4px #1e8cbe;
}
.media-selection .attachment.selection.details {
*/
.media-selection .attachment.selection.details .thumbnail {
-webkit-box-shadow:
0 0 0 1px #fff,
0 0 0 3px #1e8cbe;
@ -2914,3 +2902,51 @@
max-width: none !important;
}
}
.attachments[data-columns="1"] .attachment {
width: 100%;
}
.attachments[data-columns="2"] .attachment {
width: 50%;
}
.attachments[data-columns="3"] .attachment {
width: 33.3%;
}
.attachments[data-columns="4"] .attachment {
width: 25%;
}
.attachments[data-columns="5"] .attachment {
width: 20%;
}
.attachments[data-columns="6"] .attachment {
width: 16.6%;
}
.attachments[data-columns="7"] .attachment {
width: 14.2%;
}
.attachments[data-columns="8"] .attachment {
width: 12.5%;
}
.attachments[data-columns="9"] .attachment {
width: 11.1%;
}
.attachments[data-columns="10"] .attachment {
width: 10%;
}
.attachments[data-columns="11"] .attachment {
width: 9%;
}
.attachments[data-columns="12"] .attachment {
width: 8.3%;
}

File diff suppressed because one or more lines are too long

View File

@ -630,14 +630,6 @@
}) );
}
if ( ! this.get('edge') ) {
this.set( 'edge', 150 );
}
if ( ! this.get('gutter') ) {
this.set( 'gutter', 8 );
}
this.resetDisplays();
},
@ -838,7 +830,7 @@
describe: true,
displaySettings: true,
dragInfo: true,
edge: 199,
idealColumnWidth: 170,
editing: false,
priority: 60,
@ -991,7 +983,7 @@
describe: true,
dragInfo: true,
edge: 199,
idealColumnWidth: 170,
editing: false,
priority: 60,
SettingsView: false,
@ -2178,6 +2170,7 @@
display: state.has('display') ? state.get('display') : state.get('displaySettings'),
dragInfo: state.get('dragInfo'),
idealColumnWidth: state.get('idealColumnWidth'),
suggestedWidth: state.get('suggestedWidth'),
suggestedHeight: state.get('suggestedHeight'),
@ -4805,8 +4798,8 @@
arrowEvent: function( event ) {
var attachment = $('.attachments-browser .attachment'),
attachmentsWidth = $('.attachments-browser .attachments').width(),
thumbnailWidth = attachment.first().innerWidth() + 16,
thumbnailsPerRow = Math.floor(attachmentsWidth/thumbnailWidth),
thumbnailWidth = attachment.first().width(),
thumbnailsPerRow = Math.round( attachmentsWidth / thumbnailWidth ),
totalThumnails = attachment.length,
totalRows = Math.ceil(totalThumnails/thumbnailsPerRow),
thisIndex = attachment.filter( ':focus' ).index(),
@ -5218,8 +5211,6 @@
tabIndex: -1
},
cssTemplate: media.template('attachments-css'),
initialize: function() {
this.el.id = _.uniqueId('__attachments-view-');
@ -5228,7 +5219,8 @@
refreshThreshold: 3,
AttachmentView: media.view.Attachment,
sortable: false,
resize: true
resize: true,
idealColumnWidth: 150
});
this._viewsByCid = {};
@ -5258,56 +5250,35 @@
this.initSortable();
_.bindAll( this, 'css' );
this.model.on( 'change:edge change:gutter', this.css, this );
this._resizeCss = _.debounce( _.bind( this.css, this ), this.refreshSensitivity );
_.bindAll( this, 'setColumns' );
if ( this.options.resize ) {
$(window).on( 'resize.attachments', this._resizeCss );
$( window ).on( 'resize.attachments', this.setColumns );
}
// Call this.css() after this view has been rendered in the DOM so
// Call this.setColumns() after this view has been rendered in the DOM so
// attachments get proper width applied.
_.defer( this.css, this );
_.defer( this.setColumns, this );
},
dispose: function() {
this.collection.props.off( null, null, this );
$(window).off( 'resize.attachments', this._resizeCss );
$( window ).off( 'resize.attachments', this.setColumns );
/**
* call 'dispose' directly on the parent class
*/
media.View.prototype.dispose.apply( this, arguments );
},
css: function() {
var $css = $( '#' + this.el.id + '-css' );
setColumns: function() {
var prev = this.columns;
if ( $css.length ) {
$css.remove();
this.columns = Math.round( this.$el.width() / this.options.idealColumnWidth );
if ( prev !== this.columns ) {
this.$el.attr( 'data-columns', this.columns );
}
media.view.Attachments.$head().append( this.cssTemplate({
id: this.el.id,
edge: this.edge(),
gutter: this.model.get('gutter')
}) );
},
/**
* @returns {Number}
*/
edge: function() {
var edge = this.model.get('edge'),
gutter, width, columns;
if ( ! this.$el.is(':visible') ) {
return edge;
}
gutter = this.model.get('gutter') * 2;
width = this.$el.width() - gutter;
columns = Math.ceil( width / ( edge + gutter ) );
edge = Math.floor( ( width - ( columns * gutter ) ) / columns );
return edge;
},
initSortable: function() {
@ -5453,13 +5424,6 @@
});
}
}
}, {
$head: (function() {
var $head;
return function() {
return $head = $head || $('head');
};
}())
});
/**
@ -5895,6 +5859,7 @@
model: this.model,
sortable: this.options.sortable,
scrollElement: this.options.scrollElement,
idealColumnWidth: this.options.idealColumnWidth,
// The single `Attachment` view to be used in the `Attachments` view.
AttachmentView: this.options.AttachmentView
@ -6003,10 +5968,7 @@
controller: this.controller,
collection: this.collection,
selection: this.collection,
model: new Backbone.Model({
edge: 40,
gutter: 5
})
model: new Backbone.Model()
});
this.views.set( '.selection-view', this.attachments );

File diff suppressed because one or more lines are too long

View File

@ -414,24 +414,26 @@ function wp_print_media_templates() {
<script type="text/html" id="tmpl-attachment">
<div class="attachment-preview js--select-attachment type-{{ data.type }} subtype-{{ data.subtype }} {{ data.orientation }}">
<# if ( data.uploading ) { #>
<div class="media-progress-bar"><div></div></div>
<# } else if ( 'image' === data.type ) { #>
<div class="thumbnail">
<# if ( data.uploading ) { #>
<div class="media-progress-bar"><div>
<# } else if ( 'image' === data.type ) { #>
<div class="centered">
<img src="{{ data.size.url }}" draggable="false" alt="" />
</div>
<# } else { #>
<div class="centered">
<# if ( data.thumb && data.thumb.src && data.thumb.src !== data.icon ) { #>
<img src="{{ data.thumb.src }}" class="thumbnail" draggable="false" />
<# } else { #>
<img src="{{ data.icon }}" class="icon" draggable="false" />
<# } #>
</div>
<# } else {
if ( data.thumb && data.thumb.src && data.thumb.src !== data.icon ) {
#><img src="{{ data.thumb.src }}" class="thumbnail" draggable="false" /><#
} else {
#><img src="{{ data.icon }}" class="icon" draggable="false" /><#
} #>
<div class="filename">
<div>{{ data.filename }}</div>
</div>
<# } #>
</div>
<# if ( data.buttons.close ) { #>
<a class="close media-modal-icon" href="#" title="<?php esc_attr_e('Remove'); ?>"></a>
<# } #>
@ -822,35 +824,6 @@ function wp_print_media_templates() {
</div>
</script>
<script type="text/html" id="tmpl-attachments-css">
<style type="text/css" id="{{ data.id }}-css">
#{{ data.id }} {
padding: 0 {{ data.gutter }}px;
}
#{{ data.id }} .attachment {
margin: {{ data.gutter }}px;
width: {{ data.edge }}px;
}
#{{ data.id }} .attachment-preview,
#{{ data.id }} .attachment-preview .thumbnail {
width: {{ data.edge }}px;
height: {{ data.edge }}px;
}
#{{ data.id }} .portrait .thumbnail img {
max-width: {{ data.edge }}px;
height: auto;
}
#{{ data.id }} .landscape .thumbnail img {
width: auto;
max-height: {{ data.edge }}px;
}
</style>
</script>
<script type="text/html" id="tmpl-image-details">
<div class="media-embed">
<div class="embed-media-settings">