diff --git a/src/wp-includes/css/media-views.css b/src/wp-includes/css/media-views.css index 4fcb24458b..ecac256426 100644 --- a/src/wp-includes/css/media-views.css +++ b/src/wp-includes/css/media-views.css @@ -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,13 +804,13 @@ 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% ); } .attachment .thumbnail .centered img { -webkit-transform: translate( -50%, -50% ); - -ms-transform: translate( -50%, -50% ); + -ms-transform: translate(-50%,-50%); 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,22 +897,27 @@ 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, - 0 0 0 2px #1e8cbe; - box-shadow: 0 0 0 1px #fff, - 0 0 0 2px #1e8cbe; + -webkit-box-shadow: + 0 0 0 1px #fff, + 0 0 0 2px #1e8cbe; + box-shadow: + 0 0 0 1px #fff, + 0 0 0 2px #1e8cbe; } .media-frame.mode-grid .attachment .check { @@ -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; @@ -1218,7 +1190,7 @@ left: 0; right: 0; -webkit-transform: translateY( -50% ); - -ms-transform: translateY( -50% ); + -ms-transform: translateY(-50%); transform: translateY( -50% ); font-size: 40px; color: #fff; @@ -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; @@ -2056,7 +2044,7 @@ left: 0; right: 0; -webkit-transform: translateY( -50% ); - -ms-transform: translateY( -50% ); + -ms-transform: translateY(-50%); transform: translateY( -50% ); font-size: 3em; line-height: 1.3; @@ -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%; +} diff --git a/src/wp-includes/js/media-views.js b/src/wp-includes/js/media-views.js index 206acf6dc8..230794383a 100644 --- a/src/wp-includes/js/media-views.js +++ b/src/wp-includes/js/media-views.js @@ -630,14 +630,6 @@ }) ); } - if ( ! this.get('edge') ) { - this.set( 'edge', 150 ); - } - - if ( ! this.get('gutter') ) { - this.set( 'gutter', 8 ); - } - this.resetDisplays(); }, @@ -835,12 +827,12 @@ content: 'browse', toolbar: 'gallery-edit', - describe: true, - displaySettings: true, - dragInfo: true, - edge: 199, - editing: false, - priority: 60, + describe: true, + displaySettings: true, + dragInfo: true, + idealColumnWidth: 170, + editing: false, + priority: 60, // Don't sync the selection, as the Edit Gallery library // *is* the selection. @@ -989,12 +981,12 @@ // Region mode defaults. content: 'browse', - describe: true, - dragInfo: true, - edge: 199, - editing: false, - priority: 60, - SettingsView: false, + describe: true, + dragInfo: true, + idealColumnWidth: 170, + editing: false, + priority: 60, + SettingsView: false, // Don't sync the selection, as the Edit {Collection} library // *is* the selection. @@ -2178,8 +2170,9 @@ display: state.has('display') ? state.get('display') : state.get('displaySettings'), dragInfo: state.get('dragInfo'), - suggestedWidth: state.get('suggestedWidth'), - suggestedHeight: state.get('suggestedHeight'), + idealColumnWidth: state.get('idealColumnWidth'), + suggestedWidth: state.get('suggestedWidth'), + suggestedHeight: state.get('suggestedHeight'), AttachmentView: state.get('AttachmentView') }); @@ -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 ); diff --git a/src/wp-includes/media-template.php b/src/wp-includes/media-template.php index 7cf334917f..dafa2a9b7e 100644 --- a/src/wp-includes/media-template.php +++ b/src/wp-includes/media-template.php @@ -414,24 +414,26 @@ function wp_print_media_templates() { - -