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