Skip to content

Commit

Permalink
Merge pull request #117 from opencomponents/remove-ie9-support
Browse files Browse the repository at this point in the history
remove ie9 support
  • Loading branch information
ricardo-devis-agullo authored Aug 26, 2024
2 parents e81f9a1 + e915f58 commit e9ccab8
Show file tree
Hide file tree
Showing 4 changed files with 191 additions and 197 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
],
"rules": {
"@typescript-eslint/no-var-requires": "off",
"@typescript-eslint/no-empty-function": "off"
"@typescript-eslint/no-empty-function": "off",
"no-shadow": "error"
},
"globals": {
"oc": true,
Expand Down
130 changes: 51 additions & 79 deletions src/oc-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ var oc = oc || {};
// The code
var $,
noop = function () {},
nav = $window.navigator.userAgent,
is9 = !!nav.match(/MSIE 9/),
initialised = false,
initialising = false,
retries = {},
Expand All @@ -58,31 +56,24 @@ var oc = oc || {};
isFunction = function (a) {
return typeof a == 'function';
},
timeout = setTimeout,
ocCmd = oc.cmd,
ocConf = oc.conf,
renderedComponents = oc.renderedComponents,
firstPlaceholder = '{0}',
secondPlaceholder = '{1}',
dataRenderedAttribute = 'data-rendered',
dataRenderingAttribute = 'data-rendering';

var logger = {
error: function (msg) {
// eslint-disable-next-line no-console
return console.log(msg);
dataRenderingAttribute = 'data-rendering',
error = function (msg) {
console.log(msg);
},
info: function (msg) {
// eslint-disable-next-line no-console
return ocConf.debug ? console.log(msg) : false;
}
};
info = function (msg) {
ocConf.debug && console.log(msg);
};

// constants
var CDNJS_BASEURL = 'https://cdnjs.cloudflare.com/ajax/libs/',
IE9_AJAX_POLYFILL_URL =
CDNJS_BASEURL +
'jquery-ajaxtransport-xdomainrequest/1.0.3/jquery.xdomainrequest.min.js',
JQUERY_URL = CDNJS_BASEURL + 'jquery/3.6.0/jquery.min.js',
var JQUERY_URL =
'https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js',
RETRY_INTERVAL = ocConf.retryInterval || __DEFAULT_RETRY_INTERVAL__,
RETRY_LIMIT = ocConf.retryLimit || __DEFAULT_RETRY_LIMIT__,
DISABLE_LOADER = isBool(ocConf.disableLoader)
Expand Down Expand Up @@ -130,31 +121,22 @@ var oc = oc || {};
}

var retry = function (component, cb, failedRetryCb) {
if (retries[component] === undefined) {
if (retries[component] == undefined) {
retries[component] = RETRY_LIMIT;
}

if (retries[component] <= 0) {
return failedRetryCb();
}

setTimeout(function () {
timeout(function () {
cb(RETRY_LIMIT - retries[component] + 1);
}, RETRY_INTERVAL);
retries[component]--;
};

var addParametersToHref = function (href, parameters) {
if (href && parameters) {
var param = $.param(parameters);
if (href.indexOf('?') > -1) {
return href + '&' + param;
} else {
return href + '?' + param;
}
}

return href;
return href + (~href.indexOf('?') ? '&' : '?') + $.param(parameters);
};

var getHeaders = function () {
Expand Down Expand Up @@ -241,7 +223,7 @@ var oc = oc || {};
loaded = [];
}

if (toLoad.length == 0) {
if (!toLoad.length) {
return callback();
}

Expand Down Expand Up @@ -316,15 +298,13 @@ var oc = oc || {};
crossDomain: true,
success: function (apiResponse) {
var response = apiResponse[0].response;
if (response.renderMode === 'rendered') {
if (response.renderMode == 'rendered') {
return cb(MESSAGES_ERRORS_GETTING_DATA);
}
var error = response.error ? response.details || response.error : null;
return cb(error, response.data, apiResponse[0]);
var err = response.error ? response.details || response.error : null;
return cb(err, response.data, apiResponse[0]);
},
error: function (err) {
return cb(err);
}
error: cb
};
if (jsonRequest) {
ajaxOptions.dataType = 'json';
Expand Down Expand Up @@ -412,14 +392,6 @@ var oc = oc || {};
} else {
initialising = true;

var requirePolyfills = function ($, cb) {
if (is9 && !$.IE_POLYFILL_LOADED) {
oc.require(IE9_AJAX_POLYFILL_URL, cb);
} else {
cb();
}
};

var done = function () {
initialised = true;
initialising = false;
Expand Down Expand Up @@ -458,14 +430,12 @@ var oc = oc || {};

oc.require('jQuery', JQUERY_URL, function (jQuery) {
oc.requireSeries(externals, function () {
requirePolyfills(jQuery, function () {
if (wasJqueryThereAlready || wasDollarThereAlready) {
$ = oc.$ = jQuery;
} else {
$ = oc.$ = jQuery.noConflict();
}
done();
});
if (wasJqueryThereAlready || wasDollarThereAlready) {
$ = oc.$ = jQuery;
} else {
$ = oc.$ = jQuery.noConflict();
}
done();
});
});
}
Expand All @@ -474,7 +444,7 @@ var oc = oc || {};
oc.render = function (compiledViewInfo, model, callback) {
oc.ready(function () {
// TODO: integrate with oc-empty-response-handler module
if (model && model.__oc_emptyResponse === true) {
if (model && model.__oc_emptyResponse == true) {
return callback(null, '');
}

Expand All @@ -500,10 +470,12 @@ var oc = oc || {};
asyncRequireForEach(template.externals, function () {
if (type == 'oc-template-handlebars') {
try {
var linked = $window.Handlebars.template(compiledView, []);
callback(null, linked(model));
callback(
null,
$window.Handlebars.template(compiledView, [])(model)
);
} catch (e) {
callback(e.toString());
callback('' + e);
}
} else {
callback(null, compiledView(model));
Expand Down Expand Up @@ -537,7 +509,7 @@ var oc = oc || {};
: dataRendered == 'true';

if (!isRendering && !isRendered) {
logger.info(MESSAGES_RETRIEVING);
info(MESSAGES_RETRIEVING);
attr(dataRenderingAttribute, true);
if (!DISABLE_LOADER) {
$component.html(
Expand All @@ -549,24 +521,24 @@ var oc = oc || {};
{ href: attr('href'), id: attr('id') },
function (err, data) {
if (err || !data) {
attr(dataRenderingAttribute, 'false');
attr(dataRenderedAttribute, 'false');
attr('data-failed', 'true');
attr(dataRenderingAttribute, false);
attr(dataRenderedAttribute, false);
attr('data-failed', true);
$component.html('');
oc.events.fire('oc:failed', {
originalError: err,
data: data,
component: $component[0]
});
logger.error(err);
error(err);
return callback();
}

processHtml($component, data, callback);
}
);
} else {
setTimeout(callback, POLLING_INTERVAL);
timeout(callback, POLLING_INTERVAL);
}
});
};
Expand All @@ -588,20 +560,21 @@ var oc = oc || {};
}

oc.ready(function () {
if (href !== '') {
var extraParams = RETRY_SEND_NUMBER ? { __oc_Retry: retryNumber } : {};
var finalisedHref = addParametersToHref(
href,
$.extend({}, ocConf.globalParameters, extraParams)
);

if (href) {
$.ajax({
url: finalisedHref,
url: addParametersToHref(
href,
$.extend(
{},
ocConf.globalParameters,
RETRY_SEND_NUMBER && { __oc_Retry: retryNumber }
)
),
headers: getHeaders(),
contentType: 'text/plain',
crossDomain: true,
success: function (apiResponse) {
if (apiResponse.renderMode === 'unrendered') {
if (apiResponse.renderMode == 'unrendered') {
apiResponse.data.id = id;
oc.render(
apiResponse.template,
Expand All @@ -615,7 +588,7 @@ var oc = oc || {};
).replace(secondPlaceholder, err)
);
}
logger.info(
info(
MESSAGES_RENDERED.replace(
firstPlaceholder,
apiResponse.template.src
Expand All @@ -631,8 +604,8 @@ var oc = oc || {};
});
}
);
} else if (apiResponse.renderMode === 'rendered') {
logger.info(
} else if (apiResponse.renderMode == 'rendered') {
info(
MESSAGES_RENDERED.replace(firstPlaceholder, apiResponse.href)
);

Expand All @@ -654,10 +627,9 @@ var oc = oc || {};
});
}
},
error: function (error) {
var status = error && error.status;
if (status === 429) retries[href] = 0;
logger.error(MESSAGES_ERRORS_RETRIEVING);
error: function (err) {
if (err && err.status == 429) retries[href] = 0;
error(MESSAGES_ERRORS_RETRIEVING);
retry(
href,
function (requestNumber) {
Expand Down
14 changes: 2 additions & 12 deletions tasks/karma.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,6 @@ const customLaunchers = {
platform: 'Windows 8',
version: '10'
},
ie9: {
base: 'SauceLabs',
browserName: 'internet explorer',
platform: 'Windows 7',
version: '9'
},
safari: {
base: 'SauceLabs',
browserName: 'Safari',
Expand Down Expand Up @@ -86,12 +80,8 @@ module.exports = {
browsers: ['chrome', 'ff', 'android']
},
'sauce-windows': {
customLaunchers: _.pick(customLaunchers, 'edge14', 'ie11', 'ie10', 'ie9'),
browsers: ['edge14', 'ie11', 'ie10', 'ie9']
},
'sauce-ie9': {
customLaunchers: _.pick(customLaunchers, 'ie9'),
browsers: ['ie9']
customLaunchers: _.pick(customLaunchers, 'edge14', 'ie11'),
browsers: ['edge14', 'ie11']
},
'sauce-osx': {
customLaunchers: _.pick(customLaunchers, 'safari', 'iphone', 'ipad'),
Expand Down
Loading

0 comments on commit e9ccab8

Please sign in to comment.