2012-10-16 71 views
2

我正在使用的JQuery Mobile應用程序在軟鍵盤啓動時往往會嚇倒。我提出了一個解決方案,它工作的很好,但我不得不直接編輯jquery.mobile-1.2.0.js來完成它。我寧願將我的更改保存在擴展jQuery Mobile的jquery.mobile.customizations.js文件中。

我試圖做沒有成功如下:

delete $.mobile.getScreenHeight; 
$.mobile.last_width = null; 
$.mobile.last_height = null; 
$.mobile.getScreenHeight = function() 
{ 
    // My modified version 
} 

我加入警報陳述了我的$.mobile.getScreenHeight,加上原來的$.mobile.getScreenHeight。我確實看到我的自定義方法的警報被解僱,但有時它也會觸發原始函數中的警報。

有誰知道正確的方式來覆蓋$ .mobile中的方法,並且還添加了兩個新的屬性?

(約原來的問題全部細節都在window.resize due to virtual keyboard causes issues with jquery mobile

更新:

@elclanrs - 我已經試過,沒有運氣來實現下面的代碼。我也嘗試交換第二個和第三個參數。每當我運行代碼時,它會激發我的擴展getScreenHeight,但隨後它會激發getScreenHeight基礎。 (我掏空原getScreenHeight並把警報內。該警報不應該這樣火。

公開賽的想法!

$.mobile = $.extend({}, $.mobile, { 
    last_width: null, 
    last_height: null, 
    getScreenHeight: function() { 
     // My code... 
    } 
}); 
+0

我找不到'last_width'和'last_height'通過查看源代碼,但覆蓋'getScreenHeight'就像應該工作... – elclanrs

+0

是的,抱歉 - 澄清,我添加了last_width和last_height屬性,並且我想重寫getScreenHeight()。然而,我試過的方法,如上所示,並沒有像預期的那樣工作。它激發了我的自定義功能和原始功能。 – Anthony

+0

您不需要刪除它就可以覆蓋它。用'.extend'替代$'.extend({getScreenHeight:function(){...}},$ .mobile)' – elclanrs

回答

0

出錯行似乎是一個getScreenHeight = $.mobile.getScreenHeight;哪個地方封閉內目前的定義。對於resetActivePageHeight功能我不知道這是可能的情況下直接編輯文件來覆蓋這一點,但你也許能阻止它的下游:

//simply set the active page's minimum height to screen height, depending on orientation 
    function resetActivePageHeight() { 
    var aPage = $("." + $.mobile.activePageClass), 
     aPagePadT = parseFloat(aPage.css("padding-top")), 
     aPagePadB = parseFloat(aPage.css("padding-bottom")), 
     aPageBorderT = parseFloat(aPage.css("border-top-width")), 
     aPageBorderB = parseFloat(aPage.css("border-bottom-width")); 

    aPage.css("min-height", getScreenHeight() - aPagePadT - aPagePadB - aPageBorderT - aPageBorderB); 
    } 


    //set page min-heights to be device specific 
    $(document).bind("pageshow", resetActivePageHeight); 
    $(window).bind("throttledresize", resetActivePageHeight); 

定義自己的resetActivePageHeight然後0那些可能會做的伎倆。這有點亂。

相關問題