Skip to content

Commit 8aeb729

Browse files
committed
#56 AMD Support
1 parent ec9da3e commit 8aeb729

7 files changed

Lines changed: 99 additions & 56 deletions

File tree

README.md

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,38 @@ This Javascript library provides an emulation of HTML5 History API for older bro
55

66
The library operates according to W3C specification, adding no new or incompatible methods. The library can be used exactly as described, for example, in Dive Into HTML5 book (http://diveintohtml5.info/history.html) or in the History API Specification (http://www.w3.org/TR/html5/browsers.html#the-history-interface).
77

8-
Example of using the library in the pure JS context:
8+
### You may install this plugin with this command:
9+
```shell
10+
nmp install html5-history-api
11+
```
12+
13+
### AMD Support:
14+
```html
15+
<!DOCTYPE html>
16+
<html>
17+
<head>
18+
<script type="text/javascript" src="/require.js"></script>
19+
<script type="text/javascript">
20+
requirejs.config({
21+
paths: {
22+
'html5-history-api': '/history'
23+
}
24+
});
25+
requirejs(['html5-history-api'], function(history) {
26+
if (history.emulate) {
27+
console.log('In your browser is emulated HTML5-History-API');
28+
} else {
29+
console.log('In your browser is natively support HTML5-History-API');
30+
}
31+
});
32+
</script>
33+
</head>
34+
<body>
35+
</body>
36+
</html>
37+
```
938

39+
### Example of using the library in the pure JS context:
1040
```html
1141
<!DOCTYPE html>
1242
<html>
@@ -69,8 +99,7 @@ Example of using the library in the pure JS context:
6999
</html>
70100
```
71101

72-
Example of using the library along with JQuery:
73-
102+
### Example of using the library along with JQuery:
74103
```html
75104
<!DOCTYPE html>
76105
<html>
@@ -125,8 +154,7 @@ Example of using the library along with JQuery:
125154
</html>
126155
```
127156

128-
Example of using popstate (pure JS):
129-
157+
### Example of using popstate (pure JS):
130158
```javascript
131159
window[window.addEventListener ? 'addEventListener' : 'attachEvent']('popstate', function(event) {
132160

@@ -138,8 +166,7 @@ window[window.addEventListener ? 'addEventListener' : 'attachEvent']('popstate',
138166
}, false);
139167
```
140168

141-
Example of using popstate with JQuery:
142-
169+
### Example of using popstate with JQuery:
143170
```javascript
144171
$(window).on('popstate', function(event) {
145172

@@ -150,7 +177,7 @@ $(window).on('popstate', function(event) {
150177
});
151178
```
152179

153-
Advanced library configuration:
180+
### Advanced library configuration:
154181

155182
history.js?basepath=/pathtosite/ - the base path to the site; defaults to the root "/".
156183
history.js?redirect=true - enable link translation.

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "history",
33
"repo": "devote/HTML5-History-API",
44
"description": "HTML5 History API expansion for browsers not supporting pushState, replaceState",
5-
"version": "4.1.4",
5+
"version": "4.1.5",
66
"keywords": ["history", "pushState", "replaceState"],
77
"main": "history.js",
88
"scripts": ["history.js"],

history.iegte8.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*!
2-
* History API JavaScript Library v4.1.4
2+
* History API JavaScript Library v4.1.5
33
*
44
* Support: IE8+, FF3+, Opera 9+, Safari, Chrome and other
55
*
@@ -11,9 +11,18 @@
1111
* http://www.opensource.org/licenses/mit-license.php
1212
* http://www.gnu.org/licenses/gpl.html
1313
*
14-
* Update: 2014-05-14 14:27
14+
* Update: 2014-05-14 22:01
1515
*/
16-
(function(window) {
16+
(function(factory) {
17+
if (typeof self === 'object' && self.history) {
18+
factory(self);
19+
if (typeof define === 'function' && define['amd']) {
20+
define("html5-history-api", function() {
21+
return self.history;
22+
});
23+
}
24+
}
25+
})(function(window) {
1726
// Prevent the code from running if there is no window.history object
1827
if (!window.history) return;
1928
// symlink to document
@@ -977,4 +986,4 @@
977986
window[removeEventListenerName] = removeEventListener;
978987
window[dispatchEventName] = dispatchEvent;
979988

980-
})(window);
989+
});

history.iegte8.min.js

Lines changed: 15 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

history.js

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*!
2-
* History API JavaScript Library v4.1.4
2+
* History API JavaScript Library v4.1.5
33
*
44
* Support: IE6+, FF3+, Opera 9+, Safari, Chrome and other
55
*
@@ -11,11 +11,18 @@
1111
* http://www.opensource.org/licenses/mit-license.php
1212
* http://www.gnu.org/licenses/gpl.html
1313
*
14-
* Update: 2014-05-14 14:27
14+
* Update: 2014-05-14 22:01
1515
*/
16-
(function(window) {
17-
// Prevent the code from running if there is no window.history object
18-
if (!window.history) return;
16+
(function(factory) {
17+
if (typeof self === 'object' && self.history) {
18+
factory(self);
19+
if (typeof define === 'function' && define['amd']) {
20+
define("html5-history-api", function() {
21+
return self.history;
22+
});
23+
}
24+
}
25+
})(function(window) {
1926
// symlink to document
2027
var document = window.document;
2128
// HTML element
@@ -1207,4 +1214,4 @@
12071214

12081215
window['JSON'] = JSON;
12091216
}
1210-
})(window);
1217+
});

0 commit comments

Comments
 (0)