jquery-historyjs 0.1.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -9,7 +9,7 @@
9
9
  (function(window,undefined){
10
10
  "use strict";
11
11
 
12
- // --------------------------------------------------------------------------
12
+ // ========================================================================
13
13
  // Initialise
14
14
 
15
15
  // Localise Globals
@@ -25,7 +25,8 @@
25
25
  throw new Error('History.js HTML4 Support has already been loaded...');
26
26
  }
27
27
 
28
- // --------------------------------------------------------------------------
28
+
29
+ // ========================================================================
29
30
  // Initialise HTML4 Support
30
31
 
31
32
  // Initialise HTML4 Support
@@ -39,7 +40,8 @@
39
40
  History.initHtml4.initialized = true;
40
41
  }
41
42
 
42
- // ----------------------------------------------------------------------
43
+
44
+ // ====================================================================
43
45
  // Properties
44
46
 
45
47
  /**
@@ -49,7 +51,7 @@
49
51
  History.enabled = true;
50
52
 
51
53
 
52
- // ----------------------------------------------------------------------
54
+ // ====================================================================
53
55
  // Hash Storage
54
56
 
55
57
  /**
@@ -66,10 +68,11 @@
66
68
  */
67
69
  History.isLastHash = function(newHash){
68
70
  // Prepare
69
- var oldHash = History.getHashByIndex();
71
+ var oldHash = History.getHashByIndex(),
72
+ isLast;
70
73
 
71
74
  // Check
72
- var isLast = newHash === oldHash;
75
+ isLast = newHash === oldHash;
73
76
 
74
77
  // Return isLast
75
78
  return isLast;
@@ -122,7 +125,8 @@
122
125
  return hash;
123
126
  };
124
127
 
125
- // ----------------------------------------------------------------------
128
+
129
+ // ====================================================================
126
130
  // Discarded States
127
131
 
128
132
  /**
@@ -146,10 +150,11 @@
146
150
  History.discardState = function(discardedState,forwardState,backState){
147
151
  //History.debug('History.discardState', arguments);
148
152
  // Prepare
149
- var discardedStateHash = History.getHashByState(discardedState);
153
+ var discardedStateHash = History.getHashByState(discardedState),
154
+ discardObject;
150
155
 
151
156
  // Create Discard Object
152
- var discardObject = {
157
+ discardObject = {
153
158
  'discardedState': discardedState,
154
159
  'backState': backState,
155
160
  'forwardState': forwardState
@@ -192,10 +197,11 @@
192
197
  */
193
198
  History.discardedState = function(State){
194
199
  // Prepare
195
- var StateHash = History.getHashByState(State);
200
+ var StateHash = History.getHashByState(State),
201
+ discarded;
196
202
 
197
203
  // Check
198
- var discarded = History.discardedStates[StateHash]||false;
204
+ discarded = History.discardedStates[StateHash]||false;
199
205
 
200
206
  // Return true
201
207
  return discarded;
@@ -237,7 +243,8 @@
237
243
  return true;
238
244
  };
239
245
 
240
- // ----------------------------------------------------------------------
246
+
247
+ // ====================================================================
241
248
  // HTML4 HashChange Support
242
249
 
