lundi 21 novembre 2016

If/Else Javascript statement to disable transition animation if failed

I have a navigation bar that has a hamburger menu button. The navigation menu worked on all browsers before I added an open/close javascript animation. On a few older browsers, the script will unfortunately prevent the menu from opening at all if clicked. But it works on most newer browsers. I need to make the script stop if it doesn't execute properly to let the older browsers be able to open the navigation bar.

I have written an easy fix to stop the script from executing if "something" is false.

if (something == false) {
  <!--animation script goes here -->
stop
}

Changing "something" to different things has given me interesting results. If I change it to

if (data == false) {
  <!--animation script goes here -->
stop
}

Then it will completely stop the script even in the browsers that ran the animation perfectly before.

My question is, what can I replace "something" with to make the script stop if it didn't run successfully?

Here is the animation script, if you need it. (Don't let it scare you. All I need is to stop this script if the animation fails.)

! function() {
"use strict";

function e() {
    var e, t = document.createElement("div"),
        n = {
            transition: "transitionend",
            OTransition: "otransitionend",
            MozTransition: "transitionend",
            WebkitTransition: "webkitTransitionEnd"
        };
    for (e in n)
        if (n.hasOwnProperty(e) && void 0 !== t.style[e]) return n[e];
    return !1
}

function t(e) {
    var t = {};
    e = e || window.event, t.evTarget = e.currentTarget || e.srcElement;
    var n = t.evTarget.getAttribute("data-target");
    return t.dataTarget = n ? document.querySelector(n) : !1, t
}

function n(e) {
    var t = e.style.height;
    e.style.height = "auto";
    var n = getComputedStyle(e).height;
    return e.style.height = t, e.offsetHeight, n
}

function a(e, t) {
    if (document.createEvent) {
        var n = document.createEvent("HTMLEvents");
        n.initEvent(t, !0, !1), e.dispatchEvent(n)
    } else e.fireEvent("on" + t)
}

function r(e, t) {
    e.classList.remove("collapse"), e.classList.add("collapsing"), t.classList.remove("collapsed"), t.setAttribute("aria-expanded", !0), e.style.height = n(e), u ? e.addEventListener(u, function() {
        s(e)
    }, !1) : s(e)
}

function i(e, t) {
    e.classList.remove("collapse"), e.classList.remove("in"), e.classList.add("collapsing"), t.classList.add("collapsed"), t.setAttribute("aria-expanded", !1), e.style.height = getComputedStyle(e).height, e.offsetHeight, e.style.height = "0px"
}

function s(e) {
    e.classList.remove("collapsing"), e.classList.add("collapse"), e.setAttribute("aria-expanded", !1), "0px" !== e.style.height && (e.classList.add("in"), e.style.height = "auto")
}

function o(e) {
    e.preventDefault();
    var n = t(e),
        a = n.dataTarget;
    return a.classList.contains("in") ? i(a, n.evTarget) : r(a, n.evTarget), !1
}

function l(e) {
    function n() {
        try {
            i.parentNode.removeChild(i), a(i, "closed.bs.alert")
        } catch (e) {
            window.console.error("Unable to remove alert")
        }
    }
    e.preventDefault();
    var r = t(e),
        i = r.dataTarget;
    if (!i) {
        var s = r.evTarget.parentNode;
        s.classList.contains("alert") ? i = s : s.parentNode.classList.contains("alert") && (i = s.parentNode)
    }
    return a(i, "close.bs.alert"), i.classList.remove("in"), u && i.classList.contains("fade") ? i.addEventListener(u, function() {
        n()
    }, !1) : n(), !1
}

function c(e) {
    e = e || window.event;
    var t = e.currentTarget || e.srcElement;
    return t.parentElement.classList.toggle("open"), !1
}

function d(e) {
    e = e || window.event;
    var t = e.currentTarget || e.srcElement;
    return t.parentElement.classList.remove("open"), e.relatedTarget && "dropdown" !== e.relatedTarget.getAttribute("data-toggle") && e.relatedTarget.click(), !1
}
for (var u = e(), g = document.querySelectorAll("[data-toggle=collapse]"), v = 0, f = g.length; f > v; v++) g[v].onclick = o;
for (var p = document.querySelectorAll("[data-dismiss=alert]"), h = 0, m = p.length; m > h; h++) p[h].onclick = l;
for (var L, T = document.querySelectorAll("[data-toggle=dropdown]"), y = 0, E = T.length; E > y; y++) L = T[y], L.setAttribute("tabindex", "0"), L.onclick = c, L.onblur = d}();

I was thinking someone may be able to just say something like "if (transition == false) { stop }" or something that does that, that would be perfect.

Aucun commentaire:

Enregistrer un commentaire