开发者

How to use jQuery BlockUI in the master page to load Please wait Message..

开发者 https://www.devze.com 2023-01-29 06:35 出处:网络
I need to implement jquery blockUI for my application.. I have this code.. $.blockUI({ css: { border: \'none\',

I need to implement jquery blockUI for my application.. I have this code..

 $.blockUI({ css: { 
            border: 'none', 
            padding: '15px', 
            backgroundColor: '#000', 
            '-webkit-border-radius': '10px', 
            '-moz-border-radius': '10px', 
            opacity: .5, 
            color: '#fff' 
        } }); 

        setTimeout($.unblockUI, 2000); 
    }); 

I am keeping this code in each click function in my views.. then it working fine. but I need to make this code centralized that is keeping this code in master file if something is taking more tha开发者_如何学运维n 2000 milliseconds can I show do jQuery BlockUI? for my entire application. if so please can any one help me out how to keep this code in master page what kind of code I need to implement in master page to access this jQuery blockUI?


I do this way:

In the masterpage I have added the script reference and a reference to a custom script where I have the following code

//Set Defaults values for blockUI
$.blockUI.defaults.theme = true;
$.blockUI.defaults.title = 'Please wait...';
$.blockUI.defaults.message = '<img src="_assets/images/blockUI_Loader.gif" />';
$.blockUI.defaults.css = {};
$.blockUI.defaults.themedCSS = {};
$.blockUI.defaults.themedCSS.width = 100;
$.blockUI.defaults.themedCSS.height = 64;
$.blockUI.defaults.overlayCSS = {};
$.blockUI.defaults.overlayCSS.backgroundColor = '#ffffff';
$.blockUI.defaults.overlayCSS.opacity = 0.6; 

Then when I have to use it in ajax calls I simply use

$("#element").block();
$.ajax({
    type: "get",
    dataType: "html",
    url: "some/url",
    data: {},
    success: function (response, status, xml) {
        $("#element").unblock();
    },
    error: function (response) {
        $("#element").unblock();
    }
});


To make it accessible everywhere without writing it over and over again, you can place the code in a function()

for example, place this in your global javascript file:

function blockUI(){
// $.blockUI({ css: {...
}

Then anywhere you need it, call blockUI();

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号