-
Notifications
You must be signed in to change notification settings - Fork 91
Additional documentation
Defines acceptable url variables and their acceptable values. Used for validation by setAnchor but not by makeAnchorMap.
###schema_map An object with the following general structure:
{
independent_var : true,
_independent_var : {
dependent_var: true,
dependent_var: { acceptable_value : true, acceptable_value : true, ... },
...
},
independent_var : { acceptable_value : true, acceptable_value : true, ... },
_independent_var : {
dependent_var: true,
dependent_var: { acceptable_value : true, acceptable_value : true, ... },
...
},
...
}
Independent variables can be defined simply as legal:
independent_var : true
or with a set of acceptable values:
independent_var : { acceptable_value : true, acceptable_value : true }
When calling setAnchor, using an undefined independent variable will cause an error. If acceptable values are defined, using an undefined value will also cause an error.
Dependent variables can be defined the same way, with an important behavior difference. Simple definitions without acceptable values are for documentation only. Using an undefined dependent variable does not cause an error. However, when a list of acceptable values is defined, using a dependent variable with an undefined value will cause an error.
schema_map: {
page: true,
_page: {
topic: true,
category: { '1 fish': true, '2 fish': true, 'red fish': false }
},
slider: { confirm: true, deny: true },
_slider: { text: true, what: true },
color: { red: true, green: true, blue: false }
}
Let's take a look at this, line by line:
page : true,
Defines page
as an independent variable that will accept any value.
_page: {
topic: true,
category: { '1 fish': true, '2 fish': true, 'red fish': false }
},
Defines dependent variables that apply only if page
is used. The dependent variable category
can have the value "1 fish" or "2 fish", but "red fish" and all other values will cause an error. The dependent variable topic
is included for documentation only. There are no restrictions on the names of dependent variables except when they have a list of acceptable values.
slider: { confirm: true, deny: true },
Defines slider
as an independent var, with acceptable values "confirm" and "deny".
_slider: { text: true, what: true },
Defines dependent variables text
and what
which apply when slider
is used.
color: { red: true, green: true, blue: false }
Defines independent variable color
with acceptable values red
and green
. The value blue
will cause an error.
###Sample setAnchor calls
and the URIs they generate, based on the above schema_map:
URI: #!page=main:topic,ocean|category,1%20fish|depth,50
$.uriAnchor.setAnchor({
page: 'main',
_page: {
topic: 'ocean',
category: '1 fish',
depth: 50
}
});
URI: #!page=main:topic,Anything%20you%20want|category,1%20fish|thing,zero&slider=confirm:text,hello|pretty,123&color=red
$.uriAnchor.setAnchor({
page: 'main',
_page: {
topic: 'Anything you want',
category: '1 fish',
thing: 'zero'
},
slider: 'confirm',
_slider: {
text: 'hello',
pretty: 123
},
color: 'red',
});
URI: #!page=main:online,2%20fish|nothing,zero&slider=confirm:text,hello|pretty,123&color=red
$.uriAnchor.setAnchor({
page: 'main',
_page: {
online: '2 fish',
nothing: 'zero'
},
slider: 'confirm',
_slider: {
text: 'hello',
pretty: 123
},
color: 'red'
});
#!page=main:topic,ocean|category,1%20fish|depth,50
$.uriAnchor.setAnchor({
page: 'main',
_page: {
topic: 'ocean',
category: '1 fish',
depth: 50
}
});