Merge branch 'master' into jsrefactor and fixing baseUri unit test

This commit is contained in:
El RIDO 2017-03-05 12:11:55 +01:00
commit fb99d5bb93
No known key found for this signature in database
GPG key ID: 0F5C940A6BD81F92
13 changed files with 195 additions and 51 deletions

View file

@ -36,11 +36,9 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
/**
* static Helper methods
*
* @param {object} window
* @param {object} document
* @class
*/
var Helper = (function (window, document) {
var Helper = (function () {
var me = {};
/**
@ -278,14 +276,19 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
return baseUri;
}
// get official base uri string, from base tag in head of HTML
baseUri = document.baseURI;
// window.baseURI isn't emulated by JSdom
var loc = window.location;
baseUri = loc.href.substring(
0,
loc.href.length - loc.search.length - loc.hash.length
);
// if base uri contains query string (when no base tag is present),
// it is unwanted
if (baseUri.indexOf('?')) {
var queryIndex = baseUri.indexOf('?');
if (queryIndex !== -1) {
// so we built our own baseuri
baseUri = window.location.origin + window.location.pathname;
baseUri = baseUri.substring(0, queryIndex);
}
return baseUri;
@ -307,8 +310,19 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
});
}
/**
* resets state, used for unit testing
*
* @name Model.reset
* @function
*/
me.reset = function()
{
baseUri = null;
}
return me;
})(window, document);
})();
/**
* internationalization module
@ -336,7 +350,7 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
* @prop {string[]}
* @readonly
*/
var supportedLanguages = ['de', 'es', 'fr', 'it', 'no', 'pl', 'oc', 'ru', 'sl', 'zh'];
var supportedLanguages = ['de', 'es', 'fr', 'it', 'no', 'pl', 'pt', 'oc', 'ru', 'sl', 'zh'];
/**
* built in language
@ -491,7 +505,7 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
return (n % 10 === 1 && n % 100 !== 11 ? 0 : (n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2));
case 'sl':
return (n % 100 === 1 ? 1 : (n % 100 === 2 ? 2 : (n % 100 === 3 || n % 100 === 4 ? 3 : 0)));
// de, en, es, it, no
// de, en, es, it, no, pt
default:
return (n !== 1 ? 1 : 0);
}