Hello guys i know my question is similar to other questions but my problem is different. Please listen to me carefully.
Simply i just want to know if am calling a function again and again how to set a condition in my plugin code that if am not calling that particular section is not run.
I have write a plugin type short code in jQuery. which is specific for my project.
It works for set width and height of that particular element which i'll pass in parameters.
On window load and window resize.
Am a beginner in jquery so am not too much familiar with objects.
here is the code
//creating some universal variable
var _W, _H, _header, _lH, _lW, _lH1, _lH2, _lH3;
(function($){
adjust = function(options) {
var defaults = {
headerClass: '',
containerClass : '',
Hlevel1:{space:0, divClass :'', prevDivClass : ''},
Hlevel2:{space:0, divClass :'', prevDivClass : ''},
Hlevel3:'',
Wlevel1 : {space:0, divClass : '', prevDivClass : ''},
Wlevel2 : {space:0, divClass : '', prevDivClass : ''}
};
var opts = $.extend(defaults, options);
function performAdjust(){
_W = $(window).width(); //retrieve current window width
_H = $(window).height(); //retrieve current window height
_headH = $(opts.headerClass).outerHeight(true);//retrieve current header height
// take left height after header height subtract to window height
_lH = _H - _headH
//make a variable for level one height
_lH1 = _lH - (opts.Hlevel1.space + $(opts.Hlevel1.prevDivClass).outerHeight(true))
//make a variable for level two height
_lH2 = _lH1 - (opts.Hlevel2.space + $(opts.Hlevel2.prevDivClass).outerHeight(true));
//applying height on main container
$(opts.containerClass).css({height:_lH});
//applying height on level 1 div
$(opts.Hlevel1.divClass).css({height:_lH1 });
//applying height on level 2 div
$(opts.Hlevel2.divClass).css({height:_lH2 });
//take left width after level one element
// if(typeof opts.Wlevel1.divClass === 'undefined'){
// console.log('insert in if');
// }
var prdiv_lw1 = $(opts.Wlevel1.prevDivClass).outerWidth(true);
_lW1 = _W - (prdiv_lw1+ opts.Wlevel1.space);
//applying Width on level 1 div
$(opts.Wlevel1.divClass).css({width:_lW1 });
//take left width after level one element
_lW2 = _lW1 - ($(opts.Wlevel2.prevDivClass).outerWidth(true)+ opts.Wlevel2.space);
//applying Width on level 2 div
$(opts.Wlevel2.divClass).css({width:_lW2 });
};
$(function() {
performAdjust();
});
$(window).resize(function() {
performAdjust();
});
}
})(jQuery);
How to Initialize it
// initialize adjust function for manage route
$(document).ready(function (){
adjust({
headerClass : '.header',
containerClass :'.container, .navContainer',
Hlevel1: {space:0, divClass : '.viewport', prevDivClass : '#leftBreadcrumb'},
Wlevel1 :{space:0, divClass : '.contentContainer', prevDivClass : '.navContainer'},
Wlevel2 :{space:0, divClass : '.header-midsec', prevDivClass : '.navContainer'}
})
});
Initialize it again when the page came by ajax request
$(document).ready(function (){
adjust({
Hlevel1: {space:100, divClass : '.viewport1', prevDivClass : '.routeHead '},
})
});
The Problem
When i initialize it again for other elements it will override all property.
first time i initialize it for main page structure. Next time my page came from ajax request so underneath that structure some elements need dynamic width, height for adjust this i've to initialize it again but it will override all property.
I would like to make a condition if i'll calling this function again and not passing unused object and parameter then that will not run.
How can i achieve this please let me know
Thanks in advance and sorry for my english
Simply i just want to know if am calling a function again and again how to set a condition in my plugin that if am not calling that particular section is not run.
One more thing i've tried typeof but i can't understand how to handle it.