jQuery( document ).ready( function ( $ ) { function advads_load_ad_type_parameter_metabox ( ad_type ) { jQuery( '#advanced-ad-type input' ).prop( 'disabled', true ) $( '#advanced-ads-tinymce-wrapper' ).hide() $( '#advanced-ads-ad-parameters' ).html( '' ) $.ajax( { type: 'POST', url: ajaxurl, data: { 'action': 'load_ad_parameters_metabox', 'ad_type': ad_type, 'ad_id': $( '#post_ID' ).val(), 'nonce': advadsglobal.ajax_nonce }, success: function ( data, textStatus, XMLHttpRequest ) { // toggle main content field. if ( data ) { $( '#advanced-ads-ad-parameters' ).html( data ).trigger( 'paramloaded' ) advads_maybe_textarea_to_tinymce( ad_type ) } }, error: function ( MLHttpRequest, textStatus, errorThrown ) { $( '#advanced-ads-ad-parameters' ).html( errorThrown ) } } ).always( function ( MLHttpRequest, textStatus, errorThrown ) { jQuery( '#advanced-ad-type input[name^="advanced_ad"]' ).prop( 'disabled', false ); } ) } $( document ).on( 'click', '#switch-to-adsense-type', function ( ev ) { ev.preventDefault() AdvancedAdsAdmin.AdImporter.adsenseCode = Advanced_Ads_Admin.get_ad_source_editor_text() $( '#advanced-ad-type-adsense' ).trigger( 'click' ) $( this ).closest( 'li' ).addClass( 'hidden' ) } ) $( document ).on( 'change', '#advanced-ad-type input', function () { var ad_type = $( this ).val() advads_load_ad_type_parameter_metabox( ad_type ) } ) // trigger for ad injection after ad creation $( '#advads-ad-injection-box .advads-ad-injection-button' ).on( 'click', function () { var placement_type = this.dataset.placementType, // create new placement placement_slug = this.dataset.placementSlug, // use existing placement options = {} if ( ! placement_type && ! placement_slug ) { return } // create new placement if ( placement_type ) { // for content injection if ( 'post_content' === placement_type ) { var paragraph = prompt( advadstxt.after_paragraph_promt, 1 ) if ( paragraph !== null ) { options.index = parseInt( paragraph, 10 ) } } } $( '#advads-ad-injection-box .advads-loader' ).show() $( '#advads-ad-injection-box-placements' ).hide() $( 'body' ).animate( { scrollTop: $( '#advads-ad-injection-box' ).offset().top - 40 }, 1, 'linear' ) $.ajax( { type: 'POST', url: ajaxurl, data: { action: 'advads-ad-injection-content', placement_type: placement_type, placement_slug: placement_slug, ad_id: $( '#post_ID' ).val(), options: options, nonce: advadsglobal.ajax_nonce }, success: function ( r, textStatus, XMLHttpRequest ) { if ( ! r ) { $( '#advads-ad-injection-box' ).html( 'an error occured' ) return } $( '#advads-ad-injection-box *' ).hide() // append anchor to placement message $( '#advads-ad-injection-message-placement-created .advads-placement-link' ).attr( 'href', $( '#advads-ad-injection-message-placement-created a' ).attr( 'href' ) + r ) $( '#advads-ad-injection-message-placement-created, #advads-ad-injection-message-placement-created *' ).show() }, error: function ( MLHttpRequest, textStatus, errorThrown ) { $( '#advads-ad-injection-box' ).html( errorThrown ) } } ).always( function ( MLHttpRequest, textStatus, errorThrown ) { // jQuery( '#advanced-ad-type input').prop( 'disabled', false ); } ) } ) // activate general buttons $( '.advads-buttonset' ).advads_buttonset() // activate accordions if ( $.fn.accordion ) { $( '.advads-accordion' ).accordion( { active: false, collapsible: true, } ) } /** * Logic for ad groups */ // display new ad group form $( '#advads-new-ad-group-link' ).on( 'click', function ( e ) { e.preventDefault() $( '#advads-new-group-form' ).show().find( 'input[type="text"]' ).focus() } ) // display ad groups form $( '#advads-ad-group-list a.edit, #advads-ad-group-list a.row-title' ).on( 'click', function ( e ) { e.preventDefault(); var advadsgroupformrow = $(this).parents('.advads-group-row').next('.advads-ad-group-form'); if (advadsgroupformrow.is(':visible')) { advadsgroupformrow.addClass('hidden'); // clear last edited id $('#advads-last-edited-group').val(''); } else { advadsgroupformrow.removeClass('hidden'); var group_id = advadsgroupformrow.find('.advads-group-id').val() $('#advads-last-edited-group').val(group_id); // remember that we opened that one advadsgroupformrow.data('touched', true); } }); // display ad groups usage $( '#advads-ad-group-list a.usage' ).on( 'click', function ( e ) { e.preventDefault(); var usagediv = $(this).parents('.advads-group-row').find('.advads-usage'); if (usagediv.is(':visible')) { usagediv.addClass('hidden'); } else { usagediv.removeClass('hidden'); } }); // handle the submission of the groups form $( 'form#advads-form-groups' ).on( 'submit', function () { jQuery( 'tr.advads-ad-group-form' ).each( function ( k, v ) { v = jQuery( v ) if ( ! v.data( 'touched' ) ) { v.remove() } } ) } ) /** * Logic for placement list */ // filter placement by type jQuery( '.advads_filter_placement_type' ).on( 'change', function () { var selectedValue = jQuery( this ).val(); if ( selectedValue === '0' ) { jQuery( '.advads-placements-table tbody > tr' ).show(); } else { jQuery( '.advads-placements-table tbody > tr' ).each( function () { if ( jQuery( this ).data( 'type' ) !== selectedValue ) { jQuery( this ).hide(); } else { jQuery( this ).show(); } } ); } } ); // search placement by name jQuery( '.advads_search_placement_name' ).on( 'keyup', function () { jQuery( '.advads_filter_placement_type option[value=\'0\']' ).attr( 'selected', true ); var value = this.value; jQuery( '.advads-placements-table' ).find( 'tr' ).each( function ( index ) { if ( ! index ) { return; } var name = jQuery( this ).data( 'name' ); if ( typeof name !== 'undefined' ) { jQuery( this ).toggle( name.toLowerCase().indexOf( value.toLowerCase() ) !== - 1 ); } } ); } ); jQuery( '.advads-modal-close-action' ).on( 'click', function () { // Change url hash, so that the modal doesn't load after refresh again. window.location.hash = '#close'; jQuery( '#advanced-ads-placements-form' ).submit(); } ); jQuery( '.advads-delete-tag' ).each( function () { jQuery( this ).on( 'click', function () { var r = confirm( window.advadstxt.delete_placement_confirmation ); if ( r === true ) { var row = jQuery( this ).parents( '.advanced-ads-placement-row' ); row.find( '.advads-placements-item-delete' ).prop( 'checked', true ); row.data( 'touched', true ); jQuery( '#advanced-ads-placements-form' ).submit(); } } ); } ); // sort placement by type order or name jQuery( '.advads-sort' ).on( 'click', function ( e ) { var sort = jQuery( this ); var order = sort.data( 'order' ); var table = jQuery( '.advads-placements-table' ); var rows = jQuery( '> tbody > tr', table ); var links = jQuery( '> thead th > a', table ); links.each( function () { jQuery( this ).removeClass( 'advads-placement-sorted' ); } ); sort.addClass( 'advads-placement-sorted' ); rows.sort( function ( a, b ) { var keyA = jQuery( a ).data( order ); var keyB = jQuery( b ).data( order ); if ( order === 'ordertype' ) { return keyA - keyB; } return ( keyA.localeCompare( keyB ) ); } ); jQuery.each( rows, function ( index, row ) { table.append( row ); } ); sort.data( 'order', order ); var state = {order: order}; var url = window.location.pathname + window.location.search; if ( url.indexOf( 'orderby=' ) !== - 1 ) { url = url.replace( /\borderby=[0-9a-zA-Z_@.#+-]{1,50}\b/, 'orderby=' + order ); } else { url += '&orderby=' + order; } window.history.replaceState( state, document.title, url ); e.preventDefault(); } ); // show warning if Container ID option contains invalid characters $( '#advads-output-wrapper-id' ).on( 'keyup', function () { var id_value = $( this ).val() if ( /^[a-z-0-9]*$/.test( id_value ) ) { $( '.advads-output-wrapper-id-error' ).addClass( 'hidden' ) } else { $( '.advads-output-wrapper-id-error' ).removeClass( 'hidden' ) } } ) // group page: add ad to group $( '.advads-group-add-ad button' ).on( 'click', function () { var $settings_row = $( this ).closest( '.advads-ad-group-form' ), $ad = $settings_row.find( '.advads-group-add-ad-list-ads option:selected' ) $weight_selector = $settings_row.find( '.advads-group-add-ad-list-weights' ).last(), $ad_table = $settings_row.find( '.advads-group-ads tbody' ) // add new row if does not already exist if ( $ad.length && $weight_selector.length && ! $ad_table.find( '[name="' + $ad.val() + '"]' ).length ) { $ad_table.append( $( '
' + textStatus + ': ' + errorThrown + '
' + jQuery( '#advads-ads-txt-notice-error' ).text().replace( '%s', parseInt( jqXHR.status, 10 ) ), +'
' ) set_loading( false ) } function load ( type ) { set_loading( true ) jQuery.ajax( { type: 'POST', url: ajaxurl, data: { action: 'advads-ads-txt', nonce: advadsglobal.ajax_nonce, type, }, } ).done( done ).fail( fail ) } jQuery( document ).on( 'click', '#advads-ads-txt-remove-real', function ( event ) { event.preventDefault() var args = { data: { action: 'advads-ads-txt', nonce: advadsglobal.ajax_nonce, type: 'remove_real_file', }, done: function ( response ) { if ( response.additional_content ) { jQuery( '#advads-ads-txt-additional-content' ).val( response.additional_content ) } done( response ) }, fail: fail, before_send: function () { set_loading( true ) }, } advanced_ads_admin.filesystem.ajax( args ) } ) jQuery( document ).on( 'click', '#advads-ads-txt-create-real', function ( event ) { event.preventDefault() var args = { data: { action: 'advads-ads-txt', nonce: advadsglobal.ajax_nonce, type: 'create_real_file', }, done: done, fail: fail, before_send: function () { set_loading( true ) }, } advanced_ads_admin.filesystem.ajax( args ) } ) } window.advanced_ads_admin = window.advanced_ads_admin || {} advanced_ads_admin.filesystem = { /** * Holds the current job while the user writes data in the 'Connection Information' modal. * * @type {obj} */ _locked_job: false, /** * Toggle the 'Connection Information' modal. */ _requestForCredentialsModalToggle: function () { this.$filesystemModal.toggle() jQuery( 'body' ).toggleClass( 'modal-open' ) }, _init: function () { this._init = function () {} var self = this self.$filesystemModal = jQuery( '#advanced-ads-rfc-dialog' ) /** * Sends saved job. */ self.$filesystemModal.on( 'submit', 'form', function ( event ) { event.preventDefault() self.ajax( self._locked_job, true ) self._requestForCredentialsModalToggle() } ) /** * Closes the request credentials modal when clicking the 'Cancel' button. */ self.$filesystemModal.on( 'click', '[data-js-action="close"]', function () { if ( jQuery.isPlainObject( self._locked_job ) && self._locked_job.on_modal_close ) { self._locked_job.on_modal_close() } self._locked_job = false self._requestForCredentialsModalToggle() } ) }, /** * Sends AJAX request. Shows 'Connection Information' modal if needed. * * @param {object} args * @param {bool} skip_modal */ ajax: function ( args, skip_modal ) { this._init() if ( ! skip_modal && this.$filesystemModal.length > 0 ) { this._requestForCredentialsModalToggle() this.$filesystemModal.find( 'input:enabled:first' ).focus() // Do not send request. this._locked_job = args return } var options = { method: 'POST', url: window.ajaxurl, data: { username: jQuery( '#username' ).val(), password: jQuery( '#password' ).val(), hostname: jQuery( '#hostname' ).val(), connection_type: jQuery( 'input[name="connection_type"]:checked' ).val(), public_key: jQuery( '#public_key' ).val(), private_key: jQuery( '#private_key' ).val(), _fs_nonce: jQuery( '#_fs_nonce' ).val() } } if ( args.before_send ) { args.before_send() } options.data = jQuery.extend( options.data, args.data ) var request = jQuery.ajax( options ) if ( args.done ) { request.done( args.done ) } if ( args.fail ) { request.fail( args.fail ) } } } window.Advanced_Ads_Admin = window.Advanced_Ads_Admin || { init_ad_source_editor: function () { }, get_ad_source_editor_text: function () { var text = undefined if ( Advanced_Ads_Admin.editor ) { if ( Advanced_Ads_Admin.editor.codemirror ) { text = Advanced_Ads_Admin.editor.codemirror.getValue() } } if ( ! text ) { var ta = jQuery( '#advads-ad-content-plain' ) if ( ta ) text = ta.val() } return text }, set_ad_source_editor_text: function ( text ) { if ( Advanced_Ads_Admin.editor && Advanced_Ads_Admin.editor.codemirror ) { Advanced_Ads_Admin.editor.codemirror.setValue( text ) } else { jQuery( '#advads-ad-content-plain' ).val( text ) } }, check_ad_source: function () { var text = Advanced_Ads_Admin.get_ad_source_editor_text() var enabled_php = jQuery( '#advads-parameters-php' ).prop( 'checked' ) var enabled_sc = jQuery( '#advads-parameters-shortcodes' ).prop( 'checked' ) if ( enabled_php && ! /\<\?php/.test( text ) ) { jQuery( '#advads-parameters-php-warning' ).show() } else { jQuery( '#advads-parameters-php-warning' ).hide() } if ( enabled_sc && ! /\[[^\]]+\]/.test( text ) ) { jQuery( '#advads-parameters-shortcodes-warning' ).show() } else { jQuery( '#advads-parameters-shortcodes-warning' ).hide() } }, /** * Toggle placement advanced options. * * @deprecated. Used only by add-ons when the base plugin version < 1.19. */ toggle_placements_visibility: function ( elm, state ) { var advadsplacementformrow = jQuery( elm ).next( '.advads-placements-advanced-options' ) var hide = ( typeof state !== 'undefined' ) ? ! state : advadsplacementformrow.is( ':visible' );; if ( hide ) { advadsplacementformrow.hide() // clear last edited id jQuery( '#advads-last-edited-placement' ).val( '' ) } else { var placement_id = jQuery( elm ).parents( '.advads-placements-table-options' ).find( '.advads-placement-slug' ).val() advadsplacementformrow.show() jQuery( '#advads-last-edited-placement' ).val( placement_id ) // Some special elements (color picker) may not be detected with jquery. var tr = jQuery( elm ).closest( 'tr.advanced-ads-placement-row' ) if ( tr ) { tr.data( 'touched', true ) } } }, /** * get a cookie value * * @param {str} name of the cookie */ get_cookie: function (name) { var i, x, y, ADVcookies = document.cookie.split( ";" ); for (i = 0; i < ADVcookies.length; i++) { x = ADVcookies[i].substr( 0, ADVcookies[i].indexOf( "=" ) ); y = ADVcookies[i].substr( ADVcookies[i].indexOf( "=" ) + 1 ); x = x.replace( /^\s+|\s+$/g, "" ); if (x === name) { return unescape( y ); } } }, /** * set a cookie value * * @param {str} name of the cookie * @param {str} value of the cookie * @param {int} exdays days until cookie expires * set 0 to expire cookie immidiatelly * set null to expire cookie in the current session */ set_cookie: function (name, value, exdays, path, domain, secure) { // days in seconds var expiry = ( exdays == null ) ? null : exdays * 24 * 60 * 60; this.set_cookie_sec( name, value, expiry, path, domain, secure ); }, /** * set a cookie with expiry given in seconds * * @param {str} name of the cookie * @param {str} value of the cookie * @param {int} expiry seconds until cookie expires * set 0 to expire cookie immidiatelly * set null to expire cookie in the current session */ set_cookie_sec: function (name, value, expiry, path, domain, secure) { var exdate = new Date(); exdate.setSeconds( exdate.getSeconds() + parseInt( expiry ) ); document.cookie = name + "=" + escape( value ) + ((expiry == null) ? "" : "; expires=" + exdate.toUTCString()) + ((path == null) ? "; path=/" : "; path=" + path) + ((domain == null) ? "" : "; domain=" + domain) + ((secure == null) ? "" : "; secure"); } } if ( ! window.AdvancedAdsAdmin ) window.AdvancedAdsAdmin = {} if ( ! window.AdvancedAdsAdmin.AdImporter ) window.AdvancedAdsAdmin.AdImporter = { /** * will highlight the currently selected ads in the list * @param hideInactive when true will hide inactive ad units * @returns the selector of the selected row or false if no row was selected. */ highlightSelectedRowInExternalAdsList: function ( hideInactive ) { if ( typeof (hideInactive) == 'undefined' ) hideInactive = AdvancedAdsAdmin.AdImporter.adNetwork.hideIdle const tbody = jQuery( '#mapi-table-wrap tbody' ) const btn = jQuery( '#mapi-toggle-idle' ) // count the ad units to determine if there's a need for the overflow class (scrolling) const nbUnits = hideInactive ? jQuery( '#mapi-table-wrap tbody tr[data-active=1]' ).length : jQuery( '#mapi-table-wrap tbody tr' ).length if ( nbUnits > 8 ) jQuery( '#mapi-table-wrap' ).addClass( 'overflow' ) else jQuery( '#mapi-table-wrap' ).removeClass( 'overflow' ) const selectedRow = AdvancedAdsAdmin.AdImporter.getSelectedRow() tbody.find( 'tr' ).removeClass( 'selected error' ); if ( selectedRow ) { //make sure, it is visible before applying the zebra stripes selectedRow.show() } // make the table's rows striped. const visible = tbody.find( 'tr:visible' ) visible.filter( ':odd' ).css( 'background-color', '#FFFFFF' ) visible.filter( ':even' ).css( 'background-color', '#F9F9F9' ) // highlight the selected row if ( selectedRow ) { // highlight the selected row selectedRow.css( 'background-color', '' ) selectedRow.addClass( 'selected' ) this.scrollToSelectedRow(selectedRow); } return selectedRow || false }, scrollToSelectedRow($selectedRow) { const $wrap = jQuery('#mapi-table-wrap'), wrapHeight = $wrap.height(), wrapScrolled = $wrap.scrollTop(); // just in case this does not get passed a selected row, scroll to top of the table if (!$selectedRow) { $wrap.animate({scrollTop: 0}, 200); return; } // get the position of the selectedRow within the table wrap let scroll = $selectedRow.position().top, bottom = +scroll + $selectedRow.height(); // if the (top of the) element is not yet visible scroll to it if (scroll < wrapScrolled || bottom > wrapScrolled || scroll > wrapScrolled + wrapHeight) { // scrolled element is below current scroll position, i.e. we need to scroll past it not to top if (bottom > $wrap.children('table').height() - wrapHeight) { scroll = bottom; } // if the selected element is on the "first page" let's scroll all the way to the top if (scroll < wrapHeight) { scroll = 0; } $wrap.animate({scrollTop: scroll}, 200); } }, getSelectedRow () { const selectedId = AdvancedAdsAdmin.AdImporter.adNetwork.getSelectedId() const tbody = jQuery( '#mapi-table-wrap tbody' ) if ( selectedId ) { const selectedRows = tbody.find( 'tr[data-slotid="' + selectedId + '"]' ) if ( selectedRows.length ) { return selectedRows } } return null }, openExternalAdsList: function () { const network = AdvancedAdsAdmin.AdImporter.adNetwork network.openSelector() jQuery( '.mapi-insert-code' ).css( 'display', 'inline' ) jQuery( '.mapi-open-selector' ).css( 'display', 'none' ) jQuery( '.mapi-close-selector-link' ).css( 'display', 'inline' ) jQuery( '.advads-adsense-code' ).css( 'display', 'none' ) jQuery( '#remote-ad-unsupported-ad-type' ).css( 'display', 'none' ) AdvancedAdsAdmin.AdImporter.highlightSelectedRowInExternalAdsList( network.hideIdle ) var SNT = network.getCustomInputs() SNT.css( 'display', 'none' ) jQuery( '#mapi-wrap' ).css( 'display', 'block' ) if ( ! network.fetchedExternalAds ) { network.fetchedExternalAds = true const nbUnits = jQuery( '#mapi-table-wrap tbody tr[data-slotid]' ).length if ( nbUnits == 0 ) { //usually we start with a preloaded list. //only reload, when the count is zero (true for new accounts). AdvancedAdsAdmin.AdImporter.refreshAds() } } jQuery( '#wpwrap' ).trigger( 'advads-mapi-adlist-opened' ); AdvancedAdsAdmin.AdImporter.resizeAdListHeader() }, /** * will be called every time the ad type is changed. * required for onBlur detection */ onChangedAdType: function () { if ( AdvancedAdsAdmin.AdImporter.adNetwork ) { AdvancedAdsAdmin.AdImporter.adNetwork.onBlur() AdvancedAdsAdmin.AdImporter.adNetwork = null } }, setup: function ( adNetwork ) { AdvancedAdsAdmin.AdImporter.adNetwork = adNetwork adNetwork.onSelected() if ( AdvancedAdsAdmin.AdImporter.isSetup ) { AdvancedAdsAdmin.AdImporter.highlightSelectedRowInExternalAdsList() return } AdvancedAdsAdmin.AdImporter.isSetup = true jQuery( document ).on( 'click', '.prevent-default', function ( ev ) { ev.preventDefault() } ) // handle clicks for the "insert new ... code" anchor jQuery( document ).on( 'click', '.mapi-insert-code', function ( e ) { e.preventDefault() jQuery( '#remote-ad-unsupported-ad-type' ).css( 'display', 'none' ); jQuery( '.advads-adsense-code' ).show() jQuery( '.mapi-open-selector' ).css( 'display', 'inline' ) jQuery( '.mapi-close-selector-link' ).css( 'display', 'inline' ) jQuery( '.mapi-insert-code' ).css( 'display', 'none' ); jQuery( '#mapi-wrap' ).css( 'display', 'none' ) var SNT = AdvancedAdsAdmin.AdImporter.adNetwork.getCustomInputs() SNT.css( 'display', 'none' ) } ) // handle clicks for the "get ad code from your linked account" anchor jQuery( document ).on( 'click', '.mapi-open-selector a', function () { AdvancedAdsAdmin.AdImporter.openExternalAdsList() } ) // the close button of the ad unit list jQuery( document ).on( 'click', '#mapi-close-selector,.mapi-close-selector-link', function () { jQuery( '#remote-ad-unsupported-ad-type' ).css( 'display', 'none' ); AdvancedAdsAdmin.AdImporter.manualSetup() } ) //the individual rows of the ad units may contain elements with the mapiaction class jQuery( document ).on( 'click', '.mapiaction', function ( ev ) { var action = jQuery( this ).attr( 'data-mapiaction' ) switch ( action ) { case 'updateList': AdvancedAdsAdmin.AdImporter.refreshAds() break case 'getCode': if ( jQuery( this ).hasClass( 'disabled' ) ) { break } var slotId = jQuery( this ).attr( 'data-slotid' ) AdvancedAdsAdmin.AdImporter.adNetwork.selectAdFromList( slotId ) break case 'updateCode': var slotId = jQuery( this ).attr( 'data-slotid' ) AdvancedAdsAdmin.AdImporter.adNetwork.updateAdFromList( slotId ) break case 'toggleidle': if ( 'undefined' != typeof AdvancedAdsAdmin.AdImporter.adNetwork.getMapiAction && 'function' == typeof AdvancedAdsAdmin.AdImporter.adNetwork.getMapiAction( 'toggleidle' ) ) { AdvancedAdsAdmin.AdImporter.adNetwork.getMapiAction( 'toggleidle' )( ev, this ); } else { AdvancedAdsAdmin.AdImporter.adNetwork.hideIdle = ! AdvancedAdsAdmin.AdImporter.adNetwork.hideIdle AdvancedAdsAdmin.AdImporter.toggleIdleAds( AdvancedAdsAdmin.AdImporter.adNetwork.hideIdle ) const $inactiveNotice = jQuery( '#mapi-notice-inactive' ); if ( $inactiveNotice.length ) { $inactiveNotice.toggle( AdvancedAdsAdmin.AdImporter.adNetwork.hideIdle ); } break; } default: } } ) AdvancedAdsAdmin.AdImporter.adNetwork.onDomReady() // AdvancedAdsAdmin.AdImporter.openExternalAdsList(); }, /** * call this method to display the manual setup (if available for the current ad network) * this method is an equivalent to the close ad list button. */ manualSetup () { jQuery( '.mapi-open-selector,.advads-adsense-show-code' ).css( 'display', 'inline' ) jQuery( '.mapi-insert-code' ).css( 'display', 'inline' ) jQuery( '.mapi-close-selector-link' ).css( 'display', 'none' ) jQuery( '#mapi-wrap' ).css( 'display', 'none' ) var SNT = AdvancedAdsAdmin.AdImporter.adNetwork.getCustomInputs() SNT.css( 'display', 'block' ) // hide custom layout key if type is not in-feed if (jQuery('#unit-type').val() !== 'in-feed') { jQuery('.advads-adsense-layout-key').css('display', 'none') .next('div').css('display', 'none'); } AdvancedAdsAdmin.AdImporter.adNetwork.onManualSetup() }, setRemoteErrorMessage ( msg ) { if ( ! msg ) jQuery( '#remote-ad-code-msg' ).empty() else jQuery( '#remote-ad-code-msg' ).html( msg ) }, // another legacy method resizeAdListHeader: function () { var th = jQuery( '#mapi-list-header span' ) var tb = jQuery( '#mapi-table-wrap tbody tr:visible' ) var w = [] tb.first().find( 'td' ).each( function () { w.push( jQuery( this ).width() ) } ) th.each( function ( i ) { if ( i != w.length - 1 ) { jQuery( this ).width( w[ i ] ) } } ) }, /** * legacy method */ closeAdSelector: function () { // close the ad unit selector setTimeout( function () { jQuery( '#mapi-wrap' ).animate( { height: 0, }, 360, function () { jQuery( '.mapi-open-selector,.advads-adsense-show-code' ).css( 'display', 'inline' ) jQuery( '.mapi-close-selector-link' ).css( 'display', 'none' ) jQuery( '#mapi-wrap' ).css( { display: 'none', height: 'auto', } ) const SNT = AdvancedAdsAdmin.AdImporter.adNetwork.getCustomInputs() SNT.css( 'display', 'block' ) } ) }, 80 ) }, /** * legacy method * updates the UI, (call if the selected unit is supported) */ unitIsNotSupported: function ( slotID ) { jQuery( '#remote-ad-unsupported-ad-type' ).css( 'display', 'block' ); AdsenseMAPI.unsupportedUnits[ slotID ] = 1; jQuery( '#unit-code' ).val( '' ); jQuery( '#unit-type' ).val( 'normal' ); jQuery( '#ad-layout-key' ).val( '' ); jQuery( 'tr[data-slotid^="ca-"]' ).removeClass( 'selected error' ); var $selectedRow = jQuery('tr[data-slotid="' + slotID + '"]'); $selectedRow.addClass('selected error').css('background-color', ''); this.scrollToSelectedRow($selectedRow); }, /** * legacy method * updates the UI, (call if the selected unit is NOT supported) */ unitIsSupported: function ( slotID ) { jQuery( '#remote-ad-unsupported-ad-type' ).css( 'display', 'none' ) if ( 'undefined' != typeof AdsenseMAPI.unsupportedUnits[ slotID ] ) { delete AdsenseMAPI.unsupportedUnits[ slotID ] } jQuery( 'i[data-mapiaction="getCode"][data-slotid="' + slotID + '"]' ).removeClass( 'disabled' ) if ( jQuery( 'tr[data-slotid="' + slotID + '"] .unittype a' ).length ) { var td = jQuery( 'tr[data-slotid="' + slotID + '"] .unittype' ) var content = jQuery( 'tr[data-slotid="' + slotID + '"] .unittype a' ).attr( 'data-type' ) td.text( content ) } if ( jQuery( 'tr[data-slotid="' + slotID + '"] .unitsize a' ).length ) { var td = jQuery( 'tr[data-slotid="' + slotID + '"] .unitsize' ) var content = jQuery( 'tr[data-slotid="' + slotID + '"] .unitsize a' ).attr( 'data-size' ) td.text( content ) } }, /** * legacy method * updates the UI, (call if the selected unit is NOT supported) */ emptyMapiSelector: function ( msg ) { const nag = '