Changeset 831703
- Timestamp:
- 01/02/2014 04:41:24 PM (12 years ago)
- Location:
- gravity-forms-sisyphus/trunk
- Files:
-
- 3 added
- 4 edited
-
Gruntfile.js (added)
-
gravity-forms-sisyphus.php (modified) (8 diffs)
-
js/sisyphus.js (added)
-
js/sisyphus.min.js (modified) (1 diff)
-
package.json (added)
-
readme.md (modified) (3 diffs)
-
readme.txt (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
gravity-forms-sisyphus/trunk/gravity-forms-sisyphus.php
r713448 r831703 4 4 Plugin URI: https://github.com/bhays/gravity-forms-sisyphus 5 5 Description: Persist your form's data in a browser's Local Storage and never loose them on occasional tabs closing, browser crashes and other disasters with Sisyphus. 6 Version: 1.06 Version: 2.0 7 7 Author: Ben Hays 8 8 Author URI: http://benhays.com … … 35 35 private static $url = "http://www.gravityforms.com"; 36 36 private static $slug = "gravity-forms-sisyphus"; 37 private static $version = " 1.0";37 private static $version = "2.0"; 38 38 private static $min_gravityforms_version = "1.7"; 39 private static $sisyphus_version = '1.1 ';39 private static $sisyphus_version = '1.1.107'; 40 40 41 41 //Plugin starting point. Will load appropriate files … … 59 59 add_action('gform_enqueue_scripts', array( 'GFSisyphus', 'gform_enqueue_scripts' ), '', 2 ); 60 60 } 61 62 public static function gform_enqueue_scripts( $form = null ) 63 { 64 if ( ! $form == null ) 61 62 public static function gform_enqueue_scripts( $form = null ) 63 { 64 if ( ! $form == null ) 65 65 { 66 66 // Check form for enabled sisyphus … … 68 68 { 69 69 wp_enqueue_script('sisyphus', plugins_url( 'js/sisyphus.min.js' , __FILE__ ), array('jquery'),self::$sisyphus_version); 70 70 71 71 // Add sisyphus script to page 72 72 add_action('gform_register_init_scripts', array('GFSisyphus', 'add_page_script')); … … 74 74 } 75 75 } 76 76 77 77 public static function add_page_script($form) 78 78 { 79 79 self::log_debug('Adding page script to '.$form['id']); 80 80 81 81 $script = "(function($){" . 82 82 "$('#gform_".$form['id']."').sisyphus();". … … 84 84 GFFormDisplay::add_init_script($form['id'], 'gravity-forms-js-validate', GFFormDisplay::ON_PAGE_RENDER, $script); 85 85 return $form; 86 } 86 } 87 87 public static function add_form_setting( $settings, $form ) 88 88 { 89 89 $current = rgar($form, 'enable_sisyphus'); 90 90 $checked = !empty($current) ? 'checked="checked"' : ''; 91 91 92 92 $settings['Form Options']['enable_sisyphus'] = ' 93 93 <tr> … … 96 96 </tr>'; 97 97 98 return $settings; 99 } 100 98 return $settings; 99 } 100 101 101 public static function save_form_setting($form) 102 102 { 103 103 $form['enable_sisyphus'] = rgpost('enable_sisyphus'); 104 return $form; 104 return $form; 105 105 } 106 106 … … 123 123 echo '</tr><tr class="plugin-update-tr"><td colspan="5" class="plugin-update"><div class="update-message" ' . $style . '>' . $message . '</div></td>'; 124 124 } 125 125 126 126 private static function is_gravityforms_installed(){ 127 127 return class_exists("RGForms"); -
gravity-forms-sisyphus/trunk/js/sisyphus.min.js
r713448 r831703 1 (function(a){a.fn.sisyphus=function(b){var c=a.map(this,function(b){return a(b).attr("id")+a(b).attr("name")}).join(),d=Sisyphus.getInstance(c);return d.protect(this,b),d};var b={};b.isAvailable=function(){if("object"==typeof a.jStorage)return!0;try{return localStorage.getItem}catch(b){return!1}},b.set=function(b,c){if("object"==typeof a.jStorage)a.jStorage.set(b,c+"");else try{localStorage.setItem(b,c+"")}catch(d){}},b.get=function(b){if("object"==typeof a.jStorage){var c=a.jStorage.get(b);return c?""+c:c}return localStorage.getItem(b)},b.remove=function(b){"object"==typeof a.jStorage?a.jStorage.deleteKey(b):localStorage.removeItem(b)},Sisyphus=function(){function d(){return{setInstanceIdentifier:function(a){this.identifier=a},getInstanceIdentifier:function(){return this.identifier},setInitialOptions:function(c){var d={excludeFields:[],customKeyPrefix:"",locationBased:!1,timeout:0,autoRelease:!0,onSave:function(){},onBeforeRestore: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,d){this.setOptions(d),b=b||{};var e=this;if(this.targets=this.targets||[],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 f=e.options.onBeforeRestore.call(e);(void 0===f||f)&&e.restoreAllData(),this.options.autoRelease&&e.bindReleaseData(),c.started[this.getInstanceIdentifier()]||(e.bindSaveData(),c.started[this.getInstanceIdentifier()]=!0)},bindSaveData:function(){var b=this;b.options.timeout&&b.saveDataByTimeout(),b.targets.each(function(){var c=a(this).attr("id")+a(this).attr("name"),d=a(this).find(":input").not(":submit").not(":reset").not(":button").not(":file").not(":password");d.each(function(){if(-1!==a.inArray(this,b.options.excludeFields))return!0;var d=a(this),e=(b.options.locationBased?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")+a(this).attr("name"),d=a(this).find(":input").not(":submit").not(":reset").not(":button").not(":file").not(":password");d.each(function(){var d=a(this);if(-1!==a.inArray(this,b.options.excludeFields)||void 0===d.attr("name"))return!0;var e=(b.options.locationBased?b.href:"")+c+d.attr("name")+b.options.customKeyPrefix,f=d.val();d.is(":checkbox")?(-1!==d.attr("name").indexOf("[")?(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)})}),b.options.onSave.call()},restoreAllData:function(){var b=this,c=!1;b.targets.each(function(){var d=a(this),e=a(this).attr("id")+a(this).attr("name"),f=d.find(":input").not(":submit").not(":reset").not(":button").not(":file").not(":password");f.each(function(){if(-1!==a.inArray(this,b.options.excludeFields))return!0;var d=a(this),f=(b.options.locationBased?b.href:"")+e+d.attr("name")+b.options.customKeyPrefix,g=b.browserStorage.get(f);g&&(b.restoreFieldsData(d,g),c=!0)})}),c&&b.options.onRestore.call()},restoreFieldsData:function(a,b){return void 0===a.attr("name")?!1:(a.is(":checkbox")&&"false"!==b&&-1===a.attr("name").indexOf("[")?a.attr("checked","checked"):a.is(":checkbox")&&"false"===b&&-1===a.attr("name").indexOf("[")?a.removeAttr("checked"):a.is(":radio")?a.val()===b&&a.attr("checked","checked"):-1===a.attr("name").indexOf("[")?a.val(b):(b=b.split(","),a.val(b)),void 0)},bindSaveDataImmediately:function(a,b){var c=this;"onpropertychange"in a?a.get(0).onpropertychange=function(){c.saveToBrowserStorage(b,a.val())}:a.get(0).oninput=function(){c.saveToBrowserStorage(b,a.val())}},saveToBrowserStorage:function(a,b,c){c=void 0===c?!0:c,this.browserStorage.set(a,b),c&&""!==b&&this.options.onSave.call()},bindSaveDataOnChange:function(a){var c=this;a.change(function(){c.saveAllData()})},saveDataByTimeout:function(){var a=this,b=a.targets;setTimeout(function(){function c(){a.saveAllData(),setTimeout(c,1e3*a.options.timeout)}return c}(b),1e3*a.options.timeout)},bindReleaseData:function(){var b=this;b.targets.each(function(){var d=a(this),e=d.find(":input").not(":submit").not(":reset").not(":button").not(":file").not(":password"),f=d.attr("id")+d.attr("name");a(this).bind("submit reset",function(){b.releaseData(f,e)})})},manuallyReleaseData:function(){var b=this;b.targets.each(function(){var d=a(this),e=d.find(":input").not(":submit").not(":reset").not(":button").not(":file").not(":password"),f=d.attr("id")+d.attr("name");b.releaseData(f,e)})},releaseData:function(b,c){var d=!1,e=this;c.each(function(){if(-1!==a.inArray(this,e.options.excludeFields))return!0;var c=a(this),f=(e.options.locationBased?e.href:"")+b+c.attr("name")+e.options.customKeyPrefix;e.browserStorage.remove(f),d=!0}),d&&e.options.onRelease.call()}}}var c={instantiated:[],started:[]};return{getInstance:function(a){return c.instantiated[a]||(c.instantiated[a]=d(),c.instantiated[a].setInstanceIdentifier(a),c.instantiated[a].setInitialOptions()),a?c.instantiated[a]:c.instantiated[a]},free:function(){return c={},null}}}()})(jQuery); 1 /*! gravity-forms-sisyphus built on 2014-01-01 : Based on https://github.com/simsalabim/sisyphus */ 2 !function(a){a.fn.sisyphus=function(b){var c=a.map(this,function(b){return a(b).attr("id")+a(b).attr("name")}).join(),d=Sisyphus.getInstance(c);return d.protect(this,b),d};var b={};b.isAvailable=function(){if("object"==typeof a.jStorage)return!0;try{return localStorage.getItem}catch(b){return!1}},b.set=function(b,c){if("object"==typeof a.jStorage)a.jStorage.set(b,c+"");else try{localStorage.setItem(b,c+"")}catch(d){}},b.get=function(b){if("object"==typeof a.jStorage){var c=a.jStorage.get(b);return c?c.toString():c}return localStorage.getItem(b)},b.remove=function(b){"object"==typeof a.jStorage?a.jStorage.deleteKey(b):localStorage.removeItem(b)},Sisyphus=function(){function c(){return{setInstanceIdentifier:function(a){this.identifier=a},getInstanceIdentifier:function(){return this.identifier},setInitialOptions:function(c){var d={excludeFields:[],customKeySuffix:"",locationBased:!1,timeout:0,autoRelease:!0,onSave:function(){},onBeforeRestore: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,c){this.setOptions(c),b=b||{};var e=this;if(this.targets=this.targets||[],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 f=e.options.onBeforeRestore.call(e);if((void 0===f||f)&&e.restoreAllData(),this.options.autoRelease&&e.bindReleaseData(),!d.started[this.getInstanceIdentifier()])if(e.isCKEditorPresent())var g=setInterval(function(){CKEDITOR.isLoaded&&(clearInterval(g),e.bindSaveData(),d.started[e.getInstanceIdentifier()]=!0)},100);else e.bindSaveData(),d.started[e.getInstanceIdentifier()]=!0},isCKEditorPresent:function(){return this.isCKEditorExists()?(CKEDITOR.isLoaded=!1,CKEDITOR.on("instanceReady",function(){CKEDITOR.isLoaded=!0}),!0):!1},isCKEditorExists:function(){return"undefined"!=typeof CKEDITOR},findFieldsToProtect:function(a){return a.find(":input").not(":submit").not(":reset").not(":button").not(":file").not(":password").not(":disabled").not("[readonly]").not(".gform_next_button").not("gform_previous_button").not(".gform_hidden")},bindSaveData:function(){var b=this;b.options.timeout&&b.saveDataByTimeout(),b.targets.each(function(){var c=a(this).attr("id");b.findFieldsToProtect(a(this)).each(function(){if(-1!==a.inArray(this,b.options.excludeFields))return!0;var d=a(this),e=(b.options.locationBased?b.href:"")+c+d.attr("id")+b.options.customKeySuffix;(d.is(":text")||d.is("textarea"))&&(b.options.timeout||b.bindSaveDataImmediately(d,e)),b.bindSaveDataOnChange(d)})})},saveAllData:function(){var b=this;b.targets.each(function(){var c=a(this).attr("id"),d={};b.findFieldsToProtect(a(this)).each(function(){var e=a(this);if(-1!==a.inArray(this,b.options.excludeFields)||void 0===e.attr("name"))return!0;var f=(b.options.locationBased?b.href:"")+c+e.attr("id")+b.options.customKeySuffix,g=e.val();if(e.is(":checkbox")){if(-1!==e.attr("name").indexOf("[")){if(d[e.attr("name")]===!0)return;g=[],a("[name='"+e.attr("name")+"']:checked").each(function(){g.push(a(this).val())}),d[e.attr("name")]=!0}else g=e.is(":checked");b.saveToBrowserStorage(f,g,!1)}else if(e.is(":radio"))e.is(":checked")&&(g=e.val(),b.saveToBrowserStorage(f,g,!1));else if(b.isCKEditorExists()){var h;(h=CKEDITOR.instances[e.attr("name")]||CKEDITOR.instances[e.attr("id")])?(h.updateElement(),b.saveToBrowserStorage(f,e.val(),!1)):b.saveToBrowserStorage(f,g,!1)}else b.saveToBrowserStorage(f,g,!1)})}),b.options.onSave.call(b)},restoreAllData:function(){var b=this,c=!1;b.targets.each(function(){var d=a(this),e=a(this).attr("id");b.findFieldsToProtect(d).each(function(){if(-1!==a.inArray(this,b.options.excludeFields))return!0;var d=a(this),f=(b.options.locationBased?b.href:"")+e+d.attr("id")+b.options.customKeySuffix,g=b.browserStorage.get(f);null!==g&&(b.restoreFieldsData(d,g),c=!0)})}),c&&b.options.onRestore.call(b)},restoreFieldsData:function(a,b){return void 0===a.attr("name")?!1:(a.is(":checkbox")&&"false"!==b&&-1===a.attr("name").indexOf("[")?a.attr("checked","checked"):a.is(":checkbox")&&"false"===b&&-1===a.attr("name").indexOf("[")?a.removeAttr("checked"):a.is(":radio")?a.val()===b&&a.attr("checked","checked"):-1===a.attr("name").indexOf("[")?a.val(b):(b=b.split(","),a.val(b)),void 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;(d=CKEDITOR.instances[a.attr("name")]||CKEDITOR.instances[a.attr("id")])&&d.document.on("keyup",function(){d.updateElement(),c.saveToBrowserStorage(b,a.val())})}},saveToBrowserStorage:function(a,b,c){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 b=this;b.targets.each(function(){var c=a(this),d=c.attr("id");c.find("[id^=gform_submit_button]","reset").on("click",function(){b.releaseData(d,b.findFieldsToProtect(c))})})},manuallyReleaseData:function(){var b=this;b.targets.each(function(){var c=a(this),d=c.attr("id");b.releaseData(d,b.findFieldsToProtect(c))})},releaseData:function(b,c){var e=!1,f=this;d.started[f.getInstanceIdentifier()]=!1,c.each(function(){if(-1!==a.inArray(this,f.options.excludeFields))return!0;var c=a(this),d=(f.options.locationBased?f.href:"")+b+c.attr("id")+f.options.customKeySuffix;f.browserStorage.remove(d),e=!0}),e&&f.options.onRelease.call(f)}}}var d={instantiated:[],started:[]};return{getInstance:function(a){return d.instantiated[a]||(d.instantiated[a]=c(),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.107"}}()}(jQuery); -
gravity-forms-sisyphus/trunk/readme.md
r713448 r831703 2 2 ====================== 3 3 4 Version 1.04 Version 2.0 5 5 6 6 Allow for saving your form data with local storage using [Sisyphus](http://sisyphus-js.herokuapp.com/). … … 8 8 Persist your form's data in a browser's Local Storage and never loose them on occasional tabs closing, browser crashes and other disasters! 9 9 10 Thanks to swingline0 for the updates on v2.0. Now works with paged forms. 10 11 11 12 ## Requirements … … 21 22 ## Changelog 22 23 23 ### 1.0 24 ### 2.0 25 * Thanks to swingline0 for the updates on v2.0 26 * Update to current Sisyphus 27 * Support for paged forms 28 * Multi-part date field restored all three fields with contents of the third 29 * Sisyphus altering Gravity Forms hidden fields 30 * Sisyphus creating excessive entries during Chrome autocomplete 31 32 ### 1.0 24 33 * Initial release with Sisyphus 1.1 25 34 -
gravity-forms-sisyphus/trunk/readme.txt
r713448 r831703 1 1 === Gravity Forms Sisyphus === 2 Contributors: benhays 3 Donate link: 2 Contributors: benhays swingline0 3 Donate link: 4 4 Tags: gravity forms, gravityforms, sisyphus, save data, local storage 5 5 Requires at least: 3.3 6 Tested up to: 3. 5.17 Stable tag: 1.06 Tested up to: 3.8 7 Stable tag: 2.0 8 8 License: GPLv2 or later 9 9 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 16 16 17 17 Persist your form's data in a browser's Local Storage and never loose them on occasional tabs closing, browser crashes and other disasters! 18 19 Thanks to swingline0 for the updates on v2.0. Now works with paged forms. 18 20 19 21 This requires Gravity Forms version 1.7 or higher. … … 33 35 == Changelog == 34 36 37 ### 2.0 38 * Thanks to swingline0 for the updates on v2.0 39 * Update to current Sisyphus 40 * Support for paged forms 41 * Multi-part date field restored all three fields with contents of the third 42 * Sisyphus altering Gravity Forms hidden fields 43 * Sisyphus creating excessive entries during Chrome autocomplete 44 35 45 ### 1.0 36 46 * Initial release with Sisyphus 1.1
Note: See TracChangeset
for help on using the changeset viewer.