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

Version Description

  • Bug fix: Cursor position always at the end of block name
  • State of debugging functions saved to cookie
  • Few minor bug fixes
Download this release

Release Info

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

Code changes from version 2.0.3 to 2.0.4

ad-inserter.php CHANGED
@@ -1,7 +1,7 @@
1
  <?php
2
  /*
3
  Plugin Name: Ad Inserter
4
- Version: 2.0.3
5
  Description: Insert any ad or code into Wordpress. Perfect for all kinds of ads. Simply enter any ad or HTML/Javascript/PHP code and select where and how you want to display it.
6
  Author: Igor Funa
7
  Author URI: http://igorfuna.com/
@@ -11,6 +11,11 @@ Plugin URI: http://tinymonitor.com/ad-inserter
11
  /*
12
  Change Log
13
 
 
 
 
 
 
14
  Ad Inserter 2.0.3 - 26 September 2016
15
  - Debugging functions in admin toolbar available only for administrators
16
  - Added option to hide debugging functions in admin toolbar
@@ -293,21 +298,18 @@ foreach ($version_array as $number) {
293
  $ai_wp_data [AI_WP_DEBUGGING] = 0;
294
  $ai_wp_data [AI_WP_URL] = remove_parameters_from_url ($_SERVER ['REQUEST_URI']);
295
 
296
- if (!session_id()) session_start();
297
-
298
-
299
- if (!isset ($_GET [AI_URL_DEBUG]))
300
- if (isset ($_GET [AI_URL_DEBUG_PROCESSING]) || (isset ($_SESSION ['AI_WP_DEBUGGING']) && ($_SESSION ['AI_WP_DEBUGGING'] & AI_DEBUG_PROCESSING) != 0)) {
301
- if (isset ($_GET [AI_URL_DEBUG_PROCESSING]) && $_GET [AI_URL_DEBUG_PROCESSING] == 0) {
302
- $_SESSION ['AI_WP_DEBUGGING'] &= ~AI_DEBUG_PROCESSING;
303
- } else {
304
  $ai_wp_data [AI_WP_DEBUGGING] |= AI_DEBUG_PROCESSING;
305
- $_SESSION ['AI_WP_DEBUGGING'] |= AI_DEBUG_PROCESSING;
306
  $ai_last_time = microtime ();
307
  $ai_processing_log = array ();
308
  ai_log ("INITIALIZATION START");
309
  }
310
- }
 
311
 
312
  $ad_interter_globals = array ();
313
  $block_object = array ();
@@ -698,33 +700,35 @@ function ai_wp_hook () {
698
 
699
  $url_debugging = get_remote_debugging () || ($ai_wp_data [AI_WP_USER] & AI_USER_ADMINISTRATOR) != 0;
700
 
701
- if (!session_id()) session_start();
 
 
 
 
 
 
 
 
702
 
703
- if (isset ($_GET [AI_URL_DEBUG]) && $_GET [AI_URL_DEBUG] == 0) {
704
- unset ($_SESSION ['AI_WP_DEBUGGING']);
705
- unset ($_SESSION ['AI_WP_DEBUG_BLOCK']);
706
- } else {
707
- if (isset ($_SESSION ['AI_WP_DEBUGGING'])) $_SESSION ['AI_WP_DEBUGGING'] |= $ai_wp_data [AI_WP_DEBUGGING]; else $_SESSION ['AI_WP_DEBUGGING'] = $ai_wp_data [AI_WP_DEBUGGING];
708
- if (!isset ($_SESSION ['AI_WP_DEBUG_BLOCK'])) $_SESSION ['AI_WP_DEBUG_BLOCK'] = 0;
709
 
710
- if (isset ($_GET [AI_URL_DEBUG_BLOCKS]))
711
- if ($_GET [AI_URL_DEBUG_BLOCKS] && $url_debugging) $_SESSION ['AI_WP_DEBUGGING'] |= AI_DEBUG_BLOCKS; else $_SESSION ['AI_WP_DEBUGGING'] &= ~AI_DEBUG_BLOCKS;
712
 
713
- if (isset ($_GET [AI_URL_DEBUG_TAGS]))
714
- if ($_GET [AI_URL_DEBUG_TAGS] && $url_debugging) $_SESSION ['AI_WP_DEBUGGING'] |= AI_DEBUG_TAGS; else $_SESSION ['AI_WP_DEBUGGING'] &= ~AI_DEBUG_TAGS;
715
 
716
- if (isset ($_GET [AI_URL_DEBUG_NO_INSERTION]))
717
- if ($_GET [AI_URL_DEBUG_NO_INSERTION] && $url_debugging) $_SESSION ['AI_WP_DEBUGGING'] |= AI_DEBUG_NO_INSERTION; else $_SESSION ['AI_WP_DEBUGGING'] &= ~AI_DEBUG_NO_INSERTION;
 
 
 
718
 
719
- if (isset ($_GET [AI_URL_DEBUG_POSITIONS])) {
720
- if ($_GET [AI_URL_DEBUG_POSITIONS] !== '' && $url_debugging) $_SESSION ['AI_WP_DEBUGGING'] |= AI_DEBUG_POSITIONS; else $_SESSION ['AI_WP_DEBUGGING'] &= ~AI_DEBUG_POSITIONS;
721
- if (is_numeric ($_GET [AI_URL_DEBUG_POSITIONS])) $_SESSION ['AI_WP_DEBUG_BLOCK'] = intval ($_GET [AI_URL_DEBUG_POSITIONS]);
722
- if ($_SESSION ['AI_WP_DEBUG_BLOCK'] < 0 || $_SESSION ['AI_WP_DEBUG_BLOCK'] > AD_INSERTER_BLOCKS) $_SESSION ['AI_WP_DEBUG_BLOCK'] = 0;
723
  }
724
-
725
- $ai_wp_data [AI_WP_DEBUGGING] = $_SESSION ['AI_WP_DEBUGGING'];
726
- $ai_wp_data [AI_WP_DEBUG_BLOCK] = $_SESSION ['AI_WP_DEBUG_BLOCK'];
727
- }
728
 
729
  $debug_positions = ($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_POSITIONS) != 0;
730
  $debug_tags_positions = ($ai_wp_data [AI_WP_DEBUGGING] & (AI_DEBUG_POSITIONS | AI_DEBUG_TAGS)) != 0;
@@ -747,7 +751,7 @@ function ai_wp_hook () {
747
  };
748
 
749
  function ai_init_hook() {
750
- global $block_object;
751
 
752
  add_shortcode ('adinserter', 'process_shortcodes');
753
  }
@@ -1294,8 +1298,7 @@ function ai_write_debug_info ($write_processing_log = false) {
1294
  $all_plugins = get_plugins();
1295
  $active_plugins = get_option ('active_plugins');
1296
  foreach ($all_plugins as $plugin_path => $plugin) {
1297
- // echo sprintf ("%s %-40s %s\n", in_array ($plugin_path, $active_plugins) ? '*' : ' ', $plugin ["Name"], $plugin ["Version"]);
1298
- echo in_array ($plugin_path, $active_plugins) ? '* ' : ' ', $plugin ["Name"], ' ', $plugin ["Version"], "\n";
1299
  }
1300
  }
1301
  }
@@ -1692,6 +1695,12 @@ function ai_preview () {
1692
  }
1693
  }
1694
 
 
 
 
 
 
 
1695
  die ();
1696
  }
1697
 
1
  <?php
2
  /*
3
  Plugin Name: Ad Inserter
4
+ Version: 2.0.4
5
  Description: Insert any ad or code into Wordpress. Perfect for all kinds of ads. Simply enter any ad or HTML/Javascript/PHP code and select where and how you want to display it.
6
  Author: Igor Funa
7
  Author URI: http://igorfuna.com/
11
  /*
12
  Change Log
13
 
14
+ Ad Inserter 2.0.4 - 30 September 2016
15
+ - Bug fix: Cursor position always at the end of block name
16
+ - State of debugging functions is saved to cookie
17
+ - Few minor bug fixes
18
+
19
  Ad Inserter 2.0.3 - 26 September 2016
20
  - Debugging functions in admin toolbar available only for administrators
21
  - Added option to hide debugging functions in admin toolbar
298
  $ai_wp_data [AI_WP_DEBUGGING] = 0;
299
  $ai_wp_data [AI_WP_URL] = remove_parameters_from_url ($_SERVER ['REQUEST_URI']);
300
 
301
+ if (!is_admin()) {
302
+ if (!isset ($_GET [AI_URL_DEBUG]))
303
+ if (isset ($_GET [AI_URL_DEBUG_PROCESSING]) || (isset ($_COOKIE ['AI_WP_DEBUGGING']) && ($_COOKIE ['AI_WP_DEBUGGING'] & AI_DEBUG_PROCESSING) != 0)) {
304
+ if (!isset ($_GET [AI_URL_DEBUG_PROCESSING]) || $_GET [AI_URL_DEBUG_PROCESSING] == 1) {
 
 
 
 
305
  $ai_wp_data [AI_WP_DEBUGGING] |= AI_DEBUG_PROCESSING;
306
+
307
  $ai_last_time = microtime ();
308
  $ai_processing_log = array ();
309
  ai_log ("INITIALIZATION START");
310
  }
311
+ }
312
+ }
313
 
314
  $ad_interter_globals = array ();
315
  $block_object = array ();
700
 
701
  $url_debugging = get_remote_debugging () || ($ai_wp_data [AI_WP_USER] & AI_USER_ADMINISTRATOR) != 0;
702
 
703
+ if (!is_admin()) {
704
+ if (isset ($_GET [AI_URL_DEBUG]) && $_GET [AI_URL_DEBUG] == 0) {
705
+ unset ($_COOKIE ['AI_WP_DEBUGGING']);
706
+ setcookie ('AI_WP_DEBUGGING', '', time() - (15 * 60), COOKIEPATH);
707
+ unset ($_COOKIE ['AI_WP_DEBUG_BLOCK']);
708
+ setcookie ('AI_WP_DEBUG_BLOCK', '', time() - (15 * 60), COOKIEPATH);
709
+ } else {
710
+ $ai_wp_data [AI_WP_DEBUGGING] = isset ($_COOKIE ['AI_WP_DEBUGGING']) ? $ai_wp_data [AI_WP_DEBUGGING] | ($_COOKIE ['AI_WP_DEBUGGING'] & ~AI_DEBUG_PROCESSING) : $ai_wp_data [AI_WP_DEBUGGING];
711
+ $ai_wp_data [AI_WP_DEBUG_BLOCK] = isset ($_COOKIE ['AI_WP_DEBUG_BLOCK']) ? $_COOKIE ['AI_WP_DEBUG_BLOCK'] : 0;
712
 
713
+ if (isset ($_GET [AI_URL_DEBUG_BLOCKS]))
714
+ if ($_GET [AI_URL_DEBUG_BLOCKS] && $url_debugging) $ai_wp_data [AI_WP_DEBUGGING] |= AI_DEBUG_BLOCKS; else $ai_wp_data [AI_WP_DEBUGGING] &= ~AI_DEBUG_BLOCKS;
 
 
 
 
715
 
716
+ if (isset ($_GET [AI_URL_DEBUG_TAGS]))
717
+ if ($_GET [AI_URL_DEBUG_TAGS] && $url_debugging) $ai_wp_data [AI_WP_DEBUGGING] |= AI_DEBUG_TAGS; else $ai_wp_data [AI_WP_DEBUGGING] &= ~AI_DEBUG_TAGS;
718
 
719
+ if (isset ($_GET [AI_URL_DEBUG_NO_INSERTION]))
720
+ if ($_GET [AI_URL_DEBUG_NO_INSERTION] && $url_debugging) $ai_wp_data [AI_WP_DEBUGGING] |= AI_DEBUG_NO_INSERTION; else $ai_wp_data [AI_WP_DEBUGGING] &= ~AI_DEBUG_NO_INSERTION;
721
 
722
+ if (isset ($_GET [AI_URL_DEBUG_POSITIONS])) {
723
+ if ($_GET [AI_URL_DEBUG_POSITIONS] !== '' && $url_debugging) $ai_wp_data [AI_WP_DEBUGGING] |= AI_DEBUG_POSITIONS; else $ai_wp_data [AI_WP_DEBUGGING] &= ~AI_DEBUG_POSITIONS;
724
+ if (is_numeric ($_GET [AI_URL_DEBUG_POSITIONS])) $ai_wp_data [AI_WP_DEBUG_BLOCK] = intval ($_GET [AI_URL_DEBUG_POSITIONS]);
725
+ if ($ai_wp_data [AI_WP_DEBUG_BLOCK] < 0 || $ai_wp_data [AI_WP_DEBUG_BLOCK] > AD_INSERTER_BLOCKS) $ai_wp_data [AI_WP_DEBUG_BLOCK] = 0;
726
+ }
727
 
728
+ setcookie ('AI_WP_DEBUGGING', $ai_wp_data [AI_WP_DEBUGGING], time() + AI_COOKIE_TIME, COOKIEPATH);
729
+ setcookie ('AI_WP_DEBUG_BLOCK', $ai_wp_data [AI_WP_DEBUG_BLOCK], time() + AI_COOKIE_TIME, COOKIEPATH);
 
 
730
  }
731
+ }
 
 
 
732
 
733
  $debug_positions = ($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_POSITIONS) != 0;
734
  $debug_tags_positions = ($ai_wp_data [AI_WP_DEBUGGING] & (AI_DEBUG_POSITIONS | AI_DEBUG_TAGS)) != 0;
751
  };
752
 
753
  function ai_init_hook() {
754
+ global $block_object, $ai_wp_data;
755
 
756
  add_shortcode ('adinserter', 'process_shortcodes');
757
  }
1298
  $all_plugins = get_plugins();
1299
  $active_plugins = get_option ('active_plugins');
1300
  foreach ($all_plugins as $plugin_path => $plugin) {
1301
+ echo in_array ($plugin_path, $active_plugins) ? '* ' : ' ', html_entity_decode ($plugin ["Name"]), ' ', $plugin ["Version"], "\n";
 
1302
  }
1303
  }
1304
  }
1695
  }
1696
  }
1697
 
1698
+ if (isset ($_GET ["image"])) {
1699
+ header ("Content-Type: image/png");
1700
+ header ("Content-Length: " . filesize (AD_INSERTER_PLUGIN_DIR.'images/'.$_GET ["image"]));
1701
+ readfile (AD_INSERTER_PLUGIN_DIR.'images/'.$_GET ["image"]);
1702
+ }
1703
+
1704
  die ();
1705
  }
1706
 
class.php CHANGED
@@ -2119,11 +2119,12 @@ abstract class ai_CodeBlock extends ai_BaseCodeBlock {
2119
  if (!empty ($tags)) {
2120
 
2121
  $first_tag = reset ($tags);
2122
- $tag = str_replace (array ("&amp;", "#"), array ("and", ""), $first_tag->name);
2123
 
2124
  $tag_array = array ();
2125
  foreach ($tags as $tag_data) {
2126
- $tag_array [] = explode (" ", $tag_data->name);
 
2127
  }
2128
 
2129
  $selected_tag = '';
@@ -2147,7 +2148,7 @@ abstract class ai_CodeBlock extends ai_BaseCodeBlock {
2147
 
2148
  if ($selected_tag == '') {
2149
  $first_tag = reset ($tags);
2150
- $smart_tag = implode (" ", array_slice (explode (" ", $first_tag->name), 0, 3));
2151
  } else $smart_tag = implode (" ", $selected_tag);
2152
 
2153
  $smart_tag = str_replace (array ("&amp;", "#"), array ("and", ""), $smart_tag);
2119
  if (!empty ($tags)) {
2120
 
2121
  $first_tag = reset ($tags);
2122
+ $tag = str_replace (array ("&amp;", "#"), array ("and", ""), isset ($first_tag->name) ? $first_tag->name : '');
2123
 
2124
  $tag_array = array ();
2125
  foreach ($tags as $tag_data) {
2126
+ if (isset ($tag_data->name))
2127
+ $tag_array [] = explode (" ", $tag_data->name);
2128
  }
2129
 
2130
  $selected_tag = '';
2148
 
2149
  if ($selected_tag == '') {
2150
  $first_tag = reset ($tags);
2151
+ $smart_tag = implode (" ", array_slice (explode (" ", isset ($first_tag->name) ? $first_tag->name : ''), 0, 3));
2152
  } else $smart_tag = implode (" ", $selected_tag);
2153
 
2154
  $smart_tag = str_replace (array ("&amp;", "#"), array ("and", ""), $smart_tag);
constants.php CHANGED
@@ -11,7 +11,7 @@ if (!defined( 'AD_INSERTER_NAME'))
11
  define ('AD_INSERTER_NAME', 'Ad Inserter');
12
 
13
  if (!defined( 'AD_INSERTER_VERSION'))
14
- define ('AD_INSERTER_VERSION', '2.0.3');
15
 
16
  if (!defined ('AD_INSERTER_BLOCKS'))
17
  define ('AD_INSERTER_BLOCKS', 16);
@@ -50,7 +50,7 @@ define ('AD_EMPTY_DATA', '');
50
  define ('AD_ZERO', '0');
51
  define ('AD_ONE', '1');
52
  define ('AD_TWO', '2');
53
- define ('AD_GENERAL_TAG', 'wordpress');
54
  define ('AD_NAME', 'Block');
55
 
56
  // Old options
@@ -230,6 +230,7 @@ define('AD_SETTINGS_CHECKED', '1');
230
  define('AD_SETTINGS_NOT_CHECKED', '0');
231
 
232
  define('DEFAULT_MARGIN', 8);
 
233
 
234
  define ('DEFAULT_SYNTAX_HIGHLIGHTER_THEME', 'ad_inserter');
235
  define ('DEFAULT_BLOCK_CLASS_NAME', 'code-block');
11
  define ('AD_INSERTER_NAME', 'Ad Inserter');
12
 
13
  if (!defined( 'AD_INSERTER_VERSION'))
14
+ define ('AD_INSERTER_VERSION', '2.0.4');
15
 
16
  if (!defined ('AD_INSERTER_BLOCKS'))
17
  define ('AD_INSERTER_BLOCKS', 16);
50
  define ('AD_ZERO', '0');
51
  define ('AD_ONE', '1');
52
  define ('AD_TWO', '2');
53
+ define ('AD_GENERAL_TAG', 'electronics');
54
  define ('AD_NAME', 'Block');
55
 
56
  // Old options
230
  define('AD_SETTINGS_NOT_CHECKED', '0');
231
 
232
  define('DEFAULT_MARGIN', 8);
233
+ define('AI_COOKIE_TIME', 3600);
234
 
235
  define ('DEFAULT_SYNTAX_HIGHLIGHTER_THEME', 'ad_inserter');
236
  define ('DEFAULT_BLOCK_CLASS_NAME', 'code-block');
css/ad-inserter.css CHANGED
@@ -1,5 +1,5 @@
1
  #data {
2
- font-family: "2.0.3"; /* Used for version number of the file */
3
  }
