themes/enanium/js/inlinerename.js
author Dan Fuhry <dan@enanocms.org>
Tue, 16 Nov 2010 12:31:41 -0500
branch1.1.7-maintenance
changeset 1317 6012710ae538
parent 958 3dafe0969e5a
child 1300 1f97ee3ec614
permissions -rw-r--r--
SECURITY: Fix SQL injection in banlist check (1.1.7 branch)
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
958
3dafe0969e5a Enanium: added collapse for left sidebar
Dan
parents: 955
diff changeset
     2
function enanium_toggle_sidebar(side)
955
de4f81abc5e3 Enanium: Set right sidebar as collapsible. Whether I will do the left one I do not know.
Dan
parents: 921
diff changeset
     3
{
958
3dafe0969e5a Enanium: added collapse for left sidebar
Dan
parents: 955
diff changeset
     4
  if ( document.getElementById('enanium_sidebar_' + side).style.display == 'none' )
955
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
958
3dafe0969e5a Enanium: added collapse for left sidebar
Dan
parents: 955
diff changeset
     7
    document.getElementById('enanium_sidebar_' + side).style.display = 'block';
3dafe0969e5a Enanium: added collapse for left sidebar
Dan
parents: 955
diff changeset
     8
    document.getElementById('enanium_sidebar_' + side + '_hidden').style.display = 'none';
3dafe0969e5a Enanium: added collapse for left sidebar
Dan
parents: 955
diff changeset
     9
    createCookie(side + '_sidebar', 'open', 365);
955
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
958
3dafe0969e5a Enanium: added collapse for left sidebar
Dan
parents: 955
diff changeset
    14
    document.getElementById('enanium_sidebar_' + side).style.display = 'none';
3dafe0969e5a Enanium: added collapse for left sidebar
Dan
parents: 955
diff changeset
    15
    document.getElementById('enanium_sidebar_' + side + '_hidden').style.display = 'block';
3dafe0969e5a Enanium: added collapse for left sidebar
Dan
parents: 955
diff changeset
    16
    createCookie(side + '_sidebar', 'collapsed', 365);
955
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
958
3dafe0969e5a Enanium: added collapse for left sidebar
Dan
parents: 955
diff changeset
    20
function enanium_toggle_sidebar_right()
3dafe0969e5a Enanium: added collapse for left sidebar
Dan
parents: 955
diff changeset
    21
{
3dafe0969e5a Enanium: added collapse for left sidebar
Dan
parents: 955
diff changeset
    22
  enanium_toggle_sidebar('right');
3dafe0969e5a Enanium: added collapse for left sidebar
Dan
parents: 955
diff changeset
    23
}
3dafe0969e5a Enanium: added collapse for left sidebar
Dan
parents: 955
diff changeset
    24
3dafe0969e5a Enanium: added collapse for left sidebar
Dan
parents: 955
diff changeset
    25
function enanium_toggle_sidebar_left()
3dafe0969e5a Enanium: added collapse for left sidebar
Dan
parents: 955
diff changeset
    26
{
3dafe0969e5a Enanium: added collapse for left sidebar
Dan
parents: 955
diff changeset
    27
  enanium_toggle_sidebar('left');
3dafe0969e5a Enanium: added collapse for left sidebar
Dan
parents: 955
diff changeset
    28
}
3dafe0969e5a Enanium: added collapse for left sidebar
Dan
parents: 955
diff changeset
    29
955
de4f81abc5e3 Enanium: Set right sidebar as collapsible. Whether I will do the left one I do not know.
Dan
parents: 921
diff changeset
    30
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
    31
  {
958
3dafe0969e5a Enanium: added collapse for left sidebar
Dan
parents: 955
diff changeset
    32
    if ( readCookie('left_sidebar') == 'collapsed' )
3dafe0969e5a Enanium: added collapse for left sidebar
Dan
parents: 955
diff changeset
    33
    {
3dafe0969e5a Enanium: added collapse for left sidebar
Dan
parents: 955
diff changeset
    34
      document.getElementById('enanium_sidebar_left').style.display = 'none';
3dafe0969e5a Enanium: added collapse for left sidebar
Dan
parents: 955
diff changeset
    35
      document.getElementById('enanium_sidebar_left_hidden').style.display = 'block';
3dafe0969e5a Enanium: added collapse for left sidebar
Dan
parents: 955
diff changeset
    36
    }
3dafe0969e5a Enanium: added collapse for left sidebar
Dan
parents: 955
diff changeset
    37
    
955
de4f81abc5e3 Enanium: Set right sidebar as collapsible. Whether I will do the left one I do not know.
Dan
parents: 921
diff changeset
    38
    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
    39
    {
de4f81abc5e3 Enanium: Set right sidebar as collapsible. Whether I will do the left one I do not know.
Dan
parents: 921
diff changeset
    40
      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
    41
      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
    42
    }
de4f81abc5e3 Enanium: Set right sidebar as collapsible. Whether I will do the left one I do not know.
Dan
parents: 921
diff changeset
    43
  });
