Accordion Shortcodes - Version 2.2

Version Description

  • NEW: Accessible for users requiring tabbed keyboard navigation control (this took way too long)
  • NEW: A classname of 'read' is now added to accordion item titles as they are opened. This allows you to style all read accordion items.
  • NEW: Compatibility mode adds a prefix to the shortcodes for themes that already include accordion shortcodes with matching names.
  • FIXED: Animation queue not clearing.
  • Now compatible up to WordPress 4.2
Download this release

Release Info

Developer philbuchanan
Plugin Icon 128x128 Accordion Shortcodes
Version 2.2
Comparing to
See all releases

Code changes from version 2.1.1 to 2.2

accordion-shortcodes.php CHANGED
@@ -2,7 +2,7 @@
2
  /**
3
  * Plugin Name: Accordion Shortcodes
4
  * Description: Shortcodes for creating responsive accordion drop-downs.
5
- * Version: 2.1.1
6
  * Author: Phil Buchanan
7
  * Author URI: http://philbuchanan.com
8
  */
@@ -14,15 +14,68 @@ if (!class_exists('Accordion_Shortcodes')) :
14
 
15
  class Accordion_Shortcodes {
16
 
17
- private $plugin_version = '2.1.1';
18
- private $add_script = false;
19
- private $script_data = array();
20
- private $id = 0;
21
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
  private $wrapper_tag = 'div';
23
- private $title_tag = 'h3';
 
 
 
 
 
 
 
 
 
 
 
 
24
  private $content_tag = 'div';
25
 
 
 
 
 
 
 
 
26
  function __construct() {
27
  $basename = plugin_basename(__FILE__);
28
 
@@ -33,31 +86,56 @@ class Accordion_Shortcodes {
33
  add_action('wp_enqueue_scripts', array($this, 'register_script'));
34
 
35
  // Add shortcodes
36
- add_shortcode('accordion', array($this, 'accordion_shortcode'));
37
- add_shortcode('accordion-item', array($this, 'accordion_item_shortcode'));
 
 
38
 
39
  // Print script in wp_footer
40
  add_action('wp_footer', array($this, 'print_script'));
41
 
42
- // Add link to documentation
43
- add_filter("plugin_action_links_$basename", array($this, 'add_documentation_link'));
44
-
45
- // Add buttons to editor
46
  if (is_admin()) {
 
 
 
 
47
  $Accordion_Shortcode_Tinymce_Extensions = new Accordion_Shortcode_Tinymce_Extensions;
48
  }
49
  }
50
 
51
- // Registers the minified accordion JavaScript file
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
52
  public function register_script() {
53
  $min = (defined('SCRIPT_DEBUG') && SCRIPT_DEBUG) ? '' : '.min';
54
  wp_register_script('accordion-shortcodes-script', plugins_url('accordion' . $min . '.js', __FILE__), array('jquery'), $this->plugin_version, true);
55
  }
56
 
57
- // Prints the minified accordion JavaScript file in the footer
 
 
 
 
 
 
58
  public function print_script() {
59
  // Check to see if shortcodes are used on page
60
- if (!$this->add_script) return;
61
 
62
  wp_enqueue_script('accordion-shortcodes-script');
63
 
@@ -65,12 +143,27 @@ class Accordion_Shortcodes {
65
  wp_localize_script('accordion-shortcodes-script', 'accordionShortcodesSettings', $this->script_data);
66
  }
67
 
68
- // Checks for boolean value
69
- private function parse_boolean($value) {
 
 
 
 
 
 
 
70
  return filter_var($value, FILTER_VALIDATE_BOOLEAN);
71
  }
72
 
73
- // Check for valid HTML tag
 
 
 
 
 
 
 
 
74
  private function check_html_tag($tag) {
75
  $tag = preg_replace('/\s/', '', $tag);
76
  $tags = array('h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'p', 'div');
@@ -79,13 +172,56 @@ class Accordion_Shortcodes {
79
  else return $this->title_tag;
80
  }
81
 
82
- // Accordion wrapper shortcode
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
83
  public function accordion_shortcode($atts, $content = null) {
84
  // The shortcode is used on the page, so load the JavaScript
85
- $this->add_script = true;
86
 
87
- // Increment accordion counter
88
- $this->id++;
 
89
 
90
  extract(shortcode_atts(array(
91
  'tag' => '',
@@ -116,26 +252,30 @@ class Accordion_Shortcodes {
116
 
117
  // Set settings object (for use in JavaScript)
118
  $script_data = array(
119
- 'id' => "accordion-$this->id",
120
- 'autoClose' => $this->parse_boolean($autoclose),
121
- 'openFirst' => $this->parse_boolean($openfirst),
122
- 'openAll' => $this->parse_boolean($openall),
123
- 'clickToClose' => $this->parse_boolean($clicktoclose),
124
- 'scroll' => $scroll
125
  );
126
 
127
  // Add this shortcodes settings instance to the global script data array
128
  $this->script_data[] = $script_data;
129
 
130
- return sprintf('<%2$s id="%3$s" class="accordion no-js%4$s">%1$s</%2$s>',
131
  do_shortcode($content),
132
  $this->wrapper_tag,
133
- "accordion-$this->id",
134
  $class ? " $class" : ''
135
  );
136
  }
137
 
138
- // Accordion item shortcode
 
 
 
 
139
  public function accordion_item_shortcode($atts, $content = null) {
140
  extract(shortcode_atts(array(
141
  'title' => '',
@@ -144,21 +284,38 @@ class Accordion_Shortcodes {
144
  'class' => ''
145
  ), $atts, 'accordion-item'));
146
 
147
- return sprintf('<%4$s class="accordion-title%6$s"%3$s>%1$s</%4$s><%5$s class="accordion-content">%2$s</%5$s>',
148
- $title ? $title : '<span style="color:red;">' . __('Please enter a title attribute', 'accordion_shortcodes') . '</span>',
149
- do_shortcode($content),
150
- $id ? ' id="' . $id . '"' : '',
 
 
151
  $tag ? $this->check_html_tag($tag) : $this->title_tag,
152
- $this->content_tag,
 
 
153
  $class ? " $class" : ''
154
  );
 
 
 
 
 
 
 
 
 
155
  }
156
 
157
- // Add documentation link on plugin page
 
 
 
 
158
  public function add_documentation_link($links) {
159
  array_push($links, sprintf('<a href="%s">%s</a>',
160
  'http://wordpress.org/plugins/accordion-shortcodes/',
161
- __('Documentation', 'accordion_shortcodes')
162
  ));
163
 
164
  return $links;
2
  /**
3
  * Plugin Name: Accordion Shortcodes
4
  * Description: Shortcodes for creating responsive accordion drop-downs.
5
+ * Version: 2.2
6
  * Author: Phil Buchanan
7
  * Author URI: http://philbuchanan.com
8
  */
14
 
15
  class Accordion_Shortcodes {
16
 
17
+ /**
18
+ * Current plugin version number
19
+ */
20
+ private $plugin_version = '2.2';
21
 
22
+
23
+
24
+ /**
25
+ * Should the accordion JavaScript file be loaded the on the current page
26
+ * False by default
27
+ */
28
+ private $load_script = false;
29
+
30
+
31
+
32
+ /**
33
+ * Holds all the accordion shortcodes group settings
34
+ */
35
+ private $script_data = array();
36
+
37
+
38
+
39
+ /**
40
+ * Count of each accordion group on a page
41
+ */
42
+ private $group_count = 0;
43
+
44
+
45
+
46
+ /**
47
+ * Count for each accordion item within an accordion group
48
+ */
49
+ private $item_count = 0;
50
+
51
+
52
+
53
+ /**
54
+ * Holds the accordion group container HTML tag
55
+ */
56
  private $wrapper_tag = 'div';
57
+
58
+
59
+
60
+ /**
61
+ * Holds the accordion item title HTML tag
62
+ */
63
+ private $title_tag = 'h3';
64
+
65
+
66
+
67
+ /**
68
+ * Holds the accordion item content container HTML tag
69
+ */
70
  private $content_tag = 'div';
71
 
72
+
73
+
74
+ /**
75
+ * Class constructor
76
+ * Sets up the plugin, including: textdomain, adding shortcodes, registering
77
+ * scripts and adding buttons.
78
+ */
79
  function __construct() {
80
  $basename = plugin_basename(__FILE__);
81
 
86
  add_action('wp_enqueue_scripts', array($this, 'register_script'));
87
 
88
  // Add shortcodes
89
+ $prefix = $this->get_compatibility_prefix();
90
+
91
+ add_shortcode($prefix . 'accordion', array($this, 'accordion_shortcode'));
92
+ add_shortcode($prefix . 'accordion-item', array($this, 'accordion_item_shortcode'));
93
 
94
  // Print script in wp_footer
95
  add_action('wp_footer', array($this, 'print_script'));
96
 
 
 
 
 
97
  if (is_admin()) {
98
+ // Add link to documentation on plugin page
99
+ add_filter("plugin_action_links_$basename", array($this, 'add_documentation_link'));
100
+
101
+ // Add buttons to MCE editor
102
  $Accordion_Shortcode_Tinymce_Extensions = new Accordion_Shortcode_Tinymce_Extensions;
103
  }
104
  }
105
 
106
+
107
+
108
+ /**
109
+ * Get the compatibility mode prefix
110
+ *
111
+ * return string The compatibility mode prefix
112
+ */
113
+ private function get_compatibility_prefix() {
114
+ return defined('AS_COMPATIBILITY') && AS_COMPATIBILITY ? 'as-' : '';
115
+ }
116
+
117
+
118
+
119
+ /**
120
+ * Registers the JavaScript file
121
+ * If SCRIPT_DEBUG is set to true in the config file, the un-minified
122
+ * version of the JavaScript file will be used.
123
+ */
124
  public function register_script() {
125
  $min = (defined('SCRIPT_DEBUG') && SCRIPT_DEBUG) ? '' : '.min';
126
  wp_register_script('accordion-shortcodes-script', plugins_url('accordion' . $min . '.js', __FILE__), array('jquery'), $this->plugin_version, true);
127
  }
128
 
129
+
130
+
131
+ /**
132
+ * Prints the accordion JavaScript in the footer
133
+ * This inlcludes both the accordion jQuery plugin file registered by
134
+ * 'register_script()' and the accordion settings JavaScript variable.
135
+ */
136
  public function print_script() {
137
  // Check to see if shortcodes are used on page
138
+ if (!$this->load_script) return;
139
 
140
  wp_enqueue_script('accordion-shortcodes-script');
141
 
143
  wp_localize_script('accordion-shortcodes-script', 'accordionShortcodesSettings', $this->script_data);
144
  }
145
 
146
+
147
+
148
+ /**
149
+ * Checks if a value is boolean
150
+ *
151
+ * @param string $value The value to test
152
+ * return bool
153
+ */
154
+ private function is_boolean($value) {
155
  return filter_var($value, FILTER_VALIDATE_BOOLEAN);
156
  }
157
 
158
+
159
+
160
+ /**
161
+ * Check for valid HTML tag
162
+ * Checks the supplied HTML tag against a list of approved tags.
163
+ *
164
+ * @param string $tag The HTML tag to test
165
+ * return string A valid HTML tag
166
+ */
167
  private function check_html_tag($tag) {
168
  $tag = preg_replace('/\s/', '', $tag);
169
  $tags = array('h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'p', 'div');
172
  else return $this->title_tag;
173
  }
174
 
175
+
176
+
177
+ /**
178
+ * Check for valid scroll value
179
+ * Scroll value must be either an int or bool
180
+ *
181
+ * @param int/bool $scroll The scroll offset integer or true/false
182
+ * return int/bool The scroll offset integer else true/false
183
+ */
184
+ private function check_scroll_value($scroll) {
185
+ $int = intval($scroll);
186
+
187
+ if (is_int($int) && $int != 0) {
188
+ return $int;
189
+ }
190
+ else {
191
+ return $this->is_boolean($scroll);
192
+ }
193
+ }
194
+
195
+
196
+
197
+ /**
198
+ * Get's the ID for an accordion item
199
+ *
200
+ * @param string $id If the user set an ID
201
+ * return array The IDs for the accordion title and item
202
+ */
203
+ private function get_accordion_id($id) {
204
+ $title_id = $id ? $id : "accordion-$this->group_count-t$this->item_count";
205
+ $content_id = $id ? "content-$id" : "accordion-$this->group_count-c$this->item_count";
206
+
207
+ return array(
208
+ 'title' => $title_id,
209
+ 'content' => $content_id
210
+ );
211
+ }
212
+
213
+
214
+
215
+ /**
216
+ * Accordion group shortcode
217
+ */
218
  public function accordion_shortcode($atts, $content = null) {
219
  // The shortcode is used on the page, so load the JavaScript
220
+ $this->load_script = true;
221
 
222
+ // Set accordion counters
223
+ $this->group_count++;
224
+ $this->item_count = 0;
225
 
226
  extract(shortcode_atts(array(
227
  'tag' => '',
252
 
253
  // Set settings object (for use in JavaScript)
254
  $script_data = array(
255
+ 'id' => "accordion-$this->group_count",
256
+ 'autoClose' => $this->is_boolean($autoclose),
257
+ 'openFirst' => $this->is_boolean($openfirst),
258
+ 'openAll' => $this->is_boolean($openall),
259
+ 'clickToClose' => $this->is_boolean($clicktoclose),
260
+ 'scroll' => $this->check_scroll_value($scroll)
261
  );
262
 
263
  // Add this shortcodes settings instance to the global script data array
264
  $this->script_data[] = $script_data;
265
 
266
+ return sprintf('<%2$s id="%3$s" class="accordion no-js%4$s" role="tablist">%1$s</%2$s>',
267
  do_shortcode($content),
268
  $this->wrapper_tag,
269
+ "accordion-$this->group_count",
270
  $class ? " $class" : ''
271
  );
272
  }
273
 
274
+
275
+
276
+ /**
277
+ * Accordion item shortcode
278
+ */
279
  public function accordion_item_shortcode($atts, $content = null) {
280
  extract(shortcode_atts(array(
281
  'title' => '',
284
  'class' => ''
285
  ), $atts, 'accordion-item'));
286
 
287
+ // Increment accordion item count
288
+ $this->item_count++;
289
+
290
+ $ids = $this->get_accordion_id($id);
291
+
292
+ $accordion_title = sprintf('<%1$s id="%3$s" class="accordion-title%5$s" role="tab" aria-controls="%4$s" aria-selected="false" aria-expanded="false">%2$s</%1$s>',
293
  $tag ? $this->check_html_tag($tag) : $this->title_tag,
294
+ $title ? $title : '<span style="color:red;">' . __('Please enter a title attribute', 'accordion_shortcodes') . '</span>',
295
+ $ids['title'],
296
+ $ids['content'],
297
  $class ? " $class" : ''
298
  );
299
+
300
+ $accordion_content = sprintf('<%1$s id="%3$s" class="accordion-content" role="tabpanel" aria-labelledby="%4$s" aria-hidden="true">%2$s</%1$s>',
301
+ $this->content_tag,
302
+ do_shortcode($content),
303
+ $ids['content'],
304
+ $ids['title']
305
+ );
306
+
307
+ return $accordion_title . $accordion_content;
308
  }
309
 
310
+
311
+
312
+ /**
313
+ * Add documentation link on plugin page
314
+ */
315
  public function add_documentation_link($links) {
316
  array_push($links, sprintf('<a href="%s">%s</a>',
317
  'http://wordpress.org/plugins/accordion-shortcodes/',
318
+ _x('Documentation', 'link to documentation on wordpress.org site', 'accordion_shortcodes')
319
  ));
320
 
321
  return $links;
accordion.js CHANGED
@@ -27,54 +27,134 @@
27
  scroll: false
28
  }, options);
29
 
30
- // Remove 'no-js' class since JavaScript is enabled
 
 
 
 
 
 
31
  $('.accordion').removeClass('no-js');
32
 
33
- // Set the scroll offset
34
  settings.scrollOffset = Math.floor(parseInt(settings.scroll)) | 0;
35
 
36
- // Should any accordions be opened on load?
37
- if (selectedId.length && selectedId.hasClass('accordion-title')) {
38
- selectedId.addClass('open');
39
- selectedId.next().slideDown(duration);
40
- }
41
- else if (settings.openAll) {
42
- allPanels.show();
43
- allTitles.addClass('open');
44
- }
45
- else if (settings.openFirst) {
46
- firstTitle.addClass('open');
47
- firstPanel.slideDown(duration);
48
- }
49
 
50
- // Add event listener
51
- allTitles.click(function() {
 
 
 
 
52
  // Only open the item if item isn't already open
53
  if (!$(this).hasClass('open')) {
54
  // Close all accordion items
55
  if (settings.autoClose) {
56
- allPanels.slideUp(duration);
57
- allTitles.removeClass('open');
 
58
  }
59
 
60
  // Open clicked item
61
- $(this).next().slideDown(duration, function() {
62
- // Scroll page to the title
63
- if (settings.scroll) {
64
- $('html, body').animate({
65
- scrollTop: $(this).prev().offset().top - settings.scrollOffset
66
- }, duration);
67
- }
68
- });
69
- $(this).addClass('open');
70
  }
71
  // If item is open, and click to close is set, close it
72
  else if (settings.clickToClose) {
73
- $(this).next().slideUp(duration);
74
- $(this).removeClass('open');
75
  }
76
 
77
  return false;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
78
  });
79
 
80
  // Listen for hash changes (in page jump links for accordions)
@@ -82,20 +162,17 @@
82
  selectedId = $(window.location.hash);
83
 
84
  if (selectedId.length && selectedId.hasClass('accordion-title')) {
85
- allPanels.slideUp(duration);
86
- allTitles.removeClass('open');
87
- selectedId.addClass('open');
 
 
88
 
89
- selectedId.next().slideDown(duration, function() {
90
- $('html, body').animate({
91
- scrollTop: $(this).prev().offset().top - settings.scrollOffset
92
- }, duration);
93
- });
94
  }
95
  });
96
 
97
  return this;
98
-
99
  };
100
 
101
 
27
  scroll: false
28
  }, options);
29
 
30
+
31
+
32
+ /**
33
+ * Initial setup
34
+ * Remove the 'no-js' class since JavaScript is enabled and set the
35
+ * scroll offset.
36
+ */
37
  $('.accordion').removeClass('no-js');
38
 
 
39
  settings.scrollOffset = Math.floor(parseInt(settings.scroll)) | 0;
40
 
 
 
 
 
 
 
 
 
 
 
 
 
 
41
 
42
+
43
+ /**
44
+ * Defualt click function
45
+ * Called when an accordion title is clicked.
46
+ */
47
+ function clickHandler() {
48
  // Only open the item if item isn't already open
49
  if (!$(this).hasClass('open')) {
50
  // Close all accordion items
51
  if (settings.autoClose) {
52
+ allTitles.each(function() {
53
+ closeItem($(this));
54
+ });
55
  }
56
 
57
  // Open clicked item
58
+ openItem($(this));
 
 
 
 
 
 
 
 
59
  }
60
  // If item is open, and click to close is set, close it
61
  else if (settings.clickToClose) {
62
+ closeItem($(this));
 
63
  }
64
 
65
  return false;
66
+ }
67
+
68
+
69
+
70
+ /**
71
+ * Opens an accordion item
72
+ * Also handles accessibility attribute settings.
73
+ *
74
+ * @param object ele The accordion item title to open
75
+ */
76
+ function openItem(ele) {
77
+ // Clear/stop any previous animations before revealing content
78
+ ele.next().clearQueue().stop().slideDown(duration, function() {
79
+ // Scroll page to the title
80
+ if (settings.scroll) {
81
+ $('html, body').animate({
82
+ scrollTop: $(this).prev().offset().top - settings.scrollOffset
83
+ }, duration);
84
+ }
85
+ });
86
+ ele.addClass('open');
87
+
88
+ // Mark accordion item as read
89
+ ele.addClass('read');
90
+
91
+ // Set accessibility attributes
92
+ ele.attr({
93
+ 'aria-selected': 'true',
94
+ 'aria-expanded': 'true'
95
+ });
96
+
97
+ ele.next().attr({
98
+ 'aria-hidden': 'false'
99
+ });
100
+ }
101
+
102
+
103
+
104
+ /**
105
+ * Closes an accordion item
106
+ * Also handles accessibility attribute settings.
107
+ *
108
+ * @param object ele The accordion item title to open
109
+ */
110
+ function closeItem(ele) {
111
+ ele.next().slideUp(duration);
112
+ ele.removeClass('open');
113
+
114
+ // Set accessibility attributes
115
+ ele.attr({
116
+ 'aria-selected': 'false',
117
+ 'aria-expanded': 'false'
118
+ });
119
+
120
+ ele.next().attr({
121
+ 'aria-hidden': 'true'
122
+ });
123
+ }
124
+
125
+
126
+
127
+ /**
128
+ * Should any accordions be opened on load?
129
+ * Open first, open all or open based on URL hash.
130
+ */
131
+ if (selectedId.length && selectedId.hasClass('accordion-title')) {
132
+ openItem(selectedId);
133
+ }
134
+ else if (settings.openAll) {
135
+ allTitles.each(function() {
136
+ openItem($(this));
137
+ });
138
+ }
139
+ else if (settings.openFirst) {
140
+ openItem(firstTitle);
141
+ }
142
+
143
+
144
+
145
+ /**
146
+ * Add event listeners
147
+ */
148
+ allTitles.click(clickHandler);
149
+
150
+ allTitles.keydown(function(e) {
151
+ var code = e.which;
152
+
153
+ // 13 = Return, 32 = Space
154
+ if ((code === 13) || (code === 32)) {
155
+ // Simulate click on title
156
+ $(this).click();
157
+ }
158
  });
159
 
160
  // Listen for hash changes (in page jump links for accordions)
162
  selectedId = $(window.location.hash);
163
 
164
  if (selectedId.length && selectedId.hasClass('accordion-title')) {
165
+ if (settings.autoClose) {
166
+ allTitles.each(function() {
167
+ closeItem($(this));
168
+ });
169
+ }
170
 
171
+ openItem(selectedId);
 
 
 
 
172
  }
173
  });
174
 
175
  return this;
 
176
  };
177
 
178
 
accordion.min.js CHANGED
@@ -1 +1 @@
1
- (function(e){"use strict";var t,n;e.fn.accordionShortcodes=function(t){var n=this.children(".accordion-title"),r=this.children(".accordion-content").hide(),i=n.first(),s=r.first(),o=e(window.location.hash),u=250,a=e.extend({autoClose:true,openFirst:false,openAll:false,clickToClose:false,scroll:false},t);e(".accordion").removeClass("no-js");a.scrollOffset=Math.floor(parseInt(a.scroll))|0;if(o.length&&o.hasClass("accordion-title")){o.addClass("open");o.next().slideDown(u)}else if(a.openAll){r.show();n.addClass("open")}else if(a.openFirst){i.addClass("open");s.slideDown(u)}n.click(function(){if(!e(this).hasClass("open")){if(a.autoClose){r.slideUp(u);n.removeClass("open")}e(this).next().slideDown(u,function(){if(a.scroll){e("html, body").animate({scrollTop:e(this).prev().offset().top-a.scrollOffset},u)}});e(this).addClass("open")}else if(a.clickToClose){e(this).next().slideUp(u);e(this).removeClass("open")}return false});e(window).on("hashchange",function(){o=e(window.location.hash);if(o.length&&o.hasClass("accordion-title")){r.slideUp(u);n.removeClass("open");o.addClass("open");o.next().slideDown(u,function(){e("html, body").animate({scrollTop:e(this).prev().offset().top-a.scrollOffset},u)})}});return this};for(var t=0;t<accordionShortcodesSettings.length;t+=1){n=accordionShortcodesSettings[t];e("#"+n.id).accordionShortcodes(n)}})(jQuery)
1
+ !function(o){"use strict";var t,e;o.fn.accordionShortcodes=function(t){function e(){return o(this).hasClass("open")?d.clickToClose&&s(o(this)):(d.autoClose&&i.each(function(){s(o(this))}),n(o(this))),!1}function n(t){t.next().clearQueue().stop().slideDown(l,function(){d.scroll&&o("html, body").animate({scrollTop:o(this).prev().offset().top-d.scrollOffset},l)}),t.addClass("open"),t.addClass("read"),t.attr({"aria-selected":"true","aria-expanded":"true"}),t.next().attr({"aria-hidden":"false"})}function s(o){o.next().slideUp(l),o.removeClass("open"),o.attr({"aria-selected":"false","aria-expanded":"false"}),o.next().attr({"aria-hidden":"true"})}var i=this.children(".accordion-title"),a=this.children(".accordion-content").hide(),c=i.first(),r=(a.first(),o(window.location.hash)),l=250,d=o.extend({autoClose:!0,openFirst:!1,openAll:!1,clickToClose:!1,scroll:!1},t);return o(".accordion").removeClass("no-js"),d.scrollOffset=0|Math.floor(parseInt(d.scroll)),r.length&&r.hasClass("accordion-title")?n(r):d.openAll?i.each(function(){n(o(this))}):d.openFirst&&n(c),i.click(e),i.keydown(function(t){var e=t.which;(13===e||32===e)&&o(this).click()}),o(window).on("hashchange",function(){r=o(window.location.hash),r.length&&r.hasClass("accordion-title")&&(d.autoClose&&i.each(function(){s(o(this))}),n(r))}),this};for(var t=0;t<accordionShortcodesSettings.length;t+=1)e=accordionShortcodesSettings[t],o("#"+e.id).accordionShortcodes(e)}(jQuery);
languages/default.po CHANGED
@@ -1,24 +1,102 @@
1
  msgid ""
2
  msgstr ""
3
  "Project-Id-Version: Accordion Shortcodes\n"
4
- "POT-Creation-Date: 2014-07-28 14:53-0500\n"
5
- "PO-Revision-Date: 2014-07-28 14:53-0500\n"
6
  "Last-Translator: Phil Buchanan <info@philbuchanan.com>\n"
7
  "Language-Team: \n"
8
  "Language: en_CA\n"
9
  "MIME-Version: 1.0\n"
10
  "Content-Type: text/plain; charset=UTF-8\n"
11
  "Content-Transfer-Encoding: 8bit\n"
12
- "X-Generator: Poedit 1.6.7\n"
13
  "X-Poedit-KeywordsList: __;_e;_n:1,2;_x:1,2c;_ex:1,2c\n"
14
  "X-Poedit-Basepath: .\n"
15
  "Plural-Forms: nplurals=2; plural=n != 1;\n"
16
  "X-Poedit-SearchPath-0: ..\n"
17
 
18
- #: ../accordion-shortcodes.php:126
19
  msgid "Please enter a title attribute"
20
  msgstr ""
21
 
22
- #: ../accordion-shortcodes.php:138
 
23
  msgid "Documentation"
24
  msgstr ""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  msgid ""
2
  msgstr ""
3
  "Project-Id-Version: Accordion Shortcodes\n"
4
+ "POT-Creation-Date: 2015-01-01 12:50-0500\n"
5
+ "PO-Revision-Date: 2015-01-01 12:50-0500\n"
6
  "Last-Translator: Phil Buchanan <info@philbuchanan.com>\n"
7
  "Language-Team: \n"
8
  "Language: en_CA\n"
9
  "MIME-Version: 1.0\n"
10
  "Content-Type: text/plain; charset=UTF-8\n"
11
  "Content-Transfer-Encoding: 8bit\n"
12
+ "X-Generator: Poedit 1.7.1\n"
13
  "X-Poedit-KeywordsList: __;_e;_n:1,2;_x:1,2c;_ex:1,2c\n"
14
  "X-Poedit-Basepath: .\n"
15
  "Plural-Forms: nplurals=2; plural=n != 1;\n"
16
  "X-Poedit-SearchPath-0: ..\n"
17
 
18
+ #: ../accordion-shortcodes.php:225
19
  msgid "Please enter a title attribute"
20
  msgstr ""
21
 
22
+ #: ../accordion-shortcodes.php:242
23
+ msgctxt "link to documentation on wordpress.org site"
24
  msgid "Documentation"
25
  msgstr ""
26
+
27
+ #: ../accordion-shortcodes.php:258
28
+ msgid ""
29
+ "It is recommended that you use the accordion group and accordion item "
30
+ "shortcode buttons to insert pre-formatted shortcodes. Your [accordion-items] "
31
+ "should be nested inside an [accordion]...[/accordion] block."
32
+ msgstr ""
33
+
34
+ #: ../accordion-shortcodes.php:259
35
+ msgid ""
36
+ "You can set custom accordion settings on the opening [accordion] shortcode "
37
+ "to change the behaviour of your accordion. Some of the settings you can add "
38
+ "are: autoclose, openfirst, openall, clicktoclose, and scroll (set each equal "
39
+ "to \"true\" or \"false\"). You can also change the default HTML tag for the "
40
+ "accordion titles or add a custom CSS classname."
41
+ msgstr ""
42
+
43
+ #: ../accordion-shortcodes.php:260
44
+ msgid "View the full accordion shortcodes plugin documentation"
45
+ msgstr ""
46
+
47
+ #: ../accordion-shortcodes.php:264
48
+ msgctxt "plugin title, displays in admin help tab"
49
+ msgid "Accordion Shortcodes"
50
+ msgstr ""
51
+
52
+ #: ../tinymce/tinymce.php:67
53
+ msgid "Add an accordion group"
54
+ msgstr ""
55
+
56
+ #: ../tinymce/tinymce.php:68
57
+ msgid "Insert Accordion Shortcode"
58
+ msgstr ""
59
+
60
+ #: ../tinymce/tinymce.php:69
61
+ msgid "Auto Close Accordions"
62
+ msgstr ""
63
+
64
+ #: ../tinymce/tinymce.php:70
65
+ msgid "Open First Accordion"
66
+ msgstr ""
67
+
68
+ #: ../tinymce/tinymce.php:71
69
+ msgid "Open All Accordions"
70
+ msgstr ""
71
+
72
+ #: ../tinymce/tinymce.php:72
73
+ msgid "Click to Close Accordions"
74
+ msgstr ""
75
+
76
+ #: ../tinymce/tinymce.php:73
77
+ msgid "Scroll to Top of Accordion"
78
+ msgstr ""
79
+
80
+ #: ../tinymce/tinymce.php:74
81
+ msgid "HTML Tag for Title"
82
+ msgstr ""
83
+
84
+ #: ../tinymce/tinymce.php:75
85
+ msgid "Add an accordion item"
86
+ msgstr ""
87
+
88
+ #: ../tinymce/tinymce.php:76
89
+ msgid "Insert Accordion Item Shortcode"
90
+ msgstr ""
91
+
92
+ #: ../tinymce/tinymce.php:77
93
+ msgid "Accordion Item Title"
94
+ msgstr ""
95
+
96
+ #: ../tinymce/tinymce.php:78
97
+ msgid "ID (optional)"
98
+ msgstr ""
99
+
100
+ #: ../tinymce/tinymce.php:79
101
+ msgid "Each ID on a single page must be unique and cannot contain spaces."
102
+ msgstr ""
readme.txt CHANGED
@@ -4,8 +4,8 @@ Author URI: http://philbuchanan.com/
4
  Donate Link: http://philbuchanan.com/
5
  Tags: accordion, accordions, shortcodes, responsive accordions, accordions plugin, jquery accordions, accordions short-code, accordions plugin wordpress, accordions plugin jquery
6
  Requires at least: 3.3
7
- Tested up to: 4.1
8
- Stable tag: 2.1.1
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
@@ -26,6 +26,7 @@ The accordions should blend seemlessly with your theme. However, you may want to
26
  * No default CSS added
27
  * Only adds JavaScript on pages that use the shortcodes
28
  * Support for item IDs and direct links
 
29
 
30
  = Optional Features =
31
 
@@ -170,13 +171,17 @@ For example, you could set the `openfirst` option for all accordions across the
170
  return $atts;
171
  }
172
 
173
- = Issues/Suggestions =
174
 
175
- For bug reports or feature requests or if you'd like to contribute to the plugin you can check everything out on [Github](https://github.com/philbuchanan/Accordion-Shortcodes/).
 
 
 
 
176
 
177
- = Additional Thanks =
178
 
179
- Thank you to [dgrevink](https://github.com/dgrevink) for his support in developing the item IDs and direct linking feature.
180
 
181
  == Screenshots ==
182
 
@@ -185,6 +190,13 @@ Thank you to [dgrevink](https://github.com/dgrevink) for his support in developi
185
  3. The Accordion Item shortcode insertion dialog box
186
 
187
  == Changelog ==
 
 
 
 
 
 
 
188
  = 2.1.1 =
189
  * FIXED: An issue where openfirst would not work if title tag was set to div
190
  * FIXED: An issue where title tag setting was not respected when using multiple accordions on one page
@@ -207,6 +219,9 @@ Thank you to [dgrevink](https://github.com/dgrevink) for his support in developi
207
  * FIXED: A few incredibly small bugs/annoyances
208
 
209
  == Upgrade Notice ==
 
 
 
210
  = 2.1.1 =
211
  Fixes a few minor issues accidentally introduced in the 2.1 update.
212
 
4
  Donate Link: http://philbuchanan.com/
5
  Tags: accordion, accordions, shortcodes, responsive accordions, accordions plugin, jquery accordions, accordions short-code, accordions plugin wordpress, accordions plugin jquery
6
  Requires at least: 3.3
7
+ Tested up to: 4.2
8
+ Stable tag: 2.2
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
26
  * No default CSS added
27
  * Only adds JavaScript on pages that use the shortcodes
28
  * Support for item IDs and direct links
29
+ * Accessible (for users requiring tabbed keyboard navigation control)
30
 
31
  = Optional Features =
32
 
171
  return $atts;
172
  }
173
 
174
+ = Compatibility Mode =
175
 
176
+ If you have a theme that already includes the shortcodes `[accordion]` or `[accordion-item]` you can enable compatibility mode.
177
+
178
+ To enable compatibility mode add `define('AS_COMPATIBILITY', true);` to your config.php file. This will add a prefix of 'as-' to the two accordion shortcodes.
179
+
180
+ With compatibility mode enabled, make sure your shortcodes start with `as-` like this: `[as-accordion]...[/as-accordion]` and `[as-accordion-item]...[/as-accordion-item]`.
181
 
182
+ = Issues/Suggestions =
183
 
184
+ For bug reports or feature requests or if you'd like to contribute to the plugin you can check everything out on [Github](https://github.com/philbuchanan/Accordion-Shortcodes/).
185
 
186
  == Screenshots ==
187
 
190
  3. The Accordion Item shortcode insertion dialog box
191
 
192
  == Changelog ==
193
+ = 2.2 =
194
+ * NEW: Accessible for users requiring tabbed keyboard navigation control (this took way too long)
195
+ * NEW: A classname of 'read' is now added to accordion item titles as they are opened. This allows you to style all read accordion items.
196
+ * NEW: Compatibility mode adds a prefix to the shortcodes for themes that already include accordion shortcodes with matching names.
197
+ * FIXED: Animation queue not clearing.
198
+ * Now compatible up to WordPress 4.2
199
+
200
  = 2.1.1 =
201
  * FIXED: An issue where openfirst would not work if title tag was set to div
202
  * FIXED: An issue where title tag setting was not respected when using multiple accordions on one page
219
  * FIXED: A few incredibly small bugs/annoyances
220
 
221
  == Upgrade Notice ==
222
+ = 2.2 =
223
+ Drastically improved accessibility. New 'read' class added to opened accordion items. Compatibility mode added for themes with the same accordion shortcode names. WordPress 4.2 compatibility.
224
+
225
  = 2.1.1 =
226
  Fixes a few minor issues accidentally introduced in the 2.1 update.
227
 
tinymce/tinymce-plugin.js CHANGED
@@ -3,144 +3,133 @@
3
 
4
  tinymce.create('tinymce.plugins.accordionShortcodesExtensions', {
5
  init: function(editor, url) {
6
- editor.addButton('AccordionShortcode', {
7
- title: 'Add an accordion group',
8
- cmd: 'accordionShortcode',
9
- image: url + '/images/accordion.gif'
10
- });
11
 
12
- editor.addCommand('accordionShortcode', function() {
13
- editor.windowManager.open({
14
- title: 'Insert Accordion Shortcode',
15
- body: [
16
- {
17
- type: 'checkbox',
18
- name: 'autoclose',
19
- label: 'Auto Close Accordions',
20
- checked: true
21
- },
22
- {
23
- type: 'checkbox',
24
- name: 'openfirst',
25
- label: 'Open First Accordion'
26
- },
27
- {
28
- type: 'checkbox',
29
- name: 'openall',
30
- label: 'Open All Accordions'
31
- },
32
- {
33
- type: 'checkbox',
34
- name: 'clicktoclose',
35
- label: 'Click to Close Accordions'
36
- },
37
- {
38
- type: 'checkbox',
39
- name: 'scroll',
40
- label: 'Scroll to Top of Accordion'
41
- },
42
- {
43
- type: 'listbox',
44
- name: 'tag',
45
- label: 'HTML Tag for Title',
46
- minWidth: 75,
47
- values: [
48
- {text: '---', value: null},
49
- {text: 'h1', value: 'h1'},
50
- {text: 'h2', value: 'h2'},
51
- {text: 'h3', value: 'h3'},
52
- {text: 'h4', value: 'h4'},
53
- {text: 'h5', value: 'h5'},
54
- {text: 'h6', value: 'h6'},
55
- {text: 'p', value: 'p'},
56
- {text: 'div', value: 'div'}
57
- ]
58
- }
59
- ],
60
- onsubmit: function(e) {
61
- var shortcode = '[accordion';
62
-
63
- if (e.data.autoclose === false) {
64
- shortcode += ' autoclose=' + e.data.autoclose;
65
- }
66
- if (e.data.openfirst) {
67
- shortcode += ' openfirst=' + e.data.openfirst;
68
- }
69
- if (e.data.openall) {
70
- shortcode += ' openall=' + e.data.openall;
71
- }
72
- if (e.data.clicktoclose) {
73
- shortcode += ' clicktoclose=' + e.data.clicktoclose;
74
- }
75
- if (e.data.scroll) {
76
- shortcode += ' scroll=' + e.data.scroll;
77
- }
78
- if (e.data.tag) {
79
- shortcode += ' tag=' + e.data.tag;
 
 
 
 
 
 
 
 
 
80
  }
81
-
82
- shortcode += ']' + editor.selection.getContent() + '[/accordion]';
83
-
84
- editor.execCommand('mceInsertContent', 0, shortcode);
85
- }
86
- });
87
  });
88
 
89
- // Accordion Item
90
  editor.addButton('AccordionItemShortcode', {
91
- title: 'Add an accordion item',
92
- cmd: 'accordionItemShortcode',
93
- image: url + '/images/accordion-item.gif'
94
- });
95
-
96
- editor.addCommand('accordionItemShortcode', function() {
97
- editor.windowManager.open({
98
- title: 'Insert Accordion Item Shortcode',
99
- body: [
100
- {
101
- type: 'textbox',
102
- name: 'title',
103
- label: 'Accordion Item Title',
104
- minWidth: 300
105
- },
106
- {
107
- type: 'textbox',
108
- name: 'id',
109
- label: 'ID (optional)',
110
- minWidth: 300
111
- },
112
- {
113
- type: 'container',
114
- html: 'Each ID on a single page must be unique and cannot contain spaces.'
115
- }
116
- ],
117
- onsubmit: function(e) {
118
- var shortcode = '[accordion-item title="';
119
-
120
- if (e.data.title) {
121
- shortcode += e.data.title;
122
- }
123
- shortcode += '"';
124
-
125
- if (e.data.id) {
126
- shortcode += ' id=' + e.data.id;
 
 
127
  }
128
-
129
- shortcode += ']' + editor.selection.getContent() + '[/accordion-item]';
130
-
131
- editor.execCommand('mceInsertContent', 0, shortcode);
132
- }
133
- });
134
  });
135
- },
136
-
137
- getInfo: function() {
138
- return {
139
- longname: 'Accordion Buttons',
140
- author: 'Phil Buchanan',
141
- authorurl: 'http://philbuchanan.com/',
142
- version: '2.1.1'
143
- };
144
  }
145
  });
146
 
3
 
4
  tinymce.create('tinymce.plugins.accordionShortcodesExtensions', {
5
  init: function(editor, url) {
 
 
 
 
 
6
 
7
+ // Accordion group
8
+ editor.addButton('AccordionShortcode', {
9
+ title: accordionShortcodesTranslations.group_button_label,
10
+ image: url + '/images/accordion.gif',
11
+ onclick: function() {
12
+ editor.windowManager.open({
13
+ title: accordionShortcodesTranslations.group_window_title,
14
+ body: [
15
+ {
16
+ type: 'checkbox',
17
+ name: 'autoclose',
18
+ label: accordionShortcodesTranslations.group_auto_close_label,
19
+ checked: true
20
+ },
21
+ {
22
+ type: 'checkbox',
23
+ name: 'openfirst',
24
+ label: accordionShortcodesTranslations.group_open_first_label
25
+ },
26
+ {
27
+ type: 'checkbox',
28
+ name: 'openall',
29
+ label: accordionShortcodesTranslations.group_open_all_label
30
+ },
31
+ {
32
+ type: 'checkbox',
33
+ name: 'clicktoclose',
34
+ label: accordionShortcodesTranslations.group_click_to_close_label
35
+ },
36
+ {
37
+ type: 'checkbox',
38
+ name: 'scroll',
39
+ label: accordionShortcodesTranslations.group_scroll_label
40
+ },
41
+ {
42
+ type: 'listbox',
43
+ name: 'tag',
44
+ label: accordionShortcodesTranslations.group_html_tag_label,
45
+ minWidth: 75,
46
+ values: [
47
+ {text: '---', value: null},
48
+ {text: 'h1', value: 'h1'},
49
+ {text: 'h2', value: 'h2'},
50
+ {text: 'h3', value: 'h3'},
51
+ {text: 'h4', value: 'h4'},
52
+ {text: 'h5', value: 'h5'},
53
+ {text: 'h6', value: 'h6'},
54
+ {text: 'p', value: 'p'},
55
+ {text: 'div', value: 'div'}
56
+ ]
57
+ }
58
+ ],
59
+ onsubmit: function(e) {
60
+ var shortcode = '[' + accordionShortcodesPrefix + 'accordion';
61
+
62
+ if (e.data.autoclose === false) {
63
+ shortcode += ' autoclose=' + e.data.autoclose;
64
+ }
65
+ if (e.data.openfirst) {
66
+ shortcode += ' openfirst=' + e.data.openfirst;
67
+ }
68
+ if (e.data.openall) {
69
+ shortcode += ' openall=' + e.data.openall;
70
+ }
71
+ if (e.data.clicktoclose) {
72
+ shortcode += ' clicktoclose=' + e.data.clicktoclose;
73
+ }
74
+ if (e.data.scroll) {
75
+ shortcode += ' scroll=' + e.data.scroll;
76
+ }
77
+ if (e.data.tag) {
78
+ shortcode += ' tag=' + e.data.tag;
79
+ }
80
+
81
+ shortcode += ']' + editor.selection.getContent() + '[/' + accordionShortcodesPrefix + 'accordion]';
82
+
83
+ editor.insertContent(shortcode);
84
  }
85
+ });
86
+ }
 
 
 
 
87
  });
88
 
89
+ // Accordion item
90
  editor.addButton('AccordionItemShortcode', {
91
+ title: accordionShortcodesTranslations.item_button_label,
92
+ image: url + '/images/accordion-item.gif',
93
+ onclick: function() {
94
+ editor.windowManager.open({
95
+ title: accordionShortcodesTranslations.item_window_title,
96
+ body: [
97
+ {
98
+ type: 'textbox',
99
+ name: 'title',
100
+ label: accordionShortcodesTranslations.item_title_label,
101
+ minWidth: 300
102
+ },
103
+ {
104
+ type: 'textbox',
105
+ name: 'id',
106
+ label: accordionShortcodesTranslations.item_id_label,
107
+ minWidth: 300
108
+ },
109
+ {
110
+ type: 'container',
111
+ html: accordionShortcodesTranslations.item_notes
112
+ }
113
+ ],
114
+ onsubmit: function(e) {
115
+ var shortcode = '[' + accordionShortcodesPrefix + 'accordion-item title="';
116
+
117
+ if (e.data.title) {
118
+ shortcode += e.data.title;
119
+ }
120
+ shortcode += '"';
121
+
122
+ if (e.data.id) {
123
+ shortcode += ' id=' + e.data.id.replace(/\s+/g, '-');
124
+ }
125
+
126
+ shortcode += ']' + editor.selection.getContent() + '[/' + accordionShortcodesPrefix + 'accordion-item]';
127
+
128
+ editor.insertContent(shortcode);
129
  }
130
+ })
131
+ }
 
 
 
 
132
  });
 
 
 
 
 
 
 
 
 
133
  }
134
  });
135
 
tinymce/tinymce.php CHANGED
@@ -5,32 +5,98 @@ if (!class_exists('Accordion_Shortcode_Tinymce_Extensions')) :
5
 
6
  class Accordion_Shortcode_Tinymce_Extensions {
7
 
 
 
 
 
8
  function __construct() {
9
  add_action('admin_init', array($this, 'button_hooks'));
 
 
 
 
10
  }
11
 
 
 
 
 
 
12
  public function button_hooks() {
13
- if ((current_user_can('edit_posts') || current_user_can('edit_pages')) && get_user_option('rich_editing')) {
14
  add_filter('mce_external_plugins', array($this, 'add_tinymce_plugin'));
15
  add_filter('mce_buttons', array($this, 'register_buttons'));
16
  }
17
  }
18
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
  public function register_buttons($buttons) {
20
  $newButtons = array(
21
  'AccordionShortcode',
22
  'AccordionItemShortcode'
23
  );
 
 
24
  array_splice($buttons, 12, 0, $newButtons);
25
 
26
  return $buttons;
27
  }
28
 
29
- public function add_tinymce_plugin($plugin_array) {
30
- $plugin_array['accordionShortcodesExtensions'] = plugins_url('accordion-shortcodes/tinymce/tinymce-plugin.js');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31
 
32
- return $plugin_array;
33
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34
 
35
  }
36
 
5
 
6
  class Accordion_Shortcode_Tinymce_Extensions {
7
 
8
+ /**
9
+ * Class constructor
10
+ * Adds the button hooks when the admin panel initializes.
11
+ */
12
  function __construct() {
13
  add_action('admin_init', array($this, 'button_hooks'));
14
+
15
+ foreach(array('post.php','post-new.php') as $hook) {
16
+ add_action("admin_head-$hook", array($this, 'admin_head'));
17
+ }
18
  }
19
 
20
+
21
+
22
+ /**
23
+ * Load the plugin and register the buttons
24
+ */
25
  public function button_hooks() {
26
+ if ((current_user_can('edit_posts') || current_user_can('edit_pages')) && get_user_option('rich_editing')) {
27
  add_filter('mce_external_plugins', array($this, 'add_tinymce_plugin'));
28
  add_filter('mce_buttons', array($this, 'register_buttons'));
29
  }
30
  }
31
 
32
+
33
+
34
+ /**
35
+ * Register the accordion shortcodes buttons plugin
36
+ */
37
+ public function add_tinymce_plugin($plugin_array) {
38
+ $plugin_array['accordionShortcodesExtensions'] = plugins_url('accordion-shortcodes/tinymce/tinymce-plugin.js');
39
+
40
+ return $plugin_array;
41
+ }
42
+
43
+
44
+
45
+ /**
46
+ * Register the accordion shortcode buttons
47
+ */
48
  public function register_buttons($buttons) {
49
  $newButtons = array(
50
  'AccordionShortcode',
51
  'AccordionItemShortcode'
52
  );
53
+
54
+ // Place the buttons before the "insert more" button
55
  array_splice($buttons, 12, 0, $newButtons);
56
 
57
  return $buttons;
58
  }
59
 
60
+
61
+
62
+ /**
63
+ * Localize MCE buttons and labels
64
+ */
65
+ public function admin_head() {
66
+ $translations_arr = array(
67
+ 'group_button_label' => __('Add an accordion group', 'accordion_shortcodes'),
68
+ 'group_window_title' => __('Insert Accordion Shortcode', 'accordion_shortcodes'),
69
+ 'group_auto_close_label' => __('Auto Close Accordions', 'accordion_shortcodes'),
70
+ 'group_open_first_label' => __('Open First Accordion', 'accordion_shortcodes'),
71
+ 'group_open_all_label' => __('Open All Accordions', 'accordion_shortcodes'),
72
+ 'group_click_to_close_label' => __('Click to Close Accordions', 'accordion_shortcodes'),
73
+ 'group_scroll_label' => __('Scroll to Top of Accordion', 'accordion_shortcodes'),
74
+ 'group_html_tag_label' => __('HTML Tag for Title', 'accordion_shortcodes'),
75
+ 'item_button_label' => __('Add an accordion item', 'accordion_shortcodes'),
76
+ 'item_window_title' => __('Insert Accordion Item Shortcode', 'accordion_shortcodes'),
77
+ 'item_title_label' => __('Accordion Item Title', 'accordion_shortcodes'),
78
+ 'item_id_label' => __('ID (optional)', 'accordion_shortcodes'),
79
+ 'item_notes' => __('Each ID on a single page must be unique and cannot contain spaces.', 'accordion_shortcodes')
80
+ );
81
 
82
+ foreach($translations_arr as $key => $value) {
83
+ $translations[] = "'$key': '$value'";
84
+ }
85
+
86
+ if (defined('AS_COMPATIBILITY') && AS_COMPATIBILITY) {
87
+ $prefix = 'as-';
88
+ }
89
+ else {
90
+ $prefix = '';
91
+ } ?>
92
+
93
+ <script type="text/javascript">
94
+ var accordionShortcodesTranslations = {
95
+ <?php echo implode(',', $translations); ?>
96
+ },
97
+ accordionShortcodesPrefix = '<?php echo $prefix; ?>';
98
+ </script>
99
+ <?php }
100
 
101
  }
102