243
250
  if ( History.emulated.hashChange ) {
@@ -254,8 +261,9 @@
254
261
  History.checkerFunction = null;
255
262
 
256
263
  // Define some variables that will help in our checker function
257
- var
258
- lastDocumentHash = '';
264
+ var lastDocumentHash = '',
265
+ iframeId, iframe,
266
+ lastIframeHash, checkerRunning;
259
267
 
260
268
  // Handle depending on the browser
261
269
  if ( History.isInternetExplorer() ) {
@@ -263,9 +271,8 @@
263
271
  // We need to use an iframe to emulate the back and forward buttons
264
272
 
265
273
  // Create iFrame
266
- var
267
- iframeId = 'historyjs-iframe',
268
- iframe = document.createElement('iframe');
274
+ iframeId = 'historyjs-iframe';
275
+ iframe = document.createElement('iframe');
269
276
 
270
277
  // Adjust iFarme
271
278
  iframe.setAttribute('id', iframeId);
@@ -279,9 +286,8 @@
279
286
  iframe.contentWindow.document.close();
280
287
 
281
288
  // Define some variables that will help in our checker function
282
- var
283
- lastIframeHash = '',
284
- checkerRunning = false;
289
+ lastIframeHash = '';
290
+ checkerRunning = false;
285
291
 
286
292
  // Define the checker function
287
293
  History.checkerFunction = function(){
@@ -294,8 +300,7 @@
294
300
  checkerRunning = true;
295
301
 
296
302
  // Fetch
297
- var
298
- documentHash = History.getHash()||'',
303
+ var documentHash = History.getHash()||'',
299
304
  iframeHash = History.unescapeHash(iframe.contentWindow.document.location.hash)||'';
300
305
 
301
306
  // The Document Hash has changed (application caused)
@@ -376,9 +381,10 @@
376
381
  } // History.emulated.hashChange
377
382
 
378
383
 
379
- // ----------------------------------------------------------------------
384
+ // ====================================================================
380
385
  // HTML5 State Support
381
386
 
387
+ // Non-Native pushState Implementation
382
388
  if ( History.emulated.pushState ) {
383
389
  /*
384
390
  * We must emulate the HTML5 State Management by using HTML4 HashChange
@@ -392,12 +398,12 @@
392
398
  //History.debug('History.onHashChange', arguments);
393
399
 
394
400
  // Prepare
395
- var
396
- currentUrl = ((event && event.newURL) || document.location.href),
397
- currentHash = History.getHashByUrl(currentUrl),
398
- currentState = null,
399
- currentStateHash = null,
400
- currentStateHashExits = null;
401
+ var currentUrl = ((event && event.newURL) || document.location.href),
402
+ currentHash = History.getHashByUrl(currentUrl),
403
+ currentState = null,
404
+ currentStateHash = null,
405
+ currentStateHashExits = null,
406
+ discardObject;
401
407
 
402
408
  // Check if we are the same state
403
409
  if ( History.isLastHash(currentHash) ) {
@@ -437,7 +443,7 @@
437
443
  currentStateHash = History.getHashByState(currentState);
438
444
 
439
445
  // Check if we are DiscardedState
440
- var discardObject = History.discardedState(currentState);
446
+ discardObject = History.discardedState(currentState);
441
447
  if ( discardObject ) {
442
448
  // Ignore this state as it has been discarded and go back to the state before it
443
449
  if ( History.getHashByIndex(-2) === History.getHashByState(discardObject.forwardState) ) {
@@ -495,8 +501,7 @@
495
501
  History.busy(true);
496
502
 
497
503
  // Fetch the State Object
498
- var
499
- newState = History.createStateObject(data,title,url),
504
+ var newState = History.createStateObject(data,title,url),
500
505
  newStateHash = History.getHashByState(newState),
501
506
  oldState = History.getState(false),
502
507
  oldStateHash = History.getHashByState(oldState),
@@ -572,8 +577,7 @@
572
577
  History.busy(true);
573
578
 
574
579
  // Fetch the State Objects
575
- var
576
- newState = History.createStateObject(data,title,url),
580
+ var newState = History.createStateObject(data,title,url),
577
581
  oldState = History.getState(false),
578
582
  previousState = History.getStateByIndex(-2);
579
583
 
@@ -587,6 +591,15 @@
587
591
  return true;
588
592
  };
589
593
 
594
+ } // History.emulated.pushState
595
+
596
+
597
+
598
+ // ====================================================================
599
+ // Initialise
600
+
601
+ // Non-Native pushState Implementation
602
+ if ( History.emulated.pushState ) {
590
603
  /**
591
604
  * Ensure initial state is handled correctly
592
605
  */
@@ -601,6 +614,8 @@
601
614
  }; // History.initHtml4
602
615
 
603
616
  // Try and Initialise History
604
- History.init();
617
+ if ( typeof History.init !== 'undefined' ) {
618
+ History.init();
619
+ }
605
620
 
606
621
  })(window);
metadata CHANGED
@@ -1,93 +1,68 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: jquery-historyjs
3
- version: !ruby/object:Gem::Version
4
- hash: 27
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.1
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 1
9
- - 0
10
- version: 0.1.0
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - William Weidendorf
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2011-06-05 00:00:00 Z
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
12
+ date: 2011-11-22 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
21
15
  name: railties
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: &70187635725740 !ruby/object:Gem::Requirement
24
17
  none: false
25
- requirements:
18
+ requirements:
26
19
  - - ~>
27
- - !ruby/object:Gem::Version
28
- hash: 7
29
- segments:
30
- - 3
31
- - 0
32
- version: "3.0"
20
+ - !ruby/object:Gem::Version
21
+ version: '3.0'
33
22
  type: :runtime
34
- version_requirements: *id001
35
- - !ruby/object:Gem::Dependency
36
- name: thor
37
23
  prerelease: false
