applyFilters( “set_data” )

  1. Home
  2. Knowledge Base
  3. Codex
  4. JS API
  5. JS Filters
  6. applyFilters( “set_data” )
DiviArea.applyFilters( "set_data", value, key );
DiviArea.applyFilters( "set_data_{key}", value, key );

Filters a value that will be written to a Cookie or the localStorage.

The {key} part in the hook name is the sanitized variable-name (all lower case, dashes changed to underscores).

Params

value
(string) The value that will be saved to a Cookie or localStorage.
key
(string) Name of the entry. This will be part of the Cookie name or the localStorage object key.

Source

This filter is called inside DiviArea.Utils.setLocalData().

Examples

// Example 1: Output data to the console before it will be saved.
DiviArea.addFilter( 'set_data', function( value, key ) {
    console.log('Saving local variable', key, 'with value', value);
    return value;
});


// Example 2: Disable local data
DiviArea.addFilter( 'set_data', function( value, key ) {
    return false;
});

Notes

The setLocalData() method will decide, whether to write a Cookie or to save data to the localStorage instead.

When this filter returns boolean false, then no entry is saved in the localStorage (and no Cookie will be changed)

Was this article helpful?

Related Articles