Plugin Directory

Changeset 831703


Ignore:
Timestamp:
01/02/2014 04:41:24 PM (12 years ago)
Author:
benhays
Message:

paged forms, updated sisyphus and more

Location:
gravity-forms-sisyphus/trunk
Files:
3 added
4 edited

Legend:

Unmodified
Added
Removed
  • gravity-forms-sisyphus/trunk/gravity-forms-sisyphus.php

    r713448 r831703  
    44Plugin URI: https://github.com/bhays/gravity-forms-sisyphus
    55Description: 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.0
     6Version: 2.0
    77Author: Ben Hays
    88Author URI: http://benhays.com
     
    3535    private static $url = "http://www.gravityforms.com";
    3636    private static $slug = "gravity-forms-sisyphus";
    37     private static $version = "1.0";
     37    private static $version = "2.0";
    3838    private static $min_gravityforms_version = "1.7";
    39     private static $sisyphus_version = '1.1';
     39    private static $sisyphus_version = '1.1.107';
    4040
    4141    //Plugin starting point. Will load appropriate files
     
    5959        add_action('gform_enqueue_scripts', array( 'GFSisyphus', 'gform_enqueue_scripts' ), '', 2 );
    6060    }
    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 )
    6565        {
    6666            // Check form for enabled sisyphus
     
    6868            {
    6969                wp_enqueue_script('sisyphus', plugins_url( 'js/sisyphus.min.js' , __FILE__ ), array('jquery'),self::$sisyphus_version);
    70        
     70
    7171                // Add sisyphus script to page
    7272                add_action('gform_register_init_scripts', array('GFSisyphus', 'add_page_script'));
     
    7474        }
    7575    }
    76    
     76
    7777    public static function add_page_script($form)
    7878    {
    7979        self::log_debug('Adding page script to '.$form['id']);
    80        
     80
    8181        $script = "(function($){" .
    8282            "$('#gform_".$form['id']."').sisyphus();".
     
    8484        GFFormDisplay::add_init_script($form['id'], 'gravity-forms-js-validate', GFFormDisplay::ON_PAGE_RENDER, $script);
    8585        return $form;
    86     }   
     86    }
    8787    public static function add_form_setting( $settings, $form )
    8888    {
    8989        $current = rgar($form, 'enable_sisyphus');
    9090        $checked = !empty($current) ? 'checked="checked"' : '';
    91        
     91
    9292        $settings['Form Options']['enable_sisyphus'] = '
    9393            <tr>
     
    9696            </tr>';
    9797
    98         return $settings;       
    99     }
    100    
     98        return $settings;
     99    }
     100
    101101    public static function save_form_setting($form)
    102102    {
    103103        $form['enable_sisyphus'] = rgpost('enable_sisyphus');
    104         return $form;   
     104        return $form;
    105105    }
    106106
     
    123123        echo '</tr><tr class="plugin-update-tr"><td colspan="5" class="plugin-update"><div class="update-message" ' . $style . '>' . $message . '</div></td>';
    124124    }
    125    
     125
    126126    private static function is_gravityforms_installed(){
    127127        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  
    22======================
    33
    4 Version 1.0
     4Version 2.0
    55
    66Allow for saving your form data with local storage using [Sisyphus](http://sisyphus-js.herokuapp.com/).
     
    88Persist your form's data in a browser's Local Storage and never loose them on occasional tabs closing, browser crashes and other disasters!
    99
     10Thanks to swingline0 for the updates on v2.0. Now works with paged forms.
    1011
    1112## Requirements
     
    2122## Changelog
    2223
    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
    2433* Initial release with Sisyphus 1.1
    2534
  • gravity-forms-sisyphus/trunk/readme.txt

    r713448 r831703  
    11=== Gravity Forms Sisyphus ===
    2 Contributors: benhays
    3 Donate link: 
     2Contributors: benhays swingline0
     3Donate link:
    44Tags: gravity forms, gravityforms, sisyphus, save data, local storage
    55Requires at least: 3.3
    6 Tested up to: 3.5.1
    7 Stable tag: 1.0
     6Tested up to: 3.8
     7Stable tag: 2.0
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    1616
    1717Persist your form's data in a browser's Local Storage and never loose them on occasional tabs closing, browser crashes and other disasters!
     18
     19Thanks to swingline0 for the updates on v2.0. Now works with paged forms.
    1820
    1921This requires Gravity Forms version 1.7 or higher.
     
    3335== Changelog ==
    3436
     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
    3545### 1.0
    3646* Initial release with Sisyphus 1.1
Note: See TracChangeset for help on using the changeset viewer.