Version Description
Download this release
Release Info
Developer | studiopress |
Plugin | Simple Social Icons |
Version | 3.1.0 |
Comparing to | |
See all releases |
Code changes from version 3.0.2 to 3.1.0
- README.md +6 -2
- composer.json +8 -5
- package.json +1 -1
- readme.txt +2 -2
- simple-social-icons.php +213 -205
- svgxuse.js +0 -209
README.md
CHANGED
@@ -2,8 +2,8 @@
|
|
2 |
Contributors: studiopress, nathanrice, bgardner, dreamwhisper, laurenmancke, shannonsans, modernnerd, marksabbath, damiencarbery, helgatheviking, littlerchicken, tiagohillebrandt, wpmuguru, michaelbeil, norcross, rafaltomal
|
3 |
Tags: social media, social networking, social profiles
|
4 |
Requires at least: 4.0
|
5 |
-
Tested up to:
|
6 |
-
Stable tag: 3.
|
7 |
|
8 |
This plugin allows you to insert social icons in any widget area.
|
9 |
|
@@ -67,6 +67,10 @@ NOTE - The rights to each pictogram in the social extension are either trademark
|
|
67 |
|
68 |
== Changelog ==
|
69 |
|
|
|
|
|
|
|
|
|
70 |
= 3.0.0 =
|
71 |
* Obfuscate email address from spambots
|
72 |
* Prevent email links to open in new window if option selected
|
2 |
Contributors: studiopress, nathanrice, bgardner, dreamwhisper, laurenmancke, shannonsans, modernnerd, marksabbath, damiencarbery, helgatheviking, littlerchicken, tiagohillebrandt, wpmuguru, michaelbeil, norcross, rafaltomal
|
3 |
Tags: social media, social networking, social profiles
|
4 |
Requires at least: 4.0
|
5 |
+
Tested up to: 5.9
|
6 |
+
Stable tag: 3.1.0
|
7 |
|
8 |
This plugin allows you to insert social icons in any widget area.
|
9 |
|
67 |
|
68 |
== Changelog ==
|
69 |
|
70 |
+
= 3.1.0 =
|
71 |
+
* Add escaping to output
|
72 |
+
* Remove the svgxuse.js script
|
73 |
+
|
74 |
= 3.0.0 =
|
75 |
* Obfuscate email address from spambots
|
76 |
* Prevent email links to open in new window if option selected
|
composer.json
CHANGED
@@ -16,17 +16,20 @@
|
|
16 |
"wp-coding-standards/wpcs": "^1"
|
17 |
},
|
18 |
"config": {
|
19 |
-
"sort-order": true
|
|
|
|
|
|
|
|
|
20 |
},
|
21 |
"minimum-stability": "dev",
|
22 |
"prefer-stable": true,
|
23 |
"scripts": {
|
24 |
-
"phpcs": "phpcs
|
25 |
-
"
|
26 |
-
"phpcbf": "phpcbf --standard=WordPress --ignore=vendor/,node_modules/,assets/ --extensions=php -p ./"
|
27 |
},
|
28 |
"support": {
|
29 |
"issues": "https://github.com/studiopress/simple-social-icons/issues",
|
30 |
"source": "https://github.com/studiopress/simple-social-icons"
|
31 |
}
|
32 |
-
}
|
16 |
"wp-coding-standards/wpcs": "^1"
|
17 |
},
|
18 |
"config": {
|
19 |
+
"sort-order": true,
|
20 |
+
"allow-plugins": {
|
21 |
+
"composer/installers": true,
|
22 |
+
"dealerdirect/phpcodesniffer-composer-installer": true
|
23 |
+
}
|
24 |
},
|
25 |
"minimum-stability": "dev",
|
26 |
"prefer-stable": true,
|
27 |
"scripts": {
|
28 |
+
"phpcs": "phpcs",
|
29 |
+
"phpcbf": "phpcbf"
|
|
|
30 |
},
|
31 |
"support": {
|
32 |
"issues": "https://github.com/studiopress/simple-social-icons/issues",
|
33 |
"source": "https://github.com/studiopress/simple-social-icons"
|
34 |
}
|
35 |
+
}
|
package.json
CHANGED
@@ -14,7 +14,7 @@
|
|
14 |
"description": "A simple, CSS and icon font driven social icons widget.",
|
15 |
"author": "StudioPress",
|
16 |
"authoruri": "http://www.studiopress.com/",
|
17 |
-
"version": "3.0
|
18 |
"license": "GPL-2.0+",
|
19 |
"licenseuri": "http://www.gnu.org/licenses/gpl-2.0.html",
|
20 |
"textdomain": "simple-social-icons"
|
14 |
"description": "A simple, CSS and icon font driven social icons widget.",
|
15 |
"author": "StudioPress",
|
16 |
"authoruri": "http://www.studiopress.com/",
|
17 |
+
"version": "3.1.0",
|
18 |
"license": "GPL-2.0+",
|
19 |
"licenseuri": "http://www.gnu.org/licenses/gpl-2.0.html",
|
20 |
"textdomain": "simple-social-icons"
|
readme.txt
CHANGED
@@ -2,8 +2,8 @@
|
|
2 |
Contributors: studiopress, nathanrice, bgardner, dreamwhisper, laurenmancke, shannonsans, modernnerd, marksabbath, damiencarbery, helgatheviking, littlerchicken, tiagohillebrandt, wpmuguru, michaelbeil, norcross, rafaltomal
|
3 |
Tags: social media, social networking, social profiles
|
4 |
Requires at least: 4.0
|
5 |
-
Tested up to:
|
6 |
-
Stable tag: 3.0
|
7 |
|
8 |
This plugin allows you to insert social icons in any widget area.
|
9 |
|
2 |
Contributors: studiopress, nathanrice, bgardner, dreamwhisper, laurenmancke, shannonsans, modernnerd, marksabbath, damiencarbery, helgatheviking, littlerchicken, tiagohillebrandt, wpmuguru, michaelbeil, norcross, rafaltomal
|
3 |
Tags: social media, social networking, social profiles
|
4 |
Requires at least: 4.0
|
5 |
+
Tested up to: 6.0
|
6 |
+
Stable tag: 3.1.0
|
7 |
|
8 |
This plugin allows you to insert social icons in any widget area.
|
9 |
|
simple-social-icons.php
CHANGED
@@ -5,13 +5,13 @@
|
|
5 |
* Description: A simple CSS and SVG driven social icons widget.
|
6 |
* Author: StudioPress
|
7 |
* Author URI: https://www.studiopress.com/
|
8 |
-
* Version: 3.0
|
9 |
* Text Domain: simple-social-icons
|
10 |
* Domain Path: /languages
|
11 |
*
|
12 |
* License: GNU General Public License v2.0 (or later)
|
13 |
* License URI: https://www.opensource.org/licenses/gpl-license.php
|
14 |
-
*
|
15 |
* @package simple-social-icons
|
16 |
*/
|
17 |
|
@@ -23,6 +23,9 @@ function simple_social_icons_load_textdomain() {
|
|
23 |
load_plugin_textdomain( 'simple-social-icons', false, plugin_basename( dirname( __FILE__ ) ) . '/languages' );
|
24 |
}
|
25 |
|
|
|
|
|
|
|
26 |
class Simple_Social_Icons_Widget extends WP_Widget {
|
27 |
|
28 |
/**
|
@@ -72,7 +75,7 @@ class Simple_Social_Icons_Widget extends WP_Widget {
|
|
72 |
*
|
73 |
* Set some global values and create widget.
|
74 |
*/
|
75 |
-
function __construct() {
|
76 |
|
77 |
/**
|
78 |
* Filter for default widget option values.
|
@@ -81,42 +84,45 @@ class Simple_Social_Icons_Widget extends WP_Widget {
|
|
81 |
*
|
82 |
* @param array $defaults Default widget options.
|
83 |
*/
|
84 |
-
$this->defaults = apply_filters(
|
85 |
-
'
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
|
|
|
|
|
|
120 |
|
121 |
/**
|
122 |
* Filter for social profile choices.
|
@@ -125,96 +131,99 @@ class Simple_Social_Icons_Widget extends WP_Widget {
|
|
125 |
*
|
126 |
* @param array $profiles Social icons to include in widget options.
|
127 |
*/
|
128 |
-
$this->profiles = apply_filters(
|
129 |
-
'
|
130 |
-
|
131 |
-
'
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
'
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
'
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
'
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
'
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
'
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
'
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
'
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
'
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
'
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
'
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
'
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
'
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
'
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
'
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
'
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
'
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
'
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
'
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
'
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
'
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
'
|
216 |
-
|
217 |
-
|
|
|
|
|
|
|
218 |
|
219 |
/**
|
220 |
* Filter to disable output of custom CSS.
|
@@ -265,10 +274,12 @@ class Simple_Social_Icons_Widget extends WP_Widget {
|
|
265 |
*
|
266 |
* Enqueue the color picker script.
|
267 |
*
|
|
|
268 |
*/
|
269 |
-
function load_color_picker( $hook ) {
|
270 |
-
if( 'widgets.php'
|
271 |
return;
|
|
|
272 |
wp_enqueue_style( 'wp-color-picker' );
|
273 |
wp_enqueue_script( 'wp-color-picker' );
|
274 |
wp_enqueue_script( 'underscore' );
|
@@ -278,9 +289,8 @@ class Simple_Social_Icons_Widget extends WP_Widget {
|
|
278 |
* Print scripts.
|
279 |
*
|
280 |
* Reference https://core.trac.wordpress.org/attachment/ticket/25809/color-picker-widget.php
|
281 |
-
*
|
282 |
*/
|
283 |
-
function print_scripts() {
|
284 |
?>
|
285 |
<script>
|
286 |
( function( $ ){
|
@@ -317,47 +327,48 @@ class Simple_Social_Icons_Widget extends WP_Widget {
|
|
317 |
*
|
318 |
* Outputs the widget form that allows users to control the output of the widget.
|
319 |
*
|
|
|
320 |
*/
|
321 |
-
function form( $instance ) {
|
322 |
|
323 |
/** Merge with defaults */
|
324 |
$instance = wp_parse_args( (array) $instance, $this->defaults );
|
325 |
?>
|
326 |
|
327 |
-
<p><label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php
|
328 |
|
329 |
-
<p><label><input id="<?php echo $this->get_field_id( 'new_window' ); ?>" type="checkbox" name="<?php echo $this->get_field_name( 'new_window' ); ?>" value="1" <?php checked( 1, $instance['new_window'] ); ?>/> <?php esc_html_e( 'Open links in new window?', 'simple-social-icons' ); ?></label></p>
|
330 |
|
331 |
<?php if ( ! $this->disable_css_output ) { ?>
|
332 |
|
333 |
-
<p><label for="<?php echo $this->get_field_id( 'size' ); ?>"><?php
|
334 |
|
335 |
-
<p><label for="<?php echo $this->get_field_id( 'border_radius' ); ?>"><?php
|
336 |
|
337 |
-
<p><label for="<?php echo $this->get_field_id( 'border_width' ); ?>"><?php
|
338 |
|
339 |
<p>
|
340 |
-
<label for="<?php echo $this->get_field_id( 'alignment' ); ?>"><?php
|
341 |
-
<select id="<?php echo $this->get_field_id( 'alignment' ); ?>" name="<?php echo $this->get_field_name( 'alignment' ); ?>">
|
342 |
-
<option value="alignleft" <?php selected( 'alignright', $instance['alignment'] ) ?>><?php
|
343 |
-
<option value="aligncenter" <?php selected( 'aligncenter', $instance['alignment'] ) ?>><?php
|
344 |
-
<option value="alignright" <?php selected( 'alignright', $instance['alignment'] ) ?>><?php
|
345 |
</select>
|
346 |
</p>
|
347 |
|
348 |
<hr style="background: #ccc; border: 0; height: 1px; margin: 20px 0;" />
|
349 |
|
350 |
-
<p><label for="<?php echo $this->get_field_id( 'background_color' ); ?>"><?php
|
351 |
|
352 |
-
<p><label for="<?php echo $this->get_field_id( 'background_color_hover' ); ?>"><?php
|
353 |
|
354 |
-
<p><label for="<?php echo $this->get_field_id( 'background_color' ); ?>"><?php
|
355 |
|
356 |
-
<p><label for="<?php echo $this->get_field_id( 'background_color_hover' ); ?>"><?php
|
357 |
|
358 |
-
<p><label for="<?php echo $this->get_field_id( 'border_color' ); ?>"><?php
|
359 |
|
360 |
-
<p><label for="<?php echo $this->get_field_id( 'border_color_hover' ); ?>"><?php
|
361 |
|
362 |
<hr style="background: #ccc; border: 0; height: 1px; margin: 20px 0;" />
|
363 |
<?php } ?>
|
@@ -366,7 +377,7 @@ class Simple_Social_Icons_Widget extends WP_Widget {
|
|
366 |
foreach ( (array) $this->profiles as $profile => $data ) {
|
367 |
|
368 |
printf( '<p><label for="%s">%s:</label></p>', esc_attr( $this->get_field_id( $profile ) ), esc_attr( $data['label'] ) );
|
369 |
-
printf( '<p><input type="text" id="%s" name="%s" value="%s" class="widefat" />', esc_attr( $this->get_field_id( $profile ) ), esc_attr( $this->get_field_name( $profile ) ), $instance[ $profile ] );
|
370 |
printf( '</p>' );
|
371 |
|
372 |
}
|
@@ -378,8 +389,11 @@ class Simple_Social_Icons_Widget extends WP_Widget {
|
|
378 |
*
|
379 |
* Runs when you save the widget form. Allows you to validate or sanitize widget options before they are saved.
|
380 |
*
|
|
|
|
|
|
|
381 |
*/
|
382 |
-
function update( $newinstance, $oldinstance ) {
|
383 |
|
384 |
// Fields that can be transparent if their values are unset.
|
385 |
$can_be_transparent = array(
|
@@ -392,26 +406,20 @@ class Simple_Social_Icons_Widget extends WP_Widget {
|
|
392 |
foreach ( $newinstance as $key => $value ) {
|
393 |
|
394 |
/** Border radius and Icon size must not be empty, must be a digit */
|
395 |
-
if ( ( 'border_radius'
|
396 |
$newinstance[ $key ] = 0;
|
397 |
}
|
398 |
|
399 |
-
if ( ( 'border_width'
|
400 |
$newinstance[ $key ] = 0;
|
401 |
-
}
|
402 |
-
|
403 |
-
/** Accept empty colors for permitted keys. */
|
404 |
-
elseif ( in_array( $key, $can_be_transparent, true ) && '' == trim( $value ) ) {
|
405 |
$newinstance[ $key ] = '';
|
406 |
-
}
|
407 |
-
|
408 |
-
/** Validate hex code colors */
|
409 |
-
elseif ( strpos( $key, '_color' ) && 0 == preg_match( '/^#(([a-fA-F0-9]{3}$)|([a-fA-F0-9]{6}$))/', $value ) ) {
|
410 |
$newinstance[ $key ] = $oldinstance[ $key ];
|
411 |
-
}
|
412 |
-
|
413 |
-
/** Sanitize Profile URIs */
|
414 |
-
elseif ( array_key_exists( $key, (array) $this->profiles ) && ! is_email( $value ) && ! 'phone' === $key ) {
|
415 |
$newinstance[ $key ] = esc_url( $newinstance[ $key ] );
|
416 |
}
|
417 |
}
|
@@ -425,55 +433,60 @@ class Simple_Social_Icons_Widget extends WP_Widget {
|
|
425 |
*
|
426 |
* Outputs the actual widget on the front-end based on the widget options the user selected.
|
427 |
*
|
|
|
|
|
428 |
*/
|
429 |
-
function widget( $args, $instance ) {
|
430 |
-
|
431 |
-
extract( $args );
|
432 |
|
433 |
/** Merge with defaults */
|
434 |
$instance = wp_parse_args( (array) $instance, $this->defaults );
|
435 |
|
436 |
-
echo $before_widget;
|
437 |
|
438 |
-
|
439 |
-
|
|
|
440 |
|
441 |
$output = '';
|
442 |
|
443 |
$profiles = (array) $this->profiles;
|
444 |
|
445 |
-
|
446 |
-
|
447 |
-
if ( empty( $instance[ $profile ] ) )
|
448 |
-
continue;
|
449 |
|
450 |
-
|
451 |
-
|
452 |
-
|
453 |
-
$new_window = '';
|
454 |
|
455 |
-
|
456 |
-
$output .= sprintf( $data['pattern'], 'mailto:' . esc_attr( antispambot( $instance[ $profile ] ) ), $new_window );
|
457 |
-
} elseif ( 'phone' === $profile ) {
|
458 |
-
$output .= sprintf( $data['pattern'], 'tel:' . esc_attr( antispambot( $instance[ $profile ] ) ), $new_window );
|
459 |
-
} else {
|
460 |
-
$output .= sprintf( $data['pattern'], esc_url( $instance[ $profile ] ), $new_window );
|
461 |
-
}
|
462 |
|
|
|
|
|
463 |
}
|
464 |
|
465 |
-
if ( $
|
466 |
-
$output
|
467 |
-
|
|
|
|
|
|
|
468 |
}
|
|
|
469 |
|
470 |
-
|
|
|
|
|
|
|
|
|
|
|
471 |
|
472 |
$this->active_instances[] = $this->number;
|
473 |
|
474 |
}
|
475 |
|
476 |
-
|
|
|
|
|
|
|
477 |
|
478 |
/**
|
479 |
* Filter the plugin stylesheet location.
|
@@ -485,10 +498,6 @@ class Simple_Social_Icons_Widget extends WP_Widget {
|
|
485 |
$cssfile = apply_filters( 'simple_social_default_stylesheet', plugin_dir_url( __FILE__ ) . 'css/style.css' );
|
486 |
|
487 |
wp_enqueue_style( 'simple-social-icons-font', esc_url( $cssfile ), array(), $this->version, 'all' );
|
488 |
-
|
489 |
-
if ( ! function_exists( 'is_amp_endpoint' ) || ( function_exists( 'is_amp_endpoint' ) && ! is_amp_endpoint() ) ) {
|
490 |
-
wp_enqueue_script('svg-x-use', plugin_dir_url(__FILE__) . 'svgxuse.js', array(), '1.1.21' );
|
491 |
-
}
|
492 |
}
|
493 |
|
494 |
/**
|
@@ -496,7 +505,7 @@ class Simple_Social_Icons_Widget extends WP_Widget {
|
|
496 |
*
|
497 |
* Outputs custom CSS to control the look of the icons.
|
498 |
*/
|
499 |
-
function css() {
|
500 |
|
501 |
/** Pull widget settings, merge with defaults */
|
502 |
$all_instances = $this->get_settings();
|
@@ -550,22 +559,22 @@ class Simple_Social_Icons_Widget extends WP_Widget {
|
|
550 |
$css = str_replace( "\t", '', $css );
|
551 |
$css = str_replace( array( "\n", "\r" ), ' ', $css );
|
552 |
|
553 |
-
echo '<style type="text/css" media="screen">' . $css . '</style>';
|
554 |
|
555 |
}
|
556 |
|
557 |
/**
|
558 |
* Construct the markup for each icon
|
559 |
*
|
560 |
-
* @param string The lowercase icon name for use in tag attributes.
|
561 |
-
* @param string The plain text icon label.
|
562 |
*
|
563 |
* @return string The full markup for the given icon.
|
564 |
*/
|
565 |
-
function get_icon_markup( $icon, $label ) {
|
566 |
-
$markup
|
567 |
-
$markup .= '<svg role="img" class="social-' . $icon . '" aria-labelledby="social-' . $icon . '-{WIDGET_INSTANCE_ID}">';
|
568 |
-
$markup .= '<title id="social-' . $icon . '-{WIDGET_INSTANCE_ID}
|
569 |
$markup .= '<use xlink:href="' . esc_attr( plugin_dir_url( __FILE__ ) . 'symbol-defs.svg#social-' . $icon ) . '"></use>';
|
570 |
$markup .= '</svg></a></li>';
|
571 |
|
@@ -599,7 +608,6 @@ add_action( 'widgets_init', 'ssiw_load_widget' );
|
|
599 |
* Widget Registration.
|
600 |
*
|
601 |
* Register Simple Social Icons widget.
|
602 |
-
*
|
603 |
*/
|
604 |
function ssiw_load_widget() {
|
605 |
|
5 |
* Description: A simple CSS and SVG driven social icons widget.
|
6 |
* Author: StudioPress
|
7 |
* Author URI: https://www.studiopress.com/
|
8 |
+
* Version: 3.1.0
|
9 |
* Text Domain: simple-social-icons
|
10 |
* Domain Path: /languages
|
11 |
*
|
12 |
* License: GNU General Public License v2.0 (or later)
|
13 |
* License URI: https://www.opensource.org/licenses/gpl-license.php
|
14 |
+
*
|
15 |
* @package simple-social-icons
|
16 |
*/
|
17 |
|
23 |
load_plugin_textdomain( 'simple-social-icons', false, plugin_basename( dirname( __FILE__ ) ) . '/languages' );
|
24 |
}
|
25 |
|
26 |
+
/**
|
27 |
+
* The Simple Social Icons widget.
|
28 |
+
*/
|
29 |
class Simple_Social_Icons_Widget extends WP_Widget {
|
30 |
|
31 |
/**
|
75 |
*
|
76 |
* Set some global values and create widget.
|
77 |
*/
|
78 |
+
public function __construct() {
|
79 |
|
80 |
/**
|
81 |
* Filter for default widget option values.
|
84 |
*
|
85 |
* @param array $defaults Default widget options.
|
86 |
*/
|
87 |
+
$this->defaults = apply_filters(
|
88 |
+
'simple_social_default_styles',
|
89 |
+
array(
|
90 |
+
'title' => '',
|
91 |
+
'new_window' => 0,
|
92 |
+
'size' => 36,
|
93 |
+
'border_radius' => 3,
|
94 |
+
'border_width' => 0,
|
95 |
+
'border_color' => '#ffffff',
|
96 |
+
'border_color_hover' => '#ffffff',
|
97 |
+
'icon_color' => '#ffffff',
|
98 |
+
'icon_color_hover' => '#ffffff',
|
99 |
+
'background_color' => '#999999',
|
100 |
+
'background_color_hover' => '#666666',
|
101 |
+
'alignment' => 'alignleft',
|
102 |
+
'behance' => '',
|
103 |
+
'bloglovin' => '',
|
104 |
+
'dribbble' => '',
|
105 |
+
'email' => '',
|
106 |
+
'facebook' => '',
|
107 |
+
'flickr' => '',
|
108 |
+
'github' => '',
|
109 |
+
'gplus' => '',
|
110 |
+
'instagram' => '',
|
111 |
+
'linkedin' => '',
|
112 |
+
'medium' => '',
|
113 |
+
'periscope' => '',
|
114 |
+
'phone' => '',
|
115 |
+
'pinterest' => '',
|
116 |
+
'rss' => '',
|
117 |
+
'snapchat' => '',
|
118 |
+
'stumbleupon' => '',
|
119 |
+
'tumblr' => '',
|
120 |
+
'twitter' => '',
|
121 |
+
'vimeo' => '',
|
122 |
+
'xing' => '',
|
123 |
+
'youtube' => '',
|
124 |
+
)
|
125 |
+
);
|
126 |
|
127 |
/**
|
128 |
* Filter for social profile choices.
|
131 |
*
|
132 |
* @param array $profiles Social icons to include in widget options.
|
133 |
*/
|
134 |
+
$this->profiles = apply_filters(
|
135 |
+
'simple_social_default_profiles',
|
136 |
+
array(
|
137 |
+
'behance' => array(
|
138 |
+
'label' => __( 'Behance URI', 'simple-social-icons' ),
|
139 |
+
'pattern' => $this->get_icon_markup( 'behance', __( 'Behance', 'simple-social-icons' ) ),
|
140 |
+
),
|
141 |
+
'bloglovin' => array(
|
142 |
+
'label' => __( 'Bloglovin URI', 'simple-social-icons' ),
|
143 |
+
'pattern' => $this->get_icon_markup( 'bloglovin', __( 'Bloglovin', 'simple-social-icons' ) ),
|
144 |
+
),
|
145 |
+
'dribbble' => array(
|
146 |
+
'label' => __( 'Dribbble URI', 'simple-social-icons' ),
|
147 |
+
'pattern' => $this->get_icon_markup( 'dribbble', __( 'Dribbble', 'simple-social-icons' ) ),
|
148 |
+
),
|
149 |
+
'email' => array(
|
150 |
+
'label' => __( 'Email URI', 'simple-social-icons' ),
|
151 |
+
'pattern' => $this->get_icon_markup( 'email', __( 'Email', 'simple-social-icons' ) ),
|
152 |
+
),
|
153 |
+
'facebook' => array(
|
154 |
+
'label' => __( 'Facebook URI', 'simple-social-icons' ),
|
155 |
+
'pattern' => $this->get_icon_markup( 'facebook', __( 'Facebook', 'simple-social-icons' ) ),
|
156 |
+
),
|
157 |
+
'flickr' => array(
|
158 |
+
'label' => __( 'Flickr URI', 'simple-social-icons' ),
|
159 |
+
'pattern' => $this->get_icon_markup( 'flickr', __( 'Flickr', 'simple-social-icons' ) ),
|
160 |
+
),
|
161 |
+
'github' => array(
|
162 |
+
'label' => __( 'GitHub URI', 'simple-social-icons' ),
|
163 |
+
'pattern' => $this->get_icon_markup( 'github', __( 'GitHub', 'simple-social-icons' ) ),
|
164 |
+
),
|
165 |
+
'gplus' => array(
|
166 |
+
'label' => __( 'Google+ URI', 'simple-social-icons' ),
|
167 |
+
'pattern' => $this->get_icon_markup( 'gplus', __( 'Google+', 'simple-social-icons' ) ),
|
168 |
+
),
|
169 |
+
'instagram' => array(
|
170 |
+
'label' => __( 'Instagram URI', 'simple-social-icons' ),
|
171 |
+
'pattern' => $this->get_icon_markup( 'instagram', __( 'Instagram', 'simple-social-icons' ) ),
|
172 |
+
),
|
173 |
+
'linkedin' => array(
|
174 |
+
'label' => __( 'Linkedin URI', 'simple-social-icons' ),
|
175 |
+
'pattern' => $this->get_icon_markup( 'linkedin', __( 'LinkedIn', 'simple-social-icons' ) ),
|
176 |
+
),
|
177 |
+
'medium' => array(
|
178 |
+
'label' => __( 'Medium URI', 'simple-social-icons' ),
|
179 |
+
'pattern' => $this->get_icon_markup( 'medium', __( 'Medium', 'simple-social-icons' ) ),
|
180 |
+
),
|
181 |
+
'periscope' => array(
|
182 |
+
'label' => __( 'Periscope URI', 'simple-social-icons' ),
|
183 |
+
'pattern' => $this->get_icon_markup( 'periscope', __( 'Periscope', 'simple-social-icons' ) ),
|
184 |
+
),
|
185 |
+
'phone' => array(
|
186 |
+
'label' => __( 'Phone URI', 'simple-social-icons' ),
|
187 |
+
'pattern' => $this->get_icon_markup( 'phone', __( 'Phone', 'simple-social-icons' ) ),
|
188 |
+
),
|
189 |
+
'pinterest' => array(
|
190 |
+
'label' => __( 'Pinterest URI', 'simple-social-icons' ),
|
191 |
+
'pattern' => $this->get_icon_markup( 'pinterest', __( 'Pinterest', 'simple-social-icons' ) ),
|
192 |
+
),
|
193 |
+
'rss' => array(
|
194 |
+
'label' => __( 'RSS URI', 'simple-social-icons' ),
|
195 |
+
'pattern' => $this->get_icon_markup( 'rss', __( 'RSS', 'simple-social-icons' ) ),
|
196 |
+
),
|
197 |
+
'snapchat' => array(
|
198 |
+
'label' => __( 'Snapchat URI', 'simple-social-icons' ),
|
199 |
+
'pattern' => $this->get_icon_markup( 'snapchat', __( 'Snapchat', 'simple-social-icons' ) ),
|
200 |
+
),
|
201 |
+
'stumbleupon' => array(
|
202 |
+
'label' => __( 'StumbleUpon URI', 'simple-social-icons' ),
|
203 |
+
'pattern' => $this->get_icon_markup( 'stumbleupon', __( 'StumbleUpon', 'simple-social-icons' ) ),
|
204 |
+
),
|
205 |
+
'tumblr' => array(
|
206 |
+
'label' => __( 'Tumblr URI', 'simple-social-icons' ),
|
207 |
+
'pattern' => $this->get_icon_markup( 'tumblr', __( 'Tumblr', 'simple-social-icons' ) ),
|
208 |
+
),
|
209 |
+
'twitter' => array(
|
210 |
+
'label' => __( 'Twitter URI', 'simple-social-icons' ),
|
211 |
+
'pattern' => $this->get_icon_markup( 'twitter', __( 'Twitter', 'simple-social-icons' ) ),
|
212 |
+
),
|
213 |
+
'vimeo' => array(
|
214 |
+
'label' => __( 'Vimeo URI', 'simple-social-icons' ),
|
215 |
+
'pattern' => $this->get_icon_markup( 'vimeo', __( 'Vimeo', 'simple-social-icons' ) ),
|
216 |
+
),
|
217 |
+
'xing' => array(
|
218 |
+
'label' => __( 'Xing URI', 'simple-social-icons' ),
|
219 |
+
'pattern' => $this->get_icon_markup( 'xing', __( 'xing', 'simple-social-icons' ) ),
|
220 |
+
),
|
221 |
+
'youtube' => array(
|
222 |
+
'label' => __( 'YouTube URI', 'simple-social-icons' ),
|
223 |
+
'pattern' => $this->get_icon_markup( 'youtube', __( 'YouTube', 'simple-social-icons' ) ),
|
224 |
+
),
|
225 |
+
)
|
226 |
+
);
|
227 |
|
228 |
/**
|
229 |
* Filter to disable output of custom CSS.
|
274 |
*
|
275 |
* Enqueue the color picker script.
|
276 |
*
|
277 |
+
* @param string $hook The current admin page.
|
278 |
*/
|
279 |
+
public function load_color_picker( $hook ) {
|
280 |
+
if ( 'widgets.php' !== $hook ) {
|
281 |
return;
|
282 |
+
}
|
283 |
wp_enqueue_style( 'wp-color-picker' );
|
284 |
wp_enqueue_script( 'wp-color-picker' );
|
285 |
wp_enqueue_script( 'underscore' );
|
289 |
* Print scripts.
|
290 |
*
|
291 |
* Reference https://core.trac.wordpress.org/attachment/ticket/25809/color-picker-widget.php
|
|
|
292 |
*/
|
293 |
+
public function print_scripts() {
|
294 |
?>
|
295 |
<script>
|
296 |
( function( $ ){
|
327 |
*
|
328 |
* Outputs the widget form that allows users to control the output of the widget.
|
329 |
*
|
330 |
+
* @param array $instance The widget settings.
|
331 |
*/
|
332 |
+
public function form( $instance ) {
|
333 |
|
334 |
/** Merge with defaults */
|
335 |
$instance = wp_parse_args( (array) $instance, $this->defaults );
|
336 |
?>
|
337 |
|
338 |
+
<p><label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"><?php esc_html_e( 'Title:', 'simple-social-icons' ); ?></label> <input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'title' ) ); ?>" type="text" value="<?php echo esc_attr( $instance['title'] ); ?>" /></p>
|
339 |
|
340 |
+
<p><label><input id="<?php echo esc_attr( $this->get_field_id( 'new_window' ) ); ?>" type="checkbox" name="<?php echo esc_attr( $this->get_field_name( 'new_window' ) ); ?>" value="1" <?php checked( 1, $instance['new_window'] ); ?>/> <?php esc_html_e( 'Open links in new window?', 'simple-social-icons' ); ?></label></p>
|
341 |
|
342 |
<?php if ( ! $this->disable_css_output ) { ?>
|
343 |
|
344 |
+
<p><label for="<?php echo esc_attr( $this->get_field_id( 'size' ) ); ?>"><?php esc_html_e( 'Icon Size', 'simple-social-icons' ); ?>:</label> <input id="<?php echo esc_attr( $this->get_field_id( 'size' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'size' ) ); ?>" type="text" value="<?php echo esc_attr( $instance['size'] ); ?>" size="3" />px</p>
|
345 |
|
346 |
+
<p><label for="<?php echo esc_attr( $this->get_field_id( 'border_radius' ) ); ?>"><?php esc_html_e( 'Icon Border Radius:', 'simple-social-icons' ); ?></label> <input id="<?php echo esc_attr( $this->get_field_id( 'border_radius' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'border_radius' ) ); ?>" type="text" value="<?php echo esc_attr( $instance['border_radius'] ); ?>" size="3" />px</p>
|
347 |
|
348 |
+
<p><label for="<?php echo esc_attr( $this->get_field_id( 'border_width' ) ); ?>"><?php esc_html_e( 'Border Width:', 'simple-social-icons' ); ?></label> <input id="<?php echo esc_attr( $this->get_field_id( 'border_width' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'border_width' ) ); ?>" type="text" value="<?php echo esc_attr( $instance['border_width'] ); ?>" size="3" />px</p>
|
349 |
|
350 |
<p>
|
351 |
+
<label for="<?php echo esc_attr( $this->get_field_id( 'alignment' ) ); ?>"><?php esc_html_e( 'Alignment', 'simple-social-icons' ); ?>:</label>
|
352 |
+
<select id="<?php echo esc_attr( $this->get_field_id( 'alignment' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'alignment' ) ); ?>">
|
353 |
+
<option value="alignleft" <?php selected( 'alignright', $instance['alignment'] ); ?>><?php esc_html_e( 'Align Left', 'simple-social-icons' ); ?></option>
|
354 |
+
<option value="aligncenter" <?php selected( 'aligncenter', $instance['alignment'] ); ?>><?php esc_html_e( 'Align Center', 'simple-social-icons' ); ?></option>
|
355 |
+
<option value="alignright" <?php selected( 'alignright', $instance['alignment'] ); ?>><?php esc_html_e( 'Align Right', 'simple-social-icons' ); ?></option>
|
356 |
</select>
|
357 |
</p>
|
358 |
|
359 |
<hr style="background: #ccc; border: 0; height: 1px; margin: 20px 0;" />
|
360 |
|
361 |
+
<p><label for="<?php echo esc_attr( $this->get_field_id( 'background_color' ) ); ?>"><?php esc_html_e( 'Icon Color:', 'simple-social-icons' ); ?></label><br /> <input id="<?php echo esc_attr( $this->get_field_id( 'icon_color' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'icon_color' ) ); ?>" type="text" class="ssiw-color-picker" data-default-color="<?php echo esc_attr( $this->defaults['icon_color'] ); ?>" value="<?php echo esc_attr( $instance['icon_color'] ); ?>" size="6" /></p>
|
362 |
|
363 |
+
<p><label for="<?php echo esc_attr( $this->get_field_id( 'background_color_hover' ) ); ?>"><?php esc_html_e( 'Icon Hover Color:', 'simple-social-icons' ); ?></label><br /> <input id="<?php echo esc_attr( $this->get_field_id( 'icon_color_hover' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'icon_color_hover' ) ); ?>" type="text" class="ssiw-color-picker" data-default-color="<?php echo esc_attr( $this->defaults['icon_color_hover'] ); ?>" value="<?php echo esc_attr( $instance['icon_color_hover'] ); ?>" size="6" /></p>
|
364 |
|
365 |
+
<p><label for="<?php echo esc_attr( $this->get_field_id( 'background_color' ) ); ?>"><?php esc_html_e( 'Background Color:', 'simple-social-icons' ); ?></label><br /> <input id="<?php echo esc_attr( $this->get_field_id( 'background_color' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'background_color' ) ); ?>" type="text" class="ssiw-color-picker" data-default-color="<?php echo esc_attr( $this->defaults['background_color'] ); ?>" value="<?php echo esc_attr( $instance['background_color'] ); ?>" size="6" /></p>
|
366 |
|
367 |
+
<p><label for="<?php echo esc_attr( $this->get_field_id( 'background_color_hover' ) ); ?>"><?php esc_html_e( 'Background Hover Color:', 'simple-social-icons' ); ?></label><br /> <input id="<?php echo esc_attr( $this->get_field_id( 'background_color_hover' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'background_color_hover' ) ); ?>" type="text" class="ssiw-color-picker" data-default-color="<?php echo esc_attr( $this->defaults['background_color_hover'] ); ?>" value="<?php echo esc_attr( $instance['background_color_hover'] ); ?>" size="6" /></p>
|
368 |
|
369 |
+
<p><label for="<?php echo esc_attr( $this->get_field_id( 'border_color' ) ); ?>"><?php esc_html_e( 'Border Color:', 'simple-social-icons' ); ?></label><br /> <input id="<?php echo esc_attr( $this->get_field_id( 'border_color' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'border_color' ) ); ?>" type="text" class="ssiw-color-picker" data-default-color="<?php echo esc_attr( $this->defaults['border_color'] ); ?>" value="<?php echo esc_attr( $instance['border_color'] ); ?>" size="6" /></p>
|
370 |
|
371 |
+
<p><label for="<?php echo esc_attr( $this->get_field_id( 'border_color_hover' ) ); ?>"><?php esc_html_e( 'Border Hover Color:', 'simple-social-icons' ); ?></label><br /> <input id="<?php echo esc_attr( $this->get_field_id( 'border_color_hover' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'border_color_hover' ) ); ?>" type="text" class="ssiw-color-picker" data-default-color="<?php echo esc_attr( $this->defaults['border_color_hover'] ); ?>" value="<?php echo esc_attr( $instance['border_color_hover'] ); ?>" size="6" /></p>
|
372 |
|
373 |
<hr style="background: #ccc; border: 0; height: 1px; margin: 20px 0;" />
|
374 |
<?php } ?>
|
377 |
foreach ( (array) $this->profiles as $profile => $data ) {
|
378 |
|
379 |
printf( '<p><label for="%s">%s:</label></p>', esc_attr( $this->get_field_id( $profile ) ), esc_attr( $data['label'] ) );
|
380 |
+
printf( '<p><input type="text" id="%s" name="%s" value="%s" class="widefat" />', esc_attr( $this->get_field_id( $profile ) ), esc_attr( $this->get_field_name( $profile ) ), esc_attr( $instance[ $profile ] ) );
|
381 |
printf( '</p>' );
|
382 |
|
383 |
}
|
389 |
*
|
390 |
* Runs when you save the widget form. Allows you to validate or sanitize widget options before they are saved.
|
391 |
*
|
392 |
+
* @param array $newinstance The new settings.
|
393 |
+
* @param array $oldinstance The old settings.
|
394 |
+
* @return array The settings to save.
|
395 |
*/
|
396 |
+
public function update( $newinstance, $oldinstance ) {
|
397 |
|
398 |
// Fields that can be transparent if their values are unset.
|
399 |
$can_be_transparent = array(
|
406 |
foreach ( $newinstance as $key => $value ) {
|
407 |
|
408 |
/** Border radius and Icon size must not be empty, must be a digit */
|
409 |
+
if ( ( 'border_radius' === $key || 'size' === $key ) && ( '' === $value || ! ctype_digit( $value ) ) ) {
|
410 |
$newinstance[ $key ] = 0;
|
411 |
}
|
412 |
|
413 |
+
if ( ( 'border_width' === $key || 'size' === $key ) && ( '' === $value || ! ctype_digit( $value ) ) ) {
|
414 |
$newinstance[ $key ] = 0;
|
415 |
+
} elseif ( in_array( $key, $can_be_transparent, true ) && '' === trim( $value ) ) {
|
416 |
+
// Accept empty colors for permitted keys.
|
|
|
|
|
417 |
$newinstance[ $key ] = '';
|
418 |
+
} elseif ( strpos( $key, '_color' ) && 0 === preg_match( '/^#(([a-fA-F0-9]{3}$)|([a-fA-F0-9]{6}$))/', $value ) ) {
|
419 |
+
// Validate hex code colors.
|
|
|
|
|
420 |
$newinstance[ $key ] = $oldinstance[ $key ];
|
421 |
+
} elseif ( array_key_exists( $key, (array) $this->profiles ) && ! is_email( $value ) && ! 'phone' === $key ) {
|
422 |
+
// Sanitize Profile URIs.
|
|
|
|
|
423 |
$newinstance[ $key ] = esc_url( $newinstance[ $key ] );
|
424 |
}
|
425 |
}
|
433 |
*
|
434 |
* Outputs the actual widget on the front-end based on the widget options the user selected.
|
435 |
*
|
436 |
+
* @param array $args The display args.
|
437 |
+
* @param array $instance The instance settings.
|
438 |
*/
|
439 |
+
public function widget( $args, $instance ) {
|
|
|
|
|
440 |
|
441 |
/** Merge with defaults */
|
442 |
$instance = wp_parse_args( (array) $instance, $this->defaults );
|
443 |
|
444 |
+
echo $args['before_widget']; // phpcs:ignore
|
445 |
|
446 |
+
if ( ! empty( $instance['title'] ) ) {
|
447 |
+
echo $args['before_title'] . apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base ) . $args['after_title']; // phpcs:ignore
|
448 |
+
}
|
449 |
|
450 |
$output = '';
|
451 |
|
452 |
$profiles = (array) $this->profiles;
|
453 |
|
454 |
+
foreach ( $profiles as $profile => $data ) {
|
|
|
|
|
|
|
455 |
|
456 |
+
if ( empty( $instance[ $profile ] ) ) {
|
457 |
+
continue;
|
458 |
+
}
|
|
|
459 |
|
460 |
+
$new_window = $instance['new_window'] ? 'target="_blank" rel="noopener noreferrer"' : '';
|
|
|
|
|
|
|
|
|
|
|
|
|
461 |
|
462 |
+
if ( is_email( $instance[ $profile ] ) || false !== strpos( $instance[ $profile ], 'mailto:' ) ) {
|
463 |
+
$new_window = '';
|
464 |
}
|
465 |
|
466 |
+
if ( is_email( $instance[ $profile ] ) ) {
|
467 |
+
$output .= sprintf( $data['pattern'], 'mailto:' . esc_attr( antispambot( $instance[ $profile ] ) ), $new_window );
|
468 |
+
} elseif ( 'phone' === $profile ) {
|
469 |
+
$output .= sprintf( $data['pattern'], 'tel:' . esc_attr( antispambot( $instance[ $profile ] ) ), $new_window );
|
470 |
+
} else {
|
471 |
+
$output .= sprintf( $data['pattern'], esc_url( $instance[ $profile ] ), $new_window );
|
472 |
}
|
473 |
+
}
|
474 |
|
475 |
+
if ( $output ) {
|
476 |
+
$output = str_replace( '{WIDGET_INSTANCE_ID}', $this->number, $output );
|
477 |
+
printf( '<ul class="%s">%s</ul>', esc_attr( $instance['alignment'] ), $output ); // phpcs:ignore
|
478 |
+
}
|
479 |
+
|
480 |
+
echo $args['after_widget']; // phpcs:ignore
|
481 |
|
482 |
$this->active_instances[] = $this->number;
|
483 |
|
484 |
}
|
485 |
|
486 |
+
/**
|
487 |
+
* Enqueues the CSS.
|
488 |
+
*/
|
489 |
+
public function enqueue_css() {
|
490 |
|
491 |
/**
|
492 |
* Filter the plugin stylesheet location.
|
498 |
$cssfile = apply_filters( 'simple_social_default_stylesheet', plugin_dir_url( __FILE__ ) . 'css/style.css' );
|
499 |
|
500 |
wp_enqueue_style( 'simple-social-icons-font', esc_url( $cssfile ), array(), $this->version, 'all' );
|
|
|
|
|
|
|
|
|
501 |
}
|
502 |
|
503 |
/**
|
505 |
*
|
506 |
* Outputs custom CSS to control the look of the icons.
|
507 |
*/
|
508 |
+
public function css() {
|
509 |
|
510 |
/** Pull widget settings, merge with defaults */
|
511 |
$all_instances = $this->get_settings();
|
559 |
$css = str_replace( "\t", '', $css );
|
560 |
$css = str_replace( array( "\n", "\r" ), ' ', $css );
|
561 |
|
562 |
+
echo '<style type="text/css" media="screen">' . wp_strip_all_tags( $css ) . '</style>'; // phpcs:ignore
|
563 |
|
564 |
}
|
565 |
|
566 |
/**
|
567 |
* Construct the markup for each icon
|
568 |
*
|
569 |
+
* @param string $icon The lowercase icon name for use in tag attributes.
|
570 |
+
* @param string $label The plain text icon label.
|
571 |
*
|
572 |
* @return string The full markup for the given icon.
|
573 |
*/
|
574 |
+
public function get_icon_markup( $icon, $label ) {
|
575 |
+
$markup = '<li class="ssi-' . esc_attr( $icon ) . '"><a href="%s" %s>';
|
576 |
+
$markup .= '<svg role="img" class="social-' . esc_attr( $icon ) . '" aria-labelledby="social-' . esc_attr( $icon ) . '-{WIDGET_INSTANCE_ID}">';
|
577 |
+
$markup .= '<title id="social-' . esc_attr( $icon ) . '-{WIDGET_INSTANCE_ID}">' . esc_html( $label ) . '</title>';
|
578 |
$markup .= '<use xlink:href="' . esc_attr( plugin_dir_url( __FILE__ ) . 'symbol-defs.svg#social-' . $icon ) . '"></use>';
|
579 |
$markup .= '</svg></a></li>';
|
580 |
|
608 |
* Widget Registration.
|
609 |
*
|
610 |
* Register Simple Social Icons widget.
|
|
|
611 |
*/
|
612 |
function ssiw_load_widget() {
|
613 |
|
svgxuse.js
DELETED
@@ -1,209 +0,0 @@
|
|
1 |
-
/*!
|
2 |
-
* @copyright Copyright (c) 2016 IcoMoon.io
|
3 |
-
* @license Licensed under MIT license
|
4 |
-
* See https://github.com/Keyamoon/svgxuse
|
5 |
-
* @version 1.1.21
|
6 |
-
*/
|
7 |
-
/*jslint browser: true */
|
8 |
-
/*global XDomainRequest, MutationObserver, window */
|
9 |
-
(function () {
|
10 |
-
'use strict';
|
11 |
-
if (window && window.addEventListener) {
|
12 |
-
var cache = Object.create(null); // holds xhr objects to prevent multiple requests
|
13 |
-
var checkUseElems;
|
14 |
-
var tid; // timeout id
|
15 |
-
var debouncedCheck = function () {
|
16 |
-
clearTimeout(tid);
|
17 |
-
tid = setTimeout(checkUseElems, 100);
|
18 |
-
};
|
19 |
-
var unobserveChanges = function () {
|
20 |
-
return;
|
21 |
-
};
|
22 |
-
var observeChanges = function () {
|
23 |
-
var observer;
|
24 |
-
window.addEventListener('resize', debouncedCheck, false);
|
25 |
-
window.addEventListener('orientationchange', debouncedCheck, false);
|
26 |
-
if (window.MutationObserver) {
|
27 |
-
observer = new MutationObserver(debouncedCheck);
|
28 |
-
observer.observe(document.documentElement, {
|
29 |
-
childList: true,
|
30 |
-
subtree: true,
|
31 |
-
attributes: true
|
32 |
-
});
|
33 |
-
unobserveChanges = function () {
|
34 |
-
try {
|
35 |
-
observer.disconnect();
|
36 |
-
window.removeEventListener('resize', debouncedCheck, false);
|
37 |
-
window.removeEventListener('orientationchange', debouncedCheck, false);
|
38 |
-
} catch (ignore) {}
|
39 |
-
};
|
40 |
-
} else {
|
41 |
-
document.documentElement.addEventListener('DOMSubtreeModified', debouncedCheck, false);
|
42 |
-
unobserveChanges = function () {
|
43 |
-
document.documentElement.removeEventListener('DOMSubtreeModified', debouncedCheck, false);
|
44 |
-
window.removeEventListener('resize', debouncedCheck, false);
|
45 |
-
window.removeEventListener('orientationchange', debouncedCheck, false);
|
46 |
-
};
|
47 |
-
}
|
48 |
-
};
|
49 |
-
var createRequest = function (url) {
|
50 |
-
// In IE 9, cross domain requests can only be sent using XDomainRequest.
|
51 |
-
// XDomainRequest would fail if CORS headers are not set.
|
52 |
-
// Therefore, XDomainRequest should only be used with cross domain requests.
|
53 |
-
function getHostname(href) {
|
54 |
-
var a = document.createElement('a');
|
55 |
-
a.href = href;
|
56 |
-
return a.hostname;
|
57 |
-
}
|
58 |
-
var Request;
|
59 |
-
var hname = location.hostname;
|
60 |
-
var hname2;
|
61 |
-
if (window.XMLHttpRequest) {
|
62 |
-
Request = new XMLHttpRequest();
|
63 |
-
hname2 = getHostname(url);
|
64 |
-
if (Request.withCredentials === undefined && hname2 !== '' && hname2 !== hname) {
|
65 |
-
Request = XDomainRequest || undefined;
|
66 |
-
} else {
|
67 |
-
Request = XMLHttpRequest;
|
68 |
-
}
|
69 |
-
}
|
70 |
-
return Request;
|
71 |
-
};
|
72 |
-
var xlinkNS = 'http://www.w3.org/1999/xlink';
|
73 |
-
checkUseElems = function () {
|
74 |
-
var base;
|
75 |
-
var bcr;
|
76 |
-
var fallback = ''; // optional fallback URL in case no base path to SVG file was given and no symbol definition was found.
|
77 |
-
var hash;
|
78 |
-
var href;
|
79 |
-
var i;
|
80 |
-
var inProgressCount = 0;
|
81 |
-
var isHidden;
|
82 |
-
var Request;
|
83 |
-
var url;
|
84 |
-
var uses;
|
85 |
-
var xhr;
|
86 |
-
function observeIfDone() {
|
87 |
-
// If done with making changes, start watching for chagnes in DOM again
|
88 |
-
inProgressCount -= 1;
|
89 |
-
if (inProgressCount === 0) { // if all xhrs were resolved
|
90 |
-
unobserveChanges(); // make sure to remove old handlers
|
91 |
-
observeChanges(); // watch for changes to DOM
|
92 |
-
}
|
93 |
-
}
|
94 |
-
function attrUpdateFunc(spec) {
|
95 |
-
return function () {
|
96 |
-
if (cache[spec.base] !== true) {
|
97 |
-
spec.useEl.setAttributeNS(xlinkNS, 'xlink:href', '#' + spec.hash);
|
98 |
-
}
|
99 |
-
};
|
100 |
-
}
|
101 |
-
function onloadFunc(xhr) {
|
102 |
-
return function () {
|
103 |
-
var body = document.body;
|
104 |
-
var x = document.createElement('x');
|
105 |
-
var svg;
|
106 |
-
xhr.onload = null;
|
107 |
-
x.innerHTML = xhr.responseText;
|
108 |
-
svg = x.getElementsByTagName('svg')[0];
|
109 |
-
if (svg) {
|
110 |
-
svg.setAttribute('aria-hidden', 'true');
|
111 |
-
svg.style.position = 'absolute';
|
112 |
-
svg.style.width = 0;
|
113 |
-
svg.style.height = 0;
|
114 |
-
svg.style.overflow = 'hidden';
|
115 |
-
body.insertBefore(svg, body.firstChild);
|
116 |
-
}
|
117 |
-
observeIfDone();
|
118 |
-
};
|
119 |
-
}
|
120 |
-
function onErrorTimeout(xhr) {
|
121 |
-
return function () {
|
122 |
-
xhr.onerror = null;
|
123 |
-
xhr.ontimeout = null;
|
124 |
-
observeIfDone();
|
125 |
-
};
|
126 |
-
}
|
127 |
-
unobserveChanges(); // stop watching for changes to DOM
|
128 |
-
// find all use elements
|
129 |
-
uses = document.getElementsByTagName('use');
|
130 |
-
for (i = 0; i < uses.length; i += 1) {
|
131 |
-
try {
|
132 |
-
bcr = uses[i].getBoundingClientRect();
|
133 |
-
} catch (ignore) {
|
134 |
-
// failed to get bounding rectangle of the use element
|
135 |
-
bcr = false;
|
136 |
-
}
|
137 |
-
href = uses[i].getAttributeNS(xlinkNS, 'href');
|
138 |
-
if (href && href.split) {
|
139 |
-
url = href.split('#');
|
140 |
-
} else {
|
141 |
-
url = ["", ""];
|
142 |
-
}
|
143 |
-
base = url[0];
|
144 |
-
hash = url[1];
|
145 |
-
isHidden = bcr && bcr.left === 0 && bcr.right === 0 && bcr.top === 0 && bcr.bottom === 0;
|
146 |
-
if (bcr && bcr.width === 0 && bcr.height === 0 && !isHidden) {
|
147 |
-
// the use element is empty
|
148 |
-
// if there is a reference to an external SVG, try to fetch it
|
149 |
-
// use the optional fallback URL if there is no reference to an external SVG
|
150 |
-
if (fallback && !base.length && hash && !document.getElementById(hash)) {
|
151 |
-
base = fallback;
|
152 |
-
}
|
153 |
-
if (base.length) {
|
154 |
-
// schedule updating xlink:href
|
155 |
-
xhr = cache[base];
|
156 |
-
if (xhr !== true) {
|
157 |
-
// true signifies that prepending the SVG was not required
|
158 |
-
setTimeout(attrUpdateFunc({
|
159 |
-
useEl: uses[i],
|
160 |
-
base: base,
|
161 |
-
hash: hash
|
162 |
-
}), 0);
|
163 |
-
}
|
164 |
-
if (xhr === undefined) {
|
165 |
-
Request = createRequest(base);
|
166 |
-
if (Request !== undefined) {
|
167 |
-
xhr = new Request();
|
168 |
-
cache[base] = xhr;
|
169 |
-
xhr.onload = onloadFunc(xhr);
|
170 |
-
xhr.onerror = onErrorTimeout(xhr);
|
171 |
-
xhr.ontimeout = onErrorTimeout(xhr);
|
172 |
-
xhr.open('GET', base);
|
173 |
-
xhr.send();
|
174 |
-
inProgressCount += 1;
|
175 |
-
}
|
176 |
-
}
|
177 |
-
}
|
178 |
-
} else {
|
179 |
-
if (!isHidden) {
|
180 |
-
if (cache[base] === undefined) {
|
181 |
-
// remember this URL if the use element was not empty and no request was sent
|
182 |
-
cache[base] = true;
|
183 |
-
} else if (cache[base].onload) {
|
184 |
-
// if it turns out that prepending the SVG is not necessary,
|
185 |
-
// abort the in-progress xhr.
|
186 |
-
cache[base].abort();
|
187 |
-
delete cache[base].onload;
|
188 |
-
cache[base] = true;
|
189 |
-
}
|
190 |
-
} else if (base.length && cache[base]) {
|
191 |
-
attrUpdateFunc({
|
192 |
-
useEl: uses[i],
|
193 |
-
base: base,
|
194 |
-
hash: hash
|
195 |
-
})();
|
196 |
-
}
|
197 |
-
}
|
198 |
-
}
|
199 |
-
uses = '';
|
200 |
-
inProgressCount += 1;
|
201 |
-
observeIfDone();
|
202 |
-
};
|
203 |
-
// The load event fires when all resources have finished loading, which allows detecting whether SVG use elements are empty.
|
204 |
-
window.addEventListener('load', function winLoad() {
|
205 |
-
window.removeEventListener('load', winLoad, false); // to prevent memory leaks
|
206 |
-
tid = setTimeout(checkUseElems, 0);
|
207 |
-
}, false);
|
208 |
-
}
|
209 |
-
}());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|