Ad Inserter – WordPress Ads Management with AdSense Header Integration - Version 2.7.0

Version Description

  • Added support to list range of post IDs
  • Added support for browser language in client lists
  • Added support for client-side checks for filter hook ai_block_insertion_check
  • Added support for remote plugin managenent (Pro only)
  • Added support for scheduling check shortcode (Pro only)
  • Added support for daily scheduling time (Pro onlyl)
  • Added support for css attribute in check options (Pro only)
  • Few minor bug fixes, cosmetic changes and code improvements
Download this release

Release Info

Developer spacetime
Plugin Icon 128x128 Ad Inserter – WordPress Ads Management with AdSense Header Integration
Version 2.7.0
Comparing to
See all releases

Code changes from version 2.6.25 to 2.7.0

ad-inserter.php CHANGED
@@ -2,7 +2,7 @@
2
 
3
  /*
4
  Plugin Name: Ad Inserter
5
- Version: 2.6.25
6
  Description: Ad management with many advanced advertising features to insert ads at optimal positions
7
  Author: Igor Funa
8
  Author URI: http://igorfuna.com/
@@ -17,6 +17,23 @@ Requires PHP: 5.6
17
 
18
  Change Log
19
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
  Ad Inserter 2.6.25 - 2021-05-24
21
  - Added support for block names in adinserter shortcode block attributes
22
  - Added support for browser language in client list (experimental)
@@ -27,7 +44,7 @@ Ad Inserter 2.6.25 - 2021-05-24
27
  - Added support for scheduling check shortcode (Pro only, experimental)
28
  - Added support for daily scheduling time (Pro only, experimental)
29
  - Added support for css attribute in check options (Pro only, experimental)
30
- - Added support to list post ID range
31
  - Improved ad blocking detection
32
  - Reduced layout shift when using CHECK shortcodes
33
  - Fix for expanded shortcodes in the rotate code generator
@@ -133,291 +150,6 @@ Ad Inserter 2.6.9 - 2020-05-22
133
  - Added support to export statistics data to CSV file (Pro only)
134
  - Few minor bug fixes, cosmetic changes and code improvements
135
 
136
- Ad Inserter 2.6.8 - 2020-04-27
137
- - Added support to disable PHP processing by PHP constant
138
- - Added support to repeat COUNT options
139
- - Added support for offset for %n paragraph number (%n@o)
140
- - Added support for options to skip insertion for first and last paragraphs
141
- - Added support for hook filter 'ai_block_insertion_check'
142
- - Added support for background ads (Pro only)
143
- - Few minor bug fixes, cosmetic changes and code improvements
144
-
145
- Ad Inserter 2.6.7 - 2020-04-07
146
- - Added support for various shortcodes for post categories
147
- - Added support for various shortcodes for post tags
148
- - Added support for user action on click (Pro only)
149
- - Added support for manual loading (Pro only)
150
- - Few minor bug fixes, cosmetic changes and code improvements
151
-
152
- Ad Inserter 2.6.6 - 2020-03-15
153
- - Fix for exceptions list not showing all exceptions
154
- - Improved ad blocking detection
155
- - Fix for close button in preview window (Pro only)
156
- - Few minor bug fixes, cosmetic changes and code improvements
157
-
158
- Ad Inserter 2.6.5 - 2020-02-26
159
- - Added support for url data shortcode
160
- - Added warning if not all exceptions were cleared
161
- - Added support for MaxMind country only database (Pro only)
162
- - Added support for ip to country lookup filter hook (Pro only)
163
- - Fix for country groups in CHECK separators (Pro only)
164
- - Few minor bug fixes, cosmetic changes and code improvements
165
-
166
- Ad Inserter 2.6.4 - 2020-02-13
167
- - Fix for use of undefined constant warning (Pro only)
168
-
169
- Ad Inserter 2.6.3 - 2020-02-10
170
- - Added support for shortcodes to disable block insertion
171
- - Added support for child taxonomy list items
172
- - Added random parameter to Ajax requests for geolocation (Pro only)
173
- - Added options to define external tracking event category, action and label (Pro only)
174
- - Number of custom hooks increased to 20
175
- - Fix to prevent insertion into head section when using Rank Math plugin
176
- - Few minor bug fixes, cosmetic changes and code improvements
177
-
178
- Ad Inserter 2.6.2 - 2020-01-20
179
- - Added support to disable caching of block PHP code
180
- - Added support to pause blocks on the blocks list
181
- - Added support for no url parameters list item
182
- - Added support for client-side scheduling (Pro only)
183
- - Added support for server-side scheduling using W3TC (Pro only)
184
- - Added support for multisite:site-id taxonomy list item (Pro only)
185
- - Updated MaxMind GeoLite2 database download using license key (Pro only)
186
- - Changed settings format in the database to prevent export/import issues with MySQL/PhpMyAdmin
187
- - Fix for [ADINSERTER counter] shortcode not expanding inside HTML tags
188
- - Few minor bug fixes, cosmetic changes and code improvements
189
-
190
- Ad Inserter 2.6.1 - 2020-01-10
191
- - Fix for errors on the settings page
192
- - Fix for non English characters in ads
193
- - Fix for sticky widgets
194
- - Few minor bug fixes
195
-
196
- Ad Inserter 2.6.0 - 2020-01-09
197
- - Added support for VIEWPORT separator
198
- - Added support for viewport check in CHECK separators (Pro only)
199
- - Added support to show processing log on front-end
200
- - Added support to show link to the Ad Inserter Pro settings page on multisite Sites page (Pro only)
201
- - Added support to detect and prevent document.write after DOM is ready
202
- - Added support for scheduling hours (Pro only)
203
- - Added support for scheduling days in week (Pro only)
204
- - Added support for W3TC insertion debugging info
205
- - Improved Javascript code for client-side functions
206
- - Improved ad blocking detection
207
- - Default value for Wait for jQuery set to Enabled
208
- - Few minor bug fixes, cosmetic changes and code improvements
209
-
210
- Ad Inserter 2.5.10 - 2019-12-08
211
- - Optimized Javascript code to allow advanced optimizations
212
- - Added support to wait for jQuery so it can be deferred
213
- - Added support for children categories in lists
214
- - Added support to load settings page in safe mode
215
- - Added warning notice if PHP version is below 5.6
216
- - Improved user interface for lists
217
- - Modified Javascript code that was wrongly replaced by CDN url
218
- - Fix for updates server access warning message (Pro only)
219
- - Few minor bug fixes, cosmetic changes and code improvements
220
-
221
- Ad Inserter 2.5.9 - 2019-11-19
222
- - Added support for block name class
223
- - Added support for code generator for AdSense sticky AMP ads
224
- - Fix for paragraph clearance issues
225
- - Few minor bug fixes, cosmetic changes and code improvements
226
-
227
- Ad Inserter 2.5.8 - 2019-11-14
228
- - Added support to call function adinserter () with block name
229
- - Added support to insert header code with HEAD separator only once
230
- - Additional info for errors when saving settings
231
- - Improved support for insertion between posts on AMP pages
232
- - Implemented compatibility with other plugins using phpQuery library
233
- - Added support for shortcode to disable tracking on specific pages (Pro only)
234
- - Few minor bug fixes, cosmetic changes and code improvements
235
-
236
- Ad Inserter 2.5.7 - 2019-10-14
237
- - Fix for error when saving settings
238
-
239
- Ad Inserter 2.5.6 - 2019-10-12
240
- - Added support for PenCi Soledad AMP plugin
241
- - Fix for php processing on multisite installations
242
- - Fix for client-side referrer check
243
- - Fix for header and footer code on AMP pages using AMP plugin
244
- - Few minor bug fixes, cosmetic changes and code improvements
245
-
246
- Ad Inserter 2.5.5 - 2019-09-29
247
- - Added support for client list (black/whitelist operating systems, browsers, device names)
248
- - Fix for replaced tags with default value {name:default-value}
249
- - Few minor bug fixes, cosmetic changes and code improvements
250
-
251
- Ad Inserter 2.5.4 - 2019-09-27
252
- - Minor bug fix regarding update checks (Pro only)
253
-
254
- Ad Inserter 2.5.3 - 2019-09-24
255
- - Added support for warning when Ad Inserter is disabled by AMPforWP Plugin Manager
256
- - Added support for block shortcode attributes
257
- - Added support for post ID list to include all posts or static pages
258
- - Added option for maximum number of paragraphs
259
- - Added support to check for update server accessibility (Pro only)
260
- - Added ids to ad blocking popup message and overlay elements
261
- - Few minor bug fixes, cosmetic changes and code improvements
262
-
263
- Ad Inserter 2.5.2 - 2019-09-10
264
- - Added options to define paragraph counting inside container elements
265
- - Added support to pin block list (Pro only)
266
- - Few minor bug fixes, cosmetic changes and code improvements
267
-
268
- Ad Inserter 2.5.1 - 2019-08-24
269
- - Few minor bug fixes (Pro only)
270
-
271
- Ad Inserter 2.5.0 - 2019-08-20
272
- - Improved user interface
273
- - Simplified user interface for individual post/page exceptions
274
- - Added support for virtual ads.txt file
275
- - Added support for frequency capping (Pro only)
276
- - Added support for click fraud detection (Pro only)
277
- - Changed url prefix for public reports to avoid possible url collisions (Pro only)
278
- - Fix for shortcode processing when blocks were used before init hook
279
- - Many minor bug fixes, cosmetic changes and code improvements
280
-
281
- Ad Inserter 2.4.23 - 2019-07-30
282
- - Added support to define custom fields with shortocdes
283
- - Added experimental support to delay showing ads for specified number of pageviews (Pro only)
284
- - Fix for false positive ad blocking detection (Pro only)
285
- - Few minor bug fixes, cosmetic changes and code improvements
286
-
287
- Ad Inserter 2.4.22 - 2019-07-13
288
- - Fix for remote code execution vulnerability - credit to Wordfence
289
-
290
- Ad Inserter 2.4.21 - 2019-07-11
291
- - Fix for possible error Class not found (Pro only)
292
-
293
- Ad Inserter 2.4.20 - 2019-07-09
294
- - Fix for path traversal vulnerability - credit to Wilfried Becard of Synacktiv (https://synacktiv.com)
295
- - Fix for block rearrangement issues
296
- - Added experimental support to remember closed ad for specified time period (Pro only)
297
- - Added experimental support to automatically close ad after specified time period (Pro only)
298
- - Few minor bug fixes, cosmetic changes and code improvements
299
-
300
- Ad Inserter 2.4.19 - 2019-06-18
301
- - Added support for taxonomy for Yoast primary category
302
- - Layout changes to accomodate longer translated texts
303
- - Fix for escape character not saved in header, footer and ad blocking message code
304
- - Few minor bug fixes, cosmetic changes and code improvements
305
-
306
- Ad Inserter 2.4.18 - 2019-05-26
307
- - Added support for full width responsive AdSense code option
308
- - Few minor bug fixes, cosmetic changes and code improvements
309
-
310
- Ad Inserter 2.4.17 - 2019-05-13
311
- - Few minor bug fixes, cosmetic changes and code improvements
312
-
313
- Ad Inserter 2.4.16 - 2019-04-21
314
- - Fix for compatibility with AMP for WP - Accelerated Mobile Pages for WordPress
315
- - Few minor bug fixes
316
-
317
- Ad Inserter 2.4.15 - 2019-04-19
318
- - Fix for improved compatibility with other plugins
319
- - Few minor bug fixes and cosmetic changes
320
-
321
- Ad Inserter 2.4.14 - 2019-04-18
322
- - Fix for ROTATE shortcodes with option name identical to block name
323
- - Fix for possible conflict with output buffering in other plugins
324
- - Few minor bug fixes, cosmetic changes and code improvements
325
-
326
- Ad Inserter 2.4.13 - 2019-04-12
327
- - Added shortcode to disable ad blocking detection code
328
- - Added options to disable ad blocking actions for administrators or logged in users
329
- - Added option to change PDF report footer (Pro only)
330
- - Added support for public ad impression and click reports (Pro only)
331
- - Few minor bug fixes, cosmetic changes and code improvements
332
-
333
- Ad Inserter 2.4.12 - 2019-03-21
334
- - Added ads.txt editor
335
- - Added option to prevent disabling caching for logged in administrators
336
- - Improved compatibility with PHP 7.2
337
- - Few minor bug fixes, cosmetic changes and code improvements
338
-
339
- Ad Inserter 2.4.11 - 2019-02-23
340
- - Fix for saving code with slashes
341
- - Fix for rotation editor code import
342
- - Few minor bug fixes, cosmetic changes and code improvements
343
-
344
- Ad Inserter 2.4.10 - 2019-02-18
345
- - Added support for counter shortcodes
346
- - Added support for code separator selection for code preview
347
- - Added support for group rotations
348
- - Added support for CHECK separator (Pro only)
349
- - Added links to test pages for check for available positions
350
- - Few minor bug fixes, cosmetic changes and code improvements
351
-
352
- Ad Inserter 2.4.9 - 2019-02-05
353
- - Added support for HEAD separator
354
- - Added support for DoubleClick for Publishers (DFP) ads
355
- - Added support to generate statistics reports in PDF format (Pro only)
356
- - Fix for ad label when using AMP separator
357
- - Fix for AdSense code fixed by viewport
358
- - Fix for error when checking for available positions
359
- - Few minor bug fixes, cosmetic changes and code improvements
360
-
361
- Ad Inserter 2.4.8 - 2019-01-20
362
- - Added support for automatic insertion before/after image
363
- - Added support for theme checker for available positions for automatic insertion
364
-
365
- Ad Inserter 2.4.7 - 2019-01-15
366
- - Added support for automatic insertion before/after image (experimental)
367
- - Added support for theme checker for available positions for automatic insertion (experimental)
368
- - Improvements to the user interface
369
- - Fix for lazy loading in Ajax calls (Pro only)
370
- - Fix for country list editor (Pro only)
371
- - Few minor bug fixes, cosmetic changes and code improvements
372
-
373
- Ad Inserter 2.4.6 - 2019-01-08
374
- - Improved ad blocking detection (detects Firefox content blocking)
375
- - Added support for wildcards for referrers (domains)
376
- - Added debugging notice when JavaScript errors are detected
377
- - Added support to load blocks in iframes (Pro only)
378
- - Added geolocation support for country subdivisions and cities (Pro only)
379
- - Added option to hide license key on client websites (Pro only)
380
- - Few minor bug fixes, cosmetic changes and code improvements
381
-
382
- Ad Inserter 2.4.5 - 2018-12-26
383
- - Added support for AMP WP - Google AMP For WordPress
384
- - Added support to individually disable insertions for debugging purposes
385
- - Improved HTML element selection tool
386
- - Fix for Call to undefined function wp_get_current_user()
387
- - Few minor bug fixes, cosmetic changes and code improvements
388
-
389
- Ad Inserter 2.4.4 - 2018-12-11
390
- - Fix for Fatal error: Call to undefined function mb_strtoupper()
391
-
392
- Ad Inserter 2.4.3 - 2018-12-10
393
- - Added support for insertion before/after every N paragraphs (%N)
394
- - Added support for i18n
395
- - Fix for insertion on admin pages
396
- - Fix for client-side cookie check
397
- - Fix for loaded styles from other plugins/themes on the settings page
398
- - Fix for client-side insertion near HTML elements using :eq selector
399
- - Fix for deactivation feedback form not closing
400
- - Few minor bug fixes, cosmetic changes and code improvements
401
-
402
- Ad Inserter 2.4.2 - 2018-10-21
403
- - Added support for visual HTML element selection
404
- - Fix for client-side insertion inside HTML elements
405
- - Few minor bug fixes, cosmetic changes and code improvements
406
-
407
- Ad Inserter 2.4.1 - 2018-10-05
408
- - Added option to insert into HTML element (prepend, append, replace content)
409
- - Added option to remove HTML element
410
- - Added option to not show deactivation feedback form
411
- - Added support for negative relative positions for paragraph counting
412
- - Few minor bug fixes, cosmetic changes and code improvements
413
-
414
- Ad Inserter 2.4.0 - 2018-09-26
415
- - Improved code for client-side insertion
416
- - Added support for usage tracking
417
- - Fix for compatibility with older PHP versions (below 5.4)
418
- - Few minor bug fixes, cosmetic changes and code improvements
419
-
420
-
421
  */
422
 
423
 
@@ -3635,7 +3367,7 @@ function ai_wp_head_hook () {
3635
  echo "<script>\n", ai_get_js ('ai-iframes', false), "</script>\n";
3636
  }
3637
 
3638
- if (!get_disable_js_code () && ($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_POSITIONS) != 0) {
3639
  $ai_wp_data [AI_FOOTER_JS_CODE_DOM_READY] .= ' setTimeout (function(){jQuery(\'body\').prepend ("' . get_page_type_debug_info () . '");}, 1);
3640
  ';
3641
  }
@@ -3660,7 +3392,7 @@ function ai_wp_head_hook () {
3660
  }
3661
 
3662
  if (($ai_wp_data [AI_WP_DEBUGGING] & (AI_DEBUG_AD_BLOCKING_STATUS | AI_DEBUG_BLOCKS)) != 0) {
3663
- $ai_wp_data [AI_FOOTER_JS_CODE_DOM_READY] .= " jQuery('body').prepend (\"<section id='ai-iab-tcf-bar' class='".AI_DEBUG_STATUS_CLASS."' style='cursor: pointer; display: none;' title='". __('Click to delete the cokie for the consents', 'ad-inserter') ."'>IAB TCF 2.0 <span id='ai-iab-tcf-status'></span></section>\");
3664
  ";
3665
  }
3666
 
@@ -9477,15 +9209,24 @@ function check_url_parameter_and_cookie_list ($url_parameters, $white_list) {
9477
  }
9478
 
9479
  function check_scheduled_rotation ($scheduling) {
9480
- If (strpos ($scheduling, '%') === false || strpos ($scheduling, '=') === false) return false;
 
 
 
 
 
 
9481
 
9482
  $scheduling_data_array = explode ('=', $scheduling);
9483
- $scheduling_data_time = explode ('%', $scheduling_data_array [0]);
 
 
 
9484
 
9485
  $time_unit = strtolower (trim ($scheduling_data_time [0]));
9486
 
9487
- $time_division = trim ($scheduling_data_time [1]);
9488
- $scheduling_time_option = trim ($scheduling_data_array [1]);
9489
 
9490
  $current_time = current_time ('timestamp');
9491
 
@@ -9514,7 +9255,17 @@ function check_scheduled_rotation ($scheduling) {
9514
  if ($time_value == 0) $time_value = 6; else $time_value = $time_value - 1;
9515
  }
9516
 
9517
- return $time_value % $time_division == $scheduling_time_option;
 
 
 
 
 
 
 
 
 
 
9518
  }
9519
 
9520
  function check_scheduling_time ($start_time, $end_time, $days_in_week, $between) {
2
 
3
  /*
4
  Plugin Name: Ad Inserter
5
+ Version: 2.7.0
6
  Description: Ad management with many advanced advertising features to insert ads at optimal positions
7
  Author: Igor Funa
8
  Author URI: http://igorfuna.com/
17
 
18
  Change Log
19
 
20
+ Ad Inserter 2.7.0 - 2021-05-30
21
+ - Added support to list range of post IDs
22
+ - Added support for browser language in client lists
23
+ - Added support for client-side checks for filter hook ai_block_insertion_check
24
+ - Added support for remote plugin managenent (Pro only)
25
+ - Added support for scheduling check shortcode (Pro only)
26
+ - Added support for daily scheduling time (Pro onlyl)
27
+ - Added support for css attribute in check options (Pro only)
28
+ - Few minor bug fixes, cosmetic changes and code improvements
29
+
30
+ Ad Inserter 2.6.27 - 2021-05-29
31
+ - Added support for scheduled rotation
32
+ - Few minor bug fixes, cosmetic changes and code improvements
33
+
34
+ Ad Inserter 2.6.26 - 2021-05-27
35
+ - Few bug fixes (Pro only)
36
+
37
  Ad Inserter 2.6.25 - 2021-05-24
38
  - Added support for block names in adinserter shortcode block attributes
39
  - Added support for browser language in client list (experimental)
44
  - Added support for scheduling check shortcode (Pro only, experimental)
45
  - Added support for daily scheduling time (Pro only, experimental)
46
  - Added support for css attribute in check options (Pro only, experimental)
47
+ - Added support to list range of post IDs
48
  - Improved ad blocking detection
49
  - Reduced layout shift when using CHECK shortcodes
50
  - Fix for expanded shortcodes in the rotate code generator
150
  - Added support to export statistics data to CSV file (Pro only)
151
  - Few minor bug fixes, cosmetic changes and code improvements
152
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
153
  */
154
 
155
 
3367
  echo "<script>\n", ai_get_js ('ai-iframes', false), "</script>\n";
3368
  }
3369
 
3370
+ if (!get_disable_js_code () && ($ai_wp_data [AI_WP_DEBUGGING] & (AI_DEBUG_POSITIONS | AI_DEBUG_BLOCKS)) != 0) {
3371
  $ai_wp_data [AI_FOOTER_JS_CODE_DOM_READY] .= ' setTimeout (function(){jQuery(\'body\').prepend ("' . get_page_type_debug_info () . '");}, 1);
3372
  ';
3373
  }
3392
  }
3393
 
3394
  if (($ai_wp_data [AI_WP_DEBUGGING] & (AI_DEBUG_AD_BLOCKING_STATUS | AI_DEBUG_BLOCKS)) != 0) {
3395
+ $ai_wp_data [AI_FOOTER_JS_CODE_DOM_READY] .= " jQuery('body').prepend (\"<section id='ai-iab-tcf-bar' class='".AI_DEBUG_STATUS_CLASS."' style='cursor: pointer; display: none;' title='". __('Click to delete the cokie for the consents', 'ad-inserter') ."'><span id='ai-iab-tcf-status'>IAB TCF 2.0</span></section>\");
3396
  ";
3397
  }
3398
 
9209
  }
9210
 
9211
  function check_scheduled_rotation ($scheduling) {
9212
+ If (strpos ($scheduling, '=') === false) return false;
9213
+
9214
+ $result = true;
9215
+ if (strpos ($scheduling, '^') !== false) {
9216
+ $result = false;
9217
+ $scheduling = substr ($scheduling, 1);
9218
+ }
9219
 
9220
  $scheduling_data_array = explode ('=', $scheduling);
9221
+
9222
+ if (strpos ($scheduling_data_array [0], '%') !== false) {
9223
+ $scheduling_data_time = explode ('%', $scheduling_data_array [0]);
9224
+ } else $scheduling_data_time = array ($scheduling_data_array [0]);
9225
 
9226
  $time_unit = strtolower (trim ($scheduling_data_time [0]));
9227
 
9228
+ $time_division = isset ($scheduling_data_time [1]) ? trim ($scheduling_data_time [1]) : 0;
9229
+ $scheduling_time_option = str_replace (' ', '', ($scheduling_data_array [1]));
9230
 
9231
  $current_time = current_time ('timestamp');
9232
 
9255
  if ($time_value == 0) $time_value = 6; else $time_value = $time_value - 1;
9256
  }
9257
 
9258
+ $time_modulo = $time_division != 0 ? $time_value % $time_division : $time_value;
9259
+
9260
+ $scheduling_time_options = explode (',', $scheduling_time_option);
9261
+ foreach ($scheduling_time_options as $time_option) {
9262
+ if (strpos ($time_option, '-') !== false) {
9263
+ $time_limits = explode ('-', $time_option);
9264
+ if ($time_modulo >= $time_limits [0] && $time_modulo <= $time_limits [1]) return $result;
9265
+ } else if ($time_modulo == $time_option) return $result;
9266
+ }
9267
+
9268
+ return !$result;
9269
  }
9270
 
9271
  function check_scheduling_time ($start_time, $end_time, $days_in_week, $between) {
class.php CHANGED
@@ -3328,7 +3328,7 @@ abstract class ai_CodeBlock extends ai_BaseCodeBlock {
3328
  if ($option_time) $times = true;
3329
  $version_times []= $option_time ? intval ($option ['time']) : - 1;
3330
 
3331
- $option_scheduling = isset ($option ['scheduling']) && strpos ($option ['scheduling'], '%') !== false && strpos ($option ['scheduling'], '=') !== false;
3332
  if ($option_scheduling) $scheduling = true;
3333
  $version_scheduling []= $option_scheduling ? trim ($option ['scheduling']) : - 1;
3334
  }
@@ -7981,7 +7981,7 @@ echo '</body>
7981
  }
7982
 
7983
  if (strpos ($ids_listed [$index], '-') !== false) {
7984
- $id_limits = explode ('-', $ids_listed [$index]);
7985
  if ($page_id >= $id_limits [0] && $page_id <= $id_limits [1]) return $return;
7986
  }
7987
  }
3328
  if ($option_time) $times = true;
3329
  $version_times []= $option_time ? intval ($option ['time']) : - 1;
3330
 
3331
+ $option_scheduling = isset ($option ['scheduling']) && strpos ($option ['scheduling'], '=') !== false;
3332
  if ($option_scheduling) $scheduling = true;
3333
  $version_scheduling []= $option_scheduling ? trim ($option ['scheduling']) : - 1;
3334
  }
7981
  }
7982
 
7983
  if (strpos ($ids_listed [$index], '-') !== false) {
7984
+ $id_limits = explode ('-', str_replace (' ', '', $ids_listed [$index]));
7985
  if ($page_id >= $id_limits [0] && $page_id <= $id_limits [1]) return $return;
7986
  }
7987
  }
constants.php CHANGED
@@ -31,7 +31,7 @@ if (!defined( 'AD_INSERTER_NAME'))
31
  define ('AD_INSERTER_NAME', 'Ad Inserter');
32
 
33
  if (!defined( 'AD_INSERTER_VERSION'))
34
- define ('AD_INSERTER_VERSION', '2.6.25');
35
 
36
  if (!defined ('AD_INSERTER_PLUGIN_BASENAME'))
37
  define ('AD_INSERTER_PLUGIN_BASENAME', plugin_basename (__FILE__));
31
  define ('AD_INSERTER_NAME', 'Ad Inserter');
32
 
33
  if (!defined( 'AD_INSERTER_VERSION'))
34
+ define ('AD_INSERTER_VERSION', '2.7.0');
35
 
36
  if (!defined ('AD_INSERTER_PLUGIN_BASENAME'))
37
  define ('AD_INSERTER_PLUGIN_BASENAME', plugin_basename (__FILE__));
css/ai-settings.css CHANGED
@@ -1,5 +1,5 @@
1
  #ai-data {
2
- font-family: "2.6.25"; /* Used for version number of the file */
3
  }
4
 
5
  #blocked-warning {
@@ -565,7 +565,15 @@ table.ai-lists .ai-button {
565
  }
566
 
567
  .checkbox-button.dashicons.blue {
568
- color: #00f;
 
 
 
 
 
 
 
 
569
  }
570
 
571
  /*.checkbox-button.dashicons.blue-active {*/
1
  #ai-data {
2
+ font-family: "2.7.0"; /* Used for version number of the file */
3
  }
4
 
5
  #blocked-warning {
565
  }
566
 
567
  .checkbox-button.dashicons.blue {
568
+ color: #7373ff;
569
+ }
570
+
571
+ tr.ai-website-list .ai-website-key {
572
+ color: #888;
573
+ }
574
+
575
+ tr.ai-website-list.read-only .ai-website-key {
576
+ color: #49b3ff;
577
  }
578
 
579
  /*.checkbox-button.dashicons.blue-active {*/
includes/js/ai-adb.BAK ADDED
@@ -0,0 +1,791 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ var ai_adb_active = false;
2
+ var ai_adb_counter = 0;
3
+ var ai_adb_act_cookie_name = "aiADB";
4
+ var ai_adb_pgv_cookie_name = "aiADB_PV";
5
+ var ai_adb_page_redirection_cookie_name = "aiADB_PR";
6
+
7
+ var ai_adb_overlay = AI_ADB_OVERLAY_WINDOW;
8
+ var ai_adb_message_window = AI_ADB_MESSAGE_WINDOW;
9
+ var ai_adb_message_undismissible = AI_FUNCB_GET_UNDISMISSIBLE_MESSAGE;
10
+ var ai_adb_message_cookie_lifetime = AI_FUNCT_GET_NO_ACTION_PERIOD;
11
+ var ai_adb_action = AI_FUNC_GET_ADB_ACTION;
12
+ var ai_adb_page_views = "AI_FUNC_GET_DELAY_ACTION";
13
+ var ai_adb_selectors = "AI_ADB_SELECTORS";
14
+ var ai_adb_redirection_url = "AI_ADB_REDIRECTION_PAGE";
15
+
16
+ function ai_adb_process_content () {
17
+ (function ($) {
18
+
19
+ var ai_adb_debugging = typeof ai_debugging !== 'undefined'; // 1
20
+ // var ai_adb_debugging = false;
21
+
22
+ if (ai_adb_debugging) console.log ('');
23
+ if (ai_adb_debugging) console.log ("AI AD BLOCKING CONTENT PROCESSING");
24
+
25
+ $(".AI_ADB_CONTENT_CSS_BEGIN_CLASS").each (function () {
26
+ var ai_adb_parent = $(this).parent ();
27
+
28
+ if (ai_adb_debugging) console.log ("AI AD BLOCKING parent", ai_adb_parent.prop ("tagName"), "id=\""+ ai_adb_parent.attr ("id")+"\"", "class=\""+ ai_adb_parent.attr ("class")+"\"");
29
+
30
+ var ai_adb_css = $(this).data ("css");
31
+ if (typeof ai_adb_css == "undefined") ai_adb_css = "display: none !important;";
32
+
33
+ var ai_adb_selectors = $(this).data ("selectors");
34
+ if (typeof ai_adb_selectors == "undefined" || ai_adb_selectors == '') ai_adb_selectors = "p";
35
+
36
+ if (ai_adb_debugging) console.log ('AI AD BLOCKING CSS, css=\'' + ai_adb_css +'\'', "selectors='" + ai_adb_selectors + "'");
37
+
38
+ var ai_adb_action = false;
39
+ $(ai_adb_parent).find ('.AI_ADB_CONTENT_CSS_BEGIN_CLASS, .AI_ADB_CONTENT_CSS_END_CLASS, ' + ai_adb_selectors).each (function () {
40
+ if ($(this).hasClass ("AI_ADB_CONTENT_CSS_BEGIN_CLASS")) {$(this).remove (); ai_adb_action = true;}
41
+ else if ($(this).hasClass ("AI_ADB_CONTENT_CSS_END_CLASS")) {$(this).remove (); ai_adb_action = false;}
42
+ else if (ai_adb_action) {
43
+ var ai_adb_style = $(this).attr ("style");
44
+ if (typeof ai_adb_style == "undefined") ai_adb_style = "";
45
+ else {
46
+ ai_adb_style = ai_adb_style.trim ();
47
+ if (ai_adb_style != '' && ai_adb_style [ai_adb_style.length - 1] != ';') {
48
+ ai_adb_style = ai_adb_style + ';';
49
+ }
50
+ }
51
+
52
+ if (ai_adb_debugging) console.log ("AI AD BLOCKING CSS:", $(this).prop ("tagName"), "id=\""+ $(this).attr ("id")+"\"", "class=\""+ $(this).attr ("class")+"\"");
53
+
54
+ $(this).attr ("style", ai_adb_style + ' ' + ai_adb_css);
55
+ }
56
+ });
57
+ });
58
+
59
+ $(".AI_ADB_CONTENT_DELETE_BEGIN_CLASS").each (function () {
60
+ var ai_adb_parent = $(this).parent ();
61
+
62
+ if (ai_adb_debugging) console.log ("AI AD BLOCKING DELETE, parent", ai_adb_parent.prop ("tagName"), "id=\""+ ai_adb_parent.attr ("id")+"\"", "class=\""+ ai_adb_parent.attr ("class")+"\"");
63
+
64
+ var ai_adb_selectors = $(this).data ("selectors");
65
+ if (typeof ai_adb_selectors == "undefined" || ai_adb_selectors == '') ai_adb_selectors = "p";
66
+
67
+ if (ai_adb_debugging) console.log ("AI AD BLOCKING DELETE, selectors='" + ai_adb_selectors + "'");
68
+
69
+ var ai_adb_action = false;
70
+ $(ai_adb_parent).find ('.AI_ADB_CONTENT_DELETE_BEGIN_CLASS, .AI_ADB_CONTENT_DELETE_END_CLASS, ' + ai_adb_selectors).each (function () {
71
+ if ($(this).hasClass ("AI_ADB_CONTENT_DELETE_BEGIN_CLASS")) {$(this).remove (); ai_adb_action = true;}
72
+ else if ($(this).hasClass ("AI_ADB_CONTENT_DELETE_END_CLASS")) {$(this).remove (); ai_adb_action = false;}
73
+ else if (ai_adb_action) {
74
+ if (ai_adb_debugging) console.log ("AI AD BLOCKING DELETE:", $(this).prop ("tagName"), "id=\""+ $(this).attr ("id")+"\"", "class=\""+ $(this).attr ("class")+"\"");
75
+
76
+ $(this).remove ();
77
+ }
78
+ });
79
+
80
+ });
81
+
82
+ $(".AI_ADB_CONTENT_REPLACE_BEGIN_CLASS").each (function () {
83
+ var ai_adb_parent = $(this).parent ();
84
+
85
+ if (ai_adb_debugging) console.log ("AI AD BLOCKING REPLACE, parent", ai_adb_parent.prop ("tagName"), "id=\""+ ai_adb_parent.attr ("id")+"\"", "class=\""+ ai_adb_parent.attr ("class")+"\"");
86
+
87
+ var ai_adb_text = $(this).data ("text");
88
+ if (typeof ai_adb_text == "undefined") ai_adb_text = "";
89
+
90
+ var ai_adb_css = $(this).data ("css");
91
+ if (typeof ai_adb_css == "undefined") ai_adb_css = "";
92
+
93
+ var ai_adb_selectors = $(this).data ("selectors");
94
+ if (typeof ai_adb_selectors == "undefined" || ai_adb_selectors == '') ai_adb_selectors = "p";
95
+
96
+ if (ai_adb_debugging) console.log ("AI AD BLOCKING REPLACE, text=\'" + ai_adb_text + '\'', 'css=\'' + ai_adb_css +'\'', "selectors='" + ai_adb_selectors + "'");
97
+
98
+ var ai_adb_action = false;
99
+ $(ai_adb_parent).find ('.AI_ADB_CONTENT_REPLACE_BEGIN_CLASS, .AI_ADB_CONTENT_REPLACE_END_CLASS, ' + ai_adb_selectors).each (function () {
100
+ if ($(this).hasClass ("AI_ADB_CONTENT_REPLACE_BEGIN_CLASS")) {$(this).remove (); ai_adb_action = true;}
101
+ else if ($(this).hasClass ("AI_ADB_CONTENT_REPLACE_END_CLASS")) {$(this).remove (); ai_adb_action = false;}
102
+ else if (ai_adb_action) {
103
+ if (ai_adb_text.length != 0) {
104
+ var n = Math.round ($(this).text ().length / (ai_adb_text.length + 1));
105
+ $(this).text (Array(n + 1).join(ai_adb_text + ' ').trim ());
106
+ } else $(this).text ('');
107
+
108
+ if (ai_adb_css != '') {
109
+ var ai_adb_style = $(this).attr ("style");
110
+ if (typeof ai_adb_style == "undefined") ai_adb_style = "";
111
+ else {
112
+ ai_adb_style = ai_adb_style.trim ();
113
+ if (ai_adb_style != '' && ai_adb_style [ai_adb_style.length - 1] != ';') {
114
+ ai_adb_style = ai_adb_style + ';';
115
+ }
116
+ }
117
+ if (ai_adb_css != '') {
118
+ ai_adb_css = ' ' + ai_adb_css;
119
+ }
120
+ $(this).attr ("style", ai_adb_style + ai_adb_css);
121
+ }
122
+
123
+ if (ai_adb_debugging) console.log ("AI AD BLOCKING REPLACE:", $(this).prop ("tagName"), "id=\""+ $(this).attr ("id")+"\"", "class=\""+ $(this).attr ("class")+"\"");
124
+ }
125
+ });
126
+ });
127
+
128
+ }(jQuery));
129
+ }
130
+
131
+ function ai_adb_process_blocks (element) {
132
+ (function ($) {
133
+ var ai_adb_debugging = typeof ai_debugging !== 'undefined'; // 2
134
+ // var ai_adb_debugging = false;
135
+
136
+ if (typeof element == 'undefined') {
137
+ element = $('body');
138
+ if (ai_adb_debugging) console.log ('');
139
+ }
140
+
141
+ var ai_adb_data = $(b64d ("Ym9keQ==")).attr (AI_ADB_ATTR_NAME);
142
+ if (typeof ai_adb_data === "string") {
143
+ var ai_adb_active = ai_adb_data == b64d ("bWFzaw==");
144
+ } else {
145
+ var ai_adb_active = null;
146
+ }
147
+
148
+ if (ai_adb_debugging) console.log ("AI AD BLOCKING block actions:", ai_adb_active, $(element).prop ("tagName") + '.' + $(element).attr ('class'));
149
+
150
+ if (typeof ai_adb_data === "string" && typeof ai_adb_active === "boolean") {
151
+ if (ai_adb_active) {
152
+
153
+ var code_inserted = false;
154
+
155
+ do {
156
+ var code_insertion = false;
157
+
158
+ // Don't use data () as the value will be cached - wrong value for tracking
159
+ $(".ai-adb-hide", element).each (function () {
160
+ $(this).css ({"display": "none", "visibility": "hidden"});
161
+
162
+ $(this).removeClass ('ai-adb-hide');
163
+
164
+ // Disable tracking
165
+ var wrapping_div = $(this).closest ('div[data-ai]');
166
+ if (typeof wrapping_div.attr ("data-ai") != "undefined") {
167
+ var data = JSON.parse (b64d (wrapping_div.attr ("data-ai")));
168
+ if (typeof data !== "undefined" && data.constructor === Array) {
169
+ data [1] = "";
170
+
171
+ if (ai_adb_debugging) console.log ("AI AD BLOCKING TRACKING ", b64d (wrapping_div.attr ("data-ai")), ' <= ', JSON.stringify (data));
172
+
173
+ wrapping_div.attr ("data-ai", b64e (JSON.stringify (data)));
174
+ }
175
+ }
176
+
177
+ ai_disable_processing ($(this));
178
+
179
+ if (ai_adb_debugging) {
180
+ var debug_info = $(this).data ("ai-debug");
181
+ console.log ("AI AD BLOCKING HIDE", typeof debug_info != "undefined" ? debug_info : "");
182
+ }
183
+ });
184
+
185
+ // after hide to update tracking data on replace
186
+ // Don't use data () as the value will be cached - wrong value for tracking
187
+ $(".ai-adb-show", element).each (function () {
188
+ $(this).css ({"display": "block", "visibility": "visible"});
189
+
190
+ $(this).removeClass ('ai-adb-show');
191
+
192
+ if (typeof $(this).data ('code') != 'undefined') {
193
+ var adb_code = b64d ($(this).data ('code'));
194
+
195
+ if (ai_adb_debugging) console.log ('AI AD BLOCKING SHOW INSERT CODE');
196
+ if (ai_adb_debugging) console.log ('');
197
+
198
+ $(this).append (adb_code);
199
+
200
+ code_insertion = true;
201
+ code_inserted = true;
202
+
203
+ // Process rotations to set versions before tracking data is set
204
+ if (typeof ai_process_elements == 'function') {
205
+ ai_process_elements ();
206
+ }
207
+ }
208
+
209
+ var tracking_data = $(this).attr ('data-ai-tracking');
210
+ if (typeof tracking_data != 'undefined') {
211
+ var wrapping_div = $(this).closest ('div[data-ai]');
212
+ if (typeof wrapping_div.attr ("data-ai") != "undefined") {
213
+ if ($(this).hasClass ('ai-no-tracking')) {
214
+ var data = JSON.parse (b64d (wrapping_div.attr ("data-ai")));
215
+ if (typeof data !== "undefined" && data.constructor === Array) {
216
+ data [1] = "";
217
+ tracking_data = b64e (JSON.stringify (data));
218
+ }
219
+ }
220
+
221
+ if (ai_adb_debugging) console.log ("AI AD BLOCKING TRACKING ", b64d (wrapping_div.attr ("data-ai")), ' <= ', b64d (tracking_data));
222
+
223
+ wrapping_div.attr ("data-ai", tracking_data);
224
+ }
225
+ }
226
+ if (ai_adb_debugging) {
227
+ var debug_info = $(this).data ("ai-debug");
228
+ console.log ("AI AD BLOCKING SHOW", typeof debug_info != "undefined" ? debug_info : "");
229
+ }
230
+ });
231
+ } while (code_insertion);
232
+
233
+ setTimeout (function() {
234
+ if (typeof ai_process_impressions == 'function' && ai_tracking_finished == true) {
235
+ ai_process_impressions ();
236
+ }
237
+ if (typeof ai_install_click_trackers == 'function' && ai_tracking_finished == true) {
238
+ ai_install_click_trackers ();
239
+ }
240
+ }, 15);
241
+
242
+ setTimeout (ai_adb_process_content, 10);
243
+ } else {
244
+ // Prevent tracking if block was not displayed because of cookie
245
+ $(".ai-adb-hide", element).each (function () {
246
+ if (ai_adb_debugging) console.log ('AI ai-adb-hide', $(this), $(this).outerHeight (), $(this).closest ('.ai-adb-show').length);
247
+
248
+ $(this).removeClass ('ai-adb-hide');
249
+
250
+ if ($(this).outerHeight () == 0 && $(this).closest ('.ai-adb-show').length == 0) {
251
+ // Top level (not nested) block
252
+ var wrapper = $(this).closest ('div[data-ai]');
253
+ if (typeof wrapper.attr ("data-ai") != "undefined") {
254
+ var data = JSON.parse (b64d (wrapper.attr ("data-ai")));
255
+ if (typeof data !== "undefined" && data.constructor === Array) {
256
+ data [1] = "";
257
+
258
+ if (ai_adb_debugging) console.log ("AI AD BLOCKING TRACKING DISABLED: ", b64d (wrapper.attr ("data-ai")), ' <= ', JSON.stringify (data));
259
+
260
+ wrapper.attr ("data-ai", b64e (JSON.stringify (data)));
261
+
262
+ // Hide block (wrapping div with margin)
263
+ wrapper.addClass ('ai-viewport-0').css ("display", "none");
264
+ }
265
+ }
266
+
267
+ }
268
+ });
269
+
270
+ $(".ai-adb-show", element).each (function () {
271
+ ai_disable_processing ($(this));
272
+
273
+ $(this).removeClass ('ai-adb-show');
274
+
275
+ if (ai_adb_debugging) console.log ('AI AD BLOCKING SHOW disable processing', $(this).prop ("tagName") + '.' + $(this).attr ('class'));
276
+ });
277
+ }
278
+ }
279
+
280
+ if (ai_adb_debugging) console.log ("AI AD BLOCKING block actions END");
281
+ }(jQuery));
282
+ }
283
+
284
+ ai_adb_detection_type_log = function (n) {
285
+ var type = ai_adb_detection_type (n);
286
+ var ai_adb_events = jQuery('#ai-adb-events');
287
+ if (ai_adb_events.count != 0) {
288
+ var message = ai_adb_events.text ();
289
+ if (message != '') message = message + ', '; else message = message + ', EVENTS: ';
290
+ message = message + n;
291
+ ai_adb_events.text (message);
292
+ }
293
+ return type;
294
+ }
295
+
296
+ ai_adb_detection_type = function (n) {
297
+
298
+ var ai_adb_debugging = typeof ai_debugging !== 'undefined'; // 3
299
+ // var ai_adb_debugging = false;
300
+
301
+ if (ai_adb_debugging) {
302
+ switch (n) {
303
+ case 0:
304
+ return "0 debugging";
305
+ break;
306
+ case 1:
307
+ return "1 ads create element";
308
+ break;
309
+ case 2:
310
+ return "2 sponsors window var";
311
+ break;
312
+ case 3:
313
+ return "3 banner element";
314
+ break;
315
+ case 4:
316
+ return "4 custom selectors";
317
+ break;
318
+ case 5:
319
+ return "5 ga";
320
+ break;
321
+ case 6:
322
+ return "6 media.net";
323
+ break;
324
+ case 7:
325
+ return "7 adsense";
326
+ break;
327
+ case 8:
328
+ return "8 adnxs.com";
329
+ break;
330
+ case 9:
331
+ return "9 fun adblock 3";
332
+ break;
333
+ case 10:
334
+ return "10 fun adblock 4";
335
+ break;
336
+ default:
337
+ return n;
338
+ break;
339
+ }
340
+ } else return '';
341
+ }
342
+
343
+ var ai_adb_detected = function (n) {
344
+ setTimeout (function() {
345
+ ai_adb_detected_actions (n);
346
+ }, 2);
347
+ }
348
+
349
+ var ai_disable_processing = function (element) {
350
+ jQuery(element).find ('.ai-lazy').removeClass ('ai-lazy'); // Disable lazy loading
351
+ jQuery(element).find ('.ai-manual').removeClass ('ai-manual'); // Disable manual loading
352
+ jQuery(element).find ('.ai-rotate').removeClass ('ai-unprocessed').removeAttr ('data-info'); // Disable rotations
353
+ jQuery(element).find ('.ai-list-data').removeClass ('ai-list-data'); // Disable lists
354
+ jQuery(element).find ('.ai-ip-data').removeClass ('ai-ip-data'); // Disable IP lists
355
+ jQuery(element).find ('[data-code]').removeAttr ('data-code'); // Disable insertions
356
+ }
357
+
358
+ var ai_adb_detected_actions = function(n) {
359
+
360
+ var ai_adb_debugging = typeof ai_debugging !== 'undefined'; // 4
361
+ // var ai_adb_debugging = false;
362
+
363
+ if (ai_adb_debugging && n == 0) console.log ('');
364
+ if (ai_adb_debugging) console.log ("AI AD BLOCKING DETECTED", ai_adb_detection_type_log (n));
365
+
366
+ if (!ai_adb_active) {
367
+ ai_adb_active = true;
368
+
369
+ jQuery(b64d ("Ym9keQ==")).attr (AI_ADB_ATTR_NAME, b64d ("bWFzaw=="));
370
+
371
+ (function ($) {
372
+
373
+ $(window).ready(function () {
374
+ ai_adb_process_blocks ();
375
+
376
+ // if (code_inserted && typeof ai_process_elements == 'function') {
377
+ // setTimeout (ai_process_elements, 20);
378
+ // }
379
+ });
380
+
381
+ if (ai_adb_debugging) console.log ("AI AD BLOCKING action check");
382
+ // AiCookies.remove (ai_adb_pgv_cookie_name, {path: "/" });
383
+
384
+ // Disable action for bots
385
+ if (typeof MobileDetect !== "undefined") {
386
+ var md = new MobileDetect (window.navigator.userAgent);
387
+
388
+ if (ai_adb_debugging) console.log ('AI AD BLOCKING IS BOT:', md.is ('bot'));
389
+
390
+ if (md.is ('bot')) {
391
+ ai_adb_action = 0;
392
+ }
393
+ }
394
+
395
+ if (ai_adb_page_views != '') {
396
+ if (ai_adb_debugging) console.log ("AI AD BLOCKING page views delay:", ai_adb_page_views);
397
+ if (ai_adb_page_views.includes (',')) {
398
+ var ai_adb_page_view_parts = ai_adb_page_views.split (',');
399
+
400
+ var ai_adb_page_view_delay = parseInt (ai_adb_page_view_parts [0]);
401
+ var ai_adb_page_view_repeat = parseInt (ai_adb_page_view_parts [1]);
402
+
403
+ if (ai_adb_debugging) console.log ("AI AD BLOCKING page views delay:", ai_adb_page_view_delay, "repeat:", ai_adb_page_view_repeat);
404
+ } else {
405
+ var ai_adb_page_view_delay = parseInt (ai_adb_page_views);
406
+ var ai_adb_page_view_repeat = 0
407
+
408
+ if (ai_adb_debugging) console.log ("AI AD BLOCKING page views delay:", ai_adb_page_view_delay);
409
+ }
410
+
411
+ var ai_adb_page_view_counter = 1;
412
+ var cookie = AiCookies.get (ai_adb_pgv_cookie_name);
413
+ if (typeof cookie != "undefined") ai_adb_page_view_counter = parseInt (cookie) + 1;
414
+ if (ai_adb_debugging) console.log ("AI AD BLOCKING page views cookie:", cookie, "- page view:", ai_adb_page_view_counter);
415
+ if (ai_adb_page_view_counter <= ai_adb_page_view_delay) {
416
+ if (ai_adb_debugging) console.log ("AI AD BLOCKING", ai_adb_page_view_delay, "page views not reached, no action");
417
+ AiCookies.set (ai_adb_pgv_cookie_name, ai_adb_page_view_counter, {expires: 365, path: "/"});
418
+ window.ai_d1 = ai_adb_page_view_counter;
419
+ window.AI_ADB_STATUS_MESSAGE=1;
420
+ return;
421
+ }
422
+ if (ai_adb_page_view_repeat != 0) {
423
+ AiCookies.set (ai_adb_pgv_cookie_name, ai_adb_page_view_counter, {expires: 365, path: "/"});
424
+ if ((ai_adb_page_view_counter - ai_adb_page_view_delay - 1) % ai_adb_page_view_repeat != 0) {
425
+ if (ai_adb_debugging) console.log ("AI AD BLOCKING every", ai_adb_page_view_repeat, "page views, no action");
426
+ window.ai_d1 = ai_adb_page_view_counter;
427
+ window.AI_ADB_STATUS_MESSAGE=1;
428
+ return;
429
+ }
430
+ }
431
+ }
432
+
433
+ if (ai_adb_message_cookie_lifetime != 0 && (ai_adb_action != 1 || !ai_adb_message_undismissible)) {
434
+
435
+ var cookie = AiCookies.get (ai_adb_act_cookie_name);
436
+ if (ai_adb_debugging) console.log ("AI AD BLOCKING cookie:", cookie);
437
+ if (typeof cookie != "undefined" && cookie == "AI_CONST_AI_ADB_COOKIE_VALUE") {
438
+ if (ai_adb_debugging) console.log ("AI AD BLOCKING valid cookie detected, no action");
439
+ window.AI_ADB_STATUS_MESSAGE=2;
440
+ return;
441
+ }
442
+
443
+ else if (ai_adb_debugging) console.log ("AI AD BLOCKING invalid cookie");
444
+ AiCookies.set (ai_adb_act_cookie_name, "AI_CONST_AI_ADB_COOKIE_VALUE", {expires: ai_adb_message_cookie_lifetime, path: "/"});
445
+ } else
446
+ AiCookies.remove (ai_adb_act_cookie_name, {path: "/" });
447
+
448
+ if (ai_adb_debugging) console.log ("AI AD BLOCKING action", ai_adb_action);
449
+
450
+ if (ai_adb_action == 0) {
451
+ ai_dummy = 16; // Do not remove - to prevent optimization
452
+ window.AI_ADB_STATUS_MESSAGE=6;
453
+ ai_dummy ++; // Do not remove - to prevent optimization
454
+ } else {
455
+ window.AI_ADB_STATUS_MESSAGE=3;
456
+ ai_dummy = 13; // Do not remove - to prevent optimization
457
+ }
458
+
459
+ switch (ai_adb_action) {
460
+ case 1:
461
+ if (!ai_adb_message_undismissible) {
462
+ ai_adb_overlay.click (function () {
463
+ $(this).remove();
464
+ ai_adb_message_window.remove();
465
+ });
466
+ ai_adb_message_window.click (function () {
467
+ $(this).remove();
468
+ ai_adb_overlay.remove();
469
+ });
470
+ window.onkeydown = function( event ) {
471
+ if (event.keyCode === 27 ) {
472
+ ai_adb_overlay.click ();
473
+ ai_adb_message_window.click ();
474
+ }
475
+ }
476
+
477
+ if (ai_adb_debugging) console.log ("AI AD BLOCKING MESSAGE click detection installed");
478
+
479
+ } else {
480
+ // AiCookies.remove (ai_adb_act_cookie_name, {path: "/" });
481
+
482
+ ai_adb_overlay.find ('[style*="cursor"]').css ("cursor", "no-drop");
483
+ ai_adb_message_window.find ('[style*="cursor"]').css ("cursor", "no-drop");
484
+ }
485
+
486
+ if (ai_adb_debugging) console.log ("AI AD BLOCKING MESSAGE");
487
+
488
+ var body_children = $(b64d ("Ym9keQ==")).children ();
489
+ body_children.eq (Math.floor (Math.random() * body_children.length)).after (ai_adb_overlay);
490
+ body_children.eq (Math.floor (Math.random() * body_children.length)).after (ai_adb_message_window);
491
+
492
+ break;
493
+ case 2:
494
+ if (ai_adb_redirection_url != "") {
495
+ if (ai_adb_debugging) console.log ("AI AD BLOCKING REDIRECTION to", ai_adb_redirection_url);
496
+
497
+ var redirect = true;
498
+ if (ai_adb_redirection_url.toLowerCase().substring (0, 4) == "http") {
499
+ if (window.location.href == ai_adb_redirection_url) var redirect = false;
500
+ } else {
501
+ if (window.location.pathname == ai_adb_redirection_url) var redirect = false;
502
+ }
503
+
504
+ if (redirect) {
505
+ var cookie = AiCookies.get (ai_adb_page_redirection_cookie_name);
506
+ if (typeof cookie == "undefined") {
507
+ var date = new Date();
508
+ date.setTime (date.getTime() + (10 * 1000));
509
+ AiCookies.set (ai_adb_page_redirection_cookie_name, window.location.href, {expires: date, path: "/" });
510
+
511
+ window.location.replace (ai_adb_redirection_url)
512
+ } else {
513
+ if (ai_adb_debugging) console.log ("AI AD BLOCKING no redirection, cookie:", cookie);
514
+
515
+ }
516
+ } else {
517
+ if (ai_adb_debugging) console.log ("AI AD BLOCKING already on page", window.location.href);
518
+ AiCookies.remove (ai_adb_page_redirection_cookie_name, {path: "/"});
519
+ }
520
+ }
521
+ break;
522
+ }
523
+
524
+ }(jQuery));
525
+ }
526
+ }
527
+
528
+
529
+ var ai_adb_undetected = function(n) {
530
+ ai_adb_counter ++;
531
+
532
+ var ai_adb_debugging = typeof ai_debugging !== 'undefined'; // 5
533
+ // var ai_adb_debugging = false;
534
+
535
+ // if (ai_adb_debugging && n == 1) console.log ('');
536
+ if (ai_adb_debugging) console.log ("AI AD BLOCKING not detected:", '(' + ai_adb_counter + ')', ai_adb_detection_type (n));
537
+
538
+ if (!ai_adb_active && ai_adb_counter == 4) {
539
+ if (ai_adb_debugging) console.log ("AI AD BLOCKING NOT DETECTED");
540
+
541
+ jQuery(b64d ("Ym9keQ==")).attr (AI_ADB_ATTR_NAME, b64d ("Y2xlYXI="));
542
+
543
+ ai_dummy = 11; // Do not remove - to prevent optimization
544
+ window.AI_ADB_STATUS_MESSAGE=4; // Check replacement code {}
545
+ ai_dummy = 14; // Do not remove - to prevent optimization
546
+
547
+ // // Prevent tracking if block was not displayed because of cookie
548
+ // jQuery(".ai-adb-hide").each (function () {
549
+ // if (ai_adb_debugging) console.log ('AI ai-adb-hide', jQuery(this), jQuery(this).outerHeight (), jQuery(this).closest ('.ai-adb-show').length);
550
+
551
+ // if (jQuery(this).outerHeight () == 0 && jQuery(this).closest ('.ai-adb-show').length == 0) {
552
+ // // Top level (not nested) block
553
+ // var wrapper = jQuery(this).closest ('div[data-ai]');
554
+ // if (typeof wrapper.attr ("data-ai") != "undefined") {
555
+ // var data = JSON.parse (b64d (wrapper.attr ("data-ai")));
556
+ // if (typeof data !== "undefined" && data.constructor === Array) {
557
+ // data [1] = "";
558
+
559
+ // if (ai_adb_debugging) console.log ("AI AD BLOCKING TRACKING DISABLED: ", b64d (wrapper.attr ("data-ai")), ' <= ', JSON.stringify (data));
560
+
561
+ // wrapper.attr ("data-ai", b64e (JSON.stringify (data)));
562
+
563
+ // // Hide block (wrapping div with margin)
564
+ // wrapper.addClass ('ai-viewport-0').css ("display", "none");
565
+ // }
566
+ // }
567
+
568
+ // }
569
+ // });
570
+
571
+ // jQuery(".ai-adb-show").each (function () {
572
+ // ai_disable_processing (jQuery (this));
573
+ // });
574
+
575
+ ai_adb_process_blocks ();
576
+
577
+ // var redirected_page = false;
578
+ // if (ai_adb_redirection_url.toLowerCase().substring (0, 4) == "http") {
579
+ // if (window.location.href == ai_adb_redirection_url) var redirected_page = true;
580
+ // } else {
581
+ // if (window.location.pathname == ai_adb_redirection_url) var redirected_page = true;
582
+ // }
583
+
584
+ // if (redirected_page) {
585
+ // //var cookie = jQuery.cookie (ai_adb_page_redirection_cookie_name);
586
+ // var cookie = AiCookies.get (ai_adb_page_redirection_cookie_name);
587
+ // if (typeof cookie != "undefined" && cookie.toLowerCase().substring (0, 4) == "http") {
588
+ // if (ai_adb_debugging) console.log ("AI AD BLOCKING returning to", cookie);
589
+ // //jQuery.removeCookie (ai_adb_page_redirection_cookie_name, {path: "/"});
590
+ // AiCookies.remove (ai_adb_page_redirection_cookie_name, {path: "/"});
591
+ // window.location.replace (cookie);
592
+ // }
593
+ // }
594
+
595
+ }
596
+ }
597
+
598
+ if (AI_DBG_AI_DEBUG_AD_BLOCKING) jQuery (document).ready (function () {ai_adb_detected (0)});
599
+
600
+ jQuery (document).ready (function ($) {
601
+ $(window).ready (function () {
602
+
603
+ var ai_adb_debugging = typeof ai_debugging !== 'undefined'; // 6
604
+ // var ai_adb_debugging = false;
605
+
606
+ // var ai_debugging_active = typeof ai_adb_fe_dbg !== 'undefined';
607
+ ai_debugging_active = typeof ai_adb_fe_dbg !== 'undefined';
608
+
609
+ setTimeout (function() {
610
+ $("#ai-adb-bar").click (function () {
611
+ AiCookies.remove (ai_adb_act_cookie_name, {path: "/" });
612
+ AiCookies.remove (ai_adb_pgv_cookie_name, {path: "/" });
613
+ window.AI_ADB_STATUS_MESSAGE=5;
614
+ ai_dummy = 15; // Do not remove - to prevent optimization
615
+ });
616
+ }, 2);
617
+
618
+ // if (jQuery("#banner-advert-container").length) {
619
+ // if ($("#banner-advert-container img").length > 0) {
620
+ // if ($("#banner-advert-container img").outerHeight() === 0) {
621
+ // if (!ai_adb_active || ai_debugging_active) ai_adb_detected (3);
622
+ // } else ai_adb_undetected (3);
623
+ // $("#banner-advert-container img").remove();
624
+ // }
625
+ // }
626
+
627
+ if ((!ai_adb_active || ai_debugging_active) && ai_adb_selectors != "") {
628
+ var ai_adb_el_counter = 0;
629
+ var ai_adb_el_zero = 0;
630
+ var ai_adb_selector = ai_adb_selectors.split (",");
631
+ $.each (ai_adb_selector, function (i) {
632
+ ai_adb_selector [i] = ai_adb_selector [i].trim ();
633
+
634
+ if (ai_adb_debugging) console.log ("AI AD BLOCKING selector", ai_adb_selector [i]);
635
+
636
+ if ($(ai_adb_selector [i]).length != 0) {
637
+ $(ai_adb_selector [i]).each (function (n) {
638
+
639
+ var outer_height = $(this).outerHeight ();
640
+
641
+ if (ai_adb_debugging) console.log ("AI AD BLOCKING element id=\"" + $(this).attr ("id") + "\" class=\"" + $(this).attr ("class") + "\" heights:", $(this).outerHeight (), $(this).innerHeight (), $(this).height ());
642
+
643
+ var ai_attributes = $(this).find ('.ai-attributes');
644
+ if (ai_attributes.length) {
645
+ ai_attributes.each (function (){
646
+ if (ai_adb_debugging) console.log ("AI AD BLOCKING attributes height:", $(this).outerHeight ());
647
+ if (outer_height >= $(this).outerHeight ()) {
648
+ outer_height -= $(this).outerHeight ();
649
+ }
650
+ });
651
+ }
652
+
653
+ if (ai_adb_debugging) console.log ("AI AD BLOCKING effective height:", outer_height);
654
+
655
+ ai_adb_el_counter ++;
656
+ if (outer_height === 0) {
657
+ $ (document).ready (function () {if (!ai_adb_active || ai_debugging_active) ai_adb_detected (4)});
658
+ ai_adb_el_zero ++;
659
+ if (!ai_debugging_active) return false;
660
+ }
661
+
662
+ });
663
+
664
+ }
665
+ });
666
+ if (ai_adb_el_counter != 0 && ai_adb_el_zero == 0) $(document).ready (function () {ai_adb_undetected (4)});
667
+ }
668
+
669
+ var img_container = b64d ("aW1nI2FpLWFkYi1hZG54cw==");
670
+ if (jQuery(img_container).length) {
671
+ jQuery (img_container)
672
+ .on ('load', function() { ai_adb_undetected (8); })
673
+ .on ('error', function() { if (!ai_adb_active || ai_debugging_active) ai_adb_detected (8); })
674
+ .attr ("src", b64d ("aHR0cHM6Ly9pYi5hZG54cy5jb20vZ2V0dWlkP2h0dHBzJTNBJTJGJTJGcm91dGVyLmluZm9saW5rcy5jb20lMkZkeW4lMkZhcG4tdXN5bmMlM0Z1c2VyX2lkJTNEJTI0VUlE"));
675
+ }
676
+ });
677
+ });
678
+
679
+ function ai_adb_get_script (ai_adb_script, ai_adb_action) {
680
+ var ai_adb_debugging = typeof ai_debugging !== 'undefined'; // 7
681
+ // var ai_adb_debugging = false;
682
+
683
+ if (ai_adb_debugging) console.log ("AI AD BLOCKING loading script", ai_adb_script);
684
+
685
+ var script = document.createElement ('script');
686
+ var date = new Date();
687
+ script.src = 'ai-adb-url' + ai_adb_script + '.js?ver=' + date.getTime();
688
+
689
+ var head = document.getElementsByTagName ('head')[0],
690
+ done = false;
691
+
692
+ // Attach handlers for all browsers
693
+
694
+ script.onerror = function () {
695
+ if (ai_adb_debugging) console.log ("AI AD BLOCKING error loading script", ai_adb_script);
696
+
697
+ if (ai_adb_action) {
698
+ ai_adb_action ();
699
+ }
700
+ script.onerror = null;
701
+ head.removeChild (script);
702
+ }
703
+
704
+ script.onload = script.onreadystatechange = function () {
705
+ if (!done && (!this.readyState || this.readyState == 'loaded' || this.readyState == 'complete')) {
706
+ done = true;
707
+
708
+ if (ai_adb_debugging) console.log ("AI AD BLOCKING script loaded ", ai_adb_script);
709
+
710
+ if (ai_adb_action) {
711
+ ai_adb_action ();
712
+ }
713
+
714
+ script.onload = script.onreadystatechange = null;
715
+ head.removeChild (script);
716
+ };
717
+ };
718
+
719
+ head.appendChild (script);
720
+ };
721
+
722
+ jQuery (window).on ('load', function () {
723
+ var ai_adb_debugging = typeof ai_debugging !== 'undefined'; // 8
724
+ // var ai_adb_debugging = false;
725
+
726
+ if (ai_adb_debugging) console.log ("AI AD BLOCKING window load");
727
+
728
+ function ai_adb_1 () {
729
+ if (!document.getElementById ("AI_CONST_AI_ADB_1_NAME")){
730
+ if (!ai_adb_active || ai_debugging_active) ai_adb_detected (1);
731
+ } else {
732
+ ai_adb_undetected (1);
733
+ }
734
+ }
735
+
736
+ function ai_adb_2 () {
737
+ if (typeof window.AI_CONST_AI_ADB_2_NAME == "undefined") {
738
+ if (!ai_adb_active || ai_debugging_active) ai_adb_detected (2);
739
+ } else {
740
+ ai_adb_undetected (2);
741
+ }
742
+ }
743
+
744
+ setTimeout (function() {
745
+ var ai_debugging_active = typeof ai_adb_fe_dbg !== 'undefined';
746
+
747
+ if (jQuery(b64d ("I2FpLWFkYi1hZHM=")).length) {
748
+ if (!document.getElementById ("AI_CONST_AI_ADB_1_NAME")) {
749
+ ai_adb_get_script ('ads', ai_adb_1);
750
+ } else ai_adb_1 ();
751
+ }
752
+
753
+ if (jQuery(b64d ("I2FpLWFkYi1nYQ==")).length) {
754
+ if (!(typeof ga == 'function' && ga.toString().length > 30) &&
755
+ !(typeof __gaTracker == 'function' && __gaTracker.toString ().length > 30)) {
756
+ if (!ai_adb_active || ai_debugging_active) ai_adb_detected (5);
757
+ } else {
758
+ ai_adb_undetected (5);
759
+ }
760
+ }
761
+
762
+ if (jQuery(b64d ("I2FpLWFkYi1zcG9uc29ycw==")).length) {
763
+ if (typeof window.AI_CONST_AI_ADB_2_NAME == "undefined") {
764
+ ai_adb_get_script ('sponsors', ai_adb_2);
765
+ } else ai_adb_2 ();
766
+ }
767
+
768
+ var banner_advert_container = b64d ("I2Jhbm5lci1hZHZlcnQtY29udGFpbmVy");
769
+ var banner_advert_container_img = b64d ("I2Jhbm5lci1hZHZlcnQtY29udGFpbmVyIGltZw==");
770
+ if (jQuery(banner_advert_container).length) {
771
+ if (jQuery(banner_advert_container_img).length > 0) {
772
+ if (jQuery(banner_advert_container_img).outerHeight() === 0) {
773
+ if (!ai_adb_active || ai_debugging_active) ai_adb_detected (3);
774
+ } else ai_adb_undetected (3);
775
+ jQuery(banner_advert_container_img).remove();
776
+ }
777
+ }
778
+
779
+ setTimeout (function() {
780
+ if (jQuery(b64d ("I2FpLWFkYi1tbg==")).length) {
781
+ if (!(typeof _mNDetails == 'object' && JSON.stringify (_mNDetails).length > 400)) {
782
+ if (!ai_adb_active || ai_debugging_active) ai_adb_detected (6);
783
+ } else {
784
+ ai_adb_undetected (6);
785
+ }
786
+ }
787
+ }, 40);
788
+
789
+ }, 120);
790
+ });
791
+
includes/js/ai-lists.js CHANGED
@@ -925,6 +925,21 @@ jQuery (function ($) {
925
  });
926
  }
927
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
928
  $(document).ready(function($) {
929
  var ai_debug = typeof ai_debugging !== 'undefined'; // 6
930
  // var ai_debug = false;
@@ -952,37 +967,31 @@ jQuery (function ($) {
952
  }
953
  }, 50);
954
 
 
 
 
 
 
955
  jQuery("#ai-iab-tcf-bar").click (function () {
956
- // AiCookies.remove ('euconsent-v2', {path: "/", domain: '.' + window.location.hostname});
957
  document.cookie = 'euconsent-v2=; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT;';
958
 
959
  // Clickio GDPR Cookie Consent
960
- // AiCookies.remove ('__lxG__consent__v2', {path: "/", domain: '.' + window.location.hostname});
961
- // AiCookies.remove ('__lxG__consent__v2_daisybit', {path: "/", domain: '.' + window.location.hostname});
962
- // AiCookies.remove ('__lxG__consent__v2_gdaisybit', {path: "/", domain: '.' + window.location.hostname});
963
- // AiCookies.remove ('__lxG__consent__v2', {path: "/", domain: window.location.hostname});
964
- // AiCookies.remove ('__lxG__consent__v2_daisybit', {path: "/", domain: window.location.hostname});
965
- // AiCookies.remove ('__lxG__consent__v2_gdaisybit', {path: "/", domain: window.location.hostname});
966
-
967
  document.cookie = '__lxG__consent__v2=; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT;';
968
  document.cookie = '__lxG__consent__v2_daisybit=; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT;';
969
  document.cookie = '__lxG__consent__v2_gdaisybit=; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT;';
970
 
971
  // Complianz GDPR/CCPA
972
- // AiCookies.remove ('cmplz_marketing', {path: "/", domain: '.' + window.location.hostname});
973
- // AiCookies.remove ('cmplz_stats', {path: "/", domain: '.' + window.location.hostname});
974
- // AiCookies.remove ('complianz_consent_status', {path: "/", domain: '.' + window.location.hostname});
975
- // AiCookies.remove ('cmplz_marketing', {path: "/", domain: window.location.hostname});
976
- // AiCookies.remove ('cmplz_stats', {path: "/", domain: window.location.hostname});
977
- // AiCookies.remove ('complianz_consent_status', {path: "/", domain: window.location.hostname});
978
-
979
  document.cookie = 'complianz_consent_status=; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT;';
980
  document.cookie = 'cmplz_marketing=; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT;';
981
  document.cookie = 'cmplz_stats=; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT;';
982
 
 
 
 
983
  if (ai_debug) console.log ("AI LISTS clear consent cookies", window.location.hostname);
984
 
985
- jQuery('#ai-iab-tcf-status').text ('COOKIE DELETED');
986
  });
987
 
988
  }, 5);
925
  });
926
  }
927
 
928
+ function get_cookie (name) {
929
+ return document.cookie.split (';').some (c => {
930
+ return c.trim().startsWith (name + '=');
931
+ });
932
+ }
933
+
934
+ function delete_cookie (name, path, domain) {
935
+ if (get_cookie (name)) {
936
+ document.cookie = name + "=" +
937
+ ((path) ? ";path=" + path : "") +
938
+ ((domain) ? ";domain=" + domain : "") +
939
+ ";expires=Thu, 01 Jan 1970 00:00:01 GMT";
940
+ }
941
+ }
942
+
943
  $(document).ready(function($) {
944
  var ai_debug = typeof ai_debugging !== 'undefined'; // 6
945
  // var ai_debug = false;
967
  }
968
  }, 50);
969
 
970
+ jQuery(".ai-debug-page-type").dblclick (function () {
971
+ jQuery('#ai-iab-tcf-status').text ('CONSENT COOKIES');
972
+ jQuery("#ai-iab-tcf-bar").show ();
973
+ });
974
+
975
  jQuery("#ai-iab-tcf-bar").click (function () {
976
+
977
  document.cookie = 'euconsent-v2=; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT;';
978
 
979
  // Clickio GDPR Cookie Consent
 
 
 
 
 
 
 
980
  document.cookie = '__lxG__consent__v2=; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT;';
981
  document.cookie = '__lxG__consent__v2_daisybit=; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT;';
982
  document.cookie = '__lxG__consent__v2_gdaisybit=; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT;';
983
 
984
  // Complianz GDPR/CCPA
 
 
 
 
 
 
 
985
  document.cookie = 'complianz_consent_status=; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT;';
986
  document.cookie = 'cmplz_marketing=; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT;';
987
  document.cookie = 'cmplz_stats=; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT;';
988
 
989
+ // GDPR Cookie Compliance (CCPA ready)
990
+ document.cookie = 'moove_gdpr_popup=; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT;';
991
+
992
  if (ai_debug) console.log ("AI LISTS clear consent cookies", window.location.hostname);
993
 
994
+ jQuery('#ai-iab-tcf-status').text ('CONSENT COOKIES DELETED');
995
  });
996
 
997
  }, 5);
includes/js/ai-lists.min.js CHANGED
@@ -17,8 +17,8 @@ var y=(new Date).getTime()+P,D=new Date(y),H=D.getDay();w.includes(" ")||O.inclu
17
  1E3).toString()+" ="+(y>=x).toString()+" end_date:"+Math.floor(C/1E3).toString()+" =:"+(y<C).toString()+" days:"+G.toString()+" =:"+G.includes(H.toString()).toString());r.find(".ai-debug-name.ai-scheduling-status").text(c?ai_front.visible:ai_front.hidden);c||0==T||(r.removeClass("ai-debug-scheduling").addClass("ai-debug-fallback"),r.find(".ai-debug-name.ai-scheduling-status").text(ai_front.fallback+"="+T))}}if(h||M)return!0;a(this).css({visibility:"",position:"",width:"",height:"","z-index":""});
18
  c?(d.css({visibility:""}),d.hasClass("ai-remove-position")&&d.css({position:""}),"undefined"!=typeof a(this).data("code")&&(c=b64d(a(this).data("code")),0!=a(this).closest("head").length?(a(this).after(c),a(this).remove()):a(this).append(c),ai_process_element(this))):f&&!w&&0!=T?(d.css({visibility:""}),d.hasClass("ai-remove-position")&&d.css({position:""}),a(this).next(".ai-fallback").removeClass("ai-fallback"),"undefined"!=typeof a(this).data("fallback-code")?(c=b64d(a(this).data("fallback-code")),
19
  a(this).append(c),ai_process_element(this)):(a(this).hide(),d.find(".ai-debug-block").length||d.hide()),c=d.attr("data-ai"),"undefined"!==typeof c&&!1!==c&&(c=a(this).attr("fallback-tracking"),"undefined"!==typeof c&&!1!==c&&d.attr("data-ai",c))):(a(this).hide(),d.find(".ai-debug-block").length||d.hide(),d.removeAttr("data-ai").removeClass("ai-track"),d.find(".ai-debug-block").length?(d.css({visibility:""}).removeClass("ai-close"),d.hasClass("ai-remove-position")&&d.css({position:""})):d.hide());
20
- a(this).attr("data-code","");a(this).attr("data-fallback-code","");d.removeClass("ai-list-block")})}};a(document).ready(function(e){setTimeout(function(){ai_process_lists();setTimeout(function(){F();if("function"==typeof ai_load_blocks){var k=function(E){"cmplzEnableScripts"!=E.type&&"all"!==E.consentLevel||ai_load_blocks()};jQuery(document).on("cmplzEnableScripts",k);jQuery(document).on("cmplz_event_marketing",k)}},50);jQuery("#ai-iab-tcf-bar").click(function(){document.cookie="euconsent-v2=; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT;";
21
- document.cookie="__lxG__consent__v2=; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT;";document.cookie="__lxG__consent__v2_daisybit=; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT;";document.cookie="__lxG__consent__v2_gdaisybit=; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT;";document.cookie="complianz_consent_status=; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT;";document.cookie="cmplz_marketing=; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT;";document.cookie="cmplz_stats=; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT;";
22
- jQuery("#ai-iab-tcf-status").text("COOKIE DELETED")})},5)})});
23
  function ai_process_element(a){setTimeout(function(){"function"==typeof ai_process_rotations_in_element&&ai_process_rotations_in_element(a);"function"==typeof ai_process_lists&&ai_process_lists(jQuery(".ai-list-data",a));"function"==typeof ai_process_ip_addresses&&ai_process_ip_addresses(jQuery(".ai-ip-data",a));"function"==typeof ai_process_filter_hooks&&ai_process_filter_hooks(jQuery(".ai-filter-check",a));"function"==typeof ai_adb_process_blocks&&ai_adb_process_blocks(a)},5)}
24
  function getAllUrlParams(a){var l=a?a.split("?")[1]:window.location.search.slice(1);a={};if(l){l=l.split("#")[0];l=l.split("&");for(var A=0;A<l.length;A++){var q=l[A].split("="),F=void 0,t=q[0].replace(/\[\d*\]/,function(e){F=e.slice(1,-1);return""});q="undefined"===typeof q[1]?"":q[1];t=t.toLowerCase();q=q.toLowerCase();a[t]?("string"===typeof a[t]&&(a[t]=[a[t]]),"undefined"===typeof F?a[t].push(q):a[t][F]=q):a[t]=q}}return a};
17
  1E3).toString()+" ="+(y>=x).toString()+" end_date:"+Math.floor(C/1E3).toString()+" =:"+(y<C).toString()+" days:"+G.toString()+" =:"+G.includes(H.toString()).toString());r.find(".ai-debug-name.ai-scheduling-status").text(c?ai_front.visible:ai_front.hidden);c||0==T||(r.removeClass("ai-debug-scheduling").addClass("ai-debug-fallback"),r.find(".ai-debug-name.ai-scheduling-status").text(ai_front.fallback+"="+T))}}if(h||M)return!0;a(this).css({visibility:"",position:"",width:"",height:"","z-index":""});
18
  c?(d.css({visibility:""}),d.hasClass("ai-remove-position")&&d.css({position:""}),"undefined"!=typeof a(this).data("code")&&(c=b64d(a(this).data("code")),0!=a(this).closest("head").length?(a(this).after(c),a(this).remove()):a(this).append(c),ai_process_element(this))):f&&!w&&0!=T?(d.css({visibility:""}),d.hasClass("ai-remove-position")&&d.css({position:""}),a(this).next(".ai-fallback").removeClass("ai-fallback"),"undefined"!=typeof a(this).data("fallback-code")?(c=b64d(a(this).data("fallback-code")),
19
  a(this).append(c),ai_process_element(this)):(a(this).hide(),d.find(".ai-debug-block").length||d.hide()),c=d.attr("data-ai"),"undefined"!==typeof c&&!1!==c&&(c=a(this).attr("fallback-tracking"),"undefined"!==typeof c&&!1!==c&&d.attr("data-ai",c))):(a(this).hide(),d.find(".ai-debug-block").length||d.hide(),d.removeAttr("data-ai").removeClass("ai-track"),d.find(".ai-debug-block").length?(d.css({visibility:""}).removeClass("ai-close"),d.hasClass("ai-remove-position")&&d.css({position:""})):d.hide());
20
+ a(this).attr("data-code","");a(this).attr("data-fallback-code","");d.removeClass("ai-list-block")})}};a(document).ready(function(e){setTimeout(function(){ai_process_lists();setTimeout(function(){F();if("function"==typeof ai_load_blocks){var k=function(E){"cmplzEnableScripts"!=E.type&&"all"!==E.consentLevel||ai_load_blocks()};jQuery(document).on("cmplzEnableScripts",k);jQuery(document).on("cmplz_event_marketing",k)}},50);jQuery(".ai-debug-page-type").dblclick(function(){jQuery("#ai-iab-tcf-status").text("CONSENT COOKIES");
21
+ jQuery("#ai-iab-tcf-bar").show()});jQuery("#ai-iab-tcf-bar").click(function(){document.cookie="euconsent-v2=; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT;";document.cookie="__lxG__consent__v2=; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT;";document.cookie="__lxG__consent__v2_daisybit=; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT;";document.cookie="__lxG__consent__v2_gdaisybit=; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT;";document.cookie="complianz_consent_status=; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT;";
22
+ document.cookie="cmplz_marketing=; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT;";document.cookie="cmplz_stats=; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT;";document.cookie="moove_gdpr_popup=; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT;";jQuery("#ai-iab-tcf-status").text("CONSENT COOKIES DELETED")})},5)})});
23
  function ai_process_element(a){setTimeout(function(){"function"==typeof ai_process_rotations_in_element&&ai_process_rotations_in_element(a);"function"==typeof ai_process_lists&&ai_process_lists(jQuery(".ai-list-data",a));"function"==typeof ai_process_ip_addresses&&ai_process_ip_addresses(jQuery(".ai-ip-data",a));"function"==typeof ai_process_filter_hooks&&ai_process_filter_hooks(jQuery(".ai-filter-check",a));"function"==typeof ai_adb_process_blocks&&ai_adb_process_blocks(a)},5)}
24
  function getAllUrlParams(a){var l=a?a.split("?")[1]:window.location.search.slice(1);a={};if(l){l=l.split("#")[0];l=l.split("&");for(var A=0;A<l.length;A++){var q=l[A].split("="),F=void 0,t=q[0].replace(/\[\d*\]/,function(e){F=e.slice(1,-1);return""});q="undefined"===typeof q[1]?"":q[1];t=t.toLowerCase();q=q.toLowerCase();a[t]?("string"===typeof a[t]&&(a[t]=[a[t]]),"undefined"===typeof F?a[t].push(q):a[t][F]=q):a[t]=q}}return a};
includes/js/ai-rotation.js CHANGED
@@ -151,26 +151,37 @@ jQuery (function ($) {
151
 
152
  if ($(rotation_block).hasClass ('ai-rotation-scheduling')) {
153
  random_index = - 1;
154
- var gmt = $(rotation_block).data ('gmt');
155
 
156
- if (ai_debug) console.log ('AI SCHEDULED ROTATION, GMT:', gmt / 1000);
157
 
158
  for (var option_index = 0; option_index < rotate_options.length; option_index ++) {
159
  var option = $(rotate_options [option_index]);
160
  var option_data = option.data ('scheduling');
161
  if (typeof option_data != 'undefined') {
162
  var scheduling_data = b64d (option_data);
 
 
 
 
 
 
 
163
  var scheduling_data_array = scheduling_data.split ('=');
164
- var scheduling_data_time = scheduling_data_array [0].split ('%');
 
 
 
165
 
166
  var time_unit = scheduling_data_time [0].trim ().toLowerCase ();
167
 
168
- var time_division = scheduling_data_time [1].trim ();
169
- var scheduling_time_option = scheduling_data_array [1].trim ();
170
 
171
- if (ai_debug) console.log ('AI SCHEDULED ROTATION OPTION', option_index + ':', time_unit + '%' + time_division + '=' + scheduling_time_option);
 
172
 
173
- var current_time = new Date ().getTime () - gmt;
174
  var date = new Date (current_time);
175
 
176
  var time_value = 0;
@@ -198,9 +209,40 @@ jQuery (function ($) {
198
  if (time_value == 0) time_value = 6; else time_value = time_value - 1;
199
  }
200
 
201
- if (ai_debug) console.log ('AI SCHEDULED ROTATION TIME VALUE:', time_value, '%', time_division, '=', time_value % time_division);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
202
 
203
- if (time_value % time_division == scheduling_time_option) {
 
 
 
 
 
 
 
 
 
 
 
 
 
204
  random_index = option_index;
205
 
206
  if (ai_debug) console.log ('AI SCHEDULED ROTATION OPTION', random_index , 'SELECTED');
@@ -354,6 +396,10 @@ jQuery (function ($) {
354
  if (ai_debug) console.log ('AI ROTATE TRACKING DATA ', b64d (adb_show_wrapping_div.attr ("data-ai-tracking")), ' <= ', JSON.stringify (data));
355
 
356
  adb_show_wrapping_div.attr ("data-ai-tracking", b64e (JSON.stringify (data)))
 
 
 
 
357
  tracking_updated = true;
358
  }
359
  }
@@ -368,6 +414,9 @@ jQuery (function ($) {
368
  data [3] = option_name;
369
  wrapping_div.attr ("data-ai", b64e (JSON.stringify (data)))
370
 
 
 
 
371
  if (ai_debug) console.log ('AI ROTATE TRACKING DATA ', b64d (wrapping_div.attr ("data-ai")));
372
 
373
  }
@@ -426,6 +475,15 @@ function ai_process_elements () {
426
  if (typeof ai_adb_process_blocks == 'function') {
427
  ai_adb_process_blocks ();
428
  }
 
 
 
 
 
 
 
 
 
429
  }, 5);
430
  ai_process_elements_active = true;
431
  }
151
 
152
  if ($(rotation_block).hasClass ('ai-rotation-scheduling')) {
153
  random_index = - 1;
154
+ // var gmt = $(rotation_block).data ('gmt');
155
 
156
+ // if (ai_debug) console.log ('AI SCHEDULED ROTATION, GMT:', gmt / 1000);
157
 
158
  for (var option_index = 0; option_index < rotate_options.length; option_index ++) {
159
  var option = $(rotate_options [option_index]);
160
  var option_data = option.data ('scheduling');
161
  if (typeof option_data != 'undefined') {
162
  var scheduling_data = b64d (option_data);
163
+
164
+ var result = true;
165
+ if (scheduling_data.indexOf ('^') == 0) {
166
+ result = false;
167
+ scheduling_data = scheduling_data.substring (1);
168
+ }
169
+
170
  var scheduling_data_array = scheduling_data.split ('=');
171
+
172
+ if (scheduling_data.indexOf ('%') != -1) {
173
+ var scheduling_data_time = scheduling_data_array [0].split ('%');
174
+ } else var scheduling_data_time = [scheduling_data_array [0]];
175
 
176
  var time_unit = scheduling_data_time [0].trim ().toLowerCase ();
177
 
178
+ var time_division = typeof scheduling_data_time [1] != 'undefined' ? scheduling_data_time [1].trim () : 0;
179
+ var scheduling_time_option = scheduling_data_array [1].replace (' ', '');
180
 
181
+ if (ai_debug) console.log ('');
182
+ if (ai_debug) console.log ('AI SCHEDULED ROTATION OPTION', option_index + (!result ? ' INVERTED' : '') + ':', time_unit + (time_division != 0 ? '%' + time_division : '') + '=' + scheduling_time_option);
183
 
184
+ var current_time = new Date ().getTime ();
185
  var date = new Date (current_time);
186
 
187
  var time_value = 0;
209
  if (time_value == 0) time_value = 6; else time_value = time_value - 1;
210
  }
211
 
212
+ var time_modulo = time_division != 0 ? time_value % time_division : time_value;
213
+
214
+ if (ai_debug) {
215
+ if (time_division != 0) {
216
+ console.log ('AI SCHEDULED ROTATION TIME VALUE:', time_value, '%', time_division, '=', time_modulo);
217
+ } else console.log ('AI SCHEDULED ROTATION TIME VALUE:', time_value);
218
+ }
219
+
220
+ var scheduling_time_options = scheduling_time_option.split (',');
221
+
222
+ var option_selected = !result;
223
+
224
+ for (var time_option_index = 0; time_option_index < scheduling_time_options.length; time_option_index ++) {
225
+ var time_option = scheduling_time_options [time_option_index];
226
+
227
+ if (ai_debug) console.log ('AI SCHEDULED ROTATION TIME ITEM', time_option);
228
+
229
+ if (time_option.indexOf ('-') != - 1) {
230
+ var time_limits = time_option.split ('-');
231
 
232
+ if (ai_debug) console.log ('AI SCHEDULED ROTATION TIME ITEM LIMITS', time_limits [0], '-', time_limits [1]);
233
+
234
+ if (time_modulo >= time_limits [0] && time_modulo <= time_limits [1]) {
235
+ option_selected = result;
236
+ break
237
+ }
238
+ } else
239
+ if (time_modulo == time_option) {
240
+ option_selected = result;
241
+ break
242
+ }
243
+ }
244
+
245
+ if (option_selected) {
246
  random_index = option_index;
247
 
248
  if (ai_debug) console.log ('AI SCHEDULED ROTATION OPTION', random_index , 'SELECTED');
396
  if (ai_debug) console.log ('AI ROTATE TRACKING DATA ', b64d (adb_show_wrapping_div.attr ("data-ai-tracking")), ' <= ', JSON.stringify (data));
397
 
398
  adb_show_wrapping_div.attr ("data-ai-tracking", b64e (JSON.stringify (data)))
399
+
400
+ // Inserted code may need click trackers
401
+ adb_show_wrapping_div.addClass ('ai-track');
402
+
403
  tracking_updated = true;
404
  }
405
  }
414
  data [3] = option_name;
415
  wrapping_div.attr ("data-ai", b64e (JSON.stringify (data)))
416
 
417
+ // Inserted code may need click trackers
418
+ wrapping_div.addClass ('ai-track');
419
+
420
  if (ai_debug) console.log ('AI ROTATE TRACKING DATA ', b64d (wrapping_div.attr ("data-ai")));
421
 
422
  }
475
  if (typeof ai_adb_process_blocks == 'function') {
476
  ai_adb_process_blocks ();
477
  }
478
+
479
+ if (typeof ai_install_click_trackers == 'function' && ai_tracking_finished == true) {
480
+ ai_install_click_trackers ();
481
+ }
482
+
483
+ if (typeof ai_install_close_buttons == 'function') {
484
+ ai_install_close_buttons (document);
485
+ }
486
+
487
  }, 5);
488
  ai_process_elements_active = true;
489
  }
includes/js/ai-rotation.min.js CHANGED
@@ -1,11 +1,12 @@
1
- jQuery(function(a){function u(){a("div.ai-rotate.ai-rotation-groups").each(function(d,k){a(this).addClass("ai-timer");ai_process_rotation(this)})}var p=[];ai_process_rotation=function(d){if(a(d).hasClass("ai-unprocessed")||a(d).hasClass("ai-timer")){a(d).removeClass("ai-unprocessed").removeClass("ai-timer");if("undefined"!=typeof a(d).data("info")){var k="div.ai-rotate.ai-"+JSON.parse(atob(a(d).data("info")))[0];p.includes(k)&&p.splice(p.indexOf(k),1)}if("number"==typeof d.length)for(k=0;k<d.length;k++)0==
2
- k?ai_process_single_rotation(d[k],!0):ai_process_single_rotation(d[k],!1);else ai_process_single_rotation(d,!0)}};ai_process_single_rotation=function(d,k){var g=a(d).children(".ai-rotate-option");if(0!=g.length){g.hide();if("undefined"==typeof a(d).data("next"))if("undefined"!=typeof a(g[0]).data("group")){var f=-1,t=[];a("span[data-ai-groups]").each(function(q){(a(this)[0].offsetWidth||a(this)[0].offsetHeight||a(this)[0].getClientRects().length)&&t.push(this)});1<=t.length&&JSON.parse(b64d(a(t).first().data("ai-groups"))).forEach(function(q,
3
- w){-1==f&&g.each(function(v){if(b64d(a(this).data("group"))==q)return f=v,!1})})}else{var e=a(d).data("shares");if("string"===typeof e){e=JSON.parse(atob(e));var h=Math.round(100*Math.random());for(var b=0;b<e.length&&(f=b,0>e[b]||!(h<=e[b]));b++);}else e=a(d).hasClass("ai-unique"),h=new Date,e?("number"!=typeof ai_rotation_seed&&(ai_rotation_seed=(Math.floor(1E3*Math.random())+h.getMilliseconds())%g.length),e=a(d).data("counter"),f=ai_rotation_seed+e,f>=g.length&&(f-=g.length)):(f=Math.floor(Math.random()*
4
- g.length),h.getMilliseconds()%2&&(f=g.length-f-1))}else f=parseInt(a(d).attr("data-next")),b=a(g[f]),"undefined"!=typeof b.data("code")&&(b=a(b64d(b.data("code")))),0!=b.find("span[data-ai-groups]").addBack("span[data-ai-groups]").length&&0!=a(".ai-rotation-groups").length&&setTimeout(function(){u()},5);if(a(d).hasClass("ai-rotation-scheduling"))for(f=-1,e=a(d).data("gmt"),h=0;h<g.length;h++)if(b=a(g[h]),b=b.data("scheduling"),"undefined"!=typeof b){var m=b64d(b).split("="),c=m[0].split("%");b=c[0].trim().toLowerCase();
5
- c=c[1].trim();m=m[1].trim();var n=(new Date).getTime()-e;n=new Date(n);var l=0;switch(b){case "s":l=n.getSeconds();break;case "i":l=n.getMinutes();break;case "h":l=n.getHours();break;case "d":l=n.getDate();break;case "m":l=n.getMonth();break;case "y":l=n.getFullYear();break;case "w":l=n.getDay(),l=0==l?6:l-1}if(l%c==m){f=h;break}}if(!(0>f||f>=g.length)){b=a(g[f]);e="";if("undefined"!=typeof b.data("time")){h=atob(b.data("time"));if(0==h&&1<g.length){c=f;do{c++;c>=g.length&&(c=0);m=a(g[c]);if("undefined"==
6
- typeof m.data("time")){f=c;b=a(g[f]);h=0;break}m=atob(m.data("time"))}while(0==m&&c!=f);0!=h&&(f=c,b=a(g[f]),h=atob(b.data("time")))}if(0<h&&(c=f+1,c>=g.length&&(c=0),"undefined"!=typeof a(d).data("info"))){e=JSON.parse(atob(a(d).data("info")))[0];a(d).attr("data-next",c);var r="div.ai-rotate.ai-"+e;p.includes(r)&&(k=!1);k&&(p.push(r),setTimeout(function(){a(r).addClass("ai-timer");ai_process_rotation(a(r))},1E3*h));e=" ("+h+" s)"}}else"undefined"==typeof b.data("group")&&g.each(function(q){q!=f&&
7
- a(this).remove()});b.css({display:"",visibility:"",position:"",width:"",height:"",top:"",left:""}).removeClass("ai-rotate-hidden").removeClass("ai-rotate-hidden-2");a(d).css({position:""});"undefined"!=typeof b.data("code")&&(g.empty(),h=b64d(b.data("code")),b.append(h),ai_process_elements());h=b64d(b.data("name"));c=a(d).closest(".ai-debug-block");0!=c.length&&(b=c.find("kbd.ai-option-name"),c=c.find(".ai-debug-block"),"undefined"!=typeof c&&(c=c.find("kbd.ai-option-name"),b=b.slice(0,b.length-c.length)),
8
- "undefined"!=typeof b&&(c=b.first().data("separator"),"undefined"==typeof c&&(c=""),b.html(c+h+e)));b=!1;c=a(d).closest(".ai-adb-show");0!=c.length&&c.attr("data-ai-tracking")&&(e=JSON.parse(b64d(c.attr("data-ai-tracking"))),"undefined"!==typeof e&&e.constructor===Array&&(e[1]=f+1,e[3]=h,c.attr("data-ai-tracking",b64e(JSON.stringify(e))),b=!0));b||(b=a(d).closest("div[data-ai]"),"undefined"!=typeof b.attr("data-ai")&&(e=JSON.parse(b64d(b.attr("data-ai"))),"undefined"!==typeof e&&e.constructor===Array&&
9
- (e[1]=f+1,e[3]=h,b.attr("data-ai",b64e(JSON.stringify(e))))))}}};ai_process_rotations=function(){a("div.ai-rotate").each(function(d,k){ai_process_rotation(this)})};ai_process_rotations_in_element=function(d){a("div.ai-rotate",d).each(function(k,g){ai_process_rotation(this)})};a(document).ready(function(d){setTimeout(function(){ai_process_rotations()},10)})});ai_process_elements_active=!1;
10
- function ai_process_elements(){ai_process_elements_active||setTimeout(function(){ai_process_elements_active=!1;"function"==typeof ai_process_rotations&&ai_process_rotations();"function"==typeof ai_process_lists&&ai_process_lists(jQuery(".ai-list-data"));"function"==typeof ai_process_ip_addresses&&ai_process_ip_addresses(jQuery(".ai-ip-data"));"function"==typeof ai_process_filter_hooks&&ai_process_filter_hooks(jQuery(".ai-filter-check"));"function"==typeof ai_adb_process_blocks&&ai_adb_process_blocks()},
11
- 5);ai_process_elements_active=!0};
 
1
+ jQuery(function(a){function u(){a("div.ai-rotate.ai-rotation-groups").each(function(f,l){a(this).addClass("ai-timer");ai_process_rotation(this)})}var p=[];ai_process_rotation=function(f){if(a(f).hasClass("ai-unprocessed")||a(f).hasClass("ai-timer")){a(f).removeClass("ai-unprocessed").removeClass("ai-timer");if("undefined"!=typeof a(f).data("info")){var l="div.ai-rotate.ai-"+JSON.parse(atob(a(f).data("info")))[0];p.includes(l)&&p.splice(p.indexOf(l),1)}if("number"==typeof f.length)for(l=0;l<f.length;l++)0==
2
+ l?ai_process_single_rotation(f[l],!0):ai_process_single_rotation(f[l],!1);else ai_process_single_rotation(f,!0)}};ai_process_single_rotation=function(f,l){var h=a(f).children(".ai-rotate-option");if(0!=h.length){h.hide();if("undefined"==typeof a(f).data("next"))if("undefined"!=typeof a(h[0]).data("group")){var g=-1,t=[];a("span[data-ai-groups]").each(function(q){(a(this)[0].offsetWidth||a(this)[0].offsetHeight||a(this)[0].getClientRects().length)&&t.push(this)});1<=t.length&&JSON.parse(b64d(a(t).first().data("ai-groups"))).forEach(function(q,
3
+ w){-1==g&&h.each(function(v){if(b64d(a(this).data("group"))==q)return g=v,!1})})}else{var e=a(f).data("shares");if("string"===typeof e){e=JSON.parse(atob(e));var d=Math.round(100*Math.random());for(var b=0;b<e.length&&(g=b,0>e[b]||!(d<=e[b]));b++);}else e=a(f).hasClass("ai-unique"),d=new Date,e?("number"!=typeof ai_rotation_seed&&(ai_rotation_seed=(Math.floor(1E3*Math.random())+d.getMilliseconds())%h.length),e=a(f).data("counter"),g=ai_rotation_seed+e,g>=h.length&&(g-=h.length)):(g=Math.floor(Math.random()*
4
+ h.length),d.getMilliseconds()%2&&(g=h.length-g-1))}else g=parseInt(a(f).attr("data-next")),d=a(h[g]),"undefined"!=typeof d.data("code")&&(d=a(b64d(d.data("code")))),0!=d.find("span[data-ai-groups]").addBack("span[data-ai-groups]").length&&0!=a(".ai-rotation-groups").length&&setTimeout(function(){u()},5);if(a(f).hasClass("ai-rotation-scheduling"))for(g=-1,e=0;e<h.length;e++)if(d=a(h[e]),d=d.data("scheduling"),"undefined"!=typeof d){b=b64d(d);d=!0;0==b.indexOf("^")&&(d=!1,b=b.substring(1));var m=b.split("="),
5
+ c=-1!=b.indexOf("%")?m[0].split("%"):[m[0]];b=c[0].trim().toLowerCase();c="undefined"!=typeof c[1]?c[1].trim():0;m=m[1].replace(" ","");var n=(new Date).getTime();n=new Date(n);var k=0;switch(b){case "s":k=n.getSeconds();break;case "i":k=n.getMinutes();break;case "h":k=n.getHours();break;case "d":k=n.getDate();break;case "m":k=n.getMonth();break;case "y":k=n.getFullYear();break;case "w":k=n.getDay(),k=0==k?6:k-1}b=0!=c?k%c:k;c=m.split(",");m=!d;for(n=0;n<c.length;n++)if(k=c[n],-1!=k.indexOf("-")){if(k=
6
+ k.split("-"),b>=k[0]&&b<=k[1]){m=d;break}}else if(b==k){m=d;break}if(m){g=e;break}}if(!(0>g||g>=h.length)){d=a(h[g]);e="";if("undefined"!=typeof d.data("time")){b=atob(d.data("time"));if(0==b&&1<h.length){c=g;do{c++;c>=h.length&&(c=0);m=a(h[c]);if("undefined"==typeof m.data("time")){g=c;d=a(h[g]);b=0;break}m=atob(m.data("time"))}while(0==m&&c!=g);0!=b&&(g=c,d=a(h[g]),b=atob(d.data("time")))}if(0<b&&(c=g+1,c>=h.length&&(c=0),"undefined"!=typeof a(f).data("info"))){e=JSON.parse(atob(a(f).data("info")))[0];
7
+ a(f).attr("data-next",c);var r="div.ai-rotate.ai-"+e;p.includes(r)&&(l=!1);l&&(p.push(r),setTimeout(function(){a(r).addClass("ai-timer");ai_process_rotation(a(r))},1E3*b));e=" ("+b+" s)"}}else"undefined"==typeof d.data("group")&&h.each(function(q){q!=g&&a(this).remove()});d.css({display:"",visibility:"",position:"",width:"",height:"",top:"",left:""}).removeClass("ai-rotate-hidden").removeClass("ai-rotate-hidden-2");a(f).css({position:""});"undefined"!=typeof d.data("code")&&(h.empty(),b=b64d(d.data("code")),
8
+ d.append(b),ai_process_elements());d=b64d(d.data("name"));c=a(f).closest(".ai-debug-block");0!=c.length&&(b=c.find("kbd.ai-option-name"),c=c.find(".ai-debug-block"),"undefined"!=typeof c&&(c=c.find("kbd.ai-option-name"),b=b.slice(0,b.length-c.length)),"undefined"!=typeof b&&(c=b.first().data("separator"),"undefined"==typeof c&&(c=""),b.html(c+d+e)));b=!1;c=a(f).closest(".ai-adb-show");0!=c.length&&c.attr("data-ai-tracking")&&(e=JSON.parse(b64d(c.attr("data-ai-tracking"))),"undefined"!==typeof e&&
9
+ e.constructor===Array&&(e[1]=g+1,e[3]=d,c.attr("data-ai-tracking",b64e(JSON.stringify(e))),c.addClass("ai-track"),b=!0));b||(b=a(f).closest("div[data-ai]"),"undefined"!=typeof b.attr("data-ai")&&(e=JSON.parse(b64d(b.attr("data-ai"))),"undefined"!==typeof e&&e.constructor===Array&&(e[1]=g+1,e[3]=d,b.attr("data-ai",b64e(JSON.stringify(e))),b.addClass("ai-track"))))}}};ai_process_rotations=function(){a("div.ai-rotate").each(function(f,l){ai_process_rotation(this)})};ai_process_rotations_in_element=function(f){a("div.ai-rotate",
10
+ f).each(function(l,h){ai_process_rotation(this)})};a(document).ready(function(f){setTimeout(function(){ai_process_rotations()},10)})});ai_process_elements_active=!1;
11
+ function ai_process_elements(){ai_process_elements_active||setTimeout(function(){ai_process_elements_active=!1;"function"==typeof ai_process_rotations&&ai_process_rotations();"function"==typeof ai_process_lists&&ai_process_lists(jQuery(".ai-list-data"));"function"==typeof ai_process_ip_addresses&&ai_process_ip_addresses(jQuery(".ai-ip-data"));"function"==typeof ai_process_filter_hooks&&ai_process_filter_hooks(jQuery(".ai-filter-check"));"function"==typeof ai_adb_process_blocks&&ai_adb_process_blocks();
12
+ "function"==typeof ai_install_click_trackers&&1==ai_tracking_finished&&ai_install_click_trackers();"function"==typeof ai_install_close_buttons&&ai_install_close_buttons(document)},5);ai_process_elements_active=!0};
includes/preview.php CHANGED
@@ -171,7 +171,7 @@ function generate_code_preview (
171
  $sticky = false;
172
  $class = '';
173
  $sticky_parameters = '';
174
- $functions = function_exists ('ai_extract_features_2');
175
  $iframe_resize = $iframe && $obj->get_iframe_height () == '';
176
 
177
  $fixed_background = $background && $horizontal_position == AI_STICK_HORIZONTAL_CENTER;
@@ -205,6 +205,7 @@ function generate_code_preview (
205
  }
206
  }
207
 
 
208
  // Head code must be called before ai_getProcessedCode (to process head PHP)
209
  if ($head_code === null) {
210
  ob_start ();
@@ -2504,9 +2505,8 @@ input {
2504
  </table>
2505
  </div>
2506
 
2507
-
2508
  <div id="close-button-selection" style="float: right; text-align: right;<?php if ($fixed_background) echo "; display: none;"; ?>">
2509
- <?php if (function_exists ('ai_close_button_select')) ai_close_button_select (0, $close_button, $close_button, 'close-button-0'); ?>
2510
  <div id="close-buttons" style="margin: 4px 0; min-height: 74px;"></div>
2511
  </div>
2512
 
@@ -2679,8 +2679,9 @@ input {
2679
  </div>
2680
  <span id="css-index" style="display: inline-block; min-width: 30px; min-height: 12px; margin: 0 0 0 10px; font-size: 14px;" title="CSS code index"></span>
2681
  &nbsp;&nbsp;&nbsp;
 
2682
  <span id="close-button-selection" style="display: <?php echo $alignment_type == AI_ALIGNMENT_NO_WRAPPING || $close_button == AI_CLOSE_NONE ? 'none': 'inline'; ?>;">
2683
- <?php if (function_exists ('ai_close_button_select')) ai_close_button_select (0, $close_button, $close_button, 'close-button-0'); ?>
2684
  </span>
2685
  </div>
2686
 
171
  $sticky = false;
172
  $class = '';
173
  $sticky_parameters = '';
174
+ $functions = ai_pro () && function_exists ('ai_extract_features_2');
175
  $iframe_resize = $iframe && $obj->get_iframe_height () == '';
176
 
177
  $fixed_background = $background && $horizontal_position == AI_STICK_HORIZONTAL_CENTER;
205
  }
206
  }
207
 
208
+
209
  // Head code must be called before ai_getProcessedCode (to process head PHP)
210
  if ($head_code === null) {
211
  ob_start ();
2505
  </table>
2506
  </div>
2507
 
 
2508
  <div id="close-button-selection" style="float: right; text-align: right;<?php if ($fixed_background) echo "; display: none;"; ?>">
2509
+ <?php if (ai_pro () && function_exists ('ai_close_button_select')) ai_close_button_select (0, $close_button, $close_button, 'close-button-0'); ?>
2510
  <div id="close-buttons" style="margin: 4px 0; min-height: 74px;"></div>
2511
  </div>
2512
 
2679
  </div>
2680
  <span id="css-index" style="display: inline-block; min-width: 30px; min-height: 12px; margin: 0 0 0 10px; font-size: 14px;" title="CSS code index"></span>
2681
  &nbsp;&nbsp;&nbsp;
2682
+
2683
  <span id="close-button-selection" style="display: <?php echo $alignment_type == AI_ALIGNMENT_NO_WRAPPING || $close_button == AI_CLOSE_NONE ? 'none': 'inline'; ?>;">
2684
+ <?php if (ai_pro () && function_exists ('ai_close_button_select')) ai_close_button_select (0, $close_button, $close_button, 'close-button-0'); ?>
2685
  </span>
2686
  </div>
2687
 
js/ad-inserter.js CHANGED
@@ -1,6598 +1,6590 @@
1
- var javascript_version = "2.6.25";
2
- var ignore_key = true;
3
- var start = 1;
4
- var end = 16;
5
- var active_tab = 1;
6
- var active_tab_0 = 0;
7
- var tabs_to_configure = new Array();
8
- var debug = false;
9
- var debug_title = false;
10
- var save_enabled = true;
11
-
12
- var current_tab = 0;
13
- var next_tab = 0;
14
-
15
- var syntax_highlighting = false;
16
- var settings_page = "";
17
-
18
- var dateFormat = "yy-mm-dd";
19
- var timeFormat = "H:i:s";
20
-
21
- var list_search_reload = false;
22
- var website_list_search_reload = false;
23
- //var ai_ctrl_pressed = false;
24
-
25
- var AI_DISABLED = 0;
26
- var AI_BEFORE_POST = 1;
27
- var AI_AFTER_POST = 2;
28
- var AI_BEFORE_CONTENT = 3;
29
- var AI_AFTER_CONTENT = 4;
30
- var AI_BEFORE_PARAGRAPH = 5;
31
- var AI_AFTER_PARAGRAPH = 6;
32
- var AI_BEFORE_EXCERPT = 7;
33
- var AI_AFTER_EXCERPT = 8;
34
- var AI_BETWEEN_POSTS = 9;
35
- var AI_BEFORE_COMMENTS = 10;
36
- var AI_BETWEEN_COMMENTS = 11;
37
- var AI_AFTER_COMMENTS = 12;
38
- var AI_FOOTER = 13;
39
- var AI_ABOVE_HEADER = 14;
40
- var AI_BEFORE_HTML_ELEMENT = 15;
41
- var AI_AFTER_HTML_ELEMENT = 16;
42
- var AI_INSIDE_HTML_ELEMENT = 17;
43
- var AI_BEFORE_IMAGE = 18;
44
- var AI_AFTER_IMAGE = 19;
45
-
46
-
47
- var AI_ALIGNMENT_DEFAULT = 0;
48
- var AI_ALIGNMENT_LEFT = 1;
49
- var AI_ALIGNMENT_RIGHT = 2;
50
- var AI_ALIGNMENT_CENTER = 3;
51
- var AI_ALIGNMENT_FLOAT_LEFT = 4;
52
- var AI_ALIGNMENT_FLOAT_RIGHT = 5;
53
- var AI_ALIGNMENT_NO_WRAPPING = 6;
54
- var AI_ALIGNMENT_CUSTOM_CSS = 7;
55
- var AI_ALIGNMENT_STICKY_LEFT = 8;
56
- var AI_ALIGNMENT_STICKY_RIGHT = 9;
57
- var AI_ALIGNMENT_STICKY_TOP = 10;
58
- var AI_ALIGNMENT_STICKY_BOTTOM = 11;
59
- var AI_ALIGNMENT_STICKY = 12;
60
-
61
- var AI_ADB_ACTION_NONE = 0;
62
- var AI_ADB_ACTION_MESSAGE = 1;
63
- var AI_ADB_ACTION_REDIRECTION = 2;
64
-
65
- var AI_ADB_BLOCK_ACTION_DO_NOTHING = 0;
66
- var AI_ADB_BLOCK_ACTION_REPLACE = 1;
67
- var AI_ADB_BLOCK_ACTION_SHOW = 2;
68
- var AI_ADB_BLOCK_ACTION_HIDE = 3;
69
-
70
- var AI_CODE_UNKNOWN = 100;
71
- var AI_CODE_BANNER = 0;
72
- var AI_CODE_ADSENSE = 1;
73
- var AI_CODE_AMAZON = 2;
74
-
75
- var AI_ADSENSE_STANDARD = 0;
76
- var AI_ADSENSE_LINK = 1;
77
- var AI_ADSENSE_IN_ARTICLE = 2;
78
- var AI_ADSENSE_IN_FEED = 3;
79
- var AI_ADSENSE_MATCHED_CONTENT = 4;
80
-
81
- var AI_ADSENSE_SIZE_FIXED = 0;
82
- var AI_ADSENSE_SIZE_RESPONSIVE = 1;
83
- var AI_ADSENSE_SIZE_FIXED_BY_VIEWPORT = 2;
84
-
85
- var AI_HTML_INSERTION_CLIENT_SIDE = 0;
86
- //var AI_HTML_INSERTION_CLIENT_SIDE_DOM_READY = 1;
87
- var AI_HTML_INSERTION_SEREVR_SIDE = 2;
88
-
89
- var AI_STICK_TO_THE_LEFT = 0;
90
- var AI_STICK_TO_THE_CONTENT_LEFT = 1;
91
- var AI_STICK_HORIZONTAL_CENTER = 2;
92
- var AI_STICK_TO_THE_CONTENT_RIGHT = 3;
93
- var AI_STICK_TO_THE_RIGHT = 4;
94
-
95
- var AI_STICK_TO_THE_TOP = 0;
96
- var AI_STICK_VERTICAL_CENTER = 1;
97
- var AI_SCROLL_WITH_THE_CONTENT = 2;
98
- var AI_STICK_TO_THE_BOTTOM = 3;
99
-
100
- var AI_ANIMATION_NONE = 0;
101
-
102
- var AI_BACKGROUND_REPEAT_DEFAULT = 0;
103
- var AI_BACKGROUND_REPEAT_NO = 1;
104
- var AI_BACKGROUND_REPEAT_YES = 2;
105
- var AI_BACKGROUND_REPEAT_HORIZONTALY = 3;
106
- var AI_BACKGROUND_REPEAT_VERTICALLY = 4;
107
- var AI_BACKGROUND_REPEAT_SPACE = 5;
108
- var AI_BACKGROUND_REPEAT_ROUND = 6;
109
-
110
- var AI_BACKGROUND_SIZE_DEFAULT = 0;
111
- var AI_BACKGROUND_SIZE_COVER = 1;
112
- var AI_BACKGROUND_SIZE_CONTAIN = 2;
113
- var AI_BACKGROUND_SIZE_FILL = 3;
114
-
115
- var before_update_selection_from_list = null;
116
-
117
- /*
118
- * jQuery Tooltip plugin 1.3
119
- *
120
- * http://bassistance.de/jquery-plugins/jquery-plugin-tooltip/
121
- * http://docs.jquery.com/Plugins/Tooltip
122
- *
123
- * Copyright (c) 2006 - 2008 J�rn Zaefferer
124
- *
125
- * $Id: jquery.tooltip.js 5741 2008-06-21 15:22:16Z joern.zaefferer $
126
- *
127
- * Dual licensed under the MIT and GPL licenses:
128
- * http://www.opensource.org/licenses/mit-license.php
129
- * http://www.gnu.org/licenses/gpl.html
130
- */
131
- (function($) {
132
- // the tooltip element
133
- var helper = {},
134
- // the current tooltipped element
135
- current,
136
- // the title of the current element, used for restoring
137
- title,
138
- // timeout id for delayed tooltips
139
- tID,
140
- // IE 5.5 or 6
141
- // IE = $.browser.msie && /MSIE\s(5\.5|6\.)/.test(navigator.userAgent),
142
- IE = false,
143
- // flag for mouse tracking
144
- track = false;
145
- $.tooltip = {
146
- blocked: false,
147
- defaults: {
148
- delay: 200,
149
- fade: false,
150
- showURL: true,
151
- extraClass: "",
152
- top: 15,
153
- left: 15,
154
- id: "ai-tooltip"
155
- },
156
- block: function() {
157
- $.tooltip.blocked = !$.tooltip.blocked;
158
- }
159
- };
160
- $.fn.extend({
161
- tooltip: function(settings) {
162
- settings = $.extend({}, $.tooltip.defaults, settings);
163
- createHelper(settings);
164
- return this.each(function() {
165
- $.data(this, "tooltip", settings);
166
- this.tOpacity = helper.parent.css("opacity");
167
- // copy tooltip into its own expando and remove the title
168
- this.tooltipText = this.title;
169
- $(this).removeAttr("title");
170
- // also remove alt attribute to prevent default tooltip in IE
171
- this.alt = "";
172
- })
173
- .mouseover(save)
174
- .mouseout(hide)
175
- .click(hide);
176
- },
177
- fixPNG: IE ? function() {
178
- return this.each(function() {
179
- var image = $(this).css('backgroundImage');
180
- if (image.match(/^url\(["']?(.*\.png)["']?\)$/i)) {
181
- image = RegExp.$1;
182
- $(this).css({
183
- 'backgroundImage': 'none',
184
- 'filter': "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod=crop, src='" + image + "')"
185
- }).each(function() {
186
- var position = $(this).css('position');
187
- if (position != 'absolute' && position != 'relative')
188
- $(this).css('position', 'relative');
189
- });
190
- }
191
- });
192
- } : function() {
193
- return this;
194
- },
195
- unfixPNG: IE ? function() {
196
- return this.each(function() {
197
- $(this).css({
198
- 'filter': '',
199
- backgroundImage: ''
200
- });
201
- });
202
- } : function() {
203
- return this;
204
- },
205
- hideWhenEmpty: function() {
206
- return this.each(function() {
207
- $(this)[$(this).html() ? "show" : "hide"]();
208
- });
209
- },
210
- url: function() {
211
- return this.attr('href') || this.attr('src');
212
- }
213
- });
214
- function createHelper(settings) {
215
- // there can be only one tooltip helper
216
- if (helper.parent)
217
- return;
218
- // create the helper, h3 for title, div for url
219
- helper.parent = $('<div id="' + settings.id + '"><h3></h3><div class="body"></div><div class="url"></div></div>')
220
- // add to document
221
- .appendTo(document.body)
222
- // hide it at first
223
- .hide();
224
- // apply bgiframe if available
225
- if ($.fn.bgiframe)
226
- helper.parent.bgiframe();
227
- // save references to title and url elements
228
- helper.title = $('h3', helper.parent);
229
- helper.body = $('div.body', helper.parent);
230
- helper.url = $('div.url', helper.parent);
231
- }
232
- function settings(element) {
233
- return $.data(element, "tooltip");
234
- }
235
- // main event handler to start showing tooltips
236
- function handle(event) {
237
- // show helper, either with timeout or on instant
238
- if (settings(this).delay)
239
- tID = setTimeout(show, settings(this).delay);
240
- else
241
- show();
242
- // if selected, update the helper position when the mouse moves
243
- track = !!settings(this).track;
244
- $(document.body).bind('mousemove', update);
245
- // update at least once
246
- update(event);
247
- }
248
- // save elements title before the tooltip is displayed
249
- function save() {
250
- // if this is the current source, or it has no title (occurs with click event), stop
251
- if ($.tooltip.blocked || this == current || (!this.tooltipText && !settings(this).bodyHandler))
252
- return;
253
- // save current
254
- current = this;
255
- title = this.tooltipText;
256
-
257
- title = title.replace (/\[\[(.+?)\]\]/g, '<span class="tooltip-code">$1</span>');
258
- title = title.replace (/\[BR\]/g, '<br />');
259
- title = title.replace (/\[HR\]/g, '<hr />');
260
- title = title.replace (/(\[ADINSERTER.+\])/g, '<span class="tooltip-code">$1</span>');
261
- title = title.replace (/(\%N)/g, '<span class="tooltip-code">$1</span>');
262
- title = title.replace (/(\[\*\])/g, '<span class="tooltip-icon"><span class="dashicons dashicons-admin-generic" style="width: 11px; height: 11px; font-size: 12px; line-height: unset;"></span></span>');
263
- title = title.replace (/(http[^ ]+)/g, '<span class="tooltip-code">$1</span>');
264
- title = title.replace (/(pub-[0-9]+)/g, '<span class="tooltip-code">$1</span>');
265
-
266
- if (settings(this).bodyHandler) {
267
- helper.title.hide();
268
- var bodyContent = settings(this).bodyHandler.call(this);
269
- if (bodyContent.nodeType || bodyContent.jquery) {
270
- helper.body.empty().append(bodyContent)
271
- } else {
272
- helper.body.html(bodyContent);
273
- }
274
- helper.body.show();
275
- } else if (settings(this).showBody) {
276
- var parts = title.split(settings(this).showBody);
277
- if (parts.length == 2) {
278
- helper.title.html(parts.shift()).show();
279
- } else {
280
- helper.title.hide();
281
- }
282
- helper.body.empty();
283
- for (var i = 0, part;
284
- (part = parts[i]); i++) {
285
- if (i > 0)
286
- helper.body.append("<br/>");
287
- helper.body.append(part);
288
- }
289
- helper.body.hideWhenEmpty();
290
- } else {
291
- helper.title.html(title).show();
292
- helper.body.hide();
293
- }
294
- // if element has href or src, add and show it, otherwise hide it
295
- if (settings(this).showURL && $(this).url())
296
- helper.url.html($(this).url().replace('http://', '')).show();
297
- else
298
- helper.url.hide();
299
- // add an optional class for this tip
300
- helper.parent.addClass(settings(this).extraClass);
301
- // fix PNG background for IE
302
- if (settings(this).fixPNG)
303
- helper.parent.fixPNG();
304
- handle.apply(this, arguments);
305
- }
306
- // delete timeout and show helper
307
- function show() {
308
- tID = null;
309
- if ((!IE || !$.fn.bgiframe) && settings(current).fade) {
310
- if (helper.parent.is(":animated"))
311
- helper.parent.stop().show().fadeTo(settings(current).fade, current.tOpacity);
312
- else
313
- helper.parent.is(':visible') ? helper.parent.fadeTo(settings(current).fade, current.tOpacity) : helper.parent.fadeIn(settings(current).fade);
314
- } else {
315
- helper.parent.show();
316
- }
317
- update();
318
- }
319
- /**
320
- * callback for mousemove
321
- * updates the helper position
322
- * removes itself when no current element
323
- */
324
- function update(event) {
325
- if ($.tooltip.blocked)
326
- return;
327
- if (event && event.target.tagName == "OPTION") {
328
- return;
329
- }
330
- // stop updating when tracking is disabled and the tooltip is visible
331
- if (!track && helper.parent.is(":visible")) {
332
- $(document.body).unbind('mousemove', update)
333
- }
334
- // if no current element is available, remove this listener
335
- if (current == null) {
336
- $(document.body).unbind('mousemove', update);
337
- return;
338
- }
339
- // remove position helper classes
340
- helper.parent.removeClass("viewport-right").removeClass("viewport-bottom");
341
- var left = helper.parent[0].offsetLeft;
342
- var top = helper.parent[0].offsetTop;
343
- if (event) {
344
- // position the helper 15 pixel to bottom right, starting from mouse position
345
- left = event.pageX + settings(current).left;
346
- top = event.pageY + settings(current).top;
347
- var right = 'auto';
348
- if (settings(current).positionLeft) {
349
- right = $(window).width() - left;
350
- left = 'auto';
351
- }
352
- helper.parent.css({
353
- left: left,
354
- right: right,
355
- top: top
356
- });
357
- }
358
- var v = viewport(),
359
- h = helper.parent[0];
360
- // check horizontal position
361
- if (v.x + v.cx < h.offsetLeft + h.offsetWidth) {
362
- left -= h.offsetWidth + 20 + settings(current).left;
363
- helper.parent.css({
364
- left: left + 'px'
365
- }).addClass("viewport-right");
366
- }
367
- // check vertical position
368
- if (v.y + v.cy < h.offsetTop + h.offsetHeight) {
369
- top -= h.offsetHeight + 20 + settings(current).top;
370
- helper.parent.css({
371
- top: top + 'px'
372
- }).addClass("viewport-bottom");
373
- }
374
- }
375
- function viewport() {
376
- return {
377
- x: $(window).scrollLeft(),
378
- y: $(window).scrollTop(),
379
- cx: $(window).width(),
380
- cy: $(window).height()
381
- };
382
- }
383
- // hide helper and restore added classes and the title
384
- function hide(event) {
385
- if ($.tooltip.blocked)
386
- return;
387
- // clear timeout if possible
388
- if (tID)
389
- clearTimeout(tID);
390
- // no more current element
391
- current = null;
392
- var tsettings = settings(this);
393
- function complete() {
394
- helper.parent.removeClass(tsettings.extraClass).hide().css("opacity", "");
395
- }
396
- if ((!IE || !$.fn.bgiframe) && tsettings.fade) {
397
- if (helper.parent.is(':animated'))
398
- helper.parent.stop().fadeTo(tsettings.fade, 0, complete);
399
- else
400
- helper.parent.stop().fadeOut(tsettings.fade, complete);
401
- } else
402
- complete();
403
- if (settings(this).fixPNG)
404
- helper.parent.unfixPNG();
405
- }
406
- })(jQuery);
407
-
408
- function b64e (str) {
409
- // first we use encodeURIComponent to get percent-encoded UTF-8,
410
- // then we convert the percent encodings into raw bytes which
411
- // can be fed into btoa.
412
- return btoa (encodeURIComponent (str).replace (/%([0-9A-F]{2})/g,
413
- function toSolidBytes (match, p1) {
414
- return String.fromCharCode ('0x' + p1);
415
- }));
416
- }
417
-
418
- function b64d (str) {
419
- // Going backwards: from bytestream, to percent-encoding, to original string.
420
- return decodeURIComponent (atob (str).split ('').map (function(c) {
421
- return '%' + ('00' + c.charCodeAt (0).toString (16)).slice (-2);
422
- }).join (''));
423
- }
424
-
425
- // http://www.myersdaily.org/joseph/javascript/md5.js
426
-
427
- function md5cycle (x, k) {
428
- var a = x[0],
429
- b = x[1],
430
- c = x[2],
431
- d = x[3];
432
- a = ff(a, b, c, d, k[0], 7, -680876936);
433
- d = ff(d, a, b, c, k[1], 12, -389564586);
434
- c = ff(c, d, a, b, k[2], 17, 606105819);
435
- b = ff(b, c, d, a, k[3], 22, -1044525330);
436
- a = ff(a, b, c, d, k[4], 7, -176418897);
437
- d = ff(d, a, b, c, k[5], 12, 1200080426);
438
- c = ff(c, d, a, b, k[6], 17, -1473231341);
439
- b = ff(b, c, d, a, k[7], 22, -45705983);
440
- a = ff(a, b, c, d, k[8], 7, 1770035416);
441
- d = ff(d, a, b, c, k[9], 12, -1958414417);
442
- c = ff(c, d, a, b, k[10], 17, -42063);
443
- b = ff(b, c, d, a, k[11], 22, -1990404162);
444
- a = ff(a, b, c, d, k[12], 7, 1804603682);
445
- d = ff(d, a, b, c, k[13], 12, -40341101);
446
- c = ff(c, d, a, b, k[14], 17, -1502002290);
447
- b = ff(b, c, d, a, k[15], 22, 1236535329);
448
- a = gg(a, b, c, d, k[1], 5, -165796510);
449
- d = gg(d, a, b, c, k[6], 9, -1069501632);
450
- c = gg(c, d, a, b, k[11], 14, 643717713);
451
- b = gg(b, c, d, a, k[0], 20, -373897302);
452
- a = gg(a, b, c, d, k[5], 5, -701558691);
453
- d = gg(d, a, b, c, k[10], 9, 38016083);
454
- c = gg(c, d, a, b, k[15], 14, -660478335);
455
- b = gg(b, c, d, a, k[4], 20, -405537848);
456
- a = gg(a, b, c, d, k[9], 5, 568446438);
457
- d = gg(d, a, b, c, k[14], 9, -1019803690);
458
- c = gg(c, d, a, b, k[3], 14, -187363961);
459
- b = gg(b, c, d, a, k[8], 20, 1163531501);
460
- a = gg(a, b, c, d, k[13], 5, -1444681467);
461
- d = gg(d, a, b, c, k[2], 9, -51403784);
462
- c = gg(c, d, a, b, k[7], 14, 1735328473);
463
- b = gg(b, c, d, a, k[12], 20, -1926607734);
464
- a = hh(a, b, c, d, k[5], 4, -378558);
465
- d = hh(d, a, b, c, k[8], 11, -2022574463);
466
- c = hh(c, d, a, b, k[11], 16, 1839030562);
467
- b = hh(b, c, d, a, k[14], 23, -35309556);
468
- a = hh(a, b, c, d, k[1], 4, -1530992060);
469
- d = hh(d, a, b, c, k[4], 11, 1272893353);
470
- c = hh(c, d, a, b, k[7], 16, -155497632);
471
- b = hh(b, c, d, a, k[10], 23, -1094730640);
472
- a = hh(a, b, c, d, k[13], 4, 681279174);
473
- d = hh(d, a, b, c, k[0], 11, -358537222);
474
- c = hh(c, d, a, b, k[3], 16, -722521979);
475
- b = hh(b, c, d, a, k[6], 23, 76029189);
476
- a = hh(a, b, c, d, k[9], 4, -640364487);
477
- d = hh(d, a, b, c, k[12], 11, -421815835);
478
- c = hh(c, d, a, b, k[15], 16, 530742520);
479
- b = hh(b, c, d, a, k[2], 23, -995338651);
480
- a = ii(a, b, c, d, k[0], 6, -198630844);
481
- d = ii(d, a, b, c, k[7], 10, 1126891415);
482
- c = ii(c, d, a, b, k[14], 15, -1416354905);
483
- b = ii(b, c, d, a, k[5], 21, -57434055);
484
- a = ii(a, b, c, d, k[12], 6, 1700485571);
485
- d = ii(d, a, b, c, k[3], 10, -1894986606);
486
- c = ii(c, d, a, b, k[10], 15, -1051523);
487
- b = ii(b, c, d, a, k[1], 21, -2054922799);
488
- a = ii(a, b, c, d, k[8], 6, 1873313359);
489
- d = ii(d, a, b, c, k[15], 10, -30611744);
490
- c = ii(c, d, a, b, k[6], 15, -1560198380);
491
- b = ii(b, c, d, a, k[13], 21, 1309151649);
492
- a = ii(a, b, c, d, k[4], 6, -145523070);
493
- d = ii(d, a, b, c, k[11], 10, -1120210379);
494
- c = ii(c, d, a, b, k[2], 15, 718787259);
495
- b = ii(b, c, d, a, k[9], 21, -343485551);
496
- x[0] = add32(a, x[0]);
497
- x[1] = add32(b, x[1]);
498
- x[2] = add32(c, x[2]);
499
- x[3] = add32(d, x[3]);
500
- }
501
- function cmn(q, a, b, x, s, t) {
502
- a = add32(add32(a, q), add32(x, t));
503
- return add32((a << s) | (a >>> (32 - s)), b);
504
- }
505
- function ff(a, b, c, d, x, s, t) {
506
- return cmn((b & c) | ((~b) & d), a, b, x, s, t);
507
- }
508
- function gg(a, b, c, d, x, s, t) {
509
- return cmn((b & d) | (c & (~d)), a, b, x, s, t);
510
- }
511
- function hh(a, b, c, d, x, s, t) {
512
- return cmn(b ^ c ^ d, a, b, x, s, t);
513
- }
514
- function ii(a, b, c, d, x, s, t) {
515
- return cmn(c ^ (b | (~d)), a, b, x, s, t);
516
- }
517
- function md51(s) {
518
- txt = '';
519
- var n = s.length,
520
- state = [1732584193, -271733879, -1732584194, 271733878],
521
- i;
522
- for (i = 64; i <= s.length; i += 64) {
523
- md5cycle(state, md5blk(s.substring(i - 64, i)));
524
- }
525
- s = s.substring(i - 64);
526
- var tail = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
527
- for (i = 0; i < s.length; i++)
528
- tail[i >> 2] |= s.charCodeAt(i) << ((i % 4) << 3);
529
- tail[i >> 2] |= 0x80 << ((i % 4) << 3);
530
- if (i > 55) {
531
- md5cycle(state, tail);
532
- for (i = 0; i < 16; i++) tail[i] = 0;
533
- }
534
- tail[14] = n * 8;
535
- md5cycle(state, tail);
536
- return state;
537
- }
538
- /* there needs to be support for Unicode here,
539
- * unless we pretend that we can redefine the MD-5
540
- * algorithm for multi-byte characters (perhaps
541
- * by adding every four 16-bit characters and
542
- * shortening the sum to 32 bits). Otherwise
543
- * I suggest performing MD-5 as if every character
544
- * was two bytes--e.g., 0040 0025 = @%--but then
545
- * how will an ordinary MD-5 sum be matched?
546
- * There is no way to standardize text to something
547
- * like UTF-8 before transformation; speed cost is
548
- * utterly prohibitive. The JavaScript standard
549
- * itself needs to look at this: it should start
550
- * providing access to strings as preformed UTF-8
551
- * 8-bit unsigned value arrays.
552
- */
553
- function md5blk(s) { /* I figured global was faster. */
554
- var md5blks = [],
555
- i; /* Andy King said do it this way. */
556
- for (i = 0; i < 64; i += 4) {
557
- md5blks[i >> 2] = s.charCodeAt(i) +
558
- (s.charCodeAt(i + 1) << 8) +
559
- (s.charCodeAt(i + 2) << 16) +
560
- (s.charCodeAt(i + 3) << 24);
561
- }
562
- return md5blks;
563
- }
564
- var hex_chr = '0123456789abcdef'.split('');
565
- function rhex(n) {
566
- var s = '',
567
- j = 0;
568
- for (; j < 4; j++)
569
- s += hex_chr[(n >> (j * 8 + 4)) & 0x0F] +
570
- hex_chr[(n >> (j * 8)) & 0x0F];
571
- return s;
572
- }
573
- function hex(x) {
574
- for (var i = 0; i < x.length; i++)
575
- x[i] = rhex(x[i]);
576
- return x.join('');
577
- }
578
- function md5(s) {
579
- return hex(md51(s));
580
- }
581
- /* this function is much faster,
582
- so if possible we use it. Some IEs
583
- are the only ones I know of that
584
- need the idiotic second function,
585
- generated by an if clause. */
586
- function add32(a, b) {
587
- return (a + b) & 0xFFFFFFFF;
588
- }
589
- if (md5('hello') != '5d41402abc4b2a76b9719d911017c592') {
590
- function add32(x, y) {
591
- var lsw = (x & 0xFFFF) + (y & 0xFFFF),
592
- msw = (x >> 16) + (y >> 16) + (lsw >> 16);
593
- return (msw << 16) | (lsw & 0xFFFF);
594
- }
595
- }
596
-
597
-
598
- String.prototype.tabIndex = function () {
599
- return this.replace (/^\D+/g, '')
600
- };
601
-
602
- String.prototype.replaceAll = function(search, replacement) {
603
- var target = this;
604
- return target.split(search).join(replacement);
605
- };
606
-
607
- var ai_nonce = b64d (jQuery ("#ai-form").attr ('ai-value'));
608
- var ai_settings = b64d (jQuery ("#ai-form").attr ('ai-settings'));
609
- var ai_write = jQuery ("#ai-form").hasClass ('ai-write');
610
-
611
- var shSettings = {
612
- "tab_size":"4",
613
- "use_soft_tabs":"1",
614
- "word_wrap":"1",
615
- "highlight_curr_line":"0",
616
- "key_bindings":"default",
617
- "full_line_selection":"1",
618
- "show_line_numbers":"0"};
619
-
620
-
621
- function encode_code (block) {
622
- // copy code back to textarea and encode block code
623
-
624
- if (!save_enabled) return false;
625
-
626
- var textarea = jQuery ('#block-' + block);
627
- var textarea_name = textarea.attr ('name');
628
-
629
- if (typeof textarea_name !== typeof undefined && textarea_name !== false) {
630
- var editor_element = jQuery ("#editor-" + block);
631
-
632
- // Copy code from editor only if it exists (tab has been configured)
633
- if (editor_element.length != 0 && typeof editor_element !== typeof undefined && editor_element !== false) {
634
- var editor = ace.edit ("editor-" + block);
635
- var session = editor.getSession();
636
-
637
- var editor_disabled = true;
638
- if (typeof ace != 'undefined') {
639
- editor_disabled = jQuery("#simple-editor-" + block).is(":checked");
640
- }
641
- if (!editor_disabled) {
642
- textarea.val (session.getValue());
643
- }
644
-
645
- }
646
-
647
- var default_value = textarea.attr ("default");
648
- var current_value = textarea.val ();
649
- var name = textarea.attr ("name");
650
-
651
- if (typeof name != 'undefined') {
652
- if (typeof default_value != 'undefined') {
653
- // console.log (textarea.attr ("name"), ": default_value: ", default_value, ", current_value: ", current_value);
654
-
655
- if (current_value == default_value) {
656
- textarea.removeAttr ("name");
657
- // console.log ("REMOVED: ", name);
658
- }
659
- }
660
- // else console.log ("NO DEFAULT VALUE: ", textarea.attr ("name"));
661
- }
662
-
663
- var copy_id = textarea.attr ('id') + '-copy';
664
- jQuery ('#' + copy_id).remove ();
665
-
666
- var org_name = textarea.attr ('org-name');
667
- if (typeof org_name !== typeof undefined && org_name !== false) {
668
- textarea.attr ("name", org_name);
669
- } else textarea.attr ("org-name", textarea_name);
670
-
671
- var textarea_copy = textarea.clone ().attr ('id', copy_id).hide ();
672
- textarea.removeAttr ("name");
673
- textarea_copy.val (':AI:' + b64e (textarea.val ()));
674
- textarea.after (textarea_copy);
675
-
676
- // console.log (':AI:', block);
677
- }
678
-
679
- jQuery("#ai-active-tab").attr ("value", '[' + active_tab + ',' + active_tab_0 + ']');
680
-
681
- var named_parameters = jQuery("#tab-" + block + ' [name]');
682
- var block_parameters = new Array();
683
- named_parameters.each (function() {
684
- block_parameters.push (jQuery (this).attr ('name'));
685
- });
686
- jQuery("#block-parameters-" + block).attr ('name', 'block-parameters-' + block).attr ('value', b64e (JSON.stringify (block_parameters)));
687
- };
688
-
689
- function SyntaxHighlight (id, block, settings) {
690
- var textarea, editor, form, session, editDiv;
691
-
692
- settings ['tab_size'] = 2;
693
-
694
- this.textarea = textarea = jQuery(id);
695
- this.settings = settings || {};
696
-
697
- if (textarea.length === 0 ) { // Element does not exist
698
- this.valid = false;
699
- return;
700
- }
701
-
702
- this.valid = true;
703
- editDiv = jQuery('<div>', {
704
- position: 'absolute',
705
- 'class': textarea.attr('class'),
706
- 'id': 'editor-' + block
707
- }).insertBefore (textarea);
708
-
709
- textarea.css('display', 'none');
710
- this.editor = editor = ace.edit(editDiv[0]);
711
- this.form = form = textarea.closest('form');
712
- this.session = session = editor.getSession();
713
-
714
- editor.$blockScrolling = Infinity;
715
-
716
- session.setValue(textarea.val());
717
-
718
- session.setMode ("ace/mode/ai-html");
719
-
720
- this.applySettings();
721
- }
722
-
723
- SyntaxHighlight.prototype.applySettings = function () {
724
- var editor = this.editor,
725
- session = this.session,
726
- settings = this.settings;
727
-
728
- editor.renderer.setShowGutter(settings['show_line_numbers'] == 1);
729
- editor.setHighlightActiveLine(settings['highlight_curr_line'] == 1);
730
- editor.setSelectionStyle(settings['full_line_selection'] == 1 ? "line" : "text");
731
- editor.setTheme("ace/theme/" + settings['theme']);
732
- session.setUseWrapMode(settings['word_wrap'] == 1);
733
- session.setTabSize(settings['tab_size']);
734
- session.setUseSoftTabs(settings['use_soft_tabs'] == 1);
735
- };
736
-
737
- function is_sticky (custom_css) {
738
- custom_css = custom_css.replace (/\s+/g, '');
739
-
740
- if (custom_css.indexOf ("position:fixed") != - 1 && custom_css.indexOf ("z-index:") != - 1) return true;
741
-
742
- return false;
743
- }
744
-
745
- function is_background (custom_css) {
746
- custom_css = custom_css.replace (/\s+/g, '');
747
-
748
- if (custom_css.indexOf ("top:0px;left:0px;width:100%;height:100%;") != - 1) return true;
749
-
750
- return false;
751
- }
752
-
753
- function change_block_alignment (block) {
754
- jQuery ("select#block-alignment-" + block).change ();
755
- jQuery ("select#horizontal-position-" + block).change ();
756
- jQuery ("select#vertical-position-" + block).change ();
757
- jQuery ("input#background-" + block).change ();
758
- // jQuery ("input#bkg-color-" + block).colorpicker ('setValue', jQuery ("input#bkg-color-" + block).attr ('value'));
759
- jQuery ("input#bkg-color-" + block).colorpicker ('setValue', jQuery ("input#bkg-color-" + block).val ());
760
- jQuery ("select#bkg-repeat-" + block).change ();
761
- jQuery ("select#bkg-size-" + block).change ();
762
- }
763
-
764
- function change_banner_image (block) {
765
- jQuery ("input#banner-image-url-" + block).trigger ("input");
766
- }
767
-
768
- function ai_css_value_px (css, property) {
769
- var found = false;
770
-
771
- styles = css.split (';');
772
- styles.forEach (function (style, index) {
773
- style = style.trim ();
774
- if (style.indexOf (property) == 0) {
775
- style_parts = style.split (':');
776
- if (style_parts.length == 2) {
777
- style_property = style_parts [0].trim ();
778
- style_value = style_parts [1].trim ();
779
- if (style_property == property && style_value.endsWith ('px')) found = true;
780
- }
781
- }
782
- });
783
-
784
- return found;
785
- }
786
-
787
- function ai_change_css (css, property, value) {
788
- var replaced = false;
789
- styles = css.split (';');
790
- styles.forEach (function (style, index) {
791
- org_style = style;
792
- style = style.trim ();
793
- if (style.indexOf (property) == 0) {
794
- style_parts = style.split (':');
795
- if (style_parts.length == 2) {
796
- style_property = style_parts [0].trim ();
797
- style_value = style_parts [1].trim ();
798
- if (style_property == property && style_value.endsWith ('px')) {
799
- var org_style_parts = org_style.split (':');
800
- styles [index] = org_style_parts [0] + ': ' + value + 'px';
801
- replaced = true;
802
- }
803
- }
804
- }
805
- });
806
-
807
- var new_style = styles.join (';');
808
-
809
- if (!replaced) {
810
- new_style = new_style.trim ();
811
- if (new_style.length != 0 && new_style.slice (-1) == ';') new_style = new_style.substring (0, new_style.length - 1);
812
- return new_style + '; ' + property + ': ' + value + ';';
813
- }
814
-
815
- return new_style;
816
- }
817
-
818
- function update_sticky_margins (style, horizontal_margin, vertical_margin) {
819
- if (vertical_margin !== '') {
820
- if (ai_css_value_px (style, 'top')) style = ai_change_css (style, 'top', vertical_margin); else
821
- if (ai_css_value_px (style, 'bottom')) style = ai_change_css (style, 'bottom', vertical_margin);
822
- }
823
-
824
- if (horizontal_margin !== '') {
825
- if (ai_css_value_px (style, 'left')) style = ai_change_css (style, 'left', horizontal_margin); else
826
- if (ai_css_value_px (style, 'right')) style = ai_change_css (style, 'right', horizontal_margin); else
827
- if (ai_css_value_px (style, 'margin-left')) style = ai_change_css (style, 'margin-left', horizontal_margin); else
828
- if (ai_css_value_px (style, 'margin-right')) style = ai_change_css (style, 'margin-right', horizontal_margin);
829
- }
830
-
831
- return style;
832
- }
833
-
834
- (function ($) {
835
- $.widget("toggle.checkboxButton", {
836
- _create : function() {
837
- this._on(this.element, {
838
- "change" : function(event) {
839
- this.element.next ("label").find ('.checkbox-icon').toggleClass("on");
840
- }
841
- });
842
- }
843
- });
844
- }(jQuery));
845
-
846
-
847
- serialize_object = function (obj) {
848
- var str = [];
849
- for(var p in obj)
850
- if (obj.hasOwnProperty (p)) {
851
- str.push(encodeURIComponent (p) + "=" + encodeURIComponent (obj[p]));
852
- }
853
- return str.join ("&");
854
- }
855
-
856
- Number.isInteger = Number.isInteger || function (value) {
857
- return typeof value === "number" &&
858
- isFinite (value) &&
859
- Math.floor (value) === value;
860
- };
861
-
862
- function get_editor_text (block) {
863
- var editor_disabled = true;
864
- if (typeof ace != 'undefined') {
865
- var editor = ace.edit ("editor-" + block);
866
- editor_disabled = jQuery("#simple-editor-" + block).is(":checked");
867
- }
868
- if (!editor_disabled) return editor.getSession ().getValue();
869
- return jQuery ("#block-" + block).val ();
870
- }
871
-
872
- function set_editor_text (block, text) {
873
- var editor_disabled = true;
874
- if (typeof ace != 'undefined') {
875
- var editor = ace.edit ("editor-" + block);
876
- editor_disabled = jQuery("#simple-editor-" + block).is(":checked");
877
- }
878
- if (!editor_disabled)
879
- editor.getSession ().setValue(text); else
880
- jQuery ("#block-" + block).val (text);
881
-
882
- }
883
-
884
- function open_popup_window_post (url, windowoption, name, params) {
885
- var form = document.createElement("form");
886
- form.setAttribute("method", "post");
887
- form.setAttribute("action", url);
888
- form.setAttribute("target", name);
889
- for (var i in params) {
890
- if (params.hasOwnProperty(i)) {
891
- var input = document.createElement('input');
892
- input.type = 'hidden';
893
- input.name = i;
894
- input.value = encodeURI (params[i]);
895
- form.appendChild(input);
896
- }
897
- }
898
- document.body.appendChild(form);
899
- //note I am using a post.htm page since I did not want to make double request to the page
900
- //it might have some Page_Load call which might screw things up.
901
- // window.open ("post.htm", name, windowoption);
902
- window.open ("admin-ajax.php", name, windowoption);
903
- form.submit();
904
- document.body.removeChild(form);
905
- }
906
-
907
-
908
- function open_window_post (url, name, params) {
909
- var form = document.createElement("form");
910
- form.setAttribute("method", "post");
911
- form.setAttribute("action", url);
912
- form.setAttribute("target", name);
913
- for (var i in params) {
914
- if (params.hasOwnProperty(i)) {
915
- var input = document.createElement('input');
916
- input.type = 'hidden';
917
- input.name = i;
918
- input.value = encodeURI (params[i]);
919
- form.appendChild(input);
920
- }
921
- }
922
- document.body.appendChild(form);
923
- form.submit();
924
- document.body.removeChild(form);
925
- }
926
-
927
- function check_managing_slave () {
928
- if (jQuery(".ai-managing.ai-managing-slave").length) {
929
-
930
- jQuery.get (ajaxurl + '?action=ai_ajax_backend&managed=&ai_check=' + ai_nonce, function (data) {
931
- if (data != '') {
932
- setTimeout (function () {
933
- check_managing_slave ();
934
- }, 30 * 1000);
935
- } else jQuery(".ai-managing.ai-managing-slave").hide ();
936
- });
937
- }
938
- }
939
-
940
-
941
- jQuery(document).ready (function($) {
942
-
943
- var header = $('#export-container'+'-0').length != 0;
944
-
945
- if (header) {
946
- $.elycharts.templates['ai'] = {
947
- type : "line",
948
- margins : [10, 38, 20, 38],
949
- defaultSeries : {
950
- fill: true,
951
- fillProps: {
952
- opacity: .15
953
- },
954
- plotProps : {
955
- "stroke-width" : 1,
956
- },
957
- },
958
- series : {
959
- serie1 : {
960
- color : "#66f",
961
- rounded : 0.8,
962
- },
963
- serie2 : {
964
- color : "#888",
965
- axis : "r",
966
- fillProps: {
967
- opacity: .1
968
- },
969
- }
970
- },
971
- defaultAxis : {
972
- labels : true,
973
- min: 0,
974
- },
975
- features : {
976
- grid : {
977
- draw : true,
978
- forceBorder : true,
979
- ny: 5,
980
- ticks : {
981
- active : [true, true, true],
982
- size : [4, 0],
983
- props : {
984
- stroke: '#ccc',
985
- }
986
- }
987
- },
988
- },
989
- interactive: false
990
- }
991
-
992
- $.elycharts.templates['ai-clicks'] = {
993
- template: 'ai',
994
- series : {
995
- serie1 : {
996
- color : "#0a0",
997
- fillProps: {
998
- opacity: .2
999
- },
1000
- },
1001
- serie2 : {
1002
- color : "#888",
1003
- }
1004
- },
1005
- }
1006
-
1007
- $.elycharts.templates['ai-impressions'] = {
1008
- template: 'ai',
1009
- series : {
1010
- serie1 : {
1011
- color : "#66f",
1012
- },
1013
- serie2 : {
1014
- color : "#888",
1015
- }
1016
- },
1017
- }
1018
-
1019
- $.elycharts.templates['ai-ctr'] = {
1020
- template: 'ai',
1021
- series : {
1022
- serie1 : {
1023
- color : "#e22",
1024
- },
1025
- serie2 : {
1026
- color : "#888",
1027
- }
1028
- },
1029
- }
1030
-
1031
- $.elycharts.templates['ai-versions'] = {
1032
- type : "line",
1033
- margins : [10, 38, 20, 38],
1034
- defaultSeries: {
1035
- color: "#0a0",
1036
- fillProps: {
1037
- opacity: .2
1038
- },
1039
- plotProps : {
1040
- "stroke-width" : 2,
1041
- },
1042
- tooltip : {
1043
- frameProps : {
1044
- opacity : 0.8
1045
- }
1046
- },
1047
- rounded : 0.8,
1048
- },
1049
- series: {
1050
- serie1: {
1051
- color : "#aaa",
1052
- axis : "l",
1053
- },
1054
- serie2 : {
1055
- color : "#0a0",
1056
- axis : "r",
1057
- },
1058
- serie3 : {
1059
- color: "#33f",
1060
- },
1061
- serie4 : {
1062
- color : "#e22",
1063
- },
1064
- serie5 : {
1065
- color : "#e2f",
1066
- },
1067
- serie6 : {
1068
- color : "#ec6400",
1069
- },
1070
- serie7 : {
1071
- color : "#00a3b5",
1072
- },
1073
- serie8 : {
1074
- color : "#7000ff",
1075
- },
1076
- serie9 : {
1077
- color : "#000",
1078
- },
1079
- serie10 : {
1080
- color : "#000", // Used also for BLOCKED
1081
- },
1082
- },
1083
- defaultAxis : {
1084
- labels : true,
1085
- min: 0,
1086
- },
1087
- features : {
1088
- grid: {
1089
- draw: true,
1090
- forceBorder : true,
1091
- ny: 5,
1092
- ticks : {
1093
- active : [true, true, true],
1094
- size : [4, 0],
1095
- props : {
1096
- stroke: '#ccc',
1097
- }
1098
- }
1099
- },
1100
- },
1101
- interactive: true,
1102
- }
1103
-
1104
- $.elycharts.templates['ai-versions-legend'] = {
1105
- template: 'ai-versions',
1106
- margins : [10, 38, 10, 38],
1107
- defaultSeries : {
1108
- fill: true,
1109
- fillProps: {
1110
- opacity: 0
1111
- },
1112
- plotProps : {
1113
- "stroke-width" : 0,
1114
- },
1115
- },
1116
- defaultAxis : {
1117
- labels : false,
1118
- },
1119
- features: {
1120
- grid: {
1121
- draw: false,
1122
- props: {
1123
- stroke: "transparent",
1124
- },
1125
- ticks : {
1126
- active : false,
1127
- }
1128
- },
1129
- legend: {
1130
- horizontal : true,
1131
- x : 20, // X | auto, (auto solo per horizontal = true)
1132
- y : 0,
1133
- width : 540, // X | auto, (auto solo per horizontal = true)
1134
- height : 20,
1135
- itemWidth : "auto", // fixed | auto, solo per horizontal = true
1136
- borderProps: { fill : "white", stroke: "black", "stroke-width": 0},
1137
- },
1138
- },
1139
- }
1140
-
1141
- $.elycharts.templates['ai-pie'] = {
1142
- template: 'ai-versions',
1143
- type: "pie",
1144
- rPerc: 100,
1145
- startAngle: 270,
1146
- clockwise: true,
1147
- margins : [0, 0, 0, 0],
1148
- defaultSeries : {
1149
- tooltip: {
1150
- height: 55,
1151
- width: 120,
1152
- padding: [5, 5],
1153
- offset: [-15, -10],
1154
- frameProps: {
1155
- opacity: 0.95,
1156
- /* fill: "white", */
1157
- stroke: "#000"
1158
-
1159
- }
1160
- },
1161
- plotProps : {
1162
- stroke : "white",
1163
- "stroke-width" : 0,
1164
- opacity : 1
1165
- },
1166
- values : [{
1167
- plotProps : {
1168
- fill : "#aaa"
1169
- }
1170
- }, {
1171
- plotProps : {
1172
- fill : "#0a0"
1173
- }
1174
- }, {
1175
- plotProps : {
1176
- fill : "#33f"
1177
- }
1178
- }, {
1179
- plotProps : {
1180
- fill : "#e22"
1181
- }
1182
- }, {
1183
- plotProps : {
1184
- fill : "#e2f"
1185
- }
1186
- }, {
1187
- plotProps : {
1188
- fill : "#ec6400"
1189
- }
1190
- }, {
1191
- plotProps : {
1192
- fill : "#00a3b5"
1193
- }
1194
- }, {
1195
- plotProps : {
1196
- fill : "#7000ff"
1197
- }
1198
- }, {
1199
- plotProps : {
1200
- fill : "#000"
1201
- }
1202
- }, {
1203
- plotProps : {
1204
- fill : "#000" // Used also for BLOCKED
1205
- }
1206
- }]
1207
- }
1208
- }
1209
-
1210
- $.elycharts.templates['ai-bar'] = {
1211
- template: 'ai-pie',
1212
- type: "line",
1213
- margins : [5, 0, 5, 45],
1214
- barMargins : 1,
1215
- defaultSeries : {
1216
- type: "bar",
1217
- axis: "l",
1218
- tooltip: {
1219
- height: 38,
1220
- }
1221
- },
1222
- features: {
1223
- grid: {
1224
- draw: [false, false],
1225
- props : {stroke: '#e0e0e0', "stroke-width": 0},
1226
- ticks : {
1227
- props : {stroke: '#e0e0e0', "stroke-width": 0},
1228
- }
1229
- },
1230
- },
1231
- }
1232
-
1233
- }
1234
-
1235
-
1236
- shSettings ['theme'] = $('#ai-data').attr ('theme');
1237
-
1238
- var geo_groups = 0;
1239
- var geo_groups_text = $('#ai-data-2').attr ('geo_groups');
1240
- if (typeof geo_groups_text != 'undefined') {
1241
- geo_groups = parseInt (geo_groups_text);
1242
- }
1243
-
1244
- debug = parseInt ($('#ai-data').attr ('js_debugging'));
1245
- ai_tab_setup_delay = parseInt ($('#ai-data').attr ('tab-setup-delay'));
1246
-
1247
- api_string = $('#ai-data-2').attr ('api_string');
1248
- if (typeof api_string != 'undefined') {
1249
- api_debug = parseInt ($('#ai-data-2').attr ('api_debugging'));
1250
- if (api_debug < 0x22 && api_debug > 0x1e) api_debug = 0;
1251
- } else api_debug = 0;
1252
-
1253
- if (debug) {
1254
- var start_time = new Date().getTime();
1255
- var last_time = start_time;
1256
- debug_title = true;
1257
- }
1258
-
1259
- // if (api_debug) {
1260
- // console.log ('api_debug ON:', api_debug);
1261
- // }
1262
-
1263
- syntax_highlighting = typeof shSettings ['theme'] != 'undefined' && shSettings ['theme'] != 'disabled';
1264
-
1265
- var header_id = 'name';
1266
- // var preview_top = (screen.height / 2) - (820 / 2);
1267
-
1268
- function remove_default_values (block) {
1269
-
1270
- if ($('.'+'system'+'-'+'status').length) {
1271
-
1272
- $("#tab-" + block + " input:checkbox").each (function() {
1273
- if (typeof $(this).attr ("style") != 'undefined' && $(this).attr ("style").includes ("animation-name")) {
1274
- $(this).removeAttr ("name");
1275
- // console.log ("REMOVED: ", $(this).removeAttr ("name"));
1276
- }
1277
- });
1278
-
1279
- $("#tab-" + block + " input:text").each (function() {
1280
- if (typeof $(this).attr ("style") != 'undefined' && $(this).attr ("style").includes ("animation-name")) {
1281
- $(this).removeAttr ("name");
1282
- // console.log ("REMOVED: ", $(this).removeAttr ("name"));
1283
- }
1284
- });
1285
- }
1286
-
1287
- var t1 = $('.'+'system'+'-'+'stats .ai' + '-stat-' + '1').length;
1288
-
1289
- if (!api_debug || t1) {
1290
- // console.log ('remove_default_values', block);
1291
-
1292
- $("#tab-" + block + " input:checkbox").each (function() {
1293
- var default_value = $(this).attr ("default");
1294
- var current_value = $(this).is (':checked');
1295
- var name = $(this).attr ("name");
1296
-
1297
- if (typeof name != 'undefined') {
1298
- if (typeof default_value != 'undefined') {
1299
- default_value = Boolean (parseInt (default_value));
1300
- // console.log ($(this).attr ("name"), ": default_value: ", $(this).attr ("default"), " = ", default_value, ", current_value: ", current_value);
1301
-
1302
- if (current_value == default_value) {
1303
- $(this).removeAttr ("name");
1304
- $("#tab-" + block + " [name='" + name + "']").removeAttr ("name");
1305
- // console.log ("REMOVED: ", name);
1306
- }
1307
- }
1308
- // else console.log ("NO DEFAULT VALUE:", $(this).attr ("name"));
1309
-
1310
- }
1311
- });
1312
-
1313
- $("#tab-" + block + " input:text").each (function() {
1314
- var default_value = $(this).attr ("default");
1315
- var current_value = $(this).val ();
1316
- var name = $(this).attr ("name");
1317
-
1318
- if (typeof name != 'undefined') {
1319
- if (typeof default_value != 'undefined') {
1320
- // console.log ($(this).attr ("name"), ": default_value: ", default_value, ", current_value: ", current_value);
1321
-
1322
- if (current_value == default_value) {
1323
- $(this).removeAttr ("name");
1324
- // console.log ("REMOVED: ", name);
1325
- }
1326
- }
1327
- // else console.log ("NO DEFAULT VALUE: ", $(this).attr ("name"));
1328
- }
1329
- });
1330
-
1331
- $("#tab-" + block + " select").each (function() {
1332
- var default_value = $(this).attr ("default");
1333
- var current_value = $(this).val();
1334
- var name = $(this).attr ("name");
1335
-
1336
- if (typeof name != 'undefined') {
1337
- // console.log ($(this).attr ("id"), name, default_value, current_value);
1338
-
1339
- // to do: children of OPTGROUP
1340
- var childern = $(this).children ();
1341
- if (childern.prop ("tagName") == "OPTGROUP") {
1342
- var current_value = "";
1343
- childern.each (function() {
1344
- var selected = $(this).val();
1345
- if (selected.length != 0) {
1346
- current_value = selected;
1347
- return false;
1348
- }
1349
- });
1350
- }
1351
-
1352
- // if ($(this).attr ("selected-value") == 1) current_value = current_value.attr("value");
1353
-
1354
- if (typeof default_value != 'undefined') {
1355
- // console.log ($(this).attr ("name"), ": default_value: ", default_value, " current_value: ", current_value);
1356
-
1357
- if (current_value == default_value) {
1358
- $(this).removeAttr ("name");
1359
- // console.log ("REMOVED: ", name);
1360
- }
1361
- }
1362
- // else console.log ("NO DEFAULT VALUE: ", $(this).attr ("name"));
1363
- }
1364
- });
1365
-
1366
- $("#tab-" + block + " input:radio:checked").each (function() {
1367
- var default_value = $(this).attr ("default");
1368
- var current_value = $(this).is (':checked');
1369
- var name = $(this).attr ("name");
1370
-
1371
- if (typeof name != 'undefined') {
1372
- if (typeof default_value != 'undefined') {
1373
- default_value = Boolean (parseInt (default_value));
1374
- // console.log ($(this).attr ("name"), ": default_value: ", $(this).attr ("default"), " = ", default_value, ", current_value: ", current_value);
1375
-
1376
- if (current_value == default_value) {
1377
- $("#tab-" + block + " [name='" + name + "']").removeAttr ("name");
1378
- // console.log ("REMOVED: ", name);
1379
- }
1380
- }
1381
- // else console.log ("NO DEFAULT VALUE: ", $(this).attr ("name"));
1382
- }
1383
- });
1384
-
1385
- // else console.log ("NO DEFAULT API VALUE:", api_string);
1386
- }
1387
-
1388
- if (block == 0) {
1389
- var name = 'lic'+'ense'+'_'+'key';
1390
- var val = $("#tab-" + block + ' [name='+name+']');
1391
- if (typeof val != 'undefined' && val.length != 0) {
1392
- if (val.val ().length != 0 && (val.val ().length < 31 || val.val ().length > 33)) {
1393
- $('#tab-0 [name='+name+']').removeAttr ("name");
1394
- }
1395
- }
1396
- }
1397
-
1398
- }
1399
-
1400
- function configure_editor_language (block) {
1401
-
1402
- var editor = ace.edit ("editor-" + block);
1403
-
1404
- if ($("input#process-php-"+block).is(":checked")) {
1405
- editor.getSession ().setMode ("ace/mode/ai-php");
1406
- } else editor.getSession ().setMode ("ace/mode/ai-html");
1407
- }
1408
-
1409
- function disable_auto_refresh_statistics () {
1410
- $('span.icon-auto-refresh').each (function() {
1411
- $(this).removeClass ('on');
1412
- });
1413
- }
1414
-
1415
- function reload_statistics (block) {
1416
- if ($("input#auto-refresh-"+block).next ().find ('.checkbox-icon').hasClass ('on')) {
1417
- $("input#load-custom-range-"+block).click ();
1418
- setTimeout (function() {reload_statistics (block);}, 60 * 1000);
1419
- }
1420
- }
1421
-
1422
- function ai_get_time (time_string) {
1423
- if (time_string.includes (':')) {
1424
- var time_parts = time_string.split (':');
1425
- return ((parseInt (time_parts [0]) * 3600 + parseInt (time_parts [1]) * 60 + parseInt (time_parts [2])) * 1000);
1426
- }
1427
-
1428
- return null;
1429
- }
1430
-
1431
- function ai_get_date (date_element) {
1432
- var date;
1433
- try {
1434
- date = $.datepicker.parseDate (dateFormat, date_element.val ());
1435
- } catch (error) {
1436
- date = null;
1437
- }
1438
-
1439
- return date;
1440
- }
1441
-
1442
- function ai_get_date_time (date_element, time_element) {
1443
- var date;
1444
- try {
1445
- date = Date.parse (date_element.val () + ' ' + time_element.val ());
1446
- if (isNaN (date)) date = null;
1447
- } catch (error) {
1448
- date = null;
1449
- }
1450
-
1451
- return date;
1452
- }
1453
-
1454
- function process_scheduling_dates (block) {
1455
- var gmt = parseInt ($('#ai-form').attr ('gmt'));
1456
- var start_date_picker = $("#scheduling-date-on-"+block);
1457
- var end_date_picker = $("#scheduling-date-off-"+block);
1458
- var start_time_picker = $("#scheduling-time-on-"+block);
1459
- var end_time_picker = $("#scheduling-time-off-"+block);
1460
- var scheduling = $("select#scheduling-"+block).val();
1461
-
1462
- var start_date_string = start_date_picker.val ().trim ();
1463
- var end_date_string = end_date_picker.val ().trim ();
1464
- var time_only = false;
1465
-
1466
- if (start_date_string == '' && end_date_string == '') {
1467
- var start_time = ai_get_time (start_time_picker.val ().trim ());
1468
- var end_time = ai_get_time (end_time_picker.val ().trim ());
1469
- time_only = true;
1470
- } else {
1471
- var start_time = ai_get_date_time (start_date_picker, start_time_picker) + gmt;
1472
- var end_time = ai_get_date_time (end_date_picker, end_time_picker) + gmt;
1473
- }
1474
-
1475
- end_date_picker.attr ('title', '');
1476
- end_date_picker.css ("border-color", "#ddd");
1477
- end_time_picker.attr ('title', '');
1478
- end_time_picker.css ("border-color", "#ddd");
1479
-
1480
- if (start_time == null && end_time != null) {
1481
- end_date_picker.attr ('title', '');
1482
- end_time_picker.attr ('title', '');
1483
- } else
1484
- if (end_time == null && start_time != null) {
1485
- end_date_picker.attr ('title', '');
1486
- end_time_picker.attr ('title', '');
1487
- } else
1488
- if (end_time > start_time) {
1489
- if (scheduling == "2") {
1490
- var current_time = new Date ().getTime () + gmt;
1491
-
1492
- if (time_only) {
1493
- var date = new Date (current_time);
1494
- var current_time_date_only = new Date (date.getFullYear (), date.getMonth (), date.getDate ()).getTime () + gmt;
1495
-
1496
- current_time -= current_time_date_only;
1497
-
1498
- if (current_time < 0) {
1499
- current_time += 24 * 3600 * 1000;
1500
- }
1501
- }
1502
-
1503
- if (end_time <= current_time) {
1504
- var expiration = Math.floor ((current_time - end_time) / 1000 / 3600 / 24);
1505
- end_date_picker.attr ('title', ai_admin.insertion_expired);
1506
- end_date_picker.css ("border-color", "#d00");
1507
- end_time_picker.attr ('title', ai_admin.insertion_expired);
1508
- end_time_picker.css ("border-color", "#d00");
1509
- } else {
1510
- if (time_only) {
1511
- var duration = (end_time - start_time) / 1000;
1512
-
1513
- var hours = Math.floor (duration / 3600);
1514
- var duration = duration - hours * 3600;
1515
-
1516
- var minutes = Math.floor (duration / 60);
1517
- var duration = duration - minutes * 60;
1518
-
1519
- var seconds = duration;
1520
-
1521
- var title = ' ' + ai_admin.duration + ': ' + ('0' + hours).slice (-2)+':'+('0' + minutes).slice (-2)+':'+('0' + seconds).slice (-2);
1522
- } else {
1523
- var duration = Math.floor ((end_time - start_time) / 1000 / 3600 / 24);
1524
- var title = ' ' + ai_admin.duration + ': ' + duration + ' ';
1525
- switch (duration) {
1526
- case 0:
1527
- title = title + ai_admin.days_0;
1528
- break;
1529
- case 1:
1530
- title = title + ai_admin.days_1;
1531
- break;
1532
- case 2:
1533
- title = title + ai_admin.days_2;
1534
- break;
1535
- case 3:
1536
- title = title + ai_admin.days_3;
1537
- break;
1538
- case 4:
1539
- title = title + ai_admin.days_4;
1540
- break;
1541
- default:
1542
- title = title + ai_admin.days_5;
1543
- break;
1544
- }
1545
- }
1546
-
1547
- end_date_picker.attr ('title', title);
1548
- end_time_picker.attr ('title', title);
1549
- }
1550
- }
1551
- } else {
1552
- end_date_picker.attr ('title', ai_admin.invalid_end_date);
1553
- end_date_picker.css ("border-color", "#d00");
1554
- end_time_picker.attr ('title', ai_admin.invalid_end_date);
1555
- end_time_picker.css ("border-color", "#d00");
1556
- }
1557
-
1558
- end_date_picker
1559
- .tooltip({
1560
- track: true,
1561
- delay: 700,
1562
- showURL: false,
1563
- showBody: " | ",
1564
- fade: 250
1565
- });
1566
- end_time_picker
1567
- .tooltip({
1568
- track: true,
1569
- delay: 700,
1570
- showURL: false,
1571
- showBody: " | ",
1572
- fade: 250
1573
- });
1574
- }
1575
-
1576
- function process_chart_dates (block) {
1577
- var start_date_picker = $("input#chart-start-date-"+block);
1578
- var end_date_picker = $("input#chart-end-date-"+block);
1579
- var start_date = ai_get_date (start_date_picker);
1580
- var end_date = ai_get_date (end_date_picker);
1581
-
1582
- start_date_picker.attr ('title', '');
1583
- start_date_picker.css ("border-color", "rgb(221, 221, 221)");
1584
- end_date_picker.attr ('title', '');
1585
- end_date_picker.css ("border-color", "rgb(221, 221, 221)");
1586
-
1587
- if (start_date == null) {
1588
- end_date_picker.attr ('title', '');
1589
- } else
1590
- if (end_date == null) {
1591
- end_date_picker.attr ('title', '');
1592
- } else
1593
- if (end_date >= start_date) {
1594
- var now = new Date();
1595
- var today_date = new Date (now.getFullYear(), now.getMonth(), now.getDate(), 0, 0, 0, 0);
1596
- if (today_date - start_date > 366 * 24 * 3600 * 1000) {
1597
- start_date_picker.attr ('title', ai_admin.invalid_start_date);
1598
- start_date_picker.css ("border-color", "#d00");
1599
- }
1600
- if (end_date - start_date > 366 * 24 * 3600 * 1000) {
1601
- end_date_picker.attr ('title', ai_admin.invalid_date_range);
1602
- end_date_picker.css ("border-color", "#d00");
1603
- }
1604
- } else {
1605
- end_date_picker.attr ('title', ai_admin.invalid_end_date);
1606
- end_date_picker.css ("border-color", "#d00");
1607
- }
1608
- }
1609
-
1610
- function process_display_elements (block) {
1611
-
1612
- $("#paragraph-settings-"+block).hide();
1613
- $("#paragraph-buttons-"+block).hide();
1614
- $("#image-settings-"+block).hide();
1615
-
1616
- var filter_attr = $("#filter-settings-"+block).attr ('data-filter');
1617
- var filter_settings_active = typeof filter_attr !== typeof undefined && filter_attr !== false;
1618
- $("#filter-settings-"+block).removeAttr ('data-filter').hide();
1619
- $("#filter-buttons-"+block).hide();
1620
-
1621
- $("#html-element-settings-"+block).hide();
1622
-
1623
- $("#inside-element-"+block).hide();
1624
-
1625
- var automatic_insertion = $("select#insertion-type-"+block+" option:selected").attr('value');
1626
-
1627
- if (automatic_insertion == AI_BEFORE_PARAGRAPH || automatic_insertion == AI_AFTER_PARAGRAPH) {
1628
- // $("#paragraph-text-"+block).text (ai_admin.paragraphs).show();
1629
- $("#paragraph-buttons-"+block).show();
1630
- $("#paragraph-settings-"+block+ ' input').attr('title', $("#paragraph-settings-"+block+ ' input').attr('data-title-paragraphs'))
1631
- .tooltip({
1632
- track: true,
1633
- delay: 700,
1634
- showURL: false,
1635
- showBody: " | ",
1636
- fade: 250
1637
- });
1638
- $("#paragraph-settings-"+block).show();
1639
- }
1640
- else if (automatic_insertion == AI_BEFORE_IMAGE || automatic_insertion == AI_AFTER_IMAGE) {
1641
- // $("#paragraph-text-"+block).text (ai_admin.images).show();
1642
- $("#paragraph-buttons-"+block).hide();
1643
- $("#paragraph-settings-"+block + ' input').attr('title', $("#paragraph-settings-"+block+ ' input').attr('data-title-images'))
1644
- .tooltip({
1645
- track: true,
1646
- delay: 700,
1647
- showURL: false,
1648
- showBody: " | ",
1649
- fade: 250
1650
- });
1651
- $("#paragraph-settings-"+block).show();
1652
- $("#paragraph-counting-"+block).hide();
1653
- $("#paragraph-clearance-"+block).hide();
1654
- }
1655
- else if (automatic_insertion == AI_BEFORE_EXCERPT || automatic_insertion == AI_AFTER_EXCERPT || automatic_insertion == AI_BETWEEN_POSTS || automatic_insertion == AI_BETWEEN_COMMENTS) {
1656
- $("#filter-buttons-"+block).show();
1657
- var filter_title = '';
1658
- if (automatic_insertion == AI_BEFORE_EXCERPT || automatic_insertion == AI_AFTER_EXCERPT) {
1659
- // $("#filter-text-"+block).text (ai_admin.excerpts).show();
1660
- filter_title = $("#filter-settings-"+block+ ' input').attr('data-title-excerpts');
1661
- }
1662
- else if (automatic_insertion == AI_BETWEEN_POSTS) {
1663
- // $("#filter-text-"+block).text (ai_admin.posts).show();
1664
- filter_title = $("#filter-settings-"+block+ ' input').attr('data-title-posts');
1665
- }
1666
- else if (automatic_insertion == AI_BETWEEN_COMMENTS) {
1667
- // $("#filter-text-"+block).text (ai_admin.comments).show();
1668
- filter_title = $("#filter-settings-"+block+ ' input').attr('data-title-comments');
1669
- }
1670
- $("#filter-settings-"+block + ' input').attr('title', filter_title)
1671
- .tooltip({
1672
- track: true,
1673
- delay: 700,
1674
- showURL: false,
1675
- showBody: " | ",
1676
- fade: 250
1677
- });
1678
- $("#filter-settings-"+block).attr ('data-filter', '1').show();
1679
- $("#paragraph-counting-"+block).hide();
1680
- $("#paragraph-clearance-"+block).hide();
1681
- }
1682
- else {
1683
- $("#paragraph-counting-"+block).hide();
1684
- $("#paragraph-clearance-"+block).hide();
1685
- }
1686
-
1687
- var new_filter_attr = $("#filter-settings-"+block).attr ('data-filter');
1688
- var new_filter_settings_active = typeof new_filter_attr !== typeof undefined && new_filter_attr !== false;
1689
-
1690
- if (filter_settings_active && !new_filter_settings_active) {
1691
- $("#filter-settings-"+block + ' input').val ('');
1692
-
1693
- $("input#filter-numbers-"+block).val ('');
1694
- $("select#filter-type-"+block).val (0);
1695
- $("input#invert-filter-"+block).removeAttr ('checked');
1696
- }
1697
-
1698
- if (automatic_insertion == AI_BEFORE_HTML_ELEMENT || automatic_insertion == AI_AFTER_HTML_ELEMENT || automatic_insertion == AI_INSIDE_HTML_ELEMENT) {
1699
- $("#html-element-settings-"+block).show();
1700
-
1701
- if (automatic_insertion == AI_INSIDE_HTML_ELEMENT) {
1702
- $("#inside-element-"+block).css ('display', 'table-cell');
1703
- }
1704
- }
1705
-
1706
- var content_settings = automatic_insertion == AI_BEFORE_PARAGRAPH || automatic_insertion == AI_AFTER_PARAGRAPH || automatic_insertion == AI_BEFORE_CONTENT || automatic_insertion == AI_AFTER_CONTENT;
1707
-
1708
- $("#css-label-"+block).css('display', 'table-cell');
1709
- $("#edit-css-button-"+block).css('display', 'table-cell');
1710
-
1711
- $("#css-none-"+block).hide();
1712
- $("#custom-css-"+block).hide();
1713
- $("#css-left-"+block).hide();
1714
- $("#css-right-"+block).hide();
1715
- $("#css-center-"+block).hide();
1716
- $("#css-float-left-"+block).hide();
1717
- $("#css-float-right-"+block).hide();
1718
- $("#css-sticky-left-"+block).hide();
1719
- $("#css-sticky-right-"+block).hide();
1720
- $("#css-sticky-top-"+block).hide();
1721
- $("#css-sticky-bottom-"+block).hide();
1722
- $("#css-sticky-"+block).hide();
1723
- $("#css-no-wrapping-"+block).hide();
1724
-
1725
- $("#no-wrapping-warning-"+block).hide();
1726
-
1727
- $("#sticky-position-"+block).hide();
1728
- $("#sticky-animation-"+block).hide();
1729
- $("#sticky-background-"+block).hide();
1730
- $("#sticky-background-"+block).find ('.bkg-parameters').hide();
1731
-
1732
- $('#tracking-wrapping-warning-' + block).hide ();
1733
-
1734
- var alignment = $("select#block-alignment-"+block+" option:selected").attr('value');
1735
-
1736
- if (alignment == AI_ALIGNMENT_NO_WRAPPING) {
1737
- $("#css-no-wrapping-"+block).css('display', 'table-cell');
1738
- $("#css-label-"+block).hide();
1739
- $("#edit-css-button-"+block).hide();
1740
- if ($("#client-side-detection-"+block).is(":checked")) {
1741
- $("#no-wrapping-warning-"+block).show();
1742
- }
1743
-
1744
- if ($('#tracking-' + block).next ().find ('.checkbox-icon').hasClass ('on')) {
1745
- $('#tracking-wrapping-warning-' + block).show ();
1746
- }
1747
- } else
1748
- if (alignment == AI_ALIGNMENT_DEFAULT) {
1749
- $("#css-none-"+block).css('display', 'table-cell');
1750
- } else
1751
- if (alignment == AI_ALIGNMENT_CUSTOM_CSS) {
1752
- $("#icons-css-code-" + block).show();
1753
- $("#custom-css-"+block).show();
1754
- configure_selection_icons (block);
1755
- if (is_sticky ($("#custom-css-"+block).val ())) {
1756
- $("#sticky-position-"+block).show();
1757
- $("#sticky-animation-"+block).show();
1758
- $("#sticky-background-"+block).show();
1759
- $("select#animation-"+block).change ();
1760
-
1761
- if (is_background ($("#custom-css-"+block).val ()) && $("input#background-"+block).is(":checked")) {
1762
- $("#sticky-background-"+block).find ('.bkg-parameters').show();
1763
- }
1764
- }
1765
- } else
1766
- if (alignment == AI_ALIGNMENT_LEFT) {
1767
- $("#css-left-"+block).css('display', 'table-cell');
1768
- } else
1769
- if (alignment == AI_ALIGNMENT_RIGHT) {
1770
- $("#css-right-"+block).css('display', 'table-cell');
1771
- } else
1772
- if (alignment == AI_ALIGNMENT_CENTER) {
1773
- $("#css-center-"+block).css('display', 'table-cell');
1774
- } else
1775
- if (alignment == AI_ALIGNMENT_FLOAT_LEFT) {
1776
- $("#css-float-left-"+block).css('display', 'table-cell');
1777
- } else
1778
- if (alignment == AI_ALIGNMENT_FLOAT_RIGHT) {
1779
- $("#css-float-right-"+block).css('display', 'table-cell');
1780
- } else
1781
- if (alignment == AI_ALIGNMENT_STICKY_LEFT) {
1782
- $("#css-sticky-left-"+block).css('display', 'table-cell');
1783
- } else
1784
- if (alignment == AI_ALIGNMENT_STICKY_RIGHT) {
1785
- $("#css-sticky-right-"+block).css('display', 'table-cell');
1786
- }
1787
- if (alignment == AI_ALIGNMENT_STICKY_TOP) {
1788
- $("#css-sticky-top-"+block).css('display', 'table-cell');
1789
- } else
1790
- if (alignment == AI_ALIGNMENT_STICKY_BOTTOM) {
1791
- $("#css-sticky-bottom-"+block).css('display', 'table-cell');
1792
- } else
1793
- if (alignment == AI_ALIGNMENT_STICKY) {
1794
- $("#icons-css-code-" + block).show();
1795
- $("#sticky-position-"+block).show();
1796
- $("#sticky-animation-"+block).show();
1797
- $("#sticky-background-"+block).show();
1798
- $("select#animation-"+block).change ();
1799
-
1800
- if ($("select#horizontal-position-"+block+" option:selected").attr('value') == AI_STICK_HORIZONTAL_CENTER && $("input#background-"+block).is(":checked")) {
1801
- $("#sticky-background-"+block).find ('.bkg-parameters').show();
1802
- }
1803
-
1804
- $("#css-sticky-"+block).css('display', 'table-cell');
1805
- configure_selection_icons (block);
1806
- }
1807
-
1808
-
1809
- if ($('#icons-css-code-'+block).css ('display') != 'none') {
1810
- // $("#show-css-button-"+block+" span").text (ai_admin.hide);
1811
- // $("#show-css-button-"+block).addClass ('light-blue');
1812
- } else {
1813
- // $("#show-css-button-"+block+" span").text (ai_admin.show);
1814
- // $("#show-css-button-"+block).removeClass ('light-blue');
1815
- }
1816
-
1817
- var avoid_action = $("select#avoid-action-"+block+" option:selected").text();
1818
-
1819
- if (avoid_action == "do not insert")
1820
- $("#check-up-to-"+block).hide (); else
1821
- $("#check-up-to-"+block).show ();
1822
-
1823
-
1824
- $("#scheduling-delay-"+block).hide();
1825
- $("#scheduling-between-dates-1-"+block).hide();
1826
- $("#scheduling-between-dates-2-"+block).hide();
1827
- $("#scheduling-delay-warning-"+block).hide();
1828
- var scheduling = $("select#scheduling-"+block).val();
1829
- if (scheduling == "1" || scheduling == "3") {
1830
- $("#scheduling-delay-"+block).show();
1831
- } else
1832
- if (scheduling == "2" || scheduling == "4" || scheduling == "5" || scheduling == "6") {
1833
- $("#scheduling-between-dates-1-"+block).show();
1834
- $("#scheduling-between-dates-2-"+block).show();
1835
- process_scheduling_dates (block);
1836
- }
1837
-
1838
- $("#adb-block-replacement-"+block).hide();
1839
- var adb_block_action = $("select#adb-block-action-"+block).val();
1840
- if (adb_block_action == AI_ADB_BLOCK_ACTION_REPLACE) {
1841
- $("#adb-block-replacement-"+block).show();
1842
- }
1843
-
1844
- if ($("#exceptions-enabled-" + block).is(":checked")) {
1845
- $("#default-insertion-"+block).show();
1846
- } else {
1847
- $("#default-insertion-"+block).hide();
1848
- }
1849
-
1850
- if (syntax_highlighting) configure_editor_language (block);
1851
-
1852
- check_insertion (block);
1853
- }
1854
-
1855
- function process_adsense_elements (block) {
1856
- var adsense_type = parseInt ($("select#adsense-type-" + block +" option:selected").attr ('value'));
1857
- var adsense_size = parseInt ($("select#adsense-size-" + block +" option:selected").attr ('value'));
1858
-
1859
- if ((adsense_type == AI_ADSENSE_STANDARD || adsense_type == AI_ADSENSE_LINK) && adsense_size == AI_ADSENSE_SIZE_FIXED_BY_VIEWPORT) {
1860
- $('#adsense-layout-' + block).hide ();
1861
- $('#adsense-viewports-' + block).show ();
1862
- } else {
1863
- $('#adsense-layout-' + block).show ();
1864
- $('#adsense-viewports-' + block).hide ();
1865
- }
1866
-
1867
- $('#tab-adsense-' + block + ' .adsense-layout').css ('visibility', 'hidden');
1868
- $('#tab-adsense-' + block + ' .adsense-fixed-size').show ();
1869
- $('#tab-adsense-' + block + ' .adsense-fixed-size').css ('visibility', 'hidden');
1870
- $('#tab-adsense-' + block + ' .adsense-size').css ('visibility', 'hidden');
1871
- $('#tab-adsense-' + block + ' .adsense-full-width-responsive').hide ();
1872
-
1873
- switch (adsense_type) {
1874
- case AI_ADSENSE_STANDARD:
1875
- $('#tab-adsense-' + block + ' .adsense-size').css ('visibility', 'visible');
1876
- if (adsense_size == AI_ADSENSE_SIZE_FIXED) $('#tab-adsense-' + block + ' .adsense-fixed-size').css ('visibility', 'visible');
1877
- if (adsense_size == AI_ADSENSE_SIZE_RESPONSIVE) {
1878
- $('#tab-adsense-' + block + ' .adsense-fixed-size').hide ();
1879
- $('#tab-adsense-' + block + ' .adsense-full-width-responsive').show ();
1880
- }
1881
- break;
1882
- case AI_ADSENSE_LINK:
1883
- $('#tab-adsense-' + block + ' .adsense-size').css ('visibility', 'visible');
1884
- if (adsense_size == AI_ADSENSE_SIZE_FIXED) $('#tab-adsense-' + block + ' .adsense-fixed-size').css ('visibility', 'visible');
1885
- if (adsense_size == AI_ADSENSE_SIZE_RESPONSIVE) {
1886
- $('#tab-adsense-' + block + ' .adsense-fixed-size').hide ();
1887
- $('#tab-adsense-' + block + ' .adsense-full-width-responsive').show ();
1888
- }
1889
- break;
1890
- case AI_ADSENSE_IN_ARTICLE:
1891
- break;
1892
- case AI_ADSENSE_IN_FEED:
1893
- $('#tab-adsense-' + block + ' .adsense-layout').css ('visibility', 'visible');
1894
- break;
1895
- case AI_ADSENSE_MATCHED_CONTENT:
1896
- break;
1897
- }
1898
- }
1899
-
1900
- function process_amazon_elements (block) {
1901
- $('#tab-amazon-' + block + ' .amazon-amp-data').hide ();
1902
- var amzon_amp = parseInt ($("select#amazon-amp-" + block +" option:selected").attr ('value'));
1903
-
1904
- if (amzon_amp == 1) {
1905
- $('#tab-amazon-' + block + ' .amazon-amp-data').show ();
1906
- }
1907
- }
1908
-
1909
- function switch_editor (block, editor_disabled) {
1910
- var editor = ace.edit ("editor-" + block);
1911
- var textarea = $("#block-" + block);
1912
- var ace_editor = $("#editor-" + block);
1913
-
1914
- if (editor_disabled) {
1915
- textarea.val (editor.session.getValue());
1916
- textarea.css ('display', 'block');
1917
- ace_editor.css ('display', 'none');
1918
- } else {
1919
- editor.session.setValue (textarea.val ())
1920
- editor.renderer.updateFull();
1921
- ace_editor.css ('display', 'block');
1922
- textarea.css ('display', 'none');
1923
- }
1924
- }
1925
-
1926
- function configure_editor (block) {
1927
-
1928
- if (debug) console.log ("configure_editor:", block);
1929
-
1930
- if (syntax_highlighting) {
1931
- var syntax_highlighter = new SyntaxHighlight ('#block-' + block, block, shSettings);
1932
- // syntax_highlighter.editor.setPrintMarginColumn (1000);
1933
- setTimeout (function() {syntax_highlighter.editor.setPrintMarginColumn (1000);}, 50);
1934
-
1935
- $('input#simple-editor-' + block).change (function () {
1936
-
1937
- var block = $(this).attr ("id").replace ("simple-editor-","");
1938
- var editor_disabled = $(this).is(":checked");
1939
-
1940
- switch_editor (block, editor_disabled);
1941
- });
1942
- }
1943
- }
1944
-
1945
- function configure_adb () {
1946
- $("#adb-message").hide();
1947
- $("#adb-page-redirection").hide();
1948
-
1949
- var adb_action = $("select#adb-action option:selected").attr('value');
1950
-
1951
- if (adb_action == AI_ADB_ACTION_MESSAGE) {
1952
- $("#adb-message").show();
1953
- } else
1954
- if (adb_action == AI_ADB_ACTION_REDIRECTION) {
1955
- $("#adb-page-redirection").show();
1956
- }
1957
- }
1958
-
1959
- function export_statistics_pdf (block) {
1960
- var code = $('<section>' + $("div#statistics-elements-" + block).html () + '</section>');
1961
-
1962
- $('div[style*="display: none"], div[style*="display:none"]', code).remove ();
1963
- $('.ai-toolbar-button', code).remove ();
1964
- $('.ai-chart-container', code).css ('font-size', '10px');
1965
- $('.ai-chart-container.versions', code).css ('text-align', 'center');
1966
- $('.ai-statistics-legend', code).after ($('.ai-chart-container.legend', code).html());
1967
-
1968
- var param = {'action': 'ai_ajax_backend', 'pdf': 'block', 'ai_check': ai_nonce, 'code': b64e ($(code).html ())};
1969
- $('#ai-loading').show ();
1970
- setTimeout (function() {open_window_post (ajaxurl, '_blank', param);}, 5);
1971
- setTimeout (function() {$('#ai-loading').hide ();}, 1000);
1972
- }
1973
-
1974
- function export_statistics_csv (block) {
1975
- $('#ai-loading').show ();
1976
- $("span#export-csv-button-"+block).addClass ('on');
1977
- setTimeout (function() {$("input#load-custom-range-"+block).click ();}, 5);
1978
- setTimeout (function() {$('#ai-loading').hide ();}, 1000);
1979
- }
1980
-
1981
- function configure_statistics_toolbar (tab) {
1982
- $("input#load-custom-range-"+tab).click (function () {
1983
- var block = $(this).attr ("id");
1984
- block = block.replace ("load-custom-range-","");
1985
-
1986
- var label = $(this).next ().find ('.checkbox-icon');
1987
- label.addClass ('on');
1988
-
1989
- // var nonce = $(this).attr ('nonce');
1990
- // var start_date = $("input#chart-start-date-" + block).attr('value');
1991
- var start_date = $("input#chart-start-date-" + block).val ();
1992
- // var end_date = $("input#chart-end-date-" + block).attr('value');
1993
- var end_date = $("input#chart-end-date-" + block).val ();
1994
- var container = $("div#statistics-elements-" + block);
1995
-
1996
- var version_charts_container = $("div#ai-version-charts-" + block);
1997
- var version_charts_container_visible = version_charts_container.is (':visible');
1998
-
1999
- var delete_range = '';
2000
- if ($("input#clear-range-"+block).hasClass ('delete')) {
2001
- delete_range = '&delete=1';
2002
- }
2003
-
2004
- var adb = '';
2005
- if ($("input#adb-statistics-button-"+block).next ().find ('.icon-adb').hasClass ('on')) {
2006
- adb = '&adb=1';
2007
- }
2008
-
2009
- if ($("span#export-csv-button-"+block).hasClass ('on')) {
2010
- $("span#export-csv-button-"+block).removeClass ('on');
2011
-
2012
- var params = {'action': 'ai_ajax_backend', 'statistics': block, 'start-date': start_date, 'end-date': end_date, 'delete_range': delete_range == '' ? '' : 1, 'adb': adb == '' ? '' : 1, 'csv' : 1, 'ai_check': ai_nonce};
2013
-
2014
- var form = document.createElement("form");
2015
- form.setAttribute("method", "get");
2016
- form.setAttribute("action", ajaxurl);
2017
- for (var i in params) {
2018
- if (params.hasOwnProperty(i)) {
2019
- var input = document.createElement('input');
2020
- input.type = 'hidden';
2021
- input.name = i;
2022
- input.value = encodeURI (params[i]);
2023
- form.appendChild(input);
2024
- }
2025
- }
2026
- document.body.appendChild (form);
2027
- form.submit();
2028
- document.body.removeChild (form);
2029
-
2030
- label.removeClass ('on');
2031
- return;
2032
- }
2033
-
2034
- container.load (ajaxurl+"?action=ai_ajax_backend&statistics=" + block + "&start-date=" + start_date + "&end-date=" + end_date + delete_range + adb + "&ai_check=" + ai_nonce, function (response, status, xhr) {
2035
- label.removeClass ('on');
2036
- if ( status == "error" ) {
2037
- var message = "Error downloading data: " + xhr.status + " " + xhr.statusText ;
2038
- $("div#load-error-" + block).html (message);
2039
- if (debug) console.log (message);
2040
- } else {
2041
- $("span#export-pdf-button-" + block).show ();
2042
- $("span#export-csv-button-" + block).show ();
2043
- var public_report_button = $("#ai-main-toolbar-" + block + ' .public-report-button');
2044
- public_report_button.show ();
2045
-
2046
- var urls = container.find ('span.ai-statistics-export-data.ai-public-report');
2047
- public_report_button.attr ('report-data', JSON.stringify (urls.data ('report')));
2048
-
2049
- urls.remove ();
2050
-
2051
- $( "div#load-error-" + block).html ('');
2052
- if (debug) console.log ("Custom statistics loaded: " + block);
2053
- configure_charts (container);
2054
-
2055
- container.find ("label.ai-version-charts-button.not-configured").click (function () {
2056
- var no_delay_version_charts = $(this).hasClass ('no-version-charts-delay');
2057
-
2058
- $(this).removeClass ('not-configured');
2059
- var version_charts_container = $(this).closest (".ai-charts").find ('div.ai-version-charts');
2060
- version_charts_container.toggle ();
2061
-
2062
- var not_configured_charts = version_charts_container.find ('.ai-chart.not-configured.hidden');
2063
- if (not_configured_charts.length) {
2064
- not_configured_charts.each (function() {
2065
- $(this).removeClass ('hidden');
2066
- });
2067
- if (no_delay_version_charts) {
2068
- configure_charts (version_charts_container);
2069
- } else setTimeout (function() {configure_charts (version_charts_container);}, 10);
2070
- }
2071
- });
2072
-
2073
- if (version_charts_container_visible) {
2074
- container.find ("label.ai-version-charts-button.not-configured").addClass ('no-version-charts-delay').click ();
2075
- }
2076
-
2077
- $("input#chart-start-date-"+block).css ('color', '#32373c');
2078
- $("input#chart-end-date-"+block).css ('color', '#32373c');
2079
- }
2080
- });
2081
- });
2082
-
2083
- $("input#auto-refresh-"+tab).click (function () {
2084
- var block = $(this).attr ("id");
2085
- block = block.replace ("auto-refresh-","");
2086
- var label = $(this).next ().find ('.checkbox-icon');
2087
- label.toggleClass ('on');
2088
- if (label.hasClass ('on')) {
2089
- reload_statistics (block);
2090
- }
2091
- });
2092
-
2093
- $("input#clear-range-"+tab).click (function () {
2094
- var block = $(this).attr ("id");
2095
- block = block.replace ("clear-range-","");
2096
-
2097
- var delete_button = this;
2098
- // var start_date = $("input#chart-start-date-" + block).attr('value');
2099
- var start_date = $("input#chart-start-date-" + block).val ();
2100
- // var end_date = $("input#chart-end-date-" + block).attr('value');
2101
- var end_date = $("input#chart-end-date-" + block).val ();
2102
-
2103
- var message = '';
2104
- if (start_date == '' && end_date == '')
2105
- var message = ai_admin.delete_all_statistics; else
2106
- if (start_date != '' && end_date != '') var message = ai_admin.delete_statistics_between.replace ('{start_date}', start_date).replace ('{end_date}', end_date);
2107
-
2108
- if (message != '')
2109
- $('<div />').html(message).attr ('title', ai_admin.warning).dialog({
2110
- bgiframe: true,
2111
- draggable: false,
2112
- resizable: false,
2113
- modal: true,
2114
- height: "auto",
2115
- width: 400,
2116
- position: {my: 'center', at: 'center', of: '#ai-settings'},
2117
- buttons: [{
2118
- text: ai_admin.delete,
2119
- click: function() {
2120
- $(this).dialog ("close");
2121
-
2122
- $(delete_button).addClass ('delete');
2123
- $("input#load-custom-range-"+block).click ();
2124
- $(delete_button).removeClass ('delete');
2125
- }
2126
- },{
2127
- text: ai_admin.cancel,
2128
- click: function() {
2129
- $(this).dialog ("close");
2130
- }
2131
- }
2132
- ],
2133
- open: function() {$(this).parent ().find ('button:nth-child(2)').focus();}
2134
- });
2135
- });
2136
-
2137
- $("input#chart-start-date-"+tab).datepicker ({dateFormat: dateFormat, autoSize: true});
2138
- $("input#chart-end-date-"+tab).datepicker ({dateFormat: dateFormat, autoSize: true});
2139
-
2140
- $("input#chart-start-date-"+tab).change (function() {
2141
- $(this).closest (".custom-range-controls").find ('.data-range').removeClass ('selected');
2142
- var custom_range_controls = $(this).closest (".custom-range-controls");
2143
- custom_range_controls.attr ('range-name', '----');
2144
-
2145
- disable_auto_refresh_statistics ();
2146
- var block = $(this).attr('id').replace ("chart-start-date-", "");
2147
- $(this).css ('color', 'red');
2148
- process_chart_dates (block);
2149
- });
2150
-
2151
- $("input#chart-end-date-"+tab).change (function() {
2152
- $(this).closest (".custom-range-controls").find ('.data-range').removeClass ('selected');
2153
- var custom_range_controls = $(this).closest (".custom-range-controls");
2154
- custom_range_controls.attr ('range-name', '----');
2155
-
2156
- disable_auto_refresh_statistics ();
2157
- var block = $(this).attr('id').replace ("chart-end-date-", "");
2158
- $(this).css ('color', 'red');
2159
- process_chart_dates (block);
2160
- });
2161
-
2162
- $("div#custom-range-controls-"+tab+" span.data-range").click (function () {
2163
- var custom_range_controls = $(this).closest (".custom-range-controls");
2164
- custom_range_controls.find ('.data-range').removeClass ('selected');
2165
- $(this).addClass ('selected');
2166
- custom_range_controls.attr ('range-name', $(this).data ("range-name"));
2167
-
2168
- disable_auto_refresh_statistics ();
2169
- var id = $(this).closest (".custom-range-controls").attr ("id");
2170
- block = id.replace ("custom-range-controls-","");
2171
- // $("input#chart-start-date-"+block).attr ("value", $(this).data ("start-date"));
2172
- $("input#chart-start-date-"+block).attr ("value", $(this).data ("start-date")).val ($(this).data ("start-date"));
2173
- // $("input#chart-end-date-"+block).attr ("value", $(this).data ("end-date"));
2174
- $("input#chart-end-date-"+block).attr ("value", $(this).data ("end-date")).val ($(this).data ("end-date"));
2175
- process_chart_dates (block);
2176
- $("input#load-custom-range-"+block).click ();
2177
- });
2178
- }
2179
-
2180
- function configure_tab_0 () {
2181
-
2182
- if (debug) console.log ("Configure tab: 0");
2183
-
2184
- $('#tab-0').addClass ('configured');
2185
-
2186
- $('#tab-0 input[type=submit], #tab-0 button.ai-button').button().show ();
2187
-
2188
- configure_editor ('h');
2189
- configure_editor ('f');
2190
- if ($("#block-a").length)
2191
- configure_editor ('a');
2192
-
2193
- $('#ai-plugin-settings-tab-container').tabs();
2194
- $('#ai-plugin-settings-tabs').show();
2195
-
2196
- $("#export-switch-0").checkboxButton ().click (function () {
2197
- $("#export-container-0").toggle ();
2198
-
2199
- if ($("#export-container-0").is(':visible') && !$(this).hasClass ("loaded")) {
2200
- // var nonce = $(this).attr ('nonce');
2201
- $("#export_settings_0").load (ajaxurl+"?action=ai_ajax_backend&export=0&ai_check=" + ai_nonce, function (response, status, xhr) {
2202
- if (status == "error" ) {
2203
- $('#ai-error-container').text (ai_admin.error + ' ' + xhr.status + ': ' + xhr.statusText).show ();
2204
- } else {
2205
- $("#export_settings_0").attr ("name", "export_settings_0");
2206
- $("#export-switch-0").addClass ("loaded");
2207
- }
2208
-
2209
- });
2210
- }
2211
- });
2212
-
2213
- $("input#process-php-h").change (function() {
2214
- if (syntax_highlighting) configure_editor_language ('h');
2215
- });
2216
-
2217
- $("input#process-php-f").change (function() {
2218
- if (syntax_highlighting) configure_editor_language ('f')
2219
- });
2220
-
2221
- $("input#process-php-a").change (function() {
2222
- if (syntax_highlighting) configure_editor_language ('a')
2223
- });
2224
-
2225
- if (syntax_highlighting) configure_editor_language ('h');
2226
- if (syntax_highlighting) configure_editor_language ('f');
2227
- if ($("#block-a").length)
2228
- if (syntax_highlighting) configure_editor_language ('a');
2229
-
2230
- for (var index = 1; index <= geo_groups; index ++) {
2231
- create_list_selector ('group-country', index);
2232
- }
2233
-
2234
- $('#enable-header').checkboxButton ();
2235
- $('#enable-header-404').checkboxButton ();
2236
-
2237
- $('#simple-editor-h').checkboxButton ().click (function () {
2238
- var tab_id = $("#ai-plugin-settings-tab-container .ui-tabs-panel:visible").attr("id");
2239
- if (active_tab == 0 && tab_id == 'tab-header' && !$(this).hasClass ('clicked')) {
2240
- $(this).addClass ('clicked')
2241
- $('#ai-tab-container .simple-editor-button').click();
2242
- $(this).removeClass ('clicked')
2243
- }
2244
- });
2245
- // Switch to simple editor if the button was pressed before the tab was configured
2246
- if ($('#simple-editor-h').is(":checked")) {
2247
- switch_editor ('h', true);
2248
- $('#simple-editor-h').next ("label").find ('.checkbox-icon').addClass("on");
2249
- }
2250
-
2251
- $('#process-php-h').checkboxButton ();
2252
-
2253
- $('#enable-footer').checkboxButton ();
2254
- $('#enable-footer-404').checkboxButton ();
2255
-
2256
- $('#simple-editor-f').checkboxButton ().click (function () {
2257
- var tab_id = $("#ai-plugin-settings-tab-container .ui-tabs-panel:visible").attr("id");
2258
- if (active_tab == 0 && tab_id == 'tab-footer' && !$(this).hasClass ('clicked')) {
2259
- $(this).addClass ('clicked')
2260
- $('#ai-tab-container .simple-editor-button').click();
2261
- $(this).removeClass ('clicked')
2262
- }
2263
- });
2264
- // Switch to simple editor if the button was pressed before the tab was configured
2265
- if ($('#simple-editor-f').is(":checked")) {
2266
- switch_editor ('f', true);
2267
- $('#simple-editor-f').next ("label").find ('.checkbox-icon').addClass("on");
2268
- }
2269
-
2270
- $('#process-php-f').checkboxButton ();
2271
-
2272
- $('#tracking').checkboxButton ();
2273
-
2274
- configure_statistics_toolbar (0);
2275
-
2276
- $("input#statistics-button-0").checkboxButton ().click (function () {
2277
- $("div#statistics-container-0").toggle ();
2278
- $("span#export-pdf-button-0").toggle ();
2279
- $("span#export-csv-button-0").toggle ();
2280
- $("div#tab-tracking-settings").toggle ();
2281
- var container = $("div#statistics-container-0");
2282
- if (container.is(':visible')) {
2283
- if (!$(this).hasClass ('loaded')) {
2284
- $("input#load-custom-range-0").click ();
2285
- $(this).addClass ('loaded');
2286
- }
2287
- }
2288
- });
2289
-
2290
- $("#export-pdf-button-0").click (function () {
2291
- export_statistics_pdf (0);
2292
- });
2293
-
2294
- $("#export-csv-button-0").click (function () {
2295
- export_statistics_csv (0);
2296
- });
2297
-
2298
- $('#enable-adb-detection').checkboxButton ();
2299
-
2300
- $('#simple-editor-a').checkboxButton ().click (function () {
2301
- var tab_id = $("#ai-plugin-settings-tab-container .ui-tabs-panel:visible").attr("id");
2302
- if (active_tab == 0 && tab_id == 'tab-adblocking' && !$(this).hasClass ('clicked')) {
2303
- $(this).addClass ('clicked')
2304
- $('#ai-tab-container .simple-editor-button').click();
2305
- $(this).removeClass ('clicked')
2306
- }
2307
- });
2308
- // Switch to simple editor if the button was pressed before the tab was configured
2309
- if ($('#simple-editor-a').is(":checked")) {
2310
- switch_editor ('a', true);
2311
- $('#simple-editor-a').next ("label").find ('.checkbox-icon').addClass("on");
2312
- }
2313
-
2314
- $('#process-php-a').checkboxButton ();
2315
-
2316
-
2317
- configure_adb ();
2318
- $("select#adb-action").change (function() {
2319
- configure_adb ();
2320
- });
2321
-
2322
- $("#preview-button-adb").button ({
2323
- }).show ().click (function () {
2324
-
2325
- $(this).blur ();
2326
-
2327
- var code = b64e (get_editor_text ('a'));
2328
- var php = $("input#process-php-a").is(":checked") ? 1 : 0;
2329
-
2330
- var window_width = 820;
2331
- var window_height = 870;
2332
- var window_left = 100;
2333
- var window_top = (screen.height / 2) - (870 / 2);
2334
- // var nonce = $(this).attr ('nonce');
2335
- var param = {'action': 'ai_ajax_backend', 'preview': 'adb', 'ai_check': ai_nonce, 'code': code, 'php': php};
2336
- open_popup_window_post (ajaxurl, 'width='+window_width+',height='+window_height+',top='+window_top+',left='+window_left+',resizable=yes,scrollbars=yes,toolbar=no,location=no,directories=no,status=no,menubar=no', 'preview', param);
2337
- });
2338
-
2339
- $("#main-content-element-button").click (function () {
2340
- var selector = $("input#main-content-element").val ();
2341
- var home_url = $("#ai-settings").data ('home-relative-url');
2342
- var window_top = screen.availTop;
2343
- var window_left = screen.availLeft;
2344
- var window_width = screen.availWidth - 15;
2345
- var window_height = screen.availHeight - 65;
2346
-
2347
- var param = {
2348
- 'html_element_selection': 'main',
2349
- 'selector': selector,
2350
- 'input': "input#main-content-element"
2351
- };
2352
- open_popup_window_post (home_url, 'width='+window_width+',height='+window_height+',top='+window_top+',left='+window_left+',resizable=yes,scrollbars=yes,toolbar=no,location=no,directories=no,status=no,menubar=no', 'ai-selector', param);
2353
- });
2354
-
2355
- $("#custom-selectors-button").click (function () {
2356
- var selector = $("input#custom-selectors").val ();
2357
- var home_url = $("#ai-settings").data ('home-relative-url');
2358
- var window_top = screen.availTop;
2359
- var window_left = screen.availLeft;
2360
- var window_width = screen.availWidth - 15;
2361
- var window_height = screen.availHeight - 65;
2362
-
2363
- var param = {
2364
- 'html_element_selection': 'adb',
2365
- 'selector': selector,
2366
- 'input': "input#custom-selectors"
2367
- };
2368
- open_popup_window_post (home_url, 'width='+window_width+',height='+window_height+',top='+window_top+',left='+window_left+',resizable=yes,scrollbars=yes,toolbar=no,location=no,directories=no,status=no,menubar=no', 'ai-selector', param);
2369
- });
2370
-
2371
- $('#disable-header-code').checkboxButton ();
2372
- $('#disable-footer-code').checkboxButton ();
2373
- $('#disable-js-code').checkboxButton ();
2374
- $('#disable-css-code').checkboxButton ();
2375
- $('#disable-html-code').checkboxButton ();
2376
- $('#disable-php-processing').checkboxButton ();
2377
- $('#disable-blocks').checkboxButton ();
2378
-
2379
- $("input#disable-header-code").change (function() {
2380
- $('#ai-page-header').toggleClass ('ai-page-code-disabled');
2381
- });
2382
-
2383
- $("input#disable-footer-code").change (function() {
2384
- $('#ai-page-footer').toggleClass ('ai-page-code-disabled');
2385
- });
2386
-
2387
- $("input#disable-js-code").change (function() {
2388
- $('#ai-page-js').toggleClass ('ai-page-code-disabled');
2389
- });
2390
-
2391
- $("input#disable-css-code").change (function() {
2392
- $('#ai-page-css').toggleClass ('ai-page-code-disabled');
2393
- });
2394
-
2395
- $("input#disable-html-code").change (function() {
2396
- $('#ai-page-html').toggleClass ('ai-page-code-disabled');
2397
- });
2398
-
2399
- $("input#disable-php-processing").change (function() {
2400
- $('#ai-page-php').toggleClass ('ai-page-code-disabled');
2401
- });
2402
-
2403
- $("input#disable-blocks").change (function() {
2404
- $('#ai-page-block').toggleClass ('ai-page-code-disabled');
2405
- });
2406
-
2407
- $("#report-header-image-button").click (function (event) {
2408
- $(this).blur ();
2409
-
2410
- var frame;
2411
-
2412
- event.preventDefault();
2413
-
2414
- if (frame) {
2415
- frame.open();
2416
- return;
2417
- }
2418
-
2419
- frame = wp.media ({
2420
- title: ai_admin.select_header_image,
2421
- button: {
2422
- text: ai_admin.use_this_image
2423
- },
2424
- multiple: false // Set to true to allow multiple files to be selected
2425
- });
2426
-
2427
- frame.on ('select', function() {
2428
- var attachment = frame.state().get('selection').first().toJSON();
2429
- // console.log ('attachment', attachment);
2430
- $('#report-header-image').val (attachment.url);
2431
- });
2432
-
2433
- frame.open();
2434
- });
2435
-
2436
- $("#tab-0 .adsense-list").click (function () {
2437
- $(this).blur ();
2438
-
2439
- toggle_adsense_list ();
2440
- });
2441
-
2442
- $("#ai-blocked-ip-addresses").click (function () {
2443
- ip_address = $("#ai-blocked-ip-addresses").attr ('delete');
2444
- $("#ai-blocked-ip-addresses").removeAttr ('delete');
2445
-
2446
- if (ip_address == null) ip_address = '';
2447
-
2448
- $('#ai-blocked-ip-addresses-list').load (ajaxurl + '?action=ai_ajax_backend&cfp-ip-address-list='+ip_address+'&ai_check=' + ai_nonce, function (response, status, xhr) {
2449
- if (status == "error") {
2450
- var message = "Error loading CFP IP addresses: " + xhr.status + " " + xhr.statusText ;
2451
- console.log (message);
2452
- } else {
2453
- var text = $('#ai-blocked-ip-addresses-list table').data ('count-text');
2454
- if (text == null) text = '';
2455
-
2456
- $("#ai-blocked-ip-addresses").text (text);
2457
-
2458
- $(".cfp-ip-address").click (function () {
2459
- var ip_address = $(this).closest ('tr').data ('ip-address');
2460
-
2461
- setTimeout (function() {
2462
- $("#ai-blocked-ip-addresses").attr ('delete', ip_address).click ();
2463
- }, 10);
2464
- });
2465
- }
2466
- });
2467
- });
2468
-
2469
- }
2470
-
2471
- function configure_tab (tab) {
2472
-
2473
- if (debug) console.log ("Configure tab:", tab);
2474
-
2475
- $('#tab-' + tab).addClass ('configured');
2476
-
2477
- $('#tab-' + tab + ' input[type=submit], #tab-' + tab + ' button.ai-button').button().show ();
2478
-
2479
- configure_editor (tab);
2480
-
2481
- $("select#insertion-type-"+tab).change (function() {
2482
- var block = $(this).attr('id').tabIndex ();
2483
- process_display_elements (block);
2484
- set_page_statuses (block);
2485
- });
2486
-
2487
- $("select#block-alignment-"+tab).change (function() {
2488
- var block = $(this).attr('id').replace ("block-alignment-", "");
2489
- var alignment = $("select#block-alignment-"+block+" option:selected").attr('value');
2490
- var automatic_insertion = $("select#insertion-type-"+block+" option:selected").attr('value');
2491
-
2492
- if (automatic_insertion != AI_ABOVE_HEADER &&
2493
- (alignment == AI_ALIGNMENT_STICKY_LEFT ||
2494
- alignment == AI_ALIGNMENT_STICKY_RIGHT ||
2495
- alignment == AI_ALIGNMENT_STICKY_TOP || alignment ==
2496
- AI_ALIGNMENT_STICKY_BOTTOM || alignment == AI_ALIGNMENT_STICKY)
2497
- ) {
2498
- $("select#insertion-type-"+block).val (AI_FOOTER).change ();
2499
- }
2500
- process_display_elements (block);
2501
- });
2502
-
2503
- $("select#vertical-position-"+tab).change (function() {
2504
- var block = $(this).attr('id').replace ("vertical-position-", "");
2505
- configure_sticky_css (block);
2506
- });
2507
-
2508
- $("select#horizontal-position-"+tab).change (function() {
2509
- var block = $(this).attr('id').replace ("horizontal-position-", "");
2510
- configure_sticky_css (block);
2511
- process_display_elements (block);
2512
- });
2513
-
2514
- $("input#background-"+tab).change (function() {
2515
- var block = $(this).attr('id').replace ("background-", "");
2516
- check_insertion (block);
2517
- configure_sticky_css (block);
2518
- process_display_elements (block);
2519
- });
2520
-
2521
- $("input#body-background-"+tab).change (function() {
2522
- var block = $(this).attr('id').replace ("body-background-", "");
2523
- check_insertion (block);
2524
- });
2525
-
2526
- if ($("input#bkg-color-"+tab).length != 0) {
2527
- $("input#bkg-color-"+tab).colorpicker ({useAlpha: false, useHashPrefix: true, format: 'hex', fallbackColor: '#fffffe'}).on('colorpickerChange colorpickerCreate colorpickerUpdate', function (e) {
2528
- var block = $(this).attr('id').replace ("bkg-color-", "");
2529
- configure_sticky_css (block);
2530
- $("#sticky-background-" + block).find ('.banner-preview').css ('background', $(this).val ());
2531
- }).on ('input', function() {
2532
- var block = $(this).attr('id').replace ("bkg-color-", "");
2533
- configure_sticky_css (block);
2534
- $("#sticky-background-" + block).find ('.banner-preview').css ('background', $(this).val ());
2535
- })
2536
- $("input#bkg-color-"+tab).colorpicker ('setValue', $("input#bkg-color-" + tab).attr ('value'));
2537
- }
2538
-
2539
- $("select#bkg-repeat-"+tab).change (function() {
2540
- var block = $(this).attr('id').replace ("bkg-repeat-", "");
2541
- configure_sticky_css (block);
2542
- process_display_elements (block);
2543
- });
2544
-
2545
- $("select#bkg-size-"+tab).change (function() {
2546
- var block = $(this).attr('id').replace ("bkg-size-", "");
2547
- configure_sticky_css (block);
2548
- process_display_elements (block);
2549
- });
2550
-
2551
-
2552
- $("input#exceptions-enabled-"+tab).change (function() {
2553
- var block = $(this).attr('id').replace ("exceptions-enabled-", "");
2554
- process_display_elements (block);
2555
- });
2556
-
2557
- $("input#process-php-"+tab).change (function() {
2558
- var block = $(this).attr('id').replace ("process-php-", "");
2559
- process_display_elements (block);
2560
- });
2561
- $("input#show-label-"+tab).change (function() {
2562
- var block = $(this).attr('id').replace ("show-label-", "");
2563
- // process_display_elements (block);
2564
- });
2565
- $("#enable-shortcode-"+tab).change (function() {
2566
- var block = $(this).attr('id').replace ("enable-shortcode-", "");
2567
- process_display_elements (block);
2568
- });
2569
- $("#enable-php-call-"+tab).change (function() {
2570
- var block = $(this).attr('id').replace ("enable-php-call-", "");
2571
- process_display_elements (block);
2572
- });
2573
- $("select#display-for-devices-"+tab).change (function() {
2574
- var block = $(this).attr('id').replace ("display-for-devices-", "");
2575
- process_display_elements (block);
2576
- });
2577
- $("select#scheduling-"+tab).change (function() {
2578
- var block = $(this).attr('id').replace ("scheduling-", "");
2579
- process_display_elements (block);
2580
- });
2581
- $("select#adb-block-action-"+tab).change (function() {
2582
- var block = $(this).attr('id').replace ("adb-block-action-", "");
2583
- process_display_elements (block);
2584
- });
2585
-
2586
-
2587
- $("#display-homepage-"+tab).change (function() {
2588
- var block = $(this).attr('id').replace ("display-homepage-", "");
2589
- process_display_elements (block);
2590
- });
2591
- $("#display-category-"+tab).change (function() {
2592
- var block = $(this).attr('id').replace ("display-category-", "");
2593
- process_display_elements (block);
2594
- });
2595
- $("#display-search-"+tab).change (function() {
2596
- var block = $(this).attr('id').replace ("display-search-", "");
2597
- process_display_elements (block);
2598
- });
2599
- $("#display-archive-"+tab).change (function() {
2600
- var block = $(this).attr('id').replace ("display-archive-", "");
2601
- process_display_elements (block);
2602
- });
2603
-
2604
- $("#client-side-detection-"+tab).change (function() {
2605
- var block = $(this).attr('id').replace ("client-side-detection-", "");
2606
- process_display_elements (block);
2607
- });
2608
-
2609
- $("#scheduling-date-on-"+tab).change (function() {
2610
- var block = $(this).attr('id').replace ("scheduling-date-on-", "");
2611
- process_scheduling_dates (block);
2612
- });
2613
-
2614
- $("#scheduling-date-off-"+tab).change (function() {
2615
- var block = $(this).attr('id').replace ("scheduling-date-off-", "");
2616
- process_scheduling_dates (block);
2617
- });
2618
-
2619
- $("#scheduling-time-on-"+tab).change (function() {
2620
- var block = $(this).attr('id').replace ("scheduling-time-on-", "");
2621
- process_scheduling_dates (block);
2622
- });
2623
-
2624
- $("#scheduling-time-off-"+tab).change (function() {
2625
- var block = $(this).attr('id').replace ("scheduling-time-off-", "");
2626
- process_scheduling_dates (block);
2627
- });
2628
-
2629
- $("#scheduling-weekdays-"+tab).click (function() {
2630
- var block = $(this).attr('id').replace ("scheduling-weekdays-", "");
2631
- var day_indexes = $(this).selectedIndexes ();
2632
-
2633
- days = [];
2634
- $.each ($(this).selectedIndexes (), function (key, value) {
2635
- days [key] = parseInt (value);
2636
- });
2637
-
2638
- $("#scheduling-weekdays-value-"+tab).attr ('value', days.join (','));
2639
- });
2640
-
2641
- $("select#avoid-action-"+tab).change (function() {
2642
- var block = $(this).attr('id').replace ("avoid-action-", "");
2643
- process_display_elements (block);
2644
- });
2645
-
2646
- $("#tab-" + tab + " .page-checker-button").click (function () {
2647
- // $("#page-checker-container").toggle ();
2648
- $("#page-checker-button").click ();
2649
- });
2650
-
2651
- process_display_elements (tab);
2652
-
2653
- // $("#exceptions-button-"+tab).button ({
2654
- // }).click (function () {
2655
- $("#exceptions-button-"+tab).click (function () {
2656
- var block = $(this).attr ("id").replace ("exceptions-button-","");
2657
- $("#block-exceptions-" + block).toggle ();
2658
- });
2659
-
2660
- // $("#show-css-button-"+tab).button ({
2661
- // }).show ().css ('visibility', 'visible').click (function () {
2662
- $("#show-css-button-"+tab).click (function () {
2663
- var block = $(this).attr ("id").replace ("show-css-button-","");
2664
- $("#icons-css-code-" + block).toggle ();
2665
-
2666
- if ($('#icons-css-code-'+block).is(':visible')) {
2667
- // $("#show-css-button-"+block+" span").text (ai_admin.hide);
2668
- // $("#show-css-button-"+block).addClass ('light-blue');
2669
- configure_selection_icons (block);
2670
- process_display_elements (block);
2671
- } else {
2672
- // $("#show-css-button-"+block+" span").text (ai_admin.show);
2673
- // $("#show-css-button-"+block).removeClass ('light-blue');
2674
- $("#sticky-animation-"+block).hide ();
2675
- $("#sticky-background-"+block).hide();
2676
- // $("#sticky-background-"+block).find ('.bkg-parameters').hide();
2677
- }
2678
- });
2679
-
2680
- // $("#counting-button-"+tab).button ({
2681
- // }).show ().click (function () {
2682
- $("#counting-button-"+tab).click (function () {
2683
- var block = $(this).attr ("id").replace ("counting-button-","");
2684
- $("#paragraph-counting-" + block).toggle ();
2685
- });
2686
-
2687
- // $("#clearance-button-"+tab).button ({
2688
- // }).show ().click (function () {
2689
- $("#clearance-button-"+tab).click (function () {
2690
- var block = $(this).attr ("id").replace ("clearance-button-","");
2691
- $("#paragraph-clearance-" + block).toggle ();
2692
- });
2693
-
2694
- $("#filter-button-"+tab).click (function () {
2695
- var block = $(this).attr ("id").tabIndex ();
2696
- $("#misc-settings-" + block).toggle ();
2697
- if ($("#misc-settings-" + block).is (':visible')) {
2698
- $("#ai-misc-container-" + block).tabs ({active: 1});
2699
- $("#ai-misc-filter-" + block).click ();
2700
- }
2701
- });
2702
-
2703
- $("#scheduling-date-on-"+tab).datepicker ({dateFormat: dateFormat, autoSize: true});
2704
- $("#scheduling-date-off-"+tab).datepicker ({dateFormat: dateFormat, autoSize: true});
2705
-
2706
- if ($("#scheduling-weekdays-value-"+tab).length != 0) {
2707
- $("#scheduling-time-on-"+tab).timepicker ({'timeFormat': timeFormat, 'minTime': '00:00:00', 'maxTime': '23:00:00', 'step': 60});
2708
- $("#scheduling-time-off-"+tab).timepicker ({'timeFormat': timeFormat, 'minTime': '00:00:00', 'maxTime': '23:00:00', 'step': 60});
2709
-
2710
- days = [];
2711
- $.each ($("#scheduling-weekdays-value-"+tab).val ().split (','), function (key, value) {
2712
- days [key] = parseInt (value);
2713
- });
2714
- $("#scheduling-weekdays-"+tab).weekdays ({
2715
- days: [ai_admin.day_mo, ai_admin.day_tu, ai_admin.day_we, ai_admin.day_th, ai_admin.day_fr, ai_admin.day_sa, ai_admin.day_su],
2716
- selectedIndexes: days
2717
- });
2718
- }
2719
-
2720
- $(".css-code-"+tab).click (function () {
2721
- var block = $(this).attr('class').replace ("css-code-", "");
2722
- if (!$('#custom-css-'+block).is(':visible')) {
2723
- $("#edit-css-button-"+block).click ();
2724
- }
2725
- });
2726
-
2727
- $("#edit-css-button-"+tab).button ({
2728
- }).click (function () {
2729
- var block = $(this).attr('id').replace ("edit-css-button-", "");
2730
-
2731
- $("#css-left-"+block).hide();
2732
- $("#css-right-"+block).hide();
2733
- $("#css-center-"+block).hide();
2734
- $("#css-float-left-"+block).hide();
2735
- $("#css-float-right-"+block).hide();
2736
- $("#css-sticky-left-"+block).hide();
2737
- $("#css-sticky-right-"+block).hide();
2738
- $("#css-sticky-top-"+block).hide();
2739
- $("#css-sticky-bottom-"+block).hide();
2740
- $("#css-sticky-"+block).hide();
2741
-
2742
- var alignment = $("select#block-alignment-"+block+" option:selected").attr('value');
2743
-
2744
- if (alignment == AI_ALIGNMENT_DEFAULT) {
2745
- $("#css-none-"+block).hide();
2746
- $("#custom-css-"+block).show().val ($("#css-none-"+block).text ());
2747
- $("select#block-alignment-"+block).val (AI_ALIGNMENT_CUSTOM_CSS).change();
2748
- } else
2749
- if (alignment == AI_ALIGNMENT_LEFT) {
2750
- $("#css-left-"+block).hide();
2751
- $("#custom-css-"+block).show().val ($("#css-left-"+block).text ());
2752
- $("select#block-alignment-"+block).val (AI_ALIGNMENT_CUSTOM_CSS).change();
2753
- } else
2754
- if (alignment == AI_ALIGNMENT_RIGHT) {
2755
- $("#css-right-"+block).hide();
2756
- $("#custom-css-"+block).show().val ($("#css-right-"+block).text ());
2757
- $("select#block-alignment-"+block).val (AI_ALIGNMENT_CUSTOM_CSS).change();
2758
- } else
2759
- if (alignment == AI_ALIGNMENT_CENTER) {
2760
- $("#css-center-"+block).hide();
2761
- $("#custom-css-"+block).show().val ($("#css-center-"+block).text ());
2762
- $("select#block-alignment-"+block).val (AI_ALIGNMENT_CUSTOM_CSS).change();
2763
- } else
2764
- if (alignment == AI_ALIGNMENT_FLOAT_LEFT) {
2765
- $("#css-float-left-"+block).hide();
2766
- $("#custom-css-"+block).show().val ($("#css-float-left-"+block).text ());
2767
- $("select#block-alignment-"+block).val (AI_ALIGNMENT_CUSTOM_CSS).change();
2768
- } else
2769
- if (alignment == AI_ALIGNMENT_FLOAT_RIGHT) {
2770
- $("#css-float-right-"+block).hide();
2771
- $("#custom-css-"+block).show().val ($("#css-float-right-"+block).text ());
2772
- $("select#block-alignment-"+block).val (AI_ALIGNMENT_CUSTOM_CSS).change();
2773
- } else
2774
- if (alignment == AI_ALIGNMENT_STICKY_LEFT) {
2775
- $("#css-sticky-left-"+block).hide();
2776
- $("#custom-css-"+block).show().val ($("#css-sticky-left-"+block).text ());
2777
- $("select#block-alignment-"+block).val (AI_ALIGNMENT_CUSTOM_CSS).change();
2778
- } else
2779
- if (alignment == AI_ALIGNMENT_STICKY_RIGHT) {
2780
- $("#css-sticky-right-"+block).hide();
2781
- $("#custom-css-"+block).show().val ($("#css-sticky-right-"+block).text ());
2782
- $("select#block-alignment-"+block).val (AI_ALIGNMENT_CUSTOM_CSS).change();
2783
- }
2784
- if (alignment == AI_ALIGNMENT_STICKY_TOP) {
2785
- $("#css-sticky-top-"+block).hide();
2786
- $("#custom-css-"+block).show().val ($("#css-sticky-top-"+block).text ());
2787
- $("select#block-alignment-"+block).val (AI_ALIGNMENT_CUSTOM_CSS).change();
2788
- } else
2789
- if (alignment == AI_ALIGNMENT_STICKY_BOTTOM) {
2790
- $("#css-sticky-bottom-"+block).hide();
2791
- $("#custom-css-"+block).show().val ($("#css-sticky-bottom-"+block).text ());
2792
- $("select#block-alignment-"+block).val (AI_ALIGNMENT_CUSTOM_CSS).change();
2793
- } else
2794
- if (alignment == AI_ALIGNMENT_STICKY) {
2795
- $("#css-sticky-"+block).hide();
2796
- $("#custom-css-"+block).show().val ($("#css-sticky-"+block).text ());
2797
- $("select#block-alignment-"+block).val (AI_ALIGNMENT_CUSTOM_CSS).change();
2798
- }
2799
- });
2800
-
2801
-
2802
- $("#name-label-"+tab).click (function () {
2803
- var block = $(this).attr('id').replace ("name-label-", "");
2804
-
2805
- if ($("div#settings-" + block).is (':visible'))
2806
-
2807
- if (!$('#name-edit-'+block).is(':visible')) {
2808
- $("#name-edit-"+block).css('display', 'table-cell').val ($("#name-label-"+block).text ()).focus ();
2809
- $("#name-label-"+block).hide();
2810
- }
2811
- });
2812
-
2813
- $("#name-label-container-"+tab).click (function () {
2814
- var block = $(this).attr('id').replace ("name-label-container-", "");
2815
-
2816
- if ($("div#settings-" + block).is (':visible'))
2817
-
2818
- if (!$('#name-edit-'+block).is(':visible')) {
2819
- $("#name-edit-"+block).css('display', 'table-cell').val ($("#name-label-"+block).text ()).focus ();
2820
- $("#name-label-"+block).hide();
2821
- }
2822
- });
2823
-
2824
- $("#name-edit-"+tab).on('keyup keypress', function (e) {
2825
- var keyCode = e.keyCode || e.which;
2826
- ignore_key = true;
2827
- if (keyCode == 27) {
2828
- var block = $(this).attr('id').replace ("name-edit-", "");
2829
- $("#name-label-"+block).show();
2830
- $("#name-edit-"+block).hide();
2831
- ignore_key = false;
2832
- } else if (keyCode == 13) {
2833
- var block = $(this).attr('id').replace ("name-edit-", "");
2834
- $("#name-label-"+block).show().text ($("#name-edit-"+block).val ());
2835
- $("#name-edit-"+block).hide();
2836
- ignore_key = false;
2837
- e.preventDefault();
2838
- return false;
2839
- }
2840
- }).focusout (function() {
2841
- if (ignore_key) {
2842
- var block = $(this).attr('id').replace ("name-edit-", "");
2843
- $("#name-label-"+block).show().text ($("#name-edit-"+block).val ());
2844
- $("#name-edit-"+block).hide();
2845
- }
2846
- ignore_key = true;
2847
- });
2848
-
2849
- $("#export-switch-"+tab).checkboxButton ().click (function () {
2850
- var block = $(this).attr ("id");
2851
- block = block.replace ("export-switch-","");
2852
- $("#export-container-" + block).toggle ();
2853
-
2854
- if ($("#export-container-" + block).is(':visible') && !$(this).hasClass ("loaded")) {
2855
- // var nonce = $(this).attr ('nonce');
2856
- $("#export_settings_" + block).load (ajaxurl+"?action=ai_ajax_backend&export=" + block + "&ai_check=" + ai_nonce, function (response, status, xhr) {
2857
- if (status == "error" ) {
2858
- $('#ai-error-container').text (ai_admin.error + ' ' + xhr.status + ': ' + xhr.statusText).show ();
2859
- } else {
2860
- $("#export_settings_" + block).attr ("name", "export_settings_" + block);
2861
- $("#export-switch-"+block).addClass ("loaded");
2862
- }
2863
- });
2864
- }
2865
- });
2866
-
2867
- $("input#statistics-button-"+tab).checkboxButton ().click (function () {
2868
- disable_auto_refresh_statistics ();
2869
- var block = $(this).attr ("id");
2870
- block = block.replace ("statistics-button-","");
2871
- $("div#statistics-container-" + block).toggle ();
2872
- $("div#settings-" + block).toggle ();
2873
-
2874
- $("#tab-" + block + ' .ai-toolbars .ai-settings').toggle ();
2875
- $("#ai-main-toolbar-" + block + ' .ai-statistics').toggle ();
2876
-
2877
- var container = $("div#statistics-container-" + block);
2878
- if (container.is(':visible')) {
2879
- $("#name-label-container-"+block).css ('cursor', 'default');
2880
- if (!$(this).hasClass ('loaded')) {
2881
- $("input#load-custom-range-"+block).click ();
2882
- $(this).addClass ('loaded');
2883
- }
2884
- } else {
2885
- $("#name-label-container-"+block).css ('cursor', 'pointer');
2886
- }
2887
- });
2888
-
2889
- $("#export-pdf-button-"+tab).click (function () {
2890
- var block = $(this).attr ("id").tabIndex ();
2891
- export_statistics_pdf (block);
2892
- });
2893
-
2894
- $("#export-csv-button-"+tab).click (function () {
2895
- var block = $(this).attr ("id").tabIndex ();
2896
- export_statistics_csv (block);
2897
- });
2898
-
2899
- $("input#adb-statistics-button-"+tab).checkboxButton ().click (function () {
2900
- var block = $(this).attr ("id");
2901
- block = block.replace ("adb-statistics-button-","");
2902
- setTimeout (function() {$("input#load-custom-range-"+block).click ();}, 2);
2903
- });
2904
-
2905
- configure_statistics_toolbar (tab);
2906
-
2907
- $("#device-detection-button-"+tab).button ({
2908
- }).show ().click (function () {
2909
- var block = $(this).attr ("id");
2910
- block = block.replace ("device-detection-button-","");
2911
- $("#device-detection-settings-" + block).toggle ();
2912
- });
2913
-
2914
- $("#lists-button-"+tab).button ({
2915
- }).show ().click (function () {
2916
- var block = $(this).attr ("id");
2917
- block = block.replace ("lists-button-","");
2918
-
2919
- if ($("#list-settings-" + block).is(':visible')) {
2920
- if ($("#list-settings-" + block).hasClass ('ai-expaned')) {
2921
- $("#list-settings-" + block).hide ();
2922
- $("#list-settings-" + block).removeClass ('ai-expaned');
2923
- } else {
2924
- var lists = $("#list-settings-" + block + ' tr');
2925
- var list_items = $("#list-settings-" + block + ' tr.list-items');
2926
-
2927
- if (list_items.length != lists.length) {
2928
- $("#list-settings-" + block + ' tr').show ();
2929
- $("#list-settings-" + block).addClass ('ai-expaned');
2930
- } else {
2931
- $("#list-settings-" + block).hide ();
2932
- $("#list-settings-" + block).removeClass ('ai-expaned');
2933
- }
2934
- }
2935
- } else {
2936
- $("#list-settings-" + block).show ();
2937
- $("#list-settings-" + block).removeClass ('ai-expaned');
2938
- $("#list-settings-" + block + ' tr').hide ();
2939
-
2940
- var list_items = $("#list-settings-" + block + ' tr.list-items');
2941
- if (list_items.length) {
2942
- list_items.show ();
2943
- } else {
2944
- $("#list-settings-" + block + ' tr').show ();
2945
- $("#list-settings-" + block).addClass ('ai-expaned');
2946
- }
2947
- }
2948
- });
2949
-
2950
- $("#list-settings-"+tab+' span.checkbox-list-button').click (function () {
2951
- var on = $(this).hasClass ('dashicons-yes');
2952
- if (on) {
2953
- $(this).removeClass ('dashicons-yes').addClass ('dashicons-no');
2954
- $(this).prev ().removeAttr ('checked');
2955
- } else {
2956
- $(this).removeClass ('dashicons-no').addClass ('dashicons-yes');
2957
- $(this).prev ().attr ('checked', '1');
2958
- }
2959
- });
2960
-
2961
- $("#manual-button-"+tab).button ({
2962
- }).show ().click (function () {
2963
- var block = $(this).attr ("id");
2964
- block = block.replace ("manual-button-","");
2965
- $("#manual-settings-" + block).toggle ();
2966
- });
2967
-
2968
- $("#misc-button-"+tab).button ({
2969
- }).show ().click (function () {
2970
- var block = $(this).attr ("id");
2971
- block = block.replace ("misc-button-","");
2972
- $("#misc-settings-" + block).toggle ();
2973
- });
2974
-
2975
- // $("#scheduling-button-"+tab).button ({
2976
- // }).show ().click (function () {
2977
- // var block = $(this).attr ("id");
2978
- // block = block.replace ("scheduling-button-","");
2979
- // $("#scheduling-settings-" + block).toggle ();
2980
- // });
2981
-
2982
- $("#preview-button-"+tab).button ({
2983
- }).show ().click (function () {
2984
- var block = $(this).attr ("id");
2985
- block = block.replace ("preview-button-","");
2986
-
2987
- $(this).blur ();
2988
-
2989
- var sticky = false;
2990
- var iframe = $(this).attr ('iframe') == '1' ? 1 : 0;
2991
- $(this).attr ('iframe', '');
2992
-
2993
- var alignment = $("select#block-alignment-"+block+" option:selected").attr('value');
2994
- var horizontal = $("select#horizontal-position-"+block+" option:selected").attr('value');
2995
- var vertical = $("select#vertical-position-"+block+" option:selected").attr('value');
2996
- var horizontal_margin = $("#horizontal-margin-"+block).val ();
2997
- var vertical_margin = $("#vertical-margin-"+block).val ();
2998
- var animation = $("select#animation-"+block+" option:selected").attr('value');
2999
-
3000
- var custom_css = $("#custom-css-"+block).val ();
3001
-
3002
- var alignment_css = "";
3003
- if (alignment == AI_ALIGNMENT_DEFAULT) {
3004
- alignment_css = $("#css-none-"+block).text ();
3005
- } else
3006
- if (alignment == AI_ALIGNMENT_CUSTOM_CSS) {
3007
- alignment_css = custom_css;
3008
- sticky = is_sticky (custom_css);
3009
- } else
3010
- if (alignment == AI_ALIGNMENT_LEFT) {
3011
- alignment_css = $("#css-left-"+block).text ();
3012
- } else
3013
- if (alignment == AI_ALIGNMENT_RIGHT) {
3014
- alignment_css = $("#css-right-"+block).text ();
3015
- } else
3016
- if (alignment == AI_ALIGNMENT_CENTER) {
3017
- alignment_css = $("#css-center-"+block).text ();
3018
- } else
3019
- if (alignment == AI_ALIGNMENT_FLOAT_LEFT) {
3020
- alignment_css = $("#css-float-left-"+block).text ();
3021
- } else
3022
- if (alignment == AI_ALIGNMENT_FLOAT_RIGHT) {
3023
- alignment_css = $("#css-float-right-"+block).text ();
3024
- } else
3025
- if (alignment == AI_ALIGNMENT_STICKY_LEFT) {
3026
- alignment_css = $("#css-sticky-left-"+block).text ();
3027
- } else
3028
- if (alignment == AI_ALIGNMENT_STICKY_RIGHT) {
3029
- alignment_css = $("#css-sticky-right-"+block).text ();
3030
- }
3031
- if (alignment == AI_ALIGNMENT_STICKY_TOP) {
3032
- alignment_css = $("#css-sticky-top-"+block).text ();
3033
- } else
3034
- if (alignment == AI_ALIGNMENT_STICKY_BOTTOM) {
3035
- alignment_css = $("#css-sticky-bottom-"+block).text ();
3036
- } else
3037
- if (alignment == AI_ALIGNMENT_STICKY) {
3038
- alignment_css = update_sticky_margins ($("#css-sticky-"+block).text (), horizontal_margin, vertical_margin);
3039
- sticky = true;
3040
- }
3041
-
3042
- var name = $("#name-label-"+block).text ();
3043
- var code = get_editor_text (block);
3044
- var php = $("input#process-php-"+block).is(":checked") ? 1 : 0;
3045
- var label = $("input#show-label-"+block).is(":checked") ? 1 : 0;
3046
-
3047
- var close_button = $("#close-button-"+block+" option:selected").attr('value');
3048
-
3049
- var background = $("input#background-"+block).is(":checked") ? 1 : 0;
3050
- var body_background = $("input#body-background-"+block).is(":checked") ? 1 : 0;
3051
- var background_image = $("#bkg-image-url-"+block).val ();
3052
- var background_color = $("input#bkg-color-"+block).val ();
3053
- var background_size = $("select#bkg-size-"+block+" option:selected").attr('value');
3054
- var background_repeat = $("select#bkg-repeat-"+block+" option:selected").attr('value');
3055
-
3056
- if (!sticky) {
3057
- var window_top = (screen.height / 2) - (820 / 2);
3058
- var window_left = 100;
3059
- var window_width = 820;
3060
- var window_height = 820;
3061
- } else {
3062
- var window_top = screen.availTop;
3063
- var window_left = screen.availLeft;
3064
- var window_width = screen.availWidth;
3065
- var window_height = screen.availHeight;
3066
- }
3067
-
3068
- // var nonce = $("#ai-form").attr ('nonce');
3069
-
3070
- var param = {
3071
- 'action': 'ai_ajax_backend',
3072
- 'preview': block,
3073
- 'ai_check': ai_nonce,
3074
- 'name': b64e (name),
3075
- 'code': b64e (code),
3076
- 'alignment': btoa (alignment),
3077
- 'horizontal': btoa (horizontal),
3078
- 'vertical': btoa (vertical),
3079
- 'horizontal_margin': btoa (horizontal_margin),
3080
- 'vertical_margin': btoa (vertical_margin),
3081
- 'animation': btoa (animation),
3082
- 'alignment_css': btoa (alignment_css),
3083
- 'custom_css': btoa (custom_css),
3084
- 'php': php,
3085
- 'label': label,
3086
- 'close': close_button,
3087
- 'background': background,
3088
- 'body_background': body_background,
3089
- 'background_image': btoa (background_image),
3090
- 'background_color': btoa (background_color),
3091
- 'background_size': btoa (background_size),
3092
- 'background_repeat': btoa (background_repeat),
3093
- 'iframe': iframe
3094
- };
3095
- open_popup_window_post (ajaxurl, 'width='+window_width+',height='+window_height+',top='+window_top+',left='+window_left+',resizable=yes,scrollbars=yes,toolbar=no,location=no,directories=no,status=no,menubar=no', 'preview', param);
3096
- });
3097
-
3098
- $("select#animation-"+tab).change (function() {
3099
- var block = $(this).attr('id').tabIndex ();
3100
- var animation = $(this).find ("option:selected").attr('value');
3101
- var animation_parameters = $(this).closest ('.sticky-animation').find ('.animation-parameters')
3102
-
3103
- if (animation == AI_ANIMATION_NONE || $("input#background-"+block).is(":checked")) {
3104
- animation_parameters.hide ();
3105
- } else {
3106
- animation_parameters.show ();
3107
- }
3108
- });
3109
-
3110
- $("#iframe-preview-button-"+tab).button ({
3111
- }).show ().click (function () {
3112
- var block = $(this).attr ("id");
3113
- block = block.replace ("iframe-preview-button-","");
3114
- $("#preview-button-"+block).attr ('iframe', '1').click ();
3115
- });
3116
-
3117
- create_list_selector ('category', tab);
3118
- create_list_selector ('tag', tab);
3119
- create_list_selector ('taxonomy', tab);
3120
- create_list_selector ('id', tab);
3121
- create_list_editor ('url', tab);
3122
- create_list_editor ('url-parameter',tab);
3123
- create_list_editor ('referer', tab);
3124
- create_list_selector ('client', tab);
3125
- create_list_editor ('ip-address', tab);
3126
- create_list_selector ('country', tab);
3127
- create_list_selector ('city', tab);
3128
-
3129
- var toggle_country_list = function (index) {
3130
- $('#ms-country-select-' + index).toggle();
3131
- before_update_selection_from_list = null;
3132
- }
3133
-
3134
- var toggle_city_list = function (index) {
3135
- $('#ms-city-select-' + index).toggle();
3136
- before_update_selection_from_list = null;
3137
- }
3138
-
3139
- $('#country-city-' + tab).click (function () {
3140
- var block = $(this).attr('id').tabIndex ();
3141
-
3142
- $(this).find ('span').toggle ();
3143
- $(this).next ().find ('span').toggle ();
3144
-
3145
- var button_country = $('#country-button-'+block);
3146
- var button_city = $('#city-button-'+block);
3147
-
3148
- var country_selection_container = $('#ms-country-select-'+block);
3149
- country_selection_container_visible = country_selection_container.length && country_selection_container.is (':visible');
3150
-
3151
- var city_selection_container = $('#ms-city-select-'+block);
3152
- city_selection_container_visible = city_selection_container.length && city_selection_container.is (':visible');
3153
-
3154
- if (country_selection_container_visible) {
3155
- before_update_selection_from_list = toggle_country_list;
3156
- button_city.click ();
3157
- }
3158
-
3159
- if (city_selection_container_visible) {
3160
- before_update_selection_from_list = toggle_city_list;
3161
- button_country.click ();
3162
- }
3163
- });
3164
-
3165
- $('#tracking-' + tab).checkboxButton ().click (function () {
3166
- var block = $(this).attr('id').replace ("tracking-", "");
3167
- var alignment = $("select#block-alignment-"+block+" option:selected").attr('value');
3168
- var tracking = !$('#tracking-' + block).next ().find ('.checkbox-icon').hasClass ('on');
3169
- if (tracking && alignment == AI_ALIGNMENT_NO_WRAPPING) $('#tracking-wrapping-warning-' + block).show (); else $('#tracking-wrapping-warning-' + block).hide ();
3170
- });
3171
-
3172
- $('#simple-editor-' + tab).checkboxButton ().click (function () {
3173
- var block = $(this).attr('id').replace ("simple-editor-", "");
3174
- if (block == active_tab && !$(this).hasClass ('clicked')) {
3175
- $(this).addClass ('clicked')
3176
- $('#ai-tab-container .simple-editor-button').click();
3177
- $(this).removeClass ('clicked')
3178
- }
3179
- });
3180
- // Switch to simple editor if the button was pressed before the tab was configured
3181
- if ($('#simple-editor-' + tab).is(":checked")) {
3182
- switch_editor (tab, true);
3183
- $('#simple-editor-' + tab).next ("label").find ('.checkbox-icon').addClass("on");
3184
- }
3185
-
3186
- $('#process-php-' + tab).checkboxButton ();
3187
- $('#disable-insertion-' + tab).checkboxButton ();
3188
-
3189
- $('#ai-misc-container-' + tab).tabs();
3190
- $('#ai-misc-tabs-' + tab).show();
3191
-
3192
- $('#ai-devices-container-' + tab).tabs();
3193
- $('#ai-devices-tabs-' + tab).show();
3194
-
3195
- $("#tools-button-"+tab).click (function () {
3196
- if (!$(this).find ('.checkbox-icon').hasClass("on")) {
3197
- $('label.rotation-button').each (function () {
3198
- if ($(this).find ('.checkbox-icon').hasClass("on")) {
3199
- $(this).prev ().click ();
3200
- }
3201
- });
3202
-
3203
- $('label.code-generator-button').each (function () {
3204
- if ($(this).find ('.checkbox-icon').hasClass("on")) {
3205
- $(this).prev ().click ();
3206
- }
3207
- });
3208
-
3209
- $('code-generator').hide ();
3210
- }
3211
-
3212
- $('.ai-tools-toolbar').toggle();
3213
- $('label.tools-button').find ('.checkbox-icon').toggleClass("on");
3214
- });
3215
-
3216
- $('#ai-code-generator-container-' + tab).tabs();
3217
-
3218
- $("select#adsense-type-"+tab).change (function() {
3219
- var block = $(this).attr('id').replace ("adsense-type-", "");
3220
- process_adsense_elements (block);
3221
- });
3222
-
3223
- $("select#adsense-size-"+tab).change (function() {
3224
- var block = $(this).attr('id').replace ("adsense-size-", "");
3225
- process_adsense_elements (block);
3226
- });
3227
-
3228
- $("select#amazon-amp-"+tab).change (function() {
3229
- var block = $(this).attr('id').replace ("amazon-amp-", "");
3230
- console.log ('block', block);
3231
- process_amazon_elements (block);
3232
- });
3233
-
3234
- process_adsense_elements (tab);
3235
- process_amazon_elements (tab);
3236
-
3237
- $("#code-generator-"+tab).click (function () {
3238
- var block = $(this).attr('id').replace ("code-generator-", "");
3239
- $('#ai-code-generator-container-' + block).toggle();
3240
- $(this).next ("label").find ('.checkbox-icon').toggleClass("on");
3241
- });
3242
-
3243
- $("#visual-editor-"+tab).click (function () {
3244
- var block = $(this).attr('id').replace ("visual-editor-", "");
3245
-
3246
- var code = b64e (get_editor_text (block));
3247
- var php = $("input#process-php-" + block).is(":checked") ? 1 : 0;
3248
-
3249
- var window_width = 820;
3250
- var window_height = 870;
3251
- var window_left = 100;
3252
- var window_top = (screen.height / 2) - (window_height / 2);
3253
- // var nonce = $("#ai-form").attr ('nonce');
3254
- var param = {'action': 'ai_ajax_backend', 'edit': block, 'ai_check': ai_nonce, 'code': code, 'php': php};
3255
- open_popup_window_post (ajaxurl, 'width='+window_width+',height='+window_height+',top='+window_top+',left='+window_left+',resizable=yes,scrollbars=yes,toolbar=no,location=no,directories=no,status=no,menubar=no', 'edit', param);
3256
- });
3257
-
3258
- $("#select-image-button-"+tab).click (function (event) {
3259
- $(this).blur ();
3260
-
3261
- var block = $(this).attr('id').replace ("select-image-button-", "");
3262
- var frame;
3263
-
3264
- event.preventDefault();
3265
-
3266
- if (frame) {
3267
- frame.open();
3268
- return;
3269
- }
3270
-
3271
- frame = wp.media ({
3272
- title: ai_admin.select_banner_image,
3273
- button: {
3274
- text: ai_admin.use_this_image
3275
- },
3276
- multiple: false // Set to true to allow multiple files to be selected
3277
- });
3278
-
3279
- // frame.on ('open', function(){
3280
- // var selected = $('#banner-image-' + block).attr ('src');
3281
- // if (selected) {
3282
- // var selection = frame.state().get ('selection');
3283
- // var id = $('#banner-image-' + block).attr ('data-id');
3284
- // selection.add (wp.media.attachment (id));
3285
- // }
3286
- // });
3287
-
3288
- frame.on ('select', function() {
3289
- var attachment = frame.state().get('selection').first().toJSON();
3290
- // console.log ('attachment', attachment);
3291
- $('#banner-image-' + block).attr ('src', attachment.url);
3292
- $('#banner-image-url-' + block).val (attachment.url).trigger ("input");
3293
- });
3294
-
3295
- frame.open();
3296
- });
3297
-
3298
- $("#select-placeholder-button-"+tab).click (function (event) {
3299
- $(this).blur ();
3300
-
3301
- var block = $(this).attr('id').replace ("select-placeholder-button-", "");
3302
- var image_url = $('#banner-image-' + block).attr ('src');
3303
-
3304
- var window_width = 820;
3305
- var window_height = 870;
3306
- var window_left = 100;
3307
- var window_top = (screen.height / 2) - (870 / 2);
3308
- // var nonce = $("#ai-form").attr ('nonce');
3309
- var param = {'action': 'ai_ajax_backend', 'placeholder': image_url, 'block': block, 'ai_check': ai_nonce};
3310
- open_popup_window_post (ajaxurl, 'width='+window_width+',height='+window_height+',top='+window_top+',left='+window_left+',resizable=yes,scrollbars=yes,toolbar=no,location=no,directories=no,status=no,menubar=no', 'preview', param);
3311
- });
3312
-
3313
- $("#banner-image-url-" + tab).on ('input', function() {
3314
-
3315
- var block = $(this).attr('id').replace ("banner-image-url-", "");
3316
- var image = $('#banner-image-' + block);
3317
-
3318
- var new_image_src = $(this).val ();
3319
- if (new_image_src == '') {
3320
- // new_image_src = '//:0';
3321
- image.hide ();
3322
- $('div#tab-banner-' + block + ' table.ai-settings-table').css ('position', 'relative');
3323
- }
3324
-
3325
- // Removed in jQuery 3
3326
- // image.attr ('src', new_image_src).load (function () {
3327
- image.attr ('src', new_image_src).on ("load", function () {
3328
- image.show ();
3329
- $('div#tab-banner-' + block + ' table.ai-settings-table').css ('position', 'inherit');
3330
- $(this).closest ('.ai-banner').removeClass ('ai-banner-top');
3331
- var width = this.naturalWidth;
3332
- var height = this.naturalHeight;
3333
-
3334
- if (width / height > 2 && width > 300) {
3335
- $(this).closest ('.ai-banner').addClass ('ai-banner-top');
3336
- }
3337
- })
3338
- // Removed in jQuery 3
3339
- // .error (function() {
3340
- .on ("error", function() {
3341
- if (image.is(':visible')) {
3342
- // image.hide ().attr ('src', '//:0');
3343
- image.hide ().attr ('src', '');
3344
- $('div#tab-banner-' + block + ' table.ai-settings-table').css ('position', 'relative');
3345
- }
3346
- });
3347
-
3348
- });
3349
-
3350
- $("#banner-url-" + tab).on ('input', function() {
3351
- var block = $(this).attr('id').replace ("banner-url-", "");
3352
- var url = $(this).val ().trim();
3353
- if (url == '') $('#banner-link-' + block).removeAttr ('href'); else
3354
- $('#banner-link-' + block).attr ('href', $(this).val ());
3355
- });
3356
-
3357
- $("#import-code-"+tab).click (function () {
3358
- $(this).next ("label").find ('.checkbox-icon').addClass("on");
3359
-
3360
- var block = $(this).attr('id').replace ("import-code-", "");
3361
- // var nonce = $("#ai-form").attr ('nonce');
3362
-
3363
- $.post (ajaxurl, {'action': 'ai_ajax_backend', 'ai_check': ai_nonce, 'import-code': b64e (get_editor_text (block))}
3364
- ).done (function (data) {
3365
- if (data != '') {
3366
- $('#ai-error-container').hide ();
3367
-
3368
- try {
3369
- var code_data = JSON.parse (data);
3370
- } catch (error) {
3371
- console.log ("AI IMPORT CODE ERROR:", data);
3372
- $('#ai-error-container').text (data).show ();
3373
- }
3374
-
3375
- if (typeof code_data !== "undefined" && typeof code_data ['type'] !== "undefined") {
3376
-
3377
- if (debug) console.log ("AI IMPORT CODE:", code_data);
3378
-
3379
- var code_type = code_data ['type'];
3380
-
3381
- $("#ai-code-generator-container-" + block).tabs ({active: code_type == AI_CODE_UNKNOWN ? AI_CODE_BANNER : code_type});
3382
-
3383
- switch (code_type) {
3384
- case AI_CODE_BANNER:
3385
- $("#banner-image-url-" + block).val (code_data ['image']).trigger ('input');
3386
- $("#image-alt-text-" + block).val (code_data ['alt']);
3387
- $("#lazy-load-image-" + block).prop ('checked', code_data ['loading'] == 'lazy');
3388
-
3389
- $("#banner-url-" + block).val (code_data ['link']).trigger ('input');
3390
- $("#open-new-tab-" + block).prop ('checked', code_data ['target'] == '_blank');
3391
- break;
3392
- case AI_CODE_ADSENSE:
3393
- $("#adsense-comment-" + block).val (code_data ['adsense-comment']);
3394
- $("#adsense-publisher-id-" + block).val (code_data ['adsense-publisher-id']);
3395
- $("#adsense-ad-slot-id-" + block).val (code_data ['adsense-ad-slot-id']);
3396
-
3397
- $("#adsense-type-" + block).val (code_data ['adsense-type']);
3398
- $("#adsense-size-" + block).val (code_data ['adsense-size']);
3399
-
3400
- var ad_size = '';
3401
- if (code_data ['adsense-width'] != '' && code_data ['adsense-height'] != '') {
3402
- ad_size = code_data ['adsense-width'] + 'x' + code_data ['adsense-height'];
3403
- }
3404
- $('#tab-adsense-' + block + ' .adsense-ad-size.fixed').parent ().find ('.scombobox-display').val (ad_size);
3405
-
3406
- $("#adsense-amp-" + block).val (code_data ['adsense-amp']);
3407
-
3408
- $("#adsense-amp-block-on-consent-" + block).prop ('checked', code_data ['adsense-amp-block-on-consent'] != '#');
3409
-
3410
- $("#adsense-layout-" + block).val (code_data ['adsense-layout']);
3411
- $("#adsense-layout-key-" + block).val (decodeURIComponent (code_data ['adsense-layout-key']));
3412
-
3413
- if (decodeURIComponent (code_data ['adsense-full-width-responsive']) == 'false') {
3414
- $("#adsense-layout-" + block + ' select.adsense-full-width').val ('disabled');
3415
- } else {
3416
- $("#adsense-layout-" + block + ' select.adsense-full-width').val ('enabled');
3417
- }
3418
-
3419
- if ($("#adsense-size-" + block).val () == AI_ADSENSE_SIZE_FIXED_BY_VIEWPORT) {
3420
- $('#tab-adsense-' + block + ' tr.adsense-viewport').each (function (index) {
3421
- var width = code_data ['adsense-sizes'][index][0];
3422
- var height = code_data ['adsense-sizes'][index][1];
3423
-
3424
- var ad_size = '';
3425
- if (width != '' && height != '') {
3426
- ad_size = width + 'x' + height;
3427
- }
3428
-
3429
- $(this).find ('.adsense-ad-size').parent ().find ('.scombobox-display').val (ad_size);
3430
- });
3431
- }
3432
- process_adsense_elements (block);
3433
- break;
3434
- case AI_CODE_AMAZON:
3435
- $("#amazon-data-" + block).val (code_data ['amazon-data']);
3436
-
3437
- $("#amazon-amp-" + block).val (code_data ['amazon-amp']);
3438
-
3439
- $("#amazon-width-" + block).val (code_data ['amazon-width']);
3440
- $("#amazon-height-" + block).val (code_data ['amazon-height']);
3441
-
3442
- $("#amazon-amp-block-on-consent-" + block).prop ('checked', code_data ['amazon-amp-block-on-consent'] != '#');
3443
-
3444
- process_amazon_elements (block);
3445
- break;
3446
- case AI_CODE_UNKNOWN:
3447
- break;
3448
- }
3449
- }
3450
- }
3451
- }).fail (function (xhr, status, error) {
3452
- console.log ("AI IMPORT CODE ERROR:", xhr.status, xhr.statusText);
3453
- $('#ai-error-container').text (ai_admin.error + ' ' + xhr.status + ': ' + xhr.statusText).show ();
3454
- }).always (function() {
3455
- $("#import-code-"+block).next ("label").find ('.checkbox-icon').removeClass("on");
3456
- });
3457
- });
3458
-
3459
- $("#generate-code-"+tab).click (function () {
3460
- $('#ai-error-container').hide ();
3461
- $(this).next ("label").find ('.checkbox-icon').addClass("on");
3462
-
3463
- var block = $(this).attr('id').replace ("generate-code-", "");
3464
- // var nonce = $("#ai-form").attr ('nonce');
3465
- var code_type = $("#ai-code-generator-container-" + block).tabs('option', 'active');
3466
- var code_data = {'action': 'ai_ajax_backend', 'ai_check': ai_nonce, 'generate-code': code_type};
3467
-
3468
- switch (code_type) {
3469
- case AI_CODE_BANNER:
3470
- code_data ['image'] = $("#banner-image-url-" + block).val ();
3471
- code_data ['alt'] = $("#image-alt-text-" + block).val ();
3472
- if ($("#lazy-load-image-" + block).is(":checked"))
3473
- code_data ['loading'] = 'lazy';
3474
-
3475
- code_data ['link'] = $("#banner-url-" + block).val ();
3476
- if ($("#open-new-tab-" + block).is(":checked"))
3477
- code_data ['target'] = '_blank';
3478
- break;
3479
- case AI_CODE_ADSENSE:
3480
- code_data ['block'] = block;
3481
- code_data ['adsense-comment'] = $("#adsense-comment-" + block).val ();
3482
- code_data ['adsense-publisher-id'] = $("#adsense-publisher-id-" + block).val ();
3483
- code_data ['adsense-ad-slot-id'] = $("#adsense-ad-slot-id-" + block).val ();
3484
- code_data ['adsense-type'] = parseInt ($("select#adsense-type-" + block +" option:selected").attr ('value'));
3485
- code_data ['adsense-size'] = parseInt ($("select#adsense-size-" + block +" option:selected").attr ('value'));
3486
-
3487
- var ad_size = $('#tab-adsense-' + block + ' .adsense-ad-size.fixed').parent ().find ('.scombobox-display').val ().trim ().toLowerCase ().split ('x');
3488
- code_data ['adsense-width'] = '';
3489
- code_data ['adsense-height'] = '';
3490
- if (ad_size.length == 2) {
3491
- code_data ['adsense-width'] = parseInt (ad_size [0]);
3492
- code_data ['adsense-height'] = parseInt (ad_size [1]);
3493
- }
3494
-
3495
- code_data ['adsense-amp'] = parseInt ($("select#adsense-amp-" + block +" option:selected").attr ('value'));
3496
- code_data ['adsense-amp-block-on-consent'] = $("#adsense-amp-block-on-consent-" + block).is(":checked") ? '' : '#';
3497
- code_data ['adsense-layout'] = $("#adsense-layout-" + block).val ();
3498
- code_data ['adsense-layout-key'] = $("#adsense-layout-key-" + block).val ();
3499
-
3500
- code_data ['adsense-full-width-responsive'] = 'true';
3501
- if ($("#adsense-layout-" + block + ' select.adsense-full-width').val () == 'disabled') {
3502
- code_data ['adsense-full-width-responsive'] = 'false';
3503
- }
3504
-
3505
- if (code_data ['adsense-size'] == AI_ADSENSE_SIZE_FIXED_BY_VIEWPORT) {
3506
- var viewport_sizes = new Array();
3507
- $('#tab-adsense-' + block + ' tr.adsense-viewport').each (function (index) {
3508
- var ad_size = $(this).find ('.adsense-ad-size').parent ().find ('.scombobox-display').val ().trim ().toLowerCase ().split ('x');
3509
- var adsense_size = {'width': '', 'height': ''};
3510
- if (ad_size.length == 2) {
3511
- adsense_size = {'width': parseInt (ad_size [0]), 'height': parseInt (ad_size [1])};
3512
- }
3513
- viewport_sizes.push (adsense_size);
3514
- });
3515
- code_data ['adsense-viewports'] = viewport_sizes;
3516
- }
3517
- break;
3518
-
3519
- case AI_CODE_AMAZON:
3520
- code_data ['amazon-data'] = $("#amazon-data-" + block).val ();
3521
- code_data ['amazon-amp'] = $("select#amazon-amp-" + block +" option:selected").attr ('value');
3522
- code_data ['amazon-width'] = $("#amazon-width-" + block).val ();
3523
- code_data ['amazon-height'] = $("#amazon-height-" + block).val ();
3524
- code_data ['amazon-amp-block-on-consent'] = $("#amazon-amp-block-on-consent-" + block).is(":checked") ? '' : '#';
3525
- break;
3526
- case AI_CODE_UNKNOWN:
3527
- // if (debug) console.log ("AI GENERATE CODE:", code_type);
3528
- break;
3529
- }
3530
-
3531
- if (debug) {
3532
- console.log ("AI GENERATE CODE:", code_type);
3533
- console.log (code_data);
3534
- }
3535
-
3536
- $.post (ajaxurl, code_data
3537
- ).done (function (code_data) {
3538
- if (code_data != '') {
3539
- var code = JSON.parse (code_data);
3540
- if (typeof code !== "undefined")
3541
- set_editor_text (block, code);
3542
- }
3543
- }).fail (function (xhr, status, error) {
3544
- console.log ("AI GENERATE CODE ERROR:", xhr.status, xhr.statusText);
3545
- $('#ai-error-container').text (ai_admin.error + ' ' + xhr.status + ': ' + xhr.statusText).show ();
3546
- }).always (function() {
3547
- $("#generate-code-"+block).next ("label").find ('.checkbox-icon').removeClass("on");
3548
- });
3549
- });
3550
-
3551
- $("#clear-block-"+tab).click (function () {
3552
- paste_from_clipboard (true, true, true, true);
3553
- });
3554
-
3555
- $("#copy-block-"+tab).click (function () {
3556
- copy_to_clipboard ();
3557
- });
3558
-
3559
- $("#paste-name-"+tab).click (function () {
3560
- paste_from_clipboard (true, false, false, false);
3561
- });
3562
-
3563
- $("#paste-code-"+tab).click (function () {
3564
- paste_from_clipboard (false, true, false, false);
3565
- });
3566
-
3567
- $("#paste-settings-"+tab).click (function () {
3568
- paste_from_clipboard (false, false, true, false);
3569
- });
3570
-
3571
- $("#paste-block-"+tab).click (function () {
3572
- paste_from_clipboard (true, true, true, false);
3573
- });
3574
-
3575
- $("#rotation-"+tab).click (function () {
3576
- var block = $(this).attr('id').replace ("rotation-", "");
3577
- var rotation_container = $('#ai-rotation-container-' + block);
3578
- $(this).next ("label").find ('.checkbox-icon').toggleClass("on");
3579
-
3580
- rotation_container.toggle();
3581
-
3582
- var option_tabs = rotation_container.tabs ();
3583
-
3584
- var ul = option_tabs.find ("ul");
3585
-
3586
- if (rotation_container.is(':visible')) {
3587
- rotation_container.data ('code', b64e (get_editor_text (block)));
3588
- rotation_container.data ('option', 1);
3589
-
3590
- add_rotate_options (block, 1);
3591
- option_tabs.tabs ("option", "active", 0);
3592
-
3593
- $('input[name=ai_save]').css ('color', '#f00');
3594
- // $('.ai-rotation-warning').show ();
3595
-
3596
- setTimeout (function() {import_rotation_code (block);}, 5);
3597
- } else {
3598
- // set_editor_text (block, b64d (rotation_container.data ('code')));
3599
- generate_rotatation_code (block);
3600
-
3601
- ul.find ("li").remove ();
3602
- var div = option_tabs.find ("div.rounded").remove ();
3603
- }
3604
- });
3605
-
3606
- $("#add-option-"+tab).click (function () {
3607
- var block = $(this).attr('id').replace ("add-option-", "");
3608
- add_rotate_options (block, 1);
3609
-
3610
- $('#ai-rotation-container-' + block).find ("ul").find ("li").slice (- 1).click ();
3611
- });
3612
-
3613
- $("#remove-option-"+tab).click (function () {
3614
- var block = $(this).attr('id').replace ("remove-option-", "");
3615
- remove_rotate_option (block, $('#ai-rotation-container-' + block).tabs ("option", "active"));
3616
- });
3617
-
3618
- $("#rotation-groups-"+tab).click (function () {
3619
- var block = $(this).attr('id').tabIndex ();
3620
- var label = $(this).next ().find ('span');
3621
- label.toggleClass ('on');
3622
- var rotation_container = $('#ai-rotation-container-' + block);
3623
- if (label.hasClass ('on')) {
3624
- rotation_container.find ('span.group-name-label').show ();
3625
- rotation_container.find ('span.option-name-label').hide ();
3626
- rotation_container.find ('td.option-parameters').hide ();
3627
- } else {
3628
- rotation_container.find ('span.group-name-label').hide ();
3629
- rotation_container.find ('span.option-name-label').show ();
3630
- rotation_container.find ('td.option-parameters').show ();
3631
- }
3632
- });
3633
-
3634
- $("#tab-" + tab + " .adsense-list").click (function () {
3635
- $(this).blur ();
3636
-
3637
- toggle_adsense_list ();
3638
- });
3639
-
3640
- $("select#html-element-insertion-"+tab).change (function() {
3641
- var html_element_insertion = $("select#html-element-insertion-"+tab+" option:selected").attr('value');
3642
-
3643
- if (html_element_insertion == AI_HTML_INSERTION_SEREVR_SIDE)
3644
- $("#server-side-insertion-"+tab).hide (); else
3645
- $("#server-side-insertion-"+tab).show ();
3646
- });
3647
-
3648
- $("#tab-" + tab + " .adsense-ad-size").scombobox({
3649
- showDropDown: false,
3650
- invalidAsValue: true,
3651
- animation: {
3652
- duration: 50,
3653
- }
3654
- });
3655
-
3656
- $("select#close-button-" + tab).change (function () {
3657
- var block = $(this).attr('id').replace ("close-button-", "");
3658
- $("select#close-button-sticky-"+block+"").val ($("select#close-button-"+block+" option:selected").attr('value'));
3659
- });
3660
-
3661
- $("select#close-button-sticky-" + tab).change (function () {
3662
- var block = $(this).attr('id').replace ("close-button-sticky-", "");
3663
- $("select#close-button-"+block+"").val ($("select#close-button-sticky-"+block+" option:selected").attr('value'));
3664
- });
3665
-
3666
- // $("input#paragraph-numbers-" + tab).change (function () {
3667
- // var block = $(this).attr('id').tabIndex ();
3668
- // $("input#image-numbers-"+block).val ($(this).attr ('value'));
3669
- // });
3670
-
3671
- // $("input#image-numbers-" + tab).change (function () {
3672
- // var block = $(this).attr('id').tabIndex ();
3673
- // $("input#paragraph-numbers-"+block).val ($(this).attr ('value'));
3674
- // });
3675
-
3676
- $("input#filter-numbers-insertions-" + tab).on ('keyup', function () {
3677
- var block = $(this).attr('id').tabIndex ();
3678
- // $("input#filter-numbers-"+block).val ($(this).attr ('value'));
3679
- $("input#filter-numbers-"+block).val ($(this).val ());
3680
- $("select#filter-type-"+block).val (0);
3681
- $("input#invert-filter-"+block).removeAttr ('checked');
3682
- });
3683
-
3684
- $("input#filter-numbers-" + tab).on ('keyup', function () {
3685
- var block = $(this).attr('id').tabIndex ();
3686
- // $("input#filter-numbers-insertions-"+block).val ($(this).attr ('value'));
3687
- $("input#filter-numbers-insertions-"+block).val ($(this).val ());
3688
- });
3689
-
3690
- $("#html-elements-button-"+tab).click (function () {
3691
- var block = $(this).attr('id').replace ("html-elements-button-", "");
3692
-
3693
- var selector = $("input#html-elements-" + block).val ();
3694
- var home_url = $("#ai-settings").data ('home-relative-url');
3695
- var window_top = screen.availTop;
3696
- var window_left = screen.availLeft;
3697
- var window_width = screen.availWidth - 15;
3698
- var window_height = screen.availHeight - 65;
3699
-
3700
- var param = {
3701
- 'html_element_selection': block,
3702
- 'selector': selector,
3703
- 'input': "input#html-elements-" + block
3704
- };
3705
- open_popup_window_post (home_url, 'width='+window_width+',height='+window_height+',top='+window_top+',left='+window_left+',resizable=yes,scrollbars=yes,toolbar=no,location=no,directories=no,status=no,menubar=no', 'ai-selector', param);
3706
- });
3707
-
3708
- $("#wait-for-button-"+tab).click (function () {
3709
- var block = $(this).attr('id').replace ("wait-for-button-", "");
3710
-
3711
- var selector = $("input#wait-for-" + block).val ();
3712
- var home_url = $("#ai-settings").data ('home-relative-url');
3713
- var window_top = screen.availTop;
3714
- var window_left = screen.availLeft;
3715
- var window_width = screen.availWidth - 15;
3716
- var window_height = screen.availHeight - 65;
3717
-
3718
- var param = {
3719
- 'html_element_selection': block,
3720
- 'selector': selector,
3721
- 'input': "input#wait-for-" + block
3722
- };
3723
- open_popup_window_post (home_url, 'width='+window_width+',height='+window_height+',top='+window_top+',left='+window_left+',resizable=yes,scrollbars=yes,toolbar=no,location=no,directories=no,status=no,menubar=no', 'ai-selector', param);
3724
- });
3725
-
3726
- $("#select-bkg-image-button-"+tab).click (function (event) {
3727
- $(this).blur ();
3728
-
3729
- var block = $(this).attr('id').replace ("select-bkg-image-button-", "");
3730
- var frame;
3731
-
3732
- event.preventDefault();
3733
-
3734
- if (frame) {
3735
- frame.open();
3736
- return;
3737
- }
3738
-
3739
- frame = wp.media ({
3740
- title: ai_admin.select_background_image,
3741
- button: {
3742
- text: ai_admin.use_this_image
3743
- },
3744
- multiple: false // Set to true to allow multiple files to be selected
3745
- });
3746
-
3747
- // frame.on ('open', function(){
3748
- // var selected = $('#banner-image-' + block).attr ('src');
3749
- // if (selected) {
3750
- // var selection = frame.state().get ('selection');
3751
- // var id = $('#banner-image-' + block).attr ('data-id');
3752
- // selection.add (wp.media.attachment (id));
3753
- // }
3754
- // });
3755
-
3756
- frame.on ('select', function() {
3757
- var attachment = frame.state().get('selection').first().toJSON();
3758
- // console.log ('attachment', attachment);
3759
- $('#bkg-image-' + block).attr ('src', attachment.url);
3760
- $('#bkg-image-url-' + block).val (attachment.url).trigger ("input");
3761
- });
3762
-
3763
- frame.open();
3764
- });
3765
-
3766
- $("#bkg-image-url-" + tab).on ('input', function() {
3767
-
3768
- var block = $(this).attr('id').replace ("bkg-image-url-", "");
3769
- var image = $('#bkg-image-' + block);
3770
-
3771
- var new_image_src = $(this).val ();
3772
- if (new_image_src == '') {
3773
- // new_image_src = '//:0';
3774
- image.hide ();
3775
- $('div#sticky-background-' + block + ' table.ai-settings-table').css ('position', 'relative');
3776
- }
3777
-
3778
- configure_sticky_css (block);
3779
-
3780
- // image.attr ('src', new_image_src).load (function () {
3781
- image.attr ('src', new_image_src).on ('load', function () {
3782
- image.show ();
3783
- $('div#sticky-background-' + block + ' table.ai-settings-table').css ('position', 'inherit');
3784
- $(this).closest ('.ai-banner').removeClass ('ai-banner-top');
3785
- var width = this.naturalWidth;
3786
- var height = this.naturalHeight;
3787
-
3788
- if (width / height > 2 && width > 300) {
3789
- $(this).closest ('.ai-banner').addClass ('ai-banner-top');
3790
- }
3791
- })
3792
- // .error (function() {
3793
- .on ('error', function() {
3794
- if (image.is(':visible')) {
3795
- // image.hide ().attr ('src', '//:0');
3796
- image.hide ().attr ('src', '');
3797
- $('div#sticky-background-' + block + ' table.ai-settings-table').css ('position', 'relative');
3798
- }
3799
- });
3800
- });
3801
- }
3802
-
3803
- function configure_sticky_css (block) {
3804
- var horizontal_position = $("select#horizontal-position-"+block+" option:selected").attr('value');
3805
- var selected_horizontal_position = $("select#horizontal-position-"+block+" option:selected");
3806
-
3807
- var vertical_position = $("select#vertical-position-"+block+" option:selected").attr('value');
3808
- var selected_vertical_position = $("select#vertical-position-"+block+" option:selected");
3809
-
3810
- var background = $("input#background-"+block).is(":checked");
3811
- var body_background = horizontal_position == AI_STICK_HORIZONTAL_CENTER && $("input#body-background-"+block).is(":checked");
3812
-
3813
- if (background) {
3814
- $("#sticky-position-"+block).addClass ('ai-background');
3815
- } else $("#sticky-position-"+block).removeClass ('ai-background');
3816
-
3817
- var custom_vertical_position_css = selected_vertical_position.data ('css-bkg');
3818
-
3819
- if (background && typeof custom_vertical_position_css != 'undefined') {
3820
- if (body_background) {
3821
- var vertical_position_css = $("select#vertical-position-"+block).data ('css-body-bkg');
3822
- } else var vertical_position_css = custom_vertical_position_css;
3823
- } else {
3824
- var custom_vertical_position_css = selected_vertical_position.data ('css-' + horizontal_position);
3825
-
3826
- if (typeof custom_vertical_position_css != 'undefined') var vertical_position_css = custom_vertical_position_css; else
3827
- var vertical_position_css = selected_vertical_position.data ('css');
3828
- }
3829
-
3830
- var custom_horizontal_position_css = selected_horizontal_position.data ('css-bkg');
3831
-
3832
- if (background && typeof custom_horizontal_position_css != 'undefined') {
3833
- var horizontal_position_css = custom_horizontal_position_css;
3834
- } else {
3835
- var custom_horizontal_position_css = selected_horizontal_position.data ('css-' + vertical_position);
3836
-
3837
- if (typeof custom_horizontal_position_css != 'undefined') var horizontal_position_css = custom_horizontal_position_css; else
3838
- var horizontal_position_css = selected_horizontal_position.data ('css');
3839
- }
3840
-
3841
- var background_css = '';
3842
- if (horizontal_position == AI_STICK_HORIZONTAL_CENTER && background) {
3843
- // var background_color = $("input#bkg-color-"+block).attr('value').trim ();
3844
- var background_color = $("input#bkg-color-"+block).val ().trim ();
3845
- if (background_color != '') {
3846
- background_css = background_css + ' background-color: ' + background_color + ';';
3847
- }
3848
-
3849
- // var background_image = $("input#bkg-image-url-"+block).attr('value').trim ();
3850
- var background_image = $("input#bkg-image-url-"+block).val ().trim ();
3851
- if (background_image != '') {
3852
- background_css = background_css + ' background-image: url(' + background_image + ');';
3853
- }
3854
-
3855
- var background_size = parseInt ($("select#bkg-size-"+block+" option:selected").attr('value'));
3856
- if (background_size != AI_BACKGROUND_SIZE_DEFAULT) {
3857
- switch (background_size) {
3858
- case AI_BACKGROUND_SIZE_COVER:
3859
- background_css = background_css + ' background-size: cover;';
3860
- break;
3861
- case AI_BACKGROUND_SIZE_CONTAIN:
3862
- background_css = background_css + ' background-size: contain;';
3863
- break;
3864
- case AI_BACKGROUND_SIZE_FILL:
3865
- background_css = background_css + ' background-size: 100% 100%;';
3866
- break;
3867
- }
3868
- }
3869
-
3870
- var background_repeat = parseInt ($("select#bkg-repeat-"+block+" option:selected").attr('value'));
3871
- if (background_repeat != AI_BACKGROUND_REPEAT_DEFAULT) {
3872
- switch (background_repeat) {
3873
- case AI_BACKGROUND_REPEAT_NO:
3874
- background_css = background_css + ' background-repeat: no-repeat;';
3875
- break;
3876
- case AI_BACKGROUND_REPEAT_YES:
3877
- background_css = background_css + ' background-repeat: repeat;';
3878
- break;
3879
- case AI_BACKGROUND_REPEAT_HORIZONTALY:
3880
- background_css = background_css + ' background-repeat: repeat-x;';
3881
- break;
3882
- case AI_BACKGROUND_REPEAT_VERTICALLY:
3883
- background_css = background_css + ' background-repeat: repeat-y;';
3884
- break;
3885
- case AI_BACKGROUND_REPEAT_SPACE:
3886
- background_css = background_css + ' background-repeat: space;';
3887
- break;
3888
- case AI_BACKGROUND_REPEAT_ROUND:
3889
- background_css = background_css + ' background-repeat: round;';
3890
- break;
3891
- }
3892
- }
3893
- }
3894
-
3895
- $('#css-sticky-' + block + ' .ai-sticky-css').text (vertical_position_css + horizontal_position_css + background_css);
3896
-
3897
- check_insertion (block);
3898
- }
3899
-
3900
- function check_insertion (block) {
3901
- $('#sticky-scroll-warning-' + block).hide ();
3902
- var automatic_insertion = $("select#insertion-type-"+block+" option:selected").attr('value');
3903
- var alignment_style = $("select#block-alignment-"+block+" option:selected").attr('value');
3904
- var vertical_position = $("select#vertical-position-"+block+" option:selected").attr('value');
3905
- var background = $("input#background-"+block).is(":checked") ? 1 : 0;
3906
- var body_background = $("input#body-background-"+block).is(":checked") ? 1 : 0;
3907
-
3908
- if (alignment_style == AI_ALIGNMENT_STICKY && vertical_position == AI_SCROLL_WITH_THE_CONTENT && automatic_insertion != AI_ABOVE_HEADER && automatic_insertion != AI_DISABLED && !(background && body_background)) {
3909
- $('#sticky-scroll-warning-' + block).show ();
3910
- }
3911
- }
3912
-
3913
- function configure_selection_icons (block) {
3914
- var css_code_container = $('#icons-css-code-'+block);
3915
- if (!css_code_container.hasClass ('configured')) {
3916
- var titles = new Array();
3917
- $("select#insertion-type-"+block).imagepicker({hide_select: false}).find ('option').each (function (index) {
3918
- titles.push ($(this).data ('title'));
3919
- });
3920
- $("select#insertion-type-"+block+" + ul").appendTo("#automatic-insertion-"+block).css ('padding-top', '10px').find ('li').each (function (index) {
3921
- $(this).attr ('title', titles [index])
3922
- .tooltip({
3923
- track: true,
3924
- delay: 700,
3925
- showURL: false,
3926
- showBody: " | ",
3927
- fade: 250
3928
- });
3929
- });
3930
-
3931
- var titles = new Array();
3932
- $("select#block-alignment-"+block).imagepicker({hide_select: false}).find ('option').each (function (index) {
3933
- titles.push ($(this).data ('title'));
3934
- });
3935
- $("select#block-alignment-"+block+" + ul").appendTo("#alignment-style-"+block).css ('padding-top', '10px').find ('li').each (function (index) {
3936
- $(this).attr ('title', titles [index])
3937
- .tooltip({
3938
- track: true,
3939
- delay: 700,
3940
- showURL: false,
3941
- showBody: " | ",
3942
- fade: 250
3943
- });
3944
- });
3945
-
3946
- var titles = new Array();
3947
- $("select#horizontal-position-"+block).imagepicker({hide_select: false}).find ('option').each (function (index) {
3948
- titles.push ($(this).data ('title'));
3949
- });
3950
- $("select#horizontal-position-"+block+" + ul").appendTo("#horizontal-positions-"+block).css ('padding-top', '10px').find ('li').each (function (index) {
3951
- $(this).attr ('title', titles [index])
3952
- .tooltip({
3953
- track: true,
3954
- delay: 700,
3955
- showURL: false,
3956
- showBody: " | ",
3957
- fade: 250
3958
- });
3959
- });
3960
-
3961
- var titles = new Array();
3962
- $("select#vertical-position-"+block).imagepicker({hide_select: false}).find ('option').each (function (index) {
3963
- titles.push ($(this).data ('title'));
3964
- });
3965
- $("select#vertical-position-"+block+" + ul").appendTo("#vertical-positions-"+block).css ('padding-top', '10px').find ('li').each (function (index) {
3966
- $(this).attr ('title', titles [index])
3967
- .tooltip({
3968
- track: true,
3969
- delay: 700,
3970
- showURL: false,
3971
- showBody: " | ",
3972
- fade: 250
3973
- });
3974
- });
3975
-
3976
- // var titles = new Array();
3977
- // $("select#close-button-"+block).imagepicker({hide_select: false}).find ('option').each (function (index) {
3978
- // titles.push ($(this).data ('title'));
3979
- // });
3980
- // $("select#close-button-sticky-"+block+" + ul").appendTo("#close-buttons-"+block).css ('padding-top', '10px').find ('li').each (function (index) {
3981
- // $(this).attr ('title', titles [index])
3982
- // .tooltip({
3983
- // track: true,
3984
- // delay: 700,
3985
- // showURL: false,
3986
- // showBody: " | ",
3987
- // fade: 250
3988
- // });
3989
- // });
3990
-
3991
- css_code_container.addClass ('configured');
3992
- }
3993
- }
3994
-
3995
- function import_rotation_code (block) {
3996
- $("#rotation-"+block).next ("label").find ('.checkbox-icon').addClass("active");
3997
-
3998
- // var nonce = $("#ai-form").attr ('nonce');
3999
-
4000
- $.post (ajaxurl, {'action': 'ai_ajax_backend', 'ai_check': ai_nonce, 'import-rotation-code': b64e (get_editor_text (block))}
4001
- ).done (function (data) {
4002
- if (data != '') {
4003
- var code_data = JSON.parse (data);
4004
- if (typeof code_data !== "undefined" && typeof code_data ['options'] !== "undefined") {
4005
- $('#ai-error-container').hide ();
4006
-
4007
- var options = code_data ['options'].length;
4008
-
4009
- if (debug) {
4010
- console.log ("AI IMPORT ROTATION CODE:", options);
4011
- console.log (" OPTIONS:", code_data ['options']);
4012
- }
4013
-
4014
- var rotation_container = $('#ai-rotation-container-' + block);
4015
- rotation_container.find ("ul").find ("li").remove ();
4016
- rotation_container.find ("div.rounded").remove ();
4017
-
4018
- var tabs = options;
4019
- if (tabs < 1) tabs = 1;
4020
- if (tabs > 17) tabs = 17;
4021
-
4022
- add_rotate_options (block, tabs);
4023
-
4024
- rotation_container.find ('ul li').each (function (index) {
4025
- if (index < options) $(this).data ('code', b64e (code_data ['options'][index]['code'])); else
4026
- $(this).data ('code', b64e (''));
4027
- });
4028
-
4029
- rotation_container.tabs ("option", "active", 0);
4030
-
4031
- set_editor_text (block, code_data ['options'][0]['code']);
4032
-
4033
- rotation_container.find ('input.option-name').each (function (index) {
4034
- if (index < options) $(this).val (code_data ['options'][index]['name']);
4035
- });
4036
- rotation_container.find ('input.option-share').each (function (index) {
4037
- if (index < options) $(this).val (code_data ['options'][index]['share']);
4038
- });
4039
- rotation_container.find ('input.option-time').each (function (index) {
4040
- if (index < options) $(this).val (code_data ['options'][index]['time']);
4041
- });
4042
- rotation_container.find ('input.option-scheduling').each (function (index) {
4043
- if (index < options) $(this).val (code_data ['options'][index]['scheduling']);
4044
- });
4045
-
4046
- var group_label = $("#rotation-groups-" + block).next ().find ('span');
4047
- if (code_data ['options'][0]['groups']) {
4048
- group_label.removeClass ('on');
4049
- } else {
4050
- group_label.addClass ('on');
4051
- }
4052
- $("#rotation-groups-" + block).click ();
4053
- }
4054
- }
4055
- }).fail (function (xhr, status, error) {
4056
- console.log ("AI IMPORT ROTATION CODE ERROR:", xhr.status, xhr.statusText);
4057
- $('#ai-error-container').text (ai_admin.error + ' ' + xhr.status + ': ' + xhr.statusText).show ();
4058
-
4059
- var rotation_container = $('#ai-rotation-container-' + block);
4060
- set_editor_text (block, b64d (rotation_container.data ('code')));
4061
- rotation_container.hide();
4062
- $("#rotation-" + block).next ("label").find ('.checkbox-icon').removeClass("on");
4063
-
4064
- rotation_container.find ("ul").find ("li").remove ();
4065
- rotation_container.find ("div.rounded").remove ();
4066
- }).always (function() {
4067
- $("#rotation-"+block).next ("label").find ('.checkbox-icon').removeClass("active");
4068
- });
4069
- }
4070
-
4071
- function generate_rotatation_code (block) {
4072
- $("#rotation-"+block).next ("label").find ('.checkbox-icon').addClass("active");
4073
-
4074
- var rotation_container = $('#ai-rotation-container-' + block);
4075
- var option = rotation_container.tabs ("option", "active") + 1;
4076
-
4077
- $(('#option-' + block + '-' + option)).data ('code', b64e (get_editor_text (block)));
4078
-
4079
- // var nonce = $("#ai-form").attr ('nonce');
4080
-
4081
- var rotation_data = [];
4082
- rotation_container.find ("div.rounded").each (function (index) {
4083
- var code_data = $('#option-' + block + '-' + (index + 1)).data ('code');
4084
- var code = typeof code_data == 'undefined' ? '' : b64d (code_data);
4085
- var group_rotation = $("#rotation-groups-" + block).next ().find ('span').hasClass ('on');
4086
- var option_data = {
4087
- 'name': $(this).find ('input.option-name').val (),
4088
- 'share': $(this).find ('input.option-share').val (),
4089
- 'scheduling': $(this).find ('input.option-scheduling').val (),
4090
- 'time': $(this).find ('input.option-time').val (),
4091
- 'code': code, 'groups': group_rotation
4092
- };
4093
-
4094
- rotation_data.push (option_data);
4095
- });
4096
-
4097
- if (debug) console.log ('ROTATION DATA:', rotation_data);
4098
-
4099
- $.post (ajaxurl, {'action': 'ai_ajax_backend', 'ai_check': ai_nonce, 'generate-rotation-code': b64e (JSON.stringify (rotation_data))}
4100
- ).done (function (data) {
4101
- $('#ai-error-container').hide ();
4102
-
4103
- if (data != '') {
4104
- var rotation_code = JSON.parse (data);
4105
- if (typeof rotation_code !== "undefined") {
4106
- if (debug) console.log ('ROTATION CODE:', rotation_code);
4107
- set_editor_text (block, rotation_code);
4108
- }
4109
- }
4110
-
4111
- }).fail (function (xhr, status, error) {
4112
- console.log ("AI GENERATE ROTATION CODE ERROR:", xhr.status, xhr.statusText);
4113
- $('#ai-error-container').text (ai_admin.error + ' ' + xhr.status + ': ' + xhr.statusText).show ();
4114
-
4115
- var rotation_container = $('#ai-rotation-container-' + block);
4116
- set_editor_text (block, b64d (rotation_container.data ('code')));
4117
- rotation_container.hide();
4118
- $("#rotation-" + block).next ("label").find ('.checkbox-icon').removeClass("on");
4119
-
4120
- rotation_container.find ("ul").find ("li").remove ();
4121
- rotation_container.find ("div.rounded").remove ();
4122
- }).always (function() {
4123
- $("#rotation-"+block).next ("label").find ('.checkbox-icon').removeClass("active");
4124
-
4125
- $('input[name=ai_save]').css ('color', '#555');
4126
- // $('.ai-rotation-warning').hide ();
4127
- });
4128
- }
4129
-
4130
- function add_rotate_options (block, new_options) {
4131
- var rotation_container = $('#ai-rotation-container-' + block);
4132
- var ul = rotation_container.find ("ul");
4133
- var options = rotation_container.find ('ul >li').length;
4134
-
4135
- var rotation_tabs = $('#rotation-tabs');
4136
- var li = rotation_tabs.find ("li");
4137
- var div = rotation_tabs.find ("div.rounded");
4138
-
4139
- var insertion = 0;
4140
-
4141
- for (option = options + 1; option <= options + new_options; option ++) {
4142
- if (option > 17) break;
4143
-
4144
- var new_li = li.clone ().show ();
4145
- new_li.find ("a").attr ('href', '#tab-option-' + block + '-' + option).text (String.fromCharCode (64 + option));
4146
- new_li.attr ('id', 'option-' + block + '-' + option).appendTo (ul).data ('code', b64e (''));
4147
-
4148
- new_li.click (function () {
4149
- var rotation_container = $(this).closest ('.ai-rotate');
4150
- var block = rotation_container.attr('id').replace ("ai-rotation-container-", "");
4151
- var old_option = rotation_container.data ('option');
4152
- var new_option = $(this).attr('id').replace ("option-" + block + "-", "");
4153
- rotation_container.data ('option', new_option);
4154
-
4155
- if (debug) console.log ('OPTION CHANGE:', old_option, '=>', new_option);
4156
-
4157
- $(('#option-' + block + '-' + old_option)).data ('code', b64e (get_editor_text (block)));
4158
- set_editor_text (block, b64d ($(this).data ('code')));
4159
- });
4160
-
4161
- div.clone ().show ().attr ('id', 'tab-option-' + block + '-' + option).appendTo (rotation_container);
4162
-
4163
- rotation_container.tabs ("refresh");
4164
- }
4165
-
4166
- rotation_container.find ('[data-title]').each (function () {
4167
- $(this).attr ('title', $(this).data ('title'));
4168
- });
4169
-
4170
- rotation_container.find ("[title]").tooltip ({
4171
- track: true,
4172
- delay: 700,
4173
- showURL: false,
4174
- showBody: " | ",
4175
- fade: 250
4176
- });
4177
-
4178
- rotation_container.tabs ("option", "active", option - 2);
4179
- }
4180
-
4181
- function remove_rotate_option (block, option) {
4182
- var rotation_container = $('#ai-rotation-container-' + block);
4183
- var options = rotation_container.find ('ul >li').length;
4184
-
4185
- if (options == 1) return;
4186
-
4187
- var ul = rotation_container.find ("ul");
4188
-
4189
- ul.find ("li").slice (option, option + 1).remove ();
4190
- var div = rotation_container.find ("div.rounded").slice (option, option + 1).remove ();
4191
-
4192
- rotation_container.find ('ul li').each (function (index) {
4193
- var option = index + 1;
4194
- $(this).attr ('id', 'option-' + block + '-' + option).find ("a").attr ('href', '#tab-option-' + block + '-' + option).text (String.fromCharCode (64 + option));
4195
- });
4196
-
4197
- rotation_container.find ("div.rounded").each (function (index) {
4198
- var option = index + 1;
4199
- $(this).attr ('id', 'tab-option-' + block + '-' + option);
4200
- });
4201
-
4202
- rotation_container.tabs ("refresh");
4203
-
4204
- var new_option = option == 0 ? 0 : option - 1;
4205
- active_li = $('#option-' + block + '-' + (new_option + 1));
4206
- set_editor_text (block, b64d (active_li.data ('code')));
4207
- ul.closest ('.ai-rotate').data ('option', new_option + 1);
4208
- }
4209
-
4210
- function create_list_selector (element_name_prefix, index) {
4211
- var select = $('#'+element_name_prefix+'-select-' + index);
4212
- if (select.length !== 0) {
4213
- var button = $('#'+element_name_prefix+'-button-'+index);
4214
-
4215
- var list_prefix = button.data ('list');
4216
- if (list_prefix == null) list_prefix = element_name_prefix;
4217
-
4218
- function update_list (list, element_name_prefix) {
4219
- if (typeof before_update_selection_from_list == 'function') {
4220
- before_update_selection_from_list (index);
4221
- }
4222
-
4223
- button.find ('span.ui-button-text').addClass ('ai-button-updating');
4224
-
4225
- setTimeout (function() {
4226
- update_selection_from_list (list, element_name_prefix);
4227
- }, 5);
4228
- }
4229
-
4230
- button.click (function () {
4231
- if (!select.hasClass ('multi-select')) {
4232
- var options = select.find ('option');
4233
- if (options.length == 0) {
4234
- // var nonce = $("#ai-form").attr ('nonce');
4235
-
4236
- var filter_element = $('#ms-'+element_name_prefix+'-select-' + index).find ('.filter-input');
4237
- var filter = filter_element.length ? filter_element.val () : '';
4238
-
4239
- var parameters_data = select.data ('parameters');
4240
- var parameters = typeof parameters_data == 'undefined' ? '' : parameters_data;
4241
-
4242
- $('#ai-loading').show ();
4243
- button.find ('span.ui-button-text').addClass ('ai-button-active').show ();
4244
-
4245
- $.get (ajaxurl + '?action=ai_ajax_backend&list-options=' + element_name_prefix + '&parameters=' + parameters + '&filter=' + filter + '&ai_check=' + ai_nonce, function (data) {
4246
- if (data != '') {
4247
- var message = '';
4248
- var options = $('option', '<div>'+data+'</div>');
4249
- if (options.length != 0) {
4250
- if ($(options [0]).attr ('value').length == 0) {
4251
- message = $(options [0]).text ();
4252
- options = options.splice (1);
4253
- }
4254
- }
4255
- select.attr ('data-message', message);
4256
-
4257
- select.html (options);
4258
- create_multi_select (select, element_name_prefix, list_prefix, index);
4259
-
4260
- $('#ms-'+element_name_prefix+'-select-' + index).find ('.filter-message').text (message);
4261
-
4262
- update_list ($('#'+list_prefix+'-list-'+index), element_name_prefix);
4263
- }
4264
-
4265
- }).fail (function (xhr, status, error) {
4266
- $('input.filter-input', selection_container).remove ();
4267
- var message = "Error loading " + element_name_prefix + " options: " + xhr.status + " " + xhr.statusText ;
4268
- console.log (message);
4269
- })
4270
- .always (function () {
4271
- $('#ai-loading').hide ();
4272
- button.find ('span.ui-button-text').removeClass ('ai-button-active');
4273
- });
4274
-
4275
- } else create_multi_select (select, element_name_prefix, list_prefix, index);
4276
-
4277
- } else {
4278
- update_list ($('#'+list_prefix+'-list-'+index), element_name_prefix);
4279
- $('#ms-'+element_name_prefix+'-select-'+index).toggle();
4280
- }
4281
- });
4282
-
4283
-
4284
- $('#'+list_prefix+'-list-'+index).focusout (function () {
4285
- var selection_container = $('#ms-'+element_name_prefix+'-select-'+index);
4286
- if (selection_container.length && selection_container.is (':visible')) {
4287
- update_list ($(this), element_name_prefix);
4288
- }
4289
- });
4290
- }
4291
- }
4292
-
4293
- function update_list_from_selection (select_element, element_name_prefix, list_prefix) {
4294
-
4295
- var ms = select_element.$element;
4296
- var ms_val = ms.val();
4297
- if (ms_val != null) {
4298
- if (ms_val [0] == '') {
4299
- ms_val = ms_val.splice (1)
4300
- }
4301
- ms_val = ms_val.join (', ').trim (',');
4302
- }
4303
- var index = ms.attr ('id').replace (element_name_prefix+'-select-','');
4304
- var list = $('#'+list_prefix+'-list-'+index);
4305
-
4306
- var custom_data = list.attr ('data-custom');
4307
-
4308
- if (typeof custom_data != 'undefined' && custom_data != '') {
4309
- if (ms_val != null) {
4310
- if (ms_val != '') ms_val = ms_val + ', ';
4311
- ms_val = ms_val + custom_data;
4312
- } else ms_val = custom_data;
4313
- }
4314
-
4315
- list.attr ('value', ms_val);
4316
- select_element.qs1.cache();
4317
- // select_element.qs2.cache();
4318
- }
4319
-
4320
- function update_selection_from_list (list_element, element_name_prefix) {
4321
-
4322
- Array.prototype.diff = function (a) {
4323
- return this.filter(function (i) {
4324
- return a.indexOf(i) === -1;
4325
- });
4326
- };
4327
-
4328
- var index = list_element.attr ('id').replace (/^\D+/g, '');
4329
- var select = $('#'+element_name_prefix+'-select-'+index);
4330
- var selection_container = $('#ms-'+element_name_prefix+'-select-'+index);
4331
-
4332
- if (selection_container.is(':visible')) {
4333
- var list_items = list_element.attr ('value').split (',').map (Function.prototype.call, String.prototype.trim);
4334
-
4335
- if (list_items [0] == '') {
4336
- list_items = list_items.splice (1)
4337
- }
4338
-
4339
- if (list_element.hasClass ('ai-list-filter'))
4340
- for (var i = 0; i < list_items.length; i++) {
4341
- list_items [i] = list_items [i].replace (/ /g , '-').replace (/[\!\@\#\$%\^&\*\(\)\=\+\{\}\|\[\]\\\;\'\:\"\.\/\?]/g , '');
4342
- }
4343
-
4344
- if (list_element.hasClass ('ai-list-filter-cat'))
4345
- for (var i = 0; i < list_items.length; i++) {
4346
- list_items [i] = list_items [i].replace (/ /g , '-').replace (/[\!\@\#\$%\^&\(\)\=\{\}\|\[\]\\\;\'\:\"\.\/\?]/g , '');
4347
- }
4348
-
4349
- if (list_element.hasClass ('ai-list-uppercase')) list_items = list_items.map (Function.prototype.call, String.prototype.toUpperCase); else
4350
- if (list_element.hasClass ('ai-list-lowercase')) list_items = list_items.map (Function.prototype.call, String.prototype.toLowerCase); else
4351
- if (list_element.hasClass ('ai-list-country-case')) {
4352
- var list_items = list_items.map (function callback (currentValue) {
4353
- var data = currentValue.split (':');
4354
- if (data [0] != null) data [0] = data [0].toUpperCase ();
4355
- if (data [1] != null) data [1] = data [1].toUpperCase ();
4356
- if (data [2] != null) data [2] = data [2].toLowerCase ();
4357
- return data.join (':');
4358
- });
4359
- }
4360
-
4361
- $('#'+element_name_prefix+'-select-'+index).multiSelect('refresh').multiSelect ('deselect_all').multiSelect ('select', list_items);
4362
-
4363
- if (list_element.hasClass ('ai-list-custom')) {
4364
- var custom_values = list_items;
4365
- var selected_values = $('#'+element_name_prefix+'-select-'+index).val ();
4366
-
4367
- if (selected_values != null) custom_values = list_items.diff (selected_values);
4368
- if (custom_values != null) custom_values = custom_values.join (', ');
4369
-
4370
- list_element.attr ('data-custom', custom_values);
4371
-
4372
- select.multiSelect ('deselect_all').multiSelect ('select', list_items);
4373
- }
4374
-
4375
- if (select.hasClass ('ai-list-filter')) {
4376
- var filter_div = $('#ms-'+element_name_prefix+'-select-'+index).find ('.ai-list-filter-container');
4377
- var filter_input = filter_div.find ('.filter-input');
4378
- var filter_button = filter_div.find ('.filter-button');
4379
-
4380
- if (!filter_div.hasClass ('configured')) {
4381
- filter_div.addClass ('configured');
4382
-
4383
- filter_input.on ('keyup keypress', function(e) {
4384
- var keyCode = e.keyCode || e.which;
4385
- if (keyCode === 13) {
4386
- e.preventDefault();
4387
- filter_button.click ();
4388
- return false;
4389
- }
4390
- });
4391
-
4392
- filter_button.on ('click', function(e) {
4393
- e.preventDefault();
4394
-
4395
- var filter = filter_input.val ();
4396
- select.attr ('data-filter', filter);
4397
-
4398
- select.empty ();
4399
- select.removeClass ('multi-select');
4400
- $('#'+element_name_prefix+'-button-'+index).click ();
4401
-
4402
- return false;
4403
- });
4404
- }
4405
-
4406
- filter_div.show ();
4407
- $('#ms-'+element_name_prefix+'-select-'+index).find ('.search-input').hide ();
4408
- filter_button.button().show ();
4409
- filter_input.val (select.attr ('data-filter'));
4410
- $('#ms-'+element_name_prefix+'-select-' + index).find ('.filter-message').text (select.attr ('data-message'));
4411
- }
4412
- }
4413
-
4414
- var button = $('#'+element_name_prefix+'-button-'+index);
4415
- button.find ('span.ui-button-text').removeClass ('ai-button-updating');
4416
- }
4417
-
4418
- function create_multi_select (select, element_name_prefix, list_prefix, index) {
4419
- select.addClass ('multi-select');
4420
-
4421
- select.multiSelect ({
4422
- selectableHeader:
4423
- '<div class="ai-list-filter-container"> \
4424
- <input type="text" class="filter-input" autocomplete="off" placeholder="' + ai_admin.filter + '" title="' + ai_admin.filter_title + '"> \
4425
- <button class="filter-button" style="margin-top: -2px; display: none;">' + ai_admin.button_filter + '</button> \
4426
- <span class="filter-message"></span> \
4427
- </div> \
4428
- <input type="text" class="search-input" autocomplete="off" placeholder="' + ai_admin.search + '">',
4429
- selectionHeader: '',
4430
- afterInit: function(ms){
4431
- var that = this,
4432
- $selectableSearch = that.$selectableUl.prev(),
4433
- $selectionSearch = that.$selectionUl.prev(),
4434
- selectableSearchString = '#'+that.$container.attr('id')+' .ms-elem-selectable:not(.ms-selected)',
4435
- selectionSearchString = '#'+that.$container.attr('id')+' .ms-elem-selection.ms-selected';
4436
-
4437
- that.qs1 = $selectableSearch.quicksearch (selectableSearchString)
4438
- .on('keydown', function(e){
4439
- if (e.which === 40){
4440
- that.$selectableUl.focus();
4441
- return false;
4442
- }
4443
- });
4444
-
4445
- // that.qs2 = $selectionSearch.quicksearch (selectionSearchString)
4446
- // .on('keydown', function(e){
4447
- // if (e.which == 40){
4448
- // that.$selectionUl.focus();
4449
- // return false;
4450
- // }
4451
- // });
4452
- },
4453
- afterSelect: function(values){
4454
- update_list_from_selection (this, element_name_prefix, list_prefix);
4455
- },
4456
- afterDeselect: function(values){
4457
- update_list_from_selection (this, element_name_prefix, list_prefix);
4458
- }
4459
- });
4460
-
4461
- // $('#ms-'+element_name_prefix+'-select-' + index).hide();
4462
- }
4463
-
4464
- function create_list_editor (element_name_prefix, index) {
4465
- var editor = $('#'+element_name_prefix+'-editor-'+index);
4466
- var list = $('#'+element_name_prefix+'-list-'+index);
4467
- if (editor.length !== 0) {
4468
- $('#'+element_name_prefix+'-button-'+index).click (function () {
4469
- update_editor_from_list (list, element_name_prefix, true);
4470
- });
4471
-
4472
- editor.focusout (function () {
4473
- update_list_from_editor (editor, element_name_prefix)
4474
- });
4475
-
4476
- list.focusout (function () {
4477
- if (editor.is(':visible'))
4478
- update_editor_from_list ($(this), element_name_prefix, false);
4479
- });
4480
- }
4481
- }
4482
-
4483
- function clean_url_list (list_element, list_items) {
4484
-
4485
- var clean_protocol = list_element.hasClass ('ai-clean-protocol');
4486
- var clean_domain = list_element.hasClass ('ai-clean-domain');
4487
- var only_domain = list_element.hasClass ('ai-only-domain');
4488
- var sort_list = list_element.hasClass ('ai-list-sort');
4489
-
4490
- function onlyUnique (value, index, self) {
4491
- return self.indexOf (value) === index;
4492
- }
4493
-
4494
- list_items = list_items.filter (onlyUnique);
4495
-
4496
- var clean_list_items = [];
4497
-
4498
- for (var i = 0; i < list_items.length; i++) {
4499
- var list_item = list_items [i];
4500
-
4501
- if (clean_protocol && list_item.indexOf ('http') == 0) {
4502
- list_item = list_item.replace ('http://', '');
4503
- list_item = list_item.replace ('https://', '');
4504
-
4505
- var slash = list_item.indexOf ("/");
4506
-
4507
- if (clean_domain) {
4508
- if (slash > 0) {
4509
- list_item = list_item.substring (slash);
4510
- } else list_item = '';
4511
- } else
4512
- if (only_domain) {
4513
- if (slash > 0) {
4514
- list_item = list_item.substring (0, slash);
4515
- }
4516
- }
4517
- }
4518
-
4519
- if (list_item != '') clean_list_items.push (list_item);
4520
- }
4521
-
4522
- if (sort_list) {
4523
- clean_list_items.sort();
4524
- }
4525
-
4526
- return clean_list_items;
4527
- }
4528
-
4529
- function update_editor_from_list (list_element, element_name_prefix, toggle) {
4530
- var index = list_element.attr ('id').replace (element_name_prefix+'-list-','');
4531
- var editor = $('#'+element_name_prefix+'-editor-'+index);
4532
- if (toggle) editor.toggle();
4533
- if (editor.is(':visible')) {
4534
-
4535
- var list = list_element.attr ('value');
4536
- var list_separator = ',';
4537
-
4538
- if (list_element.hasClass ('ai-list-space')) {
4539
- if (list.indexOf (' ') > - 1 && list.indexOf (',') == - 1) list_separator = ' ';
4540
- }
4541
-
4542
- var list_items = list.split (list_separator).map (Function.prototype.call, String.prototype.trim);
4543
-
4544
- clean_list_items = clean_url_list (list_element, list_items);
4545
-
4546
- editor.val (clean_list_items.join ("\n"));
4547
- } else update_list_from_editor (editor, element_name_prefix)
4548
- }
4549
-
4550
- function update_list_from_editor (editor, element_name_prefix) {
4551
- var list_items = editor.val ().split ("\n").map (Function.prototype.call, String.prototype.trim);
4552
-
4553
- var index = editor.attr ('id').replace (element_name_prefix+'-editor-','');
4554
- var list_element = $('#'+element_name_prefix+'-list-'+index);
4555
-
4556
- clean_list_items = clean_url_list (list_element, list_items);
4557
-
4558
- list_element.attr ('value', clean_list_items.join (', '));
4559
- }
4560
-
4561
- function configure_hidden_tab () {
4562
- var current_tab;
4563
- var tab;
4564
-
4565
- if (debug) console.log ("");
4566
- if (debug) {
4567
- var current_time_start = new Date().getTime();
4568
- console.log ("since last time: " + ((current_time_start - last_time) / 1000).toFixed (3));
4569
- }
4570
- if (debug) console.log ("configure_hidden_tab");
4571
- if (debug) console.log ("tabs_to_configure: " + tabs_to_configure);
4572
-
4573
- do {
4574
- if (tabs_to_configure.length == 0) {
4575
- save_enabled = true;
4576
- if (debug_title) $("#plugin_name").css ("color", "#000");
4577
- if (debug) console.log ("configure_hidden_tab: DONE");
4578
- return;
4579
- }
4580
- current_tab = tabs_to_configure.pop();
4581
- tab = $("#tab-" + current_tab);
4582
- } while (tab.hasClass ('configured'));
4583
-
4584
- if (debug) console.log ("Configuring tab: " + current_tab);
4585
-
4586
- if (current_tab != 0) configure_tab (current_tab); else configure_tab_0 ();
4587
-
4588
- if (debug) {
4589
- var current_time = new Date().getTime();
4590
- console.log ("time: " + ((current_time - current_time_start) / 1000).toFixed (3));
4591
- console.log ("TIME: " + ((current_time - start_time) / 1000).toFixed (3));
4592
- last_time = current_time;
4593
- }
4594
-
4595
- // if (tabs_to_configure.length != 0) setTimeout (configure_hidden_tab, 10);
4596
- if (tabs_to_configure.length != 0) {
4597
- if (ai_tab_setup_delay != 0) {
4598
- setTimeout (configure_hidden_tab, ai_tab_setup_delay);
4599
- }
4600
- } else {
4601
- save_enabled = true;
4602
- if (debug_title && ai_tab_setup_delay != 0) $("#plugin_name").css ("color", "#000");
4603
- if (debug) console.log ("configure_hidden_tab: DONE");
4604
- }
4605
- }
4606
-
4607
- function configure_chart (container) {
4608
- var ai_adb_flag_blocked = 0x80;
4609
-
4610
- if (!$(container).hasClass ('not-configured')) return;
4611
- var template = $(container).data ('template');
4612
-
4613
- if (typeof template != 'undefined') {
4614
- var new_colors = [];
4615
- var color_indexes = $(container).data ('colors');
4616
- if (typeof color_indexes != 'undefined') {
4617
- var colors = $.elycharts.templates['ai-pie'].defaultSeries.values;
4618
- color_indexes.forEach (function (element) {
4619
- if (element == ai_adb_flag_blocked )
4620
- new_colors.push (colors [9]); else
4621
- new_colors.push (colors [element]);
4622
- });
4623
- }
4624
-
4625
- var values = $(container).data ('values-1');
4626
- if (values == null) values = $(container).data ('values-2');
4627
- if (values == null) values = $(container).data ('values-3');
4628
- if (values == null) values = $(container).data ('values-4');
4629
- if (values == null) values = $(container).data ('values-5');
4630
- if (values == null) values = $(container).data ('values-6');
4631
- if (values == null) values = $(container).data ('values-7');
4632
- if (values == null) values = $(container).data ('values-8');
4633
- if (values == null) values = $(container).data ('values-9');
4634
-
4635
- var legend = $(container).data ('legend');
4636
- if (typeof legend != 'undefined' && typeof legend ['serie' + (ai_adb_flag_blocked + 1)] != 'undefined') {
4637
- var new_legend = {};
4638
- for (var legend_item in legend) {
4639
- if (legend_item == 'serie' + (ai_adb_flag_blocked + 1))
4640
- new_legend ['serie10'] = legend [legend_item]; else
4641
- new_legend [legend_item] = legend [legend_item];
4642
- }
4643
- legend = new_legend;
4644
- }
4645
-
4646
- $(container).chart({
4647
- template: template,
4648
- labels: $(container).data ('labels'),
4649
- values: {
4650
- serie1: values,
4651
- serie2: $(container).data ('values-2'),
4652
- serie3: $(container).data ('values-3'),
4653
- serie4: $(container).data ('values-4'),
4654
- serie5: $(container).data ('values-5'),
4655
- serie6: $(container).data ('values-6'),
4656
- serie7: $(container).data ('values-7'),
4657
- serie8: $(container).data ('values-8'),
4658
- serie9: $(container).data ('values-9'),
4659
- serie10: $(container).data ('values-' + (ai_adb_flag_blocked + 1)), // BLOCKED
4660
- },
4661
- legend: legend,
4662
- tooltips: {serie1: $(container).data ('tooltips')},
4663
- defaultSeries: {values: new_colors, tooltip: {height: $(container).data ('tooltip-height')}},
4664
- defaultAxis : {
4665
- max: $(container).data ('max'),
4666
- },
4667
- features: {
4668
- grid: {
4669
- draw: values == null ? true : values.length < 50,
4670
- }
4671
- }
4672
- });
4673
-
4674
- $(container).removeClass ('not-configured');
4675
- $(container).parent().find ('div.ai-chart-label').show ();
4676
- }
4677
- }
4678
-
4679
- function update_rating (parameter) {
4680
- var rating_bar = $('#ai-rating-bar');
4681
- // var nonce = rating_bar.attr ('nonce');
4682
- $("#rating-value span").load (ajaxurl+"?action=ai_ajax_backend&rating=" + parameter + "&ai_check=" + ai_nonce, function() {
4683
- var rating = $("#rating-value span").text ();
4684
- var rating_value = 0;
4685
- if (rating != '') var rating_value = parseFloat (rating);
4686
- $("#rating-value").css ('width', rating_value * 20 + '%');
4687
-
4688
- if ($("#rating-value span").text () == '') {
4689
- $("#ai-rating-bar").hide ();
4690
- $('#ai-stars').show ();
4691
- }
4692
- });
4693
- }
4694
-
4695
- function configure_charts (container) {
4696
- $(container).find ('.ai-chart.not-configured').each (function() {
4697
- if (!$(this).hasClass ('hidden')) {
4698
- $(this).attr ('style', '');
4699
- configure_chart (this);
4700
- }
4701
- });
4702
- }
4703
-
4704
- function replace_block_number (element, attribute, old_block, new_block) {
4705
- var attr_value = element.attr (attribute);
4706
- var attr_number = attr_value.substr (- old_block.toString().length);
4707
- if (attr_number == old_block) {
4708
- element.attr (attribute, attr_value.substr (0, attr_value.length - old_block.toString().length) + new_block);
4709
-
4710
- // console.log (attribute, element.attr (attribute));
4711
- }
4712
- }
4713
-
4714
- function copy_to_clipboard () {
4715
- if (debug) console.log ("AI COPY FROM BLOCK", active_tab);
4716
-
4717
- var clipboard = $('#ai-clipboard');
4718
- clipboard.html ($('#ai-clipboard-template').html ());
4719
-
4720
- $('div#tab-' + active_tab + ' input[name]:checkbox').each (function (index){
4721
- var attr = $(this).attr('checked');
4722
- var checked = typeof attr !== typeof undefined && attr !== false;
4723
-
4724
- if (checked)
4725
- clipboard.find ('input[name]:checkbox').eq (index).attr ('checked', 'checked').next ("label").find ('.checkbox-icon').addClass("on"); else
4726
- clipboard.find ('input[name]:checkbox').eq (index).removeAttr ('checked').next ("label").find ('.checkbox-icon').removeClass("on");
4727
- });
4728
-
4729
- $('div#tab-' + active_tab + ' input[name]:radio').each (function (index){
4730
- var attr = $(this).attr('checked');
4731
- var checked = typeof attr !== typeof undefined && attr !== false;
4732
-
4733
- if (checked)
4734
- clipboard.find ('input[name]:radio').eq (index).attr ('checked', 'checked'); else
4735
- clipboard.find ('input[name]:radio').eq (index).removeAttr ('checked');
4736
- });
4737
-
4738
- $('div#tab-' + active_tab + ' select[name]').each (function (index){
4739
- var value = $(this).find ("option:selected").val ();
4740
- clipboard.find ('select[name]').eq (index).find ("option").removeAttr ('selected');
4741
- clipboard.find ('select[name]').eq (index).find ("option[value = '" + value + "']").attr ("selected", true);
4742
- });
4743
-
4744
- $('div#tab-' + active_tab + ' input[name]:text').each (function (index){
4745
- clipboard.find ('input[name]:text').eq (index).attr ('value', $(this).val ());
4746
- });
4747
-
4748
-
4749
- // Lists
4750
- if ($('#list-settings-' + active_tab).is(':visible')) {
4751
- clipboard.find ('#list-settings-999').show ();
4752
- } else {
4753
- clipboard.find ('#list-settings-999').hide ();
4754
- }
4755
-
4756
- if ($('#list-settings-' + active_tab).hasClass('ai-expanded')) {
4757
- clipboard.find ('#list-settings-999').addClass ('ai-expanded');
4758
- } else {
4759
- clipboard.find ('#list-settings-999').removeClass ('ai-expanded');
4760
- }
4761
-
4762
- $('div#tab-' + active_tab + ' table.ai-lists tr').each (function (index){
4763
- if ($(this).is(':visible')) {
4764
- clipboard.find ('table.ai-lists tr').eq (index).show ();
4765
- } else {
4766
- clipboard.find ('table.ai-lists tr').eq (index).hide ();
4767
- }
4768
-
4769
- if ($(this).find ('span.checkbox-list-button').hasClass ('dashicons-no')) {
4770
- clipboard.find ('table.ai-lists tr').eq (index).find ('span.checkbox-list-button').addClass ('dashicons-no').removeClass ('dashicons-yes');
4771
- } else {
4772
- clipboard.find ('table.ai-lists tr').eq (index).find ('span.checkbox-list-button').removeClass ('dashicons-no').addClass ('dashicons-yes');
4773
- }
4774
-
4775
- if ($(this).hasClass ('list-items')) {
4776
- clipboard.find ('table.ai-lists tr').eq (index).addClass ('list-items');
4777
- } else {
4778
- clipboard.find ('table.ai-lists tr').eq (index).removeClass ('list-items');
4779
- }
4780
- });
4781
-
4782
-
4783
- clipboard.find ('textarea.simple-editor').text (get_editor_text (active_tab));
4784
-
4785
- $("#ai-container .ai-copy").each (function () {
4786
- $(this).next ("label").find ('.checkbox-icon').addClass("on");
4787
- });
4788
- }
4789
-
4790
- function load_saved_settings_to_clipboard (block, paste) {
4791
- if (debug) console.log ("AI LOAD BLOCK", block, "FROM DB");
4792
-
4793
- var tools_button = $("#tools-button-" + active_tab);
4794
- if (!tools_button.next ('label').find ('.checkbox-icon').hasClass ("on")) {
4795
- tools_button.click ();
4796
- }
4797
-
4798
- $('#ai-loading').show ();
4799
- // var nonce = $("#ai-form").attr ('nonce');
4800
-
4801
- $.get (ajaxurl + '?action=ai_ajax_backend&settings=' + block + '&single=1&ai_check=' + ai_nonce, function (settings) {
4802
- if (debug) console.log ("AI BLOCK LOADED");
4803
-
4804
- var clipboard = $('#ai-clipboard');
4805
-
4806
- clipboard.html ($('div#tab-' + block, settings).html ());
4807
-
4808
- clipboard.find ('[id]').each (function () {
4809
- replace_block_number ($(this), 'id', block, 999);
4810
- });
4811
-
4812
- clipboard.find ('[for]').each (function () {
4813
- replace_block_number ($(this), 'for', block, 999);
4814
- });
4815
-
4816
- clipboard.find ('[href]').each (function () {
4817
- replace_block_number ($(this), 'href', block, 999);
4818
- });
4819
-
4820
- clipboard.find ('[name]').each (function () {
4821
- replace_block_number ($(this), 'name', block, 999);
4822
- });
4823
-
4824
- clipboard.find ('[class]').each (function () {
4825
- replace_block_number ($(this), 'class', block, 999);
4826
- });
4827
-
4828
- clipboard.find ('pre.ai-block-number').each (function () {
4829
- var text = $(this).text ().replace (block, 999);
4830
- $(this).text (text);
4831
- });
4832
-
4833
- $("#ai-container .ai-copy").each (function () {
4834
- $(this).next ("label").find ('.checkbox-icon').addClass("on");
4835
- });
4836
-
4837
- // if (paste) {
4838
- // var tools_visible = $('#ai-tools-toolbar-' + active_tab).is(':visible');
4839
-
4840
- // paste_from_clipboard (true, true, true, false);
4841
-
4842
- // if (tools_visible) {
4843
- // $('#ai-tools-toolbar-' + active_tab).show ();
4844
- // $("#tools-button-"+active_tab).next ('label').find ('.checkbox-icon').addClass("on");
4845
- // }
4846
- // }
4847
- }).fail (function (xhr, status, error) {
4848
- console.log ("AI LOADING ERROR:", xhr.status, xhr.statusText);
4849
- $('#ai-error-container').text (ai_admin.error + ' ' + xhr.status + ': ' + xhr.statusText).show ();
4850
- })
4851
- .always (function () {
4852
- $('#ai-loading').hide ();
4853
- });
4854
- }
4855
-
4856
- function paste_from_clipboard (paste_name, paste_code, paste_settings, clear) {
4857
-
4858
- if (clear) {
4859
- var clipboard_template = $('#ai-clipboard-template');
4860
- clipboard_template.find ('input#name-edit-999').attr ('value', 'Block ' + active_tab).attr ('default', 'Block ' + active_tab);
4861
- var clipboard = clipboard_template.html ();
4862
- } else {
4863
- var clipboard = $('#ai-clipboard').html ();
4864
- }
4865
-
4866
- if (clipboard != '' && active_tab != 0) {
4867
- if (debug) console.log ("AI PASTE TO BLOCK", active_tab);
4868
-
4869
- var destination_tab = $('div#tab-' + active_tab);
4870
-
4871
- var name = destination_tab.find ('input#name-edit-' + active_tab).val ();
4872
- var code = get_editor_text (active_tab);
4873
-
4874
- if (paste_settings) {
4875
- var simple_editor = $('#simple-editor-' + active_tab).is(":checked");
4876
- var tools_visible = $('#ai-tools-toolbar-' + active_tab).is(':visible');
4877
- var copy_active = destination_tab.find ('.ai-copy').next ("label").find ('.checkbox-icon').hasClass("on");
4878
-
4879
- if (simple_editor) {
4880
- $('#simple-editor-' + active_tab).click ();
4881
- }
4882
-
4883
- var save_button_text = destination_tab.find ('input[name=ai_save]').attr('value');
4884
- var exceptions_button = destination_tab.find ('#exceptions-button-container-' + active_tab).html ();
4885
- var exceptions_container = destination_tab.find ('#block-exceptions-' + active_tab).html ();
4886
-
4887
- destination_tab.html (clipboard).find ('input[name=ai_save]').attr('value', save_button_text);
4888
-
4889
- if (!paste_name) {
4890
- destination_tab.find ('input#name-edit-999').val (name);
4891
- }
4892
-
4893
- if (!paste_code) {
4894
- destination_tab.find ('textarea#block-999').val (code);
4895
- }
4896
-
4897
- destination_tab.find ('span#name-label-999').text (destination_tab.find ('input#name-edit-999').val ());
4898
-
4899
- var block_name = destination_tab.find ('input#name-edit-999').val ();
4900
- destination_tab.find ('pre.ai-block-name').text ('[adinserter name="' + block_name + '"]');
4901
-
4902
- destination_tab.find ('[id]').each (function () {
4903
- replace_block_number ($(this), 'id', 999, active_tab);
4904
- });
4905
-
4906
- destination_tab.find ('[for]').each (function () {
4907
- replace_block_number ($(this), 'for', 999, active_tab);
4908
- });
4909
-
4910
- destination_tab.find ('[href]').each (function () {
4911
- replace_block_number ($(this), 'href', 999, active_tab);
4912
- });
4913
-
4914
- destination_tab.find ('[name]').each (function () {
4915
- replace_block_number ($(this), 'name', 999, active_tab);
4916
- });
4917
-
4918
- destination_tab.find ('[class]').each (function () {
4919
- replace_block_number ($(this), 'class', 999, active_tab);
4920
- });
4921
-
4922
- destination_tab.find ('pre.ai-sidebars').text ('');
4923
-
4924
- destination_tab.find ('pre.ai-block-number').each (function () {
4925
- var text = $(this).text ().replace (999, active_tab);
4926
- $(this).text (text);
4927
- });
4928
-
4929
- destination_tab.find ('#exceptions-button-container-' + active_tab).html (exceptions_button);
4930
- destination_tab.find ('#block-exceptions-' + active_tab).html (exceptions_container);
4931
-
4932
- configure_tab (active_tab);
4933
-
4934
- if (simple_editor) {
4935
- $('#simple-editor-' + active_tab).click ();
4936
- }
4937
-
4938
- if (tools_visible) {
4939
- $('#ai-tools-toolbar-' + active_tab).show ();
4940
- $("#tools-button-" + active_tab).next ('label').find ('.checkbox-icon').addClass ("on");
4941
- }
4942
-
4943
- if (copy_active) {
4944
- destination_tab.find ('.ai-copy').next ("label").find ('.checkbox-icon').addClass("on");
4945
- }
4946
- } else {
4947
- if (paste_name) {
4948
- var clipboard_name = $(clipboard).find ('input#name-edit-999').val ();
4949
- destination_tab.find ('input#name-edit-' + active_tab).val (clipboard_name);
4950
- destination_tab.find ('span#name-label-' + active_tab).text (clipboard_name);
4951
- destination_tab.find ('pre.ai-block-name').text ('[adinserter name="' + clipboard_name + '"]');
4952
- }
4953
-
4954
- if (paste_code) {
4955
- set_editor_text (active_tab, $(clipboard).find ('textarea#block-999').val ());
4956
- }
4957
- }
4958
-
4959
- if (debug) console.log ("AI PASTE END");
4960
- } else if (debug) console.log ("AI PASTE FAILED");
4961
- }
4962
-
4963
- function highlight_active_block () {
4964
- $('#ai-list-table tr.ai-block-list').removeClass ('ai-block-active');
4965
- $('#ai-list-table tr.ai-block-' + active_tab).addClass ('ai-block-active');
4966
- }
4967
-
4968
- function check_and_configure_active_tab () {
4969
- highlight_active_block ();
4970
-
4971
- if (!$("#tab-" + active_tab).hasClass ('configured')) {
4972
- if (debug) console.log ("");
4973
- if (debug) console.log ("Empty tab: " + active_tab);
4974
- tabs_to_configure.push (active_tab);
4975
- setTimeout (configure_hidden_tab, 10);
4976
- if (debug) console.log ("tabs_to_configure: " + tabs_to_configure);
4977
- } else if (active_tab != 0) {
4978
- if (syntax_highlighting) {
4979
- var editor = ace.edit ("editor-" + active_tab);
4980
- editor.getSession ().highlightLines (10000000);
4981
- }
4982
- }
4983
- }
4984
-
4985
- function configure_website_list () {
4986
- $("td.ai-website-desc").click (function () {
4987
- var row = $(this).closest ('tr.ai-website-list');
4988
- var website = row.data ("website");
4989
-
4990
- var connected = row.find ('.checkbox-icon').hasClass ('on');
4991
-
4992
- if (!connected) {
4993
- $("#ai-website-list-table td.ai-website-labels").show ();
4994
- $("#ai-website-list-table td.ai-website-editor").hide ();
4995
-
4996
- // $("#ai-cancel-websites").addClass ('red');
4997
- // $("#ai-save-websites").addClass ('green');
4998
- $("#ai-cancel-websites").show ();
4999
- $("#ai-save-websites").show ();
5000
- $("#ai-rearrange-websites").removeClass ('blue');
5001
-
5002
- row.find (".ai-website-editor .ai-website-key").val (row.find (".ai-website-editor .ai-website-key").attr ('data-key'));
5003
- row.find (".ai-website-editor .ai-website-desc").val (row.find (".ai-website-labels.ai-website-desc").text ());
5004
- row.find (".ai-website-editor .ai-website-url").val (row.find (".ai-website-labels.ai-website-url").text ());
5005
-
5006
- row.find (".ai-website-labels").hide ();
5007
- row.find (".ai-website-editor").show ();
5008
-
5009
- row.find (".ai-website-editor .ai-website-desc").focus ();
5010
- }
5011
- });
5012
-
5013
- $("input.ai-website-key, input.ai-website-desc, input.ai-website-url").on('keyup keypress', function (e) {
5014
- var keyCode = e.keyCode || e.which;
5015
- ignore_key = true;
5016
-
5017
- var row = $(this).closest('tr.ai-website-list');
5018
- var website = row.data ("website");
5019
-
5020
- if (keyCode == 27) {
5021
- row.find (".ai-website-labels").show ();
5022
- row.find (".ai-website-editor").hide ();
5023
-
5024
- ignore_key = false;
5025
- }
5026
- else if (keyCode == 13) {
5027
- $("#ai-save-websites").click ();
5028
-
5029
- ignore_key = false;
5030
- e.preventDefault();
5031
- return false;
5032
- }
5033
- }).focusout (function() {
5034
- if (ignore_key) {
5035
- var row = $(this).closest ('tr.ai-website-list');
5036
- var website = row.data ("website");
5037
-
5038
- row.find (".ai-website-editor .ai-website-key").attr ('data-key', row.find (".ai-website-editor .ai-website-key").val ());
5039
- row.find (".ai-website-labels.ai-website-desc").text (row.find (".ai-website-editor .ai-website-desc").val ());
5040
- row.find (".ai-website-labels.ai-website-url").text (row.find (".ai-website-editor .ai-website-url").val ());
5041
- }
5042
- ignore_key = true;
5043
- });
5044
-
5045
- $("#ai-website-list-table .ai-delete-website").click (function () {
5046
-
5047
- var row = $(this).closest ('tr.ai-website-list');
5048
- var website = row.data ("website");
5049
- var url = row.find (".ai-website-labels.ai-website-url").text ();
5050
- var desc = row.find (".ai-website-labels.ai-website-desc").text ();
5051
- var message = website;
5052
- var message = ai_admin.delete_website + '<br />' + desc + '<br />' + url;
5053
-
5054
- $('<div />').html (message).attr ('title', ai_admin.warning).dialog ({
5055
- bgiframe: true,
5056
- draggable: false,
5057
- resizable: false,
5058
- modal: true,
5059
- height: "auto",
5060
- width: 400,
5061
- position: {my: 'center', at: 'center', of: '#ai-manage-websites-container'},
5062
- buttons: [{
5063
- text: ai_admin.cancel,
5064
- click: function() {
5065
- $(this).dialog ("close");
5066
- }
5067
- },
5068
- {
5069
- text: ai_admin.delete_all,
5070
- click: function() {
5071
- $(this).dialog ("close");
5072
-
5073
- // $("#ai-cancel-websites").removeClass ('red');
5074
- // $("#ai-save-websites").removeClass ('green');
5075
- $("#ai-cancel-websites").hide ();
5076
- $("#ai-save-websites").hide ();
5077
- $("#ai-rearrange-websites").removeClass ('blue');
5078
-
5079
- reload_websites ('&delete=all');
5080
- }
5081
- },
5082
- {
5083
- text: ai_admin.delete,
5084
- click: function() {
5085
- $(this).dialog ("close");
5086
-
5087
- // $("#ai-cancel-websites").removeClass ('red');
5088
- // $("#ai-save-websites").removeClass ('green');
5089
- $("#ai-cancel-websites").hide ();
5090
- $("#ai-save-websites").hide ();
5091
- $("#ai-rearrange-websites").removeClass ('blue');
5092
-
5093
- reload_websites ('&delete=' + website);
5094
- }
5095
- }
5096
- ],
5097
- });
5098
- });
5099
-
5100
- $("#ai-website-list-table .ai-connect-website").click (function () {
5101
- var row = $(this).closest ('tr.ai-website-list');
5102
- var website = row.data ("website");
5103
-
5104
- var connected = row.find ('.ai-connect-website .checkbox-icon').hasClass ('on');
5105
- if (connected) website = '';
5106
- ai_reload_websites_function = function () {
5107
- if ($('#ai-website-data .ai-ajax-error').length == 0) {
5108
- window.location.href = ai_settings;
5109
- }
5110
- }
5111
-
5112
- if ($("#ai-save-websites").hasClass ('green')) {
5113
- $("#ai-save-websites").attr ('data-connect', website).click ();
5114
- } else {
5115
- reload_websites ('&connect=' + website);
5116
- }
5117
- });
5118
-
5119
- $("#ai-website-list-table label[title]").tooltip ({
5120
- track: true,
5121
- delay: 700,
5122
- showURL: false,
5123
- showBody: " | ",
5124
- fade: 250
5125
- });
5126
- }
5127
-
5128
- function configure_list () {
5129
- var data_container = $("#ai-list-data");
5130
-
5131
- $(".ai-tab-link").click (function () {
5132
- var tab = $(this).data ('tab') - start;
5133
- $("#ai-tab-container").tabs ({active: tab});
5134
-
5135
- active_tab = parseInt ($(this).data ('tab'));
5136
-
5137
- if (debug) console.log ("$('.ai-tab-link').click", active_tab);
5138
-
5139
- check_and_configure_active_tab ();
5140
-
5141
- });
5142
-
5143
- $("label.ai-copy-block").click (function () {
5144
- var block = $(this).closest ('tr').data ('block');
5145
-
5146
- load_saved_settings_to_clipboard (block, true);
5147
- });
5148
-
5149
- $("label.ai-pause-block").click (function () {
5150
- if (!ai_write) return;
5151
-
5152
- var block = $(this).closest ('tr').data ('block');
5153
-
5154
- reload_list ('cmd=pause&cmd-block=' + block);
5155
- ai_reload_list_function = function () {
5156
- var block_button = $('#disable-insertion-' + block);
5157
- var block_button_paused = block_button.parent ().find ('.icon-pause').hasClass ('on');
5158
- var new_paused = $('#ai-list-table tr.ai-block-' + block).find ('label.ai-pause-block').hasClass ('ai-paused');
5159
-
5160
- if (new_paused != block_button_paused) {
5161
- block_button.click ();
5162
- }
5163
- }
5164
- });
5165
-
5166
- $("label.ai-preview-block").click (function () {
5167
- var block = $(this).closest ('tr').data ('block');
5168
-
5169
- var window_width = 820;
5170
- var window_height = 820;
5171
- var window_left = 100;
5172
- var window_top = (screen.height / 2) - (820 / 2);
5173
-
5174
- var param = {'action': 'ai_ajax_backend', 'preview': block, 'ai_check': ai_nonce, 'read_only': 1};
5175
- open_popup_window_post (ajaxurl, 'width='+window_width+',height='+window_height+',top='+window_top+',left='+window_left+',resizable=yes,scrollbars=yes,toolbar=no,location=no,directories=no,status=no,menubar=no', 'preview', param);
5176
- });
5177
-
5178
- highlight_active_block ();
5179
-
5180
- data_container.disableSelection();
5181
-
5182
- $("#ai-list-data td[title]").tooltip ({
5183
- track: true,
5184
- delay: 700,
5185
- showURL: false,
5186
- showBody: " | ",
5187
- fade: 250
5188
- });
5189
- }
5190
-
5191
- function reload_websites (parameters) {
5192
- website_list_search_reload = false;
5193
- var list = encodeURIComponent ($("#ai-website-list-search").val());
5194
-
5195
- var data_container = $("#ai-website-data");
5196
-
5197
- $('#ai-loading').show ();
5198
-
5199
- if (typeof parameters == 'undefined') parameters = '';
5200
-
5201
- data_container.load (ajaxurl+"?action=ai_ajax_backend&websites=" + list + parameters + "&ai_check=" + ai_nonce, function (response, status, xhr) {
5202
- $('#ai-loading').hide ();
5203
- if (status == "error") {
5204
- var message = "Error downloading website data: " + xhr.status + " " + xhr.statusText;
5205
- data_container.html (message);
5206
- if (debug) console.log (message);
5207
- } else {
5208
- configure_website_list ();
5209
-
5210
- if (typeof ai_reload_websites_function == 'function') {
5211
- ai_reload_websites_function ();
5212
- ai_reload_websites_function = null;
5213
- }
5214
- }
5215
- });
5216
- }
5217
-
5218
- function reload_list (settings) {
5219
- list_search_reload = false;
5220
- var list = encodeURIComponent ($("#ai-list-search").val());
5221
- var all = + !$("#ai-load-all").hasClass ('light-blue');
5222
-
5223
- var rearrange_controls = $('#list-rearrange-controls');
5224
- var rearrange = rearrange_controls.hasClass ('rearrange')
5225
-
5226
- rearrange_controls.removeClass ('rearrange').hide ();
5227
- $("#ai-rearrange").removeClass ('blue');
5228
-
5229
- var rearrange_data = '';
5230
- if (rearrange) {
5231
- var table = $('table#ai-list-table');
5232
- var original_blocks = table.data ('blocks');
5233
- if (typeof original_blocks == 'undefined') original_blocks = new Array();
5234
-
5235
- var new_blocks = new Array();
5236
- table.find ('tbody tr').each (function (index) {
5237
- new_blocks.push ($(this).data ('block'));
5238
- });
5239
-
5240
- rearrange_data = "&blocks-org=" + JSON.stringify (original_blocks) + "&blocks-new=" + JSON.stringify (new_blocks);
5241
- }
5242
-
5243
- var data_container = $("#ai-list-data");
5244
- var safe_mode = Boolean (parseInt ($('#ai-data').attr ('safe-mode')));
5245
- var safe_mode_url = safe_mode ? '&safe-mode' : '';
5246
- var settings_data = typeof settings == 'undefined' ? '' : '&' + settings;
5247
-
5248
- $('#ai-loading').show ();
5249
-
5250
- data_container.load (ajaxurl+"?action=ai_ajax_backend&list=" + list + "&all=" + all + "&start=" + start + "&end=" + end + "&active=" + active_tab + rearrange_data + safe_mode_url + settings_data + "&ai_check=" + ai_nonce, function (response, status, xhr) {
5251
- $('#ai-loading').hide ();
5252
- if (status == "error") {
5253
- var message = "Error downloading list data: " + xhr.status + " " + xhr.statusText;
5254
- data_container.html (message);
5255
- if (debug) console.log (message);
5256
- } else {
5257
- configure_list ();
5258
-
5259
- if (typeof ai_reload_list_function == 'function') {
5260
- ai_reload_list_function ();
5261
- ai_reload_list_function = null;
5262
- }
5263
- if (rearrange) reload_settings ();
5264
- }
5265
- });
5266
- }
5267
-
5268
- function reload_adsense_list (update_ad_units) {
5269
- adsense_search_reload = false;
5270
- var list = encodeURIComponent ($("#adsense-list-search").val());
5271
- var all = + !$("#adsense-load-all").parent ().find ('.checkbox-icon').hasClass ('on');
5272
- // var nonce = $("#ai-form").attr ('nonce');
5273
-
5274
- var data_container = $("#adsense-list-data");
5275
-
5276
- data_container.load (ajaxurl+"?action=ai_ajax_backend&adsense-list=" + list + "&all=" + all + "&update_ad_units=" + (update_ad_units ? 1 : 0) + "&ai_check=" + ai_nonce, function (response, status, xhr) {
5277
- $("#adsense-reload").parent ().find ('.checkbox-icon').removeClass ('on');
5278
-
5279
- if (status == "error") {
5280
- var message = "Error downloading AdSense data: " + xhr.status + " " + xhr.statusText;
5281
- data_container.html (message);
5282
- if (debug) console.log (message);
5283
-
5284
-
5285
- } else {
5286
- if ($('#adsense-client-id', data_container).length) {
5287
- $('#adsense-list-controls').hide ();
5288
- $('button.ai-top-button', data_container).button().show ();
5289
-
5290
- $("#save-client-ids").click (function () {
5291
-
5292
- var client_id = $("input#adsense-client-id").val ();
5293
- var client_secret = $("input#adsense-client-secret").val ();
5294
-
5295
- data_container.text (ai_admin.loading);
5296
-
5297
- // var nonce = $("#ai-form").attr ('nonce');
5298
-
5299
- $('#ai-loading').show ();
5300
- $.get (ajaxurl + '?action=ai_ajax_backend&adsense-client-id=' + btoa (client_id) + '&adsense-client-secret=' + btoa (client_secret) + '&ai_check=' + ai_nonce, function (data) {
5301
- reload_adsense_list (false);
5302
- }).fail (function (xhr, status, error) {
5303
- var message = "Error saving AdSense client IDs: " + xhr.status + " " + xhr.statusText ;
5304
- console.log (message);
5305
- })
5306
- .always (function () {
5307
- $('#ai-loading').hide ();
5308
- });
5309
- });
5310
-
5311
- $(".authorize-adsense", data_container).click (function () {
5312
-
5313
- $('#adsense-list-controls').show ();
5314
- data_container.text (ai_admin.loading);
5315
-
5316
- authorization_code = '';
5317
- update_adsense_authorization (authorization_code);
5318
- });
5319
-
5320
- return;
5321
- } else
5322
-
5323
- if ($('#adsense-authorization-code', data_container).length) {
5324
- $('#adsense-list-controls').hide ();
5325
- $('button.ai-top-button', data_container).button().show ();
5326
-
5327
- $(".authorize-adsense", data_container).click (function () {
5328
-
5329
- var authorization_code = $("input#adsense-authorization-code").val ();
5330
-
5331
- $('#adsense-list-controls').show ();
5332
- data_container.text (ai_admin.loading);
5333
-
5334
- if ($(this).hasClass ('clear-adsense')) authorization_code = '';
5335
- if ($(this).hasClass ('own-ids')) authorization_code = 'own-ids';
5336
-
5337
-
5338
- update_adsense_authorization (authorization_code);
5339
- });
5340
-
5341
- return;
5342
- }
5343
-
5344
- $('#adsense-list-controls').show ();
5345
-
5346
- var publisher_id = $('#adsense-data', data_container).data ('publisher-id');
5347
- if (typeof publisher_id == 'undefined') publisher_id = '';
5348
-
5349
- $('label#google-adsense-button').attr ('title', ai_admin.google_adsense_homepage + ' ' + publisher_id)
5350
- .tooltip({
5351
- track: true,
5352
- delay: 700,
5353
- showURL: false,
5354
- showBody: " | ",
5355
- fade: 250
5356
- });
5357
-
5358
- $("label.adsense-copy-code").click (function () {
5359
- var ad_slot_id = $(this).closest ('tr').data ('id');
5360
- var ad_name = atob ($(this).closest ('tr').data ('name'));
5361
- // var nonce = $("#ai-form").attr ('nonce');
5362
-
5363
- if (debug) console.log ('ADSENSE CODE: ', ad_slot_id);
5364
-
5365
- $('#ai-loading').show ();
5366
- $.get (ajaxurl + '?action=ai_ajax_backend&adsense-code=' + ad_slot_id + '&ai_check=' + ai_nonce, function (data) {
5367
-
5368
- var code_data = JSON.parse (data);
5369
- var error = code_data ['error-message'];
5370
-
5371
- if (error == '') {
5372
- var adsense_code = code_data ['code'];
5373
-
5374
- if (debug) console.log (adsense_code);
5375
-
5376
- var clipboard_template = $('#ai-clipboard-template');
5377
- var clipboard = $('#ai-clipboard');
5378
- clipboard.html (clipboard_template.html ());
5379
- clipboard.find ('input#name-edit-999').attr ('value', ad_name).attr ('default', ad_name);
5380
-
5381
- clipboard.find ('textarea.simple-editor').text (adsense_code);
5382
-
5383
- $("#ai-container .ai-copy").each (function () {
5384
- $(this).next ("label").find ('.checkbox-icon').addClass("on");
5385
- });
5386
-
5387
- var tools_button = $("#tools-button-" + active_tab);
5388
- if (!tools_button.next ('label').find ('.checkbox-icon').hasClass ("on")) {
5389
- tools_button.click ();
5390
- }
5391
- } else {
5392
- console.log ('AdSense API error:', error);
5393
- }
5394
- }).fail (function (xhr, status, error) {
5395
- var message = "Error downloading AdSense code: " + xhr.status + " " + xhr.statusText ;
5396
- console.log (message);
5397
- })
5398
- .always (function () {
5399
- $('#ai-loading').hide ();
5400
- });
5401
-
5402
- });
5403
-
5404
- $("label.adsense-preview-code").click (function () {
5405
- var ad_slot_id = $(this).closest ('tr').data ('id');
5406
- var ad_name = $(this).closest ('tr').data ('name');
5407
-
5408
- var window_width = 820;
5409
- var window_height = 820;
5410
- var window_left = 100;
5411
- var window_top = (screen.height / 2) - (820 / 2);
5412
- // var nonce = $("#ai-form").attr ('nonce');
5413
-
5414
- var param = {'action': 'ai_ajax_backend', 'preview': 'adsense', 'ai_check': ai_nonce, 'read_only': 1, 'slot_id': btoa (ad_slot_id), 'name': ad_name};
5415
- open_popup_window_post (ajaxurl, 'width='+window_width+',height='+window_height+',top='+window_top+',left='+window_left+',resizable=yes,scrollbars=yes,toolbar=no,location=no,directories=no,status=no,menubar=no', 'preview', param);
5416
- });
5417
-
5418
- $("label.adsense-get-code").click (function () {
5419
- var ad_slot_id = $(this).closest ('tr').data ('id');
5420
- var ad_name = atob ($(this).closest ('tr').data ('name'));
5421
- // var nonce = $("#ai-form").attr ('nonce');
5422
-
5423
- if (debug) console.log ('ADSENSE CODE: ', ad_slot_id);
5424
-
5425
- $('#ai-loading').show ();
5426
- $.get (ajaxurl + '?action=ai_ajax_backend&adsense-code=' + ad_slot_id + '&ai_check=' + ai_nonce, function (data) {
5427
-
5428
- var code_data = JSON.parse (data);
5429
- var error = code_data ['error-message'];
5430
-
5431
- if (error == '') {
5432
- var adsense_code = code_data ['code'];
5433
-
5434
- if (debug) console.log (adsense_code);
5435
-
5436
- set_editor_text (active_tab, adsense_code);
5437
- setTimeout (function() {$("#import-code-"+active_tab).click ();}, 10);
5438
- } else {
5439
- console.log ('AdSense API error:', error);
5440
- }
5441
- }).fail (function (xhr, status, error) {
5442
- var message = "Error downloading AdSense code: " + xhr.status + " " + xhr.statusText ;
5443
- console.log (message);
5444
- })
5445
- .always (function () {
5446
- $('#ai-loading').hide ();
5447
- });
5448
- });
5449
-
5450
- data_container.disableSelection();
5451
- }
5452
- });
5453
- }
5454
-
5455
- function load_ads_txt () {
5456
- ads_txt_reload = false;
5457
- var editor_button = $("#ads-txt-editor");
5458
- var reload_button = $("#ads-txt-reload");
5459
- var virtual_button = $("#ads-txt-virtual");
5460
- var virtual = virtual_button.hasClass ('violet') ? '1' : '0';
5461
- var view = editor_button.hasClass ('editor') ? 'text' : 'table';
5462
- var search = encodeURIComponent ($("#ads-txt-search").val());
5463
- var data_container = $("#ads-txt-data");
5464
-
5465
- reload_button.addClass ('red');
5466
-
5467
- data_container.load (ajaxurl+"?action=ai_ajax_backend&ads-txt=" + view + "&virtual=" + virtual + "&search=" + search + "&ai_check=" + ai_nonce, function (response, status, xhr) {
5468
- reload_button.removeClass ('red');
5469
-
5470
- if (status == "error") {
5471
- var message = "Error loading ads.txt file: " + xhr.status + " " + xhr.statusText;
5472
- data_container.html (message);
5473
- if (debug) console.log (message);
5474
- } else {
5475
- if ($('#ads-txt-missing').length != 0) {
5476
- view = 'text';
5477
- editor_button.addClass ('editor');
5478
- $('#ads-txt-search').hide ();
5479
- }
5480
-
5481
- switch (view) {
5482
- case 'text':
5483
- $('#ads-txt-search').hide ();
5484
-
5485
- editor_button.removeClass ('dashicons-edit');
5486
- editor_button.addClass ('dashicons-yes-alt');
5487
- editor_button.addClass ('green');
5488
- editor_button.attr ('title', editor_button.attr ('title-editor'))
5489
- .tooltip({
5490
- track: true,
5491
- delay: 700,
5492
- showURL: false,
5493
- showBody: " | ",
5494
- fade: 250
5495
- });
5496
-
5497
- reload_button.removeClass ('dashicons-download');
5498
- reload_button.addClass ('dashicons-no');
5499
-
5500
- if ($('#ads-txt-missing').length != 0) {
5501
- reload_button.removeClass ('red');
5502
- reload_button.attr ('title', reload_button.attr ('title-table'))
5503
- .tooltip({
5504
- track: true,
5505
- delay: 700,
5506
- showURL: false,
5507
- showBody: " | ",
5508
- fade: 250
5509
- });
5510
- } else {
5511
- reload_button.addClass ('red');
5512
- reload_button.attr ('title', reload_button.attr ('title-editor'))
5513
- .tooltip({
5514
- track: true,
5515
- delay: 700,
5516
- showURL: false,
5517
- showBody: " | ",
5518
- fade: 250
5519
- });
5520
- }
5521
- break;
5522
- case 'table':
5523
- editor_button.removeClass ('dashicons-yes-alt');
5524
- editor_button.removeClass ('green');
5525
- editor_button.addClass ('dashicons-edit');
5526
- editor_button.attr ('title', editor_button.attr ('title-table'))
5527
- .tooltip({
5528
- track: true,
5529
- delay: 700,
5530
- showURL: false,
5531
- showBody: " | ",
5532
- fade: 250
5533
- });
5534
-
5535
- reload_button.removeClass ('dashicons-no');
5536
- reload_button.removeClass ('red');
5537
- reload_button.addClass ('dashicons-download');
5538
- reload_button.attr ('title', reload_button.attr ('title-table'))
5539
- .tooltip({
5540
- track: true,
5541
- delay: 700,
5542
- showURL: false,
5543
- showBody: " | ",
5544
- fade: 250
5545
- });
5546
- break;
5547
- }
5548
-
5549
- $('#ads-txt-controls').show ();
5550
- }
5551
- });
5552
- }
5553
-
5554
- function save_ads_txt (reload) {
5555
- var data_container = $("#ads-txt-data");
5556
- var editor_button = $("#ads-txt-editor");
5557
- var reload_button = $("#ads-txt-reload");
5558
- var virtual_button = $("#ads-txt-virtual");
5559
- var virtual = virtual_button.hasClass ('violet') ? '1' : '0';
5560
- var ads_txt_data = {'text': b64e (data_container.find ('textarea#ads-txt-text').val ())};
5561
-
5562
- $('#ads-txt-error').text ('');
5563
-
5564
- editor_button.removeClass ('green');
5565
- editor_button.addClass ('red');
5566
-
5567
- $.post (ajaxurl+"?action=ai_ajax_backend&ads-txt=save" + "&virtual=" + virtual + "&ai_check=" + ai_nonce, ads_txt_data
5568
- ).done (function (code_data) {
5569
- }).fail (function (xhr, status, error) {
5570
- editor_button.removeClass ('red');
5571
- editor_button.addClass ('green');
5572
-
5573
- var message = "Error saving ads.txt file: " + xhr.status + " " + xhr.statusText;
5574
- $('#ads-txt-error').text (message);
5575
- if (debug) console.log (message);
5576
- }).always (function() {
5577
- editor_button.removeClass ('editor');
5578
-
5579
- editor_button.removeClass ('green');
5580
- editor_button.removeClass ('red');
5581
- editor_button.removeClass ('dashicons-yes-alt');
5582
- editor_button.addClass ('dashicons-edit');
5583
- editor_button.attr ('title', editor_button.attr ('title-editor'))
5584
- .tooltip({
5585
- track: true,
5586
- delay: 700,
5587
- showURL: false,
5588
- showBody: " | ",
5589
- fade: 250
5590
- });
5591
-
5592
- reload_button.addClass ('dashicons-download');
5593
- reload_button.removeClass ('dashicons-no');
5594
- reload_button.removeClass ('red');
5595
- reload_button.attr ('title', reload_button.attr ('title-editor'))
5596
- .tooltip({
5597
- track: true,
5598
- delay: 700,
5599
- showURL: false,
5600
- showBody: " | ",
5601
- fade: 250
5602
- });
5603
-
5604
- $('#ads-txt-search').show ();
5605
-
5606
- if (reload) {
5607
- setTimeout (function() {load_ads_txt ();}, 100);
5608
- }
5609
- });
5610
- }
5611
-
5612
- function set_page_statuses (block) {
5613
- var automatic_insertion = parseInt ($("select#insertion-type-"+block+" option:selected").attr('value'));
5614
- var table = $('#page-types-' + block);
5615
-
5616
- switch (automatic_insertion) {
5617
- case AI_BEFORE_HTML_ELEMENT:
5618
- case AI_AFTER_HTML_ELEMENT:
5619
- case AI_INSIDE_HTML_ELEMENT:
5620
- table.find ('td.ai-page-type').removeClass ('ai-unavailable');
5621
- return;
5622
- }
5623
-
5624
- var pages = ['po', 'pa', 'hp', 'cp', 'ap', 'sp'];
5625
-
5626
- pages.forEach (function (page, index) {
5627
- var positions = $('table.check-pages').attr ('data-positions-' + page);
5628
-
5629
- if (positions != null) {
5630
- var available_insertions = JSON.parse (positions);
5631
-
5632
- if (available_insertions.indexOf (automatic_insertion) != - 1) {
5633
- table.find ('td.ai-page-type.ai-' + page).removeClass ('ai-unavailable').find ('input, label').removeAttr ('title')
5634
- .tooltip({
5635
- track: true,
5636
- delay: 700,
5637
- showURL: false,
5638
- showBody: " | ",
5639
- fade: 250
5640
- });
5641
- } else {
5642
- table.find ('td.ai-page-type.ai-' + page).addClass ('ai-unavailable').find ('input, label').attr ('title', ai_admin.position_might_not_available)
5643
- .tooltip({
5644
- track: true,
5645
- delay: 700,
5646
- showURL: false,
5647
- showBody: " | ",
5648
- fade: 250
5649
- });
5650
- }
5651
- }
5652
- });
5653
- }
5654
-
5655
- function check_page (page, button, last_check) {
5656
- // var nonce = $("#ai-form").attr ('nonce');
5657
- var container = button.closest ('.ai-check-pages');
5658
- var error_message = container.find ('.ai-error-message');
5659
-
5660
- $.get (ajaxurl + '?action=ai_ajax_backend&check-page=' + page + '&ai_check=' + ai_nonce, function (data) {
5661
- if (data != '') {
5662
-
5663
- if (debug) console.log ("AI CHECK PAGES:", data);
5664
-
5665
- try {
5666
- var pages_data = JSON.parse (data);
5667
- var positions = pages_data ['positions'];
5668
- var urls = pages_data ['urls'];
5669
-
5670
- if (debug) console.log ("AI CHECK PAGES positions:", positions);
5671
- if (debug) console.log ("AI CHECK PAGES urls:", urls);
5672
-
5673
- $('table.check-pages').attr ('data-positions-' + page, JSON.stringify (positions));
5674
- $('table.check-pages').attr ('data-urls-' + page, JSON.stringify (urls));
5675
-
5676
- $('table.check-pages td.ai-position.ai-' + page).each (function () {
5677
- $(this).removeClass ('ai-not-checked');
5678
- var insertion = $(this).data ('insertion');
5679
-
5680
- if (positions.indexOf (insertion) == - 1) {
5681
- $(this).addClass ('ai-no').attr ('title', ai_admin.position_not_available);
5682
- } else {
5683
- $(this).addClass ('ai-yes').attr ('title', ai_admin.position_available);
5684
- }
5685
- $(this).tooltip({
5686
- track: true,
5687
- delay: 700,
5688
- showURL: false,
5689
- showBody: " | ",
5690
- fade: 250
5691
- });
5692
- });
5693
-
5694
- if (urls != null && urls.length != 0) {
5695
- $('table.check-pages a.ai-' + page).each (function (index, value) {
5696
- if (typeof urls [index] != 'undefined') {
5697
- $(this).attr ('href', urls [index]).show ();
5698
- }
5699
- });
5700
- }
5701
- } catch (error) {
5702
- // error_message.find ('.ai-error-message-text').text ('JSON error');
5703
- error_message.find ('.ai-error-message-text').text (data);
5704
- error_message.show ();
5705
- console.log ("AI CHECK PAGES: JSON error decoding available positions: " + data);
5706
- }
5707
- }
5708
- }).fail (function (xhr, status, error) {
5709
- error_message.find ('.ai-error-message-text').text (xhr.status + " " + xhr.statusText);
5710
- error_message.show ();
5711
- console.log ('AI CHECK PAGES: Error loading positions for', page + ':', xhr.status, xhr.statusText);
5712
- })
5713
- .always (function () {
5714
- if (last_check) {
5715
- $('#ai-loading').hide ();
5716
- $('#ai-loading-2').hide ();
5717
- button.find ('span.ui-button-text').removeClass ('on');
5718
-
5719
- for (var block = start; block <= end; block ++) {
5720
- set_page_statuses (block);
5721
- }
5722
- }
5723
- });
5724
- }
5725
-
5726
- function configure_tabs () {
5727
-
5728
- var tabs_array = new Array ();
5729
-
5730
- if (ai_tab_setup_delay != 0) {
5731
- if (active_tab != 0) tabs_array.push (0);
5732
- for (var tab = end; tab >= start; tab --) {
5733
- if (tab != active_tab) tabs_array.push (tab);
5734
- }
5735
- }
5736
-
5737
- // Concatenate existing tabs_to_configure (if tab was clicked before page was loaded)
5738
- tabs_to_configure = tabs_array.concat (tabs_to_configure);
5739
-
5740
- // setTimeout (configure_hidden_tab, 700);
5741
- if (ai_tab_setup_delay != 0) {
5742
- setTimeout (configure_hidden_tab, 3 * ai_tab_setup_delay);
5743
- }
5744
-
5745
- var index = 16;
5746
- if (active_tab != 0) index = active_tab - start;
5747
- var block_tabs = $("#ai-tab-container").tabs ({active: index});
5748
- $("#ai-plugin-settings-tab-container").tabs ({active: active_tab_0});
5749
-
5750
- // $('#ai-settings').tooltip({
5751
- // show: {effect: "blind",
5752
- // delay: 400,
5753
- // duration: 100}
5754
- // });
5755
-
5756
- if (debug_title) $("#plugin_name").css ("color", "#00f");
5757
-
5758
- if (active_tab == 0) configure_tab_0 (); else configure_tab (active_tab);
5759
-
5760
- $('#dummy-tabs').hide();
5761
- $('#ai-tabs').show();
5762
-
5763
- // $('.ai-tab').click (function () {
5764
- // var tab_block = $(this).attr ("id");
5765
- // tab_block = parseInt (tab_block.replace ("ai-tab",""));
5766
- // active_tab = tab_block;
5767
-
5768
- // highlight_active_block ();
5769
-
5770
- // if (debug) console.log ("$('.ai-tab').click", active_tab);
5771
-
5772
- // if (!$("#tab-" + tab_block).hasClass ('configured')) {
5773
- // if (debug) console.log ("");
5774
- // if (debug) console.log ("Empty tab: " + tab_block);
5775
- // tabs_to_configure.push (tab_block);
5776
- // setTimeout (configure_hidden_tab, 10);
5777
- // if (debug) console.log ("tabs_to_configure: " + tabs_to_configure);
5778
- // } else if (tab_block != 0) {
5779
- // if (syntax_highlighting) {
5780
- // var editor = ace.edit ("editor-" + tab_block);
5781
- // editor.getSession ().highlightLines (10000000);
5782
- // }
5783
- // }
5784
- // });
5785
-
5786
- $('#ai-tab-container').on ('tabsbeforeactivate', function (event, ui) {
5787
- var tab_block = ui.newTab.attr ("id");
5788
-
5789
- if (!tab_block.includes ('ai-tab')) return;
5790
-
5791
- tab_block = parseInt (tab_block.replace ("ai-tab",""));
5792
- active_tab = tab_block;
5793
-
5794
- if (debug) console.log ("on tabsbeforeactivate", active_tab);
5795
-
5796
- check_and_configure_active_tab ();
5797
-
5798
- // highlight_active_block ();
5799
-
5800
- // if (!$("#tab-" + tab_block).hasClass ('configured')) {
5801
- // if (debug) console.log ("");
5802
- // if (debug) console.log ("Empty tab: " + tab_block);
5803
- // tabs_to_configure.push (tab_block);
5804
- // setTimeout (configure_hidden_tab, 10);
5805
- // if (debug) console.log ("tabs_to_configure: " + tabs_to_configure);
5806
- // } else if (tab_block != 0) {
5807
- // if (syntax_highlighting) {
5808
- // var editor = ace.edit ("editor-" + tab_block);
5809
- // editor.getSession ().highlightLines (10000000);
5810
- // }
5811
- // }
5812
- });
5813
-
5814
- $('.ai-plugin-tab').click (function () {
5815
- active_tab_0 = $("#ai-plugin-settings-tab-container").tabs ('option', 'active');
5816
- if (debug) console.log ("active_tab_0: " + active_tab_0);
5817
-
5818
- if (syntax_highlighting) {
5819
- var tab_block = $(this).attr ("id");
5820
- tab_block = tab_block.replace ("ai-","");
5821
-
5822
- if (tab_block == 'h') {
5823
- var editor = ace.edit ("editor-h");
5824
- editor.getSession ().highlightLines (10000000);
5825
- } else
5826
- if (tab_block == 'f') {
5827
- editor = ace.edit ("editor-f");
5828
- editor.getSession ().highlightLines (10000000);
5829
- } else
5830
- if (tab_block == 'a') {
5831
- editor = ace.edit ("editor-a");
5832
- editor.getSession ().highlightLines (10000000);
5833
- }
5834
- }
5835
- });
5836
-
5837
- $("#check-pages-button").button ({
5838
- }).show ().click (function () {
5839
- var button = $(this);
5840
- var container = $(this).closest ('.ai-check-pages');
5841
- var error_message = container.find ('.ai-error-message');
5842
-
5843
- $('#ai-loading').show ();
5844
- $('#ai-loading-2').show ();
5845
- error_message.hide ();
5846
- button.find ('span.ui-button-text').addClass ('on');
5847
-
5848
- $('table.check-pages a').removeAttr ('href').hide ();
5849
-
5850
- var pages = ['po', 'pa', 'hp', 'cp', 'ap', 'sp'];
5851
-
5852
- pages.forEach (function (page, index) {
5853
- $('table.check-pages td.ai-position').each (function () {
5854
- $(this).removeClass ('ai-yes').removeClass ('ai-no').addClass ('ai-not-checked').attr ('title', ai_admin.position_not_checked);
5855
- $(this).tooltip({
5856
- track: true,
5857
- delay: 700,
5858
- showURL: false,
5859
- showBody: " | ",
5860
- fade: 250
5861
- });
5862
- });
5863
-
5864
- $('table.ai-page-types td.ai-page-type').each (function () {
5865
- $(this).removeClass ('ai-unavailable');
5866
- });
5867
-
5868
- setTimeout (function() {check_page (page, button, index == pages.length - 1);}, index * 300 + 10);
5869
- });
5870
- });
5871
- }
5872
-
5873
-
5874
- function reload_settings () {
5875
- if (debug) console.log ('RELOAD SETTINGS');
5876
-
5877
- var settings_container = $("#ai-container");
5878
-
5879
- $('#ai-error-container').hide ();
5880
- if (debug_title) $("#plugin_name").css ("color", "#f00");
5881
-
5882
- $('#ai-loading').show ();
5883
-
5884
- var tools = $('#ai-tools-toolbar-' + active_tab).is (':visible');
5885
- var simple_editor = $('#simple-editor-' + active_tab).is(":checked");
5886
- var copy = $("#copy-block-" + active_tab).next ("label").find ('.checkbox-icon').hasClass("on");
5887
-
5888
- settings_container.load (ajaxurl+"?action=ai_ajax_backend&settings=" + active_tab + "&ai_check=" + ai_nonce, function (response, status, xhr) {
5889
- if (status == "error") {
5890
- $('#ai-loading').hide ();
5891
- var message = ai_admin.error_reloading_settings + ": " + xhr.status + " " + xhr.statusText;
5892
- $('#ai-error-container').text (message).show ();
5893
- if (debug) console.log (message);
5894
- } else {
5895
- if (debug) console.log (' Configuring...');
5896
-
5897
- if (debug) {
5898
- start_time = new Date().getTime();
5899
- last_time = start_time;
5900
- }
5901
-
5902
- configure_tabs ();
5903
-
5904
- if (simple_editor) $('#simple-editor-' + active_tab).click ();
5905
-
5906
- if (tools) $('#tools-button-' + active_tab).click ();
5907
-
5908
- if (copy) {
5909
- $("#ai-container .ai-copy").each (function () {
5910
- $(this).next ("label").find ('.checkbox-icon').addClass("on");
5911
- });
5912
- }
5913
-
5914
- if (debug) console.log (' Configured');
5915
- $('#ai-loading').hide ();
5916
- }
5917
- });
5918
- }
5919
-
5920
- function update_adsense_authorization (authorization_code) {
5921
- // var nonce = $("#ai-form").attr ('nonce');
5922
-
5923
- $('#ai-loading').show ();
5924
- $.get (ajaxurl + '?action=ai_ajax_backend&adsense-authorization-code=' + btoa (authorization_code) + '&ai_check=' + ai_nonce, function (data) {
5925
- reload_adsense_list (false);
5926
- }).fail (function (xhr, status, error) {
5927
- var message = "Error saving AdSense authorization: " + xhr.status + " " + xhr.statusText ;
5928
- console.log (message);
5929
- })
5930
- .always (function () {
5931
- $('#ai-loading').hide ();
5932
- });
5933
- }
5934
-
5935
- function toggle_adsense_list () {
5936
- var container = $("#adsense-list-container");
5937
- container.toggle ();
5938
-
5939
- if (container.is(':visible')) {
5940
- $(".checkbox-icon.icon-adsense").addClass ('on');
5941
- reload_adsense_list (false);
5942
- } else {
5943
- $(".checkbox-icon.icon-adsense").removeClass ('on');
5944
- }
5945
- }
5946
-
5947
- function update_block_code_demo () {
5948
- // var nonce = $("#ai-form").attr ('nonce');
5949
-
5950
- var block_class_name = encodeURIComponent ($('#block-class-name').val ());
5951
- var block_class = $('#block-class').is(":checked") ? 1 : 0;
5952
- var block_number_class = $('#block-number-class').is(":checked") ? 1 : 0;
5953
- var block_name_class = $('#block-name-class').is(":checked") ? 1 : 0;
5954
- var inline_styles = $('#inline-styles').is(":checked") ? 1 : 0;
5955
-
5956
- $.get (ajaxurl + '?action=ai_ajax_backend&update=block-code-demo&block_class_name=' + block_class_name + '&block_class=' + block_class + '&block_number_class=' + block_number_class + '&block_name_class=' + block_name_class + '&inline_styles=' + inline_styles + '&ai_check=' + ai_nonce, function (data) {
5957
- $('span#ai-block-code-demo').html (data);
5958
- }).fail (function (xhr, status, error) {
5959
- var message = "Error updating block code demo: " + xhr.status + " " + xhr.statusText ;
5960
- console.log (message);
5961
- });
5962
- }
5963
-
5964
- if (debug) console.log ("READY");
5965
- if (debug_title) $("#plugin_name").css ("color", "#f00");
5966
- if (debug) {
5967
- var current_time_ready = new Date().getTime();
5968
- console.log ("TIME: " + ((current_time_ready - start_time) / 1000).toFixed (3));
5969
- }
5970
-
5971
- $("#blocked-warning").removeClass ('warning-enabled');
5972
- $("#blocked-warning").hide ();
5973
-
5974
- start = parseInt ($('#ai-form').attr('start'));
5975
- end = parseInt ($('#ai-form').attr('end'));
5976
-
5977
- active_tab = start;
5978
- active_tab_0 = 0;
5979
- try {
5980
- var active_tabs = JSON.parse ($("#ai-active-tab").attr ("value"));
5981
- if (typeof active_tabs !== "undefined" && active_tabs.constructor === Array && Number.isInteger (active_tabs [0]) && Number.isInteger (active_tabs [1])) {
5982
- active_tab = parseInt (active_tabs [0]);
5983
- if (active_tab != 0)
5984
- if (active_tab < start || active_tab > end) active_tab = start;
5985
- active_tab_0 = parseInt (active_tabs [1]);
5986
- }
5987
- } catch (e) {}
5988
-
5989
- if (debug) console.log ("active_tabs:", active_tab, active_tab_0);
5990
-
5991
- var plugin_version = $('#ai-data').attr ('version').split ('-') [0];
5992
- if (javascript_version != plugin_version) {
5993
- console.log ('AD INSERTER: plugin version: ' + plugin_version + ', loaded JavaScript version: ' + javascript_version);
5994
-
5995
- // Check page HTML
5996
- var javascript_version_parameter = $("script[src*='ad-inserter.js']").attr('src');
5997
- if (typeof javascript_version_parameter == 'undefined') $("#javascript-version-parameter-missing").show (); else {
5998
- javascript_version_parameter_string = javascript_version_parameter.split('=')[1];
5999
- if (typeof javascript_version_parameter_string == 'undefined') {
6000
- $("#javascript-version-parameter-missing").show ();
6001
- }
6002
- else if (javascript_version_parameter_string != plugin_version) {
6003
- console.log ('AD INSERTER: plugin version: ' + plugin_version + ', JavaScript file version: ' + javascript_version_parameter_string);
6004
- $("#javascript-version-parameter").show ();
6005
- }
6006
- }
6007
-
6008
- $("#javascript-version").html ("Javascript<br />" + javascript_version);
6009
- $("#javascript-warning").show ();
6010
- }
6011
-
6012
- var css_version = $('#ai-data').css ('font-family').replace(/[\"\']/g, '');
6013
- if (css_version.indexOf ('.') == - 1) $("#blocked-warning").show (); else
6014
- if (css_version != plugin_version) {
6015
- console.log ('AD INSERTER: plugin version:', plugin_version + ', loaded CSS version:', css_version);
6016
-
6017
- // Check page HTML
6018
- var css_version_parameter = $("link[href*='ai-settings.css']").attr('href');
6019
- if (typeof css_version_parameter == 'undefined') $("#css-version-parameter-missing").show (); else {
6020
- css_version_parameter_string = css_version_parameter.split('=')[1];
6021
- if (typeof css_version_parameter_string == 'undefined') {
6022
- $("#css-version-parameter-missing").show ();
6023
- }
6024
- else if (css_version_parameter_string != plugin_version) {
6025
- console.log ('AD INSERTER: plugin version:', plugin_version + ', CSS file version:', css_version_parameter_string);
6026
- $("#css-version-parameter").show ();
6027
- }
6028
- }
6029
-
6030
- $("#css-version").html ("CSS<br />" + css_version);
6031
- $("#css-warning").show ();
6032
- }
6033
-
6034
- $('.header button').button().show ();
6035
-
6036
- $("#ai-form").submit (function (event) {
6037
- for (var tab = start; tab <= end; tab ++) {
6038
- var rotation_button = $('#rotation-' + tab);
6039
- if (rotation_button.parent ().find ('.icon-rotation').hasClass ('on')) {
6040
- event.preventDefault();
6041
-
6042
- $("#ai-tab-container").tabs ({active: tab - 1});
6043
-
6044
- var message = '<div class="checkbox-icon icon-rotation on" style="margin: 3px 10px 24px 0px;"></div><div>' + ai_admin.rotation_active + '</div>';
6045
- $('<div />').html(message).attr ('title', ai_admin.warning).dialog({
6046
- bgiframe: true,
6047
- draggable: false,
6048
- resizable: false,
6049
- modal: true,
6050
- height: "auto",
6051
- width: 300,
6052
- position: {my: 'center', at: 'center', of: '#ai-settings'},
6053
- buttons: [{
6054
- text: ai_admin.ok,
6055
- click: function() {
6056
- $(this).dialog ("close");
6057
- }
6058
- }
6059
- ],
6060
- });
6061
-
6062
- return;
6063
- }
6064
- }
6065
-
6066
- for (var tab = start; tab <= end; tab ++) {
6067
- remove_default_values (tab);
6068
- encode_code (tab);
6069
- }
6070
-
6071
- remove_default_values (0);
6072
- encode_code ('h');
6073
- encode_code ('f');
6074
- encode_code ('a');
6075
- });
6076
-
6077
- $("div#tab-999").attr ('id', 'ai-clipboard-template').insertBefore ("#ai-clipboard");
6078
-
6079
- configure_tabs ();
6080
-
6081
- $('#plugin_name').dblclick (function () {
6082
- $(".system-debugging").toggle();
6083
- });
6084
-
6085
- $('#ai-stars').click (function () {
6086
- if ($("#rating-value span").text () != '') {
6087
- $("#ai-rating-bar").css ('display', 'inline-block');
6088
- $('#ai-stars').hide ();
6089
- }
6090
- update_rating ('update', '');
6091
- });
6092
-
6093
- $("#ai-rating-bar").click (function () {
6094
- $("#ai-rating-bar").hide ();
6095
- $('#ai-stars').show ();
6096
- });
6097
-
6098
- $("#adsense-list").click (function () {
6099
- // $(this).blur ();
6100
-
6101
- toggle_adsense_list ();
6102
- });
6103
-
6104
- $("#ai-ads-txt").click (function () {
6105
- $(this).blur ();
6106
-
6107
- var container = $("#ads-txt-container");
6108
-
6109
- container.toggle ();
6110
-
6111
- if (container.is(':visible')) {
6112
- $("#ai-ads-txt .checkbox-icon.icon-ads-txt").addClass ('on');
6113
- load_ads_txt ();
6114
- } else {
6115
- $("#ai-ads-txt .checkbox-icon.icon-ads-txt").removeClass ('on');
6116
- }
6117
- });
6118
-
6119
- $("#page-checker-button").click (function () {
6120
- $("#page-checker-container").toggle ();
6121
-
6122
- if ($("#page-checker-container").is(':visible')) {
6123
- $(".page-checker-button").addClass ('blue');
6124
- $("#page-checker-button").addClass ('blue');
6125
- } else {
6126
- $(".page-checker-button").removeClass ('blue');
6127
- $("#page-checker-button").removeClass ('blue');
6128
- }
6129
- });
6130
-
6131
- $("#ai-manage-websites").click (function () {
6132
- $("#ai-manage-websites-container").toggle ();
6133
- $("#ai-manage-websites").toggleClass ('blue');
6134
-
6135
- // $("#ai-cancel-websites").removeClass ('red');
6136
- // $("#ai-save-websites").removeClass ('green');
6137
- $("#ai-cancel-websites").hide ();
6138
- $("#ai-save-websites").hide ();
6139
- $("#ai-rearrange-websites").removeClass ('blue');
6140
-
6141
- if ($("#ai-manage-websites-container").is(':visible')) {
6142
- reload_websites ();
6143
- }
6144
- });
6145
-
6146
- $("#ai-website-list-search").keyup (function (event) {
6147
- if (!website_list_search_reload) {
6148
- website_list_search_reload = true;
6149
- setTimeout (reload_websites, 200);
6150
- }
6151
- });
6152
-
6153
- $("#ai-list").click (function () {
6154
-
6155
- $("#ai-list").toggleClass ('blue');
6156
-
6157
- var container = $("#ai-list-container");
6158
- var list_sticky = $("#ai-pin-list").hasClass ('on');
6159
-
6160
- if (!list_sticky && ($("#ai-list").hasClass ('blue') != container.is(':visible'))) {
6161
- container.toggle ();
6162
- }
6163
-
6164
- if (container.is(':visible')) {
6165
- reload_list ();
6166
- }
6167
-
6168
- if ($("#ai-list").hasClass ('blue')) {
6169
- $("#plugin_name").hide ();
6170
- $("#block-ranges").show ();
6171
- } else {
6172
- $("#plugin_name").show ();
6173
- $("#block-ranges").hide ();
6174
- }
6175
- });
6176
-
6177
- $("#ai-list-search").keyup (function (event) {
6178
- if (!list_search_reload) {
6179
- list_search_reload = true;
6180
- setTimeout (reload_list, 200);
6181
- }
6182
- });
6183
-
6184
- $("#ai-load-all").click (function () {
6185
- $(this).toggleClass ('light-blue');
6186
- reload_list ();
6187
- });
6188
-
6189
- $("#ai-rearrange").click (function () {
6190
- $(this).toggleClass ('blue');
6191
-
6192
- var data_container = $("#ai-list-data");
6193
- var rearrange_controls = $('#list-rearrange-controls');
6194
- if ($(this).hasClass ('blue')) {
6195
- $("#ai-rearrange").attr ('title', ai_admin.cancel_rearrangement)
6196
- .tooltip({
6197
- track: true,
6198
- delay: 700,
6199
- showURL: false,
6200
- showBody: " | ",
6201
- fade: 250
6202
- });
6203
-
6204
- rearrange_controls.show ();
6205
- data_container.find ('tbody').sortable ({
6206
- start: function (event, ui) {$('#list-save').show ();},
6207
- placeholder: "ui-state-highlight"
6208
- }).css ('cursor', 'move');
6209
- } else {
6210
- data_container.find ('tbody').sortable ("disable");
6211
- $("#ai-rearrange").attr ('title', ai_admin.rearrange_block_order)
6212
- .tooltip({
6213
- track: true,
6214
- delay: 700,
6215
- showURL: false,
6216
- showBody: " | ",
6217
- fade: 250
6218
- });
6219
-
6220
- $('#list-save').hide ();
6221
- rearrange_controls.hide ();
6222
- reload_list ();
6223
- }
6224
- });
6225
-
6226
- $("#ai-save-changes").click (function () {
6227
- $('#list-rearrange-controls').addClass ('rearrange')
6228
- reload_list ();
6229
- });
6230
-
6231
- $("#ai-pin-list").click (function () {
6232
- $(this).toggleClass ('on');
6233
-
6234
- var sticky = $(this).hasClass ('on') ? '1' : '0';
6235
-
6236
- if (!$("#ai-list").hasClass ('blue')) {
6237
- $("#ai-list-container").toggle ();
6238
- }
6239
-
6240
- $.get (ajaxurl+"?action=ai_ajax_backend&blocks-sticky=" + sticky + "&start=" + start + "&end=" + end + '&ai_check=' + ai_nonce, function (response, status, xhr) {
6241
- if (status == "error") {
6242
- var message = "Error updating sticky: " + xhr.status + " " + xhr.statusText;
6243
- var data_container = $("#ai-list-data");
6244
- data_container.html (message);
6245
- if (debug) console.log (message);
6246
- } else {
6247
- if (debug) console.log ('AI blocks sticky:', response);
6248
- }
6249
- });
6250
- });
6251
-
6252
- if ($("#maxmind-db-status").hasClass ('maxmind-db-missing')) {
6253
- var page = ajaxurl+"?action=ai_ajax_backend&update=maxmind&ai_check=" + ai_nonce;
6254
-
6255
- $("span.maxmind-db-missing").text (ai_admin.downloading);
6256
- $.get (page, function (update_status) {
6257
-
6258
- if (update_status == '') {
6259
- $("span.maxmind-db-missing").closest ('.notice.notice-error').hide ();
6260
- $("#maxmind-db-status").text ('');
6261
- } else {
6262
- if (debug) console.log (update_status);
6263
- var status = JSON.parse (update_status);
6264
- if (debug) console.log (status);
6265
- if (typeof status !== "undefined") {
6266
- $(".notice span.maxmind-db-missing").text (status [0]);
6267
- $("#maxmind-db-status").text (status [1]);
6268
- } else $("span.maxmind-db-missing").text (ai_admin.update_error);
6269
- }
6270
- }).fail (function(jqXHR, status, err) {
6271
- $("span.maxmind-db-missing").text (ai_admin.download_error);
6272
- });
6273
- }
6274
-
6275
- $("#adsense-load-all").click (function () {
6276
- $(this).parent ().find ('.checkbox-icon').toggleClass ('on');
6277
- reload_adsense_list (false);
6278
- });
6279
-
6280
- $("#adsense-list-search").keyup (function (event) {
6281
- if (!adsense_search_reload) {
6282
- adsense_search_reload = true;
6283
- setTimeout (function() {reload_adsense_list (false);}, 200);
6284
- }
6285
- });
6286
-
6287
- $("#adsense-reload").click (function () {
6288
- $(this).parent ().find ('.checkbox-icon').addClass ('on');
6289
- setTimeout (function() {reload_adsense_list (true);}, 200);
6290
- });
6291
-
6292
- $("#clear-adsense-authorization").click (function () {
6293
- $("#adsense-list-data").text (ai_admin.updating);
6294
- update_adsense_authorization ('');
6295
- });
6296
-
6297
- $('.ai-block-code-demo').change (function () {
6298
- update_block_code_demo ();
6299
- }).on('input',function(e){
6300
- update_block_code_demo ();
6301
- });
6302
-
6303
- setTimeout (function() {update_rating ('');}, 1000);
6304
-
6305
- $("#license-key").dblclick (function () {
6306
- $("#hide-key").toggle ();
6307
- });
6308
-
6309
- $('input[title], button[title], label[title], h2[title], li[title], td[title], select[title], div[title], span[title]').tooltip({
6310
- track: true,
6311
- delay: 700,
6312
- showURL: false,
6313
- showBody: " | ",
6314
- fade: 250
6315
- });
6316
-
6317
- if (debug) console.log ("");
6318
- if (debug) console.log ("READY END");
6319
- if (debug) {
6320
- var current_time = new Date().getTime();
6321
- console.log ("main time: " + ((current_time - current_time_ready) / 1000).toFixed (3));
6322
- }
6323
-
6324
- $("#ads-txt-virtual").click (function () {
6325
-
6326
- function switch_to_physical () {
6327
- var virtual_button = $("#ads-txt-virtual");
6328
- virtual_button.removeClass ('violet');
6329
- virtual_button.attr ('title', virtual_button.attr ('title-physical'))
6330
- .tooltip({
6331
- track: true,
6332
- delay: 700,
6333
- showURL: false,
6334
- showBody: " | ",
6335
- fade: 250
6336
- });
6337
- setTimeout (function() {load_ads_txt ();}, 50);
6338
-
6339
- }
6340
- var editor_button = $("#ads-txt-editor");
6341
- var view = editor_button.hasClass ('editor') ? 'text' : 'table';
6342
- var virtual_button = $("#ads-txt-virtual");
6343
-
6344
- if (virtual_button.hasClass ('violet')) {
6345
- var message = ai_admin.switch_to_physical_ads_txt;
6346
- var ads_txt_data = $("#ads-txt-data").find ('textarea#ads-txt-text').val ();
6347
- var ads_txt_missing = $('#ads-txt-missing').length != 0;
6348
-
6349
- if (!ads_txt_missing && (view == 'table' || ads_txt_data != '')) {
6350
- $('<div />').html(message).attr ('title', ai_admin.warning).dialog({
6351
- bgiframe: true,
6352
- draggable: false,
6353
- resizable: false,
6354
- modal: true,
6355
- height: "auto",
6356
- width: 400,
6357
- position: {my: 'center', at: 'center', of: '#ads-txt-container'},
6358
- buttons: [{
6359
- text: ai_admin.switch,
6360
- click: function() {
6361
- $(this).dialog ("close");
6362
-
6363
- switch_to_physical ();
6364
- }
6365
- },{
6366
- text: ai_admin.cancel,
6367
- click: function() {
6368
- $(this).dialog ("close");
6369
- }
6370
- }
6371
- ],
6372
- });
6373
- } else switch_to_physical ();
6374
- } else {
6375
- virtual_button.addClass ('violet');
6376
- virtual_button.attr ('title', virtual_button.attr ('title-virtual'))
6377
- .tooltip({
6378
- track: true,
6379
- delay: 700,
6380
- showURL: false,
6381
- showBody: " | ",
6382
- fade: 250
6383
- });
6384
- setTimeout (function() {load_ads_txt ();}, 50);
6385
- }
6386
-
6387
- });
6388
-
6389
- $("#ads-txt-reload").click (function () {
6390
- var editor_button = $("#ads-txt-editor");
6391
- if (editor_button.hasClass ('editor')) {
6392
- editor_button.removeClass ('editor');
6393
- }
6394
- setTimeout (function() {load_ads_txt ();}, 50);
6395
- });
6396
-
6397
- $("#ads-txt-editor").click (function () {
6398
- if ($(this).hasClass ('editor')) {
6399
- setTimeout (function() {save_ads_txt (true);}, 50);
6400
- } else {
6401
- $(this).addClass ('editor');
6402
-
6403
- setTimeout (function() {load_ads_txt ();}, 50);
6404
-
6405
- $(this).attr ('title', $(this).attr ('title-table'))
6406
- .tooltip({
6407
- track: true,
6408
- delay: 700,
6409
- showURL: false,
6410
- showBody: " | ",
6411
- fade: 250
6412
- });
6413
- }
6414
- });
6415
-
6416
- $("#ads-txt-search").keyup (function (event) {
6417
- if (!ads_txt_reload) {
6418
- ads_txt_reload = true;
6419
- setTimeout (function() {load_ads_txt ();}, 200);
6420
- }
6421
- });
6422
-
6423
- // $(document).keydown (function (event) {
6424
- // if (event.which == "17") {
6425
- // ai_ctrl_pressed = true;
6426
-
6427
- // var public_report_button = $('.public-report-button');
6428
- // public_report_button.addClass ('light-red');
6429
- // public_report_button.attr ('title', $('.public-report-button').first ().attr ('title-rw'))
6430
- // .tooltip({
6431
- // track: true,
6432
- // delay: 700,
6433
- // showURL: false,
6434
- // showBody: " | ",
6435
- // fade: 250
6436
- // });
6437
- // }
6438
- // });
6439
-
6440
- // $(document).keyup (function() {
6441
- // if (ai_ctrl_pressed) {
6442
- // ai_ctrl_pressed = false;
6443
-
6444
- // var public_report_button = $('.public-report-button');
6445
- // public_report_button.removeClass ('light-red');
6446
- // public_report_button.attr ('title', $('.public-report-button').first ().attr ('title-ro'))
6447
- // .tooltip({
6448
- // track: true,
6449
- // delay: 700,
6450
- // showURL: false,
6451
- // showBody: " | ",
6452
- // fade: 250
6453
- // });
6454
- // }
6455
- // });
6456
-
6457
- $(".ai-public-controls").dblclick (function () {
6458
- $(this).toggleClass ('on');
6459
- });
6460
-
6461
- $(".public-report-button").click (function () {
6462
- var report_data_elements = JSON.parse ($(this).attr ('report-data'));
6463
- var report_url_prefix = report_data_elements [0]
6464
- var report_dates_block = report_data_elements [1];
6465
- var report_controls = $(this).parent ().parent ().parent ().parent ().find ('.ai-public-controls').hasClass ('on') ? '1' : '0';
6466
- var report_range_name = $(this).parent ().parent ().parent ().parent ().find ('.custom-range-controls').attr ('range-name');
6467
- var report_adb = report_data_elements [2];
6468
- var report_range = report_data_elements [2];
6469
- var report = report_dates_block + report_controls + report_adb + report_range_name;
6470
- var report_id = b64e (report).replaceAll ('+', '.').replaceAll ('/', '_').replaceAll ('=', '-');
6471
- var url = report_url_prefix + md5 (report).substring (0, 2) + report_id;
6472
-
6473
- window.open (url, 'ai-report');
6474
- });
6475
-
6476
- if ($("#ai-list-data").hasClass ('ai-sticky')) {
6477
- configure_list ();
6478
- }
6479
-
6480
- $("#ai-cancel-websites").click (function () {
6481
- // $("#ai-cancel-websites").removeClass ('red');
6482
- // $("#ai-save-websites").removeClass ('green');
6483
- $("#ai-cancel-websites").hide ();
6484
- $("#ai-save-websites").hide ();
6485
- $("#ai-rearrange-websites").removeClass ('blue');
6486
-
6487
- reload_websites ();
6488
- });
6489
-
6490
- $("#ai-add-website").click (function () {
6491
- // $("#ai-cancel-websites").removeClass ('red');
6492
- // $("#ai-save-websites").removeClass ('green');
6493
- $("#ai-cancel-websites").hide ();
6494
- $("#ai-save-websites").hide ();
6495
- $("#ai-rearrange-websites").removeClass ('blue');
6496
-
6497
- ai_reload_websites_function = function () {
6498
- $('#ai-website-list-table tr.ai-website-list').last ().find (".ai-website-labels.ai-website-desc").click ();
6499
- }
6500
-
6501
- reload_websites ('&add=');
6502
- });
6503
-
6504
- $("#ai-save-websites").click (function () {
6505
-
6506
- var connect = $(this).attr ('data-connect');
6507
-
6508
- if (typeof connect !== typeof undefined && connect !== false) {
6509
- $(this).removeAttr ('data-connect');
6510
- connect = '&connect=' + connect;
6511
- } else connect = '';
6512
-
6513
- $('#ai-website-list-table tr.ai-website-list').each (function () {
6514
- var row = $(this);
6515
-
6516
- if (row.find (".ai-website-editor .ai-website-key").is (':visible')) {
6517
- row.find (".ai-website-editor .ai-website-key").attr ('data-key', row.find (".ai-website-editor .ai-website-key").val ());
6518
- row.find (".ai-website-labels.ai-website-desc").text (row.find (".ai-website-editor .ai-website-desc").val ());
6519
- row.find (".ai-website-labels.ai-website-url").text (row.find (".ai-website-editor .ai-website-url").val ());
6520
-
6521
- row.find (".ai-website-labels").show ();
6522
- row.find (".ai-website-editor").hide ();
6523
- }
6524
- });
6525
-
6526
- var websites = Array ();
6527
-
6528
- $('#ai-website-list-table tr.ai-website-list').each (function () {
6529
- var row = $(this);
6530
-
6531
- var url = row.find (".ai-website-labels.ai-website-url").text ().trim ();
6532
- var desc = row.find (".ai-website-labels.ai-website-desc").text ().trim ();
6533
- var key = row.find (".ai-website-editor .ai-website-key").attr ('data-key').trim ();
6534
-
6535
- if (url != '') {
6536
- websites.push ({'url': url, 'name': desc, 'key': b64e (key)});
6537
- }
6538
- });
6539
-
6540
- // $("#ai-cancel-websites").removeClass ('red');
6541
- // $("#ai-save-websites").removeClass ('green');
6542
- $("#ai-cancel-websites").hide ();
6543
- $("#ai-save-websites").hide ();
6544
- $("#ai-rearrange-websites").removeClass ('blue');
6545
-
6546
- reload_websites ('&save=' + b64e (JSON.stringify (websites)) + connect);
6547
- });
6548
-
6549
- $("#ai-rearrange-websites").click (function () {
6550
- $(this).toggleClass ('blue');
6551
-
6552
- var data_container = $("#ai-website-data");
6553
-
6554
- if ($(this).hasClass ('blue')) {
6555
- $('#ai-website-list-table .ai-delete-website').each (function () {
6556
- var row = $(this).closest ('tr.ai-website-list');
6557
- var connected = row.find ('.ai-connect-website .checkbox-icon').hasClass ('on');
6558
-
6559
- if (!connected) {
6560
- $(this).show ();
6561
- }
6562
- });
6563
-
6564
- data_container.find ('tbody').sortable ({
6565
- start: function (event, ui) {
6566
- // $("#ai-cancel-websites").addClass ('red');
6567
- // $("#ai-save-websites").addClass ('green');
6568
- $("#ai-cancel-websites").show ();
6569
- $("#ai-save-websites").show ();
6570
- },
6571
- placeholder: "ui-state-highlight"
6572
- }).css ('cursor', 'move');
6573
- } else {
6574
- data_container.find ('tbody').sortable ("disable");
6575
- reload_websites ();
6576
- }
6577
- });
6578
-
6579
- if ($(".ai-managing").length) {
6580
- setTimeout (function () {window.location.href = ai_settings;}, 30 * 60 * 1000);
6581
-
6582
- check_managing_slave ();
6583
-
6584
- $("#ai-connected").click (function () {
6585
- $(this).css ('color', '#ababab');
6586
- $('#ai-loading').show ();
6587
- ai_reload_websites_function = function () {
6588
- if ($('#ai-website-data .ai-ajax-error').length == 0) {
6589
- window.location.href = ai_settings;
6590
- }
6591
- }
6592
-
6593
- reload_websites ('&connect=');
6594
- });
6595
- }
6596
- });
6597
-
6598
-
1
+ var javascript_version = "2.7.0";
2
+ var ignore_key = true;
3
+ var start = 1;
4
+ var end = 16;
5
+ var active_tab = 1;
6
+ var active_tab_0 = 0;
7
+ var tabs_to_configure = new Array();
8
+ var debug = false;
9
+ var debug_title = false;
10
+ var save_enabled = true;
11
+
12
+ var current_tab = 0;
13
+ var next_tab = 0;
14
+
15
+ var syntax_highlighting = false;
16
+ var settings_page = "";
17
+
18
+ var dateFormat = "yy-mm-dd";
19
+ var timeFormat = "H:i:s";
20
+
21
+ var list_search_reload = false;
22
+ var website_list_search_reload = false;
23
+ //var ai_ctrl_pressed = false;
24
+
25
+ var AI_DISABLED = 0;
26
+ var AI_BEFORE_POST = 1;
27
+ var AI_AFTER_POST = 2;
28
+ var AI_BEFORE_CONTENT = 3;
29
+ var AI_AFTER_CONTENT = 4;
30
+ var AI_BEFORE_PARAGRAPH = 5;
31
+ var AI_AFTER_PARAGRAPH = 6;
32
+ var AI_BEFORE_EXCERPT = 7;
33
+ var AI_AFTER_EXCERPT = 8;
34
+ var AI_BETWEEN_POSTS = 9;
35
+ var AI_BEFORE_COMMENTS = 10;
36
+ var AI_BETWEEN_COMMENTS = 11;
37
+ var AI_AFTER_COMMENTS = 12;
38
+ var AI_FOOTER = 13;
39
+ var AI_ABOVE_HEADER = 14;
40
+ var AI_BEFORE_HTML_ELEMENT = 15;
41
+ var AI_AFTER_HTML_ELEMENT = 16;
42
+ var AI_INSIDE_HTML_ELEMENT = 17;
43
+ var AI_BEFORE_IMAGE = 18;
44
+ var AI_AFTER_IMAGE = 19;
45
+
46
+
47
+ var AI_ALIGNMENT_DEFAULT = 0;
48
+ var AI_ALIGNMENT_LEFT = 1;
49
+ var AI_ALIGNMENT_RIGHT = 2;
50
+ var AI_ALIGNMENT_CENTER = 3;
51
+ var AI_ALIGNMENT_FLOAT_LEFT = 4;
52
+ var AI_ALIGNMENT_FLOAT_RIGHT = 5;
53
+ var AI_ALIGNMENT_NO_WRAPPING = 6;
54
+ var AI_ALIGNMENT_CUSTOM_CSS = 7;
55
+ var AI_ALIGNMENT_STICKY_LEFT = 8;
56
+ var AI_ALIGNMENT_STICKY_RIGHT = 9;
57
+ var AI_ALIGNMENT_STICKY_TOP = 10;
58
+ var AI_ALIGNMENT_STICKY_BOTTOM = 11;
59
+ var AI_ALIGNMENT_STICKY = 12;
60
+
61
+ var AI_ADB_ACTION_NONE = 0;
62
+ var AI_ADB_ACTION_MESSAGE = 1;
63
+ var AI_ADB_ACTION_REDIRECTION = 2;
64
+
65
+ var AI_ADB_BLOCK_ACTION_DO_NOTHING = 0;
66
+ var AI_ADB_BLOCK_ACTION_REPLACE = 1;
67
+ var AI_ADB_BLOCK_ACTION_SHOW = 2;
68
+ var AI_ADB_BLOCK_ACTION_HIDE = 3;
69
+
70
+ var AI_CODE_UNKNOWN = 100;
71
+ var AI_CODE_BANNER = 0;
72
+ var AI_CODE_ADSENSE = 1;
73
+ var AI_CODE_AMAZON = 2;
74
+
75
+ var AI_ADSENSE_STANDARD = 0;
76
+ var AI_ADSENSE_LINK = 1;
77
+ var AI_ADSENSE_IN_ARTICLE = 2;
78
+ var AI_ADSENSE_IN_FEED = 3;
79
+ var AI_ADSENSE_MATCHED_CONTENT = 4;
80
+
81
+ var AI_ADSENSE_SIZE_FIXED = 0;
82
+ var AI_ADSENSE_SIZE_RESPONSIVE = 1;
83
+ var AI_ADSENSE_SIZE_FIXED_BY_VIEWPORT = 2;
84
+
85
+ var AI_HTML_INSERTION_CLIENT_SIDE = 0;
86
+ //var AI_HTML_INSERTION_CLIENT_SIDE_DOM_READY = 1;
87
+ var AI_HTML_INSERTION_SEREVR_SIDE = 2;
88
+
89
+ var AI_STICK_TO_THE_LEFT = 0;
90
+ var AI_STICK_TO_THE_CONTENT_LEFT = 1;
91
+ var AI_STICK_HORIZONTAL_CENTER = 2;
92
+ var AI_STICK_TO_THE_CONTENT_RIGHT = 3;
93
+ var AI_STICK_TO_THE_RIGHT = 4;
94
+
95
+ var AI_STICK_TO_THE_TOP = 0;
96
+ var AI_STICK_VERTICAL_CENTER = 1;
97
+ var AI_SCROLL_WITH_THE_CONTENT = 2;
98
+ var AI_STICK_TO_THE_BOTTOM = 3;
99
+
100
+ var AI_ANIMATION_NONE = 0;
101
+
102
+ var AI_BACKGROUND_REPEAT_DEFAULT = 0;
103
+ var AI_BACKGROUND_REPEAT_NO = 1;
104
+ var AI_BACKGROUND_REPEAT_YES = 2;
105
+ var AI_BACKGROUND_REPEAT_HORIZONTALY = 3;
106
+ var AI_BACKGROUND_REPEAT_VERTICALLY = 4;
107
+ var AI_BACKGROUND_REPEAT_SPACE = 5;
108
+ var AI_BACKGROUND_REPEAT_ROUND = 6;
109
+
110
+ var AI_BACKGROUND_SIZE_DEFAULT = 0;
111
+ var AI_BACKGROUND_SIZE_COVER = 1;
112
+ var AI_BACKGROUND_SIZE_CONTAIN = 2;
113
+ var AI_BACKGROUND_SIZE_FILL = 3;
114
+
115
+ var before_update_selection_from_list = null;
116
+
117
+ /*
118
+ * jQuery Tooltip plugin 1.3
119
+ *
120
+ * http://bassistance.de/jquery-plugins/jquery-plugin-tooltip/
121
+ * http://docs.jquery.com/Plugins/Tooltip
122
+ *
123
+ * Copyright (c) 2006 - 2008 J�rn Zaefferer
124
+ *
125
+ * $Id: jquery.tooltip.js 5741 2008-06-21 15:22:16Z joern.zaefferer $
126
+ *
127
+ * Dual licensed under the MIT and GPL licenses:
128
+ * http://www.opensource.org/licenses/mit-license.php
129
+ * http://www.gnu.org/licenses/gpl.html
130
+ */
131
+ (function($) {
132
+ // the tooltip element
133
+ var helper = {},
134
+ // the current tooltipped element
135
+ current,
136
+ // the title of the current element, used for restoring
137
+ title,
138
+ // timeout id for delayed tooltips
139
+ tID,
140
+ // IE 5.5 or 6
141
+ // IE = $.browser.msie && /MSIE\s(5\.5|6\.)/.test(navigator.userAgent),
142
+ IE = false,
143
+ // flag for mouse tracking
144
+ track = false;
145
+ $.tooltip = {
146
+ blocked: false,
147
+ defaults: {
148
+ delay: 200,
149
+ fade: false,
150
+ showURL: true,
151
+ extraClass: "",
152
+ top: 15,
153
+ left: 15,
154
+ id: "ai-tooltip"
155
+ },
156
+ block: function() {
157
+ $.tooltip.blocked = !$.tooltip.blocked;
158
+ }
159
+ };
160
+ $.fn.extend({
161
+ tooltip: function(settings) {
162
+ settings = $.extend({}, $.tooltip.defaults, settings);
163
+ createHelper(settings);
164
+ return this.each(function() {
165
+ $.data(this, "tooltip", settings);
166
+ this.tOpacity = helper.parent.css("opacity");
167
+ // copy tooltip into its own expando and remove the title
168
+ this.tooltipText = this.title;
169
+ $(this).removeAttr("title");
170
+ // also remove alt attribute to prevent default tooltip in IE
171
+ this.alt = "";
172
+ })
173
+ .mouseover(save)
174
+ .mouseout(hide)
175
+ .click(hide);
176
+ },
177
+ fixPNG: IE ? function() {
178
+ return this.each(function() {
179
+ var image = $(this).css('backgroundImage');
180
+ if (image.match(/^url\(["']?(.*\.png)["']?\)$/i)) {
181
+ image = RegExp.$1;
182
+ $(this).css({
183
+ 'backgroundImage': 'none',
184
+ 'filter': "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod=crop, src='" + image + "')"
185
+ }).each(function() {
186
+ var position = $(this).css('position');
187
+ if (position != 'absolute' && position != 'relative')
188
+ $(this).css('position', 'relative');
189
+ });
190
+ }
191
+ });
192
+ } : function() {
193
+ return this;
194
+ },
195
+ unfixPNG: IE ? function() {
196
+ return this.each(function() {
197
+ $(this).css({
198
+ 'filter': '',
199
+ backgroundImage: ''
200
+ });
201
+ });
202
+ } : function() {
203
+ return this;
204
+ },
205
+ hideWhenEmpty: function() {
206
+ return this.each(function() {
207
+ $(this)[$(this).html() ? "show" : "hide"]();
208
+ });
209
+ },
210
+ url: function() {
211
+ return this.attr('href') || this.attr('src');
212
+ }
213
+ });
214
+ function createHelper(settings) {
215
+ // there can be only one tooltip helper
216
+ if (helper.parent)
217
+ return;
218
+ // create the helper, h3 for title, div for url
219
+ helper.parent = $('<div id="' + settings.id + '"><h3></h3><div class="body"></div><div class="url"></div></div>')
220
+ // add to document
221
+ .appendTo(document.body)
222
+ // hide it at first
223
+ .hide();
224
+ // apply bgiframe if available
225
+ if ($.fn.bgiframe)
226
+ helper.parent.bgiframe();
227
+ // save references to title and url elements
228
+ helper.title = $('h3', helper.parent);
229
+ helper.body = $('div.body', helper.parent);
230
+ helper.url = $('div.url', helper.parent);
231
+ }
232
+ function settings(element) {
233
+ return $.data(element, "tooltip");
234
+ }
235
+ // main event handler to start showing tooltips
236
+ function handle(event) {
237
+ // show helper, either with timeout or on instant
238
+ if (settings(this).delay)
239
+ tID = setTimeout(show, settings(this).delay);
240
+ else
241
+ show();
242
+ // if selected, update the helper position when the mouse moves
243
+ track = !!settings(this).track;
244
+ $(document.body).bind('mousemove', update);
245
+ // update at least once
246
+ update(event);
247
+ }
248
+ // save elements title before the tooltip is displayed
249
+ function save() {
250
+ // if this is the current source, or it has no title (occurs with click event), stop
251
+ if ($.tooltip.blocked || this == current || (!this.tooltipText && !settings(this).bodyHandler))
252
+ return;
253
+ // save current
254
+ current = this;
255
+ title = this.tooltipText;
256
+
257
+ title = title.replace (/\[\[(.+?)\]\]/g, '<span class="tooltip-code">$1</span>');
258
+ title = title.replace (/\[BR\]/g, '<br />');
259
+ title = title.replace (/\[HR\]/g, '<hr />');
260
+ title = title.replace (/(\[ADINSERTER.+\])/g, '<span class="tooltip-code">$1</span>');
261
+ title = title.replace (/(\%N)/g, '<span class="tooltip-code">$1</span>');
262
+ title = title.replace (/(\[\*\])/g, '<span class="tooltip-icon"><span class="dashicons dashicons-admin-generic" style="width: 11px; height: 11px; font-size: 12px; line-height: unset;"></span></span>');
263
+ title = title.replace (/(http[^ ]+)/g, '<span class="tooltip-code">$1</span>');
264
+ title = title.replace (/(pub-[0-9]+)/g, '<span class="tooltip-code">$1</span>');
265
+
266
+ if (settings(this).bodyHandler) {
267
+ helper.title.hide();
268
+ var bodyContent = settings(this).bodyHandler.call(this);
269
+ if (bodyContent.nodeType || bodyContent.jquery) {
270
+ helper.body.empty().append(bodyContent)
271
+ } else {
272
+ helper.body.html(bodyContent);
273
+ }
274
+ helper.body.show();
275
+ } else if (settings(this).showBody) {
276
+ var parts = title.split(settings(this).showBody);
277
+ if (parts.length == 2) {
278
+ helper.title.html(parts.shift()).show();
279
+ } else {
280
+ helper.title.hide();
281
+ }
282
+ helper.body.empty();
283
+ for (var i = 0, part;
284
+ (part = parts[i]); i++) {
285
+ if (i > 0)
286
+ helper.body.append("<br/>");
287
+ helper.body.append(part);
288
+ }
289
+ helper.body.hideWhenEmpty();
290
+ } else {
291
+ helper.title.html(title).show();
292
+ helper.body.hide();
293
+ }
294
+ // if element has href or src, add and show it, otherwise hide it
295
+ if (settings(this).showURL && $(this).url())
296
+ helper.url.html($(this).url().replace('http://', '')).show();
297
+ else
298
+ helper.url.hide();
299
+ // add an optional class for this tip
300
+ helper.parent.addClass(settings(this).extraClass);
301
+ // fix PNG background for IE
302
+ if (settings(this).fixPNG)
303
+ helper.parent.fixPNG();
304
+ handle.apply(this, arguments);
305
+ }
306
+ // delete timeout and show helper
307
+ function show() {
308
+ tID = null;
309
+ if ((!IE || !$.fn.bgiframe) && settings(current).fade) {
310
+ if (helper.parent.is(":animated"))
311
+ helper.parent.stop().show().fadeTo(settings(current).fade, current.tOpacity);
312
+ else
313
+ helper.parent.is(':visible') ? helper.parent.fadeTo(settings(current).fade, current.tOpacity) : helper.parent.fadeIn(settings(current).fade);
314
+ } else {
315
+ helper.parent.show();
316
+ }
317
+ update();
318
+ }
319
+ /**
320
+ * callback for mousemove
321
+ * updates the helper position
322
+ * removes itself when no current element
323
+ */
324
+ function update(event) {
325
+ if ($.tooltip.blocked)
326
+ return;
327
+ if (event && event.target.tagName == "OPTION") {
328
+ return;
329
+ }
330
+ // stop updating when tracking is disabled and the tooltip is visible
331
+ if (!track && helper.parent.is(":visible")) {
332
+ $(document.body).unbind('mousemove', update)
333
+ }
334
+ // if no current element is available, remove this listener
335
+ if (current == null) {
336
+ $(document.body).unbind('mousemove', update);
337
+ return;
338
+ }
339
+ // remove position helper classes
340
+ helper.parent.removeClass("viewport-right").removeClass("viewport-bottom");
341
+ var left = helper.parent[0].offsetLeft;
342
+ var top = helper.parent[0].offsetTop;
343
+ if (event) {
344
+ // position the helper 15 pixel to bottom right, starting from mouse position
345
+ left = event.pageX + settings(current).left;
346
+ top = event.pageY + settings(current).top;
347
+ var right = 'auto';
348
+ if (settings(current).positionLeft) {
349
+ right = $(window).width() - left;
350
+ left = 'auto';
351
+ }
352
+ helper.parent.css({
353
+ left: left,
354
+ right: right,
355
+ top: top
356
+ });
357
+ }
358
+ var v = viewport(),
359
+ h = helper.parent[0];
360
+ // check horizontal position
361
+ if (v.x + v.cx < h.offsetLeft + h.offsetWidth) {
362
+ left -= h.offsetWidth + 20 + settings(current).left;
363
+ helper.parent.css({
364
+ left: left + 'px'
365
+ }).addClass("viewport-right");
366
+ }
367
+ // check vertical position
368
+ if (v.y + v.cy < h.offsetTop + h.offsetHeight) {
369
+ top -= h.offsetHeight + 20 + settings(current).top;
370
+ helper.parent.css({
371
+ top: top + 'px'
372
+ }).addClass("viewport-bottom");
373
+ }
374
+ }
375
+ function viewport() {
376
+ return {
377
+ x: $(window).scrollLeft(),
378
+ y: $(window).scrollTop(),
379
+ cx: $(window).width(),
380
+ cy: $(window).height()
381
+ };
382
+ }
383
+ // hide helper and restore added classes and the title
384
+ function hide(event) {
385
+ if ($.tooltip.blocked)
386
+ return;
387
+ // clear timeout if possible
388
+ if (tID)
389
+ clearTimeout(tID);
390
+ // no more current element
391
+ current = null;
392
+ var tsettings = settings(this);
393
+ function complete() {
394
+ helper.parent.removeClass(tsettings.extraClass).hide().css("opacity", "");
395
+ }
396
+ if ((!IE || !$.fn.bgiframe) && tsettings.fade) {
397
+ if (helper.parent.is(':animated'))
398
+ helper.parent.stop().fadeTo(tsettings.fade, 0, complete);
399
+ else
400
+ helper.parent.stop().fadeOut(tsettings.fade, complete);
401
+ } else
402
+ complete();
403
+ if (settings(this).fixPNG)
404
+ helper.parent.unfixPNG();
405
+ }
406
+ })(jQuery);
407
+
408
+ function b64e (str) {
409
+ // first we use encodeURIComponent to get percent-encoded UTF-8,
410
+ // then we convert the percent encodings into raw bytes which
411
+ // can be fed into btoa.
412
+ return btoa (encodeURIComponent (str).replace (/%([0-9A-F]{2})/g,
413
+ function toSolidBytes (match, p1) {
414
+ return String.fromCharCode ('0x' + p1);
415
+ }));
416
+ }
417
+
418
+ function b64d (str) {
419
+ // Going backwards: from bytestream, to percent-encoding, to original string.
420
+ return decodeURIComponent (atob (str).split ('').map (function(c) {
421
+ return '%' + ('00' + c.charCodeAt (0).toString (16)).slice (-2);
422
+ }).join (''));
423
+ }
424
+
425
+ // http://www.myersdaily.org/joseph/javascript/md5.js
426
+
427
+ function md5cycle (x, k) {
428
+ var a = x[0],
429
+ b = x[1],
430
+ c = x[2],
431
+ d = x[3];
432
+ a = ff(a, b, c, d, k[0], 7, -680876936);
433
+ d = ff(d, a, b, c, k[1], 12, -389564586);
434
+ c = ff(c, d, a, b, k[2], 17, 606105819);
435
+ b = ff(b, c, d, a, k[3], 22, -1044525330);
436
+ a = ff(a, b, c, d, k[4], 7, -176418897);
437
+ d = ff(d, a, b, c, k[5], 12, 1200080426);
438
+ c = ff(c, d, a, b, k[6], 17, -1473231341);
439
+ b = ff(b, c, d, a, k[7], 22, -45705983);
440
+ a = ff(a, b, c, d, k[8], 7, 1770035416);
441
+ d = ff(d, a, b, c, k[9], 12, -1958414417);
442
+ c = ff(c, d, a, b, k[10], 17, -42063);
443
+ b = ff(b, c, d, a, k[11], 22, -1990404162);
444
+ a = ff(a, b, c, d, k[12], 7, 1804603682);
445
+ d = ff(d, a, b, c, k[13], 12, -40341101);
446
+ c = ff(c, d, a, b, k[14], 17, -1502002290);
447
+ b = ff(b, c, d, a, k[15], 22, 1236535329);
448
+ a = gg(a, b, c, d, k[1], 5, -165796510);
449
+ d = gg(d, a, b, c, k[6], 9, -1069501632);
450
+ c = gg(c, d, a, b, k[11], 14, 643717713);
451
+ b = gg(b, c, d, a, k[0], 20, -373897302);
452
+ a = gg(a, b, c, d, k[5], 5, -701558691);
453
+ d = gg(d, a, b, c, k[10], 9, 38016083);
454
+ c = gg(c, d, a, b, k[15], 14, -660478335);
455
+ b = gg(b, c, d, a, k[4], 20, -405537848);
456
+ a = gg(a, b, c, d, k[9], 5, 568446438);
457
+ d = gg(d, a, b, c, k[14], 9, -1019803690);
458
+ c = gg(c, d, a, b, k[3], 14, -187363961);
459
+ b = gg(b, c, d, a, k[8], 20, 1163531501);
460
+ a = gg(a, b, c, d, k[13], 5, -1444681467);
461
+ d = gg(d, a, b, c, k[2], 9, -51403784);
462
+ c = gg(c, d, a, b, k[7], 14, 1735328473);
463
+ b = gg(b, c, d, a, k[12], 20, -1926607734);
464
+ a = hh(a, b, c, d, k[5], 4, -378558);
465
+ d = hh(d, a, b, c, k[8], 11, -2022574463);
466
+ c = hh(c, d, a, b, k[11], 16, 1839030562);
467
+ b = hh(b, c, d, a, k[14], 23, -35309556);
468
+ a = hh(a, b, c, d, k[1], 4, -1530992060);
469
+ d = hh(d, a, b, c, k[4], 11, 1272893353);
470
+ c = hh(c, d, a, b, k[7], 16, -155497632);
471
+ b = hh(b, c, d, a, k[10], 23, -1094730640);
472
+ a = hh(a, b, c, d, k[13], 4, 681279174);
473
+ d = hh(d, a, b, c, k[0], 11, -358537222);
474
+ c = hh(c, d, a, b, k[3], 16, -722521979);
475
+ b = hh(b, c, d, a, k[6], 23, 76029189);
476
+ a = hh(a, b, c, d, k[9], 4, -640364487);
477
+ d = hh(d, a, b, c, k[12], 11, -421815835);
478
+ c = hh(c, d, a, b, k[15], 16, 530742520);
479
+ b = hh(b, c, d, a, k[2], 23, -995338651);
480
+ a = ii(a, b, c, d, k[0], 6, -198630844);
481
+ d = ii(d, a, b, c, k[7], 10, 1126891415);
482
+ c = ii(c, d, a, b, k[14], 15, -1416354905);
483
+ b = ii(b, c, d, a, k[5], 21, -57434055);
484
+ a = ii(a, b, c, d, k[12], 6, 1700485571);
485
+ d = ii(d, a, b, c, k[3], 10, -1894986606);
486
+ c = ii(c, d, a, b, k[10], 15, -1051523);
487
+ b = ii(b, c, d, a, k[1], 21, -2054922799);
488
+ a = ii(a, b, c, d, k[8], 6, 1873313359);
489
+ d = ii(d, a, b, c, k[15], 10, -30611744);
490
+ c = ii(c, d, a, b, k[6], 15, -1560198380);
491
+ b = ii(b, c, d, a, k[13], 21, 1309151649);
492
+ a = ii(a, b, c, d, k[4], 6, -145523070);
493
+ d = ii(d, a, b, c, k[11], 10, -1120210379);
494
+ c = ii(c, d, a, b, k[2], 15, 718787259);
495
+ b = ii(b, c, d, a, k[9], 21, -343485551);
496
+ x[0] = add32(a, x[0]);
497
+ x[1] = add32(b, x[1]);
498
+ x[2] = add32(c, x[2]);
499
+ x[3] = add32(d, x[3]);
500
+ }
501
+ function cmn(q, a, b, x, s, t) {
502
+ a = add32(add32(a, q), add32(x, t));
503
+ return add32((a << s) | (a >>> (32 - s)), b);
504
+ }
505
+ function ff(a, b, c, d, x, s, t) {
506
+ return cmn((b & c) | ((~b) & d), a, b, x, s, t);
507
+ }
508
+ function gg(a, b, c, d, x, s, t) {
509
+ return cmn((b & d) | (c & (~d)), a, b, x, s, t);
510
+ }
511
+ function hh(a, b, c, d, x, s, t) {
512
+ return cmn(b ^ c ^ d, a, b, x, s, t);
513
+ }
514
+ function ii(a, b, c, d, x, s, t) {
515
+ return cmn(c ^ (b | (~d)), a, b, x, s, t);
516
+ }
517
+ function md51(s) {
518
+ txt = '';
519
+ var n = s.length,
520
+ state = [1732584193, -271733879, -1732584194, 271733878],
521
+ i;
522
+ for (i = 64; i <= s.length; i += 64) {
523
+ md5cycle(state, md5blk(s.substring(i - 64, i)));
524
+ }
525
+ s = s.substring(i - 64);
526
+ var tail = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
527
+ for (i = 0; i < s.length; i++)
528
+ tail[i >> 2] |= s.charCodeAt(i) << ((i % 4) << 3);
529
+ tail[i >> 2] |= 0x80 << ((i % 4) << 3);
530
+ if (i > 55) {
531
+ md5cycle(state, tail);
532
+ for (i = 0; i < 16; i++) tail[i] = 0;
533
+ }
534
+ tail[14] = n * 8;
535
+ md5cycle(state, tail);
536
+ return state;
537
+ }
538
+ /* there needs to be support for Unicode here,
539
+ * unless we pretend that we can redefine the MD-5
540
+ * algorithm for multi-byte characters (perhaps
541
+ * by adding every four 16-bit characters and
542
+ * shortening the sum to 32 bits). Otherwise
543
+ * I suggest performing MD-5 as if every character
544
+ * was two bytes--e.g., 0040 0025 = @%--but then
545
+ * how will an ordinary MD-5 sum be matched?
546
+ * There is no way to standardize text to something
547
+ * like UTF-8 before transformation; speed cost is
548
+ * utterly prohibitive. The JavaScript standard
549
+ * itself needs to look at this: it should start
550
+ * providing access to strings as preformed UTF-8
551
+ * 8-bit unsigned value arrays.
552
+ */
553
+ function md5blk(s) { /* I figured global was faster. */
554
+ var md5blks = [],
555
+ i; /* Andy King said do it this way. */
556
+ for (i = 0; i < 64; i += 4) {
557
+ md5blks[i >> 2] = s.charCodeAt(i) +
558
+ (s.charCodeAt(i + 1) << 8) +
559
+ (s.charCodeAt(i + 2) << 16) +
560
+ (s.charCodeAt(i + 3) << 24);
561
+ }
562
+ return md5blks;
563
+ }
564
+ var hex_chr = '0123456789abcdef'.split('');
565
+ function rhex(n) {
566
+ var s = '',
567
+ j = 0;
568
+ for (; j < 4; j++)
569
+ s += hex_chr[(n >> (j * 8 + 4)) & 0x0F] +
570
+ hex_chr[(n >> (j * 8)) & 0x0F];
571
+ return s;
572
+ }
573
+ function hex(x) {
574
+ for (var i = 0; i < x.length; i++)
575
+ x[i] = rhex(x[i]);
576
+ return x.join('');
577
+ }
578
+ function md5(s) {
579
+ return hex(md51(s));
580
+ }
581
+ /* this function is much faster,
582
+ so if possible we use it. Some IEs
583
+ are the only ones I know of that
584
+ need the idiotic second function,
585
+ generated by an if clause. */
586
+ function add32(a, b) {
587
+ return (a + b) & 0xFFFFFFFF;
588
+ }
589
+ if (md5('hello') != '5d41402abc4b2a76b9719d911017c592') {
590
+ function add32(x, y) {
591
+ var lsw = (x & 0xFFFF) + (y & 0xFFFF),
592
+ msw = (x >> 16) + (y >> 16) + (lsw >> 16);
593
+ return (msw << 16) | (lsw & 0xFFFF);
594
+ }
595
+ }
596
+
597
+
598
+ String.prototype.tabIndex = function () {
599
+ return this.replace (/^\D+/g, '')
600
+ };
601
+
602
+ String.prototype.replaceAll = function(search, replacement) {
603
+ var target = this;
604
+ return target.split(search).join(replacement);
605
+ };
606
+
607
+ var ai_nonce = b64d (jQuery ("#ai-form").attr ('ai-value'));
608
+ var ai_settings = b64d (jQuery ("#ai-form").attr ('ai-settings'));
609
+ var ai_read_only = jQuery ("#ai-form").hasClass ('ai-read-only');
610
+
611
+ var shSettings = {
612
+ "tab_size":"4",
613
+ "use_soft_tabs":"1",
614
+ "word_wrap":"1",
615
+ "highlight_curr_line":"0",
616
+ "key_bindings":"default",
617
+ "full_line_selection":"1",
618
+ "show_line_numbers":"0"};
619
+
620
+
621
+ function encode_code (block) {
622
+ // copy code back to textarea and encode block code
623
+
624
+ if (!save_enabled) return false;
625
+
626
+ var textarea = jQuery ('#block-' + block);
627
+ var textarea_name = textarea.attr ('name');
628
+
629
+ if (typeof textarea_name !== typeof undefined && textarea_name !== false) {
630
+ var editor_element = jQuery ("#editor-" + block);
631
+
632
+ // Copy code from editor only if it exists (tab has been configured)
633
+ if (editor_element.length != 0 && typeof editor_element !== typeof undefined && editor_element !== false) {
634
+ var editor = ace.edit ("editor-" + block);
635
+ var session = editor.getSession();
636
+
637
+ var editor_disabled = true;
638
+ if (typeof ace != 'undefined') {
639
+ editor_disabled = jQuery("#simple-editor-" + block).is(":checked");
640
+ }
641
+ if (!editor_disabled) {
642
+ textarea.val (session.getValue());
643
+ }
644
+
645
+ }
646
+
647
+ var default_value = textarea.attr ("default");
648
+ var current_value = textarea.val ();
649
+ var name = textarea.attr ("name");
650
+
651
+ if (typeof name != 'undefined') {
652
+ if (typeof default_value != 'undefined') {
653
+ // console.log (textarea.attr ("name"), ": default_value: ", default_value, ", current_value: ", current_value);
654
+
655
+ if (current_value == default_value) {
656
+ textarea.removeAttr ("name");
657
+ // console.log ("REMOVED: ", name);
658
+ }
659
+ }
660
+ // else console.log ("NO DEFAULT VALUE: ", textarea.attr ("name"));
661
+ }
662
+
663
+ var copy_id = textarea.attr ('id') + '-copy';
664
+ jQuery ('#' + copy_id).remove ();
665
+
666
+ var org_name = textarea.attr ('org-name');
667
+ if (typeof org_name !== typeof undefined && org_name !== false) {
668
+ textarea.attr ("name", org_name);
669
+ } else textarea.attr ("org-name", textarea_name);
670
+
671
+ var textarea_copy = textarea.clone ().attr ('id', copy_id).hide ();
672
+ textarea.removeAttr ("name");
673
+ textarea_copy.val (':AI:' + b64e (textarea.val ()));
674
+ textarea.after (textarea_copy);
675
+
676
+ // console.log (':AI:', block);
677
+ }
678
+
679
+ jQuery("#ai-active-tab").attr ("value", '[' + active_tab + ',' + active_tab_0 + ']');
680
+
681
+ var named_parameters = jQuery("#tab-" + block + ' [name]');
682
+ var block_parameters = new Array();
683
+ named_parameters.each (function() {
684
+ block_parameters.push (jQuery (this).attr ('name'));
685
+ });
686
+ jQuery("#block-parameters-" + block).attr ('name', 'block-parameters-' + block).attr ('value', b64e (JSON.stringify (block_parameters)));
687
+ };
688
+
689
+ function SyntaxHighlight (id, block, settings) {
690
+ var textarea, editor, form, session, editDiv;
691
+
692
+ settings ['tab_size'] = 2;
693
+
694
+ this.textarea = textarea = jQuery(id);
695
+ this.settings = settings || {};
696
+
697
+ if (textarea.length === 0 ) { // Element does not exist
698
+ this.valid = false;
699
+ return;
700
+ }
701
+
702
+ this.valid = true;
703
+ editDiv = jQuery('<div>', {
704
+ position: 'absolute',
705
+ 'class': textarea.attr('class'),
706
+ 'id': 'editor-' + block
707
+ }).insertBefore (textarea);
708
+
709
+ textarea.css('display', 'none');
710
+ this.editor = editor = ace.edit(editDiv[0]);
711
+ this.form = form = textarea.closest('form');
712
+ this.session = session = editor.getSession();
713
+
714
+ editor.$blockScrolling = Infinity;
715
+
716
+ session.setValue(textarea.val());
717
+
718
+ session.setMode ("ace/mode/ai-html");
719
+
720
+ this.applySettings();
721
+ }
722
+
723
+ SyntaxHighlight.prototype.applySettings = function () {
724
+ var editor = this.editor,
725
+ session = this.session,
726
+ settings = this.settings;
727
+
728
+ editor.renderer.setShowGutter(settings['show_line_numbers'] == 1);
729
+ editor.setHighlightActiveLine(settings['highlight_curr_line'] == 1);
730
+ editor.setSelectionStyle(settings['full_line_selection'] == 1 ? "line" : "text");
731
+ editor.setTheme("ace/theme/" + settings['theme']);
732
+ session.setUseWrapMode(settings['word_wrap'] == 1);
733
+ session.setTabSize(settings['tab_size']);
734
+ session.setUseSoftTabs(settings['use_soft_tabs'] == 1);
735
+ };
736
+
737
+ function is_sticky (custom_css) {
738
+ custom_css = custom_css.replace (/\s+/g, '');
739
+
740
+ if (custom_css.indexOf ("position:fixed") != - 1 && custom_css.indexOf ("z-index:") != - 1) return true;
741
+
742
+ return false;
743
+ }
744
+
745
+ function is_background (custom_css) {
746
+ custom_css = custom_css.replace (/\s+/g, '');
747
+
748
+ if (custom_css.indexOf ("top:0px;left:0px;width:100%;height:100%;") != - 1) return true;
749
+
750
+ return false;
751
+ }
752
+
753
+ function change_block_alignment (block) {
754
+ jQuery ("select#block-alignment-" + block).change ();
755
+ jQuery ("select#horizontal-position-" + block).change ();
756
+ jQuery ("select#vertical-position-" + block).change ();
757
+ jQuery ("input#background-" + block).change ();
758
+ // jQuery ("input#bkg-color-" + block).colorpicker ('setValue', jQuery ("input#bkg-color-" + block).attr ('value'));
759
+ jQuery ("input#bkg-color-" + block).colorpicker ('setValue', jQuery ("input#bkg-color-" + block).val ());
760
+ jQuery ("select#bkg-repeat-" + block).change ();
761
+ jQuery ("select#bkg-size-" + block).change ();
762
+ }
763
+
764
+ function change_banner_image (block) {
765
+ jQuery ("input#banner-image-url-" + block).trigger ("input");
766
+ }
767
+
768
+ function ai_css_value_px (css, property) {
769
+ var found = false;
770
+
771
+ styles = css.split (';');
772
+ styles.forEach (function (style, index) {
773
+ style = style.trim ();
774
+ if (style.indexOf (property) == 0) {
775
+ style_parts = style.split (':');
776
+ if (style_parts.length == 2) {
777
+ style_property = style_parts [0].trim ();
778
+ style_value = style_parts [1].trim ();
779
+ if (style_property == property && style_value.endsWith ('px')) found = true;
780
+ }
781
+ }
782
+ });
783
+
784
+ return found;
785
+ }
786
+
787
+ function ai_change_css (css, property, value) {
788
+ var replaced = false;
789
+ styles = css.split (';');
790
+ styles.forEach (function (style, index) {
791
+ org_style = style;
792
+ style = style.trim ();
793
+ if (style.indexOf (property) == 0) {
794
+ style_parts = style.split (':');
795
+ if (style_parts.length == 2) {
796
+ style_property = style_parts [0].trim ();
797
+ style_value = style_parts [1].trim ();
798
+ if (style_property == property && style_value.endsWith ('px')) {
799
+ var org_style_parts = org_style.split (':');
800
+ styles [index] = org_style_parts [0] + ': ' + value + 'px';
801
+ replaced = true;
802
+ }
803
+ }
804
+ }
805
+ });
806
+
807
+ var new_style = styles.join (';');
808
+
809
+ if (!replaced) {
810
+ new_style = new_style.trim ();
811
+ if (new_style.length != 0 && new_style.slice (-1) == ';') new_style = new_style.substring (0, new_style.length - 1);
812
+ return new_style + '; ' + property + ': ' + value + ';';
813
+ }
814
+
815
+ return new_style;
816
+ }
817
+
818
+ function update_sticky_margins (style, horizontal_margin, vertical_margin) {
819
+ if (vertical_margin !== '') {
820
+ if (ai_css_value_px (style, 'top')) style = ai_change_css (style, 'top', vertical_margin); else
821
+ if (ai_css_value_px (style, 'bottom')) style = ai_change_css (style, 'bottom', vertical_margin);
822
+ }
823
+
824
+ if (horizontal_margin !== '') {
825
+ if (ai_css_value_px (style, 'left')) style = ai_change_css (style, 'left', horizontal_margin); else
826
+ if (ai_css_value_px (style, 'right')) style = ai_change_css (style, 'right', horizontal_margin); else
827
+ if (ai_css_value_px (style, 'margin-left')) style = ai_change_css (style, 'margin-left', horizontal_margin); else
828
+ if (ai_css_value_px (style, 'margin-right')) style = ai_change_css (style, 'margin-right', horizontal_margin);
829
+ }
830
+
831
+ return style;
832
+ }
833
+
834
+ (function ($) {
835
+ $.widget("toggle.checkboxButton", {
836
+ _create : function() {
837
+ this._on(this.element, {
838
+ "change" : function(event) {
839
+ this.element.next ("label").find ('.checkbox-icon').toggleClass("on");
840
+ }
841
+ });
842
+ }
843
+ });
844
+ }(jQuery));
845
+
846
+
847
+ serialize_object = function (obj) {
848
+ var str = [];
849
+ for(var p in obj)
850
+ if (obj.hasOwnProperty (p)) {
851
+ str.push(encodeURIComponent (p) + "=" + encodeURIComponent (obj[p]));
852
+ }
853
+ return str.join ("&");
854
+ }
855
+
856
+ Number.isInteger = Number.isInteger || function (value) {
857
+ return typeof value === "number" &&
858
+ isFinite (value) &&
859
+ Math.floor (value) === value;
860
+ };
861
+
862
+ function get_editor_text (block) {
863
+ var editor_disabled = true;
864
+ if (typeof ace != 'undefined') {
865
+ var editor = ace.edit ("editor-" + block);
866
+ editor_disabled = jQuery("#simple-editor-" + block).is(":checked");
867
+ }
868
+ if (!editor_disabled) return editor.getSession ().getValue();
869
+ return jQuery ("#block-" + block).val ();
870
+ }
871
+
872
+ function set_editor_text (block, text) {
873
+ var editor_disabled = true;
874
+ if (typeof ace != 'undefined') {
875
+ var editor = ace.edit ("editor-" + block);
876
+ editor_disabled = jQuery("#simple-editor-" + block).is(":checked");
877
+ }
878
+ if (!editor_disabled)
879
+ editor.getSession ().setValue(text); else
880
+ jQuery ("#block-" + block).val (text);
881
+
882
+ }
883
+
884
+ function open_popup_window_post (url, windowoption, name, params) {
885
+ var form = document.createElement("form");
886
+ form.setAttribute("method", "post");
887
+ form.setAttribute("action", url);
888
+ form.setAttribute("target", name);
889
+ for (var i in params) {
890
+ if (params.hasOwnProperty(i)) {
891
+ var input = document.createElement('input');
892
+ input.type = 'hidden';
893
+ input.name = i;
894
+ input.value = encodeURI (params[i]);
895
+ form.appendChild(input);
896
+ }
897
+ }
898
+ document.body.appendChild(form);
899
+ //note I am using a post.htm page since I did not want to make double request to the page
900
+ //it might have some Page_Load call which might screw things up.
901
+ // window.open ("post.htm", name, windowoption);
902
+ window.open ("admin-ajax.php", name, windowoption);
903
+ form.submit();
904
+ document.body.removeChild(form);
905
+ }
906
+
907
+
908
+ function open_window_post (url, name, params) {
909
+ var form = document.createElement("form");
910
+ form.setAttribute("method", "post");
911
+ form.setAttribute("action", url);
912
+ form.setAttribute("target", name);
913
+ for (var i in params) {
914
+ if (params.hasOwnProperty(i)) {
915
+ var input = document.createElement('input');
916
+ input.type = 'hidden';
917
+ input.name = i;
918
+ input.value = encodeURI (params[i]);
919
+ form.appendChild(input);
920
+ }
921
+ }
922
+ document.body.appendChild(form);
923
+ form.submit();
924
+ document.body.removeChild(form);
925
+ }
926
+
927
+ function check_managing_slave () {
928
+ if (jQuery(".ai-managing.ai-managing-slave").length) {
929
+
930
+ jQuery.get (ajaxurl + '?action=ai_ajax_backend&managed=&ai_check=' + ai_nonce, function (data) {
931
+ if (data != '') {
932
+ setTimeout (function () {
933
+ check_managing_slave ();
934
+ }, 30 * 1000);
935
+ } else jQuery(".ai-managing.ai-managing-slave").hide ();
936
+ });
937
+ }
938
+ }
939
+
940
+
941
+ jQuery(document).ready (function($) {
942
+
943
+ var header = $('#export-container'+'-0').length != 0;
944
+
945
+ if (header) {
946
+ $.elycharts.templates['ai'] = {
947
+ type : "line",
948
+ margins : [10, 38, 20, 38],
949
+ defaultSeries : {
950
+ fill: true,
951
+ fillProps: {
952
+ opacity: .15
953
+ },
954
+ plotProps : {
955
+ "stroke-width" : 1,
956
+ },
957
+ },
958
+ series : {
959
+ serie1 : {
960
+ color : "#66f",
961
+ rounded : 0.8,
962
+ },
963
+ serie2 : {
964
+ color : "#888",
965
+ axis : "r",
966
+ fillProps: {
967
+ opacity: .1
968
+ },
969
+ }
970
+ },
971
+ defaultAxis : {
972
+ labels : true,
973
+ min: 0,
974
+ },
975
+ features : {
976
+ grid : {
977
+ draw : true,
978
+ forceBorder : true,
979
+ ny: 5,
980
+ ticks : {
981
+ active : [true, true, true],
982
+ size : [4, 0],
983
+ props : {
984
+ stroke: '#ccc',
985
+ }
986
+ }
987
+ },
988
+ },
989
+ interactive: false
990
+ }
991
+
992
+ $.elycharts.templates['ai-clicks'] = {
993
+ template: 'ai',
994
+ series : {
995
+ serie1 : {
996
+ color : "#0a0",
997
+ fillProps: {
998
+ opacity: .2
999
+ },
1000
+ },
1001
+ serie2 : {
1002
+ color : "#888",
1003
+ }
1004
+ },
1005
+ }
1006
+
1007
+ $.elycharts.templates['ai-impressions'] = {
1008
+ template: 'ai',
1009
+ series : {
1010
+ serie1 : {
1011
+ color : "#66f",
1012
+ },
1013
+ serie2 : {
1014
+ color : "#888",
1015
+ }
1016
+ },
1017
+ }
1018
+
1019
+ $.elycharts.templates['ai-ctr'] = {
1020
+ template: 'ai',
1021
+ series : {
1022
+ serie1 : {
1023
+ color : "#e22",
1024
+ },
1025
+ serie2 : {
1026
+ color : "#888",
1027
+ }
1028
+ },
1029
+ }
1030
+
1031
+ $.elycharts.templates['ai-versions'] = {
1032
+ type : "line",
1033
+ margins : [10, 38, 20, 38],
1034
+ defaultSeries: {
1035
+ color: "#0a0",
1036
+ fillProps: {
1037
+ opacity: .2
1038
+ },
1039
+ plotProps : {
1040
+ "stroke-width" : 2,
1041
+ },
1042
+ tooltip : {
1043
+ frameProps : {
1044
+ opacity : 0.8
1045
+ }
1046
+ },
1047
+ rounded : 0.8,
1048
+ },
1049
+ series: {
1050
+ serie1: {
1051
+ color : "#aaa",
1052
+ axis : "l",
1053
+ },
1054
+ serie2 : {
1055
+ color : "#0a0",
1056
+ axis : "r",
1057
+ },
1058
+ serie3 : {
1059
+ color: "#33f",
1060
+ },
1061
+ serie4 : {
1062
+ color : "#e22",
1063
+ },
1064
+ serie5 : {
1065
+ color : "#e2f",
1066
+ },
1067
+ serie6 : {
1068
+ color : "#ec6400",
1069
+ },
1070
+ serie7 : {
1071
+ color : "#00a3b5",
1072
+ },
1073
+ serie8 : {
1074
+ color : "#7000ff",
1075
+ },
1076
+ serie9 : {
1077
+ color : "#000",
1078
+ },
1079
+ serie10 : {
1080
+ color : "#000", // Used also for BLOCKED
1081
+ },
1082
+ },
1083
+ defaultAxis : {
1084
+ labels : true,
1085
+ min: 0,
1086
+ },
1087
+ features : {
1088
+ grid: {
1089
+ draw: true,
1090
+ forceBorder : true,
1091
+ ny: 5,
1092
+ ticks : {
1093
+ active : [true, true, true],
1094
+ size : [4, 0],
1095
+ props : {
1096
+ stroke: '#ccc',
1097
+ }
1098
+ }
1099
+ },
1100
+ },
1101
+ interactive: true,
1102
+ }
1103
+
1104
+ $.elycharts.templates['ai-versions-legend'] = {
1105
+ template: 'ai-versions',
1106
+ margins : [10, 38, 10, 38],
1107
+ defaultSeries : {
1108
+ fill: true,
1109
+ fillProps: {
1110
+ opacity: 0
1111
+ },
1112
+ plotProps : {
1113
+ "stroke-width" : 0,
1114
+ },
1115
+ },
1116
+ defaultAxis : {
1117
+ labels : false,
1118
+ },
1119
+ features: {
1120
+ grid: {
1121
+ draw: false,
1122
+ props: {
1123
+ stroke: "transparent",
1124
+ },
1125
+ ticks : {
1126
+ active : false,
1127
+ }
1128
+ },
1129
+ legend: {
1130
+ horizontal : true,
1131
+ x : 20, // X | auto, (auto solo per horizontal = true)
1132
+ y : 0,
1133
+ width : 540, // X | auto, (auto solo per horizontal = true)
1134
+ height : 20,
1135
+ itemWidth : "auto", // fixed | auto, solo per horizontal = true
1136
+ borderProps: { fill : "white", stroke: "black", "stroke-width": 0},
1137
+ },
1138
+ },
1139
+ }
1140
+
1141
+ $.elycharts.templates['ai-pie'] = {
1142
+ template: 'ai-versions',
1143
+ type: "pie",
1144
+ rPerc: 100,
1145
+ startAngle: 270,
1146
+ clockwise: true,
1147
+ margins : [0, 0, 0, 0],
1148
+ defaultSeries : {
1149
+ tooltip: {
1150
+ height: 55,
1151
+ width: 120,
1152
+ padding: [5, 5],
1153
+ offset: [-15, -10],
1154
+ frameProps: {
1155
+ opacity: 0.95,
1156
+ /* fill: "white", */
1157
+ stroke: "#000"
1158
+
1159
+ }
1160
+ },
1161
+ plotProps : {
1162
+ stroke : "white",
1163
+ "stroke-width" : 0,
1164
+ opacity : 1
1165
+ },
1166
+ values : [{
1167
+ plotProps : {
1168
+ fill : "#aaa"
1169
+ }
1170
+ }, {
1171
+ plotProps : {
1172
+ fill : "#0a0"
1173
+ }
1174
+ }, {
1175
+ plotProps : {
1176
+ fill : "#33f"
1177
+ }
1178
+ }, {
1179
+ plotProps : {
1180
+ fill : "#e22"
1181
+ }
1182
+ }, {
1183
+ plotProps : {
1184
+ fill : "#e2f"
1185
+ }
1186
+ }, {
1187
+ plotProps : {
1188
+ fill : "#ec6400"
1189
+ }
1190
+ }, {
1191
+ plotProps : {
1192
+ fill : "#00a3b5"
1193
+ }
1194
+ }, {
1195
+ plotProps : {
1196
+ fill : "#7000ff"
1197
+ }
1198
+ }, {
1199
+ plotProps : {
1200
+ fill : "#000"
1201
+ }
1202
+ }, {
1203
+ plotProps : {
1204
+ fill : "#000" // Used also for BLOCKED
1205
+ }
1206
+ }]
1207
+ }
1208
+ }
1209
+
1210
+ $.elycharts.templates['ai-bar'] = {
1211
+ template: 'ai-pie',
1212
+ type: "line",
1213
+ margins : [5, 0, 5, 45],
1214
+ barMargins : 1,
1215
+ defaultSeries : {
1216
+ type: "bar",
1217
+ axis: "l",
1218
+ tooltip: {
1219
+ height: 38,
1220
+ }
1221
+ },
1222
+ features: {
1223
+ grid: {
1224
+ draw: [false, false],
1225
+ props : {stroke: '#e0e0e0', "stroke-width": 0},
1226
+ ticks : {
1227
+ props : {stroke: '#e0e0e0', "stroke-width": 0},
1228
+ }
1229
+ },
1230
+ },
1231
+ }
1232
+
1233
+ }
1234
+
1235
+
1236
+ shSettings ['theme'] = $('#ai-data').attr ('theme');
1237
+
1238
+ var geo_groups = 0;
1239
+ var geo_groups_text = $('#ai-data-2').attr ('geo_groups');
1240
+ if (typeof geo_groups_text != 'undefined') {
1241
+ geo_groups = parseInt (geo_groups_text);
1242
+ }
1243
+
1244
+ debug = parseInt ($('#ai-data').attr ('js_debugging'));
1245
+ ai_tab_setup_delay = parseInt ($('#ai-data').attr ('tab-setup-delay'));
1246
+
1247
+ api_string = $('#ai-data-2').attr ('api_string');
1248
+ if (typeof api_string != 'undefined') {
1249
+ api_debug = parseInt ($('#ai-data-2').attr ('api_debugging'));
1250
+ if (api_debug < 0x22 && api_debug > 0x1e) api_debug = 0;
1251
+ } else api_debug = 0;
1252
+
1253
+ if (debug) {
1254
+ var start_time = new Date().getTime();
1255
+ var last_time = start_time;
1256
+ debug_title = true;
1257
+ }
1258
+
1259
+ // if (api_debug) {
1260
+ // console.log ('api_debug ON:', api_debug);
1261
+ // }
1262
+
1263
+ syntax_highlighting = typeof shSettings ['theme'] != 'undefined' && shSettings ['theme'] != 'disabled';
1264
+
1265
+ var header_id = 'name';
1266
+ // var preview_top = (screen.height / 2) - (820 / 2);
1267
+
1268
+ function remove_default_values (block) {
1269
+
1270
+ if ($('.'+'system'+'-'+'status').length) {
1271
+
1272
+ $("#tab-" + block + " input:checkbox").each (function() {
1273
+ if (typeof $(this).attr ("style") != 'undefined' && $(this).attr ("style").includes ("animation-name")) {
1274
+ $(this).removeAttr ("name");
1275
+ // console.log ("REMOVED: ", $(this).removeAttr ("name"));
1276
+ }
1277
+ });
1278
+
1279
+ $("#tab-" + block + " input:text").each (function() {
1280
+ if (typeof $(this).attr ("style") != 'undefined' && $(this).attr ("style").includes ("animation-name")) {
1281
+ $(this).removeAttr ("name");
1282
+ // console.log ("REMOVED: ", $(this).removeAttr ("name"));
1283
+ }
1284
+ });
1285
+ }
1286
+
1287
+ var t1 = $('.'+'system'+'-'+'stats .ai' + '-stat-' + '1').length;
1288
+
1289
+ if (!api_debug || t1) {
1290
+ // console.log ('remove_default_values', block);
1291
+
1292
+ $("#tab-" + block + " input:checkbox").each (function() {
1293
+ var default_value = $(this).attr ("default");
1294
+ var current_value = $(this).is (':checked');
1295
+ var name = $(this).attr ("name");
1296
+
1297
+ if (typeof name != 'undefined') {
1298
+ if (typeof default_value != 'undefined') {
1299
+ default_value = Boolean (parseInt (default_value));
1300
+ // console.log ($(this).attr ("name"), ": default_value: ", $(this).attr ("default"), " = ", default_value, ", current_value: ", current_value);
1301
+
1302
+ if (current_value == default_value) {
1303
+ $(this).removeAttr ("name");
1304
+ $("#tab-" + block + " [name='" + name + "']").removeAttr ("name");
1305
+ // console.log ("REMOVED: ", name);
1306
+ }
1307
+ }
1308
+ // else console.log ("NO DEFAULT VALUE:", $(this).attr ("name"));
1309
+
1310
+ }
1311
+ });
1312
+
1313
+ $("#tab-" + block + " input:text").each (function() {
1314
+ var default_value = $(this).attr ("default");
1315
+ var current_value = $(this).val ();
1316
+ var name = $(this).attr ("name");
1317
+
1318
+ if (typeof name != 'undefined') {
1319
+ if (typeof default_value != 'undefined') {
1320
+ // console.log ($(this).attr ("name"), ": default_value: ", default_value, ", current_value: ", current_value);
1321
+
1322
+ if (current_value == default_value) {
1323
+ $(this).removeAttr ("name");
1324
+ // console.log ("REMOVED: ", name);
1325
+ }
1326
+ }
1327
+ // else console.log ("NO DEFAULT VALUE: ", $(this).attr ("name"));
1328
+ }
1329
+ });
1330
+
1331
+ $("#tab-" + block + " select").each (function() {
1332
+ var default_value = $(this).attr ("default");
1333
+ var current_value = $(this).val();
1334
+ var name = $(this).attr ("name");
1335
+
1336
+ if (typeof name != 'undefined') {
1337
+ // console.log ($(this).attr ("id"), name, default_value, current_value);
1338
+
1339
+ // to do: children of OPTGROUP
1340
+ var childern = $(this).children ();
1341
+ if (childern.prop ("tagName") == "OPTGROUP") {
1342
+ var current_value = "";
1343
+ childern.each (function() {
1344
+ var selected = $(this).val();
1345
+ if (selected.length != 0) {
1346
+ current_value = selected;
1347
+ return false;
1348
+ }
1349
+ });
1350
+ }
1351
+
1352
+ // if ($(this).attr ("selected-value") == 1) current_value = current_value.attr("value");
1353
+
1354
+ if (typeof default_value != 'undefined') {
1355
+ // console.log ($(this).attr ("name"), ": default_value: ", default_value, " current_value: ", current_value);
1356
+
1357
+ if (current_value == default_value) {
1358
+ $(this).removeAttr ("name");
1359
+ // console.log ("REMOVED: ", name);
1360
+ }
1361
+ }
1362
+ // else console.log ("NO DEFAULT VALUE: ", $(this).attr ("name"));
1363
+ }
1364
+ });
1365
+
1366
+ $("#tab-" + block + " input:radio:checked").each (function() {
1367
+ var default_value = $(this).attr ("default");
1368
+ var current_value = $(this).is (':checked');
1369
+ var name = $(this).attr ("name");
1370
+
1371
+ if (typeof name != 'undefined') {
1372
+ if (typeof default_value != 'undefined') {
1373
+ default_value = Boolean (parseInt (default_value));
1374
+ // console.log ($(this).attr ("name"), ": default_value: ", $(this).attr ("default"), " = ", default_value, ", current_value: ", current_value);
1375
+
1376
+ if (current_value == default_value) {
1377
+ $("#tab-" + block + " [name='" + name + "']").removeAttr ("name");
1378
+ // console.log ("REMOVED: ", name);
1379
+ }
1380
+ }
1381
+ // else console.log ("NO DEFAULT VALUE: ", $(this).attr ("name"));
1382
+ }
1383
+ });
1384
+
1385
+ // else console.log ("NO DEFAULT API VALUE:", api_string);
1386
+ }
1387
+
1388
+ if (block == 0) {
1389
+ var name = 'lic'+'ense'+'_'+'key';
1390
+ var val = $("#tab-" + block + ' [name='+name+']');
1391
+ if (typeof val != 'undefined' && val.length != 0) {
1392
+ if (val.val ().length != 0 && (val.val ().length < 31 || val.val ().length > 33)) {
1393
+ $('#tab-0 [name='+name+']').removeAttr ("name");
1394
+ }
1395
+ }
1396
+ }
1397
+
1398
+ }
1399
+
1400
+ function configure_editor_language (block) {
1401
+
1402
+ var editor = ace.edit ("editor-" + block);
1403
+
1404
+ if ($("input#process-php-"+block).is(":checked")) {
1405
+ editor.getSession ().setMode ("ace/mode/ai-php");
1406
+ } else editor.getSession ().setMode ("ace/mode/ai-html");
1407
+ }
1408
+
1409
+ function disable_auto_refresh_statistics () {
1410
+ $('span.icon-auto-refresh').each (function() {
1411
+ $(this).removeClass ('on');
1412
+ });
1413
+ }
1414
+
1415
+ function reload_statistics (block) {
1416
+ if ($("input#auto-refresh-"+block).next ().find ('.checkbox-icon').hasClass ('on')) {
1417
+ $("input#load-custom-range-"+block).click ();
1418
+ setTimeout (function() {reload_statistics (block);}, 60 * 1000);
1419
+ }
1420
+ }
1421
+
1422
+ function ai_get_time (time_string) {
1423
+ if (time_string.includes (':')) {
1424
+ var time_parts = time_string.split (':');
1425
+ return ((parseInt (time_parts [0]) * 3600 + parseInt (time_parts [1]) * 60 + parseInt (time_parts [2])) * 1000);
1426
+ }
1427
+
1428
+ return null;
1429
+ }
1430
+
1431
+ function ai_get_date (date_element) {
1432
+ var date;
1433
+ try {
1434
+ date = $.datepicker.parseDate (dateFormat, date_element.val ());
1435
+ } catch (error) {
1436
+ date = null;
1437
+ }
1438
+
1439
+ return date;
1440
+ }
1441
+
1442
+ function ai_get_date_time (date_element, time_element) {
1443
+ var date;
1444
+ try {
1445
+ date = Date.parse (date_element.val () + ' ' + time_element.val ());
1446
+ if (isNaN (date)) date = null;
1447
+ } catch (error) {
1448
+ date = null;
1449
+ }
1450
+
1451
+ return date;
1452
+ }
1453
+
1454
+ function process_scheduling_dates (block) {
1455
+ var gmt = parseInt ($('#ai-form').attr ('gmt'));
1456
+ var start_date_picker = $("#scheduling-date-on-"+block);
1457
+ var end_date_picker = $("#scheduling-date-off-"+block);
1458
+ var start_time_picker = $("#scheduling-time-on-"+block);
1459
+ var end_time_picker = $("#scheduling-time-off-"+block);
1460
+ var scheduling = $("select#scheduling-"+block).val();
1461
+
1462
+ var start_date_string = start_date_picker.val ().trim ();
1463
+ var end_date_string = end_date_picker.val ().trim ();
1464
+ var time_only = false;
1465
+
1466
+ if (start_date_string == '' && end_date_string == '') {
1467
+ var start_time = ai_get_time (start_time_picker.val ().trim ());
1468
+ var end_time = ai_get_time (end_time_picker.val ().trim ());
1469
+ time_only = true;
1470
+ } else {
1471
+ var start_time = ai_get_date_time (start_date_picker, start_time_picker) + gmt;
1472
+ var end_time = ai_get_date_time (end_date_picker, end_time_picker) + gmt;
1473
+ }
1474
+
1475
+ end_date_picker.attr ('title', '');
1476
+ end_date_picker.css ("border-color", "#ddd");
1477
+ end_time_picker.attr ('title', '');
1478
+ end_time_picker.css ("border-color", "#ddd");
1479
+
1480
+ if (start_time == null && end_time != null) {
1481
+ end_date_picker.attr ('title', '');
1482
+ end_time_picker.attr ('title', '');
1483
+ } else
1484
+ if (end_time == null && start_time != null) {
1485
+ end_date_picker.attr ('title', '');
1486
+ end_time_picker.attr ('title', '');
1487
+ } else
1488
+ if (end_time > start_time) {
1489
+ if (scheduling == "2") {
1490
+ var current_time = new Date ().getTime () + gmt;
1491
+
1492
+ if (time_only) {
1493
+ var date = new Date (current_time);
1494
+ var current_time_date_only = new Date (date.getFullYear (), date.getMonth (), date.getDate ()).getTime () + gmt;
1495
+
1496
+ current_time -= current_time_date_only;
1497
+
1498
+ if (current_time < 0) {
1499
+ current_time += 24 * 3600 * 1000;
1500
+ }
1501
+ }
1502
+
1503
+ if (end_time <= current_time) {
1504
+ var expiration = Math.floor ((current_time - end_time) / 1000 / 3600 / 24);
1505
+ end_date_picker.attr ('title', ai_admin.insertion_expired);
1506
+ end_date_picker.css ("border-color", "#d00");
1507
+ end_time_picker.attr ('title', ai_admin.insertion_expired);
1508
+ end_time_picker.css ("border-color", "#d00");
1509
+ } else {
1510
+ if (time_only) {
1511
+ var duration = (end_time - start_time) / 1000;
1512
+
1513
+ var hours = Math.floor (duration / 3600);
1514
+ var duration = duration - hours * 3600;
1515
+
1516
+ var minutes = Math.floor (duration / 60);
1517
+ var duration = duration - minutes * 60;
1518
+
1519
+ var seconds = duration;
1520
+
1521
+ var title = ' ' + ai_admin.duration + ': ' + ('0' + hours).slice (-2)+':'+('0' + minutes).slice (-2)+':'+('0' + seconds).slice (-2);
1522
+ } else {
1523
+ var duration = Math.floor ((end_time - start_time) / 1000 / 3600 / 24);
1524
+ var title = ' ' + ai_admin.duration + ': ' + duration + ' ';
1525
+ switch (duration) {
1526
+ case 0:
1527
+ title = title + ai_admin.days_0;
1528
+ break;
1529
+ case 1:
1530
+ title = title + ai_admin.days_1;
1531
+ break;
1532
+ case 2:
1533
+ title = title + ai_admin.days_2;
1534
+ break;
1535
+ case 3:
1536
+ title = title + ai_admin.days_3;
1537
+ break;
1538
+ case 4:
1539
+ title = title + ai_admin.days_4;
1540
+ break;
1541
+ default:
1542
+ title = title + ai_admin.days_5;
1543
+ break;
1544
+ }
1545
+ }
1546
+
1547
+ end_date_picker.attr ('title', title);
1548
+ end_time_picker.attr ('title', title);
1549
+ }
1550
+ }
1551
+ } else {
1552
+ end_date_picker.attr ('title', ai_admin.invalid_end_date);
1553
+ end_date_picker.css ("border-color", "#d00");
1554
+ end_time_picker.attr ('title', ai_admin.invalid_end_date);
1555
+ end_time_picker.css ("border-color", "#d00");
1556
+ }
1557
+
1558
+ end_date_picker
1559
+ .tooltip({
1560
+ track: true,
1561
+ delay: 700,
1562
+ showURL: false,
1563
+ showBody: " | ",
1564
+ fade: 250
1565
+ });
1566
+ end_time_picker
1567
+ .tooltip({
1568
+ track: true,
1569
+ delay: 700,
1570
+ showURL: false,
1571
+ showBody: " | ",
1572
+ fade: 250
1573
+ });
1574
+ }
1575
+
1576
+ function process_chart_dates (block) {
1577
+ var start_date_picker = $("input#chart-start-date-"+block);
1578
+ var end_date_picker = $("input#chart-end-date-"+block);
1579
+ var start_date = ai_get_date (start_date_picker);
1580
+ var end_date = ai_get_date (end_date_picker);
1581
+
1582
+ start_date_picker.attr ('title', '');
1583
+ start_date_picker.css ("border-color", "rgb(221, 221, 221)");
1584
+ end_date_picker.attr ('title', '');
1585
+ end_date_picker.css ("border-color", "rgb(221, 221, 221)");
1586
+
1587
+ if (start_date == null) {
1588
+ end_date_picker.attr ('title', '');
1589
+ } else
1590
+ if (end_date == null) {
1591
+ end_date_picker.attr ('title', '');
1592
+ } else
1593
+ if (end_date >= start_date) {
1594
+ var now = new Date();
1595
+ var today_date = new Date (now.getFullYear(), now.getMonth(), now.getDate(), 0, 0, 0, 0);
1596
+ if (today_date - start_date > 366 * 24 * 3600 * 1000) {
1597
+ start_date_picker.attr ('title', ai_admin.invalid_start_date);
1598
+ start_date_picker.css ("border-color", "#d00");
1599
+ }
1600
+ if (end_date - start_date > 366 * 24 * 3600 * 1000) {
1601
+ end_date_picker.attr ('title', ai_admin.invalid_date_range);
1602
+ end_date_picker.css ("border-color", "#d00");
1603
+ }
1604
+ } else {
1605
+ end_date_picker.attr ('title', ai_admin.invalid_end_date);
1606
+ end_date_picker.css ("border-color", "#d00");
1607
+ }
1608
+ }
1609
+
1610
+ function process_display_elements (block) {
1611
+
1612
+ $("#paragraph-settings-"+block).hide();
1613
+ $("#paragraph-buttons-"+block).hide();
1614
+ $("#image-settings-"+block).hide();
1615
+
1616
+ var filter_attr = $("#filter-settings-"+block).attr ('data-filter');
1617
+ var filter_settings_active = typeof filter_attr !== typeof undefined && filter_attr !== false;
1618
+ $("#filter-settings-"+block).removeAttr ('data-filter').hide();
1619
+ $("#filter-buttons-"+block).hide();
1620
+
1621
+ $("#html-element-settings-"+block).hide();
1622
+
1623
+ $("#inside-element-"+block).hide();
1624
+
1625
+ var automatic_insertion = $("select#insertion-type-"+block+" option:selected").attr('value');
1626
+
1627
+ if (automatic_insertion == AI_BEFORE_PARAGRAPH || automatic_insertion == AI_AFTER_PARAGRAPH) {
1628
+ // $("#paragraph-text-"+block).text (ai_admin.paragraphs).show();
1629
+ $("#paragraph-buttons-"+block).show();
1630
+ $("#paragraph-settings-"+block+ ' input').attr('title', $("#paragraph-settings-"+block+ ' input').attr('data-title-paragraphs'))
1631
+ .tooltip({
1632
+ track: true,
1633
+ delay: 700,
1634
+ showURL: false,
1635
+ showBody: " | ",
1636
+ fade: 250
1637
+ });
1638
+ $("#paragraph-settings-"+block).show();
1639
+ }
1640
+ else if (automatic_insertion == AI_BEFORE_IMAGE || automatic_insertion == AI_AFTER_IMAGE) {
1641
+ // $("#paragraph-text-"+block).text (ai_admin.images).show();
1642
+ $("#paragraph-buttons-"+block).hide();
1643
+ $("#paragraph-settings-"+block + ' input').attr('title', $("#paragraph-settings-"+block+ ' input').attr('data-title-images'))
1644
+ .tooltip({
1645
+ track: true,
1646
+ delay: 700,
1647
+ showURL: false,
1648
+ showBody: " | ",
1649
+ fade: 250
1650
+ });
1651
+ $("#paragraph-settings-"+block).show();
1652
+ $("#paragraph-counting-"+block).hide();
1653
+ $("#paragraph-clearance-"+block).hide();
1654
+ }
1655
+ else if (automatic_insertion == AI_BEFORE_EXCERPT || automatic_insertion == AI_AFTER_EXCERPT || automatic_insertion == AI_BETWEEN_POSTS || automatic_insertion == AI_BETWEEN_COMMENTS) {
1656
+ $("#filter-buttons-"+block).show();
1657
+ var filter_title = '';
1658
+ if (automatic_insertion == AI_BEFORE_EXCERPT || automatic_insertion == AI_AFTER_EXCERPT) {
1659
+ // $("#filter-text-"+block).text (ai_admin.excerpts).show();
1660
+ filter_title = $("#filter-settings-"+block+ ' input').attr('data-title-excerpts');
1661
+ }
1662
+ else if (automatic_insertion == AI_BETWEEN_POSTS) {
1663
+ // $("#filter-text-"+block).text (ai_admin.posts).show();
1664
+ filter_title = $("#filter-settings-"+block+ ' input').attr('data-title-posts');
1665
+ }
1666
+ else if (automatic_insertion == AI_BETWEEN_COMMENTS) {
1667
+ // $("#filter-text-"+block).text (ai_admin.comments).show();
1668
+ filter_title = $("#filter-settings-"+block+ ' input').attr('data-title-comments');
1669
+ }
1670
+ $("#filter-settings-"+block + ' input').attr('title', filter_title)
1671
+ .tooltip({
1672
+ track: true,
1673
+ delay: 700,
1674
+ showURL: false,
1675
+ showBody: " | ",
1676
+ fade: 250
1677
+ });
1678
+ $("#filter-settings-"+block).attr ('data-filter', '1').show();
1679
+ $("#paragraph-counting-"+block).hide();
1680
+ $("#paragraph-clearance-"+block).hide();
1681
+ }
1682
+ else {
1683
+ $("#paragraph-counting-"+block).hide();
1684
+ $("#paragraph-clearance-"+block).hide();
1685
+ }
1686
+
1687
+ var new_filter_attr = $("#filter-settings-"+block).attr ('data-filter');
1688
+ var new_filter_settings_active = typeof new_filter_attr !== typeof undefined && new_filter_attr !== false;
1689
+
1690
+ if (filter_settings_active && !new_filter_settings_active) {
1691
+ $("#filter-settings-"+block + ' input').val ('');
1692
+
1693
+ $("input#filter-numbers-"+block).val ('');
1694
+ $("select#filter-type-"+block).val (0);
1695
+ $("input#invert-filter-"+block).removeAttr ('checked');
1696
+ }
1697
+
1698
+ if (automatic_insertion == AI_BEFORE_HTML_ELEMENT || automatic_insertion == AI_AFTER_HTML_ELEMENT || automatic_insertion == AI_INSIDE_HTML_ELEMENT) {
1699
+ $("#html-element-settings-"+block).show();
1700
+
1701
+ if (automatic_insertion == AI_INSIDE_HTML_ELEMENT) {
1702
+ $("#inside-element-"+block).css ('display', 'table-cell');
1703
+ }
1704
+ }
1705
+
1706
+ var content_settings = automatic_insertion == AI_BEFORE_PARAGRAPH || automatic_insertion == AI_AFTER_PARAGRAPH || automatic_insertion == AI_BEFORE_CONTENT || automatic_insertion == AI_AFTER_CONTENT;
1707
+
1708
+ $("#css-label-"+block).css('display', 'table-cell');
1709
+ $("#edit-css-button-"+block).css('display', 'table-cell');
1710
+
1711
+ $("#css-none-"+block).hide();
1712
+ $("#custom-css-"+block).hide();
1713
+ $("#css-left-"+block).hide();
1714
+ $("#css-right-"+block).hide();
1715
+ $("#css-center-"+block).hide();
1716
+ $("#css-float-left-"+block).hide();
1717
+ $("#css-float-right-"+block).hide();
1718
+ $("#css-sticky-left-"+block).hide();
1719
+ $("#css-sticky-right-"+block).hide();
1720
+ $("#css-sticky-top-"+block).hide();
1721
+ $("#css-sticky-bottom-"+block).hide();
1722
+ $("#css-sticky-"+block).hide();
1723
+ $("#css-no-wrapping-"+block).hide();
1724
+
1725
+ $("#no-wrapping-warning-"+block).hide();
1726
+
1727
+ $("#sticky-position-"+block).hide();
1728
+ $("#sticky-animation-"+block).hide();
1729
+ $("#sticky-background-"+block).hide();
1730
+ $("#sticky-background-"+block).find ('.bkg-parameters').hide();
1731
+
1732
+ $('#tracking-wrapping-warning-' + block).hide ();
1733
+
1734
+ var alignment = $("select#block-alignment-"+block+" option:selected").attr('value');
1735
+
1736
+ if (alignment == AI_ALIGNMENT_NO_WRAPPING) {
1737
+ $("#css-no-wrapping-"+block).css('display', 'table-cell');
1738
+ $("#css-label-"+block).hide();
1739
+ $("#edit-css-button-"+block).hide();
1740
+ if ($("#client-side-detection-"+block).is(":checked")) {
1741
+ $("#no-wrapping-warning-"+block).show();
1742
+ }
1743
+
1744
+ if ($('#tracking-' + block).next ().find ('.checkbox-icon').hasClass ('on')) {
1745
+ $('#tracking-wrapping-warning-' + block).show ();
1746
+ }
1747
+ } else
1748
+ if (alignment == AI_ALIGNMENT_DEFAULT) {
1749
+ $("#css-none-"+block).css('display', 'table-cell');
1750
+ } else
1751
+ if (alignment == AI_ALIGNMENT_CUSTOM_CSS) {
1752
+ $("#icons-css-code-" + block).show();
1753
+ $("#custom-css-"+block).show();
1754
+ configure_selection_icons (block);
1755
+ if (is_sticky ($("#custom-css-"+block).val ())) {
1756
+ $("#sticky-position-"+block).show();
1757
+ $("#sticky-animation-"+block).show();
1758
+ $("#sticky-background-"+block).show();
1759
+ $("select#animation-"+block).change ();
1760
+
1761
+ if (is_background ($("#custom-css-"+block).val ()) && $("input#background-"+block).is(":checked")) {
1762
+ $("#sticky-background-"+block).find ('.bkg-parameters').show();
1763
+ }
1764
+ }
1765
+ } else
1766
+ if (alignment == AI_ALIGNMENT_LEFT) {
1767
+ $("#css-left-"+block).css('display', 'table-cell');
1768
+ } else
1769
+ if (alignment == AI_ALIGNMENT_RIGHT) {
1770
+ $("#css-right-"+block).css('display', 'table-cell');
1771
+ } else
1772
+ if (alignment == AI_ALIGNMENT_CENTER) {
1773
+ $("#css-center-"+block).css('display', 'table-cell');
1774
+ } else
1775
+ if (alignment == AI_ALIGNMENT_FLOAT_LEFT) {
1776
+ $("#css-float-left-"+block).css('display', 'table-cell');
1777
+ } else
1778
+ if (alignment == AI_ALIGNMENT_FLOAT_RIGHT) {
1779
+ $("#css-float-right-"+block).css('display', 'table-cell');
1780
+ } else
1781
+ if (alignment == AI_ALIGNMENT_STICKY_LEFT) {
1782
+ $("#css-sticky-left-"+block).css('display', 'table-cell');
1783
+ } else
1784
+ if (alignment == AI_ALIGNMENT_STICKY_RIGHT) {
1785
+ $("#css-sticky-right-"+block).css('display', 'table-cell');
1786
+ }
1787
+ if (alignment == AI_ALIGNMENT_STICKY_TOP) {
1788
+ $("#css-sticky-top-"+block).css('display', 'table-cell');
1789
+ } else
1790
+ if (alignment == AI_ALIGNMENT_STICKY_BOTTOM) {
1791
+ $("#css-sticky-bottom-"+block).css('display', 'table-cell');
1792
+ } else
1793
+ if (alignment == AI_ALIGNMENT_STICKY) {
1794
+ $("#icons-css-code-" + block).show();
1795
+ $("#sticky-position-"+block).show();
1796
+ $("#sticky-animation-"+block).show();
1797
+ $("#sticky-background-"+block).show();
1798
+ $("select#animation-"+block).change ();
1799
+
1800
+ if ($("select#horizontal-position-"+block+" option:selected").attr('value') == AI_STICK_HORIZONTAL_CENTER && $("input#background-"+block).is(":checked")) {
1801
+ $("#sticky-background-"+block).find ('.bkg-parameters').show();
1802
+ }
1803
+
1804
+ $("#css-sticky-"+block).css('display', 'table-cell');
1805
+ configure_selection_icons (block);
1806
+ }
1807
+
1808
+
1809
+ if ($('#icons-css-code-'+block).css ('display') != 'none') {
1810
+ // $("#show-css-button-"+block+" span").text (ai_admin.hide);
1811
+ // $("#show-css-button-"+block).addClass ('light-blue');
1812
+ } else {
1813
+ // $("#show-css-button-"+block+" span").text (ai_admin.show);
1814
+ // $("#show-css-button-"+block).removeClass ('light-blue');
1815
+ }
1816
+
1817
+ var avoid_action = $("select#avoid-action-"+block+" option:selected").text();
1818
+
1819
+ if (avoid_action == "do not insert")
1820
+ $("#check-up-to-"+block).hide (); else
1821
+ $("#check-up-to-"+block).show ();
1822
+
1823
+
1824
+ $("#scheduling-delay-"+block).hide();
1825
+ $("#scheduling-between-dates-1-"+block).hide();
1826
+ $("#scheduling-between-dates-2-"+block).hide();
1827
+ $("#scheduling-delay-warning-"+block).hide();
1828
+ var scheduling = $("select#scheduling-"+block).val();
1829
+ if (scheduling == "1" || scheduling == "3") {
1830
+ $("#scheduling-delay-"+block).show();
1831
+ } else
1832
+ if (scheduling == "2" || scheduling == "4" || scheduling == "5" || scheduling == "6") {
1833
+ $("#scheduling-between-dates-1-"+block).show();
1834
+ $("#scheduling-between-dates-2-"+block).show();
1835
+ process_scheduling_dates (block);
1836
+ }
1837
+
1838
+ $("#adb-block-replacement-"+block).hide();
1839
+ var adb_block_action = $("select#adb-block-action-"+block).val();
1840
+ if (adb_block_action == AI_ADB_BLOCK_ACTION_REPLACE) {
1841
+ $("#adb-block-replacement-"+block).show();
1842
+ }
1843
+
1844
+ if ($("#exceptions-enabled-" + block).is(":checked")) {
1845
+ $("#default-insertion-"+block).show();
1846
+ } else {
1847
+ $("#default-insertion-"+block).hide();
1848
+ }
1849
+
1850
+ if (syntax_highlighting) configure_editor_language (block);
1851
+
1852
+ check_insertion (block);
1853
+ }
1854
+
1855
+ function process_adsense_elements (block) {
1856
+ var adsense_type = parseInt ($("select#adsense-type-" + block +" option:selected").attr ('value'));
1857
+ var adsense_size = parseInt ($("select#adsense-size-" + block +" option:selected").attr ('value'));
1858
+
1859
+ if ((adsense_type == AI_ADSENSE_STANDARD || adsense_type == AI_ADSENSE_LINK) && adsense_size == AI_ADSENSE_SIZE_FIXED_BY_VIEWPORT) {
1860
+ $('#adsense-layout-' + block).hide ();
1861
+ $('#adsense-viewports-' + block).show ();
1862
+ } else {
1863
+ $('#adsense-layout-' + block).show ();
1864
+ $('#adsense-viewports-' + block).hide ();
1865
+ }
1866
+
1867
+ $('#tab-adsense-' + block + ' .adsense-layout').css ('visibility', 'hidden');
1868
+ $('#tab-adsense-' + block + ' .adsense-fixed-size').show ();
1869
+ $('#tab-adsense-' + block + ' .adsense-fixed-size').css ('visibility', 'hidden');
1870
+ $('#tab-adsense-' + block + ' .adsense-size').css ('visibility', 'hidden');
1871
+ $('#tab-adsense-' + block + ' .adsense-full-width-responsive').hide ();
1872
+
1873
+ switch (adsense_type) {
1874
+ case AI_ADSENSE_STANDARD:
1875
+ $('#tab-adsense-' + block + ' .adsense-size').css ('visibility', 'visible');
1876
+ if (adsense_size == AI_ADSENSE_SIZE_FIXED) $('#tab-adsense-' + block + ' .adsense-fixed-size').css ('visibility', 'visible');
1877
+ if (adsense_size == AI_ADSENSE_SIZE_RESPONSIVE) {
1878
+ $('#tab-adsense-' + block + ' .adsense-fixed-size').hide ();
1879
+ $('#tab-adsense-' + block + ' .adsense-full-width-responsive').show ();
1880
+ }
1881
+ break;
1882
+ case AI_ADSENSE_LINK:
1883
+ $('#tab-adsense-' + block + ' .adsense-size').css ('visibility', 'visible');
1884
+ if (adsense_size == AI_ADSENSE_SIZE_FIXED) $('#tab-adsense-' + block + ' .adsense-fixed-size').css ('visibility', 'visible');
1885
+ if (adsense_size == AI_ADSENSE_SIZE_RESPONSIVE) {
1886
+ $('#tab-adsense-' + block + ' .adsense-fixed-size').hide ();
1887
+ $('#tab-adsense-' + block + ' .adsense-full-width-responsive').show ();
1888
+ }
1889
+ break;
1890
+ case AI_ADSENSE_IN_ARTICLE:
1891
+ break;
1892
+ case AI_ADSENSE_IN_FEED:
1893
+ $('#tab-adsense-' + block + ' .adsense-layout').css ('visibility', 'visible');
1894
+ break;
1895
+ case AI_ADSENSE_MATCHED_CONTENT:
1896
+ break;
1897
+ }
1898
+ }
1899
+
1900
+ function process_amazon_elements (block) {
1901
+ $('#tab-amazon-' + block + ' .amazon-amp-data').hide ();
1902
+ var amzon_amp = parseInt ($("select#amazon-amp-" + block +" option:selected").attr ('value'));
1903
+
1904
+ if (amzon_amp == 1) {
1905
+ $('#tab-amazon-' + block + ' .amazon-amp-data').show ();
1906
+ }
1907
+ }
1908
+
1909
+ function switch_editor (block, editor_disabled) {
1910
+ var editor = ace.edit ("editor-" + block);
1911
+ var textarea = $("#block-" + block);
1912
+ var ace_editor = $("#editor-" + block);
1913
+
1914
+ if (editor_disabled) {
1915
+ textarea.val (editor.session.getValue());
1916
+ textarea.css ('display', 'block');
1917
+ ace_editor.css ('display', 'none');
1918
+ } else {
1919
+ editor.session.setValue (textarea.val ())
1920
+ editor.renderer.updateFull();
1921
+ ace_editor.css ('display', 'block');
1922
+ textarea.css ('display', 'none');
1923
+ }
1924
+ }
1925
+
1926
+ function configure_editor (block) {
1927
+
1928
+ if (debug) console.log ("configure_editor:", block);
1929
+
1930
+ if (syntax_highlighting) {
1931
+ var syntax_highlighter = new SyntaxHighlight ('#block-' + block, block, shSettings);
1932
+ // syntax_highlighter.editor.setPrintMarginColumn (1000);
1933
+ setTimeout (function() {syntax_highlighter.editor.setPrintMarginColumn (1000);}, 50);
1934
+
1935
+ $('input#simple-editor-' + block).change (function () {
1936
+
1937
+ var block = $(this).attr ("id").replace ("simple-editor-","");
1938
+ var editor_disabled = $(this).is(":checked");
1939
+
1940
+ switch_editor (block, editor_disabled);
1941
+ });
1942
+ }
1943
+ }
1944
+
1945
+ function configure_adb () {
1946
+ $("#adb-message").hide();
1947
+ $("#adb-page-redirection").hide();
1948
+
1949
+ var adb_action = $("select#adb-action option:selected").attr('value');
1950
+
1951
+ if (adb_action == AI_ADB_ACTION_MESSAGE) {
1952
+ $("#adb-message").show();
1953
+ } else
1954
+ if (adb_action == AI_ADB_ACTION_REDIRECTION) {
1955
+ $("#adb-page-redirection").show();
1956
+ }
1957
+ }
1958
+
1959
+ function export_statistics_pdf (block) {
1960
+ var code = $('<section>' + $("div#statistics-elements-" + block).html () + '</section>');
1961
+
1962
+ $('div[style*="display: none"], div[style*="display:none"]', code).remove ();
1963
+ $('.ai-toolbar-button', code).remove ();
1964
+ $('.ai-chart-container', code).css ('font-size', '10px');
1965
+ $('.ai-chart-container.versions', code).css ('text-align', 'center');
1966
+ $('.ai-statistics-legend', code).after ($('.ai-chart-container.legend', code).html());
1967
+
1968
+ var param = {'action': 'ai_ajax_backend', 'pdf': 'block', 'ai_check': ai_nonce, 'code': b64e ($(code).html ())};
1969
+ $('#ai-loading').show ();
1970
+ setTimeout (function() {open_window_post (ajaxurl, '_blank', param);}, 5);
1971
+ setTimeout (function() {$('#ai-loading').hide ();}, 1000);
1972
+ }
1973
+
1974
+ function export_statistics_csv (block) {
1975
+ $('#ai-loading').show ();
1976
+ $("span#export-csv-button-"+block).addClass ('on');
1977
+ setTimeout (function() {$("input#load-custom-range-"+block).click ();}, 5);
1978
+ setTimeout (function() {$('#ai-loading').hide ();}, 1000);
1979
+ }
1980
+
1981
+ function configure_statistics_toolbar (tab) {
1982
+ $("input#load-custom-range-"+tab).click (function () {
1983
+ var block = $(this).attr ("id");
1984
+ block = block.replace ("load-custom-range-","");
1985
+
1986
+ var label = $(this).next ().find ('.checkbox-icon');
1987
+ label.addClass ('on');
1988
+
1989
+ // var nonce = $(this).attr ('nonce');
1990
+ // var start_date = $("input#chart-start-date-" + block).attr('value');
1991
+ var start_date = $("input#chart-start-date-" + block).val ();
1992
+ // var end_date = $("input#chart-end-date-" + block).attr('value');
1993
+ var end_date = $("input#chart-end-date-" + block).val ();
1994
+ var container = $("div#statistics-elements-" + block);
1995
+
1996
+ var version_charts_container = $("div#ai-version-charts-" + block);
1997
+ var version_charts_container_visible = version_charts_container.is (':visible');
1998
+
1999
+ var delete_range = '';
2000
+ if ($("input#clear-range-"+block).hasClass ('delete')) {
2001
+ delete_range = '&delete=1';
2002
+ }
2003
+
2004
+ var adb = '';
2005
+ if ($("input#adb-statistics-button-"+block).next ().find ('.icon-adb').hasClass ('on')) {
2006
+ adb = '&adb=1';
2007
+ }
2008
+
2009
+ if ($("span#export-csv-button-"+block).hasClass ('on')) {
2010
+ $("span#export-csv-button-"+block).removeClass ('on');
2011
+
2012
+ var params = {'action': 'ai_ajax_backend', 'statistics': block, 'start-date': start_date, 'end-date': end_date, 'delete_range': delete_range == '' ? '' : 1, 'adb': adb == '' ? '' : 1, 'csv' : 1, 'ai_check': ai_nonce};
2013
+
2014
+ var form = document.createElement("form");
2015
+ form.setAttribute("method", "get");
2016
+ form.setAttribute("action", ajaxurl);
2017
+ for (var i in params) {
2018
+ if (params.hasOwnProperty(i)) {
2019
+ var input = document.createElement('input');
2020
+ input.type = 'hidden';
2021
+ input.name = i;
2022
+ input.value = encodeURI (params[i]);
2023
+ form.appendChild(input);
2024
+ }
2025
+ }
2026
+ document.body.appendChild (form);
2027
+ form.submit();
2028
+ document.body.removeChild (form);
2029
+
2030
+ label.removeClass ('on');
2031
+ return;
2032
+ }
2033
+
2034
+ container.load (ajaxurl+"?action=ai_ajax_backend&statistics=" + block + "&start-date=" + start_date + "&end-date=" + end_date + delete_range + adb + "&ai_check=" + ai_nonce, function (response, status, xhr) {
2035
+ label.removeClass ('on');
2036
+ if ( status == "error" ) {
2037
+ var message = "Error downloading data: " + xhr.status + " " + xhr.statusText ;
2038
+ $("div#load-error-" + block).html (message);
2039
+ if (debug) console.log (message);
2040
+ } else {
2041
+ $("span#export-pdf-button-" + block).show ();
2042
+ $("span#export-csv-button-" + block).show ();
2043
+ var public_report_button = $("#ai-main-toolbar-" + block + ' .public-report-button');
2044
+ public_report_button.show ();
2045
+
2046
+ var urls = container.find ('span.ai-statistics-export-data.ai-public-report');
2047
+ public_report_button.attr ('report-data', JSON.stringify (urls.data ('report')));
2048
+
2049
+ urls.remove ();
2050
+
2051
+ $( "div#load-error-" + block).html ('');
2052
+ if (debug) console.log ("Custom statistics loaded: " + block);
2053
+ configure_charts (container);
2054
+
2055
+ container.find ("label.ai-version-charts-button.not-configured").click (function () {
2056
+ var no_delay_version_charts = $(this).hasClass ('no-version-charts-delay');
2057
+
2058
+ $(this).removeClass ('not-configured');
2059
+ var version_charts_container = $(this).closest (".ai-charts").find ('div.ai-version-charts');
2060
+ version_charts_container.toggle ();
2061
+
2062
+ var not_configured_charts = version_charts_container.find ('.ai-chart.not-configured.hidden');
2063
+ if (not_configured_charts.length) {
2064
+ not_configured_charts.each (function() {
2065
+ $(this).removeClass ('hidden');
2066
+ });
2067
+ if (no_delay_version_charts) {
2068
+ configure_charts (version_charts_container);
2069
+ } else setTimeout (function() {configure_charts (version_charts_container);}, 10);
2070
+ }
2071
+ });
2072
+
2073
+ if (version_charts_container_visible) {
2074
+ container.find ("label.ai-version-charts-button.not-configured").addClass ('no-version-charts-delay').click ();
2075
+ }
2076
+
2077
+ $("input#chart-start-date-"+block).css ('color', '#32373c');
2078
+ $("input#chart-end-date-"+block).css ('color', '#32373c');
2079
+ }
2080
+ });
2081
+ });
2082
+
2083
+ $("input#auto-refresh-"+tab).click (function () {
2084
+ var block = $(this).attr ("id");
2085
+ block = block.replace ("auto-refresh-","");
2086
+ var label = $(this).next ().find ('.checkbox-icon');
2087
+ label.toggleClass ('on');
2088
+ if (label.hasClass ('on')) {
2089
+ reload_statistics (block);
2090
+ }
2091
+ });
2092
+
2093
+ $("input#clear-range-"+tab).click (function () {
2094
+ var block = $(this).attr ("id");
2095
+ block = block.replace ("clear-range-","");
2096
+
2097
+ var delete_button = this;
2098
+ // var start_date = $("input#chart-start-date-" + block).attr('value');
2099
+ var start_date = $("input#chart-start-date-" + block).val ();
2100
+ // var end_date = $("input#chart-end-date-" + block).attr('value');
2101
+ var end_date = $("input#chart-end-date-" + block).val ();
2102
+
2103
+ var message = '';
2104
+ if (start_date == '' && end_date == '')
2105
+ var message = ai_admin.delete_all_statistics; else
2106
+ if (start_date != '' && end_date != '') var message = ai_admin.delete_statistics_between.replace ('{start_date}', start_date).replace ('{end_date}', end_date);
2107
+
2108
+ if (message != '')
2109
+ $('<div />').html(message).attr ('title', ai_admin.warning).dialog({
2110
+ bgiframe: true,
2111
+ draggable: false,
2112
+ resizable: false,
2113
+ modal: true,
2114
+ height: "auto",
2115
+ width: 400,
2116
+ position: {my: 'center', at: 'center', of: '#ai-settings'},
2117
+ buttons: [{
2118
+ text: ai_admin.delete,
2119
+ click: function() {
2120
+ $(this).dialog ("close");
2121
+
2122
+ $(delete_button).addClass ('delete');
2123
+ $("input#load-custom-range-"+block).click ();
2124
+ $(delete_button).removeClass ('delete');
2125
+ }
2126
+ },{
2127
+ text: ai_admin.cancel,
2128
+ click: function() {
2129
+ $(this).dialog ("close");
2130
+ }
2131
+ }
2132
+ ],
2133
+ open: function() {$(this).parent ().find ('button:nth-child(2)').focus();}
2134
+ });
2135
+ });
2136
+
2137
+ $("input#chart-start-date-"+tab).datepicker ({dateFormat: dateFormat, autoSize: true});
2138
+ $("input#chart-end-date-"+tab).datepicker ({dateFormat: dateFormat, autoSize: true});
2139
+
2140
+ $("input#chart-start-date-"+tab).change (function() {
2141
+ $(this).closest (".custom-range-controls").find ('.data-range').removeClass ('selected');
2142
+ var custom_range_controls = $(this).closest (".custom-range-controls");
2143
+ custom_range_controls.attr ('range-name', '----');
2144
+
2145
+ disable_auto_refresh_statistics ();
2146
+ var block = $(this).attr('id').replace ("chart-start-date-", "");
2147
+ $(this).css ('color', 'red');
2148
+ process_chart_dates (block);
2149
+ });
2150
+
2151
+ $("input#chart-end-date-"+tab).change (function() {
2152
+ $(this).closest (".custom-range-controls").find ('.data-range').removeClass ('selected');
2153
+ var custom_range_controls = $(this).closest (".custom-range-controls");
2154
+ custom_range_controls.attr ('range-name', '----');
2155
+
2156
+ disable_auto_refresh_statistics ();
2157
+ var block = $(this).attr('id').replace ("chart-end-date-", "");
2158
+ $(this).css ('color', 'red');
2159
+ process_chart_dates (block);
2160
+ });
2161
+
2162
+ $("div#custom-range-controls-"+tab+" span.data-range").click (function () {
2163
+ var custom_range_controls = $(this).closest (".custom-range-controls");
2164
+ custom_range_controls.find ('.data-range').removeClass ('selected');
2165
+ $(this).addClass ('selected');
2166
+ custom_range_controls.attr ('range-name', $(this).data ("range-name"));
2167
+
2168
+ disable_auto_refresh_statistics ();
2169
+ var id = $(this).closest (".custom-range-controls").attr ("id");
2170
+ block = id.replace ("custom-range-controls-","");
2171
+ // $("input#chart-start-date-"+block).attr ("value", $(this).data ("start-date"));
2172
+ $("input#chart-start-date-"+block).attr ("value", $(this).data ("start-date")).val ($(this).data ("start-date"));
2173
+ // $("input#chart-end-date-"+block).attr ("value", $(this).data ("end-date"));
2174
+ $("input#chart-end-date-"+block).attr ("value", $(this).data ("end-date")).val ($(this).data ("end-date"));
2175
+ process_chart_dates (block);
2176
+ $("input#load-custom-range-"+block).click ();
2177
+ });
2178
+ }
2179
+
2180
+ function configure_tab_0 () {
2181
+
2182
+ if (debug) console.log ("Configure tab: 0");
2183
+
2184
+ $('#tab-0').addClass ('configured');
2185
+
2186
+ $('#tab-0 input[type=submit], #tab-0 button.ai-button').button().show ();
2187
+
2188
+ configure_editor ('h');
2189
+ configure_editor ('f');
2190
+ if ($("#block-a").length)
2191
+ configure_editor ('a');
2192
+
2193
+ $('#ai-plugin-settings-tab-container').tabs();
2194
+ $('#ai-plugin-settings-tabs').show();
2195
+
2196
+ $("#export-switch-0").checkboxButton ().click (function () {
2197
+ $("#export-container-0").toggle ();
2198
+
2199
+ if ($("#export-container-0").is(':visible') && !$(this).hasClass ("loaded")) {
2200
+ // var nonce = $(this).attr ('nonce');
2201
+ $("#export_settings_0").load (ajaxurl+"?action=ai_ajax_backend&export=0&ai_check=" + ai_nonce, function (response, status, xhr) {
2202
+ if (status == "error" ) {
2203
+ $('#ai-error-container').text (ai_admin.error + ' ' + xhr.status + ': ' + xhr.statusText).show ();
2204
+ } else {
2205
+ $("#export_settings_0").attr ("name", "export_settings_0");
2206
+ $("#export-switch-0").addClass ("loaded");
2207
+ }
2208
+
2209
+ });
2210
+ }
2211
+ });
2212
+
2213
+ $("input#process-php-h").change (function() {
2214
+ if (syntax_highlighting) configure_editor_language ('h');
2215
+ });
2216
+
2217
+ $("input#process-php-f").change (function() {
2218
+ if (syntax_highlighting) configure_editor_language ('f')
2219
+ });
2220
+
2221
+ $("input#process-php-a").change (function() {
2222
+ if (syntax_highlighting) configure_editor_language ('a')
2223
+ });
2224
+
2225
+ if (syntax_highlighting) configure_editor_language ('h');
2226
+ if (syntax_highlighting) configure_editor_language ('f');
2227
+ if ($("#block-a").length)
2228
+ if (syntax_highlighting) configure_editor_language ('a');
2229
+
2230
+ for (var index = 1; index <= geo_groups; index ++) {
2231
+ create_list_selector ('group-country', index);
2232
+ }
2233
+
2234
+ $('#enable-header').checkboxButton ();
2235
+ $('#enable-header-404').checkboxButton ();
2236
+
2237
+ $('#simple-editor-h').checkboxButton ().click (function () {
2238
+ var tab_id = $("#ai-plugin-settings-tab-container .ui-tabs-panel:visible").attr("id");
2239
+ if (active_tab == 0 && tab_id == 'tab-header' && !$(this).hasClass ('clicked')) {
2240
+ $(this).addClass ('clicked')
2241
+ $('#ai-tab-container .simple-editor-button').click();
2242
+ $(this).removeClass ('clicked')
2243
+ }
2244
+ });
2245
+ // Switch to simple editor if the button was pressed before the tab was configured
2246
+ if ($('#simple-editor-h').is(":checked")) {
2247
+ switch_editor ('h', true);
2248
+ $('#simple-editor-h').next ("label").find ('.checkbox-icon').addClass("on");
2249
+ }
2250
+
2251
+ $('#process-php-h').checkboxButton ();
2252
+
2253
+ $('#enable-footer').checkboxButton ();
2254
+ $('#enable-footer-404').checkboxButton ();
2255
+
2256
+ $('#simple-editor-f').checkboxButton ().click (function () {
2257
+ var tab_id = $("#ai-plugin-settings-tab-container .ui-tabs-panel:visible").attr("id");
2258
+ if (active_tab == 0 && tab_id == 'tab-footer' && !$(this).hasClass ('clicked')) {
2259
+ $(this).addClass ('clicked')
2260
+ $('#ai-tab-container .simple-editor-button').click();
2261
+ $(this).removeClass ('clicked')
2262
+ }
2263
+ });
2264
+ // Switch to simple editor if the button was pressed before the tab was configured
2265
+ if ($('#simple-editor-f').is(":checked")) {
2266
+ switch_editor ('f', true);
2267
+ $('#simple-editor-f').next ("label").find ('.checkbox-icon').addClass("on");
2268
+ }
2269
+
2270
+ $('#process-php-f').checkboxButton ();
2271
+
2272
+ $('#tracking').checkboxButton ();
2273
+
2274
+ configure_statistics_toolbar (0);
2275
+
2276
+ $("input#statistics-button-0").checkboxButton ().click (function () {
2277
+ $("div#statistics-container-0").toggle ();
2278
+ $("span#export-pdf-button-0").toggle ();
2279
+ $("span#export-csv-button-0").toggle ();
2280
+ $("div#tab-tracking-settings").toggle ();
2281
+ var container = $("div#statistics-container-0");
2282
+ if (container.is(':visible')) {
2283
+ if (!$(this).hasClass ('loaded')) {
2284
+ $("input#load-custom-range-0").click ();
2285
+ $(this).addClass ('loaded');
2286
+ }
2287
+ }
2288
+ });
2289
+
2290
+ $("#export-pdf-button-0").click (function () {
2291
+ export_statistics_pdf (0);
2292
+ });
2293
+
2294
+ $("#export-csv-button-0").click (function () {
2295
+ export_statistics_csv (0);
2296
+ });
2297
+
2298
+ $('#enable-adb-detection').checkboxButton ();
2299
+
2300
+ $('#simple-editor-a').checkboxButton ().click (function () {
2301
+ var tab_id = $("#ai-plugin-settings-tab-container .ui-tabs-panel:visible").attr("id");
2302
+ if (active_tab == 0 && tab_id == 'tab-adblocking' && !$(this).hasClass ('clicked')) {
2303
+ $(this).addClass ('clicked')
2304
+ $('#ai-tab-container .simple-editor-button').click();
2305
+ $(this).removeClass ('clicked')
2306
+ }
2307
+ });
2308
+ // Switch to simple editor if the button was pressed before the tab was configured
2309
+ if ($('#simple-editor-a').is(":checked")) {
2310
+ switch_editor ('a', true);
2311
+ $('#simple-editor-a').next ("label").find ('.checkbox-icon').addClass("on");
2312
+ }
2313
+
2314
+ $('#process-php-a').checkboxButton ();
2315
+
2316
+
2317
+ configure_adb ();
2318
+ $("select#adb-action").change (function() {
2319
+ configure_adb ();
2320
+ });
2321
+
2322
+ $("#preview-button-adb").button ({
2323
+ }).show ().click (function () {
2324
+
2325
+ $(this).blur ();
2326
+
2327
+ var code = b64e (get_editor_text ('a'));
2328
+ var php = $("input#process-php-a").is(":checked") ? 1 : 0;
2329
+
2330
+ var window_width = 820;
2331
+ var window_height = 870;
2332
+ var window_left = 100;
2333
+ var window_top = (screen.height / 2) - (870 / 2);
2334
+ // var nonce = $(this).attr ('nonce');
2335
+ var param = {'action': 'ai_ajax_backend', 'preview': 'adb', 'ai_check': ai_nonce, 'code': code, 'php': php};
2336
+ open_popup_window_post (ajaxurl, 'width='+window_width+',height='+window_height+',top='+window_top+',left='+window_left+',resizable=yes,scrollbars=yes,toolbar=no,location=no,directories=no,status=no,menubar=no', 'preview', param);
2337
+ });
2338
+
2339
+ $("#main-content-element-button").click (function () {
2340
+ var selector = $("input#main-content-element").val ();
2341
+ var home_url = $("#ai-settings").data ('home-relative-url');
2342
+ var window_top = screen.availTop;
2343
+ var window_left = screen.availLeft;
2344
+ var window_width = screen.availWidth - 15;
2345
+ var window_height = screen.availHeight - 65;
2346
+
2347
+ var param = {
2348
+ 'html_element_selection': 'main',
2349
+ 'selector': selector,
2350
+ 'input': "input#main-content-element"
2351
+ };
2352
+ open_popup_window_post (home_url, 'width='+window_width+',height='+window_height+',top='+window_top+',left='+window_left+',resizable=yes,scrollbars=yes,toolbar=no,location=no,directories=no,status=no,menubar=no', 'ai-selector', param);
2353
+ });
2354
+
2355
+ $("#custom-selectors-button").click (function () {
2356
+ var selector = $("input#custom-selectors").val ();
2357
+ var home_url = $("#ai-settings").data ('home-relative-url');
2358
+ var window_top = screen.availTop;
2359
+ var window_left = screen.availLeft;
2360
+ var window_width = screen.availWidth - 15;
2361
+ var window_height = screen.availHeight - 65;
2362
+
2363
+ var param = {
2364
+ 'html_element_selection': 'adb',
2365
+ 'selector': selector,
2366
+ 'input': "input#custom-selectors"
2367
+ };
2368
+ open_popup_window_post (home_url, 'width='+window_width+',height='+window_height+',top='+window_top+',left='+window_left+',resizable=yes,scrollbars=yes,toolbar=no,location=no,directories=no,status=no,menubar=no', 'ai-selector', param);
2369
+ });
2370
+
2371
+ $('#disable-header-code').checkboxButton ();
2372
+ $('#disable-footer-code').checkboxButton ();
2373
+ $('#disable-js-code').checkboxButton ();
2374
+ $('#disable-css-code').checkboxButton ();
2375
+ $('#disable-html-code').checkboxButton ();
2376
+ $('#disable-php-processing').checkboxButton ();
2377
+ $('#disable-blocks').checkboxButton ();
2378
+
2379
+ $("input#disable-header-code").change (function() {
2380
+ $('#ai-page-header').toggleClass ('ai-page-code-disabled');
2381
+ });
2382
+
2383
+ $("input#disable-footer-code").change (function() {
2384
+ $('#ai-page-footer').toggleClass ('ai-page-code-disabled');
2385
+ });
2386
+
2387
+ $("input#disable-js-code").change (function() {
2388
+ $('#ai-page-js').toggleClass ('ai-page-code-disabled');
2389
+ });
2390
+
2391
+ $("input#disable-css-code").change (function() {
2392
+ $('#ai-page-css').toggleClass ('ai-page-code-disabled');
2393
+ });
2394
+
2395
+ $("input#disable-html-code").change (function() {
2396
+ $('#ai-page-html').toggleClass ('ai-page-code-disabled');
2397
+ });
2398
+
2399
+ $("input#disable-php-processing").change (function() {
2400
+ $('#ai-page-php').toggleClass ('ai-page-code-disabled');
2401
+ });
2402
+
2403
+ $("input#disable-blocks").change (function() {
2404
+ $('#ai-page-block').toggleClass ('ai-page-code-disabled');
2405
+ });
2406
+
2407
+ $("#report-header-image-button").click (function (event) {
2408
+ $(this).blur ();
2409
+
2410
+ var frame;
2411
+
2412
+ event.preventDefault();
2413
+
2414
+ if (frame) {
2415
+ frame.open();
2416
+ return;
2417
+ }
2418
+
2419
+ frame = wp.media ({
2420
+ title: ai_admin.select_header_image,
2421
+ button: {
2422
+ text: ai_admin.use_this_image
2423
+ },
2424
+ multiple: false // Set to true to allow multiple files to be selected
2425
+ });
2426
+
2427
+ frame.on ('select', function() {
2428
+ var attachment = frame.state().get('selection').first().toJSON();
2429
+ // console.log ('attachment', attachment);
2430
+ $('#report-header-image').val (attachment.url);
2431
+ });
2432
+
2433
+ frame.open();
2434
+ });
2435
+
2436
+ $("#tab-0 .adsense-list").click (function () {
2437
+ $(this).blur ();
2438
+
2439
+ toggle_adsense_list ();
2440
+ });
2441
+
2442
+ $("#ai-blocked-ip-addresses").click (function () {
2443
+ ip_address = $("#ai-blocked-ip-addresses").attr ('delete');
2444
+ $("#ai-blocked-ip-addresses").removeAttr ('delete');
2445
+
2446
+ if (ip_address == null) ip_address = '';
2447
+
2448
+ $('#ai-blocked-ip-addresses-list').load (ajaxurl + '?action=ai_ajax_backend&cfp-ip-address-list='+ip_address+'&ai_check=' + ai_nonce, function (response, status, xhr) {
2449
+ if (status == "error") {
2450
+ var message = "Error loading CFP IP addresses: " + xhr.status + " " + xhr.statusText ;
2451
+ console.log (message);
2452
+ } else {
2453
+ var text = $('#ai-blocked-ip-addresses-list table').data ('count-text');
2454
+ if (text == null) text = '';
2455
+
2456
+ $("#ai-blocked-ip-addresses").text (text);
2457
+
2458
+ $(".cfp-ip-address").click (function () {
2459
+ var ip_address = $(this).closest ('tr').data ('ip-address');
2460
+
2461
+ setTimeout (function() {
2462
+ $("#ai-blocked-ip-addresses").attr ('delete', ip_address).click ();
2463
+ }, 10);
2464
+ });
2465
+ }
2466
+ });
2467
+ });
2468
+
2469
+ }
2470
+
2471
+ function configure_tab (tab) {
2472
+
2473
+ if (debug) console.log ("Configure tab:", tab);
2474
+
2475
+ $('#tab-' + tab).addClass ('configured');
2476
+
2477
+ $('#tab-' + tab + ' input[type=submit], #tab-' + tab + ' button.ai-button').button().show ();
2478
+
2479
+ configure_editor (tab);
2480
+
2481
+ $("select#insertion-type-"+tab).change (function() {
2482
+ var block = $(this).attr('id').tabIndex ();
2483
+ process_display_elements (block);
2484
+ set_page_statuses (block);
2485
+ });
2486
+
2487
+ $("select#block-alignment-"+tab).change (function() {
2488
+ var block = $(this).attr('id').replace ("block-alignment-", "");
2489
+ var alignment = $("select#block-alignment-"+block+" option:selected").attr('value');
2490
+ var automatic_insertion = $("select#insertion-type-"+block+" option:selected").attr('value');
2491
+
2492
+ if (automatic_insertion != AI_ABOVE_HEADER &&
2493
+ (alignment == AI_ALIGNMENT_STICKY_LEFT ||
2494
+ alignment == AI_ALIGNMENT_STICKY_RIGHT ||
2495
+ alignment == AI_ALIGNMENT_STICKY_TOP || alignment ==
2496
+ AI_ALIGNMENT_STICKY_BOTTOM || alignment == AI_ALIGNMENT_STICKY)
2497
+ ) {
2498
+ $("select#insertion-type-"+block).val (AI_FOOTER).change ();
2499
+ }
2500
+ process_display_elements (block);
2501
+ });
2502
+
2503
+ $("select#vertical-position-"+tab).change (function() {
2504
+ var block = $(this).attr('id').replace ("vertical-position-", "");
2505
+ configure_sticky_css (block);
2506
+ });
2507
+
2508
+ $("select#horizontal-position-"+tab).change (function() {
2509
+ var block = $(this).attr('id').replace ("horizontal-position-", "");
2510
+ configure_sticky_css (block);
2511
+ process_display_elements (block);
2512
+ });
2513
+
2514
+ $("input#background-"+tab).change (function() {
2515
+ var block = $(this).attr('id').replace ("background-", "");
2516
+ check_insertion (block);
2517
+ configure_sticky_css (block);
2518
+ process_display_elements (block);
2519
+ });
2520
+
2521
+ $("input#body-background-"+tab).change (function() {
2522
+ var block = $(this).attr('id').replace ("body-background-", "");
2523
+ check_insertion (block);
2524
+ });
2525
+
2526
+ if ($("input#bkg-color-"+tab).length != 0) {
2527
+ $("input#bkg-color-"+tab).colorpicker ({useAlpha: false, useHashPrefix: true, format: 'hex', fallbackColor: '#fffffe'}).on('colorpickerChange colorpickerCreate colorpickerUpdate', function (e) {
2528
+ var block = $(this).attr('id').replace ("bkg-color-", "");
2529
+ configure_sticky_css (block);
2530
+ $("#sticky-background-" + block).find ('.banner-preview').css ('background', $(this).val ());
2531
+ }).on ('input', function() {
2532
+ var block = $(this).attr('id').replace ("bkg-color-", "");
2533
+ configure_sticky_css (block);
2534
+ $("#sticky-background-" + block).find ('.banner-preview').css ('background', $(this).val ());
2535
+ })
2536
+ $("input#bkg-color-"+tab).colorpicker ('setValue', $("input#bkg-color-" + tab).attr ('value'));
2537
+ }
2538
+
2539
+ $("select#bkg-repeat-"+tab).change (function() {
2540
+ var block = $(this).attr('id').replace ("bkg-repeat-", "");
2541
+ configure_sticky_css (block);
2542
+ process_display_elements (block);
2543
+ });
2544
+
2545
+ $("select#bkg-size-"+tab).change (function() {
2546
+ var block = $(this).attr('id').replace ("bkg-size-", "");
2547
+ configure_sticky_css (block);
2548
+ process_display_elements (block);
2549
+ });
2550
+
2551
+
2552
+ $("input#exceptions-enabled-"+tab).change (function() {
2553
+ var block = $(this).attr('id').replace ("exceptions-enabled-", "");
2554
+ process_display_elements (block);
2555
+ });
2556
+
2557
+ $("input#process-php-"+tab).change (function() {
2558
+ var block = $(this).attr('id').replace ("process-php-", "");
2559
+ process_display_elements (block);
2560
+ });
2561
+ $("input#show-label-"+tab).change (function() {
2562
+ var block = $(this).attr('id').replace ("show-label-", "");
2563
+ // process_display_elements (block);
2564
+ });
2565
+ $("#enable-shortcode-"+tab).change (function() {
2566
+ var block = $(this).attr('id').replace ("enable-shortcode-", "");
2567
+ process_display_elements (block);
2568
+ });
2569
+ $("#enable-php-call-"+tab).change (function() {
2570
+ var block = $(this).attr('id').replace ("enable-php-call-", "");
2571
+ process_display_elements (block);
2572
+ });
2573
+ $("select#display-for-devices-"+tab).change (function() {
2574
+ var block = $(this).attr('id').replace ("display-for-devices-", "");
2575
+ process_display_elements (block);
2576
+ });
2577
+ $("select#scheduling-"+tab).change (function() {
2578
+ var block = $(this).attr('id').replace ("scheduling-", "");
2579
+ process_display_elements (block);
2580
+ });
2581
+ $("select#adb-block-action-"+tab).change (function() {
2582
+ var block = $(this).attr('id').replace ("adb-block-action-", "");
2583
+ process_display_elements (block);
2584
+ });
2585
+
2586
+
2587
+ $("#display-homepage-"+tab).change (function() {
2588
+ var block = $(this).attr('id').replace ("display-homepage-", "");
2589
+ process_display_elements (block);
2590
+ });
2591
+ $("#display-category-"+tab).change (function() {
2592
+ var block = $(this).attr('id').replace ("display-category-", "");
2593
+ process_display_elements (block);
2594
+ });
2595
+ $("#display-search-"+tab).change (function() {
2596
+ var block = $(this).attr('id').replace ("display-search-", "");
2597
+ process_display_elements (block);
2598
+ });
2599
+ $("#display-archive-"+tab).change (function() {
2600
+ var block = $(this).attr('id').replace ("display-archive-", "");
2601
+ process_display_elements (block);
2602
+ });
2603
+
2604
+ $("#client-side-detection-"+tab).change (function() {
2605
+ var block = $(this).attr('id').replace ("client-side-detection-", "");
2606
+ process_display_elements (block);
2607
+ });
2608
+
2609
+ $("#scheduling-date-on-"+tab).change (function() {
2610
+ var block = $(this).attr('id').replace ("scheduling-date-on-", "");
2611
+ process_scheduling_dates (block);
2612
+ });
2613
+
2614
+ $("#scheduling-date-off-"+tab).change (function() {
2615
+ var block = $(this).attr('id').replace ("scheduling-date-off-", "");
2616
+ process_scheduling_dates (block);
2617
+ });
2618
+
2619
+ $("#scheduling-time-on-"+tab).change (function() {
2620
+ var block = $(this).attr('id').replace ("scheduling-time-on-", "");
2621
+ process_scheduling_dates (block);
2622
+ });
2623
+
2624
+ $("#scheduling-time-off-"+tab).change (function() {
2625
+ var block = $(this).attr('id').replace ("scheduling-time-off-", "");
2626
+ process_scheduling_dates (block);
2627
+ });
2628
+
2629
+ $("#scheduling-weekdays-"+tab).click (function() {
2630
+ var block = $(this).attr('id').replace ("scheduling-weekdays-", "");
2631
+ var day_indexes = $(this).selectedIndexes ();
2632
+
2633
+ days = [];
2634
+ $.each ($(this).selectedIndexes (), function (key, value) {
2635
+ days [key] = parseInt (value);
2636
+ });
2637
+
2638
+ $("#scheduling-weekdays-value-"+tab).attr ('value', days.join (','));
2639
+ });
2640
+
2641
+ $("select#avoid-action-"+tab).change (function() {
2642
+ var block = $(this).attr('id').replace ("avoid-action-", "");
2643
+ process_display_elements (block);
2644
+ });
2645
+
2646
+ $("#tab-" + tab + " .page-checker-button").click (function () {
2647
+ // $("#page-checker-container").toggle ();
2648
+ $("#page-checker-button").click ();
2649
+ });
2650
+
2651
+ process_display_elements (tab);
2652
+
2653
+ // $("#exceptions-button-"+tab).button ({
2654
+ // }).click (function () {
2655
+ $("#exceptions-button-"+tab).click (function () {
2656
+ var block = $(this).attr ("id").replace ("exceptions-button-","");
2657
+ $("#block-exceptions-" + block).toggle ();
2658
+ });
2659
+
2660
+ // $("#show-css-button-"+tab).button ({
2661
+ // }).show ().css ('visibility', 'visible').click (function () {
2662
+ $("#show-css-button-"+tab).click (function () {
2663
+ var block = $(this).attr ("id").replace ("show-css-button-","");
2664
+ $("#icons-css-code-" + block).toggle ();
2665
+
2666
+ if ($('#icons-css-code-'+block).is(':visible')) {
2667
+ // $("#show-css-button-"+block+" span").text (ai_admin.hide);
2668
+ // $("#show-css-button-"+block).addClass ('light-blue');
2669
+ configure_selection_icons (block);
2670
+ process_display_elements (block);
2671
+ } else {
2672
+ // $("#show-css-button-"+block+" span").text (ai_admin.show);
2673
+ // $("#show-css-button-"+block).removeClass ('light-blue');
2674
+ $("#sticky-animation-"+block).hide ();
2675
+ $("#sticky-background-"+block).hide();
2676
+ // $("#sticky-background-"+block).find ('.bkg-parameters').hide();
2677
+ }
2678
+ });
2679
+
2680
+ // $("#counting-button-"+tab).button ({
2681
+ // }).show ().click (function () {
2682
+ $("#counting-button-"+tab).click (function () {
2683
+ var block = $(this).attr ("id").replace ("counting-button-","");
2684
+ $("#paragraph-counting-" + block).toggle ();
2685
+ });
2686
+
2687
+ // $("#clearance-button-"+tab).button ({
2688
+ // }).show ().click (function () {
2689
+ $("#clearance-button-"+tab).click (function () {
2690
+ var block = $(this).attr ("id").replace ("clearance-button-","");
2691
+ $("#paragraph-clearance-" + block).toggle ();
2692
+ });
2693
+
2694
+ $("#filter-button-"+tab).click (function () {
2695
+ var block = $(this).attr ("id").tabIndex ();
2696
+ $("#misc-settings-" + block).toggle ();
2697
+ if ($("#misc-settings-" + block).is (':visible')) {
2698
+ $("#ai-misc-container-" + block).tabs ({active: 1});
2699
+ $("#ai-misc-filter-" + block).click ();
2700
+ }
2701
+ });
2702
+
2703
+ $("#scheduling-date-on-"+tab).datepicker ({dateFormat: dateFormat, autoSize: true});
2704
+ $("#scheduling-date-off-"+tab).datepicker ({dateFormat: dateFormat, autoSize: true});
2705
+
2706
+ if ($("#scheduling-weekdays-value-"+tab).length != 0) {
2707
+ $("#scheduling-time-on-"+tab).timepicker ({'timeFormat': timeFormat, 'minTime': '00:00:00', 'maxTime': '23:00:00', 'step': 60});
2708
+ $("#scheduling-time-off-"+tab).timepicker ({'timeFormat': timeFormat, 'minTime': '00:00:00', 'maxTime': '23:00:00', 'step': 60});
2709
+
2710
+ days = [];
2711
+ $.each ($("#scheduling-weekdays-value-"+tab).val ().split (','), function (key, value) {
2712
+ days [key] = parseInt (value);
2713
+ });
2714
+ $("#scheduling-weekdays-"+tab).weekdays ({
2715
+ days: [ai_admin.day_mo, ai_admin.day_tu, ai_admin.day_we, ai_admin.day_th, ai_admin.day_fr, ai_admin.day_sa, ai_admin.day_su],
2716
+ selectedIndexes: days
2717
+ });
2718
+ }
2719
+
2720
+ $(".css-code-"+tab).click (function () {
2721
+ var block = $(this).attr('class').replace ("css-code-", "");
2722
+ if (!$('#custom-css-'+block).is(':visible')) {
2723
+ $("#edit-css-button-"+block).click ();
2724
+ }
2725
+ });
2726
+
2727
+ $("#edit-css-button-"+tab).button ({
2728
+ }).click (function () {
2729
+ var block = $(this).attr('id').replace ("edit-css-button-", "");
2730
+
2731
+ $("#css-left-"+block).hide();
2732
+ $("#css-right-"+block).hide();
2733
+ $("#css-center-"+block).hide();
2734
+ $("#css-float-left-"+block).hide();
2735
+ $("#css-float-right-"+block).hide();
2736
+ $("#css-sticky-left-"+block).hide();
2737
+ $("#css-sticky-right-"+block).hide();
2738
+ $("#css-sticky-top-"+block).hide();
2739
+ $("#css-sticky-bottom-"+block).hide();
2740
+ $("#css-sticky-"+block).hide();
2741
+
2742
+ var alignment = $("select#block-alignment-"+block+" option:selected").attr('value');
2743
+
2744
+ if (alignment == AI_ALIGNMENT_DEFAULT) {
2745
+ $("#css-none-"+block).hide();
2746
+ $("#custom-css-"+block).show().val ($("#css-none-"+block).text ());
2747
+ $("select#block-alignment-"+block).val (AI_ALIGNMENT_CUSTOM_CSS).change();
2748
+ } else
2749
+ if (alignment == AI_ALIGNMENT_LEFT) {
2750
+ $("#css-left-"+block).hide();
2751
+ $("#custom-css-"+block).show().val ($("#css-left-"+block).text ());
2752
+ $("select#block-alignment-"+block).val (AI_ALIGNMENT_CUSTOM_CSS).change();
2753
+ } else
2754
+ if (alignment == AI_ALIGNMENT_RIGHT) {
2755
+ $("#css-right-"+block).hide();
2756
+ $("#custom-css-"+block).show().val ($("#css-right-"+block).text ());
2757
+ $("select#block-alignment-"+block).val (AI_ALIGNMENT_CUSTOM_CSS).change();
2758
+ } else
2759
+ if (alignment == AI_ALIGNMENT_CENTER) {
2760
+ $("#css-center-"+block).hide();
2761
+ $("#custom-css-"+block).show().val ($("#css-center-"+block).text ());
2762
+ $("select#block-alignment-"+block).val (AI_ALIGNMENT_CUSTOM_CSS).change();
2763
+ } else
2764
+ if (alignment == AI_ALIGNMENT_FLOAT_LEFT) {
2765
+ $("#css-float-left-"+block).hide();
2766
+ $("#custom-css-"+block).show().val ($("#css-float-left-"+block).text ());
2767
+ $("select#block-alignment-"+block).val (AI_ALIGNMENT_CUSTOM_CSS).change();
2768
+ } else
2769
+ if (alignment == AI_ALIGNMENT_FLOAT_RIGHT) {
2770
+ $("#css-float-right-"+block).hide();
2771
+ $("#custom-css-"+block).show().val ($("#css-float-right-"+block).text ());
2772
+ $("select#block-alignment-"+block).val (AI_ALIGNMENT_CUSTOM_CSS).change();
2773
+ } else
2774
+ if (alignment == AI_ALIGNMENT_STICKY_LEFT) {
2775
+ $("#css-sticky-left-"+block).hide();
2776
+ $("#custom-css-"+block).show().val ($("#css-sticky-left-"+block).text ());
2777
+ $("select#block-alignment-"+block).val (AI_ALIGNMENT_CUSTOM_CSS).change();
2778
+ } else
2779
+ if (alignment == AI_ALIGNMENT_STICKY_RIGHT) {
2780
+ $("#css-sticky-right-"+block).hide();
2781
+ $("#custom-css-"+block).show().val ($("#css-sticky-right-"+block).text ());
2782
+ $("select#block-alignment-"+block).val (AI_ALIGNMENT_CUSTOM_CSS).change();
2783
+ }
2784
+ if (alignment == AI_ALIGNMENT_STICKY_TOP) {
2785
+ $("#css-sticky-top-"+block).hide();
2786
+ $("#custom-css-"+block).show().val ($("#css-sticky-top-"+block).text ());
2787
+ $("select#block-alignment-"+block).val (AI_ALIGNMENT_CUSTOM_CSS).change();
2788
+ } else
2789
+ if (alignment == AI_ALIGNMENT_STICKY_BOTTOM) {
2790
+ $("#css-sticky-bottom-"+block).hide();
2791
+ $("#custom-css-"+block).show().val ($("#css-sticky-bottom-"+block).text ());
2792
+ $("select#block-alignment-"+block).val (AI_ALIGNMENT_CUSTOM_CSS).change();
2793
+ } else
2794
+ if (alignment == AI_ALIGNMENT_STICKY) {
2795
+ $("#css-sticky-"+block).hide();
2796
+ $("#custom-css-"+block).show().val ($("#css-sticky-"+block).text ());
2797
+ $("select#block-alignment-"+block).val (AI_ALIGNMENT_CUSTOM_CSS).change();
2798
+ }
2799
+ });
2800
+
2801
+
2802
+ $("#name-label-"+tab).click (function () {
2803
+ var block = $(this).attr('id').replace ("name-label-", "");
2804
+
2805
+ if ($("div#settings-" + block).is (':visible'))
2806
+
2807
+ if (!$('#name-edit-'+block).is(':visible')) {
2808
+ $("#name-edit-"+block).css('display', 'table-cell').val ($("#name-label-"+block).text ()).focus ();
2809
+ $("#name-label-"+block).hide();
2810
+ }
2811
+ });
2812
+
2813
+ $("#name-label-container-"+tab).click (function () {
2814
+ var block = $(this).attr('id').replace ("name-label-container-", "");
2815
+
2816
+ if ($("div#settings-" + block).is (':visible'))
2817
+
2818
+ if (!$('#name-edit-'+block).is(':visible')) {
2819
+ $("#name-edit-"+block).css('display', 'table-cell').val ($("#name-label-"+block).text ()).focus ();
2820
+ $("#name-label-"+block).hide();
2821
+ }
2822
+ });
2823
+
2824
+ $("#name-edit-"+tab).on('keyup keypress', function (e) {
2825
+ var keyCode = e.keyCode || e.which;
2826
+ ignore_key = true;
2827
+ if (keyCode == 27) {
2828
+ var block = $(this).attr('id').replace ("name-edit-", "");
2829
+ $("#name-label-"+block).show();
2830
+ $("#name-edit-"+block).hide();
2831
+ ignore_key = false;
2832
+ } else if (keyCode == 13) {
2833
+ var block = $(this).attr('id').replace ("name-edit-", "");
2834
+ $("#name-label-"+block).show().text ($("#name-edit-"+block).val ());
2835
+ $("#name-edit-"+block).hide();
2836
+ ignore_key = false;
2837
+ e.preventDefault();
2838
+ return false;
2839
+ }
2840
+ }).focusout (function() {
2841
+ if (ignore_key) {
2842
+ var block = $(this).attr('id').replace ("name-edit-", "");
2843
+ $("#name-label-"+block).show().text ($("#name-edit-"+block).val ());
2844
+ $("#name-edit-"+block).hide();
2845
+ }
2846
+ ignore_key = true;
2847
+ });
2848
+
2849
+ $("#export-switch-"+tab).checkboxButton ().click (function () {
2850
+ var block = $(this).attr ("id");
2851
+ block = block.replace ("export-switch-","");
2852
+ $("#export-container-" + block).toggle ();
2853
+
2854
+ if ($("#export-container-" + block).is(':visible') && !$(this).hasClass ("loaded")) {
2855
+ // var nonce = $(this).attr ('nonce');
2856
+ $("#export_settings_" + block).load (ajaxurl+"?action=ai_ajax_backend&export=" + block + "&ai_check=" + ai_nonce, function (response, status, xhr) {
2857
+ if (status == "error" ) {
2858
+ $('#ai-error-container').text (ai_admin.error + ' ' + xhr.status + ': ' + xhr.statusText).show ();
2859
+ } else {
2860
+ $("#export_settings_" + block).attr ("name", "export_settings_" + block);
2861
+ $("#export-switch-"+block).addClass ("loaded");
2862
+ }
2863
+ });
2864
+ }
2865
+ });
2866
+
2867
+ $("input#statistics-button-"+tab).checkboxButton ().click (function () {
2868
+ disable_auto_refresh_statistics ();
2869
+ var block = $(this).attr ("id");
2870
+ block = block.replace ("statistics-button-","");
2871
+ $("div#statistics-container-" + block).toggle ();
2872
+ $("div#settings-" + block).toggle ();
2873
+
2874
+ $("#tab-" + block + ' .ai-toolbars .ai-settings').toggle ();
2875
+ $("#ai-main-toolbar-" + block + ' .ai-statistics').toggle ();
2876
+
2877
+ var container = $("div#statistics-container-" + block);
2878
+ if (container.is(':visible')) {
2879
+ $("#name-label-container-"+block).css ('cursor', 'default');
2880
+ if (!$(this).hasClass ('loaded')) {
2881
+ $("input#load-custom-range-"+block).click ();
2882
+ $(this).addClass ('loaded');
2883
+ }
2884
+ } else {
2885
+ $("#name-label-container-"+block).css ('cursor', 'pointer');
2886
+ }
2887
+ });
2888
+
2889
+ $("#export-pdf-button-"+tab).click (function () {
2890
+ var block = $(this).attr ("id").tabIndex ();
2891
+ export_statistics_pdf (block);
2892
+ });
2893
+
2894
+ $("#export-csv-button-"+tab).click (function () {
2895
+ var block = $(this).attr ("id").tabIndex ();
2896
+ export_statistics_csv (block);
2897
+ });
2898
+
2899
+ $("input#adb-statistics-button-"+tab).checkboxButton ().click (function () {
2900
+ var block = $(this).attr ("id");
2901
+ block = block.replace ("adb-statistics-button-","");
2902
+ setTimeout (function() {$("input#load-custom-range-"+block).click ();}, 2);
2903
+ });
2904
+
2905
+ configure_statistics_toolbar (tab);
2906
+
2907
+ $("#device-detection-button-"+tab).button ({
2908
+ }).show ().click (function () {
2909
+ var block = $(this).attr ("id");
2910
+ block = block.replace ("device-detection-button-","");
2911
+ $("#device-detection-settings-" + block).toggle ();
2912
+ });
2913
+
2914
+ $("#lists-button-"+tab).button ({
2915
+ }).show ().click (function () {
2916
+ var block = $(this).attr ("id");
2917
+ block = block.replace ("lists-button-","");
2918
+
2919
+ if ($("#list-settings-" + block).is(':visible')) {
2920
+ if ($("#list-settings-" + block).hasClass ('ai-expaned')) {
2921
+ $("#list-settings-" + block).hide ();
2922
+ $("#list-settings-" + block).removeClass ('ai-expaned');
2923
+ } else {
2924
+ var lists = $("#list-settings-" + block + ' tr');
2925
+ var list_items = $("#list-settings-" + block + ' tr.list-items');
2926
+
2927
+ if (list_items.length != lists.length) {
2928
+ $("#list-settings-" + block + ' tr').show ();
2929
+ $("#list-settings-" + block).addClass ('ai-expaned');
2930
+ } else {
2931
+ $("#list-settings-" + block).hide ();
2932
+ $("#list-settings-" + block).removeClass ('ai-expaned');
2933
+ }
2934
+ }
2935
+ } else {
2936
+ $("#list-settings-" + block).show ();
2937
+ $("#list-settings-" + block).removeClass ('ai-expaned');
2938
+ $("#list-settings-" + block + ' tr').hide ();
2939
+
2940
+ var list_items = $("#list-settings-" + block + ' tr.list-items');
2941
+ if (list_items.length) {
2942
+ list_items.show ();
2943
+ } else {
2944
+ $("#list-settings-" + block + ' tr').show ();
2945
+ $("#list-settings-" + block).addClass ('ai-expaned');
2946
+ }
2947
+ }
2948
+ });
2949
+
2950
+ $("#list-settings-"+tab+' span.checkbox-list-button').click (function () {
2951
+ var on = $(this).hasClass ('dashicons-yes');
2952
+ if (on) {
2953
+ $(this).removeClass ('dashicons-yes').addClass ('dashicons-no');
2954
+ $(this).prev ().removeAttr ('checked');
2955
+ } else {
2956
+ $(this).removeClass ('dashicons-no').addClass ('dashicons-yes');
2957
+ $(this).prev ().attr ('checked', '1');
2958
+ }
2959
+ });
2960
+
2961
+ $("#manual-button-"+tab).button ({
2962
+ }).show ().click (function () {
2963
+ var block = $(this).attr ("id");
2964
+ block = block.replace ("manual-button-","");
2965
+ $("#manual-settings-" + block).toggle ();
2966
+ });
2967
+
2968
+ $("#misc-button-"+tab).button ({
2969
+ }).show ().click (function () {
2970
+ var block = $(this).attr ("id");
2971
+ block = block.replace ("misc-button-","");
2972
+ $("#misc-settings-" + block).toggle ();
2973
+ });
2974
+
2975
+ // $("#scheduling-button-"+tab).button ({
2976
+ // }).show ().click (function () {
2977
+ // var block = $(this).attr ("id");
2978
+ // block = block.replace ("scheduling-button-","");
2979
+ // $("#scheduling-settings-" + block).toggle ();
2980
+ // });
2981
+
2982
+ $("#preview-button-"+tab).button ({
2983
+ }).show ().click (function () {
2984
+ var block = $(this).attr ("id");
2985
+ block = block.replace ("preview-button-","");
2986
+
2987
+ $(this).blur ();
2988
+
2989
+ var sticky = false;
2990
+ var iframe = $(this).attr ('iframe') == '1' ? 1 : 0;
2991
+ $(this).attr ('iframe', '');
2992
+
2993
+ var alignment = $("select#block-alignment-"+block+" option:selected").attr('value');
2994
+ var horizontal = $("select#horizontal-position-"+block+" option:selected").attr('value');
2995
+ var vertical = $("select#vertical-position-"+block+" option:selected").attr('value');
2996
+ var horizontal_margin = $("#horizontal-margin-"+block).val ();
2997
+ var vertical_margin = $("#vertical-margin-"+block).val ();
2998
+ var animation = $("select#animation-"+block+" option:selected").attr('value');
2999
+
3000
+ var custom_css = $("#custom-css-"+block).val ();
3001
+
3002
+ var alignment_css = "";
3003
+ if (alignment == AI_ALIGNMENT_DEFAULT) {
3004
+ alignment_css = $("#css-none-"+block).text ();
3005
+ } else
3006
+ if (alignment == AI_ALIGNMENT_CUSTOM_CSS) {
3007
+ alignment_css = custom_css;
3008
+ sticky = is_sticky (custom_css);
3009
+ } else
3010
+ if (alignment == AI_ALIGNMENT_LEFT) {
3011
+ alignment_css = $("#css-left-"+block).text ();
3012
+ } else
3013
+ if (alignment == AI_ALIGNMENT_RIGHT) {
3014
+ alignment_css = $("#css-right-"+block).text ();
3015
+ } else
3016
+ if (alignment == AI_ALIGNMENT_CENTER) {
3017
+ alignment_css = $("#css-center-"+block).text ();
3018
+ } else
3019
+ if (alignment == AI_ALIGNMENT_FLOAT_LEFT) {
3020
+ alignment_css = $("#css-float-left-"+block).text ();
3021
+ } else
3022
+ if (alignment == AI_ALIGNMENT_FLOAT_RIGHT) {
3023
+ alignment_css = $("#css-float-right-"+block).text ();
3024
+ } else
3025
+ if (alignment == AI_ALIGNMENT_STICKY_LEFT) {
3026
+ alignment_css = $("#css-sticky-left-"+block).text ();
3027
+ } else
3028
+ if (alignment == AI_ALIGNMENT_STICKY_RIGHT) {
3029
+ alignment_css = $("#css-sticky-right-"+block).text ();
3030
+ }
3031
+ if (alignment == AI_ALIGNMENT_STICKY_TOP) {
3032
+ alignment_css = $("#css-sticky-top-"+block).text ();
3033
+ } else
3034
+ if (alignment == AI_ALIGNMENT_STICKY_BOTTOM) {
3035
+ alignment_css = $("#css-sticky-bottom-"+block).text ();
3036
+ } else
3037
+ if (alignment == AI_ALIGNMENT_STICKY) {
3038
+ alignment_css = update_sticky_margins ($("#css-sticky-"+block).text (), horizontal_margin, vertical_margin);
3039
+ sticky = true;
3040
+ }
3041
+
3042
+ var name = $("#name-label-"+block).text ();
3043
+ var code = get_editor_text (block);
3044
+ var php = $("input#process-php-"+block).is(":checked") ? 1 : 0;
3045
+ var label = $("input#show-label-"+block).is(":checked") ? 1 : 0;
3046
+
3047
+ var close_button = $("#close-button-"+block+" option:selected").attr('value');
3048
+
3049
+ var background = $("input#background-"+block).is(":checked") ? 1 : 0;
3050
+ var body_background = $("input#body-background-"+block).is(":checked") ? 1 : 0;
3051
+ var background_image = $("#bkg-image-url-"+block).val ();
3052
+ var background_color = $("input#bkg-color-"+block).val ();
3053
+ var background_size = $("select#bkg-size-"+block+" option:selected").attr('value');
3054
+ var background_repeat = $("select#bkg-repeat-"+block+" option:selected").attr('value');
3055
+
3056
+ if (!sticky) {
3057
+ var window_top = (screen.height / 2) - (820 / 2);
3058
+ var window_left = 100;
3059
+ var window_width = 820;
3060
+ var window_height = 820;
3061
+ } else {
3062
+ var window_top = screen.availTop;
3063
+ var window_left = screen.availLeft;
3064
+ var window_width = screen.availWidth;
3065
+ var window_height = screen.availHeight;
3066
+ }
3067
+
3068
+ // var nonce = $("#ai-form").attr ('nonce');
3069
+
3070
+ var param = {
3071
+ 'action': 'ai_ajax_backend',
3072
+ 'preview': block,
3073
+ 'ai_check': ai_nonce,
3074
+ 'name': b64e (name),
3075
+ 'code': b64e (code),
3076
+ 'alignment': btoa (alignment),
3077
+ 'horizontal': btoa (horizontal),
3078
+ 'vertical': btoa (vertical),
3079
+ 'horizontal_margin': btoa (horizontal_margin),
3080
+ 'vertical_margin': btoa (vertical_margin),
3081
+ 'animation': btoa (animation),
3082
+ 'alignment_css': btoa (alignment_css),
3083
+ 'custom_css': btoa (custom_css),
3084
+ 'php': php,
3085
+ 'label': label,
3086
+ 'close': close_button,
3087
+ 'background': background,
3088
+ 'body_background': body_background,
3089
+ 'background_image': btoa (background_image),
3090
+ 'background_color': btoa (background_color),
3091
+ 'background_size': btoa (background_size),
3092
+ 'background_repeat': btoa (background_repeat),
3093
+ 'iframe': iframe
3094
+ };
3095
+ open_popup_window_post (ajaxurl, 'width='+window_width+',height='+window_height+',top='+window_top+',left='+window_left+',resizable=yes,scrollbars=yes,toolbar=no,location=no,directories=no,status=no,menubar=no', 'preview', param);
3096
+ });
3097
+
3098
+ $("select#animation-"+tab).change (function() {
3099
+ var block = $(this).attr('id').tabIndex ();
3100
+ var animation = $(this).find ("option:selected").attr('value');
3101
+ var animation_parameters = $(this).closest ('.sticky-animation').find ('.animation-parameters')
3102
+
3103
+ if (animation == AI_ANIMATION_NONE || $("input#background-"+block).is(":checked")) {
3104
+ animation_parameters.hide ();
3105
+ } else {
3106
+ animation_parameters.show ();
3107
+ }
3108
+ });
3109
+
3110
+ $("#iframe-preview-button-"+tab).button ({
3111
+ }).show ().click (function () {
3112
+ var block = $(this).attr ("id");
3113
+ block = block.replace ("iframe-preview-button-","");
3114
+ $("#preview-button-"+block).attr ('iframe', '1').click ();
3115
+ });
3116
+
3117
+ create_list_selector ('category', tab);
3118
+ create_list_selector ('tag', tab);
3119
+ create_list_selector ('taxonomy', tab);
3120
+ create_list_selector ('id', tab);
3121
+ create_list_editor ('url', tab);
3122
+ create_list_editor ('url-parameter',tab);
3123
+ create_list_editor ('referer', tab);
3124
+ create_list_selector ('client', tab);
3125
+ create_list_editor ('ip-address', tab);
3126
+ create_list_selector ('country', tab);
3127
+ create_list_selector ('city', tab);
3128
+
3129
+ var toggle_country_list = function (index) {
3130
+ $('#ms-country-select-' + index).toggle();
3131
+ before_update_selection_from_list = null;
3132
+ }
3133
+
3134
+ var toggle_city_list = function (index) {
3135
+ $('#ms-city-select-' + index).toggle();
3136
+ before_update_selection_from_list = null;
3137
+ }
3138
+
3139
+ $('#country-city-' + tab).click (function () {
3140
+ var block = $(this).attr('id').tabIndex ();
3141
+
3142
+ $(this).find ('span').toggle ();
3143
+ $(this).next ().find ('span').toggle ();
3144
+
3145
+ var button_country = $('#country-button-'+block);
3146
+ var button_city = $('#city-button-'+block);
3147
+
3148
+ var country_selection_container = $('#ms-country-select-'+block);
3149
+ country_selection_container_visible = country_selection_container.length && country_selection_container.is (':visible');
3150
+
3151
+ var city_selection_container = $('#ms-city-select-'+block);
3152
+ city_selection_container_visible = city_selection_container.length && city_selection_container.is (':visible');
3153
+
3154
+ if (country_selection_container_visible) {
3155
+ before_update_selection_from_list = toggle_country_list;
3156
+ button_city.click ();
3157
+ }
3158
+
3159
+ if (city_selection_container_visible) {
3160
+ before_update_selection_from_list = toggle_city_list;
3161
+ button_country.click ();
3162
+ }
3163
+ });
3164
+
3165
+ $('#tracking-' + tab).checkboxButton ().click (function () {
3166
+ var block = $(this).attr('id').replace ("tracking-", "");
3167
+ var alignment = $("select#block-alignment-"+block+" option:selected").attr('value');
3168
+ var tracking = !$('#tracking-' + block).next ().find ('.checkbox-icon').hasClass ('on');
3169
+ if (tracking && alignment == AI_ALIGNMENT_NO_WRAPPING) $('#tracking-wrapping-warning-' + block).show (); else $('#tracking-wrapping-warning-' + block).hide ();
3170
+ });
3171
+
3172
+ $('#simple-editor-' + tab).checkboxButton ().click (function () {
3173
+ var block = $(this).attr('id').replace ("simple-editor-", "");
3174
+ if (block == active_tab && !$(this).hasClass ('clicked')) {
3175
+ $(this).addClass ('clicked')
3176
+ $('#ai-tab-container .simple-editor-button').click();
3177
+ $(this).removeClass ('clicked')
3178
+ }
3179
+ });
3180
+ // Switch to simple editor if the button was pressed before the tab was configured
3181
+ if ($('#simple-editor-' + tab).is(":checked")) {
3182
+ switch_editor (tab, true);
3183
+ $('#simple-editor-' + tab).next ("label").find ('.checkbox-icon').addClass("on");
3184
+ }
3185
+
3186
+ $('#process-php-' + tab).checkboxButton ();
3187
+ $('#disable-insertion-' + tab).checkboxButton ();
3188
+
3189
+ $('#ai-misc-container-' + tab).tabs();
3190
+ $('#ai-misc-tabs-' + tab).show();
3191
+
3192
+ $('#ai-devices-container-' + tab).tabs();
3193
+ $('#ai-devices-tabs-' + tab).show();
3194
+
3195
+ $("#tools-button-"+tab).click (function () {
3196
+ if (!$(this).find ('.checkbox-icon').hasClass("on")) {
3197
+ $('label.rotation-button').each (function () {
3198
+ if ($(this).find ('.checkbox-icon').hasClass("on")) {
3199
+ $(this).prev ().click ();
3200
+ }
3201
+ });
3202
+
3203
+ $('label.code-generator-button').each (function () {
3204
+ if ($(this).find ('.checkbox-icon').hasClass("on")) {
3205
+ $(this).prev ().click ();
3206
+ }
3207
+ });
3208
+
3209
+ $('code-generator').hide ();
3210
+ }
3211
+
3212
+ $('.ai-tools-toolbar').toggle();
3213
+ $('label.tools-button').find ('.checkbox-icon').toggleClass("on");
3214
+ });
3215
+
3216
+ $('#ai-code-generator-container-' + tab).tabs();
3217
+
3218
+ $("select#adsense-type-"+tab).change (function() {
3219
+ var block = $(this).attr('id').replace ("adsense-type-", "");
3220
+ process_adsense_elements (block);
3221
+ });
3222
+
3223
+ $("select#adsense-size-"+tab).change (function() {
3224
+ var block = $(this).attr('id').replace ("adsense-size-", "");
3225
+ process_adsense_elements (block);
3226
+ });
3227
+
3228
+ $("select#amazon-amp-"+tab).change (function() {
3229
+ var block = $(this).attr('id').replace ("amazon-amp-", "");
3230
+ console.log ('block', block);
3231
+ process_amazon_elements (block);
3232
+ });
3233
+
3234
+ process_adsense_elements (tab);
3235
+ process_amazon_elements (tab);
3236
+
3237
+ $("#code-generator-"+tab).click (function () {
3238
+ var block = $(this).attr('id').replace ("code-generator-", "");
3239
+ $('#ai-code-generator-container-' + block).toggle();
3240
+ $(this).next ("label").find ('.checkbox-icon').toggleClass("on");
3241
+ });
3242
+
3243
+ $("#visual-editor-"+tab).click (function () {
3244
+ var block = $(this).attr('id').replace ("visual-editor-", "");
3245
+
3246
+ var code = b64e (get_editor_text (block));
3247
+ var php = $("input#process-php-" + block).is(":checked") ? 1 : 0;
3248
+
3249
+ var window_width = 820;
3250
+ var window_height = 870;
3251
+ var window_left = 100;
3252
+ var window_top = (screen.height / 2) - (window_height / 2);
3253
+ // var nonce = $("#ai-form").attr ('nonce');
3254
+ var param = {'action': 'ai_ajax_backend', 'edit': block, 'ai_check': ai_nonce, 'code': code, 'php': php};
3255
+ open_popup_window_post (ajaxurl, 'width='+window_width+',height='+window_height+',top='+window_top+',left='+window_left+',resizable=yes,scrollbars=yes,toolbar=no,location=no,directories=no,status=no,menubar=no', 'edit', param);
3256
+ });
3257
+
3258
+ $("#select-image-button-"+tab).click (function (event) {
3259
+ $(this).blur ();
3260
+
3261
+ var block = $(this).attr('id').replace ("select-image-button-", "");
3262
+ var frame;
3263
+
3264
+ event.preventDefault();
3265
+
3266
+ if (frame) {
3267
+ frame.open();
3268
+ return;
3269
+ }
3270
+
3271
+ frame = wp.media ({
3272
+ title: ai_admin.select_banner_image,
3273
+ button: {
3274
+ text: ai_admin.use_this_image
3275
+ },
3276
+ multiple: false // Set to true to allow multiple files to be selected
3277
+ });
3278
+
3279
+ // frame.on ('open', function(){
3280
+ // var selected = $('#banner-image-' + block).attr ('src');
3281
+ // if (selected) {
3282
+ // var selection = frame.state().get ('selection');
3283
+ // var id = $('#banner-image-' + block).attr ('data-id');
3284
+ // selection.add (wp.media.attachment (id));
3285
+ // }
3286
+ // });
3287
+
3288
+ frame.on ('select', function() {
3289
+ var attachment = frame.state().get('selection').first().toJSON();
3290
+ // console.log ('attachment', attachment);
3291
+ $('#banner-image-' + block).attr ('src', attachment.url);
3292
+ $('#banner-image-url-' + block).val (attachment.url).trigger ("input");
3293
+ });
3294
+
3295
+ frame.open();
3296
+ });
3297
+
3298
+ $("#select-placeholder-button-"+tab).click (function (event) {
3299
+ $(this).blur ();
3300
+
3301
+ var block = $(this).attr('id').replace ("select-placeholder-button-", "");
3302
+ var image_url = $('#banner-image-' + block).attr ('src');
3303
+
3304
+ var window_width = 820;
3305
+ var window_height = 870;
3306
+ var window_left = 100;
3307
+ var window_top = (screen.height / 2) - (870 / 2);
3308
+ // var nonce = $("#ai-form").attr ('nonce');
3309
+ var param = {'action': 'ai_ajax_backend', 'placeholder': image_url, 'block': block, 'ai_check': ai_nonce};
3310
+ open_popup_window_post (ajaxurl, 'width='+window_width+',height='+window_height+',top='+window_top+',left='+window_left+',resizable=yes,scrollbars=yes,toolbar=no,location=no,directories=no,status=no,menubar=no', 'preview', param);
3311
+ });
3312
+
3313
+ $("#banner-image-url-" + tab).on ('input', function() {
3314
+
3315
+ var block = $(this).attr('id').replace ("banner-image-url-", "");
3316
+ var image = $('#banner-image-' + block);
3317
+
3318
+ var new_image_src = $(this).val ();
3319
+ if (new_image_src == '') {
3320
+ // new_image_src = '//:0';
3321
+ image.hide ();
3322
+ $('div#tab-banner-' + block + ' table.ai-settings-table').css ('position', 'relative');
3323
+ }
3324
+
3325
+ // Removed in jQuery 3
3326
+ // image.attr ('src', new_image_src).load (function () {
3327
+ image.attr ('src', new_image_src).on ("load", function () {
3328
+ image.show ();
3329
+ $('div#tab-banner-' + block + ' table.ai-settings-table').css ('position', 'inherit');
3330
+ $(this).closest ('.ai-banner').removeClass ('ai-banner-top');
3331
+ var width = this.naturalWidth;
3332
+ var height = this.naturalHeight;
3333
+
3334
+ if (width / height > 2 && width > 300) {
3335
+ $(this).closest ('.ai-banner').addClass ('ai-banner-top');
3336
+ }
3337
+ })
3338
+ // Removed in jQuery 3
3339
+ // .error (function() {
3340
+ .on ("error", function() {
3341
+ if (image.is(':visible')) {
3342
+ // image.hide ().attr ('src', '//:0');
3343
+ image.hide ().attr ('src', '');
3344
+ $('div#tab-banner-' + block + ' table.ai-settings-table').css ('position', 'relative');
3345
+ }
3346
+ });
3347
+
3348
+ });
3349
+
3350
+ $("#banner-url-" + tab).on ('input', function() {
3351
+ var block = $(this).attr('id').replace ("banner-url-", "");
3352
+ var url = $(this).val ().trim();
3353
+ if (url == '') $('#banner-link-' + block).removeAttr ('href'); else
3354
+ $('#banner-link-' + block).attr ('href', $(this).val ());
3355
+ });
3356
+
3357
+ $("#import-code-"+tab).click (function () {
3358
+ $(this).next ("label").find ('.checkbox-icon').addClass("on");
3359
+
3360
+ var block = $(this).attr('id').replace ("import-code-", "");
3361
+ // var nonce = $("#ai-form").attr ('nonce');
3362
+
3363
+ $.post (ajaxurl, {'action': 'ai_ajax_backend', 'ai_check': ai_nonce, 'import-code': b64e (get_editor_text (block))}
3364
+ ).done (function (data) {
3365
+ if (data != '') {
3366
+ $('#ai-error-container').hide ();
3367
+
3368
+ try {
3369
+ var code_data = JSON.parse (data);
3370
+ } catch (error) {
3371
+ console.log ("AI IMPORT CODE ERROR:", data);
3372
+ $('#ai-error-container').text (data).show ();
3373
+ }
3374
+
3375
+ if (typeof code_data !== "undefined" && typeof code_data ['type'] !== "undefined") {
3376
+
3377
+ if (debug) console.log ("AI IMPORT CODE:", code_data);
3378
+
3379
+ var code_type = code_data ['type'];
3380
+
3381
+ $("#ai-code-generator-container-" + block).tabs ({active: code_type == AI_CODE_UNKNOWN ? AI_CODE_BANNER : code_type});
3382
+
3383
+ switch (code_type) {
3384
+ case AI_CODE_BANNER:
3385
+ $("#banner-image-url-" + block).val (code_data ['image']).trigger ('input');
3386
+ $("#image-alt-text-" + block).val (code_data ['alt']);
3387
+ $("#lazy-load-image-" + block).prop ('checked', code_data ['loading'] == 'lazy');
3388
+
3389
+ $("#banner-url-" + block).val (code_data ['link']).trigger ('input');
3390
+ $("#open-new-tab-" + block).prop ('checked', code_data ['target'] == '_blank');
3391
+ break;
3392
+ case AI_CODE_ADSENSE:
3393
+ $("#adsense-comment-" + block).val (code_data ['adsense-comment']);
3394
+ $("#adsense-publisher-id-" + block).val (code_data ['adsense-publisher-id']);
3395
+ $("#adsense-ad-slot-id-" + block).val (code_data ['adsense-ad-slot-id']);
3396
+
3397
+ $("#adsense-type-" + block).val (code_data ['adsense-type']);
3398
+ $("#adsense-size-" + block).val (code_data ['adsense-size']);
3399
+
3400
+ var ad_size = '';
3401
+ if (code_data ['adsense-width'] != '' && code_data ['adsense-height'] != '') {
3402
+ ad_size = code_data ['adsense-width'] + 'x' + code_data ['adsense-height'];
3403
+ }
3404
+ $('#tab-adsense-' + block + ' .adsense-ad-size.fixed').parent ().find ('.scombobox-display').val (ad_size);
3405
+
3406
+ $("#adsense-amp-" + block).val (code_data ['adsense-amp']);
3407
+
3408
+ $("#adsense-amp-block-on-consent-" + block).prop ('checked', code_data ['adsense-amp-block-on-consent'] != '#');
3409
+
3410
+ $("#adsense-layout-" + block).val (code_data ['adsense-layout']);
3411
+ $("#adsense-layout-key-" + block).val (decodeURIComponent (code_data ['adsense-layout-key']));
3412
+
3413
+ if (decodeURIComponent (code_data ['adsense-full-width-responsive']) == 'false') {
3414
+ $("#adsense-layout-" + block + ' select.adsense-full-width').val ('disabled');
3415
+ } else {
3416
+ $("#adsense-layout-" + block + ' select.adsense-full-width').val ('enabled');
3417
+ }
3418
+
3419
+ if ($("#adsense-size-" + block).val () == AI_ADSENSE_SIZE_FIXED_BY_VIEWPORT) {
3420
+ $('#tab-adsense-' + block + ' tr.adsense-viewport').each (function (index) {
3421
+ var width = code_data ['adsense-sizes'][index][0];
3422
+ var height = code_data ['adsense-sizes'][index][1];
3423
+
3424
+ var ad_size = '';
3425
+ if (width != '' && height != '') {
3426
+ ad_size = width + 'x' + height;
3427
+ }
3428
+
3429
+ $(this).find ('.adsense-ad-size').parent ().find ('.scombobox-display').val (ad_size);
3430
+ });
3431
+ }
3432
+ process_adsense_elements (block);
3433
+ break;
3434
+ case AI_CODE_AMAZON:
3435
+ $("#amazon-data-" + block).val (code_data ['amazon-data']);
3436
+
3437
+ $("#amazon-amp-" + block).val (code_data ['amazon-amp']);
3438
+
3439
+ $("#amazon-width-" + block).val (code_data ['amazon-width']);
3440
+ $("#amazon-height-" + block).val (code_data ['amazon-height']);
3441
+
3442
+ $("#amazon-amp-block-on-consent-" + block).prop ('checked', code_data ['amazon-amp-block-on-consent'] != '#');
3443
+
3444
+ process_amazon_elements (block);
3445
+ break;
3446
+ case AI_CODE_UNKNOWN:
3447
+ break;
3448
+ }
3449
+ }
3450
+ }
3451
+ }).fail (function (xhr, status, error) {
3452
+ console.log ("AI IMPORT CODE ERROR:", xhr.status, xhr.statusText);
3453
+ $('#ai-error-container').text (ai_admin.error + ' ' + xhr.status + ': ' + xhr.statusText).show ();
3454
+ }).always (function() {
3455
+ $("#import-code-"+block).next ("label").find ('.checkbox-icon').removeClass("on");
3456
+ });
3457
+ });
3458
+
3459
+ $("#generate-code-"+tab).click (function () {
3460
+ $('#ai-error-container').hide ();
3461
+ $(this).next ("label").find ('.checkbox-icon').addClass("on");
3462
+
3463
+ var block = $(this).attr('id').replace ("generate-code-", "");
3464
+ // var nonce = $("#ai-form").attr ('nonce');
3465
+ var code_type = $("#ai-code-generator-container-" + block).tabs('option', 'active');
3466
+ var code_data = {'action': 'ai_ajax_backend', 'ai_check': ai_nonce, 'generate-code': code_type};
3467
+
3468
+ switch (code_type) {
3469
+ case AI_CODE_BANNER:
3470
+ code_data ['image'] = $("#banner-image-url-" + block).val ();
3471
+ code_data ['alt'] = $("#image-alt-text-" + block).val ();
3472
+ if ($("#lazy-load-image-" + block).is(":checked"))
3473
+ code_data ['loading'] = 'lazy';
3474
+
3475
+ code_data ['link'] = $("#banner-url-" + block).val ();
3476
+ if ($("#open-new-tab-" + block).is(":checked"))
3477
+ code_data ['target'] = '_blank';
3478
+ break;
3479
+ case AI_CODE_ADSENSE:
3480
+ code_data ['block'] = block;
3481
+ code_data ['adsense-comment'] = $("#adsense-comment-" + block).val ();
3482
+ code_data ['adsense-publisher-id'] = $("#adsense-publisher-id-" + block).val ();
3483
+ code_data ['adsense-ad-slot-id'] = $("#adsense-ad-slot-id-" + block).val ();
3484
+ code_data ['adsense-type'] = parseInt ($("select#adsense-type-" + block +" option:selected").attr ('value'));
3485
+ code_data ['adsense-size'] = parseInt ($("select#adsense-size-" + block +" option:selected").attr ('value'));
3486
+
3487
+ var ad_size = $('#tab-adsense-' + block + ' .adsense-ad-size.fixed').parent ().find ('.scombobox-display').val ().trim ().toLowerCase ().split ('x');
3488
+ code_data ['adsense-width'] = '';
3489
+ code_data ['adsense-height'] = '';
3490
+ if (ad_size.length == 2) {
3491
+ code_data ['adsense-width'] = parseInt (ad_size [0]);
3492
+ code_data ['adsense-height'] = parseInt (ad_size [1]);
3493
+ }
3494
+
3495
+ code_data ['adsense-amp'] = parseInt ($("select#adsense-amp-" + block +" option:selected").attr ('value'));
3496
+ code_data ['adsense-amp-block-on-consent'] = $("#adsense-amp-block-on-consent-" + block).is(":checked") ? '' : '#';
3497
+ code_data ['adsense-layout'] = $("#adsense-layout-" + block).val ();
3498
+ code_data ['adsense-layout-key'] = $("#adsense-layout-key-" + block).val ();
3499
+
3500
+ code_data ['adsense-full-width-responsive'] = 'true';
3501
+ if ($("#adsense-layout-" + block + ' select.adsense-full-width').val () == 'disabled') {
3502
+ code_data ['adsense-full-width-responsive'] = 'false';
3503
+ }
3504
+
3505
+ if (code_data ['adsense-size'] == AI_ADSENSE_SIZE_FIXED_BY_VIEWPORT) {
3506
+ var viewport_sizes = new Array();
3507
+ $('#tab-adsense-' + block + ' tr.adsense-viewport').each (function (index) {
3508
+ var ad_size = $(this).find ('.adsense-ad-size').parent ().find ('.scombobox-display').val ().trim ().toLowerCase ().split ('x');
3509
+ var adsense_size = {'width': '', 'height': ''};
3510
+ if (ad_size.length == 2) {
3511
+ adsense_size = {'width': parseInt (ad_size [0]), 'height': parseInt (ad_size [1])};
3512
+ }
3513
+ viewport_sizes.push (adsense_size);
3514
+ });
3515
+ code_data ['adsense-viewports'] = viewport_sizes;
3516
+ }
3517
+ break;
3518
+
3519
+ case AI_CODE_AMAZON:
3520
+ code_data ['amazon-data'] = $("#amazon-data-" + block).val ();
3521
+ code_data ['amazon-amp'] = $("select#amazon-amp-" + block +" option:selected").attr ('value');
3522
+ code_data ['amazon-width'] = $("#amazon-width-" + block).val ();
3523
+ code_data ['amazon-height'] = $("#amazon-height-" + block).val ();
3524
+ code_data ['amazon-amp-block-on-consent'] = $("#amazon-amp-block-on-consent-" + block).is(":checked") ? '' : '#';
3525
+ break;
3526
+ case AI_CODE_UNKNOWN:
3527
+ // if (debug) console.log ("AI GENERATE CODE:", code_type);
3528
+ break;
3529
+ }
3530
+
3531
+ if (debug) {
3532
+ console.log ("AI GENERATE CODE:", code_type);
3533
+ console.log (code_data);
3534
+ }
3535
+
3536
+ $.post (ajaxurl, code_data
3537
+ ).done (function (code_data) {
3538
+ if (code_data != '') {
3539
+ var code = JSON.parse (code_data);
3540
+ if (typeof code !== "undefined")
3541
+ set_editor_text (block, code);
3542
+ }
3543
+ }).fail (function (xhr, status, error) {
3544
+ console.log ("AI GENERATE CODE ERROR:", xhr.status, xhr.statusText);
3545
+ $('#ai-error-container').text (ai_admin.error + ' ' + xhr.status + ': ' + xhr.statusText).show ();
3546
+ }).always (function() {
3547
+ $("#generate-code-"+block).next ("label").find ('.checkbox-icon').removeClass("on");
3548
+ });
3549
+ });
3550
+
3551
+ $("#clear-block-"+tab).click (function () {
3552
+ paste_from_clipboard (true, true, true, true);
3553
+ });
3554
+
3555
+ $("#copy-block-"+tab).click (function () {
3556
+ copy_to_clipboard ();
3557
+ });
3558
+
3559
+ $("#paste-name-"+tab).click (function () {
3560
+ paste_from_clipboard (true, false, false, false);
3561
+ });
3562
+
3563
+ $("#paste-code-"+tab).click (function () {
3564
+ paste_from_clipboard (false, true, false, false);
3565
+ });
3566
+
3567
+ $("#paste-settings-"+tab).click (function () {
3568
+ paste_from_clipboard (false, false, true, false);
3569
+ });
3570
+
3571
+ $("#paste-block-"+tab).click (function () {
3572
+ paste_from_clipboard (true, true, true, false);
3573
+ });
3574
+
3575
+ $("#rotation-"+tab).click (function () {
3576
+ var block = $(this).attr('id').replace ("rotation-", "");
3577
+ var rotation_container = $('#ai-rotation-container-' + block);
3578
+ $(this).next ("label").find ('.checkbox-icon').toggleClass("on");
3579
+
3580
+ rotation_container.toggle();
3581
+
3582
+ var option_tabs = rotation_container.tabs ();
3583
+
3584
+ var ul = option_tabs.find ("ul");
3585
+
3586
+ if (rotation_container.is(':visible')) {
3587
+ rotation_container.data ('code', b64e (get_editor_text (block)));
3588
+ rotation_container.data ('option', 1);
3589
+
3590
+ add_rotate_options (block, 1);
3591
+ option_tabs.tabs ("option", "active", 0);
3592
+
3593
+ $('input[name=ai_save]').css ('color', '#f00');
3594
+ // $('.ai-rotation-warning').show ();
3595
+
3596
+ setTimeout (function() {import_rotation_code (block);}, 5);
3597
+ } else {
3598
+ // set_editor_text (block, b64d (rotation_container.data ('code')));
3599
+ generate_rotatation_code (block);
3600
+
3601
+ ul.find ("li").remove ();
3602
+ var div = option_tabs.find ("div.rounded").remove ();
3603
+ }
3604
+ });
3605
+
3606
+ $("#add-option-"+tab).click (function () {
3607
+ var block = $(this).attr('id').replace ("add-option-", "");
3608
+ add_rotate_options (block, 1);
3609
+
3610
+ $('#ai-rotation-container-' + block).find ("ul").find ("li").slice (- 1).click ();
3611
+ });
3612
+
3613
+ $("#remove-option-"+tab).click (function () {
3614
+ var block = $(this).attr('id').replace ("remove-option-", "");
3615
+ remove_rotate_option (block, $('#ai-rotation-container-' + block).tabs ("option", "active"));
3616
+ });
3617
+
3618
+ $("#rotation-groups-"+tab).click (function () {
3619
+ var block = $(this).attr('id').tabIndex ();
3620
+ var label = $(this).next ().find ('span');
3621
+ label.toggleClass ('on');
3622
+ var rotation_container = $('#ai-rotation-container-' + block);
3623
+ if (label.hasClass ('on')) {
3624
+ rotation_container.find ('span.group-name-label').show ();
3625
+ rotation_container.find ('span.option-name-label').hide ();
3626
+ rotation_container.find ('td.option-parameters').hide ();
3627
+ } else {
3628
+ rotation_container.find ('span.group-name-label').hide ();
3629
+ rotation_container.find ('span.option-name-label').show ();
3630
+ rotation_container.find ('td.option-parameters').show ();
3631
+ }
3632
+ });
3633
+
3634
+ $("#tab-" + tab + " .adsense-list").click (function () {
3635
+ $(this).blur ();
3636
+
3637
+ toggle_adsense_list ();
3638
+ });
3639
+
3640
+ $("select#html-element-insertion-"+tab).change (function() {
3641
+ var html_element_insertion = $("select#html-element-insertion-"+tab+" option:selected").attr('value');
3642
+
3643
+ if (html_element_insertion == AI_HTML_INSERTION_SEREVR_SIDE)
3644
+ $("#server-side-insertion-"+tab).hide (); else
3645
+ $("#server-side-insertion-"+tab).show ();
3646
+ });
3647
+
3648
+ $("#tab-" + tab + " .adsense-ad-size").scombobox({
3649
+ showDropDown: false,
3650
+ invalidAsValue: true,
3651
+ animation: {
3652
+ duration: 50,
3653
+ }
3654
+ });
3655
+
3656
+ $("select#close-button-" + tab).change (function () {
3657
+ var block = $(this).attr('id').replace ("close-button-", "");
3658
+ $("select#close-button-sticky-"+block+"").val ($("select#close-button-"+block+" option:selected").attr('value'));
3659
+ });
3660
+
3661
+ $("select#close-button-sticky-" + tab).change (function () {
3662
+ var block = $(this).attr('id').replace ("close-button-sticky-", "");
3663
+ $("select#close-button-"+block+"").val ($("select#close-button-sticky-"+block+" option:selected").attr('value'));
3664
+ });
3665
+
3666
+ // $("input#paragraph-numbers-" + tab).change (function () {
3667
+ // var block = $(this).attr('id').tabIndex ();
3668
+ // $("input#image-numbers-"+block).val ($(this).attr ('value'));
3669
+ // });
3670
+
3671
+ // $("input#image-numbers-" + tab).change (function () {
3672
+ // var block = $(this).attr('id').tabIndex ();
3673
+ // $("input#paragraph-numbers-"+block).val ($(this).attr ('value'));
3674
+ // });
3675
+
3676
+ $("input#filter-numbers-insertions-" + tab).on ('keyup', function () {
3677
+ var block = $(this).attr('id').tabIndex ();
3678
+ // $("input#filter-numbers-"+block).val ($(this).attr ('value'));
3679
+ $("input#filter-numbers-"+block).val ($(this).val ());
3680
+ $("select#filter-type-"+block).val (0);
3681
+ $("input#invert-filter-"+block).removeAttr ('checked');
3682
+ });
3683
+
3684
+ $("input#filter-numbers-" + tab).on ('keyup', function () {
3685
+ var block = $(this).attr('id').tabIndex ();
3686
+ // $("input#filter-numbers-insertions-"+block).val ($(this).attr ('value'));
3687
+ $("input#filter-numbers-insertions-"+block).val ($(this).val ());
3688
+ });
3689
+
3690
+ $("#html-elements-button-"+tab).click (function () {
3691
+ var block = $(this).attr('id').replace ("html-elements-button-", "");
3692
+
3693
+ var selector = $("input#html-elements-" + block).val ();
3694
+ var home_url = $("#ai-settings").data ('home-relative-url');
3695
+ var window_top = screen.availTop;
3696
+ var window_left = screen.availLeft;
3697
+ var window_width = screen.availWidth - 15;
3698
+ var window_height = screen.availHeight - 65;
3699
+
3700
+ var param = {
3701
+ 'html_element_selection': block,
3702
+ 'selector': selector,
3703
+ 'input': "input#html-elements-" + block
3704
+ };
3705
+ open_popup_window_post (home_url, 'width='+window_width+',height='+window_height+',top='+window_top+',left='+window_left+',resizable=yes,scrollbars=yes,toolbar=no,location=no,directories=no,status=no,menubar=no', 'ai-selector', param);
3706
+ });
3707
+
3708
+ $("#wait-for-button-"+tab).click (function () {
3709
+ var block = $(this).attr('id').replace ("wait-for-button-", "");
3710
+
3711
+ var selector = $("input#wait-for-" + block).val ();
3712
+ var home_url = $("#ai-settings").data ('home-relative-url');
3713
+ var window_top = screen.availTop;
3714
+ var window_left = screen.availLeft;
3715
+ var window_width = screen.availWidth - 15;
3716
+ var window_height = screen.availHeight - 65;
3717
+
3718
+ var param = {
3719
+ 'html_element_selection': block,
3720
+ 'selector': selector,
3721
+ 'input': "input#wait-for-" + block
3722
+ };
3723
+ open_popup_window_post (home_url, 'width='+window_width+',height='+window_height+',top='+window_top+',left='+window_left+',resizable=yes,scrollbars=yes,toolbar=no,location=no,directories=no,status=no,menubar=no', 'ai-selector', param);
3724
+ });
3725
+
3726
+ $("#select-bkg-image-button-"+tab).click (function (event) {
3727
+ $(this).blur ();
3728
+
3729
+ var block = $(this).attr('id').replace ("select-bkg-image-button-", "");
3730
+ var frame;
3731
+
3732
+ event.preventDefault();
3733
+
3734
+ if (frame) {
3735
+ frame.open();
3736
+ return;
3737
+ }
3738
+
3739
+ frame = wp.media ({
3740
+ title: ai_admin.select_background_image,
3741
+ button: {
3742
+ text: ai_admin.use_this_image
3743
+ },
3744
+ multiple: false // Set to true to allow multiple files to be selected
3745
+ });
3746
+
3747
+ // frame.on ('open', function(){
3748
+ // var selected = $('#banner-image-' + block).attr ('src');
3749
+ // if (selected) {
3750
+ // var selection = frame.state().get ('selection');
3751
+ // var id = $('#banner-image-' + block).attr ('data-id');
3752
+ // selection.add (wp.media.attachment (id));
3753
+ // }
3754
+ // });
3755
+
3756
+ frame.on ('select', function() {
3757
+ var attachment = frame.state().get('selection').first().toJSON();
3758
+ // console.log ('attachment', attachment);
3759
+ $('#bkg-image-' + block).attr ('src', attachment.url);
3760
+ $('#bkg-image-url-' + block).val (attachment.url).trigger ("input");
3761
+ });
3762
+
3763
+ frame.open();
3764
+ });
3765
+
3766
+ $("#bkg-image-url-" + tab).on ('input', function() {
3767
+
3768
+ var block = $(this).attr('id').replace ("bkg-image-url-", "");
3769
+ var image = $('#bkg-image-' + block);
3770
+
3771
+ var new_image_src = $(this).val ();
3772
+ if (new_image_src == '') {
3773
+ // new_image_src = '//:0';
3774
+ image.hide ();
3775
+ $('div#sticky-background-' + block + ' table.ai-settings-table').css ('position', 'relative');
3776
+ }
3777
+
3778
+ configure_sticky_css (block);
3779
+
3780
+ // image.attr ('src', new_image_src).load (function () {
3781
+ image.attr ('src', new_image_src).on ('load', function () {
3782
+ image.show ();
3783
+ $('div#sticky-background-' + block + ' table.ai-settings-table').css ('position', 'inherit');
3784
+ $(this).closest ('.ai-banner').removeClass ('ai-banner-top');
3785
+ var width = this.naturalWidth;
3786
+ var height = this.naturalHeight;
3787
+
3788
+ if (width / height > 2 && width > 300) {
3789
+ $(this).closest ('.ai-banner').addClass ('ai-banner-top');
3790
+ }
3791
+ })
3792
+ // .error (function() {
3793
+ .on ('error', function() {
3794
+ if (image.is(':visible')) {
3795
+ // image.hide ().attr ('src', '//:0');
3796
+ image.hide ().attr ('src', '');
3797
+ $('div#sticky-background-' + block + ' table.ai-settings-table').css ('position', 'relative');
3798
+ }
3799
+ });
3800
+ });
3801
+ }
3802
+
3803
+ function configure_sticky_css (block) {
3804
+ var horizontal_position = $("select#horizontal-position-"+block+" option:selected").attr('value');
3805
+ var selected_horizontal_position = $("select#horizontal-position-"+block+" option:selected");
3806
+
3807
+ var vertical_position = $("select#vertical-position-"+block+" option:selected").attr('value');
3808
+ var selected_vertical_position = $("select#vertical-position-"+block+" option:selected");
3809
+
3810
+ var background = $("input#background-"+block).is(":checked");
3811
+ var body_background = horizontal_position == AI_STICK_HORIZONTAL_CENTER && $("input#body-background-"+block).is(":checked");
3812
+
3813
+ if (background) {
3814
+ $("#sticky-position-"+block).addClass ('ai-background');
3815
+ } else $("#sticky-position-"+block).removeClass ('ai-background');
3816
+
3817
+ var custom_vertical_position_css = selected_vertical_position.data ('css-bkg');
3818
+
3819
+ if (background && typeof custom_vertical_position_css != 'undefined') {
3820
+ if (body_background) {
3821
+ var vertical_position_css = $("select#vertical-position-"+block).data ('css-body-bkg');
3822
+ } else var vertical_position_css = custom_vertical_position_css;
3823
+ } else {
3824
+ var custom_vertical_position_css = selected_vertical_position.data ('css-' + horizontal_position);
3825
+
3826
+ if (typeof custom_vertical_position_css != 'undefined') var vertical_position_css = custom_vertical_position_css; else
3827
+ var vertical_position_css = selected_vertical_position.data ('css');
3828
+ }
3829
+
3830
+ var custom_horizontal_position_css = selected_horizontal_position.data ('css-bkg');
3831
+
3832
+ if (background && typeof custom_horizontal_position_css != 'undefined') {
3833
+ var horizontal_position_css = custom_horizontal_position_css;
3834
+ } else {
3835
+ var custom_horizontal_position_css = selected_horizontal_position.data ('css-' + vertical_position);
3836
+
3837
+ if (typeof custom_horizontal_position_css != 'undefined') var horizontal_position_css = custom_horizontal_position_css; else
3838
+ var horizontal_position_css = selected_horizontal_position.data ('css');
3839
+ }
3840
+
3841
+ var background_css = '';
3842
+ if (horizontal_position == AI_STICK_HORIZONTAL_CENTER && background) {
3843
+ // var background_color = $("input#bkg-color-"+block).attr('value').trim ();
3844
+ var background_color = $("input#bkg-color-"+block).val ().trim ();
3845
+ if (background_color != '') {
3846
+ background_css = background_css + ' background-color: ' + background_color + ';';
3847
+ }
3848
+
3849
+ // var background_image = $("input#bkg-image-url-"+block).attr('value').trim ();
3850
+ var background_image = $("input#bkg-image-url-"+block).val ().trim ();
3851
+ if (background_image != '') {
3852
+ background_css = background_css + ' background-image: url(' + background_image + ');';
3853
+ }
3854
+
3855
+ var background_size = parseInt ($("select#bkg-size-"+block+" option:selected").attr('value'));
3856
+ if (background_size != AI_BACKGROUND_SIZE_DEFAULT) {
3857
+ switch (background_size) {
3858
+ case AI_BACKGROUND_SIZE_COVER:
3859
+ background_css = background_css + ' background-size: cover;';
3860
+ break;
3861
+ case AI_BACKGROUND_SIZE_CONTAIN:
3862
+ background_css = background_css + ' background-size: contain;';
3863
+ break;
3864
+ case AI_BACKGROUND_SIZE_FILL:
3865
+ background_css = background_css + ' background-size: 100% 100%;';
3866
+ break;
3867
+ }
3868
+ }
3869
+
3870
+ var background_repeat = parseInt ($("select#bkg-repeat-"+block+" option:selected").attr('value'));
3871
+ if (background_repeat != AI_BACKGROUND_REPEAT_DEFAULT) {
3872
+ switch (background_repeat) {
3873
+ case AI_BACKGROUND_REPEAT_NO:
3874
+ background_css = background_css + ' background-repeat: no-repeat;';
3875
+ break;
3876
+ case AI_BACKGROUND_REPEAT_YES:
3877
+ background_css = background_css + ' background-repeat: repeat;';
3878
+ break;
3879
+ case AI_BACKGROUND_REPEAT_HORIZONTALY:
3880
+ background_css = background_css + ' background-repeat: repeat-x;';
3881
+ break;
3882
+ case AI_BACKGROUND_REPEAT_VERTICALLY:
3883
+ background_css = background_css + ' background-repeat: repeat-y;';
3884
+ break;
3885
+ case AI_BACKGROUND_REPEAT_SPACE:
3886
+ background_css = background_css + ' background-repeat: space;';
3887
+ break;
3888
+ case AI_BACKGROUND_REPEAT_ROUND:
3889
+ background_css = background_css + ' background-repeat: round;';
3890
+ break;
3891
+ }
3892
+ }
3893
+ }
3894
+
3895
+ $('#css-sticky-' + block + ' .ai-sticky-css').text (vertical_position_css + horizontal_position_css + background_css);
3896
+
3897
+ check_insertion (block);
3898
+ }
3899
+
3900
+ function check_insertion (block) {
3901
+ $('#sticky-scroll-warning-' + block).hide ();
3902
+ var automatic_insertion = $("select#insertion-type-"+block+" option:selected").attr('value');
3903
+ var alignment_style = $("select#block-alignment-"+block+" option:selected").attr('value');
3904
+ var vertical_position = $("select#vertical-position-"+block+" option:selected").attr('value');
3905
+ var background = $("input#background-"+block).is(":checked") ? 1 : 0;
3906
+ var body_background = $("input#body-background-"+block).is(":checked") ? 1 : 0;
3907
+
3908
+ if (alignment_style == AI_ALIGNMENT_STICKY && vertical_position == AI_SCROLL_WITH_THE_CONTENT && automatic_insertion != AI_ABOVE_HEADER && automatic_insertion != AI_DISABLED && !(background && body_background)) {
3909
+ $('#sticky-scroll-warning-' + block).show ();
3910
+ }
3911
+ }
3912
+
3913
+ function configure_selection_icons (block) {
3914
+ var css_code_container = $('#icons-css-code-'+block);
3915
+ if (!css_code_container.hasClass ('configured')) {
3916
+ var titles = new Array();
3917
+ $("select#insertion-type-"+block).imagepicker({hide_select: false}).find ('option').each (function (index) {
3918
+ titles.push ($(this).data ('title'));
3919
+ });
3920
+ $("select#insertion-type-"+block+" + ul").appendTo("#automatic-insertion-"+block).css ('padding-top', '10px').find ('li').each (function (index) {
3921
+ $(this).attr ('title', titles [index])
3922
+ .tooltip({
3923
+ track: true,
3924
+ delay: 700,
3925
+ showURL: false,
3926
+ showBody: " | ",
3927
+ fade: 250
3928
+ });
3929
+ });
3930
+
3931
+ var titles = new Array();
3932
+ $("select#block-alignment-"+block).imagepicker({hide_select: false}).find ('option').each (function (index) {
3933
+ titles.push ($(this).data ('title'));
3934
+ });
3935
+ $("select#block-alignment-"+block+" + ul").appendTo("#alignment-style-"+block).css ('padding-top', '10px').find ('li').each (function (index) {
3936
+ $(this).attr ('title', titles [index])
3937
+ .tooltip({
3938
+ track: true,
3939
+ delay: 700,
3940
+ showURL: false,
3941
+ showBody: " | ",
3942
+ fade: 250
3943
+ });
3944
+ });
3945
+
3946
+ var titles = new Array();
3947
+ $("select#horizontal-position-"+block).imagepicker({hide_select: false}).find ('option').each (function (index) {
3948
+ titles.push ($(this).data ('title'));
3949
+ });
3950
+ $("select#horizontal-position-"+block+" + ul").appendTo("#horizontal-positions-"+block).css ('padding-top', '10px').find ('li').each (function (index) {
3951
+ $(this).attr ('title', titles [index])
3952
+ .tooltip({
3953
+ track: true,
3954
+ delay: 700,
3955
+ showURL: false,
3956
+ showBody: " | ",
3957
+ fade: 250
3958
+ });
3959
+ });
3960
+
3961
+ var titles = new Array();
3962
+ $("select#vertical-position-"+block).imagepicker({hide_select: false}).find ('option').each (function (index) {
3963
+ titles.push ($(this).data ('title'));
3964
+ });
3965
+ $("select#vertical-position-"+block+" + ul").appendTo("#vertical-positions-"+block).css ('padding-top', '10px').find ('li').each (function (index) {
3966
+ $(this).attr ('title', titles [index])
3967
+ .tooltip({
3968
+ track: true,
3969
+ delay: 700,
3970
+ showURL: false,
3971
+ showBody: " | ",
3972
+ fade: 250
3973
+ });
3974
+ });
3975
+
3976
+ // var titles = new Array();
3977
+ // $("select#close-button-"+block).imagepicker({hide_select: false}).find ('option').each (function (index) {
3978
+ // titles.push ($(this).data ('title'));
3979
+ // });
3980
+ // $("select#close-button-sticky-"+block+" + ul").appendTo("#close-buttons-"+block).css ('padding-top', '10px').find ('li').each (function (index) {
3981
+ // $(this).attr ('title', titles [index])
3982
+ // .tooltip({
3983
+ // track: true,
3984
+ // delay: 700,
3985
+ // showURL: false,
3986
+ // showBody: " | ",
3987
+ // fade: 250
3988
+ // });
3989
+ // });
3990
+
3991
+ css_code_container.addClass ('configured');
3992
+ }
3993
+ }
3994
+
3995
+ function import_rotation_code (block) {
3996
+ $("#rotation-"+block).next ("label").find ('.checkbox-icon').addClass("active");
3997
+
3998
+ // var nonce = $("#ai-form").attr ('nonce');
3999
+
4000
+ $.post (ajaxurl, {'action': 'ai_ajax_backend', 'ai_check': ai_nonce, 'import-rotation-code': b64e (get_editor_text (block))}
4001
+ ).done (function (data) {
4002
+ if (data != '') {
4003
+ var code_data = JSON.parse (data);
4004
+ if (typeof code_data !== "undefined" && typeof code_data ['options'] !== "undefined") {
4005
+ $('#ai-error-container').hide ();
4006
+
4007
+ var options = code_data ['options'].length;
4008
+
4009
+ if (debug) {
4010
+ console.log ("AI IMPORT ROTATION CODE:", options);
4011
+ console.log (" OPTIONS:", code_data ['options']);
4012
+ }
4013
+
4014
+ var rotation_container = $('#ai-rotation-container-' + block);
4015
+ rotation_container.find ("ul").find ("li").remove ();
4016
+ rotation_container.find ("div.rounded").remove ();
4017
+
4018
+ var tabs = options;
4019
+ if (tabs < 1) tabs = 1;
4020
+ if (tabs > 17) tabs = 17;
4021
+
4022
+ add_rotate_options (block, tabs);
4023
+
4024
+ rotation_container.find ('ul li').each (function (index) {
4025
+ if (index < options) $(this).data ('code', b64e (code_data ['options'][index]['code'])); else
4026
+ $(this).data ('code', b64e (''));
4027
+ });
4028
+
4029
+ rotation_container.tabs ("option", "active", 0);
4030
+
4031
+ set_editor_text (block, code_data ['options'][0]['code']);
4032
+
4033
+ rotation_container.find ('input.option-name').each (function (index) {
4034
+ if (index < options) $(this).val (code_data ['options'][index]['name']);
4035
+ });
4036
+ rotation_container.find ('input.option-share').each (function (index) {
4037
+ if (index < options) $(this).val (code_data ['options'][index]['share']);
4038
+ });
4039
+ rotation_container.find ('input.option-time').each (function (index) {
4040
+ if (index < options) $(this).val (code_data ['options'][index]['time']);
4041
+ });
4042
+ rotation_container.find ('input.option-scheduling').each (function (index) {
4043
+ if (index < options) $(this).val (code_data ['options'][index]['scheduling']);
4044
+ });
4045
+
4046
+ var group_label = $("#rotation-groups-" + block).next ().find ('span');
4047
+ if (code_data ['options'][0]['groups']) {
4048
+ group_label.removeClass ('on');
4049
+ } else {
4050
+ group_label.addClass ('on');
4051
+ }
4052
+ $("#rotation-groups-" + block).click ();
4053
+ }
4054
+ }
4055
+ }).fail (function (xhr, status, error) {
4056
+ console.log ("AI IMPORT ROTATION CODE ERROR:", xhr.status, xhr.statusText);
4057
+ $('#ai-error-container').text (ai_admin.error + ' ' + xhr.status + ': ' + xhr.statusText).show ();
4058
+
4059
+ var rotation_container = $('#ai-rotation-container-' + block);
4060
+ set_editor_text (block, b64d (rotation_container.data ('code')));
4061
+ rotation_container.hide();
4062
+ $("#rotation-" + block).next ("label").find ('.checkbox-icon').removeClass("on");
4063
+
4064
+ rotation_container.find ("ul").find ("li").remove ();
4065
+ rotation_container.find ("div.rounded").remove ();
4066
+ }).always (function() {
4067
+ $("#rotation-"+block).next ("label").find ('.checkbox-icon').removeClass("active");
4068
+ });
4069
+ }
4070
+
4071
+ function generate_rotatation_code (block) {
4072
+ $("#rotation-"+block).next ("label").find ('.checkbox-icon').addClass("active");
4073
+
4074
+ var rotation_container = $('#ai-rotation-container-' + block);
4075
+ var option = rotation_container.tabs ("option", "active") + 1;
4076
+
4077
+ $(('#option-' + block + '-' + option)).data ('code', b64e (get_editor_text (block)));
4078
+
4079
+ // var nonce = $("#ai-form").attr ('nonce');
4080
+
4081
+ var rotation_data = [];
4082
+ rotation_container.find ("div.rounded").each (function (index) {
4083
+ var code_data = $('#option-' + block + '-' + (index + 1)).data ('code');
4084
+ var code = typeof code_data == 'undefined' ? '' : b64d (code_data);
4085
+ var group_rotation = $("#rotation-groups-" + block).next ().find ('span').hasClass ('on');
4086
+ var option_data = {
4087
+ 'name': $(this).find ('input.option-name').val (),
4088
+ 'share': $(this).find ('input.option-share').val (),
4089
+ 'scheduling': $(this).find ('input.option-scheduling').val (),
4090
+ 'time': $(this).find ('input.option-time').val (),
4091
+ 'code': code, 'groups': group_rotation
4092
+ };
4093
+
4094
+ rotation_data.push (option_data);
4095
+ });
4096
+
4097
+ if (debug) console.log ('ROTATION DATA:', rotation_data);
4098
+
4099
+ $.post (ajaxurl, {'action': 'ai_ajax_backend', 'ai_check': ai_nonce, 'generate-rotation-code': b64e (JSON.stringify (rotation_data))}
4100
+ ).done (function (data) {
4101
+ $('#ai-error-container').hide ();
4102
+
4103
+ if (data != '') {
4104
+ var rotation_code = JSON.parse (data);
4105
+ if (typeof rotation_code !== "undefined") {
4106
+ if (debug) console.log ('ROTATION CODE:', rotation_code);
4107
+ set_editor_text (block, rotation_code);
4108
+ }
4109
+ }
4110
+
4111
+ }).fail (function (xhr, status, error) {
4112
+ console.log ("AI GENERATE ROTATION CODE ERROR:", xhr.status, xhr.statusText);
4113
+ $('#ai-error-container').text (ai_admin.error + ' ' + xhr.status + ': ' + xhr.statusText).show ();
4114
+
4115
+ var rotation_container = $('#ai-rotation-container-' + block);
4116
+ set_editor_text (block, b64d (rotation_container.data ('code')));
4117
+ rotation_container.hide();
4118
+ $("#rotation-" + block).next ("label").find ('.checkbox-icon').removeClass("on");
4119
+
4120
+ rotation_container.find ("ul").find ("li").remove ();
4121
+ rotation_container.find ("div.rounded").remove ();
4122
+ }).always (function() {
4123
+ $("#rotation-"+block).next ("label").find ('.checkbox-icon').removeClass("active");
4124
+
4125
+ $('input[name=ai_save]').css ('color', '#555');
4126
+ // $('.ai-rotation-warning').hide ();
4127
+ });
4128
+ }
4129
+
4130
+ function add_rotate_options (block, new_options) {
4131
+ var rotation_container = $('#ai-rotation-container-' + block);
4132
+ var ul = rotation_container.find ("ul");
4133
+ var options = rotation_container.find ('ul >li').length;
4134
+
4135
+ var rotation_tabs = $('#rotation-tabs');
4136
+ var li = rotation_tabs.find ("li");
4137
+ var div = rotation_tabs.find ("div.rounded");
4138
+
4139
+ var insertion = 0;
4140
+
4141
+ for (option = options + 1; option <= options + new_options; option ++) {
4142
+ if (option > 17) break;
4143
+
4144
+ var new_li = li.clone ().show ();
4145
+ new_li.find ("a").attr ('href', '#tab-option-' + block + '-' + option).text (String.fromCharCode (64 + option));
4146
+ new_li.attr ('id', 'option-' + block + '-' + option).appendTo (ul).data ('code', b64e (''));
4147
+
4148
+ new_li.click (function () {
4149
+ var rotation_container = $(this).closest ('.ai-rotate');
4150
+ var block = rotation_container.attr('id').replace ("ai-rotation-container-", "");
4151
+ var old_option = rotation_container.data ('option');
4152
+ var new_option = $(this).attr('id').replace ("option-" + block + "-", "");
4153
+ rotation_container.data ('option', new_option);
4154
+
4155
+ if (debug) console.log ('OPTION CHANGE:', old_option, '=>', new_option);
4156
+
4157
+ $(('#option-' + block + '-' + old_option)).data ('code', b64e (get_editor_text (block)));
4158
+ set_editor_text (block, b64d ($(this).data ('code')));
4159
+ });
4160
+
4161
+ div.clone ().show ().attr ('id', 'tab-option-' + block + '-' + option).appendTo (rotation_container);
4162
+
4163
+ rotation_container.tabs ("refresh");
4164
+ }
4165
+
4166
+ rotation_container.find ('[data-title]').each (function () {
4167
+ $(this).attr ('title', $(this).data ('title'));
4168
+ });
4169
+
4170
+ rotation_container.find ("[title]").tooltip ({
4171
+ track: true,
4172
+ delay: 700,
4173
+ showURL: false,
4174
+ showBody: " | ",
4175
+ fade: 250
4176
+ });
4177
+
4178
+ rotation_container.tabs ("option", "active", option - 2);
4179
+ }
4180
+
4181
+ function remove_rotate_option (block, option) {
4182
+ var rotation_container = $('#ai-rotation-container-' + block);
4183
+ var options = rotation_container.find ('ul >li').length;
4184
+
4185
+ if (options == 1) return;
4186
+
4187
+ var ul = rotation_container.find ("ul");
4188
+
4189
+ ul.find ("li").slice (option, option + 1).remove ();
4190
+ var div = rotation_container.find ("div.rounded").slice (option, option + 1).remove ();
4191
+
4192
+ rotation_container.find ('ul li').each (function (index) {
4193
+ var option = index + 1;
4194
+ $(this).attr ('id', 'option-' + block + '-' + option).find ("a").attr ('href', '#tab-option-' + block + '-' + option).text (String.fromCharCode (64 + option));
4195
+ });
4196
+
4197
+ rotation_container.find ("div.rounded").each (function (index) {
4198
+ var option = index + 1;
4199
+ $(this).attr ('id', 'tab-option-' + block + '-' + option);
4200
+ });
4201
+
4202
+ rotation_container.tabs ("refresh");
4203
+
4204
+ var new_option = option == 0 ? 0 : option - 1;
4205
+ active_li = $('#option-' + block + '-' + (new_option + 1));
4206
+ set_editor_text (block, b64d (active_li.data ('code')));
4207
+ ul.closest ('.ai-rotate').data ('option', new_option + 1);
4208
+ }
4209
+
4210
+ function create_list_selector (element_name_prefix, index) {
4211
+ var select = $('#'+element_name_prefix+'-select-' + index);
4212
+ if (select.length !== 0) {
4213
+ var button = $('#'+element_name_prefix+'-button-'+index);
4214
+
4215
+ var list_prefix = button.data ('list');
4216
+ if (list_prefix == null) list_prefix = element_name_prefix;
4217
+
4218
+ function update_list (list, element_name_prefix) {
4219
+ if (typeof before_update_selection_from_list == 'function') {
4220
+ before_update_selection_from_list (index);
4221
+ }
4222
+
4223
+ button.find ('span.ui-button-text').addClass ('ai-button-updating');
4224
+
4225
+ setTimeout (function() {
4226
+ update_selection_from_list (list, element_name_prefix);
4227
+ }, 5);
4228
+ }
4229
+
4230
+ button.click (function () {
4231
+ if (!select.hasClass ('multi-select')) {
4232
+ var options = select.find ('option');
4233
+ if (options.length == 0) {
4234
+ // var nonce = $("#ai-form").attr ('nonce');
4235
+
4236
+ var filter_element = $('#ms-'+element_name_prefix+'-select-' + index).find ('.filter-input');
4237
+ var filter = filter_element.length ? filter_element.val () : '';
4238
+
4239
+ var parameters_data = select.data ('parameters');
4240
+ var parameters = typeof parameters_data == 'undefined' ? '' : parameters_data;
4241
+
4242
+ $('#ai-loading').show ();
4243
+ button.find ('span.ui-button-text').addClass ('ai-button-active').show ();
4244
+
4245
+ $.get (ajaxurl + '?action=ai_ajax_backend&list-options=' + element_name_prefix + '&parameters=' + parameters + '&filter=' + filter + '&ai_check=' + ai_nonce, function (data) {
4246
+ if (data != '') {
4247
+ var message = '';
4248
+ var options = $('option', '<div>'+data+'</div>');
4249
+ if (options.length != 0) {
4250
+ if ($(options [0]).attr ('value').length == 0) {
4251
+ message = $(options [0]).text ();
4252
+ options = options.splice (1);
4253
+ }
4254
+ }
4255
+ select.attr ('data-message', message);
4256
+
4257
+ select.html (options);
4258
+ create_multi_select (select, element_name_prefix, list_prefix, index);
4259
+
4260
+ $('#ms-'+element_name_prefix+'-select-' + index).find ('.filter-message').text (message);
4261
+
4262
+ update_list ($('#'+list_prefix+'-list-'+index), element_name_prefix);
4263
+ }
4264
+
4265
+ }).fail (function (xhr, status, error) {
4266
+ $('input.filter-input', selection_container).remove ();
4267
+ var message = "Error loading " + element_name_prefix + " options: " + xhr.status + " " + xhr.statusText ;
4268
+ console.log (message);
4269
+ })
4270
+ .always (function () {
4271
+ $('#ai-loading').hide ();
4272
+ button.find ('span.ui-button-text').removeClass ('ai-button-active');
4273
+ });
4274
+
4275
+ } else create_multi_select (select, element_name_prefix, list_prefix, index);
4276
+
4277
+ } else {
4278
+ update_list ($('#'+list_prefix+'-list-'+index), element_name_prefix);
4279
+ $('#ms-'+element_name_prefix+'-select-'+index).toggle();
4280
+ }
4281
+ });
4282
+
4283
+
4284
+ $('#'+list_prefix+'-list-'+index).focusout (function () {
4285
+ var selection_container = $('#ms-'+element_name_prefix+'-select-'+index);
4286
+ if (selection_container.length && selection_container.is (':visible')) {
4287
+ update_list ($(this), element_name_prefix);
4288
+ }
4289
+ });
4290
+ }
4291
+ }
4292
+
4293
+ function update_list_from_selection (select_element, element_name_prefix, list_prefix) {
4294
+
4295
+ var ms = select_element.$element;
4296
+ var ms_val = ms.val();
4297
+ if (ms_val != null) {
4298
+ if (ms_val [0] == '') {
4299
+ ms_val = ms_val.splice (1)
4300
+ }
4301
+ ms_val = ms_val.join (', ').trim (',');
4302
+ }
4303
+ var index = ms.attr ('id').replace (element_name_prefix+'-select-','');
4304
+ var list = $('#'+list_prefix+'-list-'+index);
4305
+
4306
+ var custom_data = list.attr ('data-custom');
4307
+
4308
+ if (typeof custom_data != 'undefined' && custom_data != '') {
4309
+ if (ms_val != null) {
4310
+ if (ms_val != '') ms_val = ms_val + ', ';
4311
+ ms_val = ms_val + custom_data;
4312
+ } else ms_val = custom_data;
4313
+ }
4314
+
4315
+ list.attr ('value', ms_val);
4316
+ select_element.qs1.cache();
4317
+ // select_element.qs2.cache();
4318
+ }
4319
+
4320
+ function update_selection_from_list (list_element, element_name_prefix) {
4321
+
4322
+ Array.prototype.diff = function (a) {
4323
+ return this.filter(function (i) {
4324
+ return a.indexOf(i) === -1;
4325
+ });
4326
+ };
4327
+
4328
+ var index = list_element.attr ('id').replace (/^\D+/g, '');
4329
+ var select = $('#'+element_name_prefix+'-select-'+index);
4330
+ var selection_container = $('#ms-'+element_name_prefix+'-select-'+index);
4331
+
4332
+ if (selection_container.is(':visible')) {
4333
+ var list_items = list_element.attr ('value').split (',').map (Function.prototype.call, String.prototype.trim);
4334
+
4335
+ if (list_items [0] == '') {
4336
+ list_items = list_items.splice (1)
4337
+ }
4338
+
4339
+ if (list_element.hasClass ('ai-list-filter'))
4340
+ for (var i = 0; i < list_items.length; i++) {
4341
+ list_items [i] = list_items [i].replace (/ /g , '-').replace (/[\!\@\#\$%\^&\*\(\)\=\+\{\}\|\[\]\\\;\'\:\"\.\/\?]/g , '');
4342
+ }
4343
+
4344
+ if (list_element.hasClass ('ai-list-filter-cat'))
4345
+ for (var i = 0; i < list_items.length; i++) {
4346
+ list_items [i] = list_items [i].replace (/ /g , '-').replace (/[\!\@\#\$%\^&\(\)\=\{\}\|\[\]\\\;\'\:\"\.\/\?]/g , '');
4347
+ }
4348
+
4349
+ if (list_element.hasClass ('ai-list-uppercase')) list_items = list_items.map (Function.prototype.call, String.prototype.toUpperCase); else
4350
+ if (list_element.hasClass ('ai-list-lowercase')) list_items = list_items.map (Function.prototype.call, String.prototype.toLowerCase); else
4351
+ if (list_element.hasClass ('ai-list-country-case')) {
4352
+ var list_items = list_items.map (function callback (currentValue) {
4353
+ var data = currentValue.split (':');
4354
+ if (data [0] != null) data [0] = data [0].toUpperCase ();
4355
+ if (data [1] != null) data [1] = data [1].toUpperCase ();
4356
+ if (data [2] != null) data [2] = data [2].toLowerCase ();
4357
+ return data.join (':');
4358
+ });
4359
+ }
4360
+
4361
+ $('#'+element_name_prefix+'-select-'+index).multiSelect('refresh').multiSelect ('deselect_all').multiSelect ('select', list_items);
4362
+
4363
+ if (list_element.hasClass ('ai-list-custom')) {
4364
+ var custom_values = list_items;
4365
+ var selected_values = $('#'+element_name_prefix+'-select-'+index).val ();
4366
+
4367
+ if (selected_values != null) custom_values = list_items.diff (selected_values);
4368
+ if (custom_values != null) custom_values = custom_values.join (', ');
4369
+
4370
+ list_element.attr ('data-custom', custom_values);
4371
+
4372
+ select.multiSelect ('deselect_all').multiSelect ('select', list_items);
4373
+ }
4374
+
4375
+ if (select.hasClass ('ai-list-filter')) {
4376
+ var filter_div = $('#ms-'+element_name_prefix+'-select-'+index).find ('.ai-list-filter-container');
4377
+ var filter_input = filter_div.find ('.filter-input');
4378
+ var filter_button = filter_div.find ('.filter-button');
4379
+
4380
+ if (!filter_div.hasClass ('configured')) {
4381
+ filter_div.addClass ('configured');
4382
+
4383
+ filter_input.on ('keyup keypress', function(e) {
4384
+ var keyCode = e.keyCode || e.which;
4385
+ if (keyCode === 13) {
4386
+ e.preventDefault();
4387
+ filter_button.click ();
4388
+ return false;
4389
+ }
4390
+ });
4391
+
4392
+ filter_button.on ('click', function(e) {
4393
+ e.preventDefault();
4394
+
4395
+ var filter = filter_input.val ();
4396
+ select.attr ('data-filter', filter);
4397
+
4398
+ select.empty ();
4399
+ select.removeClass ('multi-select');
4400
+ $('#'+element_name_prefix+'-button-'+index).click ();
4401
+
4402
+ return false;
4403
+ });
4404
+ }
4405
+
4406
+ filter_div.show ();
4407
+ $('#ms-'+element_name_prefix+'-select-'+index).find ('.search-input').hide ();
4408
+ filter_button.button().show ();
4409
+ filter_input.val (select.attr ('data-filter'));
4410
+ $('#ms-'+element_name_prefix+'-select-' + index).find ('.filter-message').text (select.attr ('data-message'));
4411
+ }
4412
+ }
4413
+
4414
+ var button = $('#'+element_name_prefix+'-button-'+index);
4415
+ button.find ('span.ui-button-text').removeClass ('ai-button-updating');
4416
+ }
4417
+
4418
+ function create_multi_select (select, element_name_prefix, list_prefix, index) {
4419
+ select.addClass ('multi-select');
4420
+
4421
+ select.multiSelect ({
4422
+ selectableHeader:
4423
+ '<div class="ai-list-filter-container"> \
4424
+ <input type="text" class="filter-input" autocomplete="off" placeholder="' + ai_admin.filter + '" title="' + ai_admin.filter_title + '"> \
4425
+ <button class="filter-button" style="margin-top: -2px; display: none;">' + ai_admin.button_filter + '</button> \
4426
+ <span class="filter-message"></span> \
4427
+ </div> \
4428
+ <input type="text" class="search-input" autocomplete="off" placeholder="' + ai_admin.search + '">',
4429
+ selectionHeader: '',
4430
+ afterInit: function(ms){
4431
+ var that = this,
4432
+ $selectableSearch = that.$selectableUl.prev(),
4433
+ $selectionSearch = that.$selectionUl.prev(),
4434
+ selectableSearchString = '#'+that.$container.attr('id')+' .ms-elem-selectable:not(.ms-selected)',
4435
+ selectionSearchString = '#'+that.$container.attr('id')+' .ms-elem-selection.ms-selected';
4436
+
4437
+ that.qs1 = $selectableSearch.quicksearch (selectableSearchString)
4438
+ .on('keydown', function(e){
4439
+ if (e.which === 40){
4440
+ that.$selectableUl.focus();
4441
+ return false;
4442
+ }
4443
+ });
4444
+
4445
+ // that.qs2 = $selectionSearch.quicksearch (selectionSearchString)
4446
+ // .on('keydown', function(e){
4447
+ // if (e.which == 40){
4448
+ // that.$selectionUl.focus();
4449
+ // return false;
4450
+ // }
4451
+ // });
4452
+ },
4453
+ afterSelect: function(values){
4454
+ update_list_from_selection (this, element_name_prefix, list_prefix);
4455
+ },
4456
+ afterDeselect: function(values){
4457
+ update_list_from_selection (this, element_name_prefix, list_prefix);
4458
+ }
4459
+ });
4460
+
4461
+ // $('#ms-'+element_name_prefix+'-select-' + index).hide();
4462
+ }
4463
+
4464
+ function create_list_editor (element_name_prefix, index) {
4465
+ var editor = $('#'+element_name_prefix+'-editor-'+index);
4466
+ var list = $('#'+element_name_prefix+'-list-'+index);
4467
+ if (editor.length !== 0) {
4468
+ $('#'+element_name_prefix+'-button-'+index).click (function () {
4469
+ update_editor_from_list (list, element_name_prefix, true);
4470
+ });
4471
+
4472
+ editor.focusout (function () {
4473
+ update_list_from_editor (editor, element_name_prefix)
4474
+ });
4475
+
4476
+ list.focusout (function () {
4477
+ if (editor.is(':visible'))
4478
+ update_editor_from_list ($(this), element_name_prefix, false);
4479
+ });
4480
+ }
4481
+ }
4482
+
4483
+ function clean_url_list (list_element, list_items) {
4484
+
4485
+ var clean_protocol = list_element.hasClass ('ai-clean-protocol');
4486
+ var clean_domain = list_element.hasClass ('ai-clean-domain');
4487
+ var only_domain = list_element.hasClass ('ai-only-domain');
4488
+ var sort_list = list_element.hasClass ('ai-list-sort');
4489
+
4490
+ function onlyUnique (value, index, self) {
4491
+ return self.indexOf (value) === index;
4492
+ }
4493
+
4494
+ list_items = list_items.filter (onlyUnique);
4495
+
4496
+ var clean_list_items = [];
4497
+
4498
+ for (var i = 0; i < list_items.length; i++) {
4499
+ var list_item = list_items [i];
4500
+
4501
+ if (clean_protocol && list_item.indexOf ('http') == 0) {
4502
+ list_item = list_item.replace ('http://', '');
4503
+ list_item = list_item.replace ('https://', '');
4504
+
4505
+ var slash = list_item.indexOf ("/");
4506
+
4507
+ if (clean_domain) {
4508
+ if (slash > 0) {
4509
+ list_item = list_item.substring (slash);
4510
+ } else list_item = '';
4511
+ } else
4512
+ if (only_domain) {
4513
+ if (slash > 0) {
4514
+ list_item = list_item.substring (0, slash);
4515
+ }
4516
+ }
4517
+ }
4518
+
4519
+ if (list_item != '') clean_list_items.push (list_item);
4520
+ }
4521
+
4522
+ if (sort_list) {
4523
+ clean_list_items.sort();
4524
+ }
4525
+
4526
+ return clean_list_items;
4527
+ }
4528
+
4529
+ function update_editor_from_list (list_element, element_name_prefix, toggle) {
4530
+ var index = list_element.attr ('id').replace (element_name_prefix+'-list-','');
4531
+ var editor = $('#'+element_name_prefix+'-editor-'+index);
4532
+ if (toggle) editor.toggle();
4533
+ if (editor.is(':visible')) {
4534
+
4535
+ var list = list_element.attr ('value');
4536
+ var list_separator = ',';
4537
+
4538
+ if (list_element.hasClass ('ai-list-space')) {
4539
+ if (list.indexOf (' ') > - 1 && list.indexOf (',') == - 1) list_separator = ' ';
4540
+ }
4541
+
4542
+ var list_items = list.split (list_separator).map (Function.prototype.call, String.prototype.trim);
4543
+
4544
+ clean_list_items = clean_url_list (list_element, list_items);
4545
+
4546
+ editor.val (clean_list_items.join ("\n"));
4547
+ } else update_list_from_editor (editor, element_name_prefix)
4548
+ }
4549
+
4550
+ function update_list_from_editor (editor, element_name_prefix) {
4551
+ var list_items = editor.val ().split ("\n").map (Function.prototype.call, String.prototype.trim);
4552
+
4553
+ var index = editor.attr ('id').replace (element_name_prefix+'-editor-','');
4554
+ var list_element = $('#'+element_name_prefix+'-list-'+index);
4555
+
4556
+ clean_list_items = clean_url_list (list_element, list_items);
4557
+
4558
+ list_element.attr ('value', clean_list_items.join (', '));
4559
+ }
4560
+
4561
+ function configure_hidden_tab () {
4562
+ var current_tab;
4563
+ var tab;
4564
+
4565
+ if (debug) console.log ("");
4566
+ if (debug) {
4567
+ var current_time_start = new Date().getTime();
4568
+ console.log ("since last time: " + ((current_time_start - last_time) / 1000).toFixed (3));
4569
+ }
4570
+ if (debug) console.log ("configure_hidden_tab");
4571
+ if (debug) console.log ("tabs_to_configure: " + tabs_to_configure);
4572
+
4573
+ do {
4574
+ if (tabs_to_configure.length == 0) {
4575
+ save_enabled = true;
4576
+ if (debug_title) $("#plugin_name").css ("color", "#000");
4577
+ if (debug) console.log ("configure_hidden_tab: DONE");
4578
+ return;
4579
+ }
4580
+ current_tab = tabs_to_configure.pop();
4581
+ tab = $("#tab-" + current_tab);
4582
+ } while (tab.hasClass ('configured'));
4583
+
4584
+ if (debug) console.log ("Configuring tab: " + current_tab);
4585
+
4586
+ if (current_tab != 0) configure_tab (current_tab); else configure_tab_0 ();
4587
+
4588
+ if (debug) {
4589
+ var current_time = new Date().getTime();
4590
+ console.log ("time: " + ((current_time - current_time_start) / 1000).toFixed (3));
4591
+ console.log ("TIME: " + ((current_time - start_time) / 1000).toFixed (3));
4592
+ last_time = current_time;
4593
+ }
4594
+
4595
+ // if (tabs_to_configure.length != 0) setTimeout (configure_hidden_tab, 10);
4596
+ if (tabs_to_configure.length != 0) {
4597
+ if (ai_tab_setup_delay != 0) {
4598
+ setTimeout (configure_hidden_tab, ai_tab_setup_delay);
4599
+ }
4600
+ } else {
4601
+ save_enabled = true;
4602
+ if (debug_title && ai_tab_setup_delay != 0) $("#plugin_name").css ("color", "#000");
4603
+ if (debug) console.log ("configure_hidden_tab: DONE");
4604
+ }
4605
+ }
4606
+
4607
+ function configure_chart (container) {
4608
+ var ai_adb_flag_blocked = 0x80;
4609
+
4610
+ if (!$(container).hasClass ('not-configured')) return;
4611
+ var template = $(container).data ('template');
4612
+
4613
+ if (typeof template != 'undefined') {
4614
+ var new_colors = [];
4615
+ var color_indexes = $(container).data ('colors');
4616
+ if (typeof color_indexes != 'undefined') {
4617
+ var colors = $.elycharts.templates['ai-pie'].defaultSeries.values;
4618
+ color_indexes.forEach (function (element) {
4619
+ if (element == ai_adb_flag_blocked )
4620
+ new_colors.push (colors [9]); else
4621
+ new_colors.push (colors [element]);
4622
+ });
4623
+ }
4624
+
4625
+ var values = $(container).data ('values-1');
4626
+ if (values == null) values = $(container).data ('values-2');
4627
+ if (values == null) values = $(container).data ('values-3');
4628
+ if (values == null) values = $(container).data ('values-4');
4629
+ if (values == null) values = $(container).data ('values-5');
4630
+ if (values == null) values = $(container).data ('values-6');
4631
+ if (values == null) values = $(container).data ('values-7');
4632
+ if (values == null) values = $(container).data ('values-8');
4633
+ if (values == null) values = $(container).data ('values-9');
4634
+
4635
+ var legend = $(container).data ('legend');
4636
+ if (typeof legend != 'undefined' && typeof legend ['serie' + (ai_adb_flag_blocked + 1)] != 'undefined') {
4637
+ var new_legend = {};
4638
+ for (var legend_item in legend) {
4639
+ if (legend_item == 'serie' + (ai_adb_flag_blocked + 1))
4640
+ new_legend ['serie10'] = legend [legend_item]; else
4641
+ new_legend [legend_item] = legend [legend_item];
4642
+ }
4643
+ legend = new_legend;
4644
+ }
4645
+
4646
+ $(container).chart({
4647
+ template: template,
4648
+ labels: $(container).data ('labels'),
4649
+ values: {
4650
+ serie1: values,
4651
+ serie2: $(container).data ('values-2'),
4652
+ serie3: $(container).data ('values-3'),
4653
+ serie4: $(container).data ('values-4'),
4654
+ serie5: $(container).data ('values-5'),
4655
+ serie6: $(container).data ('values-6'),
4656
+ serie7: $(container).data ('values-7'),
4657
+ serie8: $(container).data ('values-8'),
4658
+ serie9: $(container).data ('values-9'),
4659
+ serie10: $(container).data ('values-' + (ai_adb_flag_blocked + 1)), // BLOCKED
4660
+ },
4661
+ legend: legend,
4662
+ tooltips: {serie1: $(container).data ('tooltips')},
4663
+ defaultSeries: {values: new_colors, tooltip: {height: $(container).data ('tooltip-height')}},
4664
+ defaultAxis : {
4665
+ max: $(container).data ('max'),
4666
+ },
4667
+ features: {
4668
+ grid: {
4669
+ draw: values == null ? true : values.length < 50,
4670
+ }
4671
+ }
4672
+ });
4673
+
4674
+ $(container).removeClass ('not-configured');
4675
+ $(container).parent().find ('div.ai-chart-label').show ();
4676
+ }
4677
+ }
4678
+
4679
+ function update_rating (parameter) {
4680
+ var rating_bar = $('#ai-rating-bar');
4681
+ // var nonce = rating_bar.attr ('nonce');
4682
+ $("#rating-value span").load (ajaxurl+"?action=ai_ajax_backend&rating=" + parameter + "&ai_check=" + ai_nonce, function() {
4683
+ var rating = $("#rating-value span").text ();
4684
+ var rating_value = 0;
4685
+ if (rating != '') var rating_value = parseFloat (rating);
4686
+ $("#rating-value").css ('width', rating_value * 20 + '%');
4687
+
4688
+ if ($("#rating-value span").text () == '') {
4689
+ $("#ai-rating-bar").hide ();
4690
+ $('#ai-stars').show ();
4691
+ }
4692
+ });
4693
+ }
4694
+
4695
+ function configure_charts (container) {
4696
+ $(container).find ('.ai-chart.not-configured').each (function() {
4697
+ if (!$(this).hasClass ('hidden')) {
4698
+ $(this).attr ('style', '');
4699
+ configure_chart (this);
4700
+ }
4701
+ });
4702
+ }
4703
+
4704
+ function replace_block_number (element, attribute, old_block, new_block) {
4705
+ var attr_value = element.attr (attribute);
4706
+ var attr_number = attr_value.substr (- old_block.toString().length);
4707
+ if (attr_number == old_block) {
4708
+ element.attr (attribute, attr_value.substr (0, attr_value.length - old_block.toString().length) + new_block);
4709
+
4710
+ // console.log (attribute, element.attr (attribute));
4711
+ }
4712
+ }
4713
+
4714
+ function copy_to_clipboard () {
4715
+ if (debug) console.log ("AI COPY FROM BLOCK", active_tab);
4716
+
4717
+ var clipboard = $('#ai-clipboard');
4718
+ clipboard.html ($('#ai-clipboard-template').html ());
4719
+
4720
+ $('div#tab-' + active_tab + ' input[name]:checkbox').each (function (index){
4721
+ var attr = $(this).attr('checked');
4722
+ var checked = typeof attr !== typeof undefined && attr !== false;
4723
+
4724
+ if (checked)
4725
+ clipboard.find ('input[name]:checkbox').eq (index).attr ('checked', 'checked').next ("label").find ('.checkbox-icon').addClass("on"); else
4726
+ clipboard.find ('input[name]:checkbox').eq (index).removeAttr ('checked').next ("label").find ('.checkbox-icon').removeClass("on");
4727
+ });
4728
+
4729
+ $('div#tab-' + active_tab + ' input[name]:radio').each (function (index){
4730
+ var attr = $(this).attr('checked');
4731
+ var checked = typeof attr !== typeof undefined && attr !== false;
4732
+
4733
+ if (checked)
4734
+ clipboard.find ('input[name]:radio').eq (index).attr ('checked', 'checked'); else
4735
+ clipboard.find ('input[name]:radio').eq (index).removeAttr ('checked');
4736
+ });
4737
+
4738
+ $('div#tab-' + active_tab + ' select[name]').each (function (index){
4739
+ var value = $(this).find ("option:selected").val ();
4740
+ clipboard.find ('select[name]').eq (index).find ("option").removeAttr ('selected');
4741
+ clipboard.find ('select[name]').eq (index).find ("option[value = '" + value + "']").attr ("selected", true);
4742
+ });
4743
+
4744
+ $('div#tab-' + active_tab + ' input[name]:text').each (function (index){
4745
+ clipboard.find ('input[name]:text').eq (index).attr ('value', $(this).val ());
4746
+ });
4747
+
4748
+
4749
+ // Lists
4750
+ if ($('#list-settings-' + active_tab).is(':visible')) {
4751
+ clipboard.find ('#list-settings-999').show ();
4752
+ } else {
4753
+ clipboard.find ('#list-settings-999').hide ();
4754
+ }
4755
+
4756
+ if ($('#list-settings-' + active_tab).hasClass('ai-expanded')) {
4757
+ clipboard.find ('#list-settings-999').addClass ('ai-expanded');
4758
+ } else {
4759
+ clipboard.find ('#list-settings-999').removeClass ('ai-expanded');
4760
+ }
4761
+
4762
+ $('div#tab-' + active_tab + ' table.ai-lists tr').each (function (index){
4763
+ if ($(this).is(':visible')) {
4764
+ clipboard.find ('table.ai-lists tr').eq (index).show ();
4765
+ } else {
4766
+ clipboard.find ('table.ai-lists tr').eq (index).hide ();
4767
+ }
4768
+
4769
+ if ($(this).find ('span.checkbox-list-button').hasClass ('dashicons-no')) {
4770
+ clipboard.find ('table.ai-lists tr').eq (index).find ('span.checkbox-list-button').addClass ('dashicons-no').removeClass ('dashicons-yes');
4771
+ } else {
4772
+ clipboard.find ('table.ai-lists tr').eq (index).find ('span.checkbox-list-button').removeClass ('dashicons-no').addClass ('dashicons-yes');
4773
+ }
4774
+
4775
+ if ($(this).hasClass ('list-items')) {
4776
+ clipboard.find ('table.ai-lists tr').eq (index).addClass ('list-items');
4777
+ } else {
4778
+ clipboard.find ('table.ai-lists tr').eq (index).removeClass ('list-items');
4779
+ }
4780
+ });
4781
+
4782
+
4783
+ clipboard.find ('textarea.simple-editor').text (get_editor_text (active_tab));
4784
+
4785
+ $("#ai-container .ai-copy").each (function () {
4786
+ $(this).next ("label").find ('.checkbox-icon').addClass("on");
4787
+ });
4788
+ }
4789
+
4790
+ function load_saved_settings_to_clipboard (block, paste) {
4791
+ if (debug) console.log ("AI LOAD BLOCK", block, "FROM DB");
4792
+
4793
+ var tools_button = $("#tools-button-" + active_tab);
4794
+ if (!tools_button.next ('label').find ('.checkbox-icon').hasClass ("on")) {
4795
+ tools_button.click ();
4796
+ }
4797
+
4798
+ $('#ai-loading').show ();
4799
+ // var nonce = $("#ai-form").attr ('nonce');
4800
+
4801
+ $.get (ajaxurl + '?action=ai_ajax_backend&settings=' + block + '&single=1&ai_check=' + ai_nonce, function (settings) {
4802
+ if (debug) console.log ("AI BLOCK LOADED");
4803
+
4804
+ var clipboard = $('#ai-clipboard');
4805
+
4806
+ clipboard.html ($('div#tab-' + block, settings).html ());
4807
+
4808
+ clipboard.find ('[id]').each (function () {
4809
+ replace_block_number ($(this), 'id', block, 999);
4810
+ });
4811
+
4812
+ clipboard.find ('[for]').each (function () {
4813
+ replace_block_number ($(this), 'for', block, 999);
4814
+ });
4815
+
4816
+ clipboard.find ('[href]').each (function () {
4817
+ replace_block_number ($(this), 'href', block, 999);
4818
+ });
4819
+
4820
+ clipboard.find ('[name]').each (function () {
4821
+ replace_block_number ($(this), 'name', block, 999);
4822
+ });
4823
+
4824
+ clipboard.find ('[class]').each (function () {
4825
+ replace_block_number ($(this), 'class', block, 999);
4826
+ });
4827
+
4828
+ clipboard.find ('pre.ai-block-number').each (function () {
4829
+ var text = $(this).text ().replace (block, 999);
4830
+ $(this).text (text);
4831
+ });
4832
+
4833
+ $("#ai-container .ai-copy").each (function () {
4834
+ $(this).next ("label").find ('.checkbox-icon').addClass("on");
4835
+ });
4836
+
4837
+ // if (paste) {
4838
+ // var tools_visible = $('#ai-tools-toolbar-' + active_tab).is(':visible');
4839
+
4840
+ // paste_from_clipboard (true, true, true, false);
4841
+
4842
+ // if (tools_visible) {
4843
+ // $('#ai-tools-toolbar-' + active_tab).show ();
4844
+ // $("#tools-button-"+active_tab).next ('label').find ('.checkbox-icon').addClass("on");
4845
+ // }
4846
+ // }
4847
+ }).fail (function (xhr, status, error) {
4848
+ console.log ("AI LOADING ERROR:", xhr.status, xhr.statusText);
4849
+ $('#ai-error-container').text (ai_admin.error + ' ' + xhr.status + ': ' + xhr.statusText).show ();
4850
+ })
4851
+ .always (function () {
4852
+ $('#ai-loading').hide ();
4853
+ });
4854
+ }
4855
+
4856
+ function paste_from_clipboard (paste_name, paste_code, paste_settings, clear) {
4857
+
4858
+ if (clear) {
4859
+ var clipboard_template = $('#ai-clipboard-template');
4860
+ clipboard_template.find ('input#name-edit-999').attr ('value', 'Block ' + active_tab).attr ('default', 'Block ' + active_tab);
4861
+ var clipboard = clipboard_template.html ();
4862
+ } else {
4863
+ var clipboard = $('#ai-clipboard').html ();
4864
+ }
4865
+
4866
+ if (clipboard != '' && active_tab != 0) {
4867
+ if (debug) console.log ("AI PASTE TO BLOCK", active_tab);
4868
+
4869
+ var destination_tab = $('div#tab-' + active_tab);
4870
+
4871
+ var name = destination_tab.find ('input#name-edit-' + active_tab).val ();
4872
+ var code = get_editor_text (active_tab);
4873
+
4874
+ if (paste_settings) {
4875
+ var simple_editor = $('#simple-editor-' + active_tab).is(":checked");
4876
+ var tools_visible = $('#ai-tools-toolbar-' + active_tab).is(':visible');
4877
+ var copy_active = destination_tab.find ('.ai-copy').next ("label").find ('.checkbox-icon').hasClass("on");
4878
+
4879
+ if (simple_editor) {
4880
+ $('#simple-editor-' + active_tab).click ();
4881
+ }
4882
+
4883
+ var save_button_text = destination_tab.find ('input[name=ai_save]').attr('value');
4884
+ var exceptions_button = destination_tab.find ('#exceptions-button-container-' + active_tab).html ();
4885
+ var exceptions_container = destination_tab.find ('#block-exceptions-' + active_tab).html ();
4886
+
4887
+ destination_tab.html (clipboard).find ('input[name=ai_save]').attr('value', save_button_text);
4888
+
4889
+ if (!paste_name) {
4890
+ destination_tab.find ('input#name-edit-999').val (name);
4891
+ }
4892
+
4893
+ if (!paste_code) {
4894
+ destination_tab.find ('textarea#block-999').val (code);
4895
+ }
4896
+
4897
+ destination_tab.find ('span#name-label-999').text (destination_tab.find ('input#name-edit-999').val ());
4898
+
4899
+ var block_name = destination_tab.find ('input#name-edit-999').val ();
4900
+ destination_tab.find ('pre.ai-block-name').text ('[adinserter name="' + block_name + '"]');
4901
+
4902
+ destination_tab.find ('[id]').each (function () {
4903
+ replace_block_number ($(this), 'id', 999, active_tab);
4904
+ });
4905
+
4906
+ destination_tab.find ('[for]').each (function () {
4907
+ replace_block_number ($(this), 'for', 999, active_tab);
4908
+ });
4909
+
4910
+ destination_tab.find ('[href]').each (function () {
4911
+ replace_block_number ($(this), 'href', 999, active_tab);
4912
+ });
4913
+
4914
+ destination_tab.find ('[name]').each (function () {
4915
+ replace_block_number ($(this), 'name', 999, active_tab);
4916
+ });
4917
+
4918
+ destination_tab.find ('[class]').each (function () {
4919
+ replace_block_number ($(this), 'class', 999, active_tab);
4920
+ });
4921
+
4922
+ destination_tab.find ('pre.ai-sidebars').text ('');
4923
+
4924
+ destination_tab.find ('pre.ai-block-number').each (function () {
4925
+ var text = $(this).text ().replace (999, active_tab);
4926
+ $(this).text (text);
4927
+ });
4928
+
4929
+ destination_tab.find ('#exceptions-button-container-' + active_tab).html (exceptions_button);
4930
+ destination_tab.find ('#block-exceptions-' + active_tab).html (exceptions_container);
4931
+
4932
+ configure_tab (active_tab);
4933
+
4934
+ if (simple_editor) {
4935
+ $('#simple-editor-' + active_tab).click ();
4936
+ }
4937
+
4938
+ if (tools_visible) {
4939
+ $('#ai-tools-toolbar-' + active_tab).show ();
4940
+ $("#tools-button-" + active_tab).next ('label').find ('.checkbox-icon').addClass ("on");
4941
+ }
4942
+
4943
+ if (copy_active) {
4944
+ destination_tab.find ('.ai-copy').next ("label").find ('.checkbox-icon').addClass("on");
4945
+ }
4946
+ } else {
4947
+ if (paste_name) {
4948
+ var clipboard_name = $(clipboard).find ('input#name-edit-999').val ();
4949
+ destination_tab.find ('input#name-edit-' + active_tab).val (clipboard_name);
4950
+ destination_tab.find ('span#name-label-' + active_tab).text (clipboard_name);
4951
+ destination_tab.find ('pre.ai-block-name').text ('[adinserter name="' + clipboard_name + '"]');
4952
+ }
4953
+
4954
+ if (paste_code) {
4955
+ set_editor_text (active_tab, $(clipboard).find ('textarea#block-999').val ());
4956
+ }
4957
+ }
4958
+
4959
+ if (debug) console.log ("AI PASTE END");
4960
+ } else if (debug) console.log ("AI PASTE FAILED");
4961
+ }
4962
+
4963
+ function highlight_active_block () {
4964
+ $('#ai-list-table tr.ai-block-list').removeClass ('ai-block-active');
4965
+ $('#ai-list-table tr.ai-block-' + active_tab).addClass ('ai-block-active');
4966
+ }
4967
+
4968
+ function check_and_configure_active_tab () {
4969
+ highlight_active_block ();
4970
+
4971
+ if (!$("#tab-" + active_tab).hasClass ('configured')) {
4972
+ if (debug) console.log ("");
4973
+ if (debug) console.log ("Empty tab: " + active_tab);
4974
+ tabs_to_configure.push (active_tab);
4975
+ setTimeout (configure_hidden_tab, 10);
4976
+ if (debug) console.log ("tabs_to_configure: " + tabs_to_configure);
4977
+ } else if (active_tab != 0) {
4978
+ if (syntax_highlighting) {
4979
+ var editor = ace.edit ("editor-" + active_tab);
4980
+ editor.getSession ().highlightLines (10000000);
4981
+ }
4982
+ }
4983
+ }
4984
+
4985
+ function configure_website_list () {
4986
+ $("td.ai-website-desc").click (function () {
4987
+ var row = $(this).closest ('tr.ai-website-list');
4988
+ var website = row.data ("website");
4989
+
4990
+ var connected = row.find ('.checkbox-icon').hasClass ('on');
4991
+
4992
+ if (!connected) {
4993
+ $("#ai-website-list-table td.ai-website-labels").show ();
4994
+ $("#ai-website-list-table td.ai-website-editor").hide ();
4995
+
4996
+ $("#ai-cancel-websites").show ();
4997
+ $("#ai-save-websites").show ();
4998
+ $("#ai-rearrange-websites").removeClass ('blue');
4999
+
5000
+ row.find (".ai-website-editor .ai-website-key").val (row.find (".ai-website-editor .ai-website-key").attr ('data-key'));
5001
+ row.find (".ai-website-editor .ai-website-desc").val (row.find (".ai-website-labels.ai-website-desc").text ());
5002
+ row.find (".ai-website-editor .ai-website-url").val (row.find (".ai-website-labels.ai-website-url").text ());
5003
+
5004
+ row.find (".ai-website-labels").hide ();
5005
+ row.find (".ai-website-editor").show ();
5006
+
5007
+ row.find (".ai-website-editor .ai-website-desc").focus ();
5008
+ }
5009
+ });
5010
+
5011
+ $("span.ai-website-key").dblclick (function () {
5012
+ var row = $(this).closest ('tr.ai-website-list');
5013
+ row.toggleClass ('read-only');
5014
+ });
5015
+
5016
+ $("input.ai-website-key, input.ai-website-desc, input.ai-website-url").on('keyup keypress', function (e) {
5017
+ var keyCode = e.keyCode || e.which;
5018
+ ignore_key = true;
5019
+
5020
+ var row = $(this).closest('tr.ai-website-list');
5021
+ var website = row.data ("website");
5022
+
5023
+ if (keyCode == 27) {
5024
+ row.find (".ai-website-labels").show ();
5025
+ row.find (".ai-website-editor").hide ();
5026
+
5027
+ ignore_key = false;
5028
+ }
5029
+ else if (keyCode == 13) {
5030
+ $("#ai-save-websites").click ();
5031
+
5032
+ ignore_key = false;
5033
+ e.preventDefault();
5034
+ return false;
5035
+ }
5036
+ }).focusout (function() {
5037
+ if (ignore_key) {
5038
+ var row = $(this).closest ('tr.ai-website-list');
5039
+ var website = row.data ("website");
5040
+
5041
+ row.find (".ai-website-editor .ai-website-key").attr ('data-key', row.find (".ai-website-editor .ai-website-key").val ());
5042
+ row.find (".ai-website-labels.ai-website-desc").text (row.find (".ai-website-editor .ai-website-desc").val ());
5043
+ row.find (".ai-website-labels.ai-website-url").text (row.find (".ai-website-editor .ai-website-url").val ());
5044
+ }
5045
+ ignore_key = true;
5046
+ });
5047
+
5048
+ $("#ai-website-list-table .ai-delete-website").click (function () {
5049
+
5050
+ var row = $(this).closest ('tr.ai-website-list');
5051
+ var website = row.data ("website");
5052
+ var url = row.find (".ai-website-labels.ai-website-url").text ();
5053
+ var desc = row.find (".ai-website-labels.ai-website-desc").text ();
5054
+ var message = website;
5055
+ var message = ai_admin.delete_website + '<br />' + desc + '<br />' + url;
5056
+
5057
+ $('<div />').html (message).attr ('title', ai_admin.warning).dialog ({
5058
+ bgiframe: true,
5059
+ draggable: false,
5060
+ resizable: false,
5061
+ modal: true,
5062
+ height: "auto",
5063
+ width: 400,
5064
+ position: {my: 'center', at: 'center', of: '#ai-manage-websites-container'},
5065
+ buttons: [{
5066
+ text: ai_admin.cancel,
5067
+ click: function() {
5068
+ $(this).dialog ("close");
5069
+ }
5070
+ },
5071
+ {
5072
+ text: ai_admin.delete_all,
5073
+ click: function() {
5074
+ $(this).dialog ("close");
5075
+
5076
+ $("#ai-cancel-websites").hide ();
5077
+ $("#ai-save-websites").hide ();
5078
+ $("#ai-rearrange-websites").removeClass ('blue');
5079
+
5080
+ reload_websites ('&delete=all');
5081
+ }
5082
+ },
5083
+ {
5084
+ text: ai_admin.delete,
5085
+ click: function() {
5086
+ $(this).dialog ("close");
5087
+
5088
+ $("#ai-cancel-websites").hide ();
5089
+ $("#ai-save-websites").hide ();
5090
+ $("#ai-rearrange-websites").removeClass ('blue');
5091
+
5092
+ reload_websites ('&delete=' + website);
5093
+ }
5094
+ }
5095
+ ],
5096
+ });
5097
+ });
5098
+
5099
+ $("#ai-website-list-table .ai-connect-website").click (function () {
5100
+ var row = $(this).closest ('tr.ai-website-list');
5101
+ var website = row.data ("website");
5102
+
5103
+ var read_only_parameter = row.hasClass ('read-only') ? '&read-only=1' : '';
5104
+
5105
+ var connected = row.find ('.ai-connect-website .checkbox-icon').hasClass ('on');
5106
+ // if (connected) website = '';
5107
+
5108
+ ai_reload_websites_function = function () {
5109
+ if ($('#ai-website-data .ai-ajax-error').length == 0) {
5110
+ window.location.href = ai_settings;
5111
+ }
5112
+ }
5113
+
5114
+ if ($("#ai-save-websites").is(':visible')) {
5115
+ $("#ai-save-websites").attr ('data-connect', website).click ();
5116
+ } else {
5117
+ reload_websites ('&connect=' + website + read_only_parameter);
5118
+ }
5119
+ });
5120
+
5121
+ $("#ai-website-list-table label[title]").tooltip ({
5122
+ track: true,
5123
+ delay: 700,
5124
+ showURL: false,
5125
+ showBody: " | ",
5126
+ fade: 250
5127
+ });
5128
+ }
5129
+
5130
+ function configure_list () {
5131
+ var data_container = $("#ai-list-data");
5132
+
5133
+ $(".ai-tab-link").click (function () {
5134
+ var tab = $(this).data ('tab') - start;
5135
+ $("#ai-tab-container").tabs ({active: tab});
5136
+
5137
+ active_tab = parseInt ($(this).data ('tab'));
5138
+
5139
+ if (debug) console.log ("$('.ai-tab-link').click", active_tab);
5140
+
5141
+ check_and_configure_active_tab ();
5142
+
5143
+ });
5144
+
5145
+ $("label.ai-copy-block").click (function () {
5146
+ var block = $(this).closest ('tr').data ('block');
5147
+
5148
+ load_saved_settings_to_clipboard (block, true);
5149
+ });
5150
+
5151
+ $("label.ai-pause-block").click (function () {
5152
+ if (ai_read_only) return;
5153
+
5154
+ var block = $(this).closest ('tr').data ('block');
5155
+
5156
+ reload_list ('cmd=pause&cmd-block=' + block);
5157
+ ai_reload_list_function = function () {
5158
+ var block_button = $('#disable-insertion-' + block);
5159
+ var block_button_paused = block_button.parent ().find ('.icon-pause').hasClass ('on');
5160
+ var new_paused = $('#ai-list-table tr.ai-block-' + block).find ('label.ai-pause-block').hasClass ('ai-paused');
5161
+
5162
+ if (new_paused != block_button_paused) {
5163
+ block_button.click ();
5164
+ }
5165
+ }
5166
+ });
5167
+
5168
+ $("label.ai-preview-block").click (function () {
5169
+ var block = $(this).closest ('tr').data ('block');
5170
+
5171
+ var window_width = 820;
5172
+ var window_height = 820;
5173
+ var window_left = 100;
5174
+ var window_top = (screen.height / 2) - (820 / 2);
5175
+
5176
+ var param = {'action': 'ai_ajax_backend', 'preview': block, 'ai_check': ai_nonce, 'read_only': 1};
5177
+ open_popup_window_post (ajaxurl, 'width='+window_width+',height='+window_height+',top='+window_top+',left='+window_left+',resizable=yes,scrollbars=yes,toolbar=no,location=no,directories=no,status=no,menubar=no', 'preview', param);
5178
+ });
5179
+
5180
+ highlight_active_block ();
5181
+
5182
+ data_container.disableSelection();
5183
+
5184
+ $("#ai-list-data td[title]").tooltip ({
5185
+ track: true,
5186
+ delay: 700,
5187
+ showURL: false,
5188
+ showBody: " | ",
5189
+ fade: 250
5190
+ });
5191
+ }
5192
+
5193
+ function reload_websites (parameters) {
5194
+ website_list_search_reload = false;
5195
+ var list = encodeURIComponent ($("#ai-website-list-search").val());
5196
+
5197
+ var data_container = $("#ai-website-data");
5198
+
5199
+ $('#ai-loading').show ();
5200
+
5201
+ if (typeof parameters == 'undefined') parameters = '';
5202
+
5203
+ data_container.load (ajaxurl+"?action=ai_ajax_backend&websites=" + list + parameters + "&ai_check=" + ai_nonce, function (response, status, xhr) {
5204
+ $('#ai-loading').hide ();
5205
+ if (status == "error") {
5206
+ var message = "Error downloading website data: " + xhr.status + " " + xhr.statusText;
5207
+ data_container.html (message);
5208
+ if (debug) console.log (message);
5209
+ } else {
5210
+ configure_website_list ();
5211
+
5212
+ if (typeof ai_reload_websites_function == 'function') {
5213
+ ai_reload_websites_function ();
5214
+ ai_reload_websites_function = null;
5215
+ }
5216
+ }
5217
+ });
5218
+ }
5219
+
5220
+ function reload_list (settings) {
5221
+ list_search_reload = false;
5222
+ var list = encodeURIComponent ($("#ai-list-search").val());
5223
+ var all = + !$("#ai-load-all").hasClass ('light-blue');
5224
+
5225
+ var rearrange_controls = $('#list-rearrange-controls');
5226
+ var rearrange = rearrange_controls.hasClass ('rearrange')
5227
+
5228
+ rearrange_controls.removeClass ('rearrange').hide ();
5229
+ $("#ai-rearrange").removeClass ('blue');
5230
+
5231
+ var rearrange_data = '';
5232
+ if (rearrange) {
5233
+ var table = $('table#ai-list-table');
5234
+ var original_blocks = table.data ('blocks');
5235
+ if (typeof original_blocks == 'undefined') original_blocks = new Array();
5236
+
5237
+ var new_blocks = new Array();
5238
+ table.find ('tbody tr').each (function (index) {
5239
+ new_blocks.push ($(this).data ('block'));
5240
+ });
5241
+
5242
+ rearrange_data = "&blocks-org=" + JSON.stringify (original_blocks) + "&blocks-new=" + JSON.stringify (new_blocks);
5243
+ }
5244
+
5245
+ var data_container = $("#ai-list-data");
5246
+ var safe_mode = Boolean (parseInt ($('#ai-data').attr ('safe-mode')));
5247
+ var safe_mode_url = safe_mode ? '&safe-mode' : '';
5248
+ var settings_data = typeof settings == 'undefined' ? '' : '&' + settings;
5249
+
5250
+ $('#ai-loading').show ();
5251
+
5252
+ data_container.load (ajaxurl+"?action=ai_ajax_backend&list=" + list + "&all=" + all + "&start=" + start + "&end=" + end + "&active=" + active_tab + rearrange_data + safe_mode_url + settings_data + "&ai_check=" + ai_nonce, function (response, status, xhr) {
5253
+ $('#ai-loading').hide ();
5254
+ if (status == "error") {
5255
+ var message = "Error downloading list data: " + xhr.status + " " + xhr.statusText;
5256
+ data_container.html (message);
5257
+ if (debug) console.log (message);
5258
+ } else {
5259
+ configure_list ();
5260
+
5261
+ if (typeof ai_reload_list_function == 'function') {
5262
+ ai_reload_list_function ();
5263
+ ai_reload_list_function = null;
5264
+ }
5265
+ if (rearrange) reload_settings ();
5266
+ }
5267
+ });
5268
+ }
5269
+
5270
+ function reload_adsense_list (update_ad_units) {
5271
+ adsense_search_reload = false;
5272
+ var list = encodeURIComponent ($("#adsense-list-search").val());
5273
+ var all = + !$("#adsense-load-all").parent ().find ('.checkbox-icon').hasClass ('on');
5274
+ // var nonce = $("#ai-form").attr ('nonce');
5275
+
5276
+ var data_container = $("#adsense-list-data");
5277
+
5278
+ data_container.load (ajaxurl+"?action=ai_ajax_backend&adsense-list=" + list + "&all=" + all + "&update_ad_units=" + (update_ad_units ? 1 : 0) + "&ai_check=" + ai_nonce, function (response, status, xhr) {
5279
+ $("#adsense-reload").parent ().find ('.checkbox-icon').removeClass ('on');
5280
+
5281
+ if (status == "error") {
5282
+ var message = "Error downloading AdSense data: " + xhr.status + " " + xhr.statusText;
5283
+ data_container.html (message);
5284
+ if (debug) console.log (message);
5285
+
5286
+
5287
+ } else {
5288
+ if ($('#adsense-client-id', data_container).length) {
5289
+ $('#adsense-list-controls').hide ();
5290
+ $('button.ai-top-button', data_container).button().show ();
5291
+
5292
+ $("#save-client-ids").click (function () {
5293
+
5294
+ var client_id = $("input#adsense-client-id").val ();
5295
+ var client_secret = $("input#adsense-client-secret").val ();
5296
+
5297
+ data_container.text (ai_admin.loading);
5298
+
5299
+ // var nonce = $("#ai-form").attr ('nonce');
5300
+
5301
+ $('#ai-loading').show ();
5302
+ $.get (ajaxurl + '?action=ai_ajax_backend&adsense-client-id=' + btoa (client_id) + '&adsense-client-secret=' + btoa (client_secret) + '&ai_check=' + ai_nonce, function (data) {
5303
+ reload_adsense_list (false);
5304
+ }).fail (function (xhr, status, error) {
5305
+ var message = "Error saving AdSense client IDs: " + xhr.status + " " + xhr.statusText ;
5306
+ console.log (message);
5307
+ })
5308
+ .always (function () {
5309
+ $('#ai-loading').hide ();
5310
+ });
5311
+ });
5312
+
5313
+ $(".authorize-adsense", data_container).click (function () {
5314
+
5315
+ $('#adsense-list-controls').show ();
5316
+ data_container.text (ai_admin.loading);
5317
+
5318
+ authorization_code = '';
5319
+ update_adsense_authorization (authorization_code);
5320
+ });
5321
+
5322
+ return;
5323
+ } else
5324
+
5325
+ if ($('#adsense-authorization-code', data_container).length) {
5326
+ $('#adsense-list-controls').hide ();
5327
+ $('button.ai-top-button', data_container).button().show ();
5328
+
5329
+ $(".authorize-adsense", data_container).click (function () {
5330
+
5331
+ var authorization_code = $("input#adsense-authorization-code").val ();
5332
+
5333
+ $('#adsense-list-controls').show ();
5334
+ data_container.text (ai_admin.loading);
5335
+
5336
+ if ($(this).hasClass ('clear-adsense')) authorization_code = '';
5337
+ if ($(this).hasClass ('own-ids')) authorization_code = 'own-ids';
5338
+
5339
+
5340
+ update_adsense_authorization (authorization_code);
5341
+ });
5342
+
5343
+ return;
5344
+ }
5345
+
5346
+ $('#adsense-list-controls').show ();
5347
+
5348
+ var publisher_id = $('#adsense-data', data_container).data ('publisher-id');
5349
+ if (typeof publisher_id == 'undefined') publisher_id = '';
5350
+
5351
+ $('label#google-adsense-button').attr ('title', ai_admin.google_adsense_homepage + ' ' + publisher_id)
5352
+ .tooltip({
5353
+ track: true,
5354
+ delay: 700,
5355
+ showURL: false,
5356
+ showBody: " | ",
5357
+ fade: 250
5358
+ });
5359
+
5360
+ $("label.adsense-copy-code").click (function () {
5361
+ var ad_slot_id = $(this).closest ('tr').data ('id');
5362
+ var ad_name = atob ($(this).closest ('tr').data ('name'));
5363
+ // var nonce = $("#ai-form").attr ('nonce');
5364
+
5365
+ if (debug) console.log ('ADSENSE CODE: ', ad_slot_id);
5366
+
5367
+ $('#ai-loading').show ();
5368
+ $.get (ajaxurl + '?action=ai_ajax_backend&adsense-code=' + ad_slot_id + '&ai_check=' + ai_nonce, function (data) {
5369
+
5370
+ var code_data = JSON.parse (data);
5371
+ var error = code_data ['error-message'];
5372
+
5373
+ if (error == '') {
5374
+ var adsense_code = code_data ['code'];
5375
+
5376
+ if (debug) console.log (adsense_code);
5377
+
5378
+ var clipboard_template = $('#ai-clipboard-template');
5379
+ var clipboard = $('#ai-clipboard');
5380
+ clipboard.html (clipboard_template.html ());
5381
+ clipboard.find ('input#name-edit-999').attr ('value', ad_name).attr ('default', ad_name);
5382
+
5383
+ clipboard.find ('textarea.simple-editor').text (adsense_code);
5384
+
5385
+ $("#ai-container .ai-copy").each (function () {
5386
+ $(this).next ("label").find ('.checkbox-icon').addClass("on");
5387
+ });
5388
+
5389
+ var tools_button = $("#tools-button-" + active_tab);
5390
+ if (!tools_button.next ('label').find ('.checkbox-icon').hasClass ("on")) {
5391
+ tools_button.click ();
5392
+ }
5393
+ } else {
5394
+ console.log ('AdSense API error:', error);
5395
+ }
5396
+ }).fail (function (xhr, status, error) {
5397
+ var message = "Error downloading AdSense code: " + xhr.status + " " + xhr.statusText ;
5398
+ console.log (message);
5399
+ })
5400
+ .always (function () {
5401
+ $('#ai-loading').hide ();
5402
+ });
5403
+
5404
+ });
5405
+
5406
+ $("label.adsense-preview-code").click (function () {
5407
+ var ad_slot_id = $(this).closest ('tr').data ('id');
5408
+ var ad_name = $(this).closest ('tr').data ('name');
5409
+
5410
+ var window_width = 820;
5411
+ var window_height = 820;
5412
+ var window_left = 100;
5413
+ var window_top = (screen.height / 2) - (820 / 2);
5414
+ // var nonce = $("#ai-form").attr ('nonce');
5415
+
5416
+ var param = {'action': 'ai_ajax_backend', 'preview': 'adsense', 'ai_check': ai_nonce, 'read_only': 1, 'slot_id': btoa (ad_slot_id), 'name': ad_name};
5417
+ open_popup_window_post (ajaxurl, 'width='+window_width+',height='+window_height+',top='+window_top+',left='+window_left+',resizable=yes,scrollbars=yes,toolbar=no,location=no,directories=no,status=no,menubar=no', 'preview', param);
5418
+ });
5419
+
5420
+ $("label.adsense-get-code").click (function () {
5421
+ var ad_slot_id = $(this).closest ('tr').data ('id');
5422
+ var ad_name = atob ($(this).closest ('tr').data ('name'));
5423
+ // var nonce = $("#ai-form").attr ('nonce');
5424
+
5425
+ if (debug) console.log ('ADSENSE CODE: ', ad_slot_id);
5426
+
5427
+ $('#ai-loading').show ();
5428
+ $.get (ajaxurl + '?action=ai_ajax_backend&adsense-code=' + ad_slot_id + '&ai_check=' + ai_nonce, function (data) {
5429
+
5430
+ var code_data = JSON.parse (data);
5431
+ var error = code_data ['error-message'];
5432
+
5433
+ if (error == '') {
5434
+ var adsense_code = code_data ['code'];
5435
+
5436
+ if (debug) console.log (adsense_code);
5437
+
5438
+ set_editor_text (active_tab, adsense_code);
5439
+ setTimeout (function() {$("#import-code-"+active_tab).click ();}, 10);
5440
+ } else {
5441
+ console.log ('AdSense API error:', error);
5442
+ }
5443
+ }).fail (function (xhr, status, error) {
5444
+ var message = "Error downloading AdSense code: " + xhr.status + " " + xhr.statusText ;
5445
+ console.log (message);
5446
+ })
5447
+ .always (function () {
5448
+ $('#ai-loading').hide ();
5449
+ });
5450
+ });
5451
+
5452
+ data_container.disableSelection();
5453
+ }
5454
+ });
5455
+ }
5456
+
5457
+ function load_ads_txt () {
5458
+ ads_txt_reload = false;
5459
+ var editor_button = $("#ads-txt-editor");
5460
+ var reload_button = $("#ads-txt-reload");
5461
+ var virtual_button = $("#ads-txt-virtual");
5462
+ var virtual = virtual_button.hasClass ('violet') ? '1' : '0';
5463
+ var view = editor_button.hasClass ('editor') ? 'text' : 'table';
5464
+ var search = encodeURIComponent ($("#ads-txt-search").val());
5465
+ var data_container = $("#ads-txt-data");
5466
+
5467
+ reload_button.addClass ('red');
5468
+
5469
+ data_container.load (ajaxurl+"?action=ai_ajax_backend&ads-txt=" + view + "&virtual=" + virtual + "&search=" + search + "&ai_check=" + ai_nonce, function (response, status, xhr) {
5470
+ reload_button.removeClass ('red');
5471
+
5472
+ if (status == "error") {
5473
+ var message = "Error loading ads.txt file: " + xhr.status + " " + xhr.statusText;
5474
+ data_container.html (message);
5475
+ if (debug) console.log (message);
5476
+ } else {
5477
+ if ($('#ads-txt-missing').length != 0) {
5478
+ view = 'text';
5479
+ editor_button.addClass ('editor');
5480
+ $('#ads-txt-search').hide ();
5481
+ }
5482
+
5483
+ switch (view) {
5484
+ case 'text':
5485
+ $('#ads-txt-search').hide ();
5486
+
5487
+ editor_button.removeClass ('dashicons-edit');
5488
+ editor_button.addClass ('dashicons-yes-alt');
5489
+ editor_button.addClass ('green');
5490
+ editor_button.attr ('title', editor_button.attr ('title-editor'))
5491
+ .tooltip({
5492
+ track: true,
5493
+ delay: 700,
5494
+ showURL: false,
5495
+ showBody: " | ",
5496
+ fade: 250
5497
+ });
5498
+
5499
+ reload_button.removeClass ('dashicons-download');
5500
+ reload_button.addClass ('dashicons-no');
5501
+
5502
+ if ($('#ads-txt-missing').length != 0) {
5503
+ reload_button.removeClass ('red');
5504
+ reload_button.attr ('title', reload_button.attr ('title-table'))
5505
+ .tooltip({
5506
+ track: true,
5507
+ delay: 700,
5508
+ showURL: false,
5509
+ showBody: " | ",
5510
+ fade: 250
5511
+ });
5512
+ } else {
5513
+ reload_button.addClass ('red');
5514
+ reload_button.attr ('title', reload_button.attr ('title-editor'))
5515
+ .tooltip({
5516
+ track: true,
5517
+ delay: 700,
5518
+ showURL: false,
5519
+ showBody: " | ",
5520
+ fade: 250
5521
+ });
5522
+ }
5523
+ break;
5524
+ case 'table':
5525
+ editor_button.removeClass ('dashicons-yes-alt');
5526
+ editor_button.removeClass ('green');
5527
+ editor_button.addClass ('dashicons-edit');
5528
+ editor_button.attr ('title', editor_button.attr ('title-table'))
5529
+ .tooltip({
5530
+ track: true,
5531
+ delay: 700,
5532
+ showURL: false,
5533
+ showBody: " | ",
5534
+ fade: 250
5535
+ });
5536
+
5537
+ reload_button.removeClass ('dashicons-no');
5538
+ reload_button.removeClass ('red');
5539
+ reload_button.addClass ('dashicons-download');
5540
+ reload_button.attr ('title', reload_button.attr ('title-table'))
5541
+ .tooltip({
5542
+ track: true,
5543
+ delay: 700,
5544
+ showURL: false,
5545
+ showBody: " | ",
5546
+ fade: 250
5547
+ });
5548
+ break;
5549
+ }
5550
+
5551
+ $('#ads-txt-controls').show ();
5552
+ }
5553
+ });
5554
+ }
5555
+
5556
+ function save_ads_txt (reload) {
5557
+ var data_container = $("#ads-txt-data");
5558
+ var editor_button = $("#ads-txt-editor");
5559
+ var reload_button = $("#ads-txt-reload");
5560
+ var virtual_button = $("#ads-txt-virtual");
5561
+ var virtual = virtual_button.hasClass ('violet') ? '1' : '0';
5562
+ var ads_txt_data = {'text': b64e (data_container.find ('textarea#ads-txt-text').val ())};
5563
+
5564
+ $('#ads-txt-error').text ('');
5565
+
5566
+ editor_button.removeClass ('green');
5567
+ editor_button.addClass ('red');
5568
+
5569
+ $.post (ajaxurl+"?action=ai_ajax_backend&ads-txt=save" + "&virtual=" + virtual + "&ai_check=" + ai_nonce, ads_txt_data
5570
+ ).done (function (code_data) {
5571
+ }).fail (function (xhr, status, error) {
5572
+ editor_button.removeClass ('red');
5573
+ editor_button.addClass ('green');
5574
+
5575
+ var message = "Error saving ads.txt file: " + xhr.status + " " + xhr.statusText;
5576
+ $('#ads-txt-error').text (message);
5577
+ if (debug) console.log (message);
5578
+ }).always (function() {
5579
+ editor_button.removeClass ('editor');
5580
+
5581
+ editor_button.removeClass ('green');
5582
+ editor_button.removeClass ('red');
5583
+ editor_button.removeClass ('dashicons-yes-alt');
5584
+ editor_button.addClass ('dashicons-edit');
5585
+ editor_button.attr ('title', editor_button.attr ('title-editor'))
5586
+ .tooltip({
5587
+ track: true,
5588
+ delay: 700,
5589
+ showURL: false,
5590
+ showBody: " | ",
5591
+ fade: 250
5592
+ });
5593
+
5594
+ reload_button.addClass ('dashicons-download');
5595
+ reload_button.removeClass ('dashicons-no');
5596
+ reload_button.removeClass ('red');
5597
+ reload_button.attr ('title', reload_button.attr ('title-editor'))
5598
+ .tooltip({
5599
+ track: true,
5600
+ delay: 700,
5601
+ showURL: false,
5602
+ showBody: " | ",
5603
+ fade: 250
5604
+ });
5605
+
5606
+ $('#ads-txt-search').show ();
5607
+
5608
+ if (reload) {
5609
+ setTimeout (function() {load_ads_txt ();}, 100);
5610
+ }
5611
+ });
5612
+ }
5613
+
5614
+ function set_page_statuses (block) {
5615
+ var automatic_insertion = parseInt ($("select#insertion-type-"+block+" option:selected").attr('value'));
5616
+ var table = $('#page-types-' + block);
5617
+
5618
+ switch (automatic_insertion) {
5619
+ case AI_BEFORE_HTML_ELEMENT:
5620
+ case AI_AFTER_HTML_ELEMENT:
5621
+ case AI_INSIDE_HTML_ELEMENT:
5622
+ table.find ('td.ai-page-type').removeClass ('ai-unavailable');
5623
+ return;
5624
+ }
5625
+
5626
+ var pages = ['po', 'pa', 'hp', 'cp', 'ap', 'sp'];
5627
+
5628
+ pages.forEach (function (page, index) {
5629
+ var positions = $('table.check-pages').attr ('data-positions-' + page);
5630
+
5631
+ if (positions != null) {
5632
+ var available_insertions = JSON.parse (positions);
5633
+
5634
+ if (available_insertions.indexOf (automatic_insertion) != - 1) {
5635
+ table.find ('td.ai-page-type.ai-' + page).removeClass ('ai-unavailable').find ('input, label').removeAttr ('title')
5636
+ .tooltip({
5637
+ track: true,
5638
+ delay: 700,
5639
+ showURL: false,
5640
+ showBody: " | ",
5641
+ fade: 250
5642
+ });
5643
+ } else {
5644
+ table.find ('td.ai-page-type.ai-' + page).addClass ('ai-unavailable').find ('input, label').attr ('title', ai_admin.position_might_not_available)
5645
+ .tooltip({
5646
+ track: true,
5647
+ delay: 700,
5648
+ showURL: false,
5649
+ showBody: " | ",
5650
+ fade: 250
5651
+ });
5652
+ }
5653
+ }
5654
+ });
5655
+ }
5656
+
5657
+ function check_page (page, button, last_check) {
5658
+ // var nonce = $("#ai-form").attr ('nonce');
5659
+ var container = button.closest ('.ai-check-pages');
5660
+ var error_message = container.find ('.ai-error-message');
5661
+
5662
+ $.get (ajaxurl + '?action=ai_ajax_backend&check-page=' + page + '&ai_check=' + ai_nonce, function (data) {
5663
+ if (data != '') {
5664
+
5665
+ if (debug) console.log ("AI CHECK PAGES:", data);
5666
+
5667
+ try {
5668
+ var pages_data = JSON.parse (data);
5669
+ var positions = pages_data ['positions'];
5670
+ var urls = pages_data ['urls'];
5671
+
5672
+ if (debug) console.log ("AI CHECK PAGES positions:", positions);
5673
+ if (debug) console.log ("AI CHECK PAGES urls:", urls);
5674
+
5675
+ $('table.check-pages').attr ('data-positions-' + page, JSON.stringify (positions));
5676
+ $('table.check-pages').attr ('data-urls-' + page, JSON.stringify (urls));
5677
+
5678
+ $('table.check-pages td.ai-position.ai-' + page).each (function () {
5679
+ $(this).removeClass ('ai-not-checked');
5680
+ var insertion = $(this).data ('insertion');
5681
+
5682
+ if (positions.indexOf (insertion) == - 1) {
5683
+ $(this).addClass ('ai-no').attr ('title', ai_admin.position_not_available);
5684
+ } else {
5685
+ $(this).addClass ('ai-yes').attr ('title', ai_admin.position_available);
5686
+ }
5687
+ $(this).tooltip({
5688
+ track: true,
5689
+ delay: 700,
5690
+ showURL: false,
5691
+ showBody: " | ",
5692
+ fade: 250
5693
+ });
5694
+ });
5695
+
5696
+ if (urls != null && urls.length != 0) {
5697
+ $('table.check-pages a.ai-' + page).each (function (index, value) {
5698
+ if (typeof urls [index] != 'undefined') {
5699
+ $(this).attr ('href', urls [index]).show ();
5700
+ }
5701
+ });
5702
+ }
5703
+ } catch (error) {
5704
+ // error_message.find ('.ai-error-message-text').text ('JSON error');
5705
+ error_message.find ('.ai-error-message-text').text (data);
5706
+ error_message.show ();
5707
+ console.log ("AI CHECK PAGES: JSON error decoding available positions: " + data);
5708
+ }
5709
+ }
5710
+ }).fail (function (xhr, status, error) {
5711
+ error_message.find ('.ai-error-message-text').text (xhr.status + " " + xhr.statusText);
5712
+ error_message.show ();
5713
+ console.log ('AI CHECK PAGES: Error loading positions for', page + ':', xhr.status, xhr.statusText);
5714
+ })
5715
+ .always (function () {
5716
+ if (last_check) {
5717
+ $('#ai-loading').hide ();
5718
+ $('#ai-loading-2').hide ();
5719
+ button.find ('span.ui-button-text').removeClass ('on');
5720
+
5721
+ for (var block = start; block <= end; block ++) {
5722
+ set_page_statuses (block);
5723
+ }
5724
+ }
5725
+ });
5726
+ }
5727
+
5728
+ function configure_tabs () {
5729
+
5730
+ var tabs_array = new Array ();
5731
+
5732
+ if (ai_tab_setup_delay != 0) {
5733
+ if (active_tab != 0) tabs_array.push (0);
5734
+ for (var tab = end; tab >= start; tab --) {
5735
+ if (tab != active_tab) tabs_array.push (tab);
5736
+ }
5737
+ }
5738
+
5739
+ // Concatenate existing tabs_to_configure (if tab was clicked before page was loaded)
5740
+ tabs_to_configure = tabs_array.concat (tabs_to_configure);
5741
+
5742
+ // setTimeout (configure_hidden_tab, 700);
5743
+ if (ai_tab_setup_delay != 0) {
5744
+ setTimeout (configure_hidden_tab, 3 * ai_tab_setup_delay);
5745
+ }
5746
+
5747
+ var index = 16;
5748
+ if (active_tab != 0) index = active_tab - start;
5749
+ var block_tabs = $("#ai-tab-container").tabs ({active: index});
5750
+ $("#ai-plugin-settings-tab-container").tabs ({active: active_tab_0});
5751
+
5752
+ // $('#ai-settings').tooltip({
5753
+ // show: {effect: "blind",
5754
+ // delay: 400,
5755
+ // duration: 100}
5756
+ // });
5757
+
5758
+ if (debug_title) $("#plugin_name").css ("color", "#00f");
5759
+
5760
+ if (active_tab == 0) configure_tab_0 (); else configure_tab (active_tab);
5761
+
5762
+ $('#dummy-tabs').hide();
5763
+ $('#ai-tabs').show();
5764
+
5765
+ // $('.ai-tab').click (function () {
5766
+ // var tab_block = $(this).attr ("id");
5767
+ // tab_block = parseInt (tab_block.replace ("ai-tab",""));
5768
+ // active_tab = tab_block;
5769
+
5770
+ // highlight_active_block ();
5771
+
5772
+ // if (debug) console.log ("$('.ai-tab').click", active_tab);
5773
+
5774
+ // if (!$("#tab-" + tab_block).hasClass ('configured')) {
5775
+ // if (debug) console.log ("");
5776
+ // if (debug) console.log ("Empty tab: " + tab_block);
5777
+ // tabs_to_configure.push (tab_block);
5778
+ // setTimeout (configure_hidden_tab, 10);
5779
+ // if (debug) console.log ("tabs_to_configure: " + tabs_to_configure);
5780
+ // } else if (tab_block != 0) {
5781
+ // if (syntax_highlighting) {
5782
+ // var editor = ace.edit ("editor-" + tab_block);
5783
+ // editor.getSession ().highlightLines (10000000);
5784
+ // }
5785
+ // }
5786
+ // });
5787
+
5788
+ $('#ai-tab-container').on ('tabsbeforeactivate', function (event, ui) {
5789
+ var tab_block = ui.newTab.attr ("id");
5790
+
5791
+ if (!tab_block.includes ('ai-tab')) return;
5792
+
5793
+ tab_block = parseInt (tab_block.replace ("ai-tab",""));
5794
+ active_tab = tab_block;
5795
+
5796
+ if (debug) console.log ("on tabsbeforeactivate", active_tab);
5797
+
5798
+ check_and_configure_active_tab ();
5799
+
5800
+ // highlight_active_block ();
5801
+
5802
+ // if (!$("#tab-" + tab_block).hasClass ('configured')) {
5803
+ // if (debug) console.log ("");
5804
+ // if (debug) console.log ("Empty tab: " + tab_block);
5805
+ // tabs_to_configure.push (tab_block);
5806
+ // setTimeout (configure_hidden_tab, 10);
5807
+ // if (debug) console.log ("tabs_to_configure: " + tabs_to_configure);
5808
+ // } else if (tab_block != 0) {
5809
+ // if (syntax_highlighting) {
5810
+ // var editor = ace.edit ("editor-" + tab_block);
5811
+ // editor.getSession ().highlightLines (10000000);
5812
+ // }
5813
+ // }
5814
+ });
5815
+
5816
+ $('.ai-plugin-tab').click (function () {
5817
+ active_tab_0 = $("#ai-plugin-settings-tab-container").tabs ('option', 'active');
5818
+ if (debug) console.log ("active_tab_0: " + active_tab_0);
5819
+
5820
+ if (syntax_highlighting) {
5821
+ var tab_block = $(this).attr ("id");
5822
+ tab_block = tab_block.replace ("ai-","");
5823
+
5824
+ if (tab_block == 'h') {
5825
+ var editor = ace.edit ("editor-h");
5826
+ editor.getSession ().highlightLines (10000000);
5827
+ } else
5828
+ if (tab_block == 'f') {
5829
+ editor = ace.edit ("editor-f");
5830
+ editor.getSession ().highlightLines (10000000);
5831
+ } else
5832
+ if (tab_block == 'a') {
5833
+ editor = ace.edit ("editor-a");
5834
+ editor.getSession ().highlightLines (10000000);
5835
+ }
5836
+ }
5837
+ });
5838
+
5839
+ $("#check-pages-button").button ({
5840
+ }).show ().click (function () {
5841
+ var button = $(this);
5842
+ var container = $(this).closest ('.ai-check-pages');
5843
+ var error_message = container.find ('.ai-error-message');
5844
+
5845
+ $('#ai-loading').show ();
5846
+ $('#ai-loading-2').show ();
5847
+ error_message.hide ();
5848
+ button.find ('span.ui-button-text').addClass ('on');
5849
+
5850
+ $('table.check-pages a').removeAttr ('href').hide ();
5851
+
5852
+ var pages = ['po', 'pa', 'hp', 'cp', 'ap', 'sp'];
5853
+
5854
+ pages.forEach (function (page, index) {
5855
+ $('table.check-pages td.ai-position').each (function () {
5856
+ $(this).removeClass ('ai-yes').removeClass ('ai-no').addClass ('ai-not-checked').attr ('title', ai_admin.position_not_checked);
5857
+ $(this).tooltip({
5858
+ track: true,
5859
+ delay: 700,
5860
+ showURL: false,
5861
+ showBody: " | ",
5862
+ fade: 250
5863
+ });
5864
+ });
5865
+
5866
+ $('table.ai-page-types td.ai-page-type').each (function () {
5867
+ $(this).removeClass ('ai-unavailable');
5868
+ });
5869
+
5870
+ setTimeout (function() {check_page (page, button, index == pages.length - 1);}, index * 300 + 10);
5871
+ });
5872
+ });
5873
+ }
5874
+
5875
+
5876
+ function reload_settings () {
5877
+ if (debug) console.log ('RELOAD SETTINGS');
5878
+
5879
+ var settings_container = $("#ai-container");
5880
+
5881
+ $('#ai-error-container').hide ();
5882
+ if (debug_title) $("#plugin_name").css ("color", "#f00");
5883
+
5884
+ $('#ai-loading').show ();
5885
+
5886
+ var tools = $('#ai-tools-toolbar-' + active_tab).is (':visible');
5887
+ var simple_editor = $('#simple-editor-' + active_tab).is(":checked");
5888
+ var copy = $("#copy-block-" + active_tab).next ("label").find ('.checkbox-icon').hasClass("on");
5889
+
5890
+ settings_container.load (ajaxurl+"?action=ai_ajax_backend&settings=" + active_tab + "&ai_check=" + ai_nonce, function (response, status, xhr) {
5891
+ if (status == "error") {
5892
+ $('#ai-loading').hide ();
5893
+ var message = ai_admin.error_reloading_settings + ": " + xhr.status + " " + xhr.statusText;
5894
+ $('#ai-error-container').text (message).show ();
5895
+ if (debug) console.log (message);
5896
+ } else {
5897
+ if (debug) console.log (' Configuring...');
5898
+
5899
+ if (debug) {
5900
+ start_time = new Date().getTime();
5901
+ last_time = start_time;
5902
+ }
5903
+
5904
+ configure_tabs ();
5905
+
5906
+ if (simple_editor) $('#simple-editor-' + active_tab).click ();
5907
+
5908
+ if (tools) $('#tools-button-' + active_tab).click ();
5909
+
5910
+ if (copy) {
5911
+ $("#ai-container .ai-copy").each (function () {
5912
+ $(this).next ("label").find ('.checkbox-icon').addClass("on");
5913
+ });
5914
+ }
5915
+
5916
+ if (debug) console.log (' Configured');
5917
+ $('#ai-loading').hide ();
5918
+ }
5919
+ });
5920
+ }
5921
+
5922
+ function update_adsense_authorization (authorization_code) {
5923
+ // var nonce = $("#ai-form").attr ('nonce');
5924
+
5925
+ $('#ai-loading').show ();
5926
+ $.get (ajaxurl + '?action=ai_ajax_backend&adsense-authorization-code=' + btoa (authorization_code) + '&ai_check=' + ai_nonce, function (data) {
5927
+ reload_adsense_list (false);
5928
+ }).fail (function (xhr, status, error) {
5929
+ var message = "Error saving AdSense authorization: " + xhr.status + " " + xhr.statusText ;
5930
+ console.log (message);
5931
+ })
5932
+ .always (function () {
5933
+ $('#ai-loading').hide ();
5934
+ });
5935
+ }
5936
+
5937
+ function toggle_adsense_list () {
5938
+ var container = $("#adsense-list-container");
5939
+ container.toggle ();
5940
+
5941
+ if (container.is(':visible')) {
5942
+ $(".checkbox-icon.icon-adsense").addClass ('on');
5943
+ reload_adsense_list (false);
5944
+ } else {
5945
+ $(".checkbox-icon.icon-adsense").removeClass ('on');
5946
+ }
5947
+ }
5948
+
5949
+ function update_block_code_demo () {
5950
+ // var nonce = $("#ai-form").attr ('nonce');
5951
+
5952
+ var block_class_name = encodeURIComponent ($('#block-class-name').val ());
5953
+ var block_class = $('#block-class').is(":checked") ? 1 : 0;
5954
+ var block_number_class = $('#block-number-class').is(":checked") ? 1 : 0;
5955
+ var block_name_class = $('#block-name-class').is(":checked") ? 1 : 0;
5956
+ var inline_styles = $('#inline-styles').is(":checked") ? 1 : 0;
5957
+
5958
+ $.get (ajaxurl + '?action=ai_ajax_backend&update=block-code-demo&block_class_name=' + block_class_name + '&block_class=' + block_class + '&block_number_class=' + block_number_class + '&block_name_class=' + block_name_class + '&inline_styles=' + inline_styles + '&ai_check=' + ai_nonce, function (data) {
5959
+ $('span#ai-block-code-demo').html (data);
5960
+ }).fail (function (xhr, status, error) {
5961
+ var message = "Error updating block code demo: " + xhr.status + " " + xhr.statusText ;
5962
+ console.log (message);
5963
+ });
5964
+ }
5965
+
5966
+ if (debug) console.log ("READY");
5967
+ if (debug_title) $("#plugin_name").css ("color", "#f00");
5968
+ if (debug) {
5969
+ var current_time_ready = new Date().getTime();
5970
+ console.log ("TIME: " + ((current_time_ready - start_time) / 1000).toFixed (3));
5971
+ }
5972
+
5973
+ $("#blocked-warning").removeClass ('warning-enabled');
5974
+ $("#blocked-warning").hide ();
5975
+
5976
+ start = parseInt ($('#ai-form').attr('start'));
5977
+ end = parseInt ($('#ai-form').attr('end'));
5978
+
5979
+ active_tab = start;
5980
+ active_tab_0 = 0;
5981
+ try {
5982
+ var active_tabs = JSON.parse ($("#ai-active-tab").attr ("value"));
5983
+ if (typeof active_tabs !== "undefined" && active_tabs.constructor === Array && Number.isInteger (active_tabs [0]) && Number.isInteger (active_tabs [1])) {
5984
+ active_tab = parseInt (active_tabs [0]);
5985
+ if (active_tab != 0)
5986
+ if (active_tab < start || active_tab > end) active_tab = start;
5987
+ active_tab_0 = parseInt (active_tabs [1]);
5988
+ }
5989
+ } catch (e) {}
5990
+
5991
+ if (debug) console.log ("active_tabs:", active_tab, active_tab_0);
5992
+
5993
+ var plugin_version = $('#ai-data').attr ('version').split ('-') [0];
5994
+ if (javascript_version != plugin_version) {
5995
+ console.log ('AD INSERTER: plugin version: ' + plugin_version + ', loaded JavaScript version: ' + javascript_version);
5996
+
5997
+ // Check page HTML
5998
+ var javascript_version_parameter = $("script[src*='ad-inserter.js']").attr('src');
5999
+ if (typeof javascript_version_parameter == 'undefined') $("#javascript-version-parameter-missing").show (); else {
6000
+ javascript_version_parameter_string = javascript_version_parameter.split('=')[1];
6001
+ if (typeof javascript_version_parameter_string == 'undefined') {
6002
+ $("#javascript-version-parameter-missing").show ();
6003
+ }
6004
+ else if (javascript_version_parameter_string != plugin_version) {
6005
+ console.log ('AD INSERTER: plugin version: ' + plugin_version + ', JavaScript file version: ' + javascript_version_parameter_string);
6006
+ $("#javascript-version-parameter").show ();
6007
+ }
6008
+ }
6009
+
6010
+ $("#javascript-version").html ("Javascript<br />" + javascript_version);
6011
+ $("#javascript-warning").show ();
6012
+ }
6013
+
6014
+ var css_version = $('#ai-data').css ('font-family').replace(/[\"\']/g, '');
6015
+ if (css_version.indexOf ('.') == - 1) $("#blocked-warning").show (); else
6016
+ if (css_version != plugin_version) {
6017
+ console.log ('AD INSERTER: plugin version:', plugin_version + ', loaded CSS version:', css_version);
6018
+
6019
+ // Check page HTML
6020
+ var css_version_parameter = $("link[href*='ai-settings.css']").attr('href');
6021
+ if (typeof css_version_parameter == 'undefined') $("#css-version-parameter-missing").show (); else {
6022
+ css_version_parameter_string = css_version_parameter.split('=')[1];
6023
+ if (typeof css_version_parameter_string == 'undefined') {
6024
+ $("#css-version-parameter-missing").show ();
6025
+ }
6026
+ else if (css_version_parameter_string != plugin_version) {
6027
+ console.log ('AD INSERTER: plugin version:', plugin_version + ', CSS file version:', css_version_parameter_string);
6028
+ $("#css-version-parameter").show ();
6029
+ }
6030
+ }
6031
+
6032
+ $("#css-version").html ("CSS<br />" + css_version);
6033
+ $("#css-warning").show ();
6034
+ }
6035
+
6036
+ $('.header button').button().show ();
6037
+
6038
+ $("#ai-form").submit (function (event) {
6039
+ for (var tab = start; tab <= end; tab ++) {
6040
+ var rotation_button = $('#rotation-' + tab);
6041
+ if (rotation_button.parent ().find ('.icon-rotation').hasClass ('on')) {
6042
+ event.preventDefault();
6043
+
6044
+ $("#ai-tab-container").tabs ({active: tab - 1});
6045
+
6046
+ var message = '<div class="checkbox-icon icon-rotation on" style="margin: 3px 10px 24px 0px;"></div><div>' + ai_admin.rotation_active + '</div>';
6047
+ $('<div />').html(message).attr ('title', ai_admin.warning).dialog({
6048
+ bgiframe: true,
6049
+ draggable: false,
6050
+ resizable: false,
6051
+ modal: true,
6052
+ height: "auto",
6053
+ width: 300,
6054
+ position: {my: 'center', at: 'center', of: '#ai-settings'},
6055
+ buttons: [{
6056
+ text: ai_admin.ok,
6057
+ click: function() {
6058
+ $(this).dialog ("close");
6059
+ }
6060
+ }
6061
+ ],
6062
+ });
6063
+
6064
+ return;
6065
+ }
6066
+ }
6067
+
6068
+ for (var tab = start; tab <= end; tab ++) {
6069
+ remove_default_values (tab);
6070
+ encode_code (tab);
6071
+ }
6072
+
6073
+ remove_default_values (0);
6074
+ encode_code ('h');
6075
+ encode_code ('f');
6076
+ encode_code ('a');
6077
+ });
6078
+
6079
+ $("div#tab-999").attr ('id', 'ai-clipboard-template').insertBefore ("#ai-clipboard");
6080
+
6081
+ configure_tabs ();
6082
+
6083
+ $('#plugin_name').dblclick (function () {
6084
+ $(".system-debugging").toggle();
6085
+ });
6086
+
6087
+ $('#ai-stars').click (function () {
6088
+ if ($("#rating-value span").text () != '') {
6089
+ $("#ai-rating-bar").css ('display', 'inline-block');
6090
+ $('#ai-stars').hide ();
6091
+ }
6092
+ update_rating ('update', '');
6093
+ });
6094
+
6095
+ $("#ai-rating-bar").click (function () {
6096
+ $("#ai-rating-bar").hide ();
6097
+ $('#ai-stars').show ();
6098
+ });
6099
+
6100
+ $("#adsense-list").click (function () {
6101
+ // $(this).blur ();
6102
+
6103
+ toggle_adsense_list ();
6104
+ });
6105
+
6106
+ $("#ai-ads-txt").click (function () {
6107
+ $(this).blur ();
6108
+
6109
+ var container = $("#ads-txt-container");
6110
+
6111
+ container.toggle ();
6112
+
6113
+ if (container.is(':visible')) {
6114
+ $("#ai-ads-txt .checkbox-icon.icon-ads-txt").addClass ('on');
6115
+ load_ads_txt ();
6116
+ } else {
6117
+ $("#ai-ads-txt .checkbox-icon.icon-ads-txt").removeClass ('on');
6118
+ }
6119
+ });
6120
+
6121
+ $("#page-checker-button").click (function () {
6122
+ $("#page-checker-container").toggle ();
6123
+
6124
+ if ($("#page-checker-container").is(':visible')) {
6125
+ $(".page-checker-button").addClass ('blue');
6126
+ $("#page-checker-button").addClass ('blue');
6127
+ } else {
6128
+ $(".page-checker-button").removeClass ('blue');
6129
+ $("#page-checker-button").removeClass ('blue');
6130
+ }
6131
+ });
6132
+
6133
+ $("#ai-manage-websites").click (function () {
6134
+ $("#ai-manage-websites-container").toggle ();
6135
+ $("#ai-manage-websites").toggleClass ('blue');
6136
+
6137
+ $("#ai-cancel-websites").hide ();
6138
+ $("#ai-save-websites").hide ();
6139
+ $("#ai-rearrange-websites").removeClass ('blue');
6140
+
6141
+ if ($("#ai-manage-websites-container").is(':visible')) {
6142
+ reload_websites ();
6143
+ }
6144
+ });
6145
+
6146
+ $("#ai-website-list-search").keyup (function (event) {
6147
+ if (!website_list_search_reload) {
6148
+ website_list_search_reload = true;
6149
+ setTimeout (reload_websites, 200);
6150
+ }
6151
+ });
6152
+
6153
+ $("#ai-list").click (function () {
6154
+
6155
+ $("#ai-list").toggleClass ('blue');
6156
+
6157
+ var container = $("#ai-list-container");
6158
+ var list_sticky = $("#ai-pin-list").hasClass ('on');
6159
+
6160
+ if (!list_sticky && ($("#ai-list").hasClass ('blue') != container.is(':visible'))) {
6161
+ container.toggle ();
6162
+ }
6163
+
6164
+ if (container.is(':visible')) {
6165
+ reload_list ();
6166
+ }
6167
+
6168
+ if ($("#ai-list").hasClass ('blue')) {
6169
+ $("#plugin_name").hide ();
6170
+ $("#block-ranges").show ();
6171
+ } else {
6172
+ $("#plugin_name").show ();
6173
+ $("#block-ranges").hide ();
6174
+ }
6175
+ });
6176
+
6177
+ $("#ai-list-search").keyup (function (event) {
6178
+ if (!list_search_reload) {
6179
+ list_search_reload = true;
6180
+ setTimeout (reload_list, 200);
6181
+ }
6182
+ });
6183
+
6184
+ $("#ai-load-all").click (function () {
6185
+ $(this).toggleClass ('light-blue');
6186
+ reload_list ();
6187
+ });
6188
+
6189
+ $("#ai-rearrange").click (function () {
6190
+ $(this).toggleClass ('blue');
6191
+
6192
+ var data_container = $("#ai-list-data");
6193
+ var rearrange_controls = $('#list-rearrange-controls');
6194
+ if ($(this).hasClass ('blue')) {
6195
+ $("#ai-rearrange").attr ('title', ai_admin.cancel_rearrangement)
6196
+ .tooltip({
6197
+ track: true,
6198
+ delay: 700,
6199
+ showURL: false,
6200
+ showBody: " | ",
6201
+ fade: 250
6202
+ });
6203
+
6204
+ rearrange_controls.show ();
6205
+ data_container.find ('tbody').sortable ({
6206
+ start: function (event, ui) {$('#list-save').show ();},
6207
+ placeholder: "ui-state-highlight"
6208
+ }).css ('cursor', 'move');
6209
+ } else {
6210
+ data_container.find ('tbody').sortable ("disable");
6211
+ $("#ai-rearrange").attr ('title', ai_admin.rearrange_block_order)
6212
+ .tooltip({
6213
+ track: true,
6214
+ delay: 700,
6215
+ showURL: false,
6216
+ showBody: " | ",
6217
+ fade: 250
6218
+ });
6219
+
6220
+ $('#list-save').hide ();
6221
+ rearrange_controls.hide ();
6222
+ reload_list ();
6223
+ }
6224
+ });
6225
+
6226
+ $("#ai-save-changes").click (function () {
6227
+ $('#list-rearrange-controls').addClass ('rearrange')
6228
+ reload_list ();
6229
+ });
6230
+
6231
+ $("#ai-pin-list").click (function () {
6232
+ $(this).toggleClass ('on');
6233
+
6234
+ var sticky = $(this).hasClass ('on') ? '1' : '0';
6235
+
6236
+ if (!$("#ai-list").hasClass ('blue')) {
6237
+ $("#ai-list-container").toggle ();
6238
+ }
6239
+
6240
+ $.get (ajaxurl+"?action=ai_ajax_backend&blocks-sticky=" + sticky + "&start=" + start + "&end=" + end + '&ai_check=' + ai_nonce, function (response, status, xhr) {
6241
+ if (status == "error") {
6242
+ var message = "Error updating sticky: " + xhr.status + " " + xhr.statusText;
6243
+ var data_container = $("#ai-list-data");
6244
+ data_container.html (message);
6245
+ if (debug) console.log (message);
6246
+ } else {
6247
+ if (debug) console.log ('AI blocks sticky:', response);
6248
+ }
6249
+ });
6250
+ });
6251
+
6252
+ if ($("#maxmind-db-status").hasClass ('maxmind-db-missing')) {
6253
+ var page = ajaxurl+"?action=ai_ajax_backend&update=maxmind&ai_check=" + ai_nonce;
6254
+
6255
+ $("span.maxmind-db-missing").text (ai_admin.downloading);
6256
+ $.get (page, function (update_status) {
6257
+
6258
+ if (update_status == '') {
6259
+ $("span.maxmind-db-missing").closest ('.notice.notice-error').hide ();
6260
+ $("#maxmind-db-status").text ('');
6261
+ } else {
6262
+ if (debug) console.log (update_status);
6263
+ var status = JSON.parse (update_status);
6264
+ if (debug) console.log (status);
6265
+ if (typeof status !== "undefined") {
6266
+ $(".notice span.maxmind-db-missing").text (status [0]);
6267
+ $("#maxmind-db-status").text (status [1]);
6268
+ } else $("span.maxmind-db-missing").text (ai_admin.update_error);
6269
+ }
6270
+ }).fail (function(jqXHR, status, err) {
6271
+ $("span.maxmind-db-missing").text (ai_admin.download_error);
6272
+ });
6273
+ }
6274
+
6275
+ $("#adsense-load-all").click (function () {
6276
+ $(this).parent ().find ('.checkbox-icon').toggleClass ('on');
6277
+ reload_adsense_list (false);
6278
+ });
6279
+
6280
+ $("#adsense-list-search").keyup (function (event) {
6281
+ if (!adsense_search_reload) {
6282
+ adsense_search_reload = true;
6283
+ setTimeout (function() {reload_adsense_list (false);}, 200);
6284
+ }
6285
+ });
6286
+
6287
+ $("#adsense-reload").click (function () {
6288
+ $(this).parent ().find ('.checkbox-icon').addClass ('on');
6289
+ setTimeout (function() {reload_adsense_list (true);}, 200);
6290
+ });
6291
+
6292
+ $("#clear-adsense-authorization").click (function () {
6293
+ $("#adsense-list-data").text (ai_admin.updating);
6294
+ update_adsense_authorization ('');
6295
+ });
6296
+
6297
+ $('.ai-block-code-demo').change (function () {
6298
+ update_block_code_demo ();
6299
+ }).on('input',function(e){
6300
+ update_block_code_demo ();
6301
+ });
6302
+
6303
+ setTimeout (function() {update_rating ('');}, 1000);
6304
+
6305
+ $("#license-key").dblclick (function () {
6306
+ $("#hide-key").toggle ();
6307
+ });
6308
+
6309
+ $('input[title], button[title], label[title], h2[title], li[title], td[title], select[title], div[title], span[title]').tooltip({
6310
+ track: true,
6311
+ delay: 700,
6312
+ showURL: false,
6313
+ showBody: " | ",
6314
+ fade: 250
6315
+ });
6316
+
6317
+ if (debug) console.log ("");
6318
+ if (debug) console.log ("READY END");
6319
+ if (debug) {
6320
+ var current_time = new Date().getTime();
6321
+ console.log ("main time: " + ((current_time - current_time_ready) / 1000).toFixed (3));
6322
+ }
6323
+
6324
+ $("#ads-txt-virtual").click (function () {
6325
+
6326
+ function switch_to_physical () {
6327
+ var virtual_button = $("#ads-txt-virtual");
6328
+ virtual_button.removeClass ('violet');
6329
+ virtual_button.attr ('title', virtual_button.attr ('title-physical'))
6330
+ .tooltip({
6331
+ track: true,
6332
+ delay: 700,
6333
+ showURL: false,
6334
+ showBody: " | ",
6335
+ fade: 250
6336
+ });
6337
+ setTimeout (function() {load_ads_txt ();}, 50);
6338
+
6339
+ }
6340
+ var editor_button = $("#ads-txt-editor");
6341
+ var view = editor_button.hasClass ('editor') ? 'text' : 'table';
6342
+ var virtual_button = $("#ads-txt-virtual");
6343
+
6344
+ if (virtual_button.hasClass ('violet')) {
6345
+ var message = ai_admin.switch_to_physical_ads_txt;
6346
+ var ads_txt_data = $("#ads-txt-data").find ('textarea#ads-txt-text').val ();
6347
+ var ads_txt_missing = $('#ads-txt-missing').length != 0;
6348
+
6349
+ if (!ads_txt_missing && (view == 'table' || ads_txt_data != '')) {
6350
+ $('<div />').html(message).attr ('title', ai_admin.warning).dialog({
6351
+ bgiframe: true,
6352
+ draggable: false,
6353
+ resizable: false,
6354
+ modal: true,
6355
+ height: "auto",
6356
+ width: 400,
6357
+ position: {my: 'center', at: 'center', of: '#ads-txt-container'},
6358
+ buttons: [{
6359
+ text: ai_admin.switch,
6360
+ click: function() {
6361
+ $(this).dialog ("close");
6362
+
6363
+ switch_to_physical ();
6364
+ }
6365
+ },{
6366
+ text: ai_admin.cancel,
6367
+ click: function() {
6368
+ $(this).dialog ("close");
6369
+ }
6370
+ }
6371
+ ],
6372
+ });
6373
+ } else switch_to_physical ();
6374
+ } else {
6375
+ virtual_button.addClass ('violet');
6376
+ virtual_button.attr ('title', virtual_button.attr ('title-virtual'))
6377
+ .tooltip({
6378
+ track: true,
6379
+ delay: 700,
6380
+ showURL: false,
6381
+ showBody: " | ",
6382
+ fade: 250
6383
+ });
6384
+ setTimeout (function() {load_ads_txt ();}, 50);
6385
+ }
6386
+
6387
+ });
6388
+
6389
+ $("#ads-txt-reload").click (function () {
6390
+ var editor_button = $("#ads-txt-editor");
6391
+ if (editor_button.hasClass ('editor')) {
6392
+ editor_button.removeClass ('editor');
6393
+ }
6394
+ setTimeout (function() {load_ads_txt ();}, 50);
6395
+ });
6396
+
6397
+ $("#ads-txt-editor").click (function () {
6398
+ if ($(this).hasClass ('editor')) {
6399
+ setTimeout (function() {save_ads_txt (true);}, 50);
6400
+ } else {
6401
+ $(this).addClass ('editor');
6402
+
6403
+ setTimeout (function() {load_ads_txt ();}, 50);
6404
+
6405
+ $(this).attr ('title', $(this).attr ('title-table'))
6406
+ .tooltip({
6407
+ track: true,
6408
+ delay: 700,
6409
+ showURL: false,
6410
+ showBody: " | ",
6411
+ fade: 250
6412
+ });
6413
+ }
6414
+ });
6415
+
6416
+ $("#ads-txt-search").keyup (function (event) {
6417
+ if (!ads_txt_reload) {
6418
+ ads_txt_reload = true;
6419
+ setTimeout (function() {load_ads_txt ();}, 200);
6420
+ }
6421
+ });
6422
+
6423
+ // $(document).keydown (function (event) {
6424
+ // if (event.which == "17") {
6425
+ // ai_ctrl_pressed = true;
6426
+
6427
+ // var public_report_button = $('.public-report-button');
6428
+ // public_report_button.addClass ('light-red');
6429
+ // public_report_button.attr ('title', $('.public-report-button').first ().attr ('title-rw'))
6430
+ // .tooltip({
6431
+ // track: true,
6432
+ // delay: 700,
6433
+ // showURL: false,
6434
+ // showBody: " | ",
6435
+ // fade: 250
6436
+ // });
6437
+ // }
6438
+ // });
6439
+
6440
+ // $(document).keyup (function() {
6441
+ // if (ai_ctrl_pressed) {
6442
+ // ai_ctrl_pressed = false;
6443
+
6444
+ // var public_report_button = $('.public-report-button');
6445
+ // public_report_button.removeClass ('light-red');
6446
+ // public_report_button.attr ('title', $('.public-report-button').first ().attr ('title-ro'))
6447
+ // .tooltip({
6448
+ // track: true,
6449
+ // delay: 700,
6450
+ // showURL: false,
6451
+ // showBody: " | ",
6452
+ // fade: 250
6453
+ // });
6454
+ // }
6455
+ // });
6456
+
6457
+ $(".ai-public-controls").dblclick (function () {
6458
+ $(this).toggleClass ('on');
6459
+ });
6460
+
6461
+ $(".public-report-button").click (function () {
6462
+ var report_data_elements = JSON.parse ($(this).attr ('report-data'));
6463
+ var report_url_prefix = report_data_elements [0]
6464
+ var report_dates_block = report_data_elements [1];
6465
+ var report_controls = $(this).parent ().parent ().parent ().parent ().find ('.ai-public-controls').hasClass ('on') ? '1' : '0';
6466
+ var report_range_name = $(this).parent ().parent ().parent ().parent ().find ('.custom-range-controls').attr ('range-name');
6467
+ var report_adb = report_data_elements [2];
6468
+ var report_range = report_data_elements [2];
6469
+ var report = report_dates_block + report_controls + report_adb + report_range_name;
6470
+ var report_id = b64e (report).replaceAll ('+', '.').replaceAll ('/', '_').replaceAll ('=', '-');
6471
+ var url = report_url_prefix + md5 (report).substring (0, 2) + report_id;
6472
+
6473
+ window.open (url, 'ai-report');
6474
+ });
6475
+
6476
+ if ($("#ai-list-data").hasClass ('ai-sticky')) {
6477
+ configure_list ();
6478
+ }
6479
+
6480
+ $("#ai-cancel-websites").click (function () {
6481
+ $("#ai-cancel-websites").hide ();
6482
+ $("#ai-save-websites").hide ();
6483
+ $("#ai-rearrange-websites").removeClass ('blue');
6484
+
6485
+ reload_websites ();
6486
+ });
6487
+
6488
+ $("#ai-add-website").click (function () {
6489
+ $("#ai-cancel-websites").hide ();
6490
+ $("#ai-save-websites").hide ();
6491
+ $("#ai-rearrange-websites").removeClass ('blue');
6492
+
6493
+ ai_reload_websites_function = function () {
6494
+ $('#ai-website-list-table tr.ai-website-list').last ().find (".ai-website-labels.ai-website-desc").click ();
6495
+ }
6496
+
6497
+ reload_websites ('&add=');
6498
+ });
6499
+
6500
+ $("#ai-save-websites").click (function () {
6501
+
6502
+ var connect = $(this).attr ('data-connect');
6503
+
6504
+ if (typeof connect !== typeof undefined && connect !== false) {
6505
+ $(this).removeAttr ('data-connect');
6506
+ connect = '&connect=' + connect;
6507
+ } else connect = '';
6508
+
6509
+ $('#ai-website-list-table tr.ai-website-list').each (function () {
6510
+ var row = $(this);
6511
+
6512
+ if (row.find (".ai-website-editor .ai-website-key").is (':visible')) {
6513
+ row.find (".ai-website-editor .ai-website-key").attr ('data-key', row.find (".ai-website-editor .ai-website-key").val ());
6514
+ row.find (".ai-website-labels.ai-website-desc").text (row.find (".ai-website-editor .ai-website-desc").val ());
6515
+ row.find (".ai-website-labels.ai-website-url").text (row.find (".ai-website-editor .ai-website-url").val ());
6516
+
6517
+ row.find (".ai-website-labels").show ();
6518
+ row.find (".ai-website-editor").hide ();
6519
+ }
6520
+ });
6521
+
6522
+ var websites = Array ();
6523
+
6524
+ $('#ai-website-list-table tr.ai-website-list').each (function () {
6525
+ var row = $(this);
6526
+
6527
+ var url = row.find (".ai-website-labels.ai-website-url").text ().trim ();
6528
+ var desc = row.find (".ai-website-labels.ai-website-desc").text ().trim ();
6529
+ var key = row.find (".ai-website-editor .ai-website-key").attr ('data-key').trim ();
6530
+
6531
+ if (url != '') {
6532
+ websites.push ({'url': url, 'name': desc, 'key': b64e (key)});
6533
+ }
6534
+ });
6535
+
6536
+ $("#ai-cancel-websites").hide ();
6537
+ $("#ai-save-websites").hide ();
6538
+ $("#ai-rearrange-websites").removeClass ('blue');
6539
+
6540
+ reload_websites ('&save=' + b64e (JSON.stringify (websites)) + connect);
6541
+ });
6542
+
6543
+ $("#ai-rearrange-websites").click (function () {
6544
+ $(this).toggleClass ('blue');
6545
+
6546
+ var data_container = $("#ai-website-data");
6547
+
6548
+ if ($(this).hasClass ('blue')) {
6549
+ $('#ai-website-list-table .ai-delete-website').each (function () {
6550
+ var row = $(this).closest ('tr.ai-website-list');
6551
+ var connected = row.find ('.ai-connect-website .checkbox-icon').hasClass ('on');
6552
+
6553
+ if (!connected) {
6554
+ $(this).show ();
6555
+ }
6556
+ });
6557
+
6558
+ data_container.find ('tbody').sortable ({
6559
+ start: function (event, ui) {
6560
+ $("#ai-cancel-websites").show ();
6561
+ $("#ai-save-websites").show ();
6562
+ },
6563
+ placeholder: "ui-state-highlight"
6564
+ }).css ('cursor', 'move');
6565
+ } else {
6566
+ data_container.find ('tbody').sortable ("disable");
6567
+ reload_websites ();
6568
+ }
6569
+ });
6570
+
6571
+ if ($(".ai-managing").length) {
6572
+ setTimeout (function () {window.location.href = ai_settings;}, 30 * 60 * 1000);
6573
+
6574
+ check_managing_slave ();
6575
+
6576
+ $("#ai-connected").click (function () {
6577
+ $(this).css ('color', '#ababab');
6578
+ $('#ai-loading').show ();
6579
+ ai_reload_websites_function = function () {
6580
+ if ($('#ai-website-data .ai-ajax-error').length == 0) {
6581
+ window.location.href = ai_settings;
6582
+ }
6583
+ }
6584
+
6585
+ reload_websites ('&connect=');
6586
+ });
6587
+ }
6588
+ });
6589
+
6590
+
 
 
 
 
 
 
 
 
readme.txt CHANGED
@@ -6,7 +6,7 @@ Tags: ads, adsense, ad rotation, ad manager, amp, amazon, ad blocking detection,
6
  Requires at least: 4.6
7
  Tested up to: 5.8
8
  Requires PHP: 5.6
9
- Stable tag: 2.6.25
10
  License: GPLv3
11
 
12
  Manage Google AdSense, Media.net, Amazon banners, ads.txt, ad rotation, sticky widgets, AMP ads, DFP, tracking, AdSense header and footer code
@@ -352,6 +352,23 @@ If you are not happy to reveal this information and you have opted in, simply di
352
 
353
  == Changelog ==
354
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
355
  = 2.6.25 =
356
  - Added support for block names in adinserter shortcode block attributes
357
  - Added support for default custom field values
@@ -539,6 +556,23 @@ For the changelog of earlier versions, please refer to the separate changelog.tx
539
 
540
  == Upgrade Notice ==
541
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
542
  = 2.6.25 =
543
  Added support for block names in adinserter shortcode block attributes;
544
  Added support for default custom field values;
6
  Requires at least: 4.6
7
  Tested up to: 5.8
8
  Requires PHP: 5.6
9
+ Stable tag: 2.7.0
10
  License: GPLv3
11
 
12
  Manage Google AdSense, Media.net, Amazon banners, ads.txt, ad rotation, sticky widgets, AMP ads, DFP, tracking, AdSense header and footer code
352
 
353
  == Changelog ==
354
 
355
+ = 2.7.0 =
356
+ - Added support to list range of post IDs
357
+ - Added support for browser language in client lists
358
+ - Added support for client-side checks for filter hook ai_block_insertion_check
359
+ - Added support for remote plugin managenent (Pro only)
360
+ - Added support for scheduling check shortcode (Pro only)
361
+ - Added support for daily scheduling time (Pro onlyl)
362
+ - Added support for css attribute in check options (Pro only)
363
+ - Few minor bug fixes, cosmetic changes and code improvements
364
+
365
+ = 2.6.27 =
366
+ - Added support for scheduled rotation
367
+ - Few minor bug fixes, cosmetic changes and code improvements
368
+
369
+ = 2.6.26 =
370
+ - Few bug fixes (Pro only)
371
+
372
  = 2.6.25 =
373
  - Added support for block names in adinserter shortcode block attributes
374
  - Added support for default custom field values
556
 
557
  == Upgrade Notice ==
558
 
559
+ = 2.7.0 =
560
+ Added support to list range of post IDs;
561
+ Added support for browser language in client lists;
562
+ Added support for client-side checks for filter hook ai_block_insertion_check;
563
+ Added support for remote plugin managenent (Pro only);
564
+ Added support for scheduling check shortcode (Pro only);
565
+ Added support for daily scheduling time (Pro onlyl);
566
+ Added support for css attribute in check options (Pro only);
567
+ Few minor bug fixes, cosmetic changes and code improvements
568
+
569
+ = 2.6.27 =
570
+ Added support for scheduled rotation;
571
+ Few minor bug fixes, cosmetic changes and code improvements
572
+
573
+ = 2.6.26 =
574
+ Few bug fixes (Pro only)
575
+
576
  = 2.6.25 =
577
  Added support for block names in adinserter shortcode block attributes;
578
  Added support for default custom field values;