@@ -119,27 +119,51 @@ function styles_and_scripts() {
119119 }
120120
121121 if ( ! $ is_rtl ) {
122- wp_enqueue_style ( 'wpcom-notes-admin-bar ' , $ this ->wpcom_static_url ( '/wp-content/mu-plugins/notes/admin-bar-v2.css ' ), array (), JETPACK_NOTES__CACHE_BUSTER );
122+ wp_enqueue_style ( 'wpcom-notes-admin-bar ' , $ this ->wpcom_static_url ( '/wp-content/mu-plugins/notes/admin-bar-v2.css ' ), array ( ' admin-bar ' ), JETPACK_NOTES__CACHE_BUSTER );
123123 } else {
124- wp_enqueue_style ( 'wpcom-notes-admin-bar ' , $ this ->wpcom_static_url ( '/wp-content/mu-plugins/notes/rtl/admin-bar-v2-rtl.css ' ), array (), JETPACK_NOTES__CACHE_BUSTER );
124+ wp_enqueue_style ( 'wpcom-notes-admin-bar ' , $ this ->wpcom_static_url ( '/wp-content/mu-plugins/notes/rtl/admin-bar-v2-rtl.css ' ), array ( ' admin-bar ' ), JETPACK_NOTES__CACHE_BUSTER );
125125 }
126- wp_enqueue_style ( 'noticons ' , $ this ->wpcom_static_url ( '/i/noticons/noticons.css ' ), array (), JETPACK_NOTES__CACHE_BUSTER );
126+
127+ wp_enqueue_style ( 'noticons ' , $ this ->wpcom_static_url ( '/i/noticons/noticons.css ' ), array ( 'wpcom-notes-admin-bar ' ), JETPACK_NOTES__CACHE_BUSTER );
127128
128129 $ this ->print_js ();
129130
130131 // attempt to use core or plugin libraries if registered
132+ $ script_handles = array ();
131133 if ( !wp_script_is ( 'mustache ' , 'registered ' ) ) {
132134 wp_register_script ( 'mustache ' , $ this ->wpcom_static_url ( '/wp-content/js/mustache.js ' ), null , JETPACK_NOTES__CACHE_BUSTER );
133135 }
136+ $ script_handles [] = 'mustache ' ;
134137 if ( !wp_script_is ( 'underscore ' , 'registered ' ) ) {
135138 wp_register_script ( 'underscore ' , $ this ->wpcom_static_url ( '/wp-includes/js/underscore.min.js ' ), null , JETPACK_NOTES__CACHE_BUSTER );
136139 }
140+ $ script_handles [] = 'underscore ' ;
137141 if ( !wp_script_is ( 'backbone ' , 'registered ' ) ) {
138142 wp_register_script ( 'backbone ' , $ this ->wpcom_static_url ( '/wp-includes/js/backbone.min.js ' ), array ( 'underscore ' ), JETPACK_NOTES__CACHE_BUSTER );
139143 }
144+ $ script_handles [] = 'backbone ' ;
140145
141146 wp_register_script ( 'wpcom-notes-common ' , $ this ->wpcom_static_url ( '/wp-content/mu-plugins/notes/notes-common-v2.js ' ), array ( 'jquery ' , 'underscore ' , 'backbone ' , 'mustache ' ), JETPACK_NOTES__CACHE_BUSTER );
147+ $ script_handles [] = 'wpcom-notes-common ' ;
148+ $ script_handles [] = 'jquery ' ;
149+ $ script_handles [] = 'jquery-migrate ' ;
150+ $ script_handles [] = 'jquery-core ' ;
142151 wp_enqueue_script ( 'wpcom-notes-admin-bar ' , $ this ->wpcom_static_url ( '/wp-content/mu-plugins/notes/admin-bar-v2.js ' ), array ( 'wpcom-notes-common ' ), JETPACK_NOTES__CACHE_BUSTER );
152+ $ script_handles [] = 'wpcom-notes-admin-bar ' ;
153+
154+ if ( class_exists ( 'Jetpack_AMP_Support ' ) && Jetpack_AMP_Support::is_amp_request () ) {
155+ add_filter (
156+ 'script_loader_tag ' ,
157+ function ( $ tag , $ handle ) use ( $ script_handles ) {
158+ if ( in_array ( $ handle , $ script_handles , true ) ) {
159+ $ tag = preg_replace ( '/(?<=<script)(?=\s|>)/i ' , ' data-ampdevmode ' , $ tag );
160+ }
161+ return $ tag ;
162+ },
163+ 10 ,
164+ 2
165+ );
166+ }
143167 }
144168
145169 function admin_bar_menu () {
@@ -180,7 +204,7 @@ function admin_bar_menu() {
180204 function print_js () {
181205 $ link_accounts_url = is_user_logged_in () && !Jetpack::is_user_connected () ? Jetpack::admin_url () : false ;
182206?>
183- <script type="text/javascript">
207+ <script data-ampdevmode type="text/javascript">
184208/* <![CDATA[ */
185209 var wpNotesIsJetpackClient = true;
186210 var wpNotesIsJetpackClientV2 = true;
0 commit comments