Permalink
Browse files

Uses quinit.

Test _sanitizeString
  • Loading branch information...
1 parent 6e5aaa9 commit 11e65238474983dcc208797f2ee9f9b4ec0ec5da @eduardocereto eduardocereto committed Mar 24, 2011
Showing with 1,749 additions and 32 deletions.
  1. +12 −4 dist/gas.js
  2. +31 −24 dist/gas.min.js
  3. +2 −2 src/core.js
  4. +6 −2 src/helpers.js
  5. +19 −0 test/index.html
  6. +215 −0 test/qunit/qunit.css
  7. +1,442 −0 test/qunit/qunit.js
  8. +22 −0 test/test_core.js
View
@@ -60,7 +60,7 @@ _gas._functions._trackException = function(exception, message) {
};
_gas._execute = function() {
- console.dir(arguments);
+ //console.dir(arguments);
var args = slice.call(arguments),
sub = args.shift(),
i, foo, hooks, acct_name, repl_sub;
@@ -70,7 +70,7 @@ _gas._execute = function() {
return _gaq.push(
(function(s) {
var f = function() {
- s.call(_gas);
+ s.call(_gas.gh);
};
return f;
})(sub)
@@ -167,7 +167,7 @@ _gas.push = function() {
var gas_helpers = {};
-gas_helpers['_sanitizeString'] = function(str) {
+gas_helpers['_sanitizeString'] = function(str, strict) {
str = str.toLowerCase()
.replace(/^\ +/, '')
.replace(/\ +$/, '')
@@ -178,7 +178,11 @@ gas_helpers['_sanitizeString'] = function(str) {
.replace(/[óòôõöøº]/g, 'o')
.replace(/[úùûü]/g, 'u')
.replace(/[碩]/g, 'c');
- return str;
+
+ if(strict){
+ str = str.replace(/[^a-z0-9_-]/g,'_');
+ }
+ return str.replace(/_+/g, '_');
};
gas_helpers['_addEventListener'] = function(obj, evt, fnc) {
@@ -444,6 +448,10 @@ _gas.push(['_addHook', '_setDomainName', function(domainName) {
return false;
}
}]);
+_gas.push(['_addHook', '_addExternalDomainName', function(domainName) {
+ _external_domains.push(domainName);
+ return false;
+}]);
function track_links() {
var internal = document.location.hostname,
View
@@ -14,7 +14,7 @@
}
this._addEventListener(a, "submit", b)
}
- function m() {
+ function n() {
var a = 0, b = 0;
if(typeof f.innerWidth == "number") {
a = f.innerWidth;
@@ -32,7 +32,7 @@
}
return[a, b]
}
- function n() {
+ function o() {
var a = 0, b = 0;
if(typeof f.pageYOffset == "number") {
b = f.pageYOffset;
@@ -50,23 +50,23 @@
}
return[a, b]
}
- function o() {
+ function p() {
var a = c;
return Math.max(Math.max(a.body.scrollHeight, a.documentElement.scrollHeight), Math.max(a.body.offsetHeight, a.documentElement.offsetHeight), Math.max(a.body.clientHeight, a.documentElement.clientHeight))
}
- function p(a) {
+ function q(a) {
k && clearTimeout(k);
if(a === true) {
- i = Math.max((n()[1] + m()[1]) / o() * 100, i)
+ i = Math.max((o()[1] + n()[1]) / p() * 100, i)
}else {
k = setTimeout(function() {
- i = Math.max((n()[1] + m()[1]) / o() * 100, i)
+ i = Math.max((o()[1] + n()[1]) / p() * 100, i)
}, 400)
}
}
function w() {
this._addEventListener(f, "beforeunload", function() {
- p(true);
+ q(true);
var a = Math.floor(i / 10) * 10;
if(a < 100) {
a = String(a) + "-" + String(a + 9)
@@ -76,10 +76,10 @@
}
var c = f.document;
f._gaq = f._gaq || [];
- var q = f._gas || [];
- if(!(q._accounts_length >= 0)) {
- var r = Object.prototype.hasOwnProperty, x = Array.prototype.slice, y = Array.prototype.indexOf, z = c.location.href;
- f._gas = {_accounts:{}, _accounts_length:0, _hooks:{}, _functions:{}, _queue:q};
+ var r = f._gas || [];
+ if(!(r._accounts_length >= 0)) {
+ var s = Object.prototype.hasOwnProperty, x = Array.prototype.slice, y = Array.prototype.indexOf, z = c.location.href;
+ f._gas = {_accounts:{}, _accounts_length:0, _hooks:{}, _functions:{}, _queue:r};
_gas._functions._addHook = function(a, b) {
if(typeof a === "string" && typeof b === "function") {
if(typeof _gas._hooks[a] === "undefined") {
@@ -92,12 +92,11 @@
_gas.push(["_trackEvent", "Exception " + (a.name || "Error"), b || a.message || a, z])
};
_gas._execute = function() {
- console.dir(arguments);
var a = x.call(arguments), b = a.shift(), d, e, g, h;
if(typeof b === "function") {
return _gaq.push(function(A) {
return function() {
- A.call(_gas)
+ A.call(_gas.gh)
}
}(b))
}else {
@@ -122,7 +121,7 @@
}
}
}
- if(r.call(_gas._functions, e)) {
+ if(s.call(_gas._functions, e)) {
try {
_gas._functions[e].apply(_gas.gh, b)
}catch(B) {
@@ -135,16 +134,16 @@
_gas._accounts_length++;
return _gaq.push([g + "." + e, b[0]])
}
- var s;
+ var t;
for(d in _gas._accounts) {
- if(r.call(_gas._accounts, d)) {
+ if(s.call(_gas._accounts, d)) {
g = d + "." + e;
a = b.slice();
a.unshift(g);
- s += _gaq.push(a)
+ t += _gaq.push(a)
}
}
- return s ? 1 : 0
+ return t ? 1 : 0
}
}
};
@@ -156,8 +155,12 @@
})(arguments)
};
var l = {};
- l._sanitizeString = function(a) {
- return a = a.toLowerCase().replace(/^\ +/, "").replace(/\ +$/, "").replace(/\s+/g, "_").replace(/[\u00e1\u00e0\u00e2\u00e3\u00e5\u00e4\u00e6\u00aa]/g, "a").replace(/[\u00e9\u00e8\u00ea\u00eb\u0404\u20ac]/g, "e").replace(/[\u00ed\u00ec\u00ee\u00ef]/g, "i").replace(/[\u00f3\u00f2\u00f4\u00f5\u00f6\u00f8\u00ba]/g, "o").replace(/[\u00fa\u00f9\u00fb\u00fc]/g, "u").replace(/[\u00e7\u00a2\u00a9]/g, "c")
+ l._sanitizeString = function(a, b) {
+ a = a.toLowerCase().replace(/^\ +/, "").replace(/\ +$/, "").replace(/\s+/g, "_").replace(/[\u00e1\u00e0\u00e2\u00e3\u00e5\u00e4\u00e6\u00aa]/g, "a").replace(/[\u00e9\u00e8\u00ea\u00eb\u0404\u20ac]/g, "e").replace(/[\u00ed\u00ec\u00ee\u00ef]/g, "i").replace(/[\u00f3\u00f2\u00f4\u00f5\u00f6\u00f8\u00ba]/g, "o").replace(/[\u00fa\u00f9\u00fb\u00fc]/g, "u").replace(/[\u00e7\u00a2\u00a9]/g, "c");
+ if(b) {
+ a = a.replace(/[^a-z0-9_-]/g, "_")
+ }
+ return a.replace(/_+/g, "_")
};
l._addEventListener = function(a, b, d) {
if(a.addEventListener) {
@@ -193,7 +196,7 @@
}
var k = null, i = 0;
_gas._functions._trackMaxSrcoll = function() {
- this._addEventListener(f, "scroll", p);
+ this._addEventListener(f, "scroll", q);
w.call(this)
};
if(typeof _gas._functions === "undefined") {
@@ -209,20 +212,24 @@
}
return[a, b]
}]);
- var t = [];
+ var m = [];
_gas.push(["_addHook", "_setDomainName", function(a) {
if(c.location.hostname.indexOf(a) < 0) {
- t.push(a);
+ m.push(a);
return false
}
}]);
+ _gas.push(["_addHook", "_addExternalDomainName", function(a) {
+ m.push(a);
+ return false
+ }]);
_gas._functions._trackMultiDomain = function() {
var a = c.location.hostname, b, d;
for(b = 0;b < c.links.length;b++) {
d = c.links[b];
if(d.href.indexOf("http") == 0) {
if(d.hostname != a) {
- if(d.hostname in t) {
+ if(d.hostname in m) {
d.href = this._getLinkerUrl(d.href, _gas._allowAnchor)
}
}
View
@@ -59,7 +59,7 @@ _gas._functions._trackException = function(exception, message) {
};
_gas._execute = function() {
- console.dir(arguments);
+ //console.dir(arguments);
var args = slice.call(arguments),
sub = args.shift(),
i, foo, hooks, acct_name, repl_sub;
@@ -69,7 +69,7 @@ _gas._execute = function() {
return _gaq.push(
(function(s) {
var f = function() {
- s.call(_gas);
+ s.call(_gas.gh);
};
return f;
})(sub)
View
@@ -13,7 +13,7 @@
var gas_helpers = {};
-gas_helpers['_sanitizeString'] = function(str) {
+gas_helpers['_sanitizeString'] = function(str, strict) {
str = str.toLowerCase()
.replace(/^\ +/, '')
.replace(/\ +$/, '')
@@ -24,7 +24,11 @@ gas_helpers['_sanitizeString'] = function(str) {
.replace(/[óòôõöøº]/g, 'o')
.replace(/[úùûü]/g, 'u')
.replace(/[碩]/g, 'c');
- return str;
+
+ if(strict){
+ str = str.replace(/[^a-z0-9_-]/g,'_');
+ }
+ return str.replace(/_+/g, '_');
};
gas_helpers['_addEventListener'] = function(obj, evt, fnc) {
View
@@ -0,0 +1,19 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <meta charset="utf-8">
+ <title>GAS Test Suite</title>
+ <link rel="stylesheet" href="qunit/qunit.css" type="text/css" media="screen">
+ <script type="text/javascript" src="qunit/qunit.js"></script>
+ <script type="text/javascript" src="../dist/gas.min.js"></script>
+ <script type="text/javascript" src="test_core.js"></script>
+</head>
+<body>
+ <h1 id="qunit-header">GAS Test Suite</h1>
+ <h2 id="qunit-banner"></h2>
+ <div id="qunit-testrunner-toolbar"></div>
+ <h2 id="qunit-userAgent"></h2>
+ <ol id="qunit-tests"></ol>
+ <div id="qunit-fixture">test markup</div>
+</body>
+</html>
Oops, something went wrong.

0 comments on commit 11e6523

Please sign in to comment.