Changeset 1996
- Timestamp:
- 03/14/2009 03:19:11 AM (17 years ago)
- Location:
- trunk/bb-includes/js
- Files:
-
- 2 edited
-
wp-ajax-response.js (modified) (4 diffs)
-
wp-lists.js (modified) (21 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/bb-includes/js/wp-ajax-response.js
r1476 r1996 1 wpAjax = jQuery.extend( {1 var wpAjax = jQuery.extend( { 2 2 unserialize: function( s ) { 3 var r = {}; if ( !s ) { return r; } 4 var q = s.split('?'); if ( q[1] ) { s = q[1]; } 5 var pp = s.split('&'); 6 for ( var i in pp ) { 3 var r = {}, q, pp, i, p; 4 if ( !s ) { return r; } 5 q = s.split('?'); if ( q[1] ) { s = q[1]; } 6 pp = s.split('&'); 7 for ( i in pp ) { 7 8 if ( jQuery.isFunction(pp.hasOwnProperty) && !pp.hasOwnProperty(i) ) { continue; } 8 varp = pp[i].split('=');9 p = pp[i].split('='); 9 10 r[p[0]] = p[1]; 10 11 } … … 12 13 }, 13 14 parseAjaxResponse: function( x, r, e ) { // 1 = good, 0 = strange (bad data?), -1 = you lack permission 14 var parsed = {} ;15 var re = jQuery('#' + r).html(''); 15 var parsed = {}, re = jQuery('#' + r).html(''), err = ''; 16 16 17 if ( x && typeof x == 'object' && x.getElementsByTagName('wp_ajax') ) { 17 18 parsed.responses = []; 18 19 parsed.errors = false; 19 var err = '';20 20 jQuery('response', x).each( function() { 21 var th = jQuery(this); 22 var child = jQuery(this.firstChild); 23 var response = { action: th.attr('action'), what: child.get(0).nodeName, id: child.attr('id'), oldId: child.attr('old_id'), position: child.attr('position') }; 21 var th = jQuery(this), child = jQuery(this.firstChild), response; 22 response = { action: th.attr('action'), what: child.get(0).nodeName, id: child.attr('id'), oldId: child.attr('old_id'), position: child.attr('position') }; 24 23 response.data = jQuery( 'response_data', child ).text(); 25 24 response.supplemental = {}; … … 29 28 response.errors = []; 30 29 if ( !jQuery('wp_error', child).each( function() { 31 var code = jQuery(this).attr('code') ;32 varanError = { code: code, message: this.firstChild.nodeValue, data: false };33 varerrorData = jQuery('wp_error_data[code="' + code + '"]', x);30 var code = jQuery(this).attr('code'), anError, errorData, formField; 31 anError = { code: code, message: this.firstChild.nodeValue, data: false }; 32 errorData = jQuery('wp_error_data[code="' + code + '"]', x); 34 33 if ( errorData ) { anError.data = errorData.get(); } 35 varformField = jQuery( 'form-field', errorData ).text();34 formField = jQuery( 'form-field', errorData ).text(); 36 35 if ( formField ) { code = formField; } 37 36 if ( e ) { wpAjax.invalidateForm( jQuery('#' + e + ' :input[name="' + code + '"]' ).parents('.form-field:first') ); } … … 56 55 validateForm: function( selector ) { 57 56 selector = jQuery( selector ); 58 return !wpAjax.invalidateForm( selector.find('.form-required'). andSelf().filter('.form-required:has(:input[value=""]), .form-required:input[value=""]') ).size();57 return !wpAjax.invalidateForm( selector.find('.form-required').filter( function() { return jQuery('input:visible', this).val() == ''; } ) ).size(); 59 58 } 60 59 }, wpAjax || { noPerm: 'You do not have permission to do that.', broken: 'An unidentified error has occurred.' } ); 60 61 // Basic form validation 62 jQuery(document).ready( function($){ 63 $('form.validate').submit( function() { return wpAjax.validateForm( $(this) ); } ); 64 }); -
trunk/bb-includes/js/wp-lists.js
r1837 r1996 1 1 (function($) { 2 var currentFormEl = false; 3 var fs = {add:'ajaxAdd',del:'ajaxDel',dim:'ajaxDim',process:'process',recolor:'recolor'}; 4 5 var wpList = { 2 var currentFormEl = false, fs = {add:'ajaxAdd',del:'ajaxDel',dim:'ajaxDim',process:'process',recolor:'recolor'}, wpList; 3 4 wpList = { 6 5 settings: { 7 6 url: wpListL10n.url, type: 'POST', … … 34 33 35 34 pre: function(e,s,a) { 36 var bg ; varr;35 var bg, r; 37 36 s = $.extend( {}, this.wpList.settings, { 38 37 element: null, … … 53 52 54 53 ajaxAdd: function( e, s ) { 55 var list = this; e = $(e); s = s || {}; 56 var cls = wpList.parseClass(e,'add'); 54 e = $(e); 55 s = s || {}; 56 var list = this, cls = wpList.parseClass(e,'add'), es, valid, formData; 57 57 s = wpList.pre.call( list, e, s, 'add' ); 58 58 … … 71 71 s.nonce = wpList.nonce(e,s); 72 72 73 vares = $('#' + s.element + ' :input').not('[name=_ajax_nonce], [name=_wpnonce], [name=action]');74 va r valid = wpAjax.validateForm( '#' + s.element );73 es = $('#' + s.element + ' :input').not('[name=_ajax_nonce], [name=_wpnonce], [name=action]'); 74 valid = wpAjax.validateForm( '#' + s.element ); 75 75 if ( !valid ) { return false; } 76 76 77 77 s.data = $.param( $.extend( { _ajax_nonce: s.nonce, action: s.action }, wpAjax.unserialize( cls[4] || '' ) ) ); 78 varformData = $.isFunction(es.fieldSerialize) ? es.fieldSerialize() : es.serialize();78 formData = $.isFunction(es.fieldSerialize) ? es.fieldSerialize() : es.serialize(); 79 79 if ( formData ) { s.data += '&' + formData; } 80 80 … … 86 86 87 87 s.success = function(r) { 88 var res = wpAjax.parseAjaxResponse(r, s.response, s.element) ;88 var res = wpAjax.parseAjaxResponse(r, s.response, s.element), o; 89 89 if ( !res || res.errors ) { return false; } 90 90 … … 100 100 101 101 if ( $.isFunction(s.addAfter) ) { 102 varo = this.complete;102 o = this.complete; 103 103 this.complete = function(x,st) { 104 104 var _s = $.extend( { xml: x, status: st, parsed: res }, s ); … … 116 116 117 117 ajaxDel: function( e, s ) { 118 var list = this;e = $(e); s = s || {};119 var cls = wpList.parseClass(e,'delete');118 e = $(e); s = s || {}; 119 var list = this, cls = wpList.parseClass(e,'delete'), element, anim; 120 120 s = wpList.pre.call( list, e, s, 'delete' ); 121 121 … … 141 141 if ( !s.data._ajax_nonce ) { return true; } 142 142 143 varelement = $('#' + s.element);143 element = $('#' + s.element); 144 144 145 145 if ( 'none' != s.delColor ) { 146 varanim = 'slideUp';146 anim = 'slideUp'; 147 147 if ( element.css( 'display' ).match(/table/) ) 148 148 anim = 'fadeOut'; // Can't slideup table rows and other table elements. Known jQuery bug … … 155 155 156 156 s.success = function(r) { 157 var res = wpAjax.parseAjaxResponse(r, s.response, s.element) ;157 var res = wpAjax.parseAjaxResponse(r, s.response, s.element), o; 158 158 if ( !res || res.errors ) { 159 159 element.stop().stop().css( 'backgroundColor', '#FF3333' ).show().queue( function() { list.wpList.recolor(); $(this).dequeue(); } ); … … 161 161 } 162 162 if ( $.isFunction(s.delAfter) ) { 163 varo = this.complete;163 o = this.complete; 164 164 this.complete = function(x,st) { 165 165 element.queue( function() { … … 178 178 if ( $(e).parent().css('display') == 'none' ) // Prevent hidden links from being clicked by hotkeys 179 179 return false; 180 var list = this;e = $(e); s = s || {};181 var cls = wpList.parseClass(e,'dim');180 e = $(e); s = s || {}; 181 var list = this, cls = wpList.parseClass(e,'dim'), element, isClass, color, dimColor; 182 182 s = wpList.pre.call( list, e, s, 'dim' ); 183 183 … … 205 205 } 206 206 207 varelement = $('#' + s.element);208 varisClass = element.toggleClass(s.dimClass).is('.' + s.dimClass);209 varcolor = wpList.getColor( element );207 element = $('#' + s.element); 208 isClass = element.toggleClass(s.dimClass).is('.' + s.dimClass); 209 color = wpList.getColor( element ); 210 210 element.toggleClass( s.dimClass ) 211 vardimColor = isClass ? s.dimAddColor : s.dimDelColor;211 dimColor = isClass ? s.dimAddColor : s.dimDelColor; 212 212 if ( 'none' != dimColor ) { 213 213 element … … 220 220 221 221 s.success = function(r) { 222 var res = wpAjax.parseAjaxResponse(r, s.response, s.element) ;222 var res = wpAjax.parseAjaxResponse(r, s.response, s.element), o; 223 223 if ( !res || res.errors ) { 224 224 element.stop().stop().css( 'backgroundColor', '#FF3333' )[isClass?'removeClass':'addClass'](s.dimClass).show().queue( function() { list.wpList.recolor(); $(this).dequeue(); } ); … … 226 226 } 227 227 if ( $.isFunction(s.dimAfter) ) { 228 varo = this.complete;228 o = this.complete; 229 229 this.complete = function(x,st) { 230 230 element.queue( function() { … … 255 255 256 256 add: function( e, s ) { 257 var list = $(this);258 257 e = $(e); 259 258 260 var old = false; 261 var _s = { pos: 0, id: 0, oldId: null }; 259 var list = $(this), old = false, _s = { pos: 0, id: 0, oldId: null }, ba, ref, color; 262 260 if ( 'string' == typeof s ) { s = { what: s }; } 263 261 s = $.extend(_s, this.wpList.settings, s); … … 269 267 old.replaceWith(e); 270 268 } else if ( isNaN(s.pos) ) { 271 varba = 'after';269 ba = 'after'; 272 270 if ( '-' == s.pos.substr(0,1) ) { 273 271 s.pos = s.pos.substr(1); 274 272 ba = 'before'; 275 273 } 276 varref = list.find( '#' + s.pos );274 ref = list.find( '#' + s.pos ); 277 275 if ( 1 === ref.size() ) { ref[ba](e); } 278 276 else { list.append(e); } … … 289 287 290 288 if ( 'none' != s.addColor ) { 291 varcolor = wpList.getColor( e );289 color = wpList.getColor( e ); 292 290 e.css( 'backgroundColor', s.addColor ).animate( { backgroundColor: color }, { complete: function() { $(this).css( 'backgroundColor', '' ); } } ); 293 291 } … … 297 295 298 296 clear: function(e) { 299 var list = this ;297 var list = this, t, tag; 300 298 e = $(e); 301 299 if ( list.wpList && e.parents( '#' + list.id ).size() ) { return; } … … 303 301 if ( $(this).parents('.form-no-clear').size() ) 304 302 return; 305 var t = this.type.toLowerCase(); var tag = this.tagName.toLowerCase(); 303 t = this.type.toLowerCase(); 304 tag = this.tagName.toLowerCase(); 306 305 if ( 'text' == t || 'password' == t || 'textarea' == tag ) { this.value = ''; } 307 306 else if ( 'checkbox' == t || 'radio' == t ) { this.checked = false; } … … 315 314 .filter('form').submit( function() { return list.wpList.add(this); } ).end() 316 315 .not('form').click( function() { return list.wpList.add(this); } ).each( function() { 317 var addEl = this; 318 var c = wpList.parseClass(this,'add')[2] || addEl.id; 316 var addEl = this, c = wpList.parseClass(this,'add')[2] || addEl.id, forms = [], ins = []; 319 317 if ( !c ) { return; } 320 var forms = []; var ins = [];// this is all really inefficient318 // this is all really inefficient 321 319 $('#' + c + ' :input').focus( function() { currentFormEl = this; } ).blur( function() { currentFormEl = false; } ).each( function() { 322 320 ins.push(this); … … 337 335 338 336 recolor: function() { 339 var list = this ;337 var list = this, items, eo; 340 338 if ( !list.wpList.settings.alt ) { return; } 341 varitems = $('.list-item:visible', list);339 items = $('.list-item:visible', list); 342 340 if ( !items.size() ) { items = $(list).children(':visible'); } 343 vareo = [':even',':odd'];341 eo = [':even',':odd']; 344 342 if ( list.wpList.settings.altOffset % 2 ) { eo.reverse(); } 345 343 items.filter(eo[0]).addClass(list.wpList.settings.alt).end().filter(eo[1]).removeClass(list.wpList.settings.alt);
Note: See TracChangeset
for help on using the changeset viewer.