Accordion Shortcodes - Version 2.0.1

Version Description

  • NEW: Add a custom CSS classname to your accordion item group or accordion item shortcode
  • NEW: Set an integer for scroll property to offset the scrolling by that many pixels
  • Now compatible up to WordPress 4.0
Download this release

Release Info

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

Code changes from version 2.0 to 2.0.1

accordion-shortcodes.php CHANGED
@@ -2,7 +2,7 @@
2
  /**
3
  * Plugin Name: Accordion Shortcodes
4
  * Description: Adds a few shortcodes to allow for accordion dropdowns.
5
- * Version: 2.0
6
  * Author: Phil Buchanan
7
  * Author URI: http://philbuchanan.com
8
  */
@@ -14,7 +14,7 @@ if (!class_exists('Accordion_Shortcodes')) :
14
 
15
  class Accordion_Shortcodes {
16
 
17
- private $plugin_version = '2.0';
18
  private $add_script = false;
19
 
20
  private $wrapper_tag = 'div';
@@ -86,7 +86,8 @@ class Accordion_Shortcodes {
86
  'openall' => false,
87
  'clicktoclose' => false,
88
  'scroll' => false,
89
- 'semantics' => ''
 
90
  ), $atts, 'accordion'));
91
 
92
  # Set global HTML tag names
@@ -104,13 +105,14 @@ class Accordion_Shortcodes {
104
  'openFirst' => $this -> parse_boolean($openfirst),
105
  'openAll' => $this -> parse_boolean($openall),
106
  'clickToClose' => $this -> parse_boolean($clicktoclose),
107
- 'scroll' => $this -> parse_boolean($scroll)
108
  );
109
  wp_localize_script('accordion-shortcodes-script', 'accordionSettings', $script_data);
110
 
111
- return sprintf('<%2$s class="accordion no-js">%1$s</%2$s>',
112
  do_shortcode($content),
113
- $this -> wrapper_tag
 
114
  );
115
  }
116
 
@@ -119,15 +121,17 @@ class Accordion_Shortcodes {
119
  extract(shortcode_atts(array(
120
  'title' => '',
121
  'id' => '',
122
- 'tag' => ''
 
123
  ), $atts, 'accordion-item'));
124
 
125
- return sprintf('<%4$s class="accordion-title"%3$s>%1$s</%4$s><%5$s class="accordion-content">%2$s</%5$s>',
126
  $title ? $title : '<span style="color:red;">' . __('Please enter a title attribute', 'accordion_shortcodes') . '</span>',
127
  do_shortcode($content),
128
  $id ? ' id="' . $id . '"' : '',
129
  $tag ? $this -> check_html_tag($tag) : $this -> title_tag,
130
- $this -> content_tag
 
131
  );
132
  }
133
 
2
  /**
3
  * Plugin Name: Accordion Shortcodes
4
  * Description: Adds a few shortcodes to allow for accordion dropdowns.
5
+ * Version: 2.0.1
6
  * Author: Phil Buchanan
7
  * Author URI: http://philbuchanan.com
8
  */
14
 
15
  class Accordion_Shortcodes {
16
 
17
+ private $plugin_version = '2.0.1';
18
  private $add_script = false;
19
 
20
  private $wrapper_tag = 'div';
86
  'openall' => false,
87
  'clicktoclose' => false,
88
  'scroll' => false,
89
+ 'semantics' => '',
90
+ 'class' => ''
91
  ), $atts, 'accordion'));
92
 
93
  # Set global HTML tag names
105
  'openFirst' => $this -> parse_boolean($openfirst),
106
  'openAll' => $this -> parse_boolean($openall),
107
  'clickToClose' => $this -> parse_boolean($clicktoclose),
108
+ 'scroll' => $scroll
109
  );
110
  wp_localize_script('accordion-shortcodes-script', 'accordionSettings', $script_data);
111
 
112
+ return sprintf('<%2$s class="accordion no-js%3$s">%1$s</%2$s>',
113
  do_shortcode($content),
114
+ $this -> wrapper_tag,
115
+ $class ? " $class" : ''
116
  );
