2012-10-16 69 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那些可能会做的伎俩。这有点乱。

相关问题