@@ -23,22 +23,31 @@ function init() {
23
23
noWrapMode ( ) ;
24
24
noLinkifyMode ( ) ;
25
25
}
26
+ // Call init() on page load.
27
+ $ ( init ) ;
26
28
27
29
28
30
// Re-initialize page state if the back button is clicked.
29
- // NOTE(ms): It seems that the popstate event is fired on page load. Thus, it
30
- // is not necessary to bind the init() to page load independently.
31
- $ ( window ) . bind ( 'popstate' , init ) ;
31
+ // A workaround is required here because Chrome calls popstate on page load
32
+ // whereas Firefox does not.
33
+ $ ( window ) . bind ( 'popstate' , function ( ev ) {
34
+ if ( ! window . history . ready && // set this before each history.pushState
35
+ ! ev . originalEvent . state )
36
+ return ; // workaround for popstate on load
37
+
38
+ init ( ) ;
39
+ } ) ;
32
40
33
41
34
42
// Short-circuit 'new paste' link.
35
43
$ ( 'a.new' ) . unbind ( 'click' ) ;
36
- $ ( 'a.new' ) . click ( function ( e ) {
44
+ $ ( 'a.new' ) . click ( function ( e ) {
37
45
// Browsers that support history modification can change the page state
38
46
// without a refresh.
39
47
if ( window . history && history . pushState ) {
40
48
$ ( '#_content' ) . val ( '' ) ; // clear only the content field
41
49
showOnly ( 'new' ) ;
50
+ window . history . ready = true ;
42
51
history . pushState ( null , null , '/' ) ;
43
52
44
53
// Stop propagation.
@@ -52,6 +61,7 @@ $('a.new').click(function(e) {
52
61
// Redirects to 'url'. Employs deep magic to hide the referrer URL.
53
62
function redirect ( url ) {
54
63
if ( window . history && history . replaceState ) {
64
+ window . history . ready = true ;
55
65
history . replaceState ( null , null , '/' ) ;
56
66
}
57
67
window . location . href = url ;
@@ -181,6 +191,7 @@ $('.pastearea').blur(pasteAreaBlur);
181
191
function pasteSuccess ( data , text_status , jq_xhr ) {
182
192
// Update address bar with URL of paste.
183
193
if ( window . history && history . pushState ) {
194
+ window . history . ready = true ;
184
195
history . pushState ( null , null , data . id ) ;
185
196
loadPaste ( data . id ) ;
186
197
} else {
0 commit comments