4
 
5
  #blocked-warning {
1
  #data {
2
+ font-family: "2.0.4"; /* Used for version number of the file */
3
  }
4
 
5
  #blocked-warning {
{js → includes/js}/jquery.mousewheel.js RENAMED
File without changes
{js → includes/js}/jquery.mousewheel.min.js RENAMED
File without changes
{js → includes/js}/jquery.ui.spinner.js RENAMED
@@ -532,3 +532,12 @@ $.widget( "ui.spinner", {
532
  });
533
 
534
  }( jQuery ) );
 
 
 
 
 
 
 
 
 
532
  });
533
 
534
  }( jQuery ) );
535
+
536
+ jQuery(document).ready(function($) {
537
+ $("#blocked-warning.warning-enabled").removeClass ('warning-enabled');
538
+ $("#blocked-warning").hide ();
539
+
540
+ var css_version = $('#data').css ('font-family').replace(/\"/g, '');
541
+ if (css_version.indexOf ('.') == - 1) $("#blocked-warning").show ();
542
+ });
543
+
js/ad-inserter.js CHANGED
@@ -1,807 +1,811 @@
1
- var javascript_version = "2.0.3";
2
- var ignore_key = true;
3
- var start = 1;
4
- var end = 16;
5
- var active_tab = 1;
6
- var tabs_to_configure = new Array();
7
-
8
- var current_tab = 0;
9
- var next_tab = 0;
10
-
11
- var syntax_highlighting = false;
12
- var settings_page = "";
13
-
14
- var shSettings = {
15
- "tab_size":"4",
16
- "use_soft_tabs":"1",
17
- "word_wrap":"1",
18
- "highlight_curr_line":"0",
19
- "key_bindings":"default",
20
- "full_line_selection":"1",
21
- "show_line_numbers":"0"};
22
-
23
- function SyntaxHighlight (id, block, settings) {
24
- var textarea, editor, form, session, editDiv;
25
-
26
- this.textarea = textarea = jQuery(id);
27
- this.settings = settings || {};
28
-
29
- if (textarea.length === 0 ) { // Element does not exist
30
- this.valid = false;
31
- return;
32
- }
33
-
34
- this.valid = true;
35
- editDiv = jQuery('<div>', {
36
- position: 'absolute',
37
- // width: textarea.width() + 14,
38
- // width: 733,
39
- // height: textarea.height() + 4,
40
- // height: 384,
41
- 'class': textarea.attr('class'),
42
- 'id': 'editor-' + block
43
- }).insertBefore (textarea);
44
-
45
- textarea.css('display', 'none');
46
- this.editor = editor = ace.edit(editDiv[0]);
47
- this.form = form = textarea.closest('form');
48
- this.session = session = editor.getSession();
49
- session.setValue(textarea.val());
50
-
51
- // copy back to textarea on form submit...
52
- form.submit (function () {
53
- var block = textarea.attr ("id").replace ("block-","");
54
- var editor_disabled = jQuery("#simple-editor-" + block).is(":checked");
55
- if (!editor_disabled) {
56
- textarea.val (session.getValue());
57
- }
58
- if (textarea.val () == "") {
59
- textarea.removeAttr ("name");
60
- }
61
-
62
- jQuery("#ai-active-tab").attr ("value", active_tab);
63
- });
64
-
65
- session.setMode ("ace/mode/html");
66
-
67
- this.applySettings();
68
- }
69
-
70
- SyntaxHighlight.prototype.applySettings = function () {
71
- var editor = this.editor,
72
- session = this.session,
73
- settings = this.settings;
74
-
75
- editor.renderer.setShowGutter(settings['show_line_numbers'] == 1);
76
- editor.setHighlightActiveLine(settings['highlight_curr_line'] == 1);
77
- editor.setSelectionStyle(settings['full_line_selection'] == 1 ? "line" : "text");
78
- editor.setTheme("ace/theme/" + settings['theme']);
79
- session.setUseWrapMode(settings['word_wrap'] == 1);
80
- session.setTabSize(settings['tab_size']);
81
- session.setUseSoftTabs(settings['use_soft_tabs'] == 1);
82
- };
83
-
84
- function change_block_alignment (block) {
85
- jQuery("select#block-alignment-" + block).change ();
86
- }
87
-
88
- jQuery(document).ready(function($) {
89
-
90
- shSettings ['theme'] = $('#data').attr ('theme');
91
-
92
- var debug = parseInt ($('#data').attr ('javascript_debugging'));
93
- var debug_title = false;
94
-
95
- if (debug) {
96
- var start_time = new Date().getTime();
97
- var last_time = start_time;
98
- debug_title = true;
99
- }
100
-
101
- syntax_highlighting = typeof shSettings ['theme'] != 'undefined' && shSettings ['theme'] != 'disabled';
102
-
103
- var header = $('#ai-settings-' + 'header').length != 0;
104
- var header_id = 'name';
105
- var preview_top = (screen.height / 2) - (820 / 2);
106
-
107
- function remove_default_values (block) {
108
- $("#tab-" + block + " input:checkbox").each (function() {
109
- var default_value = $(this).attr ("default");
110
- var current_value = $(this).is (':checked');
111
-
112
- if (typeof default_value != 'undefined') {
113
- default_value = Boolean (parseInt (default_value));
114
- // console.log ($(this).attr ("name"), ": default_value: ", $(this).attr ("default"), " = ", default_value, ", current_value: ", current_value);
115
-
116
- if (current_value == default_value) {
117
- var name = $(this).attr ("name");
118
- $(this).removeAttr ("name");
119
- $("#tab-" + block + " [name='" + name + "']").removeAttr ("name");
120
- // console.log ("REMOVED: ", name);
121
- }
122
- }
123
- // else console.log ("NO DEFAULT VALUE:", $(this).attr ("name"));
124
- });
125
-
126
- $("#tab-" + block + " input:text").each (function() {
127
- var default_value = $(this).attr ("default");
128
- var current_value = $(this).val ();
129
-
130
- if (typeof default_value != 'undefined') {
131
- // console.log ($(this).attr ("name"), ": default_value: ", default_value, ", current_value: ", current_value);
132
-
133
- if (current_value == default_value) {
134
- var name = $(this).attr ("name");
135
- $(this).removeAttr ("name");
136
- // console.log ("REMOVED: ", name);
137
- }
138
- }
139
- // else console.log ("NO DEFAULT VALUE: ", $(this).attr ("name"));
140
- });
141
-
142
- $("#tab-" + block + " select").each (function() {
143
- var default_value = $(this).attr ("default");
144
- var current_value = $(this).children ("option:selected");
145
-
146
- var childern = $(this).children ();
147
- if (childern.prop ("tagName") == "OPTGROUP") {
148
- var current_value = "";
149
- childern.each (function() {
150
- var selected = $(this).children ("option:selected");
151
- if (selected.length != 0) {
152
- current_value = selected;
153
- return false;
154
- }
155
- });
156
- }
157
-
158
- if ($(this).attr ("selected-value") == 1) current_value = current_value.attr("value"); else current_value = current_value.text();
159
-
160
- if (typeof default_value != 'undefined') {
161
- // console.log ($(this).attr ("name"), ": default_value: ", default_value, ", current_value: ", current_value);
162
-
163
- if (current_value == default_value) {
164
- var name = $(this).attr ("name");
165
- $(this).removeAttr ("name");
166
- // console.log ("REMOVED: ", name);
167
- }
168
- }
169
- // else console.log ("NO DEFAULT VALUE: ", $(this).attr ("name"));
170
- });
171
-
172
- $("#tab-" + block + " input:radio:checked").each (function() {
173
- var default_value = $(this).attr ("default");
174
- var current_value = $(this).is (':checked');
175
-
176
- if (typeof default_value != 'undefined') {
177
- default_value = Boolean (parseInt (default_value));
178
- // console.log ($(this).attr ("name"), ": default_value: ", $(this).attr ("default"), " = ", default_value, ", current_value: ", current_value);
179
-
180
- if (current_value == default_value) {
181
- var name = $(this).attr ("name");
182
- $("#tab-" + block + " [name='" + name + "']").removeAttr ("name");
183
- // console.log ("REMOVED: ", name);
184
- }
185
- }
186
- // else console.log ("NO DEFAULT VALUE: ", $(this).attr ("name"));
187
- });
188
- }
189
-
190
- function configure_editor_language (block) {
191
-
192
- var editor = ace.edit ("editor-" + block);
193
-
194
- if ($("input#process-php-"+block).is(":checked")) {
195
- editor.getSession ().setMode ("ace/mode/php");
196
- } else editor.getSession ().setMode ("ace/mode/html");
197
- }
198
-
199
- function process_display_elements (block) {
200
-
201
- $("#paragraph-settings-"+block).hide();
202
- $("#content-settings-"+block).hide();
203
-
204
- // var display_type = '';
205
- // $("select#display-type-"+block+" option:selected").each(function() {
206
- // display_type += $(this).text();
207
- // });
208
- var display_type = $("select#display-type-"+block+" option:selected").text();
209
-
210
- if (display_type == "Before Paragraph" || display_type == "After Paragraph") {
211
- $("#paragraph-settings-"+block).show();
212
- } else {
213
- $("#paragraph-counting-"+block).hide();
214
- $("#paragraph-clearance-"+block).hide();
215
- }
216
-
217
- if (display_type == "Before Paragraph" || display_type == "After Paragraph" || display_type == "Before Content" || display_type == "After Content") {
218
- $("#content-settings-"+block).show();
219
- }
220
-
221
- $("#css-label-"+block).css('display', 'table-cell');
222
- $("#edit-css-button-"+block).css('display', 'table-cell');
223
-
224
- $("#css-none-"+block).hide();
225
- $("#custom-css-"+block).hide();
226
- $("#css-left-"+block).hide();
227
- $("#css-right-"+block).hide();
228
- $("#css-center-"+block).hide();
229
- $("#css-float-left-"+block).hide();
230
- $("#css-float-right-"+block).hide();
231
- $("#css-no-wrapping-"+block).hide();
232
-
233
- $("#no-wrapping-warning-"+block).hide();
234
-
235
- var alignment = $("select#block-alignment-"+block+" option:selected").text();
236
-
237
- if (alignment == "No Wrapping") {
238
- $("#css-no-wrapping-"+block).css('display', 'table-cell');
239
- $("#css-label-"+block).hide();
240
- $("#edit-css-button-"+block).hide();
241
- if ($("#client-side-detection-"+block).is(":checked")) {
242
- $("#no-wrapping-warning-"+block).show();
243
- }
244
- } else
245
- if (alignment == "None") {
246
- $("#css-none-"+block).css('display', 'table-cell');
247
- } else
248
- if (alignment == "Custom CSS") {
249
- $("#css-code-" + block).show();
250
- $("#custom-css-"+block).show();
251
- } else
252
- if (alignment == "Align Left") {
253
- $("#css-left-"+block).css('display', 'table-cell');
254
- } else
255
- if (alignment == "Align Right") {
256
- $("#css-right-"+block).css('display', 'table-cell');
257
- } else
258
- if (alignment == "Center") {
259
- $("#css-center-"+block).css('display', 'table-cell');
260
- } else
261
- if (alignment == "Float Left") {
262
- $("#css-float-left-"+block).css('display', 'table-cell');
263
- } else
264
- if (alignment == "Float Right") {
265
- $("#css-float-right-"+block).css('display', 'table-cell');
266
- }
267
-
268
- if ($('#css-code-'+block).is(':visible')) {
269
- $("#show-css-button-"+block+" span").text ("Hide CSS");
270
- } else {
271
- $("#show-css-button-"+block+" span").text ("Show CSS");
272
- }
273
-
274
- var avoid_action = $("select#avoid-action-"+block+" option:selected").text();
275
-
276
- if (avoid_action == "do not insert")
277
- $("#check-up-to-"+block).hide (); else
278
- $("#check-up-to-"+block).show ();
279
-
280
- if (syntax_highlighting) configure_editor_language (block);
281
- }
282
-
283
- function configure_editor (block) {
284
-
285
- if (debug) console.log ("configure_editor: " + block);
286
-
287
- if (syntax_highlighting) {
288
- var syntax_highlighter = new SyntaxHighlight ('#block-' + block, block, shSettings);
289
- syntax_highlighter.editor.setPrintMarginColumn (1000);
290
-
291
- $('input#simple-editor-' + block).change (function () {
292
-
293
- var block = $(this).attr ("id").replace ("simple-editor-","");
294
- var editor_disabled = $(this).is(":checked");
295
- var editor = ace.edit ("editor-" + block);
296
- var textarea = $("#block-" + block);
297
- var ace_editor = $("#editor-" + block);
298
-
299
- if (editor_disabled) {
300
- textarea.val (editor.session.getValue());
301
- textarea.css ('display', 'block');
302
- ace_editor.css ('display', 'none');
303
- } else {
304
- editor.session.setValue (textarea.val ())
305
- editor.renderer.updateFull();
306
- ace_editor.css ('display', 'block');
307
- textarea.css ('display', 'none');
308
- }
309
- });
310
- }
311
-
312
- if (block != 'h' && block != 'f' && !header) {
313
- if ((block - 1) >> 4) {
314
- $('#block' + '-' + block).removeAttr(header_id);
315
- $('#display' + '-type-' + block).removeAttr(header_id);
316
- }
317
-
318
- if (block >> 2) {
319
- $('#option' + '-name-' + block).removeAttr(header_id);
320
- $('#option' + '-length-' + block).removeAttr(header_id);
321
- }
322
- }
323
- }
324
-
325
- function configure_tab_0 () {
326
-
327
- if (debug) console.log ("configure_tab_0");
328
-
329
- $('#tab-0').addClass ('configured');
330
-
331
- $('#tab-0 input[type=submit], #tab-0 button').button().show ();
332
-
333
- configure_editor ('h');
334
- configure_editor ('f');
335
-
336
- $('#ai-plugin-settings-tab-container').tabs();
337
- $('#ai-plugin-settings-tabs').show();
338
-
339
- $("#export-switch-0").button ({
340
- icons: {
341
- primary: "ui-icon-gear",
342
- secondary: "ui-icon-triangle-1-s"
343
- },
344
- text: false
345
- }).show ().click (function () {
346
- $("#export-container-0").toggle ();
347
-
348
- if ($("#export-container-0").is(':visible') && !$(this).hasClass ("loaded")) {
349
- var nonce = $(this).attr ('nonce');
350
- $("#export_settings_0").load ("/wp-admin/admin-ajax.php?action=ai_preview&export=0&ai_check=" + nonce, function() {
351
- $("#export_settings_0").attr ("name", "export_settings_0");
352
- $("#export-switch-0").addClass ("loaded");
353
- });
354
- }
355
- });
356
-
357
- $("input#process-php-h").change (function() {
358
- if (syntax_highlighting) configure_editor_language ('h');
359
- });
360
-
361
- $("input#process-php-f").change (function() {
362
- if (syntax_highlighting) configure_editor_language ('f')
363
- });
364
-
365
- if (syntax_highlighting) configure_editor_language ('h');
366
- if (syntax_highlighting) configure_editor_language ('f');
367
- }
368
-
369
- function configure_tab (tab) {
370
-
371
- $('#tab-' + tab).addClass ('configured');
372
-
373
- $('#tab-' + tab + ' input[type=submit], #tab-' + tab + ' button').button().show ();
374
-
375
- configure_editor (tab);
376
-
377
- $("select#display-type-"+tab).change (function() {
378
- var block = $(this).attr('id').replace ("display-type-", "");
379
- process_display_elements (block);
380
- });
381
- $("select#block-alignment-"+tab).change (function() {
382
- var block = $(this).attr('id').replace ("block-alignment-", "");
383
- process_display_elements (block);
384
- });
385
- $("input#process-php-"+tab).change (function() {
386
- var block = $(this).attr('id').replace ("process-php-", "");
387
- process_display_elements (block);
388
- });
389
- $("#enable-shortcode-"+tab).change (function() {
390
- var block = $(this).attr('id').replace ("enable-shortcode-", "");
391
- process_display_elements (block);
392
- });
393
- $("#enable-php-call-"+tab).change (function() {
394
- var block = $(this).attr('id').replace ("enable-php-call-", "");
395
- process_display_elements (block);
396
- });
397
- $("select#display-for-devices-"+tab).change (function() {
398
- var block = $(this).attr('id').replace ("display-for-devices-", "");
399
- process_display_elements (block);
400
- });
401
-
402
- $("#display-homepage-"+tab).change (function() {
403
- var block = $(this).attr('id').replace ("display-homepage-", "");
404
- process_display_elements (block);
405
- });
406
- $("#display-category-"+tab).change (function() {
407
- var block = $(this).attr('id').replace ("display-category-", "");
408
- process_display_elements (block);
409
- });
410
- $("#display-search-"+tab).change (function() {
411
- var block = $(this).attr('id').replace ("display-search-", "");
412
- process_display_elements (block);
413
- });
414
- $("#display-archive-"+tab).change (function() {
415
- var block = $(this).attr('id').replace ("display-archive-", "");
416
- process_display_elements (block);
417
- });
418
-
419
- $("#client-side-detection-"+tab).change (function() {
420
- var block = $(this).attr('id').replace ("client-side-detection-", "");
421
- process_display_elements (block);
422
- });
423
-
424
- $("select#avoid-action-"+tab).change (function() {
425
- var block = $(this).attr('id').replace ("avoid-action-", "");
426
- process_display_elements (block);
427
- });
428
-
429
- process_display_elements (tab);
430
-
431
- $("#widgets-button-"+tab).button ({
432
- }).click (function () {
433
- window.location.href = "widgets.php";
434
- });
435
-
436
- $("#show-css-button-"+tab).button ({
437
- }).show ().click (function () {
438
- var block = $(this).attr ("id").replace ("show-css-button-","");
439
- $("#css-code-" + block).toggle ();
440
-
441
- if ($('#css-code-'+block).is(':visible')) {
442
- $("#show-css-button-"+block+" span").text ("Hide CSS");
443
- } else {
444
- $("#show-css-button-"+block+" span").text ("Show CSS");
445
- }
446
- });
447
-
448
- $("#counting-button-"+tab).button ({
449
- }).show ().click (function () {
450
- var block = $(this).attr ("id").replace ("counting-button-","");
451
- $("#paragraph-counting-" + block).toggle ();
452
- });
453
-
454
- $("#clearance-button-"+tab).button ({
455
- }).show ().click (function () {
456
- var block = $(this).attr ("id").replace ("clearance-button-","");
457
- $("#paragraph-clearance-" + block).toggle ();
458
- });
459
-
460
- $("#edit-css-button-"+tab).button ({
461
- }).click (function () {
462
- var block = $(this).attr('id').replace ("edit-css-button-", "");
463
-
464
- $("#css-left-"+block).hide();
465
- $("#css-right-"+block).hide();
466
- $("#css-center-"+block).hide();
467
- $("#css-float-left-"+block).hide();
468
- $("#css-float-right-"+block).hide();
469
-
470
- var alignment = $("select#block-alignment-"+block+" option:selected").text();
471
-
472
- if (alignment == "None") {
473
- $("#css-none-"+block).hide();
474
- $("#custom-css-"+block).show().val ($("#css-none-"+block).text ());
475
- $("select#block-alignment-"+block).val ("Custom CSS").change();
476
- } else
477
- if (alignment == "Align Left") {
478
- $("#css-left-"+block).hide();
479
- $("#custom-css-"+block).show().val ($("#css-left-"+block).text ());
480
- $("select#block-alignment-"+block).val ("Custom CSS").change();
481
- } else
482
- if (alignment == "Align Right") {
483
- $("#css-right-"+block).hide();
484
- $("#custom-css-"+block).show().val ($("#css-right-"+block).text ());
485
- $("select#block-alignment-"+block).val ("Custom CSS").change();
486
- } else
487
- if (alignment == "Center") {
488
- $("#css-center-"+block).hide();
489
- $("#custom-css-"+block).show().val ($("#css-center-"+block).text ());
490
- $("select#block-alignment-"+block).val ("Custom CSS").change();
491
- } else
492
- if (alignment == "Float Left") {
493
- $("#css-float-left-"+block).hide();
494
- $("#custom-css-"+block).show().val ($("#css-float-left-"+block).text ());
495
- $("select#block-alignment-"+block).val ("Custom CSS").change();
496
- } else
497
- if (alignment == "Float Right") {
498
- $("#css-float-right-"+block).hide();
499
- $("#custom-css-"+block).show().val ($("#css-float-right-"+block).text ());
500
- $("select#block-alignment-"+block).val ("Custom CSS").change();
501
- }
502
- });
503
-
504
- $("#name-label-"+tab).click (function () {
505
- var block = $(this).attr('id').replace ("name-label-", "");
506
- $("#name-edit-"+block).css('display', 'table-cell').val ($("#name-label-"+block).text ()).focus ();
507
- $("#name-label-"+block).hide();
508
- });
509
-
510
- $("#name-label-container-"+tab).click (function () {
511
- var block = $(this).attr('id').replace ("name-label-container-", "");
512
- $("#name-edit-"+block).css('display', 'table-cell').val ($("#name-label-"+block).text ()).focus ();
513
- $("#name-label-"+block).hide();
514
- });
515
-
516
- $("#name-edit-"+tab).on('keyup keypress', function (e) {
517
- var keyCode = e.keyCode || e.which;
518
- ignore_key = true;
519
- if (keyCode == 27) {
520
- var block = $(this).attr('id').replace ("name-edit-", "");
521
- $("#name-label-"+block).show();
522
- $("#name-edit-"+block).hide();
523
- ignore_key = false;
524
- } else if (keyCode == 13) {
525
- var block = $(this).attr('id').replace ("name-edit-", "");
526
- $("#name-label-"+block).show().text ($("#name-edit-"+block).val ());
527
- $("#name-edit-"+block).hide();
528
- ignore_key = false;
529
- e.preventDefault();
530
- return false;
531
- }
532
- }).focusout (function() {
533
- if (ignore_key) {
534
- var block = $(this).attr('id').replace ("name-edit-", "");
535
- $("#name-label-"+block).show().text ($("#name-edit-"+block).val ());
536
- $("#name-edit-"+block).hide();
537
- }
538
- ignore_key = true;
539
- });
540
-
541
- $("#export-switch-"+tab).button ({
542
- icons: {
543
- secondary: "ui-icon-triangle-1-s"
544
- },
545
- text: false
546
- }).show ().click (function () {
547
- var block = $(this).attr ("id");
548
- block = block.replace ("export-switch-","");
549
- $("#export-container-" + block).toggle ();
550
-
551
- if ($("#export-container-" + block).is(':visible') && !$(this).hasClass ("loaded")) {
552
- var nonce = $(this).attr ('nonce');
553
- $("#export_settings_" + block).load ("/wp-admin/admin-ajax.php?action=ai_preview&export=" + block + "&ai_check=" + nonce, function() {
554
- $("#export_settings_" + block).attr ("name", "export_settings_" + block);
555
- $("#export-switch-"+block).addClass ("loaded");
556
- });
557
- }
558
- });
559
-
560
- $("#device-detection-button-"+tab).button ({
561
- }).show ().click (function () {
562
- var block = $(this).attr ("id");
563
- block = block.replace ("device-detection-button-","");
564
- $("#device-detection-settings-" + block).toggle ();
565
- });
566
-
567
- $("#lists-button-"+tab).button ({
568
- }).show ().click (function () {
569
- var block = $(this).attr ("id");
570
- block = block.replace ("lists-button-","");
571
- $("#list-settings-" + block).toggle ();
572
- });
573
-
574
- $("#manual-button-"+tab).button ({
575
- }).show ().click (function () {
576
- var block = $(this).attr ("id");
577
- block = block.replace ("manual-button-","");
578
- $("#manual-settings-" + block).toggle ();
579
- });
580
-
581
- $("#misc-button-"+tab).button ({
582
- }).show ().click (function () {
583
- var block = $(this).attr ("id");
584
- block = block.replace ("misc-button-","");
585
- $("#misc-settings-" + block).toggle ();
586
- });
587
-
588
- $("#preview-button-"+tab).button ({
589
- }).show ().click (function () {
590
- var block = $(this).attr ("id");
591
- block = block.replace ("preview-button-","");
592
-
593
- $(this).blur ();
594
-
595
-
596
- var alignment = $("select#block-alignment-"+block+" option:selected").text();
597
-
598
- var css = "";
599
- if (alignment == "None") {
600
- css = $("#css-none-"+block).text ();
601
- } else
602
- if (alignment == "Custom CSS") {
603
- css = $("#custom-css-"+block).val();
604
- } else
605
- if (alignment == "Align Left") {
606
- css = $("#css-left-"+block).text ();
607
- } else
608
- if (alignment == "Align Right") {
609
- css = $("#css-right-"+block).text ();
610
- } else
611
- if (alignment == "Center") {
612
- css = $("#css-center-"+block).text ();
613
- } else
614
- if (alignment == "Float Left") {
615
- css = $("#css-float-left-"+block).text ();
616
- } else
617
- if (alignment == "Float Right") {
618
- css = $("#css-float-right-"+block).text ();
619
- }
620
-
621
- var name = $("#name-label-"+block).text ();
622
-
623
- var window_width = 820;
624
- var window_height = 820;
625
- var nonce = $(this).attr ('nonce');
626
- var page = "/wp-admin/admin-ajax.php?action=ai_preview&preview=" + block + "&ai_check=" + nonce + "&alignment=" + encodeURI (alignment) + "&css=" + encodeURI (css) + "&name=" + encodeURI (name);
627
- var window_left = 120;
628
- var window_top = (screen.height / 2) - (820 / 2);
629
- var preview_window = window.open (page, 'preview','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');
630
- });
631
- }
632
-
633
- function configure_hidden_tab () {
634
- var current_tab;
635
- var tab;
636
-
637
- if (debug) console.log ("");
638
- if (debug) {
639
- var current_time_start = new Date().getTime();
640
- console.log ("since last time: " + ((current_time_start - last_time) / 1000).toFixed (3));
641
- }
642
- if (debug) console.log ("configure_hidden_tab");
643
- if (debug) console.log ("tabs_to_configure: " + tabs_to_configure);
644
-
645
- do {
646
- if (tabs_to_configure.length == 0) {
647
- if (debug_title) $("#plugin_name").css ("color", "#000");
648
- if (debug) console.log ("configure_hidden_tab: DONE");
649
- return;
650
- }
651
- current_tab = tabs_to_configure.pop();
652
- tab = $("#tab-" + current_tab);
653
- } while (tab.hasClass ('configured'));
654
-
655
- if (debug) console.log ("Configuring tab: " + current_tab);
656
-
657
- if (current_tab != 0) configure_tab (current_tab); else configure_tab_0 ();
658
-
659
- if (debug) {
660
- var current_time = new Date().getTime();
661
- console.log ("time: " + ((current_time - current_time_start) / 1000).toFixed (3));
662
- console.log ("TIME: " + ((current_time - start_time) / 1000).toFixed (3));
663
- last_time = current_time;
664
- }
665
-
666
- if (tabs_to_configure.length != 0) setTimeout (configure_hidden_tab, 10); else if (debug_title) $("#plugin_name").css ("color", "#000");
667
- }
668
-
669
-
670
-
671
- if (debug) console.log ("READY");
672
- if (debug_title) $("#plugin_name").css ("color", "#f00");
673
- if (debug) {
674
- var current_time_ready = new Date().getTime();
675
- console.log ("TIME: " + ((current_time_ready - start_time) / 1000).toFixed (3));
676
- }
677
-
678
- $("#blocked-warning.warning-enabled").removeClass ('warning-enabled');
679
- $("#blocked-warning").hide ();
680
-
681
- start = parseInt ($('#ai-form').attr('start'));
682
- end = parseInt ($('#ai-form').attr('end'));
683
- active_tab = parseInt ($("#ai-active-tab").attr ("value"));
684
-
685
- if (debug) console.log ("active_tab: " + active_tab);
686
-
687
- var tabs_array = new Array ();
688
- if (active_tab != 0) tabs_array.push (0);
689
- for (var tab = end; tab >= start; tab --) {
690
- if (tab != active_tab) tabs_array.push (tab);
691
- }
692
- // Concate existing tabs_to_configure (if tab was clicked before page was loaded)
693
- tabs_to_configure = tabs_array.concat (tabs_to_configure);
694
-
695
- setTimeout (configure_hidden_tab, 700);
696
-
697
- var plugin_version = $('#data').attr ('version');
698
- if (javascript_version != plugin_version) {
699
-
700
- // Check page HTML
701
- var javascript_version_parameter = $("script[src*='ad-inserter.js']").attr('src');
702
- if (typeof javascript_version_parameter == 'undefined') $("#javascript-version-parameter-missing").show (); else {
703
- javascript_version_parameter_string = javascript_version_parameter.split('=')[1];
704
- if (typeof javascript_version_parameter_string == 'undefined') {
705
- $("#javascript-version-parameter-missing").show ();
706
- }
707
- else if (javascript_version_parameter_string != plugin_version) {
708
- $("#javascript-version-parameter").show ();
709
- }
710
- }
711
-
712
- $("#javascript-version").html ("&nbsp;javascript " + javascript_version);
713
- $("#javascript-warning").show ();
714
- }
715
-
716
- var css_version = $('#data').css ('font-family').replace(/\"/g, '');
717
- if (css_version.length > 8) $("#blocked-warning").show (); else
718
- if (css_version != plugin_version) {
719
-
720
- // Check page HTML
721
- var css_version_parameter = $("link[href*='ad-inserter.css']").attr('href');
722
- if (typeof css_version_parameter == 'undefined') $("#css-version-parameter-missing").show (); else {
723
- css_version_parameter_string = css_version_parameter.split('=')[1];
724
- if (typeof css_version_parameter_string == 'undefined') {
725
- $("#css-version-parameter-missing").show ();
726
- }
727
- else if (css_version_parameter_string != plugin_version) {
728
- $("#css-version-parameter").show ();
729
- }
730
- }
731
-
732
- $("#css-version").html ("&nbsp;CSS " + css_version);
733
- $("#css-warning").show ();
734
- }
735
-
736
- var index = 16;
737
- if (active_tab != 0) index = active_tab - start;
738
- var block_tabs = $("#ai-tab-container").tabs ({active: index});
739
-
740
- $('#ai-settings').tooltip({
741
- show: {effect: "blind",
742
- delay: 400,
743
- duration: 100}
744
- });
745
-
746
- if (debug_title) $("#plugin_name").css ("color", "#00f");
747
-
748
- if (active_tab == 0) configure_tab_0 (); else configure_tab (active_tab);
749
-
750
- $('#dummy-ranges').hide();
751
- $('#ai-ranges').show();
752
-
753
- $('#dummy-tabs').hide();
754
- $('#ai-tabs').show();
755
-
756
- $('.header button').button().show ();
757
-
758
- $("#ai-form").submit (function (event) {
759
- for (var tab = start; tab <= end; tab ++) {
760
- remove_default_values (tab);
761
- }
762
- });
763
-
764
- if (syntax_highlighting) {
765
- $('.ai-tab').click (function () {
766
- tab_block = $(this).attr ("id");
767
- tab_block = tab_block.replace ("ai-tab","");
768
- active_tab = tab_block;
769
-
770
- if (!$("#tab-" + tab_block).hasClass ('configured')) {
771
- if (debug) console.log ("");
772
- if (debug) console.log ("Empty tab: " + tab_block);
773
- tabs_to_configure.push (tab_block);
774
- setTimeout (configure_hidden_tab, 10);
775
- if (debug) console.log ("tabs_to_configure: " + tabs_to_configure);
776
- } else if (tab_block != 0) {
777
- var editor = ace.edit ("editor-" + tab_block);
778
- editor.getSession ().highlightLines (10000000);
779
- }
780
- });
781
-
782
- $('.ai-plugin-tab').click (function () {
783
- tab_block = $(this).attr ("id");
784
- tab_block = tab_block.replace ("ai-","");
785
-
786
- if (tab_block == 'h') {
787
- var editor = ace.edit ("editor-h");
788
- editor.getSession ().highlightLines (10000000);
789
- } else
790
- if (tab_block == 'f') {
791
- editor = ace.edit ("editor-f");
792
- editor.getSession ().highlightLines (10000000);
793
- }
794
- });
795
- }
796
-
797
- $('#plugin_name').dblclick (function () {
798
- $("#system-debugging").toggle();
799
- });
800
-
801
- if (debug) console.log ("");
802
- if (debug) console.log ("READY END");
803
- if (debug) {
804
- var current_time = new Date().getTime();
805
- console.log ("main time: " + ((current_time - current_time_ready) / 1000).toFixed (3));
806
- }
807
- });
 
 
 
 
1
+ var javascript_version = "2.0.4";
2
+ var ignore_key = true;
3
+ var start = 1;
4
+ var end = 16;
5
+ var active_tab = 1;
6
+ var tabs_to_configure = new Array();
7
+
8
+ var current_tab = 0;
9
+ var next_tab = 0;
10
+
11
+ var syntax_highlighting = false;
12
+ var settings_page = "";
13
+
14
+ var shSettings = {
15
+ "tab_size":"4",
16
+ "use_soft_tabs":"1",
17
+ "word_wrap":"1",
18
+ "highlight_curr_line":"0",
19
+ "key_bindings":"default",
20
+ "full_line_selection":"1",
21
+ "show_line_numbers":"0"};
22
+
23
+ function SyntaxHighlight (id, block, settings) {
24
+ var textarea, editor, form, session, editDiv;
25
+
26
+ this.textarea = textarea = jQuery(id);
27
+ this.settings = settings || {};
28
+
29
+ if (textarea.length === 0 ) { // Element does not exist
30
+ this.valid = false;
31
+ return;
32
+ }
33
+
34
+ this.valid = true;
35
+ editDiv = jQuery('<div>', {
36
+ position: 'absolute',
37
+ // width: textarea.width() + 14,
38
+ // width: 733,
39
+ // height: textarea.height() + 4,
40
+ // height: 384,
41
+ 'class': textarea.attr('class'),
42
+ 'id': 'editor-' + block
43
+ }).insertBefore (textarea);
44
+
45
+ textarea.css('display', 'none');
46
+ this.editor = editor = ace.edit(editDiv[0]);
47
+ this.form = form = textarea.closest('form');
48
+ this.session = session = editor.getSession();
49
+ session.setValue(textarea.val());
50
+
51
+ // copy back to textarea on form submit...
52
+ form.submit (function () {
53
+ var block = textarea.attr ("id").replace ("block-","");
54
+ var editor_disabled = jQuery("#simple-editor-" + block).is(":checked");
55
+ if (!editor_disabled) {
56
+ textarea.val (session.getValue());
57
+ }
58
+ if (textarea.val () == "") {
59
+ textarea.removeAttr ("name");
60
+ }
61
+
62
+ jQuery("#ai-active-tab").attr ("value", active_tab);
63
+ });
64
+
65
+ session.setMode ("ace/mode/html");
66
+
67
+ this.applySettings();
68
+ }
69
+
70
+ SyntaxHighlight.prototype.applySettings = function () {
71
+ var editor = this.editor,
72
+ session = this.session,
73
+ settings = this.settings;
74
+
75
+ editor.renderer.setShowGutter(settings['show_line_numbers'] == 1);
76
+ editor.setHighlightActiveLine(settings['highlight_curr_line'] == 1);
77
+ editor.setSelectionStyle(settings['full_line_selection'] == 1 ? "line" : "text");
78
+ editor.setTheme("ace/theme/" + settings['theme']);
79
+ session.setUseWrapMode(settings['word_wrap'] == 1);
80
+ session.setTabSize(settings['tab_size']);
81
+ session.setUseSoftTabs(settings['use_soft_tabs'] == 1);
82
+ };
83
+
84
+ function change_block_alignment (block) {
85
+ jQuery("select#block-alignment-" + block).change ();
86
+ }
87
+
88
+ jQuery(document).ready(function($) {
89
+
90
+ shSettings ['theme'] = $('#data').attr ('theme');
91
+
92
+ var debug = parseInt ($('#data').attr ('javascript_debugging'));
93
+ var debug_title = false;
94
+
95
+ if (debug) {
96
+ var start_time = new Date().getTime();
97
+ var last_time = start_time;
98
+ debug_title = true;
99
+ }
100
+
101
+ syntax_highlighting = typeof shSettings ['theme'] != 'undefined' && shSettings ['theme'] != 'disabled';
102
+
103
+ var header = $('#ai-settings-' + 'header').length != 0;
104
+ var header_id = 'name';
105
+ var preview_top = (screen.height / 2) - (820 / 2);
106
+
107
+ function remove_default_values (block) {
108
+ $("#tab-" + block + " input:checkbox").each (function() {
109
+ var default_value = $(this).attr ("default");
110
+ var current_value = $(this).is (':checked');
111
+
112
+ if (typeof default_value != 'undefined') {
113
+ default_value = Boolean (parseInt (default_value));
114
+ // console.log ($(this).attr ("name"), ": default_value: ", $(this).attr ("default"), " = ", default_value, ", current_value: ", current_value);
115
+
116
+ if (current_value == default_value) {
117
+ var name = $(this).attr ("name");
118
+ $(this).removeAttr ("name");
119
+ $("#tab-" + block + " [name='" + name + "']").removeAttr ("name");
120
+ // console.log ("REMOVED: ", name);
121
+ }
122
+ }
123
+ // else console.log ("NO DEFAULT VALUE:", $(this).attr ("name"));
124
+ });
125
+
126
+ $("#tab-" + block + " input:text").each (function() {
127
+ var default_value = $(this).attr ("default");
128
+ var current_value = $(this).val ();
129
+
130
+ if (typeof default_value != 'undefined') {
131
+ // console.log ($(this).attr ("name"), ": default_value: ", default_value, ", current_value: ", current_value);
132
+
133
+ if (current_value == default_value) {
134
+ var name = $(this).attr ("name");
135
+ $(this).removeAttr ("name");
136
+ // console.log ("REMOVED: ", name);
137
+ }
138
+ }
139
+ // else console.log ("NO DEFAULT VALUE: ", $(this).attr ("name"));
140
+ });
141
+
142
+ $("#tab-" + block + " select").each (function() {
143
+ var default_value = $(this).attr ("default");
144
+ var current_value = $(this).children ("option:selected");
145
+
146
+ var childern = $(this).children ();
147
+ if (childern.prop ("tagName") == "OPTGROUP") {
148
+ var current_value = "";
149
+ childern.each (function() {
150
+ var selected = $(this).children ("option:selected");
151
+ if (selected.length != 0) {
152
+ current_value = selected;
153
+ return false;
154
+ }
155
+ });
156
+ }
157
+
158
+ if ($(this).attr ("selected-value") == 1) current_value = current_value.attr("value"); else current_value = current_value.text();
159
+
160
+ if (typeof default_value != 'undefined') {
161
+ // console.log ($(this).attr ("name"), ": default_value: ", default_value, ", current_value: ", current_value);
162
+
163
+ if (current_value == default_value) {
164
+ var name = $(this).attr ("name");
165
+ $(this).removeAttr ("name");
166
+ // console.log ("REMOVED: ", name);
167
+ }
168
+ }
169
+ // else console.log ("NO DEFAULT VALUE: ", $(this).attr ("name"));
170
+ });
171
+
172
+ $("#tab-" + block + " input:radio:checked").each (function() {
173
+ var default_value = $(this).attr ("default");
174
+ var current_value = $(this).is (':checked');
175
+
176
+ if (typeof default_value != 'undefined') {
177
+ default_value = Boolean (parseInt (default_value));
178
+ // console.log ($(this).attr ("name"), ": default_value: ", $(this).attr ("default"), " = ", default_value, ", current_value: ", current_value);
179
+
180
+ if (current_value == default_value) {
181
+ var name = $(this).attr ("name");
182
+ $("#tab-" + block + " [name='" + name + "']").removeAttr ("name");
183
+ // console.log ("REMOVED: ", name);
184
+ }
185
+ }
186
+ // else console.log ("NO DEFAULT VALUE: ", $(this).attr ("name"));
187
+ });
188
+ }
189
+
190
+ function configure_editor_language (block) {
191
+
192
+ var editor = ace.edit ("editor-" + block);
193
+
194
+ if ($("input#process-php-"+block).is(":checked")) {
195
+ editor.getSession ().setMode ("ace/mode/php");
196
+ } else editor.getSession ().setMode ("ace/mode/html");
197
+ }
198
+
199
+ function process_display_elements (block) {
200
+
201
+ $("#paragraph-settings-"+block).hide();
202
+ $("#content-settings-"+block).hide();
203
+
204
+ // var display_type = '';
205
+ // $("select#display-type-"+block+" option:selected").each(function() {
206
+ // display_type += $(this).text();
207
+ // });
208
+ var display_type = $("select#display-type-"+block+" option:selected").text();
209
+
210
+ if (display_type == "Before Paragraph" || display_type == "After Paragraph") {
211
+ $("#paragraph-settings-"+block).show();
212
+ } else {
213
+ $("#paragraph-counting-"+block).hide();
214
+ $("#paragraph-clearance-"+block).hide();
215
+ }
216
+
217
+ if (display_type == "Before Paragraph" || display_type == "After Paragraph" || display_type == "Before Content" || display_type == "After Content") {
218
+ $("#content-settings-"+block).show();
219
+ }
220
+
221
+ $("#css-label-"+block).css('display', 'table-cell');
222
+ $("#edit-css-button-"+block).css('display', 'table-cell');
223
+
224
+ $("#css-none-"+block).hide();
225
+ $("#custom-css-"+block).hide();
226
+ $("#css-left-"+block).hide();
227
+ $("#css-right-"+block).hide();
228
+ $("#css-center-"+block).hide();
229
+ $("#css-float-left-"+block).hide();
230
+ $("#css-float-right-"+block).hide();
231
+ $("#css-no-wrapping-"+block).hide();
232
+
233
+ $("#no-wrapping-warning-"+block).hide();
234
+
235
+ var alignment = $("select#block-alignment-"+block+" option:selected").text();
236
+
237
+ if (alignment == "No Wrapping") {
238
+ $("#css-no-wrapping-"+block).css('display', 'table-cell');
239
+ $("#css-label-"+block).hide();
240
+ $("#edit-css-button-"+block).hide();
241
+ if ($("#client-side-detection-"+block).is(":checked")) {
242
+ $("#no-wrapping-warning-"+block).show();
243
+ }
244
+ } else
245
+ if (alignment == "None") {
246
+ $("#css-none-"+block).css('display', 'table-cell');
247
+ } else
248
+ if (alignment == "Custom CSS") {
249
+ $("#css-code-" + block).show();
250
+ $("#custom-css-"+block).show();
251
+ } else
252
+ if (alignment == "Align Left") {
253
+ $("#css-left-"+block).css('display', 'table-cell');
254
+ } else
255
+ if (alignment == "Align Right") {
256
+ $("#css-right-"+block).css('display', 'table-cell');
257
+ } else
258
+ if (alignment == "Center") {
259
+ $("#css-center-"+block).css('display', 'table-cell');
260
+ } else
261
+ if (alignment == "Float Left") {
262
+ $("#css-float-left-"+block).css('display', 'table-cell');
263
+ } else
264
+ if (alignment == "Float Right") {
265
+ $("#css-float-right-"+block).css('display', 'table-cell');
266
+ }
267
+
268
+ if ($('#css-code-'+block).is(':visible')) {
269
+ $("#show-css-button-"+block+" span").text ("Hide CSS");
270
+ } else {
271
+ $("#show-css-button-"+block+" span").text ("Show CSS");
272
+ }
273
+
274
+ var avoid_action = $("select#avoid-action-"+block+" option:selected").text();
275
+
276
+ if (avoid_action == "do not insert")
277
+ $("#check-up-to-"+block).hide (); else
278
+ $("#check-up-to-"+block).show ();
279
+
280
+ if (syntax_highlighting) configure_editor_language (block);
281
+ }
282
+
283
+ function configure_editor (block) {
284
+
285
+ if (debug) console.log ("configure_editor: " + block);
286
+
287
+ if (syntax_highlighting) {
288
+ var syntax_highlighter = new SyntaxHighlight ('#block-' + block, block, shSettings);
289
+ syntax_highlighter.editor.setPrintMarginColumn (1000);
290
+
291
+ $('input#simple-editor-' + block).change (function () {
292
+
293
+ var block = $(this).attr ("id").replace ("simple-editor-","");
294
+ var editor_disabled = $(this).is(":checked");
295
+ var editor = ace.edit ("editor-" + block);
296
+ var textarea = $("#block-" + block);
297
+ var ace_editor = $("#editor-" + block);
298
+
299
+ if (editor_disabled) {
300
+ textarea.val (editor.session.getValue());
301
+ textarea.css ('display', 'block');
302
+ ace_editor.css ('display', 'none');
303
+ } else {
304
+ editor.session.setValue (textarea.val ())
305
+ editor.renderer.updateFull();
306
+ ace_editor.css ('display', 'block');
307
+ textarea.css ('display', 'none');
308
+ }
309
+ });
310
+ }
311
+
312
+ if (block != 'h' && block != 'f' && !header) {
313
+ if ((block - 1) >> 4) {
314
+ $('#block' + '-' + block).removeAttr(header_id);
315
+ $('#display' + '-type-' + block).removeAttr(header_id);
316
+ }
317
+
318
+ if (block >> 2) {
319
+ $('#option' + '-name-' + block).removeAttr(header_id);
320
+ $('#option' + '-length-' + block).removeAttr(header_id);
321
+ }
322
+ }
323
+ }
324
+
325
+ function configure_tab_0 () {
326
+
327
+ if (debug) console.log ("configure_tab_0");
328
+
329
+ $('#tab-0').addClass ('configured');
330
+
331
+ $('#tab-0 input[type=submit], #tab-0 button').button().show ();
332
+
333
+ configure_editor ('h');
334
+ configure_editor ('f');
335
+
336
+ $('#ai-plugin-settings-tab-container').tabs();
337
+ $('#ai-plugin-settings-tabs').show();
338
+
339
+ $("#export-switch-0").button ({
340
+ icons: {
341
+ primary: "ui-icon-gear",
342
+ secondary: "ui-icon-triangle-1-s"
343
+ },
344
+ text: false
345
+ }).show ().click (function () {
346
+ $("#export-container-0").toggle ();
347
+
348
+ if ($("#export-container-0").is(':visible') && !$(this).hasClass ("loaded")) {
349
+ var nonce = $(this).attr ('nonce');
350
+ $("#export_settings_0").load ("/wp-admin/admin-ajax.php?action=ai_preview&export=0&ai_check=" + nonce, function() {
351
+ $("#export_settings_0").attr ("name", "export_settings_0");
352
+ $("#export-switch-0").addClass ("loaded");
353
+ });
354
+ }
355
+ });
356
+
357
+ $("input#process-php-h").change (function() {
358
+ if (syntax_highlighting) configure_editor_language ('h');
359
+ });
360
+
361
+ $("input#process-php-f").change (function() {
362
+ if (syntax_highlighting) configure_editor_language ('f')
363
+ });
364
+
365
+ if (syntax_highlighting) configure_editor_language ('h');
366
+ if (syntax_highlighting) configure_editor_language ('f');
367
+ }
368
+
369
+ function configure_tab (tab) {
370
+
371
+ $('#tab-' + tab).addClass ('configured');
372
+
373
+ $('#tab-' + tab + ' input[type=submit], #tab-' + tab + ' button').button().show ();
374
+
375
+ configure_editor (tab);
376
+
377
+ $("select#display-type-"+tab).change (function() {
378
+ var block = $(this).attr('id').replace ("display-type-", "");
379
+ process_display_elements (block);
380
+ });
381
+ $("select#block-alignment-"+tab).change (function() {
382
+ var block = $(this).attr('id').replace ("block-alignment-", "");
383
+ process_display_elements (block);
384
+ });
385
+ $("input#process-php-"+tab).change (function() {
386
+ var block = $(this).attr('id').replace ("process-php-", "");
387
+ process_display_elements (block);
388
+ });
389
+ $("#enable-shortcode-"+tab).change (function() {
390
+ var block = $(this).attr('id').replace ("enable-shortcode-", "");
391
+ process_display_elements (block);
392
+ });
393
+ $("#enable-php-call-"+tab).change (function() {
394
+ var block = $(this).attr('id').replace ("enable-php-call-", "");
395
+ process_display_elements (block);
396
+ });
397
+ $("select#display-for-devices-"+tab).change (function() {
398
+ var block = $(this).attr('id').replace ("display-for-devices-", "");
399
+ process_display_elements (block);
400
+ });
401
+
402
+ $("#display-homepage-"+tab).change (function() {
403
+ var block = $(this).attr('id').replace ("display-homepage-", "");
404
+ process_display_elements (block);
405
+ });
406
+ $("#display-category-"+tab).change (function() {
407
+ var block = $(this).attr('id').replace ("display-category-", "");
408
+ process_display_elements (block);
409
+ });
410
+ $("#display-search-"+tab).change (function() {
411
+ var block = $(this).attr('id').replace ("display-search-", "");
412
+ process_display_elements (block);
413
+ });
414
+ $("#display-archive-"+tab).change (function() {
415
+ var block = $(this).attr('id').replace ("display-archive-", "");
416
+ process_display_elements (block);
417
+ });
418
+
419
+ $("#client-side-detection-"+tab).change (function() {
420
+ var block = $(this).attr('id').replace ("client-side-detection-", "");
421
+ process_display_elements (block);
422
+ });
423
+
424
+ $("select#avoid-action-"+tab).change (function() {
425
+ var block = $(this).attr('id').replace ("avoid-action-", "");
426
+ process_display_elements (block);
427
+ });
428
+
429
+ process_display_elements (tab);
430
+
431
+ $("#widgets-button-"+tab).button ({
432
+ }).click (function () {
433
+ window.location.href = "widgets.php";
434
+ });
435
+
436
+ $("#show-css-button-"+tab).button ({
437
+ }).show ().click (function () {
438
+ var block = $(this).attr ("id").replace ("show-css-button-","");
439
+ $("#css-code-" + block).toggle ();
440
+
441
+ if ($('#css-code-'+block).is(':visible')) {
442
+ $("#show-css-button-"+block+" span").text ("Hide CSS");
443
+ } else {
444
+ $("#show-css-button-"+block+" span").text ("Show CSS");
445
+ }
446
+ });
447
+
448
+ $("#counting-button-"+tab).button ({
449
+ }).show ().click (function () {
450
+ var block = $(this).attr ("id").replace ("counting-button-","");
451
+ $("#paragraph-counting-" + block).toggle ();
452
+ });
453
+
454
+ $("#clearance-button-"+tab).button ({
455
+ }).show ().click (function () {
456
+ var block = $(this).attr ("id").replace ("clearance-button-","");
457
+ $("#paragraph-clearance-" + block).toggle ();
458
+ });
459
+
460
+ $("#edit-css-button-"+tab).button ({
461
+ }).click (function () {
462
+ var block = $(this).attr('id').replace ("edit-css-button-", "");
463
+
464
+ $("#css-left-"+block).hide();
465
+ $("#css-right-"+block).hide();
466
+ $("#css-center-"+block).hide();
467
+ $("#css-float-left-"+block).hide();
468
+ $("#css-float-right-"+block).hide();
469
+
470
+ var alignment = $("select#block-alignment-"+block+" option:selected").text();
471
+
472
+ if (alignment == "None") {
473
+ $("#css-none-"+block).hide();
474
+ $("#custom-css-"+block).show().val ($("#css-none-"+block).text ());
475
+ $("select#block-alignment-"+block).val ("Custom CSS").change();
476
+ } else
477
+ if (alignment == "Align Left") {
478
+ $("#css-left-"+block).hide();
479
+ $("#custom-css-"+block).show().val ($("#css-left-"+block).text ());
480
+ $("select#block-alignment-"+block).val ("Custom CSS").change();
481
+ } else
482
+ if (alignment == "Align Right") {
483
+ $("#css-right-"+block).hide();
484
+ $("#custom-css-"+block).show().val ($("#css-right-"+block).text ());
485
+ $("select#block-alignment-"+block).val ("Custom CSS").change();
486
+ } else
487
+ if (alignment == "Center") {
488
+ $("#css-center-"+block).hide();
489
+ $("#custom-css-"+block).show().val ($("#css-center-"+block).text ());
490
+ $("select#block-alignment-"+block).val ("Custom CSS").change();
491
+ } else
492
+ if (alignment == "Float Left") {
493
+ $("#css-float-left-"+block).hide();
494
+ $("#custom-css-"+block).show().val ($("#css-float-left-"+block).text ());
495
+ $("select#block-alignment-"+block).val ("Custom CSS").change();
496
+ } else
497
+ if (alignment == "Float Right") {
498
+ $("#css-float-right-"+block).hide();
499
+ $("#custom-css-"+block).show().val ($("#css-float-right-"+block).text ());
500
+ $("select#block-alignment-"+block).val ("Custom CSS").change();
501
+ }
502
+ });
503
+
504
+ $("#name-label-"+tab).click (function () {
505
+ var block = $(this).attr('id').replace ("name-label-", "");
506
+ if (!$('#name-edit-'+block).is(':visible')) {
507
+ $("#name-edit-"+block).css('display', 'table-cell').val ($("#name-label-"+block).text ()).focus ();
508
+ $("#name-label-"+block).hide();
509
+ }
510
+ });
511
+
512
+ $("#name-label-container-"+tab).click (function () {
513
+ var block = $(this).attr('id').replace ("name-label-container-", "");
514
+ if (!$('#name-edit-'+block).is(':visible')) {
515
+ $("#name-edit-"+block).css('display', 'table-cell').val ($("#name-label-"+block).text ()).focus ();
516
+ $("#name-label-"+block).hide();
517
+ }
518
+ });
519
+
520
+ $("#name-edit-"+tab).on('keyup keypress', function (e) {
521
+ var keyCode = e.keyCode || e.which;
522
+ ignore_key = true;
523
+ if (keyCode == 27) {
524
+ var block = $(this).attr('id').replace ("name-edit-", "");
525
+ $("#name-label-"+block).show();
526
+ $("#name-edit-"+block).hide();
527
+ ignore_key = false;
528
+ } else if (keyCode == 13) {
529
+ var block = $(this).attr('id').replace ("name-edit-", "");
530
+ $("#name-label-"+block).show().text ($("#name-edit-"+block).val ());
531
+ $("#name-edit-"+block).hide();
532
+ ignore_key = false;
533
+ e.preventDefault();
534
+ return false;
535
+ }
536
+ }).focusout (function() {
537
+ if (ignore_key) {
538
+ var block = $(this).attr('id').replace ("name-edit-", "");
539
+ $("#name-label-"+block).show().text ($("#name-edit-"+block).val ());
540
+ $("#name-edit-"+block).hide();
541
+ }
542
+ ignore_key = true;
543
+ });
544
+
545
+ $("#export-switch-"+tab).button ({
546
+ icons: {
547
+ secondary: "ui-icon-triangle-1-s"
548
+ },
549
+ text: false
550
+ }).show ().click (function () {
551
+ var block = $(this).attr ("id");
552
+ block = block.replace ("export-switch-","");
553
+ $("#export-container-" + block).toggle ();
554
+
555
+ if ($("#export-container-" + block).is(':visible') && !$(this).hasClass ("loaded")) {
556
+ var nonce = $(this).attr ('nonce');
557
+ $("#export_settings_" + block).load ("/wp-admin/admin-ajax.php?action=ai_preview&export=" + block + "&ai_check=" + nonce, function() {
558
+ $("#export_settings_" + block).attr ("name", "export_settings_" + block);
559
+ $("#export-switch-"+block).addClass ("loaded");
560
+ });
561
+ }
562
+ });
563
+
564
+ $("#device-detection-button-"+tab).button ({
565
+ }).show ().click (function () {
566
+ var block = $(this).attr ("id");
567
+ block = block.replace ("device-detection-button-","");
568
+ $("#device-detection-settings-" + block).toggle ();
569
+ });
570
+
571
+ $("#lists-button-"+tab).button ({
572
+ }).show ().click (function () {
573
+ var block = $(this).attr ("id");
574
+ block = block.replace ("lists-button-","");
575
+ $("#list-settings-" + block).toggle ();
576
+ });
577
+
578
+ $("#manual-button-"+tab).button ({
579
+ }).show ().click (function () {
580
+ var block = $(this).attr ("id");
581
+ block = block.replace ("manual-button-","");
582
+ $("#manual-settings-" + block).toggle ();
583
+ });
584
+
585
+ $("#misc-button-"+tab).button ({
586
+ }).show ().click (function () {
587
+ var block = $(this).attr ("id");
588
+ block = block.replace ("misc-button-","");
589
+ $("#misc-settings-" + block).toggle ();
590
+ });
591
+
592
+ $("#preview-button-"+tab).button ({
593
+ }).show ().click (function () {
594
+ var block = $(this).attr ("id");
595
+ block = block.replace ("preview-button-","");
596
+
597
+ $(this).blur ();
598
+
599
+
600
+ var alignment = $("select#block-alignment-"+block+" option:selected").text();
601
+
602
+ var css = "";
603
+ if (alignment == "None") {
604
+ css = $("#css-none-"+block).text ();
605
+ } else
606
+ if (alignment == "Custom CSS") {
607
+ css = $("#custom-css-"+block).val();
608
+ } else
609
+ if (alignment == "Align Left") {
610
+ css = $("#css-left-"+block).text ();
611
+ } else
612
+ if (alignment == "Align Right") {
613
+ css = $("#css-right-"+block).text ();
614
+ } else
615
+ if (alignment == "Center") {
616
+ css = $("#css-center-"+block).text ();
617
+ } else
618
+ if (alignment == "Float Left") {
619
+ css = $("#css-float-left-"+block).text ();
620
+ } else
621
+ if (alignment == "Float Right") {
622
+ css = $("#css-float-right-"+block).text ();
623
+ }
624
+
625
+ var name = $("#name-label-"+block).text ();
626
+
627
+ var window_width = 820;
628
+ var window_height = 820;
629
+ var nonce = $(this).attr ('nonce');
630
+ var page = "/wp-admin/admin-ajax.php?action=ai_preview&preview=" + block + "&ai_check=" + nonce + "&alignment=" + encodeURI (alignment) + "&css=" + encodeURI (css) + "&name=" + encodeURI (name);
631
+ var window_left = 120;
632
+ var window_top = (screen.height / 2) - (820 / 2);
633
+ var preview_window = window.open (page, 'preview','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');
634
+ });
635
+ }
636
+
637
+ function configure_hidden_tab () {
638
+ var current_tab;
639
+ var tab;
640
+
641
+ if (debug) console.log ("");
642
+ if (debug) {
643
+ var current_time_start = new Date().getTime();
644
+ console.log ("since last time: " + ((current_time_start - last_time) / 1000).toFixed (3));
645
+ }
646
+ if (debug) console.log ("configure_hidden_tab");
647
+ if (debug) console.log ("tabs_to_configure: " + tabs_to_configure);
648
+
649
+ do {
650
+ if (tabs_to_configure.length == 0) {
651
+ if (debug_title) $("#plugin_name").css ("color", "#000");
652
+ if (debug) console.log ("configure_hidden_tab: DONE");
653
+ return;
654
+ }
655
+ current_tab = tabs_to_configure.pop();
656
+ tab = $("#tab-" + current_tab);
657
+ } while (tab.hasClass ('configured'));
658
+
659
+ if (debug) console.log ("Configuring tab: " + current_tab);
660
+
661
+ if (current_tab != 0) configure_tab (current_tab); else configure_tab_0 ();
662
+
663
+ if (debug) {
664
+ var current_time = new Date().getTime();
665
+ console.log ("time: " + ((current_time - current_time_start) / 1000).toFixed (3));
666
+ console.log ("TIME: " + ((current_time - start_time) / 1000).toFixed (3));
667
+ last_time = current_time;
668
+ }
669
+
670
+ if (tabs_to_configure.length != 0) setTimeout (configure_hidden_tab, 10); else if (debug_title) $("#plugin_name").css ("color", "#000");
671
+ }
672
+
673
+
674
+
675
+ if (debug) console.log ("READY");
676
+ if (debug_title) $("#plugin_name").css ("color", "#f00");
677
+ if (debug) {
678
+ var current_time_ready = new Date().getTime();
679
+ console.log ("TIME: " + ((current_time_ready - start_time) / 1000).toFixed (3));
680
+ }
681
+
682
+ $("#blocked-warning").removeClass ('warning-enabled');
683
+ $("#blocked-warning").hide ();
684
+
685
+ start = parseInt ($('#ai-form').attr('start'));
686
+ end = parseInt ($('#ai-form').attr('end'));
687
+ active_tab = parseInt ($("#ai-active-tab").attr ("value"));
688
+
689
+ if (debug) console.log ("active_tab: " + active_tab);
690
+
691
+ var tabs_array = new Array ();
692
+ if (active_tab != 0) tabs_array.push (0);
693
+ for (var tab = end; tab >= start; tab --) {
694
+ if (tab != active_tab) tabs_array.push (tab);
695
+ }
696
+ // Concate existing tabs_to_configure (if tab was clicked before page was loaded)
697
+ tabs_to_configure = tabs_array.concat (tabs_to_configure);
698
+
699
+ setTimeout (configure_hidden_tab, 700);
700
+
701
+ var plugin_version = $('#data').attr ('version');
702
+ if (javascript_version != plugin_version) {
703
+
704
+ // Check page HTML
705
+ var javascript_version_parameter = $("script[src*='ad-inserter.js']").attr('src');
706
+ if (typeof javascript_version_parameter == 'undefined') $("#javascript-version-parameter-missing").show (); else {
707
+ javascript_version_parameter_string = javascript_version_parameter.split('=')[1];
708
+ if (typeof javascript_version_parameter_string == 'undefined') {
709
+ $("#javascript-version-parameter-missing").show ();
710
+ }
711
+ else if (javascript_version_parameter_string != plugin_version) {
712
+ $("#javascript-version-parameter").show ();
713
+ }
714
+ }
715
+
716
+ $("#javascript-version").html ("&nbsp;javascript " + javascript_version);
717
+ $("#javascript-warning").show ();
718
+ }
719
+
720
+ var css_version = $('#data').css ('font-family').replace(/\"/g, '');
721
+ if (css_version.indexOf ('.') == - 1) $("#blocked-warning").show (); else
722
+ if (css_version != plugin_version) {
723
+
724
+ // Check page HTML
725
+ var css_version_parameter = $("link[href*='ad-inserter.css']").attr('href');
726
+ if (typeof css_version_parameter == 'undefined') $("#css-version-parameter-missing").show (); else {
727
+ css_version_parameter_string = css_version_parameter.split('=')[1];
728
+ if (typeof css_version_parameter_string == 'undefined') {
729
+ $("#css-version-parameter-missing").show ();
730
+ }
731
+ else if (css_version_parameter_string != plugin_version) {
732
+ $("#css-version-parameter").show ();
733
+ }
734
+ }
735
+
736
+ $("#css-version").html ("&nbsp;CSS " + css_version);
737
+ $("#css-warning").show ();
738
+ }
739
+
740
+ var index = 16;
741
+ if (active_tab != 0) index = active_tab - start;
742
+ var block_tabs = $("#ai-tab-container").tabs ({active: index});
743
+
744
+ $('#ai-settings').tooltip({
745
+ show: {effect: "blind",
746
+ delay: 400,
747
+ duration: 100}
748
+ });
749
+
750
+ if (debug_title) $("#plugin_name").css ("color", "#00f");
751
+
752
+ if (active_tab == 0) configure_tab_0 (); else configure_tab (active_tab);
753
+
754
+ $('#dummy-ranges').hide();
755
+ $('#ai-ranges').show();
756
+
757
+ $('#dummy-tabs').hide();
758
+ $('#ai-tabs').show();
759
+
760
+ $('.header button').button().show ();
761
+
762
+ $("#ai-form").submit (function (event) {
763
+ for (var tab = start; tab <= end; tab ++) {
764
+ remove_default_values (tab);
765
+ }
766
+ });
767
+
768
+ if (syntax_highlighting) {
769
+ $('.ai-tab').click (function () {
770
+ tab_block = $(this).attr ("id");
771
+ tab_block = tab_block.replace ("ai-tab","");
772
+ active_tab = tab_block;
773
+
774
+ if (!$("#tab-" + tab_block).hasClass ('configured')) {
775
+ if (debug) console.log ("");
776
+ if (debug) console.log ("Empty tab: " + tab_block);
777
+ tabs_to_configure.push (tab_block);
778
+ setTimeout (configure_hidden_tab, 10);
779
+ if (debug) console.log ("tabs_to_configure: " + tabs_to_configure);
780
+ } else if (tab_block != 0) {
781
+ var editor = ace.edit ("editor-" + tab_block);
782
+ editor.getSession ().highlightLines (10000000);
783
+ }
784
+ });
785
+
786
+ $('.ai-plugin-tab').click (function () {
787
+ tab_block = $(this).attr ("id");
788
+ tab_block = tab_block.replace ("ai-","");
789
+
790
+ if (tab_block == 'h') {
791
+ var editor = ace.edit ("editor-h");
792
+ editor.getSession ().highlightLines (10000000);
793
+ } else
794
+ if (tab_block == 'f') {
795
+ editor = ace.edit ("editor-f");
796
+ editor.getSession ().highlightLines (10000000);
797
+ }
798
+ });
799
+ }
800
+
801
+ $('#plugin_name').dblclick (function () {
802
+ $("#system-debugging").toggle();
803
+ });
804
+
805
+ if (debug) console.log ("");
806
+ if (debug) console.log ("READY END");
807
+ if (debug) {
808
+ var current_time = new Date().getTime();
809
+ console.log ("main time: " + ((current_time - current_time_ready) / 1000).toFixed (3));
810
+ }
811
+ });
preview.php CHANGED
@@ -16,13 +16,13 @@ function generate_code_preview ($block) {
16
  <head>
17
  <title><?php echo AD_INSERTER_NAME; ?> Code Preview</title>
18
  <meta name="viewport" content="width=device-width,initial-scale=1.0">
19
- <link rel='stylesheet' href='/wp-content/plugins/ad-inserter/css/ad-inserter.css'>
20
  <script src='https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js'></script>
21
  <script src='https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js'></script>
22
  <link rel='stylesheet' href='https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/smoothness/jquery-ui.css'>
23
- <script src='/wp-content/plugins/ad-inserter/js/jquery.mousewheel.min.js'></script>
24
- <script src='/wp-content/plugins/ad-inserter/js/jquery.ui.spinner.js'></script>
25
- <link rel='stylesheet' href='/wp-content/plugins/ad-inserter/css/jquery.ui.spinner.css'>
26
  <script>
27
 
28
  // initialize_preview ();
@@ -470,8 +470,16 @@ function generate_code_preview ($block) {
470
 
471
  jQuery(document).ready(function($) {
472
  initialize_preview ();
 
 
473
  });
474
 
 
 
 
 
 
 
475
  </script>
476
  <style>
477
  .responsive-table td {
@@ -622,6 +630,8 @@ td.demo-wrapper-background {
622
 
623
  </head>
624
  <body style='font-family: arial; text-align: justify; overflow-x: hidden;'>
 
 
625
  <div style="margin: 0 -8px 10px; display: none;">
626
  <table class="screen" cellspacing=0 cellpadding=0>
627
  <tr>
@@ -644,8 +654,8 @@ td.demo-wrapper-background {
644
  </div>
645
 
646
  <div id="blocked-warning" class="warning-enabled" style="padding: 2px 8px 2px 8px; margin: 8px 0 8px 0; border: 1px solid rgb(221, 221, 221); border-radius: 5px;">
647
- <div style="float: right; text-align: right; margin: 20px 18px 0px 0;">
648
- Please check browser, plugins and ad blockers that may block this page.
649
  </div>
650
  <h3 style="color: red;" title="Error loading page">PAGE BLOCKED</h3>
651
 
@@ -802,7 +812,6 @@ Enable and use at least one display option (Automatic Display, Widget, Shortcode
802
  Enable display on at least one Wordpress page type (Posts, Static pages, Homepage, Category pages, Search Pages, Archive pages).
803
  For Posts and static pages select default value On all Posts / On all Static pages unless you really know what are you doing.</p>
804
  <?php ai_wp_footer_hook (); ?>
805
-
806
  </body>
807
  </html>
808
  <?php
16
  <head>
17
  <title><?php echo AD_INSERTER_NAME; ?> Code Preview</title>
18
  <meta name="viewport" content="width=device-width,initial-scale=1.0">
19
+ <link rel='stylesheet' href='/wp-content/plugins/ad-inserter/css/ad-inserter.css?ver=<?php echo AD_INSERTER_VERSION; ?>'>
20
  <script src='https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js'></script>
21
  <script src='https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js'></script>
22
  <link rel='stylesheet' href='https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/smoothness/jquery-ui.css'>
23
+ <script src='/wp-content/plugins/ad-inserter/includes/js/jquery.mousewheel.min.js?ver=<?php echo AD_INSERTER_VERSION; ?>'></script>
24
+ <script src='/wp-content/plugins/ad-inserter/includes/js/jquery.ui.spinner.js?ver=<?php echo AD_INSERTER_VERSION; ?>'></script>
25
+ <link rel='stylesheet' href='/wp-content/plugins/ad-inserter/css/jquery.ui.spinner.css?ver=<?php echo AD_INSERTER_VERSION; ?>'>
26
  <script>
27
 
28
  // initialize_preview ();
470
 
471
  jQuery(document).ready(function($) {
472
  initialize_preview ();
473
+
474
+ setTimeout (show_blocked_warning, 400);
475
  });
476
 
477
+ function show_blocked_warning () {
478
+ jQuery("#blocked-warning.warning-enabled").show ();
479
+ jQuery("#blocked-warning.warning-enabled .blocked-warning-text").css ('color', '#00f');
480
+ }
481
+
482
+
483
  </script>
484
  <style>
485
  .responsive-table td {
630
 
631
  </head>
632
  <body style='font-family: arial; text-align: justify; overflow-x: hidden;'>
633
+ <div id="data" style="display: none;" version="<?php echo AD_INSERTER_VERSION; ?>"></div>
634
+
635
  <div style="margin: 0 -8px 10px; display: none;">
636
  <table class="screen" cellspacing=0 cellpadding=0>
637
  <tr>
654
  </div>
655
 
656
  <div id="blocked-warning" class="warning-enabled" style="padding: 2px 8px 2px 8px; margin: 8px 0 8px 0; border: 1px solid rgb(221, 221, 221); border-radius: 5px;">
657
+ <div style="float: right; text-align: right; margin: 20px 0px 0px 0;">
658
+ This page was not loaded properly. Please check browser, plugins and ad blockers.
659
  </div>
660
  <h3 style="color: red;" title="Error loading page">PAGE BLOCKED</h3>
661
 
812
  Enable display on at least one Wordpress page type (Posts, Static pages, Homepage, Category pages, Search Pages, Archive pages).
813
  For Posts and static pages select default value On all Posts / On all Static pages unless you really know what are you doing.</p>
814
  <?php ai_wp_footer_hook (); ?>
 
815
  </body>
816
  </html>
817
  <?php
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_i
4
  Tags: adsense, amazon, clickbank, cj, ad, ads, html, javascript, php, code, widget, sidebar, responsive, viewport, rotating, banner, banner rotation, multisite, contextual, shortcodes, widgets, header, footer, users, logged in, not logged in, mobile, desktop, phone, tablet, custom css, category, tag, filter, url, skip
5
  Requires at least: 4.0
6
  Tested up to: 4.6.1
7
- Stable tag: 2.0.2
8
  License: GPLv3
9
 
10
  Insert any ad or HTML/Javascript/PHP code into Wordpress. Perfect for all kinds of ads. 16 code blocks, many display options and features.
@@ -804,6 +804,10 @@ AD CODE RIGHT
804
 
805
  == Changelog ==
806
 
 
 
 
 
807
 
808
  = 2.0.3 =
809
  - Debugging functions in admin toolbar available only for administrators
@@ -1054,6 +1058,11 @@ AD CODE RIGHT
1054
 
1055
  == Upgrade Notice ==
1056
 
 
 
 
 
 
1057
  = 2.0.3 =
1058
  Debugging functions in admin toolbar available only for administrators;
1059
  Added option to hide debugging functions in admin toolbar;
4
  Tags: adsense, amazon, clickbank, cj, ad, ads, html, javascript, php, code, widget, sidebar, responsive, viewport, rotating, banner, banner rotation, multisite, contextual, shortcodes, widgets, header, footer, users, logged in, not logged in, mobile, desktop, phone, tablet, custom css, category, tag, filter, url, skip
5
  Requires at least: 4.0
6
  Tested up to: 4.6.1
7
+ Stable tag: 2.0.3
8
  License: GPLv3
9
 
10
  Insert any ad or HTML/Javascript/PHP code into Wordpress. Perfect for all kinds of ads. 16 code blocks, many display options and features.
804
 
805
  == Changelog ==
806
 
807
+ = 2.0.4 =
808
+ - Bug fix: Cursor position always at the end of block name
809
+ - State of debugging functions saved to cookie
810
+ - Few minor bug fixes
811
 
812
  = 2.0.3 =
813
  - Debugging functions in admin toolbar available only for administrators
1058
 
1059
  == Upgrade Notice ==
1060
 
1061
+ = 2.0.4 =
1062
+ Bug fix: Cursor position always at the end of block name;
1063
+ State of debugging functions saved to cookie;
1064
+ Few minor bug fixes
1065
+
1066
  = 2.0.3 =
1067
  Debugging functions in admin toolbar available only for administrators;
1068
  Added option to hide debugging functions in admin toolbar;
settings.php CHANGED
@@ -1220,7 +1220,7 @@ function generate_settings_form (){
1220
  </div>
1221
 
1222
  <div class="ai-form" style="padding: 2px 8px 6px 8px; margin: 8px 0 8px 0; border: 1px solid rgb(221, 221, 221); border-radius: 5px; background: #fff;">
1223
- <a href="http://tinymonitor.com/" target="_blank"><img src="<?php echo AD_INSERTER_PLUGIN_IMAGES_URL; ?>monitors.png" alt="Tiny Monitor" /></a>
1224
  <p style="text-align: justify;"><a href="http://tinymonitor.com/" target="_blank">Tiny Monitor</a> is a PHP application that can monitor your Google AdSense earnings,
1225
  CJ earnings and PayPal transactions. The purpose of Tiny Monitor is to download data from original sources and present them in a compact way on a single web page.
1226
  With Tiny Monitor you have all the data at one place so you dont have to log in to various pages just to check earnings.
@@ -1232,13 +1232,21 @@ function generate_settings_form (){
1232
  }
1233
  ?>
1234
  <script type="text/javascript">
1235
- setTimeout (show_blocked_warning, 4000);
 
 
 
 
1236
 
1237
  function show_blocked_warning () {
1238
  jQuery("#blocked-warning.warning-enabled").show ();
1239
  jQuery("#blocked-warning.warning-enabled .blocked-warning-text").css ('color', '#00f');
1240
- }
1241
 
 
 
 
 
 
1242
  </script>
1243
 
1244
  <?php
1220
  </div>
1221
 
1222
  <div class="ai-form" style="padding: 2px 8px 6px 8px; margin: 8px 0 8px 0; border: 1px solid rgb(221, 221, 221); border-radius: 5px; background: #fff;">
1223
+ <a href="http://tinymonitor.com/" target="_blank"><img id="monitors-image" src="<?php echo AD_INSERTER_PLUGIN_IMAGES_URL; ?>monitors.png" alt="Tiny Monitor" /></a>
1224
  <p style="text-align: justify;"><a href="http://tinymonitor.com/" target="_blank">Tiny Monitor</a> is a PHP application that can monitor your Google AdSense earnings,
1225
  CJ earnings and PayPal transactions. The purpose of Tiny Monitor is to download data from original sources and present them in a compact way on a single web page.
1226
  With Tiny Monitor you have all the data at one place so you dont have to log in to various pages just to check earnings.
1232
  }
1233
  ?>
1234
  <script type="text/javascript">
1235
+ // setTimeout (show_blocked_warning, 4000);
1236
+
1237
+ jQuery(document).ready(function($) {
1238
+ setTimeout (show_blocked_warning, 400);
1239
+ });
1240
 
1241
  function show_blocked_warning () {
1242
  jQuery("#blocked-warning.warning-enabled").show ();
1243
  jQuery("#blocked-warning.warning-enabled .blocked-warning-text").css ('color', '#00f');
 
1244
 
1245
+ var image = jQuery("#monitors-image");
1246
+ if (image.height () < 100) {
1247
+ image.hide ().after (image.clone ().attr ('class', '').attr ("id", 'monitors-image-ajax').attr ('src', '/wp-admin/admin-ajax.php?action=ai_preview&image=monitors.png&ai_check=<?php echo wp_create_nonce ('adinserter_data'); ?>').css ('display', 'block'));
1248
+ }
1249
+ }
1250
  </script>
1251
 
1252
  <?php