From 0ab94cf90f3c34233744613bd38249b661725d99 Mon Sep 17 00:00:00 2001 From: William Troup Date: Wed, 3 Jan 2024 13:24:40 +0000 Subject: [PATCH 1/9] Updated to v0.4.0. --- README.md | 6 +++--- README_NUGET.md | 6 +++--- dist/observe.js | 4 ++-- dist/observe.min.js | 4 ++-- docs/CHANGE_LOG.md | 6 ++++++ observe.js.nuspec | 2 +- package.json | 2 +- src/observe.js | 4 ++-- 8 files changed, 20 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 3f43144..054bab0 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.3.0-blue)](https://www.npmjs.com/package/jobserve.js) -[![nuget](https://img.shields.io/badge/nuget-v0.3.0-purple)](https://www.nuget.org/packages/jObserve.js/) +[![npm](https://img.shields.io/badge/npmjs-v0.4.0-blue)](https://www.npmjs.com/package/jobserve.js) +[![nuget](https://img.shields.io/badge/nuget-v0.4.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://github.com/williamtroup) >

A lightweight, and easy-to-use, JavaScript library for observing any kind of JS object, or HTML DOM element, to detect changes!

->

v0.3.0

+>

v0.4.0



diff --git a/README_NUGET.md b/README_NUGET.md index 954f8d9..1d3d475 100644 --- a/README_NUGET.md +++ b/README_NUGET.md @@ -1,8 +1,8 @@ -# Observe.js v0.3.0 +# Observe.js v0.4.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.3.0-blue)](https://www.npmjs.com/package/jobserve.js) -[![nuget](https://img.shields.io/badge/nuget-v0.3.0-purple)](https://www.nuget.org/packages/jObserve.js/) +[![npm](https://img.shields.io/badge/npmjs-v0.4.0-blue)](https://www.npmjs.com/package/jobserve.js) +[![nuget](https://img.shields.io/badge/nuget-v0.4.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://github.com/williamtroup) diff --git a/dist/observe.js b/dist/observe.js index 26df14d..9d327e1 100644 --- a/dist/observe.js +++ b/dist/observe.js @@ -1,4 +1,4 @@ -/*! Observe.js v0.3.0 | (c) Bunoon | MIT License */ +/*! Observe.js v0.4.0 | (c) Bunoon | MIT License */ (function() { function collectDOMObjects() { var tagTypes = _configuration.domElementTypes; @@ -354,7 +354,7 @@ return this; }; this.getVersion = function() { - return "0.3.0"; + return "0.4.0"; }; (function(documentObject, windowObject) { _parameter_Document = documentObject; diff --git a/dist/observe.min.js b/dist/observe.min.js index ab0a48f..3d632a7 100644 --- a/dist/observe.min.js +++ b/dist/observe.min.js @@ -1,4 +1,4 @@ -/*! Observe.js v0.3.0 | (c) Bunoon | MIT License */ +/*! Observe.js v0.4.0 | (c) Bunoon | MIT License */ (function(){function I(a,b,c){var e=null;if(t(a)){e=J();var f=K(b);b={};b.options=f;b.domElementId=c;b.totalChanges=0;p(c)?(a=w.getElementById(c),q(a)&&(b.cachedObject=a.outerHTML,b.originalObject=a.outerHTML)):(b.cachedObject=JSON.stringify(a),b.originalObject=a);b.timer=setInterval(function(){var k=new Date;if(!x(f.starts)||k>=f.starts){var u=e;if(d.hasOwnProperty(u)){var h=d[u],g=p(h.domElementId),n=null;g&&(n=w.getElementById(h.domElementId),q(n)&&(h.originalObject=n.outerHTML));var l=h.cachedObject, m=h.originalObject,y=g?m:JSON.stringify(m);l!==y&&(m=h.options,m.reset?g?n.outerHTML=h.cachedObject:h.originalObject=z(l).result:h.cachedObject=y,g?A(m.onChange,l,y):(g=z(l).result,n=z(y).result,A(m.onChange,g,n),B(m.onPropertyChange)&&!L(g)&&M(g,n,m)),0=m.maximumChangesBeforeCanceling&&v(u))}x(f.expires)&&k>=f.expires&&v(e)}},f.timeout);d[e]=b}return e}function M(a, b,c){for(var e in a)if(a.hasOwnProperty(e)){var f=a[e],k=null;b.hasOwnProperty(e)&&(k=b[e]);t(f)&&t(k)?M(f,k,c):JSON.stringify(f)!==JSON.stringify(k)&&A(c.onPropertyChange,e,f,k)}}function N(){for(var a in d)d.hasOwnProperty(a)&&v(a)}function v(a){d.hasOwnProperty(a)&&(A(d[a].options.onCancel,a),clearTimeout(d[a].timer),delete d[a])}function D(a,b){var c=!1;d.hasOwnProperty(a)&&(c=d[a].options,c.starts=new Date,c.starts.setMilliseconds(c.starts.getMilliseconds()+b),c=!0);return c}function K(a){a= @@ -6,5 +6,5 @@ t(a)?a:{};a.timeout=E(a.timeout,250);var b=a;var c=a.starts;c=x(c)?c:null;b.star [],b=0;32>b;b++){8!==b&&12!==b&&16!==b&&20!==b||a.push("-");var c=Math.floor(16*Math.random()).toString(16);a.push(c)}return a.join(H.empty)}function q(a){return null!==a&&void 0!==a&&a!==H.empty}function t(a){return q(a)&&"object"===typeof a}function p(a){return q(a)&&"string"===typeof a}function B(a){return q(a)&&"function"===typeof a}function L(a){return t(a)&&a instanceof Array}function x(a){return t(a)&&a instanceof Date}function F(a,b){return q(a)&&"boolean"===typeof a?a:b}function G(a,b){return B(a)? a:b}function E(a,b){return q(a)&&"number"===typeof a?a:b}function z(a){var b=!0,c=null;try{p(a)&&(c=JSON.parse(a))}catch(e){try{c=eval("("+a+")"),B(c)&&(c=c())}catch(f){b=P("Errors in object: "+e.message+", "+f.message),c=null}}return{parsed:b,result:c}}function P(a){var b=!0;r.safeMode||(console.error(a),b=!1);return b}function O(){r.safeMode=F(r.safeMode,!0);var a=r,b=r.domElementTypes,c=["*"];p(b)?(b=b.split(H.space),0===b.length&&(b=c)):b=L(b)?b:c;a.domElementTypes=b}var w=null,C=null,H={empty:""}, d={},r={};this.watchObject=function(a,b){return I(a,b)};this.cancelWatch=function(a){var b=!1;if(d.hasOwnProperty(a))v(a),b=!0;else for(var c in d)if(d.hasOwnProperty(c)&&p(d[c].domElementId)&&d[c].domElementId===a){v(c);b=!0;break}return b};this.cancelWatches=function(){N();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)&&p(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=D(a,b);else for(var e in d)if(d.hasOwnProperty(e)&&p(d[e].domElementId)&&d[e].domElementId===a){c=D(e,b);break}return c};this.setConfiguration=function(a){r=t(a)?a:{};O();return this};this.getVersion=function(){return"0.3.0"};(function(a,b){w=a;C=b;O();w.addEventListener("DOMContentLoaded",function(){for(var c=r.domElementTypes,e=c.length,f=0;f + + ## Version 0.3.0: #### **New Features:** diff --git a/observe.js.nuspec b/observe.js.nuspec index 401c08a..653de0f 100644 --- a/observe.js.nuspec +++ b/observe.js.nuspec @@ -2,7 +2,7 @@ jObserve.js - 0.3.0 + 0.4.0 Observe.js A lightweight, and easy-to-use, JavaScript library for observing any kind of JS object, or HTML DOM element, to detect changes. William Troup diff --git a/package.json b/package.json index 7342240..8b80507 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "jobserve.js", "title": "Observe.js", "description": "A lightweight, and easy-to-use, JavaScript library for observing any kind of JS object, or HTML DOM element, to detect changes.", - "version": "0.3.0", + "version": "0.4.0", "main": "dist/observe.js", "author": { "name": "Bunoon" diff --git a/src/observe.js b/src/observe.js index e1f4320..a8ef846 100644 --- a/src/observe.js +++ b/src/observe.js @@ -4,7 +4,7 @@ * A lightweight, and easy-to-use, JavaScript library for observing any kind of JS object, or HTML DOM element, to detect changes. * * @file observe.js - * @version v0.3.0 + * @version v0.4.0 * @author Bunoon * @license MIT License * @copyright Bunoon 2023 @@ -640,7 +640,7 @@ * @returns {string} The version number. */ this.getVersion = function() { - return "0.3.0"; + return "0.4.0"; }; From 0782639c1c4fe88530369dcabe3ca979dacc6383 Mon Sep 17 00:00:00 2001 From: William Troup Date: Wed, 3 Jan 2024 13:34:48 +0000 Subject: [PATCH 2/9] Added new public function "searchDomForNewWatches()", which is used to search the DOM for new elements to watch, and adds them. --- dist/observe.js | 4 ++++ dist/observe.min.js | 19 ++++++++++--------- docs/CHANGE_LOG.md | 4 +++- docs/PUBLIC_FUNCTIONS.md | 6 ++++++ src/observe.js | 15 +++++++++++++++ 5 files changed, 38 insertions(+), 10 deletions(-) diff --git a/dist/observe.js b/dist/observe.js index 9d327e1..99a1a14 100644 --- a/dist/observe.js +++ b/dist/observe.js @@ -348,6 +348,10 @@ } return result; }; + this.searchDomForNewWatches = function() { + collectDOMObjects(); + return this; + }; this.setConfiguration = function(newOptions) { _configuration = !isDefinedObject(newOptions) ? {} : newOptions; buildDefaultConfiguration(); diff --git a/dist/observe.min.js b/dist/observe.min.js index 3d632a7..8326d28 100644 --- a/dist/observe.min.js +++ b/dist/observe.min.js @@ -1,10 +1,11 @@ /*! Observe.js v0.4.0 | (c) Bunoon | MIT License */ -(function(){function I(a,b,c){var e=null;if(t(a)){e=J();var f=K(b);b={};b.options=f;b.domElementId=c;b.totalChanges=0;p(c)?(a=w.getElementById(c),q(a)&&(b.cachedObject=a.outerHTML,b.originalObject=a.outerHTML)):(b.cachedObject=JSON.stringify(a),b.originalObject=a);b.timer=setInterval(function(){var k=new Date;if(!x(f.starts)||k>=f.starts){var u=e;if(d.hasOwnProperty(u)){var h=d[u],g=p(h.domElementId),n=null;g&&(n=w.getElementById(h.domElementId),q(n)&&(h.originalObject=n.outerHTML));var l=h.cachedObject, -m=h.originalObject,y=g?m:JSON.stringify(m);l!==y&&(m=h.options,m.reset?g?n.outerHTML=h.cachedObject:h.originalObject=z(l).result:h.cachedObject=y,g?A(m.onChange,l,y):(g=z(l).result,n=z(y).result,A(m.onChange,g,n),B(m.onPropertyChange)&&!L(g)&&M(g,n,m)),0=m.maximumChangesBeforeCanceling&&v(u))}x(f.expires)&&k>=f.expires&&v(e)}},f.timeout);d[e]=b}return e}function M(a, -b,c){for(var e in a)if(a.hasOwnProperty(e)){var f=a[e],k=null;b.hasOwnProperty(e)&&(k=b[e]);t(f)&&t(k)?M(f,k,c):JSON.stringify(f)!==JSON.stringify(k)&&A(c.onPropertyChange,e,f,k)}}function N(){for(var a in d)d.hasOwnProperty(a)&&v(a)}function v(a){d.hasOwnProperty(a)&&(A(d[a].options.onCancel,a),clearTimeout(d[a].timer),delete d[a])}function D(a,b){var c=!1;d.hasOwnProperty(a)&&(c=d[a].options,c.starts=new Date,c.starts.setMilliseconds(c.starts.getMilliseconds()+b),c=!0);return c}function K(a){a= -t(a)?a:{};a.timeout=E(a.timeout,250);var b=a;var c=a.starts;c=x(c)?c:null;b.starts=c;b=a;c=a.expires;c=x(c)?c:null;b.expires=c;a.reset=F(a.reset,!1);a.cancelOnChange=F(a.cancelOnChange,!1);a.maximumChangesBeforeCanceling=E(a.maximumChangesBeforeCanceling,0);a.pauseTimeoutOnChange=E(a.pauseTimeoutOnChange,0);a.onChange=G(a.onChange,null);a.onPropertyChange=G(a.onPropertyChange,null);a.onCancel=G(a.onCancel,null);return a}function A(a){B(a)&&a.apply(null,[].slice.call(arguments,1))}function J(){for(var a= -[],b=0;32>b;b++){8!==b&&12!==b&&16!==b&&20!==b||a.push("-");var c=Math.floor(16*Math.random()).toString(16);a.push(c)}return a.join(H.empty)}function q(a){return null!==a&&void 0!==a&&a!==H.empty}function t(a){return q(a)&&"object"===typeof a}function p(a){return q(a)&&"string"===typeof a}function B(a){return q(a)&&"function"===typeof a}function L(a){return t(a)&&a instanceof Array}function x(a){return t(a)&&a instanceof Date}function F(a,b){return q(a)&&"boolean"===typeof a?a:b}function G(a,b){return B(a)? -a:b}function E(a,b){return q(a)&&"number"===typeof a?a:b}function z(a){var b=!0,c=null;try{p(a)&&(c=JSON.parse(a))}catch(e){try{c=eval("("+a+")"),B(c)&&(c=c())}catch(f){b=P("Errors in object: "+e.message+", "+f.message),c=null}}return{parsed:b,result:c}}function P(a){var b=!0;r.safeMode||(console.error(a),b=!1);return b}function O(){r.safeMode=F(r.safeMode,!0);var a=r,b=r.domElementTypes,c=["*"];p(b)?(b=b.split(H.space),0===b.length&&(b=c)):b=L(b)?b:c;a.domElementTypes=b}var w=null,C=null,H={empty:""}, -d={},r={};this.watchObject=function(a,b){return I(a,b)};this.cancelWatch=function(a){var b=!1;if(d.hasOwnProperty(a))v(a),b=!0;else for(var c in d)if(d.hasOwnProperty(c)&&p(d[c].domElementId)&&d[c].domElementId===a){v(c);b=!0;break}return b};this.cancelWatches=function(){N();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)&&p(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=D(a,b);else for(var e in d)if(d.hasOwnProperty(e)&&p(d[e].domElementId)&&d[e].domElementId===a){c=D(e,b);break}return c};this.setConfiguration=function(a){r=t(a)?a:{};O();return this};this.getVersion=function(){return"0.4.0"};(function(a,b){w=a;C=b;O();w.addEventListener("DOMContentLoaded",function(){for(var c=r.domElementTypes,e=c.length,f=0;f=g.starts){var k=e;if(d.hasOwnProperty(k)){var h=d[k],f=q(h.domElementId),t=null;f&&(t=v.getElementById(h.domElementId),p(t)&&(h.originalObject=t.outerHTML));var y= +h.cachedObject,l=h.originalObject,z=f?l:JSON.stringify(l);y!==z&&(l=h.options,l.reset?f?t.outerHTML=h.cachedObject:h.originalObject=w(y).result:h.cachedObject=z,f?A(l.onChange,y,z):(f=w(y).result,t=w(z).result,A(l.onChange,f,t),B(l.onPropertyChange)&&!M(f)&&N(f,t,l)),0=l.maximumChangesBeforeCanceling&&u(k))}x(g.expires)&&m>=g.expires&&u(e)}},g.timeout);d[e]= +b}return e}function N(a,b,c){for(var e in a)if(a.hasOwnProperty(e)){var g=a[e],m=null;b.hasOwnProperty(e)&&(m=b[e]);r(g)&&r(m)?N(g,m,c):JSON.stringify(g)!==JSON.stringify(m)&&A(c.onPropertyChange,e,g,m)}}function O(){for(var a in d)d.hasOwnProperty(a)&&u(a)}function u(a){d.hasOwnProperty(a)&&(A(d[a].options.onCancel,a),clearTimeout(d[a].timer),delete d[a])}function D(a,b){var c=!1;d.hasOwnProperty(a)&&(c=d[a].options,c.starts=new Date,c.starts.setMilliseconds(c.starts.getMilliseconds()+b),c=!0);return c} +function J(a){a=r(a)?a:{};a.timeout=E(a.timeout,250);var b=a;var c=a.starts;c=x(c)?c:null;b.starts=c;b=a;c=a.expires;c=x(c)?c:null;b.expires=c;a.reset=F(a.reset,!1);a.cancelOnChange=F(a.cancelOnChange,!1);a.maximumChangesBeforeCanceling=E(a.maximumChangesBeforeCanceling,0);a.pauseTimeoutOnChange=E(a.pauseTimeoutOnChange,0);a.onChange=G(a.onChange,null);a.onPropertyChange=G(a.onPropertyChange,null);a.onCancel=G(a.onCancel,null);return a}function A(a){B(a)&&a.apply(null,[].slice.call(arguments,1))} +function K(){for(var a=[],b=0;32>b;b++){8!==b&&12!==b&&16!==b&&20!==b||a.push("-");var c=Math.floor(16*Math.random()).toString(16);a.push(c)}return a.join(H.empty)}function p(a){return null!==a&&void 0!==a&&a!==H.empty}function r(a){return p(a)&&"object"===typeof a}function q(a){return p(a)&&"string"===typeof a}function B(a){return p(a)&&"function"===typeof a}function M(a){return r(a)&&a instanceof Array}function x(a){return r(a)&&a instanceof Date}function F(a,b){return p(a)&&"boolean"===typeof a? +a:b}function G(a,b){return B(a)?a:b}function E(a,b){return p(a)&&"number"===typeof a?a:b}function w(a){var b=!0,c=null;try{q(a)&&(c=JSON.parse(a))}catch(e){try{c=eval("("+a+")"),B(c)&&(c=c())}catch(g){b=Q("Errors in object: "+e.message+", "+g.message),c=null}}return{parsed:b,result:c}}function Q(a){var b=!0;n.safeMode||(console.error(a),b=!1);return b}function P(){n.safeMode=F(n.safeMode,!0);var a=n,b=n.domElementTypes,c=["*"];q(b)?(b=b.split(H.space),0===b.length&&(b=c)):b=M(b)?b:c;a.domElementTypes= +b}var v=null,C=null,H={empty:""},d={},n={};this.watchObject=function(a,b){return L(a,b)};this.cancelWatch=function(a){var b=!1;if(d.hasOwnProperty(a))u(a),b=!0;else for(var c in d)if(d.hasOwnProperty(c)&&q(d[c].domElementId)&&d[c].domElementId===a){u(c);b=!0;break}return b};this.cancelWatches=function(){O();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=D(a,b);else for(var e in d)if(d.hasOwnProperty(e)&&q(d[e].domElementId)&&d[e].domElementId===a){c=D(e,b);break}return c};this.searchDomForNewWatches=function(){I();return this};this.setConfiguration=function(a){n=r(a)?a:{};P();return this};this.getVersion=function(){return"0.4.0"};(function(a,b){v=a;C=b;P();v.addEventListener("DOMContentLoaded",function(){I()});C.addEventListener("unload",function(){O()}); +p(C.$observe)||(C.$observe=this)})(document,window)})(); \ No newline at end of file diff --git a/docs/CHANGE_LOG.md b/docs/CHANGE_LOG.md index 193f043..4a4a4a1 100644 --- a/docs/CHANGE_LOG.md +++ b/docs/CHANGE_LOG.md @@ -1,7 +1,9 @@ # Observe.js - Change Log: ## Version 0.4.0: -- + +#### **Public Functions:** +- Added new public function "searchDomForNewWatches()", which is used to search the DOM for new elements to watch, and adds them.
diff --git a/docs/PUBLIC_FUNCTIONS.md b/docs/PUBLIC_FUNCTIONS.md index 4a56ce2..48ff07c 100644 --- a/docs/PUBLIC_FUNCTIONS.md +++ b/docs/PUBLIC_FUNCTIONS.md @@ -54,6 +54,12 @@ Pauses the watching of an object for changes for a specific number of millisecon
***Returns***: '*boolean*' - States if the object being watched has been paused.
+ +### **searchDomForNewWatches()**: +Searches the DOM for new elements to watch, and adds them. +
+***Returns***: '*Object*' - The Observe.js class instance. +

diff --git a/src/observe.js b/src/observe.js index a8ef846..214f437 100644 --- a/src/observe.js +++ b/src/observe.js @@ -592,6 +592,21 @@ return result; }; + /** + * searchDomForNewWatches(). + * + * Searches the DOM for new elements to watch, and adds them. + * + * @public + * + * @returns {Object} The Observe.js class instance. + */ + this.searchDomForNewWatches = function() { + collectDOMObjects(); + + return this; + }; + /* * ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- From fd97ce8181e2b8116df4147abf7bca6c74ad134b Mon Sep 17 00:00:00 2001 From: William Troup Date: Wed, 3 Jan 2024 13:37:52 +0000 Subject: [PATCH 3/9] Renamed the DOM attribute "data-observe-options" to "data-observe-watch-options". --- README.md | 6 +++--- README_NUGET.md | 6 +++--- dist/observe.js | 10 +++++----- dist/observe.min.js | 2 +- docs/CHANGE_LOG.md | 3 +++ docs/binding/options/CUSTOM_TRIGGERS.md | 4 ++-- docs/binding/options/OPTIONS.md | 4 ++-- src/observe.js | 10 +++++----- test/dist/observe.js.basic.html | 4 ++-- test/dist/observe.js.min.html | 4 ++-- test/src/observe.js.basic.html | 4 ++-- 11 files changed, 30 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index 054bab0..31956b3 100644 --- a/README.md +++ b/README.md @@ -63,7 +63,7 @@ Make sure you include the "DOCTYPE html" tag at the top of your HTML, as follows ### 3. DOM Element Binding / Object Watching: ```markdown -
+
Your HTML.
``` @@ -76,9 +76,9 @@ Make sure you include the "DOCTYPE html" tag at the top of your HTML, as follows ``` -To see a list of all the available binding options you can use for "data-observe-options", and "watchObject()", click [here](docs/binding/options/OPTIONS.md). +To see a list of all the available binding options you can use for "data-observe-watch-options", and "watchObject()", click [here](docs/binding/options/OPTIONS.md). -To see a list of all the available custom triggers you can use for "data-observe-options", and "watchObject()", click [here](docs/binding/options/CUSTOM_TRIGGERS.md). +To see a list of all the available custom triggers you can use for "data-observe-watch-options", and "watchObject()", click [here](docs/binding/options/CUSTOM_TRIGGERS.md).
diff --git a/README_NUGET.md b/README_NUGET.md index 1d3d475..cd51d2b 100644 --- a/README_NUGET.md +++ b/README_NUGET.md @@ -52,7 +52,7 @@ Make sure you include the "DOCTYPE html" tag at the top of your HTML, as follows ### 3. DOM Element Binding / Object Watching: ```markdown -
+
Your HTML.
``` @@ -65,9 +65,9 @@ Make sure you include the "DOCTYPE html" tag at the top of your HTML, as follows ``` -To see a list of all the available binding options you can use for "data-observe-options", and "watchObject()", click [here](https://github.com/williamtroup/Observe.js/blob/main/docs/binding/options/OPTIONS.md). +To see a list of all the available binding options you can use for "data-observe-watch-options", and "watchObject()", click [here](https://github.com/williamtroup/Observe.js/blob/main/docs/binding/options/OPTIONS.md). -To see a list of all the available custom triggers you can use for "data-observe-options", and "watchObject()", click [here](https://github.com/williamtroup/Observe.js/blob/main/docs/binding/options/CUSTOM_TRIGGERS.md). +To see a list of all the available custom triggers you can use for "data-observe-watch-options", and "watchObject()", click [here](https://github.com/williamtroup/Observe.js/blob/main/docs/binding/options/CUSTOM_TRIGGERS.md). ### 4. Finishing Up: diff --git a/dist/observe.js b/dist/observe.js index 99a1a14..76d2caf 100644 --- a/dist/observe.js +++ b/dist/observe.js @@ -18,8 +18,8 @@ } function collectDOMObject(element) { var result = true; - if (isDefined(element) && element.hasAttribute(_attribute_Name_Options)) { - var bindingOptionsData = element.getAttribute(_attribute_Name_Options); + if (isDefined(element) && element.hasAttribute(_attribute_Name_Watch_Options)) { + var bindingOptionsData = element.getAttribute(_attribute_Name_Watch_Options); if (isDefinedString(bindingOptionsData)) { var bindingOptions = getObjectFromString(bindingOptionsData); if (bindingOptions.parsed && isDefinedObject(bindingOptions.result)) { @@ -30,13 +30,13 @@ createWatch(element, bindingOptions, element.id); } else { if (!_configuration.safeMode) { - console.error("The attribute '" + _attribute_Name_Options + "' is not a valid object."); + 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_Options + "' has not been set correctly."); + console.error("The attribute '" + _attribute_Name_Watch_Options + "' has not been set correctly."); result = false; } } @@ -290,7 +290,7 @@ var _string = {empty:""}; var _watches = {}; var _configuration = {}; - var _attribute_Name_Options = "data-observe-options"; + var _attribute_Name_Watch_Options = "data-observe-watch-options"; this.watchObject = function(object, options) { return createWatch(object, options); }; diff --git a/dist/observe.min.js b/dist/observe.min.js index 8326d28..305822e 100644 --- a/dist/observe.min.js +++ b/dist/observe.min.js @@ -1,5 +1,5 @@ /*! Observe.js v0.4.0 | (c) Bunoon | MIT License */ -(function(){function I(){for(var a=n.domElementTypes,b=a.length,c=0;c=g.starts){var k=e;if(d.hasOwnProperty(k)){var h=d[k],f=q(h.domElementId),t=null;f&&(t=v.getElementById(h.domElementId),p(t)&&(h.originalObject=t.outerHTML));var y= h.cachedObject,l=h.originalObject,z=f?l:JSON.stringify(l);y!==z&&(l=h.options,l.reset?f?t.outerHTML=h.cachedObject:h.originalObject=w(y).result:h.cachedObject=z,f?A(l.onChange,y,z):(f=w(y).result,t=w(z).result,A(l.onChange,f,t),B(l.onPropertyChange)&&!M(f)&&N(f,t,l)),0=l.maximumChangesBeforeCanceling&&u(k))}x(g.expires)&&m>=g.expires&&u(e)}},g.timeout);d[e]= b}return e}function N(a,b,c){for(var e in a)if(a.hasOwnProperty(e)){var g=a[e],m=null;b.hasOwnProperty(e)&&(m=b[e]);r(g)&&r(m)?N(g,m,c):JSON.stringify(g)!==JSON.stringify(m)&&A(c.onPropertyChange,e,g,m)}}function O(){for(var a in d)d.hasOwnProperty(a)&&u(a)}function u(a){d.hasOwnProperty(a)&&(A(d[a].options.onCancel,a),clearTimeout(d[a].timer),delete d[a])}function D(a,b){var c=!1;d.hasOwnProperty(a)&&(c=d[a].options,c.starts=new Date,c.starts.setMilliseconds(c.starts.getMilliseconds()+b),c=!0);return c} diff --git a/docs/CHANGE_LOG.md b/docs/CHANGE_LOG.md index 4a4a4a1..db44dd2 100644 --- a/docs/CHANGE_LOG.md +++ b/docs/CHANGE_LOG.md @@ -5,6 +5,9 @@ #### **Public Functions:** - Added new public function "searchDomForNewWatches()", which is used to search the DOM for new elements to watch, and adds them. +#### **BREAKING CHANGES:** +- Renamed the DOM attribute "data-observe-options" to "data-observe-watch-options". +
diff --git a/docs/binding/options/CUSTOM_TRIGGERS.md b/docs/binding/options/CUSTOM_TRIGGERS.md index 00defa5..c2ed1df 100644 --- a/docs/binding/options/CUSTOM_TRIGGERS.md +++ b/docs/binding/options/CUSTOM_TRIGGERS.md @@ -1,6 +1,6 @@ # Observe.js - Binding Options - Custom Triggers: -Below is a list of all the custom triggers supported in the "data-observe-options" binding attribute for DOM elements. These options are also supported when calling the public function "watchObject()". +Below is a list of all the custom triggers supported in the "data-observe-watch-options" binding attribute for DOM elements. These options are also supported when calling the public function "watchObject()".

