Skip to content

Commit d89ce93

Browse files
committed
internal refactoring
1 parent 9812697 commit d89ce93

File tree

1 file changed

+49
-21
lines changed

1 file changed

+49
-21
lines changed

angular-web-notification.js

Lines changed: 49 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,50 @@
6868
};
6969
};
7070

71+
/**
72+
* @ngdoc method
73+
* @function
74+
* @memberof! webNotification
75+
* @alias webNotification.parseInput
76+
* @private
77+
*
78+
* @description
79+
* Returns an object with the show notification input.
80+
*
81+
* @param {array} argumentsArray - An array of all arguments provided to the show notification function
82+
* @returns {object} The parsed data
83+
*/
84+
var parseInput = function (argumentsArray) {
85+
//callback is always the last argument
86+
var callback = argumentsArray.pop();
87+
88+
var title = null;
89+
var options = null;
90+
if (argumentsArray.length === 2) {
91+
title = argumentsArray[0];
92+
options = argumentsArray[1];
93+
} else if (argumentsArray.length === 1) {
94+
var value = argumentsArray.pop();
95+
if (typeof value === 'string') {
96+
title = value || '';
97+
options = {};
98+
} else {
99+
title = '';
100+
options = value;
101+
}
102+
}
103+
104+
//set defaults
105+
title = title || '';
106+
options = options || {};
107+
108+
return {
109+
callback: callback,
110+
title: title,
111+
options: options
112+
};
113+
};
114+
71115
var service = {
72116
/**
73117
* True to enable automatic requesting of permissions if needed.
@@ -110,28 +154,12 @@
110154
var argumentsArray = Array.prototype.slice.call(arguments, 0);
111155

112156
if ((argumentsArray.length >= 1) && (argumentsArray.length <= 3)) {
113-
//callback is always the last argument
114-
var callback = argumentsArray.pop();
115-
116-
var title = null;
117-
var options = null;
118-
if (argumentsArray.length === 2) {
119-
title = argumentsArray[0];
120-
options = argumentsArray[1];
121-
} else if (argumentsArray.length === 1) {
122-
var value = argumentsArray.pop();
123-
if (typeof value === 'string') {
124-
title = value || '';
125-
options = {};
126-
} else {
127-
title = '';
128-
options = value;
129-
}
130-
}
157+
var data = parseInput(argumentsArray);
131158

132-
//set defaults
133-
title = title || '';
134-
options = options || {};
159+
//get values
160+
var callback = data.callback;
161+
var title = data.title;
162+
var options = data.options;
135163

136164
var hideNotification = null;
137165
if (isEnabled()) {

0 commit comments

Comments
 (0)