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