window.wp = window.wp || {}; (function($) { var container, mediaFrame, lastMimeType, mediaPreview, lastHeight, content, $container = $( '.post-formats-fields' ), shortClass = 'short-format', shortContentFormats = ['status', 'aside'], noUIFormats = ['standard', 'chat', 'status', 'aside', 'gallery'], $screenIcon = $( '.icon32' ); function switchFormatClass( format ) { container.get(0).className = container.get(0).className.replace( /\s?\bwp-format-[^ ]+/g, '' ); container.addClass('wp-format-' + format); $screenIcon.get(0).className = $screenIcon.get(0).className.replace( /\s?\bwp-format-[^ ]+/g, '' ); $screenIcon.addClass('wp-format-' + format); } function resizeContent( shorter ) { content = content || $('#content, #content_ifr'); if ( shorter ) { if ( ! content.hasClass(shortClass) ) { lastHeight = content.height(); content.addClass(shortClass).animate({ height : 120 }); } } else if ( lastHeight ) { content.removeClass(shortClass).animate({ height : lastHeight }); } } function switchFormat($this) { var editor, body, parent = $this.parent(), format = $this.data('wp-format'), description = $('.post-format-description'), postTitle = $('#title'); if ( typeof container === 'undefined' ) container = $('#post-body-content'); parent.slideUp().find('a.active').removeClass('active'); $this.addClass('active'); $('#post_format').val(format); $('.post-format-change').show().find('span.icon').removeClass(postFormats.currentPostFormat).addClass(format); if ( -1 < $.inArray( format, noUIFormats ) ) { switchFormatClass( format ); // No slide $container.hide(); } else { $container.slideUp( 200, function(){ switchFormatClass( format ); $container.slideDown( 400 ); }); } resizeContent( -1 < $.inArray( format, shortContentFormats ) ); postTitle.focus(); if ( '' === postTitle.val() ) $('#title-prompt-text').removeClass('screen-reader-text'); // Update description line description.html($this.data('description')); if (description.not(':visible')) description.slideDown('fast'); if ( typeof tinymce != 'undefined' ) { editor = tinymce.get('content'); if ( editor ) { body = editor.getBody(); body.className = body.className.replace( /\bpost-format-[^ ]+/, '' ); editor.dom.addClass( body, 'post-format-' + format ); } } postFormats.currentPostFormat = format; } $(function(){ $('.post-format-change a').click(function() { $('.post-formats-fields, .post-format-change').slideUp(); $('.post-format-options').slideDown(); return false; }); // Post formats selection $('.post-format-options').on( 'click', 'a', function (e) { e.preventDefault(); switchFormat($(this)); }); // Media selection $('.wp-format-media-select').click(function(event) { event.preventDefault(); var $el = $(this), mime = 'image', $holder = $el.closest('.wp-format-media-holder'), $field = $( '#wp_format_' + $holder.data('format') ); mime = $holder.data('format'); // If the media frame already exists, reopen it. if ( mediaFrame && lastMimeType === mime ) { mediaFrame.open(); return; } lastMimeType = mime; mediaFrame = wp.media.frames.formatMedia = wp.media( { button: { text: $el.data('update') }, states: [ new wp.media.controller.Library({ library: wp.media.query( { type: mime } ), title: $el.data('choose'), displaySettings: 'image' === mime }) ] } ); mediaPreview = function(attachment) { var w, h, dimensions = '', url = attachment.url, mime = attachment.mime, format = attachment.type; if ( 'video' === format ) { if ( attachment.width ) { w = attachment.width; if ( w > 600 ) w = 600; dimensions += ' width="' + w + '"'; } if ( attachment.height ) { h = attachment.height; if ( attachment.width && w < attachment.width ) h = Math.round( ( h * w ) / attachment.width ); dimensions += ' height="' + h + '"'; } } $('#' + format + '-preview').remove(); $holder.parent().prepend( '