@@ -35,7 +35,7 @@ Fires when a watch has been cancelled.
```markdown -
+
Your HTML.
``` diff --git a/docs/binding/options/OPTIONS.md b/docs/binding/options/OPTIONS.md index 03a6e39..524ee87 100644 --- a/docs/binding/options/OPTIONS.md +++ b/docs/binding/options/OPTIONS.md @@ -1,6 +1,6 @@ # Observe.js - Binding Options: -Below is a list of all the options supported in the "data-observe-options" binding attribute for DOM elements. These options are also supported when calling the public function "watchObject()". +Below is a list of all the options supported in the "data-observe-watch-options" binding attribute for DOM elements. These options are also supported when calling the public function "watchObject()".

@@ -24,7 +24,7 @@ Below is a list of all the options supported in the "data-observe-options" bindi
```markdown -
+
Your HTML.
``` diff --git a/src/observe.js b/src/observe.js index 214f437..9fc081d 100644 --- a/src/observe.js +++ b/src/observe.js @@ -28,7 +28,7 @@ _configuration = {}, // Variables: Attribute Names - _attribute_Name_Options = "data-observe-options"; + _attribute_Name_Watch_Options = "data-observe-watch-options"; /* @@ -57,8 +57,8 @@ function collectDOMObject( element ) { var result = true; - if ( isDefined( element ) && element.hasAttribute( _attribute_Name_Options ) ) { - var bindingOptionsData = element.getAttribute( _attribute_Name_Options ); + if ( isDefined( element ) && element.hasAttribute( _attribute_Name_Watch_Options ) ) { + var bindingOptionsData = element.getAttribute( _attribute_Name_Watch_Options ); if ( isDefinedString( bindingOptionsData ) ) { var bindingOptions = getObjectFromString( bindingOptionsData ); @@ -74,14 +74,14 @@ } else { if ( !_configuration.safeMode ) { - console.error( "The attribute '" + _attribute_Name_Options + "' is not a valid object." ); + 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_Options + "' has not been set correctly." ); + console.error( "The attribute '" + _attribute_Name_Watch_Options + "' has not been set correctly." ); result = false; } } diff --git a/test/dist/observe.js.basic.html b/test/dist/observe.js.basic.html index ca834d5..56fdecf 100644 --- a/test/dist/observe.js.basic.html +++ b/test/dist/observe.js.basic.html @@ -15,11 +15,11 @@

