Skip to content
Browse files

JSHinted

  • Loading branch information...
1 parent 656910f commit 0f44c525fdc518f729f59470df0f668a7179eee3 @eduardocereto eduardocereto committed Jul 12, 2012
View
15 .jshintrc
@@ -11,7 +11,14 @@
"mootools" : false,
"dojo" : false,
"predef" : [
- "_gaq"
+ "_gaq",
+ "_gas",
+ "slice",
+ "sindexOf",
+ "documentElement",
+ "url",
+ "GasHelper",
+ "console"
],
"debug" : false,
"devel" : false,
@@ -22,17 +29,17 @@
"laxbreak" : true,
"bitwise" : true,
"boss" : false,
- "curly" : true,
+ "curly" : false,
"eqeqeq" : true,
"eqnull" : false,
"evil" : false,
"expr" : false,
"forin" : false,
"immed" : true,
"latedef" : true,
- "loopfunc" : false,
+ "loopfunc" : true,
"noarg" : true,
- "regexp" : true,
+ "regexp" : false,
"regexdash" : false,
"scripturl" : false,
"shadow" : false,
View
19 Makefile
@@ -1,13 +1,5 @@
-# http://code.google.com/closure/compiler/
-#CLOSURE_COMPILER = java -jar ~/compiler.jar
-CLOSURE_COMPILER = java -jar ~/compiler.jar --compilation_level ADVANCED_OPTIMIZATIONS
-#CLOSURE_COMPILER = java -jar ~/compiler.jar --compilation_level ADVANCED_OPTIMIZATIONS --formatting PRETTY_PRINT
-#CLOSURE_COMPILER = java -jar ~/compiler.jar --formatting PRETTY_PRINT
UGLIFYJS = uglifyjs --ascii -v
-
-# http://code.google.com/closure/utilities/index.html
-CLOSURE_LINTER = gjslint
-FIXJSSTYLE = fixjsstyle
+JSHINT = jshint
COREJSFILES = src/helpers.js src/core.js
PLUGINS = $(wildcard src/plugins/*.js)
@@ -26,26 +18,19 @@ gas.js: $(JSFILES)
echo "(function(window, undefined) {" >> dist/$@
cat $^ >> dist/$@
echo "})(window);" >> dist/$@
- # $(CLOSURE_LINTER) dist/$@
gas.core.js: $(COREJSFILES) $(WRAPUP)
cat src/header.js > dist/$@
echo "(function(window, undefined) {" >> dist/$@
cat $^ >> dist/$@
echo "})(window);" >> dist/$@
- # $(CLOSURE_LINTER) dist/$@
gas.min.js: gas.js
- #$(CLOSURE_COMPILER) --js dist/$< --js_output_file dist/$@
$(UGLIFYJS) -o dist/$@ dist/$<
gas.core.min.js: gas.core.js
- #$(CLOSURE_COMPILER) --js dist/$< --js_output_file dist/$@
$(UGLIFYJS) -o dist/$@ dist/$<
lint: $(JSFILES)
- $(FIXJSSTYLE) -r src
- $(CLOSURE_LINTER) -r src
- $(FIXJSSTYLE) $(TESTFILES)
- $(CLOSURE_LINTER) $(TESTFILES)
+ $(JSHINT) src/
View
42 src/core.js
@@ -50,7 +50,7 @@ function GAS() {
};
// Need to be pushed to make sure tracker is done
// Sets up helpers, very first thing pushed into gas
- self.push(function() {
+ self.push(function () {
self.gh = new GasHelper();
});
}
@@ -63,7 +63,7 @@ function GAS() {
* @param {function()} cb The callback function to be appended to hooks.
* @return {boolean} Always false.
*/
-GAS.prototype._addHook = function(fn, cb) {
+GAS.prototype._addHook = function (fn, cb) {
if (typeof fn === 'string' && typeof cb === 'function') {
if (typeof _gas._hooks[fn] === 'undefined') {
_gas._hooks[fn] = [];
@@ -101,7 +101,7 @@ function _gaq_push(arr) {
* This function should not be called directly. Instead use _gas.push
* @return {number} This is the same return as _gaq.push calls.
*/
-GAS.prototype._execute = function() {
+GAS.prototype._execute = function () {
var args = slice.call(arguments),
self = this,
sub = args.shift(),
@@ -111,21 +111,21 @@ GAS.prototype._execute = function() {
if (typeof sub === 'function') {
// Pushed functions are executed right away
return _gaq_push(
- (function(s, gh) {
- return function() {
+ (function (s, gh) {
+ return function () {
// pushed functions receive helpers through this object
s.call(gh);
};
- })(sub, self.gh)
+ }(sub, self.gh))
);
- }else if (typeof sub === 'object' && sub.length > 0) {
+ } else if (typeof sub === 'object' && sub.length > 0) {
foo = sub.shift();
if (sindexOf.call(foo, '.') >= 0) {
acct_name = foo.split('.')[0];
foo = foo.split('.')[1];
- }else {
+ } else {
acct_name = undefined;
}
@@ -138,13 +138,13 @@ GAS.prototype._execute = function() {
if (repl_sub === false) {
// Returning false from a hook cancel the call
gaq_execute = false;
- }else {
+ } else {
if (repl_sub && repl_sub.length > 0) {
// Returning an array changes the call parameters
sub = repl_sub;
}
}
- }catch (e) {
+ } catch (e) {
if (foo !== '_trackException') {
self.push(['_trackException', e]);
}
@@ -159,7 +159,7 @@ GAS.prototype._execute = function() {
if (foo === '_setAccount') {
for (i in self._accounts) {
- if (self._accounts[i] == sub[0]) {
+ if (self._accounts[i] === sub[0]) {
// Repeated account
if (acct_name === undefined) {
return 1;
@@ -169,8 +169,8 @@ GAS.prototype._execute = function() {
acct_name = acct_name || '_gas' +
String(self._accounts_length + 1);
// Force that the first unamed account is _gas1
- if (typeof self._accounts['_gas1'] == 'undefined' &&
- sindexOf.call(acct_name, '_gas') != -1) {
+ if (typeof self._accounts['_gas1'] === 'undefined' &&
+ sindexOf.call(acct_name, '_gas') !== -1) {
acct_name = '_gas1';
}
self._accounts[acct_name] = sub[0];
@@ -225,15 +225,15 @@ GAS.prototype._execute = function() {
* ready for hooks. This creates _gaq as a series of functions that call
* _gas._execute() with the same arguments.
*/
-GAS.prototype.push = function() {
+GAS.prototype.push = function () {
var self = this;
var args = slice.call(arguments);
for (var i = 0; i < args.length; i++) {
- (function(arr, self) {
- window['_gaq'].push(function() {
+ (function (arr, self) {
+ window['_gaq'].push(function () {
self._execute.call(self, arr);
});
- })(args[i], self);
+ }(args[i], self));
}
};
@@ -252,7 +252,7 @@ window['_gas'] = _gas = new GAS();
*
* Watchout for circular calls
*/
-_gas.push(['_addHook', '_trackException', function(exception, message) {
+_gas.push(['_addHook', '_trackException', function (exception, message) {
_gas.push(['_trackEvent',
'Exception ' + (exception.name || 'Error'),
message || exception.message || exception,
@@ -264,7 +264,7 @@ _gas.push(['_addHook', '_trackException', function(exception, message) {
/**
* Hook to enable Debug Mode
*/
-_gas.push(['_addHook', '_setDebug', function(set_debug) {
+_gas.push(['_addHook', '_setDebug', function (set_debug) {
_gas.debug_mode = !!set_debug;
}]);
@@ -276,7 +276,7 @@ _gas.push(['_addHook', '_setDebug', function(set_debug) {
* @param {string} func _gas Function Name to remove Hooks from.
* @return {boolean} Always returns false.
*/
-_gas.push(['_addHook', '_popHook', function(func) {
+_gas.push(['_addHook', '_popHook', function (func) {
var arr = _gas._hooks[func];
if (arr && arr.pop) {
arr.pop();
@@ -289,7 +289,7 @@ _gas.push(['_addHook', '_popHook', function(func) {
*
* The default tracker is the nameless tracker that is pushed into _gaq_push
*/
-_gas.push(['_addHook', '_gasSetDefaultTracker', function(tname) {
+_gas.push(['_addHook', '_gasSetDefaultTracker', function (tname) {
_gas._default_tracker = tname;
return false;
}]);
View
34 src/helpers.js
@@ -16,11 +16,11 @@
*
* @constructor
*/
-var GasHelper = function() {
+var GasHelper = function () {
this._setDummyTracker();
};
-GasHelper.prototype._setDummyTracker = function() {
+GasHelper.prototype._setDummyTracker = function () {
if (!this['tracker']) {
var trackers = window['_gat']['_getTrackers']();
if (trackers.length > 0) {
@@ -36,7 +36,7 @@ GasHelper.prototype._setDummyTracker = function() {
* @param {object} item Item to search form.
* @return {boolean} true if contains.
*/
-GasHelper.prototype.inArray = function(obj, item) {
+GasHelper.prototype.inArray = function (obj, item) {
if (obj && obj.length) {
for (var i = 0; i < obj.length; i++) {
if (obj[i] === item) {
@@ -54,7 +54,7 @@ GasHelper.prototype.inArray = function(obj, item) {
* @param {boolean} strict_opt If we should remove any non ascii char.
* @return {string} Sanitized string.
*/
-GasHelper.prototype._sanitizeString = function(str, strict_opt) {
+GasHelper.prototype._sanitizeString = function (str, strict_opt) {
str = str.toLowerCase()
.replace(/^\ +/, '')
.replace(/\ +$/, '')
@@ -86,8 +86,8 @@ GasHelper.prototype._sanitizeString = function(str, strict_opt) {
* it.
* @return {boolean} true if it was successfuly binded.
*/
-GasHelper.prototype._addEventListener = function(obj, evt, ofnc, bubble) {
- var fnc = function(event) {
+GasHelper.prototype._addEventListener = function (obj, evt, ofnc, bubble) {
+ var fnc = function (event) {
if (!event || !event.target) {
event = window.event;
event.target = event.srcElement;
@@ -109,12 +109,12 @@ GasHelper.prototype._addEventListener = function(obj, evt, ofnc, bubble) {
if (typeof obj[evt] === 'function') {
// Object already has a function on traditional
// Let's wrap it with our own function inside another function
- fnc = (function(f1, f2) {
- return function() {
+ fnc = (function (f1, f2) {
+ return function () {
f1.apply(this, arguments);
f2.apply(this, arguments);
- }
- })(obj[evt], fnc);
+ };
+ }(obj[evt], fnc));
}
obj[evt] = fnc;
return true;
@@ -127,12 +127,12 @@ GasHelper.prototype._addEventListener = function(obj, evt, ofnc, bubble) {
* Binds to the document root. Listens to all events of the specific type.
* If event don't bubble it won't catch
*/
-GasHelper.prototype._liveEvent = function(tag, evt, ofunc) {
+GasHelper.prototype._liveEvent = function (tag, evt, ofunc) {
var gh = this;
tag = tag.toUpperCase();
tag = tag.split(',');
- gh._addEventListener(document, evt, function(me) {
+ gh._addEventListener(document, evt, function (me) {
for (var el = me.target; el.nodeName !== 'HTML';
el = el.parentNode)
{
@@ -155,13 +155,13 @@ GasHelper.prototype._liveEvent = function(tag, evt, ofunc) {
* @param {function(Event)} callback DOMReady callback.
* @return {boolean} Ignore return value.
*/
-GasHelper.prototype._DOMReady = function(callback) {
+GasHelper.prototype._DOMReady = function (callback) {
var scp = this;
- var cb = function() {
- if (arguments.callee.done) return;
- arguments.callee.done = true;
+ function cb() {
+ if (cb.done) return;
+ cb.done = true;
callback.apply(scp, arguments);
- };
+ }
if (/^(interactive|complete)/.test(document.readyState)) return cb();
this._addEventListener(document, 'DOMContentLoaded', cb, false);
this._addEventListener(window, 'load', cb, false);
View
2 src/plugins/change_title.js
@@ -2,7 +2,7 @@
* This is kept just for backward compatibility since it's now supported
* natively in _gaq.
*/
-_gas.push(['_addHook', '_trackPageview', function() {
+_gas.push(['_addHook', '_trackPageview', function () {
var args = slice.call(arguments);
if (args.length >= 2 &&
typeof args[0] === 'string' && typeof args[1] === 'string')
View
2 src/plugins/click_tracking.js
@@ -21,7 +21,7 @@ function _clickTracking(opts) {
opts['css_class'] = opts['css_class'] || ['ga_track'];
opts['category'] = opts['category'] || 'Click Tracking';
var re = opts['css_class'].join('|');
- gh._addEventListener(document, evt, function(me) {
+ gh._addEventListener(document, 'mousedown', function (me) {
for (var el = me.target; el.nodeName !== 'HTML'; el = el.parentNode)
{
if (el && el.className && el.className.match(re) !== null) {
View
6 src/plugins/download.js
@@ -41,12 +41,12 @@ function _checkFile(src, extensions) {
* @param {Array|object} opts List of possible extensions for download
* links.
*/
-var _trackDownloads = function(opts) {
+var _trackDownloads = function (opts) {
var gh = this;
if (!gh._downloadTracked) {
gh._downloadTracked = true;
- }else {
+ } else {
//Oops double tracking detected.
return;
}
@@ -66,7 +66,7 @@ var _trackDownloads = function(opts) {
ext = ext.split(',');
opts['extensions'] = opts['extensions'].concat(ext);
- gh._liveEvent('a', 'mousedown', function(e) {
+ gh._liveEvent('a', 'mousedown', function (e) {
var el = this;
if (el.href) {
var ext = _checkFile.call(gh,
View
2 src/plugins/fix_events.js
@@ -5,7 +5,7 @@
* Negative values are sent as zero.
* If val is NaN than it is sent as zero.
*/
-_gas.push(['_addHook', '_trackEvent', function() {
+_gas.push(['_addHook', '_trackEvent', function () {
var args = slice.call(arguments);
if (args[3]) {
args[3] = (args[3] < 0 ? 0 : Math.round(args[3])) || 0;
View
14 src/plugins/form_tracking.js
@@ -17,19 +17,19 @@
*/
function getFormName(el) {
while (el && el.nodeName !== 'HTML') {
- if (el.nodeName === 'FORM') {break;}
- el = el.parentNode;
+ if (el.nodeName === 'FORM') {break; }
+ el = el.parentNode;
}
if (el.nodeName === 'FORM') {
return el.name || el.id || 'none';
}
return 'none';
}
-var _gasTrackForms = function(opts) {
+var _gasTrackForms = function (opts) {
if (!this._formTracked) {
this._formTracked = true;
- }else {
+ } else {
//Oops double tracking detected.
return;
}
@@ -42,17 +42,17 @@ var _gasTrackForms = function(opts) {
opts['category'] = opts['category'] || 'Form Tracking';
//opts['live'] = opts['live'] || true; //Ignored
- var trackField = function(e) {
+ var trackField = function (e) {
var el = e.target,
el_name = el.name || el.id || el.type || el.nodeName,
form_name = getFormName(el),
action = 'form (' + form_name + ')',
label = el_name + ' (' + e.type + ')';
_gas.push(['_trackEvent', opts['category'], action, label]);
- }
+ };
- scp._DOMReady(function() {
+ scp._DOMReady(function () {
var changeTags = ['input', 'select', 'textarea', 'hidden'];
var submitTags = ['form'];
var elements = [];
View
10 src/plugins/html5_media.js
@@ -27,27 +27,27 @@ function _trackMediaElement(e) {
* @param {String} tag Either 'audio' or 'video'.
* @this {GasHelper} GA Helper object.
*/
-var _trackMedia = function(tag) {
+var _trackMedia = function (tag) {
var self = this;
self._liveEvent(tag, 'play', _trackMediaElement);
self._liveEvent(tag, 'pause', _trackMediaElement);
self._liveEvent(tag, 'ended', _trackMediaElement);
};
-var _trackVideo = function() {
+var _trackVideo = function () {
if (!this._videoTracked) {
this._videoTracked = true;
- }else {
+ } else {
//Oops double tracking detected.
return;
}
_trackMedia.call(this, 'video');
};
-var _trackAudio = function() {
+var _trackAudio = function () {
if (!this._audioTracked) {
this._audioTracked = true;
- }else {
+ } else {
//Oops double tracking detected.
return;
}
View
6 src/plugins/mailto.js
@@ -12,10 +12,10 @@
*
* @param {object} opts GAS Options.
*/
-var _gasTrackMailto = function(opts) {
+var _gasTrackMailto = function (opts) {
if (!this._mailtoTracked) {
this._mailtoTracked = true;
- }else {
+ } else {
//Oops double tracking detected.
return;
}
@@ -25,7 +25,7 @@ var _gasTrackMailto = function(opts) {
}
opts['category'] = opts['category'] || 'Mailto';
- this._liveEvent('a', 'mousedown', function(e) {
+ this._liveEvent('a', 'mousedown', function (e) {
var el = e.target;
if (el && el.href && el.href.toLowerCase &&
sindexOf.call(el.href.toLowerCase(), 'mailto:') === 0) {
View
7 src/plugins/max_scroll.js
@@ -9,6 +9,8 @@
* @author Eduardo Cereto <eduardocereto@gmail.com>
*/
+var _maxScrollOpts;
+
/**
* Get current browser viewpane heigtht
*
@@ -64,7 +66,7 @@ function _update_scroll_percentage(now) {
_max_scroll = Math.max(_get_scroll_percentage(), _max_scroll);
return;
}
- _t = setTimeout(function() {
+ _t = setTimeout(function () {
_max_scroll = Math.max(_get_scroll_percentage(), _max_scroll);
}, 400);
}
@@ -88,7 +90,6 @@ function _sendMaxScroll() {
]);
}
-var _maxScrollOpts;
/**
* Tracks the max Scroll on the page.
*
@@ -98,7 +99,7 @@ var _maxScrollOpts;
function _trackMaxScroll(opts) {
if (!this._maxScrollTracked) {
this._maxScrollTracked = true;
- }else {
+ } else {
//Oops double tracking detected.
return;
}
View
32 src/plugins/multidomain.js
@@ -20,14 +20,14 @@ _gas._allowAnchor = false;
* This stored value is used on _getLinkerUrl, _link and _linkByPost so it's
* used the same by default
*/
-_gas.push(['_addHook', '_setAllowAnchor', function(val) {
+_gas.push(['_addHook', '_setAllowAnchor', function (val) {
_gas._allowAnchor = !!val;
}]);
/**
* _link Hook to use stored allowAnchor value.
*/
-_gas.push(['_addHook', '_link', function(url, use_anchor) {
+_gas.push(['_addHook', '_link', function (url, use_anchor) {
if (use_anchor === undefined) {
use_anchor = _gas._allowAnchor;
}
@@ -37,7 +37,7 @@ _gas.push(['_addHook', '_link', function(url, use_anchor) {
/**
* _linkByPost Hook to use stored allowAnchor value.
*/
-_gas.push(['_addHook', '_linkByPost', function(url, use_anchor) {
+_gas.push(['_addHook', '_linkByPost', function (url, use_anchor) {
if (use_anchor === undefined) {
use_anchor = _gas._allowAnchor;
}
@@ -56,7 +56,7 @@ var _external_domains = [];
*
* @type string
*/
-var _internal_domain = undefined;
+var _internal_domain;
/**
* _setDomainName Hook to add pushed domains to _external_domains if it doesn't
@@ -66,7 +66,7 @@ var _internal_domain = undefined;
* apply the one that matches the current domain and the other ones will be
* used to track external domains with cookie data.
*/
-_gas.push(['_addHook', '_setDomainName', function(domainName) {
+_gas.push(['_addHook', '_setDomainName', function (domainName) {
if (sindexOf.call('.' + document.location.hostname, domainName) < 0) {
_external_domains.push(domainName);
return false;
@@ -81,7 +81,7 @@ _gas.push(['_addHook', '_setDomainName', function(domainName) {
* domain are marked to send cookies.
* You should use _setDomainName for this in most of the cases.
*/
-_gas.push(['_addHook', '_addExternalDomainName', function(domainName) {
+_gas.push(['_addHook', '_addExternalDomainName', function (domainName) {
_external_domains.push(domainName);
return false;
}]);
@@ -98,7 +98,7 @@ _gas.push(['_addHook', '_addExternalDomainName', function(domainName) {
function track_links(event_used) {
if (!this._multidomainTracked) {
this._multidomainTracked = true;
- }else {
+ } else {
//Oops double tracking detected.
return;
}
@@ -113,7 +113,7 @@ function track_links(event_used) {
el = links[i];
if (sindexOf.call(el.href, 'http') === 0) {
// Check to see if it's a internal link
- if (el.hostname == internal ||
+ if (el.hostname === internal ||
sindexOf.call(el.hostname, _internal_domain) >= 0) {
continue;
}
@@ -125,16 +125,16 @@ function track_links(event_used) {
el.href,
_gas._allowAnchor
);
- }else {
+ } else {
if (event_used === 'click') {
- this._addEventListener(el, event_used, function(e) {
- if (this.target && this.target == '_blank') {
+ this._addEventListener(el, event_used, function (e) {
+ if (this.target && this.target === '_blank') {
window.open(
gh['tracker']['_getLinkerUrl'](
this.href, _gas._allowAnchor
)
);
- }else {
+ } else {
_gas.push(
['_link', this.href, _gas._allowAnchor]
);
@@ -145,8 +145,8 @@ function track_links(event_used) {
e.returnValue = false;
return false; //needed for ie7
});
- }else {
- this._addEventListener(el, event_used, function() {
+ } else {
+ this._addEventListener(el, event_used, function () {
this.href = gh['tracker']['_getLinkerUrl'](
this.href,
_gas._allowAnchor
@@ -161,11 +161,11 @@ function track_links(event_used) {
return false;
}
-var _gasMultiDomain = function() {
+var _gasMultiDomain = function () {
var gh = this;
var args = slice.call(arguments);
if (gh && gh._DOMReady) {
- gh._DOMReady(function() {
+ gh._DOMReady(function () {
track_links.apply(gh, args);
});
}
View
8 src/plugins/outbound.js
@@ -15,10 +15,10 @@
* @this {object} GA Helper object.
* @param {object} opts Custom options for Outbound Links.
*/
-var _gasTrackOutboundLinks = function(opts) {
+var _gasTrackOutboundLinks = function (opts) {
if (!this._outboundTracked) {
this._outboundTracked = true;
- }else {
+ } else {
//Oops double tracking detected.
return;
}
@@ -28,10 +28,10 @@ var _gasTrackOutboundLinks = function(opts) {
}
opts['category'] = opts['category'] || 'Outbound';
- gh._liveEvent('a', 'mousedown', function(e) {
+ gh._liveEvent('a', 'mousedown', function (e) {
var l = this;
if (
- (l.protocol == 'http:' || l.protocol == 'https:') &&
+ (l.protocol === 'http:' || l.protocol === 'https:') &&
sindexOf.call(l.hostname, document.location.hostname) === -1)
{
var path = (l.pathname + l.search + ''),
View
12 src/plugins/vimeo.js
@@ -80,8 +80,8 @@ function _vimeoPostMessageListener(event) {
var data = JSON.parse(event.data);
if (data.event === 'ready') {
_trackVimeo.call(_gas.gh); // Force rerun since a player is ready
- }else if (data.method) {
- if (data.method == 'getVideoUrl') {
+ } else if (data.method) {
+ if (data.method === 'getVideoUrl') {
_vimeo_urls[data.player_id] = data.value;
}
} else if (data.event === 'playProgress') {
@@ -122,11 +122,11 @@ function _trackVimeo() {
if (force) {
// Reload the video enabling the api
player_src += separator + 'api=1&player_id=' + player_id;
- }else {
+ } else {
// We won't track players that don't have api enabled.
continue;
}
- }else {
+ } else {
if (sindexOf.call(player_src, 'player_id=') < -1) {
player_src += separator + 'player_id=' + player_id;
}
@@ -158,7 +158,7 @@ function _trackVimeo() {
}
}
-var _gasTrackVimeo = function(opts) {
+var _gasTrackVimeo = function (opts) {
var gh = this;
// Support
if (typeof opts === 'boolean' || opts === 'force') {
@@ -169,7 +169,7 @@ var _gasTrackVimeo = function(opts) {
opts['percentages'] = opts['percentages'] || [];
opts['force'] = opts['force'] || false;
_vimeoOpts = opts;
- gh._DOMReady(function() {
+ gh._DOMReady(function () {
_trackVimeo.call(gh);
});
return false;
View
67 src/plugins/youtube.js
@@ -22,21 +22,8 @@ var _ytOpts;
var _ytPoolMaps = {};
-function _ytStartPool(target) {
- if (_ytTimeTriggers && _ytTimeTriggers.length) {
- var h = target['getVideoData']()['video_id'];
- if (_ytPoolMaps[h]) {
- _ytStopPool(target);
- }else {
- _ytPoolMaps[h] = {};
- _ytPoolMaps[h].timeTriggers = slice.call(_ytTimeTriggers);
- }
- _ytPoolMaps[h].timer = setTimeout(_ytPool, 1000, target, h);
- }
-}
-
function _ytPool(target, hash) {
- if (_ytPoolMaps[hash] == undefined ||
+ if (_ytPoolMaps[hash] === undefined ||
_ytPoolMaps[hash].timeTriggers.length <= 0) {
return false;
}
@@ -61,6 +48,20 @@ function _ytStopPool(target) {
}
}
+function _ytStartPool(target) {
+ if (_ytTimeTriggers && _ytTimeTriggers.length) {
+ var h = target['getVideoData']()['video_id'];
+ if (_ytPoolMaps[h]) {
+ _ytStopPool(target);
+ } else {
+ _ytPoolMaps[h] = {};
+ _ytPoolMaps[h].timeTriggers = slice.call(_ytTimeTriggers);
+ }
+ _ytPoolMaps[h].timer = setTimeout(_ytPool, 1000, target, h);
+ }
+}
+
+
/**
* Called when the Video State changes
*
@@ -71,18 +72,18 @@ function _ytStopPool(target) {
function _ytStateChange(event) {
var action = '';
switch (event['data']) {
- case 0:
- action = 'finish';
- _ytStopPool(event['target']);
- break;
- case 1:
- action = 'play';
- _ytStartPool(event['target']);
- break;
- case 2:
- action = 'pause';
- _ytStopPool(event['target']);
- break;
+ case 0:
+ action = 'finish';
+ _ytStopPool(event['target']);
+ break;
+ case 1:
+ action = 'play';
+ _ytStartPool(event['target']);
+ break;
+ case 2:
+ action = 'pause';
+ _ytStopPool(event['target']);
+ break;
}
if (action) {
_gas.push(['_trackEvent',
@@ -111,11 +112,11 @@ function _ytError(event) {
function _ytMigrateObjectEmbed() {
var objs = document.getElementsByTagName('object');
var pars, ifr, ytid;
- var r = /(https?:\/\/www\.youtube(-nocookie)?\.com[^/]*).*\/v\/([^&?]+)/;
+ var r = /(https?:\/\/www\.youtube(-nocookie)?\.com[^\/]*).*\/v\/([^&?]+)/;
for (var i = 0; i < objs.length; i++) {
pars = objs[i].getElementsByTagName('param');
for (var j = 0; j < pars.length; j++) {
- if (pars[j].name == 'movie' && pars[j].value) {
+ if (pars[j].name === 'movie' && pars[j].value) {
// Replace the object with an iframe
ytid = pars[j].value.match(r);
if (ytid && ytid[1] && ytid[3]) {
@@ -166,10 +167,10 @@ function _trackYoutube(opts) {
// Reload the video enabling the api
if (sindexOf.call(iframes[i].src, '?') < 0) {
iframes[i].src += '?enablejsapi=1';
- }else {
+ } else {
iframes[i].src += '&enablejsapi=1';
}
- }else {
+ } else {
// We can't track players that don't have api enabled.
continue;
}
@@ -182,7 +183,7 @@ function _trackYoutube(opts) {
_ytTimeTriggers = opt_timeTriggers;
}
// this function will be called when the youtube api loads
- window['onYouTubePlayerAPIReady'] = function() {
+ window['onYouTubePlayerAPIReady'] = function () {
var p;
for (var i = 0; i < youtube_videos.length; i++) {
p = new window['YT']['Player'](youtube_videos[i]);
@@ -205,7 +206,7 @@ function _trackYoutube(opts) {
}
}
-var _gasTrackYoutube = function(opts) {
+var _gasTrackYoutube = function (opts) {
// Support for legacy parameters
var args = slice.call(arguments);
if (args[0] && (typeof args[0] === 'boolean' || args[0] === 'force')) {
@@ -222,7 +223,7 @@ var _gasTrackYoutube = function(opts) {
_ytOpts = opts;
var gh = this;
- gh._DOMReady(function() {
+ gh._DOMReady(function () {
_trackYoutube.call(gh, opts);
});
return false;
View
6 src/wrapup.js
@@ -8,18 +8,18 @@ while (_gas._queue.length > 0) {
// Import ga.js
if (_gaq && _gaq.length >= 0) {
- (function() {
+ (function () {
var ga = document.createElement('script');
ga.type = 'text/javascript';
ga.async = true;
ga.src = (
- 'https:' == document.location.protocol ?
+ 'https:' === document.location.protocol ?
'https://ssl' :
'http://www'
) +
'.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(ga, s);
- })();
+ }());
}

0 comments on commit 0f44c52

Please sign in to comment.
Something went wrong with that request. Please try again.