PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.3-beta
Jetpack – WP Security, Backup, Speed, & Growth v16.3-beta
16.3-beta 16.3-a.5 16.3-a.7 16.3-a.3 16.3-a.1 16.2 16.2-beta 12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 13.7.2 All 507 releases
jetpack / modules / widgets / social-icons / social-icons-admin.js

social-icons-admin.js in Jetpack – WP Security, Backup, Speed, & Growth 16.3-beta, at modules/widgets/social-icons/social-icons-admin.js

124 lines 3.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 ( function ( $ ) {
2 var timeout = null;
3
4 // Make the list of items sortable.
5 function initWidget( widget ) {
6 widget.find( '.jetpack-social-icons-widget-list' ).sortable( {
7 items: '> .jetpack-social-icons-widget-item',
8 handle: '.handle',
9 cursor: 'move',
10 placeholder: 'jetpack-social-icons-widget-item ui-state-placeholder',
11 containment: widget,
12 forcePlaceholderSize: true,
13 update: function () {
14 livePreviewUpdate( $( this ).parents( '.form' ).find( '.widget-control-save' ) );
15 },
16 } );
17 }
18
19 // Live preview update.
20 function livePreviewUpdate( button ) {
21 if ( ! $( document.body ).hasClass( 'wp-customizer' ) || ! button.length ) {
22 return;
23 }
24
25 button.trigger( 'click' ).hide();
26 }
27
28 $( document ).ready( function () {
29 // Add an item.
30 $( document ).on(
31 'click',
32 '.jetpack-social-icons-widget.add-button button',
33 function ( event ) {
34 event.preventDefault();
35
36 var template, widgetContent, widgetList, widgetLastItem, urlId, urlName;
37
38 template = $( $.trim( $( '#tmpl-jetpack-widget-social-icons-template' ).html() ) );
39 widgetContent = $( this ).parents( '.widget-content' );
40 widgetList = widgetContent.find( '.jetpack-social-icons-widget-list' );
41 urlId = widgetList.data( 'url-icon-id' );
42 urlName = widgetList.data( 'url-icon-name' );
43
44 template
45 .find( '.jetpack-widget-social-icons-url input' )
46 .attr( 'id', urlId )
47 .attr( 'name', urlName + '[]' );
48
49 widgetList.append( template );
50
51 widgetLastItem = widgetContent.find( '.jetpack-social-icons-widget-item:last' );
52 widgetLastItem.find( 'input:first' ).trigger( 'focus' );
53 }
54 );
55
56 // Remove an item.
57 $( document ).on(
58 'click',
59 '.jetpack-widget-social-icons-remove-item-button',
60 function ( event ) {
61 event.preventDefault();
62 var widgetItem = $( this ).parents( '.jetpack-social-icons-widget-item' );
63 widgetItem.find( 'input' ).change();
64 widgetItem.remove();
65 }
66 );
67
68 // Event handler for widget open button.
69 $( document ).on(
70 'click',
71 'div.widget[id*="jetpack_widget_social_icons"] .widget-title, div.widget[id*="jetpack_widget_social_icons"] .widget-action',
72 function () {
73 if ( $( this ).parents( '#available-widgets' ).length ) {
74 return;
75 }
76
77 initWidget( $( this ).parents( '.widget[id*="jetpack_widget_social_icons"]' ) );
78 }
79 );
80
81 // Event handler for widget added.
82 $( document ).on( 'widget-added', function ( event, widget ) {
83 if ( widget.is( '[id*="jetpack_widget_social_icons"]' ) ) {
84 event.preventDefault();
85 initWidget( widget );
86 }
87 } );
88
89 // Event handler for widget updated.
90 $( document ).on( 'widget-updated', function ( event, widget ) {
91 if ( widget.is( '[id*="jetpack_widget_social_icons"]' ) ) {
92 event.preventDefault();
93 initWidget( widget );
94 }
95 } );
96
97 // Live preview update on input focus out.
98 $( document ).on( 'focusout', 'input[name*="jetpack_widget_social_icons"]', function () {
99 livePreviewUpdate( $( this ).parents( '.form' ).find( '.widget-control-save' ) );
100 } );
101
102 // Live preview update on input enter key.
103 $( document ).on( 'keydown', 'input[name*="jetpack_widget_social_icons"]', function ( event ) {
104 if ( event.keyCode === 13 ) {
105 livePreviewUpdate( $( this ).parents( '.form' ).find( '.widget-control-save' ) );
106 }
107 } );
108
109 // Live preview update on input key up 1s.
110 $( document ).on( 'keyup', 'input[name*="jetpack_widget_social_icons"]', function () {
111 clearTimeout( timeout );
112
113 timeout = setTimeout( function () {
114 livePreviewUpdate( $( this ).parents( '.form' ).find( '.widget-control-save' ) );
115 }, 1000 );
116 } );
117
118 // Live preview update on select change.
119 $( document ).on( 'change', 'select[name*="jetpack_widget_social_icons"]', function () {
120 livePreviewUpdate( $( this ).parents( '.form' ).find( '.widget-control-save' ) );
121 } );
122 } );
123 } )( jQuery );
124