From d3b9fb25f516a9ccbf9ada2ca042642321a5e35c Mon Sep 17 00:00:00 2001 From: William Troup Date: Mon, 8 Jan 2024 16:36:04 +0000 Subject: [PATCH] Added "pauseWatches()" and "resumeWatches()" public functions. --- dist/observe.js | 18 ++++++++++++++++++ dist/observe.min.js | 17 +++++++++-------- docs/CHANGE_LOG.md | 4 ++++ docs/PUBLIC_FUNCTIONS.md | 18 ++++++++++++++++-- src/observe.js | 40 ++++++++++++++++++++++++++++++++++++++++ 5 files changed, 87 insertions(+), 10 deletions(-) diff --git a/dist/observe.js b/dist/observe.js index 3b64368..5d6f961 100644 --- a/dist/observe.js +++ b/dist/observe.js @@ -376,6 +376,15 @@ } return result; }; + this.pauseWatches = function(milliseconds) { + var storageId; + for (storageId in _watches) { + if (_watches.hasOwnProperty(storageId)) { + pauseWatchObject(storageId, milliseconds); + } + } + return this; + }; this.resumeWatch = function(id) { var result = false; if (_watches.hasOwnProperty(id)) { @@ -393,6 +402,15 @@ } return result; }; + this.resumeWatches = function() { + var storageId; + for (storageId in _watches) { + if (_watches.hasOwnProperty(storageId)) { + _watches[storageId].options.starts = null; + } + } + return this; + }; this.searchDomForNewWatches = function() { collectDOMObjects(); return this; diff --git a/dist/observe.min.js b/dist/observe.min.js index 28b8815..d29555f 100644 --- a/dist/observe.min.js +++ b/dist/observe.min.js @@ -2,11 +2,12 @@ (function(){function I(){for(var a=q.domElementTypes,b=a.length,c=0;c=k.starts){if(d.hasOwnProperty(h)){var e=d[h],g=p(e.domElementId), m=null;g&&(m=y.getElementById(e.domElementId),r(m)?e.originalObject=m.outerHTML:(e.originalObject=B.empty,u(e.options.onRemove,e.domElementId)));var v=e.cachedObject,n=e.originalObject;n=g?n:JSON.stringify(n);if(v!==n){e.options.reset?g?m.outerHTML=e.cachedObject:e.originalObject=z(v).result:e.cachedObject=n;if(g)u(e.options.onChange,v,n);else if(g=z(v).result,m=z(n).result,w(g)||w(m))u(e.options.onChange,g,m);else{if(w(e.options.propertyNames))for(v=e.options.propertyNames.length,n=0;n=e.options.maximumChangesBeforeCanceling&&x(h)}}A(k.expires)&&l>=k.expires&&x(h)}},k.timeout);d[f]=b}return f}function N(a,b,c){for(var f in a)if(a.hasOwnProperty(f)){var k=a[f], -h=null;b.hasOwnProperty(f)&&(h=b[f]);t(k)&&t(h)?N(k,h,c.options):(!w(c.options.propertyNames)||-1b;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(B.empty)}function r(a){return null!==a&&void 0!==a&&a!==B.empty}function t(a){return r(a)&&"object"===typeof a}function p(a){return r(a)&&"string"===typeof a}function C(a){return r(a)&&"function"===typeof a}function w(a){return t(a)&&a instanceof Array}function A(a){return t(a)&& -a instanceof Date}function H(a,b){return r(a)&&"boolean"===typeof a?a:b}function D(a,b){return C(a)?a:b}function G(a,b){return r(a)&&"number"===typeof a?a:b}function z(a){var b=!0,c=null;try{p(a)&&(c=JSON.parse(a))}catch(f){try{c=eval("("+a+")"),C(c)&&(c=c())}catch(k){b=Q("Errors in object: "+f.message+", "+k.message),c=null}}return{parsed:b,result:c}}function Q(a){var b=!0;q.safeMode||(console.error(a),b=!1);return b}function P(){q.safeMode=H(q.safeMode,!0);var a=q,b=q.domElementTypes,c=["*"];p(b)? -(b=b.split(B.space),0===b.length&&(b=c)):b=w(b)?b:c;a.domElementTypes=b}var y=null,E=null,B={empty:""},d={},q={};this.watch=function(a,b){return L(a,b)};this.cancelWatch=function(a){var b=!1;if(d.hasOwnProperty(a))x(a),b=!0;else for(var c in d)if(d.hasOwnProperty(c)&&p(d[c].domElementId)&&d[c].domElementId===a){x(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)&&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=F(a,b);else for(var f in d)if(d.hasOwnProperty(f)&&p(d[f].domElementId)&&d[f].domElementId===a){c=F(f,b);break}return c};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)&&p(d[c].domElementId)&&d[c].domElementId===a){d[c].options.starts=null;b=!0;break}return b};this.searchDomForNewWatches= -function(){I();return this};this.setConfiguration=function(a){q=t(a)?a:{};P();return this};this.getVersion=function(){return"0.6.0"};(function(a,b){y=a;E=b;P();y.addEventListener("DOMContentLoaded",function(){I()});E.addEventListener("unload",function(){O()});r(E.$observe)||(E.$observe=this)})(document,window)})(); \ No newline at end of file +e.options.propertyNames[n];if(g[M]!==m[M]){u(e.options.onChange,g,m);break}}else u(e.options.onChange,g,m);C(e.options.onPropertyChange)&&N(g,m,e)}e.totalChanges++;0=e.options.maximumChangesBeforeCanceling&&x(h)}}A(k.expires)&&l>=k.expires&&x(h)}},k.timeout);d[f]=b}return f}function N(a,b,c){for(var f in a)if(a.hasOwnProperty(f)){var k=a[f], +h=null;b.hasOwnProperty(f)&&(h=b[f]);t(k)&&t(h)?N(k,h,c.options):(!w(c.options.propertyNames)||-1b;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(B.empty)}function r(a){return null!==a&&void 0!==a&&a!==B.empty}function t(a){return r(a)&&"object"===typeof a}function p(a){return r(a)&&"string"===typeof a}function C(a){return r(a)&&"function"===typeof a}function w(a){return t(a)&&a instanceof Array}function A(a){return t(a)&& +a instanceof Date}function H(a,b){return r(a)&&"boolean"===typeof a?a:b}function E(a,b){return C(a)?a:b}function G(a,b){return r(a)&&"number"===typeof a?a:b}function z(a){var b=!0,c=null;try{p(a)&&(c=JSON.parse(a))}catch(f){try{c=eval("("+a+")"),C(c)&&(c=c())}catch(k){b=Q("Errors in object: "+f.message+", "+k.message),c=null}}return{parsed:b,result:c}}function Q(a){var b=!0;q.safeMode||(console.error(a),b=!1);return b}function P(){q.safeMode=H(q.safeMode,!0);var a=q,b=q.domElementTypes,c=["*"];p(b)? +(b=b.split(B.space),0===b.length&&(b=c)):b=w(b)?b:c;a.domElementTypes=b}var y=null,F=null,B={empty:""},d={},q={};this.watch=function(a,b){return L(a,b)};this.cancelWatch=function(a){var b=!1;if(d.hasOwnProperty(a))x(a),b=!0;else for(var c in d)if(d.hasOwnProperty(c)&&p(d[c].domElementId)&&d[c].domElementId===a){x(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)&&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.pauseWatches=function(a){for(var b in d)d.hasOwnProperty(b)&&D(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)&&p(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(){I();return this};this.setConfiguration=function(a){q=t(a)?a:{};P();return this};this.getVersion=function(){return"0.6.0"};(function(a,b){y=a;F=b;P();y.addEventListener("DOMContentLoaded",function(){I()});F.addEventListener("unload",function(){O()});r(F.$observe)||(F.$observe=this)})(document, +window)})(); \ No newline at end of file diff --git a/docs/CHANGE_LOG.md b/docs/CHANGE_LOG.md index bd052ef..50f99fd 100644 --- a/docs/CHANGE_LOG.md +++ b/docs/CHANGE_LOG.md @@ -2,6 +2,10 @@ ## Version 0.6.0: +#### **Public Functions:** +- Added new public function "pauseWatches()", which is used to pause all the watches for a specific number of milliseconds. +- Added new public function "resumeWatches()", which is used to resume all the watches currently paused. + #### **General Improvements:** - Minor internal refactoring to make things a little clearer. diff --git a/docs/PUBLIC_FUNCTIONS.md b/docs/PUBLIC_FUNCTIONS.md index 9b0fc67..90d7a68 100644 --- a/docs/PUBLIC_FUNCTIONS.md +++ b/docs/PUBLIC_FUNCTIONS.md @@ -55,12 +55,26 @@ 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.
+### **pauseWatches( *milliseconds* )**: +Pauses all the watches for a specific number of milliseconds. +
+***Parameter: milliseconds***: '*number*' - The milliseconds to pause the watches for. +
+***Returns***: '*Object*' - The Observe.js class instance. +
+ ### **resumeWatch( *id* )**: -Resumes the watching of an object for changes after it was paused. +Resumes the all the watches that are currently paused.
***Parameter: id***: '*string*' - The ID of the object being watched, or DOM element ID being watched.
-***Returns***: '*boolean*' - States if the watching of an object has been resumed +***Returns***: '*boolean*' - States if the watching of an object has been resumed. +
+ +### **resumeWatches()**: +Resumes the watching of all objects for changes after they were paused. +
+***Returns***: '*Object*' - The Observe.js class instance.
### **searchDomForNewWatches()**: diff --git a/src/observe.js b/src/observe.js index 2d89525..de03587 100644 --- a/src/observe.js +++ b/src/observe.js @@ -624,6 +624,27 @@ return result; }; + /** + * pauseWatches(). + * + * Pauses all the watches for a specific number of milliseconds. + * + * @public + * + * @param {number} milliseconds The milliseconds to pause the watches for. + * + * @returns {Object} The Observe.js class instance. + */ + this.pauseWatches = function( milliseconds ) { + for ( var storageId in _watches ) { + if ( _watches.hasOwnProperty( storageId ) ) { + pauseWatchObject( storageId, milliseconds ); + } + } + + return this; + }; + /** * resumeWatch(). * @@ -655,6 +676,25 @@ return result; }; + /** + * resumeWatches(). + * + * Resumes the all the watches that are currently paused. + * + * @public + * + * @returns {Object} The Observe.js class instance. + */ + this.resumeWatches = function() { + for ( var storageId in _watches ) { + if ( _watches.hasOwnProperty( storageId ) ) { + _watches[ storageId ].options.starts = null; + } + } + + return this; + }; + /** * searchDomForNewWatches(). *