Created
February 19, 2015 18:46
-
-
Save singerxt/edf38fe3089bdfcb8d42 to your computer and use it in GitHub Desktop.
gigya patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Gigya Patch Module | |
* | |
* 'use strict'; | |
* // variables to be ignored by JSHint' | |
* | |
* define([optional dependencies], function(dependencies reference in the same order) { | |
* // You can return any type of objects, functions or variables | |
* return { | |
* foo: function() {...} | |
* } | |
* }); | |
*/ | |
'use strict'; | |
/* global define, gigya */ | |
define(['modules/gigya/common'], function(gigyaCommon) { | |
var gigyaPatch = { | |
init: function () { | |
var self = this; | |
gigyaCommon.ready(function() { | |
//self.initPatchErrors(); // this was breaking the whole site TODO FIXME | |
// I guess is good to get rid of it since Gigya changed the 'contract' (software term) in their interfaces | |
// patch the code outside their 'supported' scope | |
self.removeGigyaStyles(); | |
}); | |
}, | |
initPatchErrors: function () { | |
var originalFunction = gigya.global.JPCMD.prototype.handleResponse, | |
originalFunctionString = originalFunction.toString(); | |
/*jshint evil: true */ | |
gigya.global.JPCMD.prototype.originalHanldeJPResponse = new Function(/\(([\s\S]*?)\)/.exec(originalFunction)[1], originalFunctionString.substring(originalFunctionString.indexOf('{') + 1, originalFunctionString.lastIndexOf('}'))); | |
/*jshint evil: false */ | |
gigya.global.JPCMD.prototype.handleResponse = function (a, b) { | |
gigya.global.JPCMD.prototype.originalHanldeJPResponse(a, b); | |
if (a.errorCode && a.errorCode !== 0 && a.errorCode !== 206001 && a.errorCode !== 206002) { | |
gigyaCommon.setError((a.errorDetails || a.errorMessage), a.errorCode); | |
} | |
}; | |
}, | |
removeGigyaStyles: function () { | |
var stylesRemoved = 0, | |
stylesTimer = setInterval(function () { | |
Array.prototype.forEach.call(document.querySelectorAll('style'), function(item) { | |
if (item.textContent.match('.gigya-') && !item.textContent.match('.gigya-reset')) { | |
item.parentNode.removeChild(item); | |
stylesRemoved += 1; | |
} | |
}); | |
if (stylesRemoved >= 1) { | |
clearInterval(stylesTimer); | |
} | |
}, 50); | |
}, | |
patchScreens: function (forScreens) { | |
// This is unbelievably hacky way of putting auto-showing dialogs into FOX popup, however it can't done other way because gigya doesn't allow it | |
setInterval(function () { | |
var startScreen = document.querySelector('.gigya-screen-dialog .gigya-screen, .gigya-screen-dialog-mobile .gigya-screen'), | |
toReplace; | |
if (startScreen && forScreens.indexOf(startScreen.getAttribute('id')) > -1) { | |
toReplace = document.querySelector('#gigyaContainer_content > div'); | |
toReplace.parentNode.appendChild(document.querySelector('.gigya-screen-dialog #' + startScreen.getAttribute('id') + ', .gigya-screen-dialog-mobile #' + startScreen.getAttribute('id'))); | |
toReplace.parentNode.removeChild(toReplace); | |
document.querySelector('.gigya-screen-dialog, .gigya-screen-dialog-mobile').style.display = 'none'; | |
} | |
if (this.gigya && this.gigya.i18n && !this.newTextSetted) { | |
/* jshint camelcase:false */ | |
this.gigya.i18n['gigya.services.accounts.plugins.screenSet.js'].en.password_does_not_meet_complexity_requirements = 'Password has to be at least 6 characters long.'; | |
this.newTextSetted = true; | |
} | |
}, 50); | |
} | |
}; | |
return gigyaPatch; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment