|
66 | 66 | , SHORT_DAYS = {}
|
67 | 67 | , EXACT_DATE_TIME = {};
|
68 | 68 |
|
69 |
| - // if node, require the file system module |
70 |
| - if (typeof window === 'undefined' && typeof require === 'function') { |
71 |
| - var nodefs = require('fs'); |
72 |
| - } |
73 |
| - |
74 | 69 | //`{ "Jan": 0, "Feb": 1, "Mar": 2, "Apr": 3, "May": 4, "Jun": 5, "Jul": 6, "Aug": 7, "Sep": 8, "Oct": 9, "Nov": 10, "Dec": 11 }`
|
75 | 70 | for (var i = 0; i < MONTHS.length; i++) {
|
76 | 71 | SHORT_MONTHS[MONTHS[i].substr(0, 3)] = i;
|
|
153 | 148 | // - `error`: error callback function
|
154 | 149 | // Returns response from URL if async is false, otherwise the AJAX request object itself
|
155 | 150 | var _transport = function (opts) {
|
| 151 | + if (!opts) return; |
| 152 | + if (!opts.url) throw new Error ('URL must be specified'); |
| 153 | + if (!('async' in opts)) opts.async = true; |
| 154 | + |
156 | 155 | // Server-side (node)
|
157 |
| - if (nodefs) { |
| 156 | + // if node, require the file system module |
| 157 | + if (typeof window === 'undefined' && typeof require === 'function') { |
| 158 | + var nodefs = require('fs'); |
158 | 159 | if (opts.async) {
|
159 | 160 | // No point if there's no success handler
|
160 | 161 | if (typeof opts.success !== 'function') return;
|
|
165 | 166 | }
|
166 | 167 | return nodefs.readFileSync(opts.url, 'utf8');
|
167 | 168 | }
|
| 169 | + |
168 | 170 | // Client-side
|
169 |
| - else { |
170 |
| - if ((!fleegix || typeof fleegix.xhr === 'undefined') && (!ajax_lib || typeof ajax_lib.ajax === 'undefined')) { |
171 |
| - throw new Error('Please use the Fleegix.js XHR module, jQuery ajax, Zepto ajax, or define your own transport mechanism for downloading zone files.'); |
172 |
| - } |
173 |
| - if (!opts) return; |
174 |
| - if (!opts.url) throw new Error ('URL must be specified'); |
175 |
| - if (!('async' in opts)) opts.async = true; |
176 |
| - if (!opts.async) { |
177 |
| - return fleegix && fleegix.xhr |
178 |
| - ? fleegix.xhr.doReq({ url: opts.url, async: false }) |
179 |
| - : ajax_lib.ajax({ url : opts.url, async : false, dataType: 'text' }).responseText; |
180 |
| - } |
| 171 | + if ((!fleegix || typeof fleegix.xhr === 'undefined') && (!ajax_lib || typeof ajax_lib.ajax === 'undefined')) { |
| 172 | + throw new Error('Please use the Fleegix.js XHR module, jQuery ajax, Zepto ajax, or define your own transport mechanism for downloading zone files.'); |
| 173 | + } |
| 174 | + if (!opts.async) { |
181 | 175 | return fleegix && fleegix.xhr
|
182 |
| - ? fleegix.xhr.send({ |
183 |
| - url : opts.url, |
184 |
| - method : 'get', |
185 |
| - handleSuccess : opts.success, |
186 |
| - handleErr : opts.error |
187 |
| - }) |
188 |
| - : ajax_lib.ajax({ |
189 |
| - url : opts.url, |
190 |
| - dataType: 'text', |
191 |
| - method : 'GET', |
192 |
| - error : opts.error, |
193 |
| - success : opts.success |
194 |
| - }); |
| 176 | + ? fleegix.xhr.doReq({ url: opts.url, async: false }) |
| 177 | + : ajax_lib.ajax({ url : opts.url, async : false, dataType: 'text' }).responseText; |
195 | 178 | }
|
| 179 | + return fleegix && fleegix.xhr |
| 180 | + ? fleegix.xhr.send({ |
| 181 | + url : opts.url, |
| 182 | + method : 'get', |
| 183 | + handleSuccess : opts.success, |
| 184 | + handleErr : opts.error |
| 185 | + }) |
| 186 | + : ajax_lib.ajax({ |
| 187 | + url : opts.url, |
| 188 | + dataType: 'text', |
| 189 | + method : 'GET', |
| 190 | + error : opts.error, |
| 191 | + success : opts.success |
| 192 | + }); |
196 | 193 | };
|
197 | 194 |
|
198 | 195 | // Constructor, which is similar to that of the native Date object itself
|
|
0 commit comments