79 |
return false; |
return false; |
80 |
} |
} |
81 |
|
|
82 |
|
/* toggle visibility and replace text with something else */ |
83 |
|
function toggleLinkAndElement ( link, elementID, text ) { |
84 |
|
|
85 |
|
Element.toggle( elementID ); // toggle the element |
86 |
|
|
87 |
|
if ( link.innerHTML != text ) { |
88 |
|
// change link text |
89 |
|
link.oldInnerHTML = link.innerHTML; |
90 |
|
link.innerHTML = text; |
91 |
|
} else { |
92 |
|
// change it back |
93 |
|
link.innerHTML = link.oldInnerHTML; |
94 |
|
} |
95 |
|
|
96 |
|
return false; |
97 |
|
} |
98 |
|
|
99 |
|
|
100 |
/* |
/* |
101 |
submit results form using AJAX |
submit results form using AJAX |
102 |
*/ |
*/ |
148 |
load record nr in some template |
load record nr in some template |
149 |
*/ |
*/ |
150 |
|
|
151 |
function load_rec(nr, tmp_template_filename) { |
function load_rec(record_uri, tmp_template_filename) { |
152 |
if (! tmp_template_filename) tmp_template_filename = template_filename; |
if (! tmp_template_filename) tmp_template_filename = template_filename; |
153 |
Logger.info('load_rec '+nr+' in '+tmp_template_filename); |
Logger.info('load_rec '+record_uri+' in '+tmp_template_filename); |
154 |
|
|
155 |
var results_form = $('results_form'); |
var results_form = $('results_form'); |
156 |
|
|
157 |
if (results_form) { |
if (results_form) { |
158 |
var args = '?mfn='+nr+'&template_filename='+tmp_template_filename; |
var args = '?record_uri='+record_uri+'&template_filename='+tmp_template_filename; |
159 |
Logger.debug('Ajax.Updater(results,/search/record) '+args); |
Logger.debug('Ajax.Updater(results,/search/record) '+args); |
160 |
|
|
161 |
new Ajax.Updater( 'results', '/search/record'+args, { |
new Ajax.Updater( 'results', '/search/record'+args, { |
174 |
} |
} |
175 |
return false; |
return false; |
176 |
} |
} |
177 |
|
|
178 |
|
var WebPAC = { }; |
179 |
|
|
180 |
|
/* |
181 |
|
autocompleter which isn't (a suggest box) |
182 |
|
- don't just on first option on appear |
183 |
|
- removed fade-in/out effect |
184 |
|
- added configurable width (content width? centered?) |
185 |
|
- add icon which means suggest |
186 |
|
|
187 |
|
hopefully, this implementation won't break (much) when I update |
188 |
|
prototype next time :-) |
189 |
|
*/ |
190 |
|
|
191 |
|
|
192 |
|
WebPAC.Suggest = Class.create(); |
193 |
|
Logger.debug('Created WebPAC.Suggest Class'); |
194 |
|
Object.extend(Object.extend(WebPAC.Suggest.prototype, Ajax.Autocompleter.prototype), { |
195 |
|
initialize: function(element, update, url, options) { |
196 |
|
this.baseInitialize(element, update, options); |
197 |
|
this.options.asynchronous = true; |
198 |
|
this.options.onComplete = this.onComplete.bind(this); |
199 |
|
this.options.defaultParams = this.options.parameters || null; |
200 |
|
this.url = url; |
201 |
|
this.ignoreReturn = true; |
202 |
|
|
203 |
|
Logger.debug('WebPAC.Sugget initialize '+element+','+update+','+url); |
204 |
|
|
205 |
|
this.options.onShow = function(element, update) { |
206 |
|
if(!update.style.position || update.style.position=='absolute') { |
207 |
|
update.style.position = 'absolute'; |
208 |
|
Position.clone(element, update, {setHeight: false, offsetTop: element.offsetHeight}); |
209 |
|
} |
210 |
|
new Element.show(update); |
211 |
|
Logger.debug('WebPAC.Suggest.onShow'); |
212 |
|
}; |
213 |
|
|
214 |
|
this.options.onHide = function(element, update) { |
215 |
|
new Element.hide(update); |
216 |
|
Logger.debug('WebPAC.Suggest.onHide'); |
217 |
|
}; |
218 |
|
}, |
219 |
|
|
220 |
|
getUpdatedChoices: function() { |
221 |
|
entry = encodeURIComponent(this.options.paramName) + '=' + |
222 |
|
encodeURIComponent(this.getToken()); |
223 |
|
|
224 |
|
this.options.parameters = this.options.callback ? |
225 |
|
this.options.callback(this.element, entry) : entry; |
226 |
|
|
227 |
|
if(this.options.defaultParams) |
228 |
|
this.options.parameters += '&' + this.options.defaultParams; |
229 |
|
|
230 |
|
Logger.debug('WebPAC.Suggest called '+this.url); |
231 |
|
new Ajax.Request(this.url, this.options); |
232 |
|
}, |
233 |
|
|
234 |
|
onComplete: function(request) { |
235 |
|
Logger.debug('WebPAC.Suggest onComplete called'); |
236 |
|
this.updateChoices(request.responseText); |
237 |
|
}, |
238 |
|
|
239 |
|
markPrevious: function() { |
240 |
|
if(this.index > 0) this.index-- |
241 |
|
// else this.index = this.entryCount-1; |
242 |
|
}, |
243 |
|
|
244 |
|
markNext: function() { |
245 |
|
if(this.index < this.entryCount-1) this.index++ |
246 |
|
// else this.index = 0; |
247 |
|
} |
248 |
|
|
249 |
|
}); |
250 |
|
|
251 |
|
/* |
252 |
|
WebPAC.Updater |
253 |
|
*/ |
254 |
|
|
255 |
|
WebPAC.Updater = Class.create(); |
256 |
|
Logger.debug('Created WebPAC.Updater Class'); |
257 |
|
Object.extend(WebPAC.Updater.prototype, { |
258 |
|
initialize: function(container, url, options) { |
259 |
|
Logger.debug('WebPAC.Updater initialize '+container+','+url+','+options); |
260 |
|
url += '/ajax'; |
261 |
|
this.updater = new Ajax.Updater(container, url, options); |
262 |
|
$('_ajax').value = 1; |
263 |
|
if ($('_ajax').value) Logger.info("using AJAX"); |
264 |
|
} |
265 |
|
}); |
266 |
|
|