Skip to content

Commit ef6df4b

Browse files
authored
Merge pull request #52 from santosh1994/custom-jquery-option
Custom jquery option
2 parents 9d98388 + e679034 commit ef6df4b

File tree

2 files changed

+40
-7
lines changed

2 files changed

+40
-7
lines changed

test/search/jqueryVersion.spec.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
describe('jQuery version', function() {
2+
3+
it('jQuery version - check minimum jQuery version required', function() {
4+
var validVersions = ['1.7.0', '1.11.1'];
5+
var inValidVersions = ['1.4.0', '0.7.1'];
6+
validVersions.forEach(function(version) {
7+
expect(window.Unbxd.isJqueryRequiredVersion(version)).to.be.true;
8+
});
9+
10+
inValidVersions.forEach(function(version) {
11+
expect(window.Unbxd.isJqueryRequiredVersion(version)).to.be.false;
12+
});
13+
});
14+
});

unbxdSearch.js

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//uglifyjs unbxdSearch.js -o unbxdSearch.min.js && gzip -c unbxdSearch.min.js > unbxdSearch.min.js.gz && aws s3 cp unbxdSearch.min.js.gz s3://unbxd/unbxdSearch.js --grants read=uri=http://acs.amazonaws.com/groups/global/AllUsers --content-encoding gzip --cache-control max-age=3600
22
var unbxdSearchInit = function(jQuery, Handlebars){
33
window.Unbxd = window.Unbxd || {};
4-
Unbxd.jsSdkVersion = "1.0.9";
4+
Unbxd.jsSdkVersion = "1.0.10";
55

66
// Production steps of ECMA-262, Edition 5, 15.4.4.14
77
// Reference: http://es5.github.io/#x15.4.4.14
@@ -1981,12 +1981,31 @@ var unbxdSearchInit = function(jQuery, Handlebars){
19811981
});
19821982
};
19831983

1984-
if(!window.jQuery || !window.Handlebars)
1985-
throw "Please include jQuery & Handlebars libraries before loading unbxdSearch.js";
19861984

1987-
var arr = jQuery.fn.jquery.split('.');
1988-
if( arr[0] < 1 || (arr[0] == 1 && arr[1] < 7) )
1989-
throw "jQuery version needs to be greater than 1.7 to use unbxdSearch.js. You can pass custom jQuery & Handlebars by calling unbxdSeachInit(jQuery, Handlebars)";
1985+
Unbxd = window.Unbxd || {};
19901986

1987+
Unbxd.isJqueryRequiredVersion = Unbxd.isJqueryRequiredVersion ||
1988+
function isJqueryRequiredVersion(current) {
1989+
var jQueryVersion = current.split('.');
1990+
jQueryVersion = jQueryVersion.map(function convertToNumber(version) {
1991+
return Number(version);
1992+
});
1993+
if (
1994+
jQueryVersion[0] > 1 || (jQueryVersion[0] === 1 && jQueryVersion[1] >= 7)
1995+
) {
1996+
return true;
1997+
}
1998+
return false;
1999+
};
19912000

1992-
unbxdSearchInit(jQuery, Handlebars);
2001+
if (!window.jQuery || !window.Handlebars) {
2002+
console.error(
2003+
'Please include jQuery & Handlebars libraries before loading unbxdSearch.js or You can pass custom jQuery & Handlebars by calling unbxdSeachInit(jQuery, Handlebars) '
2004+
);
2005+
} else if (!Unbxd.isJqueryRequiredVersion(jQuery.fn.jquery)) {
2006+
console.error(
2007+
'jQuery version needs to be greater than 1.7 to use unbxdSearch.js. You can pass custom jQuery & Handlebars by calling unbxdSeachInit(jQuery, Handlebars)'
2008+
);
2009+
} else {
2010+
unbxdSearchInit(jQuery, Handlebars);
2011+
}

0 commit comments

Comments
 (0)