Make WordPress Core

Ticket #13525: nav-menu-rtl-js.13525.diff

File nav-menu-rtl-js.13525.diff, 3.9 KB (added by filosofo, 15 years ago)
  • wp-admin/js/nav-menu.dev.js

     
    2222                menuList : undefined,   // Set in init.
    2323                targetList : undefined, // Set in init.
    2424                menusChanged : false,
     25                isRTL: !! ( 'undefined' != typeof isRtl && isRtl ),
    2526
    2627                // Functions that run on init.
    2728                init : function() {
     
    5253                        // jQuery extensions
    5354                        $.fn.extend({
    5455                                menuItemDepth : function() {
    55                                         var margin = this.eq(0).css('margin-left');
     56                                        var margin = api.isRTL ? this.eq(0).css('margin-right') : this.eq(0).css('margin-left');
    5657                                        return api.pxToDepth( margin && -1 != margin.indexOf('px') ? margin.slice(0, -2) : 0 );
    5758                                },
    5859                                updateDepthClass : function(current, prev) {
     
    244245                                placeholder: 'sortable-placeholder',
    245246                                start: function(e, ui) {
    246247                                        var height, width, parent, children, maxChildDepth, tempHolder;
     248                                       
     249                                        // handle placement for rtl orientation
     250                                        if ( api.isRTL )
     251                                                ui.item[0].style.right = 'auto';
    247252
    248253                                        transport = ui.item.children('.menu-item-transport');
    249254
     
    306311                                        // address sortable's incorrectly-calculated top in opera
    307312                                        ui.item[0].style.top = 0;
    308313
     314                                        // handle drop placement for rtl orientation
     315                                        if ( api.isRTL ) {
     316                                                ui.item[0].style.left = 'auto';
     317                                                ui.item[0].style.right = 0;
     318                                        }
     319
    309320                                },
    310321                                change: function(e, ui) {
    311322                                        // Make sure the placeholder is inside the menu.
     
    317328                                },
    318329                                sort: function(e, ui) {
    319330                                        var offset = ui.helper.offset(),
    320                                                 depth = api.pxToDepth( offset.left - menuLeft );
     331                                                depth = Math.abs( api.pxToDepth( offset.left - menuLeft ) );
    321332                                        // Check and correct if depth is not within range.
    322333                                        // Also, if the dragged element is dragged upwards over
    323334                                        // an item, shift the placeholder to a child position.
     
    656667                                        if( ! t.length ) return;
    657668                                        left = t.offset().left;
    658669                                        right = left + t.outerWidth();
    659                                         if( right > fixedRight )
    660                                                 fluid.animate({ 'margin-left' :  "+=" + (fixedRight - right) + 'px' }, 'fast');
    661                                         else if ( left < fixedLeft )
    662                                                 fluid.animate({ 'margin-left' :  "-=" + (left - fixedLeft) + 'px' }, 'fast');
     670                                        if( right > fixedRight ) {
     671                                                if ( api.isRTL )
     672                                                        fluid.animate({ 'margin-right' :  "+=" + (fixedRight - right) + 'px' }, 'fast');
     673                                                else
     674                                                        fluid.animate({ 'margin-left' :  "+=" + (fixedRight - right) + 'px' }, 'fast');
     675                                        } else if ( left < fixedLeft ) {
     676                                                if ( api.isRTL )
     677                                                        fluid.animate({ 'margin-right' :  "-=" + (left - fixedLeft) + 'px' }, 'fast');
     678                                                else
     679                                                        fluid.animate({ 'margin-left' :  "-=" + (left - fixedLeft) + 'px' }, 'fast');
     680                                        }
    663681                                        return t;
    664682                                },
    665683                                isTabVisible : function() {
     
    681699                                - fluid.css('padding-right').slice(0,-2) )
    682700                                return;
    683701
    684                         // Set up right margin for overflow, unset padding
    685                         fluid.css({
    686                                 'margin-right'  : (-1 * tabsWidth) + 'px',
    687                                 'padding' : 0
    688                         });
     702                        if ( api.isRTL ) {
     703                                fluid.css({
     704                                        'margin-left'  : (-1 * tabsWidth) + 'px',
     705                                        'padding' : 0
     706                                });
     707                        } else {
     708                                // Set up right margin for overflow, unset padding
     709                                fluid.css({
     710                                        'margin-right'  : (-1 * tabsWidth) + 'px',
     711                                        'padding' : 0
     712                                });
     713                        }
    689714
    690715                        // Build tab navigation
    691716                        arrowLeft = $('<div class="nav-tabs-arrow nav-tabs-arrow-left"><a>&laquo;</a></div>');
     
    722747                                        var last = tabs[that.last](),
    723748                                                fn = function() {
    724749                                                        if( ! last.isTabVisible() )
    725                                                                 fluid.animate({ 'margin-left' :  that.operator + '90px' }, 300, "linear", fn);
     750                                                                if ( api.isRTL )
     751                                                                        fluid.animate({ 'margin-right' :  that.operator + '90px' }, 300, "linear", fn);
     752                                                                else
     753                                                                        fluid.animate({ 'margin-left' :  that.operator + '90px' }, 300, "linear", fn);
    726754                                                };
    727755                                                fn();
    728756                                }).mouseup(function(){