From 5dd7bf41d889123b25e04fe0cc9c0b7f1e9c5de0 Mon Sep 17 00:00:00 2001 From: Adrian Lowdon Date: Mon, 16 Jan 2023 17:45:01 +0000 Subject: [PATCH] Removed jQuery deprecations --- sisyphus.js | 6 +++--- sisyphus.min.js | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/sisyphus.js b/sisyphus.js index 16cb449..23e2438 100644 --- a/sisyphus.js +++ b/sisyphus.js @@ -166,7 +166,7 @@ this.href = location.hostname + location.pathname + location.search + location.hash; } this.targets = $.merge( this.targets, targets ); - this.targets = $.unique( this.targets ); + this.targets = $.uniqueSort( this.targets ); this.targets = $( this.targets ); if ( ! this.browserStorage.isAvailable() ) { return false; @@ -439,7 +439,7 @@ */ bindSaveDataOnChange: function( field ) { var self = this; - field.change( function() { + field.on( "change", function() { self.saveAllData(); } ); }, @@ -471,7 +471,7 @@ self.targets.each( function() { var target = $( this ); var formIdAndName = getElementIdentifier( target ); - $( this ).bind( "submit reset", function() { + $( this ).on( "submit reset", function() { self.releaseData( formIdAndName, self.findFieldsToProtect( target ) ); } ); } ); diff --git a/sisyphus.min.js b/sisyphus.min.js index 0f83247..6a24c8a 100644 --- a/sisyphus.min.js +++ b/sisyphus.min.js @@ -1 +1 @@ -!function(a){function b(a){return"[id="+a.attr("id")+"][name="+a.attr("name")+"]"}a.fn.sisyphus=function(c){var d=a.map(this,function(c){return b(a(c))}).join(),e=Sisyphus.getInstance(d);return e.protect(this,c),e};var c={};c.isAvailable=function(){if("object"==typeof a.jStorage)return!0;try{return localStorage.getItem}catch(b){return!1}},c.set=function(b,c){if("object"==typeof a.jStorage)a.jStorage.set(b,c+"");else try{localStorage.setItem(b,c+"")}catch(d){}},c.get=function(b){if("object"==typeof a.jStorage){var c=a.jStorage.get(b);return c?c.toString():c}return localStorage.getItem(b)},c.remove=function(b){"object"==typeof a.jStorage?a.jStorage.deleteKey(b):localStorage.removeItem(b)},Sisyphus=function(){function f(){return{setInstanceIdentifier:function(a){this.identifier=a},getInstanceIdentifier:function(){return this.identifier},setInitialOptions:function(b){var d={excludeFields:[],customKeySuffix:"",locationBased:!1,timeout:0,autoRelease:!0,onBeforeSave:function(){},onSave:function(){},onBeforeRestore:function(){},onRestore:function(){},onRelease:function(){}};this.options=this.options||a.extend(d,b),this.browserStorage=c},setOptions:function(b){this.options=this.options||this.setInitialOptions(b),this.options=a.extend(this.options,b)},protect:function(b,c){this.setOptions(c),b=b||{};var f=this;if(this.targets=this.targets||[],f.options.name?this.href=f.options.name:this.href=location.hostname+location.pathname+location.search+location.hash,this.targets=a.merge(this.targets,b),this.targets=a.unique(this.targets),this.targets=a(this.targets),!this.browserStorage.isAvailable())return!1;var g=f.options.onBeforeRestore.call(f);if((void 0===g||g)&&f.restoreAllData(),this.options.autoRelease&&f.bindReleaseData(),!d.started[this.getInstanceIdentifier()])if(f.isCKEditorPresent())var h=setInterval(function(){e.isLoaded&&(clearInterval(h),f.bindSaveData(),d.started[f.getInstanceIdentifier()]=!0)},100);else f.bindSaveData(),d.started[f.getInstanceIdentifier()]=!0},isCKEditorPresent:function(){return this.isCKEditorExists()?(e.isLoaded=!1,e.on("instanceReady",function(){e.isLoaded=!0}),!0):!1},isCKEditorExists:function(){return"undefined"!=typeof e},findFieldsToProtect:function(a){return a.find(":input").not(":submit").not(":reset").not(":button").not(":file").not(":password").not(":disabled").not("[readonly]")},bindSaveData:function(){var c=this;c.options.timeout&&c.saveDataByTimeout(),c.targets.each(function(){var d=b(a(this));c.findFieldsToProtect(a(this)).each(function(){if(-1!==a.inArray(this,c.options.excludeFields))return!0;var e=a(this),f=(c.options.locationBased?c.href:"")+d+b(e)+c.options.customKeySuffix;(e.is(":text")||e.is("textarea"))&&(c.options.timeout||c.bindSaveDataImmediately(e,f)),c.bindSaveDataOnChange(e)})})},saveAllData:function(){var c=this;c.targets.each(function(){var d=b(a(this)),f={};c.findFieldsToProtect(a(this)).each(function(){var g=a(this);if(-1!==a.inArray(this,c.options.excludeFields)||void 0===g.attr("name")&&void 0===g.attr("id"))return!0;var h=(c.options.locationBased?c.href:"")+d+b(g)+c.options.customKeySuffix,i=g.val();if(g.is(":checkbox")){var j=g.attr("name");if(void 0!==j&&-1!==j.indexOf("[")){if(f[j]===!0)return;i=[],a("[name='"+j+"']:checked").each(function(){i.push(a(this).val())}),f[j]=!0}else i=g.is(":checked");c.saveToBrowserStorage(h,i,!1)}else if(g.is(":radio"))g.is(":checked")&&(i=g.val(),c.saveToBrowserStorage(h,i,!1));else if(c.isCKEditorExists()){var k=e.instances[g.attr("name")]||e.instances[g.attr("id")];k?(k.updateElement(),c.saveToBrowserStorage(h,g.val(),!1)):c.saveToBrowserStorage(h,i,!1)}else c.saveToBrowserStorage(h,i,!1)})}),c.options.onSave.call(c)},restoreAllData:function(){var c=this,d=!1;c.targets.each(function(){var e=a(this),f=b(a(this));c.findFieldsToProtect(e).each(function(){if(-1!==a.inArray(this,c.options.excludeFields))return!0;var e=a(this),g=(c.options.locationBased?c.href:"")+f+b(e)+c.options.customKeySuffix,h=c.browserStorage.get(g);null!==h&&(c.restoreFieldsData(e,h),d=!0)})}),d&&c.options.onRestore.call(c)},restoreFieldsData:function(a,b){if(void 0===a.attr("name")&&void 0===a.attr("id"))return!1;var c=a.attr("name");!a.is(":checkbox")||"false"===b||void 0!==c&&-1!==c.indexOf("[")?!a.is(":checkbox")||"false"!==b||void 0!==c&&-1!==c.indexOf("[")?a.is(":radio")?a.val()===b&&a.prop("checked",!0):void 0===c||-1===c.indexOf("[")?a.val(b):(b=b.split(","),a.val(b)):a.prop("checked",!1):a.prop("checked",!0)},bindSaveDataImmediately:function(a,b){var c=this;if("onpropertychange"in a?a.get(0).onpropertychange=function(){c.saveToBrowserStorage(b,a.val())}:a.get(0).oninput=function(){c.saveToBrowserStorage(b,a.val())},this.isCKEditorExists()){var d=e.instances[a.attr("name")]||e.instances[a.attr("id")];d&&d.document.on("keyup",function(){d.updateElement(),c.saveToBrowserStorage(b,a.val())})}},saveToBrowserStorage:function(a,b,c){var d=this,e=d.options.onBeforeSave.call(d);(void 0===e||e!==!1)&&(c=void 0===c?!0:c,this.browserStorage.set(a,b),c&&""!==b&&this.options.onSave.call(this))},bindSaveDataOnChange:function(a){var b=this;a.change(function(){b.saveAllData()})},saveDataByTimeout:function(){var a=this,b=a.targets;setTimeout(function(){function b(){a.saveAllData(),setTimeout(b,1e3*a.options.timeout)}return b}(b),1e3*a.options.timeout)},bindReleaseData:function(){var c=this;c.targets.each(function(){var d=a(this),e=b(d);a(this).bind("submit reset",function(){c.releaseData(e,c.findFieldsToProtect(d))})})},manuallyReleaseData:function(){var c=this;c.targets.each(function(){var d=a(this),e=b(d);c.releaseData(e,c.findFieldsToProtect(d))})},releaseData:function(c,e){var f=!1,g=this;d.started[g.getInstanceIdentifier()]=!1,e.each(function(){if(-1!==a.inArray(this,g.options.excludeFields))return!0;var d=a(this),e=(g.options.locationBased?g.href:"")+c+b(d)+g.options.customKeySuffix;g.browserStorage.remove(e),f=!0}),f&&g.options.onRelease.call(g)}}}var d={instantiated:[],started:[]},e=window.CKEDITOR;return{getInstance:function(a){return d.instantiated[a]||(d.instantiated[a]=f(),d.instantiated[a].setInstanceIdentifier(a),d.instantiated[a].setInitialOptions()),a?d.instantiated[a]:d.instantiated[a]},free:function(){return d={instantiated:[],started:[]},null},version:"1.1.3"}}()}(jQuery); \ No newline at end of file +!function(t){function e(t){return"[id="+t.attr("id")+"][name="+t.attr("name")+"]"}t.fn.sisyphus=function(i){var n=t.map(this,function(i){return e(t(i))}).join(),o=Sisyphus.getInstance(n);return o.protect(this,i),o};var i,n,o={};o.isAvailable=function(){if("object"==typeof t.jStorage)return!0;try{return localStorage.getItem}catch(e){return!1}},o.set=function(e,i){if("object"==typeof t.jStorage)t.jStorage.set(e,i+"");else try{localStorage.setItem(e,i+"")}catch(n){}},o.get=function(e){if("object"!=typeof t.jStorage)return localStorage.getItem(e);var i=t.jStorage.get(e);return i?i.toString():i},o.remove=function(e){"object"==typeof t.jStorage?t.jStorage.deleteKey(e):localStorage.removeItem(e)},Sisyphus=(i={instantiated:[],started:[]},n=window.CKEDITOR,{getInstance:function(a){return i.instantiated[a]||(i.instantiated[a]={setInstanceIdentifier:function(t){this.identifier=t},getInstanceIdentifier:function(){return this.identifier},setInitialOptions:function(e){this.options=this.options||t.extend({excludeFields:[],customKeySuffix:"",locationBased:!1,timeout:0,autoRelease:!0,onBeforeSave:function(){},onSave:function(){},onBeforeRestore:function(){},onRestore:function(){},onRelease:function(){}},e),this.browserStorage=o},setOptions:function(e){this.options=this.options||this.setInitialOptions(e),this.options=t.extend(this.options,e)},protect:function(e,o){this.setOptions(o),e=e||{};var a=this;if(this.targets=this.targets||[],a.options.name?this.href=a.options.name:this.href=location.hostname+location.pathname+location.search+location.hash,this.targets=t.merge(this.targets,e),this.targets=t.uniqueSort(this.targets),this.targets=t(this.targets),!this.browserStorage.isAvailable())return!1;var s=a.options.onBeforeRestore.call(a);if((void 0===s||s)&&a.restoreAllData(),this.options.autoRelease&&a.bindReleaseData(),!i.started[this.getInstanceIdentifier()]){if(a.isCKEditorPresent())var r=setInterval(function(){n.isLoaded&&(clearInterval(r),a.bindSaveData(),i.started[a.getInstanceIdentifier()]=!0)},100);else a.bindSaveData(),i.started[a.getInstanceIdentifier()]=!0}},isCKEditorPresent:function(){return!!this.isCKEditorExists()&&(n.isLoaded=!1,n.on("instanceReady",function(){n.isLoaded=!0}),!0)},isCKEditorExists:function(){return void 0!==n},findFieldsToProtect:function(t){return t.find(":input").not(":submit").not(":reset").not(":button").not(":file").not(":password").not(":disabled").not("[readonly]")},bindSaveData:function(){var i=this;i.options.timeout&&i.saveDataByTimeout(),i.targets.each(function(){var n=e(t(this));i.findFieldsToProtect(t(this)).each(function(){if(-1!==t.inArray(this,i.options.excludeFields))return!0;var o=t(this),a=(i.options.locationBased?i.href:"")+n+e(o)+i.options.customKeySuffix;(o.is(":text")||o.is("textarea"))&&!i.options.timeout&&i.bindSaveDataImmediately(o,a),i.bindSaveDataOnChange(o)})})},saveAllData:function(){var i=this;i.targets.each(function(){var o=e(t(this)),a={};i.findFieldsToProtect(t(this)).each(function(){var s=t(this);if(-1!==t.inArray(this,i.options.excludeFields)||void 0===s.attr("name")&&void 0===s.attr("id"))return!0;var r=(i.options.locationBased?i.href:"")+o+e(s)+i.options.customKeySuffix,c=s.val();if(s.is(":checkbox")){var f=s.attr("name");if(void 0!==f&&-1!==f.indexOf("[")){if(!0===a[f])return;c=[],t("[name='"+f+"']:checked").each(function(){c.push(t(this).val())}),a[f]=!0}else c=s.is(":checked");i.saveToBrowserStorage(r,c,!1)}else if(s.is(":radio"))s.is(":checked")?(c=s.val(),i.saveToBrowserStorage(r,c,!1)):i.browserStorage.remove(r);else if(i.isCKEditorExists()){var d=n.instances[s.attr("name")]||n.instances[s.attr("id")];d?(d.updateElement(),i.saveToBrowserStorage(r,s.val(),!1)):i.saveToBrowserStorage(r,c,!1)}else i.saveToBrowserStorage(r,c,!1)})}),i.options.onSave.call(i)},restoreAllData:function(){var i=this,n=!1;i.targets.each(function(){var o=t(this),a=e(t(this));i.findFieldsToProtect(o).each(function(){if(-1!==t.inArray(this,i.options.excludeFields))return!0;var o=t(this),s=(i.options.locationBased?i.href:"")+a+e(o)+i.options.customKeySuffix,r=i.browserStorage.get(s);null!==r&&(i.restoreFieldsData(o,r),n=!0)})}),n&&i.options.onRestore.call(i)},restoreFieldsData:function(t,e){if(void 0===t.attr("name")&&void 0===t.attr("id"))return!1;var i=t.attr("name");t.is(":checkbox")&&"false"!==e&&(void 0===i||-1===i.indexOf("["))?t.prop("checked",!0):t.is(":checkbox")&&"false"===e&&(void 0===i||-1===i.indexOf("["))?t.prop("checked",!1):t.is(":radio")?t.val()===e&&t.prop("checked",!0):(void 0===i||-1===i.indexOf("[")||(e=e.split(",")),t.val(e))},bindSaveDataImmediately:function(t,e){var i=this;if("onpropertychange"in t?t.get(0).onpropertychange=function(){i.saveToBrowserStorage(e,t.val())}:t.get(0).oninput=function(){i.saveToBrowserStorage(e,t.val())},this.isCKEditorExists()){var o=n.instances[t.attr("name")]||n.instances[t.attr("id")];o&&o.document.on("keyup",function(){o.updateElement(),i.saveToBrowserStorage(e,t.val())})}},saveToBrowserStorage:function(t,e,i){var n=this.options.onBeforeSave.call(this);(void 0===n||!1!==n)&&(i=void 0===i||i,this.browserStorage.set(t,e),i&&""!==e&&this.options.onSave.call(this))},bindSaveDataOnChange:function(t){var e=this;t.on("change",function(){e.saveAllData()})},saveDataByTimeout:function(){var t=this;setTimeout(function(){function e(){t.saveAllData(),setTimeout(e,1e3*t.options.timeout)}return e}(t.targets),1e3*t.options.timeout)},bindReleaseData:function(){var i=this;i.targets.each(function(){var n=t(this),o=e(n);t(this).on("submit reset",function(){i.releaseData(o,i.findFieldsToProtect(n))})})},manuallyReleaseData:function(){var i=this;i.targets.each(function(){var n=t(this),o=e(n);i.releaseData(o,i.findFieldsToProtect(n))})},releaseData:function(n,o){var a=!1,s=this;i.started[s.getInstanceIdentifier()]=!1,o.each(function(){if(-1!==t.inArray(this,s.options.excludeFields))return!0;var i=t(this),o=(s.options.locationBased?s.href:"")+n+e(i)+s.options.customKeySuffix;s.browserStorage.remove(o),a=!0}),a&&s.options.onRelease.call(s)}},i.instantiated[a].setInstanceIdentifier(a),i.instantiated[a].setInitialOptions()),i.instantiated[a]},free:function(){return i={instantiated:[],started:[]},null},version:"1.1.3"})}(jQuery); \ No newline at end of file