-
Notifications
You must be signed in to change notification settings - Fork 0
/
blindern.js
187 lines (151 loc) · 4.43 KB
/
blindern.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
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
$(document).ready(function() {
boxHandleObj.locate(document);
})
/**
* Markeringsbokser (som rader)
*/
var boxHandleElms = {};
function boxHandleItem(wrap, box) {
this.init = function(wrap, box) {
wrap = $(wrap); box = $(box);
box.css("display", "none");
// deaktivert?
this.disabled = false;
if (box.prop("disabled")) {
this.disabled = true;
}
// legg til elementet
this.name = box.attr("rel") || box.prop("name")+"".replace(new RegExp("^(.*)\\[.+?\\]$"), "$1[]");
this.multiple = box.attr("type") == "checkbox";
boxHandleElms[this.name] = boxHandleElms[this.name] || [];
boxHandleElms[this.name].push(this);
this.wrap = wrap;
this.box = box;
this.elements = this.wrap.tagName == "tr" ? this.wrap.find("td") : [this.wrap];
// sjekk for mellomrom i cellen
/* FIXME if (this.wrap.tagName == "tr" || this.wrap.tagName == "td")
{
if (this.wrap.getSize().y < 25 || this.elements[0].getStyle("height") == "auto") this.wrap.addClass("spacerfix");
}*/
if (!this.disabled) {
// sett pointer
wrap.css("cursor", "pointer");
var self = this;
wrap.hover(function() {
self.mouseover();
}, function() {
self.mouseout();
}).click(function(e) {
console.log(e.target.tagName);
self.click(e);
});
}
this.hover = false;
this.checked = this.box.prop("checked");
this.classname = null;
this.showimg = !this.wrap.hasClass("box_handle_noimg");
// TODO
if (this.showimg && false) {
this.elements[0].css({
"background-image": 'url(https://hsw.no/static/other/checkbox_'+(this.disabled ? 'disabled' : (this.checked ? 'yes' : 'no'))+'.gif)',
"background-position": 'left center',
"background-repeat": 'no-repeat',
"paddingLeft": '25px'
});
}
if (!this.disabled) this.check();
};
this.mouseover = function() {
this.hover = true;
this.set_background();
};
this.mouseout = function() {
this.hover = false;
this.set_background();
};
this.click = function(e) {
// klikket vi en link?
if ($(e.target).tagName == "a") return;
this.checked = !this.checked;
// har vi noen andre elementer som må krysses ut?
var self = this;
if (this.checked && !this.multiple && boxHandleElms[this.name].length > 1) {
boxHandleElms[this.name].each(function(i, obj) {
if (!obj.checked || obj == self) return;
obj.checked = false;
obj.check();
});
}
this.check();
};
this.check = function() {
this.box.prop("checked", this.checked);
//this.box.trigger((this.checked ? "" : "un")+"click");
// TODO
if (this.showimg && false)
{
this.elements[0].css("background-image", 'url(https://hsw.no/other/checkbox_'+(this.checked ? 'yes' : 'no')+'.gif)');
}
this.set_background();
};
this.set_background = function() {
// finn ut fargen
var classname = this.checked ? (this.hover ? "box_handle_checked_hover" : "box_handle_checked") : (this.hover ? "box_handle_hover" : "box_handle_normal");
if (classname != this.classname) {
var self = this;
$(this.elements).each(function(i, elm) {
$(elm).removeClass(self.classname).addClass(classname);
});
this.classname = classname;
}
return;
};
this.init(wrap, box);
}
var boxHandleObj = {
locate: function(element) {
// finn alle bokswrappere
$(element).find(".box_handle").each(function(i, wrap) {
// finn boksen
var box = $(wrap).find("input:first");
// allerede gått gjennom denne?
if (box.data("boxHandle")) return;
box.data("boxHandle", true);
// legg til boksen
new boxHandleItem(wrap, box);
});
// finn alle toogle linker
$(element).find(".box_handle_toggle").each(function(i, elm) {
elm = $(elm);
// allerede gått gjennom denne?
if (elm.data("boxHandleOK")) return;
elm.data("boxHandleOK", true);
// finn navn
var name = elm.attr("rel");
if (!name || !boxHandleElms[name] || !boxHandleElms[name][0].multiple) return;
// legg til event
elm.click(function() {
$(boxHandleElms[name]).each(function(i, obj) {
obj.checked = !obj.checked;
obj.check();
});
return false;
});
});
}
};
$(document).ready(function() {
$(".showoff").show();
$(".showoff a.activate").click(function(event) {
event.preventDefault();
var so = $($(this).parents(".showoff").get(0));
var so2 = so.next(".showon");
if (so2.is(":visible")) {
so2.hide("slow");
} else {
so.not(".keepon").hide("slow");
so2.show("slow");
}
});
$(".showon").hide();
});