Skip to content

Commit

Permalink
Staged for inclusion to jQuery plugins site
Browse files Browse the repository at this point in the history
  • Loading branch information
mmikowski committed Apr 12, 2013
1 parent 3ec190e commit 40e443d
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 57 deletions.
99 changes: 53 additions & 46 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,47 +1,58 @@
# uriAnchor
## a jquery plugin for management of the uri hash component
# uriAnchor #

Michael S. Mikowski - Posted 2013-01-12
## Summary ##

## method: setAnchor
A jQuery plugin for management of the uri hash component.

### Purpose
## Release Notes ##

### Copyright (c)###
2013 Michael S. Mikowski (mike[dot]mikowski[at]gmail[dotcom])

### License ###
Dual licensed under the MIT or GPL Version 2
http://jquery.org/license

### Version 1.1.0 ###
This is the first release registered with jQuery plugins.

## Methods ##

### $.uriAnchor.setAnchor ##

#### Purpose ####

Sets Anchor component of the URI from a Map
(The Anchor component is also known as the
'hash fragment' or 'bookmark component')

### Arguments
#### Arguments ####

Arguments are positional:

* 1 ( anchor_map ) The map to be encoded to the URI anchor
* 2 ( option_map ) : map of options
* 3 ( replace_flag ) : boolean flag to replace the URI When true, the URI is replaced, which means the prior URI is not entered into the browser history
- 1 ( `anchor_map` ) : The map to be encoded to the URI anchor
- 2 ( `option_map` ) : A map of options
- 3 ( `replace_flag` ) : A boolean flag. When true, the method replaces the URI so that prior URI is not entered into the browser history

### Environment
#### Environment ####

Expects the document.location browser object

### Settings

none

### Settings
#### Settings ####

none

### Returns
#### Returns ####

boolean: true on success, false on failure

### Throws
#### Throws ####

none

### Details
#### Details ####

The first positional argument, anchor_map, may be a simple map:
The first positional argument, `anchor_map`, may be a simple map:

$.uriAnchor.setAnchor({
page : 'profile',
Expand All @@ -57,10 +68,10 @@ All these arguments are independent, that is, they can vary
independent of each other. We also support dependent values -
values that depend on others.

An independent argument key has no '_' prefix. The same key name,
prefixed by an '_', holds the arguments that are dependent on
an independent argument. The dependent key always points
to a map. Consider:
An independent argument key has no `_` prefix. The same key name,
prefixed by an `_`, holds the arguments that are dependent on
an independent argument. The dependent key always points
to a map. Consider:

$.uriAnchor.setAnchor({
page : 'profile',
Expand All @@ -76,7 +87,7 @@ This changes the URI Anchor to:

Only independent keys and their matching dependent keys are
processed. All other keys are ignored. Importantly, this includes
keys of the form _s_/key/ ( e.g. '_s_page' ) returned by makeAnchorMap
keys of the form `_s_<key>` ( e.g. `_s_page` ) returned by makeAnchorMap

Setting a more complex anchor map is illustrated below:

Expand All @@ -99,19 +110,14 @@ This sets the URI Anchor to:
#!page=profile:uname,wendy|online,today&slider=confirm:text,hello\
|pretty,false&color=red

Options: The second positional argument tp this method, option_map,
Options: The second positional argument tp this method, `option_map`,
provides a number of options for delimiters:

* delimit_char : delimiter independent args
Defaults to '&'
* delimit_kv_char : delimiter key-value of independent args
Defaults to '='
* sub_delimit_char : delimiter independent and dependent args
Defaults to ':'
* dep_delimit_char : delimiter between key-value of dependent args
Defaults to '|'
* dep_kv_delimit_char : key-value delimiter for dependent args.
Defaults to ','
- `delimit_char` : Delimiter between independent args. Default is `&`.
- `delimit_kv_char`: Delimiter between key and value of independent args. Default is `=`.
- `sub_delimit_char` : Delimiter between independent and dependent args. Defaults is `:`.
* `dep_delimit_char` : Delimiter between key-value pairs in dependent args. Default is `|`.
- `dep_kv_delimit_char` : Delimiter between key and value of dependent args. Default is ','

Boolean values ( as part of a key-value pair ) are convert into the stings 'true' or 'false'.

Expand All @@ -138,44 +144,44 @@ module configuration to set the schema, like so:
This check occurs only during setting of the Anchor, not
during its parsing ( See makeAnchorMap )

The replace_flag instructs the routine to replace the uri,
The `replace_flag` instructs the routine to replace the uri,
discarding browser history


## method: makeAnchorMap
### $.uriAnchor.makeAnchorMap

### Purpose
#### Purpose

Parses URI anchor and returns as map

### Arguments
#### Arguments

none

### Environment
#### Environment

Expects the document.location browser object

### Settings
#### Settings

none

### Returns
#### Returns

Map

### Throws
#### Throws

none


### Details
#### Details

Parses the browser URI anchor into a map using the same
rules used to set the anchor in the method setAnchor
( see above ).

This method creates an additional key type, _s_<indendent_arg>
This method creates an additional key type, `_s_<indendent_arg>`
for each independent argument with dependent arguments.

These keys point to a string representation of the independent
Expand All @@ -185,7 +191,7 @@ These values are ignored by setAnchor, but they are useful
for routines using setAnchor to check if a part of the anchor
has changed.

### Example
#### Example

If the browser URI Anchor looks like this:

Expand All @@ -209,3 +215,4 @@ Then calling $.uriAnchor.makeAnchorMap(); will return a map that looks like so:
color : 'red'
};

END
26 changes: 15 additions & 11 deletions jquery.uriAnchor-1.1.js → jquery.uriAnchor.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
/*
* jQuery URI Anchor Plugin v1.1
* http://www.dynaorg.com/jquery/uriAnchor/
* Jquery plugin for state managment through the URI anchor (hash fragment)
*
* Copyright (c) 2013 Michael S. Mikowski
* (mike[dot]mikowski[at]gmail[dotcom])
*
* Copyright (c) 2011, 2012 Michael S. Mikowski
* Dual licensed under the MIT or GPL Version 2
* http://jquery.org/license
*
* Versions
* 1.1.0 - Initial jQuery plugin site release
*
*/

/*jslint browser : true, continue : true,
devel : true, indent : 2, maxerr : 50,
newcap : true, nomen : true, plusplus : true,
regexp : true, sloppy : true, vars : false,
white : true
*/
/*jslint browser : true, continue : true,
devel : true, indent : 2, maxerr : 50,
newcap : true, nomen : true, plusplus : true,
regexp : true, sloppy : true, vars : false,
white : true
*/

/*global jQuery */

Expand All @@ -30,7 +34,7 @@

getErrorReject, getVarType, getCleanAnchorString,
parseStringToMap, makeAnchorString, setAnchor,
makeAnchorMap
makeAnchorMap, configModule
;
//----------------- END MODULE SCOPE VARIABLES ---------------

Expand Down Expand Up @@ -478,7 +482,7 @@

// Begin public method /configModule/
// Set configuration options
var configModule = function ( arg_map ) {
configModule = function ( arg_map ) {
var
settable_map = configMap.settable_map_key,
key_name, error
Expand Down
31 changes: 31 additions & 0 deletions uriAnchor.jquery.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{ "name" : "uriAnchor",
"version" : "1.1.0",
"title" : "Sophisticated management of the URI location hash",
"author" : {
"name" : "Michael S. Mikowski",
"email" : "[email protected]"
},
"licenses" : [
{ "type" : "MIT",
"url" : "https://github.com/jquery/jquery/blob/master/MIT-LICENSE.txt"
},
{ "type" : "GPLv2",
"url" : "http://www.gnu.org/licenses/gpl-2.0.html"
}
],
"dependencies" : { "jquery" : ">=1.6.2" },

"description" : "Use this plugin to manage dependent and independent variables in the hash fragment of the URI. It has been designed and updated over five commercial SPA projects, and provides the capability to make the URI fragment your application state API. Bookmarks, browser history, the back button, and the forward button can all be made to act as the user expects. It is featured in the book 'Single page web applications - JavaScript end-to-end' (http://manning.com/mikowski)."
"keywords" : [
"hashtag", "hash", "uri", "bookmarks", "history", "address", "location",
"hashchange", "onhashchange"
],
"url" : "https://github.com/mmikowski/urianchor",
"homepage" : "https://github.com/mmikowski/urianchor",
"bugs" : "https://github.com/mmikowski/urianchor/issues",
"maintainers" : [
{ "name" : "Michael S. Mikowski",
"email" : "[email protected]"
}
]
}

0 comments on commit 40e443d

Please sign in to comment.