117
  }
118
 
121
  extract(shortcode_atts(array(
122
  'title' => '',
123
  'id' => '',
124
+ 'tag' => '',
125
+ 'class' => ''
126
  ), $atts, 'accordion-item'));
127
 
128
+ return sprintf('<%4$s class="accordion-title%6$s"%3$s>%1$s</%4$s><%5$s class="accordion-content">%2$s</%5$s>',
129
  $title ? $title : '<span style="color:red;">' . __('Please enter a title attribute', 'accordion_shortcodes') . '</span>',
130
  do_shortcode($content),
131
  $id ? ' id="' . $id . '"' : '',
132
  $tag ? $this -> check_html_tag($tag) : $this -> title_tag,
133
+ $this -> content_tag,
134
+ $class ? " $class" : ''
135
  );
136
  }
137
 
accordion.js CHANGED
@@ -20,6 +20,9 @@
20
  settings = accordionSettings;
21
  }
22
 
 
 
 
23
  // Remove no-js class if JavaScript is enabled
24
  $('.accordion').removeClass('no-js');
25
 
@@ -52,7 +55,7 @@
52
  // Scroll page to the title
53
  if (settings.scroll) {
54
  $('html, body').animate({
55
- scrollTop: $(this).prev().offset().top
56
  }, duration);
57
  }
58
  });
@@ -76,7 +79,7 @@
76
  selectId.addClass('open');
77
  selectId.next().slideDown(duration, function() {
78
  $('html, body').animate({
79
- scrollTop: $(this).prev().offset().top
80
  }, duration);
81
  });
82
  }
20
  settings = accordionSettings;
21
  }
22
 
23
+ // Set the scroll offset
24
+ settings.scrollOffset = Math.floor(parseInt(settings.scroll)) | 0;
25
+
26
  // Remove no-js class if JavaScript is enabled
27
  $('.accordion').removeClass('no-js');
28
 
55
  // Scroll page to the title
56
  if (settings.scroll) {
57
  $('html, body').animate({
58
+ scrollTop: $(this).prev().offset().top - settings.scrollOffset
59
  }, duration);
60
  }
61
  });
79
  selectId.addClass('open');
80
  selectId.next().slideDown(duration, function() {
81
  $('html, body').animate({
82
+ scrollTop: $(this).prev().offset().top - settings.scrollOffset
83
  }, duration);
84
  });
85
  }
accordion.min.js CHANGED
@@ -1 +1,8 @@
1
- (function(e){"use strict";var t=e(".accordion-title"),n=e(".accordion-content").hide(),r=e(".accordion-content:first-of-type"),i=e(window.location.hash),s=250,o={autoClose:true,openFirst:false,openAll:false,clickToClose:false,scroll:false};if(typeof accordionSettings!=="undefined"){o=accordionSettings}e(".accordion").removeClass("no-js");if(i.length&&i.hasClass("accordion-title")){i.addClass("open");i.next().slideDown(s)}else if(o.openAll){n.show();t.addClass("open")}else if(o.openFirst){r.prev().addClass("open");r.slideDown(s)}t.click(function(){if(!e(this).hasClass("open")){if(o.autoClose){n.slideUp(s);t.removeClass("open")}e(this).next().slideDown(s,function(){if(o.scroll){e("html, body").animate({scrollTop:e(this).prev().offset().top},s)}});e(this).addClass("open")}else if(o.clickToClose){e(this).next().slideUp(s);e(this).removeClass("open")}return false});e(window).on("hashchange",function(){i=e(window.location.hash);if(i.length&&i.hasClass("accordion-title")){n.slideUp(s);t.removeClass("open");i.addClass("open");i.next().slideDown(s,function(){e("html, body").animate({scrollTop:e(this).prev().offset().top},s)})}})})(jQuery)
 
 
 
 
 
 
 