Observe.js - Basic

-
+
When changed, this element should fire a custom trigger.
-
+
When changed, this element should fire a custom trigger (and reset its value back to the original).
diff --git a/test/dist/observe.js.min.html b/test/dist/observe.js.min.html index 0e54e80..493d3f0 100644 --- a/test/dist/observe.js.min.html +++ b/test/dist/observe.js.min.html @@ -15,11 +15,11 @@

Observe.js - Basic

-
+
When changed, this element should fire a custom trigger.
-
+
When changed, this element should fire a custom trigger (and reset its value back to the original).
diff --git a/test/src/observe.js.basic.html b/test/src/observe.js.basic.html index f2f5398..6887fcd 100644 --- a/test/src/observe.js.basic.html +++ b/test/src/observe.js.basic.html @@ -15,11 +15,11 @@

Observe.js - Basic

-
+
When changed, this element should fire a custom trigger.
-
+
When changed, this element should fire a custom trigger (and reset its value back to the original).
From dbbc607278bf9f228969757ad75ab98209c19293 Mon Sep 17 00:00:00 2001 From: William Troup Date: Wed, 3 Jan 2024 13:40:42 +0000 Subject: [PATCH 4/9] Fixed a fault that prevented the binding attribute from being removed from the DOM elements. --- dist/observe.js | 1 + dist/observe.min.js | 20 ++++++++++---------- docs/CHANGE_LOG.md | 3 +++ src/observe.js | 2 ++ 4 files changed, 16 insertions(+), 10 deletions(-) diff --git a/dist/observe.js b/dist/observe.js index 76d2caf..7711aa9 100644 --- a/dist/observe.js +++ b/dist/observe.js @@ -27,6 +27,7 @@ if (!isDefinedString(element.id)) { element.id = newGuid(); } + element.removeAttribute(_attribute_Name_Watch_Options); createWatch(element, bindingOptions, element.id); } else { if (!_configuration.safeMode) { diff --git a/dist/observe.min.js b/dist/observe.min.js index 305822e..1da4a4c 100644 --- a/dist/observe.min.js +++ b/dist/observe.min.js @@ -1,11 +1,11 @@ /*! Observe.js v0.4.0 | (c) Bunoon | MIT License */ -(function(){function I(){for(var a=n.domElementTypes,b=a.length,c=0;c=g.starts){var k=e;if(d.hasOwnProperty(k)){var h=d[k],f=q(h.domElementId),t=null;f&&(t=v.getElementById(h.domElementId),p(t)&&(h.originalObject=t.outerHTML));var y= -h.cachedObject,l=h.originalObject,z=f?l:JSON.stringify(l);y!==z&&(l=h.options,l.reset?f?t.outerHTML=h.cachedObject:h.originalObject=w(y).result:h.cachedObject=z,f?A(l.onChange,y,z):(f=w(y).result,t=w(z).result,A(l.onChange,f,t),B(l.onPropertyChange)&&!M(f)&&N(f,t,l)),0=l.maximumChangesBeforeCanceling&&u(k))}x(g.expires)&&m>=g.expires&&u(e)}},g.timeout);d[e]= -b}return e}function N(a,b,c){for(var e in a)if(a.hasOwnProperty(e)){var g=a[e],m=null;b.hasOwnProperty(e)&&(m=b[e]);r(g)&&r(m)?N(g,m,c):JSON.stringify(g)!==JSON.stringify(m)&&A(c.onPropertyChange,e,g,m)}}function O(){for(var a in d)d.hasOwnProperty(a)&&u(a)}function u(a){d.hasOwnProperty(a)&&(A(d[a].options.onCancel,a),clearTimeout(d[a].timer),delete d[a])}function D(a,b){var c=!1;d.hasOwnProperty(a)&&(c=d[a].options,c.starts=new Date,c.starts.setMilliseconds(c.starts.getMilliseconds()+b),c=!0);return c} -function J(a){a=r(a)?a:{};a.timeout=E(a.timeout,250);var b=a;var c=a.starts;c=x(c)?c:null;b.starts=c;b=a;c=a.expires;c=x(c)?c:null;b.expires=c;a.reset=F(a.reset,!1);a.cancelOnChange=F(a.cancelOnChange,!1);a.maximumChangesBeforeCanceling=E(a.maximumChangesBeforeCanceling,0);a.pauseTimeoutOnChange=E(a.pauseTimeoutOnChange,0);a.onChange=G(a.onChange,null);a.onPropertyChange=G(a.onPropertyChange,null);a.onCancel=G(a.onCancel,null);return a}function A(a){B(a)&&a.apply(null,[].slice.call(arguments,1))} -function K(){for(var a=[],b=0;32>b;b++){8!==b&&12!==b&&16!==b&&20!==b||a.push("-");var c=Math.floor(16*Math.random()).toString(16);a.push(c)}return a.join(H.empty)}function p(a){return null!==a&&void 0!==a&&a!==H.empty}function r(a){return p(a)&&"object"===typeof a}function q(a){return p(a)&&"string"===typeof a}function B(a){return p(a)&&"function"===typeof a}function M(a){return r(a)&&a instanceof Array}function x(a){return r(a)&&a instanceof Date}function F(a,b){return p(a)&&"boolean"===typeof a? -a:b}function G(a,b){return B(a)?a:b}function E(a,b){return p(a)&&"number"===typeof a?a:b}function w(a){var b=!0,c=null;try{q(a)&&(c=JSON.parse(a))}catch(e){try{c=eval("("+a+")"),B(c)&&(c=c())}catch(g){b=Q("Errors in object: "+e.message+", "+g.message),c=null}}return{parsed:b,result:c}}function Q(a){var b=!0;n.safeMode||(console.error(a),b=!1);return b}function P(){n.safeMode=F(n.safeMode,!0);var a=n,b=n.domElementTypes,c=["*"];q(b)?(b=b.split(H.space),0===b.length&&(b=c)):b=M(b)?b:c;a.domElementTypes= -b}var v=null,C=null,H={empty:""},d={},n={};this.watchObject=function(a,b){return L(a,b)};this.cancelWatch=function(a){var b=!1;if(d.hasOwnProperty(a))u(a),b=!0;else for(var c in d)if(d.hasOwnProperty(c)&&q(d[c].domElementId)&&d[c].domElementId===a){u(c);b=!0;break}return b};this.cancelWatches=function(){O();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=D(a,b);else for(var e in d)if(d.hasOwnProperty(e)&&q(d[e].domElementId)&&d[e].domElementId===a){c=D(e,b);break}return c};this.searchDomForNewWatches=function(){I();return this};this.setConfiguration=function(a){n=r(a)?a:{};P();return this};this.getVersion=function(){return"0.4.0"};(function(a,b){v=a;C=b;P();v.addEventListener("DOMContentLoaded",function(){I()});C.addEventListener("unload",function(){O()}); -p(C.$observe)||(C.$observe=this)})(document,window)})(); \ No newline at end of file +(function(){function I(){for(var a=n.domElementTypes,b=a.length,c=0;c=g.starts){var k=e;if(d.hasOwnProperty(k)){var h=d[k],f= +q(h.domElementId),t=null;f&&(t=v.getElementById(h.domElementId),p(t)&&(h.originalObject=t.outerHTML));var y=h.cachedObject,l=h.originalObject,z=f?l:JSON.stringify(l);y!==z&&(l=h.options,l.reset?f?t.outerHTML=h.cachedObject:h.originalObject=w(y).result:h.cachedObject=z,f?A(l.onChange,y,z):(f=w(y).result,t=w(z).result,A(l.onChange,f,t),B(l.onPropertyChange)&&!M(f)&&N(f,t,l)),0=l.maximumChangesBeforeCanceling&&u(k))}x(g.expires)&&m>=g.expires&&u(e)}},g.timeout);d[e]=b}return e}function N(a,b,c){for(var e in a)if(a.hasOwnProperty(e)){var g=a[e],m=null;b.hasOwnProperty(e)&&(m=b[e]);r(g)&&r(m)?N(g,m,c):JSON.stringify(g)!==JSON.stringify(m)&&A(c.onPropertyChange,e,g,m)}}function O(){for(var a in d)d.hasOwnProperty(a)&&u(a)}function u(a){d.hasOwnProperty(a)&&(A(d[a].options.onCancel,a),clearTimeout(d[a].timer),delete d[a])}function D(a,b){var c=!1;d.hasOwnProperty(a)&& +(c=d[a].options,c.starts=new Date,c.starts.setMilliseconds(c.starts.getMilliseconds()+b),c=!0);return c}function J(a){a=r(a)?a:{};a.timeout=E(a.timeout,250);var b=a;var c=a.starts;c=x(c)?c:null;b.starts=c;b=a;c=a.expires;c=x(c)?c:null;b.expires=c;a.reset=F(a.reset,!1);a.cancelOnChange=F(a.cancelOnChange,!1);a.maximumChangesBeforeCanceling=E(a.maximumChangesBeforeCanceling,0);a.pauseTimeoutOnChange=E(a.pauseTimeoutOnChange,0);a.onChange=G(a.onChange,null);a.onPropertyChange=G(a.onPropertyChange,null); +a.onCancel=G(a.onCancel,null);return a}function A(a){B(a)&&a.apply(null,[].slice.call(arguments,1))}function K(){for(var a=[],b=0;32>b;b++){8!==b&&12!==b&&16!==b&&20!==b||a.push("-");var c=Math.floor(16*Math.random()).toString(16);a.push(c)}return a.join(H.empty)}function p(a){return null!==a&&void 0!==a&&a!==H.empty}function r(a){return p(a)&&"object"===typeof a}function q(a){return p(a)&&"string"===typeof a}function B(a){return p(a)&&"function"===typeof a}function M(a){return r(a)&&a instanceof +Array}function x(a){return r(a)&&a instanceof Date}function F(a,b){return p(a)&&"boolean"===typeof a?a:b}function G(a,b){return B(a)?a:b}function E(a,b){return p(a)&&"number"===typeof a?a:b}function w(a){var b=!0,c=null;try{q(a)&&(c=JSON.parse(a))}catch(e){try{c=eval("("+a+")"),B(c)&&(c=c())}catch(g){b=Q("Errors in object: "+e.message+", "+g.message),c=null}}return{parsed:b,result:c}}function Q(a){var b=!0;n.safeMode||(console.error(a),b=!1);return b}function P(){n.safeMode=F(n.safeMode,!0);var a= +n,b=n.domElementTypes,c=["*"];q(b)?(b=b.split(H.space),0===b.length&&(b=c)):b=M(b)?b:c;a.domElementTypes=b}var v=null,C=null,H={empty:""},d={},n={};this.watchObject=function(a,b){return L(a,b)};this.cancelWatch=function(a){var b=!1;if(d.hasOwnProperty(a))u(a),b=!0;else for(var c in d)if(d.hasOwnProperty(c)&&q(d[c].domElementId)&&d[c].domElementId===a){u(c);b=!0;break}return b};this.cancelWatches=function(){O();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=D(a,b);else for(var e in d)if(d.hasOwnProperty(e)&&q(d[e].domElementId)&&d[e].domElementId===a){c=D(e,b);break}return c};this.searchDomForNewWatches=function(){I();return this};this.setConfiguration=function(a){n=r(a)?a:{};P();return this};this.getVersion=function(){return"0.4.0"};(function(a,b){v=a;C=b;P();v.addEventListener("DOMContentLoaded", +function(){I()});C.addEventListener("unload",function(){O()});p(C.$observe)||(C.$observe=this)})(document,window)})(); \ No newline at end of file diff --git a/docs/CHANGE_LOG.md b/docs/CHANGE_LOG.md index db44dd2..e0b1825 100644 --- a/docs/CHANGE_LOG.md +++ b/docs/CHANGE_LOG.md @@ -8,6 +8,9 @@ #### **BREAKING CHANGES:** - Renamed the DOM attribute "data-observe-options" to "data-observe-watch-options". +#### **Fixes:** +- Fixed a fault that prevented the binding attribute from being removed from the DOM elements. +
diff --git a/src/observe.js b/src/observe.js index 9fc081d..849226c 100644 --- a/src/observe.js +++ b/src/observe.js @@ -70,6 +70,8 @@ element.id = newGuid(); } + element.removeAttribute( _attribute_Name_Watch_Options ); + createWatch( element, bindingOptions, element.id ); } else { From a1abd334f3990d6d54723b787fcb1059854840a5 Mon Sep 17 00:00:00 2001 From: William Troup Date: Wed, 3 Jan 2024 13:48:46 +0000 Subject: [PATCH 5/9] Fixed a fault that prevented changes from being detected when a DOM element is removed from the DOM. --- dist/observe.js | 2 ++ dist/observe.min.js | 20 ++++++++++---------- docs/CHANGE_LOG.md | 1 + src/observe.js | 2 ++ 4 files changed, 15 insertions(+), 10 deletions(-) diff --git a/dist/observe.js b/dist/observe.js index 7711aa9..d700bc7 100644 --- a/dist/observe.js +++ b/dist/observe.js @@ -85,6 +85,8 @@ domElement = _parameter_Document.getElementById(watch.domElementId); if (isDefined(domElement)) { watch.originalObject = domElement.outerHTML; + } else { + watch.originalObject = _string.empty; } } var cachedObject = watch.cachedObject; diff --git a/dist/observe.min.js b/dist/observe.min.js index 1da4a4c..a578a76 100644 --- a/dist/observe.min.js +++ b/dist/observe.min.js @@ -1,11 +1,11 @@ /*! Observe.js v0.4.0 | (c) Bunoon | MIT License */ -(function(){function I(){for(var a=n.domElementTypes,b=a.length,c=0;c=g.starts){var k=e;if(d.hasOwnProperty(k)){var h=d[k],f= -q(h.domElementId),t=null;f&&(t=v.getElementById(h.domElementId),p(t)&&(h.originalObject=t.outerHTML));var y=h.cachedObject,l=h.originalObject,z=f?l:JSON.stringify(l);y!==z&&(l=h.options,l.reset?f?t.outerHTML=h.cachedObject:h.originalObject=w(y).result:h.cachedObject=z,f?A(l.onChange,y,z):(f=w(y).result,t=w(z).result,A(l.onChange,f,t),B(l.onPropertyChange)&&!M(f)&&N(f,t,l)),0=l.maximumChangesBeforeCanceling&&u(k))}x(g.expires)&&m>=g.expires&&u(e)}},g.timeout);d[e]=b}return e}function N(a,b,c){for(var e in a)if(a.hasOwnProperty(e)){var g=a[e],m=null;b.hasOwnProperty(e)&&(m=b[e]);r(g)&&r(m)?N(g,m,c):JSON.stringify(g)!==JSON.stringify(m)&&A(c.onPropertyChange,e,g,m)}}function O(){for(var a in d)d.hasOwnProperty(a)&&u(a)}function u(a){d.hasOwnProperty(a)&&(A(d[a].options.onCancel,a),clearTimeout(d[a].timer),delete d[a])}function D(a,b){var c=!1;d.hasOwnProperty(a)&& -(c=d[a].options,c.starts=new Date,c.starts.setMilliseconds(c.starts.getMilliseconds()+b),c=!0);return c}function J(a){a=r(a)?a:{};a.timeout=E(a.timeout,250);var b=a;var c=a.starts;c=x(c)?c:null;b.starts=c;b=a;c=a.expires;c=x(c)?c:null;b.expires=c;a.reset=F(a.reset,!1);a.cancelOnChange=F(a.cancelOnChange,!1);a.maximumChangesBeforeCanceling=E(a.maximumChangesBeforeCanceling,0);a.pauseTimeoutOnChange=E(a.pauseTimeoutOnChange,0);a.onChange=G(a.onChange,null);a.onPropertyChange=G(a.onPropertyChange,null); -a.onCancel=G(a.onCancel,null);return a}function A(a){B(a)&&a.apply(null,[].slice.call(arguments,1))}function K(){for(var a=[],b=0;32>b;b++){8!==b&&12!==b&&16!==b&&20!==b||a.push("-");var c=Math.floor(16*Math.random()).toString(16);a.push(c)}return a.join(H.empty)}function p(a){return null!==a&&void 0!==a&&a!==H.empty}function r(a){return p(a)&&"object"===typeof a}function q(a){return p(a)&&"string"===typeof a}function B(a){return p(a)&&"function"===typeof a}function M(a){return r(a)&&a instanceof -Array}function x(a){return r(a)&&a instanceof Date}function F(a,b){return p(a)&&"boolean"===typeof a?a:b}function G(a,b){return B(a)?a:b}function E(a,b){return p(a)&&"number"===typeof a?a:b}function w(a){var b=!0,c=null;try{q(a)&&(c=JSON.parse(a))}catch(e){try{c=eval("("+a+")"),B(c)&&(c=c())}catch(g){b=Q("Errors in object: "+e.message+", "+g.message),c=null}}return{parsed:b,result:c}}function Q(a){var b=!0;n.safeMode||(console.error(a),b=!1);return b}function P(){n.safeMode=F(n.safeMode,!0);var a= -n,b=n.domElementTypes,c=["*"];q(b)?(b=b.split(H.space),0===b.length&&(b=c)):b=M(b)?b:c;a.domElementTypes=b}var v=null,C=null,H={empty:""},d={},n={};this.watchObject=function(a,b){return L(a,b)};this.cancelWatch=function(a){var b=!1;if(d.hasOwnProperty(a))u(a),b=!0;else for(var c in d)if(d.hasOwnProperty(c)&&q(d[c].domElementId)&&d[c].domElementId===a){u(c);b=!0;break}return b};this.cancelWatches=function(){O();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=D(a,b);else for(var e in d)if(d.hasOwnProperty(e)&&q(d[e].domElementId)&&d[e].domElementId===a){c=D(e,b);break}return c};this.searchDomForNewWatches=function(){I();return this};this.setConfiguration=function(a){n=r(a)?a:{};P();return this};this.getVersion=function(){return"0.4.0"};(function(a,b){v=a;C=b;P();v.addEventListener("DOMContentLoaded", -function(){I()});C.addEventListener("unload",function(){O()});p(C.$observe)||(C.$observe=this)})(document,window)})(); \ No newline at end of file +(function(){function I(){for(var a=n.domElementTypes,b=a.length,c=0;c=h.starts){var k=e;if(d.hasOwnProperty(k)){var g=d[k],f= +q(g.domElementId),t=null;f&&(t=v.getElementById(g.domElementId),p(t)?g.originalObject=t.outerHTML:g.originalObject=y.empty);var z=g.cachedObject,l=g.originalObject,A=f?l:JSON.stringify(l);z!==A&&(l=g.options,l.reset?f?t.outerHTML=g.cachedObject:g.originalObject=w(z).result:g.cachedObject=A,f?B(l.onChange,z,A):(f=w(z).result,t=w(A).result,B(l.onChange,f,t),C(l.onPropertyChange)&&!M(f)&&N(f,t,l)),0=l.maximumChangesBeforeCanceling&&u(k))}x(h.expires)&&m>=h.expires&&u(e)}},h.timeout);d[e]=b}return e}function N(a,b,c){for(var e in a)if(a.hasOwnProperty(e)){var h=a[e],m=null;b.hasOwnProperty(e)&&(m=b[e]);r(h)&&r(m)?N(h,m,c):JSON.stringify(h)!==JSON.stringify(m)&&B(c.onPropertyChange,e,h,m)}}function O(){for(var a in d)d.hasOwnProperty(a)&&u(a)}function u(a){d.hasOwnProperty(a)&&(B(d[a].options.onCancel,a),clearTimeout(d[a].timer),delete d[a])}function E(a,b){var c=!1;d.hasOwnProperty(a)&& +(c=d[a].options,c.starts=new Date,c.starts.setMilliseconds(c.starts.getMilliseconds()+b),c=!0);return c}function J(a){a=r(a)?a:{};a.timeout=F(a.timeout,250);var b=a;var c=a.starts;c=x(c)?c:null;b.starts=c;b=a;c=a.expires;c=x(c)?c:null;b.expires=c;a.reset=G(a.reset,!1);a.cancelOnChange=G(a.cancelOnChange,!1);a.maximumChangesBeforeCanceling=F(a.maximumChangesBeforeCanceling,0);a.pauseTimeoutOnChange=F(a.pauseTimeoutOnChange,0);a.onChange=H(a.onChange,null);a.onPropertyChange=H(a.onPropertyChange,null); +a.onCancel=H(a.onCancel,null);return a}function B(a){C(a)&&a.apply(null,[].slice.call(arguments,1))}function K(){for(var a=[],b=0;32>b;b++){8!==b&&12!==b&&16!==b&&20!==b||a.push("-");var c=Math.floor(16*Math.random()).toString(16);a.push(c)}return a.join(y.empty)}function p(a){return null!==a&&void 0!==a&&a!==y.empty}function r(a){return p(a)&&"object"===typeof a}function q(a){return p(a)&&"string"===typeof a}function C(a){return p(a)&&"function"===typeof a}function M(a){return r(a)&&a instanceof +Array}function x(a){return r(a)&&a instanceof Date}function G(a,b){return p(a)&&"boolean"===typeof a?a:b}function H(a,b){return C(a)?a:b}function F(a,b){return p(a)&&"number"===typeof a?a:b}function w(a){var b=!0,c=null;try{q(a)&&(c=JSON.parse(a))}catch(e){try{c=eval("("+a+")"),C(c)&&(c=c())}catch(h){b=Q("Errors in object: "+e.message+", "+h.message),c=null}}return{parsed:b,result:c}}function Q(a){var b=!0;n.safeMode||(console.error(a),b=!1);return b}function P(){n.safeMode=G(n.safeMode,!0);var a= +n,b=n.domElementTypes,c=["*"];q(b)?(b=b.split(y.space),0===b.length&&(b=c)):b=M(b)?b:c;a.domElementTypes=b}var v=null,D=null,y={empty:""},d={},n={};this.watchObject=function(a,b){return L(a,b)};this.cancelWatch=function(a){var b=!1;if(d.hasOwnProperty(a))u(a),b=!0;else for(var c in d)if(d.hasOwnProperty(c)&&q(d[c].domElementId)&&d[c].domElementId===a){u(c);b=!0;break}return b};this.cancelWatches=function(){O();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=E(a,b);else for(var e in d)if(d.hasOwnProperty(e)&&q(d[e].domElementId)&&d[e].domElementId===a){c=E(e,b);break}return c};this.searchDomForNewWatches=function(){I();return this};this.setConfiguration=function(a){n=r(a)?a:{};P();return this};this.getVersion=function(){return"0.4.0"};(function(a,b){v=a;D=b;P();v.addEventListener("DOMContentLoaded", +function(){I()});D.addEventListener("unload",function(){O()});p(D.$observe)||(D.$observe=this)})(document,window)})(); \ No newline at end of file diff --git a/docs/CHANGE_LOG.md b/docs/CHANGE_LOG.md index e0b1825..40f37bd 100644 --- a/docs/CHANGE_LOG.md +++ b/docs/CHANGE_LOG.md @@ -10,6 +10,7 @@ #### **Fixes:** - Fixed a fault that prevented the binding attribute from being removed from the DOM elements. +- Fixed a fault that prevented changes from being detected when a DOM element is removed from the DOM.
diff --git a/src/observe.js b/src/observe.js index 849226c..01245f8 100644 --- a/src/observe.js +++ b/src/observe.js @@ -155,6 +155,8 @@ if ( isDefined( domElement ) ) { watch.originalObject = domElement.outerHTML; + } else { + watch.originalObject = _string.empty; } } From ace36a8d5abd4707dd8f6f5a12e8deb90817d290 Mon Sep 17 00:00:00 2001 From: William Troup Date: Wed, 3 Jan 2024 13:53:58 +0000 Subject: [PATCH 6/9] Minor internal refactoring to make things a little clearer. --- dist/observe.js | 22 ++++++++++------------ dist/observe.min.js | 20 ++++++++++---------- docs/CHANGE_LOG.md | 3 +++ src/observe.js | 26 +++++++++++--------------- 4 files changed, 34 insertions(+), 37 deletions(-) diff --git a/dist/observe.js b/dist/observe.js index d700bc7..5ccc530 100644 --- a/dist/observe.js +++ b/dist/observe.js @@ -93,8 +93,7 @@ var originalObject = watch.originalObject; var originalObjectJson = !isDomElement ? JSON.stringify(originalObject) : originalObject; if (cachedObject !== originalObjectJson) { - var watchOptions = watch.options; - if (watchOptions.reset) { + if (watch.options.reset) { if (isDomElement) { domElement.outerHTML = watch.cachedObject; } else { @@ -104,23 +103,23 @@ watch.cachedObject = originalObjectJson; } if (isDomElement) { - fireCustomTrigger(watchOptions.onChange, cachedObject, originalObjectJson); + fireCustomTrigger(watch.options.onChange, cachedObject, originalObjectJson); } else { var oldValue = getObjectFromString(cachedObject).result; var newValue = getObjectFromString(originalObjectJson).result; - fireCustomTrigger(watchOptions.onChange, oldValue, newValue); - if (isDefinedFunction(watchOptions.onPropertyChange) && !isDefinedArray(oldValue)) { - compareWatchObjectProperties(oldValue, newValue, watchOptions); + fireCustomTrigger(watch.options.onChange, oldValue, newValue); + if (isDefinedFunction(watch.options.onPropertyChange) && !isDefinedArray(oldValue)) { + compareWatchObjectProperties(oldValue, newValue, watch.options); } } - if (watchOptions.pauseTimeoutOnChange > 0) { - pauseWatchObject(storageId, watchOptions.pauseTimeoutOnChange); + if (watch.options.pauseTimeoutOnChange > 0) { + pauseWatchObject(storageId, watch.options.pauseTimeoutOnChange); } - if (watchOptions.cancelOnChange) { + if (watch.options.cancelOnChange) { cancelWatchObject(storageId); } watch.totalChanges++; - if (watchOptions.maximumChangesBeforeCanceling > 0 && watch.totalChanges >= watchOptions.maximumChangesBeforeCanceling) { + if (watch.options.maximumChangesBeforeCanceling > 0 && watch.totalChanges >= watch.options.maximumChangesBeforeCanceling) { cancelWatchObject(storageId); } } @@ -155,8 +154,7 @@ } function cancelWatchObject(storageId) { if (_watches.hasOwnProperty(storageId)) { - var watchOptions = _watches[storageId].options; - fireCustomTrigger(watchOptions.onCancel, storageId); + fireCustomTrigger(_watches[storageId].options.onCancel, storageId); clearTimeout(_watches[storageId].timer); delete _watches[storageId]; } diff --git a/dist/observe.min.js b/dist/observe.min.js index a578a76..d9d6828 100644 --- a/dist/observe.min.js +++ b/dist/observe.min.js @@ -1,11 +1,11 @@ /*! Observe.js v0.4.0 | (c) Bunoon | MIT License */ -(function(){function I(){for(var a=n.domElementTypes,b=a.length,c=0;c=h.starts){var k=e;if(d.hasOwnProperty(k)){var g=d[k],f= -q(g.domElementId),t=null;f&&(t=v.getElementById(g.domElementId),p(t)?g.originalObject=t.outerHTML:g.originalObject=y.empty);var z=g.cachedObject,l=g.originalObject,A=f?l:JSON.stringify(l);z!==A&&(l=g.options,l.reset?f?t.outerHTML=g.cachedObject:g.originalObject=w(z).result:g.cachedObject=A,f?B(l.onChange,z,A):(f=w(z).result,t=w(A).result,B(l.onChange,f,t),C(l.onPropertyChange)&&!M(f)&&N(f,t,l)),0=l.maximumChangesBeforeCanceling&&u(k))}x(h.expires)&&m>=h.expires&&u(e)}},h.timeout);d[e]=b}return e}function N(a,b,c){for(var e in a)if(a.hasOwnProperty(e)){var h=a[e],m=null;b.hasOwnProperty(e)&&(m=b[e]);r(h)&&r(m)?N(h,m,c):JSON.stringify(h)!==JSON.stringify(m)&&B(c.onPropertyChange,e,h,m)}}function O(){for(var a in d)d.hasOwnProperty(a)&&u(a)}function u(a){d.hasOwnProperty(a)&&(B(d[a].options.onCancel,a),clearTimeout(d[a].timer),delete d[a])}function E(a,b){var c=!1;d.hasOwnProperty(a)&& -(c=d[a].options,c.starts=new Date,c.starts.setMilliseconds(c.starts.getMilliseconds()+b),c=!0);return c}function J(a){a=r(a)?a:{};a.timeout=F(a.timeout,250);var b=a;var c=a.starts;c=x(c)?c:null;b.starts=c;b=a;c=a.expires;c=x(c)?c:null;b.expires=c;a.reset=G(a.reset,!1);a.cancelOnChange=G(a.cancelOnChange,!1);a.maximumChangesBeforeCanceling=F(a.maximumChangesBeforeCanceling,0);a.pauseTimeoutOnChange=F(a.pauseTimeoutOnChange,0);a.onChange=H(a.onChange,null);a.onPropertyChange=H(a.onPropertyChange,null); -a.onCancel=H(a.onCancel,null);return a}function B(a){C(a)&&a.apply(null,[].slice.call(arguments,1))}function K(){for(var a=[],b=0;32>b;b++){8!==b&&12!==b&&16!==b&&20!==b||a.push("-");var c=Math.floor(16*Math.random()).toString(16);a.push(c)}return a.join(y.empty)}function p(a){return null!==a&&void 0!==a&&a!==y.empty}function r(a){return p(a)&&"object"===typeof a}function q(a){return p(a)&&"string"===typeof a}function C(a){return p(a)&&"function"===typeof a}function M(a){return r(a)&&a instanceof -Array}function x(a){return r(a)&&a instanceof Date}function G(a,b){return p(a)&&"boolean"===typeof a?a:b}function H(a,b){return C(a)?a:b}function F(a,b){return p(a)&&"number"===typeof a?a:b}function w(a){var b=!0,c=null;try{q(a)&&(c=JSON.parse(a))}catch(e){try{c=eval("("+a+")"),C(c)&&(c=c())}catch(h){b=Q("Errors in object: "+e.message+", "+h.message),c=null}}return{parsed:b,result:c}}function Q(a){var b=!0;n.safeMode||(console.error(a),b=!1);return b}function P(){n.safeMode=G(n.safeMode,!0);var a= -n,b=n.domElementTypes,c=["*"];q(b)?(b=b.split(y.space),0===b.length&&(b=c)):b=M(b)?b:c;a.domElementTypes=b}var v=null,D=null,y={empty:""},d={},n={};this.watchObject=function(a,b){return L(a,b)};this.cancelWatch=function(a){var b=!1;if(d.hasOwnProperty(a))u(a),b=!0;else for(var c in d)if(d.hasOwnProperty(c)&&q(d[c].domElementId)&&d[c].domElementId===a){u(c);b=!0;break}return b};this.cancelWatches=function(){O();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=E(a,b);else for(var e in d)if(d.hasOwnProperty(e)&&q(d[e].domElementId)&&d[e].domElementId===a){c=E(e,b);break}return c};this.searchDomForNewWatches=function(){I();return this};this.setConfiguration=function(a){n=r(a)?a:{};P();return this};this.getVersion=function(){return"0.4.0"};(function(a,b){v=a;D=b;P();v.addEventListener("DOMContentLoaded", -function(){I()});D.addEventListener("unload",function(){O()});p(D.$observe)||(D.$observe=this)})(document,window)})(); \ No newline at end of file +(function(){function H(){for(var a=m.domElementTypes,b=a.length,c=0;c=h.starts){var k=f;if(d.hasOwnProperty(k)){var e=d[k],g= +p(e.domElementId),r=null;g&&(r=v.getElementById(e.domElementId),n(r)?e.originalObject=r.outerHTML:e.originalObject=y.empty);var z=e.cachedObject,t=e.originalObject;t=g?t:JSON.stringify(t);z!==t&&(e.options.reset?g?r.outerHTML=e.cachedObject:e.originalObject=w(z).result:e.cachedObject=t,g?A(e.options.onChange,z,t):(g=w(z).result,r=w(t).result,A(e.options.onChange,g,r),B(e.options.onPropertyChange)&&!L(g)&&M(g,r,e.options)),0=e.options.maximumChangesBeforeCanceling&&u(k))}x(h.expires)&&l>=h.expires&&u(f)}},h.timeout);d[f]=b}return f}function M(a,b,c){for(var f in a)if(a.hasOwnProperty(f)){var h=a[f],l=null;b.hasOwnProperty(f)&&(l=b[f]);q(h)&&q(l)?M(h,l,c):JSON.stringify(h)!==JSON.stringify(l)&&A(c.onPropertyChange,f,h,l)}}function N(){for(var a in d)d.hasOwnProperty(a)&&u(a)}function u(a){d.hasOwnProperty(a)&&(A(d[a].options.onCancel,a),clearTimeout(d[a].timer), +delete d[a])}function D(a,b){var c=!1;d.hasOwnProperty(a)&&(c=d[a].options,c.starts=new Date,c.starts.setMilliseconds(c.starts.getMilliseconds()+b),c=!0);return c}function I(a){a=q(a)?a:{};a.timeout=E(a.timeout,250);var b=a;var c=a.starts;c=x(c)?c:null;b.starts=c;b=a;c=a.expires;c=x(c)?c:null;b.expires=c;a.reset=F(a.reset,!1);a.cancelOnChange=F(a.cancelOnChange,!1);a.maximumChangesBeforeCanceling=E(a.maximumChangesBeforeCanceling,0);a.pauseTimeoutOnChange=E(a.pauseTimeoutOnChange,0);a.onChange=G(a.onChange, +null);a.onPropertyChange=G(a.onPropertyChange,null);a.onCancel=G(a.onCancel,null);return a}function A(a){B(a)&&a.apply(null,[].slice.call(arguments,1))}function J(){for(var a=[],b=0;32>b;b++){8!==b&&12!==b&&16!==b&&20!==b||a.push("-");var c=Math.floor(16*Math.random()).toString(16);a.push(c)}return a.join(y.empty)}function n(a){return null!==a&&void 0!==a&&a!==y.empty}function q(a){return n(a)&&"object"===typeof a}function p(a){return n(a)&&"string"===typeof a}function B(a){return n(a)&&"function"=== +typeof a}function L(a){return q(a)&&a instanceof Array}function x(a){return q(a)&&a instanceof Date}function F(a,b){return n(a)&&"boolean"===typeof a?a:b}function G(a,b){return B(a)?a:b}function E(a,b){return n(a)&&"number"===typeof a?a:b}function w(a){var b=!0,c=null;try{p(a)&&(c=JSON.parse(a))}catch(f){try{c=eval("("+a+")"),B(c)&&(c=c())}catch(h){b=P("Errors in object: "+f.message+", "+h.message),c=null}}return{parsed:b,result:c}}function P(a){var b=!0;m.safeMode||(console.error(a),b=!1);return b} +function O(){m.safeMode=F(m.safeMode,!0);var a=m,b=m.domElementTypes,c=["*"];p(b)?(b=b.split(y.space),0===b.length&&(b=c)):b=L(b)?b:c;a.domElementTypes=b}var v=null,C=null,y={empty:""},d={},m={};this.watchObject=function(a,b){return K(a,b)};this.cancelWatch=function(a){var b=!1;if(d.hasOwnProperty(a))u(a),b=!0;else for(var c in d)if(d.hasOwnProperty(c)&&p(d[c].domElementId)&&d[c].domElementId===a){u(c);b=!0;break}return b};this.cancelWatches=function(){N();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)&&p(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=D(a,b);else for(var f in d)if(d.hasOwnProperty(f)&&p(d[f].domElementId)&&d[f].domElementId===a){c=D(f,b);break}return c};this.searchDomForNewWatches=function(){H();return this};this.setConfiguration=function(a){m=q(a)?a:{};O();return this};this.getVersion= +function(){return"0.4.0"};(function(a,b){v=a;C=b;O();v.addEventListener("DOMContentLoaded",function(){H()});C.addEventListener("unload",function(){N()});n(C.$observe)||(C.$observe=this)})(document,window)})(); \ No newline at end of file diff --git a/docs/CHANGE_LOG.md b/docs/CHANGE_LOG.md index 40f37bd..81ee64c 100644 --- a/docs/CHANGE_LOG.md +++ b/docs/CHANGE_LOG.md @@ -8,6 +8,9 @@ #### **BREAKING CHANGES:** - Renamed the DOM attribute "data-observe-options" to "data-observe-watch-options". +#### **General Improvements:** +- Minor internal refactoring to make things a little clearer. + #### **Fixes:** - Fixed a fault that prevented the binding attribute from being removed from the DOM elements. - Fixed a fault that prevented changes from being detected when a DOM element is removed from the DOM. diff --git a/src/observe.js b/src/observe.js index 01245f8..88cbc58 100644 --- a/src/observe.js +++ b/src/observe.js @@ -165,9 +165,7 @@ originalObjectJson = !isDomElement ? JSON.stringify( originalObject ) : originalObject; if ( cachedObject !== originalObjectJson ) { - var watchOptions = watch.options; - - if ( watchOptions.reset ) { + if ( watch.options.reset ) { if ( isDomElement ) { domElement.outerHTML = watch.cachedObject; } else { @@ -179,30 +177,30 @@ } if ( isDomElement ) { - fireCustomTrigger( watchOptions.onChange, cachedObject, originalObjectJson ); + fireCustomTrigger( watch.options.onChange, cachedObject, originalObjectJson ); } else { var oldValue = getObjectFromString( cachedObject ).result, newValue = getObjectFromString( originalObjectJson ).result; - fireCustomTrigger( watchOptions.onChange, oldValue, newValue ); + fireCustomTrigger( watch.options.onChange, oldValue, newValue ); - if ( isDefinedFunction( watchOptions.onPropertyChange ) && !isDefinedArray( oldValue ) ) { - compareWatchObjectProperties( oldValue, newValue, watchOptions ); + if ( isDefinedFunction( watch.options.onPropertyChange ) && !isDefinedArray( oldValue ) ) { + compareWatchObjectProperties( oldValue, newValue, watch.options ); } } - if ( watchOptions.pauseTimeoutOnChange > 0 ) { - pauseWatchObject( storageId, watchOptions.pauseTimeoutOnChange ); + if ( watch.options.pauseTimeoutOnChange > 0 ) { + pauseWatchObject( storageId, watch.options.pauseTimeoutOnChange ); } - if ( watchOptions.cancelOnChange ) { + if ( watch.options.cancelOnChange ) { cancelWatchObject( storageId ); } watch.totalChanges++; - if ( watchOptions.maximumChangesBeforeCanceling > 0 && watch.totalChanges >= watchOptions.maximumChangesBeforeCanceling ) { + if ( watch.options.maximumChangesBeforeCanceling > 0 && watch.totalChanges >= watch.options.maximumChangesBeforeCanceling ) { cancelWatchObject( storageId ); } } @@ -241,11 +239,9 @@ function cancelWatchObject( storageId ) { if ( _watches.hasOwnProperty( storageId ) ) { - var watchOptions = _watches[ storageId ].options; - - fireCustomTrigger( watchOptions.onCancel, storageId ); - + fireCustomTrigger( _watches[ storageId ].options.onCancel, storageId ); clearTimeout( _watches[ storageId ].timer ); + delete _watches[ storageId ]; } } From 21467de609f23ad2fdffeeb31379ff787eda6227 Mon Sep 17 00:00:00 2001 From: William Troup Date: Wed, 3 Jan 2024 20:13:31 +0000 Subject: [PATCH 7/9] Fixed some properties being assigned to internal watches when not required. --- dist/observe.js | 19 +++++++++++-------- dist/observe.min.js | 10 +++++----- docs/CHANGE_LOG.md | 1 + src/observe.js | 25 ++++++++++++++----------- 4 files changed, 31 insertions(+), 24 deletions(-) diff --git a/dist/observe.js b/dist/observe.js index 5ccc530..679cee8 100644 --- a/dist/observe.js +++ b/dist/observe.js @@ -51,11 +51,11 @@ var watchOptions = getWatchOptions(options); var watch = {}; watch.options = watchOptions; - watch.domElementId = domElementId; watch.totalChanges = 0; if (isDefinedString(domElementId)) { var domElement = _parameter_Document.getElementById(domElementId); if (isDefined(domElement)) { + watch.domElementId = domElementId; watch.cachedObject = domElement.outerHTML; watch.originalObject = domElement.outerHTML; } @@ -64,18 +64,21 @@ watch.originalObject = object; } watch.timer = setInterval(function() { - var currentDateTime = new Date(); - if (!isDefinedDate(watchOptions.starts) || currentDateTime >= watchOptions.starts) { - watchObjectForChanges(storageId); - if (isDefinedDate(watchOptions.expires) && currentDateTime >= watchOptions.expires) { - cancelWatchObject(storageId); - } - } + watchTimer(watchOptions, storageId); }, watchOptions.timeout); _watches[storageId] = watch; } return storageId; } + function watchTimer(watchOptions, storageId) { + var currentDateTime = new Date(); + if (!isDefinedDate(watchOptions.starts) || currentDateTime >= watchOptions.starts) { + watchObjectForChanges(storageId); + if (isDefinedDate(watchOptions.expires) && currentDateTime >= watchOptions.expires) { + cancelWatchObject(storageId); + } + } + } function watchObjectForChanges(storageId) { if (_watches.hasOwnProperty(storageId)) { var watch = _watches[storageId]; diff --git a/dist/observe.min.js b/dist/observe.min.js index d9d6828..286321a 100644 --- a/dist/observe.min.js +++ b/dist/observe.min.js @@ -1,11 +1,11 @@ /*! Observe.js v0.4.0 | (c) Bunoon | MIT License */ -(function(){function H(){for(var a=m.domElementTypes,b=a.length,c=0;c=h.starts){var k=f;if(d.hasOwnProperty(k)){var e=d[k],g= -p(e.domElementId),r=null;g&&(r=v.getElementById(e.domElementId),n(r)?e.originalObject=r.outerHTML:e.originalObject=y.empty);var z=e.cachedObject,t=e.originalObject;t=g?t:JSON.stringify(t);z!==t&&(e.options.reset?g?r.outerHTML=e.cachedObject:e.originalObject=w(z).result:e.cachedObject=t,g?A(e.options.onChange,z,t):(g=w(z).result,r=w(t).result,A(e.options.onChange,g,r),B(e.options.onPropertyChange)&&!L(g)&&M(g,r,e.options)),0=e.options.maximumChangesBeforeCanceling&&u(k))}x(h.expires)&&l>=h.expires&&u(f)}},h.timeout);d[f]=b}return f}function M(a,b,c){for(var f in a)if(a.hasOwnProperty(f)){var h=a[f],l=null;b.hasOwnProperty(f)&&(l=b[f]);q(h)&&q(l)?M(h,l,c):JSON.stringify(h)!==JSON.stringify(l)&&A(c.onPropertyChange,f,h,l)}}function N(){for(var a in d)d.hasOwnProperty(a)&&u(a)}function u(a){d.hasOwnProperty(a)&&(A(d[a].options.onCancel,a),clearTimeout(d[a].timer), +(function(){function H(){for(var a=m.domElementTypes,b=a.length,c=0;c=k.starts){if(d.hasOwnProperty(h)){var e=d[h],g=p(e.domElementId), +r=null;g&&(r=v.getElementById(e.domElementId),n(r)?e.originalObject=r.outerHTML:e.originalObject=y.empty);var z=e.cachedObject,t=e.originalObject;t=g?t:JSON.stringify(t);z!==t&&(e.options.reset?g?r.outerHTML=e.cachedObject:e.originalObject=w(z).result:e.cachedObject=t,g?A(e.options.onChange,z,t):(g=w(z).result,r=w(t).result,A(e.options.onChange,g,r),B(e.options.onPropertyChange)&&!L(g)&&M(g,r,e.options)),0=e.options.maximumChangesBeforeCanceling&&u(h))}x(k.expires)&&l>=k.expires&&u(h)}},k.timeout);d[f]=b}return f}function M(a,b,c){for(var f in a)if(a.hasOwnProperty(f)){var k=a[f],h=null;b.hasOwnProperty(f)&&(h=b[f]);q(k)&&q(h)?M(k,h,c):JSON.stringify(k)!==JSON.stringify(h)&&A(c.onPropertyChange,f,k,h)}}function N(){for(var a in d)d.hasOwnProperty(a)&&u(a)}function u(a){d.hasOwnProperty(a)&&(A(d[a].options.onCancel,a),clearTimeout(d[a].timer), delete d[a])}function D(a,b){var c=!1;d.hasOwnProperty(a)&&(c=d[a].options,c.starts=new Date,c.starts.setMilliseconds(c.starts.getMilliseconds()+b),c=!0);return c}function I(a){a=q(a)?a:{};a.timeout=E(a.timeout,250);var b=a;var c=a.starts;c=x(c)?c:null;b.starts=c;b=a;c=a.expires;c=x(c)?c:null;b.expires=c;a.reset=F(a.reset,!1);a.cancelOnChange=F(a.cancelOnChange,!1);a.maximumChangesBeforeCanceling=E(a.maximumChangesBeforeCanceling,0);a.pauseTimeoutOnChange=E(a.pauseTimeoutOnChange,0);a.onChange=G(a.onChange, null);a.onPropertyChange=G(a.onPropertyChange,null);a.onCancel=G(a.onCancel,null);return a}function A(a){B(a)&&a.apply(null,[].slice.call(arguments,1))}function J(){for(var a=[],b=0;32>b;b++){8!==b&&12!==b&&16!==b&&20!==b||a.push("-");var c=Math.floor(16*Math.random()).toString(16);a.push(c)}return a.join(y.empty)}function n(a){return null!==a&&void 0!==a&&a!==y.empty}function q(a){return n(a)&&"object"===typeof a}function p(a){return n(a)&&"string"===typeof a}function B(a){return n(a)&&"function"=== -typeof a}function L(a){return q(a)&&a instanceof Array}function x(a){return q(a)&&a instanceof Date}function F(a,b){return n(a)&&"boolean"===typeof a?a:b}function G(a,b){return B(a)?a:b}function E(a,b){return n(a)&&"number"===typeof a?a:b}function w(a){var b=!0,c=null;try{p(a)&&(c=JSON.parse(a))}catch(f){try{c=eval("("+a+")"),B(c)&&(c=c())}catch(h){b=P("Errors in object: "+f.message+", "+h.message),c=null}}return{parsed:b,result:c}}function P(a){var b=!0;m.safeMode||(console.error(a),b=!1);return b} +typeof a}function L(a){return q(a)&&a instanceof Array}function x(a){return q(a)&&a instanceof Date}function F(a,b){return n(a)&&"boolean"===typeof a?a:b}function G(a,b){return B(a)?a:b}function E(a,b){return n(a)&&"number"===typeof a?a:b}function w(a){var b=!0,c=null;try{p(a)&&(c=JSON.parse(a))}catch(f){try{c=eval("("+a+")"),B(c)&&(c=c())}catch(k){b=P("Errors in object: "+f.message+", "+k.message),c=null}}return{parsed:b,result:c}}function P(a){var b=!0;m.safeMode||(console.error(a),b=!1);return b} function O(){m.safeMode=F(m.safeMode,!0);var a=m,b=m.domElementTypes,c=["*"];p(b)?(b=b.split(y.space),0===b.length&&(b=c)):b=L(b)?b:c;a.domElementTypes=b}var v=null,C=null,y={empty:""},d={},m={};this.watchObject=function(a,b){return K(a,b)};this.cancelWatch=function(a){var b=!1;if(d.hasOwnProperty(a))u(a),b=!0;else for(var c in d)if(d.hasOwnProperty(c)&&p(d[c].domElementId)&&d[c].domElementId===a){u(c);b=!0;break}return b};this.cancelWatches=function(){N();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)&&p(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=D(a,b);else for(var f in d)if(d.hasOwnProperty(f)&&p(d[f].domElementId)&&d[f].domElementId===a){c=D(f,b);break}return c};this.searchDomForNewWatches=function(){H();return this};this.setConfiguration=function(a){m=q(a)?a:{};O();return this};this.getVersion= function(){return"0.4.0"};(function(a,b){v=a;C=b;O();v.addEventListener("DOMContentLoaded",function(){H()});C.addEventListener("unload",function(){N()});n(C.$observe)||(C.$observe=this)})(document,window)})(); \ No newline at end of file diff --git a/docs/CHANGE_LOG.md b/docs/CHANGE_LOG.md index 81ee64c..3765e44 100644 --- a/docs/CHANGE_LOG.md +++ b/docs/CHANGE_LOG.md @@ -14,6 +14,7 @@ #### **Fixes:** - Fixed a fault that prevented the binding attribute from being removed from the DOM elements. - Fixed a fault that prevented changes from being detected when a DOM element is removed from the DOM. +- Fixed some properties being assigned to internal watches when not required.
diff --git a/src/observe.js b/src/observe.js index 88cbc58..1065bf0 100644 --- a/src/observe.js +++ b/src/observe.js @@ -109,13 +109,13 @@ watch = {}; watch.options = watchOptions; - watch.domElementId = domElementId; watch.totalChanges = 0; if ( isDefinedString( domElementId ) ) { var domElement = _parameter_Document.getElementById( domElementId ); if ( isDefined( domElement ) ) { + watch.domElementId = domElementId; watch.cachedObject = domElement.outerHTML; watch.originalObject = domElement.outerHTML; } @@ -126,16 +126,7 @@ } watch.timer = setInterval( function() { - var currentDateTime = new Date(); - - if ( !isDefinedDate( watchOptions.starts ) || currentDateTime >= watchOptions.starts ) { - watchObjectForChanges( storageId ); - - if ( isDefinedDate( watchOptions.expires ) && currentDateTime >= watchOptions.expires ) { - cancelWatchObject( storageId ); - } - } - + watchTimer( watchOptions, storageId ); }, watchOptions.timeout ); _watches[ storageId ] = watch; @@ -144,6 +135,18 @@ return storageId; } + function watchTimer( watchOptions, storageId ) { + var currentDateTime = new Date(); + + if ( !isDefinedDate( watchOptions.starts ) || currentDateTime >= watchOptions.starts ) { + watchObjectForChanges( storageId ); + + if ( isDefinedDate( watchOptions.expires ) && currentDateTime >= watchOptions.expires ) { + cancelWatchObject( storageId ); + } + } + } + function watchObjectForChanges( storageId ) { if ( _watches.hasOwnProperty( storageId ) ) { var watch = _watches[ storageId ], From c953587a165111ab961ac63920b3c398b7527912 Mon Sep 17 00:00:00 2001 From: William Troup Date: Wed, 3 Jan 2024 20:24:05 +0000 Subject: [PATCH 8/9] Renamed the public function "watchObject()" to "watch()". --- README.md | 6 +++--- README_NUGET.md | 6 +++--- dist/observe.js | 2 +- dist/observe.min.js | 6 +++--- docs/CHANGE_LOG.md | 1 + docs/PUBLIC_FUNCTIONS.md | 2 +- docs/binding/options/CUSTOM_TRIGGERS.md | 6 +++--- docs/binding/options/OPTIONS.md | 6 +++--- src/observe.js | 4 ++-- test/dist/observe.js.basic.html | 10 +++++----- test/dist/observe.js.min.html | 10 +++++----- test/src/observe.js.basic.html | 10 +++++----- 12 files changed, 35 insertions(+), 34 deletions(-) diff --git a/README.md b/README.md index 31956b3..90feb64 100644 --- a/README.md +++ b/README.md @@ -70,15 +70,15 @@ Make sure you include the "DOCTYPE html" tag at the top of your HTML, as follows ```markdown ``` -To see a list of all the available binding options you can use for "data-observe-watch-options", and "watchObject()", click [here](docs/binding/options/OPTIONS.md). +To see a list of all the available binding options you can use for "data-observe-watch-options", and "watch()", click [here](docs/binding/options/OPTIONS.md). -To see a list of all the available custom triggers you can use for "data-observe-watch-options", and "watchObject()", click [here](docs/binding/options/CUSTOM_TRIGGERS.md). +To see a list of all the available custom triggers you can use for "data-observe-watch-options", and "watch()", click [here](docs/binding/options/CUSTOM_TRIGGERS.md).
diff --git a/README_NUGET.md b/README_NUGET.md index cd51d2b..238a733 100644 --- a/README_NUGET.md +++ b/README_NUGET.md @@ -59,15 +59,15 @@ Make sure you include the "DOCTYPE html" tag at the top of your HTML, as follows ```markdown ``` -To see a list of all the available binding options you can use for "data-observe-watch-options", and "watchObject()", click [here](https://github.com/williamtroup/Observe.js/blob/main/docs/binding/options/OPTIONS.md). +To see a list of all the available binding options you can use for "data-observe-watch-options", and "watch()", click [here](https://github.com/williamtroup/Observe.js/blob/main/docs/binding/options/OPTIONS.md). -To see a list of all the available custom triggers you can use for "data-observe-watch-options", and "watchObject()", click [here](https://github.com/williamtroup/Observe.js/blob/main/docs/binding/options/CUSTOM_TRIGGERS.md). +To see a list of all the available custom triggers you can use for "data-observe-watch-options", and "watch()", click [here](https://github.com/williamtroup/Observe.js/blob/main/docs/binding/options/CUSTOM_TRIGGERS.md). ### 4. Finishing Up: diff --git a/dist/observe.js b/dist/observe.js index 679cee8..56135fe 100644 --- a/dist/observe.js +++ b/dist/observe.js @@ -295,7 +295,7 @@ var _watches = {}; var _configuration = {}; var _attribute_Name_Watch_Options = "data-observe-watch-options"; - this.watchObject = function(object, options) { + this.watch = function(object, options) { return createWatch(object, options); }; this.cancelWatch = function(id) { diff --git a/dist/observe.min.js b/dist/observe.min.js index 286321a..8c63381 100644 --- a/dist/observe.min.js +++ b/dist/observe.min.js @@ -6,6 +6,6 @@ u(h),e.totalChanges++,0 delete d[a])}function D(a,b){var c=!1;d.hasOwnProperty(a)&&(c=d[a].options,c.starts=new Date,c.starts.setMilliseconds(c.starts.getMilliseconds()+b),c=!0);return c}function I(a){a=q(a)?a:{};a.timeout=E(a.timeout,250);var b=a;var c=a.starts;c=x(c)?c:null;b.starts=c;b=a;c=a.expires;c=x(c)?c:null;b.expires=c;a.reset=F(a.reset,!1);a.cancelOnChange=F(a.cancelOnChange,!1);a.maximumChangesBeforeCanceling=E(a.maximumChangesBeforeCanceling,0);a.pauseTimeoutOnChange=E(a.pauseTimeoutOnChange,0);a.onChange=G(a.onChange, null);a.onPropertyChange=G(a.onPropertyChange,null);a.onCancel=G(a.onCancel,null);return a}function A(a){B(a)&&a.apply(null,[].slice.call(arguments,1))}function J(){for(var a=[],b=0;32>b;b++){8!==b&&12!==b&&16!==b&&20!==b||a.push("-");var c=Math.floor(16*Math.random()).toString(16);a.push(c)}return a.join(y.empty)}function n(a){return null!==a&&void 0!==a&&a!==y.empty}function q(a){return n(a)&&"object"===typeof a}function p(a){return n(a)&&"string"===typeof a}function B(a){return n(a)&&"function"=== typeof a}function L(a){return q(a)&&a instanceof Array}function x(a){return q(a)&&a instanceof Date}function F(a,b){return n(a)&&"boolean"===typeof a?a:b}function G(a,b){return B(a)?a:b}function E(a,b){return n(a)&&"number"===typeof a?a:b}function w(a){var b=!0,c=null;try{p(a)&&(c=JSON.parse(a))}catch(f){try{c=eval("("+a+")"),B(c)&&(c=c())}catch(k){b=P("Errors in object: "+f.message+", "+k.message),c=null}}return{parsed:b,result:c}}function P(a){var b=!0;m.safeMode||(console.error(a),b=!1);return b} -function O(){m.safeMode=F(m.safeMode,!0);var a=m,b=m.domElementTypes,c=["*"];p(b)?(b=b.split(y.space),0===b.length&&(b=c)):b=L(b)?b:c;a.domElementTypes=b}var v=null,C=null,y={empty:""},d={},m={};this.watchObject=function(a,b){return K(a,b)};this.cancelWatch=function(a){var b=!1;if(d.hasOwnProperty(a))u(a),b=!0;else for(var c in d)if(d.hasOwnProperty(c)&&p(d[c].domElementId)&&d[c].domElementId===a){u(c);b=!0;break}return b};this.cancelWatches=function(){N();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)&&p(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=D(a,b);else for(var f in d)if(d.hasOwnProperty(f)&&p(d[f].domElementId)&&d[f].domElementId===a){c=D(f,b);break}return c};this.searchDomForNewWatches=function(){H();return this};this.setConfiguration=function(a){m=q(a)?a:{};O();return this};this.getVersion= -function(){return"0.4.0"};(function(a,b){v=a;C=b;O();v.addEventListener("DOMContentLoaded",function(){H()});C.addEventListener("unload",function(){N()});n(C.$observe)||(C.$observe=this)})(document,window)})(); \ No newline at end of file +function O(){m.safeMode=F(m.safeMode,!0);var a=m,b=m.domElementTypes,c=["*"];p(b)?(b=b.split(y.space),0===b.length&&(b=c)):b=L(b)?b:c;a.domElementTypes=b}var v=null,C=null,y={empty:""},d={},m={};this.watch=function(a,b){return K(a,b)};this.cancelWatch=function(a){var b=!1;if(d.hasOwnProperty(a))u(a),b=!0;else for(var c in d)if(d.hasOwnProperty(c)&&p(d[c].domElementId)&&d[c].domElementId===a){u(c);b=!0;break}return b};this.cancelWatches=function(){N();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)&&p(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=D(a,b);else for(var f in d)if(d.hasOwnProperty(f)&&p(d[f].domElementId)&&d[f].domElementId===a){c=D(f,b);break}return c};this.searchDomForNewWatches=function(){H();return this};this.setConfiguration=function(a){m=q(a)?a:{};O();return this};this.getVersion=function(){return"0.4.0"}; +(function(a,b){v=a;C=b;O();v.addEventListener("DOMContentLoaded",function(){H()});C.addEventListener("unload",function(){N()});n(C.$observe)||(C.$observe=this)})(document,window)})(); \ No newline at end of file diff --git a/docs/CHANGE_LOG.md b/docs/CHANGE_LOG.md index 3765e44..5ca35bf 100644 --- a/docs/CHANGE_LOG.md +++ b/docs/CHANGE_LOG.md @@ -7,6 +7,7 @@ #### **BREAKING CHANGES:** - Renamed the DOM attribute "data-observe-options" to "data-observe-watch-options". +- Renamed the public function "watchObject()" to "watch()". #### **General Improvements:** - Minor internal refactoring to make things a little clearer. diff --git a/docs/PUBLIC_FUNCTIONS.md b/docs/PUBLIC_FUNCTIONS.md index 48ff07c..853b9c3 100644 --- a/docs/PUBLIC_FUNCTIONS.md +++ b/docs/PUBLIC_FUNCTIONS.md @@ -7,7 +7,7 @@ Below is a list of all the public functions that can be called from the Observe. ## Watching Objects: -### **watchObject( *object*, *options* )**: +### **watch( *object*, *options* )**: Adds an object that should be watched for changes.
***Parameter: object***: '*Object*' - The object that should be watched. diff --git a/docs/binding/options/CUSTOM_TRIGGERS.md b/docs/binding/options/CUSTOM_TRIGGERS.md index c2ed1df..75b0825 100644 --- a/docs/binding/options/CUSTOM_TRIGGERS.md +++ b/docs/binding/options/CUSTOM_TRIGGERS.md @@ -1,6 +1,6 @@ # Observe.js - Binding Options - Custom Triggers: -Below is a list of all the custom triggers supported in the "data-observe-watch-options" binding attribute for DOM elements. These options are also supported when calling the public function "watchObject()". +Below is a list of all the custom triggers supported in the "data-observe-watch-options" binding attribute for DOM elements. These options are also supported when calling the public function "watch()".

@@ -43,12 +43,12 @@ Fires when a watch has been cancelled.
-## "watchObject()" Example: +## "watch()" Example:
```markdown diff --git a/docs/binding/options/OPTIONS.md b/docs/binding/options/OPTIONS.md index 524ee87..e31b19b 100644 --- a/docs/binding/options/OPTIONS.md +++ b/docs/binding/options/OPTIONS.md @@ -1,6 +1,6 @@ # Observe.js - Binding Options: -Below is a list of all the options supported in the "data-observe-watch-options" binding attribute for DOM elements. These options are also supported when calling the public function "watchObject()". +Below is a list of all the options supported in the "data-observe-watch-options" binding attribute for DOM elements. These options are also supported when calling the public function "watch()".

@@ -32,12 +32,12 @@ Below is a list of all the options supported in the "data-observe-watch-options"
-## "watchObject()" Example: +## "watch()" Example:
```markdown diff --git a/src/observe.js b/src/observe.js index 1065bf0..2ac5b80 100644 --- a/src/observe.js +++ b/src/observe.js @@ -460,7 +460,7 @@ */ /** - * watchObject(). + * watch(). * * Adds an object that should be watched for changes. * @@ -471,7 +471,7 @@ * * @returns {string} The ID that object watch is stored under. */ - this.watchObject = function( object, options ) { + this.watch = function( object, options ) { return createWatch( object, options ); }; diff --git a/test/dist/observe.js.basic.html b/test/dist/observe.js.basic.html index 56fdecf..e55ac83 100644 --- a/test/dist/observe.js.basic.html +++ b/test/dist/observe.js.basic.html @@ -30,7 +30,7 @@

Watch:


Cancel Watch:

- +
@@ -39,12 +39,12 @@

Cancel Watches:


Pause Watch:

- +

Get Watch:

- +
@@ -74,7 +74,7 @@

Additional Data:

document.title += " v" + $observe.getVersion(); document.getElementById( "header" ).innerText += " - v" + $observe.getVersion(); - var watchObjectId = null; + var watchId = null; window.observeObject = {}; window.observeObject.bool = true; @@ -82,7 +82,7 @@

Additional Data:

window.observeObject.str = "This is a string"; function watchNewObject() { - watchObjectId = $observe.watchObject( window.observeObject, { + watchId = $observe.watch( window.observeObject, { onChange: onObservableObjectChange, onPropertyChange: onObservableObjectPropertyChange, onCancel: onCancelWatch diff --git a/test/dist/observe.js.min.html b/test/dist/observe.js.min.html index 493d3f0..df0e692 100644 --- a/test/dist/observe.js.min.html +++ b/test/dist/observe.js.min.html @@ -30,7 +30,7 @@

Watch:


Cancel Watch:

- +
@@ -39,12 +39,12 @@

Cancel Watches:


Pause Watch:

- +

Get Watch:

- +
@@ -74,7 +74,7 @@

Additional Data:

document.title += " v" + $observe.getVersion(); document.getElementById( "header" ).innerText += " - v" + $observe.getVersion(); - var watchObjectId = null; + var watchId = null; window.observeObject = {}; window.observeObject.bool = true; @@ -82,7 +82,7 @@

Additional Data:

window.observeObject.str = "This is a string"; function watchNewObject() { - watchObjectId = $observe.watchObject( window.observeObject, { + watchId = $observe.watch( window.observeObject, { onChange: onObservableObjectChange, onPropertyChange: onObservableObjectPropertyChange, onCancel: onCancelWatch diff --git a/test/src/observe.js.basic.html b/test/src/observe.js.basic.html index 6887fcd..44802d0 100644 --- a/test/src/observe.js.basic.html +++ b/test/src/observe.js.basic.html @@ -30,7 +30,7 @@

Watch:


Cancel Watch:

- +
@@ -39,12 +39,12 @@

Cancel Watches:


Pause Watch:

- +

Get Watch:

- +
@@ -74,7 +74,7 @@

Additional Data:

document.title += " v" + $observe.getVersion(); document.getElementById( "header" ).innerText += " - v" + $observe.getVersion(); - var watchObjectId = null; + var watchId = null; window.observeObject = {}; window.observeObject.bool = true; @@ -82,7 +82,7 @@

Additional Data:

window.observeObject.str = "This is a string"; function watchNewObject() { - watchObjectId = $observe.watchObject( window.observeObject, { + watchId = $observe.watch( window.observeObject, { onChange: onObservableObjectChange, onPropertyChange: onObservableObjectPropertyChange, onCancel: onCancelWatch From c694a1339400c7773bbfb840e208b75d26c896f6 Mon Sep 17 00:00:00 2001 From: William Troup Date: Wed, 3 Jan 2024 21:01:05 +0000 Subject: [PATCH 9/9] Updated change log. --- docs/CHANGE_LOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/CHANGE_LOG.md b/docs/CHANGE_LOG.md index 5ca35bf..02b162f 100644 --- a/docs/CHANGE_LOG.md +++ b/docs/CHANGE_LOG.md @@ -3,7 +3,7 @@ ## Version 0.4.0: #### **Public Functions:** -- Added new public function "searchDomForNewWatches()", which is used to search the DOM for new elements to watch, and adds them. +- Added new public function "searchDomForNewWatches()", which is used to search the DOM for new elements to watch, then adds them. #### **BREAKING CHANGES:** - Renamed the DOM attribute "data-observe-options" to "data-observe-watch-options".