I want a simple function for toggling full screen. Here is what I've written:
function toggleFullScreen() {
var elem = document.documentElement,
request = elem.requestFullscreen || elem.msRequestFullscreen || elem.mozRequestFullScreen || elem.webkitRequestFullscreen,
exit = document.exitFullscreen || document.msExitFullscreen || document.mozCancelFullScreen || document.webkitExitFullscreen;
if (!document.fullscreenElement && !document.msFullscreenElement && !document.mozFullScreenElement && !document.webkitFullscreenElement) {
request.call(elem);
} else {
exit.call(document);
}
}
Any better or simple solution?
Thanks.
Related
How can I write an alternative function for DOMSubtreeModified?
$('html').bind('DOMNodeInserted DOMNodeRemoved', function(event) {
var structure = $(event.target).closest(".form--group");
structure.find(".thevoornaam, .date_of_birth, .stepbirthVal, .livingkid, .right, .limitSelected, .pijlers, .total_pijlers").on("keyup change DOMSubtreeModified", function() {
if (structure.find(".thevoornaam").val().length > 1 && structure.find(".date_of_birth").val().length > 1 && structure.find('.stepbirthVal').html() == "" && structure.find(".livingkid").is(':checked') && structure.find(".right").is(':checked') && structure.find(".limitSelected:checked").val() == "1" && structure.find(".pijlers").val() != null && structure.find(".total_pijlers").val() != null) {
$("#stepbirth").removeClass("disabled");
} else if (structure.find(".thevoornaam").val().length > 1 && structure.find(".date_of_birth").val().length > 1 && structure.find('.stepbirthVal').html() == "" && structure.find(".livingkid").is(':checked') && structure.find(".right").is(':checked') && structure.find(".limitSelected:checked").val() == "0") {
$("#stepbirth").removeClass("disabled");
} else {
$("#stepbirth").addClass("disabled");
}
});
});
This function is working fine but i am getting this message in browser console.
[Violation] Added synchronous DOM mutation listener to a event. Consider using MutationObserver to make the page more responsive.
Can anyone help me with this?
Thanks in advance.
In event.js, to judge the same handler, here is code:
return handler
&& (!event.e || handler.e == event.e)
&& (!event.ns || matcher.test(handler.ns))
&& (!fn || zid(handler.fn) === zid(fn))
&& (!selector || handler.sel == selector)
Why use (!fn || zid(handler.fn) === zid(fn)) to (!fn || handler.fn === fn)
Here is the source code of zid
var _zid = 1
function zid(element) {
return element._zid || (element._zid = _zid++)
}
if I have to judge two functions, a === b is enough
why to use zid(a) === zid(b)? Maybe some trap?
I don't know why?
Here is the source code of zepto.js event.js: https://github.com/madrobby/zepto/blob/master/src/event.js
I wanted to hide header only in mobile applications, but have to show header in all mobile browsers as same as in desktop browsers. how can i recognize mobile application through css media queries or in java script or else is there any choice to find mobile application??
can you please help me i can i hide html header only on mobile applications ??
i have tried below java script code but i did not get result
var isOpera = (!!window.opr && !!opr.addons) || !!window.opera || navigator.userAgent.indexOf(' OPR/') >= 0;
var isFirefox = typeof InstallTrigger !== 'undefined';
var isSafari = Object.prototype.toString.call(window.HTMLElement).indexOf('Constructor') > 0;
var isIE = /*#cc_on!#*/false || !!document.documentMode;
var isEdge = !isIE && !!window.StyleMedia;
var isChrome = !!window.chrome && !!window.chrome.webstore;
var isBlink = (isChrome || isOpera) && !!window.CSS;
var isMobile = {
Android: function () {
return navigator.userAgent.match(/Android/i);
},
BlackBerry: function () {
return navigator.userAgent.match(/BlackBerry/i);
},
iOS: function () {
return navigator.userAgent.match(/iPhone|iPad|iPod/i);
},
Opera: function () {
return navigator.userAgent.match(/Opera Mini/i);
},
Windows: function () {
return navigator.userAgent.match(/IEMobile/i) || navigator.userAgent.match(/WPDesktop/i);
},
any: function () {
return (isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Opera() || isMobile.Windows());
}
};
var mobOpera = (navigator.userAgent.indexOf("Opera") || navigator.userAgent.indexOf('OPR')) != -1;
var mobChrome = navigator.userAgent.indexOf("Chrome") != -1;
var mobSafari = navigator.userAgent.indexOf("Safari") != -1;
var mobFirefox = navigator.userAgent.indexOf("Firefox") != -1;
var mobIe = (navigator.userAgent.indexOf("MSIE") != -1) || (!!document.documentMode == true);
var nua = navigator.userAgent;
var is_android = ((nua.indexOf('Mozilla/5.0') > -1 && nua.indexOf('Android ') > -1 && nua.indexOf('AppleWebKit') > -1) && !(nua.indexOf('Chrome') > -1));
if (isOpera || isFirefox || isSafari || isIE || isEdge || isChrome || isBlink) {
$(".navbar-fixed-top").css("display", "block");
}
else if (mobOpera || mobChrome || mobSafari || mobFirefox || mobIe) {
$(".navbar-fixed-top").css("display", "block");
}
else if(is_android || isMobile.any()){
$(".navbar-fixed-top").css("display", "block");
}
else
$(".navbar-fixed-top").css("display", "none");
the default behavior of setFocusOnError= true set the focus on error field. But issue is that there is a banner on top of the window having fixed position. due to which banner hides the error field. How do I override the default working of setFocusOnError so that there is a margin between banner and the error field?
<script type="text/jscript">
$(function () {
// on first time page load
if (typeof (Page_ClientValidate) != "undefined") {
ValidatorSetFocus = CustomSetFocus;
}
});
function CustomSetFocus(val, event) {
var ctrl;
if (typeof (val.controlhookup) == "string") {
var eventCtrl;
if ((typeof (event) != "undefined") && (event != null)) {
if ((typeof (event.srcElement) != "undefined") && (event.srcElement != null)) {
eventCtrl = event.srcElement;
}
else {
eventCtrl = event.target;
}
}
if ((typeof (eventCtrl) != "undefined") && (eventCtrl != null) &&
(typeof (eventCtrl.id) == "string") &&
(eventCtrl.id == val.controlhookup)) {
ctrl = eventCtrl;
}
}
if ((typeof (ctrl) == "undefined") || (ctrl == null)) {
ctrl = document.getElementById(val.controltovalidate);
}
if ((typeof (ctrl) != "undefined") && (ctrl != null) &&
(ctrl.tagName.toLowerCase() != "table" || (typeof (event) == "undefined") || (event == null)) &&
((ctrl.tagName.toLowerCase() != "input") || (ctrl.type.toLowerCase() != "hidden")) &&
(typeof (ctrl.disabled) == "undefined" || ctrl.disabled == null || ctrl.disabled == false) &&
(typeof (ctrl.visible) == "undefined" || ctrl.visible == null || ctrl.visible != false) &&
(IsInVisibleContainer(ctrl))) {
if ((ctrl.tagName.toLowerCase() == "table" && (typeof (__nonMSDOMBrowser) == "undefined" || __nonMSDOMBrowser)) ||
(ctrl.tagName.toLowerCase() == "span")) {
var inputElements = ctrl.getElementsByTagName("input");
var lastInputElement = inputElements[inputElements.length - 1];
if (lastInputElement != null) {
ctrl = lastInputElement;
}
}
if (typeof (ctrl.focus) != "undefined" && ctrl.focus != null) {
ctrl.focus();
Page_InvalidControlToBeFocused = ctrl;
var temp1=$(window).scrollTop();
temp1 = temp1 - 150;
$(window).scrollTop(temp1);
}
}
}
</script>
TableHandler.prototype.IsAlreadySelected = function(dataToCheck)
{
var _this = this;
if (_this.NewTemplateUsageSelected.length > 0)
{
var len = _this.NewTemplateUsageSelected.length;
for (var i = 0; i < len; i++)
{
var an = _this.NewTemplateUsageSelected[i];
var isTemplateUsageDataDuplicate=false;
var isNonApplicableCGDataDuplicate=false;
if ((an.CustomerName == dataToCheck.CustomerName) &&
(an.ProgramName == dataToCheck.ProgramName) &&
(an.WorkpackageName == dataToCheck.WorkpackageName) &&
(an.ActivityName == dataToCheck.ActivityName) &&
(an.SelectedWorkFlowType == dataToCheck.SelectedWorkFlowType) &&
(an.SelectedWorkFlowCategory == dataToCheck.SelectedWorkFlowCategory) &&
(an.ReWorkflow== dataToCheck.ReWorkflow) &&
(an.AllowCheckGroupSelection == dataToCheck.AllowCheckGroupSelection) &&
(an.InitiatorGroupSelection == dataToCheck.InitiatorGroupSelection) &&
(an.R1GroupSelection == dataToCheck.R1GroupSelection) &&
(an.R2GroupSelection == dataToCheck.R2GroupSelection) &&
(an.R3GroupSelection == dataToCheck.R3GroupSelection) &&
(an.R4GroupSelection == dataToCheck.R4GroupSelection) &&
(an.InitiatorMinReworkEffort == dataToCheck.InitiatorMinReworkEffort) &&
(an.R1MinReworkEffort == dataToCheck.R1MinReworkEffort) &&
(an.R2MinReworkEffort == dataToCheck.R2MinReworkEffort) &&
(an.R3MinReworkEffort == dataToCheck.R3MinReworkEffort) &&
(an.R4MinReworkEffort == dataToCheck.R4MinReworkEffort) &&
(an.AllowFileAttachment == dataToCheck.AllowFileAttachment) &&
(an.QualityReviewer== dataToCheck.QualityReviewer) &&
(an.AllowLiabiltySelection == dataToCheck.AllowLiabiltySelection)&&
(an.SetToInactive == dataToCheck.SetToInactive)&&
(an.NonApplicabilityCheckGroupAllowed == dataToCheck.NonApplicabilityCheckGroupAllowed))
{
istemplateusagedataduplicate=true;
}
var checkgroupslendataToCheck=dataToCheck.NonApplicableCheckGroupList.length;
var nalen=an.NonApplicableCheckGroupList.length;
if(checkgroupslendataToCheck == nalen )
{
for (var i = 0 ;i < checkgroupslendataToCheck ; i++)
{
var naDatatocheck= dataToCheck.NonApplicableCheckGroupList[i];
var naData=an.NonApplicableCheckGroupList[i];
if(
( naDatatocheck.INonApplicability == naData.INonApplicability )&&
( naDatatocheck.R1NonApplicability == naData.R1NonApplicability )&&
( naDatatocheck.R2NonApplicability == naData.R2NonApplicability) &&
( naDatatocheck.R3NonApplicability == naData.R3NonApplicability )&&
( naDatatocheck.R4NonApplicability == naData.R4NonApplicability))
isNonApplicableCGDataDuplicate=true;
else
{
isNonApplicableCGDataDuplicate=false;
break;
}
}
if(isNonApplicableCGDataDuplicate==true && istemplateusagedataduplicate==true)
return true;
}
}
}
};
The above code is causing error Internet may run slowly. When i seached for a solution i got solutions like change of registry and IE version, Move the code to cdebehind,usage of plugin etc.. Which are not feasible in our project. So I have to change the above logic.Any inbuilt function in javascript or jquery which i can use to campare a two nested list.
The inner loop needs to use a different variable as its counter or it will make the outer loop go on infinitely. Currently you are using i for both loops.