forked from e107inc/e107
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfeaturebox.js
128 lines (110 loc) · 4.35 KB
/
featurebox.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
/*
* e107 website system
*
* Copyright (C) 2008-2009 e107 Inc (e107.org)
* Released under the terms and conditions of the
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt)
*
* Featurebox Javascript Class
*
* $Source: /cvs_backup/e107_0.8/e107_plugins/featurebox/featurebox.js,v $
* $Revision$
* $Date$
* $Author$
*
*/
// Temporary solution, will be moved to e107Widgets
var Featurebox = Class.create({
initialize: function(container, options) {
this._container = $(container);
if(!this._container) return;
this.options = Object.extend({
'ajax_container': null,
'ajax_navbar': null,
'ajax_nav_selector': 'a.featurebox-nav-link',
'ajax_loader': null,
'ajax_hide_onload': false,
'continuous': false,
'ajax_url': '#{e_JS}'.parsePath() + 'e_ajax.php'
}, options || {});
this._ajax_container = this.options.ajax_container && $(this.options.ajax_container) ? $(this.options.ajax_container) : this._container.down('.body');
this._ajax_navbar = this.options.ajax_navbar && $(this.options.ajax_navbar) ? $(this.options.ajax_navbar) : this._container.down('.featurebox-nav');
this._ajax_loader = this.options.ajax_loader && $(this.options.ajax_loader) ? $(this.options.ajax_loader) : this._container.down('.featurebox-loader');
this._current = $A();
if(!this._ajax_container || !this._ajax_navbar) return;
this._ajax_nav = this._ajax_navbar.select(this.options.ajax_nav_selector);
this.clickObserverHandler = this.clickObserver.bindAsEventListener(this);
this.nextObserverHandler = this.nextObserver.bindAsEventListener(this);
this.prevObserverHandler = this.prevObserver.bindAsEventListener(this);
this.startObserve();
},
clickObserver: function(event) {
var element = event.element('a');
event.stop();
this.run(element);
},
nextObserver: function(event) {
event.stop();
var current = this._current[1] ? parseInt(this._current[1]) : 1,
next = current >= this._ajax_nav.length ? 0 : current;
if(!this.options.continuous && next == 0) return;
this.run(this._ajax_nav[next]);
},
prevObserver: function(event) {
event.stop();
var current = this._current[1] ? parseInt(this._current[1]) : 1,
prev = (current - 2) < 0 ? this._ajax_nav.length - 1 : current - 2;
if(!this.options.continuous && prev == this._ajax_nav.length - 1) return;
this.run(this._ajax_nav[prev]);
},
run: function(element) {
var options = element.href.split('#',2)[1].split('.'), that;
this._current = options;
if(element.hasClassName('active')) return;
this._ajax_navbar.select('.active').invoke('removeClassName', 'active');
element.addClassName('active');
if(element.up('li')) {
element.up('li').addClassName('active'); // only li support at this time
}
this.showLoader();
that = this;
new e107Ajax.Request(this.options.ajax_url, {
parameters: {
'ajax_sc': 'featurebox_items|' + varset(options[0], '') + '=from=' + varset(options[1], 0) + '&cols=' + varset(options[2], 0) + '&no_fill_empty=' + varset(options[3], 0)
},
method: 'post',
onComplete: function(transport) {
that.hideLoader(transport.responseText);
}
});
},
startObserve: function() {
this._ajax_navbar.select('a.featurebox-nav-link').invoke('observe', 'click', this.clickObserverHandler);
this._ajax_navbar.select('a.featurebox-nav-next').invoke('observe', 'click', this.nextObserverHandler);
this._ajax_navbar.select('a.featurebox-nav-prev').invoke('observe', 'click', this.prevObserverHandler);
},
stopObserve: function() {
this._ajax_navbar.select('a.featurebox-nav-link').invoke('stopObserving', 'click', this.clickObserverHandler);
this._ajax_navbar.select('a.featurebox-nav-next').invoke('stopObserving', 'click', this.nextObserverHandler);
this._ajax_navbar.select('a.featurebox-nav-prev').invoke('stopObserving', 'click', this.prevObserverHandler);
},
showLoader: function() {
if(this._ajax_loader) {
if(this.options.ajax_hide_onload) {
this._ajax_container.hide();
}
this._ajax_loader.show();
}
this.stopObserve();
},
hideLoader: function(text) {
if(this._ajax_loader) {
this._ajax_loader.hide();
if(this.options.ajax_hide_onload) {
this._ajax_container.show();
}
}
this._ajax_container.update(text);
this.startObserve();
}
});