1 // Copyright (c) 2006 spinelz.org (http://script.spinelz.org/)
\r
3 // This code is substantially based on code from script.aculo.us which has the
\r
4 // following copyright and permission notice
\r
6 // Copyright (c) 2005 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us)
\r
8 // Permission is hereby granted, free of charge, to any person obtaining
\r
9 // a copy of this software and associated documentation files (the
\r
10 // "Software"), to deal in the Software without restriction, including
\r
11 // without limitation the rights to use, copy, modify, merge, publish,
\r
12 // distribute, sublicense, and/or sell copies of the Software, and to
\r
13 // permit persons to whom the Software is furnished to do so, subject to
\r
14 // the following conditions:
\r
16 // The above copyright notice and this permission notice shall be
\r
17 // included in all copies or substantial portions of the Software.
\r
19 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
\r
20 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
\r
21 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
\r
22 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
\r
23 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
\r
24 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
\r
25 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\r
27 InPlaceEditorEx = Class.create();
\r
28 Object.extend(Object.extend(InPlaceEditorEx.prototype, Ajax.InPlaceEditor.prototype), {
\r
29 /*********************************************
\r
31 * The URL option is unnecessary because
\r
32 * of updating without Ajax.
\r
33 *********************************************
\r
34 initialize: function(element, url, options) {
\r
36 *********************************************/
\r
37 initialize: function(element, options) {
\r
38 /*********************************************/
\r
39 this.element = $(element);
\r
41 this.options = Object.extend({
\r
45 cancelText: "cancel",
\r
46 savingText: "Saving...",
\r
47 clickToEditText: "Click to edit",
\r
50 onComplete: function(transport, element) {
\r
51 new Effect.Highlight(element, {startcolor: this.options.highlightcolor});
\r
53 onFailure: function(transport) {
\r
54 alert("Error communicating with the server: " + transport.responseText.stripTags());
\r
56 callback: function(form) {
\r
57 return Form.serialize(form);
\r
59 handleLineBreaks: true,
\r
60 loadingText: 'Loading...',
\r
61 savingClassName: 'inplaceeditor-saving',
\r
62 loadingClassName: 'inplaceeditor-loading',
\r
63 formClassName: 'inplaceeditor-form',
\r
64 highlightcolor: Ajax.InPlaceEditor.defaultHighlightColor,
\r
65 highlightendcolor: "#FFFFFF",
\r
66 externalControl: null,
\r
67 submitOnBlur: false,
\r
72 if(!this.options.formId && this.element.id) {
\r
73 this.options.formId = this.element.id + "-inplaceeditor";
\r
74 if ($(this.options.formId)) {
\r
75 // there's already a form with that name, don't specify an id
\r
76 this.options.formId = null;
\r
80 if (this.options.externalControl) {
\r
81 this.options.externalControl = $(this.options.externalControl);
\r
84 this.originalBackground = Element.getStyle(this.element, 'background-color');
\r
85 if (!this.originalBackground) {
\r
86 this.originalBackground = "transparent";
\r
89 this.element.title = this.options.clickToEditText;
\r
91 /*********************************************
\r
93 * The event to enter edit mode is changed
\r
94 * from single-click to double-click.
\r
95 *********************************************
\r
96 this.onclickListener = this.enterEditMode.bindAsEventListener(this);
\r
97 this.mouseoverListener = this.enterHover.bindAsEventListener(this);
\r
98 this.mouseoutListener = this.leaveHover.bindAsEventListener(this);
\r
99 Event.observe(this.element, 'click', this.onclickListener);
\r
100 Event.observe(this.element, 'mouseover', this.mouseoverListener);
\r
101 Event.observe(this.element, 'mouseout', this.mouseoutListener);
\r
102 if (this.options.externalControl) {
\r
103 Event.observe(this.options.externalControl, 'click', this.onclickListener);
\r
104 Event.observe(this.options.externalControl, 'mouseover', this.mouseoverListener);
\r
105 Event.observe(this.options.externalControl, 'mouseout', this.mouseoutListener);
\r
107 *********************************************/
\r
108 this.ondblclickListener = this.enterEditMode.bindAsEventListener(this);
\r
109 this.mouseoverListener = this.enterHover.bindAsEventListener(this);
\r
110 this.mouseoutListener = this.leaveHover.bindAsEventListener(this);
\r
111 Event.observe(this.element, 'dblclick', this.ondblclickListener);
\r
112 Event.observe(this.element, 'mouseover', this.mouseoverListener);
\r
113 Event.observe(this.element, 'mouseout', this.mouseoutListener);
\r
114 if (this.options.externalControl) {
\r
115 Event.observe(this.options.externalControl, 'dblclick', this.ondblclickListener);
\r
116 Event.observe(this.options.externalControl, 'mouseover', this.mouseoverListener);
\r
117 Event.observe(this.options.externalControl, 'mouseout', this.mouseoutListener);
\r
119 /*********************************************/
\r
121 getText: function() {
\r
122 return this.element.innerHTML.unescapeHTML();
\r
124 onSubmit: function() {
\r
125 var value = this.editField.value.escapeHTML();
\r
127 this.onclickCancel();
\r
131 this.element.innerHTML = value;
\r
132 new InPlaceEditorEx(this.element.id, this.options);
\r
136 removeForm: function() {
\r
138 if(this.form.parentNode) {
\r
139 var childNodes = this.form.parentNode.childNodes;
\r
140 for(var i = 0; i < childNodes.length; i++) {
\r
141 childNodes[i].data = '';
\r
143 Element.remove(this.form);
\r