view wiki.js @ 3:ac7e15dcee69

Activate edits on mousedown instead of click to prevent default selection behavior.
author Atul Varma <varmaa@toolness.com>
date Sun, 01 Feb 2009 12:53:25 -0800
parents 1d3d91674bbe
children 01313b55ed09
line wrap: on
line source

function makeEditable(aEvt) {
  if (!aEvt.shiftKey)
    return;

  aEvt.preventDefault();

  var item = this;
  var newItem = $('<textarea class="wikiedit"></textarea>');
  $(newItem).attr("value", $(item).html());

  function setScrollHeight() {
    var scrollHeight = $(newItem).get(0).scrollHeight;
    $(newItem).height(scrollHeight);
  }

  $(newItem).blur(
    function() {
      var html = $(newItem).attr("value");
      $(item).html(html);
      $(item).mousedown(makeEditable);
      $(newItem).replaceWith(item);
    });

  $(newItem).keyup(setScrollHeight);
  $(item).replaceWith(newItem);
  setScrollHeight();

  $(newItem).focus();
}

function onLoad() {
  $(".wiki").mousedown(makeEditable);
}

$(window).ready(onLoad);