sizzlemctwizzle / GM_config

A lightweight, reusable, cross-browser graphical settings framework for inclusion in user scripts.

Home Page:https://github.com/sizzlemctwizzle/GM_config/wiki

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Custom Field Types

sizzlemctwizzle opened this issue · comments

As a very advance feature, users will be able to implement custom field types. They provide a default value for the type along with three functions (toNode, toValue, reset) that allows GM_config to handle the custom type. These custom functions will actually replace the default functions on field objects of this type (which will give them the scope to do all sorts of interesting shit). Implementation of this feature directly requires the implementation of #53.

GM_config.init(
{
  'id': 'GM_config',
  'fields': 
    {
      'SomeField':
      {
        // All these properties are passed to the custom functions
        'type': 'someType'
        'someProp': 'What ever'
      }
    },
  'types':
    {
      'someType': {
        'default': 'Some default value for this type',
        toNode: function() { 
          // toNode is expected to return a DOM element
          // it also needs to store a reference to the element on this.node
        },
        toValue: function() { 
          // toValue is expected to return a string value
          // or null if this.node is null
        },
        reset: function() { 
          // reset is expected to reset the field to its default value
          // or do nothing if this.node is null
        }
      }
    }
});