de4f81abc5e3 Enanium: Set right sidebar as collapsible. Whether I will do the left one I do not know.
Dan
parents: 921
diff changeset
    44
de4f81abc5e3 Enanium: Set right sidebar as collapsible. Whether I will do the left one I do not know.
Dan
parents: 921
diff changeset
    45
// 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
    46
921
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    47
function ajaxRenameInline()
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    48
{
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    49
  if ( KILL_SWITCH || IE )
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    50
    return false;
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    51
  // This trick is _so_ vBulletin...
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    52
  elem = document.getElementById('h2PageName');
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    53
  if(!elem) return;
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    54
  elem.style.display = 'none';
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    55
  name = elem.firstChild.nodeValue;
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    56
  textbox = document.createElement('input');
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    57
  textbox.type = 'text';
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    58
  textbox.value = name;
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    59
  textbox.id = 'pageheading';
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    60
  textbox.size = name.length + 7;
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    61
  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
    62
  textbox.oldname = name;
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    63
  elem.parentNode.insertBefore(textbox, elem);
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    64
  document.onclick = ajaxRenameInlineCancel;
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    65
  
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    66
  load_component(['l10n', 'fadefilter', 'messagebox']);
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    67
  textbox.focus();
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    68
  textbox.select();
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    69
}
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    70
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    71
function ajaxRenameInlineSave()
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    72
{
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    73
  elem1 = document.getElementById('h2PageName');
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    74
  elem2 = document.getElementById('pageheading');
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    75
  if(!elem1 || !elem2) return;
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    76
  value = elem2.value;
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    77
  elem2.parentNode.removeChild(elem2); // just destroy the thing
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    78
  elem1.removeChild(elem1.firstChild);
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    79
  elem1.appendChild(document.createTextNode(value));
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    80
  elem1.style.display = 'block';
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    81
  if(!value || value=='' || value==elem2.oldname) return;
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    82
  setAjaxLoading();
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    83
  ajaxPost(stdAjaxPrefix+'&_mode=rename', 'newtitle='+ajaxEscape(value), function() {
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    84
    if ( ajax.readyState == 4 )
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    85
    {
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    86
      unsetAjaxLoading();
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    87
      var response = String(ajax.responseText);
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    88
      if ( !check_json_response(response) )
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    89
      {
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    90
        handle_invalid_json(response);
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    91
        return false;
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    92
      }
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    93
      response = parseJSON(response);
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    94
      if ( response.success )
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    95
      {
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    96
        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
    97
      }
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    98
      else
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
    99
      {
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
   100
        alert(response.error);
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
   101
      }
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
   102
    }
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
   103
  });
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
   104
}
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
   105
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
   106
function ajaxRenameInlineCancel(e)
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
   107
{
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
   108
  if ( typeof(e) != 'object' && IE )
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
   109
    e = window.event;
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
   110
  elem1 = document.getElementById('h2PageName');
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
   111
  elem2 = document.getElementById('pageheading');
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
   112
  if(!elem1 || !elem2) return;
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
   113
  if ( typeof(e) == 'object' && e.target )
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
   114
  {
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
   115
    if(e.target == elem2)
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
   116
      return;
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
   117
  }
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
   118
  //value = elem2.value;
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
   119
  elem2.parentNode.removeChild(elem2); // just destroy the thing
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
   120
  //elem1.innerHTML = value;
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
   121
  elem1.style.display = 'block';
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
   122
  document.onclick = null;
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
   123
}
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
   124
955
de4f81abc5e3 Enanium: Set right sidebar as collapsible. Whether I will do the left one I do not know.
Dan
parents: 921
diff changeset
   125
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
   126
{
de4f81abc5e3 Enanium: Set right sidebar as collapsible. Whether I will do the left one I do not know.
Dan
parents: 921
diff changeset
   127
  addOnloadHook(function()
921
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
   128
    {
955
de4f81abc5e3 Enanium: Set right sidebar as collapsible. Whether I will do the left one I do not know.
Dan
parents: 921
diff changeset
   129
      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
   130
      if ( h2 )
921
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
   131
      {
955
de4f81abc5e3 Enanium: Set right sidebar as collapsible. Whether I will do the left one I do not know.
Dan
parents: 921
diff changeset
   132
        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
   133
        {
de4f81abc5e3 Enanium: Set right sidebar as collapsible. Whether I will do the left one I do not know.
Dan
parents: 921
diff changeset
   134
          ajaxRenameInline();
de4f81abc5e3 Enanium: Set right sidebar as collapsible. Whether I will do the left one I do not know.
Dan
parents: 921
diff changeset
   135
        }
921
a71de5e21423 New primary theme: Enanium
Dan
parents:
diff changeset
   136
      }
955
de4f81abc5e3 Enanium: Set right sidebar as collapsible. Whether I will do the left one I do not know.
Dan
parents: 921
diff changeset
   137
    });
de4f81abc5e3 Enanium: Set right sidebar as collapsible. Whether I will do the left one I do not know.
Dan
parents: 921
diff changeset
   138
}