|
1 | | -(function( $ ) { |
2 | | - $( document ).ready( function() { |
3 | | - |
4 | | - $( document ).on( 'click', '#api-key-submit', function( e ) { |
5 | | - e.preventDefault(); |
6 | | - |
7 | | - if ( $( this ).next( 'img' ).length === 0 ) { |
8 | | - $( this ).after( $( '<img />' ).attr( 'src', rt_transcoder_script.loader_image ).addClass( 'rtt-loader' ) ); |
9 | | - } |
10 | | - |
11 | | - var data = { |
12 | | - action: 'rt_enter_api_key', |
13 | | - apikey: $( '#new-api-key' ).val() |
14 | | - }; |
15 | | - |
16 | | - // Since 2.8 ajaxurl is always defined in the admin header and points to admin-ajax.php |
17 | | - $.getJSON( ajaxurl, data, function( response ) { |
18 | | - if ( response.error === undefined && response.apikey ) { |
19 | | - var tempUrl = window.location.href; |
20 | | - var hash = window.location.hash; |
21 | | - tempUrl = tempUrl.replace( hash, '' ); |
22 | | - |
23 | | - if ( tempUrl.toString().indexOf( '&apikey=' + response.apikey ) == -1 ) { |
24 | | - tempUrl += '&apikey=' + response.apikey; |
25 | | - } |
26 | | - if ( tempUrl.toString().indexOf( '&update=true' ) == -1 ) { |
27 | | - tempUrl += '&update=true'; |
| 1 | +/** |
| 2 | + * Transcoder admin page. |
| 3 | + * |
| 4 | + * @package transcoder |
| 5 | + */ |
| 6 | + |
| 7 | +/* global ajaxurl, rt_transcoder_script */ |
| 8 | + |
| 9 | +( function ( $ ) { |
| 10 | + $( document ).ready( |
| 11 | + function() { |
| 12 | + |
| 13 | + $( document ).on( |
| 14 | + 'click', |
| 15 | + '#api-key-submit', |
| 16 | + function( e ) { |
| 17 | + e.preventDefault(); |
| 18 | + |
| 19 | + if ( $( this ).next( 'img' ).length === 0 ) { |
| 20 | + $( this ).after( $( '<img/>' ).attr( 'src', rt_transcoder_script.loader_image ).addClass( 'rtt-loader' ) ); |
28 | 21 | } |
29 | 22 |
|
30 | | - document.location.href = tempUrl + hash; |
31 | | - } else { |
32 | | - $( '#api-key-error' ).remove(); |
33 | | - var error_div = $( '<div/>', { |
34 | | - 'id' : 'api-key-error', |
35 | | - 'class': 'error', |
36 | | - }); |
37 | | - $( 'h1:first' ).after( error_div.html( $( '<p />' ).text( response.error ) ) ); |
38 | | - } |
| 23 | + var data = { |
| 24 | + action: 'rt_enter_api_key', |
| 25 | + apikey: $( '#new-api-key' ).val() |
| 26 | + }; |
| 27 | + |
| 28 | + // Since 2.8 ajaxurl is always defined in the admin header and points to admin-ajax.php. |
| 29 | + $.getJSON( |
| 30 | + ajaxurl, |
| 31 | + data, |
| 32 | + function( response ) { |
| 33 | + |
| 34 | + var tempUrl = window.location.href; |
| 35 | + var hash = window.location.hash; |
| 36 | + |
| 37 | + if ( response.error === undefined && response.apikey ) { |
39 | 38 |
|
40 | | - $( '#api-key-submit' ).next( 'img' ).remove(); |
41 | | - } ); |
42 | | - } ); |
| 39 | + tempUrl = tempUrl.replace( hash, '' ); |
43 | 40 |
|
44 | | - $( document ).on( 'click', '#disable-transcoding', function( e ) { |
45 | | - e.preventDefault(); |
46 | | - if ( confirm( rt_transcoder_script.disable_encoding ) ) { |
| 41 | + if ( -1 === tempUrl.toString().indexOf( '&apikey=' + response.apikey ) ) { |
| 42 | + tempUrl += '&apikey=' + response.apikey; |
| 43 | + } |
47 | 44 |
|
48 | | - var data = { |
49 | | - action: 'rt_disable_transcoding' |
50 | | - }; |
| 45 | + if ( -1 === tempUrl.toString().indexOf( '&update=true' ) ) { |
| 46 | + tempUrl += '&update=true'; |
| 47 | + } |
51 | 48 |
|
52 | | - if ( $( this ).next( 'img' ).length === 0 ) { |
53 | | - $( this ).after( $( '<img />' ).attr( 'src', rt_transcoder_script.loader_image ).addClass( 'rtt-loader' ) ); |
| 49 | + document.location.href = tempUrl + hash; |
| 50 | + } else { |
| 51 | + $( '#api-key-error' ).remove(); |
| 52 | + |
| 53 | + var error_div = $( |
| 54 | + '<div/>', |
| 55 | + { |
| 56 | + id: 'api-key-error', |
| 57 | + class: 'error' |
| 58 | + } |
| 59 | + ); |
| 60 | + |
| 61 | + $( 'h1:first' ).after( error_div.html( $( '<p/>' ).text( response.error ) ) ); // phpcs:ignoe WordPressVIPMinimum.JS.HTMLExecutingFunctions.html |
| 62 | + } |
| 63 | + |
| 64 | + $( '#api-key-submit' ).next( 'img' ).remove(); |
| 65 | + } |
| 66 | + ); |
54 | 67 | } |
| 68 | + ); |
55 | 69 |
|
56 | | - // Since 2.8 ajaxurl is always defined in the admin header and points to admin-ajax.php |
57 | | - $.post( ajaxurl, data, function( response ) { |
58 | | - if ( response ) { |
| 70 | + $( document ).on( |
| 71 | + 'click', |
| 72 | + '#disable-transcoding', |
| 73 | + function( e ) { |
59 | 74 |
|
60 | | - if ( $( '#rtt-settings_updated' ).length > 0 ) { |
61 | | - $( '#rtt-settings_updated p' ).html( response ); |
62 | | - $( '#rtt-settings_updated' ).show(); |
63 | | - } else { |
| 75 | + e.preventDefault(); |
| 76 | + |
| 77 | + if ( confirm( rt_transcoder_script.disable_encoding ) ) { |
| 78 | + |
| 79 | + var data = { |
| 80 | + action: 'rt_disable_transcoding' |
| 81 | + }; |
| 82 | + |
| 83 | + if ( $( this ).next( 'img' ).length === 0 ) { |
| 84 | + $( this ).after( $( '<img />' ).attr( 'src', rt_transcoder_script.loader_image ).addClass( 'rtt-loader' ) ); |
64 | 85 | } |
65 | 86 |
|
66 | | - //$( '#rtmedia-transcoding-usage' ).hide(); |
67 | | - $( '#disable-transcoding' ).next( 'img' ).remove(); |
68 | | - $( '#disable-transcoding' ).hide(); |
69 | | - $( '#enable-transcoding' ).css( 'display', 'inline' ); |
70 | | - } else { |
| 87 | + // Since 2.8 ajaxurl is always defined in the admin header and points to admin-ajax.php. |
| 88 | + $.post( |
| 89 | + ajaxurl, |
| 90 | + data, |
| 91 | + function( response ) { |
| 92 | + if ( response ) { |
| 93 | + if ( $( '#rtt-settings_updated' ).length > 0 ) { |
| 94 | + $( '#rtt-settings_updated p' ).text( response ); |
| 95 | + $( '#rtt-settings_updated' ).show(); |
| 96 | + } |
| 97 | + |
| 98 | + // $( '#rtmedia-transcoding-usage' ).hide(); |
| 99 | + $( '#disable-transcoding' ).next( 'img' ).remove(); |
| 100 | + $( '#disable-transcoding' ).hide(); |
| 101 | + $( '#enable-transcoding' ).css( 'display', 'inline' ); |
| 102 | + } |
| 103 | + } |
| 104 | + ); |
71 | 105 | } |
72 | | - } ); |
73 | | - } |
74 | | - } ); |
| 106 | + } |
| 107 | + ); |
75 | 108 |
|
76 | | - $( document ).on( 'click', '#enable-transcoding', function( e ) { |
77 | | - e.preventDefault(); |
78 | | - if ( confirm( rt_transcoder_script.enable_encoding ) ) { |
| 109 | + $( document ).on( |
| 110 | + 'click', |
| 111 | + '#enable-transcoding', |
| 112 | + function( e ) { |
79 | 113 |
|
80 | | - var data = { |
81 | | - action: 'rt_enable_transcoding' |
82 | | - }; |
| 114 | + e.preventDefault(); |
83 | 115 |
|
84 | | - if ( $( this ).next( 'img' ).length === 0 ) { |
85 | | - $( this ).after( $( '<img />' ).attr( 'src', rt_transcoder_script.loader_image ).addClass( 'rtt-loader' ) ); |
86 | | - } |
| 116 | + if ( confirm( rt_transcoder_script.enable_encoding ) ) { |
87 | 117 |
|
88 | | - $.post( ajaxurl, data, function( response ) { |
89 | | - if ( response ) { |
90 | | - if ( $( '#rtt-settings_updated' ).length > 0 ) { |
91 | | - $( '#rtt-settings_updated p' ).html( response ); |
92 | | - $( '#rtt-settings_updated' ).show(); |
93 | | - } |
| 118 | + var data = { |
| 119 | + action: 'rt_enable_transcoding' |
| 120 | + }; |
94 | 121 |
|
95 | | - $( '#enable-transcoding' ).next( 'img' ).remove(); |
96 | | - $( '#enable-transcoding' ).hide(); |
97 | | - $( '#disable-transcoding' ).css( 'display', 'inline' ); |
98 | | - } else { |
99 | | - $( '#settings-error-transcoding-disabled' ).remove(); |
| 122 | + if ( $( this ).next( 'img' ).length === 0 ) { |
| 123 | + $( this ).after( $( '<img />' ).attr( 'src', rt_transcoder_script.loader_image ).addClass( 'rtt-loader' ) ); |
| 124 | + } |
100 | 125 |
|
| 126 | + $.post( |
| 127 | + ajaxurl, |
| 128 | + data, |
| 129 | + function( response ) { |
| 130 | + if ( response ) { |
| 131 | + if ( $( '#rtt-settings_updated' ).length > 0 ) { |
| 132 | + $( '#rtt-settings_updated p' ).text( response ); |
| 133 | + $( '#rtt-settings_updated' ).show(); |
| 134 | + } |
| 135 | + |
| 136 | + $( '#enable-transcoding' ).next( 'img' ).remove(); |
| 137 | + $( '#enable-transcoding' ).hide(); |
| 138 | + $( '#disable-transcoding' ).css( 'display', 'inline' ); |
| 139 | + } else { |
| 140 | + $( '#settings-error-transcoding-disabled' ).remove(); |
| 141 | + } |
| 142 | + } |
| 143 | + ); |
101 | 144 | } |
102 | | - } ); |
103 | | - } |
104 | | - } ); |
105 | | - } ); |
106 | | -})( jQuery ); |
| 145 | + } |
| 146 | + ); |
| 147 | + } |
| 148 | + ); |
| 149 | + |
| 150 | +} )( jQuery ); |
0 commit comments