Merge pull request #5113 from edx/renzo/remove-unused-js
Remove unused analytics JS left over by 3rd party auth changes
This commit is contained in:
@@ -16,26 +16,3 @@ describe('utility.rewriteStaticLinks', function () {
|
||||
).toBe('<img src="http://www.mysite.org/static/foo.x"/>')
|
||||
});
|
||||
});
|
||||
|
||||
describe('utility.appendParameter', function() {
|
||||
it('creates and populates query string with provided parameter', function() {
|
||||
expect(appendParameter('/cambridge', 'season', 'fall')).toBe('/cambridge?season=fall')
|
||||
});
|
||||
it('appends provided parameter to existing query string parameters', function() {
|
||||
expect(appendParameter('/cambridge?season=fall', 'color', 'red')).toBe('/cambridge?season=fall&color=red')
|
||||
});
|
||||
it('appends provided parameter to existing query string with a trailing ampersand', function() {
|
||||
expect(appendParameter('/cambridge?season=fall&', 'color', 'red')).toBe('/cambridge?season=fall&color=red')
|
||||
});
|
||||
it('overwrites existing parameter with provided value', function() {
|
||||
expect(appendParameter('/cambridge?season=fall', 'season', 'winter')).toBe('/cambridge?season=winter');
|
||||
expect(appendParameter('/cambridge?season=fall&color=red', 'color', 'orange')).toBe('/cambridge?season=fall&color=orange');
|
||||
});
|
||||
});
|
||||
|
||||
describe('utility.parseQueryString', function() {
|
||||
it('converts a non-empty query string into a key/value object', function() {
|
||||
expect(JSON.stringify(parseQueryString('season=fall'))).toBe(JSON.stringify({season:'fall'}));
|
||||
expect(JSON.stringify(parseQueryString('season=fall&color=red'))).toBe(JSON.stringify({season:'fall', color:'red'}));
|
||||
});
|
||||
});
|
||||
|
||||
@@ -41,56 +41,6 @@ window.rewriteStaticLinks = function(content, from, to) {
|
||||
return content.replace(regex, replacer);
|
||||
};
|
||||
|
||||
// Appends a parameter to a path; useful for indicating initial or return signin, for example
|
||||
window.appendParameter = function(path, key, value) {
|
||||
// Check if the given path already contains a query string by looking for the ampersand separator
|
||||
if (path.indexOf("?") > -1) {
|
||||
var splitPath = path.split("?");
|
||||
var parameters = window.parseQueryString(splitPath[1]);
|
||||
// Check if the provided key already exists in the query string
|
||||
if (key in parameters) {
|
||||
// Overwrite the existing key's value with the provided value
|
||||
parameters[key] = value;
|
||||
|
||||
// Reconstruct the path, including the overwritten key/value pair
|
||||
var reconstructedPath = splitPath[0] + "?";
|
||||
for (var k in parameters) {
|
||||
reconstructedPath = reconstructedPath + k + "=" + parameters[k] + "&";
|
||||
}
|
||||
// Strip the trailing ampersand
|
||||
return reconstructedPath.slice(0, -1);
|
||||
} else {
|
||||
// Check for a trailing ampersand
|
||||
if (path[path.length - 1] != "&") {
|
||||
// Append signin parameter to the existing query string
|
||||
return path + "&" + key + "=" + value;
|
||||
} else {
|
||||
// Append signin parameter to the existing query string, excluding the ampersand
|
||||
return path + key + "=" + value;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Append new query string containing the provided parameter
|
||||
return path + "?" + key + "=" + value;
|
||||
}
|
||||
};
|
||||
|
||||
// Convert a query string to a key/value object
|
||||
window.parseQueryString = function(queryString) {
|
||||
var parameters = {}, queries, pair, i, l;
|
||||
|
||||
// Split the query string into key/value pairs
|
||||
queries = queryString.split("&");
|
||||
|
||||
// Break the array of strings into an object
|
||||
for (i = 0, l = queries.length; i < l; i++) {
|
||||
pair = queries[i].split('=');
|
||||
parameters[pair[0]] = pair[1];
|
||||
}
|
||||
|
||||
return parameters
|
||||
};
|
||||
|
||||
window.identifyUser = function(userID, email, username) {
|
||||
analytics.identify(userID, {
|
||||
email: email,
|
||||
|
||||
@@ -61,16 +61,16 @@
|
||||
next = decodeURIComponent(next);
|
||||
}
|
||||
if (next && !isExternal(next)) {
|
||||
location.href=appendParameter(next, "signin", "return");
|
||||
location.href=next;
|
||||
} else if(json.redirect_url){
|
||||
location.href=appendParameter(json.redirect_url, "signin", "return");
|
||||
location.href=json.redirect_url;
|
||||
} else {
|
||||
location.href=appendParameter("${reverse('dashboard')}", "signin", "return");
|
||||
location.href="${reverse('dashboard')}";
|
||||
}
|
||||
} else if(json.hasOwnProperty('redirect')) {
|
||||
var u=decodeURI(window.location.search);
|
||||
if (!isExternal(json.redirect)) { // a paranoid check. Our server is the one providing json.redirect
|
||||
location.href=appendParameter(json.redirect+u, "signin", "return");
|
||||
location.href=json.redirect+u;
|
||||
} // else we just remain on this page, which is fine since this particular path implies a login failure
|
||||
// that has been generated via packet tampering (json.redirect has been messed with).
|
||||
} else {
|
||||
@@ -105,7 +105,7 @@
|
||||
|
||||
function thirdPartySignin(event, url) {
|
||||
event.preventDefault();
|
||||
window.location.href = appendParameter(url, "signin", "return");
|
||||
window.location.href = url;
|
||||
}
|
||||
|
||||
(function post_form_if_pipeline_running(pipeline_running) {
|
||||
|
||||
@@ -55,7 +55,7 @@
|
||||
|
||||
$('#register-form').on('ajax:success', function(event, json, xhr) {
|
||||
var url = json.redirect_url || "${reverse('dashboard')}";
|
||||
location.href = appendParameter(url, "signin", "initial");
|
||||
location.href = url;
|
||||
});
|
||||
|
||||
$('#register-form').on('ajax:error', function(event, jqXHR, textStatus) {
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
% if settings.FEATURES.get('SEGMENT_IO_LMS'):
|
||||
<!-- begin Segment.io -->
|
||||
<%! from django.core.urlresolvers import reverse %>
|
||||
|
||||
<script type="text/javascript">
|
||||
// Asynchronously load Segment.io's analytics.js library
|
||||
window.analytics||(window.analytics=[]),window.analytics.methods=["identify","track","trackLink","trackForm","trackClick","trackSubmit","page","pageview","ab","alias","ready","group","on","once","off"],window.analytics.factory=function(t){return function(){var a=Array.prototype.slice.call(arguments);return a.unshift(t),window.analytics.push(a),window.analytics}};for(var i=0;i<window.analytics.methods.length;i++){var method=window.analytics.methods[i];window.analytics[method]=window.analytics.factory(method)}window.analytics.load=function(t){var a=document.createElement("script");a.type="text/javascript",a.async=!0,a.src=("https:"===document.location.protocol?"https://":"http://")+"d2dq2ahtl5zl1z.cloudfront.net/analytics.js/v1/"+t+"/analytics.min.js";var n=document.getElementsByTagName("script")[0];n.parentNode.insertBefore(a,n)},window.analytics.SNIPPET_VERSION="2.0.8",
|
||||
@@ -9,11 +7,7 @@
|
||||
analytics.page();
|
||||
|
||||
% if user.is_authenticated():
|
||||
// Access the query string, stripping the leading "?"
|
||||
var queryString = window.location.search.substring(1);
|
||||
|
||||
window.identifyUser("${user.id}", "${user.email}", "${user.username}");
|
||||
|
||||
% endif
|
||||
|
||||
// Get current page URL
|
||||
|
||||
Reference in New Issue
Block a user