PluginProbe
Redirection / 2.3.8
Redirection v2.3.8
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 / js / redirection.js

redirection.js in Redirection 2.3.8, at js/redirection.js

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