پرش به محتوا

مدیاویکی:Common.js: تفاوت میان نسخه‌ها

۳٬۷۴۷ بایت اضافه‌شده ،  ‏۳۰ سپتامبر ۲۰۲۱
بدون خلاصۀ ویرایش
بدون خلاصۀ ویرایش
بدون خلاصۀ ویرایش
خط ۴۷۵: خط ۴۷۵:


// sticky sidebar
// sticky sidebar
$( function() {
/**
var checks, first, last, checked, sliced, mobileEvent, transitionTimeout, focusedRowActions,
*  Adds common WordPress functionality to the window.
// lastClicked = false,
*
// pageInput = $('input.current-page'),
*  @param {jQuery} $       jQuery object.
// currentPage = pageInput.val(),
*  @param {Object} window  The window object.
isIOS = /iPhone|iPad|iPod/.test( navigator.userAgent ),
*  @param {mixed} undefined Unused.
isAndroid = navigator.userAgent.indexOf( 'Android' ) !== -1,
*/
$adminMenuWrap = $( '#mw-panel' ), //#adminmenuwrap
(function($, window, undefined) {
$wpwrap = $( '.mediawiki' ), //#wpwrap
        var $document = $(document),
$adminmenu = $( '#adminmenu' ),
            $window = $(window),
// $overlay = $( '#wp-responsive-overlay' ),
            $body = $(document.body),
// $toolbar = $( '#wp-toolbar' ),
            __ = wp.i18n.__,
// $toolbarPopups = $toolbar.find( 'a[aria-haspopup="true"]' ),
            sprintf = wp.i18n.sprintf;
// $sortables = $('.meta-box-sortables'),
// wpResponsiveActive = false,
// $adminbar = $( '#wpadminbar' ),
lastScrollPosition = 0,
// pinnedMenuTop = false,
// pinnedMenuBottom = false,
menuTop = 0,
menuState,
menuIsPinned = false,
height = {
window: $window.height(),
wpwrap: $wpwrap.height(),
adminbar: $adminbar.height(),
menu: $adminMenuWrap.height()
},
$headerEnd = $( '.wp-header-end' );


// If the menu is higher than the window, compensate on scroll.
        $(function() {
if ( height.menu + height.adminbar > height.window ) {
                var checks, first, last, checked, sliced, mobileEvent, transitionTimeout, focusedRowActions,
// Check for overscrolling, this happens when swiping up at the top of the document in modern browsers.
                    // lastClicked = false,
if ( windowPos < 0 ) {
                    // pageInput = $('input.current-page'),
// Stick the menu to the top.
                    // currentPage = pageInput.val(),
if ( ! pinnedMenuTop ) {
                    isIOS = /iPhone|iPad|iPod/.test(navigator.userAgent),
pinnedMenuTop = true;
                    isAndroid = navigator.userAgent.indexOf('Android') !== -1,
pinnedMenuBottom = false;
                    $adminMenuWrap = $('#mw-panel'), //#adminmenuwrap
                    $wpwrap = $('.mediawiki'), //#wpwrap
                    $adminmenu = $('#adminmenu'),
                    // $overlay = $( '#wp-responsive-overlay' ),
                    // $toolbar = $( '#wp-toolbar' ),
                    // $toolbarPopups = $toolbar.find( 'a[aria-haspopup="true"]' ),
                    // $sortables = $('.meta-box-sortables'),
                    // wpResponsiveActive = false,
                    // $adminbar = $( '#wpadminbar' ),
                    lastScrollPosition = 0,
                    // pinnedMenuTop = false,
                    // pinnedMenuBottom = false,
                    menuTop = 0,
                    menuState,
                    menuIsPinned = false,
                    height = {
                        window: $window.height(),
                        wpwrap: $wpwrap.height(),
                        adminbar: $adminbar.height(),
                        menu: $adminMenuWrap.height()
                    },
                    $headerEnd = $('.wp-header-end');


$adminMenuWrap.css({
                // If the menu is higher than the window, compensate on scroll.
position: 'fixed',
                if (height.menu + height.adminbar > height.window) {
top: '',
                    // Check for overscrolling, this happens when swiping up at the top of the document in modern browsers.
bottom: ''
                    if (windowPos < 0) {
});
                        // Stick the menu to the top.
}
                        if (!pinnedMenuTop) {
                            pinnedMenuTop = true;
                            pinnedMenuBottom = false;


return;
                            $adminMenuWrap.css({
} else if ( windowPos + height.window > $document.height() - 1 ) {
                                position: 'fixed',
// When overscrolling at the bottom, stick the menu to the bottom.
                                top: '',
if ( ! pinnedMenuBottom ) {
                                bottom: ''
pinnedMenuBottom = true;
                            });
pinnedMenuTop = false;
                        }


$adminMenuWrap.css({
                        return;
position: 'fixed',
                    } else if (windowPos + height.window > $document.height() - 1) {
top: '',
                        // When overscrolling at the bottom, stick the menu to the bottom.
bottom: 0
                        if (!pinnedMenuBottom) {
});
                            pinnedMenuBottom = true;
}
                            pinnedMenuTop = false;


return;
                            $adminMenuWrap.css({
}
                                position: 'fixed',
                                top: '',
                                bottom: 0
                            });
                        }


if ( windowPos > lastScrollPosition ) {
                        return;
// When a down scroll has been detected.
                    }


// If it was pinned to the top, unpin and calculate relative scroll.
                    if (windowPos > lastScrollPosition) {
if ( pinnedMenuTop ) {
                        // When a down scroll has been detected.
pinnedMenuTop = false;
// Calculate new offset position.
menuTop = $adminMenuWrap.offset().top - height.adminbar - ( windowPos - lastScrollPosition );


if ( menuTop + height.menu + height.adminbar < windowPos + height.window ) {
                        // If it was pinned to the top, unpin and calculate relative scroll.
menuTop = windowPos + height.window - height.menu - height.adminbar;
                        if (pinnedMenuTop) {
}
                            pinnedMenuTop = false;
                            // Calculate new offset position.
                            menuTop = $adminMenuWrap.offset().top - height.adminbar - (windowPos - lastScrollPosition);


$adminMenuWrap.css({
                            if (menuTop + height.menu + height.adminbar < windowPos + height.window) {
position: 'absolute',
                                menuTop = windowPos + height.window - height.menu - height.adminbar;
top: menuTop,
                            }
bottom: ''
});
} else if ( ! pinnedMenuBottom && $adminMenuWrap.offset().top + height.menu < windowPos + height.window ) {
// Pin it to the bottom.
pinnedMenuBottom = true;


$adminMenuWrap.css({
                            $adminMenuWrap.css({
position: 'fixed',
                                position: 'absolute',
top: '',
                                top: menuTop,
bottom: 0
                                bottom: ''
});
                            });
}
                        } else if (!pinnedMenuBottom && $adminMenuWrap.offset().top + height.menu < windowPos + height.window) {
} else if ( windowPos < lastScrollPosition ) {
                            // Pin it to the bottom.
// When a scroll up is detected.
                            pinnedMenuBottom = true;


// If it was pinned to the bottom, unpin and calculate relative scroll.
                            $adminMenuWrap.css({
if ( pinnedMenuBottom ) {
                                position: 'fixed',
pinnedMenuBottom = false;
                                top: '',
                                bottom: 0
                            });
                        }
                    } else if (windowPos < lastScrollPosition) {
                        // When a scroll up is detected.


// Calculate new offset position.
                        // If it was pinned to the bottom, unpin and calculate relative scroll.
menuTop = $adminMenuWrap.offset().top - height.adminbar + ( lastScrollPosition - windowPos );
                        if (pinnedMenuBottom) {
                            pinnedMenuBottom = false;


if ( menuTop + height.menu > windowPos + height.window ) {
                            // Calculate new offset position.
menuTop = windowPos;
                            menuTop = $adminMenuWrap.offset().top - height.adminbar + (lastScrollPosition - windowPos);
}


$adminMenuWrap.css({
                            if (menuTop + height.menu > windowPos + height.window) {
position: 'absolute',
                                menuTop = windowPos;
top: menuTop,
                            }
bottom: ''
});
} else if ( ! pinnedMenuTop && $adminMenuWrap.offset().top >= windowPos + height.adminbar ) {


// Pin it to the top.
                            $adminMenuWrap.css({
pinnedMenuTop = true;
                                position: 'absolute',
                                top: menuTop,
                                bottom: ''
                            });
                        } else if (!pinnedMenuTop && $adminMenuWrap.offset().top >= windowPos + height.adminbar) {


$adminMenuWrap.css({
                            // Pin it to the top.
position: 'fixed',
                            pinnedMenuTop = true;
top: '',
bottom: ''
});
}
} else if ( resizing ) {
// Window is being resized.


pinnedMenuTop = pinnedMenuBottom = false;
                            $adminMenuWrap.css({
                                position: 'fixed',
                                top: '',
                                bottom: ''
                            });
                        }
                    } else if (resizing) {
                        // Window is being resized.


// Calculate the new offset.
                        pinnedMenuTop = pinnedMenuBottom = false;
menuTop = windowPos + height.window - height.menu - height.adminbar - 1;


if ( menuTop > 0 ) {
                        // Calculate the new offset.
$adminMenuWrap.css({
                        menuTop = windowPos + height.window - height.menu - height.adminbar - 1;
position: 'absolute',
top: menuTop,
bottom: ''
});
} else {
unpinMenu();
}
}
}


lastScrollPosition = windowPos;
                        if (menuTop > 0) {
}
                            $adminMenuWrap.css({
                                position: 'absolute',
                                top: menuTop,
                                bottom: ''
                            });
                        } else {
                            unpinMenu();
                        }
                    }
                }


/**
                lastScrollPosition = windowPos;
* Determines the height of certain elements.
            }
*
* @since 4.1.0
*
* @return {void}
*/
function resetHeights() {
height = {
window: $window.height(),
wpwrap: $wpwrap.height(),
adminbar: $adminbar.height(),
menu: $adminMenuWrap.height()
};
}


/**
            /**
* Unpins the menu.
            * Determines the height of certain elements.
*
            *
* @since 4.1.0
            * @since 4.1.0
*
            *
* @return {void}
            * @return {void}
*/
            */
function unpinMenu() {
            function resetHeights() {
if ( isIOS || ! menuIsPinned ) {
                height = {
return;
                    window: $window.height(),
}
                    wpwrap: $wpwrap.height(),
                    adminbar: $adminbar.height(),
                    menu: $adminMenuWrap.height()
                };
            }


pinnedMenuTop = pinnedMenuBottom = menuIsPinned = false;
            /**
$adminMenuWrap.css({
            * Unpins the menu.
position: '',
            *
top: '',
            * @since 4.1.0
bottom: ''
            *
});
            * @return {void}
}
            */
            function unpinMenu() {
                if (isIOS || !menuIsPinned) {
                    return;
                }


/**
                pinnedMenuTop = pinnedMenuBottom = menuIsPinned = false;
* Pins and unpins the menu when applicable.
                $adminMenuWrap.css({
*
                    position: '',
* @since 4.1.0
                    top: '',
*
                    bottom: ''
* @return {void}
                });
*/
            }
function setPinMenu() {
resetHeights();


if ( $adminmenu.data('wp-responsive') ) {
            /**
$body.removeClass( 'sticky-menu' );
            * Pins and unpins the menu when applicable.
unpinMenu();
            *
} else if ( height.menu + height.adminbar > height.window ) {
            * @since 4.1.0
pinMenu();
            *
$body.removeClass( 'sticky-menu' );
            * @return {void}
} else {
            */
$body.addClass( 'sticky-menu' );
            function setPinMenu() {
unpinMenu();
                resetHeights();
}
}


if ( ! isIOS ) {
                if ($adminmenu.data('wp-responsive')) {
$window.on( 'scroll.pin-menu', pinMenu );
                    $body.removeClass('sticky-menu');
$document.on( 'tinymce-editor-init.pin-menu', function( event, editor ) {
                    unpinMenu();
editor.on( 'wp-autoresize', resetHeights );
                } else if (height.menu + height.adminbar > height.window) {
});
                    pinMenu();
}
                    $body.removeClass('sticky-menu');
                } else {
                    $body.addClass('sticky-menu');
                    unpinMenu();
                }
            }
 
            if (!isIOS) {
                $window.on('scroll.pin-menu', pinMenu);
                $document.on('tinymce-editor-init.pin-menu', function(event, editor) {
                    editor.on('wp-autoresize', resetHeights);
                });
            }
        }(jQuery, window));