Skip to content
Browse files

Issue #18 - ie js error fix

  • Loading branch information...
1 parent 005e4f2 commit 877b12a814280fe4a32d2bf8f38548895ad09709 @simsalabim committed Feb 13, 2012
Showing with 64 additions and 64 deletions.
  1. +63 −63 sisyphus.js
  2. +1 −1 sisyphus.min.js
View
126 sisyphus.js
@@ -18,74 +18,74 @@
return sisyphus;
};
- browserStorage = {};
+ var browserStorage = {};
/**
- * Check if local storage or other browser storage is available
- *
- * @return Boolean
- */
- browserStorage.isAvailable = function() {
- if ( typeof $.jStorage === "object" ) {
- return true;
- }
- try {
- return localStorage.getItem;
- } catch ( e ) {
- return false;
- }
- }
+ * Check if local storage or other browser storage is available
+ *
+ * @return Boolean
+ */
+ browserStorage.isAvailable = function() {
+ if ( typeof $.jStorage === "object" ) {
+ return true;
+ }
+ try {
+ return localStorage.getItem;
+ } catch ( e ) {
+ return false;
+ }
+ }
/**
- * Set data to browser storage
- *
- * @param [String] key
- * @param [String] value
- *
- * @return Boolean
- */
- browserStorage.set = function( key, value ) {
- if ( typeof $.jStorage === "object" ) {
- $.jStorage.set( key, value + "" )
- } else {
- try {
- localStorage.setItem( key, value + "" );
- } catch (e) {
- //QUOTA_EXCEEDED_ERR
- }
- }
- }
+ * Set data to browser storage
+ *
+ * @param [String] key
+ * @param [String] value
+ *
+ * @return Boolean
+ */
+ browserStorage.set = function( key, value ) {
+ if ( typeof $.jStorage === "object" ) {
+ $.jStorage.set( key, value + "" )
+ } else {
+ try {
+ localStorage.setItem( key, value + "" );
+ } catch (e) {
+ //QUOTA_EXCEEDED_ERR
+ }
+ }
+ }
- /**
- * Get data from browser storage by specified key
- *
- * @param [String] key
- *
- * @return string
- */
- browserStorage.get = function( key ) {
- if ( typeof $.jStorage === "object" ) {
- var result = $.jStorage.get( key );
- return result ? result.toString() : result;
- } else {
- return localStorage.getItem( key )
- }
- }
+ /**
+ * Get data from browser storage by specified key
+ *
+ * @param [String] key
+ *
+ * @return string
+ */
+ browserStorage.get = function( key ) {
+ if ( typeof $.jStorage === "object" ) {
+ var result = $.jStorage.get( key );
+ return result ? result.toString() : result;
+ } else {
+ return localStorage.getItem( key )
+ }
+ }
- /**
- * Delete data from browser storage by specified key
- *
- * @param [String] key
- *
- * @return void
- */
- browserStorage.delete = function( key ) {
- if ( typeof $.jStorage === "object" ) {
- $.jStorage.deleteKey( key );
- } else {
- localStorage.removeItem( key );
- }
- }
+ /**
+ * Delete data from browser storage by specified key
+ *
+ * @param [String] key
+ *
+ * @return void
+ */
+ browserStorage.remove = function( key ) {
+ if ( typeof $.jStorage === "object" ) {
+ $.jStorage.deleteKey( key );
+ } else {
+ localStorage.removeItem( key );
+ }
+ }
Sisyphus = ( function() {
var params = {
@@ -434,7 +434,7 @@
}
var field = $( this );
var prefix = self.href + targetFormId + field.attr( "name" ) + self.options.customKeyPrefix;
- self.browserStorage.delete( prefix )
+ self.browserStorage.remove( prefix )
released = true;
} );
View
2 sisyphus.min.js
@@ -1 +1 @@
-(function(a){a.sisyphus=function(){return Sisyphus.getInstance()},a.fn.sisyphus=function(a){var b=Sisyphus.getInstance();return b.setOptions(a),b.protect(this),b},browserStorage={},browserStorage.isAvailable=function(){if(typeof a.jStorage=="object")return!0;try{return localStorage.getItem}catch(b){return!1}},browserStorage.set=function(b,c){if(typeof a.jStorage=="object")a.jStorage.set(b,c+"");else try{localStorage.setItem(b,c+"")}catch(d){}},browserStorage.get=function(b){if(typeof a.jStorage=="object"){var c=a.jStorage.get(b);return c?c.toString():c}return localStorage.getItem(b)},browserStorage.delete=function(b){typeof a.jStorage=="object"?a.jStorage.deleteKey(b):localStorage.removeItem(b)},Sisyphus=function(){function c(){return{setInitialOptions:function(b){var c={excludeFields:null,customKeyPrefix:"",timeout:0,autoRelease:!0,onSave:function(){},onRestore:function(){},onRelease:function(){}};this.options=this.options||a.extend(c,b),this.browserStorage=browserStorage},setOptions:function(b){this.options=this.options||this.setInitialOptions(b),this.options=a.extend(this.options,b)},protect:function(c){c=c||{};var d=this;this.targets=this.targets||[],this.href=location.hostname+location.pathname+location.search,this.targets=a.merge(this.targets,c),this.targets=a.unique(this.targets),this.targets=a(this.targets);if(!this.browserStorage.isAvailable())return!1;d.restoreAllData(),this.options.autoRelease&&d.bindReleaseData(),b.started||(d.bindSaveData(),b.started=!0)},bindSaveData:function(){var b=this;b.options.timeout&&b.saveDataByTimeout(),b.targets.each(function(){var c=a(this).attr("id"),d=a(this).find(":input").not(":submit").not(":reset").not(":button");d.each(function(){if(a.inArray(this,b.options.excludeFields)!==-1)return!0;var d=a(this),e=b.href+c+d.attr("name")+b.options.customKeyPrefix;d.is(":text")||d.is("textarea")?b.options.timeout||b.bindSaveDataImmediately(d,e):b.bindSaveDataOnChange(d,e)})})},saveAllData:function(){var b=this;b.targets.each(function(){var c=a(this).attr("id"),d=a(this).find(":input").not(":submit").not(":reset").not(":button");d.each(function(){if(a.inArray(this,b.options.excludeFields)!==-1)return!0;var d=a(this),e=b.href+c+d.attr("name")+b.options.customKeyPrefix,f=d.val();d.is(":checkbox")?(d.attr("name").indexOf("[")!=-1?(f=[],a("[name='"+d.attr("name")+"']:checked").each(function(){f.push(a(this).val())})):f=d.is(":checked"),b.saveToBrowserStorage(e,f,!1)):d.is(":radio")?d.is(":checked")&&(f=d.val(),b.saveToBrowserStorage(e,f,!1)):b.saveToBrowserStorage(e,f,!1)})}),a.isFunction(b.options.onSave)&&b.options.onSave.call()},restoreAllData:function(){var b=this,c=!1;b.targets.each(function(){var d=a(this),e=d.attr("id"),f=d.find(":input").not(":submit").not(":reset").not(":button");f.each(function(){if(a.inArray(this,b.options.excludeFields)!==-1)return!0;var d=a(this),f=b.href+e+d.attr("name")+b.options.customKeyPrefix,g=b.browserStorage.get(f);g&&(b.restoreFieldsData(d,g),c=!0)})}),c&&a.isFunction(b.options.onRestore)&&b.options.onRestore.call()},restoreFieldsData:function(a,b){a.is(":checkbox")&&b!=="false"&&a.attr("name").indexOf("[")===-1?a.attr("checked","checked"):a.is(":radio")?a.val()===b&&a.attr("checked","checked"):a.attr("name").indexOf("[")===-1?a.val(b):(b=b.split(","),a.val(b))},bindSaveDataImmediately:function(b,c){var d=this;a.browser.msie==null?b.get(0).oninput=function(){d.saveToBrowserStorage(c,b.val())}:b.get(0).onpropertychange=function(){d.saveToBrowserStorage(c,b.val())}},saveToBrowserStorage:function(b,c,d){d=d==null?!0:d,this.browserStorage.set(b,c),d&&c!==""&&a.isFunction(this.options.onSave)&&this.options.onSave.call()},bindSaveDataOnChange:function(a,b){var c=this;a.change(function(){c.saveAllData()})},saveDataByTimeout:function(){var a=this,b=a.targets;setTimeout(function(b){function c(){a.saveAllData(),setTimeout(c,a.options.timeout*1e3)}return c}(b),a.options.timeout*1e3)},bindReleaseData:function(){var b=this;b.targets.each(function(c){var d=a(this),e=d.find(":input").not(":submit").not(":reset").not(":button"),f=d.attr("id");a(this).bind("submit reset",function(){b.releaseData(f,e)})})},manuallyReleaseData:function(){var b=this;b.targets.each(function(c){var d=a(this),e=d.find(":input").not(":submit").not(":reset").not(":button"),f=d.attr("id");b.releaseData(f,e)})},releaseData:function(b,c){var d=!1,e=this;c.each(function(){if(a.inArray(this,e.options.excludeFields)!==-1)return!0;var c=a(this),f=e.href+b+c.attr("name")+e.options.customKeyPrefix;e.browserStorage.delete(f),d=!0}),d&&a.isFunction(e.options.onRelease)&&e.options.onRelease.call()}}}var b={instantiated:null,started:null};return{getInstance:function(){return b.instantiated||(b.instantiated=c(),b.instantiated.setInitialOptions()),b.instantiated},free:function(){return b={},null}}}()})(jQuery)
+(function(a){a.sisyphus=function(){return Sisyphus.getInstance()},a.fn.sisyphus=function(a){var b=Sisyphus.getInstance();return b.setOptions(a),b.protect(this),b};var b={};b.isAvailable=function(){if(typeof a.jStorage=="object")return!0;try{return localStorage.getItem}catch(b){return!1}},b.set=function(b,c){if(typeof a.jStorage=="object")a.jStorage.set(b,c+"");else try{localStorage.setItem(b,c+"")}catch(d){}},b.get=function(b){if(typeof a.jStorage=="object"){var c=a.jStorage.get(b);return c?c.toString():c}return localStorage.getItem(b)},b.remove=function(b){typeof a.jStorage=="object"?a.jStorage.deleteKey(b):localStorage.removeItem(b)},Sisyphus=function(){function d(){return{setInitialOptions:function(c){var d={excludeFields:null,customKeyPrefix:"",timeout:0,autoRelease:!0,onSave:function(){},onRestore:function(){},onRelease:function(){}};this.options=this.options||a.extend(d,c),this.browserStorage=b},setOptions:function(b){this.options=this.options||this.setInitialOptions(b),this.options=a.extend(this.options,b)},protect:function(b){b=b||{};var d=this;this.targets=this.targets||[],this.href=location.hostname+location.pathname+location.search,this.targets=a.merge(this.targets,b),this.targets=a.unique(this.targets),this.targets=a(this.targets);if(!this.browserStorage.isAvailable())return!1;d.restoreAllData(),this.options.autoRelease&&d.bindReleaseData(),c.started||(d.bindSaveData(),c.started=!0)},bindSaveData:function(){var b=this;b.options.timeout&&b.saveDataByTimeout(),b.targets.each(function(){var c=a(this).attr("id"),d=a(this).find(":input").not(":submit").not(":reset").not(":button");d.each(function(){if(a.inArray(this,b.options.excludeFields)!==-1)return!0;var d=a(this),e=b.href+c+d.attr("name")+b.options.customKeyPrefix;d.is(":text")||d.is("textarea")?b.options.timeout||b.bindSaveDataImmediately(d,e):b.bindSaveDataOnChange(d,e)})})},saveAllData:function(){var b=this;b.targets.each(function(){var c=a(this).attr("id"),d=a(this).find(":input").not(":submit").not(":reset").not(":button");d.each(function(){if(a.inArray(this,b.options.excludeFields)!==-1)return!0;var d=a(this),e=b.href+c+d.attr("name")+b.options.customKeyPrefix,f=d.val();d.is(":checkbox")?(d.attr("name").indexOf("[")!=-1?(f=[],a("[name='"+d.attr("name")+"']:checked").each(function(){f.push(a(this).val())})):f=d.is(":checked"),b.saveToBrowserStorage(e,f,!1)):d.is(":radio")?d.is(":checked")&&(f=d.val(),b.saveToBrowserStorage(e,f,!1)):b.saveToBrowserStorage(e,f,!1)})}),a.isFunction(b.options.onSave)&&b.options.onSave.call()},restoreAllData:function(){var b=this,c=!1;b.targets.each(function(){var d=a(this),e=d.attr("id"),f=d.find(":input").not(":submit").not(":reset").not(":button");f.each(function(){if(a.inArray(this,b.options.excludeFields)!==-1)return!0;var d=a(this),f=b.href+e+d.attr("name")+b.options.customKeyPrefix,g=b.browserStorage.get(f);g&&(b.restoreFieldsData(d,g),c=!0)})}),c&&a.isFunction(b.options.onRestore)&&b.options.onRestore.call()},restoreFieldsData:function(a,b){a.is(":checkbox")&&b!=="false"&&a.attr("name").indexOf("[")===-1?a.attr("checked","checked"):a.is(":radio")?a.val()===b&&a.attr("checked","checked"):a.attr("name").indexOf("[")===-1?a.val(b):(b=b.split(","),a.val(b))},bindSaveDataImmediately:function(b,c){var d=this;a.browser.msie==null?b.get(0).oninput=function(){d.saveToBrowserStorage(c,b.val())}:b.get(0).onpropertychange=function(){d.saveToBrowserStorage(c,b.val())}},saveToBrowserStorage:function(b,c,d){d=d==null?!0:d,this.browserStorage.set(b,c),d&&c!==""&&a.isFunction(this.options.onSave)&&this.options.onSave.call()},bindSaveDataOnChange:function(a,b){var c=this;a.change(function(){c.saveAllData()})},saveDataByTimeout:function(){var a=this,b=a.targets;setTimeout(function(b){function c(){a.saveAllData(),setTimeout(c,a.options.timeout*1e3)}return c}(b),a.options.timeout*1e3)},bindReleaseData:function(){var b=this;b.targets.each(function(c){var d=a(this),e=d.find(":input").not(":submit").not(":reset").not(":button"),f=d.attr("id");a(this).bind("submit reset",function(){b.releaseData(f,e)})})},manuallyReleaseData:function(){var b=this;b.targets.each(function(c){var d=a(this),e=d.find(":input").not(":submit").not(":reset").not(":button"),f=d.attr("id");b.releaseData(f,e)})},releaseData:function(b,c){var d=!1,e=this;c.each(function(){if(a.inArray(this,e.options.excludeFields)!==-1)return!0;var c=a(this),f=e.href+b+c.attr("name")+e.options.customKeyPrefix;e.browserStorage.remove(f),d=!0}),d&&a.isFunction(e.options.onRelease)&&e.options.onRelease.call()}}}var c={instantiated:null,started:null};return{getInstance:function(){return c.instantiated||(c.instantiated=d(),c.instantiated.setInitialOptions()),c.instantiated},free:function(){return c={},null}}}()})(jQuery)

0 comments on commit 877b12a

Please sign in to comment.
Something went wrong with that request. Please try again.