Add upstream
This commit is contained in:
@@ -0,0 +1,284 @@
|
||||
/* global grunionEditorView, tinyMCE, QTags, wp */
|
||||
( function( $, wp, grunionEditorView ) {
|
||||
wp.mce = wp.mce || {};
|
||||
if ( 'undefined' === typeof wp.mce.views ) {
|
||||
return;
|
||||
}
|
||||
|
||||
wp.mce.grunion_wp_view_renderer = {
|
||||
shortcode_string: 'contact-form',
|
||||
template: wp.template( 'grunion-contact-form' ),
|
||||
field_templates: {
|
||||
email: wp.template( 'grunion-field-email' ),
|
||||
telephone: wp.template( 'grunion-field-telephone' ),
|
||||
textarea: wp.template( 'grunion-field-textarea' ),
|
||||
radio: wp.template( 'grunion-field-radio' ),
|
||||
checkbox: wp.template( 'grunion-field-checkbox' ),
|
||||
'checkbox-multiple': wp.template( 'grunion-field-checkbox-multiple' ),
|
||||
select: wp.template( 'grunion-field-select' ),
|
||||
date: wp.template( 'grunion-field-date' ),
|
||||
text: wp.template( 'grunion-field-text' ),
|
||||
name: wp.template( 'grunion-field-text' ),
|
||||
url: wp.template( 'grunion-field-url' ),
|
||||
},
|
||||
edit_template: wp.template( 'grunion-field-edit' ),
|
||||
editor_inline: wp.template( 'grunion-editor-inline' ),
|
||||
editor_option: wp.template( 'grunion-field-edit-option' ),
|
||||
getContent: function() {
|
||||
var content = this.shortcode.content,
|
||||
index = 0,
|
||||
field,
|
||||
named,
|
||||
body = '';
|
||||
|
||||
// If it's the legacy `[contact-form /]` syntax, populate default fields.
|
||||
if ( ! content ) {
|
||||
content = grunionEditorView.default_form;
|
||||
}
|
||||
|
||||
// Render the fields.
|
||||
while ( ( field = wp.shortcode.next( 'contact-field', content, index ) ) ) {
|
||||
index = field.index + field.content.length;
|
||||
named = field.shortcode.attrs.named;
|
||||
if ( ! named.type || ! this.field_templates[ named.type ] ) {
|
||||
named.type = 'text';
|
||||
}
|
||||
if ( named.required ) {
|
||||
named.required = grunionEditorView.labels.required_field_text;
|
||||
}
|
||||
if ( named.options && 'string' === typeof named.options ) {
|
||||
named.options = named.options.split( ',' );
|
||||
}
|
||||
body += this.field_templates[ named.type ]( named );
|
||||
}
|
||||
|
||||
var options = {
|
||||
body: body,
|
||||
submit_button_text: grunionEditorView.labels.submit_button_text,
|
||||
};
|
||||
|
||||
return this.template( options );
|
||||
},
|
||||
edit: function( data, update_callback ) {
|
||||
var shortcode_data = wp.shortcode.next( this.shortcode_string, data ),
|
||||
shortcode = shortcode_data.shortcode,
|
||||
$tinyMCE_document = $( tinyMCE.activeEditor.getDoc() ),
|
||||
$view = $tinyMCE_document.find( '.wpview.wpview-wrap' ).filter( function() {
|
||||
return $( this ).attr( 'data-mce-selected' );
|
||||
} ),
|
||||
$editframe = $( '<iframe scrolling="no" class="inline-edit-contact-form" />' ),
|
||||
index = 0,
|
||||
named,
|
||||
fields = '',
|
||||
field;
|
||||
|
||||
if ( ! shortcode.content ) {
|
||||
shortcode.content = grunionEditorView.default_form;
|
||||
}
|
||||
|
||||
// Render the fields.
|
||||
while ( ( field = wp.shortcode.next( 'contact-field', shortcode.content, index ) ) ) {
|
||||
index = field.index + field.content.length;
|
||||
named = field.shortcode.attrs.named;
|
||||
if ( named.options && 'string' === typeof named.options ) {
|
||||
named.options = named.options.split( ',' );
|
||||
}
|
||||
fields += this.edit_template( named );
|
||||
}
|
||||
|
||||
$editframe.on( 'checkheight', function() {
|
||||
var innerDoc = this.contentDocument ? this.contentDocument : this.contentWindow.document;
|
||||
this.style.height = '10px';
|
||||
this.style.height = 5 + innerDoc.body.scrollHeight + 'px';
|
||||
tinyMCE.activeEditor.execCommand( 'wpAutoResize' );
|
||||
} );
|
||||
|
||||
$editframe.on( 'load', function() {
|
||||
var stylesheet_url =
|
||||
1 === window.isRtl
|
||||
? grunionEditorView.inline_editing_style_rtl
|
||||
: grunionEditorView.inline_editing_style,
|
||||
$stylesheet = $( '<link rel="stylesheet" href="' + stylesheet_url + '" />' ),
|
||||
$dashicons_css = $(
|
||||
'<link rel="stylesheet" href="' + grunionEditorView.dashicons_css_url + '" />'
|
||||
);
|
||||
|
||||
$stylesheet.on( 'load', function() {
|
||||
$editframe
|
||||
.contents()
|
||||
.find( 'body' )
|
||||
.css( 'visibility', 'visible' );
|
||||
$editframe.trigger( 'checkheight' );
|
||||
} );
|
||||
$editframe
|
||||
.contents()
|
||||
.find( 'head' )
|
||||
.append( $stylesheet )
|
||||
.append( $dashicons_css );
|
||||
|
||||
$editframe
|
||||
.contents()
|
||||
.find( 'body' )
|
||||
.html(
|
||||
wp.mce.grunion_wp_view_renderer.editor_inline( {
|
||||
to: shortcode.attrs.named.to,
|
||||
subject: shortcode.attrs.named.subject,
|
||||
fields: fields,
|
||||
} )
|
||||
)
|
||||
.css( 'visibility', 'hidden' );
|
||||
|
||||
$editframe
|
||||
.contents()
|
||||
.find( 'input:first' )
|
||||
.focus();
|
||||
|
||||
setTimeout( function() {
|
||||
$editframe.trigger( 'checkheight' );
|
||||
}, 250 );
|
||||
|
||||
// Add a second timeout for super long forms racing, and to not slow it down for shorter forms unnecessarily.
|
||||
setTimeout( function() {
|
||||
$editframe.trigger( 'checkheight' );
|
||||
}, 500 );
|
||||
|
||||
var $editfields = $editframe.contents().find( '.grunion-fields' ),
|
||||
$buttons = $editframe.contents().find( '.grunion-controls' );
|
||||
|
||||
$editfields.sortable();
|
||||
|
||||
// Now, add all the listeners!
|
||||
|
||||
$editfields.on( 'change select', 'select[name=type]', function() {
|
||||
$( this ).closest( '.grunion-field-edit' )[ 0 ].className =
|
||||
'card is-compact grunion-field-edit grunion-field-' + $( this ).val();
|
||||
$editframe.trigger( 'checkheight' );
|
||||
} );
|
||||
|
||||
$editfields.on( 'click', '.delete-option', function( e ) {
|
||||
e.preventDefault();
|
||||
$( this )
|
||||
.closest( 'li' )
|
||||
.remove();
|
||||
$editframe.trigger( 'checkheight' );
|
||||
} );
|
||||
|
||||
$editfields.on( 'click', '.add-option', function( e ) {
|
||||
var $new_option = $( wp.mce.grunion_wp_view_renderer.editor_option() );
|
||||
e.preventDefault();
|
||||
$( this )
|
||||
.closest( 'li' )
|
||||
.before( $new_option );
|
||||
$editframe.trigger( 'checkheight' );
|
||||
$new_option.find( 'input:first' ).focus();
|
||||
} );
|
||||
|
||||
$editfields.on( 'click', '.delete-field', function( e ) {
|
||||
e.preventDefault();
|
||||
$( this )
|
||||
.closest( '.card' )
|
||||
.remove();
|
||||
$editframe.trigger( 'checkheight' );
|
||||
} );
|
||||
|
||||
$buttons.find( 'input[name=submit]' ).on( 'click', function() {
|
||||
var new_data = shortcode;
|
||||
|
||||
new_data.type = 'closed';
|
||||
new_data.attrs = {};
|
||||
new_data.content = '';
|
||||
|
||||
$editfields.children().each( function() {
|
||||
var field_shortcode = {
|
||||
tag: 'contact-field',
|
||||
type: 'single',
|
||||
attrs: {
|
||||
label: $( this )
|
||||
.find( 'input[name=label]' )
|
||||
.val(),
|
||||
type: $( this )
|
||||
.find( 'select[name=type]' )
|
||||
.val(),
|
||||
},
|
||||
},
|
||||
options = [];
|
||||
|
||||
if ( $( this ).find( 'input[name=required]:checked' ).length ) {
|
||||
field_shortcode.attrs.required = '1';
|
||||
}
|
||||
|
||||
$( this )
|
||||
.find( 'input[name=option]' )
|
||||
.each( function() {
|
||||
if ( $( this ).val() ) {
|
||||
options.push( $( this ).val() );
|
||||
}
|
||||
} );
|
||||
if ( options.length ) {
|
||||
field_shortcode.attrs.options = options.join( ',' );
|
||||
}
|
||||
|
||||
new_data.content += wp.shortcode.string( field_shortcode );
|
||||
} );
|
||||
|
||||
if (
|
||||
$editframe
|
||||
.contents()
|
||||
.find( 'input[name=to]' )
|
||||
.val()
|
||||
) {
|
||||
new_data.attrs.to = $editframe
|
||||
.contents()
|
||||
.find( 'input[name=to]' )
|
||||
.val();
|
||||
}
|
||||
if (
|
||||
$editframe
|
||||
.contents()
|
||||
.find( 'input[name=subject]' )
|
||||
.val()
|
||||
) {
|
||||
new_data.attrs.subject = $editframe
|
||||
.contents()
|
||||
.find( 'input[name=subject]' )
|
||||
.val();
|
||||
}
|
||||
|
||||
update_callback( wp.shortcode.string( new_data ) );
|
||||
} );
|
||||
|
||||
$buttons.find( 'input[name=cancel]' ).on( 'click', function() {
|
||||
update_callback( wp.shortcode.string( shortcode ) );
|
||||
} );
|
||||
|
||||
$buttons.find( 'input[name=add-field]' ).on( 'click', function() {
|
||||
var $new_field = $( wp.mce.grunion_wp_view_renderer.edit_template( {} ) );
|
||||
$editfields.append( $new_field );
|
||||
$editfields.sortable( 'refresh' );
|
||||
$editframe.trigger( 'checkheight' );
|
||||
$new_field.find( 'input:first' ).focus();
|
||||
} );
|
||||
} );
|
||||
|
||||
$view.html( $editframe );
|
||||
},
|
||||
};
|
||||
wp.mce.views.register( 'contact-form', wp.mce.grunion_wp_view_renderer );
|
||||
|
||||
// Add the 'text' editor button.
|
||||
QTags.addButton( 'grunion_shortcode', grunionEditorView.labels.quicktags_label, function() {
|
||||
QTags.insertContent( '[contact-form]' + grunionEditorView.default_form + '[/contact-form]' );
|
||||
} );
|
||||
|
||||
var $wp_content_wrap = $( '#wp-content-wrap' );
|
||||
$( '#insert-jetpack-contact-form' ).on( 'click', function( e ) {
|
||||
e.preventDefault();
|
||||
if ( $wp_content_wrap.hasClass( 'tmce-active' ) ) {
|
||||
tinyMCE.execCommand( 'grunion_add_form' );
|
||||
} else if ( $wp_content_wrap.hasClass( 'html-active' ) ) {
|
||||
QTags.insertContent( '[contact-form]' + grunionEditorView.default_form + '[/contact-form]' );
|
||||
} else {
|
||||
window.console.error( 'Neither TinyMCE nor QuickTags is active. Unable to insert form.' );
|
||||
}
|
||||
} );
|
||||
} )( jQuery, wp, grunionEditorView );
|
||||
@@ -0,0 +1,30 @@
|
||||
/* global ajaxurl */
|
||||
jQuery( function( $ ) {
|
||||
$( document ).on( 'click', '#jetpack-check-feedback-spam:not(.button-disabled)', function( e ) {
|
||||
e.preventDefault();
|
||||
|
||||
$( '#jetpack-check-feedback-spam:not(.button-disabled)' ).addClass( 'button-disabled' );
|
||||
$( '.jetpack-check-feedback-spam-spinner' )
|
||||
.addClass( 'spinner' )
|
||||
.show();
|
||||
grunion_check_for_spam( 0, 100 );
|
||||
} );
|
||||
|
||||
function grunion_check_for_spam( offset, limit ) {
|
||||
$.post(
|
||||
ajaxurl,
|
||||
{
|
||||
action: 'grunion_recheck_queue',
|
||||
offset: offset,
|
||||
limit: limit,
|
||||
},
|
||||
function( result ) {
|
||||
if ( result.processed < limit ) {
|
||||
window.location.reload();
|
||||
} else {
|
||||
grunion_check_for_spam( offset + limit, limit );
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
} );
|
||||
@@ -0,0 +1,3 @@
|
||||
jQuery( function( $ ) {
|
||||
$( '.contact-form input.jp-contact-form-date' ).datepicker();
|
||||
} );
|
||||
1180
wp-content/plugins/jetpack/modules/contact-form/js/grunion.js
Normal file
1180
wp-content/plugins/jetpack/modules/contact-form/js/grunion.js
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,37 @@
|
||||
/* global grunionEditorView, tinymce */
|
||||
( function() {
|
||||
tinymce.create( 'tinymce.plugins.grunion_form', {
|
||||
init: function( editor ) {
|
||||
editor.addButton( 'grunion', {
|
||||
title: grunionEditorView.labels.tinymce_label,
|
||||
cmd: 'grunion_add_form',
|
||||
icon: 'grunion',
|
||||
} );
|
||||
editor.addCommand( 'grunion_add_form', function() {
|
||||
if ( grunionEditorView.default_form ) {
|
||||
editor.execCommand(
|
||||
'mceInsertContent',
|
||||
0,
|
||||
'[contact-form]' + grunionEditorView.default_form + '[/contact-form]'
|
||||
);
|
||||
} else {
|
||||
editor.execCommand( 'mceInsertContent', 0, '[contact-form /]' );
|
||||
}
|
||||
} );
|
||||
},
|
||||
|
||||
createControl: function() {
|
||||
return null;
|
||||
},
|
||||
|
||||
getInfo: function() {
|
||||
return {
|
||||
longname: 'Grunion Contact Form',
|
||||
author: 'Automattic',
|
||||
version: '1',
|
||||
};
|
||||
},
|
||||
} );
|
||||
|
||||
tinymce.PluginManager.add( 'grunion_form', tinymce.plugins.grunion_form );
|
||||
} )();
|
||||
Reference in New Issue
Block a user