Edit File by line
/home/zeestwma/richards.../wp-conte.../plugins/jetpack/modules/widgets/gallery/js
File: admin.js
/* global _wpMediaViewsL10n, _wpGalleryWidgetAdminSettings */
[0] Fix | Delete
[1] Fix | Delete
( function ( $ ) {
[2] Fix | Delete
var $ids;
[3] Fix | Delete
var $thumbs;
[4] Fix | Delete
[5] Fix | Delete
$( function () {
[6] Fix | Delete
$( document.body ).on( 'click', '.gallery-widget-choose-images', function ( event ) {
[7] Fix | Delete
event.preventDefault();
[8] Fix | Delete
[9] Fix | Delete
var widget_form = $( this ).closest( 'form, .form' );
[10] Fix | Delete
[11] Fix | Delete
$ids = widget_form.find( '.gallery-widget-ids' );
[12] Fix | Delete
$thumbs = widget_form.find( '.gallery-widget-thumbs' );
[13] Fix | Delete
[14] Fix | Delete
var idsString = $ids.val();
[15] Fix | Delete
[16] Fix | Delete
var attachments = getAttachments( idsString );
[17] Fix | Delete
[18] Fix | Delete
var selection = null;
[19] Fix | Delete
var editing = false;
[20] Fix | Delete
[21] Fix | Delete
if ( attachments ) {
[22] Fix | Delete
selection = getSelection( attachments );
[23] Fix | Delete
[24] Fix | Delete
editing = true;
[25] Fix | Delete
}
[26] Fix | Delete
[27] Fix | Delete
var options = {
[28] Fix | Delete
state: 'gallery-edit',
[29] Fix | Delete
title: wp.media.view.l10n.addMedia,
[30] Fix | Delete
multiple: true,
[31] Fix | Delete
editing: editing,
[32] Fix | Delete
selection: selection,
[33] Fix | Delete
};
[34] Fix | Delete
[35] Fix | Delete
var workflow = getWorkflow( options );
[36] Fix | Delete
[37] Fix | Delete
workflow.open();
[38] Fix | Delete
} );
[39] Fix | Delete
[40] Fix | Delete
// Setup an onchange handler to toggle various options when changing style. The different style options
[41] Fix | Delete
// require different form inputs to be presented in the widget; this event will keep the UI in sync
[42] Fix | Delete
// with the selected style
[43] Fix | Delete
$( '.widget-inside' ).on( 'change', '.gallery-widget-style', setupStyleOptions );
[44] Fix | Delete
[45] Fix | Delete
// Setup the Link To options for all forms currently on the page. Does the same as the onChange handler, but
[46] Fix | Delete
// is called once to display the correct form inputs for each widget on the page
[47] Fix | Delete
setupStyleOptions();
[48] Fix | Delete
} );
[49] Fix | Delete
[50] Fix | Delete
var media = wp.media,
[51] Fix | Delete
l10n;
[52] Fix | Delete
[53] Fix | Delete
// Link any localized strings.
[54] Fix | Delete
l10n = media.view.l10n = typeof _wpMediaViewsL10n === 'undefined' ? {} : _wpMediaViewsL10n;
[55] Fix | Delete
[56] Fix | Delete
/**
[57] Fix | Delete
* wp.media.view.MediaFrame.GalleryWidget
[58] Fix | Delete
*
[59] Fix | Delete
* This behavior can be very nearly had by setting the workflow's state to 'gallery-edit', but
[60] Fix | Delete
* we cannot use the custom WidgetGalleryEdit controller with it (must overide createStates(),
[61] Fix | Delete
* which is necessary to disable the sidebar gallery settings in the media browser)
[62] Fix | Delete
*/
[63] Fix | Delete
media.view.MediaFrame.GalleryWidget = media.view.MediaFrame.Post.extend( {
[64] Fix | Delete
createStates: function () {
[65] Fix | Delete
var options = this.options;
[66] Fix | Delete
[67] Fix | Delete
// `CollectionEdit` and `CollectionAdd` were only introduced in r27214-core,
[68] Fix | Delete
// so they may not be available yet.
[69] Fix | Delete
if ( 'CollectionEdit' in media.controller ) {
[70] Fix | Delete
this.states.add( [
[71] Fix | Delete
new media.controller.CollectionEdit( {
[72] Fix | Delete
type: 'image',
[73] Fix | Delete
collectionType: 'gallery',
[74] Fix | Delete
title: l10n.editGalleryTitle,
[75] Fix | Delete
SettingsView: media.view.Settings.Gallery,
[76] Fix | Delete
library: options.selection,
[77] Fix | Delete
editing: options.editing,
[78] Fix | Delete
menu: 'gallery',
[79] Fix | Delete
} ),
[80] Fix | Delete
new media.controller.CollectionAdd( {
[81] Fix | Delete
type: 'image',
[82] Fix | Delete
collectionType: 'gallery',
[83] Fix | Delete
title: l10n.addToGalleryTitle,
[84] Fix | Delete
} ),
[85] Fix | Delete
] );
[86] Fix | Delete
} else {
[87] Fix | Delete
// If `CollectionEdit` is not available, then use the old approach.
[88] Fix | Delete
[89] Fix | Delete
if ( ! ( 'WidgetGalleryEdit' in media.controller ) ) {
[90] Fix | Delete
// Remove the gallery settings sidebar when editing widgets.
[91] Fix | Delete
media.controller.WidgetGalleryEdit = media.controller.GalleryEdit.extend( {
[92] Fix | Delete
gallerySettings: function ( /*browser*/ ) {},
[93] Fix | Delete
} );
[94] Fix | Delete
}
[95] Fix | Delete
[96] Fix | Delete
this.states.add( [
[97] Fix | Delete
new media.controller.WidgetGalleryEdit( {
[98] Fix | Delete
library: options.selection,
[99] Fix | Delete
editing: options.editing,
[100] Fix | Delete
menu: 'gallery',
[101] Fix | Delete
} ),
[102] Fix | Delete
new media.controller.GalleryAdd( {} ),
[103] Fix | Delete
] );
[104] Fix | Delete
}
[105] Fix | Delete
},
[106] Fix | Delete
} );
[107] Fix | Delete
[108] Fix | Delete
function setupStyleOptions() {
[109] Fix | Delete
$( '.widget-inside .gallery-widget-style' ).each( function ( /*i*/ ) {
[110] Fix | Delete
var style = $( this ).val();
[111] Fix | Delete
[112] Fix | Delete
var form = $( this ).parents( 'form' );
[113] Fix | Delete
[114] Fix | Delete
switch ( style ) {
[115] Fix | Delete
case 'slideshow':
[116] Fix | Delete
form.find( '.gallery-widget-link-wrapper' ).hide();
[117] Fix | Delete
form.find( '.gallery-widget-columns-wrapper' ).hide();
[118] Fix | Delete
[119] Fix | Delete
break;
[120] Fix | Delete
[121] Fix | Delete
default:
[122] Fix | Delete
form.find( '.gallery-widget-link-wrapper' ).show();
[123] Fix | Delete
form.find( '.gallery-widget-columns-wrapper' ).show();
[124] Fix | Delete
}
[125] Fix | Delete
} );
[126] Fix | Delete
}
[127] Fix | Delete
[128] Fix | Delete
/**
[129] Fix | Delete
* Take a given Selection of attachments and a thumbs wrapper div (jQuery object)
[130] Fix | Delete
* and fill it with thumbnails
[131] Fix | Delete
*/
[132] Fix | Delete
function setupThumbs( selection, wrapper ) {
[133] Fix | Delete
wrapper.empty();
[134] Fix | Delete
[135] Fix | Delete
var imageSize = _wpGalleryWidgetAdminSettings.thumbSize;
[136] Fix | Delete
[137] Fix | Delete
selection.each( function ( model ) {
[138] Fix | Delete
var sizedUrl = model.get( 'url' ) + '?w=' + imageSize + '&h=' + imageSize + '&crop=true';
[139] Fix | Delete
[140] Fix | Delete
var thumb = jQuery( '<img>', {
[141] Fix | Delete
src: sizedUrl,
[142] Fix | Delete
alt: model.get( 'title' ),
[143] Fix | Delete
title: model.get( 'title' ),
[144] Fix | Delete
width: imageSize,
[145] Fix | Delete
height: imageSize,
[146] Fix | Delete
class: 'thumb',
[147] Fix | Delete
} );
[148] Fix | Delete
[149] Fix | Delete
wrapper.append( thumb );
[150] Fix | Delete
} );
[151] Fix | Delete
}
[152] Fix | Delete
[153] Fix | Delete
/**
[154] Fix | Delete
* Take a csv string of ids (as stored in db) and fetch a full Attachments collection
[155] Fix | Delete
*/
[156] Fix | Delete
function getAttachments( idsString ) {
[157] Fix | Delete
if ( ! idsString ) {
[158] Fix | Delete
return null;
[159] Fix | Delete
}
[160] Fix | Delete
[161] Fix | Delete
// Found in /wp-includes/js/media-editor.js
[162] Fix | Delete
var shortcode = wp.shortcode.next( 'gallery', '[gallery ids="' + idsString + '"]' );
[163] Fix | Delete
[164] Fix | Delete
// Ignore the rest of the match object, to give attachments() below what it expects
[165] Fix | Delete
shortcode = shortcode.shortcode;
[166] Fix | Delete
[167] Fix | Delete
var attachments = wp.media.gallery.attachments( shortcode );
[168] Fix | Delete
[169] Fix | Delete
return attachments;
[170] Fix | Delete
}
[171] Fix | Delete
[172] Fix | Delete
/**
[173] Fix | Delete
* Take an Attachments collection and return a corresponding Selection model that can be
[174] Fix | Delete
* passed to a MediaFrame to prepopulate the gallery picker
[175] Fix | Delete
*/
[176] Fix | Delete
function getSelection( attachments ) {
[177] Fix | Delete
var selection = new wp.media.model.Selection( attachments.models, {
[178] Fix | Delete
props: attachments.props.toJSON(),
[179] Fix | Delete
multiple: true,
[180] Fix | Delete
} );
[181] Fix | Delete
[182] Fix | Delete
selection.gallery = attachments.gallery;
[183] Fix | Delete
[184] Fix | Delete
// Fetch the query's attachments, and then break ties from the
[185] Fix | Delete
// query to allow for sorting.
[186] Fix | Delete
selection.more().done( function () {
[187] Fix | Delete
// Break ties with the query.
[188] Fix | Delete
selection.props.set( { query: false } );
[189] Fix | Delete
selection.unmirror();
[190] Fix | Delete
selection.props.unset( 'orderby' );
[191] Fix | Delete
} );
[192] Fix | Delete
[193] Fix | Delete
return selection;
[194] Fix | Delete
}
[195] Fix | Delete
[196] Fix | Delete
/**
[197] Fix | Delete
* Create a media 'workflow' (MediaFrame). This is the main entry point for the media picker
[198] Fix | Delete
*/
[199] Fix | Delete
function getWorkflow( options ) {
[200] Fix | Delete
var workflow = new wp.media.view.MediaFrame.GalleryWidget( options );
[201] Fix | Delete
[202] Fix | Delete
workflow.on(
[203] Fix | Delete
'update',
[204] Fix | Delete
function ( selection ) {
[205] Fix | Delete
var state = workflow.state();
[206] Fix | Delete
[207] Fix | Delete
selection = selection || state.get( 'selection' );
[208] Fix | Delete
[209] Fix | Delete
if ( ! selection ) {
[210] Fix | Delete
return;
[211] Fix | Delete
}
[212] Fix | Delete
[213] Fix | Delete
// Map the Models down into a simple array of ids that can be easily imploded to a csv string
[214] Fix | Delete
var ids = selection.map( function ( model ) {
[215] Fix | Delete
return model.get( 'id' );
[216] Fix | Delete
} );
[217] Fix | Delete
[218] Fix | Delete
var id_string = ids.join( ',' );
[219] Fix | Delete
[220] Fix | Delete
$ids.val( id_string ).trigger( 'change' );
[221] Fix | Delete
[222] Fix | Delete
setupThumbs( selection, $thumbs );
[223] Fix | Delete
},
[224] Fix | Delete
this
[225] Fix | Delete
);
[226] Fix | Delete
[227] Fix | Delete
workflow.setState( workflow.options.state );
[228] Fix | Delete
[229] Fix | Delete
return workflow;
[230] Fix | Delete
}
[231] Fix | Delete
} )( jQuery );
[232] Fix | Delete
[233] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function