1
+ (function($){'use strict';var allTitles=$('.accordion-title'),allPanels=$('.accordion-content').hide(),firstPanel=$('.accordion-content:first-of-type'),selectId=$(window.location.hash),duration=250,settings={autoClose:true,openFirst:false,openAll:false,clickToClose:false,scroll:false};if(typeof accordionSettings!=='undefined'){settings=accordionSettings;}
2
+ settings.scrollOffset=Math.floor(parseInt(settings.scroll))|0;$('.accordion').removeClass('no-js');if(selectId.length&&selectId.hasClass('accordion-title')){selectId.addClass('open');selectId.next().slideDown(duration);}
3
+ else if(settings.openAll){allPanels.show();allTitles.addClass('open');}
4
+ else if(settings.openFirst){firstPanel.prev().addClass('open');firstPanel.slideDown(duration);}
5
+ allTitles.click(function(){if(!$(this).hasClass('open')){if(settings.autoClose){allPanels.slideUp(duration);allTitles.removeClass('open');}
6
+ $(this).next().slideDown(duration,function(){if(settings.scroll){$('html, body').animate({scrollTop:$(this).prev().offset().top-settings.scrollOffset},duration);}});$(this).addClass('open');}
7
+ else if(settings.clickToClose){$(this).next().slideUp(duration);$(this).removeClass('open');}
8
+ return false;});$(window).on('hashchange',function(){selectId=$(window.location.hash);if(selectId.length&&selectId.hasClass('accordion-title')){allPanels.slideUp(duration);allTitles.removeClass('open');selectId.addClass('open');selectId.next().slideDown(duration,function(){$('html, body').animate({scrollTop:$(this).prev().offset().top-settings.scrollOffset},duration);});}});}(jQuery));
assets/screenshot-1.jpg DELETED
Binary file
assets/screenshot-2.jpg DELETED
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
6
  Requires at least: 3.3
7
- Tested up to: 3.9
8
- Stable tag: 2.0
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
@@ -141,7 +141,9 @@ There are a few advanced settings you can add to the opening accordion shortcode
141
 
142
  **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`.
143
 
144
- **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`.
 
 
145
 
146
  **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`.
147
 
@@ -177,6 +179,11 @@ Thank you to [dgrevink](https://github.com/dgrevink) for his support in developi
177
  3. The Accordion Item shortcode insertion dialog box
178
 
179
  == Changelog ==
 
 
 
 
 
180
  = 2.0 =
181
  * NEW: Buttons in the editor to easily add shortcodes with various settings
182
  * NEW: Support for item IDs on accordion items and direct linking to a specific item
@@ -186,5 +193,8 @@ Thank you to [dgrevink](https://github.com/dgrevink) for his support in developi
186
  * FIXED: A few incredibly small bugs/annoyances
187
 
188
  == Upgrade Notice ==
 
 
 
189
  = 2.0 =
190
  Big changes for version 2.0! See the [changelog](http://wordpress.org/plugins/accordion-shortcodes/changelog/) for details.
4
  Donate Link: http://philbuchanan.com/
5
  Tags: accordion, accordions, shortcodes
6
  Requires at least: 3.3
7
+ Tested up to: 4.0
8
+ Stable tag: 2.0.1
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
141
 
142
  **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`.
143
 
144
+ **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"`.
145
+
146
+ **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.
147
 
148
  **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`.
149
 
179
  3. The Accordion Item shortcode insertion dialog box
180
 
181
  == Changelog ==
182
+ = 2.0.1 =
183
+ * NEW: Add a custom CSS classname to your accordion item group or accordion item shortcode
184
+ * NEW: Set an integer for scroll property to offset the scrolling by that many pixels
185
+ * Now compatible up to WordPress 4.0
186
+
187
  = 2.0 =
188
  * NEW: Buttons in the editor to easily add shortcodes with various settings
189
  * NEW: Support for item IDs on accordion items and direct linking to a specific item
193
  * FIXED: A few incredibly small bugs/annoyances
194
 
195
  == Upgrade Notice ==
196
+ = 2.0.1 =
197
+ WordPress 4.0 compatibility.
198
+
199
  = 2.0 =
200
  Big changes for version 2.0! See the [changelog](http://wordpress.org/plugins/accordion-shortcodes/changelog/) for details.