diff --git a/dist/mixpanel.amd.js b/dist/mixpanel.amd.js index dafe242c..1e8fbb64 100644 --- a/dist/mixpanel.amd.js +++ b/dist/mixpanel.amd.js @@ -1220,201 +1220,15 @@ define(function () { 'use strict'; })(); - var TOKEN_MATCH_REGEX = new RegExp('^(\\w*)\\[(\\w+)([=~\\|\\^\\$\\*]?)=?"?([^\\]"]*)"?\\]$'); - - _.dom_query = (function() { - /* document.getElementsBySelector(selector) - - returns an array of element objects from the current document - matching the CSS selector. Selectors can contain element names, - class names and ids and can be nested. For example: - - elements = document.getElementsBySelector('div#main p a.external') - - Will return an array of all 'a' elements with 'external' in their - class attribute that are contained inside 'p' elements that are - contained inside the 'div' element which has id="main" - - New in version 0.4: Support for CSS2 and CSS3 attribute selectors: - See http://www.w3.org/TR/css3-selectors/#attribute-selectors - - Version 0.4 - Simon Willison, March 25th 2003 - -- Works in Phoenix 0.5, Mozilla 1.3, Opera 7, Internet Explorer 6, Internet Explorer 5 on Windows - -- Opera 7 fails - - Version 0.5 - Carl Sverre, Jan 7th 2013 - -- Now uses jQuery-esque `hasClass` for testing class name - equality. This fixes a bug related to '-' characters being - considered not part of a 'word' in regex. - */ - - function getAllChildren(e) { - // Returns all children of element. Workaround required for IE5/Windows. Ugh. - return e.all ? e.all : e.getElementsByTagName('*'); - } - - var bad_whitespace = /[\t\r\n]/g; - - function hasClass(elem, selector) { - var className = ' ' + selector + ' '; - return ((' ' + elem.className + ' ').replace(bad_whitespace, ' ').indexOf(className) >= 0); - } - - function getElementsBySelector(selector) { - // Attempt to fail gracefully in lesser browsers - if (!document$1.getElementsByTagName) { - return []; - } - // Split selector in to tokens - var tokens = selector.split(' '); - var token, bits, tagName, found, foundCount, i, j, k, elements, currentContextIndex; - var currentContext = [document$1]; - for (i = 0; i < tokens.length; i++) { - token = tokens[i].replace(/^\s+/, '').replace(/\s+$/, ''); - if (token.indexOf('#') > -1) { - // Token is an ID selector - bits = token.split('#'); - tagName = bits[0]; - var id = bits[1]; - var element = document$1.getElementById(id); - if (!element || (tagName && element.nodeName.toLowerCase() != tagName)) { - // element not found or tag with that ID not found, return false - return []; - } - // Set currentContext to contain just this element - currentContext = [element]; - continue; // Skip to next token - } - if (token.indexOf('.') > -1) { - // Token contains a class selector - bits = token.split('.'); - tagName = bits[0]; - var className = bits[1]; - if (!tagName) { - tagName = '*'; - } - // Get elements matching tag, filter them for class selector - found = []; - foundCount = 0; - for (j = 0; j < currentContext.length; j++) { - if (tagName == '*') { - elements = getAllChildren(currentContext[j]); - } else { - elements = currentContext[j].getElementsByTagName(tagName); - } - for (k = 0; k < elements.length; k++) { - found[foundCount++] = elements[k]; - } - } - currentContext = []; - currentContextIndex = 0; - for (j = 0; j < found.length; j++) { - if (found[j].className && - _.isString(found[j].className) && // some SVG elements have classNames which are not strings - hasClass(found[j], className) - ) { - currentContext[currentContextIndex++] = found[j]; - } - } - continue; // Skip to next token - } - // Code to deal with attribute selectors - var token_match = token.match(TOKEN_MATCH_REGEX); - if (token_match) { - tagName = token_match[1]; - var attrName = token_match[2]; - var attrOperator = token_match[3]; - var attrValue = token_match[4]; - if (!tagName) { - tagName = '*'; - } - // Grab all of the tagName elements within current context - found = []; - foundCount = 0; - for (j = 0; j < currentContext.length; j++) { - if (tagName == '*') { - elements = getAllChildren(currentContext[j]); - } else { - elements = currentContext[j].getElementsByTagName(tagName); - } - for (k = 0; k < elements.length; k++) { - found[foundCount++] = elements[k]; - } - } - currentContext = []; - currentContextIndex = 0; - var checkFunction; // This function will be used to filter the elements - switch (attrOperator) { - case '=': // Equality - checkFunction = function(e) { - return (e.getAttribute(attrName) == attrValue); - }; - break; - case '~': // Match one of space seperated words - checkFunction = function(e) { - return (e.getAttribute(attrName).match(new RegExp('\\b' + attrValue + '\\b'))); - }; - break; - case '|': // Match start with value followed by optional hyphen - checkFunction = function(e) { - return (e.getAttribute(attrName).match(new RegExp('^' + attrValue + '-?'))); - }; - break; - case '^': // Match starts with value - checkFunction = function(e) { - return (e.getAttribute(attrName).indexOf(attrValue) === 0); - }; - break; - case '$': // Match ends with value - fails with "Warning" in Opera 7 - checkFunction = function(e) { - return (e.getAttribute(attrName).lastIndexOf(attrValue) == e.getAttribute(attrName).length - attrValue.length); - }; - break; - case '*': // Match ends with value - checkFunction = function(e) { - return (e.getAttribute(attrName).indexOf(attrValue) > -1); - }; - break; - default: - // Just test for existence of attribute - checkFunction = function(e) { - return e.getAttribute(attrName); - }; - } - currentContext = []; - currentContextIndex = 0; - for (j = 0; j < found.length; j++) { - if (checkFunction(found[j])) { - currentContext[currentContextIndex++] = found[j]; - } - } - // alert('Attribute Selector: '+tagName+' '+attrName+' '+attrOperator+' '+attrValue); - continue; // Skip to next token - } - // If we get here, token is JUST an element (not a class or ID selector) - tagName = token; - found = []; - foundCount = 0; - for (j = 0; j < currentContext.length; j++) { - elements = currentContext[j].getElementsByTagName(tagName); - for (k = 0; k < elements.length; k++) { - found[foundCount++] = elements[k]; - } - } - currentContext = found; - } - return currentContext; + _.dom_query = function(query) { + if (_.isElement(query)) { + return [query]; + } else if (typeof query === 'string') { + return Array.from(document$1.querySelectorAll(query)); + } else { + return query; } - - return function(query) { - if (_.isElement(query)) { - return [query]; - } else if (_.isObject(query) && !_.isUndefined(query.length)) { - return query; - } else { - return getElementsBySelector.call(this, query); - } - }; - })(); + }; var CAMPAIGN_KEYWORDS = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_content', 'utm_term']; var CLICK_IDS = ['dclid', 'fbclid', 'gclid', 'ko_click_id', 'li_fat_id', 'msclkid', 'ttclid', 'twclid', 'wbraid']; diff --git a/dist/mixpanel.cjs.js b/dist/mixpanel.cjs.js index a5c6bc67..77700917 100644 --- a/dist/mixpanel.cjs.js +++ b/dist/mixpanel.cjs.js @@ -1220,201 +1220,15 @@ _.register_event = (function() { })(); -var TOKEN_MATCH_REGEX = new RegExp('^(\\w*)\\[(\\w+)([=~\\|\\^\\$\\*]?)=?"?([^\\]"]*)"?\\]$'); - -_.dom_query = (function() { - /* document.getElementsBySelector(selector) - - returns an array of element objects from the current document - matching the CSS selector. Selectors can contain element names, - class names and ids and can be nested. For example: - - elements = document.getElementsBySelector('div#main p a.external') - - Will return an array of all 'a' elements with 'external' in their - class attribute that are contained inside 'p' elements that are - contained inside the 'div' element which has id="main" - - New in version 0.4: Support for CSS2 and CSS3 attribute selectors: - See http://www.w3.org/TR/css3-selectors/#attribute-selectors - - Version 0.4 - Simon Willison, March 25th 2003 - -- Works in Phoenix 0.5, Mozilla 1.3, Opera 7, Internet Explorer 6, Internet Explorer 5 on Windows - -- Opera 7 fails - - Version 0.5 - Carl Sverre, Jan 7th 2013 - -- Now uses jQuery-esque `hasClass` for testing class name - equality. This fixes a bug related to '-' characters being - considered not part of a 'word' in regex. - */ - - function getAllChildren(e) { - // Returns all children of element. Workaround required for IE5/Windows. Ugh. - return e.all ? e.all : e.getElementsByTagName('*'); - } - - var bad_whitespace = /[\t\r\n]/g; - - function hasClass(elem, selector) { - var className = ' ' + selector + ' '; - return ((' ' + elem.className + ' ').replace(bad_whitespace, ' ').indexOf(className) >= 0); - } - - function getElementsBySelector(selector) { - // Attempt to fail gracefully in lesser browsers - if (!document$1.getElementsByTagName) { - return []; - } - // Split selector in to tokens - var tokens = selector.split(' '); - var token, bits, tagName, found, foundCount, i, j, k, elements, currentContextIndex; - var currentContext = [document$1]; - for (i = 0; i < tokens.length; i++) { - token = tokens[i].replace(/^\s+/, '').replace(/\s+$/, ''); - if (token.indexOf('#') > -1) { - // Token is an ID selector - bits = token.split('#'); - tagName = bits[0]; - var id = bits[1]; - var element = document$1.getElementById(id); - if (!element || (tagName && element.nodeName.toLowerCase() != tagName)) { - // element not found or tag with that ID not found, return false - return []; - } - // Set currentContext to contain just this element - currentContext = [element]; - continue; // Skip to next token - } - if (token.indexOf('.') > -1) { - // Token contains a class selector - bits = token.split('.'); - tagName = bits[0]; - var className = bits[1]; - if (!tagName) { - tagName = '*'; - } - // Get elements matching tag, filter them for class selector - found = []; - foundCount = 0; - for (j = 0; j < currentContext.length; j++) { - if (tagName == '*') { - elements = getAllChildren(currentContext[j]); - } else { - elements = currentContext[j].getElementsByTagName(tagName); - } - for (k = 0; k < elements.length; k++) { - found[foundCount++] = elements[k]; - } - } - currentContext = []; - currentContextIndex = 0; - for (j = 0; j < found.length; j++) { - if (found[j].className && - _.isString(found[j].className) && // some SVG elements have classNames which are not strings - hasClass(found[j], className) - ) { - currentContext[currentContextIndex++] = found[j]; - } - } - continue; // Skip to next token - } - // Code to deal with attribute selectors - var token_match = token.match(TOKEN_MATCH_REGEX); - if (token_match) { - tagName = token_match[1]; - var attrName = token_match[2]; - var attrOperator = token_match[3]; - var attrValue = token_match[4]; - if (!tagName) { - tagName = '*'; - } - // Grab all of the tagName elements within current context - found = []; - foundCount = 0; - for (j = 0; j < currentContext.length; j++) { - if (tagName == '*') { - elements = getAllChildren(currentContext[j]); - } else { - elements = currentContext[j].getElementsByTagName(tagName); - } - for (k = 0; k < elements.length; k++) { - found[foundCount++] = elements[k]; - } - } - currentContext = []; - currentContextIndex = 0; - var checkFunction; // This function will be used to filter the elements - switch (attrOperator) { - case '=': // Equality - checkFunction = function(e) { - return (e.getAttribute(attrName) == attrValue); - }; - break; - case '~': // Match one of space seperated words - checkFunction = function(e) { - return (e.getAttribute(attrName).match(new RegExp('\\b' + attrValue + '\\b'))); - }; - break; - case '|': // Match start with value followed by optional hyphen - checkFunction = function(e) { - return (e.getAttribute(attrName).match(new RegExp('^' + attrValue + '-?'))); - }; - break; - case '^': // Match starts with value - checkFunction = function(e) { - return (e.getAttribute(attrName).indexOf(attrValue) === 0); - }; - break; - case '$': // Match ends with value - fails with "Warning" in Opera 7 - checkFunction = function(e) { - return (e.getAttribute(attrName).lastIndexOf(attrValue) == e.getAttribute(attrName).length - attrValue.length); - }; - break; - case '*': // Match ends with value - checkFunction = function(e) { - return (e.getAttribute(attrName).indexOf(attrValue) > -1); - }; - break; - default: - // Just test for existence of attribute - checkFunction = function(e) { - return e.getAttribute(attrName); - }; - } - currentContext = []; - currentContextIndex = 0; - for (j = 0; j < found.length; j++) { - if (checkFunction(found[j])) { - currentContext[currentContextIndex++] = found[j]; - } - } - // alert('Attribute Selector: '+tagName+' '+attrName+' '+attrOperator+' '+attrValue); - continue; // Skip to next token - } - // If we get here, token is JUST an element (not a class or ID selector) - tagName = token; - found = []; - foundCount = 0; - for (j = 0; j < currentContext.length; j++) { - elements = currentContext[j].getElementsByTagName(tagName); - for (k = 0; k < elements.length; k++) { - found[foundCount++] = elements[k]; - } - } - currentContext = found; - } - return currentContext; +_.dom_query = function(query) { + if (_.isElement(query)) { + return [query]; + } else if (typeof query === 'string') { + return Array.from(document$1.querySelectorAll(query)); + } else { + return query; } - - return function(query) { - if (_.isElement(query)) { - return [query]; - } else if (_.isObject(query) && !_.isUndefined(query.length)) { - return query; - } else { - return getElementsBySelector.call(this, query); - } - }; -})(); +}; var CAMPAIGN_KEYWORDS = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_content', 'utm_term']; var CLICK_IDS = ['dclid', 'fbclid', 'gclid', 'ko_click_id', 'li_fat_id', 'msclkid', 'ttclid', 'twclid', 'wbraid']; diff --git a/dist/mixpanel.globals.js b/dist/mixpanel.globals.js index ddb8877a..9884348d 100644 --- a/dist/mixpanel.globals.js +++ b/dist/mixpanel.globals.js @@ -1221,201 +1221,15 @@ })(); - var TOKEN_MATCH_REGEX = new RegExp('^(\\w*)\\[(\\w+)([=~\\|\\^\\$\\*]?)=?"?([^\\]"]*)"?\\]$'); - - _.dom_query = (function() { - /* document.getElementsBySelector(selector) - - returns an array of element objects from the current document - matching the CSS selector. Selectors can contain element names, - class names and ids and can be nested. For example: - - elements = document.getElementsBySelector('div#main p a.external') - - Will return an array of all 'a' elements with 'external' in their - class attribute that are contained inside 'p' elements that are - contained inside the 'div' element which has id="main" - - New in version 0.4: Support for CSS2 and CSS3 attribute selectors: - See http://www.w3.org/TR/css3-selectors/#attribute-selectors - - Version 0.4 - Simon Willison, March 25th 2003 - -- Works in Phoenix 0.5, Mozilla 1.3, Opera 7, Internet Explorer 6, Internet Explorer 5 on Windows - -- Opera 7 fails - - Version 0.5 - Carl Sverre, Jan 7th 2013 - -- Now uses jQuery-esque `hasClass` for testing class name - equality. This fixes a bug related to '-' characters being - considered not part of a 'word' in regex. - */ - - function getAllChildren(e) { - // Returns all children of element. Workaround required for IE5/Windows. Ugh. - return e.all ? e.all : e.getElementsByTagName('*'); - } - - var bad_whitespace = /[\t\r\n]/g; - - function hasClass(elem, selector) { - var className = ' ' + selector + ' '; - return ((' ' + elem.className + ' ').replace(bad_whitespace, ' ').indexOf(className) >= 0); - } - - function getElementsBySelector(selector) { - // Attempt to fail gracefully in lesser browsers - if (!document$1.getElementsByTagName) { - return []; - } - // Split selector in to tokens - var tokens = selector.split(' '); - var token, bits, tagName, found, foundCount, i, j, k, elements, currentContextIndex; - var currentContext = [document$1]; - for (i = 0; i < tokens.length; i++) { - token = tokens[i].replace(/^\s+/, '').replace(/\s+$/, ''); - if (token.indexOf('#') > -1) { - // Token is an ID selector - bits = token.split('#'); - tagName = bits[0]; - var id = bits[1]; - var element = document$1.getElementById(id); - if (!element || (tagName && element.nodeName.toLowerCase() != tagName)) { - // element not found or tag with that ID not found, return false - return []; - } - // Set currentContext to contain just this element - currentContext = [element]; - continue; // Skip to next token - } - if (token.indexOf('.') > -1) { - // Token contains a class selector - bits = token.split('.'); - tagName = bits[0]; - var className = bits[1]; - if (!tagName) { - tagName = '*'; - } - // Get elements matching tag, filter them for class selector - found = []; - foundCount = 0; - for (j = 0; j < currentContext.length; j++) { - if (tagName == '*') { - elements = getAllChildren(currentContext[j]); - } else { - elements = currentContext[j].getElementsByTagName(tagName); - } - for (k = 0; k < elements.length; k++) { - found[foundCount++] = elements[k]; - } - } - currentContext = []; - currentContextIndex = 0; - for (j = 0; j < found.length; j++) { - if (found[j].className && - _.isString(found[j].className) && // some SVG elements have classNames which are not strings - hasClass(found[j], className) - ) { - currentContext[currentContextIndex++] = found[j]; - } - } - continue; // Skip to next token - } - // Code to deal with attribute selectors - var token_match = token.match(TOKEN_MATCH_REGEX); - if (token_match) { - tagName = token_match[1]; - var attrName = token_match[2]; - var attrOperator = token_match[3]; - var attrValue = token_match[4]; - if (!tagName) { - tagName = '*'; - } - // Grab all of the tagName elements within current context - found = []; - foundCount = 0; - for (j = 0; j < currentContext.length; j++) { - if (tagName == '*') { - elements = getAllChildren(currentContext[j]); - } else { - elements = currentContext[j].getElementsByTagName(tagName); - } - for (k = 0; k < elements.length; k++) { - found[foundCount++] = elements[k]; - } - } - currentContext = []; - currentContextIndex = 0; - var checkFunction; // This function will be used to filter the elements - switch (attrOperator) { - case '=': // Equality - checkFunction = function(e) { - return (e.getAttribute(attrName) == attrValue); - }; - break; - case '~': // Match one of space seperated words - checkFunction = function(e) { - return (e.getAttribute(attrName).match(new RegExp('\\b' + attrValue + '\\b'))); - }; - break; - case '|': // Match start with value followed by optional hyphen - checkFunction = function(e) { - return (e.getAttribute(attrName).match(new RegExp('^' + attrValue + '-?'))); - }; - break; - case '^': // Match starts with value - checkFunction = function(e) { - return (e.getAttribute(attrName).indexOf(attrValue) === 0); - }; - break; - case '$': // Match ends with value - fails with "Warning" in Opera 7 - checkFunction = function(e) { - return (e.getAttribute(attrName).lastIndexOf(attrValue) == e.getAttribute(attrName).length - attrValue.length); - }; - break; - case '*': // Match ends with value - checkFunction = function(e) { - return (e.getAttribute(attrName).indexOf(attrValue) > -1); - }; - break; - default: - // Just test for existence of attribute - checkFunction = function(e) { - return e.getAttribute(attrName); - }; - } - currentContext = []; - currentContextIndex = 0; - for (j = 0; j < found.length; j++) { - if (checkFunction(found[j])) { - currentContext[currentContextIndex++] = found[j]; - } - } - // alert('Attribute Selector: '+tagName+' '+attrName+' '+attrOperator+' '+attrValue); - continue; // Skip to next token - } - // If we get here, token is JUST an element (not a class or ID selector) - tagName = token; - found = []; - foundCount = 0; - for (j = 0; j < currentContext.length; j++) { - elements = currentContext[j].getElementsByTagName(tagName); - for (k = 0; k < elements.length; k++) { - found[foundCount++] = elements[k]; - } - } - currentContext = found; - } - return currentContext; + _.dom_query = function(query) { + if (_.isElement(query)) { + return [query]; + } else if (typeof query === 'string') { + return Array.from(document$1.querySelectorAll(query)); + } else { + return query; } - - return function(query) { - if (_.isElement(query)) { - return [query]; - } else if (_.isObject(query) && !_.isUndefined(query.length)) { - return query; - } else { - return getElementsBySelector.call(this, query); - } - }; - })(); + }; var CAMPAIGN_KEYWORDS = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_content', 'utm_term']; var CLICK_IDS = ['dclid', 'fbclid', 'gclid', 'ko_click_id', 'li_fat_id', 'msclkid', 'ttclid', 'twclid', 'wbraid']; diff --git a/dist/mixpanel.min.js b/dist/mixpanel.min.js index 458b7853..43996ce0 100644 --- a/dist/mixpanel.min.js +++ b/dist/mixpanel.min.js @@ -1,106 +1,103 @@ (function() { -var l=void 0,m=!0,q=null,D=!1; -(function(){function Aa(){function a(){if(!a.sc)la=a.sc=m,ma=D,c.a(F,function(a){a.gc()})}function b(){try{u.documentElement.doScroll("left")}catch(d){setTimeout(b,1);return}a()}if(u.addEventListener)"complete"===u.readyState?a():u.addEventListener("DOMContentLoaded",a,D);else if(u.attachEvent){u.attachEvent("onreadystatechange",a);var d=D;try{d=x.frameElement===q}catch(f){}u.documentElement.doScroll&&d&&b()}c.Ib(x,"load",a,m)}function Ba(){y.init=function(a,b,d){if(d)return y[d]||(y[d]=F[d]=S(a, -b,d),y[d].ea()),y[d];d=y;if(F.mixpanel)d=F.mixpanel;else if(a)d=S(a,b,"mixpanel"),d.ea(),F.mixpanel=d;y=d;1===ca&&(x.mixpanel=y);Ca()}}function Ca(){c.a(F,function(a,b){"mixpanel"!==b&&(y[b]=a)});y._=c}function da(a){a=c.e(a)?a:c.g(a)?{}:{days:a};return c.extend({},Da,a)}function S(a,b,d){var f,h="mixpanel"===d?y:y[d];if(h&&0===ca)f=h;else{if(h&&!c.isArray(h)){p.error("You have already initialized "+d);return}f=new e}f.$a={};f.T(a,b,d);f.people=new j;f.people.T(f);if(!f.c("skip_first_touch_marketing")){var a= -c.info.ha(q),g={},s=D;c.a(a,function(a,b){(g["initial_"+b]=a)&&(s=m)});s&&f.people.Z(g)}J=J||f.c("debug");!c.g(h)&&c.isArray(h)&&(f.wa.call(f.people,h.people),f.wa(h));return f}function e(){}function P(){}function Ea(a){return a}function n(a){this.props={};this.qd=D;this.name=a.persistence_name?"mp_"+a.persistence_name:"mp_"+a.token+"_mixpanel";var b=a.persistence;if("cookie"!==b&&"localStorage"!==b)p.H("Unknown persistence type "+b+"; falling back to cookie"),b=a.persistence="cookie";this.i="localStorage"=== -b&&c.localStorage.oa()?c.localStorage:c.cookie;this.load();this.bc(a);this.md(a);this.save()}function j(){}function t(){}function C(a,b){this.I=b.I;this.W=new G(a,{I:c.bind(this.h,this),i:b.i});this.A=b.A;this.Qc=b.Rc;this.fa=b.fa;this.$c=b.ad;this.C=this.A.batch_size;this.la=this.A.batch_flush_interval_ms;this.qa=!this.A.batch_autostart;this.Ga=0;this.F={}}function na(a,b){var d=[];c.a(a,function(a){var c=a.id;if(c in b){if(c=b[c],c!==q)a.payload=c,d.push(a)}else d.push(a)});return d}function oa(a, -b){var d=[];c.a(a,function(a){a.id&&!b[a.id]&&d.push(a)});return d}function G(a,b){b=b||{};this.K=a;this.i=b.i||window.localStorage;this.h=b.I||c.bind(pa.error,pa);this.Ra=new qa(a,{i:this.i});this.pa=b.pa||q;this.G=[]}function qa(a,b){b=b||{};this.K=a;this.i=b.i||window.localStorage;this.Gb=b.Gb||100;this.Vb=b.Vb||2E3}function T(){this.Db="submit"}function L(){this.Db="click"}function E(){}function ra(a){var b=Fa,d=a.split("."),d=d[d.length-1];if(4a?"0"+a:a}return a.getUTCFullYear()+"-"+b(a.getUTCMonth()+1)+"-"+b(a.getUTCDate())+"T"+b(a.getUTCHours())+":"+b(a.getUTCMinutes())+":"+b(a.getUTCSeconds())};c.ra=function(a){var b={};c.a(a,function(a,f){c.Qa(a)&&0=i;)h()}function d(){var a,b,d="",c;if('"'=== -i)for(;h();){if('"'===i)return h(),d;if("\\"===i)if(h(),"u"===i){for(b=c=0;4>b;b+=1){a=parseInt(h(),16);if(!isFinite(a))break;c=16*c+a}d+=String.fromCharCode(c)}else if("string"===typeof e[i])d+=e[i];else break;else d+=i}g("Bad string")}function c(){var a;a="";"-"===i&&(a="-",h("-"));for(;"0"<=i&&"9">=i;)a+=i,h();if("."===i)for(a+=".";h()&&"0"<=i&&"9">=i;)a+=i;if("e"===i||"E"===i){a+=i;h();if("-"===i||"+"===i)a+=i,h();for(;"0"<=i&&"9">=i;)a+=i,h()}a=+a;if(isFinite(a))return a;g("Bad number")}function h(a){a&& -a!==i&&g("Expected '"+a+"' instead of '"+i+"'");i=r.charAt(s);s+=1;return i}function g(a){a=new SyntaxError(a);a.pd=s;a.text=r;throw a;}var s,i,e={'"':'"',"\\":"\\","/":"/",b:"\u0008",f:"\u000c",n:"\n",r:"\r",t:"\t"},r,o;o=function(){b();switch(i){case "{":var e;a:{var s,k={};if("{"===i){h("{");b();if("}"===i){h("}");e=k;break a}for(;i;){s=d();b();h(":");Object.hasOwnProperty.call(k,s)&&g('Duplicate key "'+s+'"');k[s]=o();b();if("}"===i){h("}");e=k;break a}h(",");b()}}g("Bad object")}return e;case "[":a:{e= -[];if("["===i){h("[");b();if("]"===i){h("]");s=e;break a}for(;i;){e.push(o());b();if("]"===i){h("]");s=e;break a}h(",");b()}}g("Bad array")}return s;case '"':return d();case "-":return c();default:return"0"<=i&&"9">=i?c():a()}};return function(a){r=a;s=0;i=" ";a=o();b();i&&g("Syntax error");return a}}();c.nc=function(a){var b,d,f,h,g=0,e=0,i="",i=[];if(!a)return a;a=c.nd(a);do b=a.charCodeAt(g++),d=a.charCodeAt(g++),f=a.charCodeAt(g++),h=b<<16|d<<8|f,b=h>>18&63,d=h>>12&63,f=h>>6&63,h&=63,i[e++]="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".charAt(b)+ -"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".charAt(d)+"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".charAt(f)+"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".charAt(h);while(ge?c++:i=127e?String.fromCharCode(e>>6|192,e&63|128):String.fromCharCode(e>>12|224,e>>6&63|128,e&63|128);i!==q&&(c>d&&(b+=a.substring(d,c)),b+=i,d=c=g+1)}c>d&&(b+=a.substring(d,a.length));return b};c.Za=function(){function a(){function a(b,d){var c,f=0;for(c=0;cv?(Qa.error("Timeout waiting for mutex on "+o+"; clearing lock. ["+k+"]"),j.removeItem(u),j.removeItem(p),h()):setTimeout(function(){try{a()}catch(c){b&&b(c)}},w*(Math.random()+0.1))}!c&&"function"!==typeof b&&(c=b,b=q);var k=c||(new Date).getTime()+"|"+Math.random(),r=(new Date).getTime(),o=this.K,w= -this.Gb,v=this.Vb,j=this.i,n=o+":X",p=o+":Y",u=o+":Z";try{if(U(j,m))h();else throw Error("localStorage support check failed");}catch(t){b&&b(t)}};var pa=ga("batch");G.prototype.Ja=function(a,b,d){var f={id:ea(),flushAfter:(new Date).getTime()+2*b,payload:a};this.Ra.Ya(c.bind(function(){var b;try{var c=this.X();c.push(f);(b=this.Ua(c))&&this.G.push(f)}catch(e){this.h("Error enqueueing item",a),b=D}d&&d(b)},this),c.bind(function(a){this.h("Error acquiring storage lock",a);d&&d(D)},this),this.pa)};G.prototype.tc= -function(a){var b=this.G.slice(0,a);if(b.lengthg.flushAfter&&!f[g.id]&&(g.Hc=m,b.push(g),b.length>=a))break}}}return b};G.prototype.Kc=function(a,b){var d={};c.a(a,function(a){d[a]=m});this.G=oa(this.G,d);var f=c.bind(function(){var b;try{var c=this.X(),c=oa(c,d);if(b=this.Ua(c))for(var c=this.X(),f=0;fe.length)this.Y();else{this.Kb=m;var i=c.bind(function(e){this.Kb= -D;try{var g=D;if(a.$b)this.W.ld(s);else if(c.e(e)&&"timeout"===e.error&&(new Date).getTime()-d>=b)this.h("Network timeout; retrying"),this.flush();else if(c.e(e)&&e.N&&(500<=e.N.status||429===e.N.status||"timeout"===e.error)){var i=2*this.la,k=e.N.responseHeaders;if(k){var j=k["Retry-After"];j&&(i=1E3*parseInt(j,10)||i)}i=Math.min(6E5,i);this.h("Error; retry in "+i+" ms");this.Mb(i)}else if(c.e(e)&&e.N&&413===e.N.status)if(1=v.timeout?"timeout":"Bad HTTP status: "+v.status+" "+v.statusText,n.l(a),e&&(k?e({status:0,error:a,N:v}):e(0))};v.send(j)}catch(y){n.l(y),h=D}else j=u.createElement("script"),j.type="text/javascript",j.async=m,j.defer=m,j.src=a,t=u.getElementsByTagName("script")[0],t.parentNode.insertBefore(j,t);return h};e.prototype.wa=function(a){function b(a,b){c.a(a,function(a){if(c.isArray(a[0])){var d=b;c.a(a,function(a){d=d[a[0]].apply(d,a.slice(1))})}else this[a[0]].apply(this,a.slice(1))}, -b)}var d,e=[],h=[],g=[];c.a(a,function(a){a&&(d=a[0],c.isArray(d)?g.push(a):"function"===typeof a?a.call(this):c.isArray(a)&&"alias"===d?e.push(a):c.isArray(a)&&-1!==d.indexOf("track")&&"function"===typeof this[d]?g.push(a):h.push(a))},this);b(e,this);b(h,this);b(g,this)};e.prototype.hb=function(){return!!this.p.ka};e.prototype.Ac=function(){var a=this.c("token");if(!this.hb()){var b=c.bind(function(b){return new C("__mpq_"+a+b.Ta,{A:this.config,Rc:c.bind(function(a,c,e){this.k(this.c("api_host")+ -b.D,this.ab(a),c,this.cb(e,a))},this),fa:c.bind(function(a){return this.fb("before_send_"+b.type,a)},this),I:this.c("error_reporter"),ad:c.bind(this.Ub,this)})},this);this.p={ka:b({type:"events",D:"/track/",Ta:"_ev"}),Ic:b({type:"people",D:"/engage/",Ta:"_pp"}),yc:b({type:"groups",D:"/groups/",Ta:"_gr"})}}this.c("batch_autostart")&&this.Tb()};e.prototype.Tb=function(){if(this.hb())this.P=m,c.a(this.p,function(a){a.start()})};e.prototype.Ub=function(){this.P=D;c.a(this.p,function(a){a.stop();a.clear()})}; -e.prototype.push=function(a){this.wa([a])};e.prototype.disable=function(a){"undefined"===typeof a?this.Q.qc=m:this.ta=this.ta.concat(a)};e.prototype.ab=function(a){a=c.ba(a);"base64"===this.c("api_payload_format")&&(a=c.nc(a));return{data:a}};e.prototype.Ca=function(a,b){var d=c.truncate(a.data,255),e=a.D,h=a.Ea,g=a.Zc,j=a.Sc||{},b=b||P,i=m,k=c.bind(function(){j.Sb||(d=this.fb("before_send_"+a.type,d));return d?(p.log("MIXPANEL REQUEST:"),p.log(d),this.k(e,this.ab(d),j,this.cb(b,d))):q},this);this.P&& -!g?h.Ja(d,function(a){a?b(1,d):k()}):i=k();return i&&d};e.prototype.o=M(function(a,b,d,e){!e&&"function"===typeof d&&(e=d,d=q);var d=d||{},h=d.transport;if(h)d.Wa=h;h=d.send_immediately;"function"!==typeof e&&(e=P);if(c.g(a))this.l("No event name provided to mixpanel.track");else if(this.bb(a))e(0);else{b=b||{};b.token=this.c("token");var g=this.persistence.Lc(a);c.g(g)||(b.$duration=parseFloat((((new Date).getTime()-g)/1E3).toFixed(3)));this.gb();g=this.c("track_marketing")?c.info.Ec():{};b=c.extend({}, -c.info.V(),g,this.persistence.V(),this.M,b);g=this.c("property_blacklist");c.isArray(g)?c.a(g,function(a){delete b[a]}):this.l("Invalid value for property_blacklist config: "+g);return this.Ca({type:"events",data:{event:a,properties:b},D:this.c("api_host")+"/track/",Ea:this.p.ka,Zc:h,Sc:d},e)}});e.prototype.Xc=M(function(a,b,d){c.isArray(b)||(b=[b]);var e={};e[a]=b;this.m(e);return this.people.set(a,b,d)});e.prototype.kc=M(function(a,b,c){var e=this.s(a);if(e===l){var h={};h[a]=[b];this.m(h)}else-1=== -e.indexOf(b)&&(e.push(b),this.m(h));return this.people.$(a,b,c)});e.prototype.Mc=M(function(a,b,c){var e=this.s(a);if(e!==l){var h=e.indexOf(b);-1(y.__SV||0)?p.H("Version mismatch; please ensure you're using the latest version of the Mixpanel code snippet."):(c.a(y._i,function(a){a&&c.isArray(a)&&(F[a[a.length-1]]=S.apply(this,a))}),Ba(),y.init(),c.a(F,function(a){a.ea()}),Aa())})()})(); +var k=void 0,l=!0,r=null,B=!1; +(function(){function ya(){function a(){if(!a.sc)ja=a.sc=l,ka=B,c.a(D,function(a){a.gc()})}function b(){try{s.documentElement.doScroll("left")}catch(d){setTimeout(b,1);return}a()}if(s.addEventListener)"complete"===s.readyState?a():s.addEventListener("DOMContentLoaded",a,B);else if(s.attachEvent){s.attachEvent("onreadystatechange",a);var d=B;try{d=t.frameElement===r}catch(f){}s.documentElement.doScroll&&d&&b()}c.Ib(t,"load",a,l)}function za(){w.init=function(a,b,d){if(d)return w[d]||(w[d]=D[d]=Q(a, +b,d),w[d].ea()),w[d];d=w;if(D.mixpanel)d=D.mixpanel;else if(a)d=Q(a,b,"mixpanel"),d.ea(),D.mixpanel=d;w=d;1===aa&&(t.mixpanel=w);Aa()}}function Aa(){c.a(D,function(a,b){"mixpanel"!==b&&(w[b]=a)});w._=c}function ba(a){a=c.e(a)?a:c.g(a)?{}:{days:a};return c.extend({},Ba,a)}function Q(a,b,d){var f,g="mixpanel"===d?w:w[d];if(g&&0===aa)f=g;else{if(g&&!c.isArray(g)){q.error("You have already initialized "+d);return}f=new e}f.Za={};f.T(a,b,d);f.people=new n;f.people.T(f);if(!f.c("skip_first_touch_marketing")){var a= +c.info.ha(r),i={},o=B;c.a(a,function(a,b){(i["initial_"+b]=a)&&(o=l)});o&&f.people.Z(i)}H=H||f.c("debug");!c.g(g)&&c.isArray(g)&&(f.wa.call(f.people,g.people),f.wa(g));return f}function e(){}function N(){}function Ca(a){return a}function j(a){this.props={};this.qd=B;this.name=a.persistence_name?"mp_"+a.persistence_name:"mp_"+a.token+"_mixpanel";var b=a.persistence;if("cookie"!==b&&"localStorage"!==b)q.H("Unknown persistence type "+b+"; falling back to cookie"),b=a.persistence="cookie";this.i="localStorage"=== +b&&c.localStorage.oa()?c.localStorage:c.cookie;this.load();this.bc(a);this.md(a);this.save()}function n(){}function p(){}function A(a,b){this.I=b.I;this.W=new E(a,{I:c.bind(this.h,this),i:b.i});this.A=b.A;this.Qc=b.Rc;this.fa=b.fa;this.$c=b.ad;this.C=this.A.batch_size;this.la=this.A.batch_flush_interval_ms;this.qa=!this.A.batch_autostart;this.Ga=0;this.F={}}function la(a,b){var d=[];c.a(a,function(a){var c=a.id;if(c in b){if(c=b[c],c!==r)a.payload=c,d.push(a)}else d.push(a)});return d}function ma(a, +b){var d=[];c.a(a,function(a){a.id&&!b[a.id]&&d.push(a)});return d}function E(a,b){b=b||{};this.K=a;this.i=b.i||window.localStorage;this.h=b.I||c.bind(na.error,na);this.Qa=new oa(a,{i:this.i});this.pa=b.pa||r;this.G=[]}function oa(a,b){b=b||{};this.K=a;this.i=b.i||window.localStorage;this.Gb=b.Gb||100;this.Vb=b.Vb||2E3}function R(){this.Db="submit"}function J(){this.Db="click"}function C(){}function pa(a){var b=Da,d=a.split("."),d=d[d.length-1];if(4a?"0"+a:a}return a.getUTCFullYear()+"-"+b(a.getUTCMonth()+1)+"-"+b(a.getUTCDate())+"T"+b(a.getUTCHours())+":"+b(a.getUTCMinutes())+":"+b(a.getUTCSeconds())};c.ra=function(a){var b={};c.a(a,function(a,f){c.yb(a)&&0=h;)g()}function d(){var a,b,d="",c;if('"'=== +h)for(;g();){if('"'===h)return g(),d;if("\\"===h)if(g(),"u"===h){for(b=c=0;4>b;b+=1){a=parseInt(g(),16);if(!isFinite(a))break;c=16*c+a}d+=String.fromCharCode(c)}else if("string"===typeof m[h])d+=m[h];else break;else d+=h}i("Bad string")}function c(){var a;a="";"-"===h&&(a="-",g("-"));for(;"0"<=h&&"9">=h;)a+=h,g();if("."===h)for(a+=".";g()&&"0"<=h&&"9">=h;)a+=h;if("e"===h||"E"===h){a+=h;g();if("-"===h||"+"===h)a+=h,g();for(;"0"<=h&&"9">=h;)a+=h,g()}a=+a;if(isFinite(a))return a;i("Bad number")}function g(a){a&& +a!==h&&i("Expected '"+a+"' instead of '"+h+"'");h=u.charAt(e);e+=1;return h}function i(a){a=new SyntaxError(a);a.pd=e;a.text=u;throw a;}var e,h,m={'"':'"',"\\":"\\","/":"/",b:"\u0008",f:"\u000c",n:"\n",r:"\r",t:"\t"},u,v;v=function(){b();switch(h){case "{":var e;a:{var o,m={};if("{"===h){g("{");b();if("}"===h){g("}");e=m;break a}for(;h;){o=d();b();g(":");Object.hasOwnProperty.call(m,o)&&i('Duplicate key "'+o+'"');m[o]=v();b();if("}"===h){g("}");e=m;break a}g(",");b()}}i("Bad object")}return e;case "[":a:{e= +[];if("["===h){g("[");b();if("]"===h){g("]");o=e;break a}for(;h;){e.push(v());b();if("]"===h){g("]");o=e;break a}g(",");b()}}i("Bad array")}return o;case '"':return d();case "-":return c();default:return"0"<=h&&"9">=h?c():a()}};return function(a){u=a;e=0;h=" ";a=v();b();h&&i("Syntax error");return a}}();c.nc=function(a){var b,d,f,g,i=0,e=0,h="",h=[];if(!a)return a;a=c.nd(a);do b=a.charCodeAt(i++),d=a.charCodeAt(i++),f=a.charCodeAt(i++),g=b<<16|d<<8|f,b=g>>18&63,d=g>>12&63,f=g>>6&63,g&=63,h[e++]="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".charAt(b)+ +"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".charAt(d)+"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".charAt(f)+"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".charAt(g);while(ie?c++:h=127e?String.fromCharCode(e>>6|192,e&63|128):String.fromCharCode(e>>12|224,e>>6&63|128,e&63|128);h!==r&&(c>d&&(b+=a.substring(d,c)),b+=h,d=c=i+1)}c>d&&(b+=a.substring(d,a.length));return b};c.Ya=function(){function a(){function a(b,d){var c,f=0;for(c=0;cLa?(Oa.error("Timeout waiting for mutex on "+v+"; clearing lock. ["+m+"]"),j.removeItem(p),j.removeItem(s),g()):setTimeout(function(){try{a()}catch(c){b&&b(c)}},n*(Math.random()+0.1))}!c&&"function"!==typeof b&&(c=b,b=r);var m=c||(new Date).getTime()+"|"+Math.random(),u=(new Date).getTime(),v=this.K,n=this.Gb,La=this.Vb,j=this.i,q=v+":X",s=v+":Y",p=v+":Z";try{if(S(j,l))g();else throw Error("localStorage support check failed");}catch(t){b&& +b(t)}};var na=ea("batch");E.prototype.Ja=function(a,b,d){var f={id:ca(),flushAfter:(new Date).getTime()+2*b,payload:a};this.Qa.Xa(c.bind(function(){var b;try{var c=this.X();c.push(f);(b=this.Ta(c))&&this.G.push(f)}catch(e){this.h("Error enqueueing item",a),b=B}d&&d(b)},this),c.bind(function(a){this.h("Error acquiring storage lock",a);d&&d(B)},this),this.pa)};E.prototype.tc=function(a){var b=this.G.slice(0,a);if(b.lengthe.flushAfter&&!f[e.id]&&(e.Hc=l,b.push(e),b.length>=a))break}}}return b};E.prototype.Kc=function(a,b){var d={};c.a(a,function(a){d[a]=l});this.G=ma(this.G,d);var f=c.bind(function(){var b;try{var c=this.X(),c=ma(c,d);if(b=this.Ta(c))for(var c=this.X(),f=0;fi.length)this.Y();else{this.Kb=l;var h=c.bind(function(i){this.Kb=B;try{var h=B;if(a.$b)this.W.ld(o);else if(c.e(i)&&"timeout"===i.error&&(new Date).getTime()- +d>=b)this.h("Network timeout; retrying"),this.flush();else if(c.e(i)&&i.N&&(500<=i.N.status||429===i.N.status||"timeout"===i.error)){var m=2*this.la,j=i.N.responseHeaders;if(j){var n=j["Retry-After"];n&&(m=1E3*parseInt(n,10)||m)}m=Math.min(6E5,m);this.h("Error; retry in "+m+" ms");this.Mb(m)}else if(c.e(i)&&i.N&&413===i.N.status)if(1=p.timeout?"timeout":"Bad HTTP status: "+p.status+" "+p.statusText,j.l(a),e&&(m?e({status:0,error:a,N:p}):e(0))};p.send(o)}catch(x){j.l(x), +g=B}else o=s.createElement("script"),o.type="text/javascript",o.async=l,o.defer=l,o.src=a,t=s.getElementsByTagName("script")[0],t.parentNode.insertBefore(o,t);return g};e.prototype.wa=function(a){function b(a,b){c.a(a,function(a){if(c.isArray(a[0])){var d=b;c.a(a,function(a){d=d[a[0]].apply(d,a.slice(1))})}else this[a[0]].apply(this,a.slice(1))},b)}var d,e=[],g=[],i=[];c.a(a,function(a){a&&(d=a[0],c.isArray(d)?i.push(a):"function"===typeof a?a.call(this):c.isArray(a)&&"alias"===d?e.push(a):c.isArray(a)&& +-1!==d.indexOf("track")&&"function"===typeof this[d]?i.push(a):g.push(a))},this);b(e,this);b(g,this);b(i,this)};e.prototype.gb=function(){return!!this.p.ka};e.prototype.Ac=function(){var a=this.c("token");if(!this.gb()){var b=c.bind(function(b){return new A("__mpq_"+a+b.Sa,{A:this.config,Rc:c.bind(function(a,c,e){this.k(this.c("api_host")+b.D,this.$a(a),c,this.bb(e,a))},this),fa:c.bind(function(a){return this.eb("before_send_"+b.type,a)},this),I:this.c("error_reporter"),ad:c.bind(this.Ub,this)})}, +this);this.p={ka:b({type:"events",D:"/track/",Sa:"_ev"}),Ic:b({type:"people",D:"/engage/",Sa:"_pp"}),yc:b({type:"groups",D:"/groups/",Sa:"_gr"})}}this.c("batch_autostart")&&this.Tb()};e.prototype.Tb=function(){if(this.gb())this.P=l,c.a(this.p,function(a){a.start()})};e.prototype.Ub=function(){this.P=B;c.a(this.p,function(a){a.stop();a.clear()})};e.prototype.push=function(a){this.wa([a])};e.prototype.disable=function(a){"undefined"===typeof a?this.Q.qc=l:this.ta=this.ta.concat(a)};e.prototype.$a=function(a){a= +c.ba(a);"base64"===this.c("api_payload_format")&&(a=c.nc(a));return{data:a}};e.prototype.Ca=function(a,b){var d=c.truncate(a.data,255),e=a.D,g=a.Ea,i=a.Zc,j=a.Sc||{},b=b||N,h=l,m=c.bind(function(){j.Sb||(d=this.eb("before_send_"+a.type,d));return d?(q.log("MIXPANEL REQUEST:"),q.log(d),this.k(e,this.$a(d),j,this.bb(b,d))):r},this);this.P&&!i?g.Ja(d,function(a){a?b(1,d):m()}):h=m();return h&&d};e.prototype.o=K(function(a,b,d,e){!e&&"function"===typeof d&&(e=d,d=r);var d=d||{},g=d.transport;if(g)d.Va= +g;g=d.send_immediately;"function"!==typeof e&&(e=N);if(c.g(a))this.l("No event name provided to mixpanel.track");else if(this.ab(a))e(0);else{b=b||{};b.token=this.c("token");var i=this.persistence.Lc(a);c.g(i)||(b.$duration=parseFloat((((new Date).getTime()-i)/1E3).toFixed(3)));this.fb();i=this.c("track_marketing")?c.info.Ec():{};b=c.extend({},c.info.V(),i,this.persistence.V(),this.M,b);i=this.c("property_blacklist");c.isArray(i)?c.a(i,function(a){delete b[a]}):this.l("Invalid value for property_blacklist config: "+ +i);return this.Ca({type:"events",data:{event:a,properties:b},D:this.c("api_host")+"/track/",Ea:this.p.ka,Zc:g,Sc:d},e)}});e.prototype.Xc=K(function(a,b,d){c.isArray(b)||(b=[b]);var e={};e[a]=b;this.m(e);return this.people.set(a,b,d)});e.prototype.kc=K(function(a,b,c){var e=this.s(a);if(e===k){var g={};g[a]=[b];this.m(g)}else-1===e.indexOf(b)&&(e.push(b),this.m(g));return this.people.$(a,b,c)});e.prototype.Mc=K(function(a,b,c){var e=this.s(a);if(e!==k){var g=e.indexOf(b);-1(w.__SV||0)? +q.H("Version mismatch; please ensure you're using the latest version of the Mixpanel code snippet."):(c.a(w._i,function(a){a&&c.isArray(a)&&(D[a[a.length-1]]=Q.apply(this,a))}),za(),w.init(),c.a(D,function(a){a.ea()}),ya())})()})(); })(); diff --git a/dist/mixpanel.umd.js b/dist/mixpanel.umd.js index 4a4c8f62..fbc28058 100644 --- a/dist/mixpanel.umd.js +++ b/dist/mixpanel.umd.js @@ -1224,201 +1224,15 @@ })(); - var TOKEN_MATCH_REGEX = new RegExp('^(\\w*)\\[(\\w+)([=~\\|\\^\\$\\*]?)=?"?([^\\]"]*)"?\\]$'); - - _.dom_query = (function() { - /* document.getElementsBySelector(selector) - - returns an array of element objects from the current document - matching the CSS selector. Selectors can contain element names, - class names and ids and can be nested. For example: - - elements = document.getElementsBySelector('div#main p a.external') - - Will return an array of all 'a' elements with 'external' in their - class attribute that are contained inside 'p' elements that are - contained inside the 'div' element which has id="main" - - New in version 0.4: Support for CSS2 and CSS3 attribute selectors: - See http://www.w3.org/TR/css3-selectors/#attribute-selectors - - Version 0.4 - Simon Willison, March 25th 2003 - -- Works in Phoenix 0.5, Mozilla 1.3, Opera 7, Internet Explorer 6, Internet Explorer 5 on Windows - -- Opera 7 fails - - Version 0.5 - Carl Sverre, Jan 7th 2013 - -- Now uses jQuery-esque `hasClass` for testing class name - equality. This fixes a bug related to '-' characters being - considered not part of a 'word' in regex. - */ - - function getAllChildren(e) { - // Returns all children of element. Workaround required for IE5/Windows. Ugh. - return e.all ? e.all : e.getElementsByTagName('*'); - } - - var bad_whitespace = /[\t\r\n]/g; - - function hasClass(elem, selector) { - var className = ' ' + selector + ' '; - return ((' ' + elem.className + ' ').replace(bad_whitespace, ' ').indexOf(className) >= 0); - } - - function getElementsBySelector(selector) { - // Attempt to fail gracefully in lesser browsers - if (!document$1.getElementsByTagName) { - return []; - } - // Split selector in to tokens - var tokens = selector.split(' '); - var token, bits, tagName, found, foundCount, i, j, k, elements, currentContextIndex; - var currentContext = [document$1]; - for (i = 0; i < tokens.length; i++) { - token = tokens[i].replace(/^\s+/, '').replace(/\s+$/, ''); - if (token.indexOf('#') > -1) { - // Token is an ID selector - bits = token.split('#'); - tagName = bits[0]; - var id = bits[1]; - var element = document$1.getElementById(id); - if (!element || (tagName && element.nodeName.toLowerCase() != tagName)) { - // element not found or tag with that ID not found, return false - return []; - } - // Set currentContext to contain just this element - currentContext = [element]; - continue; // Skip to next token - } - if (token.indexOf('.') > -1) { - // Token contains a class selector - bits = token.split('.'); - tagName = bits[0]; - var className = bits[1]; - if (!tagName) { - tagName = '*'; - } - // Get elements matching tag, filter them for class selector - found = []; - foundCount = 0; - for (j = 0; j < currentContext.length; j++) { - if (tagName == '*') { - elements = getAllChildren(currentContext[j]); - } else { - elements = currentContext[j].getElementsByTagName(tagName); - } - for (k = 0; k < elements.length; k++) { - found[foundCount++] = elements[k]; - } - } - currentContext = []; - currentContextIndex = 0; - for (j = 0; j < found.length; j++) { - if (found[j].className && - _.isString(found[j].className) && // some SVG elements have classNames which are not strings - hasClass(found[j], className) - ) { - currentContext[currentContextIndex++] = found[j]; - } - } - continue; // Skip to next token - } - // Code to deal with attribute selectors - var token_match = token.match(TOKEN_MATCH_REGEX); - if (token_match) { - tagName = token_match[1]; - var attrName = token_match[2]; - var attrOperator = token_match[3]; - var attrValue = token_match[4]; - if (!tagName) { - tagName = '*'; - } - // Grab all of the tagName elements within current context - found = []; - foundCount = 0; - for (j = 0; j < currentContext.length; j++) { - if (tagName == '*') { - elements = getAllChildren(currentContext[j]); - } else { - elements = currentContext[j].getElementsByTagName(tagName); - } - for (k = 0; k < elements.length; k++) { - found[foundCount++] = elements[k]; - } - } - currentContext = []; - currentContextIndex = 0; - var checkFunction; // This function will be used to filter the elements - switch (attrOperator) { - case '=': // Equality - checkFunction = function(e) { - return (e.getAttribute(attrName) == attrValue); - }; - break; - case '~': // Match one of space seperated words - checkFunction = function(e) { - return (e.getAttribute(attrName).match(new RegExp('\\b' + attrValue + '\\b'))); - }; - break; - case '|': // Match start with value followed by optional hyphen - checkFunction = function(e) { - return (e.getAttribute(attrName).match(new RegExp('^' + attrValue + '-?'))); - }; - break; - case '^': // Match starts with value - checkFunction = function(e) { - return (e.getAttribute(attrName).indexOf(attrValue) === 0); - }; - break; - case '$': // Match ends with value - fails with "Warning" in Opera 7 - checkFunction = function(e) { - return (e.getAttribute(attrName).lastIndexOf(attrValue) == e.getAttribute(attrName).length - attrValue.length); - }; - break; - case '*': // Match ends with value - checkFunction = function(e) { - return (e.getAttribute(attrName).indexOf(attrValue) > -1); - }; - break; - default: - // Just test for existence of attribute - checkFunction = function(e) { - return e.getAttribute(attrName); - }; - } - currentContext = []; - currentContextIndex = 0; - for (j = 0; j < found.length; j++) { - if (checkFunction(found[j])) { - currentContext[currentContextIndex++] = found[j]; - } - } - // alert('Attribute Selector: '+tagName+' '+attrName+' '+attrOperator+' '+attrValue); - continue; // Skip to next token - } - // If we get here, token is JUST an element (not a class or ID selector) - tagName = token; - found = []; - foundCount = 0; - for (j = 0; j < currentContext.length; j++) { - elements = currentContext[j].getElementsByTagName(tagName); - for (k = 0; k < elements.length; k++) { - found[foundCount++] = elements[k]; - } - } - currentContext = found; - } - return currentContext; + _.dom_query = function(query) { + if (_.isElement(query)) { + return [query]; + } else if (typeof query === 'string') { + return Array.from(document$1.querySelectorAll(query)); + } else { + return query; } - - return function(query) { - if (_.isElement(query)) { - return [query]; - } else if (_.isObject(query) && !_.isUndefined(query.length)) { - return query; - } else { - return getElementsBySelector.call(this, query); - } - }; - })(); + }; var CAMPAIGN_KEYWORDS = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_content', 'utm_term']; var CLICK_IDS = ['dclid', 'fbclid', 'gclid', 'ko_click_id', 'li_fat_id', 'msclkid', 'ttclid', 'twclid', 'wbraid']; diff --git a/examples/commonjs-browserify/bundle.js b/examples/commonjs-browserify/bundle.js index 6f7e2c78..edc85e26 100644 --- a/examples/commonjs-browserify/bundle.js +++ b/examples/commonjs-browserify/bundle.js @@ -1221,201 +1221,15 @@ _.register_event = (function() { })(); -var TOKEN_MATCH_REGEX = new RegExp('^(\\w*)\\[(\\w+)([=~\\|\\^\\$\\*]?)=?"?([^\\]"]*)"?\\]$'); - -_.dom_query = (function() { - /* document.getElementsBySelector(selector) - - returns an array of element objects from the current document - matching the CSS selector. Selectors can contain element names, - class names and ids and can be nested. For example: - - elements = document.getElementsBySelector('div#main p a.external') - - Will return an array of all 'a' elements with 'external' in their - class attribute that are contained inside 'p' elements that are - contained inside the 'div' element which has id="main" - - New in version 0.4: Support for CSS2 and CSS3 attribute selectors: - See http://www.w3.org/TR/css3-selectors/#attribute-selectors - - Version 0.4 - Simon Willison, March 25th 2003 - -- Works in Phoenix 0.5, Mozilla 1.3, Opera 7, Internet Explorer 6, Internet Explorer 5 on Windows - -- Opera 7 fails - - Version 0.5 - Carl Sverre, Jan 7th 2013 - -- Now uses jQuery-esque `hasClass` for testing class name - equality. This fixes a bug related to '-' characters being - considered not part of a 'word' in regex. - */ - - function getAllChildren(e) { - // Returns all children of element. Workaround required for IE5/Windows. Ugh. - return e.all ? e.all : e.getElementsByTagName('*'); - } - - var bad_whitespace = /[\t\r\n]/g; - - function hasClass(elem, selector) { - var className = ' ' + selector + ' '; - return ((' ' + elem.className + ' ').replace(bad_whitespace, ' ').indexOf(className) >= 0); - } - - function getElementsBySelector(selector) { - // Attempt to fail gracefully in lesser browsers - if (!document$1.getElementsByTagName) { - return []; - } - // Split selector in to tokens - var tokens = selector.split(' '); - var token, bits, tagName, found, foundCount, i, j, k, elements, currentContextIndex; - var currentContext = [document$1]; - for (i = 0; i < tokens.length; i++) { - token = tokens[i].replace(/^\s+/, '').replace(/\s+$/, ''); - if (token.indexOf('#') > -1) { - // Token is an ID selector - bits = token.split('#'); - tagName = bits[0]; - var id = bits[1]; - var element = document$1.getElementById(id); - if (!element || (tagName && element.nodeName.toLowerCase() != tagName)) { - // element not found or tag with that ID not found, return false - return []; - } - // Set currentContext to contain just this element - currentContext = [element]; - continue; // Skip to next token - } - if (token.indexOf('.') > -1) { - // Token contains a class selector - bits = token.split('.'); - tagName = bits[0]; - var className = bits[1]; - if (!tagName) { - tagName = '*'; - } - // Get elements matching tag, filter them for class selector - found = []; - foundCount = 0; - for (j = 0; j < currentContext.length; j++) { - if (tagName == '*') { - elements = getAllChildren(currentContext[j]); - } else { - elements = currentContext[j].getElementsByTagName(tagName); - } - for (k = 0; k < elements.length; k++) { - found[foundCount++] = elements[k]; - } - } - currentContext = []; - currentContextIndex = 0; - for (j = 0; j < found.length; j++) { - if (found[j].className && - _.isString(found[j].className) && // some SVG elements have classNames which are not strings - hasClass(found[j], className) - ) { - currentContext[currentContextIndex++] = found[j]; - } - } - continue; // Skip to next token - } - // Code to deal with attribute selectors - var token_match = token.match(TOKEN_MATCH_REGEX); - if (token_match) { - tagName = token_match[1]; - var attrName = token_match[2]; - var attrOperator = token_match[3]; - var attrValue = token_match[4]; - if (!tagName) { - tagName = '*'; - } - // Grab all of the tagName elements within current context - found = []; - foundCount = 0; - for (j = 0; j < currentContext.length; j++) { - if (tagName == '*') { - elements = getAllChildren(currentContext[j]); - } else { - elements = currentContext[j].getElementsByTagName(tagName); - } - for (k = 0; k < elements.length; k++) { - found[foundCount++] = elements[k]; - } - } - currentContext = []; - currentContextIndex = 0; - var checkFunction; // This function will be used to filter the elements - switch (attrOperator) { - case '=': // Equality - checkFunction = function(e) { - return (e.getAttribute(attrName) == attrValue); - }; - break; - case '~': // Match one of space seperated words - checkFunction = function(e) { - return (e.getAttribute(attrName).match(new RegExp('\\b' + attrValue + '\\b'))); - }; - break; - case '|': // Match start with value followed by optional hyphen - checkFunction = function(e) { - return (e.getAttribute(attrName).match(new RegExp('^' + attrValue + '-?'))); - }; - break; - case '^': // Match starts with value - checkFunction = function(e) { - return (e.getAttribute(attrName).indexOf(attrValue) === 0); - }; - break; - case '$': // Match ends with value - fails with "Warning" in Opera 7 - checkFunction = function(e) { - return (e.getAttribute(attrName).lastIndexOf(attrValue) == e.getAttribute(attrName).length - attrValue.length); - }; - break; - case '*': // Match ends with value - checkFunction = function(e) { - return (e.getAttribute(attrName).indexOf(attrValue) > -1); - }; - break; - default: - // Just test for existence of attribute - checkFunction = function(e) { - return e.getAttribute(attrName); - }; - } - currentContext = []; - currentContextIndex = 0; - for (j = 0; j < found.length; j++) { - if (checkFunction(found[j])) { - currentContext[currentContextIndex++] = found[j]; - } - } - // alert('Attribute Selector: '+tagName+' '+attrName+' '+attrOperator+' '+attrValue); - continue; // Skip to next token - } - // If we get here, token is JUST an element (not a class or ID selector) - tagName = token; - found = []; - foundCount = 0; - for (j = 0; j < currentContext.length; j++) { - elements = currentContext[j].getElementsByTagName(tagName); - for (k = 0; k < elements.length; k++) { - found[foundCount++] = elements[k]; - } - } - currentContext = found; - } - return currentContext; +_.dom_query = function(query) { + if (_.isElement(query)) { + return [query]; + } else if (typeof query === 'string') { + return Array.from(document$1.querySelectorAll(query)); + } else { + return query; } - - return function(query) { - if (_.isElement(query)) { - return [query]; - } else if (_.isObject(query) && !_.isUndefined(query.length)) { - return query; - } else { - return getElementsBySelector.call(this, query); - } - }; -})(); +}; var CAMPAIGN_KEYWORDS = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_content', 'utm_term']; var CLICK_IDS = ['dclid', 'fbclid', 'gclid', 'ko_click_id', 'li_fat_id', 'msclkid', 'ttclid', 'twclid', 'wbraid']; diff --git a/examples/es2015-babelify/bundle.js b/examples/es2015-babelify/bundle.js index e0c86ba4..5a0fa1e4 100644 --- a/examples/es2015-babelify/bundle.js +++ b/examples/es2015-babelify/bundle.js @@ -5848,200 +5848,15 @@ _.register_event = (function () { return register_event; })(); -var TOKEN_MATCH_REGEX = new RegExp('^(\\w*)\\[(\\w+)([=~\\|\\^\\$\\*]?)=?"?([^\\]"]*)"?\\]$'); - -_.dom_query = (function () { - /* document.getElementsBySelector(selector) - - returns an array of element objects from the current document - matching the CSS selector. Selectors can contain element names, - class names and ids and can be nested. For example: - elements = document.getElementsBySelector('div#main p a.external') - Will return an array of all 'a' elements with 'external' in their - class attribute that are contained inside 'p' elements that are - contained inside the 'div' element which has id="main" - New in version 0.4: Support for CSS2 and CSS3 attribute selectors: - See http://www.w3.org/TR/css3-selectors/#attribute-selectors - Version 0.4 - Simon Willison, March 25th 2003 - -- Works in Phoenix 0.5, Mozilla 1.3, Opera 7, Internet Explorer 6, Internet Explorer 5 on Windows - -- Opera 7 fails - Version 0.5 - Carl Sverre, Jan 7th 2013 - -- Now uses jQuery-esque `hasClass` for testing class name - equality. This fixes a bug related to '-' characters being - considered not part of a 'word' in regex. - */ - - function getAllChildren(e) { - // Returns all children of element. Workaround required for IE5/Windows. Ugh. - return e.all ? e.all : e.getElementsByTagName('*'); - } - - var bad_whitespace = /[\t\r\n]/g; - - function hasClass(elem, selector) { - var className = ' ' + selector + ' '; - return (' ' + elem.className + ' ').replace(bad_whitespace, ' ').indexOf(className) >= 0; - } - - function getElementsBySelector(selector) { - // Attempt to fail gracefully in lesser browsers - if (!document.getElementsByTagName) { - return []; - } - // Split selector in to tokens - var tokens = selector.split(' '); - var token, bits, tagName, found, foundCount, i, j, k, elements, currentContextIndex; - var currentContext = [document]; - for (i = 0; i < tokens.length; i++) { - token = tokens[i].replace(/^\s+/, '').replace(/\s+$/, ''); - if (token.indexOf('#') > -1) { - // Token is an ID selector - bits = token.split('#'); - tagName = bits[0]; - var id = bits[1]; - var element = document.getElementById(id); - if (!element || tagName && element.nodeName.toLowerCase() != tagName) { - // element not found or tag with that ID not found, return false - return []; - } - // Set currentContext to contain just this element - currentContext = [element]; - continue; // Skip to next token - } - if (token.indexOf('.') > -1) { - // Token contains a class selector - bits = token.split('.'); - tagName = bits[0]; - var className = bits[1]; - if (!tagName) { - tagName = '*'; - } - // Get elements matching tag, filter them for class selector - found = []; - foundCount = 0; - for (j = 0; j < currentContext.length; j++) { - if (tagName == '*') { - elements = getAllChildren(currentContext[j]); - } else { - elements = currentContext[j].getElementsByTagName(tagName); - } - for (k = 0; k < elements.length; k++) { - found[foundCount++] = elements[k]; - } - } - currentContext = []; - currentContextIndex = 0; - for (j = 0; j < found.length; j++) { - if (found[j].className && _.isString(found[j].className) && // some SVG elements have classNames which are not strings - hasClass(found[j], className)) { - currentContext[currentContextIndex++] = found[j]; - } - } - continue; // Skip to next token - } - // Code to deal with attribute selectors - var token_match = token.match(TOKEN_MATCH_REGEX); - if (token_match) { - tagName = token_match[1]; - var attrName = token_match[2]; - var attrOperator = token_match[3]; - var attrValue = token_match[4]; - if (!tagName) { - tagName = '*'; - } - // Grab all of the tagName elements within current context - found = []; - foundCount = 0; - for (j = 0; j < currentContext.length; j++) { - if (tagName == '*') { - elements = getAllChildren(currentContext[j]); - } else { - elements = currentContext[j].getElementsByTagName(tagName); - } - for (k = 0; k < elements.length; k++) { - found[foundCount++] = elements[k]; - } - } - currentContext = []; - currentContextIndex = 0; - var checkFunction; // This function will be used to filter the elements - switch (attrOperator) { - case '=': - // Equality - checkFunction = function (e) { - return e.getAttribute(attrName) == attrValue; - }; - break; - case '~': - // Match one of space seperated words - checkFunction = function (e) { - return e.getAttribute(attrName).match(new RegExp('\\b' + attrValue + '\\b')); - }; - break; - case '|': - // Match start with value followed by optional hyphen - checkFunction = function (e) { - return e.getAttribute(attrName).match(new RegExp('^' + attrValue + '-?')); - }; - break; - case '^': - // Match starts with value - checkFunction = function (e) { - return e.getAttribute(attrName).indexOf(attrValue) === 0; - }; - break; - case '$': - // Match ends with value - fails with "Warning" in Opera 7 - checkFunction = function (e) { - return e.getAttribute(attrName).lastIndexOf(attrValue) == e.getAttribute(attrName).length - attrValue.length; - }; - break; - case '*': - // Match ends with value - checkFunction = function (e) { - return e.getAttribute(attrName).indexOf(attrValue) > -1; - }; - break; - default: - // Just test for existence of attribute - checkFunction = function (e) { - return e.getAttribute(attrName); - }; - } - currentContext = []; - currentContextIndex = 0; - for (j = 0; j < found.length; j++) { - if (checkFunction(found[j])) { - currentContext[currentContextIndex++] = found[j]; - } - } - // alert('Attribute Selector: '+tagName+' '+attrName+' '+attrOperator+' '+attrValue); - continue; // Skip to next token - } - // If we get here, token is JUST an element (not a class or ID selector) - tagName = token; - found = []; - foundCount = 0; - for (j = 0; j < currentContext.length; j++) { - elements = currentContext[j].getElementsByTagName(tagName); - for (k = 0; k < elements.length; k++) { - found[foundCount++] = elements[k]; - } - } - currentContext = found; - } - return currentContext; +_.dom_query = function (query) { + if (_.isElement(query)) { + return [query]; + } else if (typeof query === 'string') { + return Array.from(document.querySelectorAll(query)); + } else { + return query; } - - return function (query) { - if (_.isElement(query)) { - return [query]; - } else if (_.isObject(query) && !_.isUndefined(query.length)) { - return query; - } else { - return getElementsBySelector.call(this, query); - } - }; -})(); +}; var CAMPAIGN_KEYWORDS = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_content', 'utm_term']; var CLICK_IDS = ['dclid', 'fbclid', 'gclid', 'ko_click_id', 'li_fat_id', 'msclkid', 'ttclid', 'twclid', 'wbraid']; diff --git a/examples/umd-webpack/bundle.js b/examples/umd-webpack/bundle.js index 3fcdc05b..c9003750 100644 --- a/examples/umd-webpack/bundle.js +++ b/examples/umd-webpack/bundle.js @@ -1287,201 +1287,15 @@ })(); - var TOKEN_MATCH_REGEX = new RegExp('^(\\w*)\\[(\\w+)([=~\\|\\^\\$\\*]?)=?"?([^\\]"]*)"?\\]$'); - - _.dom_query = (function() { - /* document.getElementsBySelector(selector) - - returns an array of element objects from the current document - matching the CSS selector. Selectors can contain element names, - class names and ids and can be nested. For example: - - elements = document.getElementsBySelector('div#main p a.external') - - Will return an array of all 'a' elements with 'external' in their - class attribute that are contained inside 'p' elements that are - contained inside the 'div' element which has id="main" - - New in version 0.4: Support for CSS2 and CSS3 attribute selectors: - See http://www.w3.org/TR/css3-selectors/#attribute-selectors - - Version 0.4 - Simon Willison, March 25th 2003 - -- Works in Phoenix 0.5, Mozilla 1.3, Opera 7, Internet Explorer 6, Internet Explorer 5 on Windows - -- Opera 7 fails - - Version 0.5 - Carl Sverre, Jan 7th 2013 - -- Now uses jQuery-esque `hasClass` for testing class name - equality. This fixes a bug related to '-' characters being - considered not part of a 'word' in regex. - */ - - function getAllChildren(e) { - // Returns all children of element. Workaround required for IE5/Windows. Ugh. - return e.all ? e.all : e.getElementsByTagName('*'); - } - - var bad_whitespace = /[\t\r\n]/g; - - function hasClass(elem, selector) { - var className = ' ' + selector + ' '; - return ((' ' + elem.className + ' ').replace(bad_whitespace, ' ').indexOf(className) >= 0); - } - - function getElementsBySelector(selector) { - // Attempt to fail gracefully in lesser browsers - if (!document$1.getElementsByTagName) { - return []; - } - // Split selector in to tokens - var tokens = selector.split(' '); - var token, bits, tagName, found, foundCount, i, j, k, elements, currentContextIndex; - var currentContext = [document$1]; - for (i = 0; i < tokens.length; i++) { - token = tokens[i].replace(/^\s+/, '').replace(/\s+$/, ''); - if (token.indexOf('#') > -1) { - // Token is an ID selector - bits = token.split('#'); - tagName = bits[0]; - var id = bits[1]; - var element = document$1.getElementById(id); - if (!element || (tagName && element.nodeName.toLowerCase() != tagName)) { - // element not found or tag with that ID not found, return false - return []; - } - // Set currentContext to contain just this element - currentContext = [element]; - continue; // Skip to next token - } - if (token.indexOf('.') > -1) { - // Token contains a class selector - bits = token.split('.'); - tagName = bits[0]; - var className = bits[1]; - if (!tagName) { - tagName = '*'; - } - // Get elements matching tag, filter them for class selector - found = []; - foundCount = 0; - for (j = 0; j < currentContext.length; j++) { - if (tagName == '*') { - elements = getAllChildren(currentContext[j]); - } else { - elements = currentContext[j].getElementsByTagName(tagName); - } - for (k = 0; k < elements.length; k++) { - found[foundCount++] = elements[k]; - } - } - currentContext = []; - currentContextIndex = 0; - for (j = 0; j < found.length; j++) { - if (found[j].className && - _.isString(found[j].className) && // some SVG elements have classNames which are not strings - hasClass(found[j], className) - ) { - currentContext[currentContextIndex++] = found[j]; - } - } - continue; // Skip to next token - } - // Code to deal with attribute selectors - var token_match = token.match(TOKEN_MATCH_REGEX); - if (token_match) { - tagName = token_match[1]; - var attrName = token_match[2]; - var attrOperator = token_match[3]; - var attrValue = token_match[4]; - if (!tagName) { - tagName = '*'; - } - // Grab all of the tagName elements within current context - found = []; - foundCount = 0; - for (j = 0; j < currentContext.length; j++) { - if (tagName == '*') { - elements = getAllChildren(currentContext[j]); - } else { - elements = currentContext[j].getElementsByTagName(tagName); - } - for (k = 0; k < elements.length; k++) { - found[foundCount++] = elements[k]; - } - } - currentContext = []; - currentContextIndex = 0; - var checkFunction; // This function will be used to filter the elements - switch (attrOperator) { - case '=': // Equality - checkFunction = function(e) { - return (e.getAttribute(attrName) == attrValue); - }; - break; - case '~': // Match one of space seperated words - checkFunction = function(e) { - return (e.getAttribute(attrName).match(new RegExp('\\b' + attrValue + '\\b'))); - }; - break; - case '|': // Match start with value followed by optional hyphen - checkFunction = function(e) { - return (e.getAttribute(attrName).match(new RegExp('^' + attrValue + '-?'))); - }; - break; - case '^': // Match starts with value - checkFunction = function(e) { - return (e.getAttribute(attrName).indexOf(attrValue) === 0); - }; - break; - case '$': // Match ends with value - fails with "Warning" in Opera 7 - checkFunction = function(e) { - return (e.getAttribute(attrName).lastIndexOf(attrValue) == e.getAttribute(attrName).length - attrValue.length); - }; - break; - case '*': // Match ends with value - checkFunction = function(e) { - return (e.getAttribute(attrName).indexOf(attrValue) > -1); - }; - break; - default: - // Just test for existence of attribute - checkFunction = function(e) { - return e.getAttribute(attrName); - }; - } - currentContext = []; - currentContextIndex = 0; - for (j = 0; j < found.length; j++) { - if (checkFunction(found[j])) { - currentContext[currentContextIndex++] = found[j]; - } - } - // alert('Attribute Selector: '+tagName+' '+attrName+' '+attrOperator+' '+attrValue); - continue; // Skip to next token - } - // If we get here, token is JUST an element (not a class or ID selector) - tagName = token; - found = []; - foundCount = 0; - for (j = 0; j < currentContext.length; j++) { - elements = currentContext[j].getElementsByTagName(tagName); - for (k = 0; k < elements.length; k++) { - found[foundCount++] = elements[k]; - } - } - currentContext = found; - } - return currentContext; + _.dom_query = function(query) { + if (_.isElement(query)) { + return [query]; + } else if (typeof query === 'string') { + return Array.from(document$1.querySelectorAll(query)); + } else { + return query; } - - return function(query) { - if (_.isElement(query)) { - return [query]; - } else if (_.isObject(query) && !_.isUndefined(query.length)) { - return query; - } else { - return getElementsBySelector.call(this, query); - } - }; - })(); + }; var CAMPAIGN_KEYWORDS = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_content', 'utm_term']; var CLICK_IDS = ['dclid', 'fbclid', 'gclid', 'ko_click_id', 'li_fat_id', 'msclkid', 'ttclid', 'twclid', 'wbraid']; diff --git a/src/utils.js b/src/utils.js index f5acbb57..642f3478 100644 --- a/src/utils.js +++ b/src/utils.js @@ -1218,201 +1218,15 @@ _.register_event = (function() { })(); -var TOKEN_MATCH_REGEX = new RegExp('^(\\w*)\\[(\\w+)([=~\\|\\^\\$\\*]?)=?"?([^\\]"]*)"?\\]$'); - -_.dom_query = (function() { - /* document.getElementsBySelector(selector) - - returns an array of element objects from the current document - matching the CSS selector. Selectors can contain element names, - class names and ids and can be nested. For example: - - elements = document.getElementsBySelector('div#main p a.external') - - Will return an array of all 'a' elements with 'external' in their - class attribute that are contained inside 'p' elements that are - contained inside the 'div' element which has id="main" - - New in version 0.4: Support for CSS2 and CSS3 attribute selectors: - See http://www.w3.org/TR/css3-selectors/#attribute-selectors - - Version 0.4 - Simon Willison, March 25th 2003 - -- Works in Phoenix 0.5, Mozilla 1.3, Opera 7, Internet Explorer 6, Internet Explorer 5 on Windows - -- Opera 7 fails - - Version 0.5 - Carl Sverre, Jan 7th 2013 - -- Now uses jQuery-esque `hasClass` for testing class name - equality. This fixes a bug related to '-' characters being - considered not part of a 'word' in regex. - */ - - function getAllChildren(e) { - // Returns all children of element. Workaround required for IE5/Windows. Ugh. - return e.all ? e.all : e.getElementsByTagName('*'); - } - - var bad_whitespace = /[\t\r\n]/g; - - function hasClass(elem, selector) { - var className = ' ' + selector + ' '; - return ((' ' + elem.className + ' ').replace(bad_whitespace, ' ').indexOf(className) >= 0); - } - - function getElementsBySelector(selector) { - // Attempt to fail gracefully in lesser browsers - if (!document.getElementsByTagName) { - return []; - } - // Split selector in to tokens - var tokens = selector.split(' '); - var token, bits, tagName, found, foundCount, i, j, k, elements, currentContextIndex; - var currentContext = [document]; - for (i = 0; i < tokens.length; i++) { - token = tokens[i].replace(/^\s+/, '').replace(/\s+$/, ''); - if (token.indexOf('#') > -1) { - // Token is an ID selector - bits = token.split('#'); - tagName = bits[0]; - var id = bits[1]; - var element = document.getElementById(id); - if (!element || (tagName && element.nodeName.toLowerCase() != tagName)) { - // element not found or tag with that ID not found, return false - return []; - } - // Set currentContext to contain just this element - currentContext = [element]; - continue; // Skip to next token - } - if (token.indexOf('.') > -1) { - // Token contains a class selector - bits = token.split('.'); - tagName = bits[0]; - var className = bits[1]; - if (!tagName) { - tagName = '*'; - } - // Get elements matching tag, filter them for class selector - found = []; - foundCount = 0; - for (j = 0; j < currentContext.length; j++) { - if (tagName == '*') { - elements = getAllChildren(currentContext[j]); - } else { - elements = currentContext[j].getElementsByTagName(tagName); - } - for (k = 0; k < elements.length; k++) { - found[foundCount++] = elements[k]; - } - } - currentContext = []; - currentContextIndex = 0; - for (j = 0; j < found.length; j++) { - if (found[j].className && - _.isString(found[j].className) && // some SVG elements have classNames which are not strings - hasClass(found[j], className) - ) { - currentContext[currentContextIndex++] = found[j]; - } - } - continue; // Skip to next token - } - // Code to deal with attribute selectors - var token_match = token.match(TOKEN_MATCH_REGEX); - if (token_match) { - tagName = token_match[1]; - var attrName = token_match[2]; - var attrOperator = token_match[3]; - var attrValue = token_match[4]; - if (!tagName) { - tagName = '*'; - } - // Grab all of the tagName elements within current context - found = []; - foundCount = 0; - for (j = 0; j < currentContext.length; j++) { - if (tagName == '*') { - elements = getAllChildren(currentContext[j]); - } else { - elements = currentContext[j].getElementsByTagName(tagName); - } - for (k = 0; k < elements.length; k++) { - found[foundCount++] = elements[k]; - } - } - currentContext = []; - currentContextIndex = 0; - var checkFunction; // This function will be used to filter the elements - switch (attrOperator) { - case '=': // Equality - checkFunction = function(e) { - return (e.getAttribute(attrName) == attrValue); - }; - break; - case '~': // Match one of space seperated words - checkFunction = function(e) { - return (e.getAttribute(attrName).match(new RegExp('\\b' + attrValue + '\\b'))); - }; - break; - case '|': // Match start with value followed by optional hyphen - checkFunction = function(e) { - return (e.getAttribute(attrName).match(new RegExp('^' + attrValue + '-?'))); - }; - break; - case '^': // Match starts with value - checkFunction = function(e) { - return (e.getAttribute(attrName).indexOf(attrValue) === 0); - }; - break; - case '$': // Match ends with value - fails with "Warning" in Opera 7 - checkFunction = function(e) { - return (e.getAttribute(attrName).lastIndexOf(attrValue) == e.getAttribute(attrName).length - attrValue.length); - }; - break; - case '*': // Match ends with value - checkFunction = function(e) { - return (e.getAttribute(attrName).indexOf(attrValue) > -1); - }; - break; - default: - // Just test for existence of attribute - checkFunction = function(e) { - return e.getAttribute(attrName); - }; - } - currentContext = []; - currentContextIndex = 0; - for (j = 0; j < found.length; j++) { - if (checkFunction(found[j])) { - currentContext[currentContextIndex++] = found[j]; - } - } - // alert('Attribute Selector: '+tagName+' '+attrName+' '+attrOperator+' '+attrValue); - continue; // Skip to next token - } - // If we get here, token is JUST an element (not a class or ID selector) - tagName = token; - found = []; - foundCount = 0; - for (j = 0; j < currentContext.length; j++) { - elements = currentContext[j].getElementsByTagName(tagName); - for (k = 0; k < elements.length; k++) { - found[foundCount++] = elements[k]; - } - } - currentContext = found; - } - return currentContext; +_.dom_query = function(query) { + if (_.isElement(query)) { + return [query]; + } else if (typeof query === 'string') { + return Array.from(document.querySelectorAll(query)); + } else { + return query; } - - return function(query) { - if (_.isElement(query)) { - return [query]; - } else if (_.isObject(query) && !_.isUndefined(query.length)) { - return query; - } else { - return getElementsBySelector.call(this, query); - } - }; -})(); +}; var CAMPAIGN_KEYWORDS = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_content', 'utm_term']; var CLICK_IDS = ['dclid', 'fbclid', 'gclid', 'ko_click_id', 'li_fat_id', 'msclkid', 'ttclid', 'twclid', 'wbraid'];