Skip to:
Content

bbPress.org

Changeset 1996


Ignore:
Timestamp:
03/14/2009 03:19:11 AM (17 years ago)
Author:
sambauers
Message:

Updated Javascript from WordPress

Location:
trunk/bb-includes/js
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/bb-includes/js/wp-ajax-response.js

    r1476 r1996  
    1 wpAjax = jQuery.extend( {
     1var wpAjax = jQuery.extend( {
    22        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 ) {
    78                        if ( jQuery.isFunction(pp.hasOwnProperty) && !pp.hasOwnProperty(i) ) { continue; }
    8                         var p = pp[i].split('=');
     9                        p = pp[i].split('=');
    910                        r[p[0]] = p[1];
    1011                }
     
    1213        },
    1314        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
    1617                if ( x && typeof x == 'object' && x.getElementsByTagName('wp_ajax') ) {
    1718                        parsed.responses = [];
    1819                        parsed.errors = false;
    19                         var err = '';
    2020                        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') };
    2423                                response.data = jQuery( 'response_data', child ).text();
    2524                                response.supplemental = {};
     
    2928                                response.errors = [];
    3029                                if ( !jQuery('wp_error', child).each( function() {
    31                                         var code = jQuery(this).attr('code');
    32                                         var anError = { code: code, message: this.firstChild.nodeValue, data: false };
    33                                         var errorData = 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);
    3433                                        if ( errorData ) { anError.data = errorData.get(); }
    35                                         var formField = jQuery( 'form-field', errorData ).text();
     34                                        formField = jQuery( 'form-field', errorData ).text();
    3635                                        if ( formField ) { code = formField; }
    3736                                        if ( e ) { wpAjax.invalidateForm( jQuery('#' + e + ' :input[name="' + code + '"]' ).parents('.form-field:first') ); }
     
    5655        validateForm: function( selector ) {
    5756                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();
    5958        }
    6059}, wpAjax || { noPerm: 'You do not have permission to do that.', broken: 'An unidentified error has occurred.' } );
     60
     61// Basic form validation
     62jQuery(document).ready( function($){
     63        $('form.validate').submit( function() { return wpAjax.validateForm( $(this) ); } );
     64});
  • trunk/bb-includes/js/wp-lists.js

    r1837 r1996  
    11(function($) {
    2 var currentFormEl = false;
    3 var fs = {add:'ajaxAdd',del:'ajaxDel',dim:'ajaxDim',process:'process',recolor:'recolor'};
    4 
    5 var wpList = {
     2var currentFormEl = false, fs = {add:'ajaxAdd',del:'ajaxDel',dim:'ajaxDim',process:'process',recolor:'recolor'}, wpList;
     3
     4wpList = {
    65        settings: {
    76                url: wpListL10n.url, type: 'POST',
     
    3433
    3534        pre: function(e,s,a) {
    36                 var bg; var r;
     35                var bg, r;
    3736                s = $.extend( {}, this.wpList.settings, {
    3837                        element: null,
     
    5352
    5453        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;
    5757                s = wpList.pre.call( list, e, s, 'add' );
    5858
     
    7171                s.nonce = wpList.nonce(e,s);
    7272
    73                 var es = $('#' + s.element + ' :input').not('[name=_ajax_nonce], [name=_wpnonce], [name=action]');
    74                 var valid = wpAjax.validateForm( '#' + s.element );
     73                es = $('#' + s.element + ' :input').not('[name=_ajax_nonce], [name=_wpnonce], [name=action]');
     74                valid = wpAjax.validateForm( '#' + s.element );
    7575                if ( !valid ) { return false; }
    7676
    7777                s.data = $.param( $.extend( { _ajax_nonce: s.nonce, action: s.action }, wpAjax.unserialize( cls[4] || '' ) ) );
    78                 var formData = $.isFunction(es.fieldSerialize) ? es.fieldSerialize() : es.serialize();
     78                formData = $.isFunction(es.fieldSerialize) ? es.fieldSerialize() : es.serialize();
    7979                if ( formData ) { s.data += '&' + formData; }
    8080
     
    8686
    8787                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;
    8989                        if ( !res || res.errors ) { return false; }
    9090
     
    100100
    101101                        if ( $.isFunction(s.addAfter) ) {
    102                                 var o = this.complete;
     102                                o = this.complete;
    103103                                this.complete = function(x,st) {
    104104                                        var _s = $.extend( { xml: x, status: st, parsed: res }, s );
     
    116116
    117117        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;
    120120                s = wpList.pre.call( list, e, s, 'delete' );
    121121
     
    141141                if ( !s.data._ajax_nonce ) { return true; }
    142142
    143                 var element = $('#' + s.element);
     143                element = $('#' + s.element);
    144144
    145145                if ( 'none' != s.delColor ) {
    146                         var anim = 'slideUp';
     146                        anim = 'slideUp';
    147147                        if ( element.css( 'display' ).match(/table/) )
    148148                                anim = 'fadeOut'; // Can't slideup table rows and other table elements.  Known jQuery bug
     
    155155
    156156                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;
    158158                        if ( !res || res.errors ) {
    159159                                element.stop().stop().css( 'backgroundColor', '#FF3333' ).show().queue( function() { list.wpList.recolor(); $(this).dequeue(); } );
     
    161161                        }
    162162                        if ( $.isFunction(s.delAfter) ) {
    163                                 var o = this.complete;
     163                                o = this.complete;
    164164                                this.complete = function(x,st) {
    165165                                        element.queue( function() {
     
    178178                if ( $(e).parent().css('display') == 'none' ) // Prevent hidden links from being clicked by hotkeys
    179179                        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;
    182182                s = wpList.pre.call( list, e, s, 'dim' );
    183183
     
    205205                }
    206206
    207                 var element = $('#' + s.element);
    208                 var isClass = element.toggleClass(s.dimClass).is('.' + s.dimClass);
    209                 var color = wpList.getColor( element );
     207                element = $('#' + s.element);
     208                isClass = element.toggleClass(s.dimClass).is('.' + s.dimClass);
     209                color = wpList.getColor( element );
    210210                element.toggleClass( s.dimClass )
    211                 var dimColor = isClass ? s.dimAddColor : s.dimDelColor;
     211                dimColor = isClass ? s.dimAddColor : s.dimDelColor;
    212212                if ( 'none' != dimColor ) {
    213213                        element
     
    220220
    221221                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;
    223223                        if ( !res || res.errors ) {
    224224                                element.stop().stop().css( 'backgroundColor', '#FF3333' )[isClass?'removeClass':'addClass'](s.dimClass).show().queue( function() { list.wpList.recolor(); $(this).dequeue(); } );
     
    226226                        }
    227227                        if ( $.isFunction(s.dimAfter) ) {
    228                                 var o = this.complete;
     228                                o = this.complete;
    229229                                this.complete = function(x,st) {
    230230                                        element.queue( function() {
     
    255255
    256256        add: function( e, s ) {
    257                 var list = $(this);
    258257                e = $(e);
    259258
    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;
    262260                if ( 'string' == typeof s ) { s = { what: s }; }
    263261                s = $.extend(_s, this.wpList.settings, s);
     
    269267                        old.replaceWith(e);
    270268                } else if ( isNaN(s.pos) ) {
    271                         var ba = 'after';
     269                        ba = 'after';
    272270                        if ( '-' == s.pos.substr(0,1) ) {
    273271                                s.pos = s.pos.substr(1);
    274272                                ba = 'before';
    275273                        }
    276                         var ref = list.find( '#' + s.pos );
     274                        ref = list.find( '#' + s.pos );
    277275                        if ( 1 === ref.size() ) { ref[ba](e); }
    278276                        else { list.append(e); }
     
    289287
    290288                if ( 'none' != s.addColor ) {
    291                         var color = wpList.getColor( e );
     289                        color = wpList.getColor( e );
    292290                        e.css( 'backgroundColor', s.addColor ).animate( { backgroundColor: color }, { complete: function() { $(this).css( 'backgroundColor', '' ); } } );
    293291                }
     
    297295
    298296        clear: function(e) {
    299                 var list = this;
     297                var list = this, t, tag;
    300298                e = $(e);
    301299                if ( list.wpList && e.parents( '#' + list.id ).size() ) { return; }
     
    303301                        if ( $(this).parents('.form-no-clear').size() )
    304302                                return;
    305                         var t = this.type.toLowerCase(); var tag = this.tagName.toLowerCase();
     303                        t = this.type.toLowerCase();
     304                        tag = this.tagName.toLowerCase();
    306305                        if ( 'text' == t || 'password' == t || 'textarea' == tag ) { this.value = ''; }
    307306                        else if ( 'checkbox' == t || 'radio' == t ) { this.checked = false; }
     
    315314                        .filter('form').submit( function() { return list.wpList.add(this); } ).end()
    316315                        .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 = [];
    319317                                if ( !c ) { return; }
    320                                 var forms = []; var ins = []; // this is all really inefficient
     318                                // this is all really inefficient
    321319                                $('#' + c + ' :input').focus( function() { currentFormEl = this; } ).blur( function() { currentFormEl = false; } ).each( function() {
    322320                                        ins.push(this);
     
    337335
    338336        recolor: function() {
    339                 var list = this;
     337                var list = this, items, eo;
    340338                if ( !list.wpList.settings.alt ) { return; }
    341                 var items = $('.list-item:visible', list);
     339                items = $('.list-item:visible', list);
    342340                if ( !items.size() ) { items = $(list).children(':visible'); }
    343                 var eo = [':even',':odd'];
     341                eo = [':even',':odd'];
    344342                if ( list.wpList.settings.altOffset % 2 ) { eo.reverse(); }
    345343                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.