PageRenderTime 16ms CodeModel.GetById 12ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/modules/mod_base/lib/js/modules/z.inplace-textbox.js

http://github.com/zotonic/zotonic
JavaScript | 66 lines | 29 code | 12 blank | 25 comment | 3 complexity | 28b6fd396becbe023b11bbd361526790 MD5 | raw file
 1/* inputoverlay js
 2----------------------------------------------------------
 3
 4@package:       Zotonic 2010
 5@Author:        Konstantin Nikiforov <helllamer@gmail.com>
 6
 7Copyright 2010 Konstantin Nikiforov
 8
 9Licensed under the Apache License, Version 2.0 (the "License");
10you may not use this file except in compliance with the License.
11You may obtain a copy of the License at
12
13http://www.apache.org/licenses/LICENSE-2.0
14
15Unless required by applicable law or agreed to in writing, software
16distributed under the License is distributed on an "AS IS" BASIS,
17WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18See the License for the specific language governing permissions and
19limitations under the License.
20
21---------------------------------------------------------- */
22
23/* switches the state of inplace_textbox to reading mode */
24function inplace_textbox_write2read(div) {    
25    div_read = div + "-r";
26    div_nodata = div + "-n";
27    input = div + "-i";
28    div_edit = div + "-e";
29
30    $("#" + div_edit).hide();
31    
32    value_input = $("#" + input).attr('value');
33    $("#" + div_read + " span:first").html(value_input);
34    if (jQuery.trim(value_input) == '') {
35        $("#" + div_nodata).show();
36    } else {
37        $("#" + div_read).show();
38    }
39}
40
41/* switches the state of inplace_textbox to editing mode */
42function inplace_textbox_read2write(div) {
43    div_read = div + "-r";
44    $("#" + div_read).hide();
45    
46    div_nodata = div + "-n";
47    $("#" + div_nodata).hide();
48
49    div_edit = div + "-e";
50    input = div + "-i";
51
52    value = $("#" + div_read + " span:first").html();
53    $("#" + input).attr('value', value); // copypaste value from text-span to input control
54    $("#" + div_edit).show();
55    $("#" + div_edit + " input:first").focus().select();
56}
57
58
59// show hint in read mode
60function inplace_textbox_show_hint(div) { $("#" + div + "-r" + " > #hint:first").show(); }
61function inplace_textbox_hide_hint(div) { $("#" + div + "-r" + " > #hint:first").hide(); }
62
63
64// initialize inplace_textboxes
65$(".inplace_textbox").each( function() {inplace_textbox_write2read($(this).attr('id')) } );
66