forked from zehfernandes/jquery.fullContent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjquery.fullContent.js
executable file
·132 lines (97 loc) · 3.16 KB
/
jquery.fullContent.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/*
* Project: Jquery FullContent
* Description: Plugin which allows a full content browser navigation. Flexible and Extended.
* Author: Zeh Fernandes | zehfernandes.com
* This plugin needs jquery.ScrollTo http://demos.flesler.com/jquery/scrollTo/ to work.
*/
;(function ( $, window, undefined ) {
var pluginName = 'fullContent',
document = window.document,
defaults = {
stages: "div",
idComplement: 'page_',
stageStart: 1,
speedTransition: 800,
mapPosition: '',
ease: ''
};
// The actual plugin constructor
function Plugin( element, options ) {
this.element = element;
this.$window = $(window);
this.options = $.extend( {}, defaults, options) ;
this._defaults = defaults;
this._name = pluginName;
this.init();
this.configStage();
}
Plugin.prototype.configStage = function () {
var winwidth = this.$window.width(),
winheight = this.$window.height(),
stages = this.options.stages,
childrenPosition = this.options.mapPosition,
count = 0;
$(this.element).children(stages).each(function(index) {
$(this).css({
'position' : 'absolute',
'width' : winwidth,
'height' : winheight
});
if(childrenPosition[index]) {
var position = childrenPosition[index];
$(this).css({
'top' : winheight * (position['v'] - 1),
'left' : winwidth * (position['h'] - 1)
});
} else {
$(this).css({ 'top' : winheight * count });
}
count++;
});
//Ajust the browser viewport to actual stage
if (window.location.hash) {
var hash = window.location.hash.replace(/^#\/?/,'');
$.scrollTo('#' + this.options.idComplement + hash , 0 );
}
};
Plugin.prototype.init = function () {
var self = this,
stages = this.options.stages,
idComplement = this.options.idComplement;
$(this.element).children(stages).each(function(index) {
//Change the ID, added complement to allows scroll animation
var stageID = $(this).attr('id');
$(this).attr('id', idComplement+stageID);
//Scroll To startStage
if((!window.location.hash) && (self.options.stageStart == index+1)) {
$.scrollTo($(this), 0 );
window.location.hash = $(this).attr('id').replace(idComplement, '');
}
});
this.bind();
};
Plugin.prototype.bind = function () {
var self = this,
speed = this.options.speedTransition,
idComplement = this.options.idComplement,
ease = this.options.ease;
this.$window.resize(function() {
self.configStage();
});
this.$window.bind( 'hashchange', function( event ){
var hash = window.location.hash.replace(/^#\/?/,'');
if (ease) {
$.scrollTo('#'+self.options.idComplement+hash, speed, {easing: ease});
} else {
$.scrollTo('#'+self.options.idComplement+hash, speed);
}
});
};
$.fn[pluginName] = function ( options ) {
return this.each(function () {
if (!$.data(this, 'plugin_' + pluginName)) {
$.data(this, 'plugin_' + pluginName, new Plugin( this, options ));
}
});
}
}(jQuery, window));