自定義母版頁之列表過濾菜單位置issue fix

問題描述:javascript

自定義母版頁,爲了使左邊導航和頂部導航位置不變(不滾動),將本來位於ribbon下方的#s4-workspace調整到左側導航右邊。html

<div id="s4-workspace" style="position: relative; margin-left: 155px; ">

body #s4-workspace {
overflow-y: scroll;
overflow-x: auto;
position: relative;
left: 0px;
}

  

這時,若是視圖字段較多,須要往右滾動主區域,會出現過濾菜單被左側導航壓住的狀況。java

解決:jquery

1) 修改web.config將編譯模式調整爲debug,這時候,moss會採用調試模式的js,如core.debug.js.web

2)跟蹤js代碼,最終發現設置菜單位置的js函數位於Core.debug.js的SetMenuPosition函數

3)SetMenuPosition這個函數比較複雜,可是好在它是在最後設置菜單位置的:網站

oPopup.style.left=posLeft+"px";
oPopup.style.top=posTop+"px";
oPopup.LeftForBackIframe=posLeft;
oPopup.TopForBackIframe = posTop;

這樣,咱們就能夠直接把代碼附加到這個函數後面來修復菜單的位置。spa

修復邏輯:debug

1-檢測菜單是否處於#s4-workspace內,若否,則不作操做(由於moss中的其餘彈出菜單,包括網站操做,也是採用這個js來設置位置的)調試

2-若是菜單的left小於#s4-workspace的左側滾動寬度,則將菜單的left設置爲#s4-workspace的左滾動寬度(scrollLeft)

4)修該moss自帶的js文件不是一個推薦的作法,由於系統升級的時候自帶的js文件可能被覆蓋掉。因此,這裏採用一種相似於「重載」的方式。代碼以下:

//fix function begin--------------------
//add by zjy to fix the filter menu is hidden by left bar issue
var defaultSetMenuPosition = SetMenuPosition;
SetMenuPosition = function (oMaster, oParent, oPopup, oInnerDiv, fFlipTop, fTopLevel) {
    defaultSetMenuPosition(oMaster, oParent, oPopup, oInnerDiv, fFlipTop, fTopLevel);
    var $parentWs = $(oPopup).closest("#s4-workspace");
    if($parentWs.length==0)
        return;
    var wsScrollLeft = $parentWs.scrollLeft();
    var leftStr = "" + oPopup.style.left;
    var intMenuLeft = parseInt(leftStr.substring(0,leftStr.length-2)); //2px to 2
    if(intMenuLeft<wsScrollLeft){
        oPopup.style.left = wsScrollLeft + "px";
        oPopup.LeftForBackIframe = wsScrollLeft;
    }
}
//fix function end-----------------------

備註:

1)將以上函數添加到任意地方便可,如自定義的母版頁中。 

此函數依賴jquery,請確保母版頁引用jquery.

由於core.js是採用SOD加載的,因此須要用ExecuteOrDelayUntilScriptLoaded確保SetMenuPosition函數已加載:

// Fix issue: popup menu was hidden by left menu bar.
        ExecuteOrDelayUntilScriptLoaded(function () {
            var defaultSetMenuPosition = SetMenuPosition;
            SetMenuPosition = function (oMaster, oParent, oPopup, oInnerDiv, fFlipTop, fTopLevel) {
                defaultSetMenuPosition(oMaster, oParent, oPopup, oInnerDiv, fFlipTop, fTopLevel);
                var $parentWs = $(oPopup).closest("#s4-workspace");
                if ($parentWs.length == 0)
                    return;
                var wsScrollLeft = $parentWs.scrollLeft();
                var leftStr = "" + oPopup.style.left;
                var intMenuLeft = parseInt(leftStr.substring(0, leftStr.length - 2)); //2px to 2
                if (intMenuLeft < wsScrollLeft) {
                    oPopup.style.left = wsScrollLeft + "px";
                    oPopup.LeftForBackIframe = wsScrollLeft;
                }
            }
        }, "core.js")
    </script>

2)爲避免列表項上下文菜單位置異常,滾動條必定要設置在s4-workspace上。

相關文章
相關標籤/搜索