38
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: *70187635725740
25
+ - !ruby/object:Gem::Dependency
26
+ name: thor
27
+ requirement: &70187635725260 !ruby/object:Gem::Requirement
39
28
  none: false
40
- requirements:
29
+ requirements:
41
30
  - - ~>
42
- - !ruby/object:Gem::Version
43
- hash: 23
44
- segments:
45
- - 0
46
- - 14
47
- version: "0.14"
31
+ - !ruby/object:Gem::Version
32
+ version: '0.14'
48
33
  type: :runtime
49
- version_requirements: *id002
50
- - !ruby/object:Gem::Dependency
51
- name: bundler
52
34
  prerelease: false
53
- requirement: &id003 !ruby/object:Gem::Requirement
35
+ version_requirements: *70187635725260
36
+ - !ruby/object:Gem::Dependency
37
+ name: bundler
38
+ requirement: &70187635724800 !ruby/object:Gem::Requirement
54
39
  none: false
55
- requirements:
40
+ requirements:
56
41
  - - ~>
57
- - !ruby/object:Gem::Version
58
- hash: 23
59
- segments:
60
- - 1
61
- - 0
62
- - 0
42
+ - !ruby/object:Gem::Version
63
43
  version: 1.0.0
64
44
  type: :development
65
- version_requirements: *id003
66
- - !ruby/object:Gem::Dependency
67
- name: rails
68
45
  prerelease: false
69
- requirement: &id004 !ruby/object:Gem::Requirement
46
+ version_requirements: *70187635724800
47
+ - !ruby/object:Gem::Dependency
48
+ name: rails
49
+ requirement: &70187635724340 !ruby/object:Gem::Requirement
70
50
  none: false
71
- requirements:
51
+ requirements:
72
52
  - - ~>
73
- - !ruby/object:Gem::Version
74
- hash: 7
75
- segments:
76
- - 3
77
- - 0
78
- version: "3.0"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
79
55
  type: :development
80
- version_requirements: *id004
81
- description: This gem provides History.js and the related HTML4 dependencies for using History.js with jQuery in your Rails 3+ application.
82
- email:
56
+ prerelease: false
57
+ version_requirements: *70187635724340
58
+ description: This gem provides History.js and the related HTML4 dependencies for using
59
+ History.js with jQuery in your Rails 3+ application.
60
+ email:
83
61
  - wweidendorf@gmail.com
84
62
  executables: []
85
-
86
63
  extensions: []
87
-
88
64
  extra_rdoc_files: []
89
-
90
- files:
65
+ files:
91
66
  - .gitignore
92
67
  - Gemfile
93
68
  - Gemfile.lock
@@ -103,7 +78,6 @@ files:
103
78
  - lib/jquery-historyjs.rb
104
79
  - spec/lib/jquery-historyjs_spec.rb
105
80
  - spec/spec_helper.rb
106
- - vendor/assets/javascripts/amplify_store.js
107
81
  - vendor/assets/javascripts/history.js
108
82
  - vendor/assets/javascripts/history_adapter_jquery.js
109
83
  - vendor/assets/javascripts/history_core.js
@@ -111,38 +85,26 @@ files:
111
85
  - vendor/assets/javascripts/json2.js
112
86
  homepage: http://github.com/wweidendorf/jquery-historyjs
113
87
  licenses: []
114
-
115
88
  post_install_message:
116
89
  rdoc_options: []
117
-
118
- require_paths:
90
+ require_paths:
119
91
  - lib
120
- required_ruby_version: !ruby/object:Gem::Requirement
92
+ required_ruby_version: !ruby/object:Gem::Requirement
121
93
  none: false
122
- requirements:
123
- - - ">="
124
- - !ruby/object:Gem::Version
125
- hash: 3
126
- segments:
127
- - 0
128
- version: "0"
129
- required_rubygems_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ! '>='
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ required_rubygems_version: !ruby/object:Gem::Requirement
130
99
  none: false
131
- requirements:
132
- - - ">="
133
- - !ruby/object:Gem::Version
134
- hash: 23
135
- segments:
136
- - 1
137
- - 3
138
- - 6
100
+ requirements:
101
+ - - ! '>='
102
+ - !ruby/object:Gem::Version
139
103
  version: 1.3.6
140
104
  requirements: []
141
-
142
105
  rubyforge_project: jquery-historyjs
143
- rubygems_version: 1.7.2
106
+ rubygems_version: 1.8.11
144
107
  signing_key:
145
108
  specification_version: 3
146
109
  summary: Use History.js with Rails 3 and jQuery
147
110
  test_files: []
148
-
@@ -1,251 +0,0 @@
1
- /*!
2
- * Amplify Store - Persistent Client-Side Storage 1.0beta
3
- *
4
- * Copyright 2011 appendTo LLC. (http://appendto.com/team)
5
- * Dual licensed under the MIT or GPL licenses.
6
- * http://appendto.com/open-source-licenses
7
- *
8
- * http://amplifyjs.com
9
- */
10
- (function( amplify, undefined ) {
11
-
12
- var store = amplify.store = function( key, value, options, type ) {
13
- var type = store.type;
14
- if ( options && options.type && options.type in store.types ) {
15
- type = options.type;
16
- }
17
- return store.types[ type ]( key, value, options || {} );
18
- };
19
-
20
- store.types = {};
21
- store.type = null;
22
- store.addType = function( type, storage ) {
23
- if ( !store.type ) {
24
- store.type = type;
25
- }
26
-
27
- store.types[ type ] = storage;
28
- store[ type ] = function( key, value, options ) {
29
- options = options || {};
30
- options.type = type;
31
- return store( key, value, options );
32
- };
33
- }
34
- store.error = function() {
35
- return "amplify.store quota exceeded";
36
- };
37
-
38
- function createSimpleStorage( storageType, storage ) {
39
- var values = storage.__amplify__ ? JSON.parse( storage.__amplify__ ) : {};
40
- function remove( key ) {
41
- if ( storage.removeItem ) {
42
- storage.removeItem( key );
43
- } else {
44
- delete storage[ key ];
45
- }
46
- delete values[ key ];
47
- }
48
- store.addType( storageType, function( key, value, options ) {
49
- var ret = value,
50
- now = (new Date()).getTime(),
51
- storedValue,
52
- parsed;
53
-
54
- if ( !key ) {
55
- ret = {};
56
- for ( key in values ) {
57
- storedValue = storage[ key ];
58
- parsed = storedValue ? JSON.parse( storedValue ) : { expires: -1 };
59
- if ( parsed.expires && parsed.expires <= now ) {
60
- remove( key );
61
- } else {
62
- ret[ key.replace( /^__amplify__/, "" ) ] = parsed.data;
63
- }
64
- }
65
- storage.__amplify__ = JSON.stringify( values );
66
- return ret;
67
- }
68
-
69
- // protect against overwriting built-in properties
70
- key = "__amplify__" + key;
71
-
72
- if ( value === undefined ) {
73
- if ( values[ key ] ) {
74
- storedValue = storage[ key ];
75
- parsed = storedValue ? JSON.parse( storedValue ) : { expires: -1 };
76
- if ( parsed.expires && parsed.expires <= now ) {
77
- remove( key );
78
- } else {
79
- return parsed.data;
80
- }
81
- }
82
- } else {
83
- if ( value === null ) {
84
- remove( key );
85
- } else {
86
- parsed = JSON.stringify({
87
- data: value,
88
- expires: options.expires ? now + options.expires : null
89
- });
90
- try {
91
- storage[ key ] = parsed;
92
- values[ key ] = true;
93
- // quota exceeded
94
- } catch( error ) {
95
- // expire old data and try again
96
- store[ storageType ]();
97
- try {
98
- storage[ key ] = parsed;
99
- values[ key ] = true;
100
- } catch( error ) {
101
- throw store.error();
102
- }
103
- }
104
- }
105
- }
106
-
107
- storage.__amplify__ = JSON.stringify( values );
108
- return ret;
109
- });
110
- }
111
-
112
- // localStorage + sessionStorage
113
- // IE 8+, Firefox 3.5+, Safari 4+, Chrome 4+, Opera 10.5+, iPhone 2+, Android 2+
114
- for ( var webStorageType in { localStorage: 1, sessionStorage: 1 } ) {
115
- // try/catch for file protocol in Firefox
116
- try {
117
- if ( window[ webStorageType ].getItem ) {
118
- createSimpleStorage( webStorageType, window[ webStorageType ] );
119
- }
120
- } catch( e ) {}
121
- }
122
-
123
- // globalStorage
124
- // non-standard: Firefox 2+
125
- // https://developer.mozilla.org/en/dom/storage#globalStorage
126
- if ( window.globalStorage ) {
127
- // try/catch for file protocol in Firefox
128
- try {
129
- createSimpleStorage( "globalStorage",
130
- window.globalStorage[ window.location.hostname ] );
131
- // Firefox 2.0 and 3.0 have sessionStorage and globalStorage
132
- // make sure we defualt to globalStorage
133
- // but don't default to globalStorage in 3.5+ which also has localStorage
134
- if ( store.type === "sessionStorage" ) {
135
- store.type = "globalStorage";
136
- }
137
- } catch( e ) {}
138
- }
139
-
140
- // userData
141
- // non-standard: IE 5+
142
- // http://msdn.microsoft.com/en-us/library/ms531424(v=vs.85).aspx
143
- (function() {
144
- // append to html instead of body so we can do this from the head
145
- var div = document.createElement( "div" ),
146
- attrKey = "amplify",
147
- attrs;
148
- div.style.display = "none";
149
- document.getElementsByTagName( "head" )[ 0 ].appendChild( div );
150
- if ( div.addBehavior ) {
151
- div.addBehavior( "#default#userdata" );
152
- div.load( attrKey );
153
- attrs = div.getAttribute( attrKey ) ? JSON.parse( div.getAttribute( attrKey ) ) : {};
154
-
155
- store.addType( "userData", function( key, value, options ) {
156
- var ret = value,
157
- now = (new Date()).getTime(),
158
- attr,
159
- parsed,
160
- prevValue;
161
-
162
- if ( !key ) {
163
- ret = {};
164
- for ( key in attrs ) {
165
- attr = div.getAttribute( key );
166
- parsed = attr ? JSON.parse( attr ) : { expires: -1 };
167
- if ( parsed.expires && parsed.expires <= now ) {
168
- div.removeAttribute( key );
169
- delete attrs[ key ];
170
- } else {
171
- ret[ key ] = parsed.data;
172
- }
173
- }
174
- div.setAttribute( attrKey, JSON.stringify( attrs ) );
175
- div.save( attrKey );
176
- return ret;
177
- }
178
-
179
- // convert invalid characters to dashes
180
- // http://www.w3.org/TR/REC-xml/#NT-Name
181
- // simplified to assume the starting character is valid
182
- // also removed colon as it is invalid in HTML attribute names
183
- key = key.replace( /[^-._0-9A-Za-z\xb7\xc0-\xd6\xd8-\xf6\xf8-\u037d\u37f-\u1fff\u200c-\u200d\u203f\u2040\u2070-\u218f]/g, "-" );
184
-
185
- if ( value === undefined ) {
186
- if ( key in attrs ) {
187
- attr = div.getAttribute( key );
188
- parsed = attr ? JSON.parse( attr ) : { expires: -1 };
189
- if ( parsed.expires && parsed.expires <= now ) {
190
- div.removeAttribute( key );
191
- delete attrs[ key ];
192
- } else {
193
- return parsed.data;
194
- }
195
- }
196
- } else {
197
- if ( value === null ) {
198
- div.removeAttribute( key );
199
- delete attrs[ key ];
200
- } else {
201
- // we need to get the previous value in case we need to rollback
202
- prevValue = div.getAttribute( key );
203
- parsed = JSON.stringify({
204
- data: value,
205
- expires: (options.expires ? (now + options.expires) : null)
206
- });
207
- div.setAttribute( key, parsed );
208
- attrs[ key ] = true;
209
- }
210
- }
211
-
212
- div.setAttribute( attrKey, JSON.stringify( attrs ) );
213
- try {
214
- div.save( attrKey );
215
- // quota exceeded
216
- } catch ( error ) {
217
- // roll the value back to the previous value
218
- if ( prevValue === null ) {
219
- div.removeAttribute( key );
220
- delete attrs[ key ];
221
- } else {
222
- div.setAttribute( key, prevValue );
223
- }
224
-
225
- // expire old data and try again
226
- store.userData();
227
- try {
228
- div.setAttribute( key, parsed );
229
- attrs[ key ] = true;
230
- div.save( attrKey );
231
- } catch ( error ) {
232
- // roll the value back to the previous value
233
- if ( prevValue === null ) {
234
- div.removeAttribute( key );
235
- delete attrs[ key ];
236
- } else {
237
- div.setAttribute( key, prevValue );
238
- }
239
- throw store.error();
240
- }
241
- }
242
- return ret;
243
- });
244
- }
245
- }() );
246
-
247
- // in-memory storage
248
- // fallback for all browsers to enable the API even if we can't persist data
249
- createSimpleStorage( "memory", {} );
250
-
251
- }( this.amplify = this.amplify || {} ) );