Revision 2d7b35c9
Added by Andreas Kohlbecker almost 16 years ago
- ID 2d7b35c95795d1846d218d595238f38c074d7a91
- Parent 155b094e
js/cdm_taxontree.js | ||
---|---|---|
1 | 1 |
// $Id$ |
2 | 2 |
|
3 |
|
|
3 |
|
|
4 | 4 |
(function($){ |
5 | 5 |
|
6 | 6 |
/** |
7 |
*
|
|
7 |
* |
|
8 | 8 |
*/ |
9 | 9 |
$.fn.cdm_taxontree = function(options) { |
10 |
|
|
10 |
|
|
11 | 11 |
var opts = $.extend({},$.fn.cdm_taxontree.defaults, options); |
12 |
|
|
12 |
|
|
13 | 13 |
return this.each(function() { |
14 |
|
|
14 |
|
|
15 | 15 |
/* ----------- magicbox ---------- */ |
16 | 16 |
$(this).cdm_taxontree_magicbox(); |
17 |
|
|
17 |
|
|
18 | 18 |
/* ----------- tree browser ---------- */ |
19 | 19 |
$(this).children('li').not('.invisible').click(function(event) { |
20 | 20 |
event.stopPropagation(); |
... | ... | |
28 | 28 |
var bg_image_tmp = parent_li.css('background-image'); |
29 | 29 |
var bg_image_loading = bg_image_tmp.replace(/^(.*)(\/.*)(\))$/, '$1/loading_subtree.gif$3') |
30 | 30 |
parent_li.css('background-image', bg_image_loading); |
31 |
|
|
31 |
|
|
32 | 32 |
// load DOM subtree and append it |
33 | 33 |
$.get(url, function(html){ |
34 | 34 |
var tree_container = parent_li.parents('div.cdm_taxontree_container'); |
... | ... | |
41 | 41 |
// restore scroll positions |
42 | 42 |
tree_container.children().scrollTop(tmp_scroller_y_left); |
43 | 43 |
}); |
44 |
|
|
44 |
|
|
45 | 45 |
} |
46 |
}
|
|
46 |
} |
|
47 | 47 |
$(this).removeClass('collapsed').addClass('expanded').children('ul').css('display', 'block'); |
48 | 48 |
} else if($(this).hasClass('expanded')){ |
49 | 49 |
$(this).removeClass('expanded').addClass('collapsed').children('ul').css('display', 'none'); |
50 | 50 |
} |
51 | 51 |
}); // END click() |
52 |
|
|
52 |
|
|
53 | 53 |
$(this).children('li').children('a').click(function(event) { |
54 | 54 |
event.stopPropagation(); |
55 | 55 |
}); |
56 |
|
|
56 |
|
|
57 | 57 |
/* ----------- widget ------------------- */ |
58 | 58 |
if(opts.widget){ |
59 |
var widget = $(this).parents(); |
|
59 | 60 |
var widget = $(this).parents('.cdm_taxontree_widget'); |
60 | 61 |
var optionList = widget.find('select'); |
61 |
|
|
62 |
|
|
62 | 63 |
// keep all options unselected |
63 | 64 |
optionList.change(function(){ |
64 | 65 |
$(this).children().removeAttr('selected'); |
... | ... | |
71 | 72 |
bind_select_click(optionList, $(this), opts.multiselect); |
72 | 73 |
} |
73 | 74 |
}); |
74 |
|
|
75 |
|
|
75 | 76 |
function bind_select_click(optionList, treelist, isMultiselect){ |
76 | 77 |
treelist.find('li .widget_select').click(function(event){ |
77 | 78 |
event.stopPropagation(); |
... | ... | |
86 | 87 |
optionList.children().remove(); |
87 | 88 |
} |
88 | 89 |
optionList.append('<option value="'+value+'">'+$(this).attr('title')+'</option>'); |
89 |
optionList.children().removeAttr('selected'); |
|
90 |
|
|
91 |
// fix bug in IE |
|
92 |
if( jQuery.browser['msie']) { |
|
93 |
if(jQuery.browser['version'].charAt(0) <= '6'){ |
|
94 |
return; |
|
95 |
} |
|
96 |
} |
|
97 |
// optionList.children().removeAttr('selected'); // yields a bug in IE6, @see http://gimp4you.eu.org/sandbox/js/test/removeAttr.html |
|
98 |
optionList.children("[@selected]").attr('selected',''); |
|
90 | 99 |
} |
91 | 100 |
}); |
92 | 101 |
} // END bind_select_click() |
93 |
|
|
94 |
|
|
102 |
|
|
103 |
|
|
95 | 104 |
}; // END cdm_taxontree() |
96 |
|
|
105 |
|
|
97 | 106 |
})(jQuery); |
98 | 107 |
|
99 | 108 |
|
... | ... | |
103 | 112 |
$.fn.cdm_taxontree_container_resize = function() { |
104 | 113 |
|
105 | 114 |
var current_w = $(this).parent().width(); |
106 |
|
|
107 |
// determine max horizontal extent of any children
|
|
115 |
|
|
116 |
// determine max horizontal extent of any children |
|
108 | 117 |
var tree_list = $(this).find('.cdm_taxontree_scroller_y > ul'); |
109 | 118 |
var w = tree_list.css('position', 'absolute').outerWidth({ margin: true }); |
110 | 119 |
tree_list.css('position', 'static'); |
... | ... | |
118 | 127 |
return; |
119 | 128 |
} |
120 | 129 |
} |
121 |
|
|
130 |
|
|
122 | 131 |
if(current_w < w){ |
123 | 132 |
$(this).parent().width(w); |
124 | 133 |
$(this).children().width(w); |
... | ... | |
131 | 140 |
*/ |
132 | 141 |
$.fn.cdm_taxontree_container_debug_size = function(msg) { |
133 | 142 |
|
134 |
var out = msg
|
|
143 |
var out = msg |
|
135 | 144 |
+ '<br /> scoll_x: ' + $(this).parent().width() |
136 | 145 |
+ '<br /> container: ' + $(this).width() |
137 | 146 |
+ '<br /> scoll_y: ' + $(this).children().width() |
... | ... | |
145 | 154 |
* |
146 | 155 |
*/ |
147 | 156 |
$.fn.cdm_taxontree_magicbox = function() { |
148 |
|
|
157 |
|
|
149 | 158 |
// exclude IE6 and lower versions |
150 | 159 |
if(!(jQuery.browser['msie'] && jQuery.browser['version'].charAt(0) < '7')){ |
151 | 160 |
|
... | ... | |
153 | 162 |
if(container[0] == undefined){ |
154 | 163 |
return; |
155 | 164 |
} |
156 |
|
|
165 |
|
|
157 | 166 |
container.hover( |
158 | 167 |
// --- mouseOver ---- // |
159 | 168 |
function() { |
160 | 169 |
var scroller_x = $(this).parent(); |
161 | 170 |
var scroller_y = $(this).children('.cdm_taxontree_scroller_y'); |
162 | 171 |
var container = scroller_x.parent(); |
163 |
|
|
172 |
|
|
164 | 173 |
var h = parseFloat(scroller_x.height()); |
165 | 174 |
var scroll_top = scroller_x.scrollTop(); |
166 | 175 |
var border_color = scroller_x.css('border-top-color'); |
167 | 176 |
|
168 | 177 |
// store scroll_left of scroller_x so that it can be restored on mouseOut |
169 | 178 |
scroller_x.append('<div class="_scrollLeft" style="display: none;" title="'+scroller_x.scrollLeft()+'"></div>'); |
170 |
|
|
179 |
|
|
171 | 180 |
var newWidth = $(this).cdm_taxontree_container_resize(); |
172 | 181 |
if(scroller_x.hasClass('expand-left')){ |
173 | 182 |
var shift_left = container.outerWidth({ margin: true }) - newWidth; |
... | ... | |
179 | 188 |
scroller_x.css('overflow-y', 'visible').css('overflow-x', 'visible').css('margin-left', shift_left).css('border-color', 'transparent').height(h); |
180 | 189 |
} |
181 | 190 |
// ----------------- // |
182 |
,
|
|
191 |
, |
|
183 | 192 |
// --- mouseOut ---- // |
184 | 193 |
function() { |
185 |
//return;
|
|
194 |
//return; |
|
186 | 195 |
var container = $(this); |
187 | 196 |
var scroller_x = $(this).parent('.cdm_taxontree_scroller_x'); |
188 | 197 |
var scroller_y = container.children('.cdm_taxontree_scroller_y'); |
189 | 198 |
var border_color = scroller_y.css('border-top-color'); |
190 |
|
|
199 |
|
|
191 | 200 |
var scroll_top = scroller_y.scrollTop(); |
192 | 201 |
scroller_y.css('overflow-y', 'visible').css('border-color', 'transparent'); |
193 | 202 |
scroller_x.css('overflow-y', 'auto').css('margin-left', '0').css('border-color', border_color).width('auto').scrollTop(scroll_top); |
194 |
|
|
195 |
// restore scroll_left of scroller_x
|
|
203 |
|
|
204 |
// restore scroll_left of scroller_x |
|
196 | 205 |
var scrollLeft = scroller_x.children('._scrollLeft').attr('title'); |
197 | 206 |
scroller_x.scrollLeft(scrollLeft) |
198 | 207 |
scroller_x.children('._scrollLeft').remove(); |
... | ... | |
201 | 210 |
); |
202 | 211 |
} |
203 | 212 |
// END exclude IE6 |
204 |
|
|
205 |
|
|
213 |
|
|
214 |
|
|
206 | 215 |
} |
207 | 216 |
|
208 | 217 |
$.fn.cdm_taxontree.defaults = { // set up default options |
209 | 218 |
widget: false, // true = enable widget mode |
210 |
element_name: 'widgetval', //
|
|
211 |
multiselect: false, // true = enable selection of multiple
|
|
219 |
element_name: 'widgetval', // |
|
220 |
multiselect: false // true = enable selection of multiple
|
|
212 | 221 |
}; |
213 | 222 |
|
214 |
/* ========================== auto activate ==========================
|
|
223 |
/* ========================== auto activate ========================== |
|
215 | 224 |
|
216 | 225 |
if (Drupal.jsEnabled) { |
217 | 226 |
$(document).ready(function() { |
218 | 227 |
$('ul.cdm_taxontree').cdm_taxontree(); |
219 | 228 |
}); |
220 | 229 |
} |
221 |
*/ |
|
230 |
*/ |
Also available in: Unified diff
release from 2008-10-23 of expertsdb committed to external development branch