Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#13 ES5 syntax for utils #15

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 25 additions & 13 deletions base64url/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@
*
* @returns base64url {String} : a base64url encoded string
*/
const encodeBase64URL = (dataStr) => {
let base64 = window.btoa(dataStr);
let base64url = base64.split('=')[0]; // Remove any trailing '='s
var encodeBase64URL = function encodeBase64URL(dataStr) {
var base64 = window.btoa(dataStr);
var base64url = base64.split('=')[0]; // Remove any trailing '='s

base64url = base64url.replace(/\+/g, '-'); // 62nd char of encoding

base64url = base64url.replace(/\//g, '_'); // 63rd char of encoding

return base64url;
Expand All @@ -35,22 +36,33 @@ const encodeBase64URL = (dataStr) => {
*
* @returns {String} - a regular string
*/
const decodeBase64URL = (str) => {
let base64 = str;
var decodeBase64URL = function decodeBase64URL(str) {
var base64 = str;
base64 = base64.replace(/-/g, '+'); // 62nd char of encoding

base64 = base64.replace(/_/g, '/'); // 63rd char of encoding
switch (base64.length % 4) // Pad with trailing '='s
{

switch (base64.length % 4) {
// Pad with trailing '='s
case 0:
break; // No pad chars in this case
break;
// No pad chars in this case

case 2:
base64 += "=="; break; // Two pad chars
base64 += "==";
break;
// Two pad chars

case 3:
base64 += "="; break; // One pad char
base64 += "=";
break;
// One pad char

default:
if(window.console && window.console.log){
if (window.console && window.console.log) {
window.console.log('### base64url::decodeBase64URL:: Illegal base64url string!');
}

}

try {
Expand All @@ -60,8 +72,8 @@ const decodeBase64URL = (str) => {
}
};

const base64URL = {
encode : encodeBase64URL,
var base64URL = {
encode: encodeBase64URL,
decode: decodeBase64URL
};

Expand Down
41 changes: 18 additions & 23 deletions browser/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,34 +9,29 @@
*
* @returns {Object} - browserInfo an object containing the retrieved browser properties
*/
const collectBrowserInfo = () => {
var collectBrowserInfo = function collectBrowserInfo() {
var screenWidth = window && window.screen ? window.screen.width : '';
var screenHeight = window && window.screen ? window.screen.height : '';
var colorDepth = window && window.screen ? window.screen.colorDepth : '';
var userAgent = window && window.navigator ? window.navigator.userAgent : '';
var javaEnabled = window && window.navigator ? navigator.javaEnabled() : false;
var language = '';

const screenWidth = window && window.screen ? window.screen.width : '';
const screenHeight = window && window.screen ? window.screen.height : '';
const colorDepth = window && window.screen ? window.screen.colorDepth : '';
const userAgent = window && window.navigator ? window.navigator.userAgent : '';
const javaEnabled = window && window.navigator ? navigator.javaEnabled() : false;

let language = '';
if (window && window.navigator) {
language = window.navigator.language
? window.navigator.language
: window.navigator.browserLanguage; // Else is for IE <+ 10
language = window.navigator.language ? window.navigator.language : window.navigator.browserLanguage; // Else is for IE <+ 10
}

const d = new Date();
const timeZoneOffset = d.getTimezoneOffset();

const browserInfo = {
screenWidth,
screenHeight,
colorDepth,
userAgent,
timeZoneOffset,
language,
javaEnabled,
var d = new Date();
var timeZoneOffset = d.getTimezoneOffset();
var browserInfo = {
screenWidth: screenWidth,
screenHeight: screenHeight,
colorDepth: colorDepth,
userAgent: userAgent,
timeZoneOffset: timeZoneOffset,
language: language,
javaEnabled: javaEnabled
};

return browserInfo;
};

Expand Down
2 changes: 1 addition & 1 deletion dist/threeds2-js-utils.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 5 additions & 6 deletions form/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
*
* @returns {Element} - Created form element
*/
const createForm = (name, action, target, inputName, inputValue) => {

var createForm = function createForm(name, action, target, inputName, inputValue) {
if (!name || !action || !target || !inputName || !inputValue) {
throw new Error('Not all required parameters provided for form creation');
}
Expand All @@ -21,16 +20,16 @@ const createForm = (name, action, target, inputName, inputValue) => {
throw new Error('Not all required parameters have suitable values');
}

const form = document.createElement( 'form' );
var form = document.createElement('form');
form.style.display = 'none';
form.name = name;
form.action = action;
form.method = "POST";
form.method = 'POST';
form.target = target;
const input = document.createElement( 'input' );
var input = document.createElement('input');
input.name = inputName;
input.value = inputValue;
form.appendChild( input );
form.appendChild(input);
return form;
};

Expand Down
31 changes: 15 additions & 16 deletions iframe/index.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
const configObject = {};
var configObject = {};
configObject.container = void 0;

const addIframeListener = (iframe, callback) => {
if (iframe.attachEvent){
var addIframeListener = function addIframeListener(iframe, callback) {
if (iframe.attachEvent) {
// IE fallback
iframe.attachEvent("onload", function(){
iframe.attachEvent("onload", function () {
if (callback && typeof callback === "function") {
callback(iframe.contentWindow);
}
});
} else {
iframe.onload = function(){
iframe.onload = function () {
if (callback && typeof callback === "function") {
callback(iframe.contentWindow);
}
Expand All @@ -31,34 +31,33 @@ const addIframeListener = (iframe, callback) => {
*
* @returns {Element} - Created iframe element
*/
const createIframe = (container, name, width = '0', height = '0', callback) => {
if (!name || name.length === 0){
var createIframe = function createIframe(container, name) {
var width = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '0';
var height = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : '0';
var callback = arguments.length > 4 ? arguments[4] : undefined;

if (!name || name.length === 0) {
throw new Error('Name parameter missing for iframe');
}
} // Resolve holding element for generated iframe else default to body


// Resolve holding element for generated iframe else default to body
if (container instanceof HTMLElement) {
configObject.container = container;
} else {
configObject.container = document.body;
}

const iframe = document.createElement('iframe');

var iframe = document.createElement('iframe');
iframe.classList.add(name + 'Class');
iframe.width = width;
iframe.height = height;
iframe.name = name;
iframe.setAttribute('frameborder', '0');
iframe.setAttribute('border', '0');

const noIframeElContent = document.createTextNode('<p>Your browser does not support iframes.</p>');
var noIframeElContent = document.createTextNode('<p>Your browser does not support iframes.</p>');
iframe.appendChild(noIframeElContent);

configObject.container.appendChild(iframe);

addIframeListener(iframe, callback);

return iframe;
};

Expand Down