Accordion Shortcodes - Version 2.3.0

Version Description

  • NEW: Added setting to set initial state (open or closed) of individual accordion items on page load
  • NEW: Added wp-config option to disable the TinyMCE extension
  • Now compatible up to WordPress 4.5
Download this release

Release Info

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

Code changes from version 2.2.6 to 2.3.0

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.6
6
  * Author: Phil Buchanan
7
  * Author URI: http://philbuchanan.com
8
  */
@@ -17,7 +17,7 @@ class Accordion_Shortcodes {
17
  /**
18
  * Current plugin version number
19
  */
20
- private $plugin_version = '2.2.6';
21
 
22
 
23
 
@@ -99,7 +99,9 @@ class Accordion_Shortcodes {
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
 
@@ -281,7 +283,8 @@ class Accordion_Shortcodes {
281
  'title' => '',
282
  'id' => '',
283
  'tag' => '',
284
- 'class' => ''
 
285
  ), $atts, 'accordion-item'));
286
 
287
  // Increment accordion item count
@@ -289,12 +292,13 @@ class Accordion_Shortcodes {
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>',
2
  /**
3
  * Plugin Name: Accordion Shortcodes
4
  * Description: Shortcodes for creating responsive accordion drop-downs.
5
+ * Version: 2.3.0
6
  * Author: Phil Buchanan
7
  * Author URI: http://philbuchanan.com
8
  */
17
  /**
18
  * Current plugin version number
19
  */
20
+ private $plugin_version = '2.3.0';
21
 
22
 
23
 
99
  add_filter("plugin_action_links_$basename", array($this, 'add_documentation_link'));
100
 
101
  // Add buttons to MCE editor
102
+ if (!defined('AS_TINYMCE') || AS_TINYMCE != false) {
103
+ $Accordion_Shortcode_Tinymce_Extensions = new Accordion_Shortcode_Tinymce_Extensions;
104
+ }
105
  }
106
  }
107
 
283
  'title' => '',
284
  'id' => '',
285
  'tag' => '',
286
+ 'class' => '',
287
+ 'state' => ''
288
  ), $atts, 'accordion-item'));
289
 
290
  // Increment accordion item count
292
 
293
  $ids = $this->get_accordion_id($id);
294
 
295
+ $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"%6$s>%2$s</%1$s>',
296
  $tag ? $this->check_html_tag($tag) : $this->title_tag,
297
  $title ? $title : '<span style="color:red;">' . __('Please enter a title attribute', 'accordion_shortcodes') . '</span>',
298
  $ids['title'],
299
  $ids['content'],
300
+ $class ? " $class" : '',
301
+ $state ? ' data-initialstate="' . $state . '"' : ''
302
  );
303
 
304
  $accordion_content = sprintf('<%1$s id="%3$s" class="accordion-content" role="tabpanel" aria-labelledby="%4$s" aria-hidden="true">%2$s</%1$s>',
accordion.js CHANGED
@@ -121,8 +121,9 @@
121
 
122
 
123
  /**
124
- * Should any accordions be opened on load?
125
- * Open first, open all or open based on URL hash.
 
126
  */
127
  if (selectedId.length && selectedId.hasClass('accordion-title')) {
128
  openItem(selectedId, true);
@@ -136,6 +137,21 @@
136
  openItem(firstTitle, false);
137
  }
138
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
139
 
140
 
141
  /**
121
 
122
 
123
  /**
124
+ * Should any accordions be opened or closed on load?
125
+ * Open first, open all, open based on URL hash or open/closed based on
126
+ * initial state setting.
127
  */
128
  if (selectedId.length && selectedId.hasClass('accordion-title')) {
129
  openItem(selectedId, true);
137
  openItem(firstTitle, false);
138
  }
139
 
140
+ // Open or close items if initial state set to open or close
141
+ $('[data-initialstate!=""]').each(function() {
142
+ switch ($(this).data('initialstate')) {
143
+ case 'open':
144
+ openItem($(this), false);
145
+ break;
146
+ case 'closed':
147
+ // Only close it if the hash isn't for this item
148
+ if ($(this).attr('id') !== selectedId.attr('id')) {
149
+ closeItem($(this));
150
+ }
151
+ break;
152
+ }
153
+ });
154
+
155
 
156
 
157
  /**
accordion.min.js CHANGED
@@ -1 +1 @@
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);
1
+ !function(t){"use strict";var o;t.fn.accordionShortcodes=function(o){function e(){return t(this).hasClass("open")?h.clickToClose&&n(t(this)):(h.autoClose&&a.each(function(){n(t(this))}),i(t(this),!0)),!1}function i(o,e){o.next().clearQueue().stop().slideDown(l,function(){e&&h.scroll&&t("html, body").animate({scrollTop:t(this).prev().offset().top-h.scrollOffset},l)}),o.addClass("open read").attr({"aria-selected":"true","aria-expanded":"true"}).next().attr({"aria-hidden":"false"})}function n(t){t.next().slideUp(l),t.removeClass("open"),t.attr({"aria-selected":"false","aria-expanded":"false"}).next().attr({"aria-hidden":"true"})}var a=this.children(".accordion-title"),s=this.children(".accordion-content").hide(),c=a.first(),r=(s.first(),t(window.location.hash)),l=250,h=t.extend({autoClose:!0,openFirst:!1,openAll:!1,clickToClose:!1,scroll:!1},o);return t(".accordion").removeClass("no-js"),h.scrollOffset=0|Math.floor(parseInt(h.scroll)),r.length&&r.hasClass("accordion-title")?i(r,!0):h.openAll?a.each(function(){i(t(this),!1)}):h.openFirst&&i(c,!1),t('[data-initialstate!=""]').each(function(){switch(t(this).data("initialstate")){case"open":i(t(this),!1);break;case"closed":t(this).attr("id")!==r.attr("id")&&n(t(this))}}),a.click(e),a.keydown(function(o){var e=o.which;(13===e||32===e)&&t(this).click()}),t(window).on("hashchange",function(){r=t(window.location.hash),r.length&&r.hasClass("accordion-title")&&(h.autoClose&&a.each(function(){n(t(this))}),i(r,!0))}),this},t(window).load(function(){for(var e=0;e<accordionShortcodesSettings.length;e+=1)o=accordionShortcodesSettings[e],t("#"+o.id).accordionShortcodes(o)})}(jQuery);
assets/screenshot-2.png CHANGED
Binary file
assets/screenshot-3.png CHANGED
Binary file
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.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
 
@@ -134,29 +134,33 @@ You could use this URL to open the third item by default:
134
 
135
  All you need to do is ensure that the part after the `#` in the URL matches the ID set on the accordion item.
136
 
137
- = Advanced Settings =
138
 
139
  There are a few advanced settings you can add to the opening accordion shortcode. The full shortcode, with all the default settings looks like this:
140
 
141
  [accordion autoclose="true" openfirst="false" openall="false" clicktoclose="false"]
142
 
143
- **autoclose**: Sets whether accordion items close automatically when you open the next item. Set `autoclose="true/false"` on the opening accordion tag like this: `[accordion autoclose="false"]`. Default is `true`.
144
 
145
- **openfirst**: Sets whether the first accordion item is open by default. This setting will be overridden if **openall** is set to true. Set `openfirst="true/false"` on the opening accordion tag like this: `[accordion openfirst="true"]`. Default is `false`.
146
 
147
- **openall**: Sets whether all accordion items are open by default. It is recommended that this setting be used with **clicktoclose**. Set `openall="true/false"` on the opening accordion tag like this: `[accordion openall="true"]`. Default is `false`.
148
 
149
- **clicktoclose**: Sets whether clicking an open title closes it. Set `clicktoclose="true/false"` on the opening accordion tag like this: `[accordion clicktoclose="true"]`. Default is `false`.
150
 
151
- **scroll**: Sets whether to scroll to the title when it's clicked open. This is useful if you have a lot of content within your accordion items. Set `scroll="true/false"` on the opening accordion tag like this: `[accordion scroll="true"]`. Default is `false`. You may also specify an integer for a pixel offset if you'd like the page to scroll further (useful when the site uses a fixed position header navigation). NOTE: Only use pixel offset integers of > 0. If you do not want a scroll offset, but still want scrolling, simply use `scroll="true"`.
152
 
153
  **class**: Sets a custom CSS class for the accordion group or individual accordion items. Set `class="your-class-name"` on the opening accordion or accordion-item shortcode like this: `[accordion class="your-class-name"]` or `[accordion-item class="your-class-name"]`. Added a class to the accordion-item will add the class to the title HTML tag.
154
 
155
- **tag**: Set the global HTML tag to use for all accordion titles. Set `tag="h2"` on the opening accordion tag like this: `[accordion tag="h2"]`. Default is `h3`.
 
 
 
 
156
 
157
- You can also set the HTML tag for the titles of each accordion item individually by adding `tag="tagname"` to each `[accordion-item]` shortcode. Make sure to **not** include the angle brackets around the tag name. Example: to use `<h2>` instead of the default `<h3>` tag: `[accordion-item title="Item title" tag="h2"]Item content[/accordion-item]`. Using a tag attribute on an individual accordion item will override the global setting. The list of valid tags is: h1, h2, h3, h4, h5, h6, p, div.
158
 
159
- **semantics**: You can change the entire semantic structure of the accordions to use a definition list (dl, dt, dd) by setting `semantics="dl"` on the opening accordion tag like this: `[accordion semantics="dl"]`. By default the accordion will use `div` tags for the wrapper and content containers. If you set this option to `dl`, it is recommended that you do not also use the `tag` option. This feature is not selectable from the accordion button dialog box and must be added manually.
160
 
161
  = Filtering Shortcodes =
162
 
@@ -175,10 +179,14 @@ For example, you could set the `openfirst` option for all accordions across the
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/).
@@ -190,6 +198,11 @@ 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.6 =
194
  * FIXED: Scroll offset was ignored when an accordion was linked to from another page
195
 
@@ -200,16 +213,16 @@ For bug reports or feature requests or if you'd like to contribute to the plugin
200
  * Now compatible up to WordPress 4.3
201
 
202
  = 2.2.3 =
203
- FIXED: A bug where the content editor would break in custom post types.
204
 
205
  = 2.2.1 =
206
- FIXED: A bug where setting both scroll and openfirst would scroll the window without user interaction.
207
 
208
  = 2.2 =
209
  * NEW: Accessible for users requiring tabbed keyboard navigation control (this took way too long)
210
- * 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.
211
- * NEW: Compatibility mode adds a prefix to the shortcodes for themes that already include accordion shortcodes with matching names.
212
- * FIXED: Animation queue not clearing.
213
  * Now compatible up to WordPress 4.2
214
 
215
  = 2.1.1 =
@@ -234,14 +247,17 @@ FIXED: A bug where setting both scroll and openfirst would scroll the window wit
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
 
243
  = 2.2.4 =
244
- * Now compatible up to WordPress 4.3
245
 
246
  = 2.2.3 =
247
  Fixes a bug where the content editor would break in custom post types.
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.5
8
+ Stable tag: 2.3.0
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
134
 
135
  All you need to do is ensure that the part after the `#` in the URL matches the ID set on the accordion item.
136
 
137
+ = Advanced Accordion Settings =
138
 
139
  There are a few advanced settings you can add to the opening accordion shortcode. The full shortcode, with all the default settings looks like this:
140
 
141
  [accordion autoclose="true" openfirst="false" openall="false" clicktoclose="false"]
142
 
143
+ **autoclose**: Sets whether accordion items close automatically when you open the next item. Set `autoclose="true/false"` on the opening accordion shortcode like this: `[accordion autoclose="false"]`. Default is `true`.
144
 
145
+ **openfirst**: Sets whether the first accordion item is open by default. This setting will be overridden if **openall** is set to true. Set `openfirst="true/false"` on the opening accordion shortcode like this: `[accordion openfirst="true"]`. Default is `false`.
146
 
147
+ **openall**: Sets whether all accordion items are open by default. It is recommended that this setting be used with **clicktoclose**. Set `openall="true/false"` on the opening accordion shortcode like this: `[accordion openall="true"]`. Default is `false`.
148
 
149
+ **clicktoclose**: Sets whether clicking an open title closes it. Set `clicktoclose="true/false"` on the opening accordion shortcode like this: `[accordion clicktoclose="true"]`. Default is `false`.
150
 
151
+ **scroll**: Sets whether to scroll to the title when it's clicked open. This is useful if you have a lot of content within your accordion items. Set `scroll="true/false"` on the opening accordion shortcode like this: `[accordion scroll="true"]`. Default is `false`. You may also specify an integer for a pixel offset if you'd like the page to scroll further (useful when the site uses a fixed position header navigation). NOTE: Only use pixel offset integers of > 0. If you do not want a scroll offset, but still want scrolling, simply use `scroll="true"`.
152
 
153
  **class**: Sets a custom CSS class for the accordion group or individual accordion items. Set `class="your-class-name"` on the opening accordion or accordion-item shortcode like this: `[accordion class="your-class-name"]` or `[accordion-item class="your-class-name"]`. Added a class to the accordion-item will add the class to the title HTML tag.
154
 
155
+ **tag**: Set the global HTML tag to use for all accordion titles. Set `tag="h2"` on the opening accordion shortcode like this: `[accordion tag="h2"]`. Default is `h3`.
156
+
157
+ **semantics**: You can change the entire semantic structure of the accordions to use a definition list (dl, dt, dd) by setting `semantics="dl"` on the opening accordion shortcode like this: `[accordion semantics="dl"]`. By default the accordion will use `div` tags for the wrapper and content containers. If you set this option to `dl`, it is recommended that you do not also use the `tag` option. This feature is not selectable from the accordion button dialog box and must be added manually.
158
+
159
+ = Advanced Accordion Item Settings =
160
 
161
+ **state**: Sets the initial state of the accordion item to `open` or `closed`. Set `state=open` or `state=closed` on the opening accordion item shortcode like this: `[accordion-item state=open]`. This setting will override all other accordion settings except when linking to an accordion item via ID.
162
 
163
+ **tag**: You can also set the HTML tag for the titles of each accordion item individually by adding `tag="tagname"` to each `[accordion-item]` shortcode. Make sure to **not** include the angle brackets around the tag name. Example: to use `<h2>` instead of the default `<h3>` tag: `[accordion-item title="Item title" tag="h2"]Item content[/accordion-item]`. Using a tag attribute on an individual accordion item will override the global setting. The list of valid tags is: h1, h2, h3, h4, h5, h6, p, div.
164
 
165
  = Filtering Shortcodes =
166
 
179
 
180
  If you have a theme that already includes the shortcodes `[accordion]` or `[accordion-item]` you can enable compatibility mode.
181
 
182
+ To enable compatibility mode add `define('AS_COMPATIBILITY', true);` to your wp-config.php file. This will add a prefix of 'as-' to the two accordion shortcodes.
183
 
184
  With compatibility mode enabled, make sure your shortcodes start with `as-` like this: `[as-accordion]...[/as-accordion]` and `[as-accordion-item]...[/as-accordion-item]`.
185
 
186
+ = Disable TinyMCE Buttons =
187
+
188
+ You can optionally disable the TinyMCE extension which will remove the buttons from the editor button bar. To disable the TinyMCE extension add `define('AS_TINYMCE', false);` to your wp-config.php file.
189
+
190
  = Issues/Suggestions =
191
 
192
  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/).
198
  3. The Accordion Item shortcode insertion dialog box
199
 
200
  == Changelog ==
201
+ = 2.3.0 =
202
+ * NEW: Added setting to set initial state (open or closed) of individual accordion items on page load
203
+ * NEW: Added wp-config option to disable the TinyMCE extension
204
+ * Now compatible up to WordPress 4.5
205
+
206
  = 2.2.6 =
207
  * FIXED: Scroll offset was ignored when an accordion was linked to from another page
208
 
213
  * Now compatible up to WordPress 4.3
214
 
215
  = 2.2.3 =
216
+ FIXED: A bug where the content editor would break in custom post types
217
 
218
  = 2.2.1 =
219
+ FIXED: A bug where setting both scroll and openfirst would scroll the window without user interaction
220
 
221
  = 2.2 =
222
  * NEW: Accessible for users requiring tabbed keyboard navigation control (this took way too long)
223
+ * 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
224
+ * NEW: Compatibility mode adds a prefix to the shortcodes for themes that already include accordion shortcodes with matching names
225
+ * FIXED: Animation queue not clearing
226
  * Now compatible up to WordPress 4.2
227
 
228
  = 2.1.1 =
247
  * FIXED: A few incredibly small bugs/annoyances
248
 
249
  == Upgrade Notice ==
250
+ = 2.3.0 =
251
+ Added setting to set initial state (open or closed) of individual accordion items on page load. Also now compatible up to WordPress 4.5.
252
+
253
  = 2.2.6 =
254
  Fixes an issues where the scroll offset was ignored when an accordion was linked to from another page.
255
 
256
  = 2.2.5 =
257
+ Now compatible up to WordPress 4.4.
258
 
259
  = 2.2.4 =
260
+ Now compatible up to WordPress 4.3.
261
 
262
  = 2.2.3 =
263
  Fixes a bug where the content editor would break in custom post types.
tinymce/tinymce-plugin.js CHANGED
@@ -103,6 +103,17 @@
103
  label: 'Accordion Item Title',
104
  minWidth: 300
105
  },
 
 
 
 
 
 
 
 
 
 
 
106
  {
107
  type: 'textbox',
108
  name: 'id',
@@ -125,6 +136,9 @@
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
 
103
  label: 'Accordion Item Title',
104
  minWidth: 300
105
  },
106
+ {
107
+ type: 'listbox',
108
+ name: 'initialstate',
109
+ label: 'Initial State (optional)',
110
+ minWidth: 75,
111
+ values: [
112
+ {text: '---', value: null},
113
+ {text: 'open', value: 'open'},
114
+ {text: 'closed', value: 'closed'},
115
+ ]
116
+ },
117
  {
118
  type: 'textbox',
119
  name: 'id',
136
  if (e.data.id) {
137
  shortcode += ' id=' + e.data.id.replace(/\s+/g, '-');
138
  }
139
+ if (e.data.initialstate) {
140
+ shortcode += ' state=' + e.data.initialstate;
141
+ }
142
 
143
  shortcode += ']' + editor.selection.getContent() + '[/' + accordionShortcodesPrefix + 'accordion-item]';
144