-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathglobal.js
More file actions
169 lines (150 loc) · 4.38 KB
/
global.js
File metadata and controls
169 lines (150 loc) · 4.38 KB
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
// Global (Sitewide) Javascript functions
// Revision 1 (Sprint 2): function signatures - Dave 08:13, 25 October 2007 (PDT)
// NOTE: This is JS pseudocode, and will not run!
// Constants
var Constants = new Object();
Constants.Visibility = new Object();
Constants.Visibility.KEY = 'left';
Constants.Visibility.VISIBLE = 'auto';
Constants.Visibility.HIDDEN = '-999em';
// Window openers
// params: the javascript window parameter string, looks like: "height=X,width=Y,scrollbars=auto,..."
function OpenWin(url, name, params)
{
return window.open(url, name, params);
}
function OpenWinBasic(url)
{
return OpenWin(url, "", "");
}
function OpenWinWithURLDimName(url, name, h, w)
{
var addins = $H({ height: h, width: w });
var params = addins.toQueryString().sub('&', ',');
return OpenWin(url, name, params);
}
// Image rollovers
function SwitchImageTo(id, new_img)
{
// set the image src property
$(id).src = new_img;
}
// Calls to external services for content generation *
function PlaceAdIntoContent(id, type, category)
{
alert('This function is not yet implemented.');
}
// Visibility of elements on page
// Note: toggle visible switches the visibility state; this is a convenience function when you always want to switch
// but don't want to check the state of the element beforehand.
function IsVisible(id)
{
return !$(id).hasClassName('hidden');
}
function ToggleVisible(id)
{
if(!IsVisible(id)) { SetVisible(id, true); }
else { SetVisible(id, false); }
}
function SetVisible(id, visible)
{
var elem = $(id);
if(visible) { elem.removeClassName('hidden'); }
else { elem.addClassName('hidden'); }
}
function CopyContent(id_from, id_to, visible_from, visible_to)
{
// copy the content
var content = $(id_from).innerHTML;
$(id_to).innerHTML = content;
// set visibility
if(typeof(visible_from) == undefined) { visible_from = true; }
if(typeof(visible_to) == undefined) { visible_to = true; }
SetVisible(id_from, visible_from);
SetVisible(id_to, visible_to);
}
// Form submission helpers
// *** This function is currently not working. Try using <asp:Panel>'s DefaultButton property instead.
function AttachEnterKey(textbox_id)
{
var f = function(event)
{
if(event.keyCode == Event.KEY_RETURN)
{
Event.stop(event); // don't fire the onsubmit normally anymore!
var elem = $(textbox_id);
var frm = elem.form;
if(frm.onsubmit())
{
//alert('about to submit!');
frm.submit(); // do the form submission
}
}
}
Event.observe(textbox_id, 'keypress', f);
}
// String helpers
function TrimWhitespace(str)
{
return str.strip();
}
function Trim(str, character)
{
while(str.endsWith(character))
{
str = Chop(str);
}
return str;
}
function Chop(str)
{
return str.substr(0, str.length-1);
}
// ====== Hide/Show Legacy Code =======
// reveal_colapse starts with content colapsed
// global_reveal_layer starts with a placeholder for hidden content
function reveal_collapse (object) {
if (document.getElementById) {
document.getElementById(object).style.display = 'block';
}
else if (document.layers && document.layers[object]) {
document.layers[object].display = 'block';
}
else if (document.all) {
document.all[object].style.display = 'block';
}
}
function hide_collapse (object) {
if (document.getElementById) {
document.getElementById(object).style.display = 'none';
}
else if (document.layers && document.layers[object]) {
document.layers[object].display = 'none';
}
else if (document.all) {
document.all[object].style.display = 'none';
}
}
function global_reveal_layer (object) {
if (document.getElementById) {
document.getElementById(object).style.visibility = 'visible';
}
else if (document.layers && document.layers[object]) {
document.layers[object].visibility = 'visible';
}
else if (document.all) {
document.all[object].style.visibility = 'visible';
}
}
function global_hide_layer (object) {
if (document.getElementById) {
document.getElementById(object).style.visibility = 'hidden';
}
else if (document.layers && document.layers[object]) {
document.layers[object].visibility = 'hidden';
}
else if (document.all) {
document.all[object].style.visibility = 'hidden';
}
}
// =========================================