if (typeof(Class) === 'undefined') { /* Simple Inheritance http://ejohn.org/blog/simple-javascript-inheritance/ */ (function(){ var initializing = false, fnTest = /xyz/.test(function(){xyz;}) ? /\b_super\b/ : /.*/; // The base Class implementation (does nothing) this.Class = function(){}; // Create a new Class that inherits from this class Class.extend = function(prop) { var _super = this.prototype; // Instantiate a base class (but only create the instance, // don't run the init constructor) initializing = true; var prototype = new this(); initializing = false; // Copy the properties over onto the new prototype for (var name in prop) { // Check if we're overwriting an existing function prototype[name] = typeof prop[name] == "function" && typeof _super[name] == "function" && fnTest.test(prop[name]) ? (function(name, fn){ return function() { var tmp = this._super; // Add a new ._super() method that is the same method // but on the super-class this._super = _super[name]; // The method only need to be bound temporarily, so we // remove it when we're done executing var ret = fn.apply(this, arguments); this._super = tmp; return ret; }; })(name, prop[name]) : prop[name]; } // The dummy class constructor function Class() { // All construction is actually done in the init method if ( !initializing && this.init ) this.init.apply(this, arguments); } // Populate our constructed prototype object Class.prototype = prototype; // Enforce the constructor to be what we expect Class.constructor = Class; // And make this class extendable Class.extend = arguments.callee; return Class; }; })(); }; /* jQuery delayed observer (c) 2007 - Maxime Haineault (max@centdessin.com) Special thanks to Stephen Goguen & Tane Piper. Slight modifications by Elliot Winkler */ if (typeof(jQuery.fn.delayedObserver) === 'undefined') { (function() { var delayedObserverStack = []; var observed; function delayedObserverCallback(stackPos) { observed = delayedObserverStack[stackPos]; if (observed.timer) return; observed.timer = setTimeout(function(){ observed.timer = null; observed.callback(observed.obj.val(), observed.obj); }, observed.delay * 1000); observed.oldVal = observed.obj.val(); } // going by // // I think these codes only work when using keyup or keydown function isNonPrintableKey(event) { var code = event.keyCode; return ( event.metaKey || (code >= 9 || code <= 16) || (code >= 27 && code <= 40) || (code >= 91 && code <= 93) || (code >= 112 && code <= 145) ); } jQuery.fn.extend({ delayedObserver:function(delay, callback){ $this = $(this); delayedObserverStack.push({ obj: $this, timer: null, delay: delay, oldVal: $this.val(), callback: callback }); stackPos = delayedObserverStack.length-1; $this.keyup(function(event) { if (isNonPrintableKey(event)) return; observed = delayedObserverStack[stackPos]; if (observed.obj.val() == observed.obj.oldVal) return; else delayedObserverCallback(stackPos); }); } }); })(); }; $(document).ready(function() { RecordSelect.document_loaded = true; $('div.record-select * li.record a').live('ajax:before', function(event) { var link = $(this); if (link) { if (RecordSelect.notify(link) == false) { return false; } else { link.toggleClass("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 = item.closest('.record-select-handler'); var onselect = e.get(0).onselect || e.attr('onselect'); if (typeof onselect != 'function') onselect = eval(onselect); if (onselect) { try { // .unescapeHTML() not implemented so far var label = $.trim(item.find('label').first().html()); if (label.length == 0) { label = item.html(); } onselect(item.parent().attr('id').substr(2), label, e); } catch(e) { alert(e); } return false; } else return true; } RecordSelect.render_page = function(record_select_id, page) { $('#' + record_select_id + ' ol').first().replaceWith(page); }; RecordSelect.Abstract = Class.extend({ /** * obj - the id or element that will anchor the recordselect to the page * url - the url to run the recordselect * options - ??? (check concrete classes) */ init: function(obj, url, options) { if (typeof(obj) == 'string') obj = '#' + obj; this.obj = $(obj); this.url = url; this.options = options; this.container; if (RecordSelect.document_loaded) { this.onload(); } else { var _this = this; $(document).ready(function() { _this.onload(); }) } }, /** * 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; var _this = this; $.ajax({ url: this.url, //type: "POST", //data: options['params'], //dataType: options.ajax_data_type, success: function(data){ _this.container.html(data); _this.show(); $(document.body).mousedown(jQuery.proxy(_this, "onbodyclick")); } }); }, /** * positions and reveals the recordselect */ show: function() { var offset = this.obj.offset(), top = this.obj.height() + offset.top; this.container.show(); this.container.css('left', offset.left); if (top + this.container.height() > $(document).height()) this.container.css('top', offset.top - this.container.height()); else this.container.css('top', top); if (this._use_iframe_mask()) { this.container.after('