themes/enanium/js/inlinerename.js
author Dan
Tue, 05 May 2009 21:53:48 -0400
changeset 955 de4f81abc5e3
parent 921 a71de5e21423
child 958 3dafe0969e5a
permissions -rw-r--r--
Enanium: Set right sidebar as collapsible. Whether I will do the left one I do not know.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
955
de4f81abc5e3 Enanium: Set right sidebar as collapsible. Whether I will do the left one I do not know.
Dan
parents: 921
diff changeset
     1
// Sidebar collapse
de4f81abc5e3 Enanium: Set right sidebar as collapsible. Whether I will do the left one I do not know.
Dan
parents: 921
diff changeset
     2
function enanium_toggle_sidebar_right()
de4f81abc5e3 Enanium: Set right sidebar as collapsible. Whether I will do the left one I do not know.
Dan
parents: 921
diff changeset
     3
{
de4f81abc5e3 Enanium: Set right sidebar as collapsible. Whether I will do the left one I do not know.
Dan
parents: 921
diff changeset
     4
  if ( document.getElementById('enanium_sidebar_right').style.display == 'none' )
de4f81abc5e3 Enanium: Set right sidebar as collapsible. Whether I will do the left one I do not know.
Dan
parents: 921
diff changeset
     5
  {
de4f81abc5e3 Enanium: Set right sidebar as collapsible. Whether I will do the left one I do not know.
Dan
parents: 921
diff changeset
     6
    // show
de4f81abc5e3 Enanium: Set right sidebar as collapsible. Whether I will do the left one I do not know.
Dan
parents: 921
diff changeset
     7
    document.getElementById('enanium_sidebar_right').style.display = 'block';
de4f81abc5e3 Enanium: Set right sidebar as collapsible. Whether I will do the left one I do not know.
Dan
parents: 921
diff changeset
     8
    document.getElementById('enanium_sidebar_right_hidden').style.display = 'none';
de4f81abc5e3 Enanium: Set right sidebar as collapsible. Whether I will do the left one I do not know.
Dan
parents: 921
diff changeset
     9
    createCookie('right_sidebar', 'open', 365);
de4f81abc5e3 Enanium: Set right sidebar as collapsible. Whether I will do the left one I do not know.
Dan
parents: 921
diff changeset
    10
  }
de4f81abc5e3 Enanium: Set right sidebar as collapsible. Whether I will do the left one I do not know.
Dan
parents: 921
diff changeset
    11
  else
de4f81abc5e3 Enanium: Set right sidebar as collapsible. Whether I will do the left one I do not know.
Dan
parents: 921
diff changeset
    12
  {
de4f81abc5e3 Enanium: Set right sidebar as collapsible. Whether I will do the left one I do not know.
Dan
parents: 921
diff changeset
    13
    // hide
de4f81abc5e3 Enanium: Set right sidebar as collapsible. Whether I will do the left one I do not know.
Dan
parents: 921
diff changeset
    14
    document.getElementById('enanium_sidebar_right').style.display = 'none';
de4f81abc5e3 Enanium: Set right sidebar as collapsible. Whether I will do the left one I do not know.
Dan
parents: 921
diff changeset
    15
    document.getElementById('enanium_sidebar_right_hidden').style.display = 'block';
de4f81abc5e3 Enanium: Set right sidebar as collapsible. Whether I will do the left one I do not know.
Dan
parents: 921
diff changeset
    16
    createCookie('right_sidebar', 'collapsed', 365);
de4f81abc5e3 Enanium: Set right sidebar as collapsible. Whether I will do the left one I do not know.
Dan
parents: 921
diff changeset
    17
  }
de4f81abc5e3 Enanium: Set right sidebar as collapsible. Whether I will do the left one I do not know.
Dan
parents: 921
diff changeset
    18
}
de4f81abc5e3 Enanium: Set right sidebar as collapsible. Whether I will do the left one I do not know.
Dan
parents: 921
diff changeset
    19
de4f81abc5e3 Enanium: Set right sidebar as collapsible. Whether I will do the left one I do not know.
Dan
parents: 921
diff changeset
    20
addOnloadHook(function()
de4f81abc5e3 Enanium: Set right sidebar as collapsible. Whether I will do the left one I do not know.
Dan
parents: 921
diff changeset
    21
  {
de4f81abc5e3 Enanium: Set right sidebar as collapsible. Whether I will do the left one I do not know.
Dan
parents: 921
diff changeset
    22
    if ( readCookie('right_sidebar') == 'collapsed' )
de4f81abc5e3 Enanium: Set right sidebar as collapsible. Whether I will do the left one I do not know.
Dan
parents: 921
diff changeset
    23
    {
de4f81abc5e3 Enanium: Set right sidebar as collapsible. Whether I will do the left one I do not know.
Dan
parents: 921
diff changeset
    24
      document.getElementById('enanium_sidebar_right').style.display = 'none';
de4f81abc5e3 Enanium: Set right sidebar as collapsible. Whether I will do the left one I do not know.
Dan
parents: 921
diff changeset
    25
      document.getElementById('enanium_sidebar_right_hidden').style.display = 'block';
de4f81abc5e3 Enanium: Set right sidebar as collapsible. Whether I will do the left one I do not know.
Dan
parents: 921
diff changeset
    26
    }
de4f81abc5e3 Enanium: Set right sidebar as collapsible. Whether I will do the left one I do not know.
Dan
parents: 921
diff changeset
    27
  });
