Version Description
N/A
Download this release
Release Info
Developer | GamerZ |
Plugin | WP-ShowHide |
Version | 1.04 |
Comparing to | |
See all releases |
Code changes from version 1.03 to 1.04
- index.php +2 -0
- readme.txt +6 -4
- wp-showhide.php +38 -27
index.php
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
1 |
+
<?php
|
2 |
+
# Silence is golden.
|
readme.txt
CHANGED
@@ -3,10 +3,10 @@ Contributors: GamerZ
|
|
3 |
Donate link: http://lesterchan.net/site/donation/
|
4 |
Tags: show, hide, content, visibility, press release, toggle
|
5 |
Requires at least: 3.0
|
6 |
-
Tested up to: 4.
|
7 |
-
Stable tag: 1.
|
8 |
|
9 |
-
Allows you to embed content within your blog post via WordPress ShortCode API and toggling the visibility of the
|
10 |
|
11 |
== Description ==
|
12 |
By default the content is hidden and user will have to click on the "Show Content" link to toggle it. Similar to what Engadget is doing for their press releases. Example usage: `[showhide type="pressrelease"]Press Release goes in here.[/showhide]`
|
@@ -24,9 +24,11 @@ By default the content is hidden and user will have to click on the "Show Conten
|
|
24 |
* Plugin icon by [Freepik](http://www.freepik.com) from [Flaticon](http://www.flaticon.com)
|
25 |
|
26 |
= Donations =
|
27 |
-
I spent most of my free time creating, updating, maintaining and supporting these plugins, if you really love my plugins and could spare me a couple of bucks, I will really
|
28 |
|
29 |
== Changelog ==
|
|
|
|
|
30 |
|
31 |
= Version 1.03 =
|
32 |
* NEW: Added `.sh-link` and `.sh-content` as a standard class name on top of the type specific class name.
|
3 |
Donate link: http://lesterchan.net/site/donation/
|
4 |
Tags: show, hide, content, visibility, press release, toggle
|
5 |
Requires at least: 3.0
|
6 |
+
Tested up to: 4.5
|
7 |
+
Stable tag: 1.04
|
8 |
|
9 |
+
Allows you to embed content within your blog post via WordPress ShortCode API and toggling the visibility of the content via a link.
|
10 |
|
11 |
== Description ==
|
12 |
By default the content is hidden and user will have to click on the "Show Content" link to toggle it. Similar to what Engadget is doing for their press releases. Example usage: `[showhide type="pressrelease"]Press Release goes in here.[/showhide]`
|
24 |
* Plugin icon by [Freepik](http://www.freepik.com) from [Flaticon](http://www.flaticon.com)
|
25 |
|
26 |
= Donations =
|
27 |
+
I spent most of my free time creating, updating, maintaining and supporting these plugins, if you really love my plugins and could spare me a couple of bucks, I will really appreciate it. If not feel free to use it without any obligations.
|
28 |
|
29 |
== Changelog ==
|
30 |
+
= Version 1.04 =
|
31 |
+
* NEW: Added aria-hidden and aria-expanded to elements
|
32 |
|
33 |
= Version 1.03 =
|
34 |
* NEW: Added `.sh-link` and `.sh-content` as a standard class name on top of the type specific class name.
|
wp-showhide.php
CHANGED
@@ -2,21 +2,20 @@
|
|
2 |
/*
|
3 |
Plugin Name: WP-ShowHide
|
4 |
Plugin URI: http://lesterchan.net/portfolio/programming/php/
|
5 |
-
Description: Allows you to embed content within your blog post via WordPress ShortCode API and toggling the visibility of the
|
6 |
-
Version: 1.
|
7 |
Author: Lester 'GaMerZ' Chan
|
8 |
Author URI: http://lesterchan.net
|
9 |
Text Domain: wp-showhide
|
|
|
|
|
10 |
*/
|
11 |
|
12 |
-
|
13 |
-
/*
|
14 |
-
Copyright 2014 Lester Chan (email : lesterchan@gmail.com)
|
15 |
|
16 |
This program is free software; you can redistribute it and/or modify
|
17 |
-
it under the terms of the GNU General Public License
|
18 |
-
the Free Software Foundation
|
19 |
-
(at your option) any later version.
|
20 |
|
21 |
This program is distributed in the hope that it will be useful,
|
22 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
@@ -25,68 +24,80 @@ Text Domain: wp-showhide
|
|
25 |
|
26 |
You should have received a copy of the GNU General Public License
|
27 |
along with this program; if not, write to the Free Software
|
28 |
-
Foundation, Inc.,
|
29 |
*/
|
30 |
|
31 |
|
32 |
### Function: Enqueue JavaScripts
|
33 |
-
add_action('wp_enqueue_scripts', 'showhide_scripts');
|
34 |
function showhide_scripts() {
|
35 |
-
wp_enqueue_script('jquery');
|
36 |
}
|
37 |
|
|
|
|
|
|
|
|
|
|
|
38 |
|
39 |
### Function: Short Code For Inserting Press Release Into Post
|
40 |
-
add_shortcode('showhide', 'showhide_shortcode');
|
41 |
-
function showhide_shortcode($atts, $content = null) {
|
42 |
// Variables
|
43 |
$post_id = get_the_id();
|
44 |
-
$word_count = number_format_i18n(sizeof(explode(' ', strip_tags($content))));
|
45 |
|
46 |
// Extract ShortCode Attributes
|
47 |
-
$attributes = shortcode_atts(array(
|
48 |
'type' => 'pressrelease',
|
49 |
-
'more_text' => __('Show Press Release (%s More Words)'),
|
50 |
-
'less_text' => __('Hide Press Release (%s Less Words)'),
|
51 |
'hidden' => 'yes'
|
52 |
-
), $atts);
|
53 |
|
54 |
// More/Less Text
|
55 |
-
$more_text = sprintf($attributes['more_text'], $word_count);
|
56 |
-
$less_text = sprintf($attributes['less_text'], $word_count);
|
57 |
|
58 |
// Determine Whether To Show Or Hide Press Release
|
59 |
$hidden_class = 'sh-hide';
|
60 |
$hidden_css = 'display: none;';
|
61 |
-
|
|
|
62 |
$hidden_class = 'sh-show';
|
63 |
$hidden_css = 'display: block;';
|
|
|
64 |
$tmp_text = $more_text;
|
65 |
$more_text = $less_text;
|
66 |
$less_text = $tmp_text;
|
67 |
}
|
68 |
|
69 |
// Format HTML Output
|
70 |
-
$output = '<div id="'
|
71 |
-
$output .= '<div id="'
|
72 |
|
73 |
return $output;
|
74 |
}
|
75 |
|
76 |
-
|
77 |
### Function: Add JavaScript To Footer
|
78 |
-
add_action('wp_footer', 'showhide_footer');
|
79 |
function showhide_footer() {
|
80 |
?>
|
81 |
-
<?php if(WP_DEBUG): ?>
|
82 |
<script type="text/javascript">
|
83 |
function showhide_toggle(type, post_id, more_text, less_text) {
|
84 |
var $link = jQuery("#"+ type + "-link-" + post_id)
|
|
|
85 |
, $content = jQuery("#"+ type + "-content-" + post_id)
|
86 |
, $toggle = jQuery("#"+ type + "-toggle-" + post_id)
|
87 |
, show_hide_class = 'sh-show sh-hide';
|
88 |
$link.toggleClass(show_hide_class);
|
89 |
$content.toggleClass(show_hide_class).toggle();
|
|
|
|
|
|
|
|
|
|
|
90 |
if($toggle.text() === more_text) {
|
91 |
$toggle.text(less_text);
|
92 |
} else {
|
@@ -95,7 +106,7 @@ function showhide_footer() {
|
|
95 |
}
|
96 |
</script>
|
97 |
<?php else : ?>
|
98 |
-
<script type="text/javascript">function showhide_toggle(a,b,
|
99 |
<?php endif; ?>
|
100 |
<?php
|
101 |
}
|
2 |
/*
|
3 |
Plugin Name: WP-ShowHide
|
4 |
Plugin URI: http://lesterchan.net/portfolio/programming/php/
|
5 |
+
Description: Allows you to embed content within your blog post via WordPress ShortCode API and toggling the visibility of the content via a link. By default the content is hidden and user will have to click on the "Show Content" link to toggle it. Similar to what Engadget is doing for their press releases. Example usage: <code>[showhide type="pressrelease"]Press Release goes in here.[/showhide]</code>
|
6 |
+
Version: 1.04
|
7 |
Author: Lester 'GaMerZ' Chan
|
8 |
Author URI: http://lesterchan.net
|
9 |
Text Domain: wp-showhide
|
10 |
+
Domain Path: /languages/
|
11 |
+
License: GPL2
|
12 |
*/
|
13 |
|
14 |
+
/* Copyright 2015 Lester Chan (email : lesterchan@gmail.com)
|
|
|
|
|
15 |
|
16 |
This program is free software; you can redistribute it and/or modify
|
17 |
+
it under the terms of the GNU General Public License, version 2, as
|
18 |
+
published by the Free Software Foundation.
|
|
|
19 |
|
20 |
This program is distributed in the hope that it will be useful,
|
21 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
24 |
|
25 |
You should have received a copy of the GNU General Public License
|
26 |
along with this program; if not, write to the Free Software
|
27 |
+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
28 |
*/
|
29 |
|
30 |
|
31 |
### Function: Enqueue JavaScripts
|
32 |
+
add_action( 'wp_enqueue_scripts', 'showhide_scripts' );
|
33 |
function showhide_scripts() {
|
34 |
+
wp_enqueue_script( 'jquery' );
|
35 |
}
|
36 |
|
37 |
+
### Function: Load Translation
|
38 |
+
add_action( 'plugins_loaded', 'showhide_textdomain' );
|
39 |
+
function showhide_textdomain() {
|
40 |
+
load_plugin_textdomain( 'wp-showhide', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
|
41 |
+
}
|
42 |
|
43 |
### Function: Short Code For Inserting Press Release Into Post
|
44 |
+
add_shortcode( 'showhide', 'showhide_shortcode' );
|
45 |
+
function showhide_shortcode( $atts, $content = null ) {
|
46 |
// Variables
|
47 |
$post_id = get_the_id();
|
48 |
+
$word_count = number_format_i18n( sizeof( explode( ' ', strip_tags( $content ) ) ) );
|
49 |
|
50 |
// Extract ShortCode Attributes
|
51 |
+
$attributes = shortcode_atts( array(
|
52 |
'type' => 'pressrelease',
|
53 |
+
'more_text' => __( 'Show Press Release (%s More Words)', 'wp-showhide' ),
|
54 |
+
'less_text' => __( 'Hide Press Release (%s Less Words)', 'wp-showhide' ),
|
55 |
'hidden' => 'yes'
|
56 |
+
), $atts );
|
57 |
|
58 |
// More/Less Text
|
59 |
+
$more_text = sprintf( $attributes['more_text'], $word_count );
|
60 |
+
$less_text = sprintf( $attributes['less_text'], $word_count );
|
61 |
|
62 |
// Determine Whether To Show Or Hide Press Release
|
63 |
$hidden_class = 'sh-hide';
|
64 |
$hidden_css = 'display: none;';
|
65 |
+
$hidden_aria_expanded = 'false';
|
66 |
+
if( $attributes['hidden'] === 'no' ) {
|
67 |
$hidden_class = 'sh-show';
|
68 |
$hidden_css = 'display: block;';
|
69 |
+
$hidden_aria_expanded = 'true';
|
70 |
$tmp_text = $more_text;
|
71 |
$more_text = $less_text;
|
72 |
$less_text = $tmp_text;
|
73 |
}
|
74 |
|
75 |
// Format HTML Output
|
76 |
+
$output = '<div id="' . $attributes['type'] . '-link-' . $post_id . '" class="sh-link ' . $attributes['type'] . '-link ' . $hidden_class .'"><a href="#" onclick="showhide_toggle(\'' . esc_js( $attributes['type'] ) . '\', ' . $post_id . ', \'' . esc_js( $more_text ) . '\', \'' . esc_js( $less_text ) . '\'); return false;" aria-expanded="' . $hidden_aria_expanded .'"><span id="' . $attributes['type'] . '-toggle-' . $post_id . '">' . $more_text . '</span></a></div>';
|
77 |
+
$output .= '<div id="' . $attributes['type'] . '-content-' . $post_id . '" class="sh-content ' . $attributes['type'] . '-content ' . $hidden_class . '" style="' . $hidden_css . '">' . do_shortcode( $content ) . '</div>';
|
78 |
|
79 |
return $output;
|
80 |
}
|
81 |
|
|
|
82 |
### Function: Add JavaScript To Footer
|
83 |
+
add_action( 'wp_footer', 'showhide_footer' );
|
84 |
function showhide_footer() {
|
85 |
?>
|
86 |
+
<?php if( WP_DEBUG ): ?>
|
87 |
<script type="text/javascript">
|
88 |
function showhide_toggle(type, post_id, more_text, less_text) {
|
89 |
var $link = jQuery("#"+ type + "-link-" + post_id)
|
90 |
+
, $link_a = jQuery('a', $link)
|
91 |
, $content = jQuery("#"+ type + "-content-" + post_id)
|
92 |
, $toggle = jQuery("#"+ type + "-toggle-" + post_id)
|
93 |
, show_hide_class = 'sh-show sh-hide';
|
94 |
$link.toggleClass(show_hide_class);
|
95 |
$content.toggleClass(show_hide_class).toggle();
|
96 |
+
if($link_a.attr('aria-expanded') === 'true') {
|
97 |
+
$link_a.attr('aria-expanded', 'false');
|
98 |
+
} else {
|
99 |
+
$link_a.attr('aria-expanded', 'true');
|
100 |
+
}
|
101 |
if($toggle.text() === more_text) {
|
102 |
$toggle.text(less_text);
|
103 |
} else {
|
106 |
}
|
107 |
</script>
|
108 |
<?php else : ?>
|
109 |
+
<script type="text/javascript">function showhide_toggle(a,b,d,f){var e=jQuery("#"+a+"-link-"+b),c=jQuery("a",e),g=jQuery("#"+a+"-content-"+b);a=jQuery("#"+a+"-toggle-"+b);e.toggleClass("sh-show sh-hide");g.toggleClass("sh-show sh-hide").toggle();"true"===c.attr("aria-expanded")?c.attr("aria-expanded","false"):c.attr("aria-expanded","true");a.text()===d?a.text(f):a.text(d)};</script>
|
110 |
<?php endif; ?>
|
111 |
<?php
|
112 |
}
|