mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-12 08:55:47 +01:00
removed unnecessary method + doc within Settings Framework
This commit is contained in:
@@ -13,79 +13,6 @@ define(function () {
|
||||
waitingJobs = 0,
|
||||
helper;
|
||||
|
||||
/*
|
||||
* Attributes of HTML-tags that get used by default plugins:
|
||||
* + data-key: the key to save/load the value within configuration-object
|
||||
* + data-type: highest priority type-definition to determine what kind of element it is or which plugin to hook
|
||||
* + type: normal priority type-definition
|
||||
* + data-empty: if 'false' or '0' then values that are assumed as empty turn into null. data-empty of arrays affect
|
||||
* their child-elements
|
||||
* + data-trim: if not 'false' or '0' then values will get trimmed as defined by the elements type
|
||||
* + data-split: if set and the element doesn't belong to any plugin, it's value will get split and joined by its
|
||||
* value into the input-field
|
||||
* array-elements:
|
||||
* + data-split: separator (HTML allowed) between the elements, defaults to ', '
|
||||
* + data-new: value to insert into new created elements
|
||||
* + data-attributes: an object to set the attributes of the child HTML-elements. tagName as special key will set
|
||||
* the tag-name of the child HTML-elements
|
||||
* key-fields:
|
||||
* + data-trim: if 'false' or '0' then the value will get saved as string else as object providing following
|
||||
* properties: ctrl, alt, shift, meta, code, char
|
||||
* + data-split: separator between different modifiers and the key-code of the value that gets saved
|
||||
* (only takes effect if trimming)
|
||||
* + data-short: if not 'false' or '0' then modifier-keys get saved as first uppercase character
|
||||
* (only takes effect if trimming)
|
||||
* select:
|
||||
* + data-options: an array of {"text":"Displayed Text","value":"some_value"}-like objects
|
||||
*
|
||||
* The name of the HTML-tag is lowest priority type-definition
|
||||
*
|
||||
* Examples-HTML:
|
||||
No!
|
||||
<input type="checkbox" data-key="cfg1"></input><br>
|
||||
Yes!
|
||||
<input type="checkbox" data-key="cfg2"></input><br>
|
||||
An array of checkboxes that are selected by default:
|
||||
<div data-key="cfg3" data-attributes='{"data-type":"checkbox"}' data-new='true'></div><br>
|
||||
A simple input-field of any common type:
|
||||
<input type="password" data-key="cfg4"></input><br>
|
||||
A simple textarea:
|
||||
<textarea data-key="cfg5"></textarea><br>
|
||||
Array of textareas:
|
||||
<div data-key="cfg6" data-attributes='{"data-type":"textarea"}' data-new='Hello Kitty, ahem... World!'></div><br>
|
||||
2D-Array of numbers that persist even when empty (but not empty rows):
|
||||
<div data-key="cfg7" data-split="<br>" data-attributes='{"data-type":"array","data-attributes":{"type":"number"}}' data-new='[42,21]'></div><br>
|
||||
Same with persisting empty rows, but not empty numbers, if no row is given null will get saved:
|
||||
<div data-key="cfg8" data-split="<br>" data-empty="false" data-attributes='{"data-type":"array","data-empty":true,"data-attributes":{"type":"number","data-empty":false}}' data-new='[42,21]'></div><br>
|
||||
Array of Key-shortcuts (new: Ctrl+Shift+7):
|
||||
<div data-key="cfg9" data-attributes='{"data-type":"key"}' data-new='Ctrl+Shift+#55'></div><br>
|
||||
Array of numbers (new: 42, step: 21):
|
||||
<div data-key="cfg10" data-attributes='{"data-type":"number","step":21}' data-new='42'></div><br>
|
||||
Select with dynamic options:
|
||||
<select data-key="cfg11" data-options='[{"value":"2","text":"2"},{"value":"3","text":"3"}]'></select><br>
|
||||
Select that loads faster:
|
||||
<select data-key="cfg12"><br>
|
||||
<option value="2">2</option>
|
||||
<option value="3">3</option>
|
||||
</select>
|
||||
*
|
||||
* Matching configuration:
|
||||
{
|
||||
cfg1: false,
|
||||
cfg2: true,
|
||||
cfg3: [false, false, true],
|
||||
cfg4: 'hello world',
|
||||
cfg5: 'some\nlong\ntext',
|
||||
cfg6: ['some\nlong\ntexts', 'and another one'],
|
||||
cfg7: [[]],
|
||||
cfg8: [[]],
|
||||
cfg9: [],
|
||||
cfg10: [],
|
||||
cfg11: 3,
|
||||
cfg12: 2
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
Returns the hook of given name that matches the given type or element.
|
||||
@param type The type of the element to get the matching hook for, or the element itself.
|
||||
@@ -404,26 +331,6 @@ define(function () {
|
||||
},
|
||||
/**
|
||||
Registers a new plugin and calls its use-hook.
|
||||
A plugin is an object containing a types-property to define its default bindings.
|
||||
A plugin may also provide the following properties of type function with [return-value] (parameters):
|
||||
use [void] - gets called when the Settings initializes the plugin.
|
||||
init [void] (element) - gets called on page-load and every time after the create-hook.
|
||||
; element: The element to initialize.
|
||||
create [JQuery-Object] (type, tagName, data) - gets called when a new HTML-instance needs to get created.
|
||||
; type: A string that identifies the plugin itself within this Settings-instance if set as data-type.
|
||||
; tagName: The tag-name that gets requested.
|
||||
; data: Additional data, plugin-dependent meaning.
|
||||
destruct [void] (element) - gets called after a HTML-instance got removed from DOM
|
||||
; element: The element that got removed.
|
||||
set [void] (element, value, trim) - gets called when the value of the element should be set to the given value.
|
||||
; element: The element to set its value.
|
||||
; value: The value to set.
|
||||
; trim: Whether the value is considered as trimmed.
|
||||
get [value] (element, trim, empty) - gets called when the value of the given instance is needed.
|
||||
; element: The element to get its value.
|
||||
; trim: Whether the result should be trimmed.
|
||||
; empty: Whether considered as empty values should get saved too.
|
||||
All passed elements are JQuery-Objects.
|
||||
@param service The plugin to register.
|
||||
@param types The types to bind the plugin to.
|
||||
*/
|
||||
|
||||
@@ -27,7 +27,7 @@ function trim(obj1, obj2) {
|
||||
|
||||
function mergeSettings(cfg, defCfg) {
|
||||
if (typeof cfg._settings !== typeof defCfg || typeof defCfg !== 'object') {
|
||||
return cfg._settings = defCfg;
|
||||
cfg._settings = defCfg;
|
||||
} else {
|
||||
expandObjBy(cfg._settings, defCfg);
|
||||
trim(cfg._settings, defCfg);
|
||||
@@ -103,22 +103,6 @@ Settings.prototype.persist = function (callback) {
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
Persists the settings if no settings are saved.
|
||||
@param callback Gets called when done.
|
||||
*/
|
||||
Settings.prototype.persistOnEmpty = function (callback) {
|
||||
var _this = this;
|
||||
meta.settings.get(this.hash, function (err, settings) {
|
||||
if (!settings._settings) {
|
||||
_this.persist(callback);
|
||||
} else if (typeof callback === 'function') {
|
||||
callback.call(_this);
|
||||
}
|
||||
});
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
Returns the setting of given key or default value if not set.
|
||||
@param key The key of the setting to return.
|
||||
|
||||
Reference in New Issue
Block a user