blocks
5 years ago
build
5 years ago
fonts
8 years ago
genericons
6 years ago
lib
5 years ago
social-logos
5 years ago
accessible-focus.js
5 years ago
class.jetpack-provision.php
6 years ago
connect-button.js
5 years ago
crowdsignal-shortcode.js
5 years ago
crowdsignal-survey.js
5 years ago
facebook-embed.js
5 years ago
footer.php
7 years ago
gallery-settings.js
5 years ago
genericons.php
11 years ago
header.php
7 years ago
idc-notice.js
5 years ago
jetpack-admin.js
5 years ago
jetpack-connection-banner.js
5 years ago
jetpack-deactivate-dialog.js
5 years ago
jetpack-jitm.js
5 years ago
jetpack-modules.js
5 years ago
jetpack-modules.models.js
6 years ago
jetpack-modules.views.js
5 years ago
jetpack-server-sandbox.php
6 years ago
jetpack-wizard-banner.js
5 years ago
jquery.jetpack-resize.js
5 years ago
polldaddy-shortcode.js
5 years ago
postmessage.js
8 years ago
social-logos.php
6 years ago
twitter-timeline.js
5 years ago
jetpack-deactivate-dialog.js
98 lines
| 1 | /** |
| 2 | * Adds the Deactivation modal. |
| 3 | * |
| 4 | * Depends on _inc/lib/tracks/tracks-callables.js and //stats.wp.com/w.js |
| 5 | * |
| 6 | */ |
| 7 | ( function ( $ ) { |
| 8 | // Initialize Tracks and bump stats. |
| 9 | var tracksUser = deactivate_dialog.tracksUserData; |
| 10 | |
| 11 | analytics.initialize( tracksUser.userid, tracksUser.username ); |
| 12 | |
| 13 | var deactivateLinkElem = $( |
| 14 | 'tr[data-slug=jetpack] > td.plugin-title > div > span.deactivate > a' |
| 15 | ); |
| 16 | |
| 17 | var deactivateJetpackURL = deactivateLinkElem.attr( 'href' ); |
| 18 | |
| 19 | window.deactivateJetpack = function () { |
| 20 | window.location.href = deactivateJetpackURL; |
| 21 | }; |
| 22 | |
| 23 | var observer = new MutationObserver( function ( mutations ) { |
| 24 | mutations.forEach( function ( mutation ) { |
| 25 | if ( mutation.type === 'childList' ) { |
| 26 | mutation.addedNodes.forEach( function ( addedNode ) { |
| 27 | if ( 'TB_window' === addedNode.id ) { |
| 28 | // NodeList is static, we need to modify this in the DOM |
| 29 | |
| 30 | $( '#TB_window' ).addClass( 'jetpack-disconnect-modal' ); |
| 31 | deactivationModalCentralize(); |
| 32 | |
| 33 | $( '#TB_closeWindowButton, #TB_overlay' ).on( 'click', function ( e ) { |
| 34 | deactivationModalTrackCloseEvent(); |
| 35 | } ); |
| 36 | |
| 37 | document.onkeyup = function ( e ) { |
| 38 | if ( e === null ) { |
| 39 | // ie |
| 40 | keycode = event.keyCode; |
| 41 | } else { |
| 42 | // mozilla |
| 43 | keycode = e.which; |
| 44 | } |
| 45 | if ( keycode == 27 ) { |
| 46 | // close |
| 47 | deactivationModalTrackCloseEvent(); |
| 48 | } |
| 49 | }; |
| 50 | |
| 51 | observer.disconnect(); |
| 52 | } |
| 53 | } ); |
| 54 | } |
| 55 | } ); |
| 56 | } ); |
| 57 | |
| 58 | window.deactivationModalCentralize = function () { |
| 59 | var modal = $( '#TB_window.jetpack-disconnect-modal' ); |
| 60 | var top = $( window ).height() / 2 - $( modal ).height() / 2; |
| 61 | $( modal ).css( 'top', top + 'px' ); |
| 62 | }; |
| 63 | |
| 64 | window.deactivationModalTrackCloseEvent = function () { |
| 65 | analytics.tracks.recordEvent( 'jetpack_termination_dialog_close_click', tracksProps ); |
| 66 | document.onkeyup = ''; |
| 67 | }; |
| 68 | |
| 69 | var body = $( 'body' )[ 0 ]; |
| 70 | |
| 71 | var tracksProps = { |
| 72 | location: 'plugins', |
| 73 | purpose: 'deactivate', |
| 74 | }; |
| 75 | |
| 76 | deactivateLinkElem.attr( 'href', 'plugins.php#TB_inline?inlineId=jetpack_deactivation_dialog' ); |
| 77 | deactivateLinkElem.attr( 'title', deactivate_dialog.title ); |
| 78 | deactivateLinkElem.addClass( 'thickbox' ); |
| 79 | deactivateLinkElem.html( deactivate_dialog.deactivate_label ); |
| 80 | deactivateLinkElem.on( 'click', function ( e ) { |
| 81 | observer.observe( body, { childList: true } ); |
| 82 | analytics.tracks.recordEvent( 'jetpack_termination_dialog_open', tracksProps ); |
| 83 | } ); |
| 84 | |
| 85 | $( '#jetpack_deactivation_dialog_content__button-cancel' ).on( 'click', function ( e ) { |
| 86 | tb_remove(); |
| 87 | deactivationModalTrackCloseEvent(); |
| 88 | } ); |
| 89 | |
| 90 | $( '#jetpack_deactivation_dialog_content__button-deactivate' ).on( 'click', function ( e ) { |
| 91 | e.preventDefault(); |
| 92 | |
| 93 | $( this ).prop( 'disabled', true ); |
| 94 | analytics.tracks.recordEvent( 'jetpack_termination_dialog_termination_click', tracksProps ); |
| 95 | deactivateJetpack(); |
| 96 | } ); |
| 97 | } )( jQuery ); |
| 98 |