|
68 | 68 | };
|
69 | 69 | };
|
70 | 70 |
|
| 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 | + |
71 | 115 | var service = {
|
72 | 116 | /**
|
73 | 117 | * True to enable automatic requesting of permissions if needed.
|
|
110 | 154 | var argumentsArray = Array.prototype.slice.call(arguments, 0);
|
111 | 155 |
|
112 | 156 | 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); |
131 | 158 |
|
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; |
135 | 163 |
|
136 | 164 | var hideNotification = null;
|
137 | 165 | if (isEnabled()) {
|
|
0 commit comments