Файл: static/js/sisyphus.js
Строк: 282
<?php
(function(d){d.sisyphus=function(){return Sisyphus.getInstance()},d.fn.sisyphus=function(f){var e=Sisyphus.getInstance();return e.setOptions(f),e.protect(this),e};var c={};c.isAvailable=function(){if(typeof d.jStorage=="object"){return !0}try{return localStorage.getItem}catch(a){return !1}},c.set=function(a,f){if(typeof d.jStorage=="object"){d.jStorage.set(a,f+"")}else{try{localStorage.setItem(a,f+"")}catch(e){}}},c.get=function(a){if(typeof d.jStorage=="object"){var e=d.jStorage.get(a);return e?e.toString():e}return localStorage.getItem(a)},c.remove=function(a){typeof d.jStorage=="object"?d.jStorage.deleteKey(a):localStorage.removeItem(a)},Sisyphus=function(){function a(){return{setInitialOptions:function(f){var e={excludeFields:[],customKeyPrefix:"",timeout:0,autoRelease:!0,name:null,onSave:function(){},onBeforeRestore:function(){},onRestore:function(){},onRelease:function(){}};this.options=this.options||d.extend(e,f),this.browserStorage=c},setOptions:function(e){this.options=this.options||this.setInitialOptions(e),this.options=d.extend(this.options,e)},protect:function(e){e=e||{};var f=this;this.targets=this.targets||[],this.href=this.options.name||location.hostname+location.pathname+location.search+location.hash,this.targets=d.merge(this.targets,e),this.targets=d.unique(this.targets),this.targets=d(this.targets);if(!this.browserStorage.isAvailable()){return !1}f.restoreAllData(),this.options.autoRelease&&f.bindReleaseData(),b.started||(f.bindSaveData(),b.started=!0)},bindSaveData:function(){var e=this;e.options.timeout&&e.saveDataByTimeout(),e.targets.each(function(){var g=d(this).attr("id"),f=d(this).find(":input").not(":submit").not(":reset").not(":button").not(":file");f.each(function(){if(d.inArray(this,e.options.excludeFields)!==-1){return !0}var i=d(this),h=e.href+g+i.attr("name")+e.options.customKeyPrefix;i.is(":text")||i.is("textarea")?e.options.timeout||e.bindSaveDataImmediately(i,h):e.bindSaveDataOnChange(i,h)})})},saveAllData:function(){var e=this;e.targets.each(function(){var g=d(this).attr("id"),f=d(this).find(":input").not(":submit").not(":reset").not(":button").not(":file");f.each(function(){var j=d(this);if(d.inArray(this,e.options.excludeFields)!==-1||j.attr("name")===undefined){return !0}var i=e.href+g+j.attr("name")+e.options.customKeyPrefix,h=j.val();j.is(":checkbox")?(j.attr("name").indexOf("[")!==-1?(h=[],d("[name='"+j.attr("name")+"']:checked").each(function(){h.push(d(this).val())})):h=j.is(":checked"),e.saveToBrowserStorage(i,h,!1)):j.is(":radio")?j.is(":checked")&&(h=j.val(),e.saveToBrowserStorage(i,h,!1)):e.saveToBrowserStorage(i,h,!1)})}),d.isFunction(e.options.onSave)&&e.options.onSave.call()},restoreAllData:function(){var e=this,f=!1;d.isFunction(e.options.onBeforeRestore)&&e.options.onBeforeRestore.call(e),e.targets.each(function(){var i=d(this),h=i.attr("id"),g=i.find(":input").not(":submit").not(":reset").not(":button").not(":file");g.each(function(){if(d.inArray(this,e.options.excludeFields)!==-1){return !0}var l=d(this),k=e.href+h+l.attr("name")+e.options.customKeyPrefix,j=e.browserStorage.get(k);j&&(e.restoreFieldsData(l,j),f=!0)})}),f&&d.isFunction(e.options.onRestore)&&e.options.onRestore.call()},restoreFieldsData:function(f,e){if(f.attr("name")===undefined){return !1}f.is(":checkbox")&&e!=="false"&&f.attr("name").indexOf("[")===-1?f.attr("checked","checked"):f.is(":radio")?f.val()===e&&f.attr("checked","checked"):f.attr("name").indexOf("[")===-1?f.val(e):(e=e.split(","),f.val(e))},bindSaveDataImmediately:function(e,g){var f=this;d.browser.msie===null?e.get(0).oninput=function(){f.saveToBrowserStorage(g,e.val())}:e.get(0).onpropertychange=function(){f.saveToBrowserStorage(g,e.val())}},saveToBrowserStorage:function(e,g,f){f=f===null?!0:f,this.browserStorage.set(e,g),f&&g!==""&&d.isFunction(this.options.onSave)&&this.options.onSave.call()},bindSaveDataOnChange:function(f,e){var g=this;f.change(function(){g.saveAllData()})},saveDataByTimeout:function(){var f=this,e=f.targets;setTimeout(function(g){function h(){f.saveAllData(),setTimeout(h,f.options.timeout*1000)}return h}(e),f.options.timeout*1000)},bindReleaseData:function(){var e=this;e.targets.each(function(j){var i=d(this),h=i.find(":input").not(":submit").not(":reset").not(":button").not(":file"),g=i.attr("id");d(this).bind("submit reset",function(){e.releaseData(g,h)})})},manuallyReleaseData:function(){var e=this;e.targets.each(function(j){var i=d(this),h=i.find(":input").not(":submit").not(":reset").not(":button").not(":file"),g=i.attr("id");e.releaseData(g,h)})},releaseData:function(f,i){var h=!1,g=this;i.each(function(){if(d.inArray(this,g.options.excludeFields)!==-1){return !0}var j=d(this),e=g.href+f+j.attr("name")+g.options.customKeyPrefix;g.browserStorage.remove(e),h=!0}),h&&d.isFunction(g.options.onRelease)&&g.options.onRelease.call()}}}var b={instantiated:null,started:null};return{getInstance:function(){return b.instantiated||(b.instantiated=a(),b.instantiated.setInitialOptions()),b.instantiated},free:function(){return b={},null}}}()})(jQuery);
?>