/[drupal]/contributions/modules/semantic_search/js/semantic_search_browser.js
ViewVC logotype

Contents of /contributions/modules/semantic_search/js/semantic_search_browser.js

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.1 - (show annotations) (download) (as text)
Tue Jun 5 06:37:06 2007 UTC (2 years, 5 months ago) by hendler
Branch: MAIN
CVS Tags: HEAD
Branch point for: DRUPAL-5
File MIME type: text/javascript
adding files from our SVN
1 /*
2 * Copyright (C) May 2007 Jonathan Hendler
3 * The authors can be contacted at:
4 * - jonathan [at] civicactions (dot) com
5 *
6 * @license http://www.affero.org/oagpl.html
7 * @link http://drupal.org/project/semantic_search
8 */
9 /*
10 * #semantic-search-browser-classes,
11 #semantic-search-browser-objects,
12 #semantic-search-browser-values,
13 #semantic-search-browser-properties
14 * { height: 'toggle', opacity: 'toggle'
15 }
16 */
17
18 //constants
19 var sem_browser_padding = 20;
20 var sem_browser_left_offset = 0;
21
22
23 function sem_browser_reposition(current_focus){
24 $('.semantic-search-browser-nav-title').css('border','none');
25 $('.search-focus').css('border-bottom','1px solid black');
26
27 if (current_focus != '.search-focus') {
28 $(current_focus).fadeTo('slow',.5, function(){
29 $(current_focus + '> span').slideUp( 'slow' );
30 $('.search-focus').fadeTo('slow',1, function(){});
31
32 });
33 } else {
34 $('.search-focus').fadeTo('slow',1, function(){});
35 }
36
37 var given_top = parseInt($(current_focus).css('top'));
38 var given_left = sem_browser_left_offset;
39 //alert($('.search-focus').height());
40 var added_top = $('.search-focus').height() +sem_browser_padding + given_top;
41 var added_left = given_left +sem_browser_padding + $(current_focus).width();
42 var focus_left = given_left +sem_browser_padding + $(current_focus).width()/2;
43
44
45 var left_height = (2*sem_browser_padding) + $('.search-focus').height() + $('.bottom-left').height();
46 var right_height = (2*sem_browser_padding) + $('.search-focus').height() + $('.bottom-right').height();
47
48 //calculate container height
49 var max_height = (left_height<=right_height) ? left_height: right_height;
50
51
52 $('#semantic-search-browser-container').animate( { height: max_height }, 'slow', function(){
53 $('#semantic-search-browser-triangle').animate({
54 top: (added_top -(sem_browser_padding*2)), left: focus_left
55 }, 'slow');
56
57 $('#semantic-search-browser-jellybean').animate({left: (added_left*2)});
58
59 $('.bottom-left').animate({
60 top: added_top, left: given_left
61 }, 'slow');
62
63 $('.bottom-right').animate({
64 left: added_left, top: added_top
65 }, 'slow');
66
67 $('.search-focus').animate({
68 top: given_top, left: focus_left
69 }, 'slow', function(){
70 $('.search-focus > .semantic-search-browser-nav-title').css('border-bottom','1px solid white');
71 $('.search-focus ').css('border-bottom','3px solid #444444');
72 });
73 });
74
75
76
77 }
78
79 $(document).ready(function(){
80 $('#semantic-search-browser-indicator').css('display','none');
81
82 $('.semantic-search-browser-nav-title').click( function(){
83 sem_browser_change_focus(this);
84 sem_browser_update_history();
85 }
86 );
87
88 $('#wrapper #container .sidebar').slideToggle('slow',function(){
89 $.historyInit(sem_browse_history);
90 if (window.SEMANTIC_SEARCHBHistory == undefined) window.SEMANTIC_SEARCHBHistory = new Array();
91
92
93 //set classes
94 $('#semantic-search-browser-classes').addClass('search-focus');
95 $('#semantic-search-browser-properties').addClass('bottom-left');
96 $('#semantic-search-browser-values').addClass('bottom-right');
97
98 // get data
99 sem_browser_refresh_data('.search-focus', function(){
100 sem_browser_left_offset = parseInt($('#semantic-search-browser-values').css('left'));
101 $('#semantic-search-browser-properties >span').slideUp( );
102
103 $('#semantic-search-browser-values >span').slideUp('slow',function(){
104 sem_browser_update_history();
105 sem_browser_reposition('.search-focus');
106 } );
107 } , 'CLASSES');
108 });
109
110
111
112 });
113
114 function sem_search_browse_generate_search_url(){
115 var q_string = '&edit[sesu]=1&edit[1980]=1';
116 $('#semantic-search-browser-jellybean > ul li').each( function(i) {
117
118 if ($(this).attr('type') == 'PROPERTY_VALUES'){
119 q_string += '&edit[p_value][][' + $(this).attr('vv') + ']=' + $(this).attr('title');
120 } else if ($(this).attr('type') == 'CLASSES'){
121 q_string += '&edit[cat][]['+$(this).attr('title')+']='+$(this).attr('title');
122 }
123 else {
124 q_string += '&edit[facet][][]='+$(this).attr('title');
125 }
126 } );
127
128 return q_string;
129 }
130
131 //';
132 function _semantic_searchURLAppend(element_name,element_value){
133 return sep+element_name+'='+SEMANTIC_SEARCHUrl.encode(element_value);
134 }
135
136 /**
137 * work around for back button navigation issue
138 */
139 function sem_browser_update_history(semantic_search_rpc_url){
140 //needs to pause the SEMANTIC_SEARCHTestURL
141
142 try{
143 var temploc = new String(document.location);
144 var temparray = temploc.split('#');
145
146 var hash = new String(window.SEMANTIC_SEARCHBHistory.length);
147
148 if (semantic_search_rpc_url != null) window.SEMANTIC_SEARCHBHistory[hash] = semantic_search_rpc_url;
149 else if (semantic_search_rpc_url == null) window.SEMANTIC_SEARCHBHistory[hash] = temploc;
150 $.historyLoad(hash);
151
152 } catch(e){if(true) alert(e + '\n setSEMANTIC_SEARCHBHistory()');}
153 }
154
155 function sem_browse_history(newLocation){
156
157 if (newLocation != '' && window.SEMANTIC_SEARCHBHistory != undefined)
158 {
159 try{
160 //now get link from storage
161 var newlink = window.SEMANTIC_SEARCHBHistory[newLocation];
162 if (newlink != undefined && !false && newlink != SemanticSearchBrowseBaseURL){
163 if (newLocation != 0) var x = 2; //sem_browser_update_history(newlink);
164 else window.location = newlink;
165 // alert ( newlink +' '+newLocation);
166 }
167 }catch(e){ if(true) alert(e +'/n @ SEMANTIC_SEARCHTestURL');}
168 }
169 }
170
171
172 function sem_browser_get_data_type(this_id){
173 switch(this_id){
174 case 'semantic-search-browser-values':
175 return 'PROPERTY_VALUES';
176 break;
177 case 'semantic-search-browser-properties':
178 return 'PROPERTIES';
179 break;
180 case 'semantic-search-browser-classes':
181 default:
182 return 'CLASSES';
183 }
184 }
185
186 function sem_browser_change_focus(a){
187 var this_id = $(a).parent().attr('id');
188 var this_class = $(a).parent().attr('class');
189 var id_current_focus_id = $('.search-focus').attr('id');
190 var data_type = sem_browser_get_data_type(this_id);
191
192 if (this_id != id_current_focus_id) {
193 sem_browser_refresh_data('#'+this_id, function(){
194 //swap around .search-focus with new focus
195 $('#'+id_current_focus_id).removeClass('search-focus');
196 $('#'+id_current_focus_id).addClass(this_class);
197 $('#'+this_id).addClass('search-focus');
198 $('#'+this_id).removeClass(this_class);
199 $('.search-focus > span').slideDown('slow',function(){
200 sem_browser_reposition('#'+id_current_focus_id);
201 });
202 }, data_type);
203
204 //refresh heights again
205 }
206 }
207
208 function sem_browser_refresh_data(the_id, the_function, data_type){
209 var i = 0;
210 var uri = '';
211 var title = '';
212 var base_url = SEMANTIC_SEARCH_BROWSE_RPC_PATH;
213
214 $('#semantic-search-browser-indicator').fadeIn();
215
216 var search_url = base_url+'?dt='+data_type + sem_search_browse_generate_search_url();
217 $.get(search_url, function(data){
218 try{
219 var values = eval(data);
220 //$.cachePut(url_hash,data);
221 }
222 catch(e){alert(e.message +"\n "+e.description +"\n " +search_url+"\n");}
223
224 $(the_id+' ul').html('');
225
226 for(i=0;i<values[1].length;i++){
227 sem_browser_add_item_to_list(the_id,values[1][i].uri,values[1][i].title,values[1][i].type, values[1][i].value);
228 }
229
230 the_function();
231 sem_browser_update_title_counts(values[0]);
232 $('#semantic-search-browser-objects>span').html( values[3]+values[2] );
233 $('#semantic-search-browser-indicator').fadeOut();
234 });
235
236 }
237
238 function sem_browser_update_title_counts(values){
239
240 $('#semantic-search-title-count-classes').hover(
241 function(){
242 $('#semantic-search-title-count-classes').html(
243 '<span>' +
244 values.CLASSES.list_total + ' facets<br/>' +
245 values.CLASSES.data_total + ' items<br/>' +
246 values.CLASSES.in_search_total + ' items in search</span>'
247 );
248
249 },function(){
250 $('#semantic-search-title-count-classes').html(' ');
251 });
252
253 $('#semantic-search-title-count-properties').hover(
254 function(){
255 $('#semantic-search-title-count-properties').html(
256 '<span>' +
257 values.PROPERTIES.list_total + ' facets<br/>' +
258 values.PROPERTIES.data_total + ' items<br/>' +
259 values.PROPERTIES.in_search_total + ' items in search</span>'
260 );
261
262 },function(){
263 $('#semantic-search-title-count-properties').html(' ');
264 });
265
266 //over, out
267 $('#semantic-search-title-count-values').hover(
268 function(){
269 $('#semantic-search-title-count-values').html(
270 '<span>' +
271 values.PROPERTY_VALUES.list_total + ' facets<br/>' +
272 values.PROPERTY_VALUES.data_total + ' items<br/>' +
273 values.PROPERTY_VALUES.in_search_total + ' items in search</span>'
274 );
275
276 },function(){
277 $('#semantic-search-title-count-values').html(' ');
278 });
279
280 }
281
282 function sem_browser_add_jellybean(uri,title,type,vv){
283 var n = new Date();
284 var id = 'sb-' + n.getTime();
285 var new_html = '<li class="jellybean-li" id="'+id+'" title="'+uri+'" type="'+type+'" vv="'+vv+'" ><span class="jellybean-remove" title="remove jellybean" >[-]</span>&nbsp;'+title+'</li>';
286 $('#semantic-search-browser-jellybean ul').html(new_html+$('#semantic-search-browser-jellybean ul').html());
287
288 sem_browser_refresh_data('.search-focus', function(){
289 //overwrite onclick
290 $('.jellybean-remove').click(function(){
291 var ttype = $(this).parent().attr('type');
292 $(this).parent().remove();
293 sem_browser_refresh_data('.search-focus', function(){},ttype );
294 });
295 }, type);
296 }
297
298
299
300 function sem_browser_add_item_to_list(container_id,uri,title,type,value){
301 var n = new Date();
302 var id = 'uri-' + n.getTime();
303 var new_html = '<li class="facet-li" id="'+id+'" title="'+uri+'" type="'+type+'" vv="'+value+'" ><span class="facet-add" title="add to search" >[+]</span><span class="facet-title" >&nbsp;'+title+'</span></li>';
304 $(container_id+' ul').html(new_html+$(container_id+' ul').html());
305
306 $('.facet-add').click(function(){
307 var tid = $(this).parent().attr('id');
308 var turi = $(this).parent().attr('title');
309 var ttype = $(this).parent().attr('type');
310 var vv = $(this).parent().attr('vv');
311 var ttitle = $(this).parent().children('.facet-title').html();
312 sem_browser_add_jellybean(turi,ttitle,ttype,vv);
313 });
314 }
315

  ViewVC Help
Powered by ViewVC 1.1.2