| @@ -1,16 +1,14 @@ | ||
| 1 | -/* global jQuery:false, frmGlobal, tb_remove, ajaxurl, adminpage */ | |
| 2 | 1 | /* exported frm_install_now, frmSelectSubnav, frmCreatePostEntry */ |
| 3 | -/* eslint-disable prefer-const, compat/compat */ | |
| 4 | 2 | |
| 5 | 3 | jQuery( document ).ready( function() { |
| 6 | - let deauthLink, submenuItem, li, | |
| 7 | - installLink = document.getElementById( 'frm_install_link' ); | |
| 8 | - if ( installLink !== null ) { | |
| 4 | + const installLink = document.getElementById( 'frm_install_link' ); | |
| 5 | + | |
| 6 | + if ( installLink ) { | |
| 9 | 7 | jQuery( installLink ).on( 'click', frmInstallPro ); |
| 10 | 8 | } |
| 11 | 9 | |
| 12 | - deauthLink = jQuery( '.frm_deauthorize_link' ); | |
| 10 | + const deauthLink = jQuery( '.frm_deauthorize_link' ); | |
| 13 | 11 | if ( deauthLink.length ) { |
| 14 | 12 | deauthLink.on( 'click', frmDeauthorizeNow ); |
| 15 | 13 | } |
| 16 | 14 | |
| @@ -17,11 +15,11 @@ | ||
| 17 | 15 | if ( typeof tb_remove === 'function' ) { // eslint-disable-line camelcase |
| 18 | 16 | frmAdminPopup.init(); |
| 19 | 17 | } |
| 20 | 18 | |
| 21 | - submenuItem = document.querySelector( '.frm-upgrade-submenu' ); | |
| 22 | - if ( null !== submenuItem ) { | |
| 23 | - li = submenuItem.parentNode.parentNode; | |
| 19 | + const submenuItem = document.querySelector( '.frm-upgrade-submenu' ); | |
| 20 | + if ( submenuItem ) { | |
| 21 | + const li = submenuItem.parentNode.parentNode; | |
| 24 | 22 | if ( li ) { |
| 25 | 23 | li.classList.add( 'frm-submenu-highlight' ); |
| 26 | 24 | } |
| 27 | 25 | } |
| @@ -28,9 +26,9 @@ | ||
| 28 | 26 | } ); |
| 29 | 27 | |
| 30 | 28 | function frm_install_now() { // eslint-disable-line camelcase |
| 31 | 29 | const $msg = jQuery( document.getElementById( 'frm_install_message' ) ); |
| 32 | - $msg.html( '<div class="frm_plugin_updating">' + frmGlobal.updating_msg + '<div class="spinner frm_spinner"></div></div>' ); | |
| 30 | + $msg.html( `<div class="frm_plugin_updating">${ frmGlobal.updating_msg }<div class="spinner frm_spinner"></div></div>` ); | |
| 33 | 31 | jQuery.ajax( { |
| 34 | 32 | type: 'POST', |
| 35 | 33 | url: ajaxurl, |
| 36 | 34 | data: { |
| @@ -36,9 +34,9 @@ | ||
| 36 | 34 | data: { |
| 37 | 35 | action: 'frm_install', |
| 38 | 36 | nonce: frmGlobal.nonce |
| 39 | 37 | }, |
| 40 | - success: function() { | |
| 38 | + success() { | |
| 41 | 39 | $msg.fadeOut( 'slow' ); |
| 42 | 40 | } |
| 43 | 41 | } ); |
| 44 | 42 | return false; |
| @@ -44,10 +42,9 @@ | ||
| 44 | 42 | return false; |
| 45 | 43 | } |
| 46 | 44 | |
| 47 | 45 | function frmInstallPro( e ) { |
| 48 | - let $msg, | |
| 49 | - plugin = this.getAttribute( 'data-prourl' ); | |
| 46 | + const plugin = this.getAttribute( 'data-prourl' ); | |
| 50 | 47 | if ( plugin === '' ) { |
| 51 | 48 | return true; |
| 52 | 49 | } |
| 53 | 50 | |
| @@ -52,10 +49,10 @@ | ||
| 52 | 49 | } |
| 53 | 50 | |
| 54 | 51 | e.preventDefault(); |
| 55 | 52 | |
| 56 | - $msg = jQuery( document.getElementById( 'frm_install_message' ) ); | |
| 57 | - $msg.html( '<div class="frm_plugin_updating">' + frmGlobal.updating_msg + '<div class="spinner frm_spinner"></div></div>' ); | |
| 53 | + const $msg = jQuery( document.getElementById( 'frm_install_message' ) ); | |
| 54 | + $msg.html( `<div class="frm_plugin_updating">${ frmGlobal.updating_msg }<div class="spinner frm_spinner"></div></div>` ); | |
| 58 | 55 | $msg.fadeIn( 'slow' ); |
| 59 | 56 | |
| 60 | 57 | jQuery.ajax( { |
| 61 | 58 | url: ajaxurl, |
| @@ -65,15 +62,15 @@ | ||
| 65 | 62 | dataType: 'json', |
| 66 | 63 | data: { |
| 67 | 64 | action: 'frm_install_addon', |
| 68 | 65 | nonce: frmGlobal.nonce, |
| 69 | - plugin: plugin | |
| 66 | + plugin | |
| 70 | 67 | }, |
| 71 | - success: function() { | |
| 68 | + success() { | |
| 72 | 69 | $msg.fadeOut( 'slow' ); |
| 73 | 70 | $msg.parent().fadeOut( 'slow' ); |
| 74 | 71 | }, |
| 75 | - error: function() { | |
| 72 | + error() { | |
| 76 | 73 | $msg.fadeOut( 'slow' ); |
| 77 | 74 | } |
| 78 | 75 | } ); |
| 79 | 76 | return false; |
| @@ -90,9 +87,9 @@ | ||
| 90 | 87 | data: { |
| 91 | 88 | action: 'frm_deauthorize', |
| 92 | 89 | nonce: frmGlobal.nonce |
| 93 | 90 | }, |
| 94 | - success: function() { | |
| 91 | + success() { | |
| 95 | 92 | jQuery( '.error' ).fadeOut( 'slow' ); |
| 96 | 93 | } |
| 97 | 94 | } ); |
| 98 | 95 | return false; |
| @@ -104,19 +101,19 @@ | ||
| 104 | 101 | jQuery( '#toplevel_page_formidable a.wp-has-submenu' ).removeClass( 'wp-not-current-submenu' ).addClass( 'wp-has-current-submenu wp-menu-open' ); |
| 105 | 102 | } |
| 106 | 103 | |
| 107 | 104 | function frmCreatePostEntry( id, postId ) { |
| 108 | - jQuery( '#frm_create_entry p' ).replaceWith( '<img src="' + frmGlobal.url + '/images/wpspin_light.gif" alt="' + frmGlobal.loading + '" />' ); | |
| 105 | + jQuery( '#frm_create_entry p' ).replaceWith( `<img src="${ frmGlobal.url }/images/wpspin_light.gif" alt="${ frmGlobal.loading }" />` ); | |
| 109 | 106 | jQuery.ajax( { |
| 110 | 107 | type: 'POST', |
| 111 | 108 | url: ajaxurl, |
| 112 | 109 | data: { |
| 113 | 110 | action: 'frm_create_post_entry', |
| 114 | - id: id, | |
| 111 | + id, | |
| 115 | 112 | post_id: postId, |
| 116 | 113 | nonce: frmGlobal.nonce |
| 117 | 114 | }, |
| 118 | - success: function() { | |
| 115 | + success() { | |
| 119 | 116 | jQuery( document.getElementById( 'frm_create_entry' ) ).fadeOut( 'slow' ); |
| 120 | 117 | } |
| 121 | 118 | } ); |
| 122 | 119 | } |
| @@ -122,33 +119,32 @@ | ||
| 122 | 119 | } |
| 123 | 120 | |
| 124 | 121 | function frmAdminPopupJS() { |
| 125 | 122 | function switchSc() { |
| 126 | - let val; | |
| 127 | 123 | jQuery( '.frm_switch_sc' ).removeClass( 'active' ); |
| 128 | 124 | jQuery( this ).addClass( 'active' ); |
| 129 | 125 | toggleMenu(); |
| 130 | - jQuery( '#frm_popup_content .media-frame-title h1' ).html( jQuery( this ).children( '.howto' ).text() + ' <span class="spinner" style="float:left;"></span>' ); | |
| 131 | - val = this.id.replace( 'sc-link-', '' ); | |
| 126 | + jQuery( '#frm_popup_content .media-frame-title h1' ).html( `${ jQuery( this ).children( '.howto' ).text() } <span class="spinner" style="float:left;"></span>` ); | |
| 127 | + const val = this.id.replace( 'sc-link-', '' ); | |
| 132 | 128 | populateOpts( val ); |
| 133 | 129 | return false; |
| 134 | 130 | } |
| 135 | 131 | |
| 136 | 132 | function populateOpts( val ) { |
| 137 | - let $settings, $scOpts, $spinner, | |
| 138 | - sc = document.getElementById( 'frm_complete_shortcode' ); | |
| 139 | - if ( sc !== null ) { | |
| 140 | - sc.value = '[' + val + ']'; | |
| 133 | + const sc = document.getElementById( 'frm_complete_shortcode' ); | |
| 134 | + | |
| 135 | + if ( sc ) { | |
| 136 | + sc.value = `[${ val }]`; | |
| 141 | 137 | } |
| 142 | 138 | jQuery( '.frm_shortcode_option' ).hide(); |
| 143 | 139 | |
| 144 | - $settings = document.getElementById( 'sc-opts-' + val ); | |
| 145 | - if ( $settings !== null ) { | |
| 140 | + const $settings = document.getElementById( `sc-opts-${ val }` ); | |
| 141 | + if ( $settings ) { | |
| 146 | 142 | $settings.style.display = ''; |
| 147 | - jQuery( document.getElementById( 'sc-' + val ) ).trigger( 'click' ); | |
| 143 | + jQuery( document.getElementById( `sc-${ val }` ) ).trigger( 'click' ); | |
| 148 | 144 | } else { |
| 149 | - $scOpts = jQuery( document.getElementById( 'frm_shortcode_options' ) ); | |
| 150 | - $spinner = jQuery( '.media-frame-title .spinner' ); | |
| 145 | + const $scOpts = jQuery( document.getElementById( 'frm_shortcode_options' ) ); | |
| 146 | + const $spinner = jQuery( '.media-frame-title .spinner' ); | |
| 151 | 147 | $spinner.show(); |
| 152 | 148 | jQuery.ajax( { |
| 153 | 149 | type: 'POST', |
| 154 | 150 | url: ajaxurl, |
| @@ -156,12 +152,12 @@ | ||
| 156 | 152 | action: 'frm_get_shortcode_opts', |
| 157 | 153 | shortcode: val, |
| 158 | 154 | nonce: frmGlobal.nonce |
| 159 | 155 | }, |
| 160 | - success: function( html ) { | |
| 156 | + success( html ) { | |
| 161 | 157 | $spinner.hide(); |
| 162 | 158 | $scOpts.append( html ); |
| 163 | - jQuery( document.getElementById( 'sc-' + val ) ).trigger( 'click' ); | |
| 159 | + jQuery( document.getElementById( `sc-${ val }` ) ).trigger( 'click' ); | |
| 164 | 160 | } |
| 165 | 161 | } ); |
| 166 | 162 | } |
| 167 | 163 | } |
| @@ -167,21 +163,23 @@ | ||
| 167 | 163 | } |
| 168 | 164 | |
| 169 | 165 | function addToShortcode() { |
| 170 | 166 | const sc = jQuery( 'input[name=frmsc]:checked' ).val(); |
| 171 | - const inputs = jQuery( document.getElementById( 'sc-opts-' + sc ) ).find( 'input, select' ); | |
| 172 | - let output = '[' + sc; | |
| 167 | + const inputs = jQuery( document.getElementById( `sc-opts-${ sc }` ) ).find( 'input, select' ); | |
| 168 | + let output = `[${ sc }`; | |
| 169 | + | |
| 173 | 170 | inputs.each( function() { |
| 174 | - let attrName, attrVal, | |
| 175 | - $thisInput = jQuery( this ), | |
| 176 | - attrId = this.id; | |
| 171 | + let attrName; | |
| 172 | + let attrVal; | |
| 173 | + const $thisInput = jQuery( this ); | |
| 174 | + const attrId = this.id; | |
| 175 | + | |
| 177 | 176 | if ( attrId.indexOf( 'frmsc_' ) === 0 ) { |
| 178 | - attrName = attrId.replace( 'frmsc_' + sc + '_', '' ); | |
| 177 | + attrName = attrId.replace( `frmsc_${ sc }_`, '' ); | |
| 179 | 178 | attrVal = $thisInput.val(); |
| 180 | 179 | |
| 181 | - if ( ( $thisInput.attr( 'type' ) === 'checkbox' && ! this.checked ) || ( ( $thisInput.attr( 'type' ) === 'text' || $thisInput.is( 'select' ) ) && attrVal === '' ) ) { | |
| 182 | - } else { | |
| 183 | - output += ' ' + attrName + '="' + attrVal + '"'; | |
| 180 | + if ( ( $thisInput.attr( 'type' ) !== 'checkbox' || this.checked ) && ( ( $thisInput.attr( 'type' ) !== 'text' && ! $thisInput.is( 'select' ) ) || attrVal !== '' ) ) { | |
| 181 | + output += ` ${ attrName }="${ attrVal }"`; | |
| 184 | 182 | } |
| 185 | 183 | } |
| 186 | 184 | } ); |
| 187 | 185 | output += ']'; |
| @@ -193,10 +191,10 @@ | ||
| 193 | 191 | win.send_to_editor( document.getElementById( 'frm_complete_shortcode' ).value ); |
| 194 | 192 | } |
| 195 | 193 | |
| 196 | 194 | function getFieldSelection() { |
| 197 | - let thisId, | |
| 198 | - formId = this.value; | |
| 195 | + let thisId; | |
| 196 | + const formId = this.value; | |
| 199 | 197 | if ( formId ) { |
| 200 | 198 | thisId = this.id; |
| 201 | 199 | jQuery.ajax( { |
| 202 | 200 | type: 'POST', |
| @@ -206,12 +204,12 @@ | ||
| 206 | 204 | field_id: 0, |
| 207 | 205 | form_id: formId, |
| 208 | 206 | nonce: frmGlobal.nonce |
| 209 | 207 | }, |
| 210 | - success: function( msg ) { | |
| 208 | + success( msg ) { | |
| 211 | 209 | const baseId = thisId.replace( '_form', '' ); |
| 212 | - msg = msg.replace( 'name="field_options[form_select_0]"', 'id="frmsc_' + baseId + '_fields"' ); | |
| 213 | - jQuery( document.getElementById( baseId + '_fields_container' ) ).html( msg ); | |
| 210 | + msg = msg.replace( 'name="field_options[form_select_0]"', `id="frmsc_${ baseId }_fields"` ); | |
| 211 | + jQuery( document.getElementById( `${ baseId }_fields_container` ) ).html( msg ); | |
| 214 | 212 | } |
| 215 | 213 | } ); |
| 216 | 214 | } |
| 217 | 215 | } |
| @@ -220,11 +218,9 @@ | ||
| 220 | 218 | jQuery( document.getElementById( 'frm_popup_content' ) ).find( '.media-menu' ).toggleClass( 'visible' ); |
| 221 | 219 | } |
| 222 | 220 | |
| 223 | 221 | return { |
| 224 | - init: function() { | |
| 225 | - let $scOptsDiv; | |
| 226 | - | |
| 222 | + init() { | |
| 227 | 223 | jQuery( '.frm_switch_sc' ).on( 'click', switchSc ); |
| 228 | 224 | jQuery( '.button.frm_insert_form' ).on( 'click', function() { |
| 229 | 225 | populateOpts( 'formidable' ); |
| 230 | 226 | } ); |
| @@ -229,9 +225,9 @@ | ||
| 229 | 225 | populateOpts( 'formidable' ); |
| 230 | 226 | } ); |
| 231 | 227 | jQuery( document.getElementById( 'frm_insert_shortcode' ) ).on( 'click', insertShortcode ); |
| 232 | 228 | |
| 233 | - $scOptsDiv = jQuery( document.getElementById( 'frm_shortcode_options' ) ); | |
| 229 | + const $scOptsDiv = jQuery( document.getElementById( 'frm_shortcode_options' ) ); | |
| 234 | 230 | $scOptsDiv.on( 'change', 'select, input', addToShortcode ); |
| 235 | 231 | $scOptsDiv.on( 'change', '.frm_get_field_selection', getFieldSelection ); |
| 236 | 232 | |
| 237 | 233 | jQuery( '#frm_popup_content .media-modal-close' ).on( 'click', tb_remove ); |
| @@ -252,10 +248,10 @@ | ||
| 252 | 248 | } |
| 253 | 249 | } |
| 254 | 250 | |
| 255 | 251 | function getFields() { |
| 256 | - let widget, | |
| 257 | - displayId = this.value; | |
| 252 | + let widget; | |
| 253 | + const displayId = this.value; | |
| 258 | 254 | if ( displayId !== '' ) { |
| 259 | 255 | widget = jQuery( this ).closest( '.widget-content' ); |
| 260 | 256 | |
| 261 | 257 | jQuery.ajax( { |
| @@ -266,11 +262,10 @@ | ||
| 266 | 262 | action: 'frm_get_dynamic_widget_opts', |
| 267 | 263 | display_id: displayId, |
| 268 | 264 | nonce: frmGlobal.nonce |
| 269 | 265 | }, |
| 270 | - success: function( opts ) { | |
| 271 | - let titleField, | |
| 272 | - catField = widget.find( '.frm_list_items_cat_id' ); | |
| 266 | + success( opts ) { | |
| 267 | + const catField = widget.find( '.frm_list_items_cat_id' ); | |
| 273 | 268 | catField.find( 'option' ).remove().end(); |
| 274 | 269 | catField.append( jQuery( '<option></option>' ) ); |
| 275 | 270 | jQuery.each( opts.catValues, function( key, value ) { |
| 276 | 271 | catField.append( jQuery( '<option></option>' ).attr( 'value', key ).text( value ) ); |
| @@ -275,9 +270,9 @@ | ||
| 275 | 270 | jQuery.each( opts.catValues, function( key, value ) { |
| 276 | 271 | catField.append( jQuery( '<option></option>' ).attr( 'value', key ).text( value ) ); |
| 277 | 272 | } ); |
| 278 | 273 | |
| 279 | - titleField = widget.find( '.frm_list_items_title_id' ); | |
| 274 | + const titleField = widget.find( '.frm_list_items_title_id' ); | |
| 280 | 275 | titleField.find( 'option' ).remove().end(); |
| 281 | 276 | titleField.append( jQuery( '<option></option>' ) ); |
| 282 | 277 | jQuery.each( opts.titleValues, function( key, value ) { |
| 283 | 278 | titleField.append( jQuery( '<option></option>' ).attr( 'value', key ).text( value ) ); |
| @@ -287,9 +282,9 @@ | ||
| 287 | 282 | } |
| 288 | 283 | } |
| 289 | 284 | |
| 290 | 285 | return { |
| 291 | - init: function() { | |
| 286 | + init() { | |
| 292 | 287 | jQuery( document ).on( 'click', '.frm_list_items_cat_list', toggleCatOpt ); |
| 293 | 288 | jQuery( document ).on( 'change', '.frm_list_items_display_id', getFields ); |
| 294 | 289 | } |
| 295 | 290 | }; |