1 (function($) { |
1 (function($) { |
2 var fs = {add:'ajaxAdd',del:'ajaxDel',dim:'ajaxDim',process:'process',recolor:'recolor'}, wpList; |
2 var fs = {add:'ajaxAdd',del:'ajaxDel',dim:'ajaxDim',process:'process',recolor:'recolor'}, wpList; |
3 |
3 |
4 wpList = { |
4 wpList = { |
5 settings: { |
5 settings: { |
6 url: wpListL10n.url, type: 'POST', |
6 url: ajaxurl, type: 'POST', |
7 response: 'ajax-response', |
7 response: 'ajax-response', |
8 |
8 |
9 what: '', |
9 what: '', |
10 alt: 'alternate', altOffset: 0, |
10 alt: 'alternate', altOffset: 0, |
11 addColor: null, delColor: null, dimAddColor: null, dimDelColor: null, |
11 addColor: null, delColor: null, dimAddColor: null, dimDelColor: null, |
105 s.addAfter( r, _s ); |
105 s.addAfter( r, _s ); |
106 if ( $.isFunction(o) ) { o(x,st); } |
106 if ( $.isFunction(o) ) { o(x,st); } |
107 }; |
107 }; |
108 } |
108 } |
109 list.wpList.recolor(); |
109 list.wpList.recolor(); |
|
110 $(list).trigger( 'wpListAddEnd', [ s, list.wpList ] ); |
110 wpList.clear.call(list,'#' + s.element); |
111 wpList.clear.call(list,'#' + s.element); |
111 }; |
112 }; |
112 |
113 |
113 $.ajax( s ); |
114 $.ajax( s ); |
114 return false; |
115 return false; |
115 }, |
116 }, |
116 |
117 |
117 ajaxDel: function( e, s ) { |
118 ajaxDel: function( e, s ) { |
118 e = $(e); s = s || {}; |
119 e = $(e); s = s || {}; |
119 var list = this, cls = wpList.parseClass(e,'delete'), element, anim; |
120 var list = this, cls = wpList.parseClass(e,'delete'), element; |
120 s = wpList.pre.call( list, e, s, 'delete' ); |
121 s = wpList.pre.call( list, e, s, 'delete' ); |
121 |
122 |
122 s.element = cls[2] || s.element || null; |
123 s.element = cls[2] || s.element || null; |
123 if ( cls[3] ) { s.delColor = '#' + cls[3]; } |
124 if ( cls[3] ) { s.delColor = '#' + cls[3]; } |
124 else { s.delColor = s.delColor || '#FF3333'; } |
125 else { s.delColor = s.delColor || '#faa'; } |
125 |
126 |
126 if ( !s || !s.element ) { return false; } |
127 if ( !s || !s.element ) { return false; } |
127 |
128 |
128 s.action = 'delete-' + s.what; |
129 s.action = 'delete-' + s.what; |
129 |
130 |
133 { action: s.action, id: s.element.split('-').pop(), _ajax_nonce: s.nonce }, |
134 { action: s.action, id: s.element.split('-').pop(), _ajax_nonce: s.nonce }, |
134 wpAjax.unserialize( cls[4] || '' ) |
135 wpAjax.unserialize( cls[4] || '' ) |
135 ); |
136 ); |
136 |
137 |
137 if ( $.isFunction(s.delBefore) ) { |
138 if ( $.isFunction(s.delBefore) ) { |
138 s = s.delBefore( s ); |
139 s = s.delBefore( s, list ); |
139 if ( !s ) { return true; } |
140 if ( !s ) { return true; } |
140 } |
141 } |
141 if ( !s.data._ajax_nonce ) { return true; } |
142 if ( !s.data._ajax_nonce ) { return true; } |
142 |
143 |
143 element = $('#' + s.element); |
144 element = $('#' + s.element); |
144 |
145 |
145 if ( 'none' != s.delColor ) { |
146 if ( 'none' != s.delColor ) { |
146 anim = 'slideUp'; |
147 element.css( 'backgroundColor', s.delColor ).fadeOut( 350, function(){ |
147 if ( element.css( 'display' ).match(/table/) ) |
148 list.wpList.recolor(); |
148 anim = 'fadeOut'; // Can't slideup table rows and other table elements. Known jQuery bug |
149 $(list).trigger( 'wpListDelEnd', [ s, list.wpList ] ); |
149 element |
150 }); |
150 .animate( { backgroundColor: s.delColor }, 'fast' )[anim]( 'fast' ) |
|
151 .queue( function() { list.wpList.recolor(); $(this).dequeue(); } ); |
|
152 } else { |
151 } else { |
153 list.wpList.recolor(); |
152 list.wpList.recolor(); |
|
153 $(list).trigger( 'wpListDelEnd', [ s, list.wpList ] ); |
154 } |
154 } |
155 |
155 |
156 s.success = function(r) { |
156 s.success = function(r) { |
157 var res = wpAjax.parseAjaxResponse(r, s.response, s.element), o; |
157 var res = wpAjax.parseAjaxResponse(r, s.response, s.element), o; |
158 if ( !res || res.errors ) { |
158 if ( !res || res.errors ) { |
159 element.stop().stop().css( 'backgroundColor', '#FF3333' ).show().queue( function() { list.wpList.recolor(); $(this).dequeue(); } ); |
159 element.stop().stop().css( 'backgroundColor', '#faa' ).show().queue( function() { list.wpList.recolor(); $(this).dequeue(); } ); |
160 return false; |
160 return false; |
161 } |
161 } |
162 if ( $.isFunction(s.delAfter) ) { |
162 if ( $.isFunction(s.delAfter) ) { |
163 o = this.complete; |
163 o = this.complete; |
164 this.complete = function(x,st) { |
164 this.complete = function(x,st) { |
211 dimColor = isClass ? s.dimAddColor : s.dimDelColor; |
211 dimColor = isClass ? s.dimAddColor : s.dimDelColor; |
212 if ( 'none' != dimColor ) { |
212 if ( 'none' != dimColor ) { |
213 element |
213 element |
214 .animate( { backgroundColor: dimColor }, 'fast' ) |
214 .animate( { backgroundColor: dimColor }, 'fast' ) |
215 .queue( function() { element.toggleClass(s.dimClass); $(this).dequeue(); } ) |
215 .queue( function() { element.toggleClass(s.dimClass); $(this).dequeue(); } ) |
216 .animate( { backgroundColor: color }, { complete: function() { $(this).css( 'backgroundColor', '' ); } } ); |
216 .animate( { backgroundColor: color }, { complete: function() { $(this).css( 'backgroundColor', '' ); $(list).trigger( 'wpListDimEnd', [ s, list.wpList ] ); } } ); |
|
217 } else { |
|
218 $(list).trigger( 'wpListDimEnd', [ s, list.wpList ] ); |
217 } |
219 } |
218 |
220 |
219 if ( !s.data._ajax_nonce ) { return true; } |
221 if ( !s.data._ajax_nonce ) { return true; } |
220 |
222 |
221 s.success = function(r) { |
223 s.success = function(r) { |