soundasleep / jquery-dropdown

Bootstrap-style dropdowns with some added features and no dependencies.
Other
765 stars 265 forks source link

jQuery dropdown and Wordpress Admin Plugin #113

Closed Kivylius closed 7 years ago

Kivylius commented 8 years ago

Hi, I'm working on a plugin for WordPress and because the way the position is done in WordPress Admin page, this plugin is not able to pick up on the margins and the small/extended side panel and never aligns and brakes the position of the dropdown. The great news is that I figure it out and would like to share with people that are having the same problem.

on method postion() change the following code from:

function position() {

    var jqDropdown = $('.jq-dropdown:visible').eq(0),
    trigger = jqDropdown.data('jq-dropdown-trigger'),
    hOffset = trigger ? parseInt(trigger.attr('data-horizontal-offset') || 0, 10) : null,
    vOffset = trigger ? parseInt(trigger.attr('data-vertical-offset') || 0, 10) : null;

    ....

To:

function position() {

    var jqDropdown = $('.jq-dropdown:visible').eq(0),
    trigger = jqDropdown.data('jq-dropdown-trigger'),
    hOffset = trigger ? parseInt(trigger.attr('data-horizontal-offset') || 0, 10) : null,
    vOffset = trigger ? parseInt(trigger.attr('data-vertical-offset') || 0, 10) : null;

    if($('body').hasClass("wp-admin")){
        vOffset -= parseInt($('html.wp-toolbar').css("paddding-top"));
        hOffset -= parseInt($("#adminmenuback").css("width"));
    }

    ....

Hope that help someone @Kivylius

claviska commented 7 years ago

Thanks for sharing. Not something that will be included in core, of course. I'm hoping to work out a new, more reliable way to position them in the next release.