PluginProbe
Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages / 1.9.8.0
Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages v1.9.8.0
3.4.3 3.4.2 3.4.1 3.4.0 3.3.9 3.3.8 3.3.7 3.3.6 3.3.5 3.3.4 3.3.3 3.3.2 3.3.1 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 2.2.7 2.2.8 2.2.9 2.3.0 2.3.1 All 196 releases
convertkit / resources / backend / js / modal.js

modal.js in Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages 1.9.8.0, at resources/backend/js/modal.js

138 lines 3.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /**
2 * Handles the Insert and Cancel events on TinyMCE and QuickTag Modals
3 *
4 * @since 1.9.6
5 *
6 * @package ConvertKit
7 * @author ConvertKit
8 */
9
10 jQuery( document ).ready(
11 function( $ ) {
12
13 // Cancel.
14 $( 'body' ).on(
15 'click',
16 'form.convertkit-tinymce-popup button.close',
17 function( e ) {
18
19 // TinyMCE.
20 if ( typeof tinyMCE !== 'undefined' && tinyMCE.activeEditor && ! tinyMCE.activeEditor.isHidden() ) {
21 tinymce.activeEditor.windowManager.close();
22 return;
23 }
24
25 // Text Editor.
26 convertKitQuickTagsModal.close();
27
28 }
29 );
30
31 // Insert.
32 $( 'body' ).on(
33 'click',
34 'form.convertkit-tinymce-popup div.buttons input[type=button]',
35 function( e ) {
36
37 // Prevent default action.
38 e.preventDefault();
39
40 // Get containing form.
41 var form = $( this ).closest( 'form.convertkit-tinymce-popup' );
42
43 // Build Shortcode.
44 var shortcode = '[' + $( 'input[name="shortcode"]', $( form ) ).val(),
45 shortcodeClose = ( $( 'input[name="close_shortcode"]', $( form ) ).val() == '1' ? true : false );
46
47 $( 'input, select', $( form ) ).each(
48 function( i ) {
49 // Skip if no data-shortcode attribute.
50 if ( typeof $( this ).data( 'shortcode' ) === 'undefined' ) {
51 return true;
52 }
53
54 // Skip if the value is empty.
55 if ( ! $( this ).val() ) {
56 return true;
57 }
58 if ( $( this ).val().length == 0 ) {
59 return true;
60 }
61
62 // Get shortcode attribute.
63 var key = $( this ).data( 'shortcode' ),
64 trim = ( $( this ).data( 'trim' ) == '0' ? false : true ),
65 val = $( this ).val();
66
67 // Skip if the shortcode is empty.
68 if ( ! key.length ) {
69 return true;
70 }
71
72 // Trim the value, unless the shortcode attribute disables string trimming.
73 if ( trim ) {
74 val = val.trim();
75 }
76
77 // Append attribute and value to shortcode string.
78 shortcode += ' ' + key.trim() + '="' + val + '"';
79 }
80 );
81
82 // Close Shortcode.
83 shortcode += ']';
84
85 // If the shortcode includes a closing element, append it now.
86 if ( shortcodeClose ) {
87 shortcode += '[/' + $( 'input[name="shortcode"]', $( form ) ).val() + ']';
88 }
89
90 /**
91 * Finish building the link, and insert it, depending on whether we were initialized from
92 * the Visual Editor or Text Editor.
93 */
94 if ( typeof tinyMCE !== 'undefined' && tinyMCE.activeEditor && ! tinyMCE.activeEditor.isHidden() ) {
95 // Insert into editor.
96 tinyMCE.activeEditor.execCommand( 'mceReplaceContent', false, shortcode );
97
98 // Close modal.
99 tinyMCE.activeEditor.windowManager.close();
100
101 // Done.
102 return;
103 }
104
105 // Text Editor.
106 if ( typeof QTags !== 'undefined' ) {
107 // Insert into editor.
108 QTags.insertContent( shortcode );
109
110 // Close modal.
111 convertKitQuickTagsModal.close();
112
113 // Done.
114 return;
115 }
116
117 }
118 );
119
120 }
121 );
122
123 // QuickTags: Setup Backbone Modal and Template.
124 if ( typeof wp !== 'undefined' && typeof wp.media !== 'undefined' ) {
125 var convertKitQuickTagsModal = new wp.media.view.Modal(
126 {
127 controller: { trigger: function() {} },
128 className: 'convertkit-quicktags-modal'
129 }
130 );
131 var convertKitQuickTagsModalContent = wp.Backbone.View.extend(
132 {
133 template: wp.template( 'convertkit-quicktags-modal' )
134 }
135 );
136 convertKitQuickTagsModal.content( new convertKitQuickTagsModalContent() );
137 }
138