Skip to content

Commit

Permalink
jshinting + rm _sanitizeString
Browse files Browse the repository at this point in the history
  • Loading branch information
tomfuertes committed Nov 24, 2013
1 parent 9d4bb3e commit e042350
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 46 deletions.
5 changes: 4 additions & 1 deletion src/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ if (_prev_gas._accounts_length >= 0) {
}

//Shortcuts, these speed up and compress the code
/*jshint -W079*/
var document = window.document,
toString = Object.prototype.toString,
hasOwn = Object.prototype.hasOwnProperty,
Expand All @@ -33,7 +34,7 @@ var document = window.document,
sindexOf = String.prototype.indexOf,
url = document.location.href,
documentElement = document.documentElement;

/*jshint +W079*/
/**
* GAS Sigleton
* @constructor
Expand Down Expand Up @@ -247,7 +248,9 @@ GAS.prototype.push = function () {
* everything pushed to _gas is run through possible hooks and then pushed to
* _gaq
*/
/*global _gas:true*/
window['_gas'] = _gas = new GAS();
/*global _gas:false*/


/**
Expand Down
27 changes: 2 additions & 25 deletions src/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@
*
* @constructor
*/
/*jshint -W079*/
var GasHelper = function () {
this._setDummyTracker();
};
/*jshint +W079*/

GasHelper.prototype._setDummyTracker = function () {
if (!this['tracker']) {
Expand Down Expand Up @@ -47,31 +49,6 @@ GasHelper.prototype.inArray = function (obj, item) {
return false;
};

/**
* Removes special characters and Lowercase String
*
* @param {string} str to be sanitized.
* @param {boolean} strict_opt If we should remove any non ascii char.
* @return {string} Sanitized string.
*/
GasHelper.prototype._sanitizeString = function (str, strict_opt) {
str = str.toLowerCase()
.replace(/^\ +/, '')
.replace(/\ +$/, '')
.replace(/\s+/g, '_')
.replace(/[áàâãåäæª]/g, 'a')
.replace(/[éèêëЄ€]/g, 'e')
.replace(/[íìîï]/g, 'i')
.replace(/[óòôõöøº]/g, 'o')
.replace(/[úùûü]/g, 'u')
.replace(/[碩]/g, 'c');

if (strict_opt) {
str = str.replace(/[^a-z0-9_\-]/g, '_');
}
return str.replace(/_+/g, '_');
};

/**
* Cross Browser helper to addEventListener.
*
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/mailto.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ var _gasTrackMailto = function (opts) {
this._mailtoTracked = true;
} else {
//Oops double tracking detected.
return false;;
return false;
}

if (!opts) {
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/max_scroll.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ function _trackMaxScroll(opts) {
this._maxScrollTracked = true;
} else {
//Oops double tracking detected.
return false;;
return false;
}
_maxScrollOpts = opts || {};
_maxScrollOpts['category'] = _maxScrollOpts['category'] || 'Max Scroll';
Expand Down
18 changes: 0 additions & 18 deletions test/test_core.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,24 +39,6 @@ test('multiple parameters passed to _gas.push', function() {
_gas.push(['_popHook', '_trackPageview']);
});

test('_sanitizeString', function() {
var san = _gas.gh._sanitizeString;
expect(6);
equals(san(' /tééééá íóú '), '/teeeea_iou');
equals(san(''), '');
equals(san(' '), '');
equals(san('ÇA ÄR'), 'ca_ar');

stop();
_gas.push(function() {
equals(this._sanitizeString('Áéí óù '), 'aei_ou',
'From within pushed function');
start();
});

equals(san('&$*()[]/\éa', true), '_ea', 'strict mode');
});

test('_addHook _trackPageview', function() {
expect(1);

Expand Down

0 comments on commit e042350

Please sign in to comment.