themes/enanium/js/inlinerename.js
author Dan
Wed, 15 Apr 2009 20:10:40 -0400
changeset 921 a71de5e21423
child 955 de4f81abc5e3
permissions -rw-r--r--
New primary theme: Enanium
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
921
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
     1
function ajaxRenameInline()
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
     2
{
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
     3
  if ( KILL_SWITCH || IE )
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
     4
    return false;
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
     5
  // This trick is _so_ vBulletin...
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
     6
  elem = document.getElementById('h2PageName');
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
     7
  if(!elem) return;
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
     8
  elem.style.display = 'none';
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
     9
  name = elem.firstChild.nodeValue;
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    10
  textbox = document.createElement('input');
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    11
  textbox.type = 'text';
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    12
  textbox.value = name;
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    13
  textbox.id = 'pageheading';
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    14
  textbox.size = name.length + 7;
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    15
  textbox.onkeyup = function(e) { if(!e) return; if(e.keyCode == 13) ajaxRenameInlineSave(); if(e.keyCode == 27) ajaxRenameInlineCancel(); };
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    16
  textbox.oldname = name;
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    17
  elem.parentNode.insertBefore(textbox, elem);
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    18
  document.onclick = ajaxRenameInlineCancel;
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    19
  
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    20
  load_component(['l10n', 'fadefilter', 'messagebox']);
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    21
  textbox.focus();
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    22
  textbox.select();
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    23
}
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    24
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    25
function ajaxRenameInlineSave()
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    26
{
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    27
  elem1 = document.getElementById('h2PageName');
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    28
  elem2 = document.getElementById('pageheading');
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    29
  if(!elem1 || !elem2) return;
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    30
  value = elem2.value;
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    31
  elem2.parentNode.removeChild(elem2); // just destroy the thing
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    32
  elem1.removeChild(elem1.firstChild);
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    33
  elem1.appendChild(document.createTextNode(value));
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    34
  elem1.style.display = 'block';
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    35
  if(!value || value=='' || value==elem2.oldname) return;
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    36
  setAjaxLoading();
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    37
  ajaxPost(stdAjaxPrefix+'&_mode=rename', 'newtitle='+ajaxEscape(value), function() {
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    38
    if ( ajax.readyState == 4 )
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    39
    {
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    40
      unsetAjaxLoading();
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    41
      var response = String(ajax.responseText);
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    42
      if ( !check_json_response(response) )
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    43
      {
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    44
        handle_invalid_json(response);
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    45
        return false;
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    46
      }
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    47
      response = parseJSON(response);
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    48
      if ( response.success )
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    49
      {
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    50
        new MessageBox( MB_OK|MB_ICONINFORMATION, $lang.get('ajax_rename_success_title'), $lang.get('ajax_rename_success_body', { page_name_new: value }) );
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    51
      }
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    52
      else
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    53
      {
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    54
        alert(response.error);
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    55
      }
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    56
    }
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    57
  });
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    58
}
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    59
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    60
function ajaxRenameInlineCancel(e)
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    61
{
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    62
  if ( typeof(e) != 'object' && IE )
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    63
    e = window.event;
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    64
  elem1 = document.getElementById('h2PageName');
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    65
  elem2 = document.getElementById('pageheading');
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    66
  if(!elem1 || !elem2) return;
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    67
  if ( typeof(e) == 'object' && e.target )
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    68
  {
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    69
    if(e.target == elem2)
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    70
      return;
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    71
  }
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    72
  //value = elem2.value;
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    73
  elem2.parentNode.removeChild(elem2); // just destroy the thing
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    74
  //elem1.innerHTML = value;
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    75
  elem1.style.display = 'block';
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    76
  document.onclick = null;
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    77
}
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    78
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    79
addOnloadHook(function()
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    80
  {
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    81
    var h2 = document.getElementById('h2PageName');
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    82
    if ( h2 )
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    83
    {
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    84
      h2.ondblclick = function()
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    85
      {
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    86
        ajaxRenameInline();
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    87
      }
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    88
    }
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    89
  });