diff --git a/README.md b/README.md index a6bcc1f..f660f8b 100644 --- a/README.md +++ b/README.md @@ -2,15 +2,15 @@ Observe.js [![Tweet](https://img.shields.io/twitter/url/http/shields.io.svg?style=social)](https://twitter.com/intent/tweet?text=Observe.js%2C%20a%20free%20JavaScript%observe%builder&url=https://github.com/williamtroup/Observe.js&hashtags=javascript,html,observe) -[![npm](https://img.shields.io/badge/npmjs-v0.7.1-blue)](https://www.npmjs.com/package/jobserve.js) -[![nuget](https://img.shields.io/badge/nuget-v0.7.1-purple)](https://www.nuget.org/packages/jObserve.js/) +[![npm](https://img.shields.io/badge/npmjs-v0.8.0-blue)](https://www.npmjs.com/package/jobserve.js) +[![nuget](https://img.shields.io/badge/nuget-v0.8.0-purple)](https://www.nuget.org/packages/jObserve.js/) [![license](https://img.shields.io/badge/license-MIT-green)](https://github.com/williamtroup/Observe.js/blob/main/LICENSE.txt) [![discussions Welcome](https://img.shields.io/badge/discussions-Welcome-red)](https://github.com/williamtroup/Observe.js/discussions) [![coded by William Troup](https://img.shields.io/badge/coded_by-William_Troup-yellow)](https://www.william-troup.com/) >

A lightweight JavaScript library that allows developers to keep track of changes to JavaScript objects and/or DOM elements.

->

v0.7.1

+>

v0.8.0



diff --git a/README_NUGET.md b/README_NUGET.md index 440f6bc..2427823 100644 --- a/README_NUGET.md +++ b/README_NUGET.md @@ -1,8 +1,8 @@ -# Observe.js v0.7.1 +# Observe.js v0.8.0 [![Tweet](https://img.shields.io/twitter/url/http/shields.io.svg?style=social)](https://twitter.com/intent/tweet?text=Observe.js%2C%20a%20free%20JavaScript%observe%builder&url=https://github.com/williamtroup/Observe.js&hashtags=javascript,html,observe) -[![npm](https://img.shields.io/badge/npmjs-v0.7.1-blue)](https://www.npmjs.com/package/jobserve.js) -[![nuget](https://img.shields.io/badge/nuget-v0.7.1-purple)](https://www.nuget.org/packages/jObserve.js/) +[![npm](https://img.shields.io/badge/npmjs-v0.8.0-blue)](https://www.npmjs.com/package/jobserve.js) +[![nuget](https://img.shields.io/badge/nuget-v0.8.0-purple)](https://www.nuget.org/packages/jObserve.js/) [![license](https://img.shields.io/badge/license-MIT-green)](https://github.com/williamtroup/Observe.js/blob/main/LICENSE.txt) [![discussions Welcome](https://img.shields.io/badge/discussions-Welcome-red)](https://github.com/williamtroup/Observe.js/discussions) [![coded by William Troup](https://img.shields.io/badge/coded_by-William_Troup-yellow)](https://www.william-troup.com/) diff --git a/dist/observe.js b/dist/observe.js index b0e96bc..3bcc6f5 100644 --- a/dist/observe.js +++ b/dist/observe.js @@ -1,4 +1,4 @@ -/*! Observe.js v0.7.1 | (c) Bunoon 2024 | MIT License */ +/*! Observe.js v0.8.0 | (c) Bunoon 2024 | MIT License */ (function() { function collectDOMObjects() { var tagTypes = _configuration.domElementTypes; @@ -27,19 +27,17 @@ if (!isDefinedString(element.id)) { element.id = newGuid(); } - element.removeAttribute(_attribute_Name_Watch_Options); + if (bindingOptions.removeAttribute) { + element.removeAttribute(_attribute_Name_Watch_Options); + } createWatch(element, bindingOptions, element.id); } else { - if (!_configuration.safeMode) { - console.error("The attribute '" + _attribute_Name_Watch_Options + "' is not a valid object."); - result = false; - } - } - } else { - if (!_configuration.safeMode) { - console.error("The attribute '" + _attribute_Name_Watch_Options + "' has not been set correctly."); + logError(_configuration.attributeNotValidErrorText.replace("{{attribute_name}}", _attribute_Name_Watch_Options)); result = false; } + } else { + logError(_configuration.attributeNotSetErrorText.replace("{{attribute_name}}", _attribute_Name_Watch_Options)); + result = false; } } return result; @@ -206,7 +204,7 @@ return result; } function getWatchOptions(newOptions) { - var options = !isDefinedObject(newOptions) ? {} : newOptions; + var options = getDefaultObject(newOptions, {}); options.timeout = getDefaultNumber(options.timeout, 250); options.starts = getDefaultDate(options.starts, null); options.expires = getDefaultDate(options.expires, null); @@ -217,6 +215,7 @@ options.propertyNames = getDefaultArray(options.propertyNames, null); options.allowCanceling = getDefaultBoolean(options.allowCanceling, true); options.allowPausing = getDefaultBoolean(options.allowPausing, true); + options.removeAttribute = getDefaultBoolean(options.removeAttribute, true); options = getWatchOptionsCustomTriggers(options); return options; } @@ -278,12 +277,18 @@ function getDefaultNumber(value, defaultValue) { return isDefinedNumber(value) ? value : defaultValue; } + function getDefaultString(value, defaultValue) { + return isDefinedString(value) ? value : defaultValue; + } function getDefaultDate(value, defaultValue) { return isDefinedDate(value) ? value : defaultValue; } function getDefaultArray(value, defaultValue) { return isDefinedArray(value) ? value : defaultValue; } + function getDefaultObject(value, defaultValue) { + return isDefinedObject(value) ? value : defaultValue; + } function getDefaultStringOrArray(value, defaultValue) { if (isDefinedString(value)) { value = value.split(_string.space); @@ -309,7 +314,7 @@ result = result(); } } catch (e2) { - parsed = logError("Errors in object: " + e1.message + ", " + e2.message); + parsed = logError(_configuration.objectErrorText.replace("{{error_1}}", e1.message).replace("{{error_2}}", e2.message)); result = null; } } @@ -326,6 +331,12 @@ function buildDefaultConfiguration() { _configuration.safeMode = getDefaultBoolean(_configuration.safeMode, true); _configuration.domElementTypes = getDefaultStringOrArray(_configuration.domElementTypes, ["*"]); + buildDefaultConfigurationStrings(); + } + function buildDefaultConfigurationStrings() { + _configuration.objectErrorText = getDefaultString(_configuration.objectErrorText, "Errors in object: {{error_1}}, {{error_2}}"); + _configuration.attributeNotValidErrorText = getDefaultString(_configuration.attributeNotValidErrorText, "The attribute '{{attribute_name}}' is not a valid object."); + _configuration.attributeNotSetErrorText = getDefaultString(_configuration.attributeNotSetErrorText, "The attribute '{{attribute_name}}' has not been set correctly."); } var _parameter_Document = null; var _parameter_Window = null; @@ -432,13 +443,13 @@ collectDOMObjects(); return this; }; - this.setConfiguration = function(newOptions) { - _configuration = !isDefinedObject(newOptions) ? {} : newOptions; + this.setConfiguration = function(newConfiguration) { + _configuration = getDefaultObject(newConfiguration, {}); buildDefaultConfiguration(); return this; }; this.getVersion = function() { - return "0.7.1"; + return "0.8.0"; }; (function(documentObject, windowObject, mathObject, jsonObject) { _parameter_Document = documentObject; diff --git a/dist/observe.min.js b/dist/observe.min.js index 0c350a5..c83bbde 100644 --- a/dist/observe.min.js +++ b/dist/observe.min.js @@ -1,13 +1,14 @@ -/*! Observe.js v0.7.1 | (c) Bunoon 2024 | MIT License */ -(function(){function L(){for(var a=r.domElementTypes,b=a.length,c=0;c=g.starts){if(d.hasOwnProperty(h)){var e=d[h],l=q(e.domElementId),m=null;l&&(m=A.getElementById(e.domElementId),p(m)?e.originalObject=m.outerHTML:(e.originalObject=F.empty,u(e.options.onRemove,e.domElementId)));var x=e.cachedObject,n=e.originalObject;n=l?n:w.stringify(n);if(x!==n){e.options.reset?l?m.outerHTML=e.cachedObject:e.originalObject=D(x).result:e.cachedObject=n;if(l)u(e.options.onChange,x,n);else if(l=D(x).result,m=D(n).result,y(l)||y(m))u(e.options.onChange,l,m);else{if(y(e.options.propertyNames))for(x= -e.options.propertyNames.length,n=0;n=e.options.maximumChangesBeforeCanceling&&z(h)}}E(g.expires)&&v>=g.expires&&z(h)}},g.timeout),d[f]=b)}return f}function Q(a,b,c){for(var f in a)if(a.hasOwnProperty(f)){var g= -a[f],k=null;b.hasOwnProperty(f)&&(k=b[f]);t(g)&&t(k)?Q(g,k,c.options):(!y(c.options.propertyNames)||-1b;b++){8!==b&&12!==b&&16!==b&&20!==b||a.push("-");var c=K.floor(16*K.random()).toString(16);a.push(c)}return a.join(F.empty)}function p(a){return null!==a&&void 0!==a&&a!==F.empty}function t(a){return p(a)&&"object"=== -typeof a}function q(a){return p(a)&&"string"===typeof a}function G(a){return p(a)&&"function"===typeof a}function y(a){return t(a)&&a instanceof Array}function E(a){return t(a)&&a instanceof Date}function B(a,b){return p(a)&&"boolean"===typeof a?a:b}function C(a,b){return G(a)?a:b}function J(a,b){return p(a)&&"number"===typeof a?a:b}function D(a){var b=!0,c=null;try{q(a)&&(c=w.parse(a))}catch(f){try{c=eval("("+a+")"),G(c)&&(c=c())}catch(g){b=U("Errors in object: "+f.message+", "+g.message),c=null}}return{parsed:b, -result:c}}function U(a){var b=!0;r.safeMode||(console.error(a),b=!1);return b}function T(){r.safeMode=B(r.safeMode,!0);var a=r,b=r.domElementTypes,c=["*"];q(b)?(b=b.split(F.space),0===b.length&&(b=c)):b=y(b)?b:c;a.domElementTypes=b}var A=null,I=null,K=null,w=null,F={empty:""},d={},S=!1,r={};this.watch=function(a,b){return O(a,b)};this.cancelWatch=function(a){var b=!1;if(d.hasOwnProperty(a))z(a),b=!0;else for(var c in d)if(d.hasOwnProperty(c)&&q(d[c].domElementId)&&d[c].domElementId===a){z(c);b=!0; -break}return b};this.cancelWatches=function(){R();return this};this.getWatch=function(a){var b=null;if(d.hasOwnProperty(a))b=d[a];else for(var c in d)if(d.hasOwnProperty(c)&&q(d[c].domElementId)&&d[c].domElementId===a){b=d[c];break}return b};this.getWatches=function(){return d};this.pauseWatch=function(a,b){var c=!1;if(d.hasOwnProperty(a))c=H(a,b);else for(var f in d)if(d.hasOwnProperty(f)&&q(d[f].domElementId)&&d[f].domElementId===a){c=H(f,b);break}return c};this.pauseWatches=function(a){for(var b in d)d.hasOwnProperty(b)&& -H(b,a);return this};this.resumeWatch=function(a){var b=!1;if(d.hasOwnProperty(a))d[a].options.starts=null,b=!0;else for(var c in d)if(d.hasOwnProperty(c)&&q(d[c].domElementId)&&d[c].domElementId===a){d[c].options.starts=null;b=!0;break}return b};this.resumeWatches=function(){for(var a in d)d.hasOwnProperty(a)&&(d[a].options.starts=null);return this};this.searchDomForNewWatches=function(){L();return this};this.setConfiguration=function(a){r=t(a)?a:{};T();return this};this.getVersion=function(){return"0.7.1"}; -(function(a,b,c,f){A=a;I=b;K=c;w=f;T();A.addEventListener("DOMContentLoaded",function(){L()});I.addEventListener("unload",function(){S=!0;R()});p(I.$observe)||(I.$observe=this)})(document,window,Math,JSON)})(); \ No newline at end of file +/*! Observe.js v0.8.0 | (c) Bunoon 2024 | MIT License */ +(function(){function N(){for(var a=g.domElementTypes,b=a.length,c=0;c=h.starts){if(d.hasOwnProperty(k)){var e= +d[k],n=m(e.domElementId),p=null;n&&(p=B.getElementById(e.domElementId),r(p)?e.originalObject=p.outerHTML:(e.originalObject=F.empty,u(e.options.onRemove,e.domElementId)));var x=e.cachedObject,q=e.originalObject;q=n?q:w.stringify(q);if(x!==q){e.options.reset?n?p.outerHTML=e.cachedObject:e.originalObject=D(x).result:e.cachedObject=q;if(n)u(e.options.onChange,x,q);else if(n=D(x).result,p=D(q).result,y(n)||y(p))u(e.options.onChange,n,p);else{if(y(e.options.propertyNames))for(x=e.options.propertyNames.length, +q=0;q=e.options.maximumChangesBeforeCanceling&&z(k)}}E(h.expires)&&v>=h.expires&&z(k)}},h.timeout),d[f]=b)}return f}function S(a,b,c){for(var f in a)if(a.hasOwnProperty(f)){var h= +a[f],l=null;b.hasOwnProperty(f)&&(l=b[f]);t(h)&&t(l)?S(h,l,c.options):(!y(c.options.propertyNames)||-1b;b++){8!==b&&12!==b&&16!==b&&20!==b||a.push("-");var c=L.floor(16*L.random()).toString(16);a.push(c)}return a.join(F.empty)}function r(a){return null!==a&&void 0!==a&&a!== +F.empty}function t(a){return r(a)&&"object"===typeof a}function m(a){return r(a)&&"string"===typeof a}function G(a){return r(a)&&"function"===typeof a}function y(a){return t(a)&&a instanceof Array}function E(a){return t(a)&&a instanceof Date}function A(a,b){return r(a)&&"boolean"===typeof a?a:b}function C(a,b){return G(a)?a:b}function K(a,b){return r(a)&&"number"===typeof a?a:b}function M(a,b){return m(a)?a:b}function D(a){var b=!0,c=null;try{m(a)&&(c=w.parse(a))}catch(f){try{c=eval("("+a+")"),G(c)&& +(c=c())}catch(h){b=J(g.objectErrorText.replace("{{error_1}}",f.message).replace("{{error_2}}",h.message)),c=null}}return{parsed:b,result:c}}function J(a){var b=!0;g.safeMode||(console.error(a),b=!1);return b}function V(){g.safeMode=A(g.safeMode,!0);var a=g,b=g.domElementTypes,c=["*"];m(b)?(b=b.split(F.space),0===b.length&&(b=c)):b=y(b)?b:c;a.domElementTypes=b;g.objectErrorText=M(g.objectErrorText,"Errors in object: {{error_1}}, {{error_2}}");g.attributeNotValidErrorText=M(g.attributeNotValidErrorText, +"The attribute '{{attribute_name}}' is not a valid object.");g.attributeNotSetErrorText=M(g.attributeNotSetErrorText,"The attribute '{{attribute_name}}' has not been set correctly.")}var B=null,I=null,L=null,w=null,F={empty:""},d={},U=!1,g={};this.watch=function(a,b){return Q(a,b)};this.cancelWatch=function(a){var b=!1;if(d.hasOwnProperty(a))z(a),b=!0;else for(var c in d)if(d.hasOwnProperty(c)&&m(d[c].domElementId)&&d[c].domElementId===a){z(c);b=!0;break}return b};this.cancelWatches=function(){T(); +return this};this.getWatch=function(a){var b=null;if(d.hasOwnProperty(a))b=d[a];else for(var c in d)if(d.hasOwnProperty(c)&&m(d[c].domElementId)&&d[c].domElementId===a){b=d[c];break}return b};this.getWatches=function(){return d};this.pauseWatch=function(a,b){var c=!1;if(d.hasOwnProperty(a))c=H(a,b);else for(var f in d)if(d.hasOwnProperty(f)&&m(d[f].domElementId)&&d[f].domElementId===a){c=H(f,b);break}return c};this.pauseWatches=function(a){for(var b in d)d.hasOwnProperty(b)&&H(b,a);return this};this.resumeWatch= +function(a){var b=!1;if(d.hasOwnProperty(a))d[a].options.starts=null,b=!0;else for(var c in d)if(d.hasOwnProperty(c)&&m(d[c].domElementId)&&d[c].domElementId===a){d[c].options.starts=null;b=!0;break}return b};this.resumeWatches=function(){for(var a in d)d.hasOwnProperty(a)&&(d[a].options.starts=null);return this};this.searchDomForNewWatches=function(){N();return this};this.setConfiguration=function(a){var b={};g=t(a)?a:b;V();return this};this.getVersion=function(){return"0.8.0"};(function(a,b,c,f){B= +a;I=b;L=c;w=f;V();B.addEventListener("DOMContentLoaded",function(){N()});I.addEventListener("unload",function(){U=!0;T()});r(I.$observe)||(I.$observe=this)})(document,window,Math,JSON)})(); \ No newline at end of file diff --git a/docs/CHANGE_LOG.md b/docs/CHANGE_LOG.md index fdadc39..6c47c08 100644 --- a/docs/CHANGE_LOG.md +++ b/docs/CHANGE_LOG.md @@ -1,5 +1,26 @@ # Observe.js - Change Log: +## Version 0.8.0: + +#### **Binding Options:** +- Added a new binding option called "removeAttribute", which states if the binding attribute should be removed (defaults to true). + +#### **Configuration Options:** +- Added a new configuration option called "objectErrorText", which states the error text that should be shown when an object error is detected (defaults to "Errors in object: {{error_1}}, {{error_2}}"). +- Added a new configuration option called "attributeNotValidErrorText", which states the error text that should be shown when a binding object isn't valid (defaults to "The attribute '{{attribute_name}}' is not a valid object."). +- Added a new configuration option called "attributeNotSetErrorText", which states the error text that should be shown when a binding attribute isn't set (defaults to "The attribute '{{attribute_name}}' has not been set correctly."). + +#### **General Improvements:** +- All console error logging now goes through the correct method. +- Objects are now checked and defaulted properly when invalid values are passed. +- Updated the formatting used in the "package.json" file so that it can always be parsed. + +#### **Documentation:** +- Minor tweaks to the documentation. + +
+ + ## Version 0.7.1: - Fixed a fault that caused clearTimeout() to be called instead of clearInterval(). diff --git a/docs/PUBLIC_FUNCTIONS.md b/docs/PUBLIC_FUNCTIONS.md index 4ad7478..d78d8a2 100644 --- a/docs/PUBLIC_FUNCTIONS.md +++ b/docs/PUBLIC_FUNCTIONS.md @@ -87,10 +87,10 @@ Searches the DOM for new elements to watch, and adds them. ## Configuration: -### **setConfiguration( *newOptions* )**: +### **setConfiguration( *newConfiguration* )**: Sets the specific configuration options that should be used.
-***Parameter: newOptions***: '*Options*' - All the configuration options that should be set (refer to ["Configuration Options"](configuration/OPTIONS.md) documentation for properties). +***Parameter: newConfiguration***: '*Object*' - All the configuration options that should be set (refer to ["Configuration Options"](configuration/OPTIONS.md) documentation for properties).
***Returns***: '*Object*' - The Observe.js class instance.
diff --git a/docs/binding/options/CUSTOM_TRIGGERS.md b/docs/binding/options/CUSTOM_TRIGGERS.md index 15c32fb..ecec918 100644 --- a/docs/binding/options/CUSTOM_TRIGGERS.md +++ b/docs/binding/options/CUSTOM_TRIGGERS.md @@ -13,6 +13,7 @@ Fires when a change has been detected in an object. ***Parameter:*** oldValue: '*object*' - The old value for the object.
***Parameter:*** newValue: '*object*' - The new value for the object. +
### options.onPropertyChange( *propertyName*, *oldValue*, *newValue* ): Fires when a change has been detected in an object (states which property changed). @@ -22,22 +23,25 @@ Fires when a change has been detected in an object (states which property change ***Parameter:*** oldValue: '*object*' - The old value.
***Parameter:*** newValue: '*object*' - The new value. +
### options.onCancel( *id* ): Fires when a watch has been cancelled.
***Parameter:*** id: '*string*' - The ID of the watch that has been cancelled. +
### options.onRemove( *id* ): Fires when a DOM element is no longer available in the DOM.
***Parameter:*** id: '*string*' - The ID of the DOM element. +
### options.onStart( *originalValue* ): Fires when a watch is started.
***Parameter:*** id: '*object*' - The object that the watch as started for. - +

diff --git a/docs/binding/options/OPTIONS.md b/docs/binding/options/OPTIONS.md index 2b384cc..4912481 100644 --- a/docs/binding/options/OPTIONS.md +++ b/docs/binding/options/OPTIONS.md @@ -19,6 +19,7 @@ Below is a list of all the options supported in the "data-observe-watch-options" | *string[]* | propertyNames | States the property names that should be watched for changes (defaults to all). | | *boolean* | allowCanceling | States if the watch can be cancelled (defaults to true). | | *boolean* | allowPausing | States if the watch can be paused (defaults to true). | +| *boolean* | removeAttribute | States if the binding attribute should be removed (defaults to true). |
diff --git a/docs/configuration/OPTIONS.md b/docs/configuration/OPTIONS.md index 1e00065..6752d85 100644 --- a/docs/configuration/OPTIONS.md +++ b/docs/configuration/OPTIONS.md @@ -13,6 +13,17 @@ Below are all the configuration options that can be passed to the "setConfigurat
+### Options - Strings: + +| Type: | Name: | Description: | +| --- | --- | --- | +| *string* | objectErrorText | The error text that should be shown when an object error is detected (defaults to "Errors in object: {{error_1}}, {{error_2}}"). | +| *string* | attributeNotValidErrorText | The error text that should be shown when a binding object isn't valid (defaults to "The attribute '{{attribute_name}}' is not a valid object."). | +| *string* | attributeNotSetErrorText | The error text that should be shown when a binding attribute isn't set (defaults to "The attribute '{{attribute_name}}' has not been set correctly."). | + +
+ + ## Example: ```markdown diff --git a/observe.js.nuspec b/observe.js.nuspec index 1b41c08..2fe57ac 100644 --- a/observe.js.nuspec +++ b/observe.js.nuspec @@ -2,7 +2,7 @@ jObserve.js - 0.7.1 + 0.8.0 Observe.js A lightweight JavaScript library that allows developers to keep track of changes to JavaScript objects and/or DOM elements. William Troup diff --git a/package.json b/package.json index 2fd90fb..e3179d9 100644 --- a/package.json +++ b/package.json @@ -1,35 +1,35 @@ { - "name": "jobserve.js", - "title": "Observe.js", - "description": "A lightweight JavaScript library that allows developers to keep track of changes to JavaScript objects and/or DOM elements.", - "version": "0.7.1", - "main": "dist/observe.js", - "homepage": "https://www.william-troup.com/observe-js/", - "author": { - "name": "Bunoon" - }, - "repository": { - "type": "git", - "url": "https://github.com/williamtroup/Observe.js" - }, - "keywords": [ - "javascript", - "css", - "observe.js", - "observe", - "observable", - "watcher", - "object", - "changes", - "watch", - "event", - "events", - "trigger", - "triggers", - "handler" - ], - "bugs": { - "url": "https://github.com/williamtroup/Observe.js/issues" - }, - "license": "MIT" - } \ No newline at end of file + "name": "jobserve.js", + "title": "Observe.js", + "description": "A lightweight JavaScript library that allows developers to keep track of changes to JavaScript objects and/or DOM elements.", + "version": "0.8.0", + "main": "dist/observe.js", + "homepage": "https://www.william-troup.com/observe-js/", + "author": { + "name": "Bunoon" + }, + "repository": { + "type": "git", + "url": "https://github.com/williamtroup/Observe.js" + }, + "keywords": [ + "javascript", + "css", + "observe.js", + "observe", + "observable", + "watcher", + "object", + "changes", + "watch", + "event", + "events", + "trigger", + "triggers", + "handler" + ], + "bugs": { + "url": "https://github.com/williamtroup/Observe.js/issues" + }, + "license": "MIT" +} \ No newline at end of file diff --git a/src/observe.js b/src/observe.js index 7fe2c86..2c90fe2 100644 --- a/src/observe.js +++ b/src/observe.js @@ -4,7 +4,7 @@ * A lightweight JavaScript library that allows developers to keep track of changes to JavaScript objects and/or DOM elements. * * @file observe.js - * @version v0.7.1 + * @version v0.8.0 * @author Bunoon * @license MIT License * @copyright Bunoon 2024 @@ -73,22 +73,20 @@ element.id = newGuid(); } - element.removeAttribute( _attribute_Name_Watch_Options ); + if ( bindingOptions.removeAttribute ) { + element.removeAttribute( _attribute_Name_Watch_Options ); + } createWatch( element, bindingOptions, element.id ); } else { - if ( !_configuration.safeMode ) { - console.error( "The attribute '" + _attribute_Name_Watch_Options + "' is not a valid object." ); - result = false; - } + logError( _configuration.attributeNotValidErrorText.replace( "{{attribute_name}}", _attribute_Name_Watch_Options ) ); + result = false; } } else { - if ( !_configuration.safeMode ) { - console.error( "The attribute '" + _attribute_Name_Watch_Options + "' has not been set correctly." ); - result = false; - } + logError( _configuration.attributeNotSetErrorText.replace( "{{attribute_name}}", _attribute_Name_Watch_Options ) ); + result = false; } } @@ -317,7 +315,7 @@ */ function getWatchOptions( newOptions ) { - var options = !isDefinedObject( newOptions ) ? {} : newOptions; + var options = getDefaultObject( newOptions, {} ); options.timeout = getDefaultNumber( options.timeout, 250 ); options.starts = getDefaultDate( options.starts, null ); @@ -329,6 +327,7 @@ options.propertyNames = getDefaultArray( options.propertyNames, null ); options.allowCanceling = getDefaultBoolean( options.allowCanceling, true ); options.allowPausing = getDefaultBoolean( options.allowPausing, true ); + options.removeAttribute = getDefaultBoolean( options.removeAttribute, true ); options = getWatchOptionsCustomTriggers( options ); @@ -438,6 +437,10 @@ return isDefinedNumber( value ) ? value : defaultValue; } + function getDefaultString( value, defaultValue ) { + return isDefinedString( value ) ? value : defaultValue; + } + function getDefaultDate( value, defaultValue ) { return isDefinedDate( value ) ? value : defaultValue; } @@ -446,6 +449,10 @@ return isDefinedArray( value ) ? value : defaultValue; } + function getDefaultObject( value, defaultValue ) { + return isDefinedObject( value ) ? value : defaultValue; + } + function getDefaultStringOrArray( value, defaultValue ) { if ( isDefinedString( value ) ) { value = value.split( _string.space ); @@ -480,7 +487,7 @@ } } catch ( e2 ) { - parsed = logError( "Errors in object: " + e1.message + ", " + e2.message ); + parsed = logError( _configuration.objectErrorText.replace( "{{error_1}}", e1.message ).replace( "{{error_2}}", e2.message ) ); result = null; } } @@ -749,8 +756,8 @@ * * @returns {Object} The Observe.js class instance. */ - this.setConfiguration = function( newOptions ) { - _configuration = !isDefinedObject( newOptions ) ? {} : newOptions; + this.setConfiguration = function( newConfiguration ) { + _configuration = getDefaultObject( newConfiguration, {} ); buildDefaultConfiguration(); @@ -760,6 +767,14 @@ function buildDefaultConfiguration() { _configuration.safeMode = getDefaultBoolean( _configuration.safeMode, true ); _configuration.domElementTypes = getDefaultStringOrArray( _configuration.domElementTypes, [ "*" ] ); + + buildDefaultConfigurationStrings(); + } + + function buildDefaultConfigurationStrings() { + _configuration.objectErrorText = getDefaultString( _configuration.objectErrorText, "Errors in object: {{error_1}}, {{error_2}}" ); + _configuration.attributeNotValidErrorText = getDefaultString( _configuration.attributeNotValidErrorText, "The attribute '{{attribute_name}}' is not a valid object." ); + _configuration.attributeNotSetErrorText = getDefaultString( _configuration.attributeNotSetErrorText, "The attribute '{{attribute_name}}' has not been set correctly." ); } @@ -779,7 +794,7 @@ * @returns {string} The version number. */ this.getVersion = function() { - return "0.7.1"; + return "0.8.0"; };