PluginProbe
Redirection / 2.3.13
Redirection v2.3.13
5.10.0 5.9.0 5.8.1 5.8.0 3.7.2 3.7.3 4.0 4.0.1 4.1 4.1.1 4.2 4.2.1 4.2.2 4.2.3 4.3 4.3.1 4.3.2 4.3.3 4.4 4.4.1 4.4.2 4.5 4.5.1 4.6.2 4.7.1 All 130 releases
redirection / redirection.js

redirection.js in Redirection 2.3.13, at redirection.js

201 lines 5.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 var Redirection;
2
3 (function($) {
4 Redirection_Items = function() {
5 function edit_items() {
6 $( 'table.items' ).on( 'click', '.advanced-toggle', function( ev ) {
7 ev.preventDefault();
8 $( this ).toggleClass( 'advanced-toggled' );
9 $( this ).closest( 'table' ).find( '.advanced' ).toggle();
10 } );
11
12 $( 'table.items' ).on( 'click', '.row-actions a.red-auto', function( ev ) {
13 ev.preventDefault();
14
15 $( this ).closest( 'tr' ).find( 'input[type=checkbox]' ).prop( 'checked', true );
16 $( 'select[name=action]' ).find( 'option[value=' + $( this ).data( 'action' ) + ']' ).prop( 'selected', true );
17 $( '#doaction' ).click();
18 } );
19
20 $( 'table.items' ).on( 'click', '.row-actions a.red-ajax', function( ev ) {
21 var action = $( this ).data( 'action' );
22 var container = $( this ).closest( 'td' );
23
24 ev.preventDefault();
25
26 container.data( 'cancel', container.html() );
27
28 show_loading( container.find( '.row-actions' ) );
29
30 $.post( ajaxurl, {
31 action: $( this ).data( 'action' ),
32 _ajax_nonce: $( this ).data( 'nonce' ),
33 id: $( this ).data( 'id' )
34 }, function( response ) {
35 if ( show_error( response ) )
36 return;
37
38 container.html( response.html );
39 connect_redirect_edit( container );
40 }, 'json' );
41 } );
42
43 $( document ).on( 'change', 'select.change-user-agent', function( ev ) {
44 $( this ).closest( 'td' ).find( 'input[type=text]' ).val( $( this ).val() );
45 } );
46 }
47
48 function show_loading( container ) {
49 container.replaceWith( '<div class="spinner" style="display: block"></div>' );
50 }
51
52 function show_error( response ) {
53 if (response == 0 || response == -1) {
54 alert( Redirectioni10n.error_msg );
55 return true;
56 }
57 else if (response.error) {
58 alert( response.error );
59 return true;
60 }
61
62 return false;
63 }
64
65 function connect_redirect_edit( container ) {
66 container.find( 'input[name=save]' ).on( 'click', function( ev ) {
67 var form = $( this ).closest( 'table.edit' );
68
69 ev.preventDefault();
70
71 form.addClass( 'loading' );
72
73 $.post( form.data( 'url' ), form.find( 'input, select' ).serialize(), function( response ) {
74 if ( show_error( response ) )
75 return;
76
77 container.html( response.html );
78
79 if ( response.code )
80 container.closest( 'tr' ).find( '.column-type' ).html( response.code );
81 }, 'json' );
82 } );
83
84 container.find( 'input[name=cancel]' ).on( 'click', function( ev ) {
85 ev.preventDefault();
86
87 container.html( container.data( 'cancel' ) );
88 container.data( 'cancel', null );
89 } );
90 }
91
92 edit_items();
93 };
94
95 Redirection_Modules = function() {
96 function modules() {
97 // Edit module
98 $( 'a.edit' ).unbind( 'click' ).click( function( ev ) {
99 var container = $( this ).closest( 'tr' );
100 ev.preventDefault();
101
102 $.get( $( this ).attr( 'href' ), function( response ) {
103 container.html( response );
104 } );
105 } );
106
107 // Reset links
108 $( 'a.reset' ).unbind( 'click' ).click( function() {
109 var item = $( this ).parents( 'tr' )
110 var href = this.href;
111
112 $( item ).find( '.operations div' ).hide();
113 $( item ).find( '.loader' ).show();
114 $( item ).load( this.href, function() {
115 modules();
116 });
117
118 return false;
119 });
120
121 // Delete links
122 $( 'a.rdelete' ).unbind( 'click' ).click( function() {
123 var item = $( this ).parents( 'tr' )
124
125 $( item ).find( '.operations a' ).hide();
126 $( item ).find( '.loader' ).show();
127 $.get( this.href, function() {
128 $( item ).fadeOut();
129 });
130
131 return false;
132 });
133 }
134
135 modules();
136 };
137
138 Redirection_Logs = function() {
139 function logs() {
140 $( '.add-log' ).unbind( 'click' ).click( function( item ) {
141 $( '#added' ).hide ();
142 $( '#add' ).show ();
143
144 // Copy details
145 $( '#old' ).val( $( this ).attr( 'href' ) );
146 return false;
147 } );
148 }
149
150 logs();
151 };
152
153 function get_redirect_error( response ) {
154 if ( parseInt( response, 10 ) === 0 || parseInt( response, 10 ) === -1 )
155 return Redirectioni10n.error_msg;
156 else if ( response.error )
157 return response.error;
158 return false;
159 }
160
161 Redirection_Add = function( selector, target, add_form, add_to_screen ) {
162 $( selector ).on( 'change', function() {
163 if ( $( this ).val() == 'url' || $( this ).val() == 'pass' )
164 $( target ).show();
165 else
166 $( target ).hide();
167 } );
168
169 $( add_form ).find( 'form' ).ajaxForm( {
170 beforeSubmit: function () {
171 $( add_form ).removeClass( 'loaded-error' ).addClass( 'loading' );
172 },
173 success: function( response ) {
174 var error = get_redirect_error( response );
175
176 $( add_form ).find( 'input[type=text]' ).val( '' );
177 $( add_form ).removeClass( 'loading' );
178
179 if ( error ) {
180 $( add_form ).addClass( 'loaded-error' );
181 $( add_form ).find( '.red-error' ).html( error );
182 return;
183 }
184
185 if ( add_to_screen === true ) {
186 $( add_form ).addClass( 'loaded' );
187
188 $( 'table tr.no-items' ).remove();
189 $( 'table.items' ).append( response.html );
190 $( 'table.items tr' ).each( function( pos, item ) {
191 $( item ).removeClass( 'alternate' );
192 if ( pos % 2 == 0 )
193 $( item ).addClass( 'alternate' );
194 } );
195 }
196 },
197 dataType: 'json'
198 });
199 };
200 } )( jQuery );
201