historyjs-rails 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +8 -6
- data/historyjs-rails.gemspec +2 -2
- data/lib/historyjs/rails/version.rb +2 -2
- data/spec/historyjs/rails/version_spec.rb +2 -2
- data/vendor/assets/javascripts/history_adapter_jquery.js +77 -77
- data/vendor/assets/javascripts/history_adapter_mootools.js +84 -84
- data/vendor/assets/javascripts/history_adapter_native.js +121 -121
- data/vendor/assets/javascripts/history_adapter_right.js +78 -78
- data/vendor/assets/javascripts/history_adapter_zepto.js +74 -74
- data/vendor/assets/javascripts/history_core.js +1943 -1943
- data/vendor/assets/javascripts/history_html4.js +621 -621
- data/vendor/assets/javascripts/json2.js +480 -480
- metadata +18 -8
data/README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
# History.js for Rails ![Build Status][travis_ci_build_status]
|
1
|
+
# History.js for Rails [![Build Status][travis_ci_build_status]][travis_ci][![Dependency Status][gemnasium_dependency_status]][gemnasium]
|
2
2
|
|
3
|
-
Provides History.js (1.7.1) for use with Rails 3
|
3
|
+
Provides History.js (1.7.1) for use with Rails 3 & 4
|
4
4
|
|
5
|
-
[RubyGems][ruby_gems] | [Ruby Toolbox][ruby_toolbox] | [GitHub][github] | [Travis CI][travis_ci] | [RubyDoc][ruby_doc]
|
5
|
+
[RubyGems][ruby_gems] | [Ruby Toolbox][ruby_toolbox] | [GitHub][github] | [Travis CI][travis_ci] | [Gemnasium][gemnasium] | [RubyDoc][ruby_doc]
|
6
6
|
|
7
7
|
## Installation
|
8
8
|
### Rails 3.1+
|
@@ -75,10 +75,12 @@ History.js is now installed. Woop!
|
|
75
75
|
##History.js Resources
|
76
76
|
[GitHub][historyjs_github]
|
77
77
|
|
78
|
-
[github]: http://github.com/philostler/historyjs-rails
|
79
|
-
[ruby_doc]: http://rubydoc.info/github/philostler/historyjs-rails/master/frames
|
80
78
|
[ruby_gems]: http://rubygems.org/gems/historyjs-rails
|
79
|
+
[ruby_toolbox]: http://www.ruby-toolbox.com/projects/historyjs-rails
|
80
|
+
[github]: http://github.com/philostler/historyjs-rails
|
81
81
|
[travis_ci]: http://travis-ci.org/philostler/historyjs-rails
|
82
82
|
[travis_ci_build_status]: https://secure.travis-ci.org/philostler/historyjs-rails.png
|
83
|
-
[
|
83
|
+
[gemnasium]: https://gemnasium.com/philostler/historyjs-rails
|
84
|
+
[gemnasium_dependency_status]: https://gemnasium.com/philostler/historyjs-rails.png
|
85
|
+
[ruby_doc]: http://rubydoc.info/github/philostler/historyjs-rails/master/frames
|
84
86
|
[historyjs_github]: http://github.com/balupton/history.js
|
data/historyjs-rails.gemspec
CHANGED
@@ -11,7 +11,7 @@ Gem::Specification.new do |s|
|
|
11
11
|
s.summary = %q{History.js for Rails}
|
12
12
|
s.description = %q{Provides History.js for use with Rails 3}
|
13
13
|
|
14
|
-
s.add_dependency "railties", "
|
14
|
+
s.add_dependency "railties", ">= 3.0"
|
15
15
|
|
16
16
|
s.add_development_dependency "rspec", "~> 2.0"
|
17
17
|
|
@@ -25,4 +25,4 @@ Gem::Specification.new do |s|
|
|
25
25
|
Dir["**/*.js"] +
|
26
26
|
Dir["**/*.rb"]
|
27
27
|
s.require_paths = ["lib"]
|
28
|
-
end
|
28
|
+
end
|
@@ -1,77 +1,77 @@
|
|
1
|
-
/**
|
2
|
-
* History.js jQuery Adapter
|
3
|
-
* @author Benjamin Arthur Lupton <contact@balupton.com>
|
4
|
-
* @copyright 2010-2011 Benjamin Arthur Lupton <contact@balupton.com>
|
5
|
-
* @license New BSD License <http://creativecommons.org/licenses/BSD/>
|
6
|
-
*/
|
7
|
-
|
8
|
-
// Closure
|
9
|
-
(function(window,undefined){
|
10
|
-
"use strict";
|
11
|
-
|
12
|
-
// Localise Globals
|
13
|
-
var
|
14
|
-
History = window.History = window.History||{},
|
15
|
-
jQuery = window.jQuery;
|
16
|
-
|
17
|
-
// Check Existence
|
18
|
-
if ( typeof History.Adapter !== 'undefined' ) {
|
19
|
-
throw new Error('History.js Adapter has already been loaded...');
|
20
|
-
}
|
21
|
-
|
22
|
-
// Add the Adapter
|
23
|
-
History.Adapter = {
|
24
|
-
/**
|
25
|
-
* History.Adapter.bind(el,event,callback)
|
26
|
-
* @param {Element|string} el
|
27
|
-
* @param {string} event - custom and standard events
|
28
|
-
* @param {function} callback
|
29
|
-
* @return {void}
|
30
|
-
*/
|
31
|
-
bind: function(el,event,callback){
|
32
|
-
jQuery(el).bind(event,callback);
|
33
|
-
},
|
34
|
-
|
35
|
-
/**
|
36
|
-
* History.Adapter.trigger(el,event)
|
37
|
-
* @param {Element|string} el
|
38
|
-
* @param {string} event - custom and standard events
|
39
|
-
* @param {Object=} extra - a object of extra event data (optional)
|
40
|
-
* @return {void}
|
41
|
-
*/
|
42
|
-
trigger: function(el,event,extra){
|
43
|
-
jQuery(el).trigger(event,extra);
|
44
|
-
},
|
45
|
-
|
46
|
-
/**
|
47
|
-
* History.Adapter.extractEventData(key,event,extra)
|
48
|
-
* @param {string} key - key for the event data to extract
|
49
|
-
* @param {string} event - custom and standard events
|
50
|
-
* @param {Object=} extra - a object of extra event data (optional)
|
51
|
-
* @return {mixed}
|
52
|
-
*/
|
53
|
-
extractEventData: function(key,event,extra){
|
54
|
-
// jQuery Native then jQuery Custom
|
55
|
-
var result = (event && event.originalEvent && event.originalEvent[key]) || (extra && extra[key]) || undefined;
|
56
|
-
|
57
|
-
// Return
|
58
|
-
return result;
|
59
|
-
},
|
60
|
-
|
61
|
-
/**
|
62
|
-
* History.Adapter.onDomLoad(callback)
|
63
|
-
* @param {function} callback
|
64
|
-
* @return {void}
|
65
|
-
*/
|
66
|
-
onDomLoad: function(callback) {
|
67
|
-
jQuery(callback);
|
68
|
-
}
|
69
|
-
};
|
70
|
-
|
71
|
-
// Try and Initialise History
|
72
|
-
if ( typeof History.init !== 'undefined' ) {
|
73
|
-
History.init();
|
74
|
-
}
|
75
|
-
|
76
|
-
})(window);
|
77
|
-
|
1
|
+
/**
|
2
|
+
* History.js jQuery Adapter
|
3
|
+
* @author Benjamin Arthur Lupton <contact@balupton.com>
|
4
|
+
* @copyright 2010-2011 Benjamin Arthur Lupton <contact@balupton.com>
|
5
|
+
* @license New BSD License <http://creativecommons.org/licenses/BSD/>
|
6
|
+
*/
|
7
|
+
|
8
|
+
// Closure
|
9
|
+
(function(window,undefined){
|
10
|
+
"use strict";
|
11
|
+
|
12
|
+
// Localise Globals
|
13
|
+
var
|
14
|
+
History = window.History = window.History||{},
|
15
|
+
jQuery = window.jQuery;
|
16
|
+
|
17
|
+
// Check Existence
|
18
|
+
if ( typeof History.Adapter !== 'undefined' ) {
|
19
|
+
throw new Error('History.js Adapter has already been loaded...');
|
20
|
+
}
|
21
|
+
|
22
|
+
// Add the Adapter
|
23
|
+
History.Adapter = {
|
24
|
+
/**
|
25
|
+
* History.Adapter.bind(el,event,callback)
|
26
|
+
* @param {Element|string} el
|
27
|
+
* @param {string} event - custom and standard events
|
28
|
+
* @param {function} callback
|
29
|
+
* @return {void}
|
30
|
+
*/
|
31
|
+
bind: function(el,event,callback){
|
32
|
+
jQuery(el).bind(event,callback);
|
33
|
+
},
|
34
|
+
|
35
|
+
/**
|
36
|
+
* History.Adapter.trigger(el,event)
|
37
|
+
* @param {Element|string} el
|
38
|
+
* @param {string} event - custom and standard events
|
39
|
+
* @param {Object=} extra - a object of extra event data (optional)
|
40
|
+
* @return {void}
|
41
|
+
*/
|
42
|
+
trigger: function(el,event,extra){
|
43
|
+
jQuery(el).trigger(event,extra);
|
44
|
+
},
|
45
|
+
|
46
|
+
/**
|
47
|
+
* History.Adapter.extractEventData(key,event,extra)
|
48
|
+
* @param {string} key - key for the event data to extract
|
49
|
+
* @param {string} event - custom and standard events
|
50
|
+
* @param {Object=} extra - a object of extra event data (optional)
|
51
|
+
* @return {mixed}
|
52
|
+
*/
|
53
|
+
extractEventData: function(key,event,extra){
|
54
|
+
// jQuery Native then jQuery Custom
|
55
|
+
var result = (event && event.originalEvent && event.originalEvent[key]) || (extra && extra[key]) || undefined;
|
56
|
+
|
57
|
+
// Return
|
58
|
+
return result;
|
59
|
+
},
|
60
|
+
|
61
|
+
/**
|
62
|
+
* History.Adapter.onDomLoad(callback)
|
63
|
+
* @param {function} callback
|
64
|
+
* @return {void}
|
65
|
+
*/
|
66
|
+
onDomLoad: function(callback) {
|
67
|
+
jQuery(callback);
|
68
|
+
}
|
69
|
+
};
|
70
|
+
|
71
|
+
// Try and Initialise History
|
72
|
+
if ( typeof History.init !== 'undefined' ) {
|
73
|
+
History.init();
|
74
|
+
}
|
75
|
+
|
76
|
+
})(window);
|
77
|
+
|
@@ -1,84 +1,84 @@
|
|
1
|
-
/**
|
2
|
-
* History.js MooTools Adapter
|
3
|
-
* @author Benjamin Arthur Lupton <contact@balupton.com>
|
4
|
-
* @copyright 2010-2011 Benjamin Arthur Lupton <contact@balupton.com>
|
5
|
-
* @license New BSD License <http://creativecommons.org/licenses/BSD/>
|
6
|
-
*/
|
7
|
-
|
8
|
-
// Closure
|
9
|
-
(function(window,undefined){
|
10
|
-
"use strict";
|
11
|
-
|
12
|
-
// Localise Globals
|
13
|
-
var
|
14
|
-
History = window.History = window.History||{},
|
15
|
-
MooTools = window.MooTools,
|
16
|
-
Element = window.Element;
|
17
|
-
|
18
|
-
// Check Existence
|
19
|
-
if ( typeof History.Adapter !== 'undefined' ) {
|
20
|
-
throw new Error('History.js Adapter has already been loaded...');
|
21
|
-
}
|
22
|
-
|
23
|
-
// Make MooTools aware of History.js Events
|
24
|
-
Object.append(Element.NativeEvents,{
|
25
|
-
'popstate':2,
|
26
|
-
'hashchange':2
|
27
|
-
});
|
28
|
-
|
29
|
-
// Add the Adapter
|
30
|
-
History.Adapter = {
|
31
|
-
/**
|
32
|
-
* History.Adapter.bind(el,event,callback)
|
33
|
-
* @param {Element|string} el
|
34
|
-
* @param {string} event - custom and standard events
|
35
|
-
* @param {function} callback
|
36
|
-
* @return {void}
|
37
|
-
*/
|
38
|
-
bind: function(el,event,callback){
|
39
|
-
var El = typeof el === 'string' ? document.id(el) : el;
|
40
|
-
El.addEvent(event,callback);
|
41
|
-
},
|
42
|
-
|
43
|
-
/**
|
44
|
-
* History.Adapter.trigger(el,event)
|
45
|
-
* @param {Element|string} el
|
46
|
-
* @param {string} event - custom and standard events
|
47
|
-
* @param {Object=} extra - a object of extra event data (optional)
|
48
|
-
* @return void
|
49
|
-
*/
|
50
|
-
trigger: function(el,event,extra){
|
51
|
-
var El = typeof el === 'string' ? document.id(el) : el;
|
52
|
-
El.fireEvent(event,extra);
|
53
|
-
},
|
54
|
-
|
55
|
-
/**
|
56
|
-
* History.Adapter.extractEventData(key,event,extra)
|
57
|
-
* @param {string} key - key for the event data to extract
|
58
|
-
* @param {string} event - custom and standard events
|
59
|
-
* @return {mixed}
|
60
|
-
*/
|
61
|
-
extractEventData: function(key,event){
|
62
|
-
// MooTools Native then MooTools Custom
|
63
|
-
var result = (event && event.event && event.event[key]) || (event && event[key]) || undefined;
|
64
|
-
|
65
|
-
// Return
|
66
|
-
return result;
|
67
|
-
},
|
68
|
-
|
69
|
-
/**
|
70
|
-
* History.Adapter.onDomLoad(callback)
|
71
|
-
* @param {function} callback
|
72
|
-
* @return {void}
|
73
|
-
*/
|
74
|
-
onDomLoad: function(callback) {
|
75
|
-
window.addEvent('domready',callback);
|
76
|
-
}
|
77
|
-
};
|
78
|
-
|
79
|
-
// Try and Initialise History
|
80
|
-
if ( typeof History.init !== 'undefined' ) {
|
81
|
-
History.init();
|
82
|
-
}
|
83
|
-
|
84
|
-
})(window);
|
1
|
+
/**
|
2
|
+
* History.js MooTools Adapter
|
3
|
+
* @author Benjamin Arthur Lupton <contact@balupton.com>
|
4
|
+
* @copyright 2010-2011 Benjamin Arthur Lupton <contact@balupton.com>
|
5
|
+
* @license New BSD License <http://creativecommons.org/licenses/BSD/>
|
6
|
+
*/
|
7
|
+
|
8
|
+
// Closure
|
9
|
+
(function(window,undefined){
|
10
|
+
"use strict";
|
11
|
+
|
12
|
+
// Localise Globals
|
13
|
+
var
|
14
|
+
History = window.History = window.History||{},
|
15
|
+
MooTools = window.MooTools,
|
16
|
+
Element = window.Element;
|
17
|
+
|
18
|
+
// Check Existence
|
19
|
+
if ( typeof History.Adapter !== 'undefined' ) {
|
20
|
+
throw new Error('History.js Adapter has already been loaded...');
|
21
|
+
}
|
22
|
+
|
23
|
+
// Make MooTools aware of History.js Events
|
24
|
+
Object.append(Element.NativeEvents,{
|
25
|
+
'popstate':2,
|
26
|
+
'hashchange':2
|
27
|
+
});
|
28
|
+
|
29
|
+
// Add the Adapter
|
30
|
+
History.Adapter = {
|
31
|
+
/**
|
32
|
+
* History.Adapter.bind(el,event,callback)
|
33
|
+
* @param {Element|string} el
|
34
|
+
* @param {string} event - custom and standard events
|
35
|
+
* @param {function} callback
|
36
|
+
* @return {void}
|
37
|
+
*/
|
38
|
+
bind: function(el,event,callback){
|
39
|
+
var El = typeof el === 'string' ? document.id(el) : el;
|
40
|
+
El.addEvent(event,callback);
|
41
|
+
},
|
42
|
+
|
43
|
+
/**
|
44
|
+
* History.Adapter.trigger(el,event)
|
45
|
+
* @param {Element|string} el
|
46
|
+
* @param {string} event - custom and standard events
|
47
|
+
* @param {Object=} extra - a object of extra event data (optional)
|
48
|
+
* @return void
|
49
|
+
*/
|
50
|
+
trigger: function(el,event,extra){
|
51
|
+
var El = typeof el === 'string' ? document.id(el) : el;
|
52
|
+
El.fireEvent(event,extra);
|
53
|
+
},
|
54
|
+
|
55
|
+
/**
|
56
|
+
* History.Adapter.extractEventData(key,event,extra)
|
57
|
+
* @param {string} key - key for the event data to extract
|
58
|
+
* @param {string} event - custom and standard events
|
59
|
+
* @return {mixed}
|
60
|
+
*/
|
61
|
+
extractEventData: function(key,event){
|
62
|
+
// MooTools Native then MooTools Custom
|
63
|
+
var result = (event && event.event && event.event[key]) || (event && event[key]) || undefined;
|
64
|
+
|
65
|
+
// Return
|
66
|
+
return result;
|
67
|
+
},
|
68
|
+
|
69
|
+
/**
|
70
|
+
* History.Adapter.onDomLoad(callback)
|
71
|
+
* @param {function} callback
|
72
|
+
* @return {void}
|
73
|
+
*/
|
74
|
+
onDomLoad: function(callback) {
|
75
|
+
window.addEvent('domready',callback);
|
76
|
+
}
|
77
|
+
};
|
78
|
+
|
79
|
+
// Try and Initialise History
|
80
|
+
if ( typeof History.init !== 'undefined' ) {
|
81
|
+
History.init();
|
82
|
+
}
|
83
|
+
|
84
|
+
})(window);
|
@@ -1,121 +1,121 @@
|
|
1
|
-
/**
|
2
|
-
* History.js Native Adapter
|
3
|
-
* @author Benjamin Arthur Lupton <contact@balupton.com>
|
4
|
-
* @copyright 2010-2011 Benjamin Arthur Lupton <contact@balupton.com>
|
5
|
-
* @license New BSD License <http://creativecommons.org/licenses/BSD/>
|
6
|
-
*/
|
7
|
-
|
8
|
-
// Closure
|
9
|
-
(function(window,undefined){
|
10
|
-
"use strict";
|
11
|
-
|
12
|
-
// Localise Globals
|
13
|
-
var History = window.History = window.History||{};
|
14
|
-
|
15
|
-
// Check Existence
|
16
|
-
if ( typeof History.Adapter !== 'undefined' ) {
|
17
|
-
throw new Error('History.js Adapter has already been loaded...');
|
18
|
-
}
|
19
|
-
|
20
|
-
// Add the Adapter
|
21
|
-
History.Adapter = {
|
22
|
-
/**
|
23
|
-
* History.Adapter.handlers[uid][eventName] = Array
|
24
|
-
*/
|
25
|
-
handlers: {},
|
26
|
-
|
27
|
-
/**
|
28
|
-
* History.Adapter._uid
|
29
|
-
* The current element unique identifier
|
30
|
-
*/
|
31
|
-
_uid: 1,
|
32
|
-
|
33
|
-
/**
|
34
|
-
* History.Adapter.uid(element)
|
35
|
-
* @param {Element} element
|
36
|
-
* @return {String} uid
|
37
|
-
*/
|
38
|
-
uid: function(element){
|
39
|
-
return element._uid || (element._uid = History.Adapter._uid++);
|
40
|
-
},
|
41
|
-
|
42
|
-
/**
|
43
|
-
* History.Adapter.bind(el,event,callback)
|
44
|
-
* @param {Element} element
|
45
|
-
* @param {String} eventName - custom and standard events
|
46
|
-
* @param {Function} callback
|
47
|
-
* @return
|
48
|
-
*/
|
49
|
-
bind: function(element,eventName,callback){
|
50
|
-
// Prepare
|
51
|
-
var uid = History.Adapter.uid(element);
|
52
|
-
|
53
|
-
// Apply Listener
|
54
|
-
History.Adapter.handlers[uid] = History.Adapter.handlers[uid] || {};
|
55
|
-
History.Adapter.handlers[uid][eventName] = History.Adapter.handlers[uid][eventName] || [];
|
56
|
-
History.Adapter.handlers[uid][eventName].push(callback);
|
57
|
-
|
58
|
-
// Bind Global Listener
|
59
|
-
element['on'+eventName] = (function(element,eventName){
|
60
|
-
return function(event){
|
61
|
-
History.Adapter.trigger(element,eventName,event);
|
62
|
-
};
|
63
|
-
})(element,eventName);
|
64
|
-
},
|
65
|
-
|
66
|
-
/**
|
67
|
-
* History.Adapter.trigger(el,event)
|
68
|
-
* @param {Element} element
|
69
|
-
* @param {String} eventName - custom and standard events
|
70
|
-
* @param {Object} event - a object of event data
|
71
|
-
* @return
|
72
|
-
*/
|
73
|
-
trigger: function(element,eventName,event){
|
74
|
-
// Prepare
|
75
|
-
event = event || {};
|
76
|
-
var uid = History.Adapter.uid(element),
|
77
|
-
i,n;
|
78
|
-
|
79
|
-
// Apply Listener
|
80
|
-
History.Adapter.handlers[uid] = History.Adapter.handlers[uid] || {};
|
81
|
-
History.Adapter.handlers[uid][eventName] = History.Adapter.handlers[uid][eventName] || [];
|
82
|
-
|
83
|
-
// Fire Listeners
|
84
|
-
for ( i=0,n=History.Adapter.handlers[uid][eventName].length; i<n; ++i ) {
|
85
|
-
History.Adapter.handlers[uid][eventName][i].apply(this,[event]);
|
86
|
-
}
|
87
|
-
},
|
88
|
-
|
89
|
-
/**
|
90
|
-
* History.Adapter.extractEventData(key,event,extra)
|
91
|
-
* @param {String} key - key for the event data to extract
|
92
|
-
* @param {String} event - custom and standard events
|
93
|
-
* @return {mixed}
|
94
|
-
*/
|
95
|
-
extractEventData: function(key,event){
|
96
|
-
var result = (event && event[key]) || undefined;
|
97
|
-
return result;
|
98
|
-
},
|
99
|
-
|
100
|
-
/**
|
101
|
-
* History.Adapter.onDomLoad(callback)
|
102
|
-
* @param {Function} callback
|
103
|
-
* @return
|
104
|
-
*/
|
105
|
-
onDomLoad: function(callback) {
|
106
|
-
var timeout = window.setTimeout(function(){
|
107
|
-
callback();
|
108
|
-
},2000);
|
109
|
-
window.onload = function(){
|
110
|
-
clearTimeout(timeout);
|
111
|
-
callback();
|
112
|
-
};
|
113
|
-
}
|
114
|
-
};
|
115
|
-
|
116
|
-
// Try and Initialise History
|
117
|
-
if ( typeof History.init !== 'undefined' ) {
|
118
|
-
History.init();
|
119
|
-
}
|
120
|
-
|
121
|
-
})(window);
|
1
|
+
/**
|
2
|
+
* History.js Native Adapter
|
3
|
+
* @author Benjamin Arthur Lupton <contact@balupton.com>
|
4
|
+
* @copyright 2010-2011 Benjamin Arthur Lupton <contact@balupton.com>
|
5
|
+
* @license New BSD License <http://creativecommons.org/licenses/BSD/>
|
6
|
+
*/
|
7
|
+
|
8
|
+
// Closure
|
9
|
+
(function(window,undefined){
|
10
|
+
"use strict";
|
11
|
+
|
12
|
+
// Localise Globals
|
13
|
+
var History = window.History = window.History||{};
|
14
|
+
|
15
|
+
// Check Existence
|
16
|
+
if ( typeof History.Adapter !== 'undefined' ) {
|
17
|
+
throw new Error('History.js Adapter has already been loaded...');
|
18
|
+
}
|
19
|
+
|
20
|
+
// Add the Adapter
|
21
|
+
History.Adapter = {
|
22
|
+
/**
|
23
|
+
* History.Adapter.handlers[uid][eventName] = Array
|
24
|
+
*/
|
25
|
+
handlers: {},
|
26
|
+
|
27
|
+
/**
|
28
|
+
* History.Adapter._uid
|
29
|
+
* The current element unique identifier
|
30
|
+
*/
|
31
|
+
_uid: 1,
|
32
|
+
|
33
|
+
/**
|
34
|
+
* History.Adapter.uid(element)
|
35
|
+
* @param {Element} element
|
36
|
+
* @return {String} uid
|
37
|
+
*/
|
38
|
+
uid: function(element){
|
39
|
+
return element._uid || (element._uid = History.Adapter._uid++);
|
40
|
+
},
|
41
|
+
|
42
|
+
/**
|
43
|
+
* History.Adapter.bind(el,event,callback)
|
44
|
+
* @param {Element} element
|
45
|
+
* @param {String} eventName - custom and standard events
|
46
|
+
* @param {Function} callback
|
47
|
+
* @return
|
48
|
+
*/
|
49
|
+
bind: function(element,eventName,callback){
|
50
|
+
// Prepare
|
51
|
+
var uid = History.Adapter.uid(element);
|
52
|
+
|
53
|
+
// Apply Listener
|
54
|
+
History.Adapter.handlers[uid] = History.Adapter.handlers[uid] || {};
|
55
|
+
History.Adapter.handlers[uid][eventName] = History.Adapter.handlers[uid][eventName] || [];
|
56
|
+
History.Adapter.handlers[uid][eventName].push(callback);
|
57
|
+
|
58
|
+
// Bind Global Listener
|
59
|
+
element['on'+eventName] = (function(element,eventName){
|
60
|
+
return function(event){
|
61
|
+
History.Adapter.trigger(element,eventName,event);
|
62
|
+
};
|
63
|
+
})(element,eventName);
|
64
|
+
},
|
65
|
+
|
66
|
+
/**
|
67
|
+
* History.Adapter.trigger(el,event)
|
68
|
+
* @param {Element} element
|
69
|
+
* @param {String} eventName - custom and standard events
|
70
|
+
* @param {Object} event - a object of event data
|
71
|
+
* @return
|
72
|
+
*/
|
73
|
+
trigger: function(element,eventName,event){
|
74
|
+
// Prepare
|
75
|
+
event = event || {};
|
76
|
+
var uid = History.Adapter.uid(element),
|
77
|
+
i,n;
|
78
|
+
|
79
|
+
// Apply Listener
|
80
|
+
History.Adapter.handlers[uid] = History.Adapter.handlers[uid] || {};
|
81
|
+
History.Adapter.handlers[uid][eventName] = History.Adapter.handlers[uid][eventName] || [];
|
82
|
+
|
83
|
+
// Fire Listeners
|
84
|
+
for ( i=0,n=History.Adapter.handlers[uid][eventName].length; i<n; ++i ) {
|
85
|
+
History.Adapter.handlers[uid][eventName][i].apply(this,[event]);
|
86
|
+
}
|
87
|
+
},
|
88
|
+
|
89
|
+
/**
|
90
|
+
* History.Adapter.extractEventData(key,event,extra)
|
91
|
+
* @param {String} key - key for the event data to extract
|
92
|
+
* @param {String} event - custom and standard events
|
93
|
+
* @return {mixed}
|
94
|
+
*/
|
95
|
+
extractEventData: function(key,event){
|
96
|
+
var result = (event && event[key]) || undefined;
|
97
|
+
return result;
|
98
|
+
},
|
99
|
+
|
100
|
+
/**
|
101
|
+
* History.Adapter.onDomLoad(callback)
|
102
|
+
* @param {Function} callback
|
103
|
+
* @return
|
104
|
+
*/
|
105
|
+
onDomLoad: function(callback) {
|
106
|
+
var timeout = window.setTimeout(function(){
|
107
|
+
callback();
|
108
|
+
},2000);
|
109
|
+
window.onload = function(){
|
110
|
+
clearTimeout(timeout);
|
111
|
+
callback();
|
112
|
+
};
|
113
|
+
}
|
114
|
+
};
|
115
|
+
|
116
|
+
// Try and Initialise History
|
117
|
+
if ( typeof History.init !== 'undefined' ) {
|
118
|
+
History.init();
|
119
|
+
}
|
120
|
+
|
121
|
+
})(window);
|