-
+ B6D2C77E8AC7C340E71A84D1F859D81ED20FBA8770E195C959D8F9BB7791DB5B7D711C853607AFD41D06F0E93AD787BAC9C473CB028ACD2347A2B9BEE074DB9E
mp-wp/wp-includes/js/wp-lists.js
(0 . 0)(1 . 374)
133036 (function($) {
133037 var currentFormEl = false;
133038 var fs = {add:'ajaxAdd',del:'ajaxDel',dim:'ajaxDim',process:'process',recolor:'recolor'};
133039
133040 var wpList = {
133041 settings: {
133042 url: wpListL10n.url, type: 'POST',
133043 response: 'ajax-response',
133044
133045 what: '',
133046 alt: 'alternate', altOffset: 0,
133047 addColor: null, delColor: null, dimAddColor: null, dimDelColor: null,
133048
133049 confirm: null,
133050 addBefore: null, addAfter: null,
133051 delBefore: null, delAfter: null,
133052 dimBefore: null, dimAfter: null
133053 },
133054
133055 nonce: function(e,s) {
133056 var url = wpAjax.unserialize(e.attr('href'));
133057 return s.nonce || url._ajax_nonce || $('#' + s.element + ' input[name=_ajax_nonce]').val() || url._wpnonce || $('#' + s.element + ' input[name=_wpnonce]').val() || 0;
133058 },
133059
133060 parseClass: function(e,t) {
133061 var c = [], cl;
133062 try {
133063 cl = $(e).attr('class') || '';
133064 cl = cl.match(new RegExp(t+':[\\S]+'));
133065 if ( cl ) { c = cl[0].split(':'); }
133066 } catch(r) {}
133067 return c;
133068 },
133069
133070 pre: function(e,s,a) {
133071 var bg; var r;
133072 s = $.extend( {}, this.wpList.settings, {
133073 element: null,
133074 nonce: 0,
133075 target: e.get(0)
133076 }, s || {} );
133077 if ( $.isFunction( s.confirm ) ) {
133078 if ( 'add' != a ) {
133079 bg = $('#' + s.element).css('backgroundColor');
133080 $('#' + s.element).css('backgroundColor', '#FF9966');
133081 }
133082 r = s.confirm.call(this,e,s,a,bg);
133083 if ( 'add' != a ) { $('#' + s.element).css('backgroundColor', bg ); }
133084 if ( !r ) { return false; }
133085 }
133086 return s;
133087 },
133088
133089 ajaxAdd: function( e, s ) {
133090 var list = this; e = $(e); s = s || {};
133091 var cls = wpList.parseClass(e,'add');
133092 s = wpList.pre.call( list, e, s, 'add' );
133093
133094 s.element = cls[2] || e.attr( 'id' ) || s.element || null;
133095 if ( cls[3] ) { s.addColor = '#' + cls[3]; }
133096 else { s.addColor = s.addColor || '#FFFF33'; }
133097
133098 if ( !s ) { return false; }
133099
133100 if ( !e.is("[class^=add:" + list.id + ":]") ) { return !wpList.add.call( list, e, s ); }
133101
133102 if ( !s.element ) { return true; }
133103
133104 s.action = 'add-' + s.what;
133105
133106 s.nonce = wpList.nonce(e,s);
133107
133108 var es = $('#' + s.element + ' :input').not('[name=_ajax_nonce], [name=_wpnonce], [name=action]');
133109 var valid = wpAjax.validateForm( '#' + s.element );
133110 if ( !valid ) { return false; }
133111
133112 s.data = $.param( $.extend( { _ajax_nonce: s.nonce, action: s.action }, wpAjax.unserialize( cls[4] || '' ) ) );
133113 var formData = $.isFunction(es.fieldSerialize) ? es.fieldSerialize() : es.serialize();
133114 if ( formData ) { s.data += '&' + formData; }
133115
133116 if ( $.isFunction(s.addBefore) ) {
133117 s = s.addBefore( s );
133118 if ( !s ) { return true; }
133119 }
133120 if ( !s.data.match(/_ajax_nonce=[a-f0-9]+/) ) { return true; }
133121
133122 s.success = function(r) {
133123 var res = wpAjax.parseAjaxResponse(r, s.response, s.element);
133124 if ( !res || res.errors ) { return false; }
133125
133126 if ( true === res ) { return true; }
133127
133128 jQuery.each( res.responses, function() {
133129 wpList.add.call( list, this.data, $.extend( {}, s, { // this.firstChild.nodevalue
133130 pos: this.position || 0,
133131 id: this.id || 0,
133132 oldId: this.oldId || null
133133 } ) );
133134 } );
133135
133136 if ( $.isFunction(s.addAfter) ) {
133137 var o = this.complete;
133138 this.complete = function(x,st) {
133139 var _s = $.extend( { xml: x, status: st, parsed: res }, s );
133140 s.addAfter( r, _s );
133141 if ( $.isFunction(o) ) { o(x,st); }
133142 };
133143 }
133144 list.wpList.recolor();
133145 wpList.clear.call(list,'#' + s.element);
133146 };
133147
133148 $.ajax( s );
133149 return false;
133150 },
133151
133152 ajaxDel: function( e, s ) {
133153 var list = this; e = $(e); s = s || {};
133154 var cls = wpList.parseClass(e,'delete');
133155 s = wpList.pre.call( list, e, s, 'delete' );
133156
133157 s.element = cls[2] || s.element || null;
133158 if ( cls[3] ) { s.delColor = '#' + cls[3]; }
133159 else { s.delColor = s.delColor || '#FF3333'; }
133160
133161 if ( !s || !s.element ) { return false; }
133162
133163 s.action = 'delete-' + s.what;
133164
133165 s.nonce = wpList.nonce(e,s);
133166
133167 s.data = $.extend(
133168 { action: s.action, id: s.element.split('-').pop(), _ajax_nonce: s.nonce },
133169 wpAjax.unserialize( cls[4] || '' )
133170 );
133171
133172 if ( $.isFunction(s.delBefore) ) {
133173 s = s.delBefore( s );
133174 if ( !s ) { return true; }
133175 }
133176 if ( !s.data._ajax_nonce ) { return true; }
133177
133178 var element = $('#' + s.element);
133179
133180 if ( 'none' != s.delColor ) {
133181 var anim = 'slideUp';
133182 if ( element.css( 'display' ).match(/table/) )
133183 anim = 'fadeOut'; // Can't slideup table rows and other table elements. Known jQuery bug
133184 element
133185 .animate( { backgroundColor: s.delColor }, 'fast' )[anim]( 'fast' )
133186 .queue( function() { list.wpList.recolor(); $(this).dequeue(); } );
133187 } else {
133188 list.wpList.recolor();
133189 }
133190
133191 s.success = function(r) {
133192 var res = wpAjax.parseAjaxResponse(r, s.response, s.element);
133193 if ( !res || res.errors ) {
133194 element.stop().stop().css( 'backgroundColor', '#FF3333' ).show().queue( function() { list.wpList.recolor(); $(this).dequeue(); } );
133195 return false;
133196 }
133197 if ( $.isFunction(s.delAfter) ) {
133198 var o = this.complete;
133199 this.complete = function(x,st) {
133200 element.queue( function() {
133201 var _s = $.extend( { xml: x, status: st, parsed: res }, s );
133202 s.delAfter( r, _s );
133203 if ( $.isFunction(o) ) { o(x,st); }
133204 } ).dequeue();
133205 };
133206 }
133207 };
133208 $.ajax( s );
133209 return false;
133210 },
133211
133212 ajaxDim: function( e, s ) {
133213 if ( $(e).parent().css('display') == 'none' ) // Prevent hidden links from being clicked by hotkeys
133214 return false;
133215 var list = this; e = $(e); s = s || {};
133216 var cls = wpList.parseClass(e,'dim');
133217 s = wpList.pre.call( list, e, s, 'dim' );
133218
133219 s.element = cls[2] || s.element || null;
133220 s.dimClass = cls[3] || s.dimClass || null;
133221 if ( cls[4] ) { s.dimAddColor = '#' + cls[4]; }
133222 else { s.dimAddColor = s.dimAddColor || '#FFFF33'; }
133223 if ( cls[5] ) { s.dimDelColor = '#' + cls[5]; }
133224 else { s.dimDelColor = s.dimDelColor || '#FF3333'; }
133225
133226 if ( !s || !s.element || !s.dimClass ) { return true; }
133227
133228 s.action = 'dim-' + s.what;
133229
133230 s.nonce = wpList.nonce(e,s);
133231
133232 s.data = $.extend(
133233 { action: s.action, id: s.element.split('-').pop(), dimClass: s.dimClass, _ajax_nonce : s.nonce },
133234 wpAjax.unserialize( cls[6] || '' )
133235 );
133236
133237 if ( $.isFunction(s.dimBefore) ) {
133238 s = s.dimBefore( s );
133239 if ( !s ) { return true; }
133240 }
133241
133242 var element = $('#' + s.element);
133243 var isClass = element.toggleClass(s.dimClass).is('.' + s.dimClass);
133244 var color = wpList.getColor( element );
133245 element.toggleClass( s.dimClass )
133246 var dimColor = isClass ? s.dimAddColor : s.dimDelColor;
133247 if ( 'none' != dimColor ) {
133248 element
133249 .animate( { backgroundColor: dimColor }, 'fast' )
133250 .queue( function() { element.toggleClass(s.dimClass); $(this).dequeue(); } )
133251 .animate( { backgroundColor: color }, { complete: function() { $(this).css( 'backgroundColor', '' ); } } );
133252 }
133253
133254 if ( !s.data._ajax_nonce ) { return true; }
133255
133256 s.success = function(r) {
133257 var res = wpAjax.parseAjaxResponse(r, s.response, s.element);
133258 if ( !res || res.errors ) {
133259 element.stop().stop().css( 'backgroundColor', '#FF3333' )[isClass?'removeClass':'addClass'](s.dimClass).show().queue( function() { list.wpList.recolor(); $(this).dequeue(); } );
133260 return false;
133261 }
133262 if ( $.isFunction(s.dimAfter) ) {
133263 var o = this.complete;
133264 this.complete = function(x,st) {
133265 element.queue( function() {
133266 var _s = $.extend( { xml: x, status: st, parsed: res }, s );
133267 s.dimAfter( r, _s );
133268 if ( $.isFunction(o) ) { o(x,st); }
133269 } ).dequeue();
133270 };
133271 }
133272 };
133273
133274 $.ajax( s );
133275 return false;
133276 },
133277
133278 // From jquery.color.js: jQuery Color Animation by John Resig
133279 getColor: function( el ) {
133280 if ( el.constructor == Object )
133281 el = el.get(0);
133282 var elem = el, color, rgbaTrans = new RegExp( "rgba\\(\\s*0,\\s*0,\\s*0,\\s*0\\s*\\)", "i" );
133283 do {
133284 color = jQuery.curCSS(elem, 'backgroundColor');
133285 if ( color != '' && color != 'transparent' && !color.match(rgbaTrans) || jQuery.nodeName(elem, "body") )
133286 break;
133287 } while ( elem = elem.parentNode );
133288 return color || '#ffffff';
133289 },
133290
133291 add: function( e, s ) {
133292 var list = $(this);
133293 e = $(e);
133294
133295 var old = false;
133296 var _s = { pos: 0, id: 0, oldId: null };
133297 if ( 'string' == typeof s ) { s = { what: s }; }
133298 s = $.extend(_s, this.wpList.settings, s);
133299 if ( !e.size() || !s.what ) { return false; }
133300 if ( s.oldId ) { old = $('#' + s.what + '-' + s.oldId); }
133301 if ( s.id && ( s.id != s.oldId || !old || !old.size() ) ) { $('#' + s.what + '-' + s.id).remove(); }
133302
133303 if ( old && old.size() ) {
133304 old.replaceWith(e);
133305 } else if ( isNaN(s.pos) ) {
133306 var ba = 'after';
133307 if ( '-' == s.pos.substr(0,1) ) {
133308 s.pos = s.pos.substr(1);
133309 ba = 'before';
133310 }
133311 var ref = list.find( '#' + s.pos );
133312 if ( 1 === ref.size() ) { ref[ba](e); }
133313 else { list.append(e); }
133314 } else if ( s.pos < 0 ) {
133315 list.prepend(e);
133316 } else {
133317 list.append(e);
133318 }
133319
133320 if ( s.alt ) {
133321 if ( ( list.children(':visible').index( e[0] ) + s.altOffset ) % 2 ) { e.removeClass( s.alt ); }
133322 else { e.addClass( s.alt ); }
133323 }
133324
133325 if ( 'none' != s.addColor ) {
133326 var color = wpList.getColor( e );
133327 e.css( 'backgroundColor', s.addColor ).animate( { backgroundColor: color }, { complete: function() { $(this).css( 'backgroundColor', '' ); } } );
133328 }
133329 list.each( function() { this.wpList.process( e ); } );
133330 return e;
133331 },
133332
133333 clear: function(e) {
133334 var list = this;
133335 e = $(e);
133336 if ( list.wpList && e.parents( '#' + list.id ).size() ) { return; }
133337 e.find(':input').each( function() {
133338 if ( $(this).parents('.form-no-clear').size() )
133339 return;
133340 var t = this.type.toLowerCase(); var tag = this.tagName.toLowerCase();
133341 if ( 'text' == t || 'password' == t || 'textarea' == tag ) { this.value = ''; }
133342 else if ( 'checkbox' == t || 'radio' == t ) { this.checked = false; }
133343 else if ( 'select' == tag ) { this.selectedIndex = null; }
133344 });
133345 },
133346
133347 process: function(el) {
133348 var list = this;
133349 $("[class^=add:" + list.id + ":]", el || null)
133350 .filter('form').submit( function() { return list.wpList.add(this); } ).end()
133351 .not('form').click( function() { return list.wpList.add(this); } ).each( function() {
133352 var addEl = this;
133353 var c = wpList.parseClass(this,'add')[2] || addEl.id;
133354 if ( !c ) { return; }
133355 var forms = []; var ins = []; // this is all really inefficient
133356 $('#' + c + ' :input').focus( function() { currentFormEl = this; } ).blur( function() { currentFormEl = false; } ).each( function() {
133357 ins.push(this);
133358 var f = $(this).parents('form:first').get(0);
133359 if ( $.inArray(f,forms) < 0 ) { forms.push(f); }
133360 } );
133361 $(forms).submit( function() {
133362 if ( 0 <= $.inArray(currentFormEl,ins) ) {
133363 $(addEl).trigger( 'click' );
133364 $(currentFormEl).focus();
133365 return false;
133366 }
133367 } );
133368 } );
133369 $("[class^=delete:" + list.id + ":]", el || null).click( function() { return list.wpList.del(this); } );
133370 $("[class^=dim:" + list.id + ":]", el || null).click( function() { return list.wpList.dim(this); } );
133371 },
133372
133373 recolor: function() {
133374 var list = this;
133375 if ( !list.wpList.settings.alt ) { return; }
133376 var items = $('.list-item:visible', list);
133377 if ( !items.size() ) { items = $(list).children(':visible'); }
133378 var eo = [':even',':odd'];
133379 if ( list.wpList.settings.altOffset % 2 ) { eo.reverse(); }
133380 items.filter(eo[0]).addClass(list.wpList.settings.alt).end().filter(eo[1]).removeClass(list.wpList.settings.alt);
133381 },
133382
133383 init: function() {
133384 var lists = this;
133385 lists.wpList.process = function(a) {
133386 lists.each( function() {
133387 this.wpList.process(a);
133388 } );
133389 };
133390 lists.wpList.recolor = function() {
133391 lists.each( function() {
133392 this.wpList.recolor();
133393 } );
133394 };
133395 }
133396 };
133397
133398 $.fn.wpList = function( settings ) {
133399 this.each( function() {
133400 var _this = this;
133401 this.wpList = { settings: $.extend( {}, wpList.settings, { what: wpList.parseClass(this,'list')[1] || '' }, settings ) };
133402 $.each( fs, function(i,f) { _this.wpList[i] = function( e, s ) { return wpList[f].call( _this, e, s ); }; } );
133403 } );
133404 wpList.init.call(this);
133405 this.wpList.process();
133406 return this;
133407 };
133408
133409 })(jQuery);