de4f81abc5e3 Enanium: Set right sidebar as collapsible. Whether I will do the left one I do not know.
Dan
parents: 921
diff changeset
    28
de4f81abc5e3 Enanium: Set right sidebar as collapsible. Whether I will do the left one I do not know.
Dan
parents: 921
diff changeset
    29
// Inline rename
de4f81abc5e3 Enanium: Set right sidebar as collapsible. Whether I will do the left one I do not know.
Dan
parents: 921
diff changeset
    30
921
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    31
function ajaxRenameInline()
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    32
{
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    33
  if ( KILL_SWITCH || IE )
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    34
    return false;
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    35
  // This trick is _so_ vBulletin...
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    36
  elem = document.getElementById('h2PageName');
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    37
  if(!elem) return;
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    38
  elem.style.display = 'none';
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    39
  name = elem.firstChild.nodeValue;
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    40
  textbox = document.createElement('input');
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    41
  textbox.type = 'text';
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    42
  textbox.value = name;
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    43
  textbox.id = 'pageheading';
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    44
  textbox.size = name.length + 7;
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    45
  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
    46
  textbox.oldname = name;
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    47
  elem.parentNode.insertBefore(textbox, elem);
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    48
  document.onclick = ajaxRenameInlineCancel;
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    49
  
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    50
  load_component(['l10n', 'fadefilter', 'messagebox']);
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    51
  textbox.focus();
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    52
  textbox.select();
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    53
}
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    54
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    55
function ajaxRenameInlineSave()
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    56
{
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    57
  elem1 = document.getElementById('h2PageName');
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    58
  elem2 = document.getElementById('pageheading');
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    59
  if(!elem1 || !elem2) return;
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    60
  value = elem2.value;
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    61
  elem2.parentNode.removeChild(elem2); // just destroy the thing
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    62
  elem1.removeChild(elem1.firstChild);
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    63
  elem1.appendChild(document.createTextNode(value));
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    64
  elem1.style.display = 'block';
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    65
  if(!value || value=='' || value==elem2.oldname) return;
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    66
  setAjaxLoading();
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    67
  ajaxPost(stdAjaxPrefix+'&_mode=rename', 'newtitle='+ajaxEscape(value), function() {
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    68
    if ( ajax.readyState == 4 )
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    69
    {
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    70
      unsetAjaxLoading();
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    71
      var response = String(ajax.responseText);
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    72
      if ( !check_json_response(response) )
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    73
      {
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    74
        handle_invalid_json(response);
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    75
        return false;
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    76
      }
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    77
      response = parseJSON(response);
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    78
      if ( response.success )
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    79
      {
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    80
        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
    81
      }
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    82
      else
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    83
      {
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    84
        alert(response.error);
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    85
      }
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    86
    }
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
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    90
function ajaxRenameInlineCancel(e)
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    91
{
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    92
  if ( typeof(e) != 'object' && IE )
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    93
    e = window.event;
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    94
  elem1 = document.getElementById('h2PageName');
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    95
  elem2 = document.getElementById('pageheading');
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    96
  if(!elem1 || !elem2) return;
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    97
  if ( typeof(e) == 'object' && e.target )
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    98
  {
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    99
    if(e.target == elem2)
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
   100
      return;
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
   101
  }
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
   102
  //value = elem2.value;
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
   103
  elem2.parentNode.removeChild(elem2); // just destroy the thing
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
   104
  //elem1.innerHTML = value;
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
   105
  elem1.style.display = 'block';
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
   106
  document.onclick = null;
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
   107
}
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
   108
955
de4f81abc5e3 Enanium: Set right sidebar as collapsible. Whether I will do the left one I do not know.
Dan
parents: 921
diff changeset
   109
if ( window.auth_rename )
de4f81abc5e3 Enanium: Set right sidebar as collapsible. Whether I will do the left one I do not know.
Dan
parents: 921
diff changeset
   110
{
de4f81abc5e3 Enanium: Set right sidebar as collapsible. Whether I will do the left one I do not know.
Dan
parents: 921
diff changeset
   111
  addOnloadHook(function()
921
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
   112
    {
955
de4f81abc5e3 Enanium: Set right sidebar as collapsible. Whether I will do the left one I do not know.
Dan
parents: 921
diff changeset
   113
      var h2 = document.getElementById('h2PageName');
de4f81abc5e3 Enanium: Set right sidebar as collapsible. Whether I will do the left one I do not know.
Dan
parents: 921
diff changeset
   114
      if ( h2 )
921
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
   115
      {
955
de4f81abc5e3 Enanium: Set right sidebar as collapsible. Whether I will do the left one I do not know.
Dan
parents: 921
diff changeset
   116
        h2.ondblclick = function()
de4f81abc5e3 Enanium: Set right sidebar as collapsible. Whether I will do the left one I do not know.
Dan
parents: 921
diff changeset
   117
        {
de4f81abc5e3 Enanium: Set right sidebar as collapsible. Whether I will do the left one I do not know.
Dan
parents: 921
diff changeset
   118
          ajaxRenameInline();
de4f81abc5e3 Enanium: Set right sidebar as collapsible. Whether I will do the left one I do not know.
Dan
parents: 921
diff changeset
   119
        }
921
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
   120
      }
955
de4f81abc5e3 Enanium: Set right sidebar as collapsible. Whether I will do the left one I do not know.
Dan
parents: 921
diff changeset
   121
    });
de4f81abc5e3 Enanium: Set right sidebar as collapsible. Whether I will do the left one I do not know.
Dan
parents: 921
diff changeset
   122
}