Skip to content

Commit a949457

Browse files
committed
- new version
- added sessionId - fixed minor jQuery instanceof bug - added url to default values
1 parent d359ec1 commit a949457

File tree

4 files changed

+43
-12
lines changed

4 files changed

+43
-12
lines changed

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "breinify-api",
3-
"version": "1.0.3",
3+
"version": "1.0.4",
44
"description": "This is a JavaScript library simplifying the usage of the Breinify API",
55
"authors": [
66
"Philipp Meisen <philipp@breinify.com>",

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "breinify-api",
3-
"version": "1.0.3",
3+
"version": "1.0.4",
44
"description": "This is a JavaScript library simplifying the usage of the Breinify API",
55
"authors": [
66
"Philipp Meisen <philipp@breinify.com>",

src/BreinifyUser.js

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@
4949
group: 4,
5050
optional: false
5151
});
52+
attributes.add('SESSIONID', {
53+
name: 'sessionId',
54+
group: 5,
55+
optional: false
56+
});
5257
attributes.add('additional', {
5358
validate: function (value) {
5459
return typeof value === 'undefined' || $.isPlainObject(value);
@@ -103,12 +108,29 @@
103108

104109
// set the user-agent to a default value if there isn't one yet
105110
if (instance.read('userAgent') === null) {
106-
instance.add('userAgent', navigator.userAgent);
111+
var userAgent = navigator.userAgent;
112+
113+
if (!BreinifyUtil.isEmpty(userAgent)) {
114+
instance.add('userAgent', userAgent);
115+
}
107116
}
108117

109118
// set the referrer to a default value if there isn't one yet
110119
if (instance.read('referrer') === null) {
111-
instance.add('referrer', document.referrer);
120+
var referrer = document.referrer;
121+
122+
if (!BreinifyUtil.isEmpty(referrer)) {
123+
instance.add('referrer', referrer);
124+
}
125+
}
126+
127+
// also add the current URL if not provided
128+
if (instance.read('url') === null) {
129+
var url = window.location.href;
130+
131+
if (!BreinifyUtil.isEmpty(url)) {
132+
instance.add('url', url);
133+
}
112134
}
113135

114136
// try to set the location if there isn't one yet
@@ -135,7 +157,9 @@
135157
var instance = this;
136158

137159
_privates.resolveGeoLocation(function (location) {
138-
instance.add('location', location);
160+
if (!BreinifyUtil.isEmpty(location)) {
161+
instance.add('location', location);
162+
}
139163

140164
if ($.isFunction(onReady)) {
141165
onReady(instance);
@@ -191,10 +215,12 @@
191215
if (!attributes.is(attribute)) {
192216
throw new Error('The attribute "' + attribute + '" is not supported by a user.');
193217
} else if (attribute === BreinifyUser.ATTRIBUTES.EMAIL) {
194-
this.reset(attribute);
218+
this.reset(BreinifyUser.ATTRIBUTES.MD5EMAIL);
195219

196-
//noinspection JSUnresolvedFunction
197-
this.set(BreinifyUser.ATTRIBUTES.MD5EMAIL, BreinifyUtil.md5(value));
220+
if (!BreinifyUtil.isEmpty(value)) {
221+
//noinspection JSUnresolvedFunction
222+
this.set(BreinifyUser.ATTRIBUTES.MD5EMAIL, BreinifyUtil.md5(value));
223+
}
198224
} else if (attribute === BreinifyUser.ATTRIBUTES.MD5EMAIL) {
199225
var email = this.get(BreinifyUser.ATTRIBUTES.EMAIL);
200226

@@ -209,7 +235,12 @@
209235
this._user = {};
210236
}
211237

212-
this._user[attribute] = value;
238+
// if the attribute is an empty value, we reset it
239+
if (BreinifyUtil.isEmpty(value)) {
240+
this.reset(attribute);
241+
} else {
242+
this._user[attribute] = value;
243+
}
213244
},
214245

215246
reset: function (attribute) {

src/BreinifyUtil.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@
267267
},
268268

269269
select: function (cssSelector, childSelector, directChild) {
270-
var $el = cssSelector instanceof jQuery ? cssSelector : $(cssSelector);
270+
var $el = cssSelector instanceof $ ? cssSelector : $(cssSelector);
271271
directChild = typeof directChild === 'boolean' ? directChild : false;
272272

273273
if (directChild) {
@@ -278,7 +278,7 @@
278278
},
279279

280280
texts: function (cssSelector, excludeChildren) {
281-
var $el = cssSelector instanceof jQuery ? cssSelector : $(cssSelector);
281+
var $el = cssSelector instanceof $ ? cssSelector : $(cssSelector);
282282
excludeChildren = typeof excludeChildren === 'boolean' ? excludeChildren : true;
283283

284284
var result = [];
@@ -325,7 +325,7 @@
325325
},
326326

327327
setText: function(cssSelector, text) {
328-
var $el = cssSelector instanceof jQuery ? cssSelector : $(cssSelector);
328+
var $el = cssSelector instanceof $ ? cssSelector : $(cssSelector);
329329

330330
if ($el.is('input')) {
331331
$el.val(text);

0 commit comments

Comments
 (0)