Accordion Shortcodes - Version 2.2.6

Version Description

  • FIXED: Scroll offset was ignored when an accordion was linked to from another page
Download this release

Release Info

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

Code changes from version 2.2.5 to 2.2.6

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.2.5
6
  * Author: Phil Buchanan
7
  * Author URI: http://philbuchanan.com
8
  */
@@ -17,60 +17,60 @@ class Accordion_Shortcodes {
17
  /**
18
  * Current plugin version number
19
  */
20
- private $plugin_version = '2.2.5';
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
@@ -78,33 +78,33 @@ class Accordion_Shortcodes {
78
  */
79
  function __construct() {
80
  $basename = plugin_basename(__FILE__);
81
-
82
  // Load text domain
83
  load_plugin_textdomain('accordion_shortcodes', false, dirname($basename) . '/languages/');
84
-
85
  // Register JavaScript
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
  *
@@ -113,9 +113,9 @@ class Accordion_Shortcodes {
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
@@ -125,9 +125,9 @@ class Accordion_Shortcodes {
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
@@ -136,15 +136,15 @@ class Accordion_Shortcodes {
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
-
142
  // Output accordions settings JavaScript variable
143
  wp_localize_script('accordion-shortcodes-script', 'accordionShortcodesSettings', $this->script_data);
144
  }
145
-
146
-
147
-
148
  /**
149
  * Checks if a value is boolean
150
  *
@@ -154,9 +154,9 @@ class Accordion_Shortcodes {
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.
@@ -167,13 +167,13 @@ class Accordion_Shortcodes {
167
  private function check_html_tag($tag) {
168
  $tag = preg_replace('/\s/', '', $tag);
169
  $tags = array('h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'p', 'div');
170
-
171
  if (in_array($tag, $tags)) return $tag;
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
@@ -183,7 +183,7 @@ class Accordion_Shortcodes {
183
  */
184
  private function check_scroll_value($scroll) {
185
  $int = intval($scroll);
186
-
187
  if (is_int($int) && $int != 0) {
188
  return $int;
189
  }
@@ -191,9 +191,9 @@ class Accordion_Shortcodes {
191
  return $this->is_boolean($scroll);
192
  }
193
  }
194
-
195
-
196
-
197
  /**
198
  * Get's the ID for an accordion item
199
  *
@@ -203,26 +203,26 @@ class Accordion_Shortcodes {
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' => '',
228
  'autoclose' => true,
@@ -233,12 +233,12 @@ class Accordion_Shortcodes {
233
  'semantics' => '',
234
  'class' => ''
235
  ), $atts, 'accordion'));
236
-
237
  // Set global HTML tag names
238
  // Set title HTML tag
239
  if ($tag) $this->title_tag = $this->check_html_tag($tag);
240
  else $this->title_tag = 'h3';
241
-
242
  // Set wrapper HTML tags
243
  if ($semantics == 'dl') {
244
  $this->wrapper_tag = 'dl';
@@ -249,7 +249,7 @@ class Accordion_Shortcodes {
249
  $this->wrapper_tag = 'div';
250
  $this->content_tag = 'div';
251
  }
252
-
253
  // Set settings object (for use in JavaScript)
254
  $script_data = array(
255
  'id' => "accordion-$this->group_count",
@@ -259,10 +259,10 @@ class Accordion_Shortcodes {
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,
@@ -270,9 +270,9 @@ class Accordion_Shortcodes {
270
  $class ? " $class" : ''
271
  );
272
  }
273
-
274
-
275
-
276
  /**
277
  * Accordion item shortcode
278
  */
@@ -283,12 +283,12 @@ class Accordion_Shortcodes {
283
  'tag' => '',
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>',
@@ -296,19 +296,19 @@ class Accordion_Shortcodes {
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
  */
@@ -317,7 +317,7 @@ class Accordion_Shortcodes {
317
  'http://wordpress.org/plugins/accordion-shortcodes/',
318
  _x('Documentation', 'link to documentation on wordpress.org site', 'accordion_shortcodes')
319
  ));
320
-
321
  return $links;
322
  }
323
 
2
  /**
3
  * Plugin Name: Accordion Shortcodes
4
  * Description: Shortcodes for creating responsive accordion drop-downs.
5
+ * Version: 2.2.6
6
  * Author: Phil Buchanan
7
  * Author URI: http://philbuchanan.com
8
  */
17
  /**
18
  * Current plugin version number
19
  */
20
+ private $plugin_version = '2.2.6';
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
78
  */
79
  function __construct() {
80
  $basename = plugin_basename(__FILE__);
81
+
82
  // Load text domain
83
  load_plugin_textdomain('accordion_shortcodes', false, dirname($basename) . '/languages/');
84
+
85
  // Register JavaScript
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
  *
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
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
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
+
142
  // Output accordions settings JavaScript variable
143
  wp_localize_script('accordion-shortcodes-script', 'accordionShortcodesSettings', $this->script_data);
144
  }
145
+
146
+
147
+
148
  /**
149
  * Checks if a value is boolean
150
  *
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.
167
  private function check_html_tag($tag) {
168
  $tag = preg_replace('/\s/', '', $tag);
169
  $tags = array('h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'p', 'div');
170
+
171
  if (in_array($tag, $tags)) return $tag;
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
183
  */
184
  private function check_scroll_value($scroll) {
185
  $int = intval($scroll);
186
+
187
  if (is_int($int) && $int != 0) {
188
  return $int;
189
  }
191
  return $this->is_boolean($scroll);
192
  }
193
  }
194
+
195
+
196
+
197
  /**
198
  * Get's the ID for an accordion item
199
  *
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' => '',
228
  'autoclose' => true,
233
  'semantics' => '',
234
  'class' => ''
235
  ), $atts, 'accordion'));
236
+
237
  // Set global HTML tag names
238
  // Set title HTML tag
239
  if ($tag) $this->title_tag = $this->check_html_tag($tag);
240
  else $this->title_tag = 'h3';
241
+
242
  // Set wrapper HTML tags
243
  if ($semantics == 'dl') {
244
  $this->wrapper_tag = 'dl';
249
  $this->wrapper_tag = 'div';
250
  $this->content_tag = 'div';
251
  }
252
+
253
  // Set settings object (for use in JavaScript)
254
  $script_data = array(
255
  'id' => "accordion-$this->group_count",
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,
270
  $class ? " $class" : ''
271
  );
272
  }
273
+
274
+
275
+
276
  /**
277
  * Accordion item shortcode
278
  */
283
  'tag' => '',
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>',
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
  */
317
  'http://wordpress.org/plugins/accordion-shortcodes/',
318
  _x('Documentation', 'link to documentation on wordpress.org site', 'accordion_shortcodes')
319
  ));
320
+
321
  return $links;
322
  }
323
 
accordion.js CHANGED
@@ -1,17 +1,17 @@
1
  (function($) {
2
  'use strict';
3
-
4
  var i, settings;
5
-
6
-
7
-
8
  /**
9
  * Accordion Shortcodes plugin function
10
  *
11
  * @param object options Plugin settings to override the defaults
12
  */
13
  $.fn.accordionShortcodes = function(options) {
14
-
15
  var allTitles = this.children('.accordion-title'),
16
  allPanels = this.children('.accordion-content').hide(),
17
  firstTitle = allTitles.first(),
@@ -26,20 +26,20 @@
26
  clickToClose: false,
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.
@@ -53,7 +53,7 @@
53
  closeItem($(this));
54
  });
55
  }
56
-
57
  // Open clicked item
58
  openItem($(this), true);
59
  }
@@ -61,12 +61,12 @@
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.
@@ -74,7 +74,7 @@
74
  * @param object ele The accordion item title to open
75
  * @param bool scroll Whether to scroll the page
76
  */
77
- function openItem(ele, scroll) {
78
  // Clear/stop any previous animations before revealing content
79
  ele.next().clearQueue().stop().slideDown(duration, function() {
80
  // Scroll page to the title
@@ -84,7 +84,7 @@
84
  }, duration);
85
  }
86
  });
87
-
88
  // Mark accordion item as open and read and set aria attributes
89
  ele.addClass('open read')
90
  .attr({
@@ -95,9 +95,9 @@
95
  'aria-hidden': 'false'
96
  });
97
  }
98
-
99
-
100
-
101
  /**
102
  * Closes an accordion item
103
  * Also handles accessibility attribute settings.
@@ -107,7 +107,7 @@
107
  function closeItem(ele) {
108
  ele.next().slideUp(duration);
109
  ele.removeClass('open');
110
-
111
  // Set accessibility attributes
112
  ele.attr({
113
  'aria-selected': 'false',
@@ -117,9 +117,9 @@
117
  'aria-hidden': 'true'
118
  });
119
  }
120
-
121
-
122
-
123
  /**
124
  * Should any accordions be opened on load?
125
  * Open first, open all or open based on URL hash.
@@ -135,48 +135,51 @@
135
  else if (settings.openFirst) {
136
  openItem(firstTitle, false);
137
  }
138
-
139
-
140
-
141
  /**
142
  * Add event listeners
143
  */
144
  allTitles.click(clickHandler);
145
-
146
  allTitles.keydown(function(e) {
147
  var code = e.which;
148
-
149
  // 13 = Return, 32 = Space
150
  if ((code === 13) || (code === 32)) {
151
  // Simulate click on title
152
  $(this).click();
153
  }
154
  });
155
-
156
  // Listen for hash changes (in page jump links for accordions)
157
  $(window).on('hashchange', function() {
158
  selectedId = $(window.location.hash);
159
-
160
  if (selectedId.length && selectedId.hasClass('accordion-title')) {
161
  if (settings.autoClose) {
162
  allTitles.each(function() {
163
  closeItem($(this));
164
  });
165
  }
166
-
167
  openItem(selectedId, true);
168
  }
169
  });
170
-
171
  return this;
172
  };
173
-
174
-
175
-
176
  // Loop through accordion settings objects
177
- for (var i = 0; i < accordionShortcodesSettings.length; i += 1) {
178
- settings = accordionShortcodesSettings[i];
179
-
180
- $('#' + settings.id).accordionShortcodes(settings);
181
- }
 
 
 
182
  }(jQuery));
1
  (function($) {
2
  'use strict';
3
+
4
  var i, settings;
5
+
6
+
7
+
8
  /**
9
  * Accordion Shortcodes plugin function
10
  *
11
  * @param object options Plugin settings to override the defaults
12
  */
13
  $.fn.accordionShortcodes = function(options) {
14
+
15
  var allTitles = this.children('.accordion-title'),
16
  allPanels = this.children('.accordion-content').hide(),
17
  firstTitle = allTitles.first(),
26
  clickToClose: false,
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.
53
  closeItem($(this));
54
  });
55
  }
56
+
57
  // Open clicked item
58
  openItem($(this), true);
59
  }
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.
74
  * @param object ele The accordion item title to open
75
  * @param bool scroll Whether to scroll the page
76
  */
77
+ function openItem(ele, scroll) {
78
  // Clear/stop any previous animations before revealing content
79
  ele.next().clearQueue().stop().slideDown(duration, function() {
80
  // Scroll page to the title
84
  }, duration);
85
  }
86
  });
87
+
88
  // Mark accordion item as open and read and set aria attributes
89
  ele.addClass('open read')
90
  .attr({
95
  'aria-hidden': 'false'
96
  });
97
  }
98
+
99
+
100
+
101
  /**
102
  * Closes an accordion item
103
  * Also handles accessibility attribute settings.
107
  function closeItem(ele) {
108
  ele.next().slideUp(duration);
109
  ele.removeClass('open');
110
+
111
  // Set accessibility attributes
112
  ele.attr({
113
  'aria-selected': 'false',
117
  'aria-hidden': 'true'
118
  });
119
  }
120
+
121
+
122
+
123
  /**
124
  * Should any accordions be opened on load?
125
  * Open first, open all or open based on URL hash.
135
  else if (settings.openFirst) {
136
  openItem(firstTitle, false);
137
  }
138
+
139
+
140
+
141
  /**
142
  * Add event listeners
143
  */
144
  allTitles.click(clickHandler);
145
+
146
  allTitles.keydown(function(e) {
147
  var code = e.which;
148
+
149
  // 13 = Return, 32 = Space
150
  if ((code === 13) || (code === 32)) {
151
  // Simulate click on title
152
  $(this).click();
153
  }
154
  });
155
+
156
  // Listen for hash changes (in page jump links for accordions)
157
  $(window).on('hashchange', function() {
158
  selectedId = $(window.location.hash);
159
+
160
  if (selectedId.length && selectedId.hasClass('accordion-title')) {
161
  if (settings.autoClose) {
162
  allTitles.each(function() {
163
  closeItem($(this));
164
  });
165
  }
166
+
167
  openItem(selectedId, true);
168
  }
169
  });
170
+
171
  return this;
172
  };
173
+
174
+
175
+
176
  // Loop through accordion settings objects
177
+ // Wait for the entire page to load before loading the accordion
178
+ $(window).load(function() {
179
+ for (var i = 0; i < accordionShortcodesSettings.length; i += 1) {
180
+ settings = accordionShortcodesSettings[i];
181
+
182
+ $('#' + settings.id).accordionShortcodes(settings);
183
+ }
184
+ });
185
  }(jQuery));
accordion.min.js CHANGED
@@ -1 +1 @@
1
- !function(o){"use strict";var t,e;o.fn.accordionShortcodes=function(t){function e(){return o(this).hasClass("open")?h.clickToClose&&i(o(this)):(h.autoClose&&s.each(function(){i(o(this))}),n(o(this),!0)),!1}function n(t,e){t.next().clearQueue().stop().slideDown(l,function(){e&&h.scroll&&o("html, body").animate({scrollTop:o(this).prev().offset().top-h.scrollOffset},l)}),t.addClass("open read").attr({"aria-selected":"true","aria-expanded":"true"}).next().attr({"aria-hidden":"false"})}function i(o){o.next().slideUp(l),o.removeClass("open"),o.attr({"aria-selected":"false","aria-expanded":"false"}).next().attr({"aria-hidden":"true"})}var s=this.children(".accordion-title"),a=this.children(".accordion-content").hide(),c=s.first(),r=(a.first(),o(window.location.hash)),l=250,h=o.extend({autoClose:!0,openFirst:!1,openAll:!1,clickToClose:!1,scroll:!1},t);return o(".accordion").removeClass("no-js"),h.scrollOffset=0|Math.floor(parseInt(h.scroll)),r.length&&r.hasClass("accordion-title")?n(r,!0):h.openAll?s.each(function(){n(o(this),!1)}):h.openFirst&&n(c,!1),s.click(e),s.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")&&(h.autoClose&&s.each(function(){i(o(this))}),n(r,!0))}),this};for(var t=0;t<accordionShortcodesSettings.length;t+=1)e=accordionShortcodesSettings[t],o("#"+e.id).accordionShortcodes(e)}(jQuery);
1
+ !function(o){"use strict";var t;o.fn.accordionShortcodes=function(t){function e(){return o(this).hasClass("open")?d.clickToClose&&i(o(this)):(d.autoClose&&s.each(function(){i(o(this))}),n(o(this),!0)),!1}function n(t,e){t.next().clearQueue().stop().slideDown(l,function(){e&&d.scroll&&o("html, body").animate({scrollTop:o(this).prev().offset().top-d.scrollOffset},l)}),t.addClass("open read").attr({"aria-selected":"true","aria-expanded":"true"}).next().attr({"aria-hidden":"false"})}function i(o){o.next().slideUp(l),o.removeClass("open"),o.attr({"aria-selected":"false","aria-expanded":"false"}).next().attr({"aria-hidden":"true"})}var s=this.children(".accordion-title"),a=this.children(".accordion-content").hide(),c=s.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,!0):d.openAll?s.each(function(){n(o(this),!1)}):d.openFirst&&n(c,!1),s.click(e),s.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&&s.each(function(){i(o(this))}),n(r,!0))}),this},o(window).load(function(){for(var e=0;e<accordionShortcodesSettings.length;e+=1)t=accordionShortcodesSettings[e],o("#"+t.id).accordionShortcodes(t)})}(jQuery);
readme.txt CHANGED
@@ -5,7 +5,7 @@ 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.4
8
- Stable tag: 2.2.5
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
@@ -190,6 +190,9 @@ For bug reports or feature requests or if you'd like to contribute to the plugin
190
  3. The Accordion Item shortcode insertion dialog box
191
 
192
  == Changelog ==
 
 
 
193
  = 2.2.5 =
194
  * Now compatible up to WordPress 4.4
195
 
@@ -219,7 +222,7 @@ FIXED: A bug where setting both scroll and openfirst would scroll the window wit
219
 
220
  = 2.0.1 =
221
  * NEW: Add a custom CSS classname to your accordion item group or accordion item shortcode
222
- * NEW: Set an integer for scroll property to offset the scrolling by that many pixels
223
  * Now compatible up to WordPress 4.0
224
 
225
  = 2.0 =
@@ -231,6 +234,9 @@ FIXED: A bug where setting both scroll and openfirst would scroll the window wit
231
  * FIXED: A few incredibly small bugs/annoyances
232
 
233
  == Upgrade Notice ==
 
 
 
234
  = 2.2.5 =
235
  * Now compatible up to WordPress 4.4
236
 
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.4
8
+ Stable tag: 2.2.6
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
190
  3. The Accordion Item shortcode insertion dialog box
191
 
192
  == Changelog ==
193
+ = 2.2.6 =
194
+ * FIXED: Scroll offset was ignored when an accordion was linked to from another page
195
+
196
  = 2.2.5 =
197
  * Now compatible up to WordPress 4.4
198
 
222
 
223
  = 2.0.1 =
224
  * NEW: Add a custom CSS classname to your accordion item group or accordion item shortcode
225
+ * NEW: Set an integer for scroll property to offset the scrolling by that many pixels
226
  * Now compatible up to WordPress 4.0
227
 
228
  = 2.0 =
234
  * FIXED: A few incredibly small bugs/annoyances
235
 
236
  == Upgrade Notice ==
237
+ = 2.2.6 =
238
+ Fixes an issues where the scroll offset was ignored when an accordion was linked to from another page.
239
+
240
  = 2.2.5 =
241
  * Now compatible up to WordPress 4.4
242
 
tinymce/tinymce-plugin.js CHANGED
@@ -1,12 +1,12 @@
1
  (function() {
2
  'use strict';
3
-
4
  tinymce.create('tinymce.plugins.accordionShortcodesExtensions', {
5
  init: function(editor, url) {
6
  if (accordionShortcodesPrefix == undefined) {
7
  var accordionShortcodesPrefix = '';
8
  }
9
-
10
  // Accordion group
11
  editor.addButton('AccordionShortcode', {
12
  title: 'Add an accordion group',
@@ -61,7 +61,7 @@
61
  ],
62
  onsubmit: function(e) {
63
  var shortcode = '[' + accordionShortcodesPrefix + 'accordion';
64
-
65
  if (e.data.autoclose === false) {
66
  shortcode += ' autoclose=' + e.data.autoclose;
67
  }
@@ -80,15 +80,15 @@
80
  if (e.data.tag) {
81
  shortcode += ' tag=' + e.data.tag;
82
  }
83
-
84
  shortcode += ']' + editor.selection.getContent() + '[/' + accordionShortcodesPrefix + 'accordion]';
85
-
86
  editor.insertContent(shortcode);
87
  }
88
  });
89
  }
90
  });
91
-
92
  // Accordion item
93
  editor.addButton('AccordionItemShortcode', {
94
  title: 'Add an accordion item',
@@ -116,18 +116,18 @@
116
  ],
117
  onsubmit: function(e) {
118
  var shortcode = '[' + accordionShortcodesPrefix + '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.replace(/\s+/g, '-');
127
  }
128
-
129
  shortcode += ']' + editor.selection.getContent() + '[/' + accordionShortcodesPrefix + 'accordion-item]';
130
-
131
  editor.insertContent(shortcode);
132
  }
133
  })
@@ -135,6 +135,6 @@
135
  });
136
  }
137
  });
138
-
139
  tinymce.PluginManager.add('accordionShortcodesExtensions', tinymce.plugins.accordionShortcodesExtensions);
140
  }());
1
  (function() {
2
  'use strict';
3
+
4
  tinymce.create('tinymce.plugins.accordionShortcodesExtensions', {
5
  init: function(editor, url) {
6
  if (accordionShortcodesPrefix == undefined) {
7
  var accordionShortcodesPrefix = '';
8
  }
9
+
10
  // Accordion group
11
  editor.addButton('AccordionShortcode', {
12
  title: 'Add an accordion group',
61
  ],
62
  onsubmit: function(e) {
63
  var shortcode = '[' + accordionShortcodesPrefix + 'accordion';
64
+
65
  if (e.data.autoclose === false) {
66
  shortcode += ' autoclose=' + e.data.autoclose;
67
  }
80
  if (e.data.tag) {
81
  shortcode += ' tag=' + e.data.tag;
82
  }
83
+
84
  shortcode += ']' + editor.selection.getContent() + '[/' + accordionShortcodesPrefix + 'accordion]';
85
+
86
  editor.insertContent(shortcode);
87
  }
88
  });
89
  }
90
  });
91
+
92
  // Accordion item
93
  editor.addButton('AccordionItemShortcode', {
94
  title: 'Add an accordion item',
116
  ],
117
  onsubmit: function(e) {
118
  var shortcode = '[' + accordionShortcodesPrefix + '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.replace(/\s+/g, '-');
127
  }
128
+
129
  shortcode += ']' + editor.selection.getContent() + '[/' + accordionShortcodesPrefix + 'accordion-item]';
130
+
131
  editor.insertContent(shortcode);
132
  }
133
  })
135
  });
136
  }
137
  });
138
+
139
  tinymce.PluginManager.add('accordionShortcodesExtensions', tinymce.plugins.accordionShortcodesExtensions);
140
  }());
tinymce/tinymce.php CHANGED
@@ -13,9 +13,9 @@ class Accordion_Shortcode_Tinymce_Extensions {
13
  add_action('admin_init', array($this, 'button_hooks'));
14
  add_action('admin_head', array($this, 'admin_head'));
15
  }
16
-
17
-
18
-
19
  /**
20
  * Load the plugin and register the buttons
21
  */
@@ -25,20 +25,20 @@ class Accordion_Shortcode_Tinymce_Extensions {
25
  add_filter('mce_buttons', array($this, 'register_buttons'));
26
  }
27
  }
28
-
29
-
30
-
31
  /**
32
  * Register the accordion shortcodes buttons plugin
33
  */
34
  public function add_tinymce_plugin($plugin_array) {
35
  $plugin_array['accordionShortcodesExtensions'] = plugins_url('accordion-shortcodes/tinymce/tinymce-plugin.js');
36
-
37
  return $plugin_array;
38
  }
39
-
40
-
41
-
42
  /**
43
  * Register the accordion shortcode buttons
44
  */
@@ -47,15 +47,15 @@ class Accordion_Shortcode_Tinymce_Extensions {
47
  'AccordionShortcode',
48
  'AccordionItemShortcode'
49
  );
50
-
51
  // Place the buttons before the "insert more" button
52
  array_splice($buttons, 12, 0, $newButtons);
53
-
54
  return $buttons;
55
  }
56
-
57
-
58
-
59
  /**
60
  * Localize MCE buttons and labels
61
  */
@@ -64,9 +64,9 @@ class Accordion_Shortcode_Tinymce_Extensions {
64
  $prefix = 'as-';
65
  }
66
  else {
67
- $prefix = '';
68
  } ?>
69
-
70
  <script type="text/javascript">
71
  var accordionShortcodesPrefix = '<?php echo $prefix; ?>';
72
  </script>
13
  add_action('admin_init', array($this, 'button_hooks'));
14
  add_action('admin_head', array($this, 'admin_head'));
15
  }
16
+
17
+
18
+
19
  /**
20
  * Load the plugin and register the buttons
21
  */
25
  add_filter('mce_buttons', array($this, 'register_buttons'));
26
  }
27
  }
28
+
29
+
30
+
31
  /**
32
  * Register the accordion shortcodes buttons plugin
33
  */
34
  public function add_tinymce_plugin($plugin_array) {
35
  $plugin_array['accordionShortcodesExtensions'] = plugins_url('accordion-shortcodes/tinymce/tinymce-plugin.js');
36
+
37
  return $plugin_array;
38
  }
39
+
40
+
41
+
42
  /**
43
  * Register the accordion shortcode buttons
44
  */
47
  'AccordionShortcode',
48
  'AccordionItemShortcode'
49
  );
50
+
51
  // Place the buttons before the "insert more" button
52
  array_splice($buttons, 12, 0, $newButtons);
53
+
54
  return $buttons;
55
  }
56
+
57
+
58
+
59
  /**
60
  * Localize MCE buttons and labels
61
  */
64
  $prefix = 'as-';
65
  }
66
  else {
67
+ $prefix = '';
68
  } ?>
69
+
70
  <script type="text/javascript">
71
  var accordionShortcodesPrefix = '<?php echo $prefix; ?>';
72
  </script>