PageSourceSearch

https://elektrowoz.pl/wp-content/plugins/advanced-iframe/js/ai.min.js?ver=903824

js elektrowoz.pl collected 2026-10-02 03:27:51 UTC 81,855 bytes, 2,099 lines download raw bytes

1/** Advanced iframe free/pro functions v. Created: 2025-08-06 09:49:00 */
2/**
3 *  Advanced iframe pro functions v2021.6
4*/
5/* jslint devel: true, unused: false */
6/* globals ai_show_id_only:false, aiIsIe8: false, aiChangeUrl: false, aiResizeIframeHeightId: false, aiShowIframeId: false, findAndReplaceDOMText: false, aiShowDebug: false */
7
8var aiEnableCookie=false;
9var aiId='';
10var aiExtraSpace = 0;
11var aiAccTime = 0;
12var aiOnloadEventsCounter = 0;
13
14var aiCallbackExists = typeof aiReadyCallbacks !== 'undefined' && aiReadyCallbacks instanceof Array;
15var aiReadyCallbacks = aiCallbackExists ? aiReadyCallbacks : [];
16
17
18/**
19* The debug messages are enabled if you enable the debug console.
20*/
21function aiDebugExtended(message) {
22  if (typeof aiShowDebug !== 'undefined' && aiShowDebug) {
23    if (console && console.log) {
24      console.log("Advanced iframe: " + message);
25    }
26  }
27}
28
29/**
30 *  This function resizes the iframe after loading to the height
31 *  of then content of the iframe.
32 *
33 *  The extra space is not stored in the cookie! The height would
34 *  be added every time otherwise and the iframe would grow,
35 */
36function aiResizeIframe(obj, resizeWidth, resizeMinHeight) {
37  aiDebugExtended("aiResizeIframe");
38  try {
39    if (obj.contentWindow.location.href === 'about:blank') {
40        return;
41    }
42    if (obj.contentWindow.document.body != null) {
43      var oldScrollposition = jQuery(window).scrollTop();
44      obj.style.marginTop = 0; 
45	  obj.style.marginBottom = 0;
46      obj.height = Number(resizeMinHeight); // set to 1 because otherwise the iframe does never get smaller.
47      obj.style.height = Number(resizeMinHeight) + 'px';
48      var newheight = aiGetIframeHeight(obj);
49	  aiDebugExtended("aiResizeIframe - newheight: " + newheight);
50      obj.height = newheight;
51      obj.style.height = newheight + 'px';
52
53       // set the height of the zoom div
54      if (jQuery('#ai-zoom-div-' + obj.id).length !== 0) {
55         var zoom = window['zoom_' + obj.id];
56         jQuery('#ai-zoom-div-' + obj.id).css('height', newheight * zoom);
57      }
58
59      if (aiEnableCookie && aiExtraSpace === 0 ) {
60          aiWriteCookie(newheight);
61      }
62      var hash = aiGetIframeHash(obj.contentWindow.location.href);
63      if (hash !== -1) {
64		  var iframeId = '#'+ obj.id;
65          try {
66              var hashposition = jQuery(iframeId).contents().find('#'+ hash);
67              if (hashposition.length !== 0) {
68                var hashpositionTop = hashposition.offset().top;
69                oldScrollposition = Math.round(jQuery(iframeId).offset().top + hashpositionTop);
70              }
71          } catch(e) {
72              // in case of an invalid hash it is ignored. 
73          }
74      }
75	  setTimeout(function() {
76           jQuery("html,body").scrollTop(oldScrollposition);
77      }, 50);   
78
79      if (resizeWidth === 'true') {
80        var newWidth = aiGetIframeWidth(obj);
81        obj.width = newWidth;
82        obj.style.width = newWidth + 'px';
83      }
84      var fCallback = window['resizeCallback' + obj.id];
85      fCallback();
86      // fires the onload event again if iframes are wrapped
87      if (window.frameElement != null) {
88        parent.jQuery('iframe').trigger('onload');
89      }
90    } else {
91      // body is not loaded yet - we wait 100 ms.
92      setTimeout(function() { aiResizeIframe(obj, resizeWidth); },100);
93    }
94  } catch(e) {
95    if (console && console.error) {
96      console.error('Advanced iframe configuration error: You have enabled the resize of the iframe for pages on the same domain. But you use an iframe page on a different domain. You need to use the external workaround like described in the settings. Also check the next log. There the browser message for this error is displayed.');
97      console.log(e);
98    }
99  }
100}
101
102/**
103 * returns the position of a #hash in the iframe or -1 if none was found.
104 */
105 
106function aiGetIframeHash(url) {
107    var hash = url.split('#')[1];
108    return (hash) ? hash : '-1';
109}
110
111/**
112 *  Get the iframe height
113 */
114function aiGetIframeHeight(obj) {
115      var bodyHeight = Math.max(obj.contentWindow.document.body.scrollHeight,
116       obj.contentWindow.document.body.offsetHeight,
117       obj.contentWindow.document.documentElement.scrollHeight,
118       obj.contentWindow.document.documentElement.offsetHeight);
119       var newheight = bodyHeight + aiExtraSpace;
120       return newheight;
121}
122
123/**
124 *  Get the iframe width
125 */
126function aiGetIframeWidth(obj) {
127    var oldWidth =  obj.width;
128    obj.width = 1; // set to 1 because otherwise I don't get the minimum width
129    obj.style.width = '1px';
130    var bodyWidth = Math.max(obj.contentWindow.document.body.scrollWidth,
131          obj.contentWindow.document.body.offsetWidth,
132          obj.contentWindow.document.documentElement.scrollWidth,
133          obj.contentWindow.document.documentElement.offsetWidth);
134    if (bodyWidth !== 1) { // avoid that fully responsive sites do not get displayed at all.
135      obj.width = bodyWidth;
136      obj.style.width = bodyWidth + 'px';
137    } else {
138      obj.width = oldWidth;
139      obj.style.width = oldWidth + 'px';
140    }
141    return bodyWidth;
142}
143
144/**
145 *  Get the current width of the iframe inside the parent.
146 */
147function aiGetParentIframeWidth(obj) {
148    if (obj != null && jQuery('#' + obj.id).length !== 0) {
149        return jQuery('#' + obj.id).width();
150    } else {
151        return -1;
152    }
153}
154
155
156/**
157 *  Resizes an iframe to a given height.
158 *  this is used for xss enabled iframes.
159 *  Please read the documentation!
160 */
161function aiResizeIframeHeightById(id, nHeight) {
162  aiDebugExtended("aiResizeIframeHeightById - id: " + id + ", nHeight: " + nHeight);
163  try {
164    var fCallback = window['resizeCallback' + id];
165    fCallback();
166    var height = parseInt(nHeight,10) + aiExtraSpace;
167    var iframe = document.getElementById(id);
168	var oldScrollposition = jQuery(document).scrollTop();
169    iframe.height = height;
170    iframe.style.height = height + 'px';
171    jQuery("html,body").scrollTop(oldScrollposition); 
172    if (aiEnableCookie && aiExtraSpace === 0) {
173      aiWriteCookie(height);
174    }
175    // send the new height to the parent if it is a wrapped call
176    var parentResizeCall = window['aiExecuteWorkaround_' + id];
177    if (parentResizeCall != null) {
178      parentResizeCall();
179    }
180  }  catch(e) {
181    if (console && console.error) {
182      console.error('Advanced iframe configuration error: The id of the parent and the external workaround are different! Check your settings.');
183      console.log(e);
184    }
185  }
186}
187
188
189/**
190 * Scrolls the parent window to the top.
191 * This is e.g. wanted when you have a link in the iframe and you want that the
192 * page starts at the top and not that only the iframe changes.
193 *
194 * Sometimes are 2 onload events after another. To prevent that this causes 
195 * a jump to the top a delay of 1 sec is used for the increase of the counter.
196 */
197function aiScrollToTop(id, position) {
198   aiDebugExtended("aiScrollToTop - id: " + id + ", position: " + position);
199  
200  if (aiOnloadEventsCounter > 0) {
201	  var posTop = 0;
202	  if (position === 'iframe') {
203		posTop = jQuery('#' + id).offset().top;
204	  }
205	  setTimeout(function() {
206		 aiDebugExtended("aiScrollToTop - posTop: " + posTop);   
207		window.scrollTo(0, posTop);
208	  }, 100);   
209  }
210  setTimeout(function() {
211    aiOnloadEventsCounter++;
212  }, 1000);  
213}
214
215/**
216 * Writes the last height to the cookie.
217 */
218function aiWriteCookie(height) {
219  var cookieName = 'ai-last-height';
220  if (aiId !== '') {
221    cookieName =  cookieName + '-' + aiId ;
222  }
223  var cookieStr = cookieName + '=' + height;
224  document.cookie=cookieStr;
225}
226
227/**
228 * Reads the cookie and preset the height of the iframe
229 */
230function aiUseCookie() {
231  var cookieName = 'ai-last-height';
232  if (aiId !== '') {
233    cookieName = cookieName + '-' + aiId ;
234  }
235  var allcookies = document.cookie;
236  // Get all the cookies pairs in an array
237  var cookiearray  = allcookies.split(';');
238  // Now take key value pair out of this array
239  for (var i = 0; i < cookiearray.length; i++) {
240    var name = cookiearray[i].split('=')[0];
241    var value = cookiearray[i].split('=')[1];
242    // cookie does exist and has a numeric value
243    if (name === cookieName && value !== null && aiIsNumeric(value)) {
244       var iframe = document.getElementById(aiId);
245       iframe.height = parseInt(value,10);
246       iframe.style.height = value + 'px';
247    }
248  }
249}
250
251/**
252 *  check if we have a numeric input
253 */
254function aiIsNumeric(input){
255    return !isNaN(input);
256}
257
258/**
259* Disable the additional_height input field
260*/
261function aiDisableHeight() {
262  jQuery('#additional_height').attr('readonly','readonly');
263  jQuery('#additional_height').val('0');
264}
265
266/**
267* Enable the additional_height input field
268*/
269function aiEnableHeight() {
270  jQuery('#additional_height').removeAttr('readonly');
271}
272
273/**
274 * Removes all elements from an iframe except the given one
275 *
276 * @param iframeId id of the iframe
277 * @param showElement the id, class (jQuery syntax) of the element that should be displayed.
278 */
279function aiShowElementOnly( iframeId, showElement ) {
280  aiDebugExtended("aiShowElementOnly");
281  try {
282    var iframe = jQuery(iframeId).contents().find('body');
283    var selectedBox = iframe.find(showElement).clone(true,true);
284    iframe.find('*').not(jQuery('script')).remove();
285    iframe.prepend(selectedBox);
286  }  catch(e) {
287    if (console && console.error) {
288      console.error('Advanced iframe configuration error: You have enabled to show only one element of the iframe for pages on the same domain. But you use an iframe page on a different domain. You need to use the pro version of the external workaround like described in the settings. Also check the next log. There the browser message for this error is displayed.');
289      console.log(e);
290    }
291  }
292}
293
294function aiCheckIfValidTarget(evt, elements) {
295  var targ;
296  if (!evt) {
297    evt = window.event;
298  }
299  if (evt.target) {
300    targ = evt.target;
301  } else if (evt.srcElement) {
302    targ = evt.srcElement;
303  }
304  if (targ.nodeType === 3) {
305    targ = targ.parentNode;
306  }
307
308  var parts = elements.split(',');
309  // check each part if we have a match...
310  for (var i=0; i< parts.length; ++i) {
311    var selectorArray = parts[i].split(':');
312    if (selectorArray[0].toLowerCase() === targ.nodeName.toLowerCase()) {
313      if (selectorArray.length > 1) {
314           if (targ.id.toLowerCase().indexOf(selectorArray[1].toLowerCase()) !== -1) {
315               return true;
316           }
317      } else {
318        return true;
319      }
320    }
321  }
322  return false;
323}
324
325function aiOpenSelectorWindow (url) {
326   aiDebugExtended("aiOpenSelectorWindow");
327   var localWidth =  jQuery('#width').val();
328   var localHeight = jQuery('#ai-height-0').val();
329
330   if (localWidth.indexOf('%') >= 0 || Number(localWidth) < 900) {
331       localWidth = 900;
332   }
333   localWidth = Number(localWidth) + 40;
334   if ( localWidth > (screen.width)) {
335       localWidth = screen.width;
336   }
337   if (localHeight.indexOf('%') >= 0) {
338       localHeight = screen.height;
339   } else {
340        localHeight =  Number(localHeight) + 480;
341   }
342   if ( localHeight > (screen.height-50)) {
343       localHeight = screen.height-50;
344   }
345   var options = 'width='+localWidth+',height='+localHeight+',left=0,top=0,resizable=1,scrollbars=1';
346   var popup_window = window.open(url, '', options);
347   popup_window.focus();
348}
349
350function aiDisableAiResizeOptions(value) {
351  jQuery('#onload_resize_delay').prop('readonly',value);
352  jQuery('input[id=store_height_in_cookie1]:radio, input[id=store_height_in_cookie2]:radio').attr('disabled',value);
353  jQuery('#additional_height').prop('readonly', value);
354  jQuery('input[id=onload_resize_width1]:radio, input[id=onload_resize_width2]:radio').attr('disabled',value);
355  jQuery('#resize_on_click').prop('readonly', value);
356  jQuery('#resize_on_click_elements').prop('readonly', value);
357  jQuery('#resize_on_ajax').prop('readonly', value);
358  jQuery('input[id=resize_on_ajax_jquery1]:radio, input[id=resize_on_ajax_jquery2]:radio').attr('disabled',value);
359  
360  var selector = '#onload_resize_delay, #store_height_in_cookie1, #additional_height, #onload_resize_width1, ';
361  selector += '#resize_on_click, #resize_on_click_elements, #resize_on_ajax, #resize_on_ajax_jquery1';
362  aiDisableTextSection(value, selector);
363}
364
365function aiDisablePartOfIframeOptions(value) {
366  jQuery('#show_part_of_iframe_x').prop('readonly',value);
367  jQuery('#show_part_of_iframe_y').prop('readonly',value);
368  jQuery('#show_part_of_iframe_height').prop('readonly',value);
369  jQuery('#show_part_of_iframe_width').prop('readonly',value);
370  jQuery('input[id=show_part_of_iframe_allow_scrollbar_horizontal1]:radio, input[id=show_part_of_iframe_allow_scrollbar_horizontal2]:radio').attr('disabled',value);
371  jQuery('input[id=show_part_of_iframe_allow_scrollbar_vertical1]:radio, input[id=show_part_of_iframe_allow_scrollbar_vertical2]:radio').attr('disabled',value);
372  jQuery('#show_part_of_iframe_next_viewports').prop('readonly',value);
373  jQuery('input[id=show_part_of_iframe_next_viewports_loop1]:radio, input[id=show_part_of_iframe_next_viewports_loop2]:radio').attr('disabled',value);
374  jQuery('#show_part_of_iframe_new_window').prop('readonly',value);
375  jQuery('#show_part_of_iframe_new_url').prop('readonly',value);
376  jQuery('input[id=show_part_of_iframe_next_viewports_hide1]:radio, input[id=show_part_of_iframe_next_viewports_hide2]:radio').attr('disabled',value);
377  jQuery('#show_part_of_iframe_style').prop('readonly',value);
378  jQuery('input[id=show_part_of_iframe_zoom1]:radio, input[id=show_part_of_iframe_zoom2]:radio, input[id=show_part_of_iframe_zoom3]:radio').attr('disabled',value);
379  jQuery('.media-query-input').prop('readonly',value);
380 
381 
382  var selector = '#show_part_of_iframe_x, #show_part_of_iframe_y, #show_part_of_iframe_height, #show_part_of_iframe_width, ';
383  selector += '#show_part_of_iframe_allow_scrollbar_horizontal1, #show_part_of_iframe_next_viewports, #show_part_of_iframe_next_viewports_loop1, ';
384  selector += '#show_part_of_iframe_new_window, #show_part_of_iframe_new_url, #show_part_of_iframe_next_viewports_hide1, #show_part_of_iframe_style, ';
385  selector += '#show_part_of_iframe_zoom1, #show_part_of_iframe_allow_scrollbar_vertical1, #add-media-query-show_part_of_iframe_media_query';
386  aiDisableTextSection(value, selector);
387  
388  if (value) {
389      jQuery('#add-media-query-show_part_of_iframe_media_query').hide();
390	  jQuery('.ai-delete').hide();
391  } else {
392	  jQuery('#add-media-query-show_part_of_iframe_media_query').show();
393	  jQuery('.ai-delete').show();
394  }
395  
396}
397
398function aiDisableLazyLoadOptions(value) {
399  jQuery('#enable_lazy_load_threshold').prop('readonly', value);
400  jQuery('#enable_lazy_load_fadetime').prop('readonly', value);
401  jQuery('input[id=enable_lazy_load_reserve_space1]:radio, input[id=enable_lazy_load_reserve_space2]:radio').attr('disabled',value);
402  jQuery('input[id=enable_lazy_load_manual1]:radio, input[id=enable_lazy_load_manual2]:radio, input[id=enable_lazy_load_manual3]:radio').attr('disabled',value);
403   
404  var selector = '#enable_lazy_load_threshold, #enable_lazy_load_fadetime, #enable_lazy_load_reserve_space1, #enable_lazy_load_manual1';
405  aiDisableTextSection(value, selector);
406  }
407
408function aiDisableIframeAsLayerOptions(value) {
409  jQuery('input[id=show_iframe_as_layer_full]:radio').attr('disabled',value);
410  jQuery('#show_iframe_as_layer_header_file').prop('readonly', value);
411  jQuery('#show_iframe_as_layer_header_height').prop('readonly', value);
412  jQuery('#show_iframe_as_layer_autoclick_delay').prop('readonly', value);
413  jQuery('#show_iframe_as_layer_autoclick_hide_time').prop('readonly', value);
414  jQuery('input[id=show_iframe_as_layer_header_position1]:radio, input[id=show_iframe_as_layer_header_position2]:radio').attr('disabled',value);
415  jQuery('input[id=show_iframe_as_layer_full1]:radio, input[id=show_iframe_as_layer_full2]:radio, input[id=show_iframe_as_layer_full3]:radio').attr('disabled',value);
416  jQuery('input[id=show_iframe_as_layer_keep_content1]:radio, input[id=show_iframe_as_layer_keep_content2]:radio').attr('disabled',value);
417
418  var selector = '#show_iframe_as_layer_full, #show_iframe_as_layer_header_file, #show_iframe_as_layer_header_height, ';
419  selector += '#show_iframe_as_layer_header_position1, #show_iframe_as_layer_full1, #show_iframe_as_layer_keep_content1, ';
420  selector += '#show_iframe_as_layer_autoclick_delay, #show_iframe_as_layer_autoclick_hide_time';
421    
422  aiDisableTextSection(value, selector);
423 
424}
425
426function aiDisableAddParamOptions(value) {
427	jQuery('input[id=add_iframe_url_as_param_direct1]:radio, input[id=add_iframe_url_as_param_direct2]:radio').attr('disabled',value);
428	jQuery('#add_iframe_url_as_param_prefix').prop('readonly',value);
429    var selector = '#add_iframe_url_as_param_prefix, #add_iframe_url_as_param_direct1';
430    aiDisableTextSection(value, selector);
431}
432
433function aiDisableTextSection(value, selector) {
434	if (value) {
435        jQuery(selector).closest('tr').addClass('disabled');
436    } else {
437	    jQuery(selector).closest('tr').removeClass('disabled');
438    }
439}
440
441var aiInstance;
442
443/**
444 *  This function initializes all checks that are done by Javascript
445 *  on the admin page like enabling disabling fields...
446 */
447function aiInitAdminConfiguration(isPro, acc_type) {
448    // enable checkbox of onload_resize_delay and if resize is set to true external workaround is set to false
449    if (jQuery('input[type=radio][name=onload_resize]:checked').val() === 'false') {
450        aiDisableAiResizeOptions(true);
451    }
452    jQuery('input[type=radio][name=onload_resize]').click( function(){
453    if (jQuery(this).val() === 'true') {
454           jQuery('input:radio[name=enable_external_height_workaround]')[1].checked = true; // set to external!
455           aiDisableAiResizeOptions(false);
456        } else {
457           jQuery('#onload_resize_delay').val('');
458           aiDisableAiResizeOptions(true);
459
460        }
461    });
462
463    // if external workaround is set to to true resize on load is set to false and the
464    // onload_resize_delay is made readonly
465    jQuery('input[type=radio][name=enable_external_height_workaround]').click( function(){
466    if (jQuery(this).val() === 'true') {
467           jQuery('input:radio[name=onload_resize]')[1].checked = true;
468           jQuery('#onload_resize_delay').val('');
469           aiDisableAiResizeOptions(true);
470        }
471    });
472
473    // Show only a part of the iframe enable/disable
474     if (jQuery('input[type=radio][name=show_part_of_iframe]:checked').val() === 'false') {
475        aiDisablePartOfIframeOptions(true);
476     }
477      jQuery('input[type=radio][name=show_part_of_iframe]').click( function(){
478    if (jQuery(this).val() === 'false') {
479          aiDisablePartOfIframeOptions(true);
480        } else {
481          aiDisablePartOfIframeOptions(false);
482        }
483    });
484
485    // show_iframe_as_layer enable/disable
486     if (jQuery('input[type=radio][name=show_iframe_as_layer]:checked').val() === 'false') {
487        aiDisableIframeAsLayerOptions(true);
488     }
489      jQuery('input[type=radio][name=show_iframe_as_layer]').click( function(){
490    if (jQuery(this).val() === 'false') {
491          aiDisableIframeAsLayerOptions(true);
492        } else {
493          aiDisableIframeAsLayerOptions(false);
494        }
495    });
496
497    // if expert mode
498    if (jQuery('input[type=radio][name=expert_mode]:checked').val() === 'true') {
499      jQuery('.description').css('display','none');
500      jQuery('table.form-table th').css('cursor','pointer');
501      jQuery('table.form-table th').css('padding-top','8px').css('padding-bottom','2px');
502      jQuery('table.form-table td').css('padding-top','5px').css('padding-bottom','5px');
503      jQuery('table.form-table th').click(function() {
504           jQuery('.description').css('display','none');
505           jQuery('.description', jQuery(this).parent()).css('display','block');
506        });
507    }
508    jQuery('input[type=radio][name=expert_mode]').click( function(){
509      if (jQuery(this).val() === 'false') {
510        jQuery('.description').css('display','block');
511        jQuery('table.form-table th').css('cursor','auto');
512        jQuery('table.form-table th').off('click');
513        jQuery('table.form-table th').css('padding-top','20px').css('padding-bottom','20px');
514        jQuery('table.form-table td').css('padding-top','15px').css('padding-bottom','15px');
515      } else {
516        jQuery('.description').css('display','none');
517        jQuery('table.form-table th').css('cursor','pointer');
518        jQuery('table.form-table th').css('padding-top','8px').css('padding-bottom','2px');
519        jQuery('table.form-table td').css('padding-top','5px').css('padding-bottom','5px');
520        jQuery('table.form-table th').click(function() {
521           jQuery('.description').css('display','none');
522           jQuery('.description', jQuery(this).parent()).css('display','block');
523        });
524      }
525    });
526
527
528     jQuery('#accordion').find('h1').click(function(){
529         jQuery(this).next().slideToggle(aiAccTime);
530     }).next().hide();
531
532     jQuery('#accordion').find('a').click(function(){
533         var hash = jQuery(this).prop('hash');
534         var hash_only = '#h1-' + hash.substring(1);
535         jQuery(hash_only).next().show();
536         location.hash = hash_only;
537     });
538
539    // lazy load
540    if (jQuery('input[type=radio][name=enable_lazy_load_manual]:checked').val() === 'false') {
541        jQuery('#enable_lazy_load_manual_element').prop('readonly',true);
542    }
543
544    jQuery('input[type=radio][name=enable_lazy_load_manual]').click( function(){
545    if (jQuery(this).val() === 'false' || jQuery(this).val() === 'auto') {
546           jQuery('#enable_lazy_load_manual_element').prop('readonly',true);
547        } else {
548           jQuery('#enable_lazy_load_manual_element').prop('readonly',false);
549        }
550    });
551	
552	// add_iframe_url_as_param
553	if (jQuery('input[type=radio][name=add_iframe_url_as_param]:checked').val() === 'false') {
554        aiDisableAddParamOptions(true);
555    }
556	jQuery('input[type=radio][name=add_iframe_url_as_param]').click( function(){
557        aiDisableAddParamOptions(jQuery(this).val() === 'false');
558    });
559	
560    if (jQuery('input[type=radio][name=enable_lazy_load]:checked').val() === 'false') {
561        aiDisableLazyLoadOptions(true);
562        jQuery('#enable_lazy_load_manual_element').prop('readonly',true);
563    }
564
565    jQuery('input[type=radio][name=enable_lazy_load]').click( function(){
566    if (jQuery(this).val() === 'false') {
567           aiDisableLazyLoadOptions(true);
568           jQuery('#enable_lazy_load_manual_element').prop('readonly',true);
569        } else {
570           aiDisableLazyLoadOptions(false);
571           if (jQuery('input[type=radio][name=enable_lazy_load_manual]:checked').val() === 'false' ||
572               jQuery('input[type=radio][name=enable_lazy_load_manual]:checked').val() === 'auto' ) {
573             jQuery('#enable_lazy_load_manual_element').prop('readonly',true);
574           } else {
575             jQuery('#enable_lazy_load_manual_element').prop('readonly', false);
576           }
577        }
578    });
579
580    jQuery('.confirmation').on('click', function () {
581        return confirm('Are you sure? Selecting OK will set all settings to the default.');
582    });
583
584     jQuery('a.post').click(function(e) {
585          e.stopPropagation();
586          e.preventDefault();
587          var href = this.href;
588          var parts = href.split('?');
589          var url = parts[0];
590          var params = parts[1].split('&');
591          var pp, inputs = '';
592          url += '?' + params[0];
593          for(var i = 1, n = params.length; i < n; i++) {
594              pp = params[i].split('=');
595              inputs += '<input type="hidden" name="' + pp[0] + '" value="' + pp[1] + '" />';
596          }
597          jQuery('body').append('<form action="'+url+'" method="post" id="poster">'+inputs+'</form>');
598          jQuery('#poster').submit();
599      });
600
601      jQuery('.ai-input-search').keyup(function(e) {
602           var searchTerm = jQuery('input.ai-input-search').val().toLowerCase();
603           aiSettingsSearch(searchTerm, acc_type);
604      });
605       jQuery('.ai-input-search').on('click', function(e) {
606           setTimeout(function() {
607           var searchTerm = jQuery('input.ai-input-search').val().toLowerCase();
608           aiSettingsSearch(searchTerm, acc_type);
609           }, 100);
610      });
611
612      jQuery(document).on( 'click', '.nav-tab-wrapper a', function() {
613        var current_tab = jQuery(this).attr('id');
614        jQuery('section').hide();
615        jQuery('section.' + current_tab ).show();
616        jQuery('#current_tab').val(current_tab.substr(4,1));
617        jQuery('.nav-tab').removeClass('nav-tab-active');
618        jQuery(this).addClass('nav-tab-active');
619        jQuery(this).blur();
620		
621        return false;
622      });
623
624      // set the links between tabs and open the right one at the right section.
625        jQuery(document).on( 'click', 'a#external-workaround-link', function() {
626          jQuery('.external-workaround').click();
627          location.hash = 'tab_3';
628		  // no flash
629		  aiShowHeader('tab_3');
630          return false;
631        });
632        jQuery(document).on( 'click', 'a#resize-same-link', function() {
633          jQuery('.advanced-settings-tab').click();
634		  jQuery('#id-advanced-resize').removeClass('closed');
635          location.hash = 'id-advanced-resize';
636		  // no flash
637          aiShowHeader('id-advanced-resize');  
638          return false;
639        });
640         jQuery(document).on( 'click', 'a.jquery-help-link', function() {
641          jQuery('.help-tab').click();
642		  jQuery('#id-help-jquery').removeClass('closed');
643          jQuery('#jquery-help').show();
644          location.hash = 'id-help-jquery';
645		  // no flash
646		  aiShowHeader('id-help-jquery');
647		  return false;
648        });
649        jQuery(document).on( 'click', 'a#browser-detection-link', function() {
650          jQuery('.help-tab').click();
651		  jQuery('#id-help-browser').removeClass('closed');
652          jQuery('#browser-help').show();
653          location.hash = 'id-help-browser';
654		  // no flash
655          aiShowHeader('id-help-browser');
656          return false;
657        });
658        jQuery(document).on( 'click', 'a.howto-id-link', function() {
659          jQuery('.help-tab').click();
660		  jQuery('#id-help-id').removeClass('closed');
661          location.hash = 'id-help-id';
662		  // no flash
663          aiShowHeader('id-help-id');
664          return false;
665        });
666        jQuery(document).on( 'click', '.modifycontent-link', function() {
667          jQuery('.advanced-settings-tab').click();
668		  jQuery('#id-advanced-modify-iframe').removeClass('closed');
669          location.hash = 'id-advanced-modify-iframe';
670           aiShowHeader('id-advanced-modify-iframe', 'tr-' + jQuery(this).data('detail'));   
671          return false;
672        });
673		
674        jQuery(document).on( 'click', '.id-modify-css-iframe-link', function() {
675          jQuery('.advanced-settings-tab').click();
676		  jQuery('#id-advanced-modify-iframe').removeClass('closed');
677          location.hash = 'id-modify-css-iframe';
678           aiShowHeader('id-advanced-modify-iframe', 'tr-' + jQuery(this).data('detail'));   
679          return false;
680        });
681		
682		 jQuery(document).on( 'click', '.modify-target', function() {
683          jQuery('.advanced-settings-tab').click();
684		  jQuery('#id-advanced-modify-iframe').removeClass('closed');
685          location.hash = 'id-modify-target';
686          aiShowHeader('id-advanced-modify-iframe', 'tr-' + jQuery(this).data('detail'));  
687          return false;
688        });
689
690         jQuery(document).on( 'click', 'a.link-external-domain', function() {     
691          jQuery('#id-external-different').removeClass('closed');
692		  location.hash = '#id-external-different';
693		  // no flash - 'id-external-different'
694		  aiShowHeader('id-external-different');
695          return false;
696        });
697		jQuery(document).on( 'click', 'a.link-id-external-ai-config-post', function() {
698          jQuery('#id-external-ai-config-post').removeClass('closed');
699		  location.hash = '#id-external-ai-config-post';  
700		  aiShowHeader('id-external-ai-config-post', 'tr-use_post_message');
701          return false;
702        });
703		jQuery(document).on( 'click', 'a.link-id-external-ai-overview', function() {
704          jQuery('#id-external-ai-overview').removeClass('closed');
705		  location.hash = '#id-external-ai-overview';
706		  aiShowHeader('id-external-ai-overview', 'id-external-ai-overview');
707          return false;
708        });
709		jQuery(document).on( 'click', 'a.post-message-help-link', function() {
710          jQuery('.help-tab').click();
711          jQuery('#id-help-communication').removeClass('closed');
712		  location.hash = '#id-help-communication';
713          aiShowHeader('id-help-communication','id-help-communication');
714          return false;
715        });
716		
717		jQuery(document).on( 'click', 'a.enable-admin', function() {
718          jQuery('.options-tab').click();
719		  jQuery('#id-options-display').removeClass('closed');
720          location.hash = '#id-options-display';
721          aiShowHeader('id-options-display', 'tr-demo');    
722          return false;
723        });
724		
725		jQuery(document).on( 'click', 'a.enter-registration', function() {
726          jQuery('.options-tab').click();
727		  jQuery('#id-options-display').removeClass('closed');
728          location.hash = '#id-options-display';
729          aiShowHeader('id-options-display', 'tr-demo');    
730          return false;
731        });
732	
733      jQuery(document).on( 'click', 'a#user-help-link', function() {
734          jQuery('#user-help').css('display', 'block');
735          return false;
736      });
737      jQuery(document).on( 'click', 'a#user-meta-link', function() {
738          jQuery('#meta-help').css('display', 'block');
739          return false;
740      });
741
742      jQuery(document).on( 'click', '#ai-selector-help-link', function() {
743          jQuery('#ai-selector-help').slideDown(1000);
744          return false;
745        });
746
747      jQuery(document).on( 'click', '.ai-selector-help-link-move', function() {
748          jQuery('#ai-selector-help').show('slow');
749		  location.hash = '#ai-selector-help-link';
750          // no flash
751		  aiShowHeader('ai-selector-help-link');   
752          return false;
753        });
754
755      jQuery('#ai_form').submit(function() {
756        aiSetScrollposition();
757      });
758			
759	// Close postboxes that should be closed.
760	jQuery('.if-js-closed').removeClass('if-js-closed').addClass('closed');
761	// Postboxes setup.
762	if (typeof postboxes !== 'undefined') {
763		postboxes.add_postbox_toggles('toplevel_page_advanced-iframe');
764	}
765 	
766	jQuery('.ai-spinner').css('display','none');
767	jQuery("#" + acc_type).next().show();
768	
769	jQuery(document).on( 'click', '#test-pro-admin.is-permanent-closable button', function() {
770	  closeInfoPermanent('test-pro-admin');
771    });
772	
773	jQuery(document).on( 'click', '#show-registration-message.is-permanent-closable button', function() {
774	  closeInfoPermanent('show-registration-message');
775    });
776
777	jQuery(document).on( 'click', '#show-version-message.is-permanent-closable button', function() {
778	  closeInfoPermanent('show-version-message');
779    });	
780	
781	
782	 jQuery(document).on( 'click', '.mq-breakpoint-height a', function(evt) {
783	  jQuery(this).parent().remove();
784	  aiUpdateHeightHiddenField('height');
785	  evt.preventDefault();
786	  return false;
787	});
788	
789    jQuery(document).on( 'click', 'a#add-media-query-height', function(evt) {
790	  // count existing elements
791	  var nextNr =  jQuery(".mq-breakpoint-height").length + 1; 
792	  jQuery(this).parent().append('<div id="breakpoint-row-height-'+nextNr+'" class="mq-breakpoint-height">' + 
793	  '<input type="text" id="ai-height-' + nextNr + '" style="width:150px;margin-top:5px;"  onblur="aiCheckHeightNumber(this, \'height\');" placeholder="Insert height"/> &nbsp;
793Breakpoint: ' + 
794	  '<input type="text" id="ai-breakpoint-height-' +nextNr + '" style="width:130px;" onblur="aiCheckHeightNumber(this, \'height\');" placeholder="Insert breakpoint"/>' +
795	  '<a id="delete-media-query-'+nextNr+'" href="#" class="delete ai-delete">Delete</a>');  	   
796	  evt.preventDefault();
797	  return false;
798	});
799	
800    jQuery(document).on( 'click', '.mq-breakpoint-show_part_of_iframe_media_query a', function(evt) {
801	  jQuery(this).parent().remove();
802	  aiUpdateHeightHiddenFieldMediaQuery('show_part_of_iframe_media_query');
803	  evt.preventDefault();
804	  return false;
805	});
806	
807    jQuery(document).on( 'click', 'a#add-media-query-show_part_of_iframe_media_query', function(evt) {
808	  // count existing elements
809	  var nextNr =  jQuery(".mq-breakpoint-show_part_of_iframe_media_query").length + 1; 
810	  jQuery(this).parent().append('<div id="breakpoint-row-show_part_of_iframe_media_query-'+nextNr+'" class="mq-breakpoint-show_part_of_iframe_media_query">' + 
811	  'x: <input type="text" id="ai-x-show_part_of_iframe_media_query-' + nextNr + '" class="media-query-input" ' +
812	  ' onblur="aiCheckHeightNumberMediaQuery(this, \'show_part_of_iframe_media_query\');" placeholder="x"/>' +
813	  ' &nbsp;y: <input type="text" id="ai-y-show_part_of_iframe_media_query-' + nextNr + '" class="media-query-input" ' + 
814	  ' onblur="aiCheckHeightNumberMediaQuery(this, \'show_part_of_iframe_media_query\');" placeholder="y"/>'+
815	  ' &nbsp;w: <input type="text" id="ai-w-show_part_of_iframe_media_query-' + nextNr + '" class="media-query-input" ' + 
816	  ' onblur="aiCheckHeightNumberMediaQuery(this, \'show_part_of_iframe_media_query\');" placeholder="width"/>'+
817	  ' &nbsp;h: <input type="text" id="ai-h-show_part_of_iframe_media_query-' + nextNr + '" class="media-query-input" ' + 
818	  ' onblur="aiCheckHeightNumberMediaQuery(this, \'show_part_of_iframe_media_query\');" placeholder="height"/>'+
819	  ' &nbsp;iframe width: <input type="text" id="ai-i-show_part_of_iframe_media_query-' + nextNr + '" class="media-query-input" style="width:100px;" ' + 
820	  ' onblur="aiCheckHeightNumberMediaQuery(this, \'show_part_of_iframe_media_query\');" placeholder="iframe width"/>'+
821	  ' &nbsp;Breakpoint: <input type="text" id="ai-breakpoint-show_part_of_iframe_media_query-' +nextNr + '" class="media-query-input" style="width:130px;" ' + 
822	  ' onblur="aiCheckHeightNumberMediaQuery(this, \'show_part_of_iframe_media_query\');" placeholder="Insert breakpoint"/>' + 
823	  '<a id="delete-media-query-show_part_of_iframe_media_query-'+nextNr+'" href="#" class="delete ai-delete">Delete</a>');  	   
824	  evt.preventDefault();
825	  return false;
826	});		
827}
828
829function aiCheckHeightNumber(element, id) {
830	aiCheckInputNumber(element);
831	aiUpdateHeightHiddenField(id);
832}
833
834function aiCheckHeightNumberMediaQuery(element, id) {
835	aiCheckInputNumber(element);
836	aiUpdateHeightHiddenFieldMediaQuery(id);
837}
838
839
840function aiUpdateHeightHiddenField(id) {
841	var heightDefault = jQuery('#ai-'+id+'-0').val();
842	var breakpoints = [];
843	jQuery('.mq-breakpoint-'+id).each(function( index ) {
844      
845	   var heightChild = jQuery(this).children().eq(0).val();
846	   var breakpointChild = jQuery(this).children().eq(1).val();
847	   
848	   if (heightChild !== '' && breakpointChild !== '') { 
849		  breakpoints.push({
850             heightChild: heightChild,
851             breakpointChild: breakpointChild
852         });
853       }
854    });
855	
856	// we sort to have higher breakpoints first. Because of css cascading styles order is important
857	breakpoints.sort(function(a, b) { 
858	    return b.breakpointChild - a.breakpointChild; 
859	});
860
861	let output = heightDefault; 
862	breakpoints.forEach(function(element) { output += ',' + element.heightChild + '|' + element.breakpointChild; });
863	jQuery('#'+id).val(output);
864	const newVal = jQuery('#description-'+id).html().split('Shortcode attribute: ')[0];
865	jQuery('#description-'+id).html(newVal + 'Shortcode attribute: ' + id + '="' + output + '"');
866	
867}
868
869function aiUpdateHeightHiddenFieldMediaQuery(id) {
870	var breakpoints = [];
871	jQuery('.mq-breakpoint-'+id).each(function( index ) {
872      
873	   var mediaX = jQuery(this).children().eq(0).val();
874	   var mediaY = jQuery(this).children().eq(1).val();
875	   var mediaW = jQuery(this).children().eq(2).val();
876	   var mediaH = jQuery(this).children().eq(3).val(); 
877	   var mediaIW = jQuery(this).children().eq(4).val(); 
878	   var breakpointChild = jQuery(this).children().eq(5).val();
879	   
880	   if ((mediaX !== '' || mediaY !== '' || mediaW !== '' || mediaH !== '' || mediaIW !== '') &&
881 	       breakpointChild !== '') { 
882		   breakpoints.push({
883             mediaX: mediaX,
884			 mediaY: mediaY,
885			 mediaW: mediaW,
886			 mediaH: mediaH,
887			 mediaIW: mediaIW,
888             breakpointChild: breakpointChild
889         });
890       }
891    });
892	
893	// we sort to have higher breakpoints first. Because of css cascading styles order is important
894	breakpoints.sort(function(a, b) { 
895	    return b.breakpointChild - a.breakpointChild; 
896	});
897	
898	let output = '';
899	breakpoints.forEach(function(element) { output += ',' + element.mediaX + '|' + element.mediaY + '|' + 
900	element.mediaW + '|' + element.mediaH + '|' + element.mediaIW + '|' + element.breakpointChild });
901	output = output.replace(/(^,)|(,$)/g, "");
902	jQuery('#'+id).val(output);
903	// update description
904	const newVal = jQuery('#description-'+id).html().split('Shortcode attribute: ')[0];
905	jQuery('#description-'+id).html(newVal + 'Shortcode attribute: ' + id + '="' + output + '"');
906}
907
908		   
909function aiSettingsSearch(searchTerm, accType) {
910 var found = 0;
911
912 if (searchTerm !== '') {
913   jQuery('#ai p').not('.form-table p').hide();
914   jQuery('#ai ul').not('.form-table ul').hide();
915   jQuery('#ai ol').not('.form-table ol').hide();
916   if (accType !== 'false') {
917     jQuery('#ai h1').not('.show-always').hide();
918     jQuery('#ai #accordion').attr('id','acc');
919     jQuery('#ai #acc > div').show();
920     jQuery('#ai #spacer-div').show();
921   }
922   jQuery('#ai h2,#ai .icon_ai,#ai h3,#ai h4').not('.show-always').hide();
923   jQuery('#ai .form-table').addClass('ai-remove-margin');
924   jQuery('#ai hr, .signup_account_container, .config-file-block').hide();
925   jQuery('#ai .hide-always').hide();
926   jQuery('#ai .hide-search').hide();
927   jQuery('#ai .postbox-container').not('.show-always').hide();
928 } else {
929   jQuery('#ai p').not('.form-table p').show();
930   jQuery('#ai section .ai-anchor').show();
931   jQuery('#ai ul').not('.form-table ul').show();
932   jQuery('#ai ol').not('.form-table ol').show();
933   if (accType !== 'false') {
934     jQuery('#ai h1').not('.show-always').show();
935     jQuery('#ai #acc').attr('id','accordion');
936     jQuery('#ai #accordion > div').hide();
937     jQuery('#ai #spacer-div').hide();
938   }
939   jQuery('#ai h2,#ai .icon_ai,#ai h3,#ai h4').not('.show-always').show();
940   jQuery('#ai .form-table').removeClass('ai-remove-margin');
941   jQuery('#ai hr, .signup_account_container, .config-file-block').show();
942   jQuery('#ai .sub-domain-container').show();
943   jQuery('#ai .hide-search').show();
944   jQuery('#ai .hide-always').hide();
945   jQuery('#ai .postbox-container').show();
946   
947   setTimeout(function() {
948       jQuery('#ai .postbox-container .closed .inside').css('display', '');
949   }, 5);   
950   
951 }
952
953 jQuery('#ai .mark-tab-header').removeClass('mark-tab-header');
954
955 var firstHit = '';
956
957 // check the search.
958  jQuery('#ai tr').each(function() {
959    var $this = jQuery(this);
960    var valueLabel = $this.find('th').text();
961    var valueDescription = $this.find('p.description').text();
962
963    valueLabel = (valueLabel !== undefined) ?  valueLabel.toLowerCase() : 'XXXXXXX';
964    valueDescription = (valueDescription !== undefined) ?  valueDescription.toLowerCase() : 'XXXXXXX';
965
966    if (valueLabel.indexOf(searchTerm) === -1 && valueDescription.indexOf(searchTerm) === -1) {
967      $this.addClass('hide-setting');
968    } else {
969	  $this.closest('table').prevAll('h2:first').show();
970	  $this.closest('.postbox-container').show();
971	  $this.closest('.postbox-container').find('h2, .inside').show();
972      $this.closest('table').prevAll('#ai .icon_ai:first').show();
973      $this.closest('table').nextAll('p.button-submit:first').show();
974      $this.removeClass('hide-setting');
975      $this.closest('.hide-search').show();
976
977      if (searchTerm.length > 2) {
978        var headerId = $this.closest('section').attr('class');
979        if (headerId !== undefined) {
980            jQuery('#' + headerId).addClass('mark-tab-header');
981            if (firstHit==='') {
982              firstHit = headerId;
983            }
984        }
985      }
986      found++;
987    }
988  });
989  if (found === 0) {
990    jQuery('#ai-input-search-result').show();
991    jQuery('#ai .mark-tab-header').removeClass('mark-tab-header');
992  } else {
993    jQuery('#ai-input-search-result').hide();
994    // https://github.com/padolsey/findAndReplaceDOMText
995    aiInstance && aiInstance.revert();
996      if (searchTerm !== '' && searchTerm.length > 2) {
997      var regex = RegExp(searchTerm, 'gi');
998      aiInstance = findAndReplaceDOMText(document.getElementById('tab_wrapper'), {
999        find: regex,
1000        wrap: 'em'
1001      });
1002    }
1003    jQuery('#' + firstHit).click();
1004
1005  }
1006}
1007
1008
1009/**
1010 *  Resizes the iframe with a certain ratio.
1011 *  Width is read and the height is than calculated.
1012 */
1013function aiResizeIframeRatio(obj, ratio) {
1014   aiDebugExtended("aiResizeIframeRatio");
1015   var width = jQuery('#' + obj.id).width();
1016   var valueRatio = parseFloat(ratio.replace(',', '.'));
1017   var newHeight = Math.ceil(width * valueRatio);
1018   obj.height = newHeight;
1019   obj.style.height = newHeight + 'px';
1020}
1021
1022/**
1023 * Generate a shortcode string from the current settings.
1024 */
1025function aiGenerateShortcode(isPro) {
1026    var output = '[advanced_iframe ';
1027
1028    // default section
1029    if (jQuery('#securitykey').val() !=='') {
1030      output += 'securitykey="' + jQuery('#securitykey').val() + '" ';
1031    }
1032    output += 'use_shortcode_attributes_only="true" ';
1033
1034    var include_html_val = jQuery('#include_html').val();
1035    var include_url_val = jQuery('#include_url').val();
1036    var document_domain_add = jQuery('#document_domain_add').val();
1037
1038    if (include_html_val === undefined || (include_html_val === '' && include_url_val === ''))  {
1039        var src = jQuery('#src').val();
1040        if (src === '') {
1041           alert('Required url is missing.');
1042        } else {
1043           output += 'src="' + src + '" ';
1044        }
1045
1046        output += aiGenerateTextShortcode('src_hide');
1047        output += aiGenerateTextShortcode('width');
1048        output += aiGenerateTextShortcode('height');
1049        output += aiGenerateRadioShortcode('scrolling','none');
1050        output += aiGenerateRadioShortcode('enable_ios_mobile_scolling','false');
1051        output += aiGenerateTextShortcode('marginwidth');
1052        output += aiGenerateTextShortcode('marginheight');
1053        output += aiGenerateTextShortcode('frameborder');
1054        output += aiGenerateRadioShortcode('transparency','true');
1055        output += aiGenerateTextShortcode('class');
1056        output += aiGenerateTextShortcode('style');
1057        output += aiGenerateTextShortcodeWithDefault('id', 'advanced_iframe');
1058        output += aiGenerateTextShortcode('name');
1059        output += aiGenerateRadioShortcode('allowfullscreen','false');
1060        output += aiGenerateTextShortcode('safari_fix_url');
1061
1062        // advanced settings
1063        output += aiGenerateTextShortcode('url_forward_parameter');
1064        output += aiGenerateTextShortcode('map_parameter_to_url');
1065        output += aiGenerateRadioShortcode('add_iframe_url_as_param','false');
1066        output += aiGenerateTextShortcode('add_iframe_url_as_param_prefix');
1067		output += aiGenerateRadioShortcode('add_iframe_url_as_param_direct','false');
1068
1069        output += aiGenerateRadioShortcode('onload_scroll_top','false');
1070        output += aiGenerateRadioShortcode('hide_page_until_loaded','false');
1071        output += aiGenerateRadioShortcode('show_iframe_loader','false');
1072        output += aiGenerateTextShortcode('hide_content_until_iframe_color');
1073        output += aiGenerateTextShortcode('iframe_zoom');
1074        output += aiGenerateRadioShortcode('iframe_zoom_ie8', 'false');
1075        output += aiGenerateRadioShortcode('use_zoom_absolute_fix', 'false');
1076        output += aiGenerateRadioShortcode('auto_zoom', 'false');
1077        output += aiGenerateTextShortcode('auto_zoom_by_ratio');
1078
1079        output += aiGenerateRadioShortcode('enable_responsive_iframe','false');
1080        output += aiGenerateTextShortcode('iframe_height_ratio');
1081
1082
1083        output += aiGenerateRadioShortcode('enable_lazy_load','false');
1084        output += aiGenerateTextShortcodeWithDefault('enable_lazy_load_threshold','3000');
1085        output += aiGenerateRadioShortcode('enable_lazy_load_reserve_space','true');
1086
1087        output += aiGenerateTextShortcode('enable_lazy_load_fadetime');
1088        output += aiGenerateRadioShortcode('enable_lazy_load_manual','fal
1088se');
1089        output += aiGenerateRadioShortcode('enable_lazy_load_manual_element','false');
1090        output += aiGenerateTextShortcode('reload_interval');
1091
1092        // modify the parent page
1093       output += aiGenerateTextShortcode('hide_elements');
1094       output += aiGenerateTextShortcode('content_id');
1095       output += aiGenerateTextShortcode('content_styles');
1096       output += aiGenerateTextShortcode('parent_content_css');
1097       output += aiGenerateRadioShortcode('add_css_class_parent','false');
1098
1099       output += aiGenerateTextShortcode('change_parent_links_target');
1100       output += aiGenerateRadioShortcode('show_iframe_as_layer', 'false');
1101       output += aiGenerateRadioShortcode('show_iframe_as_layer_full', 'false');
1102
1103       output += aiGenerateTextShortcode('show_iframe_as_layer_autoclick_delay');
1104       output += aiGenerateTextShortcode('show_iframe_as_layer_autoclick_hide_time');
1105       output += aiGenerateTextShortcode('show_iframe_as_layer_header_file');
1106       output += aiGenerateTextShortcodeWithDefault('show_iframe_as_layer_header_height','100');
1107       output += aiGenerateRadioShortcode('show_iframe_as_layer_header_position', 'top');
1108       output += aiGenerateRadioShortcode('show_iframe_as_layer_keep_content', 'true');
1109
1110       // show only a part of the iframe
1111       var showPartOfIframe = aiGenerateRadioShortcode('show_part_of_iframe','false');
1112       output += showPartOfIframe;
1113
1114       if (showPartOfIframe !== '') {
1115         output += aiGenerateTextShortcodeWithDefault('show_part_of_iframe_x',-1);
1116         output += aiGenerateTextShortcodeWithDefault('show_part_of_iframe_y',-1);
1117         output += aiGenerateTextShortcode('show_part_of_iframe_width');
1118         output += aiGenerateTextShortcode('show_part_of_iframe_height');
1119		 output += aiGenerateTextShortcode('show_part_of_iframe_media_query');
1120         output += aiGenerateRadioShortcode('show_part_of_iframe_allow_scrollbar_horizontal','false');
1121         output += aiGenerateRadioShortcode('show_part_of_iframe_allow_scrollbar_vertical','false');
1122         output += aiGenerateTextShortcode('show_part_of_iframe_style');
1123         output += aiGenerateRadioShortcode('show_part_of_iframe_zoom','false');
1124
1125         output += aiGenerateTextShortcode('show_part_of_iframe_next_viewports');
1126         output += aiGenerateRadioShortcode('show_part_of_iframe_next_viewports_loop','false');
1127         output += aiGenerateTextShortcode('show_part_of_iframe_new_window');
1128         output += aiGenerateTextShortcode('show_part_of_iframe_new_url');
1129         output += aiGenerateRadioShortcode('show_part_of_iframe_next_viewports_hide','false');
1130       }
1131       output += aiGenerateTextShortcode('hide_part_of_iframe');
1132       // same domain
1133       output += aiGenerateRadioShortcode('add_css_class_iframe','false');
1134       output += aiGenerateTextShortcode('iframe_hide_elements');
1135       output += aiGenerateTextShortcode('onload_show_element_only');
1136       output += aiGenerateTextShortcode('iframe_content_id');
1137       output += aiGenerateTextShortcode('iframe_content_styles');
1138       output += aiGenerateTextShortcode('iframe_content_css');
1139       output += aiGenerateTextShortcode('change_iframe_links');
1140       output += aiGenerateTextShortcode('change_iframe_links_target');
1141       output += aiGenerateTextShortcode('change_iframe_links_href');
1142       
1143       // resize content height
1144       output += aiGenerateTextShortcode('onload');
1145       output += aiGenerateRadioShortcode('onload_resize','false');
1146       output += aiGenerateTextShortcode('onload_resize_delay');
1147       output += aiGenerateRadioShortcode('store_height_in_cookie','false');
1148       output += aiGenerateTextShortcode('additional_height');
1149       output += aiGenerateRadioShortcode('onload_resize_width','false');
1150       output += aiGenerateTextShortcode('resize_on_ajax');
1151       output += aiGenerateRadioShortcode('resize_on_ajax_jquery','true');
1152       output += aiGenerateTextShortcode('resize_on_click');
1153       output += aiGenerateTextShortcodeWithDefault('resize_on_click_elements','a');
1154
1155       output += aiGenerateTextShortcode('resize_on_element_resize');
1156       output += aiGenerateTextShortcodeWithDefault('resize_on_element_resize_delay','250');
1157
1158       // tabs
1159       output += aiGenerateTextShortcode('tab_hidden');
1160       output += aiGenerateTextShortcode('tab_visible');
1161       // cross domain ....
1162       output += aiGenerateRadioShortcode('add_document_domain','false');
1163       //
1164       if (document_domain_add === 'true') {
1165           output += aiGenerateTextShortcode('document_domain');
1166       }
1167       output += aiGenerateRadioShortcode('enable_external_height_workaround','external');
1168       output += aiGenerateRadioShortcode('hide_page_until_loaded_external','false');
1169       output += aiGenerateTextShortcode('pass_id_by_url');
1170	   output += aiGenerateRadioShortcode('multi_domain_enabled','true');
1171       if (isPro === 'true') {
1172           output += aiGenerateRadioShortcode('use_post_message','true');
1173	   } else {
1174		   output += aiGenerateRadioShortcode('use_post_message','false');
1175	   }
1176       // additional files
1177       output += aiGenerateTextShortcode('additional_css');
1178       output += aiGenerateTextShortcode('additional_js');
1179       output += aiGenerateTextShortcode('additional_js_file_iframe');
1180       output += aiGenerateTextShortcode('additional_css_file_iframe');
1181   } else { // include content directly
1182      if (include_html_val === '')  {
1183         output += aiGenerateTextShortcode('include_url');
1184         output += aiGenerateTextShortcode('include_content');
1185         output += aiGenerateTextShortcode('include_height');
1186         output += aiGenerateTextShortcode('include_fade');
1187         output += aiGenerateRadioShortcode('include_hide_page_until_loaded','false');
1188      } else {
1189         output += aiGenerateTextShortcode('include_html');
1190      }
1191   }
1192   // options
1193   output += aiGenerateRadioShortcode('debug_js','false');
1194   output = output.slice(0, -1);
1195   output += ']';
1196   jQuery('#gen-shortcode').html(output);
1197}
1198
1199/**
1200 * Generate a text shortcode with default
1201 */
1202function aiGenerateTextShortcodeWithDefault(field, defaultValue) {
1203    var output = '';
1204    var value = jQuery('#' + field);
1205    var val = value.val();
1206    if (value.length > 0 && val !== '' && val !== defaultValue) {
1207        output = field + '="' + val + '" ';
1208    }
1209    return output;
1210}
1211
1212/**
1213 * Generate a text shortcode if the value is not empty or != 0
1214 */
1215function aiGenerateTextShortcode(field) {
1216    var output = '';
1217    var value = jQuery('#' + field);
1218    var val = value.val();
1219    if (value.length > 0 && val !== '' && val !== '0') {
1220        output = field + '="' + val + '" ';
1221    }
1222    return output;
1223}
1224
1225/**
1226 * Generate a radio shortcode with default
1227 */
1228function aiGenerateRadioShortcode(field, defaultValue) {
1229    var output = '';
1230    var value = jQuery('input:radio[name='+field+']:checked');
1231    var val = value.val();
1232    
1233	if (field === 'enable_ios_mobile_scolling') {
1234	    field = 'enable_ios_mobile_scrolling';
1235	}
1236	
1237	if (value.length > 0 && val !== defaultValue) {
1238        output += field + '="' + val + '" ';
1239    }
1240    return output;
1241}
1242
1243/**
1244 * Add a css class to the parents to enable that the iframe parents
1245 * can be identified very easy. Is an is ist set ai-class-<id> is used.
1246 * Otherwise a-class-<number> with an increasing number is used.
1247 */
1248function aiAddCssClassAllParents(element) {
1249  var parents = jQuery(element).parentsUntil( 'html' );
1250  var ai_class= 'ai-class-';
1251  for(var i = 0; i < parents.length; i++){
1252    var id = jQuery(parents[i]).attr('id');
1253    if (typeof id !== 'undefined') {
1254      if (id.indexOf('ai-') !== 0) {
1255          jQuery(parents[i]).addClass(ai_class + id);
1256      }
1257    } else {
1258      jQuery(parents[i]).addClass(ai_class + i);
1259    }
1260  }
1261}
1262
1263function aiAutoZoomExternalHeight(id, width, height, responsive) {
1264    aiDebugExtended("aiAutoZoomExternalHeight");
1265	var parentWidth = aiAutoZoomExternal(id, width, responsive);
1266    var zoomRatio = window['zoom_' + id];
1267    var oldScrollposition = jQuery(document).scrollTop();
1268    var newHeight = Math.ceil(height*zoomRatio);
1269    jQuery('#ai-zoom-div-' + id).css('height', newHeight);
1270    jQuery("html,body").scrollTop(oldScrollposition); 
1271 return parentWidth;
1272}
1273
1274
1275function aiAutoZoomExternal(id, width, responsive) {
1276   aiDebugExtended("aiAutoZoomExternal");
1277   var obj =  document.getElementById(id);
1278   var objAround =  document.getElementById('ai-zoom-div-' +id);
1279   var jObj = jQuery('#' + id);
1280
1281   if (responsive === 'true') {
1282    jObj.css('max-width', '100%');
1283   }
1284   var iframeWidth = width;
1285   var parentWidth = aiGetParentIframeWidth(obj);
1286   if (parentWidth === iframeWidth) {
1287     // we check again the sourounding div as some browser do return the zoomes value!
1288     parentWidth = aiGetParentIframeWidth(objAround);
1289   }
1290   var zoomRatio = parentWidth / iframeWidth;
1291   var zoomRatioRounded = Math.floor(zoomRatio * 100) / 100;
1292   if (zoomRatioRounded > 1) {
1293     zoomRatioRounded = 1;
1294   }
1295
1296   aiSetZoom(id, zoomRatioRounded);
1297   window['zoom_' + id] = zoomRatioRounded;
1298   jObj.width(iframeWidth).css('max-width', 'none');
1299   return parentWidth;
1300}
1301function aiAutoZoom(id, responsive, ratio) {
1302   aiDebugExtended("aiAutoZoom");
1303   var parts = ratio.split('|');
1304   ratio = parts[0];
1305   var width = -1;
1306   if (parts.length !== 1) {
1307     width = parts[1];
1308   }
1309
1310   var obj = document.getElementById(id);
1311   var iframeWidth; 
1312   if (width === -1) {
1313     obj.width = 1; // set to 1 because otherwise the iframe does never get smaller.
1314     obj.style.width = '1px';
1315     iframeWidth = aiGetIframeWidth(obj);
1316     obj.width = iframeWidth;
1317     obj.style.width = iframeWidth + 'px';
1318   } else {
1319     iframeWidth = width;
1320   }
1321
1322   var parentWidth = aiAutoZoomExternal(id, iframeWidth, responsive);
1323   if (ratio === '') {
1324     aiResizeIframe(obj, false);
1325   } else {
1326      var newheight = Math.ceil(iframeWidth * ratio);
1327      obj.height = newheight;
1328      obj.style.height = newheight + 'px';
1329      // set the height of the zoom div
1330      if (jQuery('#ai-zoom-div-' + obj.id).length !== 0) {
1331         var zoom = window['zoom_' + obj.id];
1332         jQuery('#ai-zoom-div-' + obj.id).css('height', Math.ceil(newheight * zoom));
1333      }
1334   }
1335   return parentWidth;
1336}
1337
1338/**
1339 * Set the zoom div settings dynamically.
1340 */
1341function aiSetZoom(id, zoom) {
1342
1343  var obj = jQuery('#' + id);
1344
1345  if (aiIsIe8 === true) {
1346    obj.css('-ms-zoom', zoom);
1347  }
1348
1349  obj.css({
1350    '-ms-transform': 'scale(' + zoom + ')',
1351    '-moz-transform': 'scale(' + zoom + ')',
1352    '-o-transform': 'scale(' + zoom + ')',
1353    '-webkit-transform': 'scale(' + zoom + ')',
1354    'transform': 'scale(' + zoom + ')'
1355  });
1356}
1357
1358function aiAutoZoomViewport(id, full) {
1359
1360  var viewportDiv = jQuery(id);
1361  var outerDiv = viewportDiv.parent();
1362  var counter = 0;
1363
1364  // We only go up and look for divs which are not from ai or p elements which are rendered by mistake.
1365  while (outerDiv.is('p') || (outerDiv.attr('id') !== undefined && outerDiv.attr('id').indexOf('ai-') === 0)) {
1366     outerDiv = outerDiv.parent();
1367     if (counter++ > 10) {
1368        alert('Unexpected div structure. Please disable the zoom.');
1369        break;
1370     }
1371  }
1372
1373  var viewportDivWidth = viewportDiv.width();
1374  var outer_div_width = outerDiv.width();
1375  var viewportDivHeight = viewportDiv.height();
1376  var zoom = outer_div_width / viewportDivWidth;
1377
1378  if (full === 'true' && zoom > 1) {
1379     zoom = 1;
1380  }
1381
1382  aiSetZoom(viewportDiv.attr('id'), zoom);
1383  // set the margin because otherwise it is normally "centered" in the old area
1384  var marginLeft = -Math.round((viewportDivWidth - viewportDivWidth * zoom) / 2);
1385  var marginTop = -Math.round((viewportDivHeight - viewportDivHeight * zoom) / 2);
1386  viewportDiv.css({
1387    'margin-left':  marginLeft + 'px',
1388    'margin-right':  marginLeft + 'px',
1389    'margin-top':  marginTop + 'px',
1390    'margin-bottom':  marginTop + 'px'
1391  });
1392
1393
1394}
1395
1396function aiResetAiSettings() {
1397  jQuery('#action').val('reset');
1398}
1399
1400function aiCheckInputNumber(inputField) {
1401    inputField.value = inputField.value.split(' ').join('');
1402    var f = inputField.value;
1403    if (inputField.value === '') { 
1404        return;
1405    }
1406    var match = f.match(/^(\-){0,1}([\d.])+(px|%|em|pt|vh|vw|rem|ch)?(\-|\+){0,1}([\d.]){0,7}(px|%|em|pt|vh|vw|rem|ch)?$/);
1407
1408    if (!match) {
1409        alert('Please check the value you have entered. Only numbers with a dot or with an optional px, %, em or pt are allowed.');
1410        setTimeout(function(){inputField.focus();}, 10);
1411    }
1412}
1413
1414
1415function aiCheckInputPurchaseCode (inputField) {
1416    inputField.value = inputField.value.split(' ').join('');
1417    var f = inputField.value;
1418    if (inputField.value === '') { 
1419        return;
1420    }
1421	
1422	var lengthTrue = f.length === 36;
1423	var minusFourTrue = (f.match(/-/g) || []).length === 4;
1424   
1425    if (!lengthTrue || !minusFourTrue) {
1426        alert('Please check the value you have entered. Your input seems not to be a valid purchase code.');
1427        setTimeout(function(){inputField.focus();}, 10);
1428    }
1429}
1430
1431
1432
1433function aiCheckInputNumberOnly(inputField) {
1434    inputField.value = inputField.value.split(' ').join('');
1435    var f = inputField.value;
1436    if (inputField.value === '') {
1437      inputField.value = '0';
1438      return;
1439    }
1440    var match = f.match(/^(\-){0,1}([\d.])+$/);
1441
1442    if (!match) {
1443        alert('Please check the value you have entered. Only numbers without a dot or optional px, %, em or pt are allowed.');
1444        setTimeout(function(){inputField.focus();}, 10);
1445    }
1446}
1447// https://codepen.io/anon/pen/baaLYB/
1448function aiShowHeader(id, element) {
1449  var y = jQuery(window).scrollTop();
1450  jQuery(window).scrollTop(y-40);
1451  if (element !== undefined) {
1452    aiFlashElement(element);
1453  }
1454}
1455
1456function aiFlashElement(element) {
1457  setTimeout(function() { jQuery('#' +element).css('background-color','#eee'); } , 500); 
1458  setTimeout(function() { jQuery('#' +element).css('background-color','#fff'); } , 900); 
1459  setTimeout(function() { jQuery('#' +element).css('background-color','#eee'); } , 1300); 
1460  setTimeout(function() { jQuery('#' +element).css('background-color','#fff'); } , 1700); 
1461}
1462
1463function aiSetScrollposition() {
1464  var scrollposition = jQuery(document).scrollTop();
1465  jQuery('#scrollposition').val(scrollposition); // +32
1466}
1467
1468function aiResetShowPartOfAnIframe(id) {
1469  jQuery('#' + id).css('top','0px').css('left','0px').css('position','static');
1470  jQuery('#ai-div-' + id).css('width','auto').css('height','auto').css('overflow','auto').css('position','static');
1471}
1472
1473function aiShowLayerIframe(event, id, path, hideUntilLoaded, showLoadingIcon, keep, reload) {
1474  aiDebugExtended("aiShowLayerIframe");
1475  keep = (keep === undefined) ? false : keep;
1476  reload = (reload === undefined) ? true : reload;
1477
1478  var layerId = '#' + id;
1479  jQuery('#ai-zoom-div-' + id).show();
1480  if  (reload && hideUntilLoaded === 'true') {
1481      jQuery(layerId).css('visibility', 'hidden');
1482  }
1483  jQuery(layerId).show();
1484  if ( jQuery( '#ai-layer-div-' + id ).length ) {
1485    layerId = '#ai-layer-div-' + id;
1486    jQuery(layerId).show();
1487  }
1488
1489  jQuery('body').css('overflow','hidden');
1490  jQuery('html').css('overflow-y','visible');
1491  jQuery('body').append('<img id="ai_backlink" src="'+path+'close.png" style="z-index:100005;position:fixed;top:0;right:0;cursor:pointer" />');
1492  // was 'body' before
1493
1494  var icon = '<!-- -->';
1495  if (reload && showLoadingIcon==='true') {
1496    icon = '<div id="ai-div-loader-global" style="position: fixed;z-index:100004;margin-left:-33px;left: 50%;top:50%;margin-top:-33px"><img src="' + path + 'loader.gif" width="66" height="66" title="Loading" alt="Loading"></div>';
1497  }
1498
1499  if (jQuery('#ai_backlayer').length === 0) { // we do not have a layer yet...
1500      jQuery(layerId).parent().append('<div id="ai_backlayer" style="z-index:100001;position:fixed;top:0;left:0;width:100%;height:100%;background-color: rgba(50,50,50,0.5);overflow:hidden;cursor:pointer"><!-- --></div>' + icon);
1501  }
1502  
1503  jQuery( '#ai_backlink, #ai_backlayer' ).click(function() {
1504    aiHideLayerIframe(id, keep);
1505  });
1506  if (!reload) {
1507    event.preventDefault();
1508    event.stopPropagation();
1509  }
1510}
1511
1512function aiHideLayerIframe(id, keep) {
1513  aiDebugExtended("aiHideLayerIframe");
1514  jQuery('#' + id).hide();
1515  if (!keep) {
1516      jQuery('#' + id).attr('src', 'about:blank');
1517      aiLayerIframeHrefs[id] = 'about:blank';
1518  }
1519  jQuery('#ai-zoom-div-' + id).hide();
1520  jQuery('#ai-layer-div-' + id).hide();
1521  jQuery('#ai_backlink').remove();
1522  jQuery('#ai_backlayer').remove();
1523  jQuery('#ai-div-loader-global').remove();
1524  jQuery('body').css('overflow','auto');
1525  jQuery('html').css('overflow-y','scroll');
1526}
1527
1528
1529/**
1530 * As the src of an iframe cannot be read from a remote domain we remember
1531 * the urls from the links here for each opened iframe.
1532 */
1533var aiLayerIframeHrefs = [];
1534
1535/**
1536 * Check if the location of the iframe is already the one of the link.
1537 * The iframe is only loaded if it is was not loaded already.
1538 *
1539 * true - if src and url of the iframe is different and need to be loaded
1540 * false - if it is already the same;
1541 */
1542
1543
1544function aiCheckReload (link, id) {
1545    var iframeSrc;
1546    if(typeof aiLayerIframeHrefs[id] === 'undefined') {
1547        iframeSrc = jQuery('#' + id).attr('src');
1548    } else {
1549        iframeSrc = aiLayerIframeHrefs[id];
1550    }
1551    var linkHref = jQuery(link).attr('href');
1552    // alert(linkHref + ": iframe:" + iframeSrc);
1553    aiLayerIframeHrefs[id] = linkHref;
1554    return (iframeSrc !== linkHref);
1555}
1556
1557/**
1558 * This changes the current url and adds or updates the
1559 * existing parameter with the given url
1560 */
1561function aiChangeUrlParam(loc, param, orig, prefix, isDirect) {
1562   aiDebugExtended("aiChangeUrlParam");
1563   var newUrl;
1564   var keepSlash = false;
1565   
1566   // add protocol if // is used in the shortcode 
1567   if (orig.lastIndexOf("//", 0) !== -1) {
1568	   orig = location.protocol + orig;
1569   }
1570   
1571   if (loc !== encodeURIComponent(orig)) {
1572	 newUrl = aiSetGetParameter(param, loc);
1573	 var removeProtocol = true;
1574     if (prefix === 'hash' || prefix === 'hashrewrite') {
1575		 var locBase = aiRemoveQueryString(loc);
1576		 return aiGetUrlMapping(locBase, param, prefix);
1577	 } else if (prefix) {
1578       var repUrl = newUrl.replace(prefix,'');
1579       if (repUrl === newUrl) {
1580         removeProtocol = false;
1581       }
1582       newUrl = repUrl;
1583     }
1584     
1585	 // remove protocoll
1586     if (removeProtocol) {
1587       newUrl = newUrl.replace('http%3A%2F%2F','');
1588       if (window.location.href.toLowerCase().lastIndexOf("http:", 0) !== -1) {
1589           newUrl = newUrl.replace('https%3A%2F%2F','s|');  
1590       } else {
1591           newUrl = newUrl.replace('https%3A%2F%2F','');
1592       }
1593     }
1594	 
1595     if (isDirect) {		
1596		var newUrl = aiRemoveQueryString(window.location.href);
1597		var locDecoded = decodeURIComponent(loc);
1598		var queryStart = locDecoded.indexOf('?');
1599		if (queryStart !== -1) {
1600			var queryPart = locDecoded.slice(queryStart + 1);
1601			newUrl += '?' + queryPart;
1602			keepSlash = true;
1603		}		
1604	 } 
1605	 if (aiEndsWidth(newUrl, param + "=")) { 
1606        newUrl = aiRemoveURLParameter(newUrl, param);
1607     }
1608   } else {
1609      var fullUrl = window.location.href;
1610	  // remove param/* first
1611	  fullUrl = fullUrl.split("/" + param + "/",1)[0];
1612	  newUrl = aiRemoveURLParameter(fullUrl, param);
1613   }
1614
1615   aiSetBrowserUrl(newUrl, keepSlash); 
1616}
1617
1618function aiGetUrlMappingUrl(locBase, param, prefix, id) {
1619	 var fullUrl = window.location.href;
1620	 newUrl = aiRemoveURLParameter(fullUrl, param);
1621	 if (prefix === 'hash') {
1622		 var seperator = (newUrl.indexOf('?') >= 0) ? '&' : '?'; 
1623		 newUrl += seperator+param+"=" + id;
1624	 } else {
1625		 // remove param/* first
1626		 var queryString = "/";
1627		 if (newUrl.indexOf('?') >= 0) {
1628			 var newUrlArray = newUrl.split('?'); 
1629			 newUrl = newUrlArray[0];
1630			 queryString = '/?' + newUrlArray[1]; 
1631		 }
1632		 var baseUrl = newUrl.split("/" + param + "/",1)[0];
1633		 // add the path before the query string 
1634		 if (!aiEndsWidth(baseUrl, "/")) {
1635			 baseUrl += '/';
1636		 }
1637		 newUrl = baseUrl + param+"/" + id + queryString;
1638	 }		 
1639	return newUrl;
1640}
1641
1642function aiSetBrowserUrl(newUrl, keepSlash) {
1643	if (aiSupportsHistoryApi()) {
1644        if (!keepSlash) {
1645		    newUrl = newUrl.replace(/%2F/g,'/');
1646		}
1647        window.history.pushState({}, '', newUrl);
1648        // I asume the back button is clicked.
1649        window.onpopstate = function(event) {
1650          if(event && event.state) {
1651            window.history.back();
1652          }
1653        };
1654    }
1655}
1656
1657function aiRemoveQueryString(loc) {
1658    if (loc.indexOf('%3F') >= 0) {
1659	    return loc.split('%3F')[0]; 
1660	} else if (loc.indexOf('?') >= 0) {
1661	    return loc.split('?')[0]; 
1662	} else { 
1663	 return loc;
1664	}
1665}	
1666
1667function aiGetUrlMapping(url, param, prefix) {
1668	var data = {
1669      action: 'aip_map_url_action',
1670      security : MyAjax.security,
1671      url: url
1672    };
1673	
1674    // since 2.8 ajaxurl is always defined in the admin header and points to admin-ajax.php
1675    jQuery.post(MyAjax.ajaxurl, data, function(id) {
1676       var newUrl = aiGetUrlMappingUrl(url, param, prefix, id);
1677	   aiSetBrowserUrl(newUrl, false);   
1678   });  
1679}
1680
1681function closeInfoPermanent(id) {
1682	var data = {
1683      action: 'aip_close_message_permanent',
1684      security : MyAjax.security,
1685      id: id
1686    };
1687    // since 2.8 ajaxurl is always defined in the admin header and points to admin-ajax.php
1688    var message = 'The message before will only appear again when you reset the advanced iframe settings.';
1689	if (id === 'show-discount-message') {
1690		message = 'The message of advanced iframe shown before will only appear again when you reset the advanced iframe settings or a new discount is available.';
1691	} else if (id === 'show-registration-message') {
1692		message = 'The message before will only appear again when you reset the advanced iframe settings and you have not entered your purchase code.';
1693	}
1694		
1695	jQuery.post(MyAjax.ajaxurl, data, function(id) {
1696	   jQuery('h1').after('<div class="message-notice notice notice-success"><p>' + message + '</p></div>'); 
1697    }); 
1698    setTimeout(function() { jQuery(".message-notice").fadeOut() }, 4000);     
1699}
1700
1701
1702function aiSupportsHistoryApi() {
1703  return !!(window.history && history.pushState);
1704}
1705
1706function aigetIframeLocation(id) {
1707  try {
1708    var location = document.getElementById(id).contentWindow.location;
1709    return encodeURIComponent(location);
1710  }  catch(e) {
1711    if (console && console.error) {
1712      console.error('Advanced iframe configuration error: You have enabled to add the url to the url on the same domain. But you use an iframe page on a different domain. You need to use the pro version of the external workaround like described 
1712in the settings. Also check the next log. There the browser message for this error is displayed.');
1713      console.log(e);
1714    }
1715  }
1716}
1717
1718
1719/**
1720 * Replaces a url parameter with a given value.
1721 */
1722function aiSetGetParameter(paramName, paramValue)
1723{
1724    var url = window.location.href;
1725    var splitAtAnchor = url.split('#');
1726    url = splitAtAnchor[0];
1727    var anchor = typeof splitAtAnchor[1] === 'undefined' ? '' : '#' + splitAtAnchor[1];
1728    if (url.indexOf(paramName + '=') >= 0) {
1729        var prefix = url.substring(0, url.indexOf(paramName+ '='));
1730        var suffix = url.substring(url.indexOf(paramName+ '='));
1731        suffix = suffix.substring(suffix.indexOf('=') + 1);
1732        suffix = (suffix.indexOf('&') >= 0) ? suffix.substring(suffix.indexOf('&')) : '';
1733        url = prefix + paramName + '=' + paramValue + suffix;
1734    } else {
1735      if (url.indexOf('?') < 0)  {
1736          url += '?' + paramName + '=' + paramValue;
1737      } else {
1738          url += '&' + paramName + '=' + paramValue;
1739      }
1740    }
1741    return url + anchor;
1742}
1743
1744/**
1745 * Remove a given parameter from the url
1746 */
1747function aiRemoveURLParameter(url, parameter) {
1748    //prefer to use l.search if you have a location/link object
1749    var urlparts= url.split('?');
1750    if (urlparts.length>=2) {
1751
1752        var prefix= encodeURIComponent(parameter)+'=';
1753        var pars= urlparts[1].split(/[&;]/g);
1754
1755        //reverse iteration as may be destructive
1756        for (var i= pars.length; i-- > 0;) {
1757            //idiom for string.startsWith
1758            if (pars[i].lastIndexOf(prefix, 0) !== -1) {
1759                pars.splice(i, 1);
1760            }
1761        }
1762        if (pars.length !== 0) {
1763            url= urlparts[0]+'?'+pars.join('&');
1764        } else {
1765            url= urlparts[0];
1766        }
1767        return url;
1768    } else {
1769        return url;
1770    }
1771}
1772
1773function aiEndsWidth(string, target) {
1774  return string.substr(-target.length) === target;
1775}
1776
1777/**
1778* Adds css to the end of the body to make sure that styles are
1779* not overwritten by inline css of any kind.
1780*/
1781function aiAddCss(id,css){
1782    css = decodeURIComponent(css.replace(/\+/g, '%20'));
1783
1784    var body = jQuery(id).contents().find('body');
1785    var s = document.createElement('style');
1786    s.setAttribute('type', 'text/css');
1787    if (s.styleSheet) {   // IE
1788        s.styleSheet.cssText = css;
1789    } else {                // the world
1790        s.appendChild(document.createTextNode(css));
1791    }
1792    body.append(s);
1793}
1794
1795/**
1796 * add a css file to the end of the body to make sure that styles
1797 *  are not overwritten by inline css of any kind.
1798 */
1799function aiAddCssFile(id, filename) {
1800    var body = jQuery(id).contents().find('body');
1801    var link = document.createElement('link');
1802    link.rel = 'stylesheet';
1803    link.type ='text/css';
1804    link.href = filename;
1805    body.append(link);
1806}
1807
1808/**
1809 * Add a Javascript file to the end of the body
1810 */
1811function aiAddJsFile(id, filename) {
1812    jQuery.ajaxSetup({ cache:true});
1813
1814    var body = jQuery(id).contents().find('body');
1815    var script = document.createElement('script');
1816    script.type ='text/javascript';
1817    script.src = filename;
1818    body.append(script);
1819}
1820
1821function aiPresetFullscreen() {
1822    jQuery('#style').val('position:fixed;z-index:9000;top:0px;left:0px;margin:0px');
1823    jQuery('#width').val('100%');
1824    jQuery('#height').val('100%');
1825    jQuery('#content_id').val('html,body');
1826    jQuery('#content_styles').val('overflow:hidden');
1827    jQuery('#hide_content_until_iframe_color').val('#ffffff');
1828}
1829
1830/**
1831 * main ready function that calls all generated callbacks.
1832 * Add dynamically created functions that should be loaded
1833 * when the page is read to aiReadyCallbacks
1834 */
1835jQuery(document).ready(function() {
1836	aiDebugExtended("document.ready called");
1837   
1838	// wordpress adds often p elements that have margins we remove here. 
1839	jQuery('iframe').parent('p').css('margin','0');
1840	
1841	aiWindowWidth = jQuery(window).width();
1842    jQuery.each(aiReadyCallbacks, function(index, callback){
1843      callback();
1844    });
1845	
1846	setTimeout(function() { jQuery("#ai #ai-updated-text").css("visibility","hidden")}, 4000);
1847	
1848    jQuery('#ai #checkIframes').on('click', function(){ 
1849        jQuery('.ai-spinner').css('display','inline-table');
1850		jQuery(this).addClass('disabled');
1851		setTimeout(aiDisableCheckIframes, 200);
1852    });
1853
1854    var moved=false;
1855    jQuery('#aiDebugDivTotal').mousedown(function(){moved=false;}).mousemove(function(){moved=true;}).mouseup(function(event){
1856        if(!moved){
1857           var elem = jQuery('#aiDebugDiv');
1858            if (Math.floor(elem.height()) > '300') {
1859                elem.height('0px');
1860            } else {
1861               elem.height('400px');
1862            }
1863        }
1864    });
1865
1866    if (typeof ai_show_id_only !== 'undefined') {
1867         if (jQuery('#' + ai_show_id_only).length === 0) {
1868             alert('The element with the id "' + ai_show_id_only + '" cannot be found. Please check your configuration.');
1869         } else {
1870             var element = jQuery('#' + ai_show_id_only);
1871             element.siblings().hide();
1872             var parents = element.parents();
1873             parents.siblings().hide();
1874             parents.css('padding', '0px').css('margin', '0px').css('overflow', 'hidden');
1875
1876             // we send the size of the element as post message if we are in an iframe
1877             if(parent===top) {
1878                var elementRaw = element[0];
1879				elementRaw.style.marginTop = elementRaw.style.marginBottom = 0;
1880                elementRaw.style.overflow = "hidden";
1881                var newHeightRaw =  Math.max(elementRaw.scrollHeight, elementRaw.offsetHeight);
1882                var newHeight = parseInt(newHeightRaw,10);
1883                var data = { 'aitype' : 'height', 'height' : newHeight, 'id' : ai_show_id_only};
1884                var json_data = JSON.stringify(data);
1885                window.parent.postMessage(json_data, '*');
1886            }
1887       }
1888    }
1889});
1890
1891function aiDisableCheckIframes() {
1892	var input = jQuery("<input>").attr("type", "hidden").attr("name", "checkIframes").val("true");
1893    jQuery("#ai_form").append(input);
1894	jQuery( "#ai_form" ).submit();
1895    jQuery('#checkIframes').prop('disabled','disabled');
1896}
1897
1898function aiProcessMessage(event,id,debug) {
1899   var jsObject;
1900  try {
1901    var jsObject = JSON.parse(event.data);
1902  } catch(e) {
1903    // Result is not expected so we try if data is an object already
1904    // because a converter was not implemented properly.
1905     if (debug === 'debug' && console && console.log) {
1906          console.log('Advanced iframe: The received message cannot be parsed and seems not to belong to advanced iframe pro. Please disable the postMessage debug mode if this o.k. and that this message is not shown anymore.');
1907          console.log("Advanced iframe: Unknown event: ", event);
1908        }
1909    var jsObject = event.data; 
1910  }  
1911  try {
1912    // we only process objects from advanced iframe
1913    if (jsObject.hasOwnProperty('aitype')) {
1914      // we only process the ones for the same id here.
1915      if ( id === jsObject.id) {
1916          var type = jsObject.aitype;
1917          if (type === 'debug') {
1918             aiProcessDebug(jsObject);
1919          } else if (type === 'scrollToTop') {
1920             aiProcessScrollToTop(jsObject);
1921          } else {
1922            // check if the data is of the expected
1923            if (type === 'height') {
1924              aiProcessHeight(jsObject);
1925            } else if (type === 'show') {
1926              aiProcessShow(jsObject);
1927            }
1928            for (var key in jsObject.data) {
1929              if (jsObject.data.hasOwnProperty(key)) {
1930                jQuery(key).html(jsObject.data[key]);
1931              }
1932            }
1933          } 
1934        } 
1935	  }
1936	} catch(e) {
1937        if (debug === 'debug' && console && console.log) {
1938          console.log('Advanced iframe: The received message do not belong to advanced iframe pro. Please disable the postMessage debug mode if this o.k. and that this message is not shown anymore.');
1939          console.log(e);
1940        }
1941  }
1942}
1943
1944function aiProcessDebug(jsObject) {
1945    var debugData = jsObject.data;
1946    if (jQuery('#aiDebugDiv').length !== 0) {
1947		debugData = debugData.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
1948        debugData = debugData.replace('\"', '"').replace(/\\/g,"");
1949		jQuery('#aiDebugDiv').append('<p class="ai-debug-remote"> r: ' + debugData + '</p>');
1950    }
1951}
1952
1953function aiProcessScrollToTop(jsObject) {
1954     var id = jsObject.id;
1955     aiScrollToTop(id, aiOnloadScrollTop);
1956}
1957
1958function aiProcessHeight(jsObject) {
1959    var nHeight = jsObject.height; 
1960    var nWidth = jsObject.width; 
1961    var iAnchor = parseInt(jsObject.anchor,10);
1962    var id = jsObject.id;
1963
1964    if (nHeight != null) {
1965      try {
1966        var loc = jsObject.loc;
1967        if (loc != null && !loc.includes("send_console_log")) {
1968          if (typeof aiChangeUrl === "function"){
1969		      aiChangeUrl(loc);
1970		  }
1971        }
1972        if (id != null) {
1973            var iHeight = parseInt(nHeight,10);
1974            var iWidth = parseInt(nWidth,10);
1975            aiResizeIframeHeightId(iHeight,iWidth, id);
1976            if (!isNaN(iAnchor) && iAnchor > -1) {
1977				// 
1978				var iframeTop = jQuery("#" + id).offset().top; 
1979                setTimeout(function() {
1980                    jQuery("html,body").scrollTop(Math.round(iframeTop + iAnchor));
1981					aiShowIframeId(id);
1982                }, 100);   
1983            } else {
1984				aiShowIframeId(id);
1985			}
1986        } else {
1987            alert('Please update the ai_external.js to the current version.');
1988        }
1989    	} catch(e) {
1990        if (console && console.log) {
1991          console.log(e);
1992        }
1993      }
1994    }
1995}
1996
1997function aiProcessShow(jsObject) {
1998  var id = jsObject.id;
1999
2000  try {
2001     aiShowIframeId(id);
2002  } catch(e) {
2003    if (console && console.log) {
2004      console.log(e);
2005    }
2006  }
2007}
2008
2009function aiDisableRightClick(id) {
2010	try {	
2011	   window.frames[id].document.oncontextmenu = function(){ return false; };
2012	} catch(e) {
2013	   // we ignore the error as it only works on the same domain.	 
2014	}	 
2015}
2016
2017function aiRemoveElementsFromHeight(id,height,removeElements) {
2018	var iframe = jQuery('#' + id);
2019	var elementArray  = removeElements.split(',');
2020    var totalHeight = 0;
2021	for (var i = 0; i < elementArray.length; i++) {
2022		try {
2023			var el = elementArray[i];
2024			if (el.includes("|")) {
2025			  var rangeArray = el.split('|');
2026			  var bottomElement = jQuery(rangeArray[0]);
2027			  var beforeBottom = Math.round(bottomElement.offset().top + bottomElement.outerHeight(true));
2028			  var nextTop = Math.round(jQuery(rangeArray[1]).offset().top);
2029			  totalHeight += nextTop - beforeBottom;
2030			} else if (el === 'top') { 
2031			  totalHeight +=  Math.round(jQuery('#' + id).offset().top);
2032			} else if (isNaN(el)) {
2033			  totalHeight += jQuery(el).outerHeight(true);
2034			} else {
2035			  totalHeight += parseInt(el);
2036			}
2037		}  catch(e) {
2038			if (console && console.error) {
2039			  console.error('Advanced iframe configuration error: The configuration of remove_elements_from_height "'+removeElements+'" is invalid. Please check if the elements you defined do exist and ids/classes are defined properly.');
2040			  console.log(e);
2041			}
2042		  }
2043    }
2044	var calc = 'calc(' + height + ' - ' + totalHeight + 'px)';
2045	iframe.css('height', calc);
2046}
2047
2048function aiTriggerAutoOpen(id, selector, autoclickDelay, hideTime) {
2049	aiDebugExtended("aiTriggerAutoOpen");
2050   
2051	if (autoclickDelay === 0) {
2052		aiOpenIframeOnClick(id, selector);
2053	} else {
2054		setTimeout(function() {
2055		    aiOpenIframeOnClick(id, selector);	
2056		}, autoclickDelay);
2057	}
2058	
2059	var now = new Date();
2060    var time = now.getTime();
2061    var expireTime = time + (hideTime * 86400000);
2062    now.setTime(expireTime);
2063    var	trimmedSelector = selector.replace(/[^A-Za-z0-9\-]/g, '');
2064	document.cookie = 'ai_disable_autoclick_iframe_' + trimmedSelector + '=Auto open is disabled until this cookie expires;expires='+now.toUTCString()+';path=/';
2065}
2066
2067function aiCheckAutoOpenHash(id, autoclickDelay, hideTime) {
2068	if (window.location.hash) {
2069       var hash = window.location.hash;
2070	   var trimmedHash = hash.replace(/[^A-Za-z0-9\-]/g, '');
2071	   trimmedHash = "#" + trimmedHash;
2072	   if (jQuery(trimmedHash).length !== 0) { // id does exist   
2073		   if (jQuery(trimmedHash).first().attr('target') == id) { // target is iframe
2074		       aiTriggerAutoOpen(id, trimmedHash, autoclickDelay, hideTime);   
2075		   }
2076       }
2077    }
2078}
2079
2080function aiOpenIframeOnClick(id, selector) {
2081	var myelement = jQuery(selector).first().attr("href"); 
2082    jQuery("#" + id).attr("src", myelement); 
2083	jQuery(selector).first().click();
2084}
2085
2086
2087// IE11 does not support includes
2088if (!String.prototype.includes) {
2089  String.prototype.includes = function(search, start) {
2090    if (typeof start !== 'number') {
2091      start = 0;
2092    }
2093    if (start + search.length > this.length) {
2094      return false;
2095    } else {
2096      return this.indexOf(search, start) !== -1;
2097    }
2098  };
2099}

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.