• Resolved ToNowak

    (@tonowak)


    Hi,

    I installed your plugin recently to protect some of the content on the website I’ve been building. However, I noticed, that it doesn’t work on IE11, which was neccessary (despite of my deep antypathy towards that browser).

    I discovered that it was because JavaScript in /public/js/dist/ppw-rc-form.bundle.js is using arrow functions and findIndex, both not supported by Internet Explorers.

    Luckily I managed to fix it by using:
    1. https://babeljs.io to convert the code and get rid of arrow functions
    2. This solution (https://stackoverflow.com/questions/52773233/findindex-alternative-for-ie/52773320) to provide compatibility with findIndex function

    The resulting code looks like this:

    "use strict";
    
    function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
    
    !function (t) {
      var e = {};
    
      function n(o) {
        if (e[o]) return e[o].exports;
        var r = e[o] = {
          i: o,
          l: !1,
          exports: {}
        };
        return t[o].call(r.exports, r, r.exports, n), r.l = !0, r.exports;
      }
    
      n.m = t, n.c = e, n.d = function (t, e, o) {
        n.o(t, e) || Object.defineProperty(t, e, {
          enumerable: !0,
          get: o
        });
      }, n.r = function (t) {
        "undefined" != typeof Symbol && Symbol.toStringTag && Object.defineProperty(t, Symbol.toStringTag, {
          value: "Module"
        }), Object.defineProperty(t, "__esModule", {
          value: !0
        });
      }, n.t = function (t, e) {
        if (1 & e && (t = n(t)), 8 & e) return t;
        if (4 & e && "object" == _typeof(t) && t && t.__esModule) return t;
        var o = Object.create(null);
        if (n.r(o), Object.defineProperty(o, "default", {
          enumerable: !0,
          value: t
        }), 2 & e && "string" != typeof t) for (var r in t) {
          n.d(o, r, function (e) {
            return t[e];
          }.bind(null, r));
        }
        return o;
      }, n.n = function (t) {
        var e = t && t.__esModule ? function () {
          return t.default;
        } : function () {
          return t;
        };
        return n.d(e, "a", e), e;
      }, n.o = function (t, e) {
        return Object.prototype.hasOwnProperty.call(t, e);
      }, n.p = "./dist/", n(n.s = 1);
    }([function (t, e, n) {
      var o, r;
      /*!
       * JavaScript Cookie v2.2.1
       * https://github.com/js-cookie/js-cookie
       *
       * Copyright 2006, 2015 Klaus Hartl & Fagner Brack
       * Released under the MIT license
       */
    
      !function (i) {
        if (void 0 === (r = "function" == typeof (o = i) ? o.call(e, n, e, t) : o) || (t.exports = r), !0, t.exports = i(), !!0) {
          var p = window.Cookies,
              a = window.Cookies = i();
    
          a.noConflict = function () {
            return window.Cookies = p, a;
          };
        }
      }(function () {
        function t() {
          for (var t = 0, e = {}; t < arguments.length; t++) {
            var n = arguments[t];
    
            for (var o in n) {
              e[o] = n[o];
            }
          }
    
          return e;
        }
    
        function e(t) {
          return t.replace(/(%[0-9A-Z]{2})+/g, decodeURIComponent);
        }
    
        return function n(o) {
          function r() {}
    
          function i(e, n, i) {
            if ("undefined" != typeof document) {
              "number" == typeof (i = t({
                path: "/"
              }, r.defaults, i)).expires && (i.expires = new Date(1 * new Date() + 864e5 * i.expires)), i.expires = i.expires ? i.expires.toUTCString() : "";
    
              try {
                var p = JSON.stringify(n);
                /^[\{\[]/.test(p) && (n = p);
              } catch (t) {}
    
              n = o.write ? o.write(n, e) : encodeURIComponent(String(n)).replace(/%(23|24|26|2B|3A|3C|3E|3D|2F|3F|40|5B|5D|5E|60|7B|7D|7C)/g, decodeURIComponent), e = encodeURIComponent(String(e)).replace(/%(23|24|26|2B|5E|60|7C)/g, decodeURIComponent).replace(/[\(\)]/g, escape);
              var a = "";
    
              for (var s in i) {
                i[s] && (a += "; " + s, !0 !== i[s] && (a += "=" + i[s].split(";")[0]));
              }
    
              return document.cookie = e + "=" + n + a;
            }
          }
    
          function p(t, n) {
            if ("undefined" != typeof document) {
              for (var r = {}, i = document.cookie ? document.cookie.split("; ") : [], p = 0; p < i.length; p++) {
                var a = i[p].split("="),
                    s = a.slice(1).join("=");
                n || '"' !== s.charAt(0) || (s = s.slice(1, -1));
    
                try {
                  var c = e(a[0]);
                  if (s = (o.read || o)(s, c) || e(s), n) try {
                    s = JSON.parse(s);
                  } catch (t) {}
                  if (r[c] = s, t === c) break;
                } catch (t) {}
              }
    
              return t ? r[t] : r;
            }
          }
    
          return r.set = i, r.get = function (t) {
            return p(t, !1);
          }, r.getJSON = function (t) {
            return p(t, !0);
          }, r.remove = function (e, n) {
            i(e, "", t(n, {
              expires: -1
            }));
          }, r.defaults = {}, r.withConverter = n, r;
        }(function () {});
      });
    }, function (t, e, n) {
      "use strict";
    
      n.r(e);
      var o = n(0),
          r = n.n(o);
      !function (t) {
        var e = "ppw_rc";
    
        function n(n) {
          var _this = this;
    
          n.preventDefault();
          var i = t(this).attr("data-submit"),
              p = t(this).closest("div"),
              a = t(this).find("input.ppw-password-input");
          if (!a.length) return;
          var s = t(this).find("input.ppw-submit"),
              c = ppwContentGlobal && ppwContentGlobal.label && ppwContentGlobal.label.LOADING ? ppwContentGlobal.label.LOADING : "Loading...";
          !function (t, e) {
            t.attr("disabled", !0), t.attr("data-text", t.val()), t.val(e);
          }(s, c);
          var u = t(a[0]).val();
          !function (e, n, o) {
            t("#submit").prop("disabled", !0), t.ajax({
              beforeSend: function beforeSend(t) {
                t.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"), t.setRequestHeader("X-WP-Nonce", ppwContentGlobal.nonce);
              },
              url: ppwContentGlobal.restUrl + "wppp/v1/check-content-password/" + e,
              type: "POST",
              data: n,
              success: function success(t) {
                o(t, null);
              },
              error: function error(t) {
                o(null, t);
              },
              timeout: 5e3
            });
          }(i, {
            pss: u,
            idx: p.attr("ppw-data-index"),
            page: t(this).find("input.ppw-page").val(),
            formType: p.attr("ppwp-type") || "",
            metaKey: p.attr("ppwp-metakey") || ""
          }, function (n, p) {
            var a = t(_this).find("div.ppw-error");
            console.log("Error happened", p), p ? (a.text(p.responseJSON.message), o(s)) : n.isValid ? (!function (t, n, o) {
              var i = function (t, e) {
                return "".concat(t, "-").concat(e);
              }(e, t),
                  p = r.a.getJSON(i),
                  a = Array.isArray(p) ? p : [],
                  s = a.findIndex(function (e) {
                return e.post_id === t;
              });
    
              s > -1 ? -1 === a[s].passwords.indexOf(n) && a[s].passwords.push(n) : a.push({
                post_id: t,
                passwords: [n]
              });
              r.a.set(i, a, {
                expires: new Date(1e3 * o),
                path: "/"
              });
            }(i, u, n.cookie_expired_time), location.reload(!0)) : (a.text(n.message), o(s));
          });
        }
    
        function o(t) {
          t.removeAttr("disabled"), t.val(t.attr("data-text"));
        }
    
        t(document).ready(function () {
          !function () {
            var e = window.ppwContentGlobal.supportedClassNames.defaultType;
            (function (e) {
              var n = t(".ppwp-is-custom-field");
    
              for (var _o = 0; _o < n.length; _o++) {
                var _r = t(n[_o]).attr("ppwp-data-mt"),
                    i = t(n[_o]).find(".".concat(e));
    
                for (var _e = 0; _e < i.length; _e++) {
                  var _n = t(i[_e]);
    
                  _n.attr("ppw-data-index", _e), _n.attr("ppwp-type", "cf"), _n.attr("ppwp-metakey", _r);
                }
              }
            })(e), function (e) {
              var n = t(".".concat(e));
              var o = [];
    
              for (var _e2 = 0; _e2 < n.length; _e2++) {
                var _r2 = t(n[_e2]).parent().attr("class");
    
                "ppwp-is-custom-field" !== _r2 && o.push(n[_e2]);
              }
    
              for (var _e3 = 0; _e3 < o.length; _e3++) {
                t(o[_e3]).attr("ppw-data-index", _e3);
              }
            }(e);
          }(), t(".ppw-form").bind("submit", n);
        });
      }(jQuery);
    }]);
    
    // https://tc39.github.io/ecma262/#sec-array.prototype.findindex
    if (!Array.prototype.findIndex) {
      Object.defineProperty(Array.prototype, 'findIndex', {
        value: function(predicate) {
         // 1. Let O be ? ToObject(this value).
          if (this == null) {
            throw new TypeError('"this" is null or not defined');
          }
    
          var o = Object(this);
    
          // 2. Let len be ? ToLength(? Get(O, "length")).
          var len = o.length >>> 0;
    
          // 3. If IsCallable(predicate) is false, throw a TypeError exception.
          if (typeof predicate !== 'function') {
            throw new TypeError('predicate must be a function');
          }
    
          // 4. If thisArg was supplied, let T be thisArg; else let T be undefined.
          var thisArg = arguments[1];
    
          // 5. Let k be 0.
          var k = 0;
    
          // 6. Repeat, while k < len
          while (k < len) {
            // a. Let Pk be ! ToString(k).
            // b. Let kValue be ? Get(O, Pk).
            // c. Let testResult be ToBoolean(? Call(predicate, T, ? kValue, k, O ?)).
            // d. If testResult is true, return k.
            var kValue = o[k];
            if (predicate.call(thisArg, kValue, k, o)) {
              return k;
            }
            // e. Increase k by 1.
            k++;
          }
    
          // 7. Return -1.
          return -1;
        },
        configurable: true,
        writable: true
      });
    }

    If you’re having the same issues, feel free to use this.

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘How to get the plugin working on IE11-’ is closed to new replies.