document.observe("dom:loaded", function() { RecordSelect.document_loaded = true; document.on('ajax:before', 'div.record-select * li.record a', function(event) { var link = event.findElement(); if (link) { if (RecordSelect.notify(link) == false) { event.stop(); } else { link.toggleClassName("selected"); } } return true; }); }); Form.Element.AfterActivity = function(element, callback, delay) { element = $(element); if (!delay) delay = 0.25; new Form.Element.Observer(element, delay, function(element, value) { // TODO: display loading indicator if (element.activity_timer) clearTimeout(element.activity_timer); element.activity_timer = setTimeout(function() { callback(element.value); }, delay * 1000 + 50); }); } var RecordSelect = new Object(); RecordSelect.document_loaded = false; RecordSelect.notify = function(item) { var e = Element.up(item, '.record-select-handler'); var onselect = e.onselect || e.getAttribute('onselect'); if (typeof onselect != 'function') onselect = eval(onselect); if (onselect) { try { onselect(item.parentNode.id.substr(2), (item.down('label') || item).innerHTML.unescapeHTML(), e); } catch(e) { alert(e); } return false; } else return true; }; RecordSelect.render_page = function(record_select_id, page) { var page_element = $$('#' + record_select_id + ' ol')[0]; if (page_element) Element.replace(page_element, page); }; RecordSelect.Abstract = Class.create(); Object.extend(RecordSelect.Abstract.prototype, { /** * obj - the id or element that will anchor the recordselect to the page * url - the url to run the recordselect * options - ??? (check concrete classes) */ initialize: function(obj, url, options) { this.obj = $(obj); this.url = url; this.options = options; this.container; if (RecordSelect.document_loaded) this.onload(); else Event.observe(window, 'load', this.onload.bind(this)); }, /** * Finish the setup - IE doesn't like doing certain things before the page loads * --override-- */ onload: function() {}, /** * the onselect event handler - when someone clicks on a record * --override-- */ onselect: function(id, value) { alert(id + ': ' + value); }, /** * opens the recordselect */ open: function() { if (this.is_open()) return; new Ajax.Updater(this.container, this.url, { method: 'get', evalScripts: true, asynchronous: true, onComplete: function() { this.show(); // needs to be mousedown so the event doesn't get canceled by other code (see issue #26) Element.observe(document.body, 'mousedown', this.onbodyclick.bindAsEventListener(this)); }.bind(this) }); }, /** * positions and reveals the recordselect */ show: function() { var offset = Position.cumulativeOffset(this.obj); this.container.style.left = offset[0] + 'px'; this.container.style.top = (Element.getHeight(this.obj) + offset[1]) + 'px'; if (this._use_iframe_mask()) { this.container.insertAdjacentHTML('afterEnd', '