( $ => { 'use strict'; const $body = $( 'body' ); const defaultOptions = { wrapper: `<div class="rwmb-modal"> <header class="rwmb-modal-title"> <h2></h2> <button type="button" class="rwmb-modal-close">×</button> </header> <div class="rwmb-modal-content"></div> </div>`, markupIframe: '<iframe id="rwmb-modal-iframe" width="100%" height="700" src="{URL}" border="0"></iframe>', markupOverlay: '<div class="rwmb-modal-overlay"></div>', hideElement: '', hideElementDefault: '#adminmenumain, #wpadminbar, #wpfooter, .row-actions, .form-wrap.edit-term-notes, #screen-meta-links, .wp-heading-inline, .wp-header-end, .page-title-action', callback: null, closeModalCallback: null, isBlockEditor: false, $objectId: null, $objectDisplay: null, isEdit: false, size: 'large', }; $.fn.rwmbModal = function ( options = {} ) { options = { ...defaultOptions, ...options }; if ( $( '.rwmb-modal' ).length === 0 ) { return; } // $this is the button that opens the modal const $this = $( this ), $modal = $( '.rwmb-modal' ); let $input = $this.closest( '.rwmb-input' ); if ( $input.find( '.rwmb-clone' ).length > 0 && $this.closest( '.rwmb-clone' ).length > 0 ) { $input = $this.closest( '.rwmb-clone' ); } $this.click( function ( e ) { e.preventDefault(); $modal.attr( 'size', options.size ); $modal.find( '.rwmb-modal-title h2' ).html( $this.html() ); $modal.find( '.rwmb-modal-content' ).html( options.markupIframe.replace( '{URL}', $this.attr( 'data-url' ) ) ); $( '#rwmb-modal-iframe' ).on( 'load', function () { const $contents = $( this ).contents(); options.isBlockEditor = $contents.find( 'body' ).hasClass( 'block-editor-page' ); $contents.find( options.hideElement ).hide(); $modal.find( '.rwmb-modal-title' ).css( 'background-color', '' ); if ( options.isBlockEditor ) { $modal.find( '.rwmb-modal-title' ).css( 'background-color', '#fff' ); } $contents .find( options.hideElementDefault ).hide().end() .find( '.rwmb-modal-add-button' ).parents('.rwmb-field').hide(); $contents.find( 'html' ).css( 'padding-top', 0 ).end() .find( '#wpcontent' ).css( 'margin-left', 0 ).end() .find( 'a' ).on( 'click', e => e.preventDefault() ); if ( options.callback !== null && typeof options.callback === 'function' ) { options.callback( $modal, $contents ); } $body.addClass( 'rwmb-modal-show' ); $( '.rwmb-modal-overlay' ).fadeIn( 'medium' ).css( 'display', 'flex' ); $modal.fadeIn( 'medium' ).css( 'display', 'flex' ); return false; } ); $( '.rwmb-modal-close' ).on( 'click', function ( event ) { if ( options.closeModalCallback !== null && typeof options.closeModalCallback === 'function' ) { options.closeModalCallback( $( '#rwmb-modal-iframe' ).contents(), $input ); } $modal.fadeOut( 'medium' ); $( '.rwmb-modal-overlay' ).fadeOut( 'medium' ); $body.removeClass( 'rwmb-modal-show' ); // If not add new if ( !options.$objectId || !options.$objectDisplay ) { $( this ).off( event ); return; } // Select, select advanced, select tree. const $select = $input.find( 'select' ); if ( $select.length > 0 ) { $select.prepend( $( '<option>', { value: options.$objectId, text: options.$objectDisplay, selected: true } ) ); $( this ).off( event ); return; } // Radio, checkbox list, checkbox tree const $inputList = $input.find( '.rwmb-input-list:first' ), $labelClone = $inputList.find( '> label:first' ).clone(), $inputClone = $labelClone.find( 'input' ).clone(); $labelClone.html( $inputClone.val( options.$objectId ) .attr( 'checked', true ) .prop( 'outerHTML' ) + options.$objectDisplay ); $inputList.prepend( $labelClone ); // Clear event after close modal. options.$objectId = null; options.$objectDisplay = null; $( this ).off( event ); }); } ); }; if ( $( '.rwmb-modal' ).length === 0 ) { $body.append( defaultOptions.wrapper ) .append( defaultOptions.markupOverlay ); } } )( jQuery );
Name | Type | Size | Permission | Actions |
---|---|---|---|---|
jqueryui | Folder | 0755 |
|
|
leaflet | Folder | 0755 |
|
|
select2 | Folder | 0755 |
|
|
validation | Folder | 0755 |
|
|
wp-color-picker-alpha | Folder | 0755 |
|
|
autocomplete.js | File | 1.62 KB | 0644 |
|
autosave.js | File | 595 B | 0644 |
|
button-group.js | File | 1018 B | 0644 |
|
clone.js | File | 9.04 KB | 0644 |
|
color.js | File | 1.33 KB | 0644 |
|
date.js | File | 2.47 KB | 0644 |
|
datetime.js | File | 2.87 KB | 0644 |
|
file-input.js | File | 1.87 KB | 0644 |
|
file-upload.js | File | 5.1 KB | 0644 |
|
file.js | File | 3.88 KB | 0644 |
|
icon.js | File | 769 B | 0644 |
|
image-advanced.js | File | 1015 B | 0644 |
|
image-upload.js | File | 1007 B | 0644 |
|
input-list.js | File | 1.07 KB | 0644 |
|
map-frontend.js | File | 2.01 KB | 0644 |
|
map.js | File | 8.6 KB | 0644 |
|
media.js | File | 15.45 KB | 0644 |
|
modal.js | File | 4.12 KB | 0644 |
|
oembed.js | File | 880 B | 0644 |
|
osm-frontend.js | File | 1.2 KB | 0644 |
|
osm.js | File | 7.79 KB | 0644 |
|
post.js | File | 1.23 KB | 0644 |
|
range.js | File | 475 B | 0644 |
|
script.js | File | 751 B | 0644 |
|
select-advanced.js | File | 3.67 KB | 0644 |
|
select-tree.js | File | 1.62 KB | 0644 |
|
select.js | File | 536 B | 0644 |
|
slider.js | File | 922 B | 0644 |
|
taxonomy.js | File | 1.21 KB | 0644 |
|
time.js | File | 1.78 KB | 0644 |
|
user.js | File | 1.43 KB | 0644 |
|
video.js | File | 1.12 KB | 0644 |
|
wysiwyg.js | File | 5.36 KB | 0644 |
|