|
1 | | -/*! Observe.js v0.7.1 | (c) Bunoon 2024 | MIT License */ |
| 1 | +/*! Observe.js v0.8.0 | (c) Bunoon 2024 | MIT License */ |
2 | 2 | (function() { |
3 | 3 | function collectDOMObjects() { |
4 | 4 | var tagTypes = _configuration.domElementTypes; |
|
27 | 27 | if (!isDefinedString(element.id)) { |
28 | 28 | element.id = newGuid(); |
29 | 29 | } |
30 | | - element.removeAttribute(_attribute_Name_Watch_Options); |
| 30 | + if (bindingOptions.removeAttribute) { |
| 31 | + element.removeAttribute(_attribute_Name_Watch_Options); |
| 32 | + } |
31 | 33 | createWatch(element, bindingOptions, element.id); |
32 | 34 | } else { |
33 | | - if (!_configuration.safeMode) { |
34 | | - console.error("The attribute '" + _attribute_Name_Watch_Options + "' is not a valid object."); |
35 | | - result = false; |
36 | | - } |
37 | | - } |
38 | | - } else { |
39 | | - if (!_configuration.safeMode) { |
40 | | - console.error("The attribute '" + _attribute_Name_Watch_Options + "' has not been set correctly."); |
| 35 | + logError(_configuration.attributeNotValidErrorText.replace("{{attribute_name}}", _attribute_Name_Watch_Options)); |
41 | 36 | result = false; |
42 | 37 | } |
| 38 | + } else { |
| 39 | + logError(_configuration.attributeNotSetErrorText.replace("{{attribute_name}}", _attribute_Name_Watch_Options)); |
| 40 | + result = false; |
43 | 41 | } |
44 | 42 | } |
45 | 43 | return result; |
|
206 | 204 | return result; |
207 | 205 | } |
208 | 206 | function getWatchOptions(newOptions) { |
209 | | - var options = !isDefinedObject(newOptions) ? {} : newOptions; |
| 207 | + var options = getDefaultObject(newOptions, {}); |
210 | 208 | options.timeout = getDefaultNumber(options.timeout, 250); |
211 | 209 | options.starts = getDefaultDate(options.starts, null); |
212 | 210 | options.expires = getDefaultDate(options.expires, null); |
|
217 | 215 | options.propertyNames = getDefaultArray(options.propertyNames, null); |
218 | 216 | options.allowCanceling = getDefaultBoolean(options.allowCanceling, true); |
219 | 217 | options.allowPausing = getDefaultBoolean(options.allowPausing, true); |
| 218 | + options.removeAttribute = getDefaultBoolean(options.removeAttribute, true); |
220 | 219 | options = getWatchOptionsCustomTriggers(options); |
221 | 220 | return options; |
222 | 221 | } |
|
278 | 277 | function getDefaultNumber(value, defaultValue) { |
279 | 278 | return isDefinedNumber(value) ? value : defaultValue; |
280 | 279 | } |
| 280 | + function getDefaultString(value, defaultValue) { |
| 281 | + return isDefinedString(value) ? value : defaultValue; |
| 282 | + } |
281 | 283 | function getDefaultDate(value, defaultValue) { |
282 | 284 | return isDefinedDate(value) ? value : defaultValue; |
283 | 285 | } |
284 | 286 | function getDefaultArray(value, defaultValue) { |
285 | 287 | return isDefinedArray(value) ? value : defaultValue; |
286 | 288 | } |
| 289 | + function getDefaultObject(value, defaultValue) { |
| 290 | + return isDefinedObject(value) ? value : defaultValue; |
| 291 | + } |
287 | 292 | function getDefaultStringOrArray(value, defaultValue) { |
288 | 293 | if (isDefinedString(value)) { |
289 | 294 | value = value.split(_string.space); |
|
309 | 314 | result = result(); |
310 | 315 | } |
311 | 316 | } catch (e2) { |
312 | | - parsed = logError("Errors in object: " + e1.message + ", " + e2.message); |
| 317 | + parsed = logError(_configuration.objectErrorText.replace("{{error_1}}", e1.message).replace("{{error_2}}", e2.message)); |
313 | 318 | result = null; |
314 | 319 | } |
315 | 320 | } |
|
326 | 331 | function buildDefaultConfiguration() { |
327 | 332 | _configuration.safeMode = getDefaultBoolean(_configuration.safeMode, true); |
328 | 333 | _configuration.domElementTypes = getDefaultStringOrArray(_configuration.domElementTypes, ["*"]); |
| 334 | + buildDefaultConfigurationStrings(); |
| 335 | + } |
| 336 | + function buildDefaultConfigurationStrings() { |
| 337 | + _configuration.objectErrorText = getDefaultString(_configuration.objectErrorText, "Errors in object: {{error_1}}, {{error_2}}"); |
| 338 | + _configuration.attributeNotValidErrorText = getDefaultString(_configuration.attributeNotValidErrorText, "The attribute '{{attribute_name}}' is not a valid object."); |
| 339 | + _configuration.attributeNotSetErrorText = getDefaultString(_configuration.attributeNotSetErrorText, "The attribute '{{attribute_name}}' has not been set correctly."); |
329 | 340 | } |
330 | 341 | var _parameter_Document = null; |
331 | 342 | var _parameter_Window = null; |
|
432 | 443 | collectDOMObjects(); |
433 | 444 | return this; |
434 | 445 | }; |
435 | | - this.setConfiguration = function(newOptions) { |
436 | | - _configuration = !isDefinedObject(newOptions) ? {} : newOptions; |
| 446 | + this.setConfiguration = function(newConfiguration) { |
| 447 | + _configuration = getDefaultObject(newConfiguration, {}); |
437 | 448 | buildDefaultConfiguration(); |
438 | 449 | return this; |
439 | 450 | }; |
440 | 451 | this.getVersion = function() { |
441 | | - return "0.7.1"; |
| 452 | + return "0.8.0"; |
442 | 453 | }; |
443 | 454 | (function(documentObject, windowObject, mathObject, jsonObject) { |
444 | 455 | _parameter_Document = documentObject; |
|
0 commit comments