PluginProbe ʕ •ᴥ•ʔ
Advanced Ads – Ad Manager & AdSense / 1.8.21
Advanced Ads – Ad Manager & AdSense v1.8.21
2.0.26 2.0.25 2.0.24 2.0.23 2.0.22 2.0.21 1.38.0 1.39.0 1.39.1 1.39.2 1.39.3 1.39.4 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.4.9 1.40.0 1.40.1 1.40.2 1.41.0 1.42.0 1.42.1 1.42.2 1.43.0 1.44.0 1.44.1 1.45.0 1.45.1 1.46.0 1.47.0 1.47.1 1.47.2 1.47.3 1.47.4 1.47.5 1.48.0 1.48.1 1.49.0 1.5.0 1.5.0.1 1.5.1 1.5.2 1.5.2.1 1.5.4 1.5.4.1 1.5.5 1.50.0 1.51.0 1.51.1 1.51.2 1.51.3 1.52.0 1.52.1 1.52.2 1.52.3 1.52.4 1.53.0 1.53.1 1.53.2 1.54.0 1.54.1 1.55.0 1.56.0 1.56.1 1.56.2 1.56.3 1.56.4 1.6 1.6.1 1.6.10 1.6.10.1 1.6.10.2 1.6.11 1.6.11.1 1.6.12 1.6.13 1.6.14 1.6.15 1.6.16 1.6.17 1.6.17.1 1.6.17.2 1.6.2 1.6.2.1 1.6.3 1.6.4 1.6.4.1 1.6.5 1.6.6 1.6.6.1 1.6.7 1.6.7.1 1.6.8 1.6.8.1 1.6.8.2 1.6.8.3 1.6.9 1.6.9.1 1.6.9.2 1.6.9.3 1.6.9.4 1.7 1.7.0.1 1.7.0.2 1.7.0.3 1.7.1 1.7.1.1 1.7.1.2 1.7.1.3 1.7.1.4 1.7.1.5 1.7.10 trunk 1.7.11 1.0.1 1.7.12 1.0.2 1.7.13 1.0.3 1.7.14 1.1.0 1.7.15 1.1.1 1.7.16 1.1.2 1.7.17 1.1.3 1.7.18 1.10 1.7.19 1.10.1 1.7.2 1.10.10 1.7.2.1 1.10.11 1.7.20 1.10.12 1.7.21 1.10.2 1.7.22 1.10.3 1.7.23 1.10.4 1.7.24 1.10.5 1.7.25 1.10.6 1.7.3 1.10.7 1.7.4 1.10.8 1.7.4.1 1.10.9 1.7.4.2 1.11 1.7.4.3 1.11.1 1.7.4.4 1.11.2 1.7.4.5 1.12 1.7.5 1.13 1.7.5.1 1.13.1 1.7.6 1.13.2 1.7.7 1.13.3 1.7.8 1.13.4 1.7.9 1.13.5 1.7.9.1 1.13.6 1.7.9.2 1.13.7 1.7.9.3 1.13.8 1.8 1.14 1.8.1 1.14.1 1.8.10 1.14.10 1.8.11 1.14.11 1.8.12 1.14.2 1.8.13 1.14.3 1.8.14 1.14.4 1.8.15 1.14.5 1.8.16 1.14.6 1.8.17 1.14.7 1.8.18 1.14.8 1.8.19 1.14.9 1.8.2 1.15 1.8.20 1.16 1.8.21 1.16.1 1.8.22 1.17 1.8.23 1.17.1 1.8.24 1.17.10 1.8.25 1.17.10-rc.1 1.8.26 1.17.11 1.8.27 1.17.12 1.8.28 1.17.12-rc.1 1.8.29 1.17.2 1.8.3 1.17.3 1.8.30 1.17.4 1.8.4 1.17.5 1.8.5 1.17.6 1.8.6 1.17.7 1.8.7 1.17.8 1.8.8 1.17.9 1.8.9 1.17.9-beta.1 1.9 1.18.0 2.0.0 1.19.0 2.0.1 1.19.1 2.0.10 1.2 2.0.11 1.2.1 2.0.12 1.2.2 2.0.13 1.2.3 2.0.14 1.2.4 2.0.15 1.2.5 2.0.16 1.2.6 2.0.17 1.2.7 2.0.18 1.20.0 2.0.19 1.20.0-rc.1 2.0.2 1.20.0-rc.2 2.0.20 1.20.1 2.0.3 1.20.2 2.0.4 1.20.3 2.0.5 1.21.0 2.0.6 1.21.1 2.0.7 1.22.0 2.0.8 1.22.1 2.0.9 1.22.2 1.23.0 1.23.1 1.23.2 1.24.0 1.24.1 1.24.2 1.25.0 1.25.1 1.26.0 1.27.0 1.28.0 1.29.0 1.29.1 1.3 1.3.1 1.3.10 1.3.11 1.3.12 1.3.13 1.3.14 1.3.15 1.3.16 1.3.17 1.3.18 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.30.0 1.30.1 1.30.2 1.30.2-rc.1 1.30.3 1.30.4 1.30.4-rc.1 1.30.5 1.31.0 1.31.1 1.32.0 1.32.0-rc.1 1.33.0 1.33.1 1.33.2 1.34.0 1.35.0 1.35.1 1.36.0 1.36.1 1.36.2 1.36.3 1.37.0 1.37.1 1.37.2
advanced-ads / admin / assets / js / admin.js
advanced-ads / admin / assets / js Last commit date
admin-global.js 8 years ago admin.js 8 years ago advertisement.js 9 years ago shortcode.js 10 years ago wizard.js 8 years ago
admin.js
963 lines
1 jQuery( document ).ready(function ($) {
2 if ( ! $.fn.accordion || ! $.fn.tooltip || ! advads_use_ui_buttonset() ) {
3 $( '.advads-jqueryui-error').show();
4 }
5
6 function advads_load_ad_type_parameter_metabox(ad_type) {
7 jQuery( '#advanced-ad-type input' ).prop( 'disabled', true );
8 $( '#advanced-ads-tinymce-wrapper' ).hide();
9 $( '#advanced-ads-ad-parameters' ).html( '<span class="spinner advads-ad-parameters-spinner advads-spinner"></span>' );
10 $.ajax({
11 type: 'POST',
12 url: ajaxurl,
13 data: {
14 'action': 'load_ad_parameters_metabox',
15 'ad_type': ad_type,
16 'ad_id': $( '#post_ID' ).val(),
17 'nonce': advadsglobal.ajax_nonce
18 },
19 success: function (data, textStatus, XMLHttpRequest) {
20 // toggle main content field
21 if (data) {
22 $( '#advanced-ads-ad-parameters' ).html( data ).trigger( 'paramloaded' );
23 advads_maybe_textarea_to_tinymce( ad_type );
24 }
25 },
26 error: function (MLHttpRequest, textStatus, errorThrown) {
27 $( '#advanced-ads-ad-parameters' ).html( errorThrown );
28 }
29 }).always( function ( MLHttpRequest, textStatus, errorThrown ) {
30 jQuery( '#advanced-ad-type input').prop( 'disabled', false );
31 });
32 };
33
34 $( document ).on('change', '#advanced-ad-type input', function () {
35 var ad_type = $( this ).val()
36 advads_load_ad_type_parameter_metabox( ad_type );
37 });
38
39 // trigger for ad injection after ad creation
40 $( '#advads-ad-injection-box .advads-ad-injection-button' ).on( 'click', function(){
41 var placement_type = this.dataset.placementType, // create new placement
42 placement_slug = this.dataset.placementSlug, // use existing placement
43 options = {};
44
45 if ( ! placement_type && ! placement_slug ) { return; }
46
47 // create new placement
48 if ( placement_type ) {
49 // for content injection
50 if ( 'post_content' === placement_type ) {
51 var paragraph = prompt( advadstxt.after_paragraph_promt, 1);
52 if ( paragraph !== null ) {
53 options.index = parseInt( paragraph, 10 );
54 }
55 }
56 }
57 $( '#advads-ad-injection-box .advads-loader' ).show();
58 $( '#advads-ad-injection-box-placements' ).hide();
59 $( 'body').animate({ scrollTop: $( '#advads-ad-injection-box' ).offset().top -40 }, 1, 'linear' );
60
61 $.ajax({
62 type: 'POST',
63 url: ajaxurl,
64 data: {
65 action: 'advads-ad-injection-content',
66 placement_type: placement_type,
67 placement_slug: placement_slug,
68 ad_id: $( '#post_ID' ).val(),
69 options: options,
70 nonce: advadsglobal.ajax_nonce
71 },
72 success: function (r, textStatus, XMLHttpRequest) {
73 $( '#advads-ad-injection-box *' ).hide();
74 // append anchor to placement message
75 $( '#advads-ad-injection-message-placement-created .advads-placement-link' ).attr( 'href', $( '#advads-ad-injection-message-placement-created a' ).attr( 'href' ) + r );
76 $( '#advads-ad-injection-message-placement-created, #advads-ad-injection-message-placement-created *' ).show();
77 },
78 error: function (MLHttpRequest, textStatus, errorThrown) {
79 $( '#advads-ad-injection-box' ).html( errorThrown );
80 }
81 }).always( function ( MLHttpRequest, textStatus, errorThrown ) {
82 // jQuery( '#advanced-ad-type input').prop( 'disabled', false );
83 });
84 });
85
86 // activate general buttons
87 if ( advads_use_ui_buttonset() ) {
88 $( '.advads-buttonset' ).buttonset();
89 }
90 // activate accordions
91 if ( $.fn.accordion ) {
92 $( ".advads-accordion" ).accordion({
93 active: false,
94 collapsible: true,
95 });
96 }
97
98 $( document ).on('click', '.advads-conditions-terms-buttons .button', function (e) {
99 $( this ).remove();
100 });
101 // display input field to search for terms
102 $( document ).on('click', '.advads-conditions-terms-show-search', function (e) {
103 e.preventDefault();
104 // display input field
105 $( this ).siblings( '.advads-conditions-terms-search' ).show().focus();
106 // register autocomplete
107 advads_register_terms_autocomplete( $( this ).siblings( '.advads-conditions-terms-search' ) );
108 $( this ).next( 'br' ).show();
109 $( this ).hide();
110 });
111 // function for autocomplete
112 function advads_register_terms_autocomplete( self ){
113 self.autocomplete({
114 source: function(request, callback){
115 // var searchField = request.term;
116 advads_term_search( self, callback );
117 },
118 minLength: 1,
119 select: function( event, ui ) {
120 // append new line with input fields
121 $( '<label class="button ui-state-active">' + ui.item.label + '<input type="hidden" name="' + self.data('inputName') + '" value="' + ui.item.value + '"></label>' ).appendTo( self.siblings( '.advads-conditions-terms-buttons' ) );
122
123 // show / hide other elements
124 // $( '.advads-display-conditions-individual-post' ).hide();
125 // $( '.advads-conditions-postids-list .show-search a' ).show();
126 },
127 close: function( event, ui ) {
128 self.val( '' );
129 }
130 });
131 }
132 // display input field to search for post, page, etc.
133 $( document ).on( 'click', '.advads-conditions-postids-show-search', function (e) {
134 e.preventDefault();
135 // display input field
136 $( this).next().find( '.advads-display-conditions-individual-post' ).show();
137 //$( '.advads-conditions-postids-search-line .description' ).hide();
138 $( this ).hide();
139 });
140 // register autocomplete to display condition individual posts
141 $( document ).on( "focus", ".advads-display-conditions-individual-post", function(e) {
142 var self = this;
143 if ( !$(this).data("autocomplete") ) { // If the autocomplete wasn't called yet:
144 $( this ).autocomplete({
145 source: function(request, callback){
146 var searchParam = request.term;
147 advads_post_search( searchParam, callback );
148 },
149 minLength: 1,
150 select: function( event, ui ) {
151 // append new line with input fields
152 var newline = $( '<label class="button ui-state-active">' + ui.item.label + '</label>' );
153 $( '<input type="hidden" name="' + self.dataset.fieldName + '[value][]" value="' + ui.item.value + '"/>' ).appendTo( newline );
154 newline.insertBefore( $( self ).parent( '.advads-conditions-postids-search-line' ) );
155 },
156 close: function( event, ui ) {
157 $( self ).val( '' );
158 },
159 })
160 .autocomplete().data("ui-autocomplete")._renderItem = function( ul, item ) {
161 ul.addClass( "advads-conditions-postids-autocomplete-suggestions" );
162 return $( "<li></li>" )
163 .append( "<span class='left'>" + item.label + "</span>&nbsp;<span class='right'>" + item.info + "</span>" )
164 .appendTo( ul );
165 };
166 };
167 });
168
169 // remove individual posts from the display conditions post list
170 $( document ).on('click', '.advads-conditions-postid-buttons .button', function(e){
171 $( this ).remove();
172 });
173 // display/hide error message if no option was selected
174 // is also called on every click
175 function advads_display_condition_option_not_selected(){
176 $( '.advads-conditions-not-selected' ).each(function(){
177 if( $( this ).siblings('input:checked').length ){
178 $( this ).hide();
179 } else {
180 $( this ).show();
181 }
182 });
183 }
184 advads_display_condition_option_not_selected();
185 // update error messages when an item is clicked
186 $( document ).on( 'click', '.advads-conditions-terms-buttons input[type="checkbox"], .advads-conditions-single input[type="checkbox"]', function(){
187 // needs a slight delay until the buttons are updated
188 window.setTimeout( advads_display_condition_option_not_selected, 200 );
189 });
190 // activate and toggle conditions connector option
191 $('.advads-conditions-connector input').advads_button();
192 // dynamically change label
193 $(document).on('click', '.advads-conditions-connector input', function(){
194 if( $( this ).is(':checked' ) ){
195 $( this ).button( "option", "label", advadstxt.condition_or );
196 $( this ).parents( '.advads-conditions-connector' ).addClass('advads-conditions-connector-or').removeClass('advads-conditions-connector-and');
197 } else {
198 $( this ).button( "option", "label", advadstxt.condition_and );
199 $( this ).parents( '.advads-conditions-connector' ).addClass('advads-conditions-connector-and').removeClass('advads-conditions-connector-or');
200 }
201 });
202 // remove a line with a display or visitor condition
203 $(document).on('click', '.advads-conditions-remove', function(){
204 $(this).parents('.advads-conditions-table tr').prev('tr').remove();
205 $(this).parents('.advads-conditions-table tr').remove();
206 });
207
208 // display new ad group form
209 $( '#advads-new-ad-group-link' ).click(function(e){
210 e.preventDefault();
211 $( '#advads-new-group-form' ).show().find('input[type="text"]').focus();
212 });
213
214 // display ad groups form
215 $( '#advads-ad-group-list a.edit, #advads-ad-group-list a.row-title' ).click(function(e){
216 e.preventDefault();
217 var advadsgroupformrow = $( this ).parents( '.advads-group-row' ).next( '.advads-ad-group-form' );
218 if(advadsgroupformrow.is( ':visible' )){
219 advadsgroupformrow.hide();
220 // clear last edited id
221 $('#advads-last-edited-group').val('');
222 } else {
223 advadsgroupformrow.show();
224 var group_id = $( this ).parents( '.advads-group-row' ).find('.advads-group-id').val();
225 $('#advads-last-edited-group').val( group_id );
226
227 }
228 });
229 // display ad groups usage
230 $( '#advads-ad-group-list a.usage' ).click(function(e){
231 e.preventDefault();
232 var usagediv = $( this ).parents( '.advads-group-row' ).find( '.advads-usage' );
233 if(usagediv.is( ':visible' )){
234 usagediv.hide();
235 } else {
236 usagediv.show();
237 }
238 });
239 // display placement settings form
240 $( '.advads-placements-table a.advads-placement-options-link' ).click(function(e){
241 e.preventDefault();
242 var advadsplacementformrow = $( this ).next( '.advads-placements-advanced-options' );
243 if( advadsplacementformrow.is( ':visible' ) ){
244 advadsplacementformrow.hide();
245 // clear last edited id
246 $('#advads-last-edited-placement').val('');
247 } else {
248 advadsplacementformrow.show();
249 var placement_id = $( this ).parents( '.advads-placements-table-options' ).find('.advads-placement-slug').val();
250 $('#advads-last-edited-placement').val( placement_id );
251
252 }
253 });
254 // display manual placement usage
255 $( '.advads-placements-table .usage-link' ).click(function(e){
256 e.preventDefault();
257 var usagediv = $( this ).parents( 'tr' ).find( '.advads-usage' );
258 if(usagediv.is( ':visible' )){
259 usagediv.hide();
260 } else {
261 usagediv.show();
262 }
263 });
264 /**
265 * automatically open all options and show usage link when this is the placement linked in the URL
266 * also highlight the box with an effect for a short time
267 */
268 if( jQuery( window.location.hash ).length ){
269 jQuery( window.location.hash ).toggleClass( 'advads-placement-background-blink' ).find( '.advads-toggle-link + div, .advads-usage' ).show();
270
271 }
272
273 // group page: add ad to group
274 $( '.advads-group-add-ad button' ).click( function() {
275 var $settings_row = $( this ).closest( '.advads-ad-group-form' ),
276 $ad = $settings_row.find( '.advads-group-add-ad-list-ads option:selected' )
277 $weight_selector = $settings_row.find( '.advads-group-add-ad-list-weights' ).last(),
278 $ad_table = $settings_row.find( '.advads-group-ads tbody' );
279 // add new row if does not already exist
280 if ( $ad.length && $weight_selector.length && ! $ad_table.find( '[name="' + $ad.val() + '"]' ).length ) {
281 $ad_table.append(
282 $( '<tr></tr>' ).append(
283 $( '<td></td>' ).html( $ad.text() ),
284 $( '<td></td>' ).append( $weight_selector.clone().val( $weight_selector.val() ).prop( 'name', $ad.val() ) ),
285 '<td><button type="button" class="advads-remove-ad-from-group button">x</button></td>'
286 )
287 );
288 }
289 });
290 // group page: remove ad from group
291 $( '#advads-ad-group-list' ).on( 'click', '.advads-remove-ad-from-group', function() {
292 var $ad_row = $( this ).closest( 'tr' );
293
294 if ( $ad_row.data( 'ad-id' ) ) {
295 // save the ad id, it is needed when this ad is not included in any other group
296 $( '#advads-ad-group-list form' ).append(
297 '<input type="hidden" name="advads-groups-removed-ads[]" value="' + $ad_row.data( 'ad-id' ) + '">'
298 );
299 }
300 $ad_row.remove();
301 });
302 // group page: handle switching of group types based on a class derrived from that type
303 $('.advads-ad-group-type input').click(function(){
304 advads_show_group_options( $( this ) );
305 });
306 function advads_show_group_options( el ){
307 // first, hide all options except title and type
308 // iterate through all elements
309 el.each( function(){
310 var _this = jQuery( this );
311 _this.parents('.advads-ad-group-form').find('.advads-option:not(.static)').hide();
312 var current_type = _this.val();
313
314 // now, show only the ones corresponding with the group type
315 _this.parents('.advads-ad-group-form').find( '.advads-group-type-' + current_type ).show();
316 });
317 }
318 // set default group options for earch group
319
320 advads_show_group_options( $( '.advads-ad-group-type input:checked' ) );
321 // group page: hide ads if more than 4 – than only show 3
322 $('.advads-ad-group-list-ads').each( function(){
323 if( 5 <= $(this).find('li').length ){
324 $(this).find('li:gt(2)').hide();
325 };
326 });
327 // show more than 3 ads when clicked on a link
328 $('.advads-group-ads-list-show-more').click( function(){
329 jQuery( this ).hide().parents('.advads-ad-group-list-ads').find('li').show();
330 });
331
332 /**
333 * SETTINGS PAGE
334 */
335
336 // activate licenses
337 $('.advads-license-activate').click(function(){
338
339 var button = $(this);
340
341 if( ! this.dataset.addon ) { return }
342
343 // hide button to prevent issues with activation when people click twice
344 button.hide();
345
346 var query = {
347 action: 'advads-activate-license',
348 addon: this.dataset.addon,
349 pluginname: this.dataset.pluginname,
350 optionslug: this.dataset.optionslug,
351 license: $(this).parents('td').find('.advads-license-key').val(),
352 security: $('#advads-licenses-ajax-referrer').val()
353 };
354
355 // show loader
356 $( '<span class="spinner advads-spinner"></span>' ).insertAfter( button );
357
358 // send and close message
359 $.post(ajaxurl, query, function (r) {
360 // remove spinner
361 $('span.spinner').remove();
362 var parent = button.parents('td');
363
364 if( r === '1' ){
365 parent.find('.advads-license-activate-error').remove();
366 parent.find('.advads-license-deactivate').show();
367 button.fadeOut();
368 parent.find('.advads-license-activate-active').fadeIn();
369 parent.find('input').prop('readonly', 'readonly');
370 } else if( r === 'ex' ){
371 parent.find('.advads-license-activate-error').remove();
372 parent.find('.advads-license-expired-error').show();
373 button.show();
374 } else {
375 parent.find('.advads-license-activate-error').show().text( r );
376 button.show();
377 }
378 });
379 });
380
381 // deactivate licenses
382 $('.advads-license-deactivate').click(function(){
383
384 var button = $(this);
385
386 if( ! this.dataset.addon ) { return }
387
388 // hide button to prevent issues with double clicking
389 button.hide();
390
391 var query = {
392 action: 'advads-deactivate-license',
393 addon: this.dataset.addon,
394 pluginname: this.dataset.pluginname,
395 optionslug: this.dataset.optionslug,
396 security: $('#advads-licenses-ajax-referrer').val()
397 };
398
399 // show loader
400 $( '<span class="spinner advads-spinner"></span>' ).insertAfter( button );
401
402 // send and close message
403 $.post(ajaxurl, query, function (r) {
404 // remove spinner
405 $('span.spinner').remove();
406
407 if( r === '1' ){
408 button.siblings('.advads-license-activate-error').hide();
409 button.siblings('.advads-license-activate-active').hide();
410 button.siblings('.advads-license-activate').show();
411 button.siblings('input').prop('readonly', false);
412 button.fadeOut();
413 } else if( r === 'ex' ){
414 button.siblings('.advads-license-activate-error').hide();
415 button.siblings('.advads-license-activate-active').hide();
416 button.siblings('.advads-license-expired-error').show();
417 button.siblings('input').prop('readonly', false);
418 button.fadeOut();
419 } else {
420 button.siblings('.advads-license-activate-error').show().text( r );
421 button.siblings('.advads-license-activate-active').hide();
422 button.show();
423 }
424 });
425 });
426
427
428
429
430 /**
431 * PLACEMENTS
432 */
433 // show image tooltips
434 if ( $.fn.tooltip ) {
435 $( ".advads-placements-new-form .advads-placement-type" ).tooltip({
436 items: "span",
437 content: function() {
438 return $( this ).parents('.advads-placement-type').find( '.advads-placement-description' ).html();
439 }
440 });
441 }
442
443 /**
444 * Image ad uploader
445 */
446 $('body').on('click', '.advads_image_upload', function(e) {
447
448 e.preventDefault();
449
450 var button = $(this);
451
452 // If the media frame already exists, reopen it.
453 if ( file_frame ) {
454 // file_frame.uploader.uploader.param( 'post_id', set_to_post_id );
455 file_frame.open();
456 return;
457 }
458
459 // Create the media frame.
460 file_frame = wp.media.frames.file_frame = wp.media( {
461 id: 'advads_type_image_wp_media',
462 title: button.data( 'uploaderTitle' ),
463 button: {
464 text: button.data( 'uploaderButtonText' )
465 },
466 library: {
467 type: 'image'
468 },
469 multiple: false // only allow one file to be selected
470 } );
471
472 // When an image is selected, run a callback.
473 file_frame.on( 'select', function() {
474
475 var selection = file_frame.state().get('selection');
476 selection.each( function( attachment, index ) {
477 attachment = attachment.toJSON();
478 if ( 0 === index ) {
479 // place first attachment in field
480 $( '#advads-image-id' ).val( attachment.id );
481 $( '#advanced-ads-ad-parameters-size input[name="advanced_ad[width]"]' ).val( attachment.width );
482 $( '#advanced-ads-ad-parameters-size input[name="advanced_ad[height]"]' ).val( attachment.height );
483 // update image preview
484 var new_image = '<img width="'+ attachment.width +'" height="'+ attachment.height +
485 '" title="'+ attachment.title +'" alt="'+ attachment.alt +'" src="'+ attachment.url +'"/>';
486 $('#advads-image-preview').html( new_image );
487 $('#advads-image-edit-link').attr( 'href', attachment.editLink );
488 // process "reserve this space" checkbox
489 $( '#advanced-ads-ad-parameters-size input[type=number]:first' ).change();
490 }
491 });
492 });
493
494 // Finally, open the modal
495 file_frame.open();
496 });
497
498 // WP 3.5+ uploader
499 var file_frame;
500 window.formfield = '';
501
502 advads_ad_list_build_filters();
503
504 // adblocker related code
505 $( '#advanced-ads-use-adblocker' ).change( function() {
506 advads_toggle_box( this, '#advads-adblocker-wrapper' );
507 });
508
509 // processing of the rebuild asset form and the FTP/SSH credentials form
510 var $advads_adblocker_wrapper = $( '#advads-adblocker-wrapper' );
511 $advads_adblocker_wrapper.find( 'input[type="submit"]' ).prop( 'disabled', false );
512 $advads_adblocker_wrapper.on( 'submit', 'form', function( event ) {
513 event.preventDefault();
514 var $form = $( '#advanced-ads-rebuild-assets-form' );
515 $form.prev( '.error' ).remove();
516 $form.find( 'input[type="submit"]' ).prop( 'disabled', true ).after( '<span class="spinner advads-spinner"></span>' );
517
518 var args = {
519 data: {
520 action: 'advads-adblock-rebuild-assets',
521 nonce: advadsglobal.ajax_nonce,
522 },
523 done: function( data, textStatus, jqXHR ) {
524 var $advads_adblocker_wrapper = $( '#advads-adblocker-wrapper' );
525 $advads_adblocker_wrapper.html( data );
526 },
527 fail: function( jqXHR, textStatus, errorThrown ) {
528 $form.before( '<div class="error"><p>' + textStatus + ': ' + errorThrown + '</p></div>' );
529 $form.find( 'input[type="submit"]' ).prop( 'disabled', false ).next( '.advads-spinner' ).remove();
530 },
531 on_modal_close: function() {
532 var $form = $( '#advanced-ads-rebuild-assets-form' );
533 $form.find( 'input[type="submit"]' ).prop( 'disabled', false ).next( '.advads-spinner' ).remove();
534 }
535 }
536
537 $.each( $form.serializeArray(), function( i, o ) {
538 args.data[ o.name ] = o.value;
539 });
540
541 advanced_ads_admin.filesystem.ajax( args );
542 });
543
544 // process "reserve this space" checkbox
545 $( '#advanced-ads-ad-parameters' ).on( 'change', '#advanced-ads-ad-parameters-size input[type=number]', function() {
546 if ( $( '#advanced-ads-ad-parameters-size input[type=number]' ).filter( function() {
547 return parseInt( this.value, 10 ) > 0;
548 }).length === 2 ) {
549 $( '#advads-wrapper-add-sizes' ).prop( 'disabled', false );
550 } else {
551 $( '#advads-wrapper-add-sizes' ).prop( 'disabled', true ).prop( 'checked', false );
552 }
553 });
554 // process "reserve this space" checkbox - ad type changed
555 $( '#advanced-ads-ad-parameters' ).on( 'paramloaded', function() {
556 $( '#advanced-ads-ad-parameters-size input[type=number]:first' ).change();
557 })
558 // process "reserve this space" checkbox - on load
559 $( '#advanced-ads-ad-parameters-size input[type=number]:first' ).change();
560
561 // move meta box markup to hndle headline
562 $('.advads-hndlelinks').each(function(){
563 $(this).removeClass('hidden');
564 $(this).appendTo( $(this).parent('.inside').siblings('h2.hndle') );
565 });
566 // open tutorial link when clicked on it
567 $('.advads-video-link').click(function( el ){
568 el.preventDefault();
569 var video_container = $(this).parents('h2').siblings('.inside').find('.advads-video-link-container');
570 video_container.html( video_container.data('videolink') );
571 });
572 // open inline tutorial link when clicked on it
573 $('.advads-video-link-inline').click(function( el ){
574 el.preventDefault();
575 var video_container = $(this).parents('div').siblings('.advads-video-link-container');
576 video_container.html( video_container.data('videolink') );
577 });
578 // switch import type
579 jQuery( '.advads_import_type' ).change( function() {
580 if ( this.value === 'xml_content' ) {
581 jQuery( '#advads_xml_file' ).hide();
582 jQuery( '#advads_xml_content' ).show();
583 } else {
584 jQuery( '#advads_xml_file' ).show();
585 jQuery( '#advads_xml_content' ).hide();
586 }
587 });
588 });
589
590 /**
591 * store the action hash in settings form action
592 * thanks for Yoast SEO for this idea
593 */
594 function advads_set_tab_hashes() {
595 // iterate through forms
596 jQuery( '#advads-tabs' ).find( 'a' ).each(function () {
597 var id = jQuery( this ).attr( 'id' ).replace( '-tab', '' );
598 var optiontab = jQuery( '#' + id );
599
600 var form = optiontab.children( '.advads-settings-tab-main-form' );
601 if ( form.length ) {
602 var currentUrl = form.attr( 'action' ).split( '#' )[ 0 ];
603 form.attr( 'action', currentUrl + jQuery( this ).attr( 'href' ) );
604 }
605 });
606 }
607
608 /**
609 * callback for term search autocomplete
610 *
611 * @param {type} search term
612 * @param {type} callback
613 * @returns {obj} json object with labels and values
614 */
615 function advads_term_search(field, callback) {
616
617 // return ['post', 'poster'];
618 var query = {
619 action: 'advads-terms-search',
620 nonce: advadsglobal.ajax_nonce
621 };
622
623 query.search = field.val();
624 query.tax = field.data('tagName');
625
626 var querying = true;
627
628 var results = {};
629 jQuery.post(ajaxurl, query, function (r) {
630 querying = false;
631 var results = [];
632 if(r){
633 r.map(function(element, index){
634 results[index] = {
635 value: element.term_id,
636 label: element.name
637 };
638 });
639 }
640 callback( results );
641 }, 'json');
642 }
643
644 /**
645 * callback for post search autocomplete
646 *
647 * @param {str} searchParam
648 * @param {type} callback
649 * @returns {obj} json object with labels and values
650 */
651 function advads_post_search( searchParam, callback ) {
652
653 // return ['post', 'poster'];
654 var query = {
655 action: 'advads-post-search',
656 _ajax_linking_nonce: jQuery( '#_ajax_linking_nonce' ).val(),
657 'search': searchParam,
658 nonce: advadsglobal.ajax_nonce
659 };
660
661 var querying = true;
662
663 var results = {};
664 jQuery.post(ajaxurl, query, function (r) {
665 querying = false;
666 var results = [];
667 if(r){
668 r.map(function(element, index){
669 results[index] = {
670 label: element.title,
671 value: element.ID,
672 info: element.info
673 };
674 });
675 }
676 callback( results );
677 }, 'json');
678 }
679
680 /**
681 * toggle content elements (hide/show)
682 *
683 * @param selector jquery selector
684 */
685 function advads_toggle(selector) {
686 jQuery( selector ).slideToggle();
687 }
688
689 /**
690 * toggle content elements with a checkbox (hide/show)
691 *
692 * @param selector jquery selector
693 */
694 function advads_toggle_box(e, selector) {
695 if (jQuery( e ).is( ':checked' )) {
696 jQuery( selector ).slideDown();
697 } else {
698 jQuery( selector ).slideUp();
699 }
700 }
701
702 /**
703 * disable content of one box when selecting another
704 * only grey/disable it, don’t hide it
705 *
706 * @param selector jquery selector
707 */
708 function advads_toggle_box_enable(e, selector) {
709 if (jQuery( e ).is( ':checked' )) {
710 jQuery( selector ).find( 'input' ).removeAttr( 'disabled', '' );
711 } else {
712 jQuery( selector ).find( 'input' ).attr( 'disabled', 'disabled' );
713 }
714 }
715
716 /**
717 * validate placement form on submit
718 */
719 function advads_validate_placement_form(){
720 // check if placement type was selected
721 if( ! jQuery('.advads-placement-type input:checked').length){
722 jQuery('.advads-placement-type-error').show();
723 return false;
724 } else {
725 jQuery('.advads-placement-type-error').hide();
726 }
727 // check if placement name was entered
728 if( jQuery('.advads-new-placement-name').val() == '' ){
729 jQuery('.advads-placement-name-error').show();
730 return false;
731 } else {
732 jQuery('.advads-placement-name-error').hide();
733 }
734 return true;
735 }
736
737 /**
738 * replace textarea with TinyMCE editor for Rich Content ad type
739 */
740 function advads_maybe_textarea_to_tinymce( ad_type ) {
741 var textarea = jQuery( '#advads-ad-content-plain' ),
742 textarea_html = textarea.val(),
743 tinymce_id = 'advanced-ads-tinymce',
744 tinymce_id_ws = jQuery( '#' + tinymce_id ),
745 tinymce_wrapper_div = jQuery ( '#advanced-ads-tinymce-wrapper' );
746
747 if ( ad_type !== 'content' ) {
748 tinymce_id_ws.prop('name', tinymce_id );
749 tinymce_wrapper_div.hide();
750 return false;
751 }
752
753 if ( typeof tinyMCE === 'object' && tinyMCE.get( tinymce_id ) !== null ) {
754 // visual mode
755 if ( textarea_html ) {
756 // see BeforeSetContent in the wp-includes\js\tinymce\plugins\wordpress\plugin.js
757 var wp = window.wp,
758 hasWpautop = ( wp && wp.editor && wp.editor.autop && tinyMCE.get( tinymce_id ).getParam( 'wpautop', true ) );
759 if ( hasWpautop ) {
760 textarea_html = wp.editor.autop( textarea_html );
761 }
762 tinyMCE.get( tinymce_id ).setContent( textarea_html );
763 }
764 textarea.remove();
765 tinymce_id_ws.prop('name', textarea.prop( 'name' ) );
766 tinymce_wrapper_div.show();
767 } else if ( tinymce_id_ws.length ) {
768 // text mode
769 tinymce_id_ws.val( textarea_html );
770 textarea.remove();
771 tinymce_id_ws.prop('name', textarea.prop( 'name' ) );
772 tinymce_wrapper_div.show();
773 }
774 }
775
776 /**
777 * adds <option> tags to <select> dropdowns before the 'Filter' button on the ad list table
778 * @param {string} jQuery wrapped set where to find value/text for <option>
779 * @param {string} jQuery wrapped set with <select> tag
780 */
781 function advads_ad_list_add_items_to_dropdowns( $input, $select ) {
782 var all_unique_rows = [];
783
784 $input.each( function() {
785 var one_row = jQuery( this ).text();
786
787 if ( jQuery.inArray( one_row, all_unique_rows ) === -1 ) {
788 all_unique_rows.push( one_row );
789 $select.append(
790 jQuery("<option/>", {
791 value: one_row,
792 text: one_row
793 })
794 );
795 }
796 });
797 }
798
799 /**
800 * adds filter dropdowns before the 'Filter' button on the ad list table
801 */
802 function advads_ad_list_build_filters() {
803 var $filter_type = jQuery( '#advads-filter-type' ),
804 $filter_size = jQuery( '#advads-filter-size' ),
805 $filter_group = jQuery( '#advads-filter-group' ),
806 $filter_date = jQuery( '#advads-filter-date' ),
807 $ad_planning_col = jQuery( '.advads-filter-timing' );
808
809 advads_ad_list_add_items_to_dropdowns( jQuery( '.advads-ad-type' ), $filter_type );
810 advads_ad_list_add_items_to_dropdowns( jQuery( '.advads-ad-size' ), $filter_size );
811 advads_ad_list_add_items_to_dropdowns( jQuery( '.taxonomy-advanced_ads_groups a' ), $filter_group );
812 // if such classes exist on the page - show related <option>s
813 jQuery( '#advads-filter-date option:gt(0)' ).each( function() {
814 var v = jQuery( this ).val();
815 if ( $ad_planning_col.hasClass( v ) ) {
816 $filter_date.children( 'option[value="' + v + '"] ' ).show();
817 }
818 });
819
820 jQuery( "#advads-filter-type, #advads-filter-size, #advads-filter-group, #advads-filter-date" ).change( function() {
821 var $the_list_tr = jQuery( '#the-list tr' ).removeClass( 'advads-hidden' );
822
823 if ( $filter_type.val() ) {
824 $the_list_tr.filter( function() {
825 return jQuery( this ).find( '.advads-ad-type' ).text() !== $filter_type.val();
826 }).addClass( 'advads-hidden' );
827 }
828 if ( $filter_size.val() ) {
829 $the_list_tr.not( '.advads-hidden' ).filter ( function() {
830 return jQuery( this ).find( '.advads-ad-size' ).text() !== $filter_size.val();
831 }).addClass( 'advads-hidden' );
832 }
833 if ( $filter_date.val() ) {
834 $the_list_tr.not( '.advads-hidden' ).filter( function() {
835 return jQuery( this ).find( '.' + $filter_date.val() ).length === 0;
836 }).addClass( 'advads-hidden' );
837 }
838 if ( $filter_group.val() ) {
839 $the_list_tr.not( '.advads-hidden' ).filter( function() {
840 var ret = false;
841 //iterate through each group within current tr
842 jQuery( this ).find( '.taxonomy-advanced_ads_groups a' ).each( function() {
843 if ( jQuery( this ).text() === $filter_group.val() ) {
844 ret = true;
845 return false; //break the loop
846 }
847 });
848 return ret === false;
849 }).addClass( 'advads-hidden' );
850 }
851 // create stripped table, because css nth-child does not counts hidden rows
852 $the_list_tr.not( '.advads-hidden' ).filter( ':odd' ).addClass( 'advads-ad-list-odd' ).removeClass( 'advads-ad-list-even' ).end()
853 .filter( ':even' ).addClass( 'advads-ad-list-even' ).removeClass( 'advads-ad-list-odd' );
854 });
855 }
856
857 // Change JQueryUI names to fix name collision with other libraries, eg. Bootstrap
858 jQuery.fn.advads_button = jQuery.fn.button;
859
860 /**
861 * check if jQueryUI button/buttonset can be used
862 */
863 var advads_use_ui_buttonset = ( function() {
864 var ret = null;
865 return function () {
866 if ( null === ret ) {
867 var needle = 'var g="string"==typeof f,h=c.call(arguments,1)'; //string from jquery-ui source code
868 ret = jQuery.fn.advads_button && jQuery.fn.buttonset && jQuery.fn.button.toString().indexOf( needle ) !== -1;
869 }
870 return ret;
871 };
872 })();
873
874 window.advanced_ads_admin = window.advanced_ads_admin || {};
875 advanced_ads_admin.filesystem = {
876 /**
877 * Holds the current job while the user writes data in the 'Connection Information' modal.
878 *
879 * @type {obj}
880 */
881 _locked_job: false,
882
883 /**
884 * Toggle the 'Connection Information' modal.
885 */
886 _requestForCredentialsModalToggle: function() {
887 this.$filesystemModal.toggle();
888 jQuery( 'body' ).toggleClass( 'modal-open' );
889 },
890
891 _init: function() {
892 this._init = function() {}
893 var self = this;
894
895 self.$filesystemModal = jQuery( '#advanced-ads-rfc-dialog' );
896 /**
897 * Sends saved job.
898 */
899 self.$filesystemModal.on( 'submit', 'form', function( event ) {
900 event.preventDefault();
901
902 self.ajax( self._locked_job, true );
903 self._requestForCredentialsModalToggle()
904 } );
905
906 /**
907 * Closes the request credentials modal when clicking the 'Cancel' button.
908 */
909 self.$filesystemModal.on( 'click', '[data-js-action="close"]', function() {
910 if ( jQuery.isPlainObject( self._locked_job ) && self._locked_job.on_modal_close ) {
911 self._locked_job.on_modal_close();
912 }
913
914 self._locked_job = false;
915 self._requestForCredentialsModalToggle();
916 } );
917 },
918
919 /**
920 * Sends AJAX request. Shows 'Connection Information' modal if needed.
921 *
922 * @param {object} args
923 * @param {bool} skip_modal
924 */
925 ajax: function( args, skip_modal ) {
926 this._init();
927
928 if ( ! skip_modal && this.$filesystemModal.length > 0 ) {
929 this._requestForCredentialsModalToggle();
930 this.$filesystemModal.find( 'input:enabled:first' ).focus();
931
932 // Do not send request.
933 this._locked_job = args;
934 return;
935 }
936
937 var options = {
938 method: 'POST',
939 url: window.ajaxurl,
940 data: {
941 username: jQuery( '#username' ).val(),
942 password: jQuery( '#password' ).val(),
943 hostname: jQuery( '#hostname' ).val(),
944 connection_type: jQuery( 'input[name="connection_type"]:checked' ).val(),
945 public_key: jQuery( '#public_key' ).val(),
946 private_key: jQuery( '#private_key' ).val()
947 }
948 };
949
950 options.data = jQuery.extend( options.data, args.data );
951 var request = jQuery.ajax( options );
952
953 if ( args.done ) {
954 request.done( args.done );
955 }
956
957 if ( args.fail ) {
958 request.fail( args.fail );
959 }
960 }
961 }
962
963