PageRenderTime 80ms CodeModel.GetById 60ms app.highlight 14ms RepoModel.GetById 1ms app.codeStats 1ms

/public/wuwei.js

http://github.com/mtravers/wuwei
JavaScript | 87 lines | 56 code | 15 blank | 16 comment | 12 complexity | f056b879751a27690f76c6a2d669c7a3 MD5 | raw file
 1// functions to support the wuwei Lisp library
 2
 3function add_spinner(after) {
 4    var s_id = after + '_spin';
 5    Element.insert($(after), {after: "<img src='/wupub/images/spinner.gif', id='" + s_id + "'>"});
 6}
 7
 8function remove_spinner (after) {
 9    var s_id = after + '_spin';
10    var elt = $(s_id);
11    if (elt != null) {		// spinner may have been removed by an update
12	Element.remove(elt);
13    }
14}
15
16// autocomplete support
17
18function setupAutocomplete(input, continuation) {
19    var input = $(input);
20    input.continuation = continuation;
21    // on blur, if autocomplete hasn't happend, send the string to the continuation in case it can do something (+++ should be an option)
22    // Event.observe($(input), 'blur', function (event) { 
23    // 	if (input.continuation != null) {
24    // 	    window.setTimeout(function () { // yes this is horrible, but this has to happen AFTER the click handler or you get the wrong thing
25    // 		new Ajax.Request(continuation, {asynchronous:true, evalScripts:true, parameters: {value_string: $(input).value, id: $(input).id} });
26    // 		input.continuation = null;
27    // 	    },150);
28    // 	}
29    // });
30}
31
32
33function postAutocomplete(text, li) {
34    var continuation = text.continuation;
35    var value = li.id;
36    var value_string = li.innerHTML;
37    var id = text.id
38    if (continuation != null) {
39	new Ajax.Request(continuation, {asynchronous:true, evalScripts:true, parameters: {value: value, value_string: value_string, id: id} });
40	//	text.continuation = null;
41    }
42}
43
44// inplace editor support
45
46// stupid that this isn't in the thing to being with.
47if (Ajax.InPlaceEditor != null) {
48    Ajax.InPlaceEditorWithEmptyText = Class.create(Ajax.InPlaceEditor, {
49
50	initialize : function($super, element, url, options) {
51	    if (!options.emptyText)        options.emptyText      = "click to edit…";
52	    if (!options.emptyClassName)   options.emptyClassName = "inplaceeditor-empty";
53	    $super(element, url, options);
54	    this.checkEmpty();
55	},
56
57	checkEmpty : function() {
58	    if (this.element.innerHTML.length == 0 && this.options.emptyText) {
59		this.element.appendChild(
60		    new Element('span', { className : this.options.emptyClassName }).update(this.options.emptyText)
61		);
62	    }
63	},
64
65	getText : function($super) {
66	    if (empty_span = this.element.select('.' + this.options.emptyClassName).first()) {
67		empty_span.remove();
68	    }
69	    return $super();
70	},
71
72	onComplete : function($super, transport) {
73	    this.checkEmpty();
74	    return $super(transport);
75	},
76
77	wrapUp: function(transport) {
78	    this.leaveEditMode();
79	    this.checkEmpty();
80	    // Can't use triggerCallback due to backward compatibility: requires
81	    // binding + direct element
82	    this._boundComplete(transport, this.element);
83	}
84
